Skip to content

Commit

Permalink
cranelift: Centralize IntCC selection
Browse files Browse the repository at this point in the history
  • Loading branch information
afonso360 committed Sep 4, 2022
1 parent 006418e commit ca35541
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions cranelift/fuzzgen/src/function_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn insert_cmp(
let cc = *fgen.u.choose(float_cc)?;
builder.ins().fcmp(cc, lhs, rhs)
} else {
let cc = *fgen.u.choose(IntCC::all())?;
let cc = fgen.generate_icmp_intcc(args[0])?;
builder.ins().icmp(cc, lhs, rhs)
};

Expand Down Expand Up @@ -458,9 +458,6 @@ const OPCODE_SIGNATURES: &'static [(
(Opcode::Icmp, &[I16, I16], &[B1], insert_cmp),
(Opcode::Icmp, &[I32, I32], &[B1], insert_cmp),
(Opcode::Icmp, &[I64, I64], &[B1], insert_cmp),
// TODO: icmp of/nof broken for i128 on x86_64
// See: https://github.com/bytecodealliance/wasmtime/issues/4406
#[cfg(not(target_arch = "x86_64"))]
(Opcode::Icmp, &[I128, I128], &[B1], insert_cmp),
// Stack Access
(Opcode::StackStore, &[I8], &[], insert_stack_store),
Expand Down Expand Up @@ -534,6 +531,29 @@ where
Ok(self.u.int_in_range(param.clone())?)
}

fn generate_icmp_intcc(&mut self, icmp_ty: Type) -> Result<IntCC> {
// TODO: icmp of/nof broken for i128 on x86_64
// See: https://github.com/bytecodealliance/wasmtime/issues/4406
let int_ccs = if cfg!(target_arch = "x86_64") && icmp_ty == I128 {
&[
IntCC::Equal,
IntCC::NotEqual,
IntCC::SignedLessThan,
IntCC::SignedGreaterThanOrEqual,
IntCC::SignedGreaterThan,
IntCC::SignedLessThanOrEqual,
IntCC::UnsignedLessThan,
IntCC::UnsignedGreaterThanOrEqual,
IntCC::UnsignedGreaterThan,
IntCC::UnsignedLessThanOrEqual,
]
} else {
IntCC::all()
};

Ok(*self.u.choose(int_ccs)?)
}

fn generate_callconv(&mut self) -> Result<CallConv> {
// TODO: Generate random CallConvs per target
Ok(CallConv::SystemV)
Expand Down Expand Up @@ -749,14 +769,9 @@ where

fn generate_bricmp(&mut self, builder: &mut FunctionBuilder) -> Result<()> {
let (block, args) = self.generate_target_block(builder)?;
let cond = *self.u.choose(IntCC::all())?;

let bricmp_types = [
I8, I16, I32,
I64,
// I128 - TODO: https://github.com/bytecodealliance/wasmtime/issues/4406
];
let _type = *self.u.choose(&bricmp_types[..])?;
let _type = *self.u.choose(&[I8, I16, I32, I64, I128])?;
let cc = self.generate_icmp_intcc(_type)?;

let lhs_var = self.get_variable_of_type(_type)?;
let lhs_val = builder.use_var(lhs_var);
Expand All @@ -766,7 +781,7 @@ where

builder
.ins()
.br_icmp(cond, lhs_val, rhs_val, block, &args[..]);
.br_icmp(cc, lhs_val, rhs_val, block, &args[..]);

// After bricmp's we must generate a jump
self.generate_jump(builder)?;
Expand Down

0 comments on commit ca35541

Please sign in to comment.