10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " llvm/CodeGen/DeadMachineInstructionElim.h"
13
14
#include " llvm/ADT/PostOrderIterator.h"
14
15
#include " llvm/ADT/Statistic.h"
15
16
#include " llvm/CodeGen/LiveRegUnits.h"
@@ -28,37 +29,57 @@ using namespace llvm;
28
29
STATISTIC (NumDeletes, " Number of dead instructions deleted" );
29
30
30
31
namespace {
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;
33
36
34
- const MachineRegisterInfo *MRI = nullptr ;
35
- const TargetInstrInfo *TII = nullptr ;
36
- LiveRegUnits LivePhysRegs;
37
+ public:
38
+ bool runImpl (MachineFunction &MF);
37
39
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
+ };
43
44
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
48
48
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
+ }
51
58
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;
54
74
}
75
+
55
76
char DeadMachineInstructionElim::ID = 0 ;
56
77
char &llvm::DeadMachineInstructionElimID = DeadMachineInstructionElim::ID;
57
78
58
79
INITIALIZE_PASS (DeadMachineInstructionElim, DEBUG_TYPE,
59
80
" Remove dead machine instructions" , false , false )
60
81
61
- bool DeadMachineInstructionElim ::isDead(const MachineInstr *MI) const {
82
+ bool DeadMachineInstructionElimImpl ::isDead(const MachineInstr *MI) const {
62
83
// Technically speaking inline asm without side effects and no defs can still
63
84
// be deleted. But there is so much bad inline asm code out there, we should
64
85
// let them be.
@@ -102,10 +123,7 @@ bool DeadMachineInstructionElim::isDead(const MachineInstr *MI) const {
102
123
return true ;
103
124
}
104
125
105
- bool DeadMachineInstructionElim::runOnMachineFunction (MachineFunction &MF) {
106
- if (skipFunction (MF.getFunction ()))
107
- return false ;
108
-
126
+ bool DeadMachineInstructionElimImpl::runImpl (MachineFunction &MF) {
109
127
MRI = &MF.getRegInfo ();
110
128
111
129
const TargetSubtargetInfo &ST = MF.getSubtarget ();
@@ -118,7 +136,7 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) {
118
136
return AnyChanges;
119
137
}
120
138
121
- bool DeadMachineInstructionElim ::eliminateDeadMI (MachineFunction &MF) {
139
+ bool DeadMachineInstructionElimImpl ::eliminateDeadMI (MachineFunction &MF) {
122
140
bool AnyChanges = false ;
123
141
124
142
// Loop over all instructions in all blocks, from bottom to top, so that it's
0 commit comments