Merge pull request #3447 from bjorn3/remove_unused_inst_flags
Remove various unused things from the meta crate
This commit is contained in:
@@ -46,15 +46,7 @@ fn main() {
|
||||
isa_targets
|
||||
};
|
||||
|
||||
let cur_dir = env::current_dir().expect("Can't access current working directory");
|
||||
let crate_dir = cur_dir.as_path();
|
||||
|
||||
// Make sure we rebuild if this build script changes (will not happen with
|
||||
// if the path to this file contains non-UTF-8 bytes).
|
||||
println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
crate_dir.join("build.rs").to_str().unwrap()
|
||||
);
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
||||
if let Err(err) = meta::generate(&isas, &out_dir) {
|
||||
eprintln!("Error: {}", err);
|
||||
@@ -74,6 +66,7 @@ fn main() {
|
||||
|
||||
#[cfg(feature = "rebuild-peephole-optimizers")]
|
||||
{
|
||||
let cur_dir = env::current_dir().expect("Can't access current working directory");
|
||||
std::fs::write(
|
||||
std::path::Path::new(&out_dir).join("CRANELIFT_CODEGEN_PATH"),
|
||||
cur_dir.to_str().unwrap(),
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
use cranelift_entity::{entity_impl, PrimaryMap};
|
||||
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::cdsl::camel_case;
|
||||
use crate::cdsl::formats::InstructionFormat;
|
||||
use crate::cdsl::operands::Operand;
|
||||
use crate::cdsl::type_inference::Constraint;
|
||||
use crate::cdsl::typevar::TypeVar;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub(crate) struct OpcodeNumber(u32);
|
||||
entity_impl!(OpcodeNumber);
|
||||
|
||||
pub(crate) type AllInstructions = PrimaryMap<OpcodeNumber, Instruction>;
|
||||
pub(crate) type AllInstructions = Vec<Instruction>;
|
||||
|
||||
pub(crate) struct InstructionGroupBuilder<'all_inst> {
|
||||
all_instructions: &'all_inst mut AllInstructions,
|
||||
@@ -25,8 +18,7 @@ impl<'all_inst> InstructionGroupBuilder<'all_inst> {
|
||||
}
|
||||
|
||||
pub fn push(&mut self, builder: InstructionBuilder) {
|
||||
let opcode_number = OpcodeNumber(self.all_instructions.next_key().as_u32());
|
||||
let inst = builder.build(opcode_number);
|
||||
let inst = builder.build();
|
||||
self.all_instructions.push(inst);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +34,6 @@ pub(crate) struct InstructionContent {
|
||||
/// Instruction mnemonic, also becomes opcode name.
|
||||
pub name: String,
|
||||
pub camel_name: String,
|
||||
pub opcode_number: OpcodeNumber,
|
||||
|
||||
/// Documentation string.
|
||||
pub doc: String,
|
||||
@@ -74,8 +65,6 @@ pub(crate) struct InstructionContent {
|
||||
pub is_call: bool,
|
||||
/// Is this a return instruction?
|
||||
pub is_return: bool,
|
||||
/// Is this a ghost instruction?
|
||||
pub is_ghost: bool,
|
||||
/// Can this instruction read from memory?
|
||||
pub can_load: bool,
|
||||
/// Can this instruction write to memory?
|
||||
@@ -86,8 +75,6 @@ pub(crate) struct InstructionContent {
|
||||
pub other_side_effects: bool,
|
||||
/// Does this instruction write to CPU flags?
|
||||
pub writes_cpu_flags: bool,
|
||||
/// Should this opcode be considered to clobber all live registers, during regalloc?
|
||||
pub clobbers_all_regs: bool,
|
||||
}
|
||||
|
||||
impl InstructionContent {
|
||||
@@ -138,19 +125,16 @@ pub(crate) struct InstructionBuilder {
|
||||
format: Rc<InstructionFormat>,
|
||||
operands_in: Option<Vec<Operand>>,
|
||||
operands_out: Option<Vec<Operand>>,
|
||||
constraints: Option<Vec<Constraint>>,
|
||||
|
||||
// See Instruction comments for the meaning of these fields.
|
||||
is_terminator: bool,
|
||||
is_branch: bool,
|
||||
is_call: bool,
|
||||
is_return: bool,
|
||||
is_ghost: bool,
|
||||
can_load: bool,
|
||||
can_store: bool,
|
||||
can_trap: bool,
|
||||
other_side_effects: bool,
|
||||
clobbers_all_regs: bool,
|
||||
}
|
||||
|
||||
impl InstructionBuilder {
|
||||
@@ -161,18 +145,15 @@ impl InstructionBuilder {
|
||||
format: format.clone(),
|
||||
operands_in: None,
|
||||
operands_out: None,
|
||||
constraints: None,
|
||||
|
||||
is_terminator: false,
|
||||
is_branch: false,
|
||||
is_call: false,
|
||||
is_return: false,
|
||||
is_ghost: false,
|
||||
can_load: false,
|
||||
can_store: false,
|
||||
can_trap: false,
|
||||
other_side_effects: false,
|
||||
clobbers_all_regs: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,12 +169,6 @@ impl InstructionBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn constraints(mut self, constraints: Vec<Constraint>) -> Self {
|
||||
assert!(self.constraints.is_none());
|
||||
self.constraints = Some(constraints);
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn is_terminator(mut self, val: bool) -> Self {
|
||||
self.is_terminator = val;
|
||||
@@ -218,12 +193,6 @@ impl InstructionBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn is_ghost(mut self, val: bool) -> Self {
|
||||
self.is_ghost = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_load(mut self, val: bool) -> Self {
|
||||
self.can_load = val;
|
||||
self
|
||||
@@ -244,7 +213,7 @@ impl InstructionBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
fn build(self, opcode_number: OpcodeNumber) -> Instruction {
|
||||
fn build(self) -> Instruction {
|
||||
let operands_in = self.operands_in.unwrap_or_else(Vec::new);
|
||||
let operands_out = self.operands_out.unwrap_or_else(Vec::new);
|
||||
|
||||
@@ -279,7 +248,6 @@ impl InstructionBuilder {
|
||||
Rc::new(InstructionContent {
|
||||
name: self.name,
|
||||
camel_name,
|
||||
opcode_number,
|
||||
doc: self.doc,
|
||||
operands_in,
|
||||
operands_out,
|
||||
@@ -292,13 +260,11 @@ impl InstructionBuilder {
|
||||
is_branch: self.is_branch,
|
||||
is_call: self.is_call,
|
||||
is_return: self.is_return,
|
||||
is_ghost: self.is_ghost,
|
||||
can_load: self.can_load,
|
||||
can_store: self.can_store,
|
||||
can_trap: self.can_trap,
|
||||
other_side_effects: self.other_side_effects,
|
||||
writes_cpu_flags,
|
||||
clobbers_all_regs: self.clobbers_all_regs,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ pub mod instructions;
|
||||
pub mod isa;
|
||||
pub mod operands;
|
||||
pub mod settings;
|
||||
pub mod type_inference;
|
||||
pub mod types;
|
||||
pub mod typevar;
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
use crate::cdsl::typevar::TypeVar;
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub(crate) enum Constraint {
|
||||
/// Constraint specifying that a type var tv1 must be wider than or equal to type var tv2 at
|
||||
/// runtime. This requires that:
|
||||
/// 1) They have the same number of lanes
|
||||
/// 2) In a lane tv1 has at least as many bits as tv2.
|
||||
WiderOrEq(TypeVar, TypeVar),
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
//! Trait for extending `HashMap` with `get_or_default`.
|
||||
use std::collections::HashMap;
|
||||
use std::hash::Hash;
|
||||
|
||||
pub(crate) trait MapWithDefault<K, V: Default> {
|
||||
fn get_or_default(&mut self, k: K) -> &mut V;
|
||||
}
|
||||
|
||||
impl<K: Eq + Hash, V: Default> MapWithDefault<K, V> for HashMap<K, V> {
|
||||
fn get_or_default(&mut self, k: K) -> &mut V {
|
||||
self.entry(k).or_insert_with(V::default)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default() {
|
||||
let mut hash_map = HashMap::new();
|
||||
hash_map.insert(42, "hello");
|
||||
assert_eq!(*hash_map.get_or_default(43), "");
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
use std::fmt;
|
||||
|
||||
use cranelift_codegen_shared::constant_hash;
|
||||
use cranelift_entity::EntityRef;
|
||||
|
||||
use crate::cdsl::camel_case;
|
||||
use crate::cdsl::formats::InstructionFormat;
|
||||
@@ -388,7 +387,7 @@ fn gen_bool_accessor<T: Fn(&Instruction) -> bool>(
|
||||
fmtln!(fmt, "pub fn {}(self) -> bool {{", name);
|
||||
fmt.indent(|fmt| {
|
||||
let mut m = Match::new("self");
|
||||
for inst in all_inst.values() {
|
||||
for inst in all_inst.iter() {
|
||||
if get_attr(inst) {
|
||||
m.arm_no_fields(format!("Self::{}", inst.camel_name), "true");
|
||||
}
|
||||
@@ -424,7 +423,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
fmt.line("pub enum Opcode {");
|
||||
fmt.indent(|fmt| {
|
||||
let mut is_first_opcode = true;
|
||||
for inst in all_inst.values() {
|
||||
for inst in all_inst.iter() {
|
||||
fmt.doc_comment(format!("`{}`. ({})", inst, inst.format.name));
|
||||
|
||||
// Document polymorphism.
|
||||
@@ -440,8 +439,6 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
|
||||
// Enum variant itself.
|
||||
if is_first_opcode {
|
||||
assert!(inst.opcode_number.index() == 0);
|
||||
// TODO the python crate requires opcode numbers to start from one.
|
||||
fmtln!(fmt, "{} = 1,", inst.camel_name);
|
||||
is_first_opcode = false;
|
||||
} else {
|
||||
@@ -482,13 +479,6 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
"Is this a return instruction?",
|
||||
fmt,
|
||||
);
|
||||
gen_bool_accessor(
|
||||
all_inst,
|
||||
|inst| inst.is_ghost,
|
||||
"is_ghost",
|
||||
"Is this a ghost instruction?",
|
||||
fmt,
|
||||
);
|
||||
gen_bool_accessor(
|
||||
all_inst,
|
||||
|inst| inst.can_load,
|
||||
@@ -524,13 +514,6 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
"Does this instruction write to CPU flags?",
|
||||
fmt,
|
||||
);
|
||||
gen_bool_accessor(
|
||||
all_inst,
|
||||
|inst| inst.clobbers_all_regs,
|
||||
"clobbers_all_regs",
|
||||
"Should this opcode be considered to clobber all the registers, during regalloc?",
|
||||
fmt,
|
||||
);
|
||||
});
|
||||
fmt.line("}");
|
||||
fmt.empty_line();
|
||||
@@ -542,7 +525,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
all_inst.len()
|
||||
);
|
||||
fmt.indent(|fmt| {
|
||||
for inst in all_inst.values() {
|
||||
for inst in all_inst.iter() {
|
||||
fmtln!(
|
||||
fmt,
|
||||
"InstructionFormat::{}, // {}",
|
||||
@@ -558,7 +541,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
fmt.line("fn opcode_name(opc: Opcode) -> &\'static str {");
|
||||
fmt.indent(|fmt| {
|
||||
let mut m = Match::new("opc");
|
||||
for inst in all_inst.values() {
|
||||
for inst in all_inst.iter() {
|
||||
m.arm_no_fields(
|
||||
format!("Opcode::{}", inst.camel_name),
|
||||
format!("\"{}\"", inst.name),
|
||||
@@ -570,7 +553,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
fmt.empty_line();
|
||||
|
||||
// Generate an opcode hash table for looking up opcodes by name.
|
||||
let hash_table = constant_hash::generate_table(all_inst.values(), all_inst.len(), |inst| {
|
||||
let hash_table = constant_hash::generate_table(all_inst.iter(), all_inst.len(), |inst| {
|
||||
constant_hash::simple_hash(&inst.name)
|
||||
});
|
||||
fmtln!(
|
||||
@@ -743,7 +726,7 @@ fn gen_type_constraints(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
all_inst.len()
|
||||
);
|
||||
fmt.indent(|fmt| {
|
||||
for inst in all_inst.values() {
|
||||
for inst in all_inst.iter() {
|
||||
let (ctrl_typevar, ctrl_typeset) = if let Some(poly) = &inst.polymorphic_info {
|
||||
let index = type_sets.add(&*poly.ctrl_typevar.get_raw_typeset());
|
||||
(Some(&poly.ctrl_typevar), index)
|
||||
@@ -1137,7 +1120,7 @@ fn gen_builder(
|
||||
);
|
||||
fmt.line("pub trait InstBuilder<'f>: InstBuilderBase<'f> {");
|
||||
fmt.indent(|fmt| {
|
||||
for inst in instructions.values() {
|
||||
for inst in instructions.iter() {
|
||||
gen_inst_builder(inst, &*inst.format, fmt);
|
||||
fmt.empty_line();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ mod gen_inst;
|
||||
mod gen_settings;
|
||||
mod gen_types;
|
||||
|
||||
mod default_map;
|
||||
mod shared;
|
||||
mod unique_table;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ use crate::cdsl::instructions::{
|
||||
AllInstructions, InstructionBuilder as Inst, InstructionGroupBuilder,
|
||||
};
|
||||
use crate::cdsl::operands::Operand;
|
||||
use crate::cdsl::type_inference::Constraint::WiderOrEq;
|
||||
use crate::cdsl::types::{LaneType, ValueType};
|
||||
use crate::cdsl::typevar::{Interval, TypeSetBuilder, TypeVar};
|
||||
use crate::shared::formats::Formats;
|
||||
@@ -1815,8 +1814,7 @@ pub(crate) fn define(
|
||||
&formats.unary,
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![lo, hi])
|
||||
.is_ghost(true),
|
||||
.operands_out(vec![lo, hi]),
|
||||
);
|
||||
|
||||
let Any128 = &TypeVar::new(
|
||||
@@ -1851,8 +1849,7 @@ pub(crate) fn define(
|
||||
&formats.binary,
|
||||
)
|
||||
.operands_in(vec![x, y])
|
||||
.operands_out(vec![a])
|
||||
.is_ghost(true),
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
let c = &Operand::new("c", &TxN.as_bool()).with_doc("Controlling vector");
|
||||
@@ -3520,8 +3517,7 @@ pub(crate) fn define(
|
||||
&formats.unary,
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![a])
|
||||
.constraints(vec![WiderOrEq(Bool.clone(), BoolTo.clone())]),
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
let BoolTo = &TypeVar::new(
|
||||
@@ -3548,8 +3544,7 @@ pub(crate) fn define(
|
||||
&formats.unary,
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![a])
|
||||
.constraints(vec![WiderOrEq(BoolTo.clone(), Bool.clone())]),
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
let IntTo = &TypeVar::new(
|
||||
@@ -3630,8 +3625,7 @@ pub(crate) fn define(
|
||||
&formats.unary,
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![a])
|
||||
.constraints(vec![WiderOrEq(Int.clone(), IntTo.clone())]),
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
let I16or32or64xN = &TypeVar::new(
|
||||
@@ -3857,8 +3851,7 @@ pub(crate) fn define(
|
||||
&formats.unary,
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![a])
|
||||
.constraints(vec![WiderOrEq(IntTo.clone(), Int.clone())]),
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
ig.push(
|
||||
@@ -3878,8 +3871,7 @@ pub(crate) fn define(
|
||||
&formats.unary,
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![a])
|
||||
.constraints(vec![WiderOrEq(IntTo.clone(), Int.clone())]),
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
let FloatTo = &TypeVar::new(
|
||||
@@ -3912,8 +3904,7 @@ pub(crate) fn define(
|
||||
&formats.unary,
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![a])
|
||||
.constraints(vec![WiderOrEq(FloatTo.clone(), Float.clone())]),
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
ig.push(
|
||||
@@ -3935,8 +3926,7 @@ pub(crate) fn define(
|
||||
&formats.unary,
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![a])
|
||||
.constraints(vec![WiderOrEq(Float.clone(), FloatTo.clone())]),
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
let F64x2 = &TypeVar::new(
|
||||
@@ -4154,8 +4144,7 @@ pub(crate) fn define(
|
||||
&formats.unary,
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![lo, hi])
|
||||
.is_ghost(true),
|
||||
.operands_out(vec![lo, hi]),
|
||||
);
|
||||
|
||||
let NarrowInt = &TypeVar::new(
|
||||
@@ -4185,8 +4174,7 @@ pub(crate) fn define(
|
||||
&formats.binary,
|
||||
)
|
||||
.operands_in(vec![lo, hi])
|
||||
.operands_out(vec![a])
|
||||
.is_ghost(true),
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
// Instructions relating to atomic memory accesses and fences
|
||||
|
||||
@@ -54,7 +54,7 @@ impl Definitions {
|
||||
// of immediate fields.
|
||||
let mut format_structures: HashMap<FormatStructure, &InstructionFormat> = HashMap::new();
|
||||
|
||||
for inst in self.all_instructions.values() {
|
||||
for inst in self.all_instructions.iter() {
|
||||
// Check name.
|
||||
if let Some(existing_format) = format_names.get(&inst.format.name) {
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user