9
9
//! Thomas Lengauer and Robert Endre Tarjan.
10
10
//! <https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf>
11
11
12
- use std:: cmp:: Ordering ;
13
-
14
12
use rustc_index:: { Idx , IndexSlice , IndexVec } ;
15
13
16
14
use super :: ControlFlowGraph ;
@@ -64,9 +62,6 @@ fn is_small_path_graph<G: ControlFlowGraph>(g: &G) -> bool {
64
62
}
65
63
66
64
fn dominators_impl < G : ControlFlowGraph > ( graph : & G ) -> Inner < G :: Node > {
67
- // compute the post order index (rank) for each node
68
- let mut post_order_rank = IndexVec :: from_elem_n ( 0 , graph. num_nodes ( ) ) ;
69
-
70
65
// We allocate capacity for the full set of nodes, because most of the time
71
66
// most of the nodes *are* reachable.
72
67
let mut parent: IndexVec < PreorderIndex , PreorderIndex > =
@@ -83,12 +78,10 @@ fn dominators_impl<G: ControlFlowGraph>(graph: &G) -> Inner<G::Node> {
83
78
pre_order_to_real. push ( graph. start_node ( ) ) ;
84
79
parent. push ( PreorderIndex :: ZERO ) ; // the parent of the root node is the root for now.
85
80
real_to_pre_order[ graph. start_node ( ) ] = Some ( PreorderIndex :: ZERO ) ;
86
- let mut post_order_idx = 0 ;
87
81
88
82
// Traverse the graph, collecting a number of things:
89
83
//
90
84
// * Preorder mapping (to it, and back to the actual ordering)
91
- // * Postorder mapping (used exclusively for `cmp_in_dominator_order` on the final product)
92
85
// * Parents for each vertex in the preorder tree
93
86
//
94
87
// These are all done here rather than through one of the 'standard'
@@ -104,8 +97,6 @@ fn dominators_impl<G: ControlFlowGraph>(graph: &G) -> Inner<G::Node> {
104
97
continue ' recurse;
105
98
}
106
99
}
107
- post_order_rank[ pre_order_to_real[ frame. pre_order_idx ] ] = post_order_idx;
108
- post_order_idx += 1 ;
109
100
110
101
stack. pop ( ) ;
111
102
}
@@ -282,7 +273,7 @@ fn dominators_impl<G: ControlFlowGraph>(graph: &G) -> Inner<G::Node> {
282
273
283
274
let time = compute_access_time ( start_node, & immediate_dominators) ;
284
275
285
- Inner { post_order_rank , immediate_dominators, time }
276
+ Inner { immediate_dominators, time }
286
277
}
287
278
288
279
/// Evaluate the link-eval virtual forest, providing the currently minimum semi
@@ -348,7 +339,6 @@ fn compress(
348
339
/// Tracks the list of dominators for each node.
349
340
#[ derive( Clone , Debug ) ]
350
341
struct Inner < N : Idx > {
351
- post_order_rank : IndexVec < N , usize > ,
352
342
// Even though we track only the immediate dominator of each node, it's
353
343
// possible to get its full list of dominators by looking up the dominator
354
344
// of each dominator.
@@ -379,17 +369,6 @@ impl<Node: Idx> Dominators<Node> {
379
369
}
380
370
}
381
371
382
- /// Provide deterministic ordering of nodes such that, if any two nodes have a dominator
383
- /// relationship, the dominator will always precede the dominated. (The relative ordering
384
- /// of two unrelated nodes will also be consistent, but otherwise the order has no
385
- /// meaning.) This method cannot be used to determine if either Node dominates the other.
386
- pub fn cmp_in_dominator_order ( & self , lhs : Node , rhs : Node ) -> Ordering {
387
- match & self . kind {
388
- Kind :: Path => lhs. index ( ) . cmp ( & rhs. index ( ) ) ,
389
- Kind :: General ( g) => g. post_order_rank [ rhs] . cmp ( & g. post_order_rank [ lhs] ) ,
390
- }
391
- }
392
-
393
372
/// Returns true if `a` dominates `b`.
394
373
///
395
374
/// # Panics
0 commit comments