Skip to content

Commit 8c58562

Browse files
committed
[NewPM][CodeGen] Port LiveRegMatrix to NPM
1 parent ea4b201 commit 8c58562

File tree

8 files changed

+68
-33
lines changed

8 files changed

+68
-33
lines changed

llvm/include/llvm/CodeGen/LiveRegMatrix.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class MachineFunction;
3737
class TargetRegisterInfo;
3838
class VirtRegMap;
3939

40-
class LiveRegMatrix : public MachineFunctionPass {
40+
class LiveRegMatrix {
41+
friend class LiveRegMatrixWrapperPass;
4142
const TargetRegisterInfo *TRI = nullptr;
4243
LiveIntervals *LIS = nullptr;
4344
VirtRegMap *VRM = nullptr;
@@ -57,15 +58,13 @@ class LiveRegMatrix : public MachineFunctionPass {
5758
unsigned RegMaskVirtReg = 0;
5859
BitVector RegMaskUsable;
5960

60-
// MachineFunctionPass boilerplate.
61-
void getAnalysisUsage(AnalysisUsage &) const override;
62-
bool runOnMachineFunction(MachineFunction &) override;
63-
void releaseMemory() override;
61+
LiveRegMatrix() = default;
62+
void releaseMemory();
6463

6564
public:
66-
static char ID;
67-
68-
LiveRegMatrix();
65+
~LiveRegMatrix() { releaseMemory(); }
66+
LiveRegMatrix(LiveRegMatrix &&) = default;
67+
void init(MachineFunction &MF, LiveIntervals *LIS, VirtRegMap *VRM);
6968

7069
//===--------------------------------------------------------------------===//
7170
// High-level interface.
@@ -159,6 +158,32 @@ class LiveRegMatrix : public MachineFunctionPass {
159158
Register getOneVReg(unsigned PhysReg) const;
160159
};
161160

161+
class LiveRegMatrixWrapperPass : public MachineFunctionPass {
162+
LiveRegMatrix LRM;
163+
164+
public:
165+
static char ID;
166+
167+
LiveRegMatrixWrapperPass() : MachineFunctionPass(ID) {}
168+
169+
LiveRegMatrix &getLRM() { return LRM; }
170+
const LiveRegMatrix &getLRM() const { return LRM; }
171+
172+
void getAnalysisUsage(AnalysisUsage &AU) const override;
173+
bool runOnMachineFunction(MachineFunction &MF) override;
174+
void releaseMemory() override;
175+
};
176+
177+
class LiveRegMatrixAnalysis : public AnalysisInfoMixin<LiveRegMatrixAnalysis> {
178+
friend AnalysisInfoMixin<LiveRegMatrixAnalysis>;
179+
static AnalysisKey Key;
180+
181+
public:
182+
using Result = LiveRegMatrix;
183+
184+
LiveRegMatrix run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
185+
};
186+
162187
} // end namespace llvm
163188

164189
#endif // LLVM_CODEGEN_LIVEREGMATRIX_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void initializeLiveDebugValuesPass(PassRegistry &);
156156
void initializeLiveDebugVariablesPass(PassRegistry &);
157157
void initializeLiveIntervalsWrapperPassPass(PassRegistry &);
158158
void initializeLiveRangeShrinkPass(PassRegistry &);
159-
void initializeLiveRegMatrixPass(PassRegistry &);
159+
void initializeLiveRegMatrixWrapperPassPass(PassRegistry &);
160160
void initializeLiveStacksPass(PassRegistry &);
161161
void initializeLiveVariablesWrapperPassPass(PassRegistry &);
162162
void initializeLoadStoreOptPass(PassRegistry &);

llvm/lib/CodeGen/LiveRegMatrix.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,33 @@ using namespace llvm;
3535
STATISTIC(NumAssigned , "Number of registers assigned");
3636
STATISTIC(NumUnassigned , "Number of registers unassigned");
3737

38-
char LiveRegMatrix::ID = 0;
39-
INITIALIZE_PASS_BEGIN(LiveRegMatrix, "liveregmatrix",
38+
char LiveRegMatrixWrapperPass::ID = 0;
39+
INITIALIZE_PASS_BEGIN(LiveRegMatrixWrapperPass, "liveregmatrix",
4040
"Live Register Matrix", false, false)
4141
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
4242
INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperPass)
43-
INITIALIZE_PASS_END(LiveRegMatrix, "liveregmatrix",
43+
INITIALIZE_PASS_END(LiveRegMatrixWrapperPass, "liveregmatrix",
4444
"Live Register Matrix", false, false)
4545

46-
LiveRegMatrix::LiveRegMatrix() : MachineFunctionPass(ID) {}
47-
48-
void LiveRegMatrix::getAnalysisUsage(AnalysisUsage &AU) const {
46+
void LiveRegMatrixWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
4947
AU.setPreservesAll();
5048
AU.addRequiredTransitive<LiveIntervalsWrapperPass>();
5149
AU.addRequiredTransitive<VirtRegMapWrapperPass>();
5250
MachineFunctionPass::getAnalysisUsage(AU);
5351
}
5452

55-
bool LiveRegMatrix::runOnMachineFunction(MachineFunction &MF) {
53+
bool LiveRegMatrixWrapperPass::runOnMachineFunction(MachineFunction &MF) {
54+
auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
55+
auto *VRM = &getAnalysis<VirtRegMapWrapperPass>().getVRM();
56+
LRM.init(MF, LIS, VRM);
57+
return false;
58+
}
59+
60+
void LiveRegMatrix::init(MachineFunction &MF, LiveIntervals *pLIS,
61+
VirtRegMap *pVRM) {
5662
TRI = MF.getSubtarget().getRegisterInfo();
57-
LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
58-
VRM = &getAnalysis<VirtRegMapWrapperPass>().getVRM();
63+
LIS = pLIS;
64+
VRM = pVRM;
5965

6066
unsigned NumRegUnits = TRI->getNumRegUnits();
6167
if (NumRegUnits != Matrix.size())
@@ -64,9 +70,10 @@ bool LiveRegMatrix::runOnMachineFunction(MachineFunction &MF) {
6470

6571
// Make sure no stale queries get reused.
6672
invalidateVirtRegs();
67-
return false;
6873
}
6974

75+
void LiveRegMatrixWrapperPass::releaseMemory() { LRM.releaseMemory(); }
76+
7077
void LiveRegMatrix::releaseMemory() {
7178
for (unsigned i = 0, e = Matrix.size(); i != e; ++i) {
7279
Matrix[i].clear();
@@ -246,3 +253,5 @@ Register LiveRegMatrix::getOneVReg(unsigned PhysReg) const {
246253

247254
return MCRegister::NoRegister;
248255
}
256+
257+
AnalysisKey LiveRegMatrixAnalysis::Key;

llvm/lib/CodeGen/RegAllocBasic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
139139
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
140140
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
141141
INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperPass)
142-
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrix)
142+
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrixWrapperPass)
143143
INITIALIZE_PASS_END(RABasic, "regallocbasic", "Basic Register Allocator", false,
144144
false)
145145

@@ -190,8 +190,8 @@ void RABasic::getAnalysisUsage(AnalysisUsage &AU) const {
190190
AU.addPreserved<MachineLoopInfoWrapperPass>();
191191
AU.addRequired<VirtRegMapWrapperPass>();
192192
AU.addPreserved<VirtRegMapWrapperPass>();
193-
AU.addRequired<LiveRegMatrix>();
194-
AU.addPreserved<LiveRegMatrix>();
193+
AU.addRequired<LiveRegMatrixWrapperPass>();
194+
AU.addPreserved<LiveRegMatrixWrapperPass>();
195195
MachineFunctionPass::getAnalysisUsage(AU);
196196
}
197197

@@ -309,7 +309,7 @@ bool RABasic::runOnMachineFunction(MachineFunction &mf) {
309309
MF = &mf;
310310
RegAllocBase::init(getAnalysis<VirtRegMapWrapperPass>().getVRM(),
311311
getAnalysis<LiveIntervalsWrapperPass>().getLIS(),
312-
getAnalysis<LiveRegMatrix>());
312+
getAnalysis<LiveRegMatrixWrapperPass>().getLRM());
313313
VirtRegAuxInfo VRAI(
314314
*MF, *LIS, *VRM, getAnalysis<MachineLoopInfoWrapperPass>().getLI(),
315315
getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI());

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ INITIALIZE_PASS_DEPENDENCY(LiveStacks)
163163
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
164164
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
165165
INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperPass)
166-
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrix)
166+
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrixWrapperPass)
167167
INITIALIZE_PASS_DEPENDENCY(EdgeBundles)
168168
INITIALIZE_PASS_DEPENDENCY(SpillPlacement)
169169
INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
@@ -217,8 +217,8 @@ void RAGreedy::getAnalysisUsage(AnalysisUsage &AU) const {
217217
AU.addPreserved<MachineLoopInfoWrapperPass>();
218218
AU.addRequired<VirtRegMapWrapperPass>();
219219
AU.addPreserved<VirtRegMapWrapperPass>();
220-
AU.addRequired<LiveRegMatrix>();
221-
AU.addPreserved<LiveRegMatrix>();
220+
AU.addRequired<LiveRegMatrixWrapperPass>();
221+
AU.addPreserved<LiveRegMatrixWrapperPass>();
222222
AU.addRequired<EdgeBundles>();
223223
AU.addRequired<SpillPlacement>();
224224
AU.addRequired<MachineOptimizationRemarkEmitterPass>();
@@ -2715,7 +2715,7 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
27152715

27162716
RegAllocBase::init(getAnalysis<VirtRegMapWrapperPass>().getVRM(),
27172717
getAnalysis<LiveIntervalsWrapperPass>().getLIS(),
2718-
getAnalysis<LiveRegMatrix>());
2718+
getAnalysis<LiveRegMatrixWrapperPass>().getLRM());
27192719

27202720
// Early return if there is no virtual register to be allocated to a
27212721
// physical register.

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#include "llvm/CodeGen/InterleavedLoadCombine.h"
9595
#include "llvm/CodeGen/JMCInstrumenter.h"
9696
#include "llvm/CodeGen/LiveIntervals.h"
97+
#include "llvm/CodeGen/LiveRegMatrix.h"
9798
#include "llvm/CodeGen/LiveVariables.h"
9899
#include "llvm/CodeGen/LocalStackSlotAllocation.h"
99100
#include "llvm/CodeGen/LowerEmuTLS.h"

llvm/lib/Target/AMDGPU/GCNNSAReassign.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class GCNNSAReassign : public MachineFunctionPass {
5050
void getAnalysisUsage(AnalysisUsage &AU) const override {
5151
AU.addRequired<LiveIntervalsWrapperPass>();
5252
AU.addRequired<VirtRegMapWrapperPass>();
53-
AU.addRequired<LiveRegMatrix>();
53+
AU.addRequired<LiveRegMatrixWrapperPass>();
5454
AU.setPreservesAll();
5555
MachineFunctionPass::getAnalysisUsage(AU);
5656
}
@@ -96,7 +96,7 @@ INITIALIZE_PASS_BEGIN(GCNNSAReassign, DEBUG_TYPE, "GCN NSA Reassign",
9696
false, false)
9797
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
9898
INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperPass)
99-
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrix)
99+
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrixWrapperPass)
100100
INITIALIZE_PASS_END(GCNNSAReassign, DEBUG_TYPE, "GCN NSA Reassign",
101101
false, false)
102102

@@ -243,7 +243,7 @@ bool GCNNSAReassign::runOnMachineFunction(MachineFunction &MF) {
243243
MRI = &MF.getRegInfo();
244244
TRI = ST->getRegisterInfo();
245245
VRM = &getAnalysis<VirtRegMapWrapperPass>().getVRM();
246-
LRM = &getAnalysis<LiveRegMatrix>();
246+
LRM = &getAnalysis<LiveRegMatrixWrapperPass>().getLRM();
247247
LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
248248

249249
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();

llvm/lib/Target/AMDGPU/SIPreAllocateWWMRegs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class SIPreAllocateWWMRegs : public MachineFunctionPass {
6161
void getAnalysisUsage(AnalysisUsage &AU) const override {
6262
AU.addRequired<LiveIntervalsWrapperPass>();
6363
AU.addRequired<VirtRegMapWrapperPass>();
64-
AU.addRequired<LiveRegMatrix>();
64+
AU.addRequired<LiveRegMatrixWrapperPass>();
6565
AU.setPreservesAll();
6666
MachineFunctionPass::getAnalysisUsage(AU);
6767
}
@@ -77,7 +77,7 @@ INITIALIZE_PASS_BEGIN(SIPreAllocateWWMRegs, DEBUG_TYPE,
7777
"SI Pre-allocate WWM Registers", false, false)
7878
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
7979
INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperPass)
80-
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrix)
80+
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrixWrapperPass)
8181
INITIALIZE_PASS_END(SIPreAllocateWWMRegs, DEBUG_TYPE,
8282
"SI Pre-allocate WWM Registers", false, false)
8383

@@ -194,7 +194,7 @@ bool SIPreAllocateWWMRegs::runOnMachineFunction(MachineFunction &MF) {
194194
MRI = &MF.getRegInfo();
195195

196196
LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
197-
Matrix = &getAnalysis<LiveRegMatrix>();
197+
Matrix = &getAnalysis<LiveRegMatrixWrapperPass>().getLRM();
198198
VRM = &getAnalysis<VirtRegMapWrapperPass>().getVRM();
199199

200200
RegClassInfo.runOnMachineFunction(MF);

0 commit comments

Comments
 (0)