4848// / %exec = S_OR_B64 %exec, %sgpr0 // Re-enable saved exec mask bits
4949// ===----------------------------------------------------------------------===//
5050
51+ #include " SILowerControlFlow.h"
5152#include " AMDGPU.h"
5253#include " GCNSubtarget.h"
5354#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -68,7 +69,7 @@ RemoveRedundantEndcf("amdgpu-remove-redundant-endcf",
6869
6970namespace {
7071
71- class SILowerControlFlow : public MachineFunctionPass {
72+ class SILowerControlFlow {
7273private:
7374 const SIRegisterInfo *TRI = nullptr ;
7475 const SIInstrInfo *TII = nullptr ;
@@ -135,10 +136,18 @@ class SILowerControlFlow : public MachineFunctionPass {
135136 // Remove redundant SI_END_CF instructions.
136137 void optimizeEndCf ();
137138
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 {
138147public:
139148 static char ID;
140149
141- SILowerControlFlow () : MachineFunctionPass(ID) {}
150+ SILowerControlFlowLegacy () : MachineFunctionPass(ID) {}
142151
143152 bool runOnMachineFunction (MachineFunction &MF) override ;
144153
@@ -159,10 +168,10 @@ class SILowerControlFlow : public MachineFunctionPass {
159168
160169} // end anonymous namespace
161170
162- char SILowerControlFlow ::ID = 0 ;
171+ char SILowerControlFlowLegacy ::ID = 0 ;
163172
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 )
166175
167176static void setImpSCCDefDead(MachineInstr &MI, bool IsDead) {
168177 MachineOperand &ImpDefSCC = MI.getOperand (3 );
@@ -171,7 +180,7 @@ static void setImpSCCDefDead(MachineInstr &MI, bool IsDead) {
171180 ImpDefSCC.setIsDead (IsDead);
172181}
173182
174- char &llvm::SILowerControlFlowID = SILowerControlFlow ::ID;
183+ char &llvm::SILowerControlFlowLegacyID = SILowerControlFlowLegacy ::ID;
175184
176185bool SILowerControlFlow::hasKill (const MachineBasicBlock *Begin,
177186 const MachineBasicBlock *End) {
@@ -753,21 +762,13 @@ bool SILowerControlFlow::removeMBBifRedundant(MachineBasicBlock &MBB) {
753762 return true ;
754763}
755764
756- bool SILowerControlFlow::runOnMachineFunction (MachineFunction &MF) {
765+ bool SILowerControlFlow::run (MachineFunction &MF) {
757766 const GCNSubtarget &ST = MF.getSubtarget <GCNSubtarget>();
758767 TII = ST.getInstrInfo ();
759768 TRI = &TII->getRegisterInfo ();
760769 EnableOptimizeEndCf = RemoveRedundantEndcf &&
761770 MF.getTarget ().getOptLevel () > CodeGenOptLevel::None;
762771
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 ;
771772 MRI = &MF.getRegInfo ();
772773 BoolRC = TRI->getBoolRC ();
773774
@@ -864,3 +865,35 @@ bool SILowerControlFlow::runOnMachineFunction(MachineFunction &MF) {
864865
865866 return Changed;
866867}
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