Skip to content

Commit

Permalink
Optimization: process buckets only once
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Dec 6, 2021
1 parent c82fe0e commit 7379d24
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions compiler/rustc_data_structures/src/graph/dominators/mod.rs
Expand Up @@ -72,6 +72,14 @@ fn dominators_given_rpo<G: ControlFlowGraph>(graph: G, rpo: &[G::Node]) -> Domin
let mut lastlinked = None;

for &w in pre_order_nodes[1..].iter().rev() {
// Optimization: process buckets just once. We need not explicitly empty
// the bucket here, but mem::take is pretty cheap.
let z = parent[w].unwrap();
for v in std::mem::take(&mut bucket[z]) {
let y = eval(&pre_order_index, &mut parent, lastlinked, &semi, &mut label, v);
idom[v] = if pre_order_index[semi[y]] < pre_order_index[z] { y } else { z };
}

semi[w] = w;
for v in graph.predecessors(w) {
let x = eval(&pre_order_index, &mut parent, lastlinked, &semi, &mut label, v);
Expand All @@ -85,13 +93,6 @@ fn dominators_given_rpo<G: ControlFlowGraph>(graph: G, rpo: &[G::Node]) -> Domin

bucket[semi[w]].push(w);

link(&mut ancestor, &parent, w);
let z = parent[w].unwrap();
for v in std::mem::take(&mut bucket[z]) {
let y = eval(&pre_order_index, &mut ancestor, &semi, &mut label, v);
idom[v] = if pre_order_index[semi[y]] < pre_order_index[z] { y } else { z };
}

// Optimization: We share the parent array between processed and not
// processed elements; lastlinked represents the divider.
lastlinked = Some(w);
Expand Down

0 comments on commit 7379d24

Please sign in to comment.