Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 1 | //===- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework ---------*- C++ -*-===// |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 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 "DwarfStringPool.h" |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/DenseMap.h" |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallVector.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringRef.h" |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/DIE.h" |
David Blaikie | 526f30b | 2017-11-03 20:24:19 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Metadata.h" |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Allocator.h" |
Adrian Prantl | c929f7a | 2018-02-06 22:17:45 +0000 | [diff] [blame] | 20 | #include <map> |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 21 | #include <memory> |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 22 | #include <utility> |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 25 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 26 | class AsmPrinter; |
Hsiangkai Wang | cbc58ad | 2018-07-31 14:48:32 +0000 | [diff] [blame] | 27 | class DbgEntity; |
David Blaikie | f299947 | 2014-10-23 00:16:05 +0000 | [diff] [blame] | 28 | class DbgVariable; |
Hsiangkai Wang | cbc58ad | 2018-07-31 14:48:32 +0000 | [diff] [blame] | 29 | class DbgLabel; |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 30 | class DwarfCompileUnit; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 31 | class DwarfUnit; |
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 MCSection; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 34 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 35 | class DwarfFile { |
| 36 | // Target of Dwarf emission, used for sizing of abbreviations. |
| 37 | AsmPrinter *Asm; |
| 38 | |
Duncan P. N. Exon Smith | 815a6eb5 | 2015-05-27 22:31:41 +0000 | [diff] [blame] | 39 | BumpPtrAllocator AbbrevAllocator; |
| 40 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 41 | // Used to uniquely define abbreviations. |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 42 | DIEAbbrevSet Abbrevs; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 43 | |
| 44 | // A pointer to all units in the section. |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 45 | SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 46 | |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 47 | DwarfStringPool StrPool; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 48 | |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 49 | /// DWARF v5: The symbol that designates the start of the contribution to |
| 50 | /// the string offsets table. The contribution is shared by all units. |
| 51 | MCSymbol *StringOffsetsStartSym = nullptr; |
| 52 | |
Wolfgang Pieb | fcf3810 | 2018-07-12 18:18:21 +0000 | [diff] [blame] | 53 | /// DWARF v5: The symbol that designates the base of the range list table. |
| 54 | /// The table is shared by all units. |
| 55 | MCSymbol *RnglistsTableBaseSym = nullptr; |
| 56 | |
Adrian Prantl | c929f7a | 2018-02-06 22:17:45 +0000 | [diff] [blame] | 57 | /// The variables of a lexical scope. |
| 58 | struct ScopeVars { |
| 59 | /// We need to sort Args by ArgNo and check for duplicates. This could also |
| 60 | /// be implemented as a list or vector + std::lower_bound(). |
| 61 | std::map<unsigned, DbgVariable *> Args; |
| 62 | SmallVector<DbgVariable *, 8> Locals; |
| 63 | }; |
| 64 | /// Collection of DbgVariables of each lexical scope. |
| 65 | DenseMap<LexicalScope *, ScopeVars> ScopeVariables; |
David Blaikie | 80e5b1e | 2014-10-24 17:57:34 +0000 | [diff] [blame] | 66 | |
Hsiangkai Wang | cbc58ad | 2018-07-31 14:48:32 +0000 | [diff] [blame] | 67 | /// Collection of DbgLabels of each lexical scope. |
| 68 | using LabelList = SmallVector<DbgLabel *, 4>; |
| 69 | DenseMap<LexicalScope *, LabelList> ScopeLabels; |
| 70 | |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 71 | // Collection of abstract subprogram DIEs. |
| 72 | DenseMap<const MDNode *, DIE *> AbstractSPDies; |
Hsiangkai Wang | cbc58ad | 2018-07-31 14:48:32 +0000 | [diff] [blame] | 73 | DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities; |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 74 | |
David Blaikie | 9bfd7a9 | 2014-11-04 22:12:18 +0000 | [diff] [blame] | 75 | /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can |
| 76 | /// be shared across CUs, that is why we keep the map here instead |
| 77 | /// of in DwarfCompileUnit. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 78 | DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap; |
David Blaikie | 9bfd7a9 | 2014-11-04 22:12:18 +0000 | [diff] [blame] | 79 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 80 | public: |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 81 | DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 82 | |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 83 | const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() { |
| 84 | return CUs; |
| 85 | } |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 86 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 87 | /// Compute the size and offset of a DIE given an incoming Offset. |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 88 | unsigned computeSizeAndOffset(DIE &Die, unsigned Offset); |
| 89 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 90 | /// Compute the size and offset of all the DIEs. |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 91 | void computeSizeAndOffsets(); |
| 92 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 93 | /// Compute the size and offset of all the DIEs in the given unit. |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 94 | /// \returns The size of the root DIE. |
| 95 | unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU); |
| 96 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 97 | /// Add a unit to the list of CUs. |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 98 | void addUnit(std::unique_ptr<DwarfCompileUnit> U); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 99 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 100 | /// Emit all of the units to the section listed with the given |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 101 | /// abbreviation section. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 102 | void emitUnits(bool UseOffsets); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 103 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 104 | /// Emit the given unit to its section. |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 105 | void emitUnit(DwarfUnit *U, bool UseOffsets); |
| 106 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 107 | /// Emit a set of abbreviations to the specific section. |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 108 | void emitAbbrevs(MCSection *); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 109 | |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 110 | /// Emit all of the strings to the section given. If OffsetSection is |
| 111 | /// non-null, emit a table of string offsets to it. If UseRelativeOffsets |
| 112 | /// is false, emit absolute offsets to the strings. Otherwise, emit |
| 113 | /// relocatable references to the strings if they are supported by the target. |
| 114 | void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr, |
| 115 | bool UseRelativeOffsets = false); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 116 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 117 | /// Returns the string pool. |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 118 | DwarfStringPool &getStringPool() { return StrPool; } |
David Blaikie | f299947 | 2014-10-23 00:16:05 +0000 | [diff] [blame] | 119 | |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 120 | MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; } |
| 121 | |
| 122 | void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; } |
| 123 | |
Wolfgang Pieb | fcf3810 | 2018-07-12 18:18:21 +0000 | [diff] [blame] | 124 | MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; } |
| 125 | |
| 126 | void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; } |
| 127 | |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 128 | /// \returns false if the variable was merged with a previous one. |
| 129 | bool addScopeVariable(LexicalScope *LS, DbgVariable *Var); |
David Blaikie | 80e5b1e | 2014-10-24 17:57:34 +0000 | [diff] [blame] | 130 | |
Hsiangkai Wang | cbc58ad | 2018-07-31 14:48:32 +0000 | [diff] [blame] | 131 | void addScopeLabel(LexicalScope *LS, DbgLabel *Label); |
| 132 | |
Adrian Prantl | c929f7a | 2018-02-06 22:17:45 +0000 | [diff] [blame] | 133 | DenseMap<LexicalScope *, ScopeVars> &getScopeVariables() { |
David Blaikie | 80e5b1e | 2014-10-24 17:57:34 +0000 | [diff] [blame] | 134 | return ScopeVariables; |
| 135 | } |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 136 | |
Hsiangkai Wang | cbc58ad | 2018-07-31 14:48:32 +0000 | [diff] [blame] | 137 | DenseMap<LexicalScope *, LabelList> &getScopeLabels() { |
| 138 | return ScopeLabels; |
| 139 | } |
| 140 | |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 141 | DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { |
| 142 | return AbstractSPDies; |
| 143 | } |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 144 | |
Hsiangkai Wang | cbc58ad | 2018-07-31 14:48:32 +0000 | [diff] [blame] | 145 | DenseMap<const DINode *, std::unique_ptr<DbgEntity>> &getAbstractEntities() { |
| 146 | return AbstractEntities; |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 147 | } |
David Blaikie | 9bfd7a9 | 2014-11-04 22:12:18 +0000 | [diff] [blame] | 148 | |
| 149 | void insertDIE(const MDNode *TypeMD, DIE *Die) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 150 | DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die)); |
David Blaikie | 9bfd7a9 | 2014-11-04 22:12:18 +0000 | [diff] [blame] | 151 | } |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 152 | |
David Blaikie | 9bfd7a9 | 2014-11-04 22:12:18 +0000 | [diff] [blame] | 153 | DIE *getDIE(const MDNode *TypeMD) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 154 | return DITypeNodeToDieMap.lookup(TypeMD); |
David Blaikie | 9bfd7a9 | 2014-11-04 22:12:18 +0000 | [diff] [blame] | 155 | } |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 156 | }; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 157 | |
| 158 | } // end namespace llvm |
| 159 | |
| 160 | #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H |