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 ;
@@ -46,31 +65,20 @@ class SILowerWWMCopies : public MachineFunctionPass {
46
65
AU.setPreservesAll ();
47
66
MachineFunctionPass::getAnalysisUsage (AU);
48
67
}
49
-
50
- private:
51
- bool isSCCLiveAtMI (const MachineInstr &MI);
52
- void addToWWMSpills (MachineFunction &MF, Register Reg);
53
-
54
- LiveIntervals *LIS;
55
- SlotIndexes *Indexes;
56
- VirtRegMap *VRM;
57
- const SIRegisterInfo *TRI;
58
- const MachineRegisterInfo *MRI;
59
- SIMachineFunctionInfo *MFI;
60
68
};
61
69
62
70
} // End anonymous namespace.
63
71
64
- INITIALIZE_PASS_BEGIN (SILowerWWMCopies , DEBUG_TYPE, " SI Lower WWM Copies" ,
72
+ INITIALIZE_PASS_BEGIN (SILowerWWMCopiesLegacy , DEBUG_TYPE, " SI Lower WWM Copies" ,
65
73
false , false )
66
74
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
67
75
INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperLegacy)
68
- INITIALIZE_PASS_END(SILowerWWMCopies , DEBUG_TYPE, " SI Lower WWM Copies" , false ,
69
- false )
76
+ INITIALIZE_PASS_END(SILowerWWMCopiesLegacy , DEBUG_TYPE, " SI Lower WWM Copies" ,
77
+ false , false )
70
78
71
- char SILowerWWMCopies ::ID = 0;
79
+ char SILowerWWMCopiesLegacy ::ID = 0;
72
80
73
- char &llvm::SILowerWWMCopiesID = SILowerWWMCopies ::ID;
81
+ char &llvm::SILowerWWMCopiesLegacyID = SILowerWWMCopiesLegacy ::ID;
74
82
75
83
bool SILowerWWMCopies::isSCCLiveAtMI (const MachineInstr &MI) {
76
84
// We can't determine the liveness info if LIS isn't available. Early return
@@ -90,23 +98,44 @@ void SILowerWWMCopies::addToWWMSpills(MachineFunction &MF, Register Reg) {
90
98
if (Reg.isPhysical ())
91
99
return ;
92
100
101
+ // FIXME: VRM is not an optional requirement, we check it for assignment here
93
102
MCRegister PhysReg = VRM->getPhys (Reg);
94
103
assert (PhysReg && " should have allocated a physical register" );
95
104
96
105
MFI->allocateWWMSpill (MF, PhysReg);
97
106
}
98
107
99
- bool SILowerWWMCopies::runOnMachineFunction (MachineFunction &MF) {
108
+ bool SILowerWWMCopiesLegacy::runOnMachineFunction (MachineFunction &MF) {
109
+ auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
110
+ auto *LIS = LISWrapper ? &LISWrapper->getLIS () : nullptr ;
111
+
112
+ auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
113
+ auto *Indexes = SIWrapper ? &SIWrapper->getSI () : nullptr ;
114
+
115
+ auto *VRMWrapper = getAnalysisIfAvailable<VirtRegMapWrapperLegacy>();
116
+ auto *VRM = VRMWrapper ? &VRMWrapper->getVRM () : nullptr ;
117
+
118
+ SILowerWWMCopies Impl (LIS, Indexes, VRM);
119
+ return Impl.run (MF);
120
+ }
121
+
122
+ PreservedAnalyses
123
+ SILowerWWMCopiesPass::run (MachineFunction &MF,
124
+ MachineFunctionAnalysisManager &MFAM) {
125
+ auto *LIS = MFAM.getCachedResult <LiveIntervalsAnalysis>(MF);
126
+ auto *Indexes = MFAM.getCachedResult <SlotIndexesAnalysis>(MF);
127
+ auto *VRM = MFAM.getCachedResult <VirtRegMapAnalysis>(MF);
128
+
129
+ SILowerWWMCopies Impl (LIS, Indexes, VRM);
130
+ Impl.run (MF);
131
+ return PreservedAnalyses::all ();
132
+ }
133
+
134
+ bool SILowerWWMCopies::run (MachineFunction &MF) {
100
135
const GCNSubtarget &ST = MF.getSubtarget <GCNSubtarget>();
101
136
const SIInstrInfo *TII = ST.getInstrInfo ();
102
137
103
138
MFI = MF.getInfo <SIMachineFunctionInfo>();
104
- auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
105
- LIS = LISWrapper ? &LISWrapper->getLIS () : nullptr ;
106
- auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
107
- Indexes = SIWrapper ? &SIWrapper->getSI () : nullptr ;
108
- auto *VRMWrapper = getAnalysisIfAvailable<VirtRegMapWrapperLegacy>();
109
- VRM = VRMWrapper ? &VRMWrapper->getVRM () : nullptr ;
110
139
TRI = ST.getRegisterInfo ();
111
140
MRI = &MF.getRegInfo ();
112
141
0 commit comments