14
14
// /
15
15
// ===----------------------------------------------------------------------===//
16
16
17
+ #include " SIFormMemoryClauses.h"
17
18
#include " AMDGPU.h"
18
19
#include " GCNRegPressure.h"
19
20
#include " SIMachineFunctionInfo.h"
@@ -31,15 +32,37 @@ MaxClause("amdgpu-max-memory-clause", cl::Hidden, cl::init(15),
31
32
32
33
namespace {
33
34
34
- class SIFormMemoryClauses : public MachineFunctionPass {
35
+ class SIFormMemoryClausesImpl {
35
36
using RegUse = DenseMap<unsigned , std::pair<unsigned , LaneBitmask>>;
36
37
38
+ bool canBundle (const MachineInstr &MI, const RegUse &Defs,
39
+ const RegUse &Uses) const ;
40
+ bool checkPressure (const MachineInstr &MI, GCNDownwardRPTracker &RPT);
41
+ void collectRegUses (const MachineInstr &MI, RegUse &Defs, RegUse &Uses) const ;
42
+ bool processRegUses (const MachineInstr &MI, RegUse &Defs, RegUse &Uses,
43
+ GCNDownwardRPTracker &RPT);
44
+
45
+ const GCNSubtarget *ST;
46
+ const SIRegisterInfo *TRI;
47
+ const MachineRegisterInfo *MRI;
48
+ SIMachineFunctionInfo *MFI;
49
+ LiveIntervals *LIS;
50
+
51
+ unsigned LastRecordedOccupancy;
52
+ unsigned MaxVGPRs;
53
+ unsigned MaxSGPRs;
54
+
37
55
public:
38
- static char ID;
56
+ SIFormMemoryClausesImpl (LiveIntervals *LS) : LIS(LS) {}
57
+ bool run (MachineFunction &MF);
58
+ };
39
59
60
+ class SIFormMemoryClausesLegacy : public MachineFunctionPass {
40
61
public:
41
- SIFormMemoryClauses () : MachineFunctionPass(ID) {
42
- initializeSIFormMemoryClausesPass (*PassRegistry::getPassRegistry ());
62
+ static char ID;
63
+
64
+ SIFormMemoryClausesLegacy () : MachineFunctionPass(ID) {
65
+ initializeSIFormMemoryClausesLegacyPass (*PassRegistry::getPassRegistry ());
43
66
}
44
67
45
68
bool runOnMachineFunction (MachineFunction &MF) override ;
@@ -58,40 +81,22 @@ class SIFormMemoryClauses : public MachineFunctionPass {
58
81
return MachineFunctionProperties ().set (
59
82
MachineFunctionProperties::Property::IsSSA);
60
83
}
61
-
62
- private:
63
- bool canBundle (const MachineInstr &MI, const RegUse &Defs,
64
- const RegUse &Uses) const ;
65
- bool checkPressure (const MachineInstr &MI, GCNDownwardRPTracker &RPT);
66
- void collectRegUses (const MachineInstr &MI, RegUse &Defs, RegUse &Uses) const ;
67
- bool processRegUses (const MachineInstr &MI, RegUse &Defs, RegUse &Uses,
68
- GCNDownwardRPTracker &RPT);
69
-
70
- const GCNSubtarget *ST;
71
- const SIRegisterInfo *TRI;
72
- const MachineRegisterInfo *MRI;
73
- SIMachineFunctionInfo *MFI;
74
-
75
- unsigned LastRecordedOccupancy;
76
- unsigned MaxVGPRs;
77
- unsigned MaxSGPRs;
78
84
};
79
85
80
86
} // End anonymous namespace.
81
87
82
- INITIALIZE_PASS_BEGIN (SIFormMemoryClauses , DEBUG_TYPE,
88
+ INITIALIZE_PASS_BEGIN (SIFormMemoryClausesLegacy , DEBUG_TYPE,
83
89
" SI Form memory clauses" , false , false )
84
90
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
85
- INITIALIZE_PASS_END(SIFormMemoryClauses , DEBUG_TYPE,
91
+ INITIALIZE_PASS_END(SIFormMemoryClausesLegacy , DEBUG_TYPE,
86
92
" SI Form memory clauses" , false , false )
87
93
94
+ char SIFormMemoryClausesLegacy::ID = 0;
88
95
89
- char SIFormMemoryClauses::ID = 0;
90
-
91
- char &llvm::SIFormMemoryClausesID = SIFormMemoryClauses::ID;
96
+ char &llvm::SIFormMemoryClausesID = SIFormMemoryClausesLegacy::ID;
92
97
93
- FunctionPass *llvm::createSIFormMemoryClausesPass () {
94
- return new SIFormMemoryClauses ();
98
+ FunctionPass *llvm::createSIFormMemoryClausesLegacyPass () {
99
+ return new SIFormMemoryClausesLegacy ();
95
100
}
96
101
97
102
static bool isVMEMClauseInst (const MachineInstr &MI) {
@@ -147,8 +152,9 @@ static unsigned getMopState(const MachineOperand &MO) {
147
152
148
153
// Returns false if there is a use of a def already in the map.
149
154
// In this case we must break the clause.
150
- bool SIFormMemoryClauses::canBundle (const MachineInstr &MI, const RegUse &Defs,
151
- const RegUse &Uses) const {
155
+ bool SIFormMemoryClausesImpl::canBundle (const MachineInstr &MI,
156
+ const RegUse &Defs,
157
+ const RegUse &Uses) const {
152
158
// Check interference with defs.
153
159
for (const MachineOperand &MO : MI.operands ()) {
154
160
// TODO: Prologue/Epilogue Insertion pass does not process bundled
@@ -184,8 +190,8 @@ bool SIFormMemoryClauses::canBundle(const MachineInstr &MI, const RegUse &Defs,
184
190
// Since all defs in the clause are early clobber we can run out of registers.
185
191
// Function returns false if pressure would hit the limit if instruction is
186
192
// bundled into a memory clause.
187
- bool SIFormMemoryClauses ::checkPressure (const MachineInstr &MI,
188
- GCNDownwardRPTracker &RPT) {
193
+ bool SIFormMemoryClausesImpl ::checkPressure (const MachineInstr &MI,
194
+ GCNDownwardRPTracker &RPT) {
189
195
// NB: skip advanceBeforeNext() call. Since all defs will be marked
190
196
// early-clobber they will all stay alive at least to the end of the
191
197
// clause. Therefor we should not decrease pressure even if load
@@ -213,8 +219,8 @@ bool SIFormMemoryClauses::checkPressure(const MachineInstr &MI,
213
219
}
214
220
215
221
// Collect register defs and uses along with their lane masks and states.
216
- void SIFormMemoryClauses ::collectRegUses (const MachineInstr &MI,
217
- RegUse &Defs, RegUse &Uses) const {
222
+ void SIFormMemoryClausesImpl ::collectRegUses (const MachineInstr &MI,
223
+ RegUse &Defs, RegUse &Uses) const {
218
224
for (const MachineOperand &MO : MI.operands ()) {
219
225
if (!MO.isReg ())
220
226
continue ;
@@ -239,9 +245,9 @@ void SIFormMemoryClauses::collectRegUses(const MachineInstr &MI,
239
245
// Check register def/use conflicts, occupancy limits and collect def/use maps.
240
246
// Return true if instruction can be bundled with previous. If it cannot
241
247
// def/use maps are not updated.
242
- bool SIFormMemoryClauses ::processRegUses (const MachineInstr &MI,
243
- RegUse &Defs, RegUse &Uses,
244
- GCNDownwardRPTracker &RPT) {
248
+ bool SIFormMemoryClausesImpl ::processRegUses (const MachineInstr &MI,
249
+ RegUse &Defs, RegUse &Uses,
250
+ GCNDownwardRPTracker &RPT) {
245
251
if (!canBundle (MI, Defs, Uses))
246
252
return false ;
247
253
@@ -252,10 +258,7 @@ bool SIFormMemoryClauses::processRegUses(const MachineInstr &MI,
252
258
return true ;
253
259
}
254
260
255
- bool SIFormMemoryClauses::runOnMachineFunction (MachineFunction &MF) {
256
- if (skipFunction (MF.getFunction ()))
257
- return false ;
258
-
261
+ bool SIFormMemoryClausesImpl::run (MachineFunction &MF) {
259
262
ST = &MF.getSubtarget <GCNSubtarget>();
260
263
if (!ST->isXNACKEnabled ())
261
264
return false ;
@@ -264,7 +267,6 @@ bool SIFormMemoryClauses::runOnMachineFunction(MachineFunction &MF) {
264
267
TRI = ST->getRegisterInfo ();
265
268
MRI = &MF.getRegInfo ();
266
269
MFI = MF.getInfo <SIMachineFunctionInfo>();
267
- LiveIntervals *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS ();
268
270
SlotIndexes *Ind = LIS->getSlotIndexes ();
269
271
bool Changed = false ;
270
272
@@ -416,3 +418,19 @@ bool SIFormMemoryClauses::runOnMachineFunction(MachineFunction &MF) {
416
418
417
419
return Changed;
418
420
}
421
+
422
+ bool SIFormMemoryClausesLegacy::runOnMachineFunction (MachineFunction &MF) {
423
+ if (skipFunction (MF.getFunction ()))
424
+ return false ;
425
+
426
+ LiveIntervals *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS ();
427
+ return SIFormMemoryClausesImpl (LIS).run (MF);
428
+ }
429
+
430
+ PreservedAnalyses
431
+ SIFormMemoryClausesPass::run (MachineFunction &MF,
432
+ MachineFunctionAnalysisManager &MFAM) {
433
+ LiveIntervals &LIS = MFAM.getResult <LiveIntervalsAnalysis>(MF);
434
+ SIFormMemoryClausesImpl (&LIS).run (MF);
435
+ return PreservedAnalyses::all ();
436
+ }
0 commit comments