Skip to content

Commit 7379d24

Browse files
Optimization: process buckets only once
1 parent c82fe0e commit 7379d24

File tree

1 file changed

+8
-7
lines changed
  • compiler/rustc_data_structures/src/graph/dominators

1 file changed

+8
-7
lines changed

compiler/rustc_data_structures/src/graph/dominators/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ fn dominators_given_rpo<G: ControlFlowGraph>(graph: G, rpo: &[G::Node]) -> Domin
7272
let mut lastlinked = None;
7373

7474
for &w in pre_order_nodes[1..].iter().rev() {
75+
// Optimization: process buckets just once. We need not explicitly empty
76+
// the bucket here, but mem::take is pretty cheap.
77+
let z = parent[w].unwrap();
78+
for v in std::mem::take(&mut bucket[z]) {
79+
let y = eval(&pre_order_index, &mut parent, lastlinked, &semi, &mut label, v);
80+
idom[v] = if pre_order_index[semi[y]] < pre_order_index[z] { y } else { z };
81+
}
82+
7583
semi[w] = w;
7684
for v in graph.predecessors(w) {
7785
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
8593

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

88-
link(&mut ancestor, &parent, w);
89-
let z = parent[w].unwrap();
90-
for v in std::mem::take(&mut bucket[z]) {
91-
let y = eval(&pre_order_index, &mut ancestor, &semi, &mut label, v);
92-
idom[v] = if pre_order_index[semi[y]] < pre_order_index[z] { y } else { z };
93-
}
94-
9596
// Optimization: We share the parent array between processed and not
9697
// processed elements; lastlinked represents the divider.
9798
lastlinked = Some(w);

0 commit comments

Comments
 (0)