1 //===-- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework -------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
11 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
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/CodeGen/DIE.h"
20 #include "llvm/IR/Metadata.h"
21 #include "llvm/Support/Allocator.h"
27 class DwarfCompileUnit;
38 // Target of Dwarf emission, used for sizing of abbreviations.
41 BumpPtrAllocator AbbrevAllocator;
43 // Used to uniquely define abbreviations.
46 // A pointer to all units in the section.
47 SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs;
49 DwarfStringPool StrPool;
51 // Collection of dbg variables of a scope.
52 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
54 // Collection of abstract subprogram DIEs.
55 DenseMap<const MDNode *, DIE *> AbstractSPDies;
56 DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
58 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
59 /// be shared across CUs, that is why we keep the map here instead
60 /// of in DwarfCompileUnit.
61 DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
64 DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA);
66 const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
70 /// \brief Compute the size and offset of a DIE given an incoming Offset.
71 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
73 /// \brief Compute the size and offset of all the DIEs.
74 void computeSizeAndOffsets();
76 /// \brief Compute the size and offset of all the DIEs in the given unit.
77 /// \returns The size of the root DIE.
78 unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU);
80 /// \brief Add a unit to the list of CUs.
81 void addUnit(std::unique_ptr<DwarfCompileUnit> U);
83 /// \brief Emit all of the units to the section listed with the given
84 /// abbreviation section.
85 void emitUnits(bool UseOffsets);
87 /// \brief Emit the given unit to its section.
88 void emitUnit(DwarfUnit *U, bool UseOffsets);
90 /// \brief Emit a set of abbreviations to the specific section.
91 void emitAbbrevs(MCSection *);
93 /// \brief Emit all of the strings to the section given.
94 void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr);
96 /// \brief Returns the string pool.
97 DwarfStringPool &getStringPool() { return StrPool; }
99 /// \returns false if the variable was merged with a previous one.
100 bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
102 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
103 return ScopeVariables;
106 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
107 return AbstractSPDies;
109 DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> &getAbstractVariables() {
110 return AbstractVariables;
113 void insertDIE(const MDNode *TypeMD, DIE *Die) {
114 DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
116 DIE *getDIE(const MDNode *TypeMD) {
117 return DITypeNodeToDieMap.lookup(TypeMD);