David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 10 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H |
| 11 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 12 | |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 13 | #include "AddressPool.h" |
| 14 | #include "DwarfStringPool.h" |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 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/Support/Allocator.h" |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 20 | #include <memory> |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
| 25 | class AsmPrinter; |
David Blaikie | f299947 | 2014-10-23 00:16:05 +0000 | [diff] [blame] | 26 | class DbgVariable; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 27 | class DwarfUnit; |
| 28 | class DIEAbbrev; |
| 29 | class MCSymbol; |
| 30 | class DIE; |
David Blaikie | 1d96cc2 | 2014-10-31 22:30:30 +0000 | [diff] [blame] | 31 | class DISubprogram; |
David Blaikie | f299947 | 2014-10-23 00:16:05 +0000 | [diff] [blame] | 32 | class LexicalScope; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 33 | class StringRef; |
| 34 | class DwarfDebug; |
| 35 | class MCSection; |
| 36 | class DwarfFile { |
| 37 | // Target of Dwarf emission, used for sizing of abbreviations. |
| 38 | AsmPrinter *Asm; |
| 39 | |
David Blaikie | 2b22b1e | 2014-10-23 00:16:03 +0000 | [diff] [blame] | 40 | DwarfDebug ⅅ |
| 41 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 42 | // Used to uniquely define abbreviations. |
| 43 | FoldingSet<DIEAbbrev> AbbreviationsSet; |
| 44 | |
| 45 | // A list of all the unique abbreviations in use. |
| 46 | std::vector<DIEAbbrev *> Abbreviations; |
| 47 | |
| 48 | // A pointer to all units in the section. |
| 49 | SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs; |
| 50 | |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 51 | DwarfStringPool StrPool; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 52 | |
David Blaikie | 80e5b1e | 2014-10-24 17:57:34 +0000 | [diff] [blame] | 53 | // Collection of dbg variables of a scope. |
| 54 | DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables; |
| 55 | |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 56 | // Collection of abstract subprogram DIEs. |
| 57 | DenseMap<const MDNode *, DIE *> AbstractSPDies; |
| 58 | |
David Blaikie | 9bfd7a9 | 2014-11-04 22:12:18 +0000 | [diff] [blame] | 59 | /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can |
| 60 | /// be shared across CUs, that is why we keep the map here instead |
| 61 | /// of in DwarfCompileUnit. |
| 62 | DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap; |
| 63 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 64 | public: |
David Blaikie | 2b22b1e | 2014-10-23 00:16:03 +0000 | [diff] [blame] | 65 | DwarfFile(AsmPrinter *AP, DwarfDebug &DD, StringRef Pref, |
| 66 | BumpPtrAllocator &DA); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 67 | |
| 68 | ~DwarfFile(); |
| 69 | |
| 70 | const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; } |
| 71 | |
| 72 | /// \brief Compute the size and offset of a DIE given an incoming Offset. |
| 73 | unsigned computeSizeAndOffset(DIE &Die, unsigned Offset); |
| 74 | |
| 75 | /// \brief Compute the size and offset of all the DIEs. |
| 76 | void computeSizeAndOffsets(); |
| 77 | |
| 78 | /// \brief Define a unique number for the abbreviation. |
| 79 | void assignAbbrevNumber(DIEAbbrev &Abbrev); |
| 80 | |
| 81 | /// \brief Add a unit to the list of CUs. |
| 82 | void addUnit(std::unique_ptr<DwarfUnit> U); |
| 83 | |
| 84 | /// \brief Emit all of the units to the section listed with the given |
| 85 | /// abbreviation section. |
David Blaikie | 2b22b1e | 2014-10-23 00:16:03 +0000 | [diff] [blame] | 86 | void emitUnits(const MCSymbol *ASectionSym); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 87 | |
| 88 | /// \brief Emit a set of abbreviations to the specific section. |
| 89 | void emitAbbrevs(const MCSection *); |
| 90 | |
| 91 | /// \brief Emit all of the strings to the section given. |
| 92 | void emitStrings(const MCSection *StrSection, |
David Blaikie | 6741bb0 | 2014-09-11 21:12:48 +0000 | [diff] [blame] | 93 | const MCSection *OffsetSection = nullptr); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 94 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 95 | /// \brief Returns the string pool. |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 96 | DwarfStringPool &getStringPool() { return StrPool; } |
David Blaikie | f299947 | 2014-10-23 00:16:05 +0000 | [diff] [blame] | 97 | |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame^] | 98 | /// \returns false if the variable was merged with a previous one. |
| 99 | bool addScopeVariable(LexicalScope *LS, DbgVariable *Var); |
David Blaikie | 80e5b1e | 2014-10-24 17:57:34 +0000 | [diff] [blame] | 100 | |
| 101 | DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() { |
| 102 | return ScopeVariables; |
| 103 | } |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 104 | |
| 105 | DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { |
| 106 | return AbstractSPDies; |
| 107 | } |
David Blaikie | 9bfd7a9 | 2014-11-04 22:12:18 +0000 | [diff] [blame] | 108 | |
| 109 | void insertDIE(const MDNode *TypeMD, DIE *Die) { |
| 110 | MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die)); |
| 111 | } |
| 112 | DIE *getDIE(const MDNode *TypeMD) { |
| 113 | return MDTypeNodeToDieMap.lookup(TypeMD); |
| 114 | } |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 115 | }; |
| 116 | } |
| 117 | #endif |