Browse Source

Cranelift: Derive `Copy` for `InstructionData` (#5043)

* Cranelift: Derive `Copy` for `InstructionData`

And update `clone` calls to be copies.

* Add a test for `InstructionData`'s size
pull/5051/head
Nick Fitzgerald 2 years ago
committed by GitHub
parent
commit
03d77d4d6b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      cranelift/codegen/meta/src/gen_inst.rs
  2. 2
      cranelift/codegen/src/ir/function.rs
  3. 13
      cranelift/codegen/src/ir/instructions.rs
  4. 2
      cranelift/codegen/src/machinst/isle.rs
  5. 2
      cranelift/codegen/src/simple_gvn.rs

13
cranelift/codegen/meta/src/gen_inst.rs

@ -71,17 +71,16 @@ fn gen_formats(formats: &[&InstructionFormat], fmt: &mut Formatter) {
/// the SSA `Value` arguments.
fn gen_instruction_data(formats: &[&InstructionFormat], fmt: &mut Formatter) {
for (name, include_args) in &[("InstructionData", true), ("InstructionImms", false)] {
fmt.line("#[derive(Clone, Debug, PartialEq, Hash)]");
fmt.line("#[derive(Copy, Clone, Debug, PartialEq, Hash)]");
if !include_args {
// `InstructionImms` gets some extra derives: it acts like
// a sort of extended opcode and we want to allow for
// hashconsing via Eq. `Copy` also turns out to be useful.
fmt.line("#[derive(Copy, Eq)]");
// `InstructionImms` gets some extra derives: it acts like a sort of
// extended opcode and we want to allow for hashconsing via `Eq`.
fmt.line("#[derive(Eq)]");
}
fmt.line(r#"#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]"#);
fmt.line("#[allow(missing_docs)]");
// generate `enum InstructionData` or `enum InstructionImms`.
// (This comment exists so one can grep for `enum InstructionData`!)
// Generate `enum InstructionData` or `enum InstructionImms`. (This
// comment exists so one can grep for `enum InstructionData`!)
fmtln!(fmt, "pub enum {} {{", name);
fmt.indent(|fmt| {
for format in formats {

2
cranelift/codegen/src/ir/function.rs

@ -386,7 +386,7 @@ impl FunctionStencil {
.zip(self.dfg.inst_results(src))
.all(|(a, b)| self.dfg.value_type(*a) == self.dfg.value_type(*b)));
self.dfg[dst] = self.dfg[src].clone();
self.dfg[dst] = self.dfg[src];
self.layout.remove_inst(src);
}

13
cranelift/codegen/src/ir/instructions.rs

@ -755,6 +755,19 @@ mod tests {
use super::*;
use alloc::string::ToString;
#[test]
fn inst_data_is_copy() {
fn is_copy<T: Copy>() {}
is_copy::<InstructionData>();
}
#[test]
fn inst_data_size() {
// The size of `InstructionData` is performance sensitive, so make sure
// we don't regress it unintentionally.
assert_eq!(std::mem::size_of::<InstructionData>(), 16);
}
#[test]
fn opcodes() {
use core::mem;

2
cranelift/codegen/src/machinst/isle.rs

@ -226,7 +226,7 @@ macro_rules! isle_lower_prelude_methods {
#[inline]
fn inst_data(&mut self, inst: Inst) -> InstructionData {
self.lower_ctx.dfg()[inst].clone()
self.lower_ctx.dfg()[inst]
}
#[inline]

2
cranelift/codegen/src/simple_gvn.rs

@ -115,7 +115,7 @@ pub fn do_simple_gvn(func: &mut Function, domtree: &mut DominatorTree) {
let ctrl_typevar = func.dfg.ctrl_typevar(inst);
let key = HashKey {
inst: func.dfg[inst].clone(),
inst: func.dfg[inst],
ty: ctrl_typevar,
pos: &pos,
};

Loading…
Cancel
Save