-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[ThinLTO] Don't convert functions to declarations if force-import-all is enabled
#134541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ThinLTO] Don't convert functions to declarations if force-import-all is enabled
#134541
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@llvm/pr-subscribers-llvm-transforms Author: Shilei Tian (shiltian) ChangesOn one hand, we intend to With this PR, functions will no longer be converted to declarations when Full diff: https://github.com/llvm/llvm-project/pull/134541.diff 4 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index f1dce5d7904f9..19a6bc55b0147 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -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) {
if (!convertToDeclaration(GV))
// FIXME: Change this to collect replaced GVs and later erase
// them from the parent module once thinLTOResolvePrevailingGUID is
diff --git a/llvm/test/ThinLTO/AMDGPU/Inputs/noinline.ll b/llvm/test/ThinLTO/AMDGPU/Inputs/noinline.ll
new file mode 100644
index 0000000000000..6f93f880c3157
--- /dev/null
+++ b/llvm/test/ThinLTO/AMDGPU/Inputs/noinline.ll
@@ -0,0 +1,15 @@
+define void @f2(ptr %v) #0 {
+entry:
+ %v.addr = alloca ptr, align 8, addrspace(5)
+ store ptr %v, ptr addrspace(5) %v.addr, align 8
+ call void @f3(ptr %v)
+ ret void
+}
+
+define weak hidden void @f3(ptr %v) #0 {
+entry:
+ store i32 12345, ptr %v
+ ret void
+}
+
+attributes #0 = { noinline }
diff --git a/llvm/test/ThinLTO/AMDGPU/force-import-all.ll b/llvm/test/ThinLTO/AMDGPU/force-import-all.ll
new file mode 100644
index 0000000000000..f8beb0dae390f
--- /dev/null
+++ b/llvm/test/ThinLTO/AMDGPU/force-import-all.ll
@@ -0,0 +1,26 @@
+; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %s -o %t1.bc
+; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %p/Inputs/noinline.ll -o %t2.bc
+; RUN: llvm-lto -thinlto-action=run -force-import-all %t1.bc %t2.bc -thinlto-save-temps=%t3.
+; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s --check-prefix=MOD1
+; RUN: llvm-dis %t3.1.3.imported.bc -o - | FileCheck %s --check-prefix=MOD2
+
+define i32 @f1(ptr %p) #0 {
+entry:
+ call void @f2(ptr %p)
+ ret i32 0
+}
+
+define weak hidden void @f3(ptr %v) #0 {
+entry:
+ store i32 12345, ptr %v
+ ret void
+}
+
+declare void @f2(ptr)
+
+attributes #0 = { noinline }
+
+; MOD1: define weak hidden void @f3
+; MOD1: define available_externally void @f2
+; MOD2: define void @f2
+; MOD2: define available_externally hidden void @f3
diff --git a/llvm/test/ThinLTO/AMDGPU/lit.local.cfg b/llvm/test/ThinLTO/AMDGPU/lit.local.cfg
new file mode 100644
index 0000000000000..7c492428aec76
--- /dev/null
+++ b/llvm/test/ThinLTO/AMDGPU/lit.local.cfg
@@ -0,0 +1,2 @@
+if not "AMDGPU" in config.root.targets:
+ config.unsupported = True
|
|
@llvm/pr-subscribers-backend-amdgpu Author: Shilei Tian (shiltian) ChangesOn one hand, we intend to With this PR, functions will no longer be converted to declarations when Full diff: https://github.com/llvm/llvm-project/pull/134541.diff 4 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index f1dce5d7904f9..19a6bc55b0147 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -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) {
if (!convertToDeclaration(GV))
// FIXME: Change this to collect replaced GVs and later erase
// them from the parent module once thinLTOResolvePrevailingGUID is
diff --git a/llvm/test/ThinLTO/AMDGPU/Inputs/noinline.ll b/llvm/test/ThinLTO/AMDGPU/Inputs/noinline.ll
new file mode 100644
index 0000000000000..6f93f880c3157
--- /dev/null
+++ b/llvm/test/ThinLTO/AMDGPU/Inputs/noinline.ll
@@ -0,0 +1,15 @@
+define void @f2(ptr %v) #0 {
+entry:
+ %v.addr = alloca ptr, align 8, addrspace(5)
+ store ptr %v, ptr addrspace(5) %v.addr, align 8
+ call void @f3(ptr %v)
+ ret void
+}
+
+define weak hidden void @f3(ptr %v) #0 {
+entry:
+ store i32 12345, ptr %v
+ ret void
+}
+
+attributes #0 = { noinline }
diff --git a/llvm/test/ThinLTO/AMDGPU/force-import-all.ll b/llvm/test/ThinLTO/AMDGPU/force-import-all.ll
new file mode 100644
index 0000000000000..f8beb0dae390f
--- /dev/null
+++ b/llvm/test/ThinLTO/AMDGPU/force-import-all.ll
@@ -0,0 +1,26 @@
+; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %s -o %t1.bc
+; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %p/Inputs/noinline.ll -o %t2.bc
+; RUN: llvm-lto -thinlto-action=run -force-import-all %t1.bc %t2.bc -thinlto-save-temps=%t3.
+; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s --check-prefix=MOD1
+; RUN: llvm-dis %t3.1.3.imported.bc -o - | FileCheck %s --check-prefix=MOD2
+
+define i32 @f1(ptr %p) #0 {
+entry:
+ call void @f2(ptr %p)
+ ret i32 0
+}
+
+define weak hidden void @f3(ptr %v) #0 {
+entry:
+ store i32 12345, ptr %v
+ ret void
+}
+
+declare void @f2(ptr)
+
+attributes #0 = { noinline }
+
+; MOD1: define weak hidden void @f3
+; MOD1: define available_externally void @f2
+; MOD2: define void @f2
+; MOD2: define available_externally hidden void @f3
diff --git a/llvm/test/ThinLTO/AMDGPU/lit.local.cfg b/llvm/test/ThinLTO/AMDGPU/lit.local.cfg
new file mode 100644
index 0000000000000..7c492428aec76
--- /dev/null
+++ b/llvm/test/ThinLTO/AMDGPU/lit.local.cfg
@@ -0,0 +1,2 @@
+if not "AMDGPU" in config.root.targets:
+ config.unsupported = True
|
|
@llvm/pr-subscribers-lto Author: Shilei Tian (shiltian) ChangesOn one hand, we intend to With this PR, functions will no longer be converted to declarations when Full diff: https://github.com/llvm/llvm-project/pull/134541.diff 4 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index f1dce5d7904f9..19a6bc55b0147 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -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) {
if (!convertToDeclaration(GV))
// FIXME: Change this to collect replaced GVs and later erase
// them from the parent module once thinLTOResolvePrevailingGUID is
diff --git a/llvm/test/ThinLTO/AMDGPU/Inputs/noinline.ll b/llvm/test/ThinLTO/AMDGPU/Inputs/noinline.ll
new file mode 100644
index 0000000000000..6f93f880c3157
--- /dev/null
+++ b/llvm/test/ThinLTO/AMDGPU/Inputs/noinline.ll
@@ -0,0 +1,15 @@
+define void @f2(ptr %v) #0 {
+entry:
+ %v.addr = alloca ptr, align 8, addrspace(5)
+ store ptr %v, ptr addrspace(5) %v.addr, align 8
+ call void @f3(ptr %v)
+ ret void
+}
+
+define weak hidden void @f3(ptr %v) #0 {
+entry:
+ store i32 12345, ptr %v
+ ret void
+}
+
+attributes #0 = { noinline }
diff --git a/llvm/test/ThinLTO/AMDGPU/force-import-all.ll b/llvm/test/ThinLTO/AMDGPU/force-import-all.ll
new file mode 100644
index 0000000000000..f8beb0dae390f
--- /dev/null
+++ b/llvm/test/ThinLTO/AMDGPU/force-import-all.ll
@@ -0,0 +1,26 @@
+; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %s -o %t1.bc
+; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %p/Inputs/noinline.ll -o %t2.bc
+; RUN: llvm-lto -thinlto-action=run -force-import-all %t1.bc %t2.bc -thinlto-save-temps=%t3.
+; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s --check-prefix=MOD1
+; RUN: llvm-dis %t3.1.3.imported.bc -o - | FileCheck %s --check-prefix=MOD2
+
+define i32 @f1(ptr %p) #0 {
+entry:
+ call void @f2(ptr %p)
+ ret i32 0
+}
+
+define weak hidden void @f3(ptr %v) #0 {
+entry:
+ store i32 12345, ptr %v
+ ret void
+}
+
+declare void @f2(ptr)
+
+attributes #0 = { noinline }
+
+; MOD1: define weak hidden void @f3
+; MOD1: define available_externally void @f2
+; MOD2: define void @f2
+; MOD2: define available_externally hidden void @f3
diff --git a/llvm/test/ThinLTO/AMDGPU/lit.local.cfg b/llvm/test/ThinLTO/AMDGPU/lit.local.cfg
new file mode 100644
index 0000000000000..7c492428aec76
--- /dev/null
+++ b/llvm/test/ThinLTO/AMDGPU/lit.local.cfg
@@ -0,0 +1,2 @@
+if not "AMDGPU" in config.root.targets:
+ config.unsupported = True
|
70db06f to
60dd2c2
Compare
fd9f457 to
35d8ee7
Compare
| ; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %s -o %t.main.bc | ||
| ; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %p/Inputs/in-0.ll -o %t.in.0.bc | ||
| ; RUN: opt -mtriple=amdgcn-amd-amdhsa -module-summary %p/Inputs/in-1.ll -o %t.in.1.bc | ||
| ; 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you just need to run -thinlto-action=import instead of running the full pipeline and rely on save-temps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to do that as well, but it looks like thinLTOResolvePrevailingGUID doesn't run if we simply does import, as shown below:
; RUN: llvm-lto -thinlto-action=thinlink -force-import-all %t.main.bc %t.in.bc -o %t.index.bc
; RUN: llvm-lto -thinlto-action=import -force-import-all %t.main.bc %t.in.bc --thinlto-index=%t.index.bc
; RUN: llvm-dis %t.main.bc.thinlto.imported.bc -o - | FileCheck --check-prefix=MOD1 %s
; RUN: llvm-dis %t.in.bc.thinlto.imported.bc -o - | FileCheck --check-prefix=MOD2 %s
Did I miss anything here?
…l` 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.
35d8ee7 to
3f4e024
Compare
|
@cachemeifyoucan How about this version? |
cachemeifyoucan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/15917 Here is the relevant piece of the build log for the reference |

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-allis enabled.