Home | History | Annotate | Download | only in AsmPrinter
      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 "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/IR/Metadata.h"
     20 #include "llvm/Support/Allocator.h"
     21 #include <memory>
     22 #include <vector>
     23 
     24 namespace llvm {
     25 class AsmPrinter;
     26 class DbgVariable;
     27 class DwarfCompileUnit;
     28 class DwarfUnit;
     29 class DIEAbbrev;
     30 class MCSymbol;
     31 class DIE;
     32 class LexicalScope;
     33 class StringRef;
     34 class DwarfDebug;
     35 class MCSection;
     36 class MDNode;
     37 class DwarfFile {
     38   // Target of Dwarf emission, used for sizing of abbreviations.
     39   AsmPrinter *Asm;
     40 
     41   BumpPtrAllocator AbbrevAllocator;
     42 
     43   // Used to uniquely define abbreviations.
     44   FoldingSet<DIEAbbrev> AbbreviationsSet;
     45 
     46   // A list of all the unique abbreviations in use.
     47   std::vector<DIEAbbrev *> Abbreviations;
     48 
     49   // A pointer to all units in the section.
     50   SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs;
     51 
     52   DwarfStringPool StrPool;
     53 
     54   // Collection of dbg variables of a scope.
     55   DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
     56 
     57   // Collection of abstract subprogram DIEs.
     58   DenseMap<const MDNode *, DIE *> AbstractSPDies;
     59 
     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 *> DITypeNodeToDieMap;
     64 
     65 public:
     66   DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA);
     67 
     68   ~DwarfFile();
     69 
     70   const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
     71     return CUs;
     72   }
     73 
     74   /// \brief Compute the size and offset of a DIE given an incoming Offset.
     75   unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
     76 
     77   /// \brief Compute the size and offset of all the DIEs.
     78   void computeSizeAndOffsets();
     79 
     80   /// \brief Compute the size and offset of all the DIEs in the given unit.
     81   /// \returns The size of the root DIE.
     82   unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU);
     83 
     84   /// Define a unique number for the abbreviation.
     85   ///
     86   /// Compute the abbreviation for \c Die, look up its unique number, and
     87   /// return a reference to it in the uniquing table.
     88   DIEAbbrev &assignAbbrevNumber(DIE &Die);
     89 
     90   /// \brief Add a unit to the list of CUs.
     91   void addUnit(std::unique_ptr<DwarfCompileUnit> U);
     92 
     93   /// \brief Emit all of the units to the section listed with the given
     94   /// abbreviation section.
     95   void emitUnits(bool UseOffsets);
     96 
     97   /// \brief Emit the given unit to its section.
     98   void emitUnit(DwarfUnit *U, bool UseOffsets);
     99 
    100   /// \brief Emit a set of abbreviations to the specific section.
    101   void emitAbbrevs(MCSection *);
    102 
    103   /// \brief Emit all of the strings to the section given.
    104   void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr);
    105 
    106   /// \brief Returns the string pool.
    107   DwarfStringPool &getStringPool() { return StrPool; }
    108 
    109   /// \returns false if the variable was merged with a previous one.
    110   bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
    111 
    112   DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
    113     return ScopeVariables;
    114   }
    115 
    116   DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
    117     return AbstractSPDies;
    118   }
    119 
    120   void insertDIE(const MDNode *TypeMD, DIE *Die) {
    121     DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
    122   }
    123   DIE *getDIE(const MDNode *TypeMD) {
    124     return DITypeNodeToDieMap.lookup(TypeMD);
    125   }
    126 };
    127 }
    128 #endif
    129