4848//
4949// ===----------------------------------------------------------------------===//
5050
51+ #include " llvm/CodeGen/MachineCopyPropagation.h"
5152#include " llvm/ADT/DenseMap.h"
5253#include " llvm/ADT/STLExtras.h"
5354#include " llvm/ADT/SetVector.h"
@@ -449,7 +450,7 @@ class CopyTracker {
449450 }
450451};
451452
452- class MachineCopyPropagation : public MachineFunctionPass {
453+ class MachineCopyPropagation {
453454 const TargetRegisterInfo *TRI = nullptr ;
454455 const TargetInstrInfo *TII = nullptr ;
455456 const MachineRegisterInfo *MRI = nullptr ;
@@ -461,21 +462,9 @@ class MachineCopyPropagation : public MachineFunctionPass {
461462 static char ID; // Pass identification, replacement for typeid
462463
463464 MachineCopyPropagation (bool CopyInstr = false )
464- : MachineFunctionPass(ID), UseCopyInstr(CopyInstr || MCPUseCopyInstr) {
465- initializeMachineCopyPropagationPass (*PassRegistry::getPassRegistry ());
466- }
465+ : UseCopyInstr(CopyInstr || MCPUseCopyInstr) {}
467466
468- void getAnalysisUsage (AnalysisUsage &AU) const override {
469- AU.setPreservesCFG ();
470- MachineFunctionPass::getAnalysisUsage (AU);
471- }
472-
473- bool runOnMachineFunction (MachineFunction &MF) override ;
474-
475- MachineFunctionProperties getRequiredProperties () const override {
476- return MachineFunctionProperties ().set (
477- MachineFunctionProperties::Property::NoVRegs);
478- }
467+ bool run (MachineFunction &MF);
479468
480469private:
481470 typedef enum { DebugUse = false , RegularUse = true } DebugType;
@@ -510,13 +499,35 @@ class MachineCopyPropagation : public MachineFunctionPass {
510499 bool Changed = false ;
511500};
512501
502+ class MachineCopyPropagationLegacy : public MachineFunctionPass {
503+ bool UseCopyInstr;
504+
505+ public:
506+ static char ID; // pass identification
507+
508+ MachineCopyPropagationLegacy (bool UseCopyInstr = false )
509+ : MachineFunctionPass(ID), UseCopyInstr(UseCopyInstr) {}
510+
511+ void getAnalysisUsage (AnalysisUsage &AU) const override {
512+ AU.setPreservesCFG ();
513+ MachineFunctionPass::getAnalysisUsage (AU);
514+ }
515+
516+ bool runOnMachineFunction (MachineFunction &MF) override ;
517+
518+ MachineFunctionProperties getRequiredProperties () const override {
519+ return MachineFunctionProperties ().set (
520+ MachineFunctionProperties::Property::NoVRegs);
521+ }
522+ };
523+
513524} // end anonymous namespace
514525
515- char MachineCopyPropagation ::ID = 0 ;
526+ char MachineCopyPropagationLegacy ::ID = 0 ;
516527
517- char &llvm::MachineCopyPropagationID = MachineCopyPropagation ::ID;
528+ char &llvm::MachineCopyPropagationID = MachineCopyPropagationLegacy ::ID;
518529
519- INITIALIZE_PASS (MachineCopyPropagation , DEBUG_TYPE,
530+ INITIALIZE_PASS (MachineCopyPropagationLegacy , DEBUG_TYPE,
520531 " Machine Copy Propagation Pass" , false , false )
521532
522533void MachineCopyPropagation::ReadRegister(MCRegister Reg, MachineInstr &Reader,
@@ -1563,10 +1574,25 @@ void MachineCopyPropagation::EliminateSpillageCopies(MachineBasicBlock &MBB) {
15631574 Tracker.clear ();
15641575}
15651576
1566- bool MachineCopyPropagation ::runOnMachineFunction (MachineFunction &MF) {
1577+ bool MachineCopyPropagationLegacy ::runOnMachineFunction (MachineFunction &MF) {
15671578 if (skipFunction (MF.getFunction ()))
15681579 return false ;
15691580
1581+ return MachineCopyPropagation (UseCopyInstr).run (MF);
1582+ }
1583+
1584+ PreservedAnalyses
1585+ MachineCopyPropagationPass::run (MachineFunction &MF,
1586+ MachineFunctionAnalysisManager &) {
1587+ MFPropsModifier _ (*this , MF);
1588+ if (!MachineCopyPropagation (UseCopyInstr).run (MF))
1589+ return PreservedAnalyses::all ();
1590+ auto PA = getMachineFunctionPassPreservedAnalyses ();
1591+ PA.preserveSet <CFGAnalyses>();
1592+ return PA;
1593+ }
1594+
1595+ bool MachineCopyPropagation::run (MachineFunction &MF) {
15701596 bool isSpillageCopyElimEnabled = false ;
15711597 switch (EnableSpillageCopyElimination) {
15721598 case cl::BOU_UNSET:
@@ -1599,5 +1625,5 @@ bool MachineCopyPropagation::runOnMachineFunction(MachineFunction &MF) {
15991625
16001626MachineFunctionPass *
16011627llvm::createMachineCopyPropagationPass (bool UseCopyInstr = false ) {
1602- return new MachineCopyPropagation (UseCopyInstr);
1628+ return new MachineCopyPropagationLegacy (UseCopyInstr);
16031629}
0 commit comments