LLVM  10.0.0svn
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"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/CodeGen/DIE.h"
17 #include "llvm/IR/Metadata.h"
18 #include "llvm/Support/Allocator.h"
19 #include <map>
20 #include <memory>
21 #include <utility>
22 
23 namespace llvm {
24 
25 class AsmPrinter;
26 class DbgEntity;
27 class DbgVariable;
28 class DbgLabel;
29 class DwarfCompileUnit;
30 class DwarfUnit;
31 class LexicalScope;
32 class MCSection;
33 
34 // Data structure to hold a range for range lists.
35 struct RangeSpan {
36  const MCSymbol *Begin;
37  const MCSymbol *End;
38 };
39 
41 private:
42  // Index for locating within the debug_range section this particular span.
43  MCSymbol *RangeSym;
44  const DwarfCompileUnit *CU;
45  // List of ranges.
47 
48 public:
51  : RangeSym(Sym), CU(&CU), Ranges(std::move(Ranges)) {}
52  MCSymbol *getSym() const { return RangeSym; }
53  const DwarfCompileUnit &getCU() const { return *CU; }
54  const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
55 };
56 
57 class DwarfFile {
58  // Target of Dwarf emission, used for sizing of abbreviations.
59  AsmPrinter *Asm;
60 
61  BumpPtrAllocator AbbrevAllocator;
62 
63  // Used to uniquely define abbreviations.
64  DIEAbbrevSet Abbrevs;
65 
66  // A pointer to all units in the section.
68 
69  DwarfStringPool StrPool;
70 
71  // List of range lists for a given compile unit, separate from the ranges for
72  // the CU itself.
73  SmallVector<RangeSpanList, 1> CURangeLists;
74 
75  /// DWARF v5: The symbol that designates the start of the contribution to
76  /// the string offsets table. The contribution is shared by all units.
77  MCSymbol *StringOffsetsStartSym = nullptr;
78 
79  /// DWARF v5: The symbol that designates the base of the range list table.
80  /// The table is shared by all units.
81  MCSymbol *RnglistsTableBaseSym = nullptr;
82 
83  /// DWARF v5: The symbol that designates the base of the locations list table.
84  /// The table is shared by all units.
85  MCSymbol *LoclistsTableBaseSym = nullptr;
86 
87  /// The variables of a lexical scope.
88  struct ScopeVars {
89  /// We need to sort Args by ArgNo and check for duplicates. This could also
90  /// be implemented as a list or vector + std::lower_bound().
91  std::map<unsigned, DbgVariable *> Args;
93  };
94  /// Collection of DbgVariables of each lexical scope.
96 
97  /// Collection of DbgLabels of each lexical scope.
100 
101  // Collection of abstract subprogram DIEs.
102  DenseMap<const MDNode *, DIE *> AbstractSPDies;
104 
105  /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
106  /// be shared across CUs, that is why we keep the map here instead
107  /// of in DwarfCompileUnit.
108  DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
109 
110 public:
112 
114  return CUs;
115  }
116 
117  std::pair<uint32_t, RangeSpanList *> addRange(const DwarfCompileUnit &CU,
119 
120  /// getRangeLists - Get the vector of range lists.
122  return CURangeLists;
123  }
124 
125  /// Compute the size and offset of a DIE given an incoming Offset.
126  unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
127 
128  /// Compute the size and offset of all the DIEs.
129  void computeSizeAndOffsets();
130 
131  /// Compute the size and offset of all the DIEs in the given unit.
132  /// \returns The size of the root DIE.
133  unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU);
134 
135  /// Add a unit to the list of CUs.
136  void addUnit(std::unique_ptr<DwarfCompileUnit> U);
137 
138  /// Emit all of the units to the section listed with the given
139  /// abbreviation section.
140  void emitUnits(bool UseOffsets);
141 
142  /// Emit the given unit to its section.
143  void emitUnit(DwarfUnit *TheU, bool UseOffsets);
144 
145  /// Emit a set of abbreviations to the specific section.
146  void emitAbbrevs(MCSection *);
147 
148  /// Emit all of the strings to the section given. If OffsetSection is
149  /// non-null, emit a table of string offsets to it. If UseRelativeOffsets
150  /// is false, emit absolute offsets to the strings. Otherwise, emit
151  /// relocatable references to the strings if they are supported by the target.
152  void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr,
153  bool UseRelativeOffsets = false);
154 
155  /// Returns the string pool.
156  DwarfStringPool &getStringPool() { return StrPool; }
157 
158  MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }
159  void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; }
160 
161  MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; }
162  void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; }
163 
164  MCSymbol *getLoclistsTableBaseSym() const { return LoclistsTableBaseSym; }
165  void setLoclistsTableBaseSym(MCSymbol *Sym) { LoclistsTableBaseSym = Sym; }
166 
167  /// \returns false if the variable was merged with a previous one.
168  bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
169 
170  void addScopeLabel(LexicalScope *LS, DbgLabel *Label);
171 
173  return ScopeVariables;
174  }
175 
177  return ScopeLabels;
178  }
179 
181  return AbstractSPDies;
182  }
183 
185  return AbstractEntities;
186  }
187 
188  void insertDIE(const MDNode *TypeMD, DIE *Die) {
189  DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
190  }
191 
192  DIE *getDIE(const MDNode *TypeMD) {
193  return DITypeNodeToDieMap.lookup(TypeMD);
194  }
195 };
196 
197 } // end namespace llvm
198 
199 #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void setRnglistsTableBaseSym(MCSymbol *Sym)
Definition: DwarfFile.h:162
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
const SmallVectorImpl< RangeSpanList > & getRangeLists() const
getRangeLists - Get the vector of range lists.
Definition: DwarfFile.h:121
This file contains the declarations for metadata subclasses.
Metadata node.
Definition: Metadata.h:863
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:44
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:195
MCSymbol * getRnglistsTableBaseSym() const
Definition: DwarfFile.h:161
Definition: BitVector.h:937
MCSymbol * getLoclistsTableBaseSym() const
Definition: DwarfFile.h:164
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
DenseMap< LexicalScope *, ScopeVars > & getScopeVariables()
Definition: DwarfFile.h:172
const MCSymbol * Begin
Definition: DwarfFile.h:36
const MCSymbol * End
Definition: DwarfFile.h:37
const SmallVectorImpl< RangeSpan > & getRanges() const
Definition: DwarfFile.h:54
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
Definition: DwarfFile.h:180
This class is used to track local variable information.
Definition: DwarfDebug.h:118
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:113
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:135
This class is used to track label information.
Definition: DwarfDebug.h:230
MCSymbol * getStringOffsetsStartSym() const
Definition: DwarfFile.h:158
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:40
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:156
MCSymbol * getSym() const
Definition: DwarfFile.h:52
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:140
RangeSpanList(MCSymbol *Sym, const DwarfCompileUnit &CU, SmallVector< RangeSpan, 2 > Ranges)
Definition: DwarfFile.h:49
A structured debug information entry.
Definition: DIE.h:700
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
DenseMap< const DINode *, std::unique_ptr< DbgEntity > > & getAbstractEntities()
Definition: DwarfFile.h:184
const DwarfCompileUnit & getCU() const
Definition: DwarfFile.h:53
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:188
DenseMap< LexicalScope *, LabelList > & getScopeLabels()
Definition: DwarfFile.h:176
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
void setLoclistsTableBaseSym(MCSymbol *Sym)
Definition: DwarfFile.h:165
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:192
void setStringOffsetsStartSym(MCSymbol *Sym)
Definition: DwarfFile.h:159
static void addRange(SmallVectorImpl< ConstantInt *> &EndPoints, ConstantInt *Low, ConstantInt *High)
Definition: Metadata.cpp:967
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:185
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
constexpr char Args[]
Key for Kernel::Metadata::mArgs.