cranelift_codegen/isa/
winch.rs

1use crate::machinst::{ABIArg, ABIArgSlot, ArgsAccumulator};
2
3// Winch writes the first result to the highest offset, so we need to iterate through the
4// args and adjust the offsets down.
5pub(super) fn reverse_stack(mut args: ArgsAccumulator, next_stack: u32, uses_extension: bool) {
6    for arg in args.args_mut() {
7        if let ABIArg::Slots { slots, .. } = arg {
8            for slot in slots.iter_mut() {
9                if let ABIArgSlot::Stack { offset, ty, .. } = slot {
10                    let size = if uses_extension {
11                        i64::from(std::cmp::max(ty.bytes(), 8))
12                    } else {
13                        i64::from(ty.bytes())
14                    };
15                    *offset = i64::from(next_stack) - *offset - size;
16                }
17            }
18        } else {
19            unreachable!("Winch cannot handle {arg:?}");
20        }
21    }
22}