[compiler-rt] [llvm] [ThinLTO][TypeProf] Allow importing of local-linkage global variables in mod1:func_foo->mod2:func_bar -> mod2:local-var chain (PR #100448)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 12:52:17 PDT 2024
minglotus-6 wrote:
> Mentioned offline to Mingming, but this code is looking at the module of the immediate referencing function, so that would be mod2. Mingming will dig a bit to see why this isn't working.
I think you are correct that `local-var` would get imported with the ref chain `mod1:func_foo` -> `mod2:func_bar` -> `mod2:local-var`.
Here is why import of `local-var` doesn't happen for the test case without this option
1) local-vtable for Derived2 get annotated on `main` function in main.cpp with `-enable-vtable-value-profiling` on.
2) `createType` is noinline so it doesn't get imported from lib.cpp to main.cpp
3) `main` wants to import Derived2 and won't do it without this option.
The diff in [1] gives this debugging log
```
./bin/clang --driver-mode=g++ -m64 -fuse-ld=lld -ldl -m64 -fprofile-use=test.profdata -Wl,--lto-whole-program-visibility -mllvm -disable-icp=true -Wl,-mllvm,-disable-icp=false -fuse-ld=lld -g -flto=thin -fwhole-program-vtables -fno-split-lto-unit -O2 -mllvm -enable-vtable-value-profiling -Wl,-mllvm,-enable-vtable-value-profiling -mllvm -enable-vtable-profile-use -Wl,-mllvm,-enable-vtable-profile-use -Rpass=pgo-icall-prom -Wl,-mllvm,-print-after=pgo-icall-prom -Wl,-mllvm,-filter-print-funcs=main lib.cpp main.cpp
Ref VI is 10484448250040508243 (_ZTVN12_GLOBAL__N_18Derived2E)
/tmp/lib-ec0ef8.o
/tmp/main-c0fd89.o
Local 10484448250040508243 (_ZTVN12_GLOBAL__N_18Derived2E) is in module /tmp/lib-ec0ef8.obut NOT in module /tmp/main-c0fd89.o
```
[1]
```
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -385,8 +385,15 @@ class GlobalsImporter final {
errs() << "Ref VI is " << VI << "\n";
errs() << RefSummary->modulePath() << "\n";
errs() << Summary.modulePath() << "\n";
- return GlobalValue::isLocalLinkage(RefSummary->linkage()) &&
- RefSummary->modulePath() != Summary.modulePath();
+
+ const bool LocalNotInMod =
+ GlobalValue::isLocalLinkage(RefSummary->linkage()) &&
+ RefSummary->modulePath() != Summary.modulePath();
+ if (LocalNotInMod)
+ errs() << "\tLocal " << VI << " is in module "
+ << RefSummary->modulePath() << "but NOT in module "
+ << Summary.modulePath() << "\n";
+ return LocalNotInMod;
};
for (const auto &RefSummary : VI.getSummaryList()) {
```
https://github.com/llvm/llvm-project/pull/100448
More information about the llvm-commits
mailing list