1515//
1616// ===----------------------------------------------------------------------===//
1717
18+ #include " SILowerSGPRSpills.h"
1819#include " AMDGPU.h"
1920#include " GCNSubtarget.h"
2021#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -32,7 +33,7 @@ using MBBVector = SmallVector<MachineBasicBlock *, 4>;
3233
3334namespace {
3435
35- class SILowerSGPRSpills : public MachineFunctionPass {
36+ class SILowerSGPRSpills {
3637private:
3738 const SIRegisterInfo *TRI = nullptr ;
3839 const SIInstrInfo *TII = nullptr ;
@@ -45,14 +46,20 @@ class SILowerSGPRSpills : public MachineFunctionPass {
4546 MBBVector RestoreBlocks;
4647
4748public:
48- static char ID;
49-
50- SILowerSGPRSpills () : MachineFunctionPass(ID) {}
51-
49+ SILowerSGPRSpills (LiveIntervals *LIS, SlotIndexes *Indexes)
50+ : LIS(LIS), Indexes(Indexes) {}
51+ bool run (MachineFunction &MF);
5252 void calculateSaveRestoreBlocks (MachineFunction &MF);
5353 bool spillCalleeSavedRegs (MachineFunction &MF,
5454 SmallVectorImpl<int > &CalleeSavedFIs);
5555 void extendWWMVirtRegLiveness (MachineFunction &MF, LiveIntervals *LIS);
56+ };
57+
58+ class SILowerSGPRSpillsLegacy : public MachineFunctionPass {
59+ public:
60+ static char ID;
61+
62+ SILowerSGPRSpillsLegacy () : MachineFunctionPass(ID) {}
5663
5764 bool runOnMachineFunction (MachineFunction &MF) override ;
5865
@@ -71,16 +78,16 @@ class SILowerSGPRSpills : public MachineFunctionPass {
7178
7279} // end anonymous namespace
7380
74- char SILowerSGPRSpills ::ID = 0 ;
81+ char SILowerSGPRSpillsLegacy ::ID = 0 ;
7582
76- INITIALIZE_PASS_BEGIN (SILowerSGPRSpills , DEBUG_TYPE,
83+ INITIALIZE_PASS_BEGIN (SILowerSGPRSpillsLegacy , DEBUG_TYPE,
7784 " SI lower SGPR spill instructions" , false , false )
7885INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
7986INITIALIZE_PASS_DEPENDENCY(VirtRegMap)
80- INITIALIZE_PASS_END(SILowerSGPRSpills , DEBUG_TYPE,
87+ INITIALIZE_PASS_END(SILowerSGPRSpillsLegacy , DEBUG_TYPE,
8188 " SI lower SGPR spill instructions" , false , false )
8289
83- char &llvm::SILowerSGPRSpillsID = SILowerSGPRSpills ::ID;
90+ char &llvm::SILowerSGPRSpillsLegacyID = SILowerSGPRSpillsLegacy ::ID;
8491
8592// / Insert spill code for the callee-saved registers used in the function.
8693static void insertCSRSaves (MachineBasicBlock &SaveBlock,
@@ -306,16 +313,19 @@ void SILowerSGPRSpills::extendWWMVirtRegLiveness(MachineFunction &MF,
306313 }
307314}
308315
309- bool SILowerSGPRSpills::runOnMachineFunction (MachineFunction &MF) {
316+ bool SILowerSGPRSpillsLegacy::runOnMachineFunction (MachineFunction &MF) {
317+ auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
318+ LiveIntervals *LIS = LISWrapper ? &LISWrapper->getLIS () : nullptr ;
319+ auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
320+ SlotIndexes *Indexes = SIWrapper ? &SIWrapper->getSI () : nullptr ;
321+ return SILowerSGPRSpills (LIS, Indexes).run (MF);
322+ }
323+
324+ bool SILowerSGPRSpills::run (MachineFunction &MF) {
310325 const GCNSubtarget &ST = MF.getSubtarget <GCNSubtarget>();
311326 TII = ST.getInstrInfo ();
312327 TRI = &TII->getRegisterInfo ();
313328
314- auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
315- LIS = LISWrapper ? &LISWrapper->getLIS () : nullptr ;
316- auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
317- Indexes = SIWrapper ? &SIWrapper->getSI () : nullptr ;
318-
319329 assert (SaveBlocks.empty () && RestoreBlocks.empty ());
320330
321331 // First, expose any CSR SGPR spills. This is mostly the same as what PEI
@@ -446,3 +456,13 @@ bool SILowerSGPRSpills::runOnMachineFunction(MachineFunction &MF) {
446456
447457 return MadeChange;
448458}
459+
460+ PreservedAnalyses
461+ SILowerSGPRSpillsPass::run (MachineFunction &MF,
462+ MachineFunctionAnalysisManager &MFAM) {
463+ MFPropsModifier _ (*this , MF);
464+ auto *LIS = MFAM.getCachedResult <LiveIntervalsAnalysis>(MF);
465+ auto *Indexes = MFAM.getCachedResult <SlotIndexesAnalysis>(MF);
466+ SILowerSGPRSpills (LIS, Indexes).run (MF);
467+ return PreservedAnalyses::all ();
468+ }
0 commit comments