[llvm] [AMDGPU][LTO] Assume closed world after linking (PR #105845)

Anshil Gandhi via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 11:30:29 PDT 2024


https://github.com/gandhi56 updated https://github.com/llvm/llvm-project/pull/105845

>From e01a7c843c9a95aaf4f410ca0face15b51ab896a Mon Sep 17 00:00:00 2001
From: Anshil Gandhi <Anshil.Gandhi at amd.com>
Date: Thu, 22 Aug 2024 18:57:33 +0000
Subject: [PATCH] [AMDGPU][LTO] Assume closed world after linking

Change-Id: I7d8fa4251c80a6f815f55a0998677d18ade25b72
---
 llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp    |  4 ++++
 llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |  5 ++++-
 llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll   | 10 ++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
index d65e0ae92308e6..dcea615032793d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
@@ -1066,6 +1066,10 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
 
   Attributor A(Functions, InfoCache, AC);
 
+  dbgs() << "Module " << M.getName() << " is "
+         << (AC.IsClosedWorldModule ? "" : "not ")
+         << "assumed to be a closed world.\n";
+
   for (Function &F : M) {
     if (F.isIntrinsic())
       continue;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 7ac7b3315bb972..ea3fc5fecd1e5a 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -760,8 +760,11 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
         // module is partitioned for codegen.
         if (EnableLowerModuleLDS)
           PM.addPass(AMDGPULowerModuleLDSPass(*this));
+
+        AMDGPUAttributorOptions Opts;
+        Opts.IsClosedWorld = true;
         if (EnableAMDGPUAttributor && Level != OptimizationLevel::O0)
-          PM.addPass(AMDGPUAttributorPass(*this));
+          PM.addPass(AMDGPUAttributorPass(*this, Opts));
       });
 
   PB.registerRegClassFilterParsingCallback(
diff --git a/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll b/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll
new file mode 100644
index 00000000000000..1cb4daa79c6256
--- /dev/null
+++ b/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll
@@ -0,0 +1,10 @@
+; RUN: opt -O3 -debug-only=amdgpu-attributor -S -o - %s | FileCheck %s --check-prefix=PRE-LINK
+; RUN: opt -passes="lto<O3>" -debug-only=amdgpu-attributor -S -o - %s | FileCheck %s --check-prefix=POST-LINK
+
+target triple = "amdgcn-amd-amdhsa"
+
+; PRE-LINK: Module {{.*}} is not assumed to be a closed world.
+; POST-LINK: Module {{.*}} is assumed to be a closed world.
+define hidden noundef i32 @_Z3foov() {
+  ret i32 1
+}



More information about the llvm-commits mailing list