Rollup merge of #81338 - bugadani:dominator-cleanup, r=davidtwco
Clean up `dominators_given_rpo`
This commit is contained in:
commit
529f15f9b9
@ -8,7 +8,6 @@
|
||||
use super::iterate::reverse_post_order;
|
||||
use super::ControlFlowGraph;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use std::borrow::BorrowMut;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[cfg(test)]
|
||||
@ -20,22 +19,17 @@ pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
|
||||
dominators_given_rpo(graph, &rpo)
|
||||
}
|
||||
|
||||
fn dominators_given_rpo<G: ControlFlowGraph + BorrowMut<G>>(
|
||||
mut graph: G,
|
||||
rpo: &[G::Node],
|
||||
) -> Dominators<G::Node> {
|
||||
let start_node = graph.borrow().start_node();
|
||||
fn dominators_given_rpo<G: ControlFlowGraph>(graph: G, rpo: &[G::Node]) -> Dominators<G::Node> {
|
||||
let start_node = graph.start_node();
|
||||
assert_eq!(rpo[0], start_node);
|
||||
|
||||
// compute the post order index (rank) for each node
|
||||
let mut post_order_rank: IndexVec<G::Node, usize> =
|
||||
(0..graph.borrow().num_nodes()).map(|_| 0).collect();
|
||||
let mut post_order_rank = IndexVec::from_elem_n(0, graph.num_nodes());
|
||||
for (index, node) in rpo.iter().rev().cloned().enumerate() {
|
||||
post_order_rank[node] = index;
|
||||
}
|
||||
|
||||
let mut immediate_dominators: IndexVec<G::Node, Option<G::Node>> =
|
||||
(0..graph.borrow().num_nodes()).map(|_| None).collect();
|
||||
let mut immediate_dominators = IndexVec::from_elem_n(None, graph.num_nodes());
|
||||
immediate_dominators[start_node] = Some(start_node);
|
||||
|
||||
let mut changed = true;
|
||||
@ -44,7 +38,7 @@ fn dominators_given_rpo<G: ControlFlowGraph + BorrowMut<G>>(
|
||||
|
||||
for &node in &rpo[1..] {
|
||||
let mut new_idom = None;
|
||||
for pred in graph.borrow_mut().predecessors(node) {
|
||||
for pred in graph.predecessors(node) {
|
||||
if immediate_dominators[pred].is_some() {
|
||||
// (*) dominators for `pred` have been calculated
|
||||
new_idom = Some(if let Some(new_idom) = new_idom {
|
||||
|
Loading…
Reference in New Issue
Block a user