47
47
//
48
48
// ===----------------------------------------------------------------------===//
49
49
50
+ #include " llvm/CodeGen/ShrinkWrap.h"
50
51
#include " llvm/ADT/BitVector.h"
51
52
#include " llvm/ADT/PostOrderIterator.h"
52
53
#include " llvm/ADT/SetVector.h"
@@ -110,7 +111,7 @@ namespace {
110
111
// / does not rely on expensive data-flow analysis. Instead we use the
111
112
// / dominance properties and loop information to decide which point
112
113
// / are safe for such insertion.
113
- class ShrinkWrap : public MachineFunctionPass {
114
+ class ShrinkWrapImpl {
114
115
// / Hold callee-saved information.
115
116
RegisterClassInfo RCI;
116
117
MachineDominatorTree *MDT = nullptr ;
@@ -224,13 +225,8 @@ class ShrinkWrap : public MachineFunctionPass {
224
225
// / Initialize the pass for \p MF.
225
226
void init (MachineFunction &MF) {
226
227
RCI.runOnMachineFunction (MF);
227
- MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree ();
228
- MPDT = &getAnalysis<MachinePostDominatorTreeWrapperPass>().getPostDomTree ();
229
228
Save = nullptr ;
230
229
Restore = nullptr ;
231
- MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI ();
232
- MLI = &getAnalysis<MachineLoopInfoWrapperPass>().getLI ();
233
- ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE ();
234
230
EntryFreq = MBFI->getEntryFreq ();
235
231
const TargetSubtargetInfo &Subtarget = MF.getSubtarget ();
236
232
const TargetInstrInfo &TII = *Subtarget.getInstrInfo ();
@@ -248,14 +244,24 @@ class ShrinkWrap : public MachineFunctionPass {
248
244
// / shrink-wrapping.
249
245
bool ArePointsInteresting () const { return Save != Entry && Save && Restore; }
250
246
247
+ public:
248
+ ShrinkWrapImpl (MachineDominatorTree *MDT, MachinePostDominatorTree *MPDT,
249
+ MachineBlockFrequencyInfo *MBFI, MachineLoopInfo *MLI,
250
+ MachineOptimizationRemarkEmitter *ORE)
251
+ : MDT(MDT), MPDT(MPDT), MBFI(MBFI), MLI(MLI), ORE(ORE) {}
252
+
251
253
// / Check if shrink wrapping is enabled for this target and function.
252
254
static bool isShrinkWrapEnabled (const MachineFunction &MF);
253
255
256
+ bool run (MachineFunction &MF);
257
+ };
258
+
259
+ class ShrinkWrapLegacy : public MachineFunctionPass {
254
260
public:
255
261
static char ID;
256
262
257
- ShrinkWrap () : MachineFunctionPass(ID) {
258
- initializeShrinkWrapPass (*PassRegistry::getPassRegistry ());
263
+ ShrinkWrapLegacy () : MachineFunctionPass(ID) {
264
+ initializeShrinkWrapLegacyPass (*PassRegistry::getPassRegistry ());
259
265
}
260
266
261
267
void getAnalysisUsage (AnalysisUsage &AU) const override {
@@ -282,20 +288,22 @@ class ShrinkWrap : public MachineFunctionPass {
282
288
283
289
} // end anonymous namespace
284
290
285
- char ShrinkWrap ::ID = 0 ;
291
+ char ShrinkWrapLegacy ::ID = 0 ;
286
292
287
- char &llvm::ShrinkWrapID = ShrinkWrap ::ID;
293
+ char &llvm::ShrinkWrapID = ShrinkWrapLegacy ::ID;
288
294
289
- INITIALIZE_PASS_BEGIN (ShrinkWrap, DEBUG_TYPE, " Shrink Wrap Pass" , false , false )
295
+ INITIALIZE_PASS_BEGIN (ShrinkWrapLegacy, DEBUG_TYPE, " Shrink Wrap Pass" , false ,
296
+ false )
290
297
INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfoWrapperPass)
291
298
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
292
299
INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTreeWrapperPass)
293
300
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
294
301
INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
295
- INITIALIZE_PASS_END(ShrinkWrap, DEBUG_TYPE, " Shrink Wrap Pass" , false , false )
302
+ INITIALIZE_PASS_END(ShrinkWrapLegacy, DEBUG_TYPE, " Shrink Wrap Pass" , false ,
303
+ false )
296
304
297
- bool ShrinkWrap ::useOrDefCSROrFI(const MachineInstr &MI, RegScavenger *RS,
298
- bool StackAddressUsed) const {
305
+ bool ShrinkWrapImpl ::useOrDefCSROrFI(const MachineInstr &MI, RegScavenger *RS,
306
+ bool StackAddressUsed) const {
299
307
// / Check if \p Op is known to access an address not on the function's stack .
300
308
// / At the moment, accesses where the underlying object is a global, function
301
309
// / argument, or jump table are considered non-stack accesses. Note that the
@@ -549,7 +557,7 @@ static void rollbackRestoreSplit(MachineFunction &MF, MachineBasicBlock *NMBB,
549
557
// A block is deemed fit for restore point split iff there exist
550
558
// 1. DirtyPreds - preds of CurRestore reachable from use or def of CSR/FI
551
559
// 2. CleanPreds - preds of CurRestore that arent DirtyPreds
552
- bool ShrinkWrap ::checkIfRestoreSplittable (
560
+ bool ShrinkWrapImpl ::checkIfRestoreSplittable (
553
561
const MachineBasicBlock *CurRestore,
554
562
const DenseSet<const MachineBasicBlock *> &ReachableByDirty,
555
563
SmallVectorImpl<MachineBasicBlock *> &DirtyPreds,
@@ -572,8 +580,8 @@ bool ShrinkWrap::checkIfRestoreSplittable(
572
580
return !(CleanPreds.empty () || DirtyPreds.empty ());
573
581
}
574
582
575
- bool ShrinkWrap ::postShrinkWrapping (bool HasCandidate, MachineFunction &MF,
576
- RegScavenger *RS) {
583
+ bool ShrinkWrapImpl ::postShrinkWrapping (bool HasCandidate, MachineFunction &MF,
584
+ RegScavenger *RS) {
577
585
if (!EnablePostShrinkWrapOpt)
578
586
return false ;
579
587
@@ -679,8 +687,8 @@ bool ShrinkWrap::postShrinkWrapping(bool HasCandidate, MachineFunction &MF,
679
687
return true ;
680
688
}
681
689
682
- void ShrinkWrap ::updateSaveRestorePoints (MachineBasicBlock &MBB,
683
- RegScavenger *RS) {
690
+ void ShrinkWrapImpl ::updateSaveRestorePoints (MachineBasicBlock &MBB,
691
+ RegScavenger *RS) {
684
692
// Get rid of the easy cases first.
685
693
if (!Save)
686
694
Save = &MBB;
@@ -810,7 +818,7 @@ static bool giveUpWithRemarks(MachineOptimizationRemarkEmitter *ORE,
810
818
return false ;
811
819
}
812
820
813
- bool ShrinkWrap ::performShrinkWrapping (
821
+ bool ShrinkWrapImpl ::performShrinkWrapping (
814
822
const ReversePostOrderTraversal<MachineBasicBlock *> &RPOT,
815
823
RegScavenger *RS) {
816
824
for (MachineBasicBlock *MBB : RPOT) {
@@ -919,10 +927,7 @@ bool ShrinkWrap::performShrinkWrapping(
919
927
return true ;
920
928
}
921
929
922
- bool ShrinkWrap::runOnMachineFunction (MachineFunction &MF) {
923
- if (skipFunction (MF.getFunction ()) || MF.empty () || !isShrinkWrapEnabled (MF))
924
- return false ;
925
-
930
+ bool ShrinkWrapImpl::run (MachineFunction &MF) {
926
931
LLVM_DEBUG (dbgs () << " **** Analysing " << MF.getName () << ' \n ' );
927
932
928
933
init (MF);
@@ -969,7 +974,44 @@ bool ShrinkWrap::runOnMachineFunction(MachineFunction &MF) {
969
974
return Changed;
970
975
}
971
976
972
- bool ShrinkWrap::isShrinkWrapEnabled (const MachineFunction &MF) {
977
+ bool ShrinkWrapLegacy::runOnMachineFunction (MachineFunction &MF) {
978
+ if (skipFunction (MF.getFunction ()) || MF.empty () ||
979
+ !ShrinkWrapImpl::isShrinkWrapEnabled (MF))
980
+ return false ;
981
+
982
+ MachineDominatorTree *MDT =
983
+ &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree ();
984
+ MachinePostDominatorTree *MPDT =
985
+ &getAnalysis<MachinePostDominatorTreeWrapperPass>().getPostDomTree ();
986
+ MachineBlockFrequencyInfo *MBFI =
987
+ &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI ();
988
+ MachineLoopInfo *MLI = &getAnalysis<MachineLoopInfoWrapperPass>().getLI ();
989
+ MachineOptimizationRemarkEmitter *ORE =
990
+ &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE ();
991
+
992
+ return ShrinkWrapImpl (MDT, MPDT, MBFI, MLI, ORE).run (MF);
993
+ }
994
+
995
+ PreservedAnalyses ShrinkWrapPass::run (MachineFunction &MF,
996
+ MachineFunctionAnalysisManager &MFAM) {
997
+ MFPropsModifier _ (*this , MF);
998
+ if (MF.empty () || !ShrinkWrapImpl::isShrinkWrapEnabled (MF))
999
+ return PreservedAnalyses::all ();
1000
+
1001
+ MachineDominatorTree &MDT = MFAM.getResult <MachineDominatorTreeAnalysis>(MF);
1002
+ MachinePostDominatorTree &MPDT =
1003
+ MFAM.getResult <MachinePostDominatorTreeAnalysis>(MF);
1004
+ MachineBlockFrequencyInfo &MBFI =
1005
+ MFAM.getResult <MachineBlockFrequencyAnalysis>(MF);
1006
+ MachineLoopInfo &MLI = MFAM.getResult <MachineLoopAnalysis>(MF);
1007
+ MachineOptimizationRemarkEmitter &ORE =
1008
+ MFAM.getResult <MachineOptimizationRemarkEmitterAnalysis>(MF);
1009
+
1010
+ ShrinkWrapImpl (&MDT, &MPDT, &MBFI, &MLI, &ORE).run (MF);
1011
+ return PreservedAnalyses::all ();
1012
+ }
1013
+
1014
+ bool ShrinkWrapImpl::isShrinkWrapEnabled (const MachineFunction &MF) {
973
1015
const TargetFrameLowering *TFI = MF.getSubtarget ().getFrameLowering ();
974
1016
975
1017
switch (EnableShrinkWrapOpt) {
0 commit comments