Add a ValueLoc type and the locations table.

This table holds the result of register allocation.
This commit is contained in:
Jakob Stoklund Olesen
2016-12-08 13:57:28 -10:00
parent 3392a2b79a
commit f9af88c49e
4 changed files with 43 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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<Inst, Encoding>,
/// Location assigned to every value.
pub locations: EntityMap<Value, ValueLoc>,
}
impl PrimaryEntityData for StackSlotData {}
@@ -53,6 +56,7 @@ impl Function {
dfg: DataFlowGraph::new(),
layout: Layout::new(),
encodings: EntityMap::new(),
locations: EntityMap::new(),
}
}

View File

@@ -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;

View File

@@ -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
}
}