Switch Cranelift over to regalloc2. (#3989)

This PR switches Cranelift over to the new register allocator, regalloc2.

See [this document](https://gist.github.com/cfallin/08553421a91f150254fe878f67301801)
for a summary of the design changes. This switchover has implications for
core VCode/MachInst types and the lowering pass.

Overall, this change brings improvements to both compile time and speed of
generated code (runtime), as reported in #3942:

```
Benchmark       Compilation (wallclock)     Execution (wallclock)
blake3-scalar   25% faster                  28% faster
blake3-simd     no diff                     no diff
meshoptimizer   19% faster                  17% faster
pulldown-cmark  17% faster                  no diff
bz2             15% faster                  no diff
SpiderMonkey,   21% faster                  2% faster
  fib(30)
clang.wasm      42% faster                  N/A
```
This commit is contained in:
Chris Fallin
2022-04-14 10:28:21 -07:00
committed by GitHub
parent bfae6384aa
commit a0318f36f0
181 changed files with 16887 additions and 21587 deletions

View File

@@ -7,8 +7,7 @@ use crate::ir::condcodes::{FloatCC, IntCC};
use crate::ir::MemFlags;
use crate::isa::s390x::inst::*;
use crate::machinst::MachLabel;
use regalloc::{PrettyPrint, RealRegUniverse, Reg};
use crate::machinst::{PrettyPrint, Reg};
use std::string::String;
@@ -113,6 +112,40 @@ impl MemArg {
pub(crate) fn can_trap(&self) -> bool {
!self.get_flags().notrap()
}
/// Edit registers with allocations.
pub fn with_allocs(&self, allocs: &mut AllocationConsumer<'_>) -> Self {
match self {
&MemArg::BXD12 {
base,
index,
disp,
flags,
} => MemArg::BXD12 {
base: allocs.next(base),
index: allocs.next(index),
disp,
flags,
},
&MemArg::BXD20 {
base,
index,
disp,
flags,
} => MemArg::BXD20 {
base: allocs.next(base),
index: allocs.next(index),
disp,
flags,
},
&MemArg::RegOffset { reg, off, flags } => MemArg::RegOffset {
reg: allocs.next(reg),
off,
flags,
},
x => x.clone(),
}
}
}
//=============================================================================
@@ -183,49 +216,53 @@ impl Cond {
}
impl PrettyPrint for MemArg {
fn show_rru(&self, mb_rru: Option<&RealRegUniverse>) -> String {
fn pretty_print(&self, _: u8, allocs: &mut AllocationConsumer<'_>) -> String {
match self {
&MemArg::BXD12 {
base, index, disp, ..
} => {
let base = allocs.next(base);
let index = allocs.next(index);
if base != zero_reg() {
if index != zero_reg() {
format!(
"{}({},{})",
disp.show_rru(mb_rru),
index.show_rru(mb_rru),
base.show_rru(mb_rru)
disp.pretty_print_default(),
show_reg(index),
show_reg(base),
)
} else {
format!("{}({})", disp.show_rru(mb_rru), base.show_rru(mb_rru))
format!("{}({})", disp.pretty_print_default(), show_reg(base))
}
} else {
if index != zero_reg() {
format!("{}({},)", disp.show_rru(mb_rru), index.show_rru(mb_rru))
format!("{}({},)", disp.pretty_print_default(), show_reg(index))
} else {
format!("{}", disp.show_rru(mb_rru))
format!("{}", disp.pretty_print_default())
}
}
}
&MemArg::BXD20 {
base, index, disp, ..
} => {
let base = allocs.next(base);
let index = allocs.next(index);
if base != zero_reg() {
if index != zero_reg() {
format!(
"{}({},{})",
disp.show_rru(mb_rru),
index.show_rru(mb_rru),
base.show_rru(mb_rru)
disp.pretty_print_default(),
show_reg(index),
show_reg(base),
)
} else {
format!("{}({})", disp.show_rru(mb_rru), base.show_rru(mb_rru))
format!("{}({})", disp.pretty_print_default(), show_reg(base))
}
} else {
if index != zero_reg() {
format!("{}({},)", disp.show_rru(mb_rru), index.show_rru(mb_rru))
format!("{}({},)", disp.pretty_print_default(), show_reg(index))
} else {
format!("{}", disp.show_rru(mb_rru))
format!("{}", disp.pretty_print_default())
}
}
}
@@ -244,7 +281,7 @@ impl PrettyPrint for MemArg {
}
impl PrettyPrint for Cond {
fn show_rru(&self, _mb_rru: Option<&RealRegUniverse>) -> String {
fn pretty_print(&self, _: u8, _: &mut AllocationConsumer<'_>) -> String {
let s = match self.mask {
1 => "o",
2 => "h",

View File

@@ -5,8 +5,10 @@ use crate::ir::MemFlags;
use crate::ir::{SourceLoc, TrapCode};
use crate::isa::s390x::inst::*;
use crate::isa::s390x::settings as s390x_settings;
use crate::machinst::reg::count_operands;
use crate::machinst::{Reg, RegClass};
use core::convert::TryFrom;
use regalloc::{Reg, RegClass};
use regalloc2::Allocation;
/// Memory addressing mode finalization: convert "special" modes (e.g.,
/// generic arbitrary stack offset) into real addressing modes, possibly by
@@ -125,7 +127,7 @@ pub fn mem_emit(
true,
);
for inst in mem_insts.into_iter() {
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
}
if add_trap && mem.can_trap() {
@@ -195,7 +197,7 @@ pub fn mem_rs_emit(
false,
);
for inst in mem_insts.into_iter() {
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
}
if add_trap && mem.can_trap() {
@@ -237,7 +239,7 @@ pub fn mem_imm8_emit(
) {
let (mem_insts, mem) = mem_finalize(mem, state, true, true, false, false);
for inst in mem_insts.into_iter() {
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
}
if add_trap && mem.can_trap() {
@@ -275,7 +277,7 @@ pub fn mem_imm16_emit(
) {
let (mem_insts, mem) = mem_finalize(mem, state, true, false, false, false);
for inst in mem_insts.into_iter() {
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
}
if add_trap && mem.can_trap() {
@@ -300,17 +302,17 @@ pub fn mem_imm16_emit(
// Instructions and subcomponents: emission
fn machreg_to_gpr(m: Reg) -> u8 {
assert_eq!(m.get_class(), RegClass::I64);
u8::try_from(m.to_real_reg().get_hw_encoding()).unwrap()
assert_eq!(m.class(), RegClass::Int);
u8::try_from(m.to_real_reg().unwrap().hw_enc()).unwrap()
}
fn machreg_to_fpr(m: Reg) -> u8 {
assert_eq!(m.get_class(), RegClass::F64);
u8::try_from(m.to_real_reg().get_hw_encoding()).unwrap()
assert_eq!(m.class(), RegClass::Float);
u8::try_from(m.to_real_reg().unwrap().hw_enc()).unwrap()
}
fn machreg_to_gpr_or_fpr(m: Reg) -> u8 {
u8::try_from(m.to_real_reg().get_hw_encoding()).unwrap()
u8::try_from(m.to_real_reg().unwrap().hw_enc()).unwrap()
}
/// E-type instructions.
@@ -936,7 +938,15 @@ impl MachInstEmit for Inst {
type State = EmitState;
type Info = EmitInfo;
fn emit(&self, sink: &mut MachBuffer<Inst>, emit_info: &Self::Info, state: &mut EmitState) {
fn emit(
&self,
allocs: &[Allocation],
sink: &mut MachBuffer<Inst>,
emit_info: &Self::Info,
state: &mut EmitState,
) {
let mut allocs = AllocationConsumer::new(allocs);
// Verify that we can emit this Inst in the current ISA
let matches_isa_flags = |iset_requirement: &InstructionSet| -> bool {
match iset_requirement {
@@ -965,6 +975,10 @@ impl MachInstEmit for Inst {
match self {
&Inst::AluRRR { alu_op, rd, rn, rm } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let rm = allocs.next(rm);
let (opcode, have_rr) = match alu_op {
ALUOp::Add32 => (0xb9f8, true), // ARK
ALUOp::Add64 => (0xb9e8, true), // AGRK
@@ -992,7 +1006,7 @@ impl MachInstEmit for Inst {
};
if have_rr && rd.to_reg() == rn {
let inst = Inst::AluRR { alu_op, rd, rm };
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
} else {
put(sink, &enc_rrf_ab(opcode, rd.to_reg(), rn, rm, 0));
}
@@ -1003,9 +1017,12 @@ impl MachInstEmit for Inst {
rn,
imm,
} => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
if rd.to_reg() == rn {
let inst = Inst::AluRSImm16 { alu_op, rd, imm };
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
} else {
let opcode = match alu_op {
ALUOp::Add32 => 0xecd8, // AHIK
@@ -1016,6 +1033,9 @@ impl MachInstEmit for Inst {
}
}
&Inst::AluRR { alu_op, rd, rm } => {
let rd = allocs.next_writable(rd);
let rm = allocs.next(rm);
let (opcode, is_rre) = match alu_op {
ALUOp::Add32 => (0x1a, false), // AR
ALUOp::Add64 => (0xb908, true), // AGR
@@ -1051,6 +1071,9 @@ impl MachInstEmit for Inst {
rd,
ref mem,
} => {
let rd = allocs.next_writable(rd);
let mem = mem.with_allocs(&mut allocs);
let (opcode_rx, opcode_rxy) = match alu_op {
ALUOp::Add32 => (Some(0x5a), Some(0xe35a)), // A(Y)
ALUOp::Add32Ext16 => (Some(0x4a), Some(0xe34a)), // AH(Y)
@@ -1083,10 +1106,12 @@ impl MachInstEmit for Inst {
};
let rd = rd.to_reg();
mem_emit(
rd, mem, opcode_rx, opcode_rxy, None, true, sink, emit_info, state,
rd, &mem, opcode_rx, opcode_rxy, None, true, sink, emit_info, state,
);
}
&Inst::AluRSImm16 { alu_op, rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = match alu_op {
ALUOp::Add32 => 0xa7a, // AHI
ALUOp::Add64 => 0xa7b, // AGHI
@@ -1097,6 +1122,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ri_a(opcode, rd.to_reg(), imm as u16));
}
&Inst::AluRSImm32 { alu_op, rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = match alu_op {
ALUOp::Add32 => 0xc29, // AFI
ALUOp::Add64 => 0xc28, // AGFI
@@ -1107,6 +1134,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ril_a(opcode, rd.to_reg(), imm as u32));
}
&Inst::AluRUImm32 { alu_op, rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = match alu_op {
ALUOp::AddLogical32 => 0xc2b, // ALFI
ALUOp::AddLogical64 => 0xc2a, // ALGFI
@@ -1117,6 +1146,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ril_a(opcode, rd.to_reg(), imm));
}
&Inst::AluRUImm16Shifted { alu_op, rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = match (alu_op, imm.shift) {
(ALUOp::And32, 0) => 0xa57, // NILL
(ALUOp::And32, 1) => 0xa56, // NILH
@@ -1135,6 +1166,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ri_a(opcode, rd.to_reg(), imm.bits));
}
&Inst::AluRUImm32Shifted { alu_op, rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = match (alu_op, imm.shift) {
(ALUOp::And32, 0) => 0xc0b, // NILF
(ALUOp::And64, 0) => 0xc0b, // NILF
@@ -1151,38 +1184,53 @@ impl MachInstEmit for Inst {
}
&Inst::SMulWide { rn, rm } => {
let rn = allocs.next(rn);
let rm = allocs.next(rm);
let opcode = 0xb9ec; // MGRK
put(sink, &enc_rrf_ab(opcode, gpr(0), rn, rm, 0));
}
&Inst::UMulWide { rn } => {
let rn = allocs.next(rn);
let opcode = 0xb986; // MLGR
put(sink, &enc_rre(opcode, gpr(0), rn));
}
&Inst::SDivMod32 { rn } => {
let rn = allocs.next(rn);
let opcode = 0xb91d; // DSGFR
let srcloc = state.cur_srcloc();
let trap_code = TrapCode::IntegerDivisionByZero;
put_with_trap(sink, &enc_rre(opcode, gpr(0), rn), srcloc, trap_code);
}
&Inst::SDivMod64 { rn } => {
let rn = allocs.next(rn);
let opcode = 0xb90d; // DSGR
let srcloc = state.cur_srcloc();
let trap_code = TrapCode::IntegerDivisionByZero;
put_with_trap(sink, &enc_rre(opcode, gpr(0), rn), srcloc, trap_code);
}
&Inst::UDivMod32 { rn } => {
let rn = allocs.next(rn);
let opcode = 0xb997; // DLR
let srcloc = state.cur_srcloc();
let trap_code = TrapCode::IntegerDivisionByZero;
put_with_trap(sink, &enc_rre(opcode, gpr(0), rn), srcloc, trap_code);
}
&Inst::UDivMod64 { rn } => {
let rn = allocs.next(rn);
let opcode = 0xb987; // DLGR
let srcloc = state.cur_srcloc();
let trap_code = TrapCode::IntegerDivisionByZero;
put_with_trap(sink, &enc_rre(opcode, gpr(0), rn), srcloc, trap_code);
}
&Inst::Flogr { rn } => {
let rn = allocs.next(rn);
let opcode = 0xb983; // FLOGR
put(sink, &enc_rre(opcode, gpr(0), rn));
}
@@ -1194,6 +1242,10 @@ impl MachInstEmit for Inst {
shift_imm,
shift_reg,
} => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let shift_reg = allocs.next(shift_reg);
let opcode = match shift_op {
ShiftOp::RotL32 => 0xeb1d, // RLL
ShiftOp::RotL64 => 0xeb1c, // RLLG
@@ -1218,6 +1270,9 @@ impl MachInstEmit for Inst {
end_bit,
rotate_amt,
} => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let opcode = match op {
RxSBGOp::Insert => 0xec59, // RISBGN
RxSBGOp::And => 0xec54, // RNSBG
@@ -1245,6 +1300,9 @@ impl MachInstEmit for Inst {
end_bit,
rotate_amt,
} => {
let rd = allocs.next(rd);
let rn = allocs.next(rn);
let opcode = match op {
RxSBGOp::And => 0xec54, // RNSBG
RxSBGOp::Or => 0xec56, // ROSBG
@@ -1265,6 +1323,9 @@ impl MachInstEmit for Inst {
}
&Inst::UnaryRR { op, rd, rn } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
match op {
UnaryOp::Abs32 => {
let opcode = 0x10; // LPR
@@ -1316,6 +1377,9 @@ impl MachInstEmit for Inst {
from_bits,
to_bits,
} => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let opcode = match (signed, from_bits, to_bits) {
(_, 1, 32) => 0xb926, // LBR
(_, 1, 64) => 0xb906, // LGBR
@@ -1338,6 +1402,9 @@ impl MachInstEmit for Inst {
}
&Inst::CmpRR { op, rn, rm } => {
let rn = allocs.next(rn);
let rm = allocs.next(rm);
let (opcode, is_rre) = match op {
CmpOp::CmpS32 => (0x19, false), // CR
CmpOp::CmpS64 => (0xb920, true), // CGR
@@ -1354,6 +1421,9 @@ impl MachInstEmit for Inst {
}
}
&Inst::CmpRX { op, rn, ref mem } => {
let rn = allocs.next(rn);
let mem = mem.with_allocs(&mut allocs);
let (opcode_rx, opcode_rxy, opcode_ril) = match op {
CmpOp::CmpS32 => (Some(0x59), Some(0xe359), Some(0xc6d)), // C(Y), CRL
CmpOp::CmpS32Ext16 => (Some(0x49), Some(0xe379), Some(0xc65)), // CH(Y), CHRL
@@ -1367,10 +1437,12 @@ impl MachInstEmit for Inst {
CmpOp::CmpL64Ext32 => (None, Some(0xe331), Some(0xc6e)), // CLGF, CLGFRL
};
mem_emit(
rn, mem, opcode_rx, opcode_rxy, opcode_ril, true, sink, emit_info, state,
rn, &mem, opcode_rx, opcode_rxy, opcode_ril, true, sink, emit_info, state,
);
}
&Inst::CmpRSImm16 { op, rn, imm } => {
let rn = allocs.next(rn);
let opcode = match op {
CmpOp::CmpS32 => 0xa7e, // CHI
CmpOp::CmpS64 => 0xa7f, // CGHI
@@ -1379,6 +1451,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ri_a(opcode, rn, imm as u16));
}
&Inst::CmpRSImm32 { op, rn, imm } => {
let rn = allocs.next(rn);
let opcode = match op {
CmpOp::CmpS32 => 0xc2d, // CFI
CmpOp::CmpS64 => 0xc2c, // CGFI
@@ -1387,6 +1461,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ril_a(opcode, rn, imm as u32));
}
&Inst::CmpRUImm32 { op, rn, imm } => {
let rn = allocs.next(rn);
let opcode = match op {
CmpOp::CmpL32 => 0xc2f, // CLFI
CmpOp::CmpL64 => 0xc2e, // CLGFI
@@ -1401,6 +1477,9 @@ impl MachInstEmit for Inst {
cond,
trap_code,
} => {
let rn = allocs.next(rn);
let rm = allocs.next(rm);
let opcode = match op {
CmpOp::CmpS32 => 0xb972, // CRT
CmpOp::CmpS64 => 0xb960, // CGRT
@@ -1423,6 +1502,8 @@ impl MachInstEmit for Inst {
cond,
trap_code,
} => {
let rn = allocs.next(rn);
let opcode = match op {
CmpOp::CmpS32 => 0xec72, // CIT
CmpOp::CmpS64 => 0xec70, // CGIT
@@ -1443,6 +1524,8 @@ impl MachInstEmit for Inst {
cond,
trap_code,
} => {
let rn = allocs.next(rn);
let opcode = match op {
CmpOp::CmpL32 => 0xec73, // CLFIT
CmpOp::CmpL64 => 0xec71, // CLGIT
@@ -1463,6 +1546,10 @@ impl MachInstEmit for Inst {
rn,
ref mem,
} => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let mem = mem.with_allocs(&mut allocs);
let opcode = match alu_op {
ALUOp::Add32 => 0xebf8, // LAA
ALUOp::Add64 => 0xebe8, // LAAG
@@ -1481,7 +1568,7 @@ impl MachInstEmit for Inst {
mem_rs_emit(
rd,
rn,
mem,
&mem,
None,
Some(opcode),
true,
@@ -1500,6 +1587,8 @@ impl MachInstEmit for Inst {
sink.bind_label(loop_label);
for inst in (&body).into_iter() {
let op_count = count_operands(inst);
let sub_allocs = allocs.next_n(op_count);
match &inst {
// Replace a CondBreak with a branch to done_label.
&Inst::CondBreak { cond } => {
@@ -1507,9 +1596,9 @@ impl MachInstEmit for Inst {
target: done_label,
cond: *cond,
};
inst.emit(sink, emit_info, state);
inst.emit(&sub_allocs[..], sink, emit_info, state);
}
_ => inst.emit(sink, emit_info, state),
_ => inst.emit(&sub_allocs[..], sink, emit_info, state),
};
}
@@ -1517,13 +1606,17 @@ impl MachInstEmit for Inst {
target: loop_label,
cond,
};
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
// Emit label at the end of the loop.
sink.bind_label(done_label);
}
&Inst::CondBreak { .. } => unreachable!(), // Only valid inside a Loop.
&Inst::AtomicCas32 { rd, rn, ref mem } | &Inst::AtomicCas64 { rd, rn, ref mem } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let mem = mem.with_allocs(&mut allocs);
let (opcode_rs, opcode_rsy) = match self {
&Inst::AtomicCas32 { .. } => (Some(0xba), Some(0xeb14)), // CS(Y)
&Inst::AtomicCas64 { .. } => (None, Some(0xeb30)), // CSG
@@ -1532,7 +1625,7 @@ impl MachInstEmit for Inst {
let rd = rd.to_reg();
mem_rs_emit(
rd, rn, mem, opcode_rs, opcode_rsy, true, sink, emit_info, state,
rd, rn, &mem, opcode_rs, opcode_rsy, true, sink, emit_info, state,
);
}
&Inst::Fence => {
@@ -1556,6 +1649,9 @@ impl MachInstEmit for Inst {
| &Inst::LoadRev64 { rd, ref mem }
| &Inst::FpuLoad32 { rd, ref mem }
| &Inst::FpuLoad64 { rd, ref mem } => {
let rd = allocs.next_writable(rd);
let mem = mem.with_allocs(&mut allocs);
let (opcode_rx, opcode_rxy, opcode_ril) = match self {
&Inst::Load32 { .. } => (Some(0x58), Some(0xe358), Some(0xc4d)), // L(Y), LRL
&Inst::Load32ZExt8 { .. } => (None, Some(0xe394), None), // LLC
@@ -1578,19 +1674,22 @@ impl MachInstEmit for Inst {
};
let rd = rd.to_reg();
mem_emit(
rd, mem, opcode_rx, opcode_rxy, opcode_ril, true, sink, emit_info, state,
rd, &mem, opcode_rx, opcode_rxy, opcode_ril, true, sink, emit_info, state,
);
}
&Inst::FpuLoadRev32 { rd, ref mem } | &Inst::FpuLoadRev64 { rd, ref mem } => {
let rd = allocs.next_writable(rd);
let mem = mem.with_allocs(&mut allocs);
let opcode = match self {
&Inst::FpuLoadRev32 { .. } => 0xe603, // VLEBRF
&Inst::FpuLoadRev64 { .. } => 0xe602, // VLEBRG
_ => unreachable!(),
};
let (mem_insts, mem) = mem_finalize(mem, state, true, false, false, true);
let (mem_insts, mem) = mem_finalize(&mem, state, true, false, false, true);
for inst in mem_insts.into_iter() {
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
}
let srcloc = state.cur_srcloc();
@@ -1620,6 +1719,9 @@ impl MachInstEmit for Inst {
| &Inst::StoreRev64 { rd, ref mem }
| &Inst::FpuStore32 { rd, ref mem }
| &Inst::FpuStore64 { rd, ref mem } => {
let rd = allocs.next(rd);
let mem = mem.with_allocs(&mut allocs);
let (opcode_rx, opcode_rxy, opcode_ril) = match self {
&Inst::Store8 { .. } => (Some(0x42), Some(0xe372), None), // STC(Y)
&Inst::Store16 { .. } => (Some(0x40), Some(0xe370), Some(0xc47)), // STH(Y), STHRL
@@ -1633,37 +1735,44 @@ impl MachInstEmit for Inst {
_ => unreachable!(),
};
mem_emit(
rd, mem, opcode_rx, opcode_rxy, opcode_ril, true, sink, emit_info, state,
rd, &mem, opcode_rx, opcode_rxy, opcode_ril, true, sink, emit_info, state,
);
}
&Inst::StoreImm8 { imm, ref mem } => {
let mem = mem.with_allocs(&mut allocs);
let opcode_si = 0x92; // MVI
let opcode_siy = 0xeb52; // MVIY
mem_imm8_emit(
imm, mem, opcode_si, opcode_siy, true, sink, emit_info, state,
imm, &mem, opcode_si, opcode_siy, true, sink, emit_info, state,
);
}
&Inst::StoreImm16 { imm, ref mem }
| &Inst::StoreImm32SExt16 { imm, ref mem }
| &Inst::StoreImm64SExt16 { imm, ref mem } => {
let mem = mem.with_allocs(&mut allocs);
let opcode = match self {
&Inst::StoreImm16 { .. } => 0xe544, // MVHHI
&Inst::StoreImm32SExt16 { .. } => 0xe54c, // MVHI
&Inst::StoreImm64SExt16 { .. } => 0xe548, // MVGHI
_ => unreachable!(),
};
mem_imm16_emit(imm, mem, opcode, true, sink, emit_info, state);
mem_imm16_emit(imm, &mem, opcode, true, sink, emit_info, state);
}
&Inst::FpuStoreRev32 { rd, ref mem } | &Inst::FpuStoreRev64 { rd, ref mem } => {
let rd = allocs.next(rd);
let mem = mem.with_allocs(&mut allocs);
let opcode = match self {
&Inst::FpuStoreRev32 { .. } => 0xe60b, // VSTEBRF
&Inst::FpuStoreRev64 { .. } => 0xe60a, // VSTEBRG
_ => unreachable!(),
};
let (mem_insts, mem) = mem_finalize(mem, state, true, false, false, true);
let (mem_insts, mem) = mem_finalize(&mem, state, true, false, false, true);
for inst in mem_insts.into_iter() {
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
}
let srcloc = state.cur_srcloc();
@@ -1682,6 +1791,8 @@ impl MachInstEmit for Inst {
}
&Inst::LoadMultiple64 { rt, rt2, ref mem } => {
let mem = mem.with_allocs(&mut allocs);
let opcode = 0xeb04; // LMG
let rt = rt.to_reg();
let rt2 = rt2.to_reg();
@@ -1698,6 +1809,8 @@ impl MachInstEmit for Inst {
);
}
&Inst::StoreMultiple64 { rt, rt2, ref mem } => {
let mem = mem.with_allocs(&mut allocs);
let opcode = 0xeb24; // STMG
mem_rs_emit(
rt,
@@ -1713,48 +1826,73 @@ impl MachInstEmit for Inst {
}
&Inst::LoadAddr { rd, ref mem } => {
let rd = allocs.next_writable(rd);
let mem = mem.with_allocs(&mut allocs);
let opcode_rx = Some(0x41); // LA
let opcode_rxy = Some(0xe371); // LAY
let opcode_ril = Some(0xc00); // LARL
let rd = rd.to_reg();
mem_emit(
rd, mem, opcode_rx, opcode_rxy, opcode_ril, false, sink, emit_info, state,
rd, &mem, opcode_rx, opcode_rxy, opcode_ril, false, sink, emit_info, state,
);
}
&Inst::Mov64 { rd, rm } => {
let rd = allocs.next_writable(rd);
let rm = allocs.next(rm);
let opcode = 0xb904; // LGR
put(sink, &enc_rre(opcode, rd.to_reg(), rm));
}
&Inst::Mov32 { rd, rm } => {
let rd = allocs.next_writable(rd);
let rm = allocs.next(rm);
let opcode = 0x18; // LR
put(sink, &enc_rr(opcode, rd.to_reg(), rm));
}
&Inst::Mov32Imm { rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = 0xc09; // IILF
put(sink, &enc_ril_a(opcode, rd.to_reg(), imm));
}
&Inst::Mov32SImm16 { rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = 0xa78; // LHI
put(sink, &enc_ri_a(opcode, rd.to_reg(), imm as u16));
}
&Inst::Mov64SImm16 { rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = 0xa79; // LGHI
put(sink, &enc_ri_a(opcode, rd.to_reg(), imm as u16));
}
&Inst::Mov64SImm32 { rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = 0xc01; // LGFI
put(sink, &enc_ril_a(opcode, rd.to_reg(), imm as u32));
}
&Inst::CMov32 { rd, cond, rm } => {
let rd = allocs.next_writable(rd);
let rm = allocs.next(rm);
let opcode = 0xb9f2; // LOCR
put(sink, &enc_rrf_cde(opcode, rd.to_reg(), rm, cond.bits(), 0));
}
&Inst::CMov64 { rd, cond, rm } => {
let rd = allocs.next_writable(rd);
let rm = allocs.next(rm);
let opcode = 0xb9e2; // LOCGR
put(sink, &enc_rrf_cde(opcode, rd.to_reg(), rm, cond.bits(), 0));
}
&Inst::CMov32SImm16 { rd, cond, imm } => {
let rd = allocs.next_writable(rd);
let opcode = 0xec42; // LOCHI
put(
sink,
@@ -1762,6 +1900,8 @@ impl MachInstEmit for Inst {
);
}
&Inst::CMov64SImm16 { rd, cond, imm } => {
let rd = allocs.next_writable(rd);
let opcode = 0xec46; // LOCGHI
put(
sink,
@@ -1769,6 +1909,8 @@ impl MachInstEmit for Inst {
);
}
&Inst::Mov64UImm16Shifted { rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = match imm.shift {
0 => 0xa5f, // LLILL
1 => 0xa5e, // LLILH
@@ -1779,6 +1921,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ri_a(opcode, rd.to_reg(), imm.bits));
}
&Inst::Mov64UImm32Shifted { rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = match imm.shift {
0 => 0xc0f, // LLILF
1 => 0xc0e, // LLIHF
@@ -1787,6 +1931,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ril_a(opcode, rd.to_reg(), imm.bits));
}
&Inst::Insert64UImm16Shifted { rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = match imm.shift {
0 => 0xa53, // IILL
1 => 0xa52, // IILH
@@ -1797,6 +1943,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ri_a(opcode, rd.to_reg(), imm.bits));
}
&Inst::Insert64UImm32Shifted { rd, imm } => {
let rd = allocs.next_writable(rd);
let opcode = match imm.shift {
0 => 0xc09, // IILF
1 => 0xc08, // IIHF
@@ -1809,6 +1957,8 @@ impl MachInstEmit for Inst {
ref name,
offset,
} => {
let rd = allocs.next_writable(rd);
let opcode = 0xa75; // BRAS
let srcloc = state.cur_srcloc();
let reg = writable_spilltmp_reg().to_reg();
@@ -1823,38 +1973,58 @@ impl MachInstEmit for Inst {
rd,
mem: MemArg::reg(reg, MemFlags::trusted()),
};
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
}
&Inst::FpuMove32 { rd, rn } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let opcode = 0x38; // LER
put(sink, &enc_rr(opcode, rd.to_reg(), rn));
}
&Inst::FpuMove64 { rd, rn } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let opcode = 0x28; // LDR
put(sink, &enc_rr(opcode, rd.to_reg(), rn));
}
&Inst::FpuCMov32 { rd, cond, rm } => {
let rd = allocs.next_writable(rd);
let rm = allocs.next(rm);
let opcode = 0xa74; // BCR
put(sink, &enc_ri_c(opcode, cond.invert().bits(), 4 + 2));
let opcode = 0x38; // LER
put(sink, &enc_rr(opcode, rd.to_reg(), rm));
}
&Inst::FpuCMov64 { rd, cond, rm } => {
let rd = allocs.next_writable(rd);
let rm = allocs.next(rm);
let opcode = 0xa74; // BCR
put(sink, &enc_ri_c(opcode, cond.invert().bits(), 4 + 2));
let opcode = 0x28; // LDR
put(sink, &enc_rr(opcode, rd.to_reg(), rm));
}
&Inst::MovToFpr { rd, rn } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let opcode = 0xb3c1; // LDGR
put(sink, &enc_rre(opcode, rd.to_reg(), rn));
}
&Inst::MovFromFpr { rd, rn } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let opcode = 0xb3cd; // LGDR
put(sink, &enc_rre(opcode, rd.to_reg(), rn));
}
&Inst::LoadFpuConst32 { rd, const_data } => {
let rd = allocs.next_writable(rd);
let opcode = 0xa75; // BRAS
let reg = writable_spilltmp_reg().to_reg();
put(sink, &enc_ri_b(opcode, reg, 8));
@@ -1863,9 +2033,11 @@ impl MachInstEmit for Inst {
rd,
mem: MemArg::reg(reg, MemFlags::trusted()),
};
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
}
&Inst::LoadFpuConst64 { rd, const_data } => {
let rd = allocs.next_writable(rd);
let opcode = 0xa75; // BRAS
let reg = writable_spilltmp_reg().to_reg();
put(sink, &enc_ri_b(opcode, reg, 12));
@@ -1874,14 +2046,21 @@ impl MachInstEmit for Inst {
rd,
mem: MemArg::reg(reg, MemFlags::trusted()),
};
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
}
&Inst::FpuCopysign { rd, rn, rm } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let rm = allocs.next(rm);
let opcode = 0xb372; // CPSDR
put(sink, &enc_rrf_ab(opcode, rd.to_reg(), rn, rm, 0));
}
&Inst::FpuRR { fpu_op, rd, rn } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let opcode = match fpu_op {
FPUOp1::Abs32 => 0xb300, // LPEBR
FPUOp1::Abs64 => 0xb310, // LPDBR
@@ -1897,6 +2076,9 @@ impl MachInstEmit for Inst {
put(sink, &enc_rre(opcode, rd.to_reg(), rn));
}
&Inst::FpuRRR { fpu_op, rd, rm } => {
let rd = allocs.next_writable(rd);
let rm = allocs.next(rm);
let opcode = match fpu_op {
FPUOp2::Add32 => 0xb30a, // AEBR
FPUOp2::Add64 => 0xb31a, // ADBR
@@ -1911,6 +2093,10 @@ impl MachInstEmit for Inst {
put(sink, &enc_rre(opcode, rd.to_reg(), rm));
}
&Inst::FpuRRRR { fpu_op, rd, rn, rm } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let rm = allocs.next(rm);
let opcode = match fpu_op {
FPUOp3::MAdd32 => 0xb30e, // MAEBR
FPUOp3::MAdd64 => 0xb31e, // MADBR
@@ -1920,6 +2106,9 @@ impl MachInstEmit for Inst {
put(sink, &enc_rrd(opcode, rd.to_reg(), rm, rn));
}
&Inst::FpuToInt { op, rd, rn } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let opcode = match op {
FpuToIntOp::F32ToI32 => 0xb398, // CFEBRA
FpuToIntOp::F32ToU32 => 0xb39c, // CLFEBR
@@ -1933,6 +2122,9 @@ impl MachInstEmit for Inst {
put(sink, &enc_rrf_cde(opcode, rd.to_reg(), rn, 5, 0));
}
&Inst::IntToFpu { op, rd, rn } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let opcode = match op {
IntToFpuOp::I32ToF32 => 0xb394, // CEFBRA
IntToFpuOp::U32ToF32 => 0xb390, // CELFBR
@@ -1946,6 +2138,9 @@ impl MachInstEmit for Inst {
put(sink, &enc_rrf_cde(opcode, rd.to_reg(), rn, 0, 0));
}
&Inst::FpuRound { op, rd, rn } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let (opcode, m3) = match op {
FpuRoundMode::Minus32 => (0xb357, 7), // FIEBR
FpuRoundMode::Minus64 => (0xb35f, 7), // FIDBR
@@ -1959,6 +2154,10 @@ impl MachInstEmit for Inst {
put(sink, &enc_rrf_cde(opcode, rd.to_reg(), rn, m3, 0));
}
&Inst::FpuVecRRR { fpu_op, rd, rn, rm } => {
let rd = allocs.next_writable(rd);
let rn = allocs.next(rn);
let rm = allocs.next(rm);
let (opcode, m4) = match fpu_op {
FPUOp2::Max32 => (0xe7ef, 2), // VFMAX
FPUOp2::Max64 => (0xe7ef, 3), // VFMAX
@@ -1969,15 +2168,23 @@ impl MachInstEmit for Inst {
put(sink, &enc_vrr(opcode, rd.to_reg(), rn, rm, m4, 8, 1));
}
&Inst::FpuCmp32 { rn, rm } => {
let rn = allocs.next(rn);
let rm = allocs.next(rm);
let opcode = 0xb309; // CEBR
put(sink, &enc_rre(opcode, rn, rm));
}
&Inst::FpuCmp64 { rn, rm } => {
let rn = allocs.next(rn);
let rm = allocs.next(rm);
let opcode = 0xb319; // CDBR
put(sink, &enc_rre(opcode, rn, rm));
}
&Inst::Call { link, ref info } => {
let link = allocs.next_writable(link);
let opcode = 0xc05; // BRASL
let reloc = Reloc::S390xPCRel32Dbl;
let srcloc = state.cur_srcloc();
@@ -1998,17 +2205,22 @@ impl MachInstEmit for Inst {
}
}
&Inst::CallInd { link, ref info } => {
let link = allocs.next_writable(link);
let rn = allocs.next(info.rn);
let opcode = 0x0d; // BASR
let srcloc = state.cur_srcloc();
if let Some(s) = state.take_stack_map() {
sink.add_stack_map(StackMapExtent::UpcomingBytes(2), s);
}
put(sink, &enc_rr(opcode, link.to_reg(), info.rn));
put(sink, &enc_rr(opcode, link.to_reg(), rn));
if info.opcode.is_call() {
sink.add_call_site(srcloc, info.opcode);
}
}
&Inst::Ret { link } => {
&Inst::Ret { link, .. } => {
let link = allocs.next(link);
let opcode = 0x07; // BCR
put(sink, &enc_rr(opcode, gpr(15), link));
}
@@ -2025,6 +2237,8 @@ impl MachInstEmit for Inst {
put(sink, &enc_ril_c(opcode, 15, 0));
}
&Inst::IndirectBr { rn, .. } => {
let rn = allocs.next(rn);
let opcode = 0x07; // BCR
put(sink, &enc_rr(opcode, gpr(15), rn));
}
@@ -2079,6 +2293,8 @@ impl MachInstEmit for Inst {
put_with_trap(sink, &enc_e(0x0000), srcloc, trap_code);
}
&Inst::JTSequence { ridx, ref targets } => {
let ridx = allocs.next(ridx);
let table_label = sink.get_label();
// This sequence is *one* instruction in the vcode, and is expanded only here at
@@ -2093,7 +2309,7 @@ impl MachInstEmit for Inst {
target: table_label,
},
};
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
// Set temp to target address by adding the value of the jump table entry.
let inst = Inst::AluRX {
@@ -2101,7 +2317,7 @@ impl MachInstEmit for Inst {
rd: rtmp,
mem: MemArg::reg_plus_reg(rtmp.to_reg(), ridx, MemFlags::trusted()),
};
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
// Branch to computed address. (`targets` here is only used for successor queries
// and is not needed for emission.)
@@ -2109,7 +2325,7 @@ impl MachInstEmit for Inst {
rn: rtmp.to_reg(),
targets: vec![],
};
inst.emit(sink, emit_info, state);
inst.emit(&[], sink, emit_info, state);
// Emit jump table (table of 32-bit offsets).
// The first entry is the default target, which is not emitted
@@ -2138,13 +2354,11 @@ impl MachInstEmit for Inst {
state.virtual_sp_offset += offset;
}
&Inst::ValueLabelMarker { .. } => {
// Nothing; this is only used to compute debug info.
}
&Inst::Unwind { ref inst } => {
sink.add_unwind(inst.clone());
}
&Inst::DummyUse { .. } => {}
}
let end_off = sink.cur_offset();
@@ -2153,7 +2367,8 @@ impl MachInstEmit for Inst {
state.clear_post_insn();
}
fn pretty_print(&self, mb_rru: Option<&RealRegUniverse>, state: &mut EmitState) -> String {
self.print_with_state(mb_rru, state)
fn pretty_print_inst(&self, allocs: &[Allocation], state: &mut EmitState) -> String {
let mut allocs = AllocationConsumer::new(allocs);
self.print_with_state(state, &mut allocs)
}
}

View File

@@ -1585,7 +1585,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpS32,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61D00000003",
@@ -1624,7 +1624,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpS32Ext16,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61500000003",
@@ -1649,7 +1649,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpS64,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61800000003",
@@ -1674,7 +1674,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpS64Ext16,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61400000003",
@@ -1699,7 +1699,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpS64Ext32,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61C00000003",
@@ -1738,7 +1738,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpL32,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61F00000003",
@@ -1749,7 +1749,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpL32Ext16,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61700000003",
@@ -1774,7 +1774,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpL64,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61A00000003",
@@ -1785,7 +1785,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpL64Ext16,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61600000003",
@@ -1810,7 +1810,7 @@ fn test_s390x_binemit() {
op: CmpOp::CmpL64Ext32,
rn: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C61E00000003",
@@ -4536,7 +4536,7 @@ fn test_s390x_binemit() {
Inst::Load32 {
rd: writable_gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41D00000003",
@@ -4546,7 +4546,7 @@ fn test_s390x_binemit() {
Inst::Load32SExt16 {
rd: writable_gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41500000003",
@@ -4556,7 +4556,7 @@ fn test_s390x_binemit() {
Inst::Load32ZExt16 {
rd: writable_gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41200000003",
@@ -4566,7 +4566,7 @@ fn test_s390x_binemit() {
Inst::Load64 {
rd: writable_gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41800000003",
@@ -4576,7 +4576,7 @@ fn test_s390x_binemit() {
Inst::Load64SExt16 {
rd: writable_gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41400000003",
@@ -4586,7 +4586,7 @@ fn test_s390x_binemit() {
Inst::Load64ZExt16 {
rd: writable_gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41600000003",
@@ -4596,7 +4596,7 @@ fn test_s390x_binemit() {
Inst::Load64SExt32 {
rd: writable_gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41C00000003",
@@ -4606,7 +4606,7 @@ fn test_s390x_binemit() {
Inst::Load64ZExt32 {
rd: writable_gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41E00000003",
@@ -5790,7 +5790,7 @@ fn test_s390x_binemit() {
Inst::Store16 {
rd: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41700000003",
@@ -5800,7 +5800,7 @@ fn test_s390x_binemit() {
Inst::Store32 {
rd: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41F00000003",
@@ -5810,7 +5810,7 @@ fn test_s390x_binemit() {
Inst::Store64 {
rd: gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C41B00000003",
@@ -6035,7 +6035,7 @@ fn test_s390x_binemit() {
Inst::LoadAddr {
rd: writable_gpr(1),
mem: MemArg::Label {
target: MachLabel::from_block(1),
target: MachLabel::from_block(BlockIndex::new(1)),
},
},
"C01000000003",
@@ -6499,7 +6499,7 @@ fn test_s390x_binemit() {
insns.push((
Inst::Jump {
dest: MachLabel::from_block(0),
dest: MachLabel::from_block(BlockIndex::new(0)),
},
"C0F400000000",
"jg label0",
@@ -6507,7 +6507,7 @@ fn test_s390x_binemit() {
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(1),
},
"C01400000000",
@@ -6515,7 +6515,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(2),
},
"C02400000000",
@@ -6523,7 +6523,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(3),
},
"C03400000000",
@@ -6531,7 +6531,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(4),
},
"C04400000000",
@@ -6539,7 +6539,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(5),
},
"C05400000000",
@@ -6547,7 +6547,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(6),
},
"C06400000000",
@@ -6555,7 +6555,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(7),
},
"C07400000000",
@@ -6563,7 +6563,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(8),
},
"C08400000000",
@@ -6571,7 +6571,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(9),
},
"C09400000000",
@@ -6579,7 +6579,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(10),
},
"C0A400000000",
@@ -6587,7 +6587,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(11),
},
"C0B400000000",
@@ -6595,7 +6595,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(12),
},
"C0C400000000",
@@ -6603,7 +6603,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(13),
},
"C0D400000000",
@@ -6611,7 +6611,7 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::OneWayCondBr {
target: MachLabel::from_block(0),
target: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(14),
},
"C0E400000000",
@@ -6620,8 +6620,8 @@ fn test_s390x_binemit() {
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(1),
},
"C01400000000C0F4FFFFFFFD",
@@ -6629,8 +6629,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(2),
},
"C02400000000C0F4FFFFFFFD",
@@ -6638,8 +6638,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(3),
},
"C03400000000C0F4FFFFFFFD",
@@ -6647,8 +6647,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(4),
},
"C04400000000C0F4FFFFFFFD",
@@ -6656,8 +6656,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(5),
},
"C05400000000C0F4FFFFFFFD",
@@ -6665,8 +6665,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(6),
},
"C06400000000C0F4FFFFFFFD",
@@ -6674,8 +6674,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(7),
},
"C07400000000C0F4FFFFFFFD",
@@ -6683,8 +6683,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(8),
},
"C08400000000C0F4FFFFFFFD",
@@ -6692,8 +6692,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(9),
},
"C09400000000C0F4FFFFFFFD",
@@ -6701,8 +6701,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(10),
},
"C0A400000000C0F4FFFFFFFD",
@@ -6710,8 +6710,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(11),
},
"C0B400000000C0F4FFFFFFFD",
@@ -6719,8 +6719,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(12),
},
"C0C400000000C0F4FFFFFFFD",
@@ -6728,8 +6728,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(13),
},
"C0D400000000C0F4FFFFFFFD",
@@ -6737,8 +6737,8 @@ fn test_s390x_binemit() {
));
insns.push((
Inst::CondBr {
taken: MachLabel::from_block(0),
not_taken: MachLabel::from_block(0),
taken: MachLabel::from_block(BlockIndex::new(0)),
not_taken: MachLabel::from_block(BlockIndex::new(0)),
cond: Cond::from_mask(14),
},
"C0E400000000C0F4FFFFFFFD",
@@ -6782,7 +6782,14 @@ fn test_s390x_binemit() {
"basr %r14, %r1",
));
insns.push((Inst::Ret { link: gpr(14) }, "07FE", "br %r14"));
insns.push((
Inst::Ret {
link: gpr(14),
rets: vec![],
},
"07FE",
"br %r14",
));
insns.push((Inst::Debugtrap, "0001", "debugtrap"));
@@ -8246,7 +8253,6 @@ fn test_s390x_binemit() {
isa_flag_builder.enable("arch13").unwrap();
let isa_flags = s390x_settings::Flags::new(&flags, isa_flag_builder);
let rru = create_reg_universe(&flags);
let emit_info = EmitInfo::new(flags, isa_flags);
for (insn, expected_encoding, expected_printing) in insns {
println!(
@@ -8255,7 +8261,8 @@ fn test_s390x_binemit() {
);
// Check the printed text is as expected.
let actual_printing = insn.show_rru(Some(&rru));
let actual_printing =
insn.print_with_state(&mut EmitState::default(), &mut AllocationConsumer::new(&[]));
assert_eq!(expected_printing, actual_printing);
let mut buffer = MachBuffer::new();
@@ -8265,7 +8272,7 @@ fn test_s390x_binemit() {
buffer.bind_label(label0);
// Emit the instruction.
insn.emit(&mut buffer, &emit_info, &mut Default::default());
insn.emit(&[], &mut buffer, &emit_info, &mut Default::default());
// Label 1 after the instruction.
let label1 = buffer.get_label();

View File

@@ -1,6 +1,6 @@
//! S390x ISA definitions: immediate constants.
use regalloc::{PrettyPrint, RealRegUniverse};
use crate::machinst::{AllocationConsumer, PrettyPrint};
use std::string::String;
/// An unsigned 12-bit immediate.
@@ -207,25 +207,25 @@ impl UImm32Shifted {
}
impl PrettyPrint for UImm12 {
fn show_rru(&self, _mb_rru: Option<&RealRegUniverse>) -> String {
fn pretty_print(&self, _: u8, _: &mut AllocationConsumer<'_>) -> String {
format!("{}", self.value)
}
}
impl PrettyPrint for SImm20 {
fn show_rru(&self, _mb_rru: Option<&RealRegUniverse>) -> String {
fn pretty_print(&self, _: u8, _: &mut AllocationConsumer<'_>) -> String {
format!("{}", self.value)
}
}
impl PrettyPrint for UImm16Shifted {
fn show_rru(&self, _mb_rru: Option<&RealRegUniverse>) -> String {
fn pretty_print(&self, _: u8, _: &mut AllocationConsumer<'_>) -> String {
format!("{}", self.bits)
}
}
impl PrettyPrint for UImm32Shifted {
fn show_rru(&self, _mb_rru: Option<&RealRegUniverse>) -> String {
fn pretty_print(&self, _: u8, _: &mut AllocationConsumer<'_>) -> String {
format!("{}", self.bits)
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,12 @@
//! S390x ISA definitions: registers.
use alloc::string::String;
use regalloc2::MachineEnv;
use regalloc2::PReg;
use regalloc2::VReg;
use crate::machinst::*;
use crate::settings;
use regalloc::{RealRegUniverse, Reg, RegClass, RegClassInfo, Writable, NUM_REG_CLASSES};
//=============================================================================
// Registers, the Universe thereof, and printing
@@ -29,11 +34,8 @@ const FPR_INDICES: [u8; 16] = [
/// Get a reference to a GPR (integer register).
pub fn gpr(num: u8) -> Reg {
assert!(num < 16);
Reg::new_real(
RegClass::I64,
/* enc = */ num,
/* index = */ GPR_INDICES[num as usize],
)
let preg = PReg::new(num as usize, RegClass::Int);
Reg::from(VReg::new(preg.index(), RegClass::Int))
}
/// Get a writable reference to a GPR.
@@ -44,11 +46,8 @@ pub fn writable_gpr(num: u8) -> Writable<Reg> {
/// Get a reference to a FPR (floating-point register).
pub fn fpr(num: u8) -> Reg {
assert!(num < 16);
Reg::new_real(
RegClass::F64,
/* enc = */ num,
/* index = */ FPR_INDICES[num as usize],
)
let preg = PReg::new(num as usize, RegClass::Float);
Reg::from(VReg::new(preg.index(), RegClass::Float))
}
/// Get a writable reference to a V-register.
@@ -88,81 +87,73 @@ pub fn zero_reg() -> Reg {
}
/// Create the register universe for AArch64.
pub fn create_reg_universe(_flags: &settings::Flags) -> RealRegUniverse {
let mut regs = vec![];
let mut allocable_by_class = [None; NUM_REG_CLASSES];
// Numbering Scheme: we put FPRs first, then GPRs. The GPRs exclude several registers:
// r0 (we cannot use this for addressing // FIXME regalloc)
// r1 (spilltmp)
// r15 (stack pointer)
// FPRs.
let mut base = regs.len();
regs.push((fpr(0).to_real_reg(), "%f0".into()));
regs.push((fpr(2).to_real_reg(), "%f2".into()));
regs.push((fpr(4).to_real_reg(), "%f4".into()));
regs.push((fpr(6).to_real_reg(), "%f6".into()));
regs.push((fpr(1).to_real_reg(), "%f1".into()));
regs.push((fpr(3).to_real_reg(), "%f3".into()));
regs.push((fpr(5).to_real_reg(), "%f5".into()));
regs.push((fpr(7).to_real_reg(), "%f7".into()));
regs.push((fpr(8).to_real_reg(), "%f8".into()));
regs.push((fpr(10).to_real_reg(), "%f10".into()));
regs.push((fpr(12).to_real_reg(), "%f12".into()));
regs.push((fpr(14).to_real_reg(), "%f14".into()));
regs.push((fpr(9).to_real_reg(), "%f9".into()));
regs.push((fpr(11).to_real_reg(), "%f11".into()));
regs.push((fpr(13).to_real_reg(), "%f13".into()));
regs.push((fpr(15).to_real_reg(), "%f15".into()));
allocable_by_class[RegClass::F64.rc_to_usize()] = Some(RegClassInfo {
first: base,
last: regs.len() - 1,
suggested_scratch: Some(fpr(1).get_index()),
});
// Caller-saved GPRs in the SystemV s390x ABI.
base = regs.len();
regs.push((gpr(2).to_real_reg(), "%r2".into()));
regs.push((gpr(3).to_real_reg(), "%r3".into()));
regs.push((gpr(4).to_real_reg(), "%r4".into()));
regs.push((gpr(5).to_real_reg(), "%r5".into()));
// Callee-saved GPRs in the SystemV s390x ABI.
// We start from r14 downwards in an attempt to allow the
// prolog to use as short a STMG as possible.
regs.push((gpr(14).to_real_reg(), "%r14".into()));
regs.push((gpr(13).to_real_reg(), "%r13".into()));
regs.push((gpr(12).to_real_reg(), "%r12".into()));
regs.push((gpr(11).to_real_reg(), "%r11".into()));
regs.push((gpr(10).to_real_reg(), "%r10".into()));
regs.push((gpr(9).to_real_reg(), "%r9".into()));
regs.push((gpr(8).to_real_reg(), "%r8".into()));
regs.push((gpr(7).to_real_reg(), "%r7".into()));
regs.push((gpr(6).to_real_reg(), "%r6".into()));
allocable_by_class[RegClass::I64.rc_to_usize()] = Some(RegClassInfo {
first: base,
last: regs.len() - 1,
suggested_scratch: Some(gpr(13).get_index()),
});
// Other regs, not available to the allocator.
let allocable = regs.len();
regs.push((gpr(15).to_real_reg(), "%r15".into()));
regs.push((gpr(0).to_real_reg(), "%r0".into()));
regs.push((gpr(1).to_real_reg(), "%r1".into()));
// Assert sanity: the indices in the register structs must match their
// actual indices in the array.
for (i, reg) in regs.iter().enumerate() {
assert_eq!(i, reg.0.get_index());
pub fn create_machine_env(_flags: &settings::Flags) -> MachineEnv {
fn preg(r: Reg) -> PReg {
r.to_real_reg().unwrap().into()
}
RealRegUniverse {
regs,
allocable,
allocable_by_class,
MachineEnv {
preferred_regs_by_class: [
vec![
// no r0; can't use for addressing?
// no r1; it is our spilltmp.
preg(gpr(2)),
preg(gpr(3)),
preg(gpr(4)),
preg(gpr(5)),
],
vec![
preg(fpr(0)),
preg(fpr(1)),
preg(fpr(2)),
preg(fpr(3)),
preg(fpr(4)),
preg(fpr(5)),
preg(fpr(6)),
preg(fpr(7)),
],
],
non_preferred_regs_by_class: [
vec![
preg(gpr(6)),
preg(gpr(7)),
preg(gpr(8)),
preg(gpr(9)),
preg(gpr(10)),
preg(gpr(11)),
preg(gpr(12)),
// no r13; it is our scratch reg.
preg(gpr(14)),
// no r15; it is the stack pointer.
],
vec![
preg(fpr(8)),
preg(fpr(9)),
preg(fpr(10)),
preg(fpr(11)),
preg(fpr(12)),
preg(fpr(13)),
preg(fpr(14)),
// no f15; it is our scratch reg.
],
],
scratch_by_class: [preg(gpr(13)), preg(fpr(15))],
fixed_stack_slots: vec![],
}
}
pub fn show_reg(reg: Reg) -> String {
if let Some(rreg) = reg.to_real_reg() {
match rreg.class() {
RegClass::Int => format!("%r{}", rreg.hw_enc()),
RegClass::Float => format!("%f{}", rreg.hw_enc()),
}
} else {
format!("%{:?}", reg)
}
}
pub fn pretty_print_reg(reg: Reg, allocs: &mut AllocationConsumer<'_>) -> String {
let reg = allocs.next(reg);
show_reg(reg)
}

View File

@@ -1,8 +1,8 @@
//! Unwind information for System V ABI (s390x).
use crate::isa::unwind::systemv::RegisterMappingError;
use crate::machinst::{Reg, RegClass};
use gimli::{write::CommonInformationEntry, Encoding, Format, Register};
use regalloc::{Reg, RegClass};
/// Creates a new s390x common information entry (CIE).
pub fn create_cie() -> CommonInformationEntry {
@@ -64,10 +64,9 @@ pub fn map_reg(reg: Reg) -> Result<Register, RegisterMappingError> {
Register(31),
];
match reg.get_class() {
RegClass::I64 => Ok(GPR_MAP[reg.get_hw_encoding() as usize]),
RegClass::F64 => Ok(FPR_MAP[reg.get_hw_encoding() as usize]),
_ => Err(RegisterMappingError::UnsupportedRegisterBank("class?")),
match reg.class() {
RegClass::Int => Ok(GPR_MAP[reg.to_real_reg().unwrap().hw_enc() as usize]),
RegClass::Float => Ok(FPR_MAP[reg.to_real_reg().unwrap().hw_enc() as usize]),
}
}