Skip to content

Commit 814db6c

Browse files
authored
[CodeGen][NewPM] Port GCNPreRALongBranchReg to NPM. (llvm#125844)
1 parent b83c960 commit 814db6c

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ extern char &AMDGPUOpenCLEnqueuedBlockLoweringLegacyID;
451451
void initializeGCNNSAReassignPass(PassRegistry &);
452452
extern char &GCNNSAReassignID;
453453

454-
void initializeGCNPreRALongBranchRegPass(PassRegistry &);
454+
void initializeGCNPreRALongBranchRegLegacyPass(PassRegistry &);
455455
extern char &GCNPreRALongBranchRegID;
456456

457457
void initializeGCNPreRAOptimizationsPass(PassRegistry &);

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ FUNCTION_PASS_WITH_PARAMS(
9797
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
9898
#endif
9999
MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
100+
MACHINE_FUNCTION_PASS("amdgpu-pre-ra-long-branch-reg", GCNPreRALongBranchRegPass())
100101
MACHINE_FUNCTION_PASS("gcn-dpp-combine", GCNDPPCombinePass())
101102
MACHINE_FUNCTION_PASS("si-fix-sgpr-copies", SIFixSGPRCopiesPass())
102103
MACHINE_FUNCTION_PASS("si-fix-vgpr-copies", SIFixVGPRCopiesPass())
@@ -117,7 +118,6 @@ MACHINE_FUNCTION_PASS("si-wqm", SIWholeQuadModePass())
117118
#define DUMMY_MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
118119
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-insert-delay-alu", AMDGPUInsertDelayAluPass())
119120
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-nsa-reassign", GCNNSAReassignPass())
120-
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-pre-ra-long-branch-reg", GCNPreRALongBranchRegPass())
121121
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-pre-ra-optimizations", GCNPreRAOptimizationsPass())
122122
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-rewrite-partial-reg-uses", GCNRewritePartialRegUsesPass())
123123
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-set-wave-priority", AMDGPUSetWavePriorityPass())

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "AMDGPUWaitSGPRHazards.h"
3333
#include "GCNDPPCombine.h"
3434
#include "GCNIterativeScheduler.h"
35+
#include "GCNPreRALongBranchReg.h"
3536
#include "GCNSchedStrategy.h"
3637
#include "GCNVOPDUtils.h"
3738
#include "R600.h"
@@ -548,7 +549,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
548549
initializeAMDGPUResourceUsageAnalysisPass(*PR);
549550
initializeGCNNSAReassignPass(*PR);
550551
initializeGCNPreRAOptimizationsPass(*PR);
551-
initializeGCNPreRALongBranchRegPass(*PR);
552+
initializeGCNPreRALongBranchRegLegacyPass(*PR);
552553
initializeGCNRewritePartialRegUsesPass(*PR);
553554
initializeGCNRegPressurePrinterPass(*PR);
554555
initializeAMDGPUPreloadKernArgPrologLegacyPass(*PR);

llvm/lib/Target/AMDGPU/GCNPreRALongBranchReg.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// distrance threshold tuning of what is considered "long" is handled through
1515
// amdgpu-long-branch-factor cl argument which sets LongBranchFactor.
1616
//===----------------------------------------------------------------------===//
17+
#include "GCNPreRALongBranchReg.h"
1718
#include "AMDGPU.h"
1819
#include "GCNSubtarget.h"
1920
#include "SIMachineFunctionInfo.h"
@@ -36,7 +37,7 @@ static cl::opt<double> LongBranchFactor(
3637
"reserved. We lean towards always reserving a register for "
3738
"long jumps"));
3839

39-
class GCNPreRALongBranchReg : public MachineFunctionPass {
40+
class GCNPreRALongBranchReg {
4041

4142
struct BasicBlockInfo {
4243
// Offset - Distance from the beginning of the function to the beginning
@@ -48,27 +49,39 @@ class GCNPreRALongBranchReg : public MachineFunctionPass {
4849
void generateBlockInfo(MachineFunction &MF,
4950
SmallVectorImpl<BasicBlockInfo> &BlockInfo);
5051

52+
public:
53+
GCNPreRALongBranchReg() = default;
54+
bool run(MachineFunction &MF);
55+
};
56+
57+
class GCNPreRALongBranchRegLegacy : public MachineFunctionPass {
5158
public:
5259
static char ID;
53-
GCNPreRALongBranchReg() : MachineFunctionPass(ID) {
54-
initializeGCNPreRALongBranchRegPass(*PassRegistry::getPassRegistry());
60+
GCNPreRALongBranchRegLegacy() : MachineFunctionPass(ID) {
61+
initializeGCNPreRALongBranchRegLegacyPass(*PassRegistry::getPassRegistry());
5562
}
56-
bool runOnMachineFunction(MachineFunction &MF) override;
63+
64+
bool runOnMachineFunction(MachineFunction &MF) override {
65+
return GCNPreRALongBranchReg().run(MF);
66+
}
67+
5768
StringRef getPassName() const override {
5869
return "AMDGPU Pre-RA Long Branch Reg";
5970
}
71+
6072
void getAnalysisUsage(AnalysisUsage &AU) const override {
6173
AU.setPreservesAll();
6274
MachineFunctionPass::getAnalysisUsage(AU);
6375
}
6476
};
6577
} // End anonymous namespace.
66-
char GCNPreRALongBranchReg::ID = 0;
6778

68-
INITIALIZE_PASS(GCNPreRALongBranchReg, DEBUG_TYPE,
79+
char GCNPreRALongBranchRegLegacy::ID = 0;
80+
81+
INITIALIZE_PASS(GCNPreRALongBranchRegLegacy, DEBUG_TYPE,
6982
"AMDGPU Pre-RA Long Branch Reg", false, false)
7083

71-
char &llvm::GCNPreRALongBranchRegID = GCNPreRALongBranchReg::ID;
84+
char &llvm::GCNPreRALongBranchRegID = GCNPreRALongBranchRegLegacy::ID;
7285
void GCNPreRALongBranchReg::generateBlockInfo(
7386
MachineFunction &MF, SmallVectorImpl<BasicBlockInfo> &BlockInfo) {
7487

@@ -99,7 +112,8 @@ void GCNPreRALongBranchReg::generateBlockInfo(
99112
PrevNum = Num;
100113
}
101114
}
102-
bool GCNPreRALongBranchReg::runOnMachineFunction(MachineFunction &MF) {
115+
116+
bool GCNPreRALongBranchReg::run(MachineFunction &MF) {
103117
const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
104118
const SIInstrInfo *TII = STM.getInstrInfo();
105119
const SIRegisterInfo *TRI = STM.getRegisterInfo();
@@ -136,3 +150,10 @@ bool GCNPreRALongBranchReg::runOnMachineFunction(MachineFunction &MF) {
136150
}
137151
return false;
138152
}
153+
154+
PreservedAnalyses
155+
GCNPreRALongBranchRegPass::run(MachineFunction &MF,
156+
MachineFunctionAnalysisManager &MFAM) {
157+
GCNPreRALongBranchReg().run(MF);
158+
return PreservedAnalyses::all();
159+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===- GCNPreRALongBranchReg.h ----------------------------------*- C++- *-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIB_TARGET_AMDGPU_GCNPRERALONGBRANCHREG_H
10+
#define LLVM_LIB_TARGET_AMDGPU_GCNPRERALONGBRANCHREG_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
class GCNPreRALongBranchRegPass
16+
: public PassInfoMixin<GCNPreRALongBranchRegPass> {
17+
public:
18+
PreservedAnalyses run(MachineFunction &MF,
19+
MachineFunctionAnalysisManager &MFAM);
20+
};
21+
} // namespace llvm
22+
23+
#endif // LLVM_LIB_TARGET_AMDGPU_GCNPRERALONGBRANCHREG_H

0 commit comments

Comments
 (0)