Rename EntityMap to SecondaryMap (#528)
* Rename `EntityMap` to `SecondaryMap`
This commit is contained in:
committed by
Dan Gohman
parent
7ff71fcfd9
commit
d266b1a42d
@@ -1,6 +1,6 @@
|
||||
//! A Dominator Tree represented as mappings of Ebbs to their immediate dominator.
|
||||
|
||||
use entity::EntityMap;
|
||||
use entity::SecondaryMap;
|
||||
use flowgraph::{BasicBlock, ControlFlowGraph};
|
||||
use ir::instructions::BranchInfo;
|
||||
use ir::{Ebb, ExpandedProgramPoint, Function, Inst, Layout, ProgramOrder, Value};
|
||||
@@ -38,7 +38,7 @@ struct DomNode {
|
||||
|
||||
/// The dominator tree for a single function.
|
||||
pub struct DominatorTree {
|
||||
nodes: EntityMap<Ebb, DomNode>,
|
||||
nodes: SecondaryMap<Ebb, DomNode>,
|
||||
|
||||
/// CFG post-order of all reachable EBBs.
|
||||
postorder: Vec<Ebb>,
|
||||
@@ -217,7 +217,7 @@ impl DominatorTree {
|
||||
/// function.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
nodes: EntityMap::new(),
|
||||
nodes: SecondaryMap::new(),
|
||||
postorder: Vec::new(),
|
||||
stack: Vec::new(),
|
||||
valid: false,
|
||||
@@ -505,7 +505,7 @@ impl DominatorTree {
|
||||
/// 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.
|
||||
pub struct DominatorTreePreorder {
|
||||
nodes: EntityMap<Ebb, ExtraNode>,
|
||||
nodes: SecondaryMap<Ebb, ExtraNode>,
|
||||
|
||||
// Scratch memory used by `compute_postorder()`.
|
||||
stack: Vec<Ebb>,
|
||||
@@ -533,7 +533,7 @@ impl DominatorTreePreorder {
|
||||
/// Create a new blank `DominatorTreePreorder`.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
nodes: EntityMap::new(),
|
||||
nodes: SecondaryMap::new(),
|
||||
stack: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
//! and `(Ebb0, jmp Ebb2)` respectively.
|
||||
|
||||
use bforest;
|
||||
use entity::EntityMap;
|
||||
use entity::SecondaryMap;
|
||||
use ir::instructions::BranchInfo;
|
||||
use ir::{Ebb, Function, Inst};
|
||||
use std::mem;
|
||||
@@ -72,7 +72,7 @@ struct CFGNode {
|
||||
/// and successors where predecessors are basic blocks and successors are
|
||||
/// extended basic blocks.
|
||||
pub struct ControlFlowGraph {
|
||||
data: EntityMap<Ebb, CFGNode>,
|
||||
data: SecondaryMap<Ebb, CFGNode>,
|
||||
pred_forest: bforest::MapForest<Inst, Ebb>,
|
||||
succ_forest: bforest::SetForest<Ebb>,
|
||||
valid: bool,
|
||||
@@ -82,7 +82,7 @@ impl ControlFlowGraph {
|
||||
/// Allocate a new blank control flow graph.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: EntityMap::new(),
|
||||
data: SecondaryMap::new(),
|
||||
valid: false,
|
||||
pred_forest: bforest::MapForest::new(),
|
||||
succ_forest: bforest::SetForest::new(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Data flow graph tracking Instructions, Values, and EBBs.
|
||||
|
||||
use entity::{self, EntityMap, PrimaryMap};
|
||||
use entity::{self, PrimaryMap, SecondaryMap};
|
||||
use ir;
|
||||
use ir::builder::ReplaceBuilder;
|
||||
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
|
||||
/// primary `insts` map.
|
||||
results: EntityMap<Inst, ValueList>,
|
||||
results: SecondaryMap<Inst, ValueList>,
|
||||
|
||||
/// Extended basic blocks in the function and their parameters.
|
||||
///
|
||||
@@ -67,7 +67,7 @@ impl DataFlowGraph {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
insts: PrimaryMap::new(),
|
||||
results: EntityMap::new(),
|
||||
results: SecondaryMap::new(),
|
||||
ebbs: PrimaryMap::new(),
|
||||
value_lists: ValueListPool::new(),
|
||||
values: PrimaryMap::new(),
|
||||
@@ -90,7 +90,7 @@ impl DataFlowGraph {
|
||||
/// Get the total number of instructions created in this function, whether they are 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_insts(&self) -> usize {
|
||||
self.insts.len()
|
||||
}
|
||||
@@ -103,7 +103,7 @@ impl DataFlowGraph {
|
||||
/// Get the total number of extended basic blocks created in this function, whether they are
|
||||
/// 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 {
|
||||
self.ebbs.len()
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! instructions.
|
||||
|
||||
use binemit::CodeOffset;
|
||||
use entity::{EntityMap, PrimaryMap};
|
||||
use entity::{PrimaryMap, SecondaryMap};
|
||||
use ir;
|
||||
use ir::{DataFlowGraph, ExternalName, Layout, Signature};
|
||||
use ir::{
|
||||
@@ -84,10 +84,10 @@ impl Function {
|
||||
jump_tables: PrimaryMap::new(),
|
||||
dfg: DataFlowGraph::new(),
|
||||
layout: Layout::new(),
|
||||
encodings: EntityMap::new(),
|
||||
locations: EntityMap::new(),
|
||||
offsets: EntityMap::new(),
|
||||
srclocs: EntityMap::new(),
|
||||
encodings: SecondaryMap::new(),
|
||||
locations: SecondaryMap::new(),
|
||||
offsets: SecondaryMap::new(),
|
||||
srclocs: SecondaryMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! 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.
|
||||
|
||||
use entity::EntityMap;
|
||||
use entity::SecondaryMap;
|
||||
use ir::progpoint::{ExpandedProgramPoint, ProgramOrder};
|
||||
use ir::{Ebb, Inst};
|
||||
use packed_option::PackedOption;
|
||||
@@ -28,11 +28,11 @@ use timing;
|
||||
pub struct Layout {
|
||||
/// Linked list nodes for the layout order of EBBs Forms a doubly linked list, terminated in
|
||||
/// 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,
|
||||
/// 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: Option<Ebb>,
|
||||
@@ -45,8 +45,8 @@ impl Layout {
|
||||
/// Create a new empty `Layout`.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
ebbs: EntityMap::new(),
|
||||
insts: EntityMap::new(),
|
||||
ebbs: SecondaryMap::new(),
|
||||
insts: SecondaryMap::new(),
|
||||
first_ebb: None,
|
||||
last_ebb: None,
|
||||
}
|
||||
|
||||
@@ -47,20 +47,20 @@ pub use ir::types::Type;
|
||||
pub use ir::valueloc::{ArgumentLoc, ValueLoc};
|
||||
|
||||
use binemit;
|
||||
use entity::{EntityMap, PrimaryMap};
|
||||
use entity::{PrimaryMap, SecondaryMap};
|
||||
use isa;
|
||||
|
||||
/// Map of value locations.
|
||||
pub type ValueLocations = EntityMap<Value, ValueLoc>;
|
||||
pub type ValueLocations = SecondaryMap<Value, ValueLoc>;
|
||||
|
||||
/// Map of jump tables.
|
||||
pub type JumpTables = PrimaryMap<JumpTable, JumpTableData>;
|
||||
|
||||
/// Map of instruction encodings.
|
||||
pub type InstEncodings = EntityMap<Inst, isa::Encoding>;
|
||||
pub type InstEncodings = SecondaryMap<Inst, isa::Encoding>;
|
||||
|
||||
/// Code offsets for EBBs.
|
||||
pub type EbbOffsets = EntityMap<Ebb, binemit::CodeOffset>;
|
||||
pub type EbbOffsets = SecondaryMap<Ebb, binemit::CodeOffset>;
|
||||
|
||||
/// Source locations for instructions.
|
||||
pub type SourceLocs = EntityMap<Inst, SourceLoc>;
|
||||
pub type SourceLocs = SecondaryMap<Inst, SourceLoc>;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! and parent in the loop tree.
|
||||
|
||||
use dominator_tree::DominatorTree;
|
||||
use entity::EntityMap;
|
||||
use entity::SecondaryMap;
|
||||
use entity::{Keys, PrimaryMap};
|
||||
use flowgraph::{BasicBlock, ControlFlowGraph};
|
||||
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.
|
||||
pub struct LoopAnalysis {
|
||||
loops: PrimaryMap<Loop, LoopData>,
|
||||
ebb_loop_map: EntityMap<Ebb, PackedOption<Loop>>,
|
||||
ebb_loop_map: SecondaryMap<Ebb, PackedOption<Loop>>,
|
||||
valid: bool,
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ impl LoopAnalysis {
|
||||
Self {
|
||||
valid: false,
|
||||
loops: PrimaryMap::new(),
|
||||
ebb_loop_map: EntityMap::new(),
|
||||
ebb_loop_map: SecondaryMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Utility routines for pretty-printing error messages.
|
||||
|
||||
use entity::EntityMap;
|
||||
use entity::SecondaryMap;
|
||||
use ir;
|
||||
use ir::entities::{AnyEntity, Inst, Value};
|
||||
use ir::function::Function;
|
||||
@@ -40,7 +40,7 @@ impl<'a> FuncWriter for PrettyVerifierError<'a> {
|
||||
&mut self,
|
||||
w: &mut Write,
|
||||
func: &Function,
|
||||
aliases: &EntityMap<Value, Vec<Value>>,
|
||||
aliases: &SecondaryMap<Value, Vec<Value>>,
|
||||
isa: Option<&TargetIsa>,
|
||||
inst: Inst,
|
||||
indent: usize,
|
||||
@@ -63,7 +63,7 @@ impl<'a> FuncWriter for PrettyVerifierError<'a> {
|
||||
fn pretty_instruction_error(
|
||||
w: &mut Write,
|
||||
func: &Function,
|
||||
aliases: &EntityMap<Value, Vec<Value>>,
|
||||
aliases: &SecondaryMap<Value, Vec<Value>>,
|
||||
isa: Option<&TargetIsa>,
|
||||
cur_inst: Inst,
|
||||
indent: usize,
|
||||
|
||||
@@ -15,7 +15,7 @@ use dbg::DisplayList;
|
||||
use dominator_tree::DominatorTreePreorder;
|
||||
use entity::EntityRef;
|
||||
use entity::{EntityList, ListPool};
|
||||
use entity::{EntityMap, Keys, PrimaryMap};
|
||||
use entity::{Keys, PrimaryMap, SecondaryMap};
|
||||
use ir::{Function, Value};
|
||||
use packed_option::PackedOption;
|
||||
use ref_slice::ref_slice;
|
||||
@@ -45,10 +45,10 @@ pub struct VirtRegs {
|
||||
unused_vregs: Vec<VirtReg>,
|
||||
|
||||
/// 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.
|
||||
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
|
||||
/// registers by the `finish_union_find()` function.
|
||||
@@ -62,8 +62,8 @@ impl VirtRegs {
|
||||
pool: ListPool::new(),
|
||||
vregs: PrimaryMap::new(),
|
||||
unused_vregs: Vec::new(),
|
||||
value_vregs: EntityMap::new(),
|
||||
union_find: EntityMap::new(),
|
||||
value_vregs: SecondaryMap::new(),
|
||||
union_find: SecondaryMap::new(),
|
||||
pending_values: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Verify CPU flags values.
|
||||
|
||||
use entity::{EntityMap, SparseSet};
|
||||
use entity::{SecondaryMap, SparseSet};
|
||||
use flowgraph::{BasicBlock, ControlFlowGraph};
|
||||
use ir;
|
||||
use ir::instructions::BranchInfo;
|
||||
@@ -32,7 +32,7 @@ pub fn verify_flags(
|
||||
func,
|
||||
cfg,
|
||||
encinfo: isa.map(|isa| isa.encoding_info()),
|
||||
livein: EntityMap::new(),
|
||||
livein: SecondaryMap::new(),
|
||||
};
|
||||
verifier.check(errors)
|
||||
}
|
||||
@@ -43,7 +43,7 @@ struct FlagsVerifier<'a> {
|
||||
encinfo: Option<isa::EncInfo>,
|
||||
|
||||
/// 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> {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! 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.
|
||||
|
||||
use entity::EntityMap;
|
||||
use entity::SecondaryMap;
|
||||
use ir::entities::AnyEntity;
|
||||
use ir::{DataFlowGraph, Ebb, Function, Inst, SigRef, Type, Value, ValueDef};
|
||||
use isa::{RegInfo, TargetIsa};
|
||||
@@ -19,7 +19,7 @@ pub trait FuncWriter {
|
||||
&mut self,
|
||||
w: &mut Write,
|
||||
func: &Function,
|
||||
aliases: &EntityMap<Value, Vec<Value>>,
|
||||
aliases: &SecondaryMap<Value, Vec<Value>>,
|
||||
isa: Option<&TargetIsa>,
|
||||
inst: Inst,
|
||||
ident: usize,
|
||||
@@ -101,7 +101,7 @@ impl FuncWriter for PlainWriter {
|
||||
&mut self,
|
||||
w: &mut Write,
|
||||
func: &Function,
|
||||
aliases: &EntityMap<Value, Vec<Value>>,
|
||||
aliases: &SecondaryMap<Value, Vec<Value>>,
|
||||
isa: Option<&TargetIsa>,
|
||||
inst: Inst,
|
||||
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
|
||||
fn alias_map(func: &Function) -> EntityMap<Value, Vec<Value>> {
|
||||
let mut aliases = EntityMap::<_, Vec<_>>::new();
|
||||
fn alias_map(func: &Function) -> SecondaryMap<Value, Vec<Value>> {
|
||||
let mut aliases = SecondaryMap::<_, Vec<_>>::new();
|
||||
for v in func.dfg.values() {
|
||||
// VADFS returns the immediate target of an alias
|
||||
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,
|
||||
w: &mut Write,
|
||||
func: &Function,
|
||||
aliases: &EntityMap<Value, Vec<Value>>,
|
||||
aliases: &SecondaryMap<Value, Vec<Value>>,
|
||||
isa: Option<&TargetIsa>,
|
||||
ebb: Ebb,
|
||||
) -> 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
|
||||
fn write_value_aliases(
|
||||
w: &mut Write,
|
||||
aliases: &EntityMap<Value, Vec<Value>>,
|
||||
aliases: &SecondaryMap<Value, Vec<Value>>,
|
||||
target: Value,
|
||||
indent: usize,
|
||||
) -> fmt::Result {
|
||||
@@ -293,7 +293,7 @@ fn write_value_aliases(
|
||||
fn write_instruction(
|
||||
w: &mut Write,
|
||||
func: &Function,
|
||||
aliases: &EntityMap<Value, Vec<Value>>,
|
||||
aliases: &SecondaryMap<Value, Vec<Value>>,
|
||||
isa: Option<&TargetIsa>,
|
||||
inst: Inst,
|
||||
indent: usize,
|
||||
|
||||
@@ -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.
|
||||
|
||||
Another is that this crate has two core map types, `PrimaryMap` and
|
||||
`EntityMap`, which serve complementary purposes. A `PrimaryMap` creates its
|
||||
own keys when elements are inserted, while an `EntityMap` reuses the keys
|
||||
`SecondaryMap`, which serve complementary purposes. A `PrimaryMap` creates its
|
||||
own keys when elements are inserted, while an `SecondaryMap` reuses the keys
|
||||
values of a `PrimaryMap`, conceptually storing additional data in the same
|
||||
index space. `EntityMap`'s values must implement `Default` and all elements
|
||||
in an `EntityMap` initially have the value of `default()`.
|
||||
index space. `SecondaryMap`'s values must implement `Default` and all elements
|
||||
in an `SecondaryMap` initially have the value of `default()`.
|
||||
|
||||
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
|
||||
@@ -30,9 +30,9 @@ in some cases.
|
||||
Additional utilities provided by this crate include:
|
||||
- `EntityList`, for allocating many small arrays (such as instruction operand
|
||||
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.
|
||||
- `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.
|
||||
|
||||
[slotmap]: https://crates.io/crates/slotmap
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
//!
|
||||
//! - [`PrimaryMap`](struct.PrimaryMap.html) is used to keep track of a vector of entities,
|
||||
//! 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
|
||||
//! been inserted. Instead, any unknown entities map to the default value.
|
||||
//! - [`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;
|
||||
|
||||
/// 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 {
|
||||
/// Create a new entity reference from a small integer.
|
||||
/// 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::keys::Keys;
|
||||
pub use self::list::{EntityList, ListPool};
|
||||
pub use self::map::EntityMap;
|
||||
pub use self::map::SecondaryMap;
|
||||
pub use self::primary::PrimaryMap;
|
||||
pub use self::set::EntitySet;
|
||||
pub use self::sparse::{SparseMap, SparseMapValue, SparseSet};
|
||||
|
||||
@@ -8,14 +8,14 @@ use {EntityRef, Iter, IterMut, Keys};
|
||||
|
||||
/// 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.
|
||||
/// Unlike `PrimaryMap`, an `EntityMap` can't be used to allocate entity references. It is used to
|
||||
/// The `SecondaryMap` data structure uses the dense index space to implement a map with a vector.
|
||||
/// Unlike `PrimaryMap`, an `SecondaryMap` can't be used to allocate entity references. It is used to
|
||||
/// 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
|
||||
/// all keys have a default entry from the beginning.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EntityMap<K, V>
|
||||
pub struct SecondaryMap<K, V>
|
||||
where
|
||||
K: EntityRef,
|
||||
V: Clone,
|
||||
@@ -25,8 +25,8 @@ where
|
||||
unused: PhantomData<K>,
|
||||
}
|
||||
|
||||
/// Shared `EntityMap` implementation for all value types.
|
||||
impl<K, V> EntityMap<K, V>
|
||||
/// Shared `SecondaryMap` implementation for all value types.
|
||||
impl<K, V> SecondaryMap<K, V>
|
||||
where
|
||||
K: EntityRef,
|
||||
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.
|
||||
impl<K, V> Index<K> for EntityMap<K, V>
|
||||
impl<K, V> Index<K> for SecondaryMap<K, V>
|
||||
where
|
||||
K: EntityRef,
|
||||
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.
|
||||
impl<K, V> IndexMut<K> for EntityMap<K, V>
|
||||
impl<K, V> IndexMut<K> for SecondaryMap<K, V>
|
||||
where
|
||||
K: EntityRef,
|
||||
V: Clone,
|
||||
@@ -154,7 +154,7 @@ mod tests {
|
||||
let r0 = E(0);
|
||||
let r1 = E(1);
|
||||
let r2 = E(2);
|
||||
let mut m = EntityMap::new();
|
||||
let mut m = SecondaryMap::new();
|
||||
|
||||
let v: Vec<E> = m.keys().collect();
|
||||
assert_eq!(v, []);
|
||||
|
||||
@@ -7,7 +7,7 @@ use {EntityRef, Keys};
|
||||
/// 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.
|
||||
/// 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)]
|
||||
pub struct EntitySet<K>
|
||||
where
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::mem;
|
||||
use std::slice;
|
||||
use std::u32;
|
||||
use std::vec::Vec;
|
||||
use {EntityMap, EntityRef};
|
||||
use {EntityRef, SecondaryMap};
|
||||
|
||||
/// Trait for extracting keys from values stored in a `SparseMap`.
|
||||
///
|
||||
@@ -27,16 +27,16 @@ pub trait SparseMapValue<K> {
|
||||
///
|
||||
/// A `SparseMap<K, V>` map provides:
|
||||
///
|
||||
/// - Memory usage equivalent to `EntityMap<K, u32>` + `Vec<V>`, so much smaller than
|
||||
/// `EntityMap<K, V>` for sparse mappings of larger `V` types.
|
||||
/// - Constant time lookup, slightly slower than `EntityMap`.
|
||||
/// - Memory usage equivalent to `SecondaryMap<K, u32>` + `Vec<V>`, so much smaller than
|
||||
/// `SecondaryMap<K, V>` for sparse mappings of larger `V` types.
|
||||
/// - Constant time lookup, slightly slower than `SecondaryMap`.
|
||||
/// - A very fast, constant time `clear()` operation.
|
||||
/// - Fast insert and erase operations.
|
||||
/// - 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
|
||||
/// references to objects as they are pushed onto the map. It is only the secondary entity maps
|
||||
/// 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
|
||||
/// 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.
|
||||
/// - 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
|
||||
/// 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).
|
||||
/// - `SparseMap` requires the values to implement `SparseMapValue<K>` which means that they must
|
||||
/// contain their own key.
|
||||
@@ -56,7 +56,7 @@ where
|
||||
K: EntityRef,
|
||||
V: SparseMapValue<K>,
|
||||
{
|
||||
sparse: EntityMap<K, u32>,
|
||||
sparse: SecondaryMap<K, u32>,
|
||||
dense: Vec<V>,
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ where
|
||||
/// Create a new empty mapping.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
sparse: EntityMap::new(),
|
||||
sparse: SecondaryMap::new(),
|
||||
dense: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! A frontend for building Cranelift IR from other languages.
|
||||
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::function::DisplayFunction;
|
||||
use cranelift_codegen::ir::{
|
||||
@@ -24,8 +24,8 @@ use variable::Variable;
|
||||
/// use here, `variable::Variable` can be used.
|
||||
pub struct FunctionBuilderContext {
|
||||
ssa: SSABuilder,
|
||||
ebbs: EntityMap<Ebb, EbbData>,
|
||||
types: EntityMap<Variable, Type>,
|
||||
ebbs: SecondaryMap<Ebb, EbbData>,
|
||||
types: SecondaryMap<Variable, Type>,
|
||||
}
|
||||
|
||||
/// Temporary object used to build a single Cranelift IR `Function`.
|
||||
@@ -79,8 +79,8 @@ impl FunctionBuilderContext {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
ssa: SSABuilder::new(),
|
||||
ebbs: EntityMap::new(),
|
||||
types: EntityMap::new(),
|
||||
ebbs: SecondaryMap::new(),
|
||||
types: SecondaryMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//! Lecture Notes in Computer Science, vol 7791. Springer, Berlin, Heidelberg
|
||||
|
||||
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::instructions::BranchInfo;
|
||||
use cranelift_codegen::ir::types::{F32, F64};
|
||||
@@ -36,13 +36,13 @@ use Variable;
|
||||
pub struct SSABuilder {
|
||||
// Records for every variable and for every relevant block, the last definition of
|
||||
// the variable in the block.
|
||||
// TODO: Consider a sparse representation rather than EntityMap-of-EntityMap.
|
||||
variables: EntityMap<Variable, EntityMap<Block, PackedOption<Value>>>,
|
||||
// TODO: Consider a sparse representation rather than SecondaryMap-of-SecondaryMap.
|
||||
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
|
||||
// block.
|
||||
blocks: PrimaryMap<Block, BlockData>,
|
||||
// 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.
|
||||
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.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
variables: EntityMap::with_default(EntityMap::new()),
|
||||
variables: SecondaryMap::with_default(SecondaryMap::new()),
|
||||
blocks: PrimaryMap::new(),
|
||||
ebb_headers: EntityMap::new(),
|
||||
ebb_headers: SecondaryMap::new(),
|
||||
calls: Vec::new(),
|
||||
results: Vec::new(),
|
||||
side_effects: SideEffects::new(),
|
||||
|
||||
Reference in New Issue
Block a user