Skip to content

Commit 3118593

Browse files
committed
[AMDGPU][Attributor] Add ThinOrFullLTOPhase as an argument
1 parent 3757ecf commit 3118593

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
@@ -1337,7 +1337,8 @@ static void addPreloadKernArgHint(Function &F, TargetMachine &TM) {
13371337
}
13381338

13391339
static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
1340-
AMDGPUAttributorOptions Options) {
1340+
AMDGPUAttributorOptions Options,
1341+
ThinOrFullLTOPhase LTOPhase) {
13411342
SetVector<Function *> Functions;
13421343
for (Function &F : M) {
13431344
if (!F.isIntrinsic())
@@ -1372,9 +1373,27 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
13721373

13731374
Attributor A(Functions, InfoCache, AC);
13741375

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

13791398
for (auto *F : Functions) {
13801399
A.getOrCreateAAFor<AAAMDAttributes>(IRPosition::function(*F));
@@ -1427,7 +1446,8 @@ class AMDGPUAttributorLegacy : public ModulePass {
14271446

14281447
bool runOnModule(Module &M) override {
14291448
AnalysisGetter AG(this);
1430-
return runImpl(M, AG, *TM, /*Options=*/{});
1449+
return runImpl(M, AG, *TM, /*Options=*/{},
1450+
/*LTOPhase=*/ThinOrFullLTOPhase::None);
14311451
}
14321452

14331453
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -1448,8 +1468,8 @@ PreservedAnalyses llvm::AMDGPUAttributorPass::run(Module &M,
14481468
AnalysisGetter AG(FAM);
14491469

14501470
// TODO: Probably preserves CFG
1451-
return runImpl(M, AG, TM, Options) ? PreservedAnalyses::none()
1452-
: PreservedAnalyses::all();
1471+
return runImpl(M, AG, TM, Options, LTOPhase) ? PreservedAnalyses::none()
1472+
: PreservedAnalyses::all();
14531473
}
14541474

14551475
char AMDGPUAttributorLegacy::ID = 0;

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
876876
OptimizationLevel Level,
877877
ThinOrFullLTOPhase Phase) {
878878
if (Level != OptimizationLevel::O0) {
879-
if (!isLTOPreLink(Phase))
880-
MPM.addPass(AMDGPUAttributorPass(*this));
879+
if (!isLTOPreLink(Phase)) {
880+
AMDGPUAttributorOptions Opts;
881+
MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
882+
}
881883
}
882884
});
883885

@@ -900,7 +902,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
900902
AMDGPUAttributorOptions Opt;
901903
if (HasClosedWorldAssumption)
902904
Opt.IsClosedWorld = true;
903-
PM.addPass(AMDGPUAttributorPass(*this, Opt));
905+
PM.addPass(AMDGPUAttributorPass(
906+
*this, Opt, ThinOrFullLTOPhase::FullLTOPostLink));
904907
}
905908
}
906909
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)