Skip to content

Commit

Permalink
Remove IFLAGS/FFLAGS types (#5406)
Browse files Browse the repository at this point in the history
All instructions using the CPU flags types (IFLAGS/FFLAGS) were already
removed.  This patch completes the cleanup by removing all remaining
instructions that define values of CPU flags types, as well as the
types themselves.

Specifically, the following features are removed:
- The IFLAGS and FFLAGS types and the SpecialType category.
- Special handling of IFLAGS and FFLAGS in machinst/isle.rs and
  machinst/lower.rs.
- The ifcmp, ifcmp_imm, ffcmp, iadd_ifcin, iadd_ifcout, iadd_ifcarry,
  isub_ifbin, isub_ifbout, and isub_ifborrow instructions.
- The writes_cpu_flags instruction property.
- The flags verifier pass.
- Flags handling in the interpreter.

All of these features are currently unused; no functional change
intended by this patch.

This addresses #3249.
  • Loading branch information
uweigand authored Dec 9, 2022
1 parent 6e0a029 commit e913cf3
Show file tree
Hide file tree
Showing 42 changed files with 55 additions and 1,119 deletions.
6 changes: 0 additions & 6 deletions cranelift/codegen/meta/src/cdsl/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ pub(crate) struct InstructionContent {
pub can_trap: bool,
/// Does this instruction have other side effects besides can_* flags?
pub other_side_effects: bool,
/// Does this instruction write to CPU flags?
pub writes_cpu_flags: bool,
}

impl InstructionContent {
Expand Down Expand Up @@ -240,9 +238,6 @@ impl InstructionBuilder {
let polymorphic_info =
verify_polymorphic(&operands_in, &operands_out, &self.format, &value_opnums);

// Infer from output operands whether an instruction clobbers CPU flags or not.
let writes_cpu_flags = operands_out.iter().any(|op| op.is_cpu_flags());

let camel_name = camel_case(&self.name);

Rc::new(InstructionContent {
Expand All @@ -264,7 +259,6 @@ impl InstructionBuilder {
can_store: self.can_store,
can_trap: self.can_trap,
other_side_effects: self.other_side_effects,
writes_cpu_flags,
})
}
}
Expand Down
11 changes: 0 additions & 11 deletions cranelift/codegen/meta/src/cdsl/operands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,6 @@ impl Operand {
_ => false,
}
}

pub fn is_cpu_flags(&self) -> bool {
match &self.kind.fields {
OperandKindFields::TypeVar(type_var)
if type_var.name == "iflags" || type_var.name == "fflags" =>
{
true
}
_ => false,
}
}
}

pub type EnumValues = HashMap<&'static str, &'static str>;
Expand Down
102 changes: 0 additions & 102 deletions cranelift/codegen/meta/src/cdsl/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ static RUST_NAME_PREFIX: &str = "ir::types::";
pub(crate) enum ValueType {
Lane(LaneType),
Reference(ReferenceType),
Special(SpecialType),
Vector(VectorType),
DynamicVector(DynamicVectorType),
}
Expand All @@ -29,11 +28,6 @@ impl ValueType {
LaneTypeIterator::new()
}

/// Iterate through all of the special types (neither lanes nor vectors).
pub fn all_special_types() -> SpecialTypeIterator {
SpecialTypeIterator::new()
}

pub fn all_reference_types() -> ReferenceTypeIterator {
ReferenceTypeIterator::new()
}
Expand All @@ -43,7 +37,6 @@ impl ValueType {
match *self {
ValueType::Lane(l) => l.doc(),
ValueType::Reference(r) => r.doc(),
ValueType::Special(s) => s.doc(),
ValueType::Vector(ref v) => v.doc(),
ValueType::DynamicVector(ref v) => v.doc(),
}
Expand All @@ -54,7 +47,6 @@ impl ValueType {
match *self {
ValueType::Lane(l) => l.lane_bits(),
ValueType::Reference(r) => r.lane_bits(),
ValueType::Special(s) => s.lane_bits(),
ValueType::Vector(ref v) => v.lane_bits(),
ValueType::DynamicVector(ref v) => v.lane_bits(),
}
Expand All @@ -78,7 +70,6 @@ impl ValueType {
match *self {
ValueType::Lane(l) => l.number(),
ValueType::Reference(r) => r.number(),
ValueType::Special(s) => s.number(),
ValueType::Vector(ref v) => v.number(),
ValueType::DynamicVector(ref v) => v.number(),
}
Expand All @@ -100,7 +91,6 @@ impl fmt::Display for ValueType {
match *self {
ValueType::Lane(l) => l.fmt(f),
ValueType::Reference(r) => r.fmt(f),
ValueType::Special(s) => s.fmt(f),
ValueType::Vector(ref v) => v.fmt(f),
ValueType::DynamicVector(ref v) => v.fmt(f),
}
Expand All @@ -121,13 +111,6 @@ impl From<ReferenceType> for ValueType {
}
}

/// Create a ValueType from a given special type.
impl From<SpecialType> for ValueType {
fn from(spec: SpecialType) -> Self {
ValueType::Special(spec)
}
}

/// Create a ValueType from a given vector type.
impl From<VectorType> for ValueType {
fn from(vector: VectorType) -> Self {
Expand Down Expand Up @@ -436,91 +419,6 @@ impl fmt::Debug for DynamicVectorType {
}
}

/// A concrete scalar type that is neither a vector nor a lane type.
///
/// Special types cannot be used to form vectors.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) enum SpecialType {
Flag(shared_types::Flag),
}

impl SpecialType {
/// Return a string containing the documentation comment for this special type.
pub fn doc(self) -> String {
match self {
SpecialType::Flag(shared_types::Flag::IFlags) => String::from(
"CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:`intcc` condition code.",
),
SpecialType::Flag(shared_types::Flag::FFlags) => String::from(
"CPU flags representing the result of a floating point comparison. These
flags can be tested with a :type:`floatcc` condition code.",
),
}
}

/// Return the number of bits in a lane.
pub fn lane_bits(self) -> u64 {
match self {
SpecialType::Flag(_) => 0,
}
}

/// Find the unique number associated with this special type.
pub fn number(self) -> u16 {
match self {
SpecialType::Flag(shared_types::Flag::IFlags) => 1,
SpecialType::Flag(shared_types::Flag::FFlags) => 2,
}
}
}

impl fmt::Display for SpecialType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SpecialType::Flag(shared_types::Flag::IFlags) => write!(f, "iflags"),
SpecialType::Flag(shared_types::Flag::FFlags) => write!(f, "fflags"),
}
}
}

impl fmt::Debug for SpecialType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match *self {
SpecialType::Flag(_) => format!("FlagsType({})", self),
}
)
}
}

impl From<shared_types::Flag> for SpecialType {
fn from(f: shared_types::Flag) -> Self {
SpecialType::Flag(f)
}
}

pub(crate) struct SpecialTypeIterator {
flag_iter: shared_types::FlagIterator,
}

impl SpecialTypeIterator {
fn new() -> Self {
Self {
flag_iter: shared_types::FlagIterator::new(),
}
}
}

impl Iterator for SpecialTypeIterator {
type Item = SpecialType;
fn next(&mut self) -> Option<Self::Item> {
self.flag_iter.next().map(SpecialType::from)
}
}

/// Reference type is scalar type, but not lane type.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct ReferenceType(pub shared_types::Reference);
Expand Down
Loading

0 comments on commit e913cf3

Please sign in to comment.