1+ // /===- DroppedVariableStatsMIR.cpp ---------------------------------------===//
2+ // /
3+ // / Part of the LLVM Project, under the Apache License v2.0 with LLVM
4+ // / Exceptions. See https://llvm.org/LICENSE.txt for license information.
5+ // / SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ // /
7+ // /===---------------------------------------------------------------------===//
8+ // / \file
9+ // / Dropped Variable Statistics for Debug Information. Reports any number
10+ // / of DBG_VALUEs that get dropped due to an optimization pass.
11+ // /
12+ // /===---------------------------------------------------------------------===//
13+
14+ #include " llvm/CodeGen/DroppedVariableStatsMIR.h"
15+
16+ using namespace llvm ;
17+
18+ void DroppedVariableStatsMIR::runOnMachineFunction (const MachineFunction *MF,
19+ bool Before) {
20+ auto &DebugVariables = DebugVariablesStack.back ()[&MF->getFunction ()];
21+ auto FuncName = MF->getName ();
22+ MFunc = MF;
23+ run (DebugVariables, FuncName, Before);
24+ }
25+
26+ void DroppedVariableStatsMIR::calculateDroppedVarStatsOnMachineFunction (
27+ const MachineFunction *MF, StringRef PassID, StringRef FuncOrModName) {
28+ MFunc = MF;
29+ StringRef FuncName = MF->getName ();
30+ const Function *Func = &MF->getFunction ();
31+ DebugVariables &DbgVariables = DebugVariablesStack.back ()[Func];
32+ calculateDroppedStatsAndPrint (DbgVariables, FuncName, PassID, FuncOrModName,
33+ " MachineFunction" , Func);
34+ }
35+
36+ void DroppedVariableStatsMIR::visitEveryInstruction (
37+ unsigned &DroppedCount, DenseMap<VarID, DILocation *> &InlinedAtsMap,
38+ VarID Var) {
39+ unsigned PrevDroppedCount = DroppedCount;
40+ const DIScope *DbgValScope = std::get<0 >(Var);
41+ for (const auto &MBB : *MFunc) {
42+ for (const auto &MI : MBB) {
43+ if (!MI.isDebugInstr ()) {
44+ auto *DbgLoc = MI.getDebugLoc ().get ();
45+ if (!DbgLoc)
46+ continue ;
47+
48+ auto *Scope = DbgLoc->getScope ();
49+ if (updateDroppedCount (DbgLoc, Scope, DbgValScope, InlinedAtsMap, Var,
50+ DroppedCount))
51+ break ;
52+ }
53+ }
54+ if (PrevDroppedCount != DroppedCount) {
55+ PrevDroppedCount = DroppedCount;
56+ break ;
57+ }
58+ }
59+ }
60+
61+ void DroppedVariableStatsMIR::visitEveryDebugRecord (
62+ DenseSet<VarID> &VarIDSet,
63+ DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,
64+ StringRef FuncName, bool Before) {
65+ for (const auto &MBB : *MFunc) {
66+ for (const auto &MI : MBB) {
67+ if (MI.isDebugValueLike ()) {
68+ auto *DbgVar = MI.getDebugVariable ();
69+ if (!DbgVar)
70+ continue ;
71+ auto DbgLoc = MI.getDebugLoc ();
72+ populateVarIDSetAndInlinedMap (DbgVar, DbgLoc, VarIDSet, InlinedAtsMap,
73+ FuncName, Before);
74+ }
75+ }
76+ }
77+ }
0 commit comments