14#ifndef LLVM_CODEGEN_DROPPEDVARIABLESTATS_H
15#define LLVM_CODEGEN_DROPPEDVARIABLESTATS_H
30 std::tuple<const DIScope *, const DIScope *, const DILocalVariable *>;
38 if (DroppedVarStatsEnabled)
40 <<
"Pass Level, Pass Name, Num of Dropped Variables, Func or "
62 "DebugVariablesStack shouldn't be empty!");
95 unsigned DroppedCount = 0;
105 for (
VarID Var : DebugVariablesBeforeSet) {
106 if (DebugVariablesAfterSet.
contains(Var))
109 removeVarFromAllSets(Var, Func);
111 if (DroppedCount > 0) {
112 llvm::outs() << PassLevel <<
", " << PassID <<
", " << DroppedCount
113 <<
", " << FuncOrModName <<
"\n";
114 PassDroppedVariables =
true;
116 PassDroppedVariables =
false;
124 VarID Var,
unsigned &DroppedCount) {
128 if (isScopeChildOfOrEqualTo(Scope, DbgValScope))
129 if (isInlinedAtChildOfOrEqualTo(DbgLoc->getInlinedAt(),
130 InlinedAtsMap[Var])) {
157 VarID Key{DbgVar->
getScope(), DbgLoc->getInlinedAtScope(), DbgVar};
160 InlinedAtsMap[FuncName].try_emplace(Key, DbgLoc.
getInlinedAt());
183 DebugVariablesMap[
F].DebugVariablesBefore.erase(Var);
187 bool isScopeChildOfOrEqualTo(
const DIScope *Scope,
189 while (Scope !=
nullptr) {
192 if (Scope == DbgValScope) {
196 Scope = Scope->getScope();
206 bool isInlinedAtChildOfOrEqualTo(
const DILocation *InlinedAt,
207 const DILocation *DbgValInlinedAt) {
208 if (DbgValInlinedAt == InlinedAt)
210 if (!DbgValInlinedAt)
212 auto *
IA = InlinedAt;
214 if (IA == DbgValInlinedAt)
216 IA =
IA->getInlinedAt();
220 bool PassDroppedVariables =
false;
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DILocalScope * getScope() const
Get the local scope for this variable.
Base class for scope-like contexts.
DILocation * getInlinedAt() const
Implements a dense probed hash-table based set.
A base class to collect and print dropped debug information variable statistics.
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...
DenseSet< const DIScope * > VisitedScope
A DenseSet tracking whether a scope was visited before.
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...
bool getPassDroppedVariables()
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...
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...
DroppedVariableStats(bool DroppedVarStatsEnabled)
DroppedVariableStats(const DroppedVariableStats &)=delete
bool DroppedVariableStatsEnabled
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.
void run(DebugVariables &DbgVariables, StringRef FuncName, bool Before)
Run code to populate relevant data structures over an llvm::Function or llvm::MachineFunction.
SmallVector< DenseMap< const Function *, DebugVariables > > DebugVariablesStack
A stack of a DenseMap, that maps DebugVariables for every pass to an llvm::Function.
void operator=(const DroppedVariableStats &)=delete
virtual ~DroppedVariableStats()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
This is an optimization pass for GlobalISel generic memory operations.
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
std::tuple< const DIScope *, const DIScope *, const DILocalVariable * > VarID
A unique key that represents a debug variable.
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.