LLVM: lib/CodeGen/RemoveRedundantDebugValues.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
21
22
23
24
25
26
27#define DEBUG_TYPE "removeredundantdebugvalues"
28
29using namespace llvm;
30
31STATISTIC(NumRemovedBackward, "Number of DBG_VALUEs removed (backward scan)");
32STATISTIC(NumRemovedForward, "Number of DBG_VALUEs removed (forward scan)");
33
34namespace {
35
37public:
38 static char ID;
39
40 RemoveRedundantDebugValues();
41
43
44
46
50 }
51};
52
53}
54
55
56
57
58
59char RemoveRedundantDebugValues::ID = 0;
60
62
64 "Remove Redundant DEBUG_VALUE analysis", false, false)
65
66
67RemoveRedundantDebugValues::RemoveRedundantDebugValues()
70}
71
72
73
74
75
76
77
78
79
80
81
84
87 VariableMap;
89
91 if (MI.isDebugValue()) {
93 MI.getDebugLoc()->getInlinedAt());
94 auto VMI = VariableMap.find(Var);
95
96
97
98
99
100
101 if (MI.isDebugValueList() && VMI != VariableMap.end()) {
102 VariableMap.erase(VMI);
103 continue;
104 }
105
107 if (!Loc.isReg()) {
108
109 if (VMI != VariableMap.end())
110 VariableMap.erase(VMI);
111 continue;
112 }
113
114
115 if (VMI == VariableMap.end() ||
116 VMI->second.first->getReg() != Loc.getReg() ||
117 VMI->second.second != MI.getDebugExpression()) {
118 VariableMap[Var] = {&Loc, MI.getDebugExpression()};
119 continue;
120 }
121
122
123
125 }
126
127 if (MI.isMetaInstruction())
128 continue;
129
130
131 for (auto &Var : VariableMap) {
132 auto &LocOp = Var.second.first;
133 if (MI.modifiesRegister(LocOp->getReg(), TRI))
134 VariableMap.erase(Var.first);
135 }
136 }
137
138 for (auto &Instr : DbgValsToBeRemoved) {
140 Instr->eraseFromParent();
141 ++NumRemovedForward;
142 }
143
144 return !DbgValsToBeRemoved.empty();
145}
146
147
148
149
150
151
152
153
154
155
160
162 if (MI.isDebugValue()) {
163 DebugVariable Var(MI.getDebugVariable(), MI.getDebugExpression(),
164 MI.getDebugLoc()->getInlinedAt());
165 auto R = VariableSet.insert(Var);
166
167
168
169
170 if (MI.isNonListDebugValue()) {
172 if (!Loc.isReg()) {
173
174
175 if (!R.second)
176 VariableSet.erase(Var);
177 continue;
178 }
179 }
180
181
182
183 if (!R.second)
185 continue;
186 }
187
188
189
190 VariableSet.clear();
191 }
192
193 for (auto &Instr : DbgValsToBeRemoved) {
195 Instr->eraseFromParent();
196 ++NumRemovedBackward;
197 }
198
199 return !DbgValsToBeRemoved.empty();
200}
201
202bool RemoveRedundantDebugValues::reduceDbgValues(MachineFunction &MF) {
204
205 bool Changed = false;
206
207 for (auto &MBB : MF) {
210 }
211
212 return Changed;
213}
214
215bool RemoveRedundantDebugValues::runOnMachineFunction(MachineFunction &MF) {
216
218 return false;
219
220
223 return false;
224
225 bool Changed = reduceDbgValues(MF);
226 return Changed;
227}
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool reduceDbgValsForwardScan(MachineBasicBlock &MBB)
static bool reduceDbgValsBackwardScan(MachineBasicBlock &MBB)
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Represent the analysis usage information of a pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Identifies a unique instance of a variable.
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
DISubprogram * getSubprogram() const
Get the attached subprogram.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Implements a dense probed hash-table based set with some number of buckets stored inline.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
std::pair< iterator, bool > insert(const ValueT &V)
bool erase(const ValueT &V)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
auto reverse(ContainerTy &&C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
char & RemoveRedundantDebugValuesID
RemoveRedundantDebugValues pass.
void initializeRemoveRedundantDebugValuesPass(PassRegistry &)