Skip to content

Commit

Permalink
cranelift/s390x: Use PRegs consistently
Browse files Browse the repository at this point in the history
When OperandCollector's reg_use/reg_late_use/reg_def/reg_early_def
methods are handed a Reg that refers to a physical ("real") register,
they all delegate to reg_fixed_nonallocatable, ignoring the constraint
kinds and positions.

In several cases, the s390x backend was calling those methods with the
result of the `gpr` or `writable_gpr` functions, which return physical
registers. In these cases we can be more explicit that this is a
non-allocatable register.
  • Loading branch information
jameysharp committed Apr 23, 2024
1 parent 3befbe5 commit bbc8210
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
18 changes: 9 additions & 9 deletions cranelift/codegen/src/isa/s390x/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ fn memarg_operands<F: Fn(VReg) -> VReg>(memarg: &MemArg, collector: &mut Operand
}
// mem_finalize might require %r1 to hold (part of) the address.
// Conservatively assume this will always be necessary here.
collector.reg_early_def(writable_gpr(1));
collector.reg_fixed_nonallocatable(gpr_preg(1));
}

fn s390x_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandCollector<'_, F>) {
Expand Down Expand Up @@ -604,7 +604,7 @@ fn s390x_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandC
let first_regnum = rt.to_reg().to_real_reg().unwrap().hw_enc();
let last_regnum = rt2.to_reg().to_real_reg().unwrap().hw_enc();
for regnum in first_regnum..last_regnum + 1 {
collector.reg_def(writable_gpr(regnum));
collector.reg_fixed_nonallocatable(gpr_preg(regnum));
}
}
&Inst::StoreMultiple64 {
Expand All @@ -614,15 +614,15 @@ fn s390x_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandC
let first_regnum = rt.to_real_reg().unwrap().hw_enc();
let last_regnum = rt2.to_real_reg().unwrap().hw_enc();
for regnum in first_regnum..last_regnum + 1 {
collector.reg_use(gpr(regnum));
collector.reg_fixed_nonallocatable(gpr_preg(regnum));
}
}
&Inst::Mov64 { rd, rm } => {
collector.reg_def(rd);
collector.reg_use(rm);
}
&Inst::MovPReg { rd, rm } => {
debug_assert!([regs::gpr(0), regs::gpr(14), regs::gpr(15)].contains(&rm.into()));
&Inst::MovPReg { rd, ref rm } => {
debug_assert!([gpr_preg(0), gpr_preg(14), gpr_preg(15)].contains(rm));
debug_assert!(rd.to_reg().is_virtual());
collector.reg_def(rd);
}
Expand Down Expand Up @@ -689,7 +689,7 @@ fn s390x_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandC
}
&Inst::LoadFpuConst32 { rd, .. } | &Inst::LoadFpuConst64 { rd, .. } => {
collector.reg_def(rd);
collector.reg_def(writable_gpr(1));
collector.reg_fixed_nonallocatable(gpr_preg(1));
}
&Inst::FpuRound { rd, rn, .. } => {
collector.reg_def(rd);
Expand Down Expand Up @@ -833,7 +833,7 @@ fn s390x_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandC
}
&Inst::VecLoadConst { rd, .. } | &Inst::VecLoadConstReplicate { rd, .. } => {
collector.reg_def(rd);
collector.reg_def(writable_gpr(1));
collector.reg_fixed_nonallocatable(gpr_preg(1));
}
&Inst::VecImmByteMask { rd, .. } => {
collector.reg_def(rd);
Expand Down Expand Up @@ -966,11 +966,11 @@ fn s390x_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandC
&Inst::TrapIf { .. } => {}
&Inst::JTSequence { ridx, .. } => {
collector.reg_use(ridx);
collector.reg_early_def(writable_gpr(1));
collector.reg_fixed_nonallocatable(gpr_preg(1));
}
&Inst::LoadSymbolReloc { rd, .. } => {
collector.reg_def(rd);
collector.reg_def(writable_gpr(1));
collector.reg_fixed_nonallocatable(gpr_preg(1));
}
&Inst::LoadAddr { rd, ref mem } => {
collector.reg_def(rd);
Expand Down
7 changes: 2 additions & 5 deletions cranelift/codegen/src/isa/s390x/inst/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use alloc::string::String;
use regalloc2::PReg;
use regalloc2::VReg;

use crate::isa::s390x::inst::{RegPair, WritableRegPair};
use crate::machinst::*;
Expand All @@ -12,8 +11,7 @@ use crate::machinst::*;

/// Get a reference to a GPR (integer register).
pub fn gpr(num: u8) -> Reg {
let preg = gpr_preg(num);
Reg::from(VReg::new(preg.index(), RegClass::Int))
Reg::from(gpr_preg(num))
}

pub(crate) const fn gpr_preg(num: u8) -> PReg {
Expand All @@ -28,8 +26,7 @@ pub fn writable_gpr(num: u8) -> Writable<Reg> {

/// Get a reference to a VR (vector register).
pub fn vr(num: u8) -> Reg {
let preg = vr_preg(num);
Reg::from(VReg::new(preg.index(), RegClass::Float))
Reg::from(vr_preg(num))
}

pub(crate) const fn vr_preg(num: u8) -> PReg {
Expand Down

0 comments on commit bbc8210

Please sign in to comment.