diff --git a/src/native/reloop_nest/shape.rs b/src/native/reloop_nest/shape.rs index 5f6de1128..fb359427e 100644 --- a/src/native/reloop_nest/shape.rs +++ b/src/native/reloop_nest/shape.rs @@ -113,10 +113,7 @@ impl Graph { stack.push((target, 0)); } // A retreating edge: legal only when the target dominates the source. - 1 if !dominators - .get(&node) - .is_some_and(|doms| doms.contains(&target)) => - { + 1 if !dominators.dominates(target, node) => { return false; } _ => {} @@ -128,43 +125,169 @@ impl Graph { true } - /// Iterative dominator sets over the reachable subgraph. - fn dominators(&self) -> BTreeMap> { - let reachable = self.reachable(); - let mut dominators: BTreeMap> = reachable - .iter() - .map(|label| (*label, reachable.clone())) - .collect(); - if let Some(entry) = dominators.get_mut(&self.entry) { - *entry = BTreeSet::from([self.entry]); + /// The reachable subgraph in reverse postorder, entry first. + /// + /// Reverse postorder is what makes the dominator iteration below converge in a couple of passes + /// instead of one pass per graph depth: every node's predecessors along a forward edge are + /// already final when it is visited. + fn reverse_postorder(&self) -> Vec