Skip to content

Commit 60dd2c2

Browse files
committed
[ThinLTO] Don't convert functions to declarations if force-import-all is enabled
On one hand, we intend to `force-import-all` functions when the option is enabled. On the other hand, we currently drop definitions of some functions and convert them to declarations, which contradicts this intent. With this PR, functions will no longer be converted to declarations when `force-import-all` is enabled.
1 parent 449e2f5 commit 60dd2c2

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,13 +1701,16 @@ void llvm::thinLTOFinalizeInModule(Module &TheModule,
17011701
if (NewLinkage == GV.getLinkage())
17021702
return;
17031703

1704+
bool ForceImportFunction = isa<Function>(GV) && ForceImportAll;
1705+
17041706
// Check for a non-prevailing def that has interposable linkage
17051707
// (e.g. non-odr weak or linkonce). In that case we can't simply
17061708
// convert to available_externally, since it would lose the
17071709
// interposable property and possibly get inlined. Simply drop
17081710
// the definition in that case.
17091711
if (GlobalValue::isAvailableExternallyLinkage(NewLinkage) &&
1710-
GlobalValue::isInterposableLinkage(GV.getLinkage())) {
1712+
GlobalValue::isInterposableLinkage(GV.getLinkage()) &&
1713+
!ForceImportFunction) {
17111714
if (!convertToDeclaration(GV))
17121715
// FIXME: Change this to collect replaced GVs and later erase
17131716
// them from the parent module once thinLTOResolvePrevailingGUID is
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
define void @f2(ptr %v) #0 {
2+
entry:
3+
%v.addr = alloca ptr, align 8, addrspace(5)
4+
store ptr %v, ptr addrspace(5) %v.addr, align 8
5+
call void @f3(ptr %v)
6+
ret void
7+
}
8+
9+
define weak hidden void @f3(ptr %v) #0 {
10+
entry:
11+
store i32 12345, ptr %v
12+
ret void
13+
}
14+
15+
attributes #0 = { noinline }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %s -o %t1.bc
2+
; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %p/Inputs/noinline.ll -o %t2.bc
3+
; RUN: llvm-lto -thinlto-action=thinlink -force-import-all %t1.bc %t2.bc -o %t3.index.bc
4+
; RUN: llvm-lto -thinlto-action=import -force-import-all %t1.bc %t2.bc --thinlto-index=%t3.index.bc -thinlto-save-temps=%t3.
5+
; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s --check-prefix=MOD1
6+
; RUN: llvm-dis %t3.1.3.imported.bc -o - | FileCheck %s --check-prefix=MOD2
7+
8+
define i32 @f1(ptr %p) #0 {
9+
entry:
10+
call void @f2(ptr %p)
11+
ret i32 0
12+
}
13+
14+
define weak hidden void @f3(ptr %v) #0 {
15+
entry:
16+
store i32 12345, ptr %v
17+
ret void
18+
}
19+
20+
declare void @f2(ptr)
21+
22+
attributes #0 = { noinline }
23+
24+
; MOD1: define weak hidden void @f3
25+
; MOD1: define available_externally void @f2
26+
; MOD2: define void @f2
27+
; MOD2: define available_externally hidden void @f3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not "AMDGPU" in config.root.targets:
2+
config.unsupported = True

0 commit comments

Comments
 (0)