1010//
1111// ===----------------------------------------------------------------------===//
1212
13+ #include " llvm/CodeGen/DeadMachineInstructionElim.h"
1314#include " llvm/ADT/PostOrderIterator.h"
1415#include " llvm/ADT/Statistic.h"
1516#include " llvm/CodeGen/LiveRegUnits.h"
@@ -28,37 +29,57 @@ using namespace llvm;
2829STATISTIC (NumDeletes, " Number of dead instructions deleted" );
2930
3031namespace {
31- class DeadMachineInstructionElim : public MachineFunctionPass {
32- bool runOnMachineFunction (MachineFunction &MF) override ;
32+ class DeadMachineInstructionElimImpl {
33+ const MachineRegisterInfo *MRI = nullptr ;
34+ const TargetInstrInfo *TII = nullptr ;
35+ LiveRegUnits LivePhysRegs;
3336
34- const MachineRegisterInfo *MRI = nullptr ;
35- const TargetInstrInfo *TII = nullptr ;
36- LiveRegUnits LivePhysRegs;
37+ public:
38+ bool runImpl (MachineFunction &MF);
3739
38- public:
39- static char ID; // Pass identification, replacement for typeid
40- DeadMachineInstructionElim () : MachineFunctionPass(ID) {
41- initializeDeadMachineInstructionElimPass (*PassRegistry::getPassRegistry ());
42- }
40+ private:
41+ bool isDead (const MachineInstr *MI) const ;
42+ bool eliminateDeadMI (MachineFunction &MF);
43+ };
4344
44- void getAnalysisUsage (AnalysisUsage &AU) const override {
45- AU.setPreservesCFG ();
46- MachineFunctionPass::getAnalysisUsage (AU);
47- }
45+ class DeadMachineInstructionElim : public MachineFunctionPass {
46+ public:
47+ static char ID; // Pass identification, replacement for typeid
4848
49- private:
50- bool isDead (const MachineInstr *MI) const ;
49+ DeadMachineInstructionElim () : MachineFunctionPass(ID) {
50+ initializeDeadMachineInstructionElimPass (*PassRegistry::getPassRegistry ());
51+ }
52+
53+ bool runOnMachineFunction (MachineFunction &MF) override {
54+ if (skipFunction (MF.getFunction ()))
55+ return false ;
56+ return DeadMachineInstructionElimImpl ().runImpl (MF);
57+ }
5158
52- bool eliminateDeadMI (MachineFunction &MF);
53- };
59+ void getAnalysisUsage (AnalysisUsage &AU) const override {
60+ AU.setPreservesCFG ();
61+ MachineFunctionPass::getAnalysisUsage (AU);
62+ }
63+ };
64+ } // namespace
65+
66+ PreservedAnalyses
67+ DeadMachineInstructionElimPass::run (MachineFunction &MF,
68+ MachineFunctionAnalysisManager &) {
69+ if (!DeadMachineInstructionElimImpl ().runImpl (MF))
70+ return PreservedAnalyses::all ();
71+ PreservedAnalyses PA;
72+ PA.preserveSet <CFGAnalyses>();
73+ return PA;
5474}
75+
5576char DeadMachineInstructionElim::ID = 0 ;
5677char &llvm::DeadMachineInstructionElimID = DeadMachineInstructionElim::ID;
5778
5879INITIALIZE_PASS (DeadMachineInstructionElim, DEBUG_TYPE,
5980 " Remove dead machine instructions" , false , false )
6081
61- bool DeadMachineInstructionElim ::isDead(const MachineInstr *MI) const {
82+ bool DeadMachineInstructionElimImpl ::isDead(const MachineInstr *MI) const {
6283 // Technically speaking inline asm without side effects and no defs can still
6384 // be deleted. But there is so much bad inline asm code out there, we should
6485 // let them be.
@@ -102,10 +123,7 @@ bool DeadMachineInstructionElim::isDead(const MachineInstr *MI) const {
102123 return true ;
103124}
104125
105- bool DeadMachineInstructionElim::runOnMachineFunction (MachineFunction &MF) {
106- if (skipFunction (MF.getFunction ()))
107- return false ;
108-
126+ bool DeadMachineInstructionElimImpl::runImpl (MachineFunction &MF) {
109127 MRI = &MF.getRegInfo ();
110128
111129 const TargetSubtargetInfo &ST = MF.getSubtarget ();
@@ -118,7 +136,7 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) {
118136 return AnyChanges;
119137}
120138
121- bool DeadMachineInstructionElim ::eliminateDeadMI (MachineFunction &MF) {
139+ bool DeadMachineInstructionElimImpl ::eliminateDeadMI (MachineFunction &MF) {
122140 bool AnyChanges = false ;
123141
124142 // Loop over all instructions in all blocks, from bottom to top, so that it's
0 commit comments