|
18 | 18 | #include "llvm/IR/DebugInfoMetadata.h" |
19 | 19 | #include "llvm/IR/DiagnosticInfo.h" |
20 | 20 | #include "llvm/IR/Function.h" |
| 21 | +#include "llvm/IR/InstIterator.h" |
21 | 22 | #include "llvm/IR/Module.h" |
22 | 23 | #include "llvm/IR/PassInstrumentation.h" |
23 | 24 |
|
@@ -206,12 +207,33 @@ class DroppedVariableStatsIR : public DroppedVariableStats { |
206 | 207 | virtual void |
207 | 208 | visitEveryInstruction(unsigned &DroppedCount, |
208 | 209 | DenseMap<VarID, DILocation *> &InlinedAtsMap, |
209 | | - VarID Var) override; |
| 210 | + VarID Var) override { |
| 211 | + const DIScope *DbgValScope = std::get<0>(Var); |
| 212 | + for (const auto &I : instructions(Func)) { |
| 213 | + auto *DbgLoc = I.getDebugLoc().get(); |
| 214 | + if (!DbgLoc) |
| 215 | + continue; |
| 216 | + if (updateDroppedCount(DbgLoc, DbgLoc->getScope(), DbgValScope, |
| 217 | + InlinedAtsMap, Var, DroppedCount)) |
| 218 | + break; |
| 219 | + } |
| 220 | + } |
210 | 221 | /// Override base class method to run on #dbg_values specifically. |
211 | 222 | virtual void visitEveryDebugRecord( |
212 | 223 | DenseSet<VarID> &VarIDSet, |
213 | 224 | DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap, |
214 | | - StringRef FuncName, bool Before) override; |
| 225 | + StringRef FuncName, bool Before) override { |
| 226 | + for (const auto &I : instructions(Func)) { |
| 227 | + for (DbgRecord &DR : I.getDbgRecordRange()) { |
| 228 | + if (auto *Dbg = dyn_cast<DbgVariableRecord>(&DR)) { |
| 229 | + auto *DbgVar = Dbg->getVariable(); |
| 230 | + auto DbgLoc = DR.getDebugLoc(); |
| 231 | + populateVarIDSetAndInlinedMap(DbgVar, DbgLoc, VarIDSet, InlinedAtsMap, |
| 232 | + FuncName, Before); |
| 233 | + } |
| 234 | + } |
| 235 | + } |
| 236 | + } |
215 | 237 |
|
216 | 238 | template <typename IRUnitT> static const IRUnitT *unwrapIR(Any IR) { |
217 | 239 | const IRUnitT **IRPtr = llvm::any_cast<const IRUnitT *>(&IR); |
|
0 commit comments