winch: Multi-Value Part 1 #7535
Merged
saulecabrera merged 4 commits intoNov 14, 2023
Merged
Conversation
Subscribe to Label ActionDetailsThis issue or pull request has been labeled: "winch"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
This commit prepares Winch to support WebAssembly Multi-Value. The most notorious piece of this change is the introduction of the `ABIParams` and `ABIResults` structs which are type wrappers around the concept of an `ABIOperand`, which is the underlying main representation of a param or result. This change also consolidates how the size for WebAssembly types is derived by introducing `ABI::sizeof`, as well as introducing `ABI::stack_slot_size` to concretely indicate the stack slot size in bytes for stack params, which is ABI dependent.
This change adds the necessary changes at the ABI level in order to
handle multi-value.
The most notable modifications in this change are:
* Modifying Winch's default ABI to reverse the order of results,
ensuring that results that go in the stack should always come first;
this makes it easier to respect the following two stack invariants:
* Spilled memory values always precede register values
* Spilled values are stored from oldest to newest, matching their
respective locations on the machine stack.
* Modify all calling conventions supported by Winch so that only one result, the first one is stored in
registers. This differs from their vanilla counterparts in that these
ABIs can handle multiple results in registers. Given that Winch is not
a generic code generator, keeping the ABI close to what Wasmtime
expects makes it easier to pass multiple results at trampolines.
93ea3cd to
bd0b571
Compare
This commit adds more tests for multi-value and improves documentation. prtest:full
bd0b571 to
fb63967
Compare
fitzgen
approved these changes
Nov 14, 2023
Member
fitzgen
left a comment
There was a problem hiding this comment.
LGTM but I'm still a little sketched out by those disassembly changes where I feel like I'm only seeing one half of a change or something like that. Maybe you can explain what is going on?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change adds initial support for the Multi-Value proposal to Winch, focusing on function calls, support for Multi-Value for blocks will be added on top of this change in a different pull request.
This change is divided into two main parts:
Infrastructure changes needed to support Multi-Value
Some notable changes were needed in order to support this proposal, namely:
ABIOperandsand rewriting theABIParamsandABIResultsin terms ofABIOperands.pushvssub + mov). My intention is to profile, and try to improve this strategy if needed, later on.Handling Multi-Value returns for function calls
The approach for handling multiple results for function calls involves:
Adding an implicit extra parameter to the
ABIParamsdefinition, when a function returns multiple values; from the callee's perspective, this parameter is treated like any other "special" parameter (e.gVMContext), to which, we give it a well knowLocalSlotfor later referencing when storing the return values. From the caller's perspective, extra stack space is created before the call, and the address to that space is passed in to the callee, via the return pointer parameter and once the function returns, the values in the created space are captured as values in the value stack.