13
13
// /
14
14
// ===----------------------------------------------------------------------===//
15
15
16
+ #include " GCNNSAReassign.h"
16
17
#include " AMDGPU.h"
17
18
#include " GCNSubtarget.h"
18
19
#include " SIMachineFunctionInfo.h"
@@ -34,26 +35,12 @@ STATISTIC(NumNSAConverted,
34
35
" Number of NSA instructions changed to sequential" );
35
36
36
37
namespace {
37
-
38
- class GCNNSAReassign : public MachineFunctionPass {
38
+ class GCNNSAReassignImpl {
39
39
public:
40
- static char ID;
41
-
42
- GCNNSAReassign () : MachineFunctionPass(ID) {
43
- initializeGCNNSAReassignPass (*PassRegistry::getPassRegistry ());
44
- }
45
-
46
- bool runOnMachineFunction (MachineFunction &MF) override ;
40
+ GCNNSAReassignImpl (VirtRegMap *VM, LiveRegMatrix *LM, LiveIntervals *LS)
41
+ : VRM(VM), LRM(LM), LIS(LS) {}
47
42
48
- StringRef getPassName () const override { return " GCN NSA Reassign" ; }
49
-
50
- void getAnalysisUsage (AnalysisUsage &AU) const override {
51
- AU.addRequired <LiveIntervalsWrapperPass>();
52
- AU.addRequired <VirtRegMapWrapperLegacy>();
53
- AU.addRequired <LiveRegMatrixWrapperLegacy>();
54
- AU.setPreservesAll ();
55
- MachineFunctionPass::getAnalysisUsage (AU);
56
- }
43
+ bool run (MachineFunction &MF);
57
44
58
45
private:
59
46
using NSA_Status = enum {
@@ -90,24 +77,43 @@ class GCNNSAReassign : public MachineFunctionPass {
90
77
bool scavengeRegs (SmallVectorImpl<LiveInterval *> &Intervals) const ;
91
78
};
92
79
80
+ class GCNNSAReassignLegacy : public MachineFunctionPass {
81
+ public:
82
+ static char ID;
83
+
84
+ GCNNSAReassignLegacy () : MachineFunctionPass(ID) {
85
+ initializeGCNNSAReassignLegacyPass (*PassRegistry::getPassRegistry ());
86
+ }
87
+
88
+ bool runOnMachineFunction (MachineFunction &MF) override ;
89
+
90
+ StringRef getPassName () const override { return " GCN NSA Reassign" ; };
91
+
92
+ void getAnalysisUsage (AnalysisUsage &AU) const override {
93
+ AU.addRequired <LiveIntervalsWrapperPass>();
94
+ AU.addRequired <VirtRegMapWrapperLegacy>();
95
+ AU.addRequired <LiveRegMatrixWrapperLegacy>();
96
+ AU.setPreservesAll ();
97
+ MachineFunctionPass::getAnalysisUsage (AU);
98
+ }
99
+ };
100
+
93
101
} // End anonymous namespace.
94
102
95
- INITIALIZE_PASS_BEGIN (GCNNSAReassign , DEBUG_TYPE, " GCN NSA Reassign" ,
103
+ INITIALIZE_PASS_BEGIN (GCNNSAReassignLegacy , DEBUG_TYPE, " GCN NSA Reassign" ,
96
104
false , false )
97
105
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
98
106
INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperLegacy)
99
107
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrixWrapperLegacy)
100
- INITIALIZE_PASS_END(GCNNSAReassign, DEBUG_TYPE, " GCN NSA Reassign" ,
101
- false , false )
102
-
108
+ INITIALIZE_PASS_END(GCNNSAReassignLegacy, DEBUG_TYPE, " GCN NSA Reassign" , false ,
109
+ false )
103
110
104
- char GCNNSAReassign ::ID = 0;
111
+ char GCNNSAReassignLegacy ::ID = 0;
105
112
106
- char &llvm::GCNNSAReassignID = GCNNSAReassign ::ID;
113
+ char &llvm::GCNNSAReassignID = GCNNSAReassignLegacy ::ID;
107
114
108
- bool
109
- GCNNSAReassign::tryAssignRegisters (SmallVectorImpl<LiveInterval *> &Intervals,
110
- unsigned StartReg) const {
115
+ bool GCNNSAReassignImpl::tryAssignRegisters (
116
+ SmallVectorImpl<LiveInterval *> &Intervals, unsigned StartReg) const {
111
117
unsigned NumRegs = Intervals.size ();
112
118
113
119
for (unsigned N = 0 ; N < NumRegs; ++N)
@@ -124,7 +130,7 @@ GCNNSAReassign::tryAssignRegisters(SmallVectorImpl<LiveInterval *> &Intervals,
124
130
return true ;
125
131
}
126
132
127
- bool GCNNSAReassign ::canAssign (unsigned StartReg, unsigned NumRegs) const {
133
+ bool GCNNSAReassignImpl ::canAssign (unsigned StartReg, unsigned NumRegs) const {
128
134
for (unsigned N = 0 ; N < NumRegs; ++N) {
129
135
unsigned Reg = StartReg + N;
130
136
if (!MRI->isAllocatable (Reg))
@@ -139,8 +145,8 @@ bool GCNNSAReassign::canAssign(unsigned StartReg, unsigned NumRegs) const {
139
145
return true ;
140
146
}
141
147
142
- bool
143
- GCNNSAReassign::scavengeRegs ( SmallVectorImpl<LiveInterval *> &Intervals) const {
148
+ bool GCNNSAReassignImpl::scavengeRegs (
149
+ SmallVectorImpl<LiveInterval *> &Intervals) const {
144
150
unsigned NumRegs = Intervals.size ();
145
151
146
152
if (NumRegs > MaxNumVGPRs)
@@ -158,8 +164,8 @@ GCNNSAReassign::scavengeRegs(SmallVectorImpl<LiveInterval *> &Intervals) const {
158
164
return false ;
159
165
}
160
166
161
- GCNNSAReassign ::NSA_Status
162
- GCNNSAReassign ::CheckNSA (const MachineInstr &MI, bool Fast) const {
167
+ GCNNSAReassignImpl ::NSA_Status
168
+ GCNNSAReassignImpl ::CheckNSA (const MachineInstr &MI, bool Fast) const {
163
169
const AMDGPU::MIMGInfo *Info = AMDGPU::getMIMGInfo (MI.getOpcode ());
164
170
if (!Info)
165
171
return NSA_Status::NOT_NSA;
@@ -235,16 +241,13 @@ GCNNSAReassign::CheckNSA(const MachineInstr &MI, bool Fast) const {
235
241
return NSA ? NSA_Status::NON_CONTIGUOUS : NSA_Status::CONTIGUOUS;
236
242
}
237
243
238
- bool GCNNSAReassign::runOnMachineFunction (MachineFunction &MF) {
244
+ bool GCNNSAReassignImpl::run (MachineFunction &MF) {
239
245
ST = &MF.getSubtarget <GCNSubtarget>();
240
246
if (!ST->hasNSAEncoding () || !ST->hasNonNSAEncoding ())
241
247
return false ;
242
248
243
249
MRI = &MF.getRegInfo ();
244
250
TRI = ST->getRegisterInfo ();
245
- VRM = &getAnalysis<VirtRegMapWrapperLegacy>().getVRM ();
246
- LRM = &getAnalysis<LiveRegMatrixWrapperLegacy>().getLRM ();
247
- LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS ();
248
251
249
252
const SIMachineFunctionInfo *MFI = MF.getInfo <SIMachineFunctionInfo>();
250
253
MaxNumVGPRs = ST->getMaxNumVGPRs (MF);
@@ -367,3 +370,24 @@ bool GCNNSAReassign::runOnMachineFunction(MachineFunction &MF) {
367
370
368
371
return Changed;
369
372
}
373
+
374
+ bool GCNNSAReassignLegacy::runOnMachineFunction (MachineFunction &MF) {
375
+ auto *VRM = &getAnalysis<VirtRegMapWrapperLegacy>().getVRM ();
376
+ auto *LRM = &getAnalysis<LiveRegMatrixWrapperLegacy>().getLRM ();
377
+ auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS ();
378
+
379
+ GCNNSAReassignImpl Impl (VRM, LRM, LIS);
380
+ return Impl.run (MF);
381
+ }
382
+
383
+ PreservedAnalyses
384
+ GCNNSAReassignPass::run (MachineFunction &MF,
385
+ MachineFunctionAnalysisManager &MFAM) {
386
+ auto &VRM = MFAM.getResult <VirtRegMapAnalysis>(MF);
387
+ auto &LRM = MFAM.getResult <LiveRegMatrixAnalysis>(MF);
388
+ auto &LIS = MFAM.getResult <LiveIntervalsAnalysis>(MF);
389
+
390
+ GCNNSAReassignImpl Impl (&VRM, &LRM, &LIS);
391
+ Impl.run (MF);
392
+ return PreservedAnalyses::all ();
393
+ }
0 commit comments