[llvm] 04269ea - [AMDGPU] Re-enable closed-world assumption as an opt-in feature (#115371)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 10 12:57:45 PST 2024
Author: Shilei Tian
Date: 2024-12-10T15:57:41-05:00
New Revision: 04269ea0e40abb3c5aa0c96adde65c72195cbb6e
URL: https://github.com/llvm/llvm-project/commit/04269ea0e40abb3c5aa0c96adde65c72195cbb6e
DIFF: https://github.com/llvm/llvm-project/commit/04269ea0e40abb3c5aa0c96adde65c72195cbb6e.diff
LOG: [AMDGPU] Re-enable closed-world assumption as an opt-in feature (#115371)
Although the ABI (if one exists) doesn’t explicitly prohibit
cross-code-object function calls—particularly since our loader can
handle them—such calls are not actually allowed in any of the officially
supported programming models. However, this limitation has some nuances.
For instance, the loader can handle cross-code-object global variables,
which complicates the situation further.
Given this complexity, assuming a closed-world model at link time isn’t
always safe. To address this, this PR introduces an option that enables
this assumption, providing end users the flexibility to enable it for
improved compiler optimizations. However, it is the user’s
responsibility to ensure they do not violate this assumption.
Added:
llvm/test/LTO/AMDGPU/closed-world-assumption.ll
Modified:
llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
index 0cbee8dbef5fb2..06e852fe4752e0 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
@@ -1286,6 +1286,10 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
Attributor A(Functions, InfoCache, AC);
+ LLVM_DEBUG(dbgs() << "[AMDGPUAttributor] Module " << M.getName() << " is "
+ << (AC.IsClosedWorldModule ? "" : "not ")
+ << "assumed to be a closed world.\n");
+
for (auto *F : Functions) {
A.getOrCreateAAFor<AAAMDAttributes>(IRPosition::function(*F));
A.getOrCreateAAFor<AAUniformWorkGroupSize>(IRPosition::function(*F));
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 34ad99dd980f27..3f21d5a00ab7d5 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -454,6 +454,11 @@ static cl::opt<bool> NewRegBankSelect(
"regbankselect"),
cl::init(false), cl::Hidden);
+static cl::opt<bool> HasClosedWorldAssumption(
+ "amdgpu-link-time-closed-world",
+ cl::desc("Whether has closed-world assumption at link time"),
+ cl::init(false), cl::Hidden);
+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
// Register the target
RegisterTargetMachine<R600TargetMachine> X(getTheR600Target());
@@ -859,8 +864,12 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
PM.addPass(InternalizePass(mustPreserveGV));
PM.addPass(GlobalDCEPass());
}
- if (EnableAMDGPUAttributor)
- PM.addPass(AMDGPUAttributorPass(*this));
+ if (EnableAMDGPUAttributor) {
+ AMDGPUAttributorOptions Opt;
+ if (HasClosedWorldAssumption)
+ Opt.IsClosedWorld = true;
+ PM.addPass(AMDGPUAttributorPass(*this, Opt));
+ }
}
});
diff --git a/llvm/test/LTO/AMDGPU/closed-world-assumption.ll b/llvm/test/LTO/AMDGPU/closed-world-assumption.ll
new file mode 100644
index 00000000000000..dd084e7f3d9ed0
--- /dev/null
+++ b/llvm/test/LTO/AMDGPU/closed-world-assumption.ll
@@ -0,0 +1,12 @@
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -O3 -debug-only=amdgpu-attributor -o - %s 2>&1 | FileCheck %s --check-prefix=NO-CW
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes="lto<O3>" -debug-only=amdgpu-attributor -o - %s 2>&1 | FileCheck %s --check-prefix=NO-CW
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes="lto<O3>" -debug-only=amdgpu-attributor -amdgpu-link-time-closed-world=1 -o - %s 2>&1 | FileCheck %s --check-prefix=CW
+
+; REQUIRES: amdgpu-registered-target
+; REQUIRES: asserts
+
+; NO-CW: Module {{.*}} is not assumed to be a closed world.
+; CW: Module {{.*}} is assumed to be a closed world.
+define hidden noundef i32 @_Z3foov() {
+ ret i32 1
+}
More information about the llvm-commits
mailing list