A dominator tree can be used to compute natural loops.
- For every node
Hin a post-order traversal of the dominator tree (or the original CFG), find all predecessors that are dominated byH. This identifies all back edges. - Each back edge
T->Hidentifies a natural loop withHas the header.- Perform a flood fill starting from
Tin the reversed dominator tree (from exiting block to header) - All visited nodes reachable from the root belong to the natural loop
associated with the back edge. These nodes are guaranteed to be
reachable from
Hdue to the dominator property. - Visited nodes unreachable from the root should be ignored.
- Loops associated with visited nodes are considered subloops.
- Perform a flood fill starting from