[LifetimeSafety] Add bailout for large CFGs (#170444)
This PR introduces a flag for setting a threshold size for CFG blocks
above which lifetime safety analysis will skip processing those CFGs.
The major contributor of compilation time increase due to lifetime
safety analysis is the costly join operation during loan propagation.
This can be avoided at the cost of introducing some false negatives by
ignoring some large CFG blocks.
The `block-size-threshold` flag accepts an integer value which serves as
the threshold. CFG blocks with size above this threshold are ignored.
This value is only used if an integer > 0 is passed to it. By default it
is set to 0 and no CFG blocks are skipped during analysis. The CFG block
size refers to the number of facts associated with a CFG block. This PR
also adds a debug-only option that dumps the sizes of CFG blocks
associated with an analysis context:
Example output (for `llvm-project/llvm/lib/Demangle/Demangle.cpp`):
With different values for `MaxCfgBlocks` the values for
`task-clock:uppp_event` are as follows (the files are taken from there
top files
[here](https://llvm-compile-time-tracker.com/compare_clang.php?from=128eacfaba78162c944c073270db02e237b7b851&to=e39caf5a04aadf6053470b7843a4d987250083f1&stat=instructions%3Au&sortBy=absolute-difference))
| | CompilerInvocation.cpp | | | SemaARM.cpp | | | X86ISelLowering.cpp |
| |
|:---------------:|:----------------------:|:----------------------:|:----------------------:|:--------------:|:------------------------:|:----------------------:|:-------------------:|:-----------------------:|:-----------------------:|
| | No bailout | >5000 | >1000 | No bailout | >5000 | >1000 | No bailout
| >5000 | >1000 |
| Total Time | 27,143,500,000 | 27,108,750,000 (-0.1%) | 27,058,000,000
(-0.3%) | 13,819,750,000 | 13,807,750,000 (-0.086%) | 13,790,500,000
(-0.2%) | 49,580,250,000 | 49,248,500,000 (-0.67%) | 49,422,000,000
(-0.42%) |
| Lifetime Safety | 97,000,000 | 95,500,000 (-1.5%) | 91,250,000 (-5.9%)
| 68,750,000 | 64,500,000 (-6.18%) | 63,750,000 (-7.27%) | 131,500,000 |
130,250,000 (-0.9%) | 124,500,000 (-5.3%) |