A dominator tree can be used to compute natural loops.
- For every node
H
in 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->H
identifies a natural loop withH
as the header.- Perform a flood fill starting from
T
in 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
H
due 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