diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2021-05-09 14:05:32 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2021-12-06 15:05:22 -0500 |
| commit | 7379d24ebc1ed0bbd8f33b9767b1390ea1a7177d (patch) | |
| tree | 781996d1f51b4158798e64c7cecabdb5655fb0ec /compiler/rustc_data_structures/src | |
| parent | c82fe0efb4591f1a39e135152db77a43a6820c51 (diff) | |
| download | rust-7379d24ebc1ed0bbd8f33b9767b1390ea1a7177d.tar.gz rust-7379d24ebc1ed0bbd8f33b9767b1390ea1a7177d.zip | |
Optimization: process buckets only once
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/graph/dominators/mod.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs index eb6e2b296cd..99119610f93 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs @@ -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); |
