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:
@@ -936,7 +936,8 @@ impl ABIMachineSpec for AArch64MachineDeps {
|
||||
_outgoing_args_size: u32,
|
||||
) -> SmallVec<[Inst; 16]> {
|
||||
let mut insts = SmallVec::new();
|
||||
let (clobbered_int, clobbered_vec) = get_regs_restored_in_epilogue(call_conv, clobbers);
|
||||
let (clobbered_int, clobbered_vec) =
|
||||
get_regs_restored_in_epilogue(call_conv, flags, clobbers);
|
||||
|
||||
// Free the fixed frame if necessary.
|
||||
if fixed_frame_storage_size > 0 {
|
||||
@@ -1189,12 +1190,13 @@ impl ABIMachineSpec for AArch64MachineDeps {
|
||||
|
||||
fn get_clobbered_callee_saves(
|
||||
call_conv: isa::CallConv,
|
||||
flags: &settings::Flags,
|
||||
regs: &[Writable<RealReg>],
|
||||
) -> Vec<Writable<RealReg>> {
|
||||
let mut regs: Vec<Writable<RealReg>> = regs
|
||||
.iter()
|
||||
.cloned()
|
||||
.filter(|r| is_reg_saved_in_prologue(call_conv, r.to_reg()))
|
||||
.filter(|r| is_reg_saved_in_prologue(call_conv, flags.enable_pinned_reg(), r.to_reg()))
|
||||
.collect();
|
||||
|
||||
// Sort registers for deterministic code output. We can do an unstable
|
||||
@@ -1229,7 +1231,7 @@ fn legal_type_for_machine(ty: Type) -> bool {
|
||||
|
||||
/// Is the given register saved in the prologue if clobbered, i.e., is it a
|
||||
/// callee-save?
|
||||
fn is_reg_saved_in_prologue(call_conv: isa::CallConv, r: RealReg) -> bool {
|
||||
fn is_reg_saved_in_prologue(call_conv: isa::CallConv, enable_pinned_reg: bool, r: RealReg) -> bool {
|
||||
if call_conv.extends_baldrdash() {
|
||||
match r.class() {
|
||||
RegClass::Int => {
|
||||
@@ -1246,7 +1248,14 @@ fn is_reg_saved_in_prologue(call_conv: isa::CallConv, r: RealReg) -> bool {
|
||||
match r.class() {
|
||||
RegClass::Int => {
|
||||
// x19 - x28 inclusive are callee-saves.
|
||||
r.hw_enc() >= 19 && r.hw_enc() <= 28
|
||||
// However, x21 is the pinned reg if `enable_pinned_reg`
|
||||
// is set, and is implicitly globally-allocated, hence not
|
||||
// callee-saved in prologues.
|
||||
if enable_pinned_reg && r.hw_enc() == PINNED_REG {
|
||||
false
|
||||
} else {
|
||||
r.hw_enc() >= 19 && r.hw_enc() <= 28
|
||||
}
|
||||
}
|
||||
RegClass::Float => {
|
||||
// v8 - v15 inclusive are callee-saves.
|
||||
@@ -1260,12 +1269,13 @@ fn is_reg_saved_in_prologue(call_conv: isa::CallConv, r: RealReg) -> bool {
|
||||
/// written by the function's body.
|
||||
fn get_regs_restored_in_epilogue(
|
||||
call_conv: isa::CallConv,
|
||||
flags: &settings::Flags,
|
||||
regs: &[Writable<RealReg>],
|
||||
) -> (Vec<Writable<RealReg>>, Vec<Writable<RealReg>>) {
|
||||
let mut int_saves = vec![];
|
||||
let mut vec_saves = vec![];
|
||||
for ® in regs {
|
||||
if is_reg_saved_in_prologue(call_conv, reg.to_reg()) {
|
||||
if is_reg_saved_in_prologue(call_conv, flags.enable_pinned_reg(), reg.to_reg()) {
|
||||
match reg.to_reg().class() {
|
||||
RegClass::Int => int_saves.push(reg),
|
||||
RegClass::Float => vec_saves.push(reg),
|
||||
|
||||
Reference in New Issue
Block a user