blob: 405903a173143444100e8572d513c8e93f2bc009 [file] [log] [blame]
David Blaikie319a05f2013-12-02 19:33:10 +00001//===-- llvm/CodeGen/DwarfUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
Devang Patel5eb43192011-04-12 17:40:32 +00002//
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// This file contains support for writing dwarf compile unit.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H
15#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H
Devang Patel5eb43192011-04-12 17:40:32 +000016
Eric Christopher9e429ae2013-10-05 00:27:02 +000017#include "DwarfDebug.h"
Devang Patel5eb43192011-04-12 17:40:32 +000018#include "llvm/ADT/DenseMap.h"
David Blaikief2443192013-10-21 17:28:37 +000019#include "llvm/ADT/Optional.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000020#include "llvm/ADT/StringMap.h"
Adrian Prantl702bf5a2014-03-18 02:34:52 +000021#include "llvm/CodeGen/AsmPrinter.h"
Frederic Risse541e0b2015-01-05 21:29:41 +000022#include "llvm/CodeGen/DIE.h"
Chandler Carruth12664a02014-03-06 00:22:06 +000023#include "llvm/IR/DIBuilder.h"
Chandler Carruth9a4c9e52014-03-06 00:46:21 +000024#include "llvm/IR/DebugInfo.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000025#include "llvm/MC/MCDwarf.h"
David Blaikief3cd7c52013-06-28 20:05:04 +000026#include "llvm/MC/MCExpr.h"
David Blaikie7d734602013-12-06 22:33:05 +000027#include "llvm/MC/MCSection.h"
Devang Patel5eb43192011-04-12 17:40:32 +000028
29namespace llvm {
30
Devang Patelf20c4f72011-04-12 22:53:02 +000031class MachineLocation;
32class MachineOperand;
33class ConstantInt;
David Blaikiea39a76e2013-01-20 01:18:01 +000034class ConstantFP;
Devang Patelf20c4f72011-04-12 22:53:02 +000035class DbgVariable;
David Blaikie15632ae2014-02-12 00:31:30 +000036class DwarfCompileUnit;
Devang Patelf20c4f72011-04-12 22:53:02 +000037
Eric Christopher0f63d062013-12-03 00:45:45 +000038// Data structure to hold a range for range lists.
39class RangeSpan {
40public:
41 RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {}
Eric Christopher270ba4a2013-12-04 19:06:58 +000042 const MCSymbol *getStart() const { return Start; }
43 const MCSymbol *getEnd() const { return End; }
Eric Christopher384f3fe2014-03-20 19:16:16 +000044 void setEnd(const MCSymbol *E) { End = E; }
Eric Christopher0f63d062013-12-03 00:45:45 +000045
46private:
47 const MCSymbol *Start, *End;
48};
49
50class RangeSpanList {
51private:
52 // Index for locating within the debug_range section this particular span.
Eric Christopherf8790642013-12-04 22:04:50 +000053 MCSymbol *RangeSym;
Eric Christopher0f63d062013-12-03 00:45:45 +000054 // List of ranges.
55 SmallVector<RangeSpan, 2> Ranges;
56
57public:
David Blaikie5b02a192014-11-03 23:10:59 +000058 RangeSpanList(MCSymbol *Sym, SmallVector<RangeSpan, 2> Ranges)
59 : RangeSym(Sym), Ranges(std::move(Ranges)) {}
Eric Christopherf8790642013-12-04 22:04:50 +000060 MCSymbol *getSym() const { return RangeSym; }
Eric Christopher0f63d062013-12-03 00:45:45 +000061 const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
62 void addRange(RangeSpan Range) { Ranges.push_back(Range); }
63};
64
Devang Patel5eb43192011-04-12 17:40:32 +000065//===----------------------------------------------------------------------===//
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +000066/// This dwarf writer support class manages information associated with a
67/// source file.
Eric Christophera5a79422013-12-09 23:32:48 +000068class DwarfUnit {
David Blaikie319a05f2013-12-02 19:33:10 +000069protected:
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +000070 /// A numeric ID unique among all CUs in the module
Eli Benderskyb42d1462012-12-03 18:45:45 +000071 unsigned UniqueID;
Devang Patel5eb43192011-04-12 17:40:32 +000072
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +000073 /// MDNode for the compile unit.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000074 const DICompileUnit *CUNode;
David Blaikie7480ae62014-01-09 03:03:27 +000075
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +000076 // All DIEValues are allocated through this allocator.
77 BumpPtrAllocator DIEValueAllocator;
78
David Blaikie2a80e442013-12-02 22:09:48 +000079 /// Unit debug information entry.
Duncan P. N. Exon Smith827200c2015-06-25 23:52:10 +000080 DIE &UnitDie;
Devang Patel5eb43192011-04-12 17:40:32 +000081
David Blaikie2a80e442013-12-02 22:09:48 +000082 /// Offset of the UnitDie from beginning of debug info section.
Eric Christophera16725b2013-11-21 01:29:16 +000083 unsigned DebugInfoOffset;
84
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +000085 /// Target of Dwarf emission.
Devang Patelf20c4f72011-04-12 22:53:02 +000086 AsmPrinter *Asm;
87
Eric Christophere698f532012-12-20 21:58:36 +000088 // Holders for some common dwarf information.
Devang Patelf20c4f72011-04-12 22:53:02 +000089 DwarfDebug *DD;
Eric Christopherf8194852013-12-05 18:06:10 +000090 DwarfFile *DU;
Devang Patelf20c4f72011-04-12 22:53:02 +000091
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +000092 /// An anonymous type for index type. Owned by UnitDie.
Devang Patel5eb43192011-04-12 17:40:32 +000093 DIE *IndexTyDie;
94
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +000095 /// Tracks the mapping of unit level debug information variables to debug
96 /// information entries.
Devang Patel5eb43192011-04-12 17:40:32 +000097 DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
98
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +000099 /// A list of all the DIEBlocks in use.
Devang Patelf20c4f72011-04-12 22:53:02 +0000100 std::vector<DIEBlock *> DIEBlocks;
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000101
102 /// A list of all the DIELocs in use.
Eric Christopher4a741042014-02-16 08:46:55 +0000103 std::vector<DIELoc *> DIELocs;
Devang Patelf20c4f72011-04-12 22:53:02 +0000104
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000105 /// This map is used to keep track of subprogram DIEs that need
106 /// DW_AT_containing_type attribute. This attribute points to a DIE that
Devang Patel89543712011-08-15 17:24:54 +0000107 /// corresponds to the MDNode mapped with the subprogram DIE.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000108 DenseMap<DIE *, const DINode *> ContainingTypeMap;
Devang Patel89543712011-08-15 17:24:54 +0000109
David Blaikie03073f72013-12-06 22:14:48 +0000110 /// The section this unit will be emitted in.
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000111 MCSection *Section;
David Blaikie03073f72013-12-06 22:14:48 +0000112
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000113 DwarfUnit(unsigned UID, dwarf::Tag, const DICompileUnit *CU, AsmPrinter *A,
David Blaikiebd579052014-04-28 21:14:27 +0000114 DwarfDebug *DW, DwarfFile *DWU);
David Blaikie319a05f2013-12-02 19:33:10 +0000115
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000116 /// \brief Add a string attribute data and value.
117 ///
118 /// This is guaranteed to be in the local string pool instead of indirected.
David Blaikiecafd9622014-11-02 08:51:37 +0000119 void addLocalString(DIE &Die, dwarf::Attribute Attribute, StringRef Str);
120
121 void addIndexedString(DIE &Die, dwarf::Attribute Attribute, StringRef Str);
122
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000123 bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie);
David Blaikie3a443c22014-11-04 22:12:25 +0000124
Devang Patel5eb43192011-04-12 17:40:32 +0000125public:
Eric Christophera5a79422013-12-09 23:32:48 +0000126 virtual ~DwarfUnit();
Devang Patel5eb43192011-04-12 17:40:32 +0000127
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000128 void initSection(MCSection *Section);
Rafael Espindola063d7252015-03-10 16:58:10 +0000129
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000130 MCSection *getSection() const {
David Blaikie03073f72013-12-06 22:14:48 +0000131 assert(Section);
132 return Section;
133 }
134
Devang Patel5eb43192011-04-12 17:40:32 +0000135 // Accessors.
Adrian Prantl00dbc2a2015-01-12 22:19:26 +0000136 AsmPrinter* getAsmPrinter() const { return Asm; }
Eric Christopherca68bbf2013-08-26 23:58:22 +0000137 unsigned getUniqueID() const { return UniqueID; }
Duncan P. N. Exon Smith35ef22c2015-04-15 23:19:27 +0000138 uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000139 const DICompileUnit *getCUNode() const { return CUNode; }
David Blaikiebd579052014-04-28 21:14:27 +0000140 DIE &getUnitDie() { return UnitDie; }
Devang Patel5eb43192011-04-12 17:40:32 +0000141
Manman Rence20d462013-10-29 22:57:10 +0000142 unsigned getDebugInfoOffset() const { return DebugInfoOffset; }
143 void setDebugInfoOffset(unsigned DbgInfoOff) { DebugInfoOffset = DbgInfoOff; }
144
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000145 /// \brief Return true if this compile unit has something to write out.
Duncan P. N. Exon Smith8d3197f2015-05-28 19:56:34 +0000146 bool hasContent() const { return UnitDie.hasChildren(); }
Devang Patel5eb43192011-04-12 17:40:32 +0000147
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000148 /// \brief Get string containing language specific context for a global name.
149 ///
150 /// Walks the metadata parent chain in a language specific manner (using the
151 /// compile unit language) and returns it as a string. This is done at the
152 /// metadata level because DIEs may not currently have been added to the
153 /// parent context and walking the DIEs looking for names is more expensive
154 /// than walking the metadata.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000155 std::string getParentContextString(const DIScope *Context) const;
Eric Christopher2c8b7902013-10-17 02:06:06 +0000156
David Blaikie98cf1722014-11-02 06:06:14 +0000157 /// Add a new global name to the compile unit.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000158 virtual void addGlobalName(StringRef Name, DIE &Die, const DIScope *Context) {
Duncan P. N. Exon Smithbe9e4fe2015-04-20 18:32:29 +0000159 }
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000160
David Blaikie98cf1722014-11-02 06:06:14 +0000161 /// Add a new global type to the compile unit.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000162 virtual void addGlobalType(const DIType *Ty, const DIE &Die,
163 const DIScope *Context) {}
David Blaikie98cf1722014-11-02 06:06:14 +0000164
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000165 /// \brief Add a new name to the namespace accelerator table.
David Blaikie65a74662014-04-25 18:26:14 +0000166 void addAccelNamespace(StringRef Name, const DIE &Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000167
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000168 /// \brief Returns the DIE map slot for the specified debug variable.
169 ///
170 /// We delegate the request to DwarfDebug when the MDNode can be part of the
171 /// type system, since DIEs for the type system can be shared across CUs and
172 /// the mappings are kept in DwarfDebug.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000173 DIE *getDIE(const DINode *D) const;
Devang Patel5eb43192011-04-12 17:40:32 +0000174
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000175 /// \brief Returns a fresh newly allocated DIELoc.
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000176 DIELoc *getDIELoc() { return new (DIEValueAllocator) DIELoc; }
Devang Patelf20c4f72011-04-12 22:53:02 +0000177
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000178 /// \brief Insert DIE into the map.
179 ///
180 /// We delegate the request to DwarfDebug when the MDNode can be part of the
181 /// type system, since DIEs for the type system can be shared across CUs and
182 /// the mappings are kept in DwarfDebug.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000183 void insertDIE(const DINode *Desc, DIE *D);
Devang Patel5eb43192011-04-12 17:40:32 +0000184
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000185 /// \brief Add a flag that is true to the DIE.
David Blaikie65a74662014-04-25 18:26:14 +0000186 void addFlag(DIE &Die, dwarf::Attribute Attribute);
Eric Christopher48fef592012-12-20 21:58:40 +0000187
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000188 /// \brief Add an unsigned integer attribute data and value.
David Blaikie65a74662014-04-25 18:26:14 +0000189 void addUInt(DIE &Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
David Blaikief2443192013-10-21 17:28:37 +0000190 uint64_t Integer);
191
David Blaikie65a74662014-04-25 18:26:14 +0000192 void addUInt(DIE &Block, dwarf::Form Form, uint64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000193
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000194 /// \brief Add an signed integer attribute data and value.
David Blaikie65a74662014-04-25 18:26:14 +0000195 void addSInt(DIE &Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
David Blaikief2443192013-10-21 17:28:37 +0000196 int64_t Integer);
197
David Blaikie65a74662014-04-25 18:26:14 +0000198 void addSInt(DIELoc &Die, Optional<dwarf::Form> Form, int64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000199
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000200 /// \brief Add a string attribute data and value.
201 ///
202 /// We always emit a reference to the string pool instead of immediate
203 /// strings so that DIEs have more predictable sizes. In the case of split
204 /// dwarf we emit an index into another table which gets us the static offset
205 /// into the string table.
Craig Topper6dc4a8bc2014-08-30 16:48:02 +0000206 void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str);
Devang Patelf20c4f72011-04-12 22:53:02 +0000207
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000208 /// \brief Add a Dwarf label attribute data and value.
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +0000209 DIE::value_iterator addLabel(DIE &Die, dwarf::Attribute Attribute,
210 dwarf::Form Form, const MCSymbol *Label);
Devang Patelf20c4f72011-04-12 22:53:02 +0000211
David Blaikie65a74662014-04-25 18:26:14 +0000212 void addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label);
David Blaikief2443192013-10-21 17:28:37 +0000213
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000214 /// \brief Add an offset into a section attribute data and value.
David Blaikie65a74662014-04-25 18:26:14 +0000215 void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer);
Eric Christopher33ff6972013-11-21 23:46:41 +0000216
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000217 /// \brief Add a dwarf op address data and value using the form given and an
218 /// op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
David Blaikie65a74662014-04-25 18:26:14 +0000219 void addOpAddress(DIELoc &Die, const MCSymbol *Label);
Eric Christophere9ec2452013-01-18 22:11:33 +0000220
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000221 /// \brief Add a label delta attribute data and value.
David Blaikie65a74662014-04-25 18:26:14 +0000222 void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
David Blaikie48b1bdc2014-03-07 01:30:55 +0000223 const MCSymbol *Lo);
224
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000225 /// \brief Add a DIE attribute data and value.
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000226 void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry);
Eric Christopher48fef592012-12-20 21:58:40 +0000227
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000228 /// \brief Add a DIE attribute data and value.
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000229 void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIEEntry Entry);
Manman Ren4dbdc902013-10-31 17:54:35 +0000230
David Blaikie65a74662014-04-25 18:26:14 +0000231 void addDIETypeSignature(DIE &Die, const DwarfTypeUnit &Type);
David Blaikie47f615e2013-12-17 23:32:35 +0000232
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000233 /// \brief Add block data.
David Blaikie65a74662014-04-25 18:26:14 +0000234 void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Block);
Eric Christopher4a741042014-02-16 08:46:55 +0000235
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000236 /// \brief Add block data.
David Blaikie65a74662014-04-25 18:26:14 +0000237 void addBlock(DIE &Die, dwarf::Attribute Attribute, DIEBlock *Block);
Devang Patelf20c4f72011-04-12 22:53:02 +0000238
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000239 /// \brief Add location information to specified debug information entry.
David Blaikie65a74662014-04-25 18:26:14 +0000240 void addSourceLine(DIE &Die, unsigned Line, StringRef File,
David Blaikie101613e2014-02-12 00:11:25 +0000241 StringRef Directory);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000242 void addSourceLine(DIE &Die, const DILocalVariable *V);
243 void addSourceLine(DIE &Die, const DIGlobalVariable *G);
244 void addSourceLine(DIE &Die, const DISubprogram *SP);
245 void addSourceLine(DIE &Die, const DIType *Ty);
246 void addSourceLine(DIE &Die, const DINamespace *NS);
247 void addSourceLine(DIE &Die, const DIObjCProperty *Ty);
Devang Patelf20c4f72011-04-12 22:53:02 +0000248
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000249 /// \brief Add constant value entry in variable DIE.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000250 void addConstantValue(DIE &Die, const MachineOperand &MO, const DIType *Ty);
251 void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty);
252 void addConstantValue(DIE &Die, const APInt &Val, const DIType *Ty);
David Blaikie65a74662014-04-25 18:26:14 +0000253 void addConstantValue(DIE &Die, const APInt &Val, bool Unsigned);
David Blaikie60cae1b2014-05-11 16:08:41 +0000254 void addConstantValue(DIE &Die, bool Unsigned, uint64_t Val);
Devang Patelf20c4f72011-04-12 22:53:02 +0000255
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000256 /// \brief Add constant value entry in variable DIE.
David Blaikie65a74662014-04-25 18:26:14 +0000257 void addConstantFPValue(DIE &Die, const MachineOperand &MO);
258 void addConstantFPValue(DIE &Die, const ConstantFP *CFP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000259
Paul Robinson857b4432015-03-10 22:44:45 +0000260 /// \brief Add a linkage name, if it isn't empty.
261 void addLinkageName(DIE &Die, StringRef LinkageName);
262
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000263 /// \brief Add template parameters in buffer.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000264 void addTemplateParams(DIE &Buffer, DINodeArray TParams);
Devang Patelf20c4f72011-04-12 22:53:02 +0000265
Adrian Prantlab255fc2014-12-05 01:02:46 +0000266 /// \brief Add register operand.
267 /// \returns false if the register does not exist, e.g., because it was never
268 /// materialized.
269 bool addRegisterOpPiece(DIELoc &TheDie, unsigned Reg,
Adrian Prantlb1416832014-08-01 22:11:58 +0000270 unsigned SizeInBits = 0, unsigned OffsetInBits = 0);
Devang Patelba5fbf12011-04-26 19:06:18 +0000271
Adrian Prantlab255fc2014-12-05 01:02:46 +0000272 /// \brief Add register offset.
273 /// \returns false if the register does not exist, e.g., because it was never
274 /// materialized.
275 bool addRegisterOffset(DIELoc &TheDie, unsigned Reg, int64_t Offset);
Devang Patelba5fbf12011-04-26 19:06:18 +0000276
Devang Patelf20c4f72011-04-12 22:53:02 +0000277 // FIXME: Should be reformulated in terms of addComplexAddress.
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000278 /// Start with the address based on the location provided, and generate the
279 /// DWARF information necessary to find the actual Block variable (navigating
280 /// the Block struct) based on the starting location. Add the DWARF
281 /// information to the die. Obsolete, please use addComplexAddress instead.
David Blaikie65a74662014-04-25 18:26:14 +0000282 void addBlockByrefAddress(const DbgVariable &DV, DIE &Die,
Eric Christophera07e4f52013-11-19 09:28:34 +0000283 dwarf::Attribute Attribute,
Devang Patelf20c4f72011-04-12 22:53:02 +0000284 const MachineLocation &Location);
285
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000286 /// \brief Add a new type attribute to the specified entity.
287 ///
288 /// This takes and attribute parameter because DW_AT_friend attributes are
289 /// also type references.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000290 void addType(DIE &Entity, const DIType *Ty,
Eric Christophera07e4f52013-11-19 09:28:34 +0000291 dwarf::Attribute Attribute = dwarf::DW_AT_type);
Devang Patelf20c4f72011-04-12 22:53:02 +0000292
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000293 DIE *getOrCreateNameSpace(const DINamespace *NS);
294 DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal = false);
Devang Patel89543712011-08-15 17:24:54 +0000295
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000296 void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,
David Blaikie279c4512014-11-02 08:18:06 +0000297 bool Minimal = false);
David Blaikie7f916862014-05-27 18:37:38 +0000298
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000299 /// \brief Find existing DIE or create new DIE for the given type.
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000300 DIE *getOrCreateTypeDIE(const MDNode *N);
Devang Patelf20c4f72011-04-12 22:53:02 +0000301
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000302 /// \brief Get context owner's DIE.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000303 DIE *createTypeDIE(const DICompositeType *Ty);
David Blaikie409dd9c2013-11-19 23:08:21 +0000304
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000305 /// \brief Get context owner's DIE.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000306 DIE *getOrCreateContextDIE(const DIScope *Context);
Devang Patelf20c4f72011-04-12 22:53:02 +0000307
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000308 /// \brief Construct DIEs for types that contain vtables.
Eric Christopherfa205ca2013-10-05 00:05:51 +0000309 void constructContainingTypeDIEs();
Devang Patelf20c4f72011-04-12 22:53:02 +0000310
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000311 /// \brief Construct function argument DIEs.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000312 void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args);
Adrian Prantl69140d22014-02-25 22:27:14 +0000313
Manman Renb987e512013-10-29 00:53:03 +0000314 /// Create a DIE with the given Tag, add the DIE to its parent, and
315 /// call insertDIE if MD is not null.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000316 DIE &createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N = nullptr);
Manman Renb987e512013-10-29 00:53:03 +0000317
David Blaikie6b288cf2013-10-30 20:42:41 +0000318 /// Compute the size of a header for this unit, not including the initial
319 /// length field.
David Blaikiebc563272013-12-13 21:33:40 +0000320 virtual unsigned getHeaderSize() const {
David Blaikie6b288cf2013-10-30 20:42:41 +0000321 return sizeof(int16_t) + // DWARF version number
322 sizeof(int32_t) + // Offset Into Abbrev. Section
323 sizeof(int8_t); // Pointer Size (in bytes)
324 }
325
326 /// Emit the header for this unit, not including the initial length field.
Rafael Espindola063d7252015-03-10 16:58:10 +0000327 virtual void emitHeader(bool UseOffsets);
David Blaikie6b288cf2013-10-30 20:42:41 +0000328
David Blaikie15632ae2014-02-12 00:31:30 +0000329 virtual DwarfCompileUnit &getCU() = 0;
David Blaikied696fac2014-02-12 00:32:05 +0000330
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000331 void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy);
David Blaikiee12b49a2014-04-26 17:27:38 +0000332
David Blaikie319a05f2013-12-02 19:33:10 +0000333protected:
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000334 /// \brief Create new static data member DIE.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000335 DIE *getOrCreateStaticMemberDIE(const DIDerivedType *DT);
David Blaikie319a05f2013-12-02 19:33:10 +0000336
David Blaikie4a2f95f2014-03-18 01:17:26 +0000337 /// Look up the source ID with the given directory and source file names. If
338 /// none currently exists, create a new ID and insert it in the line table.
339 virtual unsigned getOrCreateSourceID(StringRef File, StringRef Directory) = 0;
340
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000341 /// \brief Look in the DwarfDebug map for the MDNode that corresponds to the
342 /// reference.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000343 template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
Duncan P. N. Exon Smith000fa2c2015-04-07 04:14:33 +0000344 return DD->resolve(Ref);
345 }
David Blaikie58410f22014-10-10 06:39:26 +0000346
Eric Christopherfa205ca2013-10-05 00:05:51 +0000347private:
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000348 void constructTypeDIE(DIE &Buffer, const DIBasicType *BTy);
349 void constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy);
350 void constructTypeDIE(DIE &Buffer, const DISubroutineType *DTy);
351 void constructSubrangeDIE(DIE &Buffer, const DISubrange *SR, DIE *IndexTy);
352 void constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy);
353 void constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy);
354 void constructMemberDIE(DIE &Buffer, const DIDerivedType *DT);
Manman Renffc9a712013-10-23 23:05:28 +0000355 void constructTemplateTypeParameterDIE(DIE &Buffer,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000356 const DITemplateTypeParameter *TP);
Manman Renffc9a712013-10-23 23:05:28 +0000357 void constructTemplateValueParameterDIE(DIE &Buffer,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000358 const DITemplateValueParameter *TVP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000359
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000360 /// \brief Return the default lower bound for an array.
361 ///
362 /// If the DWARF version doesn't handle the language, return -1.
Eric Christopherfa205ca2013-10-05 00:05:51 +0000363 int64_t getDefaultLowerBound() const;
364
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000365 /// \brief Get an anonymous type for index type.
David Blaikie871c2d92014-11-02 03:09:13 +0000366 DIE *getIndexTyDie();
Eric Christopherfa205ca2013-10-05 00:05:51 +0000367
Duncan P. N. Exon Smithd89ef162015-04-20 20:29:51 +0000368 /// \brief Set D as anonymous type for index which can be reused later.
Eric Christopherfa205ca2013-10-05 00:05:51 +0000369 void setIndexTyDie(DIE *D) { IndexTyDie = D; }
370
David Blaikie2ea848b2013-11-19 22:51:04 +0000371 /// If this is a named finished type then include it in the list of types for
372 /// the accelerator tables.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000373 void updateAcceleratorTables(const DIScope *Context, const DIType *Ty,
Duncan P. N. Exon Smithbe9e4fe2015-04-20 18:32:29 +0000374 const DIE &TyDIE);
David Blaikiecafd9622014-11-02 08:51:37 +0000375
376 virtual bool isDwoUnit() const = 0;
Devang Patel5eb43192011-04-12 17:40:32 +0000377};
378
Eric Christopher4287a492013-12-09 23:57:44 +0000379class DwarfTypeUnit : public DwarfUnit {
David Blaikiebc563272013-12-13 21:33:40 +0000380 uint64_t TypeSignature;
381 const DIE *Ty;
David Blaikie15632ae2014-02-12 00:31:30 +0000382 DwarfCompileUnit &CU;
David Blaikie8287aff2014-03-18 02:13:23 +0000383 MCDwarfDwoLineTable *SplitLineTable;
David Blaikie319a05f2013-12-02 19:33:10 +0000384
David Blaikiecafd9622014-11-02 08:51:37 +0000385 unsigned getOrCreateSourceID(StringRef File, StringRef Directory) override;
386 bool isDwoUnit() const override;
387
David Blaikie319a05f2013-12-02 19:33:10 +0000388public:
David Blaikiebd579052014-04-28 21:14:27 +0000389 DwarfTypeUnit(unsigned UID, DwarfCompileUnit &CU, AsmPrinter *A,
390 DwarfDebug *DW, DwarfFile *DWU,
David Blaikie8287aff2014-03-18 02:13:23 +0000391 MCDwarfDwoLineTable *SplitLineTable = nullptr);
David Blaikie319a05f2013-12-02 19:33:10 +0000392
David Blaikiebc563272013-12-13 21:33:40 +0000393 void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
David Blaikie47f615e2013-12-17 23:32:35 +0000394 uint64_t getTypeSignature() const { return TypeSignature; }
David Blaikiebc563272013-12-13 21:33:40 +0000395 void setType(const DIE *Ty) { this->Ty = Ty; }
396
David Blaikiebc563272013-12-13 21:33:40 +0000397 /// Emit the header for this unit, not including the initial length field.
Rafael Espindola063d7252015-03-10 16:58:10 +0000398 void emitHeader(bool UseOffsets) override;
Craig Topper73156022014-03-02 09:09:27 +0000399 unsigned getHeaderSize() const override {
David Blaikiebc563272013-12-13 21:33:40 +0000400 return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature
401 sizeof(uint32_t); // Type DIE Offset
402 }
Craig Topper73156022014-03-02 09:09:27 +0000403 DwarfCompileUnit &getCU() override { return CU; }
David Blaikie319a05f2013-12-02 19:33:10 +0000404};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000405} // end llvm namespace
Devang Patel5eb43192011-04-12 17:40:32 +0000406#endif