Skip to content

Commit

Permalink
Refactor x64 PCC code to avoid deep pattern matches on Gpr/Xmm types;…
Browse files Browse the repository at this point in the history
… explicitly match every instruction kind.
  • Loading branch information
cfallin committed Oct 26, 2023
1 parent c1ed20c commit a0cfee2
Show file tree
Hide file tree
Showing 3 changed files with 543 additions and 314 deletions.
5 changes: 4 additions & 1 deletion cranelift/codegen/src/ir/pcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,10 @@ pub fn check_vcode_facts<B: LowerBackend + TargetIsa>(
let block = BlockIndex::new(block);
for inst in vcode.block_insns(block).iter() {
// Check any output facts on this inst.
backend.check_fact(&ctx, vcode, inst)?;
if let Err(e) = backend.check_fact(&ctx, vcode, inst) {
log::error!("Error checking instruction: {:?}", vcode[inst]);
return Err(e);
}

// If this is a branch, check that all block arguments subsume
// the assumed facts on the blockparams of successors.
Expand Down
16 changes: 13 additions & 3 deletions cranelift/codegen/src/isa/x64/inst/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,18 @@ macro_rules! newtype_of_reg {
$(
/// A newtype wrapper around `RegMem` for general-purpose registers.
#[derive(Clone, Debug)]
pub struct $newtype_reg_mem(pub RegMem);
pub struct $newtype_reg_mem(RegMem);

impl From<$newtype_reg_mem> for RegMem {
fn from(rm: $newtype_reg_mem) -> Self {
rm.0
}
}
impl<'a> From<&'a $newtype_reg_mem> for &'a RegMem {
fn from(rm: &'a $newtype_reg_mem) -> &'a RegMem {
&rm.0
}
}

impl From<$newtype_reg> for $newtype_reg_mem {
fn from(r: $newtype_reg) -> Self {
Expand Down Expand Up @@ -169,13 +174,18 @@ macro_rules! newtype_of_reg {
$(
/// A newtype wrapper around `RegMemImm`.
#[derive(Clone, Debug)]
pub struct $newtype_reg_mem_imm(pub RegMemImm);
pub struct $newtype_reg_mem_imm(RegMemImm);

impl From<$newtype_reg_mem_imm> for RegMemImm {
fn from(rmi: $newtype_reg_mem_imm) -> RegMemImm {
rmi.0
}
}
impl<'a> From<&'a $newtype_reg_mem_imm> for &'a RegMemImm {
fn from(rmi: &'a $newtype_reg_mem_imm) -> &'a RegMemImm {
&rmi.0
}
}

impl From<$newtype_reg> for $newtype_reg_mem_imm {
fn from(r: $newtype_reg) -> Self {
Expand Down Expand Up @@ -233,7 +243,7 @@ macro_rules! newtype_of_reg {
/// A newtype wrapper around `Imm8Reg`.
#[derive(Clone, Debug)]
#[allow(dead_code)] // Used by some newtypes and not others.
pub struct $newtype_imm8_reg(pub Imm8Reg);
pub struct $newtype_imm8_reg(Imm8Reg);

impl From<$newtype_reg> for $newtype_imm8_reg {
fn from(r: $newtype_reg) -> Self {
Expand Down
Loading

0 comments on commit a0cfee2

Please sign in to comment.