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