cranelift: Add coerce_bools_to_ints helper

This commit is contained in:
Afonso Bordado
2021-09-10 15:38:30 +01:00
parent d31bdff7db
commit 85d468dc5a
2 changed files with 19 additions and 9 deletions

View File

@@ -340,6 +340,19 @@ impl Type {
Err(()) => panic!("unable to determine architecture pointer width"),
}
}
/// Coerces boolean types (scalar and vectors) into their integer counterparts.
/// B1 is converted into I8.
pub fn coerce_bools_to_ints(self) -> Self {
let is_scalar_bool = self.is_bool();
let is_vector_bool = self.is_vector() && self.lane_type().is_bool();
if is_scalar_bool || is_vector_bool {
self.as_int()
} else {
self
}
}
}
impl Display for Type {