Rename EntityMap to SecondaryMap (#528)

* Rename `EntityMap` to `SecondaryMap`
This commit is contained in:
Muhammad Mominul Huque
2018-09-27 01:03:44 +06:00
committed by Dan Gohman
parent 7ff71fcfd9
commit d266b1a42d
18 changed files with 91 additions and 91 deletions

View File

@@ -1,6 +1,6 @@
//! A Dominator Tree represented as mappings of Ebbs to their immediate dominator. //! A Dominator Tree represented as mappings of Ebbs to their immediate dominator.
use entity::EntityMap; use entity::SecondaryMap;
use flowgraph::{BasicBlock, ControlFlowGraph}; use flowgraph::{BasicBlock, ControlFlowGraph};
use ir::instructions::BranchInfo; use ir::instructions::BranchInfo;
use ir::{Ebb, ExpandedProgramPoint, Function, Inst, Layout, ProgramOrder, Value}; use ir::{Ebb, ExpandedProgramPoint, Function, Inst, Layout, ProgramOrder, Value};
@@ -38,7 +38,7 @@ struct DomNode {
/// The dominator tree for a single function. /// The dominator tree for a single function.
pub struct DominatorTree { pub struct DominatorTree {
nodes: EntityMap<Ebb, DomNode>, nodes: SecondaryMap<Ebb, DomNode>,
/// CFG post-order of all reachable EBBs. /// CFG post-order of all reachable EBBs.
postorder: Vec<Ebb>, postorder: Vec<Ebb>,
@@ -217,7 +217,7 @@ impl DominatorTree {
/// function. /// function.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
nodes: EntityMap::new(), nodes: SecondaryMap::new(),
postorder: Vec::new(), postorder: Vec::new(),
stack: Vec::new(), stack: Vec::new(),
valid: false, valid: false,
@@ -505,7 +505,7 @@ impl DominatorTree {
/// The information in this auxillary data structure is not easy to update when the control flow /// The information in this auxillary data structure is not easy to update when the control flow
/// graph changes, which is why it is kept separate. /// graph changes, which is why it is kept separate.
pub struct DominatorTreePreorder { pub struct DominatorTreePreorder {
nodes: EntityMap<Ebb, ExtraNode>, nodes: SecondaryMap<Ebb, ExtraNode>,
// Scratch memory used by `compute_postorder()`. // Scratch memory used by `compute_postorder()`.
stack: Vec<Ebb>, stack: Vec<Ebb>,
@@ -533,7 +533,7 @@ impl DominatorTreePreorder {
/// Create a new blank `DominatorTreePreorder`. /// Create a new blank `DominatorTreePreorder`.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
nodes: EntityMap::new(), nodes: SecondaryMap::new(),
stack: Vec::new(), stack: Vec::new(),
} }
} }

View File

@@ -24,7 +24,7 @@
//! and `(Ebb0, jmp Ebb2)` respectively. //! and `(Ebb0, jmp Ebb2)` respectively.
use bforest; use bforest;
use entity::EntityMap; use entity::SecondaryMap;
use ir::instructions::BranchInfo; use ir::instructions::BranchInfo;
use ir::{Ebb, Function, Inst}; use ir::{Ebb, Function, Inst};
use std::mem; use std::mem;
@@ -72,7 +72,7 @@ struct CFGNode {
/// and successors where predecessors are basic blocks and successors are /// and successors where predecessors are basic blocks and successors are
/// extended basic blocks. /// extended basic blocks.
pub struct ControlFlowGraph { pub struct ControlFlowGraph {
data: EntityMap<Ebb, CFGNode>, data: SecondaryMap<Ebb, CFGNode>,
pred_forest: bforest::MapForest<Inst, Ebb>, pred_forest: bforest::MapForest<Inst, Ebb>,
succ_forest: bforest::SetForest<Ebb>, succ_forest: bforest::SetForest<Ebb>,
valid: bool, valid: bool,
@@ -82,7 +82,7 @@ impl ControlFlowGraph {
/// Allocate a new blank control flow graph. /// Allocate a new blank control flow graph.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
data: EntityMap::new(), data: SecondaryMap::new(),
valid: false, valid: false,
pred_forest: bforest::MapForest::new(), pred_forest: bforest::MapForest::new(),
succ_forest: bforest::SetForest::new(), succ_forest: bforest::SetForest::new(),

View File

@@ -1,6 +1,6 @@
//! Data flow graph tracking Instructions, Values, and EBBs. //! Data flow graph tracking Instructions, Values, and EBBs.
use entity::{self, EntityMap, PrimaryMap}; use entity::{self, PrimaryMap, SecondaryMap};
use ir; use ir;
use ir::builder::ReplaceBuilder; use ir::builder::ReplaceBuilder;
use ir::extfunc::ExtFuncData; use ir::extfunc::ExtFuncData;
@@ -34,7 +34,7 @@ pub struct DataFlowGraph {
/// ///
/// This map gets resized automatically by `make_inst()` so it is always in sync with the /// This map gets resized automatically by `make_inst()` so it is always in sync with the
/// primary `insts` map. /// primary `insts` map.
results: EntityMap<Inst, ValueList>, results: SecondaryMap<Inst, ValueList>,
/// Extended basic blocks in the function and their parameters. /// Extended basic blocks in the function and their parameters.
/// ///
@@ -67,7 +67,7 @@ impl DataFlowGraph {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
insts: PrimaryMap::new(), insts: PrimaryMap::new(),
results: EntityMap::new(), results: SecondaryMap::new(),
ebbs: PrimaryMap::new(), ebbs: PrimaryMap::new(),
value_lists: ValueListPool::new(), value_lists: ValueListPool::new(),
values: PrimaryMap::new(), values: PrimaryMap::new(),
@@ -90,7 +90,7 @@ impl DataFlowGraph {
/// Get the total number of instructions created in this function, whether they are currently /// Get the total number of instructions created in this function, whether they are currently
/// inserted in the layout or not. /// inserted in the layout or not.
/// ///
/// This is intended for use with `EntityMap::with_capacity`. /// This is intended for use with `SecondaryMap::with_capacity`.
pub fn num_insts(&self) -> usize { pub fn num_insts(&self) -> usize {
self.insts.len() self.insts.len()
} }
@@ -103,7 +103,7 @@ impl DataFlowGraph {
/// Get the total number of extended basic blocks created in this function, whether they are /// Get the total number of extended basic blocks created in this function, whether they are
/// currently inserted in the layout or not. /// currently inserted in the layout or not.
/// ///
/// This is intended for use with `EntityMap::with_capacity`. /// This is intended for use with `SecondaryMap::with_capacity`.
pub fn num_ebbs(&self) -> usize { pub fn num_ebbs(&self) -> usize {
self.ebbs.len() self.ebbs.len()
} }

View File

@@ -4,7 +4,7 @@
//! instructions. //! instructions.
use binemit::CodeOffset; use binemit::CodeOffset;
use entity::{EntityMap, PrimaryMap}; use entity::{PrimaryMap, SecondaryMap};
use ir; use ir;
use ir::{DataFlowGraph, ExternalName, Layout, Signature}; use ir::{DataFlowGraph, ExternalName, Layout, Signature};
use ir::{ use ir::{
@@ -84,10 +84,10 @@ impl Function {
jump_tables: PrimaryMap::new(), jump_tables: PrimaryMap::new(),
dfg: DataFlowGraph::new(), dfg: DataFlowGraph::new(),
layout: Layout::new(), layout: Layout::new(),
encodings: EntityMap::new(), encodings: SecondaryMap::new(),
locations: EntityMap::new(), locations: SecondaryMap::new(),
offsets: EntityMap::new(), offsets: SecondaryMap::new(),
srclocs: EntityMap::new(), srclocs: SecondaryMap::new(),
} }
} }

View File

@@ -3,7 +3,7 @@
//! The order of extended basic blocks in a function and the order of instructions in an EBB is //! The order of extended basic blocks in a function and the order of instructions in an EBB is
//! determined by the `Layout` data structure defined in this module. //! determined by the `Layout` data structure defined in this module.
use entity::EntityMap; use entity::SecondaryMap;
use ir::progpoint::{ExpandedProgramPoint, ProgramOrder}; use ir::progpoint::{ExpandedProgramPoint, ProgramOrder};
use ir::{Ebb, Inst}; use ir::{Ebb, Inst};
use packed_option::PackedOption; use packed_option::PackedOption;
@@ -28,11 +28,11 @@ use timing;
pub struct Layout { pub struct Layout {
/// Linked list nodes for the layout order of EBBs Forms a doubly linked list, terminated in /// Linked list nodes for the layout order of EBBs Forms a doubly linked list, terminated in
/// both ends by `None`. /// both ends by `None`.
ebbs: EntityMap<Ebb, EbbNode>, ebbs: SecondaryMap<Ebb, EbbNode>,
/// Linked list nodes for the layout order of instructions. Forms a double linked list per EBB, /// Linked list nodes for the layout order of instructions. Forms a double linked list per EBB,
/// terminated in both ends by `None`. /// terminated in both ends by `None`.
insts: EntityMap<Inst, InstNode>, insts: SecondaryMap<Inst, InstNode>,
/// First EBB in the layout order, or `None` when no EBBs have been laid out. /// First EBB in the layout order, or `None` when no EBBs have been laid out.
first_ebb: Option<Ebb>, first_ebb: Option<Ebb>,
@@ -45,8 +45,8 @@ impl Layout {
/// Create a new empty `Layout`. /// Create a new empty `Layout`.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
ebbs: EntityMap::new(), ebbs: SecondaryMap::new(),
insts: EntityMap::new(), insts: SecondaryMap::new(),
first_ebb: None, first_ebb: None,
last_ebb: None, last_ebb: None,
} }

View File

@@ -47,20 +47,20 @@ pub use ir::types::Type;
pub use ir::valueloc::{ArgumentLoc, ValueLoc}; pub use ir::valueloc::{ArgumentLoc, ValueLoc};
use binemit; use binemit;
use entity::{EntityMap, PrimaryMap}; use entity::{PrimaryMap, SecondaryMap};
use isa; use isa;
/// Map of value locations. /// Map of value locations.
pub type ValueLocations = EntityMap<Value, ValueLoc>; pub type ValueLocations = SecondaryMap<Value, ValueLoc>;
/// Map of jump tables. /// Map of jump tables.
pub type JumpTables = PrimaryMap<JumpTable, JumpTableData>; pub type JumpTables = PrimaryMap<JumpTable, JumpTableData>;
/// Map of instruction encodings. /// Map of instruction encodings.
pub type InstEncodings = EntityMap<Inst, isa::Encoding>; pub type InstEncodings = SecondaryMap<Inst, isa::Encoding>;
/// Code offsets for EBBs. /// Code offsets for EBBs.
pub type EbbOffsets = EntityMap<Ebb, binemit::CodeOffset>; pub type EbbOffsets = SecondaryMap<Ebb, binemit::CodeOffset>;
/// Source locations for instructions. /// Source locations for instructions.
pub type SourceLocs = EntityMap<Inst, SourceLoc>; pub type SourceLocs = SecondaryMap<Inst, SourceLoc>;

View File

@@ -2,7 +2,7 @@
//! and parent in the loop tree. //! and parent in the loop tree.
use dominator_tree::DominatorTree; use dominator_tree::DominatorTree;
use entity::EntityMap; use entity::SecondaryMap;
use entity::{Keys, PrimaryMap}; use entity::{Keys, PrimaryMap};
use flowgraph::{BasicBlock, ControlFlowGraph}; use flowgraph::{BasicBlock, ControlFlowGraph};
use ir::{Ebb, Function, Layout}; use ir::{Ebb, Function, Layout};
@@ -21,7 +21,7 @@ entity_impl!(Loop, "loop");
/// its eventual parent in the loop tree and all the EBB belonging to the loop. /// its eventual parent in the loop tree and all the EBB belonging to the loop.
pub struct LoopAnalysis { pub struct LoopAnalysis {
loops: PrimaryMap<Loop, LoopData>, loops: PrimaryMap<Loop, LoopData>,
ebb_loop_map: EntityMap<Ebb, PackedOption<Loop>>, ebb_loop_map: SecondaryMap<Ebb, PackedOption<Loop>>,
valid: bool, valid: bool,
} }
@@ -48,7 +48,7 @@ impl LoopAnalysis {
Self { Self {
valid: false, valid: false,
loops: PrimaryMap::new(), loops: PrimaryMap::new(),
ebb_loop_map: EntityMap::new(), ebb_loop_map: SecondaryMap::new(),
} }
} }

View File

@@ -1,6 +1,6 @@
//! Utility routines for pretty-printing error messages. //! Utility routines for pretty-printing error messages.
use entity::EntityMap; use entity::SecondaryMap;
use ir; use ir;
use ir::entities::{AnyEntity, Inst, Value}; use ir::entities::{AnyEntity, Inst, Value};
use ir::function::Function; use ir::function::Function;
@@ -40,7 +40,7 @@ impl<'a> FuncWriter for PrettyVerifierError<'a> {
&mut self, &mut self,
w: &mut Write, w: &mut Write,
func: &Function, func: &Function,
aliases: &EntityMap<Value, Vec<Value>>, aliases: &SecondaryMap<Value, Vec<Value>>,
isa: Option<&TargetIsa>, isa: Option<&TargetIsa>,
inst: Inst, inst: Inst,
indent: usize, indent: usize,
@@ -63,7 +63,7 @@ impl<'a> FuncWriter for PrettyVerifierError<'a> {
fn pretty_instruction_error( fn pretty_instruction_error(
w: &mut Write, w: &mut Write,
func: &Function, func: &Function,
aliases: &EntityMap<Value, Vec<Value>>, aliases: &SecondaryMap<Value, Vec<Value>>,
isa: Option<&TargetIsa>, isa: Option<&TargetIsa>,
cur_inst: Inst, cur_inst: Inst,
indent: usize, indent: usize,

View File

@@ -15,7 +15,7 @@ use dbg::DisplayList;
use dominator_tree::DominatorTreePreorder; use dominator_tree::DominatorTreePreorder;
use entity::EntityRef; use entity::EntityRef;
use entity::{EntityList, ListPool}; use entity::{EntityList, ListPool};
use entity::{EntityMap, Keys, PrimaryMap}; use entity::{Keys, PrimaryMap, SecondaryMap};
use ir::{Function, Value}; use ir::{Function, Value};
use packed_option::PackedOption; use packed_option::PackedOption;
use ref_slice::ref_slice; use ref_slice::ref_slice;
@@ -45,10 +45,10 @@ pub struct VirtRegs {
unused_vregs: Vec<VirtReg>, unused_vregs: Vec<VirtReg>,
/// Each value belongs to at most one virtual register. /// Each value belongs to at most one virtual register.
value_vregs: EntityMap<Value, PackedOption<VirtReg>>, value_vregs: SecondaryMap<Value, PackedOption<VirtReg>>,
/// Table used during the union-find phase while `vregs` is empty. /// Table used during the union-find phase while `vregs` is empty.
union_find: EntityMap<Value, i32>, union_find: SecondaryMap<Value, i32>,
/// Values that have been activated in the `union_find` table, but not yet added to any virtual /// Values that have been activated in the `union_find` table, but not yet added to any virtual
/// registers by the `finish_union_find()` function. /// registers by the `finish_union_find()` function.
@@ -62,8 +62,8 @@ impl VirtRegs {
pool: ListPool::new(), pool: ListPool::new(),
vregs: PrimaryMap::new(), vregs: PrimaryMap::new(),
unused_vregs: Vec::new(), unused_vregs: Vec::new(),
value_vregs: EntityMap::new(), value_vregs: SecondaryMap::new(),
union_find: EntityMap::new(), union_find: SecondaryMap::new(),
pending_values: Vec::new(), pending_values: Vec::new(),
} }
} }

View File

@@ -1,6 +1,6 @@
//! Verify CPU flags values. //! Verify CPU flags values.
use entity::{EntityMap, SparseSet}; use entity::{SecondaryMap, SparseSet};
use flowgraph::{BasicBlock, ControlFlowGraph}; use flowgraph::{BasicBlock, ControlFlowGraph};
use ir; use ir;
use ir::instructions::BranchInfo; use ir::instructions::BranchInfo;
@@ -32,7 +32,7 @@ pub fn verify_flags(
func, func,
cfg, cfg,
encinfo: isa.map(|isa| isa.encoding_info()), encinfo: isa.map(|isa| isa.encoding_info()),
livein: EntityMap::new(), livein: SecondaryMap::new(),
}; };
verifier.check(errors) verifier.check(errors)
} }
@@ -43,7 +43,7 @@ struct FlagsVerifier<'a> {
encinfo: Option<isa::EncInfo>, encinfo: Option<isa::EncInfo>,
/// The single live-in flags value (if any) for each EBB. /// The single live-in flags value (if any) for each EBB.
livein: EntityMap<ir::Ebb, PackedOption<ir::Value>>, livein: SecondaryMap<ir::Ebb, PackedOption<ir::Value>>,
} }
impl<'a> FlagsVerifier<'a> { impl<'a> FlagsVerifier<'a> {

View File

@@ -3,7 +3,7 @@
//! The `write` module provides the `write_function` function which converts an IR `Function` to an //! The `write` module provides the `write_function` function which converts an IR `Function` to an
//! equivalent textual form. This textual form can be read back by the `cranelift-reader` crate. //! equivalent textual form. This textual form can be read back by the `cranelift-reader` crate.
use entity::EntityMap; use entity::SecondaryMap;
use ir::entities::AnyEntity; use ir::entities::AnyEntity;
use ir::{DataFlowGraph, Ebb, Function, Inst, SigRef, Type, Value, ValueDef}; use ir::{DataFlowGraph, Ebb, Function, Inst, SigRef, Type, Value, ValueDef};
use isa::{RegInfo, TargetIsa}; use isa::{RegInfo, TargetIsa};
@@ -19,7 +19,7 @@ pub trait FuncWriter {
&mut self, &mut self,
w: &mut Write, w: &mut Write,
func: &Function, func: &Function,
aliases: &EntityMap<Value, Vec<Value>>, aliases: &SecondaryMap<Value, Vec<Value>>,
isa: Option<&TargetIsa>, isa: Option<&TargetIsa>,
inst: Inst, inst: Inst,
ident: usize, ident: usize,
@@ -101,7 +101,7 @@ impl FuncWriter for PlainWriter {
&mut self, &mut self,
w: &mut Write, w: &mut Write,
func: &Function, func: &Function,
aliases: &EntityMap<Value, Vec<Value>>, aliases: &SecondaryMap<Value, Vec<Value>>,
isa: Option<&TargetIsa>, isa: Option<&TargetIsa>,
inst: Inst, inst: Inst,
indent: usize, indent: usize,
@@ -117,8 +117,8 @@ pub fn write_function(w: &mut Write, func: &Function, isa: Option<&TargetIsa>) -
} }
/// Create a reverse-alias map from a value to all aliases having that value as a direct target /// Create a reverse-alias map from a value to all aliases having that value as a direct target
fn alias_map(func: &Function) -> EntityMap<Value, Vec<Value>> { fn alias_map(func: &Function) -> SecondaryMap<Value, Vec<Value>> {
let mut aliases = EntityMap::<_, Vec<_>>::new(); let mut aliases = SecondaryMap::<_, Vec<_>>::new();
for v in func.dfg.values() { for v in func.dfg.values() {
// VADFS returns the immediate target of an alias // VADFS returns the immediate target of an alias
if let Some(k) = func.dfg.value_alias_dest_for_serialization(v) { if let Some(k) = func.dfg.value_alias_dest_for_serialization(v) {
@@ -216,7 +216,7 @@ fn decorate_ebb<FW: FuncWriter>(
func_w: &mut FW, func_w: &mut FW,
w: &mut Write, w: &mut Write,
func: &Function, func: &Function,
aliases: &EntityMap<Value, Vec<Value>>, aliases: &SecondaryMap<Value, Vec<Value>>,
isa: Option<&TargetIsa>, isa: Option<&TargetIsa>,
ebb: Ebb, ebb: Ebb,
) -> fmt::Result { ) -> fmt::Result {
@@ -279,7 +279,7 @@ fn type_suffix(func: &Function, inst: Inst) -> Option<Type> {
/// Write out any aliases to the given target, including indirect aliases /// Write out any aliases to the given target, including indirect aliases
fn write_value_aliases( fn write_value_aliases(
w: &mut Write, w: &mut Write,
aliases: &EntityMap<Value, Vec<Value>>, aliases: &SecondaryMap<Value, Vec<Value>>,
target: Value, target: Value,
indent: usize, indent: usize,
) -> fmt::Result { ) -> fmt::Result {
@@ -293,7 +293,7 @@ fn write_value_aliases(
fn write_instruction( fn write_instruction(
w: &mut Write, w: &mut Write,
func: &Function, func: &Function,
aliases: &EntityMap<Value, Vec<Value>>, aliases: &SecondaryMap<Value, Vec<Value>>,
isa: Option<&TargetIsa>, isa: Option<&TargetIsa>,
inst: Inst, inst: Inst,
indent: usize, indent: usize,

View File

@@ -17,11 +17,11 @@ easy to declare new unique types for use as keys. Any attempt to use a key in
a map it's not intended for is diagnosed with a type error. a map it's not intended for is diagnosed with a type error.
Another is that this crate has two core map types, `PrimaryMap` and Another is that this crate has two core map types, `PrimaryMap` and
`EntityMap`, which serve complementary purposes. A `PrimaryMap` creates its `SecondaryMap`, which serve complementary purposes. A `PrimaryMap` creates its
own keys when elements are inserted, while an `EntityMap` reuses the keys own keys when elements are inserted, while an `SecondaryMap` reuses the keys
values of a `PrimaryMap`, conceptually storing additional data in the same values of a `PrimaryMap`, conceptually storing additional data in the same
index space. `EntityMap`'s values must implement `Default` and all elements index space. `SecondaryMap`'s values must implement `Default` and all elements
in an `EntityMap` initially have the value of `default()`. in an `SecondaryMap` initially have the value of `default()`.
A common way to implement `Default` is to wrap a type in `Option`, however A common way to implement `Default` is to wrap a type in `Option`, however
this crate also provides the `PackedOption` utility which can use less memory this crate also provides the `PackedOption` utility which can use less memory
@@ -30,9 +30,9 @@ in some cases.
Additional utilities provided by this crate include: Additional utilities provided by this crate include:
- `EntityList`, for allocating many small arrays (such as instruction operand - `EntityList`, for allocating many small arrays (such as instruction operand
lists in a compiler code generator). lists in a compiler code generator).
- `SparseMap`: an alternative to `EntityMap` which can use less memory - `SparseMap`: an alternative to `SecondaryMap` which can use less memory
in some situations. in some situations.
- `EntitySet`: a specialized form of `EntityMap` using a bitvector to - `EntitySet`: a specialized form of `SecondaryMap` using a bitvector to
record which entities are members of the set. record which entities are members of the set.
[slotmap]: https://crates.io/crates/slotmap [slotmap]: https://crates.io/crates/slotmap

View File

@@ -15,7 +15,7 @@
//! //!
//! - [`PrimaryMap`](struct.PrimaryMap.html) is used to keep track of a vector of entities, //! - [`PrimaryMap`](struct.PrimaryMap.html) is used to keep track of a vector of entities,
//! assigning a unique entity reference to each. //! assigning a unique entity reference to each.
//! - [`EntityMap`](struct.EntityMap.html) is used to associate secondary information to an entity. //! - [`SecondaryMap`](struct.SecondaryMap.html) is used to associate secondary information to an entity.
//! The map is implemented as a simple vector, so it does not keep track of which entities have //! The map is implemented as a simple vector, so it does not keep track of which entities have
//! been inserted. Instead, any unknown entities map to the default value. //! been inserted. Instead, any unknown entities map to the default value.
//! - [`SparseMap`](struct.SparseMap.html) is used to associate secondary information to a small //! - [`SparseMap`](struct.SparseMap.html) is used to associate secondary information to a small
@@ -70,7 +70,7 @@ mod std {
pub extern crate core as __core; pub extern crate core as __core;
/// A type wrapping a small integer index should implement `EntityRef` so it can be used as the key /// A type wrapping a small integer index should implement `EntityRef` so it can be used as the key
/// of an `EntityMap` or `SparseMap`. /// of an `SecondaryMap` or `SparseMap`.
pub trait EntityRef: Copy + Eq { pub trait EntityRef: Copy + Eq {
/// Create a new entity reference from a small integer. /// Create a new entity reference from a small integer.
/// This should crash if the requested index is not representable. /// This should crash if the requested index is not representable.
@@ -135,7 +135,7 @@ mod sparse;
pub use self::iter::{Iter, IterMut}; pub use self::iter::{Iter, IterMut};
pub use self::keys::Keys; pub use self::keys::Keys;
pub use self::list::{EntityList, ListPool}; pub use self::list::{EntityList, ListPool};
pub use self::map::EntityMap; pub use self::map::SecondaryMap;
pub use self::primary::PrimaryMap; pub use self::primary::PrimaryMap;
pub use self::set::EntitySet; pub use self::set::EntitySet;
pub use self::sparse::{SparseMap, SparseMapValue, SparseSet}; pub use self::sparse::{SparseMap, SparseMapValue, SparseSet};

View File

@@ -8,14 +8,14 @@ use {EntityRef, Iter, IterMut, Keys};
/// A mapping `K -> V` for densely indexed entity references. /// A mapping `K -> V` for densely indexed entity references.
/// ///
/// The `EntityMap` data structure uses the dense index space to implement a map with a vector. /// The `SecondaryMap` data structure uses the dense index space to implement a map with a vector.
/// Unlike `PrimaryMap`, an `EntityMap` can't be used to allocate entity references. It is used to /// Unlike `PrimaryMap`, an `SecondaryMap` can't be used to allocate entity references. It is used to
/// associate secondary information with entities. /// associate secondary information with entities.
/// ///
/// The map does not track if an entry for a key has been inserted or not. Instead it behaves as if /// The map does not track if an entry for a key has been inserted or not. Instead it behaves as if
/// all keys have a default entry from the beginning. /// all keys have a default entry from the beginning.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct EntityMap<K, V> pub struct SecondaryMap<K, V>
where where
K: EntityRef, K: EntityRef,
V: Clone, V: Clone,
@@ -25,8 +25,8 @@ where
unused: PhantomData<K>, unused: PhantomData<K>,
} }
/// Shared `EntityMap` implementation for all value types. /// Shared `SecondaryMap` implementation for all value types.
impl<K, V> EntityMap<K, V> impl<K, V> SecondaryMap<K, V>
where where
K: EntityRef, K: EntityRef,
V: Clone, V: Clone,
@@ -100,10 +100,10 @@ where
} }
} }
/// Immutable indexing into an `EntityMap`. /// Immutable indexing into an `SecondaryMap`.
/// ///
/// All keys are permitted. Untouched entries have the default value. /// All keys are permitted. Untouched entries have the default value.
impl<K, V> Index<K> for EntityMap<K, V> impl<K, V> Index<K> for SecondaryMap<K, V>
where where
K: EntityRef, K: EntityRef,
V: Clone, V: Clone,
@@ -115,10 +115,10 @@ where
} }
} }
/// Mutable indexing into an `EntityMap`. /// Mutable indexing into an `SecondaryMap`.
/// ///
/// The map grows as needed to accommodate new keys. /// The map grows as needed to accommodate new keys.
impl<K, V> IndexMut<K> for EntityMap<K, V> impl<K, V> IndexMut<K> for SecondaryMap<K, V>
where where
K: EntityRef, K: EntityRef,
V: Clone, V: Clone,
@@ -154,7 +154,7 @@ mod tests {
let r0 = E(0); let r0 = E(0);
let r1 = E(1); let r1 = E(1);
let r2 = E(2); let r2 = E(2);
let mut m = EntityMap::new(); let mut m = SecondaryMap::new();
let v: Vec<E> = m.keys().collect(); let v: Vec<E> = m.keys().collect();
assert_eq!(v, []); assert_eq!(v, []);

View File

@@ -7,7 +7,7 @@ use {EntityRef, Keys};
/// A set of `K` for densely indexed entity references. /// A set of `K` for densely indexed entity references.
/// ///
/// The `EntitySet` data structure uses the dense index space to implement a set with a bitvector. /// The `EntitySet` data structure uses the dense index space to implement a set with a bitvector.
/// Like `EntityMap`, an `EntitySet` is used to associate secondary information with entities. /// Like `SecondaryMap`, an `EntitySet` is used to associate secondary information with entities.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct EntitySet<K> pub struct EntitySet<K>
where where

View File

@@ -11,7 +11,7 @@ use std::mem;
use std::slice; use std::slice;
use std::u32; use std::u32;
use std::vec::Vec; use std::vec::Vec;
use {EntityMap, EntityRef}; use {EntityRef, SecondaryMap};
/// Trait for extracting keys from values stored in a `SparseMap`. /// Trait for extracting keys from values stored in a `SparseMap`.
/// ///
@@ -27,16 +27,16 @@ pub trait SparseMapValue<K> {
/// ///
/// A `SparseMap<K, V>` map provides: /// A `SparseMap<K, V>` map provides:
/// ///
/// - Memory usage equivalent to `EntityMap<K, u32>` + `Vec<V>`, so much smaller than /// - Memory usage equivalent to `SecondaryMap<K, u32>` + `Vec<V>`, so much smaller than
/// `EntityMap<K, V>` for sparse mappings of larger `V` types. /// `SecondaryMap<K, V>` for sparse mappings of larger `V` types.
/// - Constant time lookup, slightly slower than `EntityMap`. /// - Constant time lookup, slightly slower than `SecondaryMap`.
/// - A very fast, constant time `clear()` operation. /// - A very fast, constant time `clear()` operation.
/// - Fast insert and erase operations. /// - Fast insert and erase operations.
/// - Stable iteration that is as fast as a `Vec<V>`. /// - Stable iteration that is as fast as a `Vec<V>`.
/// ///
/// # Compared to `EntityMap` /// # Compared to `SecondaryMap`
/// ///
/// When should we use a `SparseMap` instead of a secondary `EntityMap`? First of all, `SparseMap` /// When should we use a `SparseMap` instead of a secondary `SecondaryMap`? First of all, `SparseMap`
/// does not provide the functionality of a `PrimaryMap` which can allocate and assign entity /// does not provide the functionality of a `PrimaryMap` which can allocate and assign entity
/// references to objects as they are pushed onto the map. It is only the secondary entity maps /// references to objects as they are pushed onto the map. It is only the secondary entity maps
/// that can be replaced with a `SparseMap`. /// that can be replaced with a `SparseMap`.
@@ -44,10 +44,10 @@ pub trait SparseMapValue<K> {
/// - A secondary entity map assigns a default mapping to all keys. It doesn't distinguish between /// - A secondary entity map assigns a default mapping to all keys. It doesn't distinguish between
/// an unmapped key and one that maps to the default value. `SparseMap` does not require /// an unmapped key and one that maps to the default value. `SparseMap` does not require
/// `Default` values, and it tracks accurately if a key has been mapped or not. /// `Default` values, and it tracks accurately if a key has been mapped or not.
/// - Iterating over the contents of an `EntityMap` is linear in the size of the *key space*, while /// - Iterating over the contents of an `SecondaryMap` is linear in the size of the *key space*, while
/// iterating over a `SparseMap` is linear in the number of elements in the mapping. This is an /// iterating over a `SparseMap` is linear in the number of elements in the mapping. This is an
/// advantage precisely when the mapping is sparse. /// advantage precisely when the mapping is sparse.
/// - `SparseMap::clear()` is constant time and super-fast. `EntityMap::clear()` is linear in the /// - `SparseMap::clear()` is constant time and super-fast. `SecondaryMap::clear()` is linear in the
/// size of the key space. (Or, rather the required `resize()` call following the `clear()` is). /// size of the key space. (Or, rather the required `resize()` call following the `clear()` is).
/// - `SparseMap` requires the values to implement `SparseMapValue<K>` which means that they must /// - `SparseMap` requires the values to implement `SparseMapValue<K>` which means that they must
/// contain their own key. /// contain their own key.
@@ -56,7 +56,7 @@ where
K: EntityRef, K: EntityRef,
V: SparseMapValue<K>, V: SparseMapValue<K>,
{ {
sparse: EntityMap<K, u32>, sparse: SecondaryMap<K, u32>,
dense: Vec<V>, dense: Vec<V>,
} }
@@ -68,7 +68,7 @@ where
/// Create a new empty mapping. /// Create a new empty mapping.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
sparse: EntityMap::new(), sparse: SecondaryMap::new(),
dense: Vec::new(), dense: Vec::new(),
} }
} }

View File

@@ -1,6 +1,6 @@
//! A frontend for building Cranelift IR from other languages. //! A frontend for building Cranelift IR from other languages.
use cranelift_codegen::cursor::{Cursor, FuncCursor}; use cranelift_codegen::cursor::{Cursor, FuncCursor};
use cranelift_codegen::entity::{EntityMap, EntitySet}; use cranelift_codegen::entity::{EntitySet, SecondaryMap};
use cranelift_codegen::ir; use cranelift_codegen::ir;
use cranelift_codegen::ir::function::DisplayFunction; use cranelift_codegen::ir::function::DisplayFunction;
use cranelift_codegen::ir::{ use cranelift_codegen::ir::{
@@ -24,8 +24,8 @@ use variable::Variable;
/// use here, `variable::Variable` can be used. /// use here, `variable::Variable` can be used.
pub struct FunctionBuilderContext { pub struct FunctionBuilderContext {
ssa: SSABuilder, ssa: SSABuilder,
ebbs: EntityMap<Ebb, EbbData>, ebbs: SecondaryMap<Ebb, EbbData>,
types: EntityMap<Variable, Type>, types: SecondaryMap<Variable, Type>,
} }
/// Temporary object used to build a single Cranelift IR `Function`. /// Temporary object used to build a single Cranelift IR `Function`.
@@ -79,8 +79,8 @@ impl FunctionBuilderContext {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
ssa: SSABuilder::new(), ssa: SSABuilder::new(),
ebbs: EntityMap::new(), ebbs: SecondaryMap::new(),
types: EntityMap::new(), types: SecondaryMap::new(),
} }
} }

View File

@@ -6,7 +6,7 @@
//! Lecture Notes in Computer Science, vol 7791. Springer, Berlin, Heidelberg //! Lecture Notes in Computer Science, vol 7791. Springer, Berlin, Heidelberg
use cranelift_codegen::cursor::{Cursor, FuncCursor}; use cranelift_codegen::cursor::{Cursor, FuncCursor};
use cranelift_codegen::entity::{EntityMap, EntityRef, PrimaryMap}; use cranelift_codegen::entity::{EntityRef, PrimaryMap, SecondaryMap};
use cranelift_codegen::ir::immediates::{Ieee32, Ieee64}; use cranelift_codegen::ir::immediates::{Ieee32, Ieee64};
use cranelift_codegen::ir::instructions::BranchInfo; use cranelift_codegen::ir::instructions::BranchInfo;
use cranelift_codegen::ir::types::{F32, F64}; use cranelift_codegen::ir::types::{F32, F64};
@@ -36,13 +36,13 @@ use Variable;
pub struct SSABuilder { pub struct SSABuilder {
// Records for every variable and for every relevant block, the last definition of // Records for every variable and for every relevant block, the last definition of
// the variable in the block. // the variable in the block.
// TODO: Consider a sparse representation rather than EntityMap-of-EntityMap. // TODO: Consider a sparse representation rather than SecondaryMap-of-SecondaryMap.
variables: EntityMap<Variable, EntityMap<Block, PackedOption<Value>>>, variables: SecondaryMap<Variable, SecondaryMap<Block, PackedOption<Value>>>,
// Records the position of the basic blocks and the list of values used but not defined in the // Records the position of the basic blocks and the list of values used but not defined in the
// block. // block.
blocks: PrimaryMap<Block, BlockData>, blocks: PrimaryMap<Block, BlockData>,
// Records the basic blocks at the beginning of the `Ebb`s. // Records the basic blocks at the beginning of the `Ebb`s.
ebb_headers: EntityMap<Ebb, PackedOption<Block>>, ebb_headers: SecondaryMap<Ebb, PackedOption<Block>>,
// Call and result stacks for use in the `use_var`/`predecessors_lookup` state machine. // Call and result stacks for use in the `use_var`/`predecessors_lookup` state machine.
calls: Vec<Call>, calls: Vec<Call>,
@@ -158,9 +158,9 @@ impl SSABuilder {
/// Allocate a new blank SSA builder struct. Use the API function to interact with the struct. /// Allocate a new blank SSA builder struct. Use the API function to interact with the struct.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
variables: EntityMap::with_default(EntityMap::new()), variables: SecondaryMap::with_default(SecondaryMap::new()),
blocks: PrimaryMap::new(), blocks: PrimaryMap::new(),
ebb_headers: EntityMap::new(), ebb_headers: SecondaryMap::new(),
calls: Vec::new(), calls: Vec::new(),
results: Vec::new(), results: Vec::new(),
side_effects: SideEffects::new(), side_effects: SideEffects::new(),