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
This commit is contained in:
@@ -71,17 +71,16 @@ fn gen_formats(formats: &[&InstructionFormat], fmt: &mut Formatter) {
|
|||||||
/// the SSA `Value` arguments.
|
/// the SSA `Value` arguments.
|
||||||
fn gen_instruction_data(formats: &[&InstructionFormat], fmt: &mut Formatter) {
|
fn gen_instruction_data(formats: &[&InstructionFormat], fmt: &mut Formatter) {
|
||||||
for (name, include_args) in &[("InstructionData", true), ("InstructionImms", false)] {
|
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 {
|
if !include_args {
|
||||||
// `InstructionImms` gets some extra derives: it acts like
|
// `InstructionImms` gets some extra derives: it acts like a sort of
|
||||||
// a sort of extended opcode and we want to allow for
|
// extended opcode and we want to allow for hashconsing via `Eq`.
|
||||||
// hashconsing via Eq. `Copy` also turns out to be useful.
|
fmt.line("#[derive(Eq)]");
|
||||||
fmt.line("#[derive(Copy, Eq)]");
|
|
||||||
}
|
}
|
||||||
fmt.line(r#"#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]"#);
|
fmt.line(r#"#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]"#);
|
||||||
fmt.line("#[allow(missing_docs)]");
|
fmt.line("#[allow(missing_docs)]");
|
||||||
// generate `enum InstructionData` or `enum InstructionImms`.
|
// Generate `enum InstructionData` or `enum InstructionImms`. (This
|
||||||
// (This comment exists so one can grep for `enum InstructionData`!)
|
// comment exists so one can grep for `enum InstructionData`!)
|
||||||
fmtln!(fmt, "pub enum {} {{", name);
|
fmtln!(fmt, "pub enum {} {{", name);
|
||||||
fmt.indent(|fmt| {
|
fmt.indent(|fmt| {
|
||||||
for format in formats {
|
for format in formats {
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ impl FunctionStencil {
|
|||||||
.zip(self.dfg.inst_results(src))
|
.zip(self.dfg.inst_results(src))
|
||||||
.all(|(a, b)| self.dfg.value_type(*a) == self.dfg.value_type(*b)));
|
.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);
|
self.layout.remove_inst(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -755,6 +755,19 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use alloc::string::ToString;
|
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]
|
#[test]
|
||||||
fn opcodes() {
|
fn opcodes() {
|
||||||
use core::mem;
|
use core::mem;
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ macro_rules! isle_lower_prelude_methods {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inst_data(&mut self, inst: Inst) -> InstructionData {
|
fn inst_data(&mut self, inst: Inst) -> InstructionData {
|
||||||
self.lower_ctx.dfg()[inst].clone()
|
self.lower_ctx.dfg()[inst]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ pub fn do_simple_gvn(func: &mut Function, domtree: &mut DominatorTree) {
|
|||||||
|
|
||||||
let ctrl_typevar = func.dfg.ctrl_typevar(inst);
|
let ctrl_typevar = func.dfg.ctrl_typevar(inst);
|
||||||
let key = HashKey {
|
let key = HashKey {
|
||||||
inst: func.dfg[inst].clone(),
|
inst: func.dfg[inst],
|
||||||
ty: ctrl_typevar,
|
ty: ctrl_typevar,
|
||||||
pos: &pos,
|
pos: &pos,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user