LLVM 20.0.0git
DroppedVariableStatsIR.cpp
Go to the documentation of this file.
1///===- DroppedVariableStatsIR.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_value that get dropped due to an optimization pass.
11///
12///===---------------------------------------------------------------------===//
13
15
16using namespace llvm;
17
18void DroppedVariableStatsIR::runOnFunction(const Function *F, bool Before) {
19 auto &DebugVariables = DebugVariablesStack.back()[F];
20 auto FuncName = F->getName();
21 Func = F;
22 run(DebugVariables, FuncName, Before);
23}
24
25void DroppedVariableStatsIR::calculateDroppedVarStatsOnFunction(
26 const Function *F, StringRef PassID, StringRef FuncOrModName,
27 StringRef PassLevel) {
28 Func = F;
29 StringRef FuncName = F->getName();
30 DebugVariables &DbgVariables = DebugVariablesStack.back()[F];
31 calculateDroppedStatsAndPrint(DbgVariables, FuncName, PassID, FuncOrModName,
32 PassLevel, Func);
33}
34
35void DroppedVariableStatsIR::runOnModule(const Module *M, bool Before) {
36 for (auto &F : *M)
37 runOnFunction(&F, Before);
38}
39
40void DroppedVariableStatsIR::calculateDroppedVarStatsOnModule(
41 const Module *M, StringRef PassID, StringRef FuncOrModName,
42 StringRef PassLevel) {
43 for (auto &F : *M) {
44 calculateDroppedVarStatsOnFunction(&F, PassID, FuncOrModName, PassLevel);
45 }
46}
47
51 return;
52
54 [this](StringRef P, Any IR) { return runBeforePass(IR); });
56 [this](StringRef P, Any IR, const PreservedAnalyses &PA) {
57 return runAfterPass(P, IR);
58 });
60 [this](StringRef P, const PreservedAnalyses &PA) { return cleanup(); });
61}
62
63void DroppedVariableStatsIR::visitEveryInstruction(
64 unsigned &DroppedCount, DenseMap<VarID, DILocation *> &InlinedAtsMap,
65 VarID Var) {
66 const DIScope *DbgValScope = std::get<0>(Var);
67 for (const auto &I : instructions(Func)) {
68 auto *DbgLoc = I.getDebugLoc().get();
69 if (!DbgLoc)
70 continue;
71 if (updateDroppedCount(DbgLoc, DbgLoc->getScope(), DbgValScope,
72 InlinedAtsMap, Var, DroppedCount))
73 break;
74 }
75}
76
77void DroppedVariableStatsIR::visitEveryDebugRecord(
78 DenseSet<VarID> &VarIDSet,
80 StringRef FuncName, bool Before) {
81 for (const auto &I : instructions(Func)) {
82 for (DbgRecord &DR : I.getDbgRecordRange()) {
83 if (auto *Dbg = dyn_cast<DbgVariableRecord>(&DR)) {
84 auto *DbgVar = Dbg->getVariable();
85 auto DbgLoc = DR.getDebugLoc();
86 populateVarIDSetAndInlinedMap(DbgVar, DbgLoc, VarIDSet, InlinedAtsMap,
87 FuncName, Before);
88 }
89 }
90 }
91}
Expand Atomic instructions
===- DroppedVariableStatsIR.h - Opt Diagnostics -*- C++ -*-----------—===//
Legalize the Machine IR a function s Machine IR
Definition: Legalizer.cpp:80
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define P(N)
PassInstrumentationCallbacks PIC
Definition: Any.h:28
Base class for scope-like contexts.
Base class for non-instruction debug metadata records that have positions within IR.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
void registerCallbacks(PassInstrumentationCallbacks &PIC)
void runAfterPass(StringRef P, Any IR)
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...
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...
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.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::tuple< const DIScope *, const DIScope *, const DILocalVariable * > VarID
A unique key that represents a debug variable.
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)