1111//
1212// ===----------------------------------------------------------------------===//
1313
14+ #include " SIPreAllocateWWMRegs.h"
1415#include " AMDGPU.h"
1516#include " GCNSubtarget.h"
1617#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -34,7 +35,7 @@ static cl::opt<bool>
3435
3536namespace {
3637
37- class SIPreAllocateWWMRegs : public MachineFunctionPass {
38+ class SIPreAllocateWWMRegs {
3839private:
3940 const SIInstrInfo *TII;
4041 const SIRegisterInfo *TRI;
@@ -48,13 +49,21 @@ class SIPreAllocateWWMRegs : public MachineFunctionPass {
4849#ifndef NDEBUG
4950 void printWWMInfo (const MachineInstr &MI);
5051#endif
52+ bool processDef (MachineOperand &MO);
53+ void rewriteRegs (MachineFunction &MF);
54+
55+ public:
56+ SIPreAllocateWWMRegs (LiveIntervals *LIS, LiveRegMatrix *Matrix,
57+ VirtRegMap *VRM)
58+ : LIS(LIS), Matrix(Matrix), VRM(VRM) {}
59+ bool run (MachineFunction &MF);
60+ };
5161
62+ class SIPreAllocateWWMRegsLegacy : public MachineFunctionPass {
5263public:
5364 static char ID;
5465
55- SIPreAllocateWWMRegs () : MachineFunctionPass(ID) {
56- initializeSIPreAllocateWWMRegsPass (*PassRegistry::getPassRegistry ());
57- }
66+ SIPreAllocateWWMRegsLegacy () : MachineFunctionPass(ID) {}
5867
5968 bool runOnMachineFunction (MachineFunction &MF) override ;
6069
@@ -65,28 +74,24 @@ class SIPreAllocateWWMRegs : public MachineFunctionPass {
6574 AU.setPreservesAll ();
6675 MachineFunctionPass::getAnalysisUsage (AU);
6776 }
68-
69- private:
70- bool processDef (MachineOperand &MO);
71- void rewriteRegs (MachineFunction &MF);
7277};
7378
7479} // End anonymous namespace.
7580
76- INITIALIZE_PASS_BEGIN (SIPreAllocateWWMRegs , DEBUG_TYPE,
77- " SI Pre-allocate WWM Registers" , false , false )
81+ INITIALIZE_PASS_BEGIN (SIPreAllocateWWMRegsLegacy , DEBUG_TYPE,
82+ " SI Pre-allocate WWM Registers" , false , false )
7883INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
7984INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperLegacy)
8085INITIALIZE_PASS_DEPENDENCY(LiveRegMatrixWrapperLegacy)
81- INITIALIZE_PASS_END(SIPreAllocateWWMRegs , DEBUG_TYPE,
82- " SI Pre-allocate WWM Registers" , false , false )
86+ INITIALIZE_PASS_END(SIPreAllocateWWMRegsLegacy , DEBUG_TYPE,
87+ " SI Pre-allocate WWM Registers" , false , false )
8388
84- char SIPreAllocateWWMRegs ::ID = 0;
89+ char SIPreAllocateWWMRegsLegacy ::ID = 0;
8590
86- char &llvm::SIPreAllocateWWMRegsID = SIPreAllocateWWMRegs ::ID;
91+ char &llvm::SIPreAllocateWWMRegsLegacyID = SIPreAllocateWWMRegsLegacy ::ID;
8792
88- FunctionPass *llvm::createSIPreAllocateWWMRegsPass () {
89- return new SIPreAllocateWWMRegs ();
93+ FunctionPass *llvm::createSIPreAllocateWWMRegsLegacyPass () {
94+ return new SIPreAllocateWWMRegsLegacy ();
9095}
9196
9297bool SIPreAllocateWWMRegs::processDef (MachineOperand &MO) {
@@ -184,7 +189,14 @@ SIPreAllocateWWMRegs::printWWMInfo(const MachineInstr &MI) {
184189
185190#endif
186191
187- bool SIPreAllocateWWMRegs::runOnMachineFunction (MachineFunction &MF) {
192+ bool SIPreAllocateWWMRegsLegacy::runOnMachineFunction (MachineFunction &MF) {
193+ auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS ();
194+ auto *Matrix = &getAnalysis<LiveRegMatrixWrapperLegacy>().getLRM ();
195+ auto *VRM = &getAnalysis<VirtRegMapWrapperLegacy>().getVRM ();
196+ return SIPreAllocateWWMRegs (LIS, Matrix, VRM).run (MF);
197+ }
198+
199+ bool SIPreAllocateWWMRegs::run (MachineFunction &MF) {
188200 LLVM_DEBUG (dbgs () << " SIPreAllocateWWMRegs: function " << MF.getName () << " \n " );
189201
190202 const GCNSubtarget &ST = MF.getSubtarget <GCNSubtarget>();
@@ -193,10 +205,6 @@ bool SIPreAllocateWWMRegs::runOnMachineFunction(MachineFunction &MF) {
193205 TRI = &TII->getRegisterInfo ();
194206 MRI = &MF.getRegInfo ();
195207
196- LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS ();
197- Matrix = &getAnalysis<LiveRegMatrixWrapperLegacy>().getLRM ();
198- VRM = &getAnalysis<VirtRegMapWrapperLegacy>().getVRM ();
199-
200208 RegClassInfo.runOnMachineFunction (MF);
201209
202210 bool PreallocateSGPRSpillVGPRs =
@@ -251,3 +259,13 @@ bool SIPreAllocateWWMRegs::runOnMachineFunction(MachineFunction &MF) {
251259 rewriteRegs (MF);
252260 return true ;
253261}
262+
263+ PreservedAnalyses
264+ SIPreAllocateWWMRegsPass::run (MachineFunction &MF,
265+ MachineFunctionAnalysisManager &MFAM) {
266+ auto *LIS = &MFAM.getResult <LiveIntervalsAnalysis>(MF);
267+ auto *Matrix = &MFAM.getResult <LiveRegMatrixAnalysis>(MF);
268+ auto *VRM = &MFAM.getResult <VirtRegMapAnalysis>(MF);
269+ SIPreAllocateWWMRegs (LIS, Matrix, VRM).run (MF);
270+ return PreservedAnalyses::all ();
271+ }
0 commit comments