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