Skip to content

Commit

Permalink
Merge pull request #3447 from bjorn3/remove_unused_inst_flags
Browse files Browse the repository at this point in the history
Remove various unused things from the meta crate
  • Loading branch information
cfallin authored Oct 13, 2021
2 parents 59a9bd6 + b2d9faa commit 14cde24
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 126 deletions.
11 changes: 2 additions & 9 deletions cranelift/codegen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(),
Expand Down
40 changes: 3 additions & 37 deletions cranelift/codegen/meta/src/cdsl/instructions.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -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?
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}

Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -279,7 +248,6 @@ impl InstructionBuilder {
Rc::new(InstructionContent {
name: self.name,
camel_name,
opcode_number,
doc: self.doc,
operands_in,
operands_out,
Expand All @@ -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,
})
}
}
Expand Down
1 change: 0 additions & 1 deletion cranelift/codegen/meta/src/cdsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 0 additions & 10 deletions cranelift/codegen/meta/src/cdsl/type_inference.rs

This file was deleted.

20 changes: 0 additions & 20 deletions cranelift/codegen/meta/src/default_map.rs

This file was deleted.

31 changes: 7 additions & 24 deletions cranelift/codegen/meta/src/gen_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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::{}, // {}",
Expand All @@ -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),
Expand All @@ -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!(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down
1 change: 0 additions & 1 deletion cranelift/codegen/meta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mod gen_inst;
mod gen_settings;
mod gen_types;

mod default_map;
mod shared;
mod unique_table;

Expand Down
Loading

0 comments on commit 14cde24

Please sign in to comment.