LLVM 22.0.0git
DwarfFile.h
Go to the documentation of this file.
1//===- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework ---------*- 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#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
10#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
11
12#include "DwarfStringPool.h"
13#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/CodeGen/DIE.h"
19#include <map>
20#include <memory>
21#include <utility>
22
23namespace llvm {
24
25class AsmPrinter;
26class DbgEntity;
27class DbgVariable;
28class DbgLabel;
29class DINode;
30class DILocalScope;
31class DISubprogram;
33class DwarfUnit;
34class LexicalScope;
35class MCSection;
36class MDNode;
37
38// Data structure to hold a range for range lists.
39struct RangeSpan {
41 const MCSymbol *End;
42
43 bool operator==(const RangeSpan &Other) const {
44 return Begin == Other.Begin && End == Other.End;
45 }
46};
47
49 // Index for locating within the debug_range section this particular span.
52 // List of ranges.
54};
55
56class DwarfFile {
57 // Target of Dwarf emission, used for sizing of abbreviations.
58 AsmPrinter *Asm;
59
60 BumpPtrAllocator AbbrevAllocator;
61
62 // Used to uniquely define abbreviations.
63 DIEAbbrevSet Abbrevs;
64
65 // A pointer to all units in the section.
67
68 DwarfStringPool StrPool;
69
70 // List of range lists for a given compile unit, separate from the ranges for
71 // the CU itself.
73
74 /// DWARF v5: The symbol that designates the start of the contribution to
75 /// the string offsets table. The contribution is shared by all units.
76 MCSymbol *StringOffsetsStartSym = nullptr;
77
78 /// DWARF v5: The symbol that designates the base of the range list table.
79 /// The table is shared by all units.
80 MCSymbol *RnglistsTableBaseSym = nullptr;
81
82 /// The variables of a lexical scope.
83 struct ScopeVars {
84 /// We need to sort Args by ArgNo and check for duplicates. This could also
85 /// be implemented as a list or vector + std::lower_bound().
86 std::map<unsigned, DbgVariable *> Args;
88 };
89 /// Collection of DbgVariables of each lexical scope.
91
92 /// Collection of DbgLabels of each lexical scope.
93 using LabelList = SmallVector<DbgLabel *, 4>;
95
96 // Collection of abstract subprogram DIEs.
97 DenseMap<const DILocalScope *, DIE *> AbstractLocalScopeDIEs;
99 /// Keeps track of abstract subprograms to populate them only once.
100 // FIXME: merge creation and population of abstract scopes.
101 SmallPtrSet<const DISubprogram *, 8> FinalizedAbstractSubprograms;
102
103 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
104 /// be shared across CUs, that is why we keep the map here instead
105 /// of in DwarfCompileUnit.
106 DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
107
108public:
110
114
115 std::pair<uint32_t, RangeSpanList *> addRange(const DwarfCompileUnit &CU,
117
118 /// getRangeLists - Get the vector of range lists.
120 return CURangeLists;
121 }
122
123 /// Compute the size and offset of a DIE given an incoming Offset.
124 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
125
126 /// Compute the size and offset of all the DIEs.
128
129 /// Compute the size and offset of all the DIEs in the given unit.
130 /// \returns The size of the root DIE.
132
133 /// Add a unit to the list of CUs.
134 void addUnit(std::unique_ptr<DwarfCompileUnit> U);
135
136 /// Emit all of the units to the section listed with the given
137 /// abbreviation section.
138 void emitUnits(bool UseOffsets);
139
140 /// Emit the given unit to its section.
141 void emitUnit(DwarfUnit *TheU, bool UseOffsets);
142
143 /// Emit a set of abbreviations to the specific section.
144 void emitAbbrevs(MCSection *);
145
146 /// Emit all of the strings to the section given. If OffsetSection is
147 /// non-null, emit a table of string offsets to it. If UseRelativeOffsets
148 /// is false, emit absolute offsets to the strings. Otherwise, emit
149 /// relocatable references to the strings if they are supported by the target.
150 void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr,
151 bool UseRelativeOffsets = false);
152
153 /// Returns the string pool.
154 DwarfStringPool &getStringPool() { return StrPool; }
155
156 MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }
157 void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; }
158
159 MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; }
160 void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; }
161
163
164 void addScopeLabel(LexicalScope *LS, DbgLabel *Label);
165
167 return ScopeVariables;
168 }
169
171 return ScopeLabels;
172 }
173
175 return AbstractLocalScopeDIEs;
176 }
177
181
183 return FinalizedAbstractSubprograms;
184 }
185
186 void insertDIE(const MDNode *TypeMD, DIE *Die) {
187 DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
188 }
189
190 DIE *getDIE(const MDNode *TypeMD) {
191 return DITypeNodeToDieMap.lookup(TypeMD);
192 }
193};
194
195} // end namespace llvm
196
197#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
This file defines the BumpPtrAllocator interface.
This file defines the DenseMap class.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:90
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition DIE.h:141
A structured debug information entry.
Definition DIE.h:828
A scope for locals.
Tagged DWARF-like metadata node.
Subprogram description. Uses SubclassData1.
This class is defined as the common parent of DbgVariable and DbgLabel such that it could levarage po...
Definition DwarfDebug.h:65
This class is used to track label information.
Definition DwarfDebug.h:289
This class is used to track local variable information.
Definition DwarfDebug.h:214
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset)
Compute the size and offset of a DIE given an incoming Offset.
Definition DwarfFile.cpp:92
void addScopeLabel(LexicalScope *LS, DbgLabel *Label)
void addUnit(std::unique_ptr< DwarfCompileUnit > U)
Add a unit to the list of CUs.
Definition DwarfFile.cpp:23
void computeSizeAndOffsets()
Compute the size and offset of all the DIEs.
Definition DwarfFile.cpp:57
void setRnglistsTableBaseSym(MCSymbol *Sym)
Definition DwarfFile.h:160
DenseMap< LexicalScope *, ScopeVars > & getScopeVariables()
Definition DwarfFile.h:166
DenseMap< const DINode *, std::unique_ptr< DbgEntity > > & getAbstractEntities()
Definition DwarfFile.h:178
unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU)
Compute the size and offset of all the DIEs in the given unit.
Definition DwarfFile.cpp:80
void emitUnits(bool UseOffsets)
Emit all of the units to the section listed with the given abbreviation section.
Definition DwarfFile.cpp:29
void emitUnit(DwarfUnit *TheU, bool UseOffsets)
Emit the given unit to its section.
Definition DwarfFile.cpp:34
const SmallVectorImpl< RangeSpanList > & getRangeLists() const
getRangeLists - Get the vector of range lists.
Definition DwarfFile.h:119
MCSymbol * getStringOffsetsStartSym() const
Definition DwarfFile.h:156
MCSymbol * getRnglistsTableBaseSym() const
Definition DwarfFile.h:159
DwarfStringPool & getStringPool()
Returns the string pool.
Definition DwarfFile.h:154
void emitAbbrevs(MCSection *)
Emit a set of abbreviations to the specific section.
Definition DwarfFile.cpp:97
DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
Definition DwarfFile.cpp:20
void emitStrings(MCSection *StrSection, MCSection *OffsetSection=nullptr, bool UseRelativeOffsets=false)
Emit all of the strings to the section given.
DenseMap< LexicalScope *, LabelList > & getScopeLabels()
Definition DwarfFile.h:170
void addScopeVariable(LexicalScope *LS, DbgVariable *Var)
std::pair< uint32_t, RangeSpanList * > addRange(const DwarfCompileUnit &CU, SmallVector< RangeSpan, 2 > R)
DenseMap< const DILocalScope *, DIE * > & getAbstractScopeDIEs()
Definition DwarfFile.h:174
void setStringOffsetsStartSym(MCSymbol *Sym)
Definition DwarfFile.h:157
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition DwarfFile.h:111
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition DwarfFile.h:186
DIE * getDIE(const MDNode *TypeMD)
Definition DwarfFile.h:190
auto & getFinalizedAbstractSubprograms()
Definition DwarfFile.h:182
This dwarf writer support class manages information associated with a source file.
Definition DwarfUnit.h:35
This class is used to track scope information.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:521
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Metadata node.
Definition Metadata.h:1077
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
@ Other
Any other memory.
Definition ModRef.h:68
SmallVector< RangeSpan, 2 > Ranges
Definition DwarfFile.h:53
MCSymbol * Label
Definition DwarfFile.h:50
bool operator==(const RangeSpan &Other) const
Definition DwarfFile.h:43
const MCSymbol * End
Definition DwarfFile.h:41
const MCSymbol * Begin
Definition DwarfFile.h:40