Skip to content

Commit b760c22

Browse files
committed
Don't pass the tail-call scratch through the register allocator
Regalloc3 doesn't support def operands on return instructions and this doesn't interact with register allocation anyways, so hard-code the use of r11 directly in `emit_return_call_common_sequence`.
1 parent ab76f64 commit b760c22

File tree

3 files changed

+7
-21
lines changed

3 files changed

+7
-21
lines changed

cranelift/codegen/src/isa/x64/inst/emit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,9 @@ fn emit_return_call_common_sequence<T>(
19841984
but the current implementation relies on them being present"
19851985
);
19861986

1987-
let tmp = call_info.tmp.to_writable_reg();
1987+
// Hard-coded register which doesn't conflict with function arguments or
1988+
// callee-saved registers.
1989+
let tmp = Writable::from_reg(regs::r11());
19881990

19891991
for inst in
19901992
X64ABIMachineSpec::gen_clobber_restore(CallConv::Tail, &info.flags, state.frame_layout())

cranelift/codegen/src/isa/x64/inst/mod.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ pub struct ReturnCallInfo<T> {
5050

5151
/// The in-register arguments and their constraints.
5252
pub uses: CallArgList,
53-
54-
/// A temporary for use when moving the return address.
55-
pub tmp: WritableGpr,
5653
}
5754

5855
#[test]
@@ -676,11 +673,9 @@ impl PrettyPrint for Inst {
676673
let ReturnCallInfo {
677674
uses,
678675
new_stack_arg_size,
679-
tmp,
680676
dest,
681677
} = &**info;
682-
let tmp = pretty_print_reg(tmp.to_reg().to_reg(), 8);
683-
let mut s = format!("return_call_known {dest:?} ({new_stack_arg_size}) tmp={tmp}");
678+
let mut s = format!("return_call_known {dest:?} ({new_stack_arg_size})");
684679
for ret in uses {
685680
let preg = regs::show_reg(ret.preg);
686681
let vreg = pretty_print_reg(ret.vreg, 8);
@@ -693,13 +688,10 @@ impl PrettyPrint for Inst {
693688
let ReturnCallInfo {
694689
uses,
695690
new_stack_arg_size,
696-
tmp,
697691
dest,
698692
} = &**info;
699693
let callee = pretty_print_reg(*dest, 8);
700-
let tmp = pretty_print_reg(tmp.to_reg().to_reg(), 8);
701-
let mut s =
702-
format!("return_call_unknown {callee} ({new_stack_arg_size}) tmp={tmp}");
694+
let mut s = format!("return_call_unknown {callee} ({new_stack_arg_size})");
703695
for ret in uses {
704696
let preg = regs::show_reg(ret.preg);
705697
let vreg = pretty_print_reg(ret.vreg, 8);
@@ -1133,10 +1125,7 @@ fn x64_get_operands(inst: &mut Inst, collector: &mut impl OperandVisitor) {
11331125
}
11341126

11351127
Inst::ReturnCallKnown { info } => {
1136-
let ReturnCallInfo {
1137-
dest, uses, tmp, ..
1138-
} = &mut **info;
1139-
collector.reg_fixed_def(tmp, regs::r11());
1128+
let ReturnCallInfo { dest, uses, .. } = &mut **info;
11401129
// Same as in the `Inst::CallKnown` branch.
11411130
debug_assert_ne!(*dest, ExternalName::LibCall(LibCall::Probestack));
11421131
for CallArgPair { vreg, preg } in uses {
@@ -1145,9 +1134,7 @@ fn x64_get_operands(inst: &mut Inst, collector: &mut impl OperandVisitor) {
11451134
}
11461135

11471136
Inst::ReturnCallUnknown { info } => {
1148-
let ReturnCallInfo {
1149-
dest, uses, tmp, ..
1150-
} = &mut **info;
1137+
let ReturnCallInfo { dest, uses, .. } = &mut **info;
11511138

11521139
// TODO(https://github.com/bytecodealliance/regalloc2/issues/145):
11531140
// This shouldn't be a fixed register constraint, but it's not clear how to
@@ -1156,7 +1143,6 @@ fn x64_get_operands(inst: &mut Inst, collector: &mut impl OperandVisitor) {
11561143
// safe to use.
11571144
collector.reg_fixed_use(dest, regs::r10());
11581145

1159-
collector.reg_fixed_def(tmp, regs::r11());
11601146
for CallArgPair { vreg, preg } in uses {
11611147
collector.reg_fixed_use(vreg, *preg);
11621148
}

cranelift/codegen/src/isa/x64/lower/isle.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ impl Context for IsleContext<'_, '_, MInst, X64Backend> {
131131
Box::new(ReturnCallInfo {
132132
dest,
133133
uses,
134-
tmp: self.lower_ctx.temp_writable_gpr(),
135134
new_stack_arg_size,
136135
})
137136
}
@@ -150,7 +149,6 @@ impl Context for IsleContext<'_, '_, MInst, X64Backend> {
150149
Box::new(ReturnCallInfo {
151150
dest,
152151
uses,
153-
tmp: self.lower_ctx.temp_writable_gpr(),
154152
new_stack_arg_size,
155153
})
156154
}

0 commit comments

Comments
 (0)