diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp index 0cbee8dbef5fb..06e852fe4752e 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(IRPosition::function(*F)); A.getOrCreateAAFor(IRPosition::function(*F)); diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp index 34ad99dd980f2..3f21d5a00ab7d 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -454,6 +454,11 @@ static cl::opt NewRegBankSelect( "regbankselect"), cl::init(false), cl::Hidden); +static cl::opt 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 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 0000000000000..dd084e7f3d9ed --- /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" -debug-only=amdgpu-attributor -o - %s 2>&1 | FileCheck %s --check-prefix=NO-CW +; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes="lto" -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 +}