LLVM  14.0.0git
DebugInfo.h
Go to the documentation of this file.
1 //===- DebugInfo.h - Debug Information Helpers ------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a bunch of datatypes that are useful for creating and
10 // walking debug info in LLVM IR form. They essentially provide wrappers around
11 // the information in the global variables that's needed when constructing the
12 // DWARF information.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_IR_DEBUGINFO_H
17 #define LLVM_IR_DEBUGINFO_H
18 
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/TinyPtrVector.h"
25 
26 namespace llvm {
27 
28 class DbgDeclareInst;
29 class DbgValueInst;
30 class DbgVariableIntrinsic;
31 class Instruction;
32 class Module;
33 
34 /// Finds all intrinsics declaring local variables as living in the memory that
35 /// 'V' points to. This may include a mix of dbg.declare and
36 /// dbg.addr intrinsics.
37 TinyPtrVector<DbgVariableIntrinsic *> FindDbgAddrUses(Value *V);
38 
39 /// Like \c FindDbgAddrUses, but only returns dbg.declare intrinsics, not
40 /// dbg.addr.
41 TinyPtrVector<DbgDeclareInst *> FindDbgDeclareUses(Value *V);
42 
43 /// Finds the llvm.dbg.value intrinsics describing a value.
44 void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V);
45 
46 /// Finds the debug info intrinsics describing a value.
47 void findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts, Value *V);
48 
49 /// Find subprogram that is enclosing this scope.
50 DISubprogram *getDISubprogram(const MDNode *Scope);
51 
52 /// Strip debug info in the module if it exists.
53 ///
54 /// To do this, we remove all calls to the debugger intrinsics and any named
55 /// metadata for debugging. We also remove debug locations for instructions.
56 /// Return true if module is modified.
57 bool StripDebugInfo(Module &M);
58 bool stripDebugInfo(Function &F);
59 
60 /// Downgrade the debug info in a module to contain only line table information.
61 ///
62 /// In order to convert debug info to what -gline-tables-only would have
63 /// created, this does the following:
64 /// 1) Delete all debug intrinsics.
65 /// 2) Delete all non-CU named metadata debug info nodes.
66 /// 3) Create new DebugLocs for each instruction.
67 /// 4) Create a new CU debug info, and similarly for every metadata node
68 /// that's reachable from the CU debug info.
69 /// All debug type metadata nodes are unreachable and garbage collected.
71 
72 /// Update the debug locations contained within the MD_loop metadata attached
73 /// to the instruction \p I, if one exists. \p Updater is applied to Metadata
74 /// operand in the MD_loop metadata: the returned value is included in the
75 /// updated loop metadata node if it is non-null.
77  Instruction &I, function_ref<Metadata *(Metadata *)> Updater);
78 
79 /// Return Debug Info Metadata Version by checking module flags.
81 
82 /// Utility to find all debug info in a module.
83 ///
84 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
85 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
86 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
87 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
88 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
89 /// used by the CUs.
91 public:
92  /// Process entire module and collect debug info anchors.
93  void processModule(const Module &M);
94  /// Process a single instruction and collect debug info anchors.
95  void processInstruction(const Module &M, const Instruction &I);
96 
97  /// Process DbgVariableIntrinsic.
98  void processVariable(const Module &M, const DbgVariableIntrinsic &DVI);
99  /// Process debug info location.
100  void processLocation(const Module &M, const DILocation *Loc);
101 
102  /// Process subprogram.
104 
105  /// Clear all lists.
106  void reset();
107 
108 private:
109  void processCompileUnit(DICompileUnit *CU);
110  void processScope(DIScope *Scope);
111  void processType(DIType *DT);
112  bool addCompileUnit(DICompileUnit *CU);
113  bool addGlobalVariable(DIGlobalVariableExpression *DIG);
114  bool addScope(DIScope *Scope);
115  bool addSubprogram(DISubprogram *SP);
116  bool addType(DIType *DT);
117 
118 public:
119  using compile_unit_iterator =
126 
128  return make_range(CUs.begin(), CUs.end());
129  }
130 
132  return make_range(SPs.begin(), SPs.end());
133  }
134 
136  return make_range(GVs.begin(), GVs.end());
137  }
138 
140  return make_range(TYs.begin(), TYs.end());
141  }
142 
144  return make_range(Scopes.begin(), Scopes.end());
145  }
146 
147  unsigned compile_unit_count() const { return CUs.size(); }
148  unsigned global_variable_count() const { return GVs.size(); }
149  unsigned subprogram_count() const { return SPs.size(); }
150  unsigned type_count() const { return TYs.size(); }
151  unsigned scope_count() const { return Scopes.size(); }
152 
153 private:
160 };
161 
162 } // end namespace llvm
163 
164 #endif // LLVM_IR_DEBUGINFO_H
llvm::StripDebugInfo
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:476
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::DIType
Base class for types.
Definition: DebugInfoMetadata.h:662
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::DebugInfoFinder::reset
void reset()
Clear all lists.
Definition: DebugInfo.cpp:139
DebugInfoMetadata.h
llvm::DebugInfoFinder::type_count
unsigned type_count() const
Definition: DebugInfo.h:150
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::findDbgUsers
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Definition: DebugInfo.cpp:102
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1580
llvm::getDISubprogram
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:129
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
llvm::FindDbgAddrUses
TinyPtrVector< DbgVariableIntrinsic * > FindDbgAddrUses(Value *V)
Finds all intrinsics declaring local variables as living in the memory that 'V' points to.
Definition: DebugInfo.cpp:46
STLExtras.h
llvm::DebugInfoFinder::compile_units
iterator_range< compile_unit_iterator > compile_units() const
Definition: DebugInfo.h:127
llvm::DebugInfoFinder
Utility to find all debug info in a module.
Definition: DebugInfo.h:90
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::DebugInfoFinder::type_iterator
SmallVectorImpl< DIType * >::const_iterator type_iterator
Definition: DebugInfo.h:124
llvm::DebugInfoFinder::scope_iterator
SmallVectorImpl< DIScope * >::const_iterator scope_iterator
Definition: DebugInfo.h:125
llvm::Instruction
Definition: Instruction.h:45
llvm::FindDbgDeclareUses
TinyPtrVector< DbgDeclareInst * > FindDbgDeclareUses(Value *V)
Like FindDbgAddrUses, but only returns dbg.declare intrinsics, not dbg.addr.
Definition: DebugInfo.cpp:68
llvm::stripDebugInfo
bool stripDebugInfo(Function &F)
Definition: DebugInfo.cpp:441
SmallPtrSet.h
llvm::DebugInfoFinder::scope_count
unsigned scope_count() const
Definition: DebugInfo.h:151
llvm::DebugInfoFinder::processSubprogram
void processSubprogram(DISubprogram *SP)
Process subprogram.
Definition: DebugInfo.cpp:258
llvm::DbgVariableIntrinsic
This is the common base class for debug info intrinsics for variables.
Definition: IntrinsicInst.h:148
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::DICompileUnit
Compile unit.
Definition: DebugInfoMetadata.h:1335
llvm::findDbgValues
void findDbgValues(SmallVectorImpl< DbgValueInst * > &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: DebugInfo.cpp:76
llvm::SmallVectorImpl::const_iterator
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:563
llvm::DebugInfoFinder::processModule
void processModule(const Module &M)
Process entire module and collect debug info anchors.
Definition: DebugInfo.cpp:148
llvm::DebugInfoFinder::global_variable_expression_iterator
SmallVectorImpl< DIGlobalVariableExpression * >::const_iterator global_variable_expression_iterator
Definition: DebugInfo.h:123
iterator_range.h
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
TinyPtrVector.h
llvm::DebugInfoFinder::global_variables
iterator_range< global_variable_expression_iterator > global_variables() const
Definition: DebugInfo.h:135
llvm::DebugInfoFinder::processLocation
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
Definition: DebugInfo.cpp:201
llvm::DebugInfoFinder::subprograms
iterator_range< subprogram_iterator > subprograms() const
Definition: DebugInfo.h:131
llvm::DebugInfoFinder::subprogram_count
unsigned subprogram_count() const
Definition: DebugInfo.h:149
llvm::DebugInfoFinder::processVariable
void processVariable(const Module &M, const DbgVariableIntrinsic &DVI)
Process DbgVariableIntrinsic.
Definition: DebugInfo.cpp:281
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::updateLoopMetadataDebugLocations
void updateLoopMetadataDebugLocations(Instruction &I, function_ref< Metadata *(Metadata *)> Updater)
Update the debug locations contained within the MD_loop metadata attached to the instruction I,...
Definition: DebugInfo.cpp:374
llvm::DebugInfoFinder::subprogram_iterator
SmallVectorImpl< DISubprogram * >::const_iterator subprogram_iterator
Definition: DebugInfo.h:121
llvm::DIScope
Base class for scope-like contexts.
Definition: DebugInfoMetadata.h:476
llvm::DebugInfoFinder::compile_unit_count
unsigned compile_unit_count() const
Definition: DebugInfo.h:147
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::DIGlobalVariableExpression
A pair of DIGlobalVariable and DIExpression.
Definition: DebugInfoMetadata.h:3401
SmallVector.h
llvm::stripNonLineTableDebugInfo
bool stripNonLineTableDebugInfo(Module &M)
Downgrade the debug info in a module to contain only line table information.
Definition: DebugInfo.cpp:711
LineType::Metadata
@ Metadata
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::DISubprogram
Subprogram description.
Definition: DebugInfoMetadata.h:1820
llvm::getDebugMetadataVersionFromModule
unsigned getDebugMetadataVersionFromModule(const Module &M)
Return Debug Info Metadata Version by checking module flags.
Definition: DebugInfo.cpp:808
llvm::DebugInfoFinder::scopes
iterator_range< scope_iterator > scopes() const
Definition: DebugInfo.h:143
llvm::DebugInfoFinder::types
iterator_range< type_iterator > types() const
Definition: DebugInfo.h:139
llvm::DebugInfoFinder::processInstruction
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
Definition: DebugInfo.cpp:192
llvm::DebugInfoFinder::compile_unit_iterator
SmallVectorImpl< DICompileUnit * >::const_iterator compile_unit_iterator
Definition: DebugInfo.h:120
CU
Definition: AArch64AsmBackend.cpp:501
llvm::DebugInfoFinder::global_variable_count
unsigned global_variable_count() const
Definition: DebugInfo.h:148