1515//
1616// ===----------------------------------------------------------------------===//
1717
18+ #include " SILowerWWMCopies.h"
1819#include " AMDGPU.h"
1920#include " GCNSubtarget.h"
2021#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -30,12 +31,30 @@ using namespace llvm;
3031
3132namespace {
3233
33- class SILowerWWMCopies : public MachineFunctionPass {
34+ class SILowerWWMCopies {
35+ public:
36+ SILowerWWMCopies (LiveIntervals *LIS, SlotIndexes *SI, VirtRegMap *VRM)
37+ : LIS(LIS), Indexes(SI), VRM(VRM) {}
38+ bool run (MachineFunction &MF);
39+
40+ private:
41+ bool isSCCLiveAtMI (const MachineInstr &MI);
42+ void addToWWMSpills (MachineFunction &MF, Register Reg);
43+
44+ LiveIntervals *LIS;
45+ SlotIndexes *Indexes;
46+ VirtRegMap *VRM;
47+ const SIRegisterInfo *TRI;
48+ const MachineRegisterInfo *MRI;
49+ SIMachineFunctionInfo *MFI;
50+ };
51+
52+ class SILowerWWMCopiesLegacy : public MachineFunctionPass {
3453public:
3554 static char ID;
3655
37- SILowerWWMCopies () : MachineFunctionPass(ID) {
38- initializeSILowerWWMCopiesPass (*PassRegistry::getPassRegistry ());
56+ SILowerWWMCopiesLegacy () : MachineFunctionPass(ID) {
57+ initializeSILowerWWMCopiesLegacyPass (*PassRegistry::getPassRegistry ());
3958 }
4059
4160 bool runOnMachineFunction (MachineFunction &MF) override ;
@@ -49,31 +68,20 @@ class SILowerWWMCopies : public MachineFunctionPass {
4968 AU.setPreservesAll ();
5069 MachineFunctionPass::getAnalysisUsage (AU);
5170 }
52-
53- private:
54- bool isSCCLiveAtMI (const MachineInstr &MI);
55- void addToWWMSpills (MachineFunction &MF, Register Reg);
56-
57- LiveIntervals *LIS;
58- SlotIndexes *Indexes;
59- VirtRegMap *VRM;
60- const SIRegisterInfo *TRI;
61- const MachineRegisterInfo *MRI;
62- SIMachineFunctionInfo *MFI;
6371};
6472
6573} // End anonymous namespace.
6674
67- INITIALIZE_PASS_BEGIN (SILowerWWMCopies , DEBUG_TYPE, " SI Lower WWM Copies" ,
75+ INITIALIZE_PASS_BEGIN (SILowerWWMCopiesLegacy , DEBUG_TYPE, " SI Lower WWM Copies" ,
6876 false , false )
6977INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
7078INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperLegacy)
71- INITIALIZE_PASS_END(SILowerWWMCopies , DEBUG_TYPE, " SI Lower WWM Copies" , false ,
72- false )
79+ INITIALIZE_PASS_END(SILowerWWMCopiesLegacy , DEBUG_TYPE, " SI Lower WWM Copies" ,
80+ false , false )
7381
74- char SILowerWWMCopies ::ID = 0;
82+ char SILowerWWMCopiesLegacy ::ID = 0;
7583
76- char &llvm::SILowerWWMCopiesID = SILowerWWMCopies ::ID;
84+ char &llvm::SILowerWWMCopiesLegacyID = SILowerWWMCopiesLegacy ::ID;
7785
7886bool SILowerWWMCopies::isSCCLiveAtMI (const MachineInstr &MI) {
7987 // We can't determine the liveness info if LIS isn't available. Early return
@@ -93,23 +101,44 @@ void SILowerWWMCopies::addToWWMSpills(MachineFunction &MF, Register Reg) {
93101 if (Reg.isPhysical ())
94102 return ;
95103
104+ // FIXME: VRM may be null here.
96105 MCRegister PhysReg = VRM->getPhys (Reg);
97106 assert (PhysReg && " should have allocated a physical register" );
98107
99108 MFI->allocateWWMSpill (MF, PhysReg);
100109}
101110
102- bool SILowerWWMCopies::runOnMachineFunction (MachineFunction &MF) {
111+ bool SILowerWWMCopiesLegacy::runOnMachineFunction (MachineFunction &MF) {
112+ auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
113+ auto *LIS = LISWrapper ? &LISWrapper->getLIS () : nullptr ;
114+
115+ auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
116+ auto *Indexes = SIWrapper ? &SIWrapper->getSI () : nullptr ;
117+
118+ auto *VRMWrapper = getAnalysisIfAvailable<VirtRegMapWrapperLegacy>();
119+ auto *VRM = VRMWrapper ? &VRMWrapper->getVRM () : nullptr ;
120+
121+ SILowerWWMCopies Impl (LIS, Indexes, VRM);
122+ return Impl.run (MF);
123+ }
124+
125+ PreservedAnalyses
126+ SILowerWWMCopiesPass::run (MachineFunction &MF,
127+ MachineFunctionAnalysisManager &MFAM) {
128+ auto *LIS = MFAM.getCachedResult <LiveIntervalsAnalysis>(MF);
129+ auto *Indexes = MFAM.getCachedResult <SlotIndexesAnalysis>(MF);
130+ auto *VRM = MFAM.getCachedResult <VirtRegMapAnalysis>(MF);
131+
132+ SILowerWWMCopies Impl (LIS, Indexes, VRM);
133+ Impl.run (MF);
134+ return PreservedAnalyses::all ();
135+ }
136+
137+ bool SILowerWWMCopies::run (MachineFunction &MF) {
103138 const GCNSubtarget &ST = MF.getSubtarget <GCNSubtarget>();
104139 const SIInstrInfo *TII = ST.getInstrInfo ();
105140
106141 MFI = MF.getInfo <SIMachineFunctionInfo>();
107- auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
108- LIS = LISWrapper ? &LISWrapper->getLIS () : nullptr ;
109- auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
110- Indexes = SIWrapper ? &SIWrapper->getSI () : nullptr ;
111- auto *VRMWrapper = getAnalysisIfAvailable<VirtRegMapWrapperLegacy>();
112- VRM = VRMWrapper ? &VRMWrapper->getVRM () : nullptr ;
113142 TRI = ST.getRegisterInfo ();
114143 MRI = &MF.getRegInfo ();
115144
0 commit comments