48
48
// / %exec = S_OR_B64 %exec, %sgpr0 // Re-enable saved exec mask bits
49
49
// ===----------------------------------------------------------------------===//
50
50
51
+ #include " SILowerControlFlow.h"
51
52
#include " AMDGPU.h"
52
53
#include " GCNSubtarget.h"
53
54
#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -68,7 +69,7 @@ RemoveRedundantEndcf("amdgpu-remove-redundant-endcf",
68
69
69
70
namespace {
70
71
71
- class SILowerControlFlow : public MachineFunctionPass {
72
+ class SILowerControlFlow {
72
73
private:
73
74
const SIRegisterInfo *TRI = nullptr ;
74
75
const SIInstrInfo *TII = nullptr ;
@@ -135,10 +136,18 @@ class SILowerControlFlow : public MachineFunctionPass {
135
136
// Remove redundant SI_END_CF instructions.
136
137
void optimizeEndCf ();
137
138
139
+ public:
140
+ SILowerControlFlow (LiveIntervals *LIS, LiveVariables *LV,
141
+ MachineDominatorTree *MDT)
142
+ : LIS(LIS), LV(LV), MDT(MDT) {}
143
+ bool run (MachineFunction &MF);
144
+ };
145
+
146
+ class SILowerControlFlowLegacy : public MachineFunctionPass {
138
147
public:
139
148
static char ID;
140
149
141
- SILowerControlFlow () : MachineFunctionPass(ID) {}
150
+ SILowerControlFlowLegacy () : MachineFunctionPass(ID) {}
142
151
143
152
bool runOnMachineFunction (MachineFunction &MF) override ;
144
153
@@ -159,10 +168,10 @@ class SILowerControlFlow : public MachineFunctionPass {
159
168
160
169
} // end anonymous namespace
161
170
162
- char SILowerControlFlow ::ID = 0 ;
171
+ char SILowerControlFlowLegacy ::ID = 0 ;
163
172
164
- INITIALIZE_PASS (SILowerControlFlow , DEBUG_TYPE,
165
- " SI lower control flow " , false , false )
173
+ INITIALIZE_PASS (SILowerControlFlowLegacy , DEBUG_TYPE, " SI lower control flow " ,
174
+ false , false )
166
175
167
176
static void setImpSCCDefDead(MachineInstr &MI, bool IsDead) {
168
177
MachineOperand &ImpDefSCC = MI.getOperand (3 );
@@ -171,7 +180,7 @@ static void setImpSCCDefDead(MachineInstr &MI, bool IsDead) {
171
180
ImpDefSCC.setIsDead (IsDead);
172
181
}
173
182
174
- char &llvm::SILowerControlFlowID = SILowerControlFlow ::ID;
183
+ char &llvm::SILowerControlFlowLegacyID = SILowerControlFlowLegacy ::ID;
175
184
176
185
bool SILowerControlFlow::hasKill (const MachineBasicBlock *Begin,
177
186
const MachineBasicBlock *End) {
@@ -753,21 +762,13 @@ bool SILowerControlFlow::removeMBBifRedundant(MachineBasicBlock &MBB) {
753
762
return true ;
754
763
}
755
764
756
- bool SILowerControlFlow::runOnMachineFunction (MachineFunction &MF) {
765
+ bool SILowerControlFlow::run (MachineFunction &MF) {
757
766
const GCNSubtarget &ST = MF.getSubtarget <GCNSubtarget>();
758
767
TII = ST.getInstrInfo ();
759
768
TRI = &TII->getRegisterInfo ();
760
769
EnableOptimizeEndCf = RemoveRedundantEndcf &&
761
770
MF.getTarget ().getOptLevel () > CodeGenOptLevel::None;
762
771
763
- // This doesn't actually need LiveIntervals, but we can preserve them.
764
- auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
765
- LIS = LISWrapper ? &LISWrapper->getLIS () : nullptr ;
766
- // This doesn't actually need LiveVariables, but we can preserve them.
767
- auto *LVWrapper = getAnalysisIfAvailable<LiveVariablesWrapperPass>();
768
- LV = LVWrapper ? &LVWrapper->getLV () : nullptr ;
769
- auto *MDTWrapper = getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
770
- MDT = MDTWrapper ? &MDTWrapper->getDomTree () : nullptr ;
771
772
MRI = &MF.getRegInfo ();
772
773
BoolRC = TRI->getBoolRC ();
773
774
@@ -864,3 +865,35 @@ bool SILowerControlFlow::runOnMachineFunction(MachineFunction &MF) {
864
865
865
866
return Changed;
866
867
}
868
+
869
+ bool SILowerControlFlowLegacy::runOnMachineFunction (MachineFunction &MF) {
870
+ // This doesn't actually need LiveIntervals, but we can preserve them.
871
+ auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
872
+ LiveIntervals *LIS = LISWrapper ? &LISWrapper->getLIS () : nullptr ;
873
+ // This doesn't actually need LiveVariables, but we can preserve them.
874
+ auto *LVWrapper = getAnalysisIfAvailable<LiveVariablesWrapperPass>();
875
+ LiveVariables *LV = LVWrapper ? &LVWrapper->getLV () : nullptr ;
876
+ auto *MDTWrapper = getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
877
+ MachineDominatorTree *MDT = MDTWrapper ? &MDTWrapper->getDomTree () : nullptr ;
878
+ return SILowerControlFlow (LIS, LV, MDT).run (MF);
879
+ }
880
+
881
+ PreservedAnalyses
882
+ SILowerControlFlowPass::run (MachineFunction &MF,
883
+ MachineFunctionAnalysisManager &MFAM) {
884
+ LiveIntervals *LIS = MFAM.getCachedResult <LiveIntervalsAnalysis>(MF);
885
+ LiveVariables *LV = MFAM.getCachedResult <LiveVariablesAnalysis>(MF);
886
+ MachineDominatorTree *MDT =
887
+ MFAM.getCachedResult <MachineDominatorTreeAnalysis>(MF);
888
+
889
+ bool Changed = SILowerControlFlow (LIS, LV, MDT).run (MF);
890
+ if (!Changed)
891
+ return PreservedAnalyses::all ();
892
+
893
+ auto PA = getMachineFunctionPassPreservedAnalyses ();
894
+ PA.preserve <MachineDominatorTreeAnalysis>();
895
+ PA.preserve <SlotIndexesAnalysis>();
896
+ PA.preserve <LiveIntervalsAnalysis>();
897
+ PA.preserve <LiveVariablesAnalysis>();
898
+ return PA;
899
+ }
0 commit comments