LLVM: lib/IR/DroppedVariableStats.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
18
19using namespace llvm;
20
23 if (DroppedVarStatsEnabled)
24 llvm::outs() << "Pass Level, Pass Name, Num of Dropped Variables, Func or "
25 "Module Name\n";
26}
27
32
35 "DebugVariablesStack shouldn't be empty!");
36 assert(.empty() && "InlinedAts shouldn't be empty!");
39}
40
44 unsigned DroppedCount = 0;
47 auto It = InlinedAts.back().find(FuncName);
49 return;
51
52
53
54
55
56 for (VarID Var : DebugVariablesBeforeSet) {
57 if (DebugVariablesAfterSet.contains(Var))
58 continue;
60 removeVarFromAllSets(Var, Func);
61 }
62 if (DroppedCount > 0) {
63 llvm::outs() << PassLevel << ", " << PassID << ", " << DroppedCount << ", "
64 << FuncOrModName << "\n";
65 PassDroppedVariables = true;
66 } else
67 PassDroppedVariables = false;
68}
69
73 unsigned &DroppedCount) {
74
75
76
77 if (isScopeChildOfOrEqualTo(Scope, DbgValScope))
78 if (isInlinedAtChildOfOrEqualTo(DbgLoc->getInlinedAt(),
79 InlinedAtsMap[Var])) {
80
81
82
83 DroppedCount++;
84 return true;
85 }
86 return false;
87}
88
90 bool Before) {
93 auto &InlinedAtsMap = InlinedAts.back();
94 if (Before)
98}
99
103 StringRef FuncName, bool Before) {
104 VarID Key{DbgVar->getScope(), DbgLoc->getInlinedAtScope(), DbgVar};
106 if (Before)
107 InlinedAtsMap[FuncName].try_emplace(Key, DbgLoc.getInlinedAt());
108}
109
110void DroppedVariableStats::removeVarFromAllSets(VarID Var, const Function *F) {
111
112
114 DebugVariablesMap[F].DebugVariablesBefore.erase(Var);
115}
116
117bool DroppedVariableStats::isScopeChildOfOrEqualTo(const DIScope *Scope,
118 const DIScope *DbgValScope) {
119 while (Scope != nullptr) {
121 if (Scope == DbgValScope) {
123 return true;
124 }
126 } else {
128 return false;
129 }
130 }
131 return false;
132}
133
134bool DroppedVariableStats::isInlinedAtChildOfOrEqualTo(
136 if (DbgValInlinedAt == InlinedAt)
137 return true;
138 if (!DbgValInlinedAt)
139 return false;
140 auto *IA = InlinedAt;
141 while (IA) {
142 if (IA == DbgValInlinedAt)
143 return true;
145 }
146 return false;
147}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
===- DroppedVariableStats.h - Opt Diagnostics -*- C++ -*-------------—===//
DILocalScope * getScope() const
Get the local scope for this variable.
Base class for scope-like contexts.
LLVM_ABI DILocation * getInlinedAt() const
Implements a dense probed hash-table based set.
DenseSet< const DIScope * > VisitedScope
A DenseSet tracking whether a scope was visited before.
LLVM_ABI void calculateDroppedStatsAndPrint(DebugVariables &DbgVariables, StringRef FuncName, StringRef PassID, StringRef FuncOrModName, StringRef PassLevel, const Function *Func)
Calculate the number of dropped variables in an llvm::Function or llvm::MachineFunction and print the...
Definition DroppedVariableStats.cpp:41
virtual void visitEveryInstruction(unsigned &DroppedCount, DenseMap< VarID, DILocation * > &InlinedAtsMap, VarID Var)=0
Visit every llvm::Instruction or llvm::MachineInstruction and check if the debug variable denoted by ...
SmallVector< DenseMap< StringRef, DenseMap< VarID, DILocation * > > > InlinedAts
A stack of DenseMaps, which map the name of an llvm::Function to a DenseMap of VarIDs and their inlin...
LLVM_ABI bool updateDroppedCount(DILocation *DbgLoc, const DIScope *Scope, const DIScope *DbgValScope, DenseMap< VarID, DILocation * > &InlinedAtsMap, VarID Var, unsigned &DroppedCount)
Check if a Var has been dropped or is a false positive.
Definition DroppedVariableStats.cpp:70
virtual void visitEveryDebugRecord(DenseSet< VarID > &VarIDSet, DenseMap< StringRef, DenseMap< VarID, DILocation * > > &InlinedAtsMap, StringRef FuncName, bool Before)=0
Visit every debug record in an llvm::Function or llvm::MachineFunction and call populateVarIDSetAndIn...
bool DroppedVariableStatsEnabled
LLVM_ABI void setup()
Definition DroppedVariableStats.cpp:28
LLVM_ABI void populateVarIDSetAndInlinedMap(const DILocalVariable *DbgVar, DebugLoc DbgLoc, DenseSet< VarID > &VarIDSet, DenseMap< StringRef, DenseMap< VarID, DILocation * > > &InlinedAtsMap, StringRef FuncName, bool Before)
Populate the VarIDSet and InlinedAtMap with the relevant information needed for before and after pass...
Definition DroppedVariableStats.cpp:100
LLVM_ABI DroppedVariableStats(bool DroppedVarStatsEnabled)
Definition DroppedVariableStats.cpp:21
SmallVector< DenseMap< const Function *, DebugVariables > > DebugVariablesStack
A stack of a DenseMap, that maps DebugVariables for every pass to an llvm::Function.
LLVM_ABI void run(DebugVariables &DbgVariables, StringRef FuncName, bool Before)
Run code to populate relevant data structures over an llvm::Function or llvm::MachineFunction.
Definition DroppedVariableStats.cpp:89
LLVM_ABI void cleanup()
Definition DroppedVariableStats.cpp:33
StringRef - Represent a constant reference to a string, i.e.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
This is an optimization pass for GlobalISel generic memory operations.
std::tuple< const DIScope *, const DIScope *, const DILocalVariable * > VarID
A unique key that represents a debug variable.
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
auto drop_end(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the last N elements excluded.
DenseSet< VarID > DebugVariablesAfter
DenseSet of VarIDs after an optimization pass has run.
DenseSet< VarID > DebugVariablesBefore
DenseSet of VarIDs before an optimization pass has run.