21bool DroppedVariableStats::isScopeChildOfOrEqualTo(
const DIScope *Scope,
23 while (Scope !=
nullptr) {
26 if (Scope == DbgValScope) {
39bool DroppedVariableStats::isInlinedAtChildOfOrEqualTo(
41 if (DbgValInlinedAt == InlinedAt)
47 if (IA == DbgValInlinedAt)
49 IA =
IA->getInlinedAt();
57 unsigned DroppedCount = 0;
66 for (
VarID Var : DebugVariablesBeforeSet) {
67 if (DebugVariablesAfterSet.
contains(Var))
70 removeVarFromAllSets(Var, Func);
72 if (DroppedCount > 0) {
73 llvm::outs() << PassLevel <<
", " << PassID <<
", " << DroppedCount <<
", "
74 << FuncOrModName <<
"\n";
75 PassDroppedVariables =
true;
77 PassDroppedVariables =
false;
83 unsigned &DroppedCount) {
88 if (isScopeChildOfOrEqualTo(Scope, DbgValScope))
89 if (isInlinedAtChildOfOrEqualTo(DbgLoc->getInlinedAt(),
90 InlinedAtsMap[Var])) {
115 VarID Key{DbgVar->
getScope(), DbgLoc->getInlinedAtScope(), DbgVar};
118 InlinedAtsMap[FuncName].try_emplace(Key, DbgLoc.
getInlinedAt());
121void DroppedVariableStatsIR::runOnFunction(
const Function *
F,
bool Before) {
123 auto FuncName =
F->getName();
128void DroppedVariableStatsIR::calculateDroppedVarStatsOnFunction(
138void DroppedVariableStatsIR::runOnModule(
const Module *M,
bool Before) {
143void DroppedVariableStatsIR::calculateDroppedVarStatsOnModule(
147 calculateDroppedVarStatsOnFunction(&
F, PassID, FuncOrModName, PassLevel);
166void DroppedVariableStatsIR::visitEveryInstruction(
169 const DIScope *DbgValScope = std::get<0>(Var);
171 auto *DbgLoc =
I.getDebugLoc().get();
175 InlinedAtsMap, Var, DroppedCount))
180void DroppedVariableStatsIR::visitEveryDebugRecord(
186 if (
auto *Dbg = dyn_cast<DbgVariableRecord>(&DR)) {
187 auto *DbgVar =
Dbg->getVariable();
188 auto DbgLoc = DR.getDebugLoc();
Expand Atomic instructions
===- DroppedVariableStats.h - Opt Diagnostics -*- C++ -*-------------—===//
Module.h This file contains the declarations for the Module class.
Legalize the Machine IR a function s Machine IR
PassInstrumentationCallbacks PIC
DILocalScope * getScope() const
Get the local scope for this variable.
Base class for scope-like contexts.
Base class for non-instruction debug metadata records that have positions within IR.
DILocation * getInlinedAt() const
Implements a dense probed hash-table based set.
void registerCallbacks(PassInstrumentationCallbacks &PIC)
void runAfterPass(StringRef P, Any IR)
void runBeforePass(Any IR)
DenseSet< const DIScope * > VisitedScope
A DenseSet tracking whether a scope was visited before.
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...
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 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.
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
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...
SmallVector< DenseMap< const Function *, DebugVariables > > DebugVariablesStack
A stack of a DenseMap, that maps DebugVariables for every pass to an llvm::Function.
void run(DebugVariables &DbgVariables, StringRef FuncName, bool Before)
Run code to populate relevant data structures over an llvm::Function or llvm::MachineFunction.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
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.
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.
DenseSet< VarID > DebugVariablesAfter
DenseSet of VarIDs after an optimization pass has run.
DenseSet< VarID > DebugVariablesBefore
DenseSet of VarIDs before an optimization pass has run.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
void registerAfterPassInvalidatedCallback(CallableT C, bool ToFront=false)
void registerBeforeNonSkippedPassCallback(CallableT C)
void registerAfterPassCallback(CallableT C, bool ToFront=false)