Skip to content

Commit c7ec8bb

Browse files
committed
[AMDGPU][NPM] Port SILateBranchLowering to NPM
1 parent 78cee57 commit c7ec8bb

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ extern char &SILowerControlFlowLegacyID;
213213
void initializeSIPreEmitPeepholePass(PassRegistry &);
214214
extern char &SIPreEmitPeepholeID;
215215

216-
void initializeSILateBranchLoweringPass(PassRegistry &);
216+
void initializeSILateBranchLoweringLegacyPass(PassRegistry &);
217217
extern char &SILateBranchLoweringPassID;
218218

219219
void initializeSIOptimizeExecMaskingLegacyPass(PassRegistry &);
@@ -384,6 +384,14 @@ class SIInsertHardClausesPass : public PassInfoMixin<SIInsertHardClausesPass> {
384384
MachineFunctionAnalysisManager &MFAM);
385385
};
386386

387+
class SILateBranchLoweringPass
388+
: public PassInfoMixin<SILateBranchLoweringPass> {
389+
public:
390+
PreservedAnalyses run(MachineFunction &MF,
391+
MachineFunctionAnalysisManager &MFAM);
392+
static bool isRequired() { return true; }
393+
};
394+
387395
FunctionPass *createAMDGPUAnnotateUniformValuesLegacy();
388396

389397
ModulePass *createAMDGPUPrintfRuntimeBinding();

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ MACHINE_FUNCTION_PASS("si-form-memory-clauses", SIFormMemoryClausesPass())
112112
MACHINE_FUNCTION_PASS("si-i1-copies", SILowerI1CopiesPass())
113113
MACHINE_FUNCTION_PASS("si-insert-hard-clauses", SIInsertHardClausesPass())
114114
MACHINE_FUNCTION_PASS("si-insert-waitcnts", SIInsertWaitcntsPass())
115+
MACHINE_FUNCTION_PASS("si-late-branch-lowering", SILateBranchLoweringPass())
115116
MACHINE_FUNCTION_PASS("si-load-store-opt", SILoadStoreOptimizerPass())
116117
MACHINE_FUNCTION_PASS("si-lower-control-flow", SILowerControlFlowPass())
117118
MACHINE_FUNCTION_PASS("si-lower-sgpr-spills", SILowerSGPRSpillsPass())
@@ -133,7 +134,6 @@ DUMMY_MACHINE_FUNCTION_PASS("amdgpu-pre-ra-optimizations", GCNPreRAOptimizations
133134
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-rewrite-partial-reg-uses", GCNRewritePartialRegUsesPass())
134135
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-set-wave-priority", AMDGPUSetWavePriorityPass())
135136

136-
DUMMY_MACHINE_FUNCTION_PASS("si-late-branch-lowering", SILateBranchLoweringPass())
137137
DUMMY_MACHINE_FUNCTION_PASS("si-pre-emit-peephole", SIPreEmitPeepholePass())
138138
// TODO: Move amdgpu-preload-kern-arg-prolog to MACHINE_FUNCTION_PASS since it
139139
// already exists.

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
541541
initializeSIWholeQuadModeLegacyPass(*PR);
542542
initializeSILowerControlFlowLegacyPass(*PR);
543543
initializeSIPreEmitPeepholePass(*PR);
544-
initializeSILateBranchLoweringPass(*PR);
544+
initializeSILateBranchLoweringLegacyPass(*PR);
545545
initializeSIMemoryLegalizerLegacyPass(*PR);
546546
initializeSIOptimizeExecMaskingLegacyPass(*PR);
547547
initializeSIPreAllocateWWMRegsLegacyPass(*PR);
@@ -2162,7 +2162,8 @@ void AMDGPUCodeGenPassBuilder::addPreEmitPass(AddMachinePass &addPass) const {
21622162
// TODO: addPass(SIInsertHardClausesPass());
21632163
}
21642164

2165-
// addPass(SILateBranchLoweringPass());
2165+
addPass(SILateBranchLoweringPass());
2166+
21662167
if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less)) {
21672168
// TODO: addPass(AMDGPUSetWavePriorityPass());
21682169
}

llvm/lib/Target/AMDGPU/SILateBranchLowering.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
1717
#include "SIMachineFunctionInfo.h"
1818
#include "llvm/CodeGen/MachineDominators.h"
19+
#include "llvm/CodeGen/MachinePassManager.h"
1920

2021
using namespace llvm;
2122

2223
#define DEBUG_TYPE "si-late-branch-lowering"
2324

2425
namespace {
2526

26-
class SILateBranchLowering : public MachineFunctionPass {
27+
class SILateBranchLowering {
2728
private:
2829
const SIRegisterInfo *TRI = nullptr;
2930
const SIInstrInfo *TII = nullptr;
@@ -33,14 +34,23 @@ class SILateBranchLowering : public MachineFunctionPass {
3334
void earlyTerm(MachineInstr &MI, MachineBasicBlock *EarlyExitBlock);
3435

3536
public:
36-
static char ID;
37+
SILateBranchLowering(MachineDominatorTree *MDT) : MDT(MDT) {}
38+
39+
bool run(MachineFunction &MF);
3740

3841
unsigned MovOpc;
3942
Register ExecReg;
43+
};
4044

41-
SILateBranchLowering() : MachineFunctionPass(ID) {}
45+
class SILateBranchLoweringLegacy : public MachineFunctionPass {
46+
public:
47+
static char ID;
48+
SILateBranchLoweringLegacy() : MachineFunctionPass(ID) {}
4249

43-
bool runOnMachineFunction(MachineFunction &MF) override;
50+
bool runOnMachineFunction(MachineFunction &MF) override {
51+
auto *MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
52+
return SILateBranchLowering(MDT).run(MF);
53+
}
4454

4555
StringRef getPassName() const override {
4656
return "SI Final Branch Preparation";
@@ -55,15 +65,15 @@ class SILateBranchLowering : public MachineFunctionPass {
5565

5666
} // end anonymous namespace
5767

58-
char SILateBranchLowering::ID = 0;
68+
char SILateBranchLoweringLegacy::ID = 0;
5969

60-
INITIALIZE_PASS_BEGIN(SILateBranchLowering, DEBUG_TYPE,
70+
INITIALIZE_PASS_BEGIN(SILateBranchLoweringLegacy, DEBUG_TYPE,
6171
"SI insert s_cbranch_execz instructions", false, false)
6272
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
63-
INITIALIZE_PASS_END(SILateBranchLowering, DEBUG_TYPE,
73+
INITIALIZE_PASS_END(SILateBranchLoweringLegacy, DEBUG_TYPE,
6474
"SI insert s_cbranch_execz instructions", false, false)
6575

66-
char &llvm::SILateBranchLoweringPassID = SILateBranchLowering::ID;
76+
char &llvm::SILateBranchLoweringPassID = SILateBranchLoweringLegacy::ID;
6777

6878
static void generateEndPgm(MachineBasicBlock &MBB,
6979
MachineBasicBlock::iterator I, DebugLoc DL,
@@ -144,11 +154,21 @@ void SILateBranchLowering::earlyTerm(MachineInstr &MI,
144154
MDT->insertEdge(&MBB, EarlyExitBlock);
145155
}
146156

147-
bool SILateBranchLowering::runOnMachineFunction(MachineFunction &MF) {
157+
PreservedAnalyses
158+
llvm::SILateBranchLoweringPass::run(MachineFunction &MF,
159+
MachineFunctionAnalysisManager &MFAM) {
160+
auto *MDT = &MFAM.getResult<MachineDominatorTreeAnalysis>(MF);
161+
if (!SILateBranchLowering(MDT).run(MF))
162+
return PreservedAnalyses::all();
163+
164+
return getMachineFunctionPassPreservedAnalyses()
165+
.preserve<MachineDominatorTreeAnalysis>();
166+
}
167+
168+
bool SILateBranchLowering::run(MachineFunction &MF) {
148169
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
149170
TII = ST.getInstrInfo();
150171
TRI = &TII->getRegisterInfo();
151-
MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
152172

153173
MovOpc = ST.isWave32() ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
154174
ExecReg = ST.isWave32() ? AMDGPU::EXEC_LO : AMDGPU::EXEC;

llvm/test/CodeGen/AMDGPU/early-term.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 -mattr=+wavefrontsize64 -run-pass=si-late-branch-lowering -verify-machineinstrs %s -o - | FileCheck -check-prefixes=GCN,GFX10 %s
33
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize64 -run-pass=si-late-branch-lowering -verify-machineinstrs %s -o - | FileCheck -check-prefixes=GCN,GFX11 %s
44

5+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize64 -passes=si-late-branch-lowering -verify-machineinstrs %s -o - | FileCheck -check-prefixes=GCN,GFX11 %s
6+
57
--- |
68
define amdgpu_ps void @early_term_scc0_end_block() {
79
ret void

llvm/test/CodeGen/AMDGPU/readlane_exec0.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -o - %s -mtriple=amdgcn -mcpu=fiji -run-pass=si-late-branch-lowering -verify-machineinstrs | FileCheck -check-prefix=GCN %s
2+
# RUN: llc -o - %s -mtriple=amdgcn -mcpu=fiji -passes=si-late-branch-lowering -verify-machineinstrs | FileCheck -check-prefix=GCN %s
23

34
# GCN-LABEL: readlane_exec0
45
# GCN: bb.0

0 commit comments

Comments
 (0)