Improve coalescing performance by using a FxHashMap (#340)
* Use FxHashMap instead of HashMap for better performance * Replace the binary search in the coalescing pass with a FxHashMap This speeds up coalescing by up to 16% and overall compilation by 9%
This commit is contained in:
committed by
Dan Gohman
parent
80fdfb2376
commit
e9d362d902
@@ -10,6 +10,7 @@ use cursor::{Cursor, EncCursor};
|
||||
use dbg::DisplayList;
|
||||
use dominator_tree::{DominatorTree, DominatorTreePreorder};
|
||||
use flowgraph::ControlFlowGraph;
|
||||
use fx::FxHashMap;
|
||||
use ir::{self, InstBuilder, ProgramOrder};
|
||||
use ir::{Ebb, ExpandedProgramPoint, Function, Inst, Value};
|
||||
use isa::{EncInfo, TargetIsa};
|
||||
@@ -883,11 +884,9 @@ struct VirtualCopies {
|
||||
|
||||
// Filter for the currently active node iterator.
|
||||
//
|
||||
// An (ebb, set_id, num) entry means that branches to `ebb` are active in `set_id` with branch
|
||||
// An ebb => (set_id, num) entry means that branches to `ebb` are active in `set_id` with branch
|
||||
// argument number `num`.
|
||||
//
|
||||
// This is ordered by EBB number for fast binary search.
|
||||
filter: Vec<(Ebb, u8, usize)>,
|
||||
filter: FxHashMap<Ebb, (u8, usize)>,
|
||||
}
|
||||
|
||||
impl VirtualCopies {
|
||||
@@ -896,7 +895,7 @@ impl VirtualCopies {
|
||||
Self {
|
||||
params: Vec::new(),
|
||||
branches: Vec::new(),
|
||||
filter: Vec::new(),
|
||||
filter: FxHashMap(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1010,12 +1009,10 @@ impl VirtualCopies {
|
||||
// Stop once we're outside the bounds of `self.params`.
|
||||
break;
|
||||
}
|
||||
self.filter.push((ebb, set_id, num));
|
||||
self.filter.insert(ebb, (set_id, num));
|
||||
}
|
||||
}
|
||||
}
|
||||
// We'll be using `binary_search_by` with the numerical EBB ordering.
|
||||
self.filter.sort_unstable();
|
||||
}
|
||||
|
||||
/// Look up the set_id and argument number for `ebb` in the current filter.
|
||||
@@ -1023,13 +1020,7 @@ impl VirtualCopies {
|
||||
/// Returns `None` if none of the currently active parameters are defined at `ebb`. Otherwise
|
||||
/// returns `(set_id, argnum)` for an active parameter defined at `ebb`.
|
||||
fn lookup(&self, ebb: Ebb) -> Option<(u8, usize)> {
|
||||
self.filter
|
||||
.binary_search_by(|&(e, _, _)| e.cmp(&ebb))
|
||||
.ok()
|
||||
.map(|i| {
|
||||
let t = self.filter[i];
|
||||
(t.1, t.2)
|
||||
})
|
||||
self.filter.get(&ebb).map(|t| *t)
|
||||
}
|
||||
|
||||
/// Get an iterator of dom-forest nodes corresponding to the current filter.
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
use dominator_tree::DominatorTree;
|
||||
use entity::{EntityList, ListPool};
|
||||
use fx::FxHashMap;
|
||||
use ir::{DataFlowGraph, Ebb, ExpandedProgramPoint, Inst, Layout, Value};
|
||||
use partition_slice::partition_slice;
|
||||
use regalloc::affinity::Affinity;
|
||||
use regalloc::liveness::Liveness;
|
||||
use regalloc::liverange::LiveRange;
|
||||
use std::collections::HashMap;
|
||||
use std::vec::Vec;
|
||||
|
||||
type ValueList = EntityList<Value>;
|
||||
@@ -25,7 +25,7 @@ pub struct LiveValueTracker {
|
||||
/// dominator of an EBB.
|
||||
///
|
||||
/// This is the set of values that are live *before* the branch.
|
||||
idom_sets: HashMap<Inst, ValueList>,
|
||||
idom_sets: FxHashMap<Inst, ValueList>,
|
||||
|
||||
/// Memory pool for the live sets.
|
||||
idom_pool: ListPool<Value>,
|
||||
@@ -128,7 +128,7 @@ impl LiveValueTracker {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
live: LiveValueVec::new(),
|
||||
idom_sets: HashMap::new(),
|
||||
idom_sets: FxHashMap(),
|
||||
idom_pool: ListPool::new(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user