Optimization: process buckets only once

This commit is contained in:
Mark Rousskov 2021-05-09 14:05:32 -04:00
parent c82fe0efb4
commit 7379d24ebc

View File

@ -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);
@ -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);