Add back support for accumulating outgoing arguments

The unwind rework (commit 2d5db92a) removed support for the
feature to allow a target to allocate the space for outgoing
function arguments right in the prologue (originally added
via commit 80c2d70d).   This patch adds it back.
This commit is contained in:
Ulrich Weigand
2021-04-14 13:51:16 +02:00
parent 67cc42d4c3
commit 336c6369b4
5 changed files with 37 additions and 0 deletions

View File

@@ -587,6 +587,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
flags: &settings::Flags, flags: &settings::Flags,
clobbers: &Set<Writable<RealReg>>, clobbers: &Set<Writable<RealReg>>,
fixed_frame_storage_size: u32, fixed_frame_storage_size: u32,
_outgoing_args_size: u32,
) -> (u64, SmallVec<[Inst; 16]>) { ) -> (u64, SmallVec<[Inst; 16]>) {
let mut insts = SmallVec::new(); let mut insts = SmallVec::new();
let (clobbered_int, clobbered_vec) = get_regs_saved_in_prologue(call_conv, clobbers); let (clobbered_int, clobbered_vec) = get_regs_saved_in_prologue(call_conv, clobbers);
@@ -691,6 +692,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
flags: &settings::Flags, flags: &settings::Flags,
clobbers: &Set<Writable<RealReg>>, clobbers: &Set<Writable<RealReg>>,
fixed_frame_storage_size: u32, fixed_frame_storage_size: u32,
_outgoing_args_size: u32,
) -> SmallVec<[Inst; 16]> { ) -> SmallVec<[Inst; 16]> {
let mut insts = SmallVec::new(); let mut insts = SmallVec::new();
let (clobbered_int, clobbered_vec) = get_regs_saved_in_prologue(call_conv, clobbers); let (clobbered_int, clobbered_vec) = get_regs_saved_in_prologue(call_conv, clobbers);

View File

@@ -319,6 +319,7 @@ impl ABIMachineSpec for Arm32MachineDeps {
_flags: &settings::Flags, _flags: &settings::Flags,
clobbers: &Set<Writable<RealReg>>, clobbers: &Set<Writable<RealReg>>,
fixed_frame_storage_size: u32, fixed_frame_storage_size: u32,
_outgoing_args_size: u32,
) -> (u64, SmallVec<[Inst; 16]>) { ) -> (u64, SmallVec<[Inst; 16]>) {
let mut insts = SmallVec::new(); let mut insts = SmallVec::new();
if fixed_frame_storage_size > 0 { if fixed_frame_storage_size > 0 {
@@ -348,6 +349,7 @@ impl ABIMachineSpec for Arm32MachineDeps {
_flags: &settings::Flags, _flags: &settings::Flags,
clobbers: &Set<Writable<RealReg>>, clobbers: &Set<Writable<RealReg>>,
_fixed_frame_storage_size: u32, _fixed_frame_storage_size: u32,
_outgoing_args_size: u32,
) -> SmallVec<[Inst; 16]> { ) -> SmallVec<[Inst; 16]> {
let mut insts = SmallVec::new(); let mut insts = SmallVec::new();
let clobbered_vec = get_callee_saves(clobbers); let clobbered_vec = get_callee_saves(clobbers);

View File

@@ -500,6 +500,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
flags: &settings::Flags, flags: &settings::Flags,
clobbers: &Set<Writable<RealReg>>, clobbers: &Set<Writable<RealReg>>,
fixed_frame_storage_size: u32, fixed_frame_storage_size: u32,
_outgoing_args_size: u32,
) -> (u64, SmallVec<[Self::I; 16]>) { ) -> (u64, SmallVec<[Self::I; 16]>) {
let mut insts = SmallVec::new(); let mut insts = SmallVec::new();
// Find all clobbered registers that are callee-save. // Find all clobbered registers that are callee-save.
@@ -574,6 +575,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
flags: &settings::Flags, flags: &settings::Flags,
clobbers: &Set<Writable<RealReg>>, clobbers: &Set<Writable<RealReg>>,
fixed_frame_storage_size: u32, fixed_frame_storage_size: u32,
_outgoing_args_size: u32,
) -> SmallVec<[Self::I; 16]> { ) -> SmallVec<[Self::I; 16]> {
let mut insts = SmallVec::new(); let mut insts = SmallVec::new();

View File

@@ -30,6 +30,12 @@ pub trait ABICallee {
/// Access the (possibly legalized) signature. /// Access the (possibly legalized) signature.
fn signature(&self) -> &Signature; fn signature(&self) -> &Signature;
/// Accumulate outgoing arguments. This ensures that at least SIZE bytes
/// are allocated in the prologue to be available for use in function calls
/// to hold arguments and/or return values. If this function is called
/// multiple times, the maximum of all SIZE values will be available.
fn accumulate_outgoing_args_size(&mut self, size: u32);
/// Get the settings controlling this function's compilation. /// Get the settings controlling this function's compilation.
fn flags(&self) -> &settings::Flags; fn flags(&self) -> &settings::Flags;
@@ -242,6 +248,13 @@ pub trait ABICaller {
/// Emit code to post-adjust the satck, after call return and return-value copies. /// Emit code to post-adjust the satck, after call return and return-value copies.
fn emit_stack_post_adjust<C: LowerCtx<I = Self::I>>(&self, ctx: &mut C); fn emit_stack_post_adjust<C: LowerCtx<I = Self::I>>(&self, ctx: &mut C);
/// Accumulate outgoing arguments. This ensures that the caller (as
/// identified via the CTX argument) allocates enough space in the
/// prologue to hold all arguments and return values for this call.
/// There is no code emitted at the call site, everything is done
/// in the caller's function prologue.
fn accumulate_outgoing_args_size<C: LowerCtx<I = Self::I>>(&self, ctx: &mut C);
/// Emit the call itself. /// Emit the call itself.
/// ///
/// The returned instruction should have proper use- and def-sets according /// The returned instruction should have proper use- and def-sets according

View File

@@ -444,6 +444,7 @@ pub trait ABIMachineSpec {
flags: &settings::Flags, flags: &settings::Flags,
clobbers: &Set<Writable<RealReg>>, clobbers: &Set<Writable<RealReg>>,
fixed_frame_storage_size: u32, fixed_frame_storage_size: u32,
outgoing_args_size: u32,
) -> (u64, SmallVec<[Self::I; 16]>); ) -> (u64, SmallVec<[Self::I; 16]>);
/// Generate a clobber-restore sequence. This sequence should perform the /// Generate a clobber-restore sequence. This sequence should perform the
@@ -455,6 +456,7 @@ pub trait ABIMachineSpec {
flags: &settings::Flags, flags: &settings::Flags,
clobbers: &Set<Writable<RealReg>>, clobbers: &Set<Writable<RealReg>>,
fixed_frame_storage_size: u32, fixed_frame_storage_size: u32,
outgoing_args_size: u32,
) -> SmallVec<[Self::I; 16]>; ) -> SmallVec<[Self::I; 16]>;
/// Generate a call instruction/sequence. This method is provided one /// Generate a call instruction/sequence. This method is provided one
@@ -576,6 +578,8 @@ pub struct ABICalleeImpl<M: ABIMachineSpec> {
stackslots: PrimaryMap<StackSlot, u32>, stackslots: PrimaryMap<StackSlot, u32>,
/// Total stack size of all stackslots. /// Total stack size of all stackslots.
stackslots_size: u32, stackslots_size: u32,
/// Stack size to be reserved for outgoing arguments.
outgoing_args_size: u32,
/// Clobbered registers, from regalloc. /// Clobbered registers, from regalloc.
clobbered: Set<Writable<RealReg>>, clobbered: Set<Writable<RealReg>>,
/// Total number of spillslots, from regalloc. /// Total number of spillslots, from regalloc.
@@ -691,6 +695,7 @@ impl<M: ABIMachineSpec> ABICalleeImpl<M> {
sig, sig,
stackslots, stackslots,
stackslots_size: stack_offset, stackslots_size: stack_offset,
outgoing_args_size: 0,
clobbered: Set::empty(), clobbered: Set::empty(),
spillslots: None, spillslots: None,
fixed_frame_storage_size: 0, fixed_frame_storage_size: 0,
@@ -917,6 +922,12 @@ impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
} }
} }
fn accumulate_outgoing_args_size(&mut self, size: u32) {
if size > self.outgoing_args_size {
self.outgoing_args_size = size;
}
}
fn flags(&self) -> &settings::Flags { fn flags(&self) -> &settings::Flags {
&self.flags &self.flags
} }
@@ -1290,6 +1301,7 @@ impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
&self.flags, &self.flags,
&self.clobbered, &self.clobbered,
self.fixed_frame_storage_size, self.fixed_frame_storage_size,
self.outgoing_args_size,
); );
insts.extend(clobber_insts); insts.extend(clobber_insts);
@@ -1317,6 +1329,7 @@ impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
&self.flags, &self.flags,
&self.clobbered, &self.clobbered,
self.fixed_frame_storage_size, self.fixed_frame_storage_size,
self.outgoing_args_size,
)); ));
// N.B.: we do *not* emit a nominal SP adjustment here, because (i) there will be no // N.B.: we do *not* emit a nominal SP adjustment here, because (i) there will be no
@@ -1519,6 +1532,11 @@ impl<M: ABIMachineSpec> ABICaller for ABICallerImpl<M> {
} }
} }
fn accumulate_outgoing_args_size<C: LowerCtx<I = Self::I>>(&self, ctx: &mut C) {
let off = self.sig.stack_arg_space + self.sig.stack_ret_space;
ctx.abi().accumulate_outgoing_args_size(off as u32);
}
fn emit_stack_pre_adjust<C: LowerCtx<I = Self::I>>(&self, ctx: &mut C) { fn emit_stack_pre_adjust<C: LowerCtx<I = Self::I>>(&self, ctx: &mut C) {
let off = self.sig.stack_arg_space + self.sig.stack_ret_space; let off = self.sig.stack_arg_space + self.sig.stack_ret_space;
adjust_stack_and_nominal_sp::<M, C>(ctx, off as i32, /* is_sub = */ true) adjust_stack_and_nominal_sp::<M, C>(ctx, off as i32, /* is_sub = */ true)