Skip to content

Commit bbe924f

Browse files
committed
[AMDGPU][Attributor] Add ThinOrFullLTOPhase as an argument
1 parent 499930e commit bbe924f

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,12 @@ class AMDGPUAttributorPass : public PassInfoMixin<AMDGPUAttributorPass> {
339339

340340
AMDGPUAttributorOptions Options;
341341

342+
const ThinOrFullLTOPhase LTOPhase;
343+
342344
public:
343-
AMDGPUAttributorPass(TargetMachine &TM, AMDGPUAttributorOptions Options = {})
344-
: TM(TM), Options(Options) {};
345+
AMDGPUAttributorPass(TargetMachine &TM, AMDGPUAttributorOptions Options,
346+
ThinOrFullLTOPhase LTOPhase = ThinOrFullLTOPhase::None)
347+
: TM(TM), Options(Options), LTOPhase(LTOPhase) {};
345348
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
346349
};
347350

llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,8 @@ static void addPreloadKernArgHint(Function &F, TargetMachine &TM) {
13341334
}
13351335

13361336
static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
1337-
AMDGPUAttributorOptions Options) {
1337+
AMDGPUAttributorOptions Options,
1338+
ThinOrFullLTOPhase LTOPhase) {
13381339
SetVector<Function *> Functions;
13391340
for (Function &F : M) {
13401341
if (!F.isIntrinsic())
@@ -1369,9 +1370,27 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
13691370

13701371
Attributor A(Functions, InfoCache, AC);
13711372

1372-
LLVM_DEBUG(dbgs() << "[AMDGPUAttributor] Module " << M.getName() << " is "
1373-
<< (AC.IsClosedWorldModule ? "" : "not ")
1374-
<< "assumed to be a closed world.\n");
1373+
LLVM_DEBUG({
1374+
auto PhaseToString = [](ThinOrFullLTOPhase LTOPhase) -> StringRef {
1375+
switch (LTOPhase) {
1376+
case ThinOrFullLTOPhase::None:
1377+
return "None";
1378+
case ThinOrFullLTOPhase::ThinLTOPreLink:
1379+
return "ThinLTOPreLink";
1380+
case ThinOrFullLTOPhase::ThinLTOPostLink:
1381+
return "ThinLTOPostLink";
1382+
case ThinOrFullLTOPhase::FullLTOPreLink:
1383+
return "FullLTOPreLink";
1384+
case ThinOrFullLTOPhase::FullLTOPostLink:
1385+
return "FullLTOPostLink";
1386+
}
1387+
};
1388+
StringRef LTOPhaseStr = PhaseToString(LTOPhase);
1389+
dbgs() << "[AMDGPUAttributor] Running at phase " << LTOPhaseStr << '\n'
1390+
<< "[AMDGPUAttributor] Module " << M.getName() << " is "
1391+
<< (AC.IsClosedWorldModule ? "" : "not ")
1392+
<< "assumed to be a closed world.\n";
1393+
});
13751394

13761395
for (auto *F : Functions) {
13771396
A.getOrCreateAAFor<AAAMDAttributes>(IRPosition::function(*F));
@@ -1424,7 +1443,8 @@ class AMDGPUAttributorLegacy : public ModulePass {
14241443

14251444
bool runOnModule(Module &M) override {
14261445
AnalysisGetter AG(this);
1427-
return runImpl(M, AG, *TM, /*Options=*/{});
1446+
return runImpl(M, AG, *TM, /*Options=*/{},
1447+
/*LTOPhase=*/ThinOrFullLTOPhase::None);
14281448
}
14291449

14301450
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -1445,8 +1465,8 @@ PreservedAnalyses llvm::AMDGPUAttributorPass::run(Module &M,
14451465
AnalysisGetter AG(FAM);
14461466

14471467
// TODO: Probably preserves CFG
1448-
return runImpl(M, AG, TM, Options) ? PreservedAnalyses::none()
1449-
: PreservedAnalyses::all();
1468+
return runImpl(M, AG, TM, Options, LTOPhase) ? PreservedAnalyses::none()
1469+
: PreservedAnalyses::all();
14501470
}
14511471

14521472
char AMDGPUAttributorLegacy::ID = 0;

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
878878
OptimizationLevel Level,
879879
ThinOrFullLTOPhase Phase) {
880880
if (Level != OptimizationLevel::O0) {
881-
if (!isLTOPreLink(Phase))
882-
MPM.addPass(AMDGPUAttributorPass(*this));
881+
if (!isLTOPreLink(Phase)) {
882+
AMDGPUAttributorOptions Opts;
883+
MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
884+
}
883885
}
884886
});
885887

@@ -902,7 +904,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
902904
AMDGPUAttributorOptions Opt;
903905
if (HasClosedWorldAssumption)
904906
Opt.IsClosedWorld = true;
905-
PM.addPass(AMDGPUAttributorPass(*this, Opt));
907+
PM.addPass(AMDGPUAttributorPass(
908+
*this, Opt, ThinOrFullLTOPhase::FullLTOPostLink));
906909
}
907910
}
908911
if (!NoKernelInfoEndLTO) {

llvm/test/LTO/AMDGPU/closed-world-assumption.ll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -O3 -debug-only=amdgpu-attributor -o - %s 2>&1 | FileCheck %s --check-prefix=NO-CW
2-
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes="lto<O3>" -debug-only=amdgpu-attributor -o - %s 2>&1 | FileCheck %s --check-prefix=NO-CW
3-
; 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
1+
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -O3 -debug-only=amdgpu-attributor -o - %s 2>&1 | FileCheck %s --check-prefixes=NO-CW,NO-LTO
2+
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes="lto<O3>" -debug-only=amdgpu-attributor -o - %s 2>&1 | FileCheck %s --check-prefixes=NO-CW,LTO
3+
; 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-prefixes=CW,LTO
44

55
; REQUIRES: amdgpu-registered-target
66
; REQUIRES: asserts
77

8+
; NO-LTO: Running at phase None
9+
; LTO: Running at phase FullLTOPostLink
810
; NO-CW: Module {{.*}} is not assumed to be a closed world.
911
; CW: Module {{.*}} is assumed to be a closed world.
1012
define hidden noundef i32 @_Z3foov() {

0 commit comments

Comments
 (0)