LLVM  6.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 <memory>
21 #include <utility>
22 
23 namespace llvm {
24 
25 class AsmPrinter;
26 class DbgVariable;
27 class DwarfCompileUnit;
28 class DwarfUnit;
29 class LexicalScope;
30 class MCSection;
31 
32 class DwarfFile {
33  // Target of Dwarf emission, used for sizing of abbreviations.
34  AsmPrinter *Asm;
35 
36  BumpPtrAllocator AbbrevAllocator;
37 
38  // Used to uniquely define abbreviations.
39  DIEAbbrevSet Abbrevs;
40 
41  // A pointer to all units in the section.
43 
44  DwarfStringPool StrPool;
45 
46  // Collection of dbg variables of a scope.
48 
49  // Collection of abstract subprogram DIEs.
50  DenseMap<const MDNode *, DIE *> AbstractSPDies;
52 
53  /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
54  /// be shared across CUs, that is why we keep the map here instead
55  /// of in DwarfCompileUnit.
56  DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
57 
58 public:
60 
62  return CUs;
63  }
64 
65  /// \brief Compute the size and offset of a DIE given an incoming Offset.
66  unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
67 
68  /// \brief Compute the size and offset of all the DIEs.
69  void computeSizeAndOffsets();
70 
71  /// \brief Compute the size and offset of all the DIEs in the given unit.
72  /// \returns The size of the root DIE.
74 
75  /// \brief Add a unit to the list of CUs.
76  void addUnit(std::unique_ptr<DwarfCompileUnit> U);
77 
78  /// \brief Emit all of the units to the section listed with the given
79  /// abbreviation section.
80  void emitUnits(bool UseOffsets);
81 
82  /// \brief Emit the given unit to its section.
83  void emitUnit(DwarfUnit *U, bool UseOffsets);
84 
85  /// \brief Emit a set of abbreviations to the specific section.
86  void emitAbbrevs(MCSection *);
87 
88  /// \brief Emit all of the strings to the section given.
89  void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr);
90 
91  /// \brief Returns the string pool.
92  DwarfStringPool &getStringPool() { return StrPool; }
93 
94  /// \returns false if the variable was merged with a previous one.
96 
98  return ScopeVariables;
99  }
100 
102  return AbstractSPDies;
103  }
104 
106  return AbstractVariables;
107  }
108 
109  void insertDIE(const MDNode *TypeMD, DIE *Die) {
110  DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
111  }
112 
113  DIE *getDIE(const MDNode *TypeMD) {
114  return DITypeNodeToDieMap.lookup(TypeMD);
115  }
116 };
117 
118 } // end namespace llvm
119 
120 #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
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset)
Compute the size and offset of a DIE given an incoming Offset.
Definition: DwarfFile.cpp:73
This file contains the declarations for metadata subclasses.
DenseMap< LexicalScope *, SmallVector< DbgVariable *, 8 > > & getScopeVariables()
Definition: DwarfFile.h:97
Metadata node.
Definition: Metadata.h:862
void emitStrings(MCSection *StrSection, MCSection *OffsetSection=nullptr)
Emit all of the strings to the section given.
Definition: DwarfFile.cpp:80
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< const MDNode *, DIE * > & getAbstractSPDies()
Definition: DwarfFile.h:101
This class is used to track local variable information.
Definition: DwarfDebug.h:76
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:61
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:61
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:92
void emitUnit(DwarfUnit *U, bool UseOffsets)
Emit the given unit to its section.
Definition: DwarfFile.cpp:38
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:138
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:77
void computeSizeAndOffsets()
Compute the size and offset of all the DIEs.
Definition: DwarfFile.cpp:49
bool addScopeVariable(LexicalScope *LS, DbgVariable *Var)
Definition: DwarfFile.cpp:84
DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
Definition: DwarfFile.cpp:24
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:109
DenseMap< const MDNode *, std::unique_ptr< DbgVariable > > & getAbstractVariables()
Definition: DwarfFile.h:105
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:113
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 emitAbbrevs(MCSection *)
Emit a set of abbreviations to the specific section.
Definition: DwarfFile.cpp:77
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:33