machinst ABI: Allow back-end to define stack alignment

The common gen_prologue code currently assumes that the stack
pointer has to be aligned to twice the word size.  While this
is true for many ABIs, it does not hold universally.

This patch adds a new callback stack_align that back-ends can
provide to define the specific stack alignment required by the
ABI on that platform.
This commit is contained in:
Ulrich Weigand
2020-11-02 13:07:49 +01:00
parent d1be8dcfc0
commit d02ae3940c
4 changed files with 19 additions and 1 deletions

View File

@@ -152,6 +152,11 @@ impl ABIMachineSpec for AArch64MachineDeps {
64 64
} }
/// Return required stack alignment in bytes.
fn stack_align(_call_conv: isa::CallConv) -> u32 {
16
}
fn compute_arg_locs( fn compute_arg_locs(
call_conv: isa::CallConv, call_conv: isa::CallConv,
params: &[ir::AbiParam], params: &[ir::AbiParam],

View File

@@ -45,6 +45,11 @@ impl ABIMachineSpec for Arm32MachineDeps {
32 32
} }
/// Return required stack alignment in bytes.
fn stack_align(_call_conv: isa::CallConv) -> u32 {
8
}
fn compute_arg_locs( fn compute_arg_locs(
_call_conv: isa::CallConv, _call_conv: isa::CallConv,
params: &[ir::AbiParam], params: &[ir::AbiParam],

View File

@@ -90,6 +90,11 @@ impl ABIMachineSpec for X64ABIMachineSpec {
64 64
} }
/// Return required stack alignment in bytes.
fn stack_align(_call_conv: isa::CallConv) -> u32 {
16
}
fn compute_arg_locs( fn compute_arg_locs(
call_conv: isa::CallConv, call_conv: isa::CallConv,
params: &[ir::AbiParam], params: &[ir::AbiParam],

View File

@@ -216,6 +216,9 @@ pub trait ABIMachineSpec {
} }
} }
/// Returns required stack alignment in bytes.
fn stack_align(call_conv: isa::CallConv) -> u32;
/// Process a list of parameters or return values and allocate them to registers /// Process a list of parameters or return values and allocate them to registers
/// and stack slots. /// and stack slots.
/// ///
@@ -936,7 +939,7 @@ impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
); );
total_stacksize += self.flags.baldrdash_prologue_words() as u32 * bytes; total_stacksize += self.flags.baldrdash_prologue_words() as u32 * bytes;
} }
let mask = 2 * bytes - 1; let mask = M::stack_align(self.call_conv) - 1;
let total_stacksize = (total_stacksize + mask) & !mask; // 16-align the stack. let total_stacksize = (total_stacksize + mask) & !mask; // 16-align the stack.
let mut fixed_frame_storage_size = 0; let mut fixed_frame_storage_size = 0;