Skip to content

Commit 34fd831

Browse files
committed
[AMDGPU][Attributor] Add ThinOrFullLTOPhase as an argument
1 parent 7ad8a3d commit 34fd831

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

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

334334
AMDGPUAttributorOptions Options;
335335

336+
const ThinOrFullLTOPhase LTOPhase;
337+
336338
public:
337-
AMDGPUAttributorPass(TargetMachine &TM, AMDGPUAttributorOptions Options = {})
338-
: TM(TM), Options(Options) {};
339+
AMDGPUAttributorPass(TargetMachine &TM, AMDGPUAttributorOptions Options,
340+
ThinOrFullLTOPhase LTOPhase = ThinOrFullLTOPhase::None)
341+
: TM(TM), Options(Options), LTOPhase(LTOPhase) {};
339342
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
340343
};
341344

llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,8 @@ static void addPreloadKernArgHint(Function &F, TargetMachine &TM) {
13301330
}
13311331

13321332
static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
1333-
AMDGPUAttributorOptions Options) {
1333+
AMDGPUAttributorOptions Options,
1334+
ThinOrFullLTOPhase LTOPhase) {
13341335
SetVector<Function *> Functions;
13351336
for (Function &F : M) {
13361337
if (!F.isIntrinsic())
@@ -1365,9 +1366,30 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
13651366

13661367
Attributor A(Functions, InfoCache, AC);
13671368

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

13721394
for (auto *F : Functions) {
13731395
A.getOrCreateAAFor<AAAMDAttributes>(IRPosition::function(*F));
@@ -1420,7 +1442,8 @@ class AMDGPUAttributorLegacy : public ModulePass {
14201442

14211443
bool runOnModule(Module &M) override {
14221444
AnalysisGetter AG(this);
1423-
return runImpl(M, AG, *TM, /*Options=*/{});
1445+
return runImpl(M, AG, *TM, /*Options=*/{},
1446+
/*LTOPhase=*/ThinOrFullLTOPhase::None);
14241447
}
14251448

14261449
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -1441,8 +1464,8 @@ PreservedAnalyses llvm::AMDGPUAttributorPass::run(Module &M,
14411464
AnalysisGetter AG(FAM);
14421465

14431466
// TODO: Probably preserves CFG
1444-
return runImpl(M, AG, TM, Options) ? PreservedAnalyses::none()
1445-
: PreservedAnalyses::all();
1467+
return runImpl(M, AG, TM, Options, LTOPhase) ? PreservedAnalyses::none()
1468+
: PreservedAnalyses::all();
14461469
}
14471470

14481471
char AMDGPUAttributorLegacy::ID = 0;

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
852852
OptimizationLevel Level,
853853
ThinOrFullLTOPhase Phase) {
854854
if (Level != OptimizationLevel::O0) {
855-
if (!isLTOPreLink(Phase))
856-
MPM.addPass(AMDGPUAttributorPass(*this));
855+
if (!isLTOPreLink(Phase)) {
856+
AMDGPUAttributorOptions Opts;
857+
MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
858+
}
857859
}
858860
});
859861

@@ -876,7 +878,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
876878
AMDGPUAttributorOptions Opt;
877879
if (HasClosedWorldAssumption)
878880
Opt.IsClosedWorld = true;
879-
PM.addPass(AMDGPUAttributorPass(*this, Opt));
881+
PM.addPass(AMDGPUAttributorPass(
882+
*this, Opt, ThinOrFullLTOPhase::FullLTOPostLink));
880883
}
881884
}
882885
});

0 commit comments

Comments
 (0)