This patch implements the TODOs in BlockFrequencyInfoImpl.h.
- handle nested irreducible loop.
- true weight distribution among multi-heads of irreducible loop, instead of even split + adjustment by backedge later.
- Use geometric series instead of loop scale for mass iteration. loop scale are still used, but for the purpose of scaling down local mass below 1.0.
- normal code path for reducible loop is not affected.
This patch passes all regression test. Several test cases are changed accordingly. I've changed the @nonentry_header case in irreducible.ll to use
huge weight on the switch instruction to show that 'bottom' block should not be hot.
Method:
- for loop a, found all SCCs, create SCC loops and adjust nodes in its parent node list accordingly.
- In topological order, propagate mass on all SCCs where non-trivial SCCs incur resursion.
- compute start term of geometric series.
- for each header, compute its ratio of geometric series by propogation full mass starting from itself and other block hass empty mass. The cumulated backege mass is ratio.
- find the max ratio among headers.
- compute local scaled down mass for all headers with geometric series equation [a/(1-r)]. assume n is infinity. I've add a TODO in file to see if we should use [a*(1-r^n)/(1-r)].
- Propagate with header mass to other blocks in loop.
This comment seems to now be stale -- rewrite?