|
7 | 7 | ///===---------------------------------------------------------------------===//
|
8 | 8 | /// \file
|
9 | 9 | /// Dropped Variable Statistics for Debug Information. Reports any number
|
10 |
| -/// of #dbg_value that get dropped due to an optimization pass. |
| 10 | +/// of #dbg_values or DBG_VALUEs that get dropped due to an optimization pass. |
11 | 11 | ///
|
12 | 12 | ///===---------------------------------------------------------------------===//
|
13 | 13 |
|
@@ -192,3 +192,64 @@ void DroppedVariableStatsIR::visitEveryDebugRecord(
|
192 | 192 | }
|
193 | 193 | }
|
194 | 194 | }
|
| 195 | + |
| 196 | +void DroppedVariableStatsMIR::runOnMachineFunction(const MachineFunction *MF, |
| 197 | + bool Before) { |
| 198 | + auto &DebugVariables = DebugVariablesStack.back()[&MF->getFunction()]; |
| 199 | + auto FuncName = MF->getName(); |
| 200 | + MFunc = MF; |
| 201 | + run(DebugVariables, FuncName, Before); |
| 202 | +} |
| 203 | + |
| 204 | +void DroppedVariableStatsMIR::calculateDroppedVarStatsOnMachineFunction( |
| 205 | + const MachineFunction *MF, StringRef PassID, StringRef FuncOrModName) { |
| 206 | + MFunc = MF; |
| 207 | + StringRef FuncName = MF->getName(); |
| 208 | + const Function *Func = &MF->getFunction(); |
| 209 | + DebugVariables &DbgVariables = DebugVariablesStack.back()[Func]; |
| 210 | + calculateDroppedStatsAndPrint(DbgVariables, FuncName, PassID, FuncOrModName, |
| 211 | + "MachineFunction", Func); |
| 212 | +} |
| 213 | + |
| 214 | +void DroppedVariableStatsMIR::visitEveryInstruction( |
| 215 | + unsigned &DroppedCount, DenseMap<VarID, DILocation *> &InlinedAtsMap, |
| 216 | + VarID Var) { |
| 217 | + unsigned PrevDroppedCount = DroppedCount; |
| 218 | + const DIScope *DbgValScope = std::get<0>(Var); |
| 219 | + for (const auto &MBB : *MFunc) { |
| 220 | + for (const auto &MI : MBB) { |
| 221 | + if (!MI.isDebugInstr()) { |
| 222 | + auto *DbgLoc = MI.getDebugLoc().get(); |
| 223 | + if (!DbgLoc) |
| 224 | + continue; |
| 225 | + |
| 226 | + auto *Scope = DbgLoc->getScope(); |
| 227 | + if (updateDroppedCount(DbgLoc, Scope, DbgValScope, InlinedAtsMap, Var, |
| 228 | + DroppedCount)) |
| 229 | + break; |
| 230 | + } |
| 231 | + } |
| 232 | + if (PrevDroppedCount != DroppedCount) { |
| 233 | + PrevDroppedCount = DroppedCount; |
| 234 | + break; |
| 235 | + } |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | +void DroppedVariableStatsMIR::visitEveryDebugRecord( |
| 240 | + DenseSet<VarID> &VarIDSet, |
| 241 | + DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap, |
| 242 | + StringRef FuncName, bool Before) { |
| 243 | + for (const auto &MBB : *MFunc) { |
| 244 | + for (const auto &MI : MBB) { |
| 245 | + if (MI.isDebugValueLike()) { |
| 246 | + auto *DbgVar = MI.getDebugVariable(); |
| 247 | + if (!DbgVar) |
| 248 | + continue; |
| 249 | + auto DbgLoc = MI.getDebugLoc(); |
| 250 | + populateVarIDSetAndInlinedMap(DbgVar, DbgLoc, VarIDSet, InlinedAtsMap, |
| 251 | + FuncName, Before); |
| 252 | + } |
| 253 | + } |
| 254 | + } |
| 255 | +} |
0 commit comments