Cranelift: fix use of pinned reg with SysV calling convention. (#4176)

Previously, the pinned register (enabled by the `enable_pinned_reg`
Cranelift setting and used via the `get_pinned_reg` and `set_pinned_reg`
CLIF ops) was only used when Cranelift was embedded in SpiderMonkey, in
order to support a pinned heap register. SpiderMonkey has its own
calling convention in Cranelift (named after the integration layer,
"Baldrdash").

However, the feature is more general, and should be usable with the
default system calling convention too, e.g. SysV or Windows Fastcall.

This PR fixes the ABI code to properly treat the pinned register as a
globally allocated register -- and hence an implicit input and output to
every function, not saved/restored in the prologue/epilogue -- for SysV
on x86-64 and aarch64, and Fastcall on x86-64.

Fixes #4170.
This commit is contained in:
Chris Fallin
2022-05-23 09:18:51 -07:00
committed by GitHub
parent 2d8ff7a9a9
commit 32622b3e6f
6 changed files with 92 additions and 15 deletions

View File

@@ -428,6 +428,7 @@ pub trait ABIMachineSpec {
/// contains the registers in a sorted order.
fn get_clobbered_callee_saves(
call_conv: isa::CallConv,
flags: &settings::Flags,
regs: &[Writable<RealReg>],
) -> Vec<Writable<RealReg>>;
@@ -1224,7 +1225,8 @@ impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
}
let mask = M::stack_align(self.call_conv) - 1;
let total_stacksize = (total_stacksize + mask) & !mask; // 16-align the stack.
let clobbered_callee_saves = M::get_clobbered_callee_saves(self.call_conv, &self.clobbered);
let clobbered_callee_saves =
M::get_clobbered_callee_saves(self.call_conv, &self.flags, &self.clobbered);
let mut insts = smallvec![];
if !self.call_conv.extends_baldrdash() {