Process current bucket instead of parent's bucket when starting loop for dominators.
This commit is contained in:
@@ -109,28 +109,27 @@ pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
|
||||
// they have been placed in the bucket.
|
||||
//
|
||||
// We compute a partial set of immediate dominators here.
|
||||
let z = parent[w];
|
||||
for &v in bucket[z].iter() {
|
||||
for &v in bucket[w].iter() {
|
||||
// This uses the result of Lemma 5 from section 2 from the original
|
||||
// 1979 paper, to compute either the immediate or relative dominator
|
||||
// for a given vertex v.
|
||||
//
|
||||
// eval returns a vertex y, for which semi[y] is minimum among
|
||||
// vertices semi[v] +> y *> v. Note that semi[v] = z as we're in the
|
||||
// z bucket.
|
||||
// vertices semi[v] +> y *> v. Note that semi[v] = w as we're in the
|
||||
// w bucket.
|
||||
//
|
||||
// Given such a vertex y, semi[y] <= semi[v] and idom[y] = idom[v].
|
||||
// If semi[y] = semi[v], though, idom[v] = semi[v].
|
||||
//
|
||||
// Using this, we can either set idom[v] to be:
|
||||
// * semi[v] (i.e. z), if semi[y] is z
|
||||
// * semi[v] (i.e. w), if semi[y] is w
|
||||
// * idom[y], otherwise
|
||||
//
|
||||
// We don't directly set to idom[y] though as it's not necessarily
|
||||
// known yet. The second preorder traversal will cleanup by updating
|
||||
// the idom for any that were missed in this pass.
|
||||
let y = eval(&mut parent, lastlinked, &semi, &mut label, v);
|
||||
idom[v] = if semi[y] < z { y } else { z };
|
||||
idom[v] = if semi[y] < w { y } else { w };
|
||||
}
|
||||
|
||||
// This loop computes the semi[w] for w.
|
||||
@@ -213,10 +212,11 @@ pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
|
||||
// If we don't yet know the idom directly, then push this vertex into
|
||||
// our semidominator's bucket, where it will get processed at a later
|
||||
// stage to compute its immediate dominator.
|
||||
if parent[w] != semi[w] {
|
||||
let z = parent[w];
|
||||
if z != semi[w] {
|
||||
bucket[semi[w]].push(w);
|
||||
} else {
|
||||
idom[w] = parent[w];
|
||||
idom[w] = z;
|
||||
}
|
||||
|
||||
// Optimization: We share the parent array between processed and not
|
||||
|
||||
Reference in New Issue
Block a user