15
15
//
16
16
// ===----------------------------------------------------------------------===//
17
17
18
+ #include " SILowerWWMCopies.h"
18
19
#include " AMDGPU.h"
19
20
#include " GCNSubtarget.h"
20
21
#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -30,12 +31,30 @@ using namespace llvm;
30
31
31
32
namespace {
32
33
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 {
34
53
public:
35
54
static char ID;
36
55
37
- SILowerWWMCopies () : MachineFunctionPass(ID) {
38
- initializeSILowerWWMCopiesPass (*PassRegistry::getPassRegistry ());
56
+ SILowerWWMCopiesLegacy () : MachineFunctionPass(ID) {
57
+ initializeSILowerWWMCopiesLegacyPass (*PassRegistry::getPassRegistry ());
39
58
}
40
59
41
60
bool runOnMachineFunction (MachineFunction &MF) override ;
@@ -49,31 +68,20 @@ class SILowerWWMCopies : public MachineFunctionPass {
49
68
AU.setPreservesAll ();
50
69
MachineFunctionPass::getAnalysisUsage (AU);
51
70
}
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;
63
71
};
64
72
65
73
} // End anonymous namespace.
66
74
67
- INITIALIZE_PASS_BEGIN (SILowerWWMCopies , DEBUG_TYPE, " SI Lower WWM Copies" ,
75
+ INITIALIZE_PASS_BEGIN (SILowerWWMCopiesLegacy , DEBUG_TYPE, " SI Lower WWM Copies" ,
68
76
false , false )
69
77
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
70
78
INITIALIZE_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 )
73
81
74
- char SILowerWWMCopies ::ID = 0;
82
+ char SILowerWWMCopiesLegacy ::ID = 0;
75
83
76
- char &llvm::SILowerWWMCopiesID = SILowerWWMCopies ::ID;
84
+ char &llvm::SILowerWWMCopiesLegacyID = SILowerWWMCopiesLegacy ::ID;
77
85
78
86
bool SILowerWWMCopies::isSCCLiveAtMI (const MachineInstr &MI) {
79
87
// 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) {
93
101
if (Reg.isPhysical ())
94
102
return ;
95
103
104
+ // FIXME: VRM may be null here.
96
105
MCRegister PhysReg = VRM->getPhys (Reg);
97
106
assert (PhysReg && " should have allocated a physical register" );
98
107
99
108
MFI->allocateWWMSpill (MF, PhysReg);
100
109
}
101
110
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) {
103
138
const GCNSubtarget &ST = MF.getSubtarget <GCNSubtarget>();
104
139
const SIInstrInfo *TII = ST.getInstrInfo ();
105
140
106
141
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 ;
113
142
TRI = ST.getRegisterInfo ();
114
143
MRI = &MF.getRegInfo ();
115
144
0 commit comments