LLVM  7.0.0svn
DwarfFile.h
Go to the documentation of this file.
1 //===- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
11 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
12 
13 #include "DwarfStringPool.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/CodeGen/DIE.h"
18 #include "llvm/IR/Metadata.h"
19 #include "llvm/Support/Allocator.h"
20 #include <map>
21 #include <memory>
22 #include <utility>
23 
24 namespace llvm {
25 
26 class AsmPrinter;
27 class DbgVariable;
28 class DwarfCompileUnit;
29 class DwarfUnit;
30 class LexicalScope;
31 class MCSection;
32 
33 class DwarfFile {
34  // Target of Dwarf emission, used for sizing of abbreviations.
35  AsmPrinter *Asm;
36 
37  BumpPtrAllocator AbbrevAllocator;
38 
39  // Used to uniquely define abbreviations.
40  DIEAbbrevSet Abbrevs;
41 
42  // A pointer to all units in the section.
44 
45  DwarfStringPool StrPool;
46 
47  /// DWARF v5: The symbol that designates the start of the contribution to
48  /// the string offsets table. The contribution is shared by all units.
49  MCSymbol *StringOffsetsStartSym = nullptr;
50 
51  /// The variables of a lexical scope.
52  struct ScopeVars {
53  /// We need to sort Args by ArgNo and check for duplicates. This could also
54  /// be implemented as a list or vector + std::lower_bound().
55  std::map<unsigned, DbgVariable *> Args;
57  };
58  /// Collection of DbgVariables of each lexical scope.
60 
61  // Collection of abstract subprogram DIEs.
62  DenseMap<const MDNode *, DIE *> AbstractSPDies;
64 
65  /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
66  /// be shared across CUs, that is why we keep the map here instead
67  /// of in DwarfCompileUnit.
68  DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
69 
70 public:
72 
74  return CUs;
75  }
76 
77  /// \brief Compute the size and offset of a DIE given an incoming Offset.
78  unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
79 
80  /// \brief Compute the size and offset of all the DIEs.
81  void computeSizeAndOffsets();
82 
83  /// \brief Compute the size and offset of all the DIEs in the given unit.
84  /// \returns The size of the root DIE.
86 
87  /// \brief Add a unit to the list of CUs.
88  void addUnit(std::unique_ptr<DwarfCompileUnit> U);
89 
90  /// Emit the string table offsets header.
92 
93  /// \brief Emit all of the units to the section listed with the given
94  /// abbreviation section.
95  void emitUnits(bool UseOffsets);
96 
97  /// \brief Emit the given unit to its section.
98  void emitUnit(DwarfUnit *U, bool UseOffsets);
99 
100  /// \brief Emit a set of abbreviations to the specific section.
101  void emitAbbrevs(MCSection *);
102 
103  /// Emit all of the strings to the section given. If OffsetSection is
104  /// non-null, emit a table of string offsets to it. If UseRelativeOffsets
105  /// is false, emit absolute offsets to the strings. Otherwise, emit
106  /// relocatable references to the strings if they are supported by the target.
107  void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr,
108  bool UseRelativeOffsets = false);
109 
110  /// \brief Returns the string pool.
111  DwarfStringPool &getStringPool() { return StrPool; }
112 
113  MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }
114 
115  void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; }
116 
117  /// \returns false if the variable was merged with a previous one.
119 
121  return ScopeVariables;
122  }
123 
125  return AbstractSPDies;
126  }
127 
129  return AbstractVariables;
130  }
131 
132  void insertDIE(const MDNode *TypeMD, DIE *Die) {
133  DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
134  }
135 
136  DIE *getDIE(const MDNode *TypeMD) {
137  return DITypeNodeToDieMap.lookup(TypeMD);
138  }
139 };
140 
141 } // end namespace llvm
142 
143 #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
void addUnit(std::unique_ptr< DwarfCompileUnit > U)
Add a unit to the list of CUs.
Definition: DwarfFile.cpp:27
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset)
Compute the size and offset of a DIE given an incoming Offset.
Definition: DwarfFile.cpp:93
This file contains the declarations for metadata subclasses.
Metadata node.
Definition: Metadata.h:862
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:45
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:191
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
DenseMap< LexicalScope *, ScopeVars > & getScopeVariables()
Definition: DwarfFile.h:120
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
Definition: DwarfFile.h:124
This class is used to track local variable information.
Definition: DwarfDebug.h:76
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:73
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:135
unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU)
Compute the size and offset of all the DIEs in the given unit.
Definition: DwarfFile.cpp:81
MCSymbol * getStringOffsetsStartSym() const
Definition: DwarfFile.h:113
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:68
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:111
void emitUnit(DwarfUnit *U, bool UseOffsets)
Emit the given unit to its section.
Definition: DwarfFile.cpp:58
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:143
A structured debug information entry.
Definition: DIE.h:662
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
void computeSizeAndOffsets()
Compute the size and offset of all the DIEs.
Definition: DwarfFile.cpp:69
bool addScopeVariable(LexicalScope *LS, DbgVariable *Var)
Definition: DwarfFile.cpp:105
DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
Definition: DwarfFile.cpp:24
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:132
DenseMap< const MDNode *, std::unique_ptr< DbgVariable > > & getAbstractVariables()
Definition: DwarfFile.h:128
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:862
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:136
void setStringOffsetsStartSym(MCSymbol *Sym)
Definition: DwarfFile.h:115
void emitStrings(MCSection *StrSection, MCSection *OffsetSection=nullptr, bool UseRelativeOffsets=false)
Emit all of the strings to the section given.
Definition: DwarfFile.cpp:100
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:181
void emitStringOffsetsTableHeader(MCSection *Section)
Emit the string table offsets header.
Definition: DwarfFile.cpp:31
void emitAbbrevs(MCSection *)
Emit a set of abbreviations to the specific section.
Definition: DwarfFile.cpp:97
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void emitUnits(bool UseOffsets)
Emit all of the units to the section listed with the given abbreviation section.
Definition: DwarfFile.cpp:53
constexpr char Args[]
Key for Kernel::Metadata::mArgs.