LLVM 24.0.0git
DroppedVariableStats.h
Go to the documentation of this file.
1///===- DroppedVariableStats.h - Opt Diagnostics -*- C++ -*----------------===//
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
14#ifndef LLVM_CODEGEN_DROPPEDVARIABLESTATS_H
15#define LLVM_CODEGEN_DROPPEDVARIABLESTATS_H
16
17#include "llvm/ADT/DenseSet.h"
21
22namespace llvm {
23
24class Function;
25class DebugLoc;
26class StringRef;
27
28/// A unique key that represents one instance of a debug variable.
30
31/// A base class to collect and print dropped debug information variable
32/// statistics.
34public:
35 LLVM_ABI DroppedVariableStats(bool DroppedVarStatsEnabled);
36
37 virtual ~DroppedVariableStats() = default;
38
39 // We intend this to be unique per-compilation, thus no copies.
41 void operator=(const DroppedVariableStats &) = delete;
42
43 bool getPassDroppedVariables() { return PassDroppedVariables; }
44
45protected:
46 LLVM_ABI void setup();
47
48 LLVM_ABI void cleanup();
49
52 /// DenseSet of VarIDs before an optimization pass has run.
54 /// DenseSet of VarIDs after an optimization pass has run.
56 };
57
58 /// A stack of a DenseMap, that maps DebugVariables for every pass to an
59 /// llvm::Function. A stack is used because an optimization pass can call
60 /// other passes.
62
63 /// Calculate the number of dropped variables in an llvm::Function or
64 /// llvm::MachineFunction and print the relevant information to stdout.
67 StringRef FuncOrModName,
68 StringRef PassLevel,
69 const Function *Func);
70
71 /// Check if a \p Var has been dropped or is a false positive. Also update the
72 /// \p DroppedCount if a debug variable is dropped.
73 LLVM_ABI bool updateDroppedCount(const DILocation *DbgLoc, VarID Var,
74 unsigned &DroppedCount);
75
76 /// Run code to populate relevant data structures over an llvm::Function or
77 /// llvm::MachineFunction.
78 LLVM_ABI void run(DebugVariables &DbgVariables, bool Before);
79
80 /// Add the VarID of the debug record of \p DbgVar at \p DbgLoc to
81 /// \p VarIDSet.
82 LLVM_ABI void populateVarIDSet(const DILocalVariable *DbgVar, DebugLoc DbgLoc,
83 DenseSet<VarID> &VarIDSet);
84
85 /// Visit every llvm::Instruction or llvm::MachineInstruction and check if the
86 /// debug variable denoted by its ID \p Var may have been dropped by an
87 /// optimization pass.
88 virtual void visitEveryInstruction(unsigned &DroppedCount, VarID Var) = 0;
89 /// Visit every debug record in an llvm::Function or llvm::MachineFunction
90 /// and call populateVarIDSet on it.
91 virtual void visitEveryDebugRecord(DenseSet<VarID> &VarIDSet) = 0;
92
93private:
94 /// Remove a dropped debug variable's VarID from all Sets in the
95 /// DroppedVariablesBefore stack.
96 void removeVarFromAllSets(VarID Var, const Function *F);
97
98 /// Return true if \p Scope is the same as \p VarScope or a child scope of
99 /// \p VarScope, return false otherwise.
100 static bool isScopeChildOfOrEqualTo(const DIScope *Scope,
101 const DIScope *VarScope);
102
103 /// Return true if a debugger stopped at \p Loc can observe \p Var, in the
104 /// frame of \p Loc or in a frame \p Loc was inlined into.
105 static bool isVarInScopeAt(const DILocation *Loc, VarID Var);
106
107 bool PassDroppedVariables = false;
108};
109
110} // namespace llvm
111
112#endif
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseSet and SmallDenseSet classes.
#define F(x, y, z)
Definition MD5.cpp:54
This file defines the SmallVector class.
Base class for scope-like contexts.
A debug info location.
Definition DebugLoc.h:126
Identifies a unique instance of a whole variable (discards/ignores fragment information).
Implements a dense probed hash-table based set.
Definition DenseSet.h:283
LLVM_ABI void populateVarIDSet(const DILocalVariable *DbgVar, DebugLoc DbgLoc, DenseSet< VarID > &VarIDSet)
Add the VarID of the debug record of DbgVar at DbgLoc to VarIDSet.
virtual void visitEveryInstruction(unsigned &DroppedCount, VarID Var)=0
Visit every llvm::Instruction or llvm::MachineInstruction and check if the debug variable denoted by ...
virtual void visitEveryDebugRecord(DenseSet< VarID > &VarIDSet)=0
Visit every debug record in an llvm::Function or llvm::MachineFunction and call populateVarIDSet on i...
DroppedVariableStats(const DroppedVariableStats &)=delete
LLVM_ABI void run(DebugVariables &DbgVariables, bool Before)
Run code to populate relevant data structures over an llvm::Function or llvm::MachineFunction.
LLVM_ABI DroppedVariableStats(bool DroppedVarStatsEnabled)
LLVM_ABI void calculateDroppedStatsAndPrint(DebugVariables &DbgVariables, 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...
SmallVector< DenseMap< const Function *, DebugVariables > > DebugVariablesStack
A stack of a DenseMap, that maps DebugVariables for every pass to an llvm::Function.
LLVM_ABI bool updateDroppedCount(const DILocation *DbgLoc, VarID Var, unsigned &DroppedCount)
Check if a Var has been dropped or is a false positive.
void operator=(const DroppedVariableStats &)=delete
virtual ~DroppedVariableStats()=default
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This is an optimization pass for GlobalISel generic memory operations.
DebugVariableAggregate VarID
A unique key that represents one instance of 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.