Skip to content

Commit fd9f457

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 0d68bad commit fd9f457

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
define void @f1(ptr %v) #0 {
2+
entry:
3+
call void @weak_common(ptr %v)
4+
ret void
5+
}
6+
7+
define weak hidden void @weak_common(ptr %v) #0 {
8+
entry:
9+
store i32 12345, ptr %v
10+
ret void
11+
}
12+
13+
attributes #0 = { noinline }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
define void @f2(ptr %v) #0 {
2+
entry:
3+
call void @weak_common(ptr %v)
4+
ret void
5+
}
6+
7+
define weak hidden void @weak_common(ptr %v) #0 {
8+
entry:
9+
store i32 12345, ptr %v
10+
ret void
11+
}
12+
13+
attributes #0 = { noinline }
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %s -o %t.main.bc
2+
; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %p/Inputs/in-0.ll -o %t.in.0.bc
3+
; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %p/Inputs/in-1.ll -o %t.in.1.bc
4+
; RUN: llvm-lto -thinlto-action=run -force-import-all %t.main.bc %t.in.0.bc %t.in.1.bc --thinlto-save-temps=%t.2.
5+
; RUN: llvm-dis %t.2.0.3.imported.bc -o - | FileCheck --check-prefix=MOD1 %s
6+
; RUN: llvm-dis %t.2.1.3.imported.bc -o - | FileCheck --check-prefix=MOD2 %s
7+
; RUN: llvm-dis %t.2.2.3.imported.bc -o - | FileCheck --check-prefix=MOD3 %s
8+
9+
define void @f0(ptr %p) #0 {
10+
entry:
11+
call void @f1(ptr %p)
12+
call void @f2(ptr %p)
13+
ret void
14+
}
15+
16+
define weak hidden void @weak_common(ptr %v) #0 {
17+
entry:
18+
store i32 12345, ptr %v
19+
ret void
20+
}
21+
22+
declare void @f1(ptr)
23+
24+
declare void @f2(ptr)
25+
26+
attributes #0 = { noinline }
27+
28+
; MOD1: define available_externally void @f1
29+
; MOD1: define available_externally void @f2
30+
31+
; MOD2: define void @f1
32+
; MOD2: define available_externally hidden void @weak_common
33+
34+
; MOD3: define void @f2
35+
; MOD3: define available_externally hidden void @weak_common
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)