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. 42 SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs; 43 44 DwarfStringPool StrPool; 45 46 // Collection of dbg variables of a scope. 47 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables; 48 49 // Collection of abstract subprogram DIEs. 50 DenseMap<const MDNode *, DIE *> AbstractSPDies; 51 DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables; 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: 59 DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA); 60 61 const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() { 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. 73 unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU); 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. 95 bool addScopeVariable(LexicalScope *LS, DbgVariable *Var); 96 97 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() { 98 return ScopeVariables; 99 } 100 101 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { 102 return AbstractSPDies; 103 } 104 105 DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> &getAbstractVariables() { 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 121