Skip to content

Commit f044145

Browse files
committed
[AMDGPU][Attributor] Add ThinOrFullLTOPhase as an argument
1 parent cc0d4a5 commit f044145

File tree

3 files changed

+38
-12
lines changed

3 files changed

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

13721391
for (auto *F : Functions) {
13731392
A.getOrCreateAAFor<AAAMDAttributes>(IRPosition::function(*F));
@@ -1420,7 +1439,8 @@ class AMDGPUAttributorLegacy : public ModulePass {
14201439

14211440
bool runOnModule(Module &M) override {
14221441
AnalysisGetter AG(this);
1423-
return runImpl(M, AG, *TM, /*Options=*/{});
1442+
return runImpl(M, AG, *TM, /*Options=*/{},
1443+
/*LTOPhase=*/ThinOrFullLTOPhase::None);
14241444
}
14251445

14261446
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -1441,8 +1461,8 @@ PreservedAnalyses llvm::AMDGPUAttributorPass::run(Module &M,
14411461
AnalysisGetter AG(FAM);
14421462

14431463
// TODO: Probably preserves CFG
1444-
return runImpl(M, AG, TM, Options) ? PreservedAnalyses::none()
1445-
: PreservedAnalyses::all();
1464+
return runImpl(M, AG, TM, Options, LTOPhase) ? PreservedAnalyses::none()
1465+
: PreservedAnalyses::all();
14461466
}
14471467

14481468
char AMDGPUAttributorLegacy::ID = 0;

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
868868
OptimizationLevel Level,
869869
ThinOrFullLTOPhase Phase) {
870870
if (Level != OptimizationLevel::O0) {
871-
if (!isLTOPreLink(Phase))
872-
MPM.addPass(AMDGPUAttributorPass(*this));
871+
if (!isLTOPreLink(Phase)) {
872+
AMDGPUAttributorOptions Opts;
873+
MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
874+
}
873875
}
874876
});
875877

@@ -892,7 +894,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
892894
AMDGPUAttributorOptions Opt;
893895
if (HasClosedWorldAssumption)
894896
Opt.IsClosedWorld = true;
895-
PM.addPass(AMDGPUAttributorPass(*this, Opt));
897+
PM.addPass(AMDGPUAttributorPass(
898+
*this, Opt, ThinOrFullLTOPhase::FullLTOPostLink));
896899
}
897900
}
898901
if (!NoKernelInfoEndLTO) {

0 commit comments

Comments
 (0)