Fix all dead-code warnings in cranelift-codegen-meta
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
use cranelift_codegen_shared::condcodes::IntCC;
|
||||
use cranelift_entity::{entity_impl, PrimaryMap};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::fmt::{Display, Error, Formatter};
|
||||
use std::rc::Rc;
|
||||
@@ -10,10 +8,9 @@ use crate::cdsl::camel_case;
|
||||
use crate::cdsl::formats::{FormatField, InstructionFormat};
|
||||
use crate::cdsl::operands::Operand;
|
||||
use crate::cdsl::type_inference::Constraint;
|
||||
use crate::cdsl::types::{LaneType, ReferenceType, ValueType, VectorType};
|
||||
use crate::cdsl::types::{LaneType, ReferenceType, ValueType};
|
||||
use crate::cdsl::typevar::TypeVar;
|
||||
|
||||
use crate::shared::formats::Formats;
|
||||
use crate::shared::types::{Bool, Float, Int, Reference};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
@@ -317,11 +314,6 @@ impl InstructionBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn clobbers_all_regs(mut self, val: bool) -> Self {
|
||||
self.clobbers_all_regs = val;
|
||||
self
|
||||
}
|
||||
|
||||
fn build(self, opcode_number: OpcodeNumber) -> Instruction {
|
||||
let operands_in = self.operands_in.unwrap_or_else(Vec::new);
|
||||
let operands_out = self.operands_out.unwrap_or_else(Vec::new);
|
||||
@@ -387,33 +379,20 @@ impl InstructionBuilder {
|
||||
#[derive(Clone)]
|
||||
pub(crate) enum ValueTypeOrAny {
|
||||
ValueType(ValueType),
|
||||
Any,
|
||||
}
|
||||
|
||||
impl ValueTypeOrAny {
|
||||
pub fn expect(self, msg: &str) -> ValueType {
|
||||
pub fn expect(self) -> ValueType {
|
||||
match self {
|
||||
ValueTypeOrAny::ValueType(vt) => vt,
|
||||
ValueTypeOrAny::Any => panic!("Unexpected Any: {}", msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The number of bits in the vector
|
||||
type VectorBitWidth = u64;
|
||||
|
||||
/// An parameter used for binding instructions to specific types or values
|
||||
pub(crate) enum BindParameter {
|
||||
Any,
|
||||
Lane(LaneType),
|
||||
Vector(LaneType, VectorBitWidth),
|
||||
Reference(ReferenceType),
|
||||
Immediate(Immediate),
|
||||
}
|
||||
|
||||
/// Constructor for more easily building vector parameters from any lane type
|
||||
pub(crate) fn vector(parameter: impl Into<LaneType>, vector_size: VectorBitWidth) -> BindParameter {
|
||||
BindParameter::Vector(parameter.into(), vector_size)
|
||||
}
|
||||
|
||||
impl From<Int> for BindParameter {
|
||||
@@ -446,22 +425,13 @@ impl From<Reference> for BindParameter {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Immediate> for BindParameter {
|
||||
fn from(imm: Immediate) -> Self {
|
||||
BindParameter::Immediate(imm)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) enum Immediate {
|
||||
// When needed, this enum should be expanded to include other immediate types (e.g. u8, u128).
|
||||
IntCC(IntCC),
|
||||
}
|
||||
pub(crate) enum Immediate {}
|
||||
|
||||
impl Display for Immediate {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||
fn fmt(&self, _f: &mut Formatter) -> Result<(), Error> {
|
||||
match self {
|
||||
Immediate::IntCC(x) => write!(f, "IntCC::{:?}", x),
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -530,28 +500,14 @@ impl Bindable for BoundInstruction {
|
||||
fn bind(&self, parameter: impl Into<BindParameter>) -> BoundInstruction {
|
||||
let mut modified = self.clone();
|
||||
match parameter.into() {
|
||||
BindParameter::Any => modified.value_types.push(ValueTypeOrAny::Any),
|
||||
BindParameter::Lane(lane_type) => modified
|
||||
.value_types
|
||||
.push(ValueTypeOrAny::ValueType(lane_type.into())),
|
||||
BindParameter::Vector(lane_type, vector_size_in_bits) => {
|
||||
let num_lanes = vector_size_in_bits / lane_type.lane_bits();
|
||||
assert!(
|
||||
num_lanes >= 2,
|
||||
"Minimum lane number for bind_vector is 2, found {}.",
|
||||
num_lanes,
|
||||
);
|
||||
let vector_type = ValueType::Vector(VectorType::new(lane_type, num_lanes));
|
||||
modified
|
||||
.value_types
|
||||
.push(ValueTypeOrAny::ValueType(vector_type));
|
||||
}
|
||||
BindParameter::Reference(reference_type) => {
|
||||
modified
|
||||
.value_types
|
||||
.push(ValueTypeOrAny::ValueType(reference_type.into()));
|
||||
}
|
||||
BindParameter::Immediate(immediate) => modified.immediate_values.push(immediate),
|
||||
}
|
||||
modified.verify_bindings().unwrap();
|
||||
modified
|
||||
@@ -767,41 +723,6 @@ fn is_ctrl_typevar_candidate(
|
||||
pub(crate) enum FormatPredicateKind {
|
||||
/// Is the field member equal to the expected value (stored here)?
|
||||
IsEqual(String),
|
||||
|
||||
/// Is the immediate instruction format field representable as an n-bit two's complement
|
||||
/// integer? (with width: first member, scale: second member).
|
||||
/// The predicate is true if the field is in the range: `-2^(width-1) -- 2^(width-1)-1` and a
|
||||
/// multiple of `2^scale`.
|
||||
IsSignedInt(usize, usize),
|
||||
|
||||
/// Is the immediate instruction format field representable as an n-bit unsigned integer? (with
|
||||
/// width: first member, scale: second member).
|
||||
/// The predicate is true if the field is in the range: `0 -- 2^width - 1` and a multiple of
|
||||
/// `2^scale`.
|
||||
IsUnsignedInt(usize, usize),
|
||||
|
||||
/// Is the immediate format field member an integer equal to zero?
|
||||
IsZeroInt,
|
||||
/// Is the immediate format field member equal to zero? (float32 version)
|
||||
IsZero32BitFloat,
|
||||
|
||||
/// Is the immediate format field member equal to zero? (float64 version)
|
||||
IsZero64BitFloat,
|
||||
|
||||
/// Is the immediate format field member equal zero in all lanes?
|
||||
IsAllZeroes,
|
||||
|
||||
/// Does the immediate format field member have ones in all bits of all lanes?
|
||||
IsAllOnes,
|
||||
|
||||
/// Has the value list (in member_name) the size specified in parameter?
|
||||
LengthEquals(usize),
|
||||
|
||||
/// Is the referenced function colocated?
|
||||
IsColocatedFunc,
|
||||
|
||||
/// Is the referenced data object colocated?
|
||||
IsColocatedData,
|
||||
}
|
||||
|
||||
#[derive(Clone, Hash, PartialEq, Eq)]
|
||||
@@ -812,19 +733,6 @@ pub(crate) struct FormatPredicateNode {
|
||||
}
|
||||
|
||||
impl FormatPredicateNode {
|
||||
fn new(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
kind: FormatPredicateKind,
|
||||
) -> Self {
|
||||
let member_name = format.imm_by_name(field_name).member;
|
||||
Self {
|
||||
format_name: format.name,
|
||||
member_name,
|
||||
kind,
|
||||
}
|
||||
}
|
||||
|
||||
fn new_raw(
|
||||
format: &InstructionFormat,
|
||||
member_name: &'static str,
|
||||
@@ -839,11 +747,6 @@ impl FormatPredicateNode {
|
||||
|
||||
fn destructuring_member_name(&self) -> &'static str {
|
||||
match &self.kind {
|
||||
FormatPredicateKind::LengthEquals(_) => {
|
||||
// Length operates on the argument value list.
|
||||
assert!(self.member_name == "args");
|
||||
"ref args"
|
||||
}
|
||||
_ => self.member_name,
|
||||
}
|
||||
}
|
||||
@@ -853,41 +756,6 @@ impl FormatPredicateNode {
|
||||
FormatPredicateKind::IsEqual(arg) => {
|
||||
format!("predicates::is_equal({}, {})", self.member_name, arg)
|
||||
}
|
||||
FormatPredicateKind::IsSignedInt(width, scale) => format!(
|
||||
"predicates::is_signed_int({}, {}, {})",
|
||||
self.member_name, width, scale
|
||||
),
|
||||
FormatPredicateKind::IsUnsignedInt(width, scale) => format!(
|
||||
"predicates::is_unsigned_int({}, {}, {})",
|
||||
self.member_name, width, scale
|
||||
),
|
||||
FormatPredicateKind::IsZeroInt => {
|
||||
format!("predicates::is_zero_int({})", self.member_name)
|
||||
}
|
||||
FormatPredicateKind::IsZero32BitFloat => {
|
||||
format!("predicates::is_zero_32_bit_float({})", self.member_name)
|
||||
}
|
||||
FormatPredicateKind::IsZero64BitFloat => {
|
||||
format!("predicates::is_zero_64_bit_float({})", self.member_name)
|
||||
}
|
||||
FormatPredicateKind::IsAllZeroes => format!(
|
||||
"predicates::is_all_zeroes(func.dfg.constants.get({}))",
|
||||
self.member_name
|
||||
),
|
||||
FormatPredicateKind::IsAllOnes => format!(
|
||||
"predicates::is_all_ones(func.dfg.constants.get({}))",
|
||||
self.member_name
|
||||
),
|
||||
FormatPredicateKind::LengthEquals(num) => format!(
|
||||
"predicates::has_length_of({}, {}, func)",
|
||||
self.member_name, num
|
||||
),
|
||||
FormatPredicateKind::IsColocatedFunc => {
|
||||
format!("predicates::is_colocated_func({}, func)", self.member_name,)
|
||||
}
|
||||
FormatPredicateKind::IsColocatedData => {
|
||||
format!("predicates::is_colocated_data({}, func)", self.member_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -926,9 +794,6 @@ pub(crate) enum InstructionPredicateNode {
|
||||
|
||||
/// An AND-combination of two or more other predicates.
|
||||
And(Vec<InstructionPredicateNode>),
|
||||
|
||||
/// An OR-combination of two or more other predicates.
|
||||
Or(Vec<InstructionPredicateNode>),
|
||||
}
|
||||
|
||||
impl InstructionPredicateNode {
|
||||
@@ -941,11 +806,6 @@ impl InstructionPredicateNode {
|
||||
.map(|x| x.rust_predicate(func_str))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" && "),
|
||||
InstructionPredicateNode::Or(nodes) => nodes
|
||||
.iter()
|
||||
.map(|x| x.rust_predicate(func_str))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" || "),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -967,9 +827,9 @@ impl InstructionPredicateNode {
|
||||
|
||||
pub fn is_type_predicate(&self) -> bool {
|
||||
match self {
|
||||
InstructionPredicateNode::FormatPredicate(_)
|
||||
| InstructionPredicateNode::And(_)
|
||||
| InstructionPredicateNode::Or(_) => false,
|
||||
InstructionPredicateNode::FormatPredicate(_) | InstructionPredicateNode::And(_) => {
|
||||
false
|
||||
}
|
||||
InstructionPredicateNode::TypePredicate(_) => true,
|
||||
}
|
||||
}
|
||||
@@ -977,7 +837,7 @@ impl InstructionPredicateNode {
|
||||
fn collect_leaves(&self) -> Vec<&InstructionPredicateNode> {
|
||||
let mut ret = Vec::new();
|
||||
match self {
|
||||
InstructionPredicateNode::And(nodes) | InstructionPredicateNode::Or(nodes) => {
|
||||
InstructionPredicateNode::And(nodes) => {
|
||||
for node in nodes {
|
||||
ret.extend(node.collect_leaves());
|
||||
}
|
||||
@@ -1004,10 +864,6 @@ impl InstructionPredicate {
|
||||
Self { node: None }
|
||||
}
|
||||
|
||||
pub fn unwrap(self) -> InstructionPredicateNode {
|
||||
self.node.unwrap()
|
||||
}
|
||||
|
||||
pub fn new_typevar_check(
|
||||
inst: &Instruction,
|
||||
type_var: &TypeVar,
|
||||
@@ -1032,18 +888,6 @@ impl InstructionPredicate {
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_field_equal(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
imm_value: String,
|
||||
) -> InstructionPredicateNode {
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
format,
|
||||
field_name,
|
||||
FormatPredicateKind::IsEqual(imm_value),
|
||||
))
|
||||
}
|
||||
|
||||
/// Used only for the AST module, which directly passes in the format field.
|
||||
pub fn new_is_field_equal_ast(
|
||||
format: &InstructionFormat,
|
||||
@@ -1057,127 +901,11 @@ impl InstructionPredicate {
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_signed_int(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
width: usize,
|
||||
scale: usize,
|
||||
) -> InstructionPredicateNode {
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
format,
|
||||
field_name,
|
||||
FormatPredicateKind::IsSignedInt(width, scale),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_unsigned_int(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
width: usize,
|
||||
scale: usize,
|
||||
) -> InstructionPredicateNode {
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
format,
|
||||
field_name,
|
||||
FormatPredicateKind::IsUnsignedInt(width, scale),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_zero_int(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
) -> InstructionPredicateNode {
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
format,
|
||||
field_name,
|
||||
FormatPredicateKind::IsZeroInt,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_zero_32bit_float(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
) -> InstructionPredicateNode {
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
format,
|
||||
field_name,
|
||||
FormatPredicateKind::IsZero32BitFloat,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_zero_64bit_float(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
) -> InstructionPredicateNode {
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
format,
|
||||
field_name,
|
||||
FormatPredicateKind::IsZero64BitFloat,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_all_zeroes(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
) -> InstructionPredicateNode {
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
format,
|
||||
field_name,
|
||||
FormatPredicateKind::IsAllZeroes,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_all_ones(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
) -> InstructionPredicateNode {
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
format,
|
||||
field_name,
|
||||
FormatPredicateKind::IsAllOnes,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_length_equals(format: &InstructionFormat, size: usize) -> InstructionPredicateNode {
|
||||
assert!(
|
||||
format.has_value_list,
|
||||
"the format must be variadic in number of arguments"
|
||||
);
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new_raw(
|
||||
format,
|
||||
"args",
|
||||
FormatPredicateKind::LengthEquals(size),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_colocated_func(
|
||||
format: &InstructionFormat,
|
||||
field_name: &'static str,
|
||||
) -> InstructionPredicateNode {
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
format,
|
||||
field_name,
|
||||
FormatPredicateKind::IsColocatedFunc,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_is_colocated_data(formats: &Formats) -> InstructionPredicateNode {
|
||||
let format = &formats.unary_global_value;
|
||||
InstructionPredicateNode::FormatPredicate(FormatPredicateNode::new(
|
||||
&*format,
|
||||
"global_value",
|
||||
FormatPredicateKind::IsColocatedData,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn and(mut self, new_node: InstructionPredicateNode) -> Self {
|
||||
let node = self.node;
|
||||
let mut and_nodes = match node {
|
||||
Some(node) => match node {
|
||||
InstructionPredicateNode::And(nodes) => nodes,
|
||||
InstructionPredicateNode::Or(_) => {
|
||||
panic!("Can't mix and/or without implementing operator precedence!")
|
||||
}
|
||||
_ => vec![node],
|
||||
},
|
||||
_ => Vec::new(),
|
||||
@@ -1187,23 +915,6 @@ impl InstructionPredicate {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn or(mut self, new_node: InstructionPredicateNode) -> Self {
|
||||
let node = self.node;
|
||||
let mut or_nodes = match node {
|
||||
Some(node) => match node {
|
||||
InstructionPredicateNode::Or(nodes) => nodes,
|
||||
InstructionPredicateNode::And(_) => {
|
||||
panic!("Can't mix and/or without implementing operator precedence!")
|
||||
}
|
||||
_ => vec![node],
|
||||
},
|
||||
_ => Vec::new(),
|
||||
};
|
||||
or_nodes.push(new_node);
|
||||
self.node = Some(InstructionPredicateNode::Or(or_nodes));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn rust_predicate(&self, func_str: &str) -> Option<String> {
|
||||
self.node.as_ref().map(|root| root.rust_predicate(func_str))
|
||||
}
|
||||
@@ -1232,40 +943,6 @@ entity_impl!(InstructionPredicateNumber);
|
||||
pub(crate) type InstructionPredicateMap =
|
||||
PrimaryMap<InstructionPredicateNumber, InstructionPredicate>;
|
||||
|
||||
/// A registry of predicates to help deduplicating them, during Encodings construction. When the
|
||||
/// construction process is over, it needs to be extracted with `extract` and associated to the
|
||||
/// TargetIsa.
|
||||
pub(crate) struct InstructionPredicateRegistry {
|
||||
/// Maps a predicate number to its actual predicate.
|
||||
map: InstructionPredicateMap,
|
||||
|
||||
/// Inverse map: maps a predicate to its predicate number. This is used before inserting a
|
||||
/// predicate, to check whether it already exists.
|
||||
inverted_map: HashMap<InstructionPredicate, InstructionPredicateNumber>,
|
||||
}
|
||||
|
||||
impl InstructionPredicateRegistry {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
map: PrimaryMap::new(),
|
||||
inverted_map: HashMap::new(),
|
||||
}
|
||||
}
|
||||
pub fn insert(&mut self, predicate: InstructionPredicate) -> InstructionPredicateNumber {
|
||||
match self.inverted_map.get(&predicate) {
|
||||
Some(&found) => found,
|
||||
None => {
|
||||
let key = self.map.push(predicate.clone());
|
||||
self.inverted_map.insert(predicate, key);
|
||||
key
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn extract(self) -> InstructionPredicateMap {
|
||||
self.map
|
||||
}
|
||||
}
|
||||
|
||||
/// An instruction specification, containing an instruction that has bound types or not.
|
||||
pub(crate) enum InstSpec {
|
||||
Inst(Instruction),
|
||||
|
||||
Reference in New Issue
Block a user