As I worked on analyzing hot spots for large applications I found that iterating on a particular function was painful primarily because recompilation took a long time. For example, compiling SPEC2017/blender in LTO mode takes 30 minutes. Also a debug-only dump is huge since that has to be done for all functions. In this change we are introducing a single method compilation mode where only a function and optionally all callee functions reachable from the specified function will be compiled. This aims at compiling the minimal part of the program to replay the compilation of the user-specified function.
It might be never possible to replay a method compilation accurately without compiling the whole program. For example, a top-down interprocedural pass may propagate a value down from the root entry to the target function. A callee function on the path from entry to the target may return a value that contributes to the target compilation. That said, this change can still help if the compilation it triggers generates the same code with the original full compilation.
To minimized callee function exploding, a profile is used to narrow down the potential indirect call targets. Without a profile, alias analysis or type analysis can be used instead. This is not done in this change.
The mode works with non-LTO, thinLTO and fullLTO modes. More specifically, the following switches are introduced. All switches can be specified multiple times in one invocation with input aggregated.
- A clang switch -fsingle-func=Name for non-LTO.
- A lld switch --lto-single-func=Name for LTO.
- An opt switch -single-func=Name.
clang-tidy: warning: invalid case style for member 'LTOFunctionsToCompile' [readability-identifier-naming]
not useful