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(StringRef PassID, const Function *F,
19 bool Before) {
20 auto &DebugVariables = DebugVariablesStack.back()[F];
21 auto FuncName = F->getName();
22 Func = F;
23 run(DebugVariables, FuncName, Before);
24}
25
26void DroppedVariableStatsIR::calculateDroppedVarStatsOnFunction(
27 const Function *F, StringRef PassID, StringRef FuncOrModName,
28 StringRef PassLevel) {
29 Func = F;
30 StringRef FuncName = F->getName();
31 DebugVariables &DbgVariables = DebugVariablesStack.back()[F];
32 calculateDroppedStatsAndPrint(DbgVariables, FuncName, PassID, FuncOrModName,
33 PassLevel, Func);
34}
35
36void DroppedVariableStatsIR::runOnModule(StringRef PassID, const Module *M,
37 bool Before) {
38 for (auto &F : *M) {
39 runOnFunction(PassID, &F, Before);
40 }
41}
42
43void DroppedVariableStatsIR::calculateDroppedVarStatsOnModule(
44 const Module *M, StringRef PassID, StringRef FuncOrModName,
45 StringRef PassLevel) {
46 for (auto &F : *M) {
47 calculateDroppedVarStatsOnFunction(&F, PassID, FuncOrModName, PassLevel);
48 }
49}
50
54 return;
55
57 [this](StringRef P, Any IR) { return runBeforePass(P, IR); });
59 [this](StringRef P, Any IR, const PreservedAnalyses &PA) {
60 return runAfterPass(P, IR);
61 });
63 [this](StringRef P, const PreservedAnalyses &PA) { return cleanup(); });
64}
65
66void DroppedVariableStatsIR::visitEveryInstruction(
67 unsigned &DroppedCount, DenseMap<VarID, DILocation *> &InlinedAtsMap,
68 VarID Var) {
69 const DIScope *DbgValScope = std::get<0>(Var);
70 for (const auto &I : instructions(Func)) {
71 auto *DbgLoc = I.getDebugLoc().get();
72 if (!DbgLoc)
73 continue;
74 if (updateDroppedCount(DbgLoc, DbgLoc->getScope(), DbgValScope,
75 InlinedAtsMap, Var, DroppedCount))
76 break;
77 }
78}
79
80void DroppedVariableStatsIR::visitEveryDebugRecord(
81 DenseSet<VarID> &VarIDSet,
83 StringRef FuncName, bool Before) {
84 for (const auto &I : instructions(Func)) {
85 for (DbgRecord &DR : I.getDbgRecordRange()) {
86 if (auto *Dbg = dyn_cast<DbgVariableRecord>(&DR)) {
87 auto *DbgVar = Dbg->getVariable();
88 auto DbgLoc = DR.getDebugLoc();
89 populateVarIDSetAndInlinedMap(DbgVar, DbgLoc, VarIDSet, InlinedAtsMap,
90 FuncName, Before);
91 }
92 }
93 }
94}
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 runBeforePass(StringRef P, Any IR)
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)