Skip to content

Commit dc736ad

Browse files
committed
[AMDGPU][Attributor] Add ThinOrFullLTOPhase as an argument
1 parent cd6a614 commit dc736ad

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
@@ -336,9 +336,12 @@ class AMDGPUAttributorPass : public PassInfoMixin<AMDGPUAttributorPass> {
336336

337337
AMDGPUAttributorOptions Options;
338338

339+
const ThinOrFullLTOPhase LTOPhase;
340+
339341
public:
340-
AMDGPUAttributorPass(TargetMachine &TM, AMDGPUAttributorOptions Options = {})
341-
: TM(TM), Options(Options) {};
342+
AMDGPUAttributorPass(TargetMachine &TM, AMDGPUAttributorOptions Options,
343+
ThinOrFullLTOPhase LTOPhase = ThinOrFullLTOPhase::None)
344+
: TM(TM), Options(Options), LTOPhase(LTOPhase) {};
342345
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
343346
};
344347

llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp

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

13451345
static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
1346-
AMDGPUAttributorOptions Options) {
1346+
AMDGPUAttributorOptions Options,
1347+
ThinOrFullLTOPhase LTOPhase) {
13471348
SetVector<Function *> Functions;
13481349
for (Function &F : M) {
13491350
if (!F.isIntrinsic())
@@ -1378,9 +1379,27 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
13781379

13791380
Attributor A(Functions, InfoCache, AC);
13801381

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

13851404
for (auto *F : Functions) {
13861405
A.getOrCreateAAFor<AAAMDAttributes>(IRPosition::function(*F));
@@ -1433,7 +1452,8 @@ class AMDGPUAttributorLegacy : public ModulePass {
14331452

14341453
bool runOnModule(Module &M) override {
14351454
AnalysisGetter AG(this);
1436-
return runImpl(M, AG, *TM, /*Options=*/{});
1455+
return runImpl(M, AG, *TM, /*Options=*/{},
1456+
/*LTOPhase=*/ThinOrFullLTOPhase::None);
14371457
}
14381458

14391459
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -1454,8 +1474,8 @@ PreservedAnalyses llvm::AMDGPUAttributorPass::run(Module &M,
14541474
AnalysisGetter AG(FAM);
14551475

14561476
// TODO: Probably preserves CFG
1457-
return runImpl(M, AG, TM, Options) ? PreservedAnalyses::none()
1458-
: PreservedAnalyses::all();
1477+
return runImpl(M, AG, TM, Options, LTOPhase) ? PreservedAnalyses::none()
1478+
: PreservedAnalyses::all();
14591479
}
14601480

14611481
char AMDGPUAttributorLegacy::ID = 0;

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
884884
OptimizationLevel Level,
885885
ThinOrFullLTOPhase Phase) {
886886
if (Level != OptimizationLevel::O0) {
887-
if (!isLTOPreLink(Phase))
888-
MPM.addPass(AMDGPUAttributorPass(*this));
887+
if (!isLTOPreLink(Phase)) {
888+
AMDGPUAttributorOptions Opts;
889+
MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
890+
}
889891
}
890892
});
891893

@@ -914,7 +916,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
914916
AMDGPUAttributorOptions Opt;
915917
if (HasClosedWorldAssumption)
916918
Opt.IsClosedWorld = true;
917-
PM.addPass(AMDGPUAttributorPass(*this, Opt));
919+
PM.addPass(AMDGPUAttributorPass(
920+
*this, Opt, ThinOrFullLTOPhase::FullLTOPostLink));
918921
}
919922
}
920923
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)