[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:17:58 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:
FWIW, the goal here isn't about enabling inlining. What we actually want is to ensure that function definitions exist in every module, regardless of whether the functions get inlined or not. They just can't be converted to declarations.
In fact, the specific case I'm trying to resolve in this PR is a function defined in a header file like this:
```cpp
extern "C" __device__ __attribute__((noinline)) __attribute__((weak)) void __assert_fail(...
```
This function is marked `noinline`, so it won't be inlined. However, it still ends up being converted into a declaration, which is the issue we're trying to fix.
https://github.com/llvm/llvm-project/pull/134541
More information about the llvm-commits
mailing list