Many multi-value returns (#1147)
* Add x86 encodings for `bint` converting to `i8` and `i16`
* Introduce tests for many multi-value returns
* Support arbitrary numbers of return values
This commit implements support for returning an arbitrary number of return
values from a function. During legalization we transform multi-value signatures
to take a struct return ("sret") return pointer, instead of returning its values
in registers. Callers allocate the sret space in their stack frame and pass a
pointer to it into the caller, and once the caller returns to them, they load
the return values back out of the sret stack slot. The callee's return
operations are legalized to store the return values through the given sret
pointer.
* Keep track of old, pre-legalized signatures
When legalizing a call or return for its new legalized signature, we may need to
look at the old signature in order to figure out how to legalize the call or
return.
* Add test for multi-value returns and `call_indirect`
* Encode bool -> int x86 instructions in a loop
* Rename `Signature::uses_sret` to `Signature::uses_struct_return_param`
* Rename `p` to `param`
* Add a clarifiying comment in `num_registers_required`
* Rename `num_registers_required` to `num_return_registers_required`
* Re-add newline
* Handle already-assigned parameters in `num_return_registers_required`
* Document what some debug assertions are checking for
* Make "illegalizing" closure's control flow simpler
* Add unit tests and comments for our rounding-up-to-the-next-multiple-of-a-power-of-2 function
* Use `append_isnt_arg` instead of doing the same thing manually
* Fix grammar in comment
* Add `Signature::uses_special_{param,return}` helper functions
* Inline the definition of `legalize_type_for_sret_load` for readability
* Move sret legalization debug assertions out into their own function
* Add `round_up_to_multiple_of_type_align` helper for readability
* Add a debug assertion that we aren't removing the wrong return value
* Rename `RetPtr` stack slots to `StructReturnSlot`
* Make `legalize_type_for_sret_store` more symmetrical to `legalized_type_for_sret`
* rustfmt
* Remove unnecessary loop labels
* Do not pre-assign offsets to struct return stack slots
Instead, let the existing frame layout algorithm decide where they should go.
* Expand "sret" into explicit "struct return" in doc comment
* typo: "than" -> "then" in comment
* Fold test's debug message into the assertion itself
This commit is contained in:
@@ -25,7 +25,7 @@ pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CodegenResu
|
||||
// stack layout from high to low addresses will be:
|
||||
//
|
||||
// 1. incoming arguments.
|
||||
// 2. spills + explicits.
|
||||
// 2. spills + explicits + struct returns.
|
||||
// 3. outgoing arguments.
|
||||
//
|
||||
// The incoming arguments can have both positive and negative offsets. A negative offset
|
||||
@@ -56,7 +56,8 @@ pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CodegenResu
|
||||
.ok_or(CodegenError::ImplLimitExceeded)?;
|
||||
outgoing_max = max(outgoing_max, offset);
|
||||
}
|
||||
StackSlotKind::SpillSlot
|
||||
StackSlotKind::StructReturnSlot
|
||||
| StackSlotKind::SpillSlot
|
||||
| StackSlotKind::ExplicitSlot
|
||||
| StackSlotKind::EmergencySlot => {
|
||||
// Determine the smallest alignment of any explicit or spill slot.
|
||||
@@ -65,9 +66,9 @@ pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CodegenResu
|
||||
}
|
||||
}
|
||||
|
||||
// Lay out spill slots and explicit slots below the incoming arguments.
|
||||
// The offset is negative, growing downwards.
|
||||
// Start with the smallest alignments for better packing.
|
||||
// Lay out spill slots, struct return slots, and explicit slots below the
|
||||
// incoming arguments. The offset is negative, growing downwards. Start with
|
||||
// the smallest alignments for better packing.
|
||||
let mut offset = incoming_min;
|
||||
debug_assert!(min_align.is_power_of_two());
|
||||
while min_align <= alignment {
|
||||
@@ -75,6 +76,7 @@ pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CodegenResu
|
||||
// Pick out explicit and spill slots with exact alignment `min_align`.
|
||||
match slot.kind {
|
||||
StackSlotKind::SpillSlot
|
||||
| StackSlotKind::StructReturnSlot
|
||||
| StackSlotKind::ExplicitSlot
|
||||
| StackSlotKind::EmergencySlot => {
|
||||
if slot.alignment(alignment) != min_align {
|
||||
|
||||
Reference in New Issue
Block a user