From 0b8bf530b075085768d0161e35facc9dd6f1817b Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 15 Sep 2016 08:41:19 -0700 Subject: [PATCH] Make functions cloneable for testing. It's not super fast to clone a function, but it is faster than re-parsing the test case file it came from. Some tests want to mutate the function, and there may be other tests in the same script that need the original function. --- cranelift/src/libcretonne/entity_map.rs | 2 +- cranelift/src/libcretonne/ir/dfg.rs | 3 +++ cranelift/src/libcretonne/ir/function.rs | 4 ++++ cranelift/src/libcretonne/ir/instructions.rs | 12 ++++++------ cranelift/src/libcretonne/ir/jumptable.rs | 1 + cranelift/src/libcretonne/ir/layout.rs | 1 + cranelift/src/libcretonne/ir/stackslot.rs | 2 +- 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cranelift/src/libcretonne/entity_map.rs b/cranelift/src/libcretonne/entity_map.rs index df486c48ed..2a76e3cce9 100644 --- a/cranelift/src/libcretonne/entity_map.rs +++ b/cranelift/src/libcretonne/entity_map.rs @@ -45,7 +45,7 @@ pub trait EntityRef: Copy + Eq { } /// A mapping `K -> V` for densely indexed entity references. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct EntityMap where K: EntityRef { diff --git a/cranelift/src/libcretonne/ir/dfg.rs b/cranelift/src/libcretonne/ir/dfg.rs index 3fc4d596eb..35bb9c8f7e 100644 --- a/cranelift/src/libcretonne/ir/dfg.rs +++ b/cranelift/src/libcretonne/ir/dfg.rs @@ -15,6 +15,7 @@ use std::u16; /// The layout of EBBs in the function and of instructions in each EBB is recorded by the /// `FunctionLayout` data structure which form the other half of the function representation. /// +#[derive(Clone)] pub struct DataFlowGraph { /// Data about all of the instructions in the function, including opcodes and operands. /// The instructions in this map are not in program order. That is tracked by `Layout`, along @@ -119,6 +120,7 @@ pub enum ValueDef { } // Internal table storage for extended values. +#[derive(Clone)] enum ValueData { // Value is defined by an instruction, but it is not the first result. Inst { @@ -336,6 +338,7 @@ impl DataFlowGraph { // Arguments for an extended basic block are values that dominate everything in the EBB. All // branches to this EBB must provide matching arguments, and the arguments to the entry EBB must // match the function arguments. +#[derive(Clone)] struct EbbData { // First argument to this EBB, or `NO_VALUE` if the block has no arguments. // diff --git a/cranelift/src/libcretonne/ir/function.rs b/cranelift/src/libcretonne/ir/function.rs index 2f8344d801..d6a44edfa6 100644 --- a/cranelift/src/libcretonne/ir/function.rs +++ b/cranelift/src/libcretonne/ir/function.rs @@ -9,6 +9,10 @@ use entity_map::{EntityMap, PrimaryEntityData}; use std::fmt::{self, Debug, Formatter}; /// A function. +/// +/// Functions can be cloned, but it is not a very fast operation. +/// The clone will have all the same entity numbers as the original. +#[derive(Clone)] pub struct Function { /// Name of this function. Mostly used by `.cton` files. pub name: FunctionName, diff --git a/cranelift/src/libcretonne/ir/instructions.rs b/cranelift/src/libcretonne/ir/instructions.rs index a6d664170e..c8228d1f43 100644 --- a/cranelift/src/libcretonne/ir/instructions.rs +++ b/cranelift/src/libcretonne/ir/instructions.rs @@ -93,7 +93,7 @@ impl FromStr for Opcode { /// value should have its `ty` field set to `VOID`. The size of `InstructionData` should be kept at /// 16 bytes on 64-bit architectures. If more space is needed to represent an instruction, use a /// `Box` to store the additional information out of line. -#[derive(Debug)] +#[derive(Clone, Debug)] pub enum InstructionData { Nullary { opcode: Opcode, ty: Type }, Unary { @@ -203,7 +203,7 @@ pub enum InstructionData { /// A variable list of `Value` operands used for function call arguments and passing arguments to /// basic blocks. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct VariableArgs(Vec); impl VariableArgs { @@ -256,7 +256,7 @@ impl Default for VariableArgs { /// Payload data for jump instructions. These need to carry lists of EBB arguments that won't fit /// in the allowed InstructionData size. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct JumpData { pub destination: Ebb, pub arguments: VariableArgs, @@ -274,7 +274,7 @@ impl Display for JumpData { /// Payload data for branch instructions. These need to carry lists of EBB arguments that won't fit /// in the allowed InstructionData size. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct BranchData { pub arg: Value, pub destination: Ebb, @@ -292,7 +292,7 @@ impl Display for BranchData { } /// Payload of a call instruction. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct CallData { /// Second result value for a call producing multiple return values. second_result: Value, @@ -308,7 +308,7 @@ impl Display for CallData { } /// Payload of a return instruction. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct ReturnData { // Dynamically sized array containing return values. pub args: VariableArgs, diff --git a/cranelift/src/libcretonne/ir/jumptable.rs b/cranelift/src/libcretonne/ir/jumptable.rs index 8a2308fbe1..cbd8630e46 100644 --- a/cranelift/src/libcretonne/ir/jumptable.rs +++ b/cranelift/src/libcretonne/ir/jumptable.rs @@ -12,6 +12,7 @@ use std::fmt::{self, Display, Formatter}; /// /// All jump tables use 0-based indexing and are expected to be densely populated. They don't need /// to be completely populated, though. Individual entries can be missing. +#[derive(Clone)] pub struct JumpTableData { // Table entries, using NO_EBB as a placeholder for missing entries. table: Vec, diff --git a/cranelift/src/libcretonne/ir/layout.rs b/cranelift/src/libcretonne/ir/layout.rs index c519a1c44f..a872efa5d8 100644 --- a/cranelift/src/libcretonne/ir/layout.rs +++ b/cranelift/src/libcretonne/ir/layout.rs @@ -20,6 +20,7 @@ use ir::entities::{Ebb, NO_EBB, Inst, NO_INST}; /// While data dependencies are not recorded, instruction ordering does affect control /// dependencies, so part of the semantics of the program are determined by the layout. /// +#[derive(Clone)] pub struct Layout { // Linked list nodes for the layout order of EBBs Forms a doubly linked list, terminated in // both ends by NO_EBB. diff --git a/cranelift/src/libcretonne/ir/stackslot.rs b/cranelift/src/libcretonne/ir/stackslot.rs index 31bee66eda..b22b82919c 100644 --- a/cranelift/src/libcretonne/ir/stackslot.rs +++ b/cranelift/src/libcretonne/ir/stackslot.rs @@ -6,7 +6,7 @@ use std::fmt::{self, Display, Formatter}; /// Contents of a stack slot. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct StackSlotData { /// Size of stack slot in bytes. pub size: u32,