Merge pull request #3447 from bjorn3/remove_unused_inst_flags

Remove various unused things from the meta crate
This commit is contained in:
Chris Fallin
2021-10-13 11:31:31 -07:00
committed by GitHub
9 changed files with 24 additions and 126 deletions

View File

@@ -46,15 +46,7 @@ fn main() {
isa_targets isa_targets
}; };
let cur_dir = env::current_dir().expect("Can't access current working directory"); println!("cargo:rerun-if-changed=build.rs");
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()
);
if let Err(err) = meta::generate(&isas, &out_dir) { if let Err(err) = meta::generate(&isas, &out_dir) {
eprintln!("Error: {}", err); eprintln!("Error: {}", err);
@@ -74,6 +66,7 @@ fn main() {
#[cfg(feature = "rebuild-peephole-optimizers")] #[cfg(feature = "rebuild-peephole-optimizers")]
{ {
let cur_dir = env::current_dir().expect("Can't access current working directory");
std::fs::write( std::fs::write(
std::path::Path::new(&out_dir).join("CRANELIFT_CODEGEN_PATH"), std::path::Path::new(&out_dir).join("CRANELIFT_CODEGEN_PATH"),
cur_dir.to_str().unwrap(), cur_dir.to_str().unwrap(),

View File

@@ -1,19 +1,12 @@
use cranelift_entity::{entity_impl, PrimaryMap};
use std::fmt; use std::fmt;
use std::rc::Rc; use std::rc::Rc;
use crate::cdsl::camel_case; use crate::cdsl::camel_case;
use crate::cdsl::formats::InstructionFormat; use crate::cdsl::formats::InstructionFormat;
use crate::cdsl::operands::Operand; use crate::cdsl::operands::Operand;
use crate::cdsl::type_inference::Constraint;
use crate::cdsl::typevar::TypeVar; use crate::cdsl::typevar::TypeVar;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub(crate) type AllInstructions = Vec<Instruction>;
pub(crate) struct OpcodeNumber(u32);
entity_impl!(OpcodeNumber);
pub(crate) type AllInstructions = PrimaryMap<OpcodeNumber, Instruction>;
pub(crate) struct InstructionGroupBuilder<'all_inst> { pub(crate) struct InstructionGroupBuilder<'all_inst> {
all_instructions: &'all_inst mut AllInstructions, all_instructions: &'all_inst mut AllInstructions,
@@ -25,8 +18,7 @@ impl<'all_inst> InstructionGroupBuilder<'all_inst> {
} }
pub fn push(&mut self, builder: InstructionBuilder) { pub fn push(&mut self, builder: InstructionBuilder) {
let opcode_number = OpcodeNumber(self.all_instructions.next_key().as_u32()); let inst = builder.build();
let inst = builder.build(opcode_number);
self.all_instructions.push(inst); self.all_instructions.push(inst);
} }
} }
@@ -42,7 +34,6 @@ pub(crate) struct InstructionContent {
/// Instruction mnemonic, also becomes opcode name. /// Instruction mnemonic, also becomes opcode name.
pub name: String, pub name: String,
pub camel_name: String, pub camel_name: String,
pub opcode_number: OpcodeNumber,
/// Documentation string. /// Documentation string.
pub doc: String, pub doc: String,
@@ -74,8 +65,6 @@ pub(crate) struct InstructionContent {
pub is_call: bool, pub is_call: bool,
/// Is this a return instruction? /// Is this a return instruction?
pub is_return: bool, pub is_return: bool,
/// Is this a ghost instruction?
pub is_ghost: bool,
/// Can this instruction read from memory? /// Can this instruction read from memory?
pub can_load: bool, pub can_load: bool,
/// Can this instruction write to memory? /// Can this instruction write to memory?
@@ -86,8 +75,6 @@ pub(crate) struct InstructionContent {
pub other_side_effects: bool, pub other_side_effects: bool,
/// Does this instruction write to CPU flags? /// Does this instruction write to CPU flags?
pub writes_cpu_flags: bool, pub writes_cpu_flags: bool,
/// Should this opcode be considered to clobber all live registers, during regalloc?
pub clobbers_all_regs: bool,
} }
impl InstructionContent { impl InstructionContent {
@@ -138,19 +125,16 @@ pub(crate) struct InstructionBuilder {
format: Rc<InstructionFormat>, format: Rc<InstructionFormat>,
operands_in: Option<Vec<Operand>>, operands_in: Option<Vec<Operand>>,
operands_out: Option<Vec<Operand>>, operands_out: Option<Vec<Operand>>,
constraints: Option<Vec<Constraint>>,
// See Instruction comments for the meaning of these fields. // See Instruction comments for the meaning of these fields.
is_terminator: bool, is_terminator: bool,
is_branch: bool, is_branch: bool,
is_call: bool, is_call: bool,
is_return: bool, is_return: bool,
is_ghost: bool,
can_load: bool, can_load: bool,
can_store: bool, can_store: bool,
can_trap: bool, can_trap: bool,
other_side_effects: bool, other_side_effects: bool,
clobbers_all_regs: bool,
} }
impl InstructionBuilder { impl InstructionBuilder {
@@ -161,18 +145,15 @@ impl InstructionBuilder {
format: format.clone(), format: format.clone(),
operands_in: None, operands_in: None,
operands_out: None, operands_out: None,
constraints: None,
is_terminator: false, is_terminator: false,
is_branch: false, is_branch: false,
is_call: false, is_call: false,
is_return: false, is_return: false,
is_ghost: false,
can_load: false, can_load: false,
can_store: false, can_store: false,
can_trap: false, can_trap: false,
other_side_effects: false, other_side_effects: false,
clobbers_all_regs: false,
} }
} }
@@ -188,12 +169,6 @@ impl InstructionBuilder {
self 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)] #[allow(clippy::wrong_self_convention)]
pub fn is_terminator(mut self, val: bool) -> Self { pub fn is_terminator(mut self, val: bool) -> Self {
self.is_terminator = val; self.is_terminator = val;
@@ -218,12 +193,6 @@ impl InstructionBuilder {
self 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 { pub fn can_load(mut self, val: bool) -> Self {
self.can_load = val; self.can_load = val;
self self
@@ -244,7 +213,7 @@ impl InstructionBuilder {
self 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_in = self.operands_in.unwrap_or_else(Vec::new);
let operands_out = self.operands_out.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 { Rc::new(InstructionContent {
name: self.name, name: self.name,
camel_name, camel_name,
opcode_number,
doc: self.doc, doc: self.doc,
operands_in, operands_in,
operands_out, operands_out,
@@ -292,13 +260,11 @@ impl InstructionBuilder {
is_branch: self.is_branch, is_branch: self.is_branch,
is_call: self.is_call, is_call: self.is_call,
is_return: self.is_return, is_return: self.is_return,
is_ghost: self.is_ghost,
can_load: self.can_load, can_load: self.can_load,
can_store: self.can_store, can_store: self.can_store,
can_trap: self.can_trap, can_trap: self.can_trap,
other_side_effects: self.other_side_effects, other_side_effects: self.other_side_effects,
writes_cpu_flags, writes_cpu_flags,
clobbers_all_regs: self.clobbers_all_regs,
}) })
} }
} }

View File

@@ -8,7 +8,6 @@ pub mod instructions;
pub mod isa; pub mod isa;
pub mod operands; pub mod operands;
pub mod settings; pub mod settings;
pub mod type_inference;
pub mod types; pub mod types;
pub mod typevar; pub mod typevar;

View File

@@ -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),
}

View File

@@ -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), "");
}

View File

@@ -2,7 +2,6 @@
use std::fmt; use std::fmt;
use cranelift_codegen_shared::constant_hash; use cranelift_codegen_shared::constant_hash;
use cranelift_entity::EntityRef;
use crate::cdsl::camel_case; use crate::cdsl::camel_case;
use crate::cdsl::formats::InstructionFormat; use crate::cdsl::formats::InstructionFormat;
@@ -388,7 +387,7 @@ fn gen_bool_accessor<T: Fn(&Instruction) -> bool>(
fmtln!(fmt, "pub fn {}(self) -> bool {{", name); fmtln!(fmt, "pub fn {}(self) -> bool {{", name);
fmt.indent(|fmt| { fmt.indent(|fmt| {
let mut m = Match::new("self"); let mut m = Match::new("self");
for inst in all_inst.values() { for inst in all_inst.iter() {
if get_attr(inst) { if get_attr(inst) {
m.arm_no_fields(format!("Self::{}", inst.camel_name), "true"); 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.line("pub enum Opcode {");
fmt.indent(|fmt| { fmt.indent(|fmt| {
let mut is_first_opcode = true; 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)); fmt.doc_comment(format!("`{}`. ({})", inst, inst.format.name));
// Document polymorphism. // Document polymorphism.
@@ -440,8 +439,6 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
// Enum variant itself. // Enum variant itself.
if is_first_opcode { 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); fmtln!(fmt, "{} = 1,", inst.camel_name);
is_first_opcode = false; is_first_opcode = false;
} else { } else {
@@ -482,13 +479,6 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
"Is this a return instruction?", "Is this a return instruction?",
fmt, fmt,
); );
gen_bool_accessor(
all_inst,
|inst| inst.is_ghost,
"is_ghost",
"Is this a ghost instruction?",
fmt,
);
gen_bool_accessor( gen_bool_accessor(
all_inst, all_inst,
|inst| inst.can_load, |inst| inst.can_load,
@@ -524,13 +514,6 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
"Does this instruction write to CPU flags?", "Does this instruction write to CPU flags?",
fmt, 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.line("}");
fmt.empty_line(); fmt.empty_line();
@@ -542,7 +525,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
all_inst.len() all_inst.len()
); );
fmt.indent(|fmt| { fmt.indent(|fmt| {
for inst in all_inst.values() { for inst in all_inst.iter() {
fmtln!( fmtln!(
fmt, fmt,
"InstructionFormat::{}, // {}", "InstructionFormat::{}, // {}",
@@ -558,7 +541,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
fmt.line("fn opcode_name(opc: Opcode) -> &\'static str {"); fmt.line("fn opcode_name(opc: Opcode) -> &\'static str {");
fmt.indent(|fmt| { fmt.indent(|fmt| {
let mut m = Match::new("opc"); let mut m = Match::new("opc");
for inst in all_inst.values() { for inst in all_inst.iter() {
m.arm_no_fields( m.arm_no_fields(
format!("Opcode::{}", inst.camel_name), format!("Opcode::{}", inst.camel_name),
format!("\"{}\"", inst.name), format!("\"{}\"", inst.name),
@@ -570,7 +553,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
fmt.empty_line(); fmt.empty_line();
// Generate an opcode hash table for looking up opcodes by name. // 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) constant_hash::simple_hash(&inst.name)
}); });
fmtln!( fmtln!(
@@ -743,7 +726,7 @@ fn gen_type_constraints(all_inst: &AllInstructions, fmt: &mut Formatter) {
all_inst.len() all_inst.len()
); );
fmt.indent(|fmt| { 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 (ctrl_typevar, ctrl_typeset) = if let Some(poly) = &inst.polymorphic_info {
let index = type_sets.add(&*poly.ctrl_typevar.get_raw_typeset()); let index = type_sets.add(&*poly.ctrl_typevar.get_raw_typeset());
(Some(&poly.ctrl_typevar), index) (Some(&poly.ctrl_typevar), index)
@@ -1137,7 +1120,7 @@ fn gen_builder(
); );
fmt.line("pub trait InstBuilder<'f>: InstBuilderBase<'f> {"); fmt.line("pub trait InstBuilder<'f>: InstBuilderBase<'f> {");
fmt.indent(|fmt| { fmt.indent(|fmt| {
for inst in instructions.values() { for inst in instructions.iter() {
gen_inst_builder(inst, &*inst.format, fmt); gen_inst_builder(inst, &*inst.format, fmt);
fmt.empty_line(); fmt.empty_line();
} }

View File

@@ -11,7 +11,6 @@ mod gen_inst;
mod gen_settings; mod gen_settings;
mod gen_types; mod gen_types;
mod default_map;
mod shared; mod shared;
mod unique_table; mod unique_table;

View File

@@ -4,7 +4,6 @@ use crate::cdsl::instructions::{
AllInstructions, InstructionBuilder as Inst, InstructionGroupBuilder, AllInstructions, InstructionBuilder as Inst, InstructionGroupBuilder,
}; };
use crate::cdsl::operands::Operand; use crate::cdsl::operands::Operand;
use crate::cdsl::type_inference::Constraint::WiderOrEq;
use crate::cdsl::types::{LaneType, ValueType}; use crate::cdsl::types::{LaneType, ValueType};
use crate::cdsl::typevar::{Interval, TypeSetBuilder, TypeVar}; use crate::cdsl::typevar::{Interval, TypeSetBuilder, TypeVar};
use crate::shared::formats::Formats; use crate::shared::formats::Formats;
@@ -1815,8 +1814,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![lo, hi]) .operands_out(vec![lo, hi]),
.is_ghost(true),
); );
let Any128 = &TypeVar::new( let Any128 = &TypeVar::new(
@@ -1851,8 +1849,7 @@ pub(crate) fn define(
&formats.binary, &formats.binary,
) )
.operands_in(vec![x, y]) .operands_in(vec![x, y])
.operands_out(vec![a]) .operands_out(vec![a]),
.is_ghost(true),
); );
let c = &Operand::new("c", &TxN.as_bool()).with_doc("Controlling vector"); let c = &Operand::new("c", &TxN.as_bool()).with_doc("Controlling vector");
@@ -3520,8 +3517,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![a]) .operands_out(vec![a]),
.constraints(vec![WiderOrEq(Bool.clone(), BoolTo.clone())]),
); );
let BoolTo = &TypeVar::new( let BoolTo = &TypeVar::new(
@@ -3548,8 +3544,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![a]) .operands_out(vec![a]),
.constraints(vec![WiderOrEq(BoolTo.clone(), Bool.clone())]),
); );
let IntTo = &TypeVar::new( let IntTo = &TypeVar::new(
@@ -3630,8 +3625,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![a]) .operands_out(vec![a]),
.constraints(vec![WiderOrEq(Int.clone(), IntTo.clone())]),
); );
let I16or32or64xN = &TypeVar::new( let I16or32or64xN = &TypeVar::new(
@@ -3857,8 +3851,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![a]) .operands_out(vec![a]),
.constraints(vec![WiderOrEq(IntTo.clone(), Int.clone())]),
); );
ig.push( ig.push(
@@ -3878,8 +3871,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![a]) .operands_out(vec![a]),
.constraints(vec![WiderOrEq(IntTo.clone(), Int.clone())]),
); );
let FloatTo = &TypeVar::new( let FloatTo = &TypeVar::new(
@@ -3912,8 +3904,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![a]) .operands_out(vec![a]),
.constraints(vec![WiderOrEq(FloatTo.clone(), Float.clone())]),
); );
ig.push( ig.push(
@@ -3935,8 +3926,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![a]) .operands_out(vec![a]),
.constraints(vec![WiderOrEq(Float.clone(), FloatTo.clone())]),
); );
let F64x2 = &TypeVar::new( let F64x2 = &TypeVar::new(
@@ -4154,8 +4144,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![lo, hi]) .operands_out(vec![lo, hi]),
.is_ghost(true),
); );
let NarrowInt = &TypeVar::new( let NarrowInt = &TypeVar::new(
@@ -4185,8 +4174,7 @@ pub(crate) fn define(
&formats.binary, &formats.binary,
) )
.operands_in(vec![lo, hi]) .operands_in(vec![lo, hi])
.operands_out(vec![a]) .operands_out(vec![a]),
.is_ghost(true),
); );
// Instructions relating to atomic memory accesses and fences // Instructions relating to atomic memory accesses and fences

View File

@@ -54,7 +54,7 @@ impl Definitions {
// of immediate fields. // of immediate fields.
let mut format_structures: HashMap<FormatStructure, &InstructionFormat> = HashMap::new(); 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. // Check name.
if let Some(existing_format) = format_names.get(&inst.format.name) { if let Some(existing_format) = format_names.get(&inst.format.name) {
assert!( assert!(