1*9880d681SAndroid Build Coastguard Worker //===-- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework -------*- C++ -*--===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H 11*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H 12*9880d681SAndroid Build Coastguard Worker 13*9880d681SAndroid Build Coastguard Worker #include "AddressPool.h" 14*9880d681SAndroid Build Coastguard Worker #include "DwarfStringPool.h" 15*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseMap.h" 16*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/FoldingSet.h" 17*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallVector.h" 18*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/StringMap.h" 19*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Metadata.h" 20*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Allocator.h" 21*9880d681SAndroid Build Coastguard Worker #include <memory> 22*9880d681SAndroid Build Coastguard Worker #include <vector> 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Worker namespace llvm { 25*9880d681SAndroid Build Coastguard Worker class AsmPrinter; 26*9880d681SAndroid Build Coastguard Worker class DbgVariable; 27*9880d681SAndroid Build Coastguard Worker class DwarfCompileUnit; 28*9880d681SAndroid Build Coastguard Worker class DwarfUnit; 29*9880d681SAndroid Build Coastguard Worker class DIEAbbrev; 30*9880d681SAndroid Build Coastguard Worker class MCSymbol; 31*9880d681SAndroid Build Coastguard Worker class DIE; 32*9880d681SAndroid Build Coastguard Worker class LexicalScope; 33*9880d681SAndroid Build Coastguard Worker class StringRef; 34*9880d681SAndroid Build Coastguard Worker class DwarfDebug; 35*9880d681SAndroid Build Coastguard Worker class MCSection; 36*9880d681SAndroid Build Coastguard Worker class MDNode; 37*9880d681SAndroid Build Coastguard Worker class DwarfFile { 38*9880d681SAndroid Build Coastguard Worker // Target of Dwarf emission, used for sizing of abbreviations. 39*9880d681SAndroid Build Coastguard Worker AsmPrinter *Asm; 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Worker BumpPtrAllocator AbbrevAllocator; 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker // Used to uniquely define abbreviations. 44*9880d681SAndroid Build Coastguard Worker FoldingSet<DIEAbbrev> AbbreviationsSet; 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Worker // A list of all the unique abbreviations in use. 47*9880d681SAndroid Build Coastguard Worker std::vector<DIEAbbrev *> Abbreviations; 48*9880d681SAndroid Build Coastguard Worker 49*9880d681SAndroid Build Coastguard Worker // A pointer to all units in the section. 50*9880d681SAndroid Build Coastguard Worker SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs; 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Worker DwarfStringPool StrPool; 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker // Collection of dbg variables of a scope. 55*9880d681SAndroid Build Coastguard Worker DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables; 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Worker // Collection of abstract subprogram DIEs. 58*9880d681SAndroid Build Coastguard Worker DenseMap<const MDNode *, DIE *> AbstractSPDies; 59*9880d681SAndroid Build Coastguard Worker 60*9880d681SAndroid Build Coastguard Worker /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can 61*9880d681SAndroid Build Coastguard Worker /// be shared across CUs, that is why we keep the map here instead 62*9880d681SAndroid Build Coastguard Worker /// of in DwarfCompileUnit. 63*9880d681SAndroid Build Coastguard Worker DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap; 64*9880d681SAndroid Build Coastguard Worker 65*9880d681SAndroid Build Coastguard Worker public: 66*9880d681SAndroid Build Coastguard Worker DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA); 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Worker ~DwarfFile(); 69*9880d681SAndroid Build Coastguard Worker getUnits()70*9880d681SAndroid Build Coastguard Worker const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() { 71*9880d681SAndroid Build Coastguard Worker return CUs; 72*9880d681SAndroid Build Coastguard Worker } 73*9880d681SAndroid Build Coastguard Worker 74*9880d681SAndroid Build Coastguard Worker /// \brief Compute the size and offset of a DIE given an incoming Offset. 75*9880d681SAndroid Build Coastguard Worker unsigned computeSizeAndOffset(DIE &Die, unsigned Offset); 76*9880d681SAndroid Build Coastguard Worker 77*9880d681SAndroid Build Coastguard Worker /// \brief Compute the size and offset of all the DIEs. 78*9880d681SAndroid Build Coastguard Worker void computeSizeAndOffsets(); 79*9880d681SAndroid Build Coastguard Worker 80*9880d681SAndroid Build Coastguard Worker /// \brief Compute the size and offset of all the DIEs in the given unit. 81*9880d681SAndroid Build Coastguard Worker /// \returns The size of the root DIE. 82*9880d681SAndroid Build Coastguard Worker unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU); 83*9880d681SAndroid Build Coastguard Worker 84*9880d681SAndroid Build Coastguard Worker /// Define a unique number for the abbreviation. 85*9880d681SAndroid Build Coastguard Worker /// 86*9880d681SAndroid Build Coastguard Worker /// Compute the abbreviation for \c Die, look up its unique number, and 87*9880d681SAndroid Build Coastguard Worker /// return a reference to it in the uniquing table. 88*9880d681SAndroid Build Coastguard Worker DIEAbbrev &assignAbbrevNumber(DIE &Die); 89*9880d681SAndroid Build Coastguard Worker 90*9880d681SAndroid Build Coastguard Worker /// \brief Add a unit to the list of CUs. 91*9880d681SAndroid Build Coastguard Worker void addUnit(std::unique_ptr<DwarfCompileUnit> U); 92*9880d681SAndroid Build Coastguard Worker 93*9880d681SAndroid Build Coastguard Worker /// \brief Emit all of the units to the section listed with the given 94*9880d681SAndroid Build Coastguard Worker /// abbreviation section. 95*9880d681SAndroid Build Coastguard Worker void emitUnits(bool UseOffsets); 96*9880d681SAndroid Build Coastguard Worker 97*9880d681SAndroid Build Coastguard Worker /// \brief Emit the given unit to its section. 98*9880d681SAndroid Build Coastguard Worker void emitUnit(DwarfUnit *U, bool UseOffsets); 99*9880d681SAndroid Build Coastguard Worker 100*9880d681SAndroid Build Coastguard Worker /// \brief Emit a set of abbreviations to the specific section. 101*9880d681SAndroid Build Coastguard Worker void emitAbbrevs(MCSection *); 102*9880d681SAndroid Build Coastguard Worker 103*9880d681SAndroid Build Coastguard Worker /// \brief Emit all of the strings to the section given. 104*9880d681SAndroid Build Coastguard Worker void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr); 105*9880d681SAndroid Build Coastguard Worker 106*9880d681SAndroid Build Coastguard Worker /// \brief Returns the string pool. getStringPool()107*9880d681SAndroid Build Coastguard Worker DwarfStringPool &getStringPool() { return StrPool; } 108*9880d681SAndroid Build Coastguard Worker 109*9880d681SAndroid Build Coastguard Worker /// \returns false if the variable was merged with a previous one. 110*9880d681SAndroid Build Coastguard Worker bool addScopeVariable(LexicalScope *LS, DbgVariable *Var); 111*9880d681SAndroid Build Coastguard Worker getScopeVariables()112*9880d681SAndroid Build Coastguard Worker DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() { 113*9880d681SAndroid Build Coastguard Worker return ScopeVariables; 114*9880d681SAndroid Build Coastguard Worker } 115*9880d681SAndroid Build Coastguard Worker getAbstractSPDies()116*9880d681SAndroid Build Coastguard Worker DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { 117*9880d681SAndroid Build Coastguard Worker return AbstractSPDies; 118*9880d681SAndroid Build Coastguard Worker } 119*9880d681SAndroid Build Coastguard Worker insertDIE(const MDNode * TypeMD,DIE * Die)120*9880d681SAndroid Build Coastguard Worker void insertDIE(const MDNode *TypeMD, DIE *Die) { 121*9880d681SAndroid Build Coastguard Worker DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die)); 122*9880d681SAndroid Build Coastguard Worker } getDIE(const MDNode * TypeMD)123*9880d681SAndroid Build Coastguard Worker DIE *getDIE(const MDNode *TypeMD) { 124*9880d681SAndroid Build Coastguard Worker return DITypeNodeToDieMap.lookup(TypeMD); 125*9880d681SAndroid Build Coastguard Worker } 126*9880d681SAndroid Build Coastguard Worker }; 127*9880d681SAndroid Build Coastguard Worker } 128*9880d681SAndroid Build Coastguard Worker #endif 129