Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Wasmtime ABIs from Cranelift #6649

Merged
merged 5 commits into from
Jun 28, 2023

Conversation

alexcrichton
Copy link
Member

This commit removes the Wasmtime* family of ABIs from Cranelift. These were originally added to support multi-value in Wasmtime via the TypedFunc API, but they should now no longer be necessary. In general this is a higher-level Wasmtime concern than something all backends of Cranelift should have to deal with.

Today with recent refactorings it's possible to remove the reliance on ABI details for multi-value and instead codify it directly into the Cranelift IR generated. For example wasm calls are able to have a "purely internal" ABI which Wasmtime's Rust code doesn't see at all, and the Rust code only interacts with the native ABI. The native ABI is redefined to be what the previous Wasmtime ABIs were, which is to return the first of a 2+ value return through a register (native return value) and everything else through a return pointer.

This commit removes the `Wasmtime*` family of ABIs from Cranelift. These
were originally added to support multi-value in Wasmtime via the
`TypedFunc` API, but they should now no longer be necessary. In general
this is a higher-level Wasmtime concern than something all backends of
Cranelift should have to deal with.

Today with recent refactorings it's possible to remove the reliance on
ABI details for multi-value and instead codify it directly into the
Cranelift IR generated. For example wasm calls are able to have a
"purely internal" ABI which Wasmtime's Rust code doesn't see at all, and
the Rust code only interacts with the native ABI. The native ABI is
redefined to be what the previous Wasmtime ABIs were, which is to return
the first of a 2+ value return through a register (native return value)
and everything else through a return pointer.
@alexcrichton alexcrichton requested review from a team as code owners June 27, 2023 17:03
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team June 27, 2023 17:03
@alexcrichton
Copy link
Member Author

alexcrichton commented Jun 27, 2023

cc @uweigand if you're up for it I could use some help on the s390x-side of things. I believe that the Wasmtime ABI was load-bearing in a way not related to multi-value on the s390x backend to handle lane order of vector types, meaning that I think as-is this can't land since it'll fail tests on s390x. I was wondering if you had thoughts or ideas about how to go about fixing this? In my mind the fix would look something along the lines of:

  • Somehow get all wasm funtions to think they're using little-endian lane ordering. Previously this was done with the Wasmtime* family of calling conventions but I'd ideally like to remove this Wasmtime "brand" from Cranelift to avoid all backends having to deal with it.
  • Converting between big and little-endian lane orders in the various trampolines as necessary. This may not actually be required since v128 is never passed in registers via TypedFunc (haven't gotten around to implementing that in Wasmtime), so this point may already be "solved". In the future though I think it'd be fine to "just" generate more code in trampolines.

So I guess the question boils down to: should an ABI be added for s390x to specify that the lane order of vectors is little-endian? Or are there other options you can think of to solve this?

@fitzgen
Copy link
Member

fitzgen commented Jun 27, 2023

I think this will be easier once we switch all internal Wasm functions to using the tail calling convention, and then the tail calling convention can specify a little-endian lane ordering.

@alexcrichton
Copy link
Member Author

Yeah the more I think about this the more I realize it's probably best to leave things as-is and tied to the calling convention for now. I think it'd be good nonetheless to get stuff in ahead of time before tail if possible so I've left WasmtimeSystemV for now for s390x but left all the other changes so multi-return is not different in the calling convention and instead multi-return is handled differently in the native ABI.

@alexcrichton
Copy link
Member Author

Hurray looks like tests are green on s390x! I think this is good to go and we can tackle how to avoid having a specific ABI for s390x, if at all, in the future.

// On S390x we need a Wasmtime calling convention to ensure
// we're using little-endian vector lane order.
wasmtime_call_conv(isa)
CallConv::AppleAarch64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always need something special here? Because I'd like this function to unconditionally use CallConv::Tail soon, but I don't understand the details of this apple aarch64 stuff.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm so I'm not actually entirely sure what's going on here. This comment was added in #4195 with relation to pointer-authentication support on AArch64 I believe, but I'm not sure what ended up leading to the apple-aarch64 change here. I can confirm locally that if I change this to Fast that everything passes locally.

I'll file this as a follow-up to have it as a separate change.

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen isle Related to the ISLE domain-specific language labels Jun 27, 2023
@github-actions
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen

This issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64", "cranelift:area:machinst", "cranelift:area:x64", "isle"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@alexcrichton alexcrichton added this pull request to the merge queue Jun 28, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 28, 2023
@alexcrichton alexcrichton added this pull request to the merge queue Jun 28, 2023
@github-actions github-actions bot added the winch Winch issues or pull requests label Jun 28, 2023
@github-actions
Copy link

Subscribe to Label Action

cc @saulecabrera

This issue or pull request has been labeled: "winch"

Thus the following users have been cc'd because of the following labels:

  • saulecabrera: winch

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@alexcrichton alexcrichton removed this pull request from the merge queue due to a manual request Jun 28, 2023
@alexcrichton alexcrichton added this pull request to the merge queue Jun 28, 2023
Merged via the queue into bytecodealliance:main with commit 39c96c7 Jun 28, 2023
25 checks passed
@alexcrichton alexcrichton deleted the remove-wasmtime-abi branch June 28, 2023 19:33
salewski pushed a commit to salewski/wasmtime that referenced this pull request Jun 30, 2023
* Remove Wasmtime ABIs from Cranelift

This commit removes the `Wasmtime*` family of ABIs from Cranelift. These
were originally added to support multi-value in Wasmtime via the
`TypedFunc` API, but they should now no longer be necessary. In general
this is a higher-level Wasmtime concern than something all backends of
Cranelift should have to deal with.

Today with recent refactorings it's possible to remove the reliance on
ABI details for multi-value and instead codify it directly into the
Cranelift IR generated. For example wasm calls are able to have a
"purely internal" ABI which Wasmtime's Rust code doesn't see at all, and
the Rust code only interacts with the native ABI. The native ABI is
redefined to be what the previous Wasmtime ABIs were, which is to return
the first of a 2+ value return through a register (native return value)
and everything else through a return pointer.

* Remove some wasmtime_system_v usage in tests

* Add back WasmtimeSystemV for s390x

* Fix some docs and references in winch
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Jun 30, 2023
This resolves two issues from recent changes in bytecodealliance#6649:

* First the s390x calling convention for wasm functions is changed back
  to `WasmtimeSystemV` from `Fast`. This was an accidental omission from
  bytecodealliance#6649 where the conclusion was that s390x will continue using a
  calling convention with little-endian lane order for lane arguments.
  The only calling convention that supports this today is
  `WasmtimeSystemV`, although the `Tail` calling convention will likely
  use it in the future as well.

* Second the apple-aarch64 platform now uses the `Fast` calling
  convention instead of `AppleAarch64` calling convention. That
  convention was specified in bytecodealliance#4195 but local testing shows that is not
  necessary in the sense that tests all pass with the `Fast` calling
  convention. This means that the prior comment why the `AppleAarch64`
  calling convention is required is no longer accurate and in the
  absence of a reason not to I went ahead and switched it to `Fast`.

In the near future all wasm functions will unconditionally use the
`Tail` calling convention and at that time the lane order can be
specified on s390x to be little-endian to satisfy all the constraints
here. Additionally any unwinding directives, if necessary for aarch64,
can be specified as needed.
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Jul 5, 2023
This resolves two issues from recent changes in bytecodealliance#6649:

* First the s390x calling convention for wasm functions is changed back
  to `WasmtimeSystemV` from `Fast`. This was an accidental omission from
  bytecodealliance#6649 where the conclusion was that s390x will continue using a
  calling convention with little-endian lane order for lane arguments.
  The only calling convention that supports this today is
  `WasmtimeSystemV`, although the `Tail` calling convention will likely
  use it in the future as well.

* Second the apple-aarch64 platform now uses the `Fast` calling
  convention instead of `AppleAarch64` calling convention. That
  convention was specified in bytecodealliance#4195 but local testing shows that is not
  necessary in the sense that tests all pass with the `Fast` calling
  convention. This means that the prior comment why the `AppleAarch64`
  calling convention is required is no longer accurate and in the
  absence of a reason not to I went ahead and switched it to `Fast`.

In the near future all wasm functions will unconditionally use the
`Tail` calling convention and at that time the lane order can be
specified on s390x to be little-endian to satisfy all the constraints
here. Additionally any unwinding directives, if necessary for aarch64,
can be specified as needed.
github-merge-queue bot pushed a commit that referenced this pull request Jul 6, 2023
* Update calling conventions for wasm functions slightly

This resolves two issues from recent changes in #6649:

* First the s390x calling convention for wasm functions is changed back
  to `WasmtimeSystemV` from `Fast`. This was an accidental omission from
  #6649 where the conclusion was that s390x will continue using a
  calling convention with little-endian lane order for lane arguments.
  The only calling convention that supports this today is
  `WasmtimeSystemV`, although the `Tail` calling convention will likely
  use it in the future as well.

* Second the apple-aarch64 platform now uses the `Fast` calling
  convention instead of `AppleAarch64` calling convention. That
  convention was specified in #4195 but local testing shows that is not
  necessary in the sense that tests all pass with the `Fast` calling
  convention. This means that the prior comment why the `AppleAarch64`
  calling convention is required is no longer accurate and in the
  absence of a reason not to I went ahead and switched it to `Fast`.

In the near future all wasm functions will unconditionally use the
`Tail` calling convention and at that time the lane order can be
specified on s390x to be little-endian to satisfy all the constraints
here. Additionally any unwinding directives, if necessary for aarch64,
can be specified as needed.

* Fix compile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language winch Winch issues or pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants