diff --git a/cranelift/codegen/src/ir/condcodes.rs b/cranelift/codegen/src/ir/condcodes.rs index e998ada5c25f..6e16823504da 100644 --- a/cranelift/codegen/src/ir/condcodes.rs +++ b/cranelift/codegen/src/ir/condcodes.rs @@ -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 { @@ -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); @@ -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); @@ -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)); } diff --git a/cranelift/fuzzgen/src/function_generator.rs b/cranelift/fuzzgen/src/function_generator.rs index 14f0e2ece62c..6a980298509d 100644 --- a/cranelift/fuzzgen/src/function_generator.rs +++ b/cranelift/fuzzgen/src/function_generator.rs @@ -484,25 +484,6 @@ where Ok(CallConv::SystemV) } - fn generate_intcc(&mut self) -> Result { - 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 { // TODO: It would be nice if we could get these directly from cranelift let scalars = [ @@ -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,