Commit f6b0a734 authored by xumingjie.enna1's avatar xumingjie.enna1
Browse files

[BPI] Cache LoopExitBlocks to improve compile time

The `LoopBlock` stored in `LoopWorkList` consist of basic block and its loop
data information. When iterate `LoopWorkList`, if estimated weight of a loop
is not stored in `EstimatedLoopWeight`, `getLoopExitBlocks()` is called to get
all exit blocks of the loop. The estimated weight of a loop is calculated by
iterating over edges leading from basic block to all exit blocks of the loop.
If at least one edge has unknown estimated weight, the estimated weight of loop
is unknown and will not be stored in `EstimatedLoopWeight`.
`LoopWorkList` can contain different blocks in a same loop, so there is
wasted work that calls `getLoopExitBlocks()` for same loop multiple times.

Since computing the exit blocks of loop is expensive and the loop structure is
not mutated in Branch Probability Analysis, we can cache the result and improve
compile time.

With this change, the overall compile time for a file containing a
very large loop is dropped by around 82%.
parent bafda89a
Pipeline #2737 failed with stages
in 0 seconds
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment