71
71
//
72
72
// ===----------------------------------------------------------------------===//
73
73
74
+ #include " SIOptimizeVGPRLiveRange.h"
74
75
#include " AMDGPU.h"
75
76
#include " GCNSubtarget.h"
76
77
#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -86,7 +87,7 @@ using namespace llvm;
86
87
87
88
namespace {
88
89
89
- class SIOptimizeVGPRLiveRange : public MachineFunctionPass {
90
+ class SIOptimizeVGPRLiveRange {
90
91
private:
91
92
const SIRegisterInfo *TRI = nullptr ;
92
93
const SIInstrInfo *TII = nullptr ;
@@ -96,7 +97,10 @@ class SIOptimizeVGPRLiveRange : public MachineFunctionPass {
96
97
MachineRegisterInfo *MRI = nullptr ;
97
98
98
99
public:
99
- static char ID;
100
+ SIOptimizeVGPRLiveRange (LiveVariables *LV, MachineDominatorTree *MDT,
101
+ MachineLoopInfo *Loops)
102
+ : LV(LV), MDT(MDT), Loops(Loops) {}
103
+ bool run (MachineFunction &MF);
100
104
101
105
MachineBasicBlock *getElseTarget (MachineBasicBlock *MBB) const ;
102
106
@@ -136,8 +140,13 @@ class SIOptimizeVGPRLiveRange : public MachineFunctionPass {
136
140
Register Reg, MachineBasicBlock *LoopHeader,
137
141
SmallSetVector<MachineBasicBlock *, 2 > &LoopBlocks,
138
142
SmallVectorImpl<MachineInstr *> &Instructions) const ;
143
+ };
139
144
140
- SIOptimizeVGPRLiveRange () : MachineFunctionPass(ID) {}
145
+ class SIOptimizeVGPRLiveRangeLegacy : public MachineFunctionPass {
146
+ public:
147
+ static char ID;
148
+
149
+ SIOptimizeVGPRLiveRangeLegacy () : MachineFunctionPass(ID) {}
141
150
142
151
bool runOnMachineFunction (MachineFunction &MF) override ;
143
152
@@ -611,35 +620,59 @@ void SIOptimizeVGPRLiveRange::optimizeWaterfallLiveRange(
611
620
}
612
621
}
613
622
614
- char SIOptimizeVGPRLiveRange ::ID = 0 ;
623
+ char SIOptimizeVGPRLiveRangeLegacy ::ID = 0 ;
615
624
616
- INITIALIZE_PASS_BEGIN (SIOptimizeVGPRLiveRange , DEBUG_TYPE,
625
+ INITIALIZE_PASS_BEGIN (SIOptimizeVGPRLiveRangeLegacy , DEBUG_TYPE,
617
626
" SI Optimize VGPR LiveRange" , false , false )
618
627
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
619
628
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
620
629
INITIALIZE_PASS_DEPENDENCY(LiveVariablesWrapperPass)
621
- INITIALIZE_PASS_END(SIOptimizeVGPRLiveRange , DEBUG_TYPE,
630
+ INITIALIZE_PASS_END(SIOptimizeVGPRLiveRangeLegacy , DEBUG_TYPE,
622
631
" SI Optimize VGPR LiveRange" , false , false )
623
632
624
- char &llvm::SIOptimizeVGPRLiveRangeID = SIOptimizeVGPRLiveRange::ID;
633
+ char &llvm::SIOptimizeVGPRLiveRangeLegacyID = SIOptimizeVGPRLiveRangeLegacy::ID;
634
+
635
+ FunctionPass *llvm::createSIOptimizeVGPRLiveRangeLegacyPass () {
636
+ return new SIOptimizeVGPRLiveRangeLegacy ();
637
+ }
638
+
639
+ bool SIOptimizeVGPRLiveRangeLegacy::runOnMachineFunction (MachineFunction &MF) {
640
+ if (skipFunction (MF.getFunction ()))
641
+ return false ;
625
642
626
- FunctionPass *llvm::createSIOptimizeVGPRLiveRangePass () {
627
- return new SIOptimizeVGPRLiveRange ();
643
+ LiveVariables *LV = &getAnalysis<LiveVariablesWrapperPass>().getLV ();
644
+ MachineDominatorTree *MDT =
645
+ &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree ();
646
+ MachineLoopInfo *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI ();
647
+ return SIOptimizeVGPRLiveRange (LV, MDT, Loops).run (MF);
628
648
}
629
649
630
- bool SIOptimizeVGPRLiveRange::runOnMachineFunction (MachineFunction &MF) {
650
+ PreservedAnalyses
651
+ SIOptimizeVGPRLiveRangePass::run (MachineFunction &MF,
652
+ MachineFunctionAnalysisManager &MFAM) {
653
+ MFPropsModifier _ (*this , MF);
654
+ LiveVariables *LV = &MFAM.getResult <LiveVariablesAnalysis>(MF);
655
+ MachineDominatorTree *MDT = &MFAM.getResult <MachineDominatorTreeAnalysis>(MF);
656
+ MachineLoopInfo *Loops = &MFAM.getResult <MachineLoopAnalysis>(MF);
657
+
658
+ bool Changed = SIOptimizeVGPRLiveRange (LV, MDT, Loops).run (MF);
659
+ if (!Changed)
660
+ return PreservedAnalyses::all ();
661
+
662
+ auto PA = getMachineFunctionPassPreservedAnalyses ();
663
+ PA.preserve <LiveVariablesAnalysis>();
664
+ PA.preserve <DominatorTreeAnalysis>();
665
+ PA.preserve <MachineLoopAnalysis>();
666
+ PA.preserveSet <CFGAnalyses>();
667
+ return PA;
668
+ }
631
669
670
+ bool SIOptimizeVGPRLiveRange::run (MachineFunction &MF) {
632
671
const GCNSubtarget &ST = MF.getSubtarget <GCNSubtarget>();
633
672
TII = ST.getInstrInfo ();
634
673
TRI = &TII->getRegisterInfo ();
635
- MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree ();
636
- Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI ();
637
- LV = &getAnalysis<LiveVariablesWrapperPass>().getLV ();
638
674
MRI = &MF.getRegInfo ();
639
675
640
- if (skipFunction (MF.getFunction ()))
641
- return false ;
642
-
643
676
bool MadeChange = false ;
644
677
645
678
// TODO: we need to think about the order of visiting the blocks to get
0 commit comments