[lld] [LLD][ELF] add bp-* options in ELF (PR #120514)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 5 22:20:01 PST 2025
MaskRay wrote:
> If passing -flto -fprofile-use to clang, it also passes -plugin-opt=cs-profile-path to the linker. Therefore, it might be useful to standardize to irpgo-profile or reuse cs-profile-path to avoid duplicate options and simplify the use of this feature. (i.e. end-users only need to use -fprofile-use and -Wl,-bp-*)
> I could be wrong but I think lto-cs-profile-path is used for profile generation with CSIRPGO, not profile consumption. Also, I think it isn't available for MachO so there would be a discrepancy there. I can take a closer look Monday.
Second this. With the typical CSPGO usage lld --lto-cs-profile-path is for context-sensitive profile generation (`if (PGOOpt->CSAction == PGOOptions::CSIRInstr)`).
```
# -fprofile-generate instruments the module
clang -O2 -c -flto=thin -fprofile-generate=profile a.c b.c
# -fprofile-generate just links in the runtime
clang -flto=thin -fprofile-generate=profile -fuse-ld=lld a.o b.o
# collect profile
./a.out
llvm-profdata merge profile/*.profraw -o default.profdata
# -fprofile-use performs optimization. -fcs-profile-generate at ThinLTO prelink phase just runs PGOInstrumentationGenCreateVar to create __llvm_profile_raw_version.
clang -O2 -c -flto=thin -fprofile-use=default.profdata -fcs-profile-generate=csprofile a.c b.c
# Pass -plugin-opt=cs-profile-path=csprofile/default_%m.profraw to lld.
# ThinLTO backend compile performs a post inline PGO instrumentation pass.
# Moreover, link in the runtime.
clang -flto=thin -fcs-profile-generate=csprofile -fuse-ld=lld a.o b.o
# Dump CS profile csprofile/default_%m.profraw
./a.out
# Merge it into the regular PGO profile
llvm-profdata merge default.profdata csprofile/*.profraw -o default.profdata
clang -O2 -c -flto=thin -fprofile-use=default.profdata a.c b.c
clang -flto=thin -fuse-ld=lld a.o b.o
# final executable
./a.out
```
It could also be utilized for CS profile use (`else if (PGOOpt->CSAction == PGOOptions::CSIRUse)`), but there isn't a proper lld test. @xur-llvm
https://github.com/llvm/llvm-project/pull/120514
More information about the llvm-commits
mailing list