diff options
Diffstat (limited to 'llvm/lib/CodeGen/MachineCopyPropagation.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineCopyPropagation.cpp | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp index d44b064..460749a 100644 --- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp +++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp @@ -48,6 +48,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/CodeGen/MachineCopyPropagation.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" @@ -449,7 +450,7 @@ public: } }; -class MachineCopyPropagation : public MachineFunctionPass { +class MachineCopyPropagation { const TargetRegisterInfo *TRI = nullptr; const TargetInstrInfo *TII = nullptr; const MachineRegisterInfo *MRI = nullptr; @@ -458,24 +459,10 @@ class MachineCopyPropagation : public MachineFunctionPass { bool UseCopyInstr; public: - static char ID; // Pass identification, replacement for typeid - MachineCopyPropagation(bool CopyInstr = false) - : MachineFunctionPass(ID), UseCopyInstr(CopyInstr || MCPUseCopyInstr) { - initializeMachineCopyPropagationPass(*PassRegistry::getPassRegistry()); - } - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesCFG(); - MachineFunctionPass::getAnalysisUsage(AU); - } - - bool runOnMachineFunction(MachineFunction &MF) override; + : UseCopyInstr(CopyInstr || MCPUseCopyInstr) {} - MachineFunctionProperties getRequiredProperties() const override { - return MachineFunctionProperties().set( - MachineFunctionProperties::Property::NoVRegs); - } + bool run(MachineFunction &MF); private: typedef enum { DebugUse = false, RegularUse = true } DebugType; @@ -510,13 +497,35 @@ private: bool Changed = false; }; +class MachineCopyPropagationLegacy : public MachineFunctionPass { + bool UseCopyInstr; + +public: + static char ID; // pass identification + + MachineCopyPropagationLegacy(bool UseCopyInstr = false) + : MachineFunctionPass(ID), UseCopyInstr(UseCopyInstr) {} + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.setPreservesCFG(); + MachineFunctionPass::getAnalysisUsage(AU); + } + + bool runOnMachineFunction(MachineFunction &MF) override; + + MachineFunctionProperties getRequiredProperties() const override { + return MachineFunctionProperties().set( + MachineFunctionProperties::Property::NoVRegs); + } +}; + } // end anonymous namespace -char MachineCopyPropagation::ID = 0; +char MachineCopyPropagationLegacy::ID = 0; -char &llvm::MachineCopyPropagationID = MachineCopyPropagation::ID; +char &llvm::MachineCopyPropagationID = MachineCopyPropagationLegacy::ID; -INITIALIZE_PASS(MachineCopyPropagation, DEBUG_TYPE, +INITIALIZE_PASS(MachineCopyPropagationLegacy, DEBUG_TYPE, "Machine Copy Propagation Pass", false, false) void MachineCopyPropagation::ReadRegister(MCRegister Reg, MachineInstr &Reader, @@ -1563,10 +1572,25 @@ void MachineCopyPropagation::EliminateSpillageCopies(MachineBasicBlock &MBB) { Tracker.clear(); } -bool MachineCopyPropagation::runOnMachineFunction(MachineFunction &MF) { +bool MachineCopyPropagationLegacy::runOnMachineFunction(MachineFunction &MF) { if (skipFunction(MF.getFunction())) return false; + return MachineCopyPropagation(UseCopyInstr).run(MF); +} + +PreservedAnalyses +MachineCopyPropagationPass::run(MachineFunction &MF, + MachineFunctionAnalysisManager &) { + MFPropsModifier _(*this, MF); + if (!MachineCopyPropagation(UseCopyInstr).run(MF)) + return PreservedAnalyses::all(); + auto PA = getMachineFunctionPassPreservedAnalyses(); + PA.preserveSet<CFGAnalyses>(); + return PA; +} + +bool MachineCopyPropagation::run(MachineFunction &MF) { bool isSpillageCopyElimEnabled = false; switch (EnableSpillageCopyElimination) { case cl::BOU_UNSET: @@ -1599,5 +1623,5 @@ bool MachineCopyPropagation::runOnMachineFunction(MachineFunction &MF) { MachineFunctionPass * llvm::createMachineCopyPropagationPass(bool UseCopyInstr = false) { - return new MachineCopyPropagation(UseCopyInstr); + return new MachineCopyPropagationLegacy(UseCopyInstr); } |