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 "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/FoldingSet.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/StringMap.h"
17 #include "llvm/Support/Allocator.h"
18 #include "AddressPool.h"
19 #include "DwarfStringPool.h"
38 // Target of Dwarf emission, used for sizing of abbreviations.
43 // Used to uniquely define abbreviations.
44 FoldingSet<DIEAbbrev> AbbreviationsSet;
46 // A list of all the unique abbreviations in use.
47 std::vector<DIEAbbrev *> Abbreviations;
49 // A pointer to all units in the section.
50 SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
52 DwarfStringPool StrPool;
54 // Collection of dbg variables of a scope.
55 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
57 // Collection of abstract subprogram DIEs.
58 DenseMap<const MDNode *, DIE *> AbstractSPDies;
60 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
61 /// be shared across CUs, that is why we keep the map here instead
62 /// of in DwarfCompileUnit.
63 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
66 DwarfFile(AsmPrinter *AP, DwarfDebug &DD, StringRef Pref,
67 BumpPtrAllocator &DA);
71 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
73 /// \brief Compute the size and offset of a DIE given an incoming Offset.
74 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
76 /// \brief Compute the size and offset of all the DIEs.
77 void computeSizeAndOffsets();
79 /// \brief Define a unique number for the abbreviation.
80 void assignAbbrevNumber(DIEAbbrev &Abbrev);
82 /// \brief Add a unit to the list of CUs.
83 void addUnit(std::unique_ptr<DwarfUnit> U);
85 /// \brief Emit all of the units to the section listed with the given
86 /// abbreviation section.
87 void emitUnits(const MCSymbol *ASectionSym);
89 /// \brief Emit a set of abbreviations to the specific section.
90 void emitAbbrevs(const MCSection *);
92 /// \brief Emit all of the strings to the section given.
93 void emitStrings(const MCSection *StrSection,
94 const MCSection *OffsetSection = nullptr);
96 /// \brief Returns the string pool.
97 DwarfStringPool &getStringPool() { return StrPool; }
99 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
101 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
102 return ScopeVariables;
105 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
106 return AbstractSPDies;
109 void insertDIE(const MDNode *TypeMD, DIE *Die) {
110 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
112 DIE *getDIE(const MDNode *TypeMD) {
113 return MDTypeNodeToDieMap.lookup(TypeMD);