1313//
1414// ===----------------------------------------------------------------------===//
1515
16+ #include " llvm/CodeGen/MachineLateInstrsCleanup.h"
1617#include " llvm/ADT/BitVector.h"
1718#include " llvm/ADT/PostOrderIterator.h"
1819#include " llvm/ADT/Statistic.h"
@@ -36,7 +37,7 @@ STATISTIC(NumRemoved, "Number of redundant instructions removed.");
3637
3738namespace {
3839
39- class MachineLateInstrsCleanup : public MachineFunctionPass {
40+ class MachineLateInstrsCleanup {
4041 const TargetRegisterInfo *TRI = nullptr ;
4142 const TargetInstrInfo *TII = nullptr ;
4243
@@ -59,11 +60,17 @@ class MachineLateInstrsCleanup : public MachineFunctionPass {
5960 void clearKillsForDef (Register Reg, MachineBasicBlock *MBB,
6061 BitVector &VisitedPreds);
6162
63+ public:
64+ bool run (MachineFunction &MF);
65+ };
66+
67+ class MachineLateInstrsCleanupLegacy : public MachineFunctionPass {
6268public:
6369 static char ID; // Pass identification, replacement for typeid
6470
65- MachineLateInstrsCleanup () : MachineFunctionPass(ID) {
66- initializeMachineLateInstrsCleanupPass (*PassRegistry::getPassRegistry ());
71+ MachineLateInstrsCleanupLegacy () : MachineFunctionPass(ID) {
72+ initializeMachineLateInstrsCleanupLegacyPass (
73+ *PassRegistry::getPassRegistry ());
6774 }
6875
6976 void getAnalysisUsage (AnalysisUsage &AU) const override {
@@ -81,17 +88,32 @@ class MachineLateInstrsCleanup : public MachineFunctionPass {
8188
8289} // end anonymous namespace
8390
84- char MachineLateInstrsCleanup ::ID = 0 ;
91+ char MachineLateInstrsCleanupLegacy ::ID = 0 ;
8592
86- char &llvm::MachineLateInstrsCleanupID = MachineLateInstrsCleanup ::ID;
93+ char &llvm::MachineLateInstrsCleanupID = MachineLateInstrsCleanupLegacy ::ID;
8794
88- INITIALIZE_PASS (MachineLateInstrsCleanup , DEBUG_TYPE,
95+ INITIALIZE_PASS (MachineLateInstrsCleanupLegacy , DEBUG_TYPE,
8996 " Machine Late Instructions Cleanup Pass" , false , false )
9097
91- bool MachineLateInstrsCleanup ::runOnMachineFunction(MachineFunction &MF) {
98+ bool MachineLateInstrsCleanupLegacy ::runOnMachineFunction(MachineFunction &MF) {
9299 if (skipFunction (MF.getFunction ()))
93100 return false ;
94101
102+ return MachineLateInstrsCleanup ().run (MF);
103+ }
104+
105+ PreservedAnalyses
106+ MachineLateInstrsCleanupPass::run (MachineFunction &MF,
107+ MachineFunctionAnalysisManager &MFAM) {
108+ MFPropsModifier _ (*this , MF);
109+ if (!MachineLateInstrsCleanup ().run (MF))
110+ return PreservedAnalyses::all ();
111+ auto PA = getMachineFunctionPassPreservedAnalyses ();
112+ PA.preserveSet <CFGAnalyses>();
113+ return PA;
114+ }
115+
116+ bool MachineLateInstrsCleanup::run (MachineFunction &MF) {
95117 TRI = MF.getSubtarget ().getRegisterInfo ();
96118 TII = MF.getSubtarget ().getInstrInfo ();
97119
0 commit comments