blob: b354255d70996271bf4cfb5b8c3ed415c15c244a [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//===----------------------------------------------------------------------===//
David Blaikie319a05f2013-12-02 19:33:10 +000066/// Unit - This dwarf writer support class manages information associated
Devang Patel5eb43192011-04-12 17:40:32 +000067/// with a source file.
Eric Christophera5a79422013-12-09 23:32:48 +000068class DwarfUnit {
David Blaikie319a05f2013-12-02 19:33:10 +000069protected:
Eli Benderskyb42d1462012-12-03 18:45:45 +000070 /// UniqueID - 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
David Blaikie7480ae62014-01-09 03:03:27 +000073 /// Node - MDNode for the compile unit.
David Blaikief645f962014-01-09 03:23:41 +000074 DICompileUnit CUNode;
David Blaikie7480ae62014-01-09 03:03:27 +000075
David Blaikie2a80e442013-12-02 22:09:48 +000076 /// Unit debug information entry.
David Blaikiebd579052014-04-28 21:14:27 +000077 DIE UnitDie;
Devang Patel5eb43192011-04-12 17:40:32 +000078
David Blaikie2a80e442013-12-02 22:09:48 +000079 /// Offset of the UnitDie from beginning of debug info section.
Eric Christophera16725b2013-11-21 01:29:16 +000080 unsigned DebugInfoOffset;
81
Devang Patelf20c4f72011-04-12 22:53:02 +000082 /// Asm - Target of Dwarf emission.
83 AsmPrinter *Asm;
84
Eric Christophere698f532012-12-20 21:58:36 +000085 // Holders for some common dwarf information.
Devang Patelf20c4f72011-04-12 22:53:02 +000086 DwarfDebug *DD;
Eric Christopherf8194852013-12-05 18:06:10 +000087 DwarfFile *DU;
Devang Patelf20c4f72011-04-12 22:53:02 +000088
David Blaikie2a80e442013-12-02 22:09:48 +000089 /// IndexTyDie - An anonymous type for index type. Owned by UnitDie.
Devang Patel5eb43192011-04-12 17:40:32 +000090 DIE *IndexTyDie;
91
Eric Christopher61560112013-05-08 00:11:10 +000092 /// MDNodeToDieMap - Tracks the mapping of unit level debug information
Devang Patel5eb43192011-04-12 17:40:32 +000093 /// variables to debug information entries.
94 DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
95
Eric Christopher61560112013-05-08 00:11:10 +000096 /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug information
Devang Patel5eb43192011-04-12 17:40:32 +000097 /// descriptors to debug information entries using a DIEEntry proxy.
98 DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
99
Devang Patelf20c4f72011-04-12 22:53:02 +0000100 /// DIEBlocks - A list of all the DIEBlocks in use.
101 std::vector<DIEBlock *> DIEBlocks;
Eric Christopher4a741042014-02-16 08:46:55 +0000102
103 /// DIELocs - A list of all the DIELocs in use.
104 std::vector<DIELoc *> DIELocs;
Devang Patelf20c4f72011-04-12 22:53:02 +0000105
Devang Patel89543712011-08-15 17:24:54 +0000106 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
107 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
108 /// corresponds to the MDNode mapped with the subprogram DIE.
109 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
110
Eric Christopher3264a482013-10-05 00:39:55 +0000111 // DIEValueAllocator - All DIEValues are allocated through this allocator.
112 BumpPtrAllocator DIEValueAllocator;
113
114 // DIEIntegerOne - A preallocated DIEValue because 1 is used frequently.
115 DIEInteger *DIEIntegerOne;
116
David Blaikie03073f72013-12-06 22:14:48 +0000117 /// The section this unit will be emitted in.
118 const MCSection *Section;
119
David Blaikiebd579052014-04-28 21:14:27 +0000120 DwarfUnit(unsigned UID, dwarf::Tag, DICompileUnit CU, AsmPrinter *A,
121 DwarfDebug *DW, DwarfFile *DWU);
David Blaikie319a05f2013-12-02 19:33:10 +0000122
David Blaikiecafd9622014-11-02 08:51:37 +0000123
124 /// Add a string attribute data and value.
125 void addLocalString(DIE &Die, dwarf::Attribute Attribute, StringRef Str);
126
127 void addIndexedString(DIE &Die, dwarf::Attribute Attribute, StringRef Str);
128
David Blaikie3a443c22014-11-04 22:12:25 +0000129 bool applySubprogramDefinitionAttributes(DISubprogram SP, DIE &SPDie);
130
Devang Patel5eb43192011-04-12 17:40:32 +0000131public:
Eric Christophera5a79422013-12-09 23:32:48 +0000132 virtual ~DwarfUnit();
Devang Patel5eb43192011-04-12 17:40:32 +0000133
Rafael Espindola063d7252015-03-10 16:58:10 +0000134 void initSection(const MCSection *Section);
135
David Blaikie03073f72013-12-06 22:14:48 +0000136 const MCSection *getSection() const {
137 assert(Section);
138 return Section;
139 }
140
Devang Patel5eb43192011-04-12 17:40:32 +0000141 // Accessors.
Adrian Prantl00dbc2a2015-01-12 22:19:26 +0000142 AsmPrinter* getAsmPrinter() const { return Asm; }
Eric Christopherca68bbf2013-08-26 23:58:22 +0000143 unsigned getUniqueID() const { return UniqueID; }
Duncan P. N. Exon Smith35ef22c2015-04-15 23:19:27 +0000144 uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
David Blaikief645f962014-01-09 03:23:41 +0000145 DICompileUnit getCUNode() const { return CUNode; }
David Blaikiebd579052014-04-28 21:14:27 +0000146 DIE &getUnitDie() { return UnitDie; }
Devang Patel5eb43192011-04-12 17:40:32 +0000147
Manman Rence20d462013-10-29 22:57:10 +0000148 unsigned getDebugInfoOffset() const { return DebugInfoOffset; }
149 void setDebugInfoOffset(unsigned DbgInfoOff) { DebugInfoOffset = DbgInfoOff; }
150
Devang Patel5eb43192011-04-12 17:40:32 +0000151 /// hasContent - Return true if this compile unit has something to write out.
David Blaikiebd579052014-04-28 21:14:27 +0000152 bool hasContent() const { return !UnitDie.getChildren().empty(); }
Devang Patel5eb43192011-04-12 17:40:32 +0000153
Eric Christopher2c8b7902013-10-17 02:06:06 +0000154 /// getParentContextString - Get a string containing the language specific
155 /// context for a global name.
156 std::string getParentContextString(DIScope Context) const;
157
David Blaikie98cf1722014-11-02 06:06:14 +0000158 /// Add a new global name to the compile unit.
David Blaikie192b45c2014-11-02 06:16:39 +0000159 virtual void addGlobalName(StringRef Name, DIE &Die, DIScope Context) {}
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.
David Blaikie192b45c2014-11-02 06:16:39 +0000162 virtual void addGlobalType(DIType Ty, const DIE &Die, DIScope Context) {}
David Blaikie98cf1722014-11-02 06:06:14 +0000163
Eric Christopher9cd26af2013-09-20 23:22:52 +0000164 /// addAccelNamespace - Add a new name to the namespace accelerator table.
David Blaikie65a74662014-04-25 18:26:14 +0000165 void addAccelNamespace(StringRef Name, const DIE &Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000166
Devang Patel5eb43192011-04-12 17:40:32 +0000167 /// getDIE - Returns the debug information entry map slot for the
Manman Ren4dbdc902013-10-31 17:54:35 +0000168 /// specified debug variable. We delegate the request to DwarfDebug
169 /// when the MDNode can be part of the type system, since DIEs for
170 /// the type system can be shared across CUs and the mappings are
171 /// kept in DwarfDebug.
David Blaikie2ad00162013-11-15 23:09:13 +0000172 DIE *getDIE(DIDescriptor D) const;
Devang Patel5eb43192011-04-12 17:40:32 +0000173
Eric Christopher4a741042014-02-16 08:46:55 +0000174 /// getDIELoc - Returns a fresh newly allocated DIELoc.
175 DIELoc *getDIELoc() { return new (DIEValueAllocator) DIELoc(); }
Devang Patelf20c4f72011-04-12 22:53:02 +0000176
Manman Ren4dbdc902013-10-31 17:54:35 +0000177 /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug
178 /// when the MDNode can be part of the type system, since DIEs for
179 /// the type system can be shared across CUs and the mappings are
180 /// kept in DwarfDebug.
David Blaikie2ad00162013-11-15 23:09:13 +0000181 void insertDIE(DIDescriptor Desc, DIE *D);
Devang Patel5eb43192011-04-12 17:40:32 +0000182
Eric Christopherbb69a272012-08-24 01:14:27 +0000183 /// addFlag - Add a flag that is true to the DIE.
David Blaikie65a74662014-04-25 18:26:14 +0000184 void addFlag(DIE &Die, dwarf::Attribute Attribute);
Eric Christopher48fef592012-12-20 21:58:40 +0000185
Devang Patelf20c4f72011-04-12 22:53:02 +0000186 /// addUInt - Add an unsigned integer attribute data and value.
David Blaikie65a74662014-04-25 18:26:14 +0000187 void addUInt(DIE &Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
David Blaikief2443192013-10-21 17:28:37 +0000188 uint64_t Integer);
189
David Blaikie65a74662014-04-25 18:26:14 +0000190 void addUInt(DIE &Block, dwarf::Form Form, uint64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000191
192 /// addSInt - Add an signed integer attribute data and value.
David Blaikie65a74662014-04-25 18:26:14 +0000193 void addSInt(DIE &Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
David Blaikief2443192013-10-21 17:28:37 +0000194 int64_t Integer);
195
David Blaikie65a74662014-04-25 18:26:14 +0000196 void addSInt(DIELoc &Die, Optional<dwarf::Form> Form, int64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000197
198 /// addString - Add a string attribute data and value.
Craig Topper6dc4a8bc2014-08-30 16:48:02 +0000199 void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str);
Devang Patelf20c4f72011-04-12 22:53:02 +0000200
201 /// addLabel - Add a Dwarf label attribute data and value.
David Blaikie65a74662014-04-25 18:26:14 +0000202 void addLabel(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form,
Devang Patelf20c4f72011-04-12 22:53:02 +0000203 const MCSymbol *Label);
204
David Blaikie65a74662014-04-25 18:26:14 +0000205 void addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label);
David Blaikief2443192013-10-21 17:28:37 +0000206
Eric Christopher33ff6972013-11-21 23:46:41 +0000207 /// addSectionOffset - Add an offset into a section attribute data and value.
208 ///
David Blaikie65a74662014-04-25 18:26:14 +0000209 void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer);
Eric Christopher33ff6972013-11-21 23:46:41 +0000210
Eric Christophere9ec2452013-01-18 22:11:33 +0000211 /// addOpAddress - Add a dwarf op address data and value using the
212 /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
David Blaikie65a74662014-04-25 18:26:14 +0000213 void addOpAddress(DIELoc &Die, const MCSymbol *Label);
Eric Christophere9ec2452013-01-18 22:11:33 +0000214
David Blaikie48b1bdc2014-03-07 01:30:55 +0000215 /// addLabelDelta - Add a label delta attribute data and value.
David Blaikie65a74662014-04-25 18:26:14 +0000216 void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
David Blaikie48b1bdc2014-03-07 01:30:55 +0000217 const MCSymbol *Lo);
218
Devang Patelf20c4f72011-04-12 22:53:02 +0000219 /// addDIEEntry - Add a DIE attribute data and value.
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000220 void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry);
Eric Christopher48fef592012-12-20 21:58:40 +0000221
Manman Ren4dbdc902013-10-31 17:54:35 +0000222 /// addDIEEntry - Add a DIE attribute data and value.
David Blaikie65a74662014-04-25 18:26:14 +0000223 void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIEEntry *Entry);
Manman Ren4dbdc902013-10-31 17:54:35 +0000224
David Blaikie65a74662014-04-25 18:26:14 +0000225 void addDIETypeSignature(DIE &Die, const DwarfTypeUnit &Type);
David Blaikie47f615e2013-12-17 23:32:35 +0000226
Devang Patelf20c4f72011-04-12 22:53:02 +0000227 /// addBlock - Add block data.
David Blaikie65a74662014-04-25 18:26:14 +0000228 void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Block);
Eric Christopher4a741042014-02-16 08:46:55 +0000229
230 /// addBlock - Add block data.
David Blaikie65a74662014-04-25 18:26:14 +0000231 void addBlock(DIE &Die, dwarf::Attribute Attribute, DIEBlock *Block);
Devang Patelf20c4f72011-04-12 22:53:02 +0000232
233 /// addSourceLine - Add location information to specified debug information
234 /// entry.
David Blaikie65a74662014-04-25 18:26:14 +0000235 void addSourceLine(DIE &Die, unsigned Line, StringRef File,
David Blaikie101613e2014-02-12 00:11:25 +0000236 StringRef Directory);
David Blaikie65a74662014-04-25 18:26:14 +0000237 void addSourceLine(DIE &Die, DIVariable V);
238 void addSourceLine(DIE &Die, DIGlobalVariable G);
239 void addSourceLine(DIE &Die, DISubprogram SP);
240 void addSourceLine(DIE &Die, DIType Ty);
241 void addSourceLine(DIE &Die, DINameSpace NS);
242 void addSourceLine(DIE &Die, DIObjCProperty Ty);
Devang Patelf20c4f72011-04-12 22:53:02 +0000243
Devang Patelf20c4f72011-04-12 22:53:02 +0000244 /// addConstantValue - Add constant value entry in variable DIE.
David Blaikie65a74662014-04-25 18:26:14 +0000245 void addConstantValue(DIE &Die, const MachineOperand &MO, DIType Ty);
David Blaikiec0a28412014-05-11 15:56:59 +0000246 void addConstantValue(DIE &Die, const ConstantInt *CI, DIType Ty);
247 void addConstantValue(DIE &Die, const APInt &Val, DIType Ty);
David Blaikie65a74662014-04-25 18:26:14 +0000248 void addConstantValue(DIE &Die, const APInt &Val, bool Unsigned);
David Blaikie60cae1b2014-05-11 16:08:41 +0000249 void addConstantValue(DIE &Die, bool Unsigned, uint64_t Val);
Devang Patelf20c4f72011-04-12 22:53:02 +0000250
251 /// addConstantFPValue - Add constant value entry in variable DIE.
David Blaikie65a74662014-04-25 18:26:14 +0000252 void addConstantFPValue(DIE &Die, const MachineOperand &MO);
253 void addConstantFPValue(DIE &Die, const ConstantFP *CFP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000254
Paul Robinson857b4432015-03-10 22:44:45 +0000255 /// \brief Add a linkage name, if it isn't empty.
256 void addLinkageName(DIE &Die, StringRef LinkageName);
257
Devang Patelf20c4f72011-04-12 22:53:02 +0000258 /// addTemplateParams - Add template parameters in buffer.
259 void addTemplateParams(DIE &Buffer, DIArray TParams);
260
Adrian Prantlab255fc2014-12-05 01:02:46 +0000261 /// \brief Add register operand.
262 /// \returns false if the register does not exist, e.g., because it was never
263 /// materialized.
264 bool addRegisterOpPiece(DIELoc &TheDie, unsigned Reg,
Adrian Prantlb1416832014-08-01 22:11:58 +0000265 unsigned SizeInBits = 0, unsigned OffsetInBits = 0);
Devang Patelba5fbf12011-04-26 19:06:18 +0000266
Adrian Prantlab255fc2014-12-05 01:02:46 +0000267 /// \brief Add register offset.
268 /// \returns false if the register does not exist, e.g., because it was never
269 /// materialized.
270 bool addRegisterOffset(DIELoc &TheDie, unsigned Reg, int64_t Offset);
Devang Patelba5fbf12011-04-26 19:06:18 +0000271
Devang Patelf20c4f72011-04-12 22:53:02 +0000272 // FIXME: Should be reformulated in terms of addComplexAddress.
273 /// addBlockByrefAddress - Start with the address based on the location
274 /// provided, and generate the DWARF information necessary to find the
275 /// actual Block variable (navigating the Block struct) based on the
276 /// starting location. Add the DWARF information to the die. Obsolete,
277 /// please use addComplexAddress instead.
David Blaikie65a74662014-04-25 18:26:14 +0000278 void addBlockByrefAddress(const DbgVariable &DV, DIE &Die,
Eric Christophera07e4f52013-11-19 09:28:34 +0000279 dwarf::Attribute Attribute,
Devang Patelf20c4f72011-04-12 22:53:02 +0000280 const MachineLocation &Location);
281
Eric Christopher7285c7d2012-03-28 07:34:31 +0000282 /// addType - Add a new type attribute to the specified entity. This takes
283 /// and attribute parameter because DW_AT_friend attributes are also
284 /// type references.
David Blaikie65a74662014-04-25 18:26:14 +0000285 void addType(DIE &Entity, DIType Ty,
Eric Christophera07e4f52013-11-19 09:28:34 +0000286 dwarf::Attribute Attribute = dwarf::DW_AT_type);
Devang Patelf20c4f72011-04-12 22:53:02 +0000287
288 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
289 DIE *getOrCreateNameSpace(DINameSpace NS);
290
Devang Patel89543712011-08-15 17:24:54 +0000291 /// getOrCreateSubprogramDIE - Create new DIE using SP.
David Blaikie3a443c22014-11-04 22:12:25 +0000292 DIE *getOrCreateSubprogramDIE(DISubprogram SP, bool Minimal = false);
Devang Patel89543712011-08-15 17:24:54 +0000293
David Blaikie279c4512014-11-02 08:18:06 +0000294 void applySubprogramAttributes(DISubprogram SP, DIE &SPDie,
295 bool Minimal = false);
David Blaikie7f916862014-05-27 18:37:38 +0000296
Devang Patelf20c4f72011-04-12 22:53:02 +0000297 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
298 /// given DIType.
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000299 DIE *getOrCreateTypeDIE(const MDNode *N);
Devang Patelf20c4f72011-04-12 22:53:02 +0000300
Eric Christopherfa205ca2013-10-05 00:05:51 +0000301 /// getOrCreateContextDIE - Get context owner's DIE.
David Blaikie409dd9c2013-11-19 23:08:21 +0000302 DIE *createTypeDIE(DICompositeType Ty);
303
304 /// getOrCreateContextDIE - Get context owner's DIE.
Eric Christopherfa205ca2013-10-05 00:05:51 +0000305 DIE *getOrCreateContextDIE(DIScope Context);
Devang Patelf20c4f72011-04-12 22:53:02 +0000306
Eric Christopherfa205ca2013-10-05 00:05:51 +0000307 /// constructContainingTypeDIEs - Construct DIEs for types that contain
308 /// vtables.
309 void constructContainingTypeDIEs();
Devang Patelf20c4f72011-04-12 22:53:02 +0000310
Adrian Prantl69140d22014-02-25 22:27:14 +0000311 /// constructSubprogramArguments - Construct function argument DIEs.
Manman Renf8a19672014-07-28 22:24:06 +0000312 void constructSubprogramArguments(DIE &Buffer, DITypeArray 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.
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000316 DIE &createAndAddDIE(unsigned Tag, DIE &Parent,
Eric Christophera07e4f52013-11-19 09:28:34 +0000317 DIDescriptor N = DIDescriptor());
Manman Renb987e512013-10-29 00:53:03 +0000318
David Blaikie6b288cf2013-10-30 20:42:41 +0000319 /// Compute the size of a header for this unit, not including the initial
320 /// length field.
David Blaikiebc563272013-12-13 21:33:40 +0000321 virtual unsigned getHeaderSize() const {
David Blaikie6b288cf2013-10-30 20:42:41 +0000322 return sizeof(int16_t) + // DWARF version number
323 sizeof(int32_t) + // Offset Into Abbrev. Section
324 sizeof(int8_t); // Pointer Size (in bytes)
325 }
326
327 /// Emit the header for this unit, not including the initial length field.
Rafael Espindola063d7252015-03-10 16:58:10 +0000328 virtual void emitHeader(bool UseOffsets);
David Blaikie6b288cf2013-10-30 20:42:41 +0000329
David Blaikie15632ae2014-02-12 00:31:30 +0000330 virtual DwarfCompileUnit &getCU() = 0;
David Blaikied696fac2014-02-12 00:32:05 +0000331
David Blaikiee12b49a2014-04-26 17:27:38 +0000332 /// constructTypeDIE - Construct type DIE from DICompositeType.
333 void constructTypeDIE(DIE &Buffer, DICompositeType CTy);
334
David Blaikie319a05f2013-12-02 19:33:10 +0000335protected:
336 /// getOrCreateStaticMemberDIE - Create new static data member DIE.
337 DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
338
David Blaikie4a2f95f2014-03-18 01:17:26 +0000339 /// Look up the source ID with the given directory and source file names. If
340 /// none currently exists, create a new ID and insert it in the line table.
341 virtual unsigned getOrCreateSourceID(StringRef File, StringRef Directory) = 0;
342
David Blaikie58410f22014-10-10 06:39:26 +0000343 /// resolve - Look in the DwarfDebug map for the MDNode that
344 /// corresponds to the reference.
Duncan P. N. Exon Smith000fa2c2015-04-07 04:14:33 +0000345 template <typename T> T *resolve(TypedDebugNodeRef<T> Ref) const {
346 return DD->resolve(Ref);
347 }
David Blaikie58410f22014-10-10 06:39:26 +0000348
Eric Christopherfa205ca2013-10-05 00:05:51 +0000349private:
Devang Patelf20c4f72011-04-12 22:53:02 +0000350 /// constructTypeDIE - Construct basic type die from DIBasicType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000351 void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000352
353 /// constructTypeDIE - Construct derived type die from DIDerivedType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000354 void constructTypeDIE(DIE &Buffer, DIDerivedType DTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000355
Devang Patelf20c4f72011-04-12 22:53:02 +0000356 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
357 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
358
359 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
Eric Christopherdf9955d2013-11-11 18:52:31 +0000360 void constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000361
362 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
Eric Christopheraeb105f2013-11-11 18:52:39 +0000363 void constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000364
Manman Ren230ec862013-10-23 23:00:44 +0000365 /// constructMemberDIE - Construct member DIE from DIDerivedType.
366 void constructMemberDIE(DIE &Buffer, DIDerivedType DT);
Manman Ren7cc62702013-10-18 21:14:19 +0000367
Manman Renffc9a712013-10-23 23:05:28 +0000368 /// constructTemplateTypeParameterDIE - Construct new DIE for the given
369 /// DITemplateTypeParameter.
370 void constructTemplateTypeParameterDIE(DIE &Buffer,
371 DITemplateTypeParameter TP);
Manman Ren7cc62702013-10-18 21:14:19 +0000372
Manman Renffc9a712013-10-23 23:05:28 +0000373 /// constructTemplateValueParameterDIE - Construct new DIE for the given
374 /// DITemplateValueParameter.
375 void constructTemplateValueParameterDIE(DIE &Buffer,
376 DITemplateValueParameter TVP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000377
Eric Christopherfa205ca2013-10-05 00:05:51 +0000378 /// getLowerBoundDefault - Return the default lower bound for an array. If the
379 /// DWARF version doesn't handle the language, return -1.
380 int64_t getDefaultLowerBound() const;
381
382 /// getDIEEntry - Returns the debug information entry for the specified
383 /// debug variable.
384 DIEEntry *getDIEEntry(const MDNode *N) const {
385 return MDNodeToDIEEntryMap.lookup(N);
386 }
387
388 /// insertDIEEntry - Insert debug information entry into the map.
389 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
390 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
391 }
392
393 // getIndexTyDie - Get an anonymous type for index type.
David Blaikie871c2d92014-11-02 03:09:13 +0000394 DIE *getIndexTyDie();
Eric Christopherfa205ca2013-10-05 00:05:51 +0000395
396 // setIndexTyDie - Set D as anonymous type for index which can be reused
397 // later.
398 void setIndexTyDie(DIE *D) { IndexTyDie = D; }
399
400 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
401 /// information entry.
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000402 DIEEntry *createDIEEntry(DIE &Entry);
David Blaikie684fc532013-05-06 23:33:07 +0000403
David Blaikie2ea848b2013-11-19 22:51:04 +0000404 /// If this is a named finished type then include it in the list of types for
405 /// the accelerator tables.
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000406 void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE &TyDIE);
David Blaikiecafd9622014-11-02 08:51:37 +0000407
408 virtual bool isDwoUnit() const = 0;
Devang Patel5eb43192011-04-12 17:40:32 +0000409};
410
Eric Christopher4287a492013-12-09 23:57:44 +0000411class DwarfTypeUnit : public DwarfUnit {
David Blaikiebc563272013-12-13 21:33:40 +0000412 uint64_t TypeSignature;
413 const DIE *Ty;
David Blaikie15632ae2014-02-12 00:31:30 +0000414 DwarfCompileUnit &CU;
David Blaikie8287aff2014-03-18 02:13:23 +0000415 MCDwarfDwoLineTable *SplitLineTable;
David Blaikie319a05f2013-12-02 19:33:10 +0000416
David Blaikiecafd9622014-11-02 08:51:37 +0000417 unsigned getOrCreateSourceID(StringRef File, StringRef Directory) override;
418 bool isDwoUnit() const override;
419
David Blaikie319a05f2013-12-02 19:33:10 +0000420public:
David Blaikiebd579052014-04-28 21:14:27 +0000421 DwarfTypeUnit(unsigned UID, DwarfCompileUnit &CU, AsmPrinter *A,
422 DwarfDebug *DW, DwarfFile *DWU,
David Blaikie8287aff2014-03-18 02:13:23 +0000423 MCDwarfDwoLineTable *SplitLineTable = nullptr);
David Blaikie319a05f2013-12-02 19:33:10 +0000424
David Blaikiebc563272013-12-13 21:33:40 +0000425 void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
David Blaikie47f615e2013-12-17 23:32:35 +0000426 uint64_t getTypeSignature() const { return TypeSignature; }
David Blaikiebc563272013-12-13 21:33:40 +0000427 void setType(const DIE *Ty) { this->Ty = Ty; }
428
David Blaikiebc563272013-12-13 21:33:40 +0000429 /// Emit the header for this unit, not including the initial length field.
Rafael Espindola063d7252015-03-10 16:58:10 +0000430 void emitHeader(bool UseOffsets) override;
Craig Topper73156022014-03-02 09:09:27 +0000431 unsigned getHeaderSize() const override {
David Blaikiebc563272013-12-13 21:33:40 +0000432 return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature
433 sizeof(uint32_t); // Type DIE Offset
434 }
Craig Topper73156022014-03-02 09:09:27 +0000435 DwarfCompileUnit &getCU() override { return CU; }
David Blaikie319a05f2013-12-02 19:33:10 +0000436};
Devang Patel5eb43192011-04-12 17:40:32 +0000437} // end llvm namespace
438#endif