Expand remarks hotness threshold option -fdiagnostics-hotness-threshold in clang
driver command-line to both filtering remarks by hotness threshold from profile
summary and automatic remarks options pass-through to linker.
Remarks hotness filtering relies on several driver options. Table below lists
how different options are correlated and affect final remarks outputs:
profile | hotness | threshold | remarks printed |
---|---|---|---|
No | No | No | All |
No | No | Yes | None |
No | Yes | No | All |
No | Yes | Yes | None |
Yes | No | No | All |
Yes | No | Yes | None |
Yes | Yes | No | All |
Yes | Yes | Yes | >=threshold |
The new argument value -fdiagnostics-hotness-threshold=auto indicates threshold
will be synced with hotness threshold from profile summary during compilation.
In addition, when the following conditions are met, remarks related options are
passed into linker as well:
- LTO is enabled;
- Single arch target is specified;
- The linker is lld;
The "auto" threshold relies on the availability of profile summary. In case of
missing such information, no remarks will be generated.
This gives novice user a convenient way to collect and filter remarks throughout
a typical toolchain invocation with sample profile and LTO using single switch
from the clang driver.
A typical use of this option from clang command-line:
- Using -Rpass* options to print remarks to screen:
clang -fuse-ld=lld -flto=thin
-fprofile-sample-use=foo_sample.txt -Rpass=inline -Rpass-missed=inline -Rpass-analysis=inline -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=auto -o foo foo.cpp
Remarks will be dumped to screen from both pre-lto and lto compilation.
- Using serialized remarks options:
clang -fuse-ld=lld -flto=thin
-fprofile-sample-use=foo_sample.txt -fsave-optimization-record -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=auto -o foo foo.cpp
This will produce multiple yaml files containing optimization remarks:
- foo.opt.yaml : remarks from pre-lto
- foo.opt.ld.yaml.thin.1.yaml: remark during lto
Both types of options can be used together.
Given its restricted use cases, this shouldn't be viewed as a complete
replacement of current remarks option handling for the linker.
In order to make the option consistent across various tools, the support for the
new 'auto' argument is also available in the following tools:
- lld: -opt-remarks-with-hotness=auto
- llvm-lto: -lto-pass-remarks-hotness-threshold=auto
- opt/llc: --pass-remarks-hotness-threshold=auto