mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 18:16:42 +00:00
[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.
This commit is contained in:
parent
f3c675feec
commit
04269ea0e4
@ -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));
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
12
llvm/test/LTO/AMDGPU/closed-world-assumption.ll
Normal file
12
llvm/test/LTO/AMDGPU/closed-world-assumption.ll
Normal file
@ -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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user