1313// /
1414// ===----------------------------------------------------------------------===//
1515
16+ #include " GCNNSAReassign.h"
1617#include " AMDGPU.h"
1718#include " GCNSubtarget.h"
1819#include " SIMachineFunctionInfo.h"
@@ -34,26 +35,12 @@ STATISTIC(NumNSAConverted,
3435 " Number of NSA instructions changed to sequential" );
3536
3637namespace {
37-
38- class GCNNSAReassign : public MachineFunctionPass {
38+ class GCNNSAReassignImpl {
3939public:
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) {}
4742
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);
5744
5845private:
5946 using NSA_Status = enum {
@@ -90,24 +77,43 @@ class GCNNSAReassign : public MachineFunctionPass {
9077 bool scavengeRegs (SmallVectorImpl<LiveInterval *> &Intervals) const ;
9178};
9279
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+
93101} // End anonymous namespace.
94102
95- INITIALIZE_PASS_BEGIN (GCNNSAReassign , DEBUG_TYPE, " GCN NSA Reassign" ,
103+ INITIALIZE_PASS_BEGIN (GCNNSAReassignLegacy , DEBUG_TYPE, " GCN NSA Reassign" ,
96104 false , false )
97105INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
98106INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperLegacy)
99107INITIALIZE_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 )
103110
104- char GCNNSAReassign ::ID = 0;
111+ char GCNNSAReassignLegacy ::ID = 0;
105112
106- char &llvm::GCNNSAReassignID = GCNNSAReassign ::ID;
113+ char &llvm::GCNNSAReassignID = GCNNSAReassignLegacy ::ID;
107114
108- bool
109- GCNNSAReassign::tryAssignRegisters (SmallVectorImpl<LiveInterval *> &Intervals,
110- unsigned StartReg) const {
115+ bool GCNNSAReassignImpl::tryAssignRegisters (
116+ SmallVectorImpl<LiveInterval *> &Intervals, unsigned StartReg) const {
111117 unsigned NumRegs = Intervals.size ();
112118
113119 for (unsigned N = 0 ; N < NumRegs; ++N)
@@ -124,7 +130,7 @@ GCNNSAReassign::tryAssignRegisters(SmallVectorImpl<LiveInterval *> &Intervals,
124130 return true ;
125131}
126132
127- bool GCNNSAReassign ::canAssign (unsigned StartReg, unsigned NumRegs) const {
133+ bool GCNNSAReassignImpl ::canAssign (unsigned StartReg, unsigned NumRegs) const {
128134 for (unsigned N = 0 ; N < NumRegs; ++N) {
129135 unsigned Reg = StartReg + N;
130136 if (!MRI->isAllocatable (Reg))
@@ -139,8 +145,8 @@ bool GCNNSAReassign::canAssign(unsigned StartReg, unsigned NumRegs) const {
139145 return true ;
140146}
141147
142- bool
143- GCNNSAReassign::scavengeRegs ( SmallVectorImpl<LiveInterval *> &Intervals) const {
148+ bool GCNNSAReassignImpl::scavengeRegs (
149+ SmallVectorImpl<LiveInterval *> &Intervals) const {
144150 unsigned NumRegs = Intervals.size ();
145151
146152 if (NumRegs > MaxNumVGPRs)
@@ -158,8 +164,8 @@ GCNNSAReassign::scavengeRegs(SmallVectorImpl<LiveInterval *> &Intervals) const {
158164 return false ;
159165}
160166
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 {
163169 const AMDGPU::MIMGInfo *Info = AMDGPU::getMIMGInfo (MI.getOpcode ());
164170 if (!Info)
165171 return NSA_Status::NOT_NSA;
@@ -235,16 +241,13 @@ GCNNSAReassign::CheckNSA(const MachineInstr &MI, bool Fast) const {
235241 return NSA ? NSA_Status::NON_CONTIGUOUS : NSA_Status::CONTIGUOUS;
236242}
237243
238- bool GCNNSAReassign::runOnMachineFunction (MachineFunction &MF) {
244+ bool GCNNSAReassignImpl::run (MachineFunction &MF) {
239245 ST = &MF.getSubtarget <GCNSubtarget>();
240246 if (!ST->hasNSAEncoding () || !ST->hasNonNSAEncoding ())
241247 return false ;
242248
243249 MRI = &MF.getRegInfo ();
244250 TRI = ST->getRegisterInfo ();
245- VRM = &getAnalysis<VirtRegMapWrapperLegacy>().getVRM ();
246- LRM = &getAnalysis<LiveRegMatrixWrapperLegacy>().getLRM ();
247- LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS ();
248251
249252 const SIMachineFunctionInfo *MFI = MF.getInfo <SIMachineFunctionInfo>();
250253 MaxNumVGPRs = ST->getMaxNumVGPRs (MF);
@@ -367,3 +370,24 @@ bool GCNNSAReassign::runOnMachineFunction(MachineFunction &MF) {
367370
368371 return Changed;
369372}
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