From ddbf46bef4697bf4c2a21e70f1faa632c8024c0f Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 16 Jun 2017 13:08:13 -0700 Subject: [PATCH] Add typedefs for the common entity maps. The various entity maps in a function end up being referenced in multiple places, so create typedefs for them. --- lib/cretonne/src/binemit/relaxation.rs | 7 +++---- lib/cretonne/src/ir/function.rs | 29 +++++++++++++------------- lib/cretonne/src/ir/mod.rs | 16 ++++++++++++++ lib/cretonne/src/regalloc/coloring.rs | 18 ++++++++-------- lib/cretonne/src/regalloc/reload.rs | 7 +++---- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/lib/cretonne/src/binemit/relaxation.rs b/lib/cretonne/src/binemit/relaxation.rs index 517867c725..53b7fd0112 100644 --- a/lib/cretonne/src/binemit/relaxation.rs +++ b/lib/cretonne/src/binemit/relaxation.rs @@ -28,9 +28,8 @@ //! ``` use binemit::CodeOffset; -use entity_map::EntityMap; -use ir::{Function, DataFlowGraph, Cursor, Inst, InstructionData, Opcode}; -use isa::{TargetIsa, EncInfo, Encoding}; +use ir::{Function, DataFlowGraph, Cursor, InstructionData, Opcode, InstEncodings}; +use isa::{TargetIsa, EncInfo}; use iterators::IteratorExtras; /// Relax branches and compute the final layout of EBB headers in `func`. @@ -127,7 +126,7 @@ fn fallthroughs(func: &mut Function) { /// Return the size of the replacement instructions up to and including the location where `pos` is /// left. fn relax_branch(dfg: &mut DataFlowGraph, - encodings: &mut EntityMap, + encodings: &mut InstEncodings, encinfo: &EncInfo, pos: &mut Cursor, offset: CodeOffset, diff --git a/lib/cretonne/src/ir/function.rs b/lib/cretonne/src/ir/function.rs index 3cb547fdff..59213aff13 100644 --- a/lib/cretonne/src/ir/function.rs +++ b/lib/cretonne/src/ir/function.rs @@ -3,12 +3,11 @@ //! The `Function` struct defined in this module owns all of its extended basic blocks and //! instructions. -use binemit::CodeOffset; use entity_map::{EntityMap, PrimaryEntityData}; -use ir::{FunctionName, Signature, Value, Inst, Ebb, StackSlots, JumpTable, JumpTableData, - ValueLoc, DataFlowGraph, Layout}; -use isa::{TargetIsa, Encoding}; -use std::fmt::{self, Display, Debug, Formatter}; +use ir::{FunctionName, Signature, JumpTableData, DataFlowGraph, Layout}; +use ir::{JumpTables, InstEncodings, ValueLocations, StackSlots, EbbOffsets}; +use isa::TargetIsa; +use std::fmt; use write::write_function; /// A function. @@ -27,7 +26,7 @@ pub struct Function { pub stack_slots: StackSlots, /// Jump tables used in this function. - pub jump_tables: EntityMap, + pub jump_tables: JumpTables, /// Data flow graph containing the primary definition of all instructions, EBBs and values. pub dfg: DataFlowGraph, @@ -37,17 +36,17 @@ pub struct Function { /// Encoding recipe and bits for the legal instructions. /// Illegal instructions have the `Encoding::default()` value. - pub encodings: EntityMap, + pub encodings: InstEncodings, /// Location assigned to every value. - pub locations: EntityMap, + pub locations: ValueLocations, /// Code offsets of the EBB headers. /// /// This information is only transiently available after the `binemit::relax_branches` function /// computes it, and it can easily be recomputed by calling that function. It is not included /// in the textual IL format. - pub offsets: EntityMap, + pub offsets: EbbOffsets, } impl PrimaryEntityData for JumpTableData {} @@ -82,20 +81,20 @@ impl Function { /// Wrapper type capable of displaying a `Function` with correct ISA annotations. pub struct DisplayFunction<'a>(&'a Function, Option<&'a TargetIsa>); -impl<'a> Display for DisplayFunction<'a> { - fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { +impl<'a> fmt::Display for DisplayFunction<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { write_function(fmt, self.0, self.1) } } -impl Display for Function { - fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { +impl fmt::Display for Function { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { write_function(fmt, self, None) } } -impl Debug for Function { - fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { +impl fmt::Debug for Function { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { write_function(fmt, self, None) } } diff --git a/lib/cretonne/src/ir/mod.rs b/lib/cretonne/src/ir/mod.rs index de5e1515b6..c79edfa4c6 100644 --- a/lib/cretonne/src/ir/mod.rs +++ b/lib/cretonne/src/ir/mod.rs @@ -31,3 +31,19 @@ pub use ir::function::Function; pub use ir::builder::InstBuilder; pub use ir::progpoint::{ProgramPoint, ProgramOrder, ExpandedProgramPoint}; pub use ir::memflags::MemFlags; + +use binemit; +use entity_map::EntityMap; +use isa; + +/// Map of value locations. +pub type ValueLocations = EntityMap; + +/// Map of jump tables. +pub type JumpTables = EntityMap; + +/// Map of instruction encodings. +pub type InstEncodings = EntityMap; + +/// Code offsets for EBBs. +pub type EbbOffsets = EntityMap; diff --git a/lib/cretonne/src/regalloc/coloring.rs b/lib/cretonne/src/regalloc/coloring.rs index 53546de07f..c71218e7cc 100644 --- a/lib/cretonne/src/regalloc/coloring.rs +++ b/lib/cretonne/src/regalloc/coloring.rs @@ -33,7 +33,7 @@ use entity_map::EntityMap; use dominator_tree::DominatorTree; -use ir::{Ebb, Inst, Value, Function, Cursor, ValueLoc, DataFlowGraph}; +use ir::{Ebb, Inst, Value, Function, Cursor, ValueLoc, DataFlowGraph, ValueLocations}; use ir::{InstBuilder, Signature, ArgumentType, ArgumentLoc}; use isa::{TargetIsa, Encoding, EncInfo, OperandConstraint, ConstraintKind}; use isa::{RegUnit, RegClass, RegInfo, regs_overlap}; @@ -218,7 +218,7 @@ impl<'a> Context<'a> { fn color_entry_args(&self, sig: &Signature, args: &[LiveValue], - locations: &mut EntityMap) + locations: &mut ValueLocations) -> AllocatableSet { assert_eq!(sig.argument_types.len(), args.len()); @@ -271,7 +271,7 @@ impl<'a> Context<'a> { fn color_args(&self, args: &[LiveValue], mut regs: AllocatableSet, - locations: &mut EntityMap) + locations: &mut ValueLocations) -> AllocatableSet { // Available registers *after* filtering out the dead arguments. let mut live_regs = regs.clone(); @@ -309,7 +309,7 @@ impl<'a> Context<'a> { dfg: &mut DataFlowGraph, tracker: &mut LiveValueTracker, regs: &mut AllocatableSet, - locations: &mut EntityMap, + locations: &mut ValueLocations, func_signature: &Signature) { dbg!("Coloring [{}] {}", self.encinfo.display(encoding), @@ -449,7 +449,7 @@ impl<'a> Context<'a> { // into the constraint solver. Convert them to solver variables so they can be diverted. fn divert_fixed_input_conflicts(&mut self, live: &[LiveValue], - locations: &mut EntityMap) { + locations: &mut ValueLocations) { for lv in live { if let Affinity::Reg(rci) = lv.affinity { let rc = self.reginfo.rc(rci); @@ -468,7 +468,7 @@ impl<'a> Context<'a> { constraints: &[OperandConstraint], defs: &[LiveValue], throughs: &[LiveValue], - locations: &mut EntityMap) { + locations: &mut ValueLocations) { for (op, lv) in constraints.iter().zip(defs) { if let ConstraintKind::FixedReg(reg) = op.kind { self.add_fixed_output(lv.value, op.regclass, reg, throughs, locations); @@ -483,7 +483,7 @@ impl<'a> Context<'a> { abi_types: &[ArgumentType], defs: &[LiveValue], throughs: &[LiveValue], - locations: &mut EntityMap) { + locations: &mut ValueLocations) { // It's technically possible for a call instruction to have fixed results before the // variable list of results, but we have no known instances of that. // Just assume all results are variable return values. @@ -506,7 +506,7 @@ impl<'a> Context<'a> { rc: RegClass, reg: RegUnit, throughs: &[LiveValue], - locations: &mut EntityMap) { + locations: &mut ValueLocations) { if !self.solver.add_fixed_output(rc, reg) { // The fixed output conflicts with some of the live-through registers. for lv in throughs { @@ -538,7 +538,7 @@ impl<'a> Context<'a> { constraints: &[OperandConstraint], defs: &[LiveValue], _dfg: &mut DataFlowGraph, - _locations: &mut EntityMap) { + _locations: &mut ValueLocations) { for (op, lv) in constraints.iter().zip(defs) { match op.kind { ConstraintKind::FixedReg(_) | diff --git a/lib/cretonne/src/regalloc/reload.rs b/lib/cretonne/src/regalloc/reload.rs index dd623de2b5..2226566799 100644 --- a/lib/cretonne/src/regalloc/reload.rs +++ b/lib/cretonne/src/regalloc/reload.rs @@ -10,8 +10,7 @@ //! pressure limits to be exceeded. use dominator_tree::DominatorTree; -use entity_map::EntityMap; -use ir::{Ebb, Inst, Value, Function, Signature, DataFlowGraph}; +use ir::{Ebb, Inst, Value, Function, Signature, DataFlowGraph, InstEncodings}; use ir::layout::{Cursor, CursorPosition}; use ir::{InstBuilder, Opcode, ArgumentType, ArgumentLoc}; use isa::RegClass; @@ -201,7 +200,7 @@ impl<'a> Context<'a> { encoding: Encoding, pos: &mut Cursor, dfg: &mut DataFlowGraph, - encodings: &mut EntityMap, + encodings: &mut InstEncodings, func_signature: &Signature, tracker: &mut LiveValueTracker) { // Get the operand constraints for `inst` that we are trying to satisfy. @@ -341,7 +340,7 @@ impl<'a> Context<'a> { stack: Value, reg: Value, pos: &mut Cursor, - encodings: &mut EntityMap, + encodings: &mut InstEncodings, dfg: &mut DataFlowGraph) { let ty = dfg.value_type(reg);