[llvm] [ThinLTO] Don't convert functions to declarations if `force-import-all` is enabled (PR #134541)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 8 15:54:14 PDT 2025


================
@@ -1701,13 +1701,16 @@ void llvm::thinLTOFinalizeInModule(Module &TheModule,
     if (NewLinkage == GV.getLinkage())
       return;
 
+    bool ForceImportFunction = isa<Function>(GV) && ForceImportAll;
+
     // Check for a non-prevailing def that has interposable linkage
     // (e.g. non-odr weak or linkonce). In that case we can't simply
     // convert to available_externally, since it would lose the
     // interposable property and possibly get inlined. Simply drop
     // the definition in that case.
     if (GlobalValue::isAvailableExternallyLinkage(NewLinkage) &&
-        GlobalValue::isInterposableLinkage(GV.getLinkage())) {
+        GlobalValue::isInterposableLinkage(GV.getLinkage()) &&
+        !ForceImportFunction) {
----------------
shiltian wrote:

> I am not familiar with AMDGPU backend setup and how device function is modeled in LLVM IR. How does available_externally linkage behave in AMDGPU Codegen? Does it still get dropped if not used, and do you need to prevent it from dropped (or you just need them in IR for some reason)?

Yes, that's a good point. It is indeed dropped and that's why I have another [PR](https://github.com/llvm/llvm-project/pull/134476) to prevent it from getting dropped by the pass.

> If the goal is to have all definitions, maybe we should avoid function importer getting to available_externally linkage from the first place and keep weak function as weak. I am not sure if you need to also prevent them from turning into available externally in other linkage type.

For this particular case regarding `__assert_fail`, it is not imported actually since each TU has its own definition. However, it is set to `available_externally` for all non-prevailing ones in `thinLTOResolvePrevailingGUID` as I mentioned earlier.

For the other function that are indeed imported, yes, we might want to consider to change to something else.

https://github.com/llvm/llvm-project/pull/134541


More information about the llvm-commits mailing list