From e8b18b58a1b1606b94773252ca3caf7557429550 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 12 Oct 2021 14:53:33 +0200 Subject: [PATCH 1/6] Remove is_ghost --- cranelift/codegen/meta/src/cdsl/instructions.rs | 11 ----------- cranelift/codegen/meta/src/gen_inst.rs | 7 ------- cranelift/codegen/meta/src/shared/instructions.rs | 12 ++++-------- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/cranelift/codegen/meta/src/cdsl/instructions.rs b/cranelift/codegen/meta/src/cdsl/instructions.rs index 9db2bfba81dd..40491d9cecc3 100644 --- a/cranelift/codegen/meta/src/cdsl/instructions.rs +++ b/cranelift/codegen/meta/src/cdsl/instructions.rs @@ -76,8 +76,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? @@ -148,7 +146,6 @@ pub(crate) struct InstructionBuilder { is_indirect_branch: bool, is_call: bool, is_return: bool, - is_ghost: bool, can_load: bool, can_store: bool, can_trap: bool, @@ -171,7 +168,6 @@ impl InstructionBuilder { is_indirect_branch: false, is_call: false, is_return: false, - is_ghost: false, can_load: false, can_store: false, can_trap: false, @@ -228,12 +224,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 @@ -303,7 +293,6 @@ impl InstructionBuilder { is_indirect_branch: self.is_indirect_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, diff --git a/cranelift/codegen/meta/src/gen_inst.rs b/cranelift/codegen/meta/src/gen_inst.rs index 13f4776d3bfd..c8c91ad60400 100644 --- a/cranelift/codegen/meta/src/gen_inst.rs +++ b/cranelift/codegen/meta/src/gen_inst.rs @@ -489,13 +489,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, diff --git a/cranelift/codegen/meta/src/shared/instructions.rs b/cranelift/codegen/meta/src/shared/instructions.rs index 01865ccba12c..9ddca0bb8240 100644 --- a/cranelift/codegen/meta/src/shared/instructions.rs +++ b/cranelift/codegen/meta/src/shared/instructions.rs @@ -2047,8 +2047,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( @@ -2083,8 +2082,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"); @@ -4386,8 +4384,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( @@ -4417,8 +4414,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 From 99114547be6270adbc8bd80998ab1ce93715c040 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 12 Oct 2021 14:54:39 +0200 Subject: [PATCH 2/6] Remove clobbers_all_regs --- cranelift/codegen/meta/src/cdsl/instructions.rs | 5 ----- cranelift/codegen/meta/src/gen_inst.rs | 7 ------- 2 files changed, 12 deletions(-) diff --git a/cranelift/codegen/meta/src/cdsl/instructions.rs b/cranelift/codegen/meta/src/cdsl/instructions.rs index 40491d9cecc3..42cf0e3af440 100644 --- a/cranelift/codegen/meta/src/cdsl/instructions.rs +++ b/cranelift/codegen/meta/src/cdsl/instructions.rs @@ -86,8 +86,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 { @@ -150,7 +148,6 @@ pub(crate) struct InstructionBuilder { can_store: bool, can_trap: bool, other_side_effects: bool, - clobbers_all_regs: bool, } impl InstructionBuilder { @@ -172,7 +169,6 @@ impl InstructionBuilder { can_store: false, can_trap: false, other_side_effects: false, - clobbers_all_regs: false, } } @@ -298,7 +294,6 @@ impl InstructionBuilder { can_trap: self.can_trap, other_side_effects: self.other_side_effects, writes_cpu_flags, - clobbers_all_regs: self.clobbers_all_regs, }) } } diff --git a/cranelift/codegen/meta/src/gen_inst.rs b/cranelift/codegen/meta/src/gen_inst.rs index c8c91ad60400..fb10dff8cb08 100644 --- a/cranelift/codegen/meta/src/gen_inst.rs +++ b/cranelift/codegen/meta/src/gen_inst.rs @@ -524,13 +524,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(); From 466a446f8cc3c7ebf90c900d0723cec1a33d2538 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 12 Oct 2021 14:58:34 +0200 Subject: [PATCH 3/6] Remove OpcodeNumber --- cranelift/codegen/meta/src/cdsl/instructions.rs | 15 +++------------ cranelift/codegen/meta/src/gen_inst.rs | 17 +++++++---------- cranelift/codegen/meta/src/shared/mod.rs | 2 +- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/cranelift/codegen/meta/src/cdsl/instructions.rs b/cranelift/codegen/meta/src/cdsl/instructions.rs index 42cf0e3af440..5a7a1931ad78 100644 --- a/cranelift/codegen/meta/src/cdsl/instructions.rs +++ b/cranelift/codegen/meta/src/cdsl/instructions.rs @@ -1,5 +1,3 @@ -use cranelift_entity::{entity_impl, PrimaryMap}; - use std::fmt; use std::rc::Rc; @@ -9,11 +7,7 @@ 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; +pub(crate) type AllInstructions = Vec; pub(crate) struct InstructionGroupBuilder<'all_inst> { all_instructions: &'all_inst mut AllInstructions, @@ -25,8 +19,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 +35,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, @@ -240,7 +232,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); @@ -275,7 +267,6 @@ impl InstructionBuilder { Rc::new(InstructionContent { name: self.name, camel_name, - opcode_number, doc: self.doc, operands_in, operands_out, diff --git a/cranelift/codegen/meta/src/gen_inst.rs b/cranelift/codegen/meta/src/gen_inst.rs index fb10dff8cb08..1b3b42d73ad9 100644 --- a/cranelift/codegen/meta/src/gen_inst.rs +++ b/cranelift/codegen/meta/src/gen_inst.rs @@ -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 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 { @@ -535,7 +532,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::{}, // {}", @@ -551,7 +548,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), @@ -563,7 +560,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!( @@ -736,7 +733,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) @@ -1130,7 +1127,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(); } diff --git a/cranelift/codegen/meta/src/shared/mod.rs b/cranelift/codegen/meta/src/shared/mod.rs index 549ae7cf9931..5d530b27a465 100644 --- a/cranelift/codegen/meta/src/shared/mod.rs +++ b/cranelift/codegen/meta/src/shared/mod.rs @@ -54,7 +54,7 @@ impl Definitions { // of immediate fields. let mut format_structures: HashMap = 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!( From 6b32fcfceade4c6d7248576ddde79e70c920716c Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 12 Oct 2021 15:05:45 +0200 Subject: [PATCH 4/6] Remove Constraint --- .../codegen/meta/src/cdsl/instructions.rs | 9 -------- cranelift/codegen/meta/src/cdsl/mod.rs | 1 - .../codegen/meta/src/cdsl/type_inference.rs | 10 --------- .../codegen/meta/src/shared/instructions.rs | 22 ++++++------------- 4 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 cranelift/codegen/meta/src/cdsl/type_inference.rs diff --git a/cranelift/codegen/meta/src/cdsl/instructions.rs b/cranelift/codegen/meta/src/cdsl/instructions.rs index 5a7a1931ad78..110d5e6604db 100644 --- a/cranelift/codegen/meta/src/cdsl/instructions.rs +++ b/cranelift/codegen/meta/src/cdsl/instructions.rs @@ -4,7 +4,6 @@ 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; pub(crate) type AllInstructions = Vec; @@ -128,7 +127,6 @@ pub(crate) struct InstructionBuilder { format: Rc, operands_in: Option>, operands_out: Option>, - constraints: Option>, // See Instruction comments for the meaning of these fields. is_terminator: bool, @@ -150,7 +148,6 @@ impl InstructionBuilder { format: format.clone(), operands_in: None, operands_out: None, - constraints: None, is_terminator: false, is_branch: false, @@ -176,12 +173,6 @@ impl InstructionBuilder { self } - pub fn constraints(mut self, constraints: Vec) -> 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; diff --git a/cranelift/codegen/meta/src/cdsl/mod.rs b/cranelift/codegen/meta/src/cdsl/mod.rs index bf7acbbeb4aa..fa5f62562870 100644 --- a/cranelift/codegen/meta/src/cdsl/mod.rs +++ b/cranelift/codegen/meta/src/cdsl/mod.rs @@ -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; diff --git a/cranelift/codegen/meta/src/cdsl/type_inference.rs b/cranelift/codegen/meta/src/cdsl/type_inference.rs deleted file mode 100644 index 76fc1284f2fd..000000000000 --- a/cranelift/codegen/meta/src/cdsl/type_inference.rs +++ /dev/null @@ -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), -} diff --git a/cranelift/codegen/meta/src/shared/instructions.rs b/cranelift/codegen/meta/src/shared/instructions.rs index 9ddca0bb8240..816131331572 100644 --- a/cranelift/codegen/meta/src/shared/instructions.rs +++ b/cranelift/codegen/meta/src/shared/instructions.rs @@ -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; @@ -3750,8 +3749,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( @@ -3778,8 +3776,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( @@ -3860,8 +3857,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( @@ -4087,8 +4083,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( @@ -4108,8 +4103,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( @@ -4142,8 +4136,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( @@ -4165,8 +4158,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( From b0b8c1edbfb03f3207fafc176aecfc8d90ff77e3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 12 Oct 2021 15:07:49 +0200 Subject: [PATCH 5/6] Remove default_map --- cranelift/codegen/meta/src/default_map.rs | 20 -------------------- cranelift/codegen/meta/src/lib.rs | 1 - 2 files changed, 21 deletions(-) delete mode 100644 cranelift/codegen/meta/src/default_map.rs diff --git a/cranelift/codegen/meta/src/default_map.rs b/cranelift/codegen/meta/src/default_map.rs deleted file mode 100644 index 3a2be05dacc1..000000000000 --- a/cranelift/codegen/meta/src/default_map.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! Trait for extending `HashMap` with `get_or_default`. -use std::collections::HashMap; -use std::hash::Hash; - -pub(crate) trait MapWithDefault { - fn get_or_default(&mut self, k: K) -> &mut V; -} - -impl MapWithDefault for HashMap { - 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), ""); -} diff --git a/cranelift/codegen/meta/src/lib.rs b/cranelift/codegen/meta/src/lib.rs index 20815ef8d2fc..44f0c4fd85c2 100644 --- a/cranelift/codegen/meta/src/lib.rs +++ b/cranelift/codegen/meta/src/lib.rs @@ -11,7 +11,6 @@ mod gen_inst; mod gen_settings; mod gen_types; -mod default_map; mod shared; mod unique_table; From b2d9faa4727ce8c719189d864e0fce09bf17c8cf Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 12 Oct 2021 15:10:54 +0200 Subject: [PATCH 6/6] Slightly simplify build script --- cranelift/codegen/build.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cranelift/codegen/build.rs b/cranelift/codegen/build.rs index 10def102be5b..51fcf4cbaaf5 100644 --- a/cranelift/codegen/build.rs +++ b/cranelift/codegen/build.rs @@ -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(),