diff --git a/lib/cretonne/src/ir/entities.rs b/lib/cretonne/src/ir/entities.rs index df7d81988f..4570a21009 100644 --- a/lib/cretonne/src/ir/entities.rs +++ b/lib/cretonne/src/ir/entities.rs @@ -98,6 +98,17 @@ impl Default for Inst { #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct Value(u32); +impl EntityRef for Value { + fn new(index: usize) -> Value { + assert!(index < (u32::MAX as usize)); + Value(index as u32) + } + + fn index(self) -> usize { + self.0 as usize + } +} + /// Value references can either reference an instruction directly, or they can refer to the /// extended value table. pub enum ExpandedValue { diff --git a/lib/cretonne/src/ir/function.rs b/lib/cretonne/src/ir/function.rs index 844101bf95..db6c811b5a 100644 --- a/lib/cretonne/src/ir/function.rs +++ b/lib/cretonne/src/ir/function.rs @@ -4,8 +4,8 @@ //! instructions. use std::fmt::{self, Display, Debug, Formatter}; -use ir::{FunctionName, Signature, Inst, StackSlot, StackSlotData, JumpTable, JumpTableData, - DataFlowGraph, Layout}; +use ir::{FunctionName, Signature, Value, Inst, StackSlot, StackSlotData, JumpTable, JumpTableData, + ValueLoc, DataFlowGraph, Layout}; use isa::Encoding; use entity_map::{EntityMap, PrimaryEntityData}; use write::write_function; @@ -37,6 +37,9 @@ pub struct Function { /// Encoding recipe and bits for the legal instructions. /// Illegal instructions have the `Encoding::default()` value. pub encodings: EntityMap, + + /// Location assigned to every value. + pub locations: EntityMap, } impl PrimaryEntityData for StackSlotData {} @@ -53,6 +56,7 @@ impl Function { dfg: DataFlowGraph::new(), layout: Layout::new(), encodings: EntityMap::new(), + locations: EntityMap::new(), } } diff --git a/lib/cretonne/src/ir/mod.rs b/lib/cretonne/src/ir/mod.rs index b8cda7711c..738c6336d5 100644 --- a/lib/cretonne/src/ir/mod.rs +++ b/lib/cretonne/src/ir/mod.rs @@ -13,6 +13,7 @@ pub mod function; mod funcname; mod extfunc; mod builder; +mod valueloc; pub use ir::funcname::FunctionName; pub use ir::extfunc::{Signature, ArgumentType, ArgumentExtension, ExtFuncData}; @@ -21,6 +22,7 @@ pub use ir::entities::{Ebb, Inst, Value, StackSlot, JumpTable, FuncRef, SigRef}; pub use ir::instructions::{Opcode, InstructionData, VariableArgs}; pub use ir::stackslot::StackSlotData; pub use ir::jumptable::JumpTableData; +pub use ir::valueloc::ValueLoc; pub use ir::dfg::{DataFlowGraph, ValueDef}; pub use ir::layout::{Layout, Cursor}; pub use ir::function::Function; diff --git a/lib/cretonne/src/ir/valueloc.rs b/lib/cretonne/src/ir/valueloc.rs new file mode 100644 index 0000000000..3526c58190 --- /dev/null +++ b/lib/cretonne/src/ir/valueloc.rs @@ -0,0 +1,24 @@ +//! Value locations. +//! +//! The register allocator assigns every SSA value to either a register or a stack slot. This +//! assignment is represented by a `ValueLoc` object. + +use isa::RegUnit; +use ir::StackSlot; + +/// Value location. +#[derive(Copy, Clone, Debug)] +pub enum ValueLoc { + /// This value has not been assigned to a location yet. + Unassigned, + /// Value is assigned to a register. + Reg(RegUnit), + /// Value is assigned to a stack slot. + Stack(StackSlot), +} + +impl Default for ValueLoc { + fn default() -> Self { + ValueLoc::Unassigned + } +}