Skip to content

Commit

Permalink
cranelift: Add IntCC::all()
Browse files Browse the repository at this point in the history
  • Loading branch information
afonso360 committed Aug 15, 2022
1 parent 20adda7 commit 1234776
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 38 deletions.
39 changes: 21 additions & 18 deletions cranelift/codegen/src/ir/condcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ impl CondCode for IntCC {
}

impl IntCC {
/// Returns a slice with all possible [IntCC] values.
pub fn all() -> &'static [IntCC] {
&[
IntCC::Equal,
IntCC::NotEqual,
IntCC::SignedLessThan,
IntCC::SignedGreaterThanOrEqual,
IntCC::SignedGreaterThan,
IntCC::SignedLessThanOrEqual,
IntCC::UnsignedLessThan,
IntCC::UnsignedGreaterThanOrEqual,
IntCC::UnsignedGreaterThan,
IntCC::UnsignedLessThanOrEqual,
IntCC::Overflow,
IntCC::NotOverflow,
]
}

/// Get the corresponding IntCC with the equal component removed.
/// For conditions without a zero component, this is a no-op.
pub fn without_equal(self) -> Self {
Expand Down Expand Up @@ -342,24 +360,9 @@ mod tests {
use super::*;
use std::string::ToString;

static INT_ALL: [IntCC; 12] = [
IntCC::Equal,
IntCC::NotEqual,
IntCC::SignedLessThan,
IntCC::SignedGreaterThanOrEqual,
IntCC::SignedGreaterThan,
IntCC::SignedLessThanOrEqual,
IntCC::UnsignedLessThan,
IntCC::UnsignedGreaterThanOrEqual,
IntCC::UnsignedGreaterThan,
IntCC::UnsignedLessThanOrEqual,
IntCC::Overflow,
IntCC::NotOverflow,
];

#[test]
fn int_inverse() {
for r in &INT_ALL {
for r in &IntCC::all() {
let cc = *r;
let inv = cc.inverse();
assert!(cc != inv);
Expand All @@ -369,7 +372,7 @@ mod tests {

#[test]
fn int_reverse() {
for r in &INT_ALL {
for r in &IntCC::all() {
let cc = *r;
let rev = cc.reverse();
assert_eq!(rev.reverse(), cc);
Expand All @@ -378,7 +381,7 @@ mod tests {

#[test]
fn int_display() {
for r in &INT_ALL {
for r in &IntCC::all() {
let cc = *r;
assert_eq!(cc.to_string().parse(), Ok(cc));
}
Expand Down
21 changes: 1 addition & 20 deletions cranelift/fuzzgen/src/function_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,25 +484,6 @@ where
Ok(CallConv::SystemV)
}

fn generate_intcc(&mut self) -> Result<IntCC> {
Ok(*self.u.choose(
&[
IntCC::Equal,
IntCC::NotEqual,
IntCC::SignedLessThan,
IntCC::SignedGreaterThanOrEqual,
IntCC::SignedGreaterThan,
IntCC::SignedLessThanOrEqual,
IntCC::UnsignedLessThan,
IntCC::UnsignedGreaterThanOrEqual,
IntCC::UnsignedGreaterThan,
IntCC::UnsignedLessThanOrEqual,
IntCC::Overflow,
IntCC::NotOverflow,
][..],
)?)
}

fn generate_type(&mut self) -> Result<Type> {
// TODO: It would be nice if we could get these directly from cranelift
let scalars = [
Expand Down Expand Up @@ -707,7 +688,7 @@ where

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

let bricmp_types = [
I8, I16, I32,
Expand Down

0 comments on commit 1234776

Please sign in to comment.