LLVM  3.7.0
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 "AddressPool.h"
14 #include "DwarfStringPool.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/FoldingSet.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringMap.h"
19 #include "llvm/Support/Allocator.h"
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 namespace llvm {
25 class AsmPrinter;
26 class DbgVariable;
27 class DwarfUnit;
28 class DIEAbbrev;
29 class MCSymbol;
30 class DIE;
31 class LexicalScope;
32 class StringRef;
33 class DwarfDebug;
34 class MCSection;
35 class MDNode;
36 class DwarfFile {
37  // Target of Dwarf emission, used for sizing of abbreviations.
38  AsmPrinter *Asm;
39 
40  BumpPtrAllocator AbbrevAllocator;
41 
42  // Used to uniquely define abbreviations.
43  FoldingSet<DIEAbbrev> AbbreviationsSet;
44 
45  // A list of all the unique abbreviations in use.
46  std::vector<DIEAbbrev *> Abbreviations;
47 
48  // A pointer to all units in the section.
50 
51  DwarfStringPool StrPool;
52 
53  // Collection of dbg variables of a scope.
55 
56  // Collection of abstract subprogram DIEs.
57  DenseMap<const MDNode *, DIE *> AbstractSPDies;
58 
59  /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
60  /// be shared across CUs, that is why we keep the map here instead
61  /// of in DwarfCompileUnit.
62  DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
63 
64 public:
66 
67  ~DwarfFile();
68 
70 
71  /// \brief Compute the size and offset of a DIE given an incoming Offset.
72  unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
73 
74  /// \brief Compute the size and offset of all the DIEs.
75  void computeSizeAndOffsets();
76 
77  /// Define a unique number for the abbreviation.
78  ///
79  /// Compute the abbreviation for \c Die, look up its unique number, and
80  /// return a reference to it in the uniquing table.
82 
83  /// \brief Add a unit to the list of CUs.
84  void addUnit(std::unique_ptr<DwarfUnit> U);
85 
86  /// \brief Emit all of the units to the section listed with the given
87  /// abbreviation section.
88  void emitUnits(bool UseOffsets);
89 
90  /// \brief Emit a set of abbreviations to the specific section.
91  void emitAbbrevs(MCSection *);
92 
93  /// \brief Emit all of the strings to the section given.
94  void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr);
95 
96  /// \brief Returns the string pool.
97  DwarfStringPool &getStringPool() { return StrPool; }
98 
99  /// \returns false if the variable was merged with a previous one.
101 
103  return ScopeVariables;
104  }
105 
107  return AbstractSPDies;
108  }
109 
110  void insertDIE(const MDNode *TypeMD, DIE *Die) {
111  DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
112  }
113  DIE *getDIE(const MDNode *TypeMD) {
114  return DITypeNodeToDieMap.lookup(TypeMD);
115  }
116 };
117 }
118 #endif
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
Definition: DwarfFile.cpp:20
DenseMap< LexicalScope *, SmallVector< DbgVariable *, 8 > > & getScopeVariables()
Definition: DwarfFile.h:102
Metadata node.
Definition: Metadata.h:740
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:45
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APInt.h:33
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
Definition: DwarfFile.h:106
This class is used to track local variable information.
Definition: DwarfDebug.h:81
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:97
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:135
DIE - A structured debug information entry.
Definition: DIE.h:623
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:66
void emitUnits(bool UseOffsets)
Emit all of the units to the section listed with the given abbreviation section.
Definition: DwarfFile.cpp:59
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
Definition: FoldingSet.h:396
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:110
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
DIEAbbrev & assignAbbrevNumber(DIE &Die)
Define a unique number for the abbreviation.
Definition: DwarfFile.cpp:30
void computeSizeAndOffsets()
Compute the size and offset of all the DIEs.
Definition: DwarfFile.cpp:72
void emitAbbrevs(MCSection *)
Emit a set of abbreviations to the specific section.
Definition: DwarfFile.cpp:124
bool addScopeVariable(LexicalScope *LS, DbgVariable *Var)
Definition: DwarfFile.cpp:138
DIEAbbrev - Dwarf abbreviation, describes the organization of a debug information object...
Definition: DIE.h:59
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:113
const SmallVectorImpl< std::unique_ptr< DwarfUnit > > & getUnits()
Definition: DwarfFile.h:69
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset)
Compute the size and offset of a DIE given an incoming Offset.
Definition: DwarfFile.cpp:93
void emitStrings(MCSection *StrSection, MCSection *OffsetSection=nullptr)
Emit all of the strings to the section given.
Definition: DwarfFile.cpp:134
void addUnit(std::unique_ptr< DwarfUnit > U)
Add a unit to the list of CUs.
Definition: DwarfFile.cpp:53
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40