blob: 7d7b351b9b015f04cc44874066500f74f061e75e [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
14#ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
15#define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
16
17#include "DIE.h"
Eric Christopher9e429ae2013-10-05 00:27:02 +000018#include "DwarfDebug.h"
Devang Patel5eb43192011-04-12 17:40:32 +000019#include "llvm/ADT/DenseMap.h"
David Blaikief2443192013-10-21 17:28:37 +000020#include "llvm/ADT/Optional.h"
Devang Patel5eb43192011-04-12 17:40:32 +000021#include "llvm/ADT/OwningPtr.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000022#include "llvm/ADT/StringMap.h"
23#include "llvm/DebugInfo.h"
David Blaikief3cd7c52013-06-28 20:05:04 +000024#include "llvm/MC/MCExpr.h"
David Blaikie7d734602013-12-06 22:33:05 +000025#include "llvm/MC/MCSection.h"
Devang Patel5eb43192011-04-12 17:40:32 +000026
27namespace llvm {
28
Devang Patelf20c4f72011-04-12 22:53:02 +000029class MachineLocation;
30class MachineOperand;
31class ConstantInt;
David Blaikiea39a76e2013-01-20 01:18:01 +000032class ConstantFP;
Devang Patelf20c4f72011-04-12 22:53:02 +000033class DbgVariable;
34
Eric Christopher0f63d062013-12-03 00:45:45 +000035// Data structure to hold a range for range lists.
36class RangeSpan {
37public:
38 RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {}
Eric Christopher270ba4a2013-12-04 19:06:58 +000039 const MCSymbol *getStart() const { return Start; }
40 const MCSymbol *getEnd() const { return End; }
Eric Christopher0f63d062013-12-03 00:45:45 +000041
42private:
43 const MCSymbol *Start, *End;
44};
45
46class RangeSpanList {
47private:
48 // Index for locating within the debug_range section this particular span.
Eric Christopherf8790642013-12-04 22:04:50 +000049 MCSymbol *RangeSym;
Eric Christopher0f63d062013-12-03 00:45:45 +000050 // List of ranges.
51 SmallVector<RangeSpan, 2> Ranges;
52
53public:
Eric Christopherf8790642013-12-04 22:04:50 +000054 RangeSpanList(MCSymbol *Sym) : RangeSym(Sym) {}
55 MCSymbol *getSym() const { return RangeSym; }
Eric Christopher0f63d062013-12-03 00:45:45 +000056 const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
57 void addRange(RangeSpan Range) { Ranges.push_back(Range); }
58};
59
Devang Patel5eb43192011-04-12 17:40:32 +000060//===----------------------------------------------------------------------===//
David Blaikie319a05f2013-12-02 19:33:10 +000061/// Unit - This dwarf writer support class manages information associated
Devang Patel5eb43192011-04-12 17:40:32 +000062/// with a source file.
Eric Christophera5a79422013-12-09 23:32:48 +000063class DwarfUnit {
David Blaikie319a05f2013-12-02 19:33:10 +000064protected:
Eli Benderskyb42d1462012-12-03 18:45:45 +000065 /// UniqueID - a numeric ID unique among all CUs in the module
Eli Benderskyb42d1462012-12-03 18:45:45 +000066 unsigned UniqueID;
Devang Patel5eb43192011-04-12 17:40:32 +000067
Eric Christopherbfceb2f2013-08-26 23:50:38 +000068 /// Node - MDNode for the compile unit.
David Blaikie5a152402013-11-15 23:52:02 +000069 DICompileUnit Node;
Eric Christopher3a2656b2012-02-22 08:46:13 +000070
David Blaikie2a80e442013-12-02 22:09:48 +000071 /// Unit debug information entry.
72 const OwningPtr<DIE> UnitDie;
Devang Patel5eb43192011-04-12 17:40:32 +000073
David Blaikie2a80e442013-12-02 22:09:48 +000074 /// Offset of the UnitDie from beginning of debug info section.
Eric Christophera16725b2013-11-21 01:29:16 +000075 unsigned DebugInfoOffset;
76
Devang Patelf20c4f72011-04-12 22:53:02 +000077 /// Asm - Target of Dwarf emission.
78 AsmPrinter *Asm;
79
Eric Christophere698f532012-12-20 21:58:36 +000080 // Holders for some common dwarf information.
Devang Patelf20c4f72011-04-12 22:53:02 +000081 DwarfDebug *DD;
Eric Christopherf8194852013-12-05 18:06:10 +000082 DwarfFile *DU;
Devang Patelf20c4f72011-04-12 22:53:02 +000083
David Blaikie2a80e442013-12-02 22:09:48 +000084 /// IndexTyDie - An anonymous type for index type. Owned by UnitDie.
Devang Patel5eb43192011-04-12 17:40:32 +000085 DIE *IndexTyDie;
86
Eric Christopher61560112013-05-08 00:11:10 +000087 /// MDNodeToDieMap - Tracks the mapping of unit level debug information
Devang Patel5eb43192011-04-12 17:40:32 +000088 /// variables to debug information entries.
89 DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
90
Eric Christopher61560112013-05-08 00:11:10 +000091 /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug information
Devang Patel5eb43192011-04-12 17:40:32 +000092 /// descriptors to debug information entries using a DIEEntry proxy.
93 DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
94
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +000095 /// GlobalNames - A map of globally visible named entities for this unit.
Eric Christopher0fe676a2013-11-21 00:48:22 +000096 StringMap<const DIE *> GlobalNames;
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +000097
Devang Patel5eb43192011-04-12 17:40:32 +000098 /// GlobalTypes - A map of globally visible types for this unit.
Eric Christopher0fe676a2013-11-21 00:48:22 +000099 StringMap<const DIE *> GlobalTypes;
Devang Patel5eb43192011-04-12 17:40:32 +0000100
Eric Christopher4996c702011-11-07 09:24:32 +0000101 /// AccelNames - A map of names for the name accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000102 StringMap<std::vector<const DIE *> > AccelNames;
Eric Christopher4affe8c2013-11-21 01:29:13 +0000103
104 /// AccelObjC - A map of objc spec for the objc accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000105 StringMap<std::vector<const DIE *> > AccelObjC;
Eric Christopher4affe8c2013-11-21 01:29:13 +0000106
107 /// AccelNamespace - A map of names for the namespace accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000108 StringMap<std::vector<const DIE *> > AccelNamespace;
Eric Christopher4affe8c2013-11-21 01:29:13 +0000109
110 /// AccelTypes - A map of names for the type accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000111 StringMap<std::vector<std::pair<const DIE *, unsigned> > > AccelTypes;
Eric Christopher4996c702011-11-07 09:24:32 +0000112
Devang Patelf20c4f72011-04-12 22:53:02 +0000113 /// DIEBlocks - A list of all the DIEBlocks in use.
114 std::vector<DIEBlock *> DIEBlocks;
115
Devang Patel89543712011-08-15 17:24:54 +0000116 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
117 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
118 /// corresponds to the MDNode mapped with the subprogram DIE.
119 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
120
Eric Christopher46e23432013-12-20 04:16:18 +0000121 // List of ranges for a given compile unit.
122 SmallVector<RangeSpan, 1> CURanges;
123
Eric Christopher0f63d062013-12-03 00:45:45 +0000124 // List of range lists for a given compile unit, separate from the ranges for
125 // the CU itself.
Eric Christopher270ba4a2013-12-04 19:06:58 +0000126 SmallVector<RangeSpanList, 1> CURangeLists;
Eric Christopher0f63d062013-12-03 00:45:45 +0000127
Eric Christopher3264a482013-10-05 00:39:55 +0000128 // DIEValueAllocator - All DIEValues are allocated through this allocator.
129 BumpPtrAllocator DIEValueAllocator;
130
131 // DIEIntegerOne - A preallocated DIEValue because 1 is used frequently.
132 DIEInteger *DIEIntegerOne;
133
David Blaikie03073f72013-12-06 22:14:48 +0000134 /// The section this unit will be emitted in.
135 const MCSection *Section;
136
137 /// A label at the start of the non-dwo section related to this unit.
138 MCSymbol *SectionSym;
139
David Blaikie7d734602013-12-06 22:33:05 +0000140 /// The start of the unit within its section.
141 MCSymbol *LabelBegin;
142
143 /// The end of the unit within its section.
144 MCSymbol *LabelEnd;
145
David Blaikie1ab7c2d2013-12-09 17:51:30 +0000146 /// The label for the start of the range sets for the elements of this unit.
147 MCSymbol *LabelRange;
148
Eric Christophera5a79422013-12-09 23:32:48 +0000149 DwarfUnit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A,
150 DwarfDebug *DW, DwarfFile *DWU);
David Blaikie319a05f2013-12-02 19:33:10 +0000151
Devang Patel5eb43192011-04-12 17:40:32 +0000152public:
Eric Christophera5a79422013-12-09 23:32:48 +0000153 virtual ~DwarfUnit();
Devang Patel5eb43192011-04-12 17:40:32 +0000154
David Blaikie03073f72013-12-06 22:14:48 +0000155 /// Pass in the SectionSym even though we could recreate it in every compile
156 /// unit (type units will have actually distinct symbols once they're in
157 /// comdat sections).
158 void initSection(const MCSection *Section, MCSymbol *SectionSym) {
159 assert(!this->Section);
160 this->Section = Section;
161 this->SectionSym = SectionSym;
David Blaikie7d734602013-12-06 22:33:05 +0000162 this->LabelBegin =
163 Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID());
164 this->LabelEnd =
165 Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID());
David Blaikie1ab7c2d2013-12-09 17:51:30 +0000166 this->LabelRange = Asm->GetTempSymbol("gnu_ranges", getUniqueID());
David Blaikie03073f72013-12-06 22:14:48 +0000167 }
David Blaikie1ab7c2d2013-12-09 17:51:30 +0000168
David Blaikie03073f72013-12-06 22:14:48 +0000169 const MCSection *getSection() const {
170 assert(Section);
171 return Section;
172 }
173
David Blaikie7d734602013-12-06 22:33:05 +0000174 MCSymbol *getSectionSym() const {
David Blaikie03073f72013-12-06 22:14:48 +0000175 assert(Section);
176 return SectionSym;
177 }
178
David Blaikie7d734602013-12-06 22:33:05 +0000179 MCSymbol *getLabelBegin() const {
180 assert(Section);
181 return LabelBegin;
182 }
183
184 MCSymbol *getLabelEnd() const {
185 assert(Section);
186 return LabelEnd;
187 }
188
David Blaikie1ab7c2d2013-12-09 17:51:30 +0000189 MCSymbol *getLabelRange() const {
190 assert(Section);
191 return LabelRange;
192 }
193
Devang Patel5eb43192011-04-12 17:40:32 +0000194 // Accessors.
Eric Christopherca68bbf2013-08-26 23:58:22 +0000195 unsigned getUniqueID() const { return UniqueID; }
David Blaikie319a05f2013-12-02 19:33:10 +0000196 virtual uint16_t getLanguage() const = 0;
David Blaikieb01f13e2013-11-15 23:54:45 +0000197 DICompileUnit getNode() const { return Node; }
David Blaikie2a80e442013-12-02 22:09:48 +0000198 DIE *getUnitDie() const { return UnitDie.get(); }
Eric Christopher0fe676a2013-11-21 00:48:22 +0000199 const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; }
200 const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; }
Devang Patel5eb43192011-04-12 17:40:32 +0000201
David Blaikie2ea848b2013-11-19 22:51:04 +0000202 const StringMap<std::vector<const DIE *> > &getAccelNames() const {
Eric Christopherd9843b32011-11-10 19:25:34 +0000203 return AccelNames;
204 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000205 const StringMap<std::vector<const DIE *> > &getAccelObjC() const {
Eric Christopher4996c702011-11-07 09:24:32 +0000206 return AccelObjC;
207 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000208 const StringMap<std::vector<const DIE *> > &getAccelNamespace() const {
Eric Christopher66b37db2011-11-10 21:47:55 +0000209 return AccelNamespace;
210 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000211 const StringMap<std::vector<std::pair<const DIE *, unsigned> > > &
Eric Christopherca68bbf2013-08-26 23:58:22 +0000212 getAccelTypes() const {
Eric Christopher66b37db2011-11-10 21:47:55 +0000213 return AccelTypes;
214 }
Eric Christopher48fef592012-12-20 21:58:40 +0000215
Manman Rence20d462013-10-29 22:57:10 +0000216 unsigned getDebugInfoOffset() const { return DebugInfoOffset; }
217 void setDebugInfoOffset(unsigned DbgInfoOff) { DebugInfoOffset = DbgInfoOff; }
218
Devang Patel5eb43192011-04-12 17:40:32 +0000219 /// hasContent - Return true if this compile unit has something to write out.
David Blaikie2a80e442013-12-02 22:09:48 +0000220 bool hasContent() const { return !UnitDie->getChildren().empty(); }
Devang Patel5eb43192011-04-12 17:40:32 +0000221
Eric Christopher46e23432013-12-20 04:16:18 +0000222 /// addRange - Add an address range to the list of ranges for this unit.
223 void addRange(RangeSpan Range) { CURanges.push_back(Range); }
224
225 /// getRanges - Get the list of ranges for this unit.
226 const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; }
227 SmallVectorImpl<RangeSpan> &getRanges() { return CURanges; }
228
Eric Christopher0f63d062013-12-03 00:45:45 +0000229 /// addRangeList - Add an address range list to the list of range lists.
Eric Christopher270ba4a2013-12-04 19:06:58 +0000230 void addRangeList(RangeSpanList Ranges) { CURangeLists.push_back(Ranges); }
Eric Christopher0f63d062013-12-03 00:45:45 +0000231
232 /// getRangeLists - Get the vector of range lists.
Eric Christopher270ba4a2013-12-04 19:06:58 +0000233 const SmallVectorImpl<RangeSpanList> &getRangeLists() const {
Eric Christopher0f63d062013-12-03 00:45:45 +0000234 return CURangeLists;
235 }
Eric Christopher270ba4a2013-12-04 19:06:58 +0000236 SmallVectorImpl<RangeSpanList> &getRangeLists() { return CURangeLists; }
Eric Christopher0f63d062013-12-03 00:45:45 +0000237
Eric Christopher2c8b7902013-10-17 02:06:06 +0000238 /// getParentContextString - Get a string containing the language specific
239 /// context for a global name.
240 std::string getParentContextString(DIScope Context) const;
241
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000242 /// addGlobalName - Add a new global entity to the compile unit.
243 ///
Eric Christopher2c8b7902013-10-17 02:06:06 +0000244 void addGlobalName(StringRef Name, DIE *Die, DIScope Context);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000245
Eric Christopher4996c702011-11-07 09:24:32 +0000246 /// addAccelName - Add a new name to the name accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000247 void addAccelName(StringRef Name, const DIE *Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000248
249 /// addAccelObjC - Add a new name to the ObjC accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000250 void addAccelObjC(StringRef Name, const DIE *Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000251
252 /// addAccelNamespace - Add a new name to the namespace accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000253 void addAccelNamespace(StringRef Name, const DIE *Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000254
255 /// addAccelType - Add a new type to the type accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000256 void addAccelType(StringRef Name, std::pair<const DIE *, unsigned> Die);
Eric Christopher48fef592012-12-20 21:58:40 +0000257
Devang Patel5eb43192011-04-12 17:40:32 +0000258 /// getDIE - Returns the debug information entry map slot for the
Manman Ren4dbdc902013-10-31 17:54:35 +0000259 /// specified debug variable. We delegate the request to DwarfDebug
260 /// when the MDNode can be part of the type system, since DIEs for
261 /// the type system can be shared across CUs and the mappings are
262 /// kept in DwarfDebug.
David Blaikie2ad00162013-11-15 23:09:13 +0000263 DIE *getDIE(DIDescriptor D) const;
Devang Patel5eb43192011-04-12 17:40:32 +0000264
Eric Christopher4affe8c2013-11-21 01:29:13 +0000265 /// getDIEBlock - Returns a fresh newly allocated DIEBlock.
Eric Christopherf0388b72013-10-04 23:49:29 +0000266 DIEBlock *getDIEBlock() { return new (DIEValueAllocator) DIEBlock(); }
Devang Patelf20c4f72011-04-12 22:53:02 +0000267
Manman Ren4dbdc902013-10-31 17:54:35 +0000268 /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug
269 /// when the MDNode can be part of the type system, since DIEs for
270 /// the type system can be shared across CUs and the mappings are
271 /// kept in DwarfDebug.
David Blaikie2ad00162013-11-15 23:09:13 +0000272 void insertDIE(DIDescriptor Desc, DIE *D);
Devang Patel5eb43192011-04-12 17:40:32 +0000273
Devang Patel5eb43192011-04-12 17:40:32 +0000274 /// addDie - Adds or interns the DIE to the compile unit.
275 ///
David Blaikie2a80e442013-12-02 22:09:48 +0000276 void addDie(DIE *Buffer) { UnitDie->addChild(Buffer); }
Devang Patel5eb43192011-04-12 17:40:32 +0000277
Eric Christopherbb69a272012-08-24 01:14:27 +0000278 /// addFlag - Add a flag that is true to the DIE.
David Blaikief2443192013-10-21 17:28:37 +0000279 void addFlag(DIE *Die, dwarf::Attribute Attribute);
Eric Christopher48fef592012-12-20 21:58:40 +0000280
Devang Patelf20c4f72011-04-12 22:53:02 +0000281 /// addUInt - Add an unsigned integer attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000282 void addUInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
283 uint64_t Integer);
284
285 void addUInt(DIEBlock *Block, dwarf::Form Form, uint64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000286
287 /// addSInt - Add an signed integer attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000288 void addSInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
289 int64_t Integer);
290
291 void addSInt(DIEBlock *Die, Optional<dwarf::Form> Form, int64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000292
293 /// addString - Add a string attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000294 void addString(DIE *Die, dwarf::Attribute Attribute, const StringRef Str);
Devang Patelf20c4f72011-04-12 22:53:02 +0000295
Eric Christopher2cbd5762013-01-07 19:32:41 +0000296 /// addLocalString - Add a string attribute data and value.
Eric Christophera07e4f52013-11-19 09:28:34 +0000297 void addLocalString(DIE *Die, dwarf::Attribute Attribute,
298 const StringRef Str);
Eric Christopher2cbd5762013-01-07 19:32:41 +0000299
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000300 /// addExpr - Add a Dwarf expression attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000301 void addExpr(DIEBlock *Die, dwarf::Form Form, const MCExpr *Expr);
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000302
Devang Patelf20c4f72011-04-12 22:53:02 +0000303 /// addLabel - Add a Dwarf label attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000304 void addLabel(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form,
Devang Patelf20c4f72011-04-12 22:53:02 +0000305 const MCSymbol *Label);
306
David Blaikief2443192013-10-21 17:28:37 +0000307 void addLabel(DIEBlock *Die, dwarf::Form Form, const MCSymbol *Label);
308
Eric Christopher33ff6972013-11-21 23:46:41 +0000309 /// addSectionLabel - Add a Dwarf section label attribute data and value.
310 ///
Eric Christopherf52eddf2013-11-26 22:23:27 +0000311 void addSectionLabel(DIE *Die, dwarf::Attribute Attribute,
312 const MCSymbol *Label);
Eric Christopher33ff6972013-11-21 23:46:41 +0000313
314 /// addSectionOffset - Add an offset into a section attribute data and value.
315 ///
316 void addSectionOffset(DIE *Die, dwarf::Attribute Attribute, uint64_t Integer);
317
Eric Christophere9ec2452013-01-18 22:11:33 +0000318 /// addOpAddress - Add a dwarf op address data and value using the
319 /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
David Blaikief2443192013-10-21 17:28:37 +0000320 void addOpAddress(DIEBlock *Die, const MCSymbol *Label);
Eric Christophere9ec2452013-01-18 22:11:33 +0000321
Eric Christopher33ff6972013-11-21 23:46:41 +0000322 /// addSectionDelta - Add a label delta attribute data and value.
323 void addSectionDelta(DIE *Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
324 const MCSymbol *Lo);
Devang Patelf20c4f72011-04-12 22:53:02 +0000325
326 /// addDIEEntry - Add a DIE attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000327 void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry);
Eric Christopher48fef592012-12-20 21:58:40 +0000328
Manman Ren4dbdc902013-10-31 17:54:35 +0000329 /// addDIEEntry - Add a DIE attribute data and value.
Manman Ren4dbdc902013-10-31 17:54:35 +0000330 void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIEEntry *Entry);
331
David Blaikie47f615e2013-12-17 23:32:35 +0000332 void addDIETypeSignature(DIE *Die, const DwarfTypeUnit &Type);
333
Devang Patelf20c4f72011-04-12 22:53:02 +0000334 /// addBlock - Add block data.
David Blaikief2443192013-10-21 17:28:37 +0000335 void addBlock(DIE *Die, dwarf::Attribute Attribute, DIEBlock *Block);
Devang Patelf20c4f72011-04-12 22:53:02 +0000336
337 /// addSourceLine - Add location information to specified debug information
338 /// entry.
339 void addSourceLine(DIE *Die, DIVariable V);
340 void addSourceLine(DIE *Die, DIGlobalVariable G);
341 void addSourceLine(DIE *Die, DISubprogram SP);
342 void addSourceLine(DIE *Die, DIType Ty);
343 void addSourceLine(DIE *Die, DINameSpace NS);
Eric Christopher70e1bd82012-03-29 08:42:56 +0000344 void addSourceLine(DIE *Die, DIObjCProperty Ty);
Devang Patelf20c4f72011-04-12 22:53:02 +0000345
346 /// addAddress - Add an address attribute to a die based on the location
347 /// provided.
Eric Christophera07e4f52013-11-19 09:28:34 +0000348 void addAddress(DIE *Die, dwarf::Attribute Attribute,
349 const MachineLocation &Location, bool Indirect = false);
Devang Patelf20c4f72011-04-12 22:53:02 +0000350
Devang Patelf20c4f72011-04-12 22:53:02 +0000351 /// addConstantValue - Add constant value entry in variable DIE.
Eric Christopher78fcf4902013-07-03 01:08:30 +0000352 void addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
353 void addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
354 void addConstantValue(DIE *Die, const APInt &Val, bool Unsigned);
Devang Patelf20c4f72011-04-12 22:53:02 +0000355
356 /// addConstantFPValue - Add constant value entry in variable DIE.
Eric Christopher78fcf4902013-07-03 01:08:30 +0000357 void addConstantFPValue(DIE *Die, const MachineOperand &MO);
358 void addConstantFPValue(DIE *Die, const ConstantFP *CFP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000359
360 /// addTemplateParams - Add template parameters in buffer.
361 void addTemplateParams(DIE &Buffer, DIArray TParams);
362
Devang Patelba5fbf12011-04-26 19:06:18 +0000363 /// addRegisterOp - Add register operand.
David Blaikief2443192013-10-21 17:28:37 +0000364 void addRegisterOp(DIEBlock *TheDie, unsigned Reg);
Devang Patelba5fbf12011-04-26 19:06:18 +0000365
366 /// addRegisterOffset - Add register offset.
David Blaikief2443192013-10-21 17:28:37 +0000367 void addRegisterOffset(DIEBlock *TheDie, unsigned Reg, int64_t Offset);
Devang Patelba5fbf12011-04-26 19:06:18 +0000368
Devang Patelf20c4f72011-04-12 22:53:02 +0000369 /// addComplexAddress - Start with the address based on the location provided,
370 /// and generate the DWARF information necessary to find the actual variable
371 /// (navigating the extra location information encoded in the type) based on
372 /// the starting location. Add the DWARF information to the die.
Eric Christophera07e4f52013-11-19 09:28:34 +0000373 void addComplexAddress(const DbgVariable &DV, DIE *Die,
374 dwarf::Attribute Attribute,
Devang Patelf20c4f72011-04-12 22:53:02 +0000375 const MachineLocation &Location);
376
377 // FIXME: Should be reformulated in terms of addComplexAddress.
378 /// addBlockByrefAddress - Start with the address based on the location
379 /// provided, and generate the DWARF information necessary to find the
380 /// actual Block variable (navigating the Block struct) based on the
381 /// starting location. Add the DWARF information to the die. Obsolete,
382 /// please use addComplexAddress instead.
Eric Christophera07e4f52013-11-19 09:28:34 +0000383 void addBlockByrefAddress(const DbgVariable &DV, DIE *Die,
384 dwarf::Attribute Attribute,
Devang Patelf20c4f72011-04-12 22:53:02 +0000385 const MachineLocation &Location);
386
Eric Christopher48fef592012-12-20 21:58:40 +0000387 /// addVariableAddress - Add DW_AT_location attribute for a
Devang Patel77dc5412011-04-27 22:45:24 +0000388 /// DbgVariable based on provided MachineLocation.
Eric Christopherbf2d23c2013-06-24 21:07:27 +0000389 void addVariableAddress(const DbgVariable &DV, DIE *Die,
390 MachineLocation Location);
Devang Patelf20c4f72011-04-12 22:53:02 +0000391
Eric Christopher7285c7d2012-03-28 07:34:31 +0000392 /// addType - Add a new type attribute to the specified entity. This takes
393 /// and attribute parameter because DW_AT_friend attributes are also
394 /// type references.
Eric Christophera07e4f52013-11-19 09:28:34 +0000395 void addType(DIE *Entity, DIType Ty,
396 dwarf::Attribute Attribute = dwarf::DW_AT_type);
Devang Patelf20c4f72011-04-12 22:53:02 +0000397
398 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
399 DIE *getOrCreateNameSpace(DINameSpace NS);
400
Devang Patel89543712011-08-15 17:24:54 +0000401 /// getOrCreateSubprogramDIE - Create new DIE using SP.
402 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
403
Devang Patelf20c4f72011-04-12 22:53:02 +0000404 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
405 /// given DIType.
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000406 DIE *getOrCreateTypeDIE(const MDNode *N);
Devang Patelf20c4f72011-04-12 22:53:02 +0000407
Eric Christopherfa205ca2013-10-05 00:05:51 +0000408 /// getOrCreateContextDIE - Get context owner's DIE.
David Blaikie409dd9c2013-11-19 23:08:21 +0000409 DIE *createTypeDIE(DICompositeType Ty);
410
411 /// getOrCreateContextDIE - Get context owner's DIE.
Eric Christopherfa205ca2013-10-05 00:05:51 +0000412 DIE *getOrCreateContextDIE(DIScope Context);
Devang Patelf20c4f72011-04-12 22:53:02 +0000413
Eric Christopherfa205ca2013-10-05 00:05:51 +0000414 /// constructContainingTypeDIEs - Construct DIEs for types that contain
415 /// vtables.
416 void constructContainingTypeDIEs();
Devang Patelf20c4f72011-04-12 22:53:02 +0000417
Eric Christopherfa205ca2013-10-05 00:05:51 +0000418 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
Eric Christopher34a2c872013-11-15 01:43:19 +0000419 DIE *constructVariableDIE(DbgVariable &DV, bool isScopeAbstract);
Eric Christopherfa205ca2013-10-05 00:05:51 +0000420
Manman Renb987e512013-10-29 00:53:03 +0000421 /// Create a DIE with the given Tag, add the DIE to its parent, and
422 /// call insertDIE if MD is not null.
Eric Christophera07e4f52013-11-19 09:28:34 +0000423 DIE *createAndAddDIE(unsigned Tag, DIE &Parent,
424 DIDescriptor N = DIDescriptor());
Manman Renb987e512013-10-29 00:53:03 +0000425
David Blaikie6b288cf2013-10-30 20:42:41 +0000426 /// Compute the size of a header for this unit, not including the initial
427 /// length field.
David Blaikiebc563272013-12-13 21:33:40 +0000428 virtual unsigned getHeaderSize() const {
David Blaikie6b288cf2013-10-30 20:42:41 +0000429 return sizeof(int16_t) + // DWARF version number
430 sizeof(int32_t) + // Offset Into Abbrev. Section
431 sizeof(int8_t); // Pointer Size (in bytes)
432 }
433
434 /// Emit the header for this unit, not including the initial length field.
David Blaikiebc563272013-12-13 21:33:40 +0000435 virtual void emitHeader(const MCSection *ASection,
436 const MCSymbol *ASectionSym) const;
David Blaikie6b288cf2013-10-30 20:42:41 +0000437
David Blaikie319a05f2013-12-02 19:33:10 +0000438protected:
439 /// getOrCreateStaticMemberDIE - Create new static data member DIE.
440 DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
441
Eric Christopherfa205ca2013-10-05 00:05:51 +0000442private:
Devang Patelf20c4f72011-04-12 22:53:02 +0000443 /// constructTypeDIE - Construct basic type die from DIBasicType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000444 void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000445
446 /// constructTypeDIE - Construct derived type die from DIDerivedType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000447 void constructTypeDIE(DIE &Buffer, DIDerivedType DTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000448
449 /// constructTypeDIE - Construct type DIE from DICompositeType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000450 void constructTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000451
452 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
453 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
454
455 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
Eric Christopherdf9955d2013-11-11 18:52:31 +0000456 void constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000457
458 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
Eric Christopheraeb105f2013-11-11 18:52:39 +0000459 void constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000460
Manman Ren230ec862013-10-23 23:00:44 +0000461 /// constructMemberDIE - Construct member DIE from DIDerivedType.
462 void constructMemberDIE(DIE &Buffer, DIDerivedType DT);
Manman Ren7cc62702013-10-18 21:14:19 +0000463
Manman Renffc9a712013-10-23 23:05:28 +0000464 /// constructTemplateTypeParameterDIE - Construct new DIE for the given
465 /// DITemplateTypeParameter.
466 void constructTemplateTypeParameterDIE(DIE &Buffer,
467 DITemplateTypeParameter TP);
Manman Ren7cc62702013-10-18 21:14:19 +0000468
Manman Renffc9a712013-10-23 23:05:28 +0000469 /// constructTemplateValueParameterDIE - Construct new DIE for the given
470 /// DITemplateValueParameter.
471 void constructTemplateValueParameterDIE(DIE &Buffer,
472 DITemplateValueParameter TVP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000473
Eric Christopherfa205ca2013-10-05 00:05:51 +0000474 /// getLowerBoundDefault - Return the default lower bound for an array. If the
475 /// DWARF version doesn't handle the language, return -1.
476 int64_t getDefaultLowerBound() const;
477
478 /// getDIEEntry - Returns the debug information entry for the specified
479 /// debug variable.
480 DIEEntry *getDIEEntry(const MDNode *N) const {
481 return MDNodeToDIEEntryMap.lookup(N);
482 }
483
484 /// insertDIEEntry - Insert debug information entry into the map.
485 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
486 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
487 }
488
489 // getIndexTyDie - Get an anonymous type for index type.
490 DIE *getIndexTyDie() { return IndexTyDie; }
491
492 // setIndexTyDie - Set D as anonymous type for index which can be reused
493 // later.
494 void setIndexTyDie(DIE *D) { IndexTyDie = D; }
495
496 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
497 /// information entry.
498 DIEEntry *createDIEEntry(DIE *Entry);
David Blaikie684fc532013-05-06 23:33:07 +0000499
Eric Christopher9e429ae2013-10-05 00:27:02 +0000500 /// resolve - Look in the DwarfDebug map for the MDNode that
Eric Christopher87b9c492013-10-05 00:32:34 +0000501 /// corresponds to the reference.
Eric Christopher9e429ae2013-10-05 00:27:02 +0000502 template <typename T> T resolve(DIRef<T> Ref) const {
503 return DD->resolve(Ref);
504 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000505
506 /// If this is a named finished type then include it in the list of types for
507 /// the accelerator tables.
David Blaikie9d861be2013-11-26 00:15:27 +0000508 void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE *TyDIE);
Devang Patel5eb43192011-04-12 17:40:32 +0000509};
510
Eric Christopher4287a492013-12-09 23:57:44 +0000511class DwarfCompileUnit : public DwarfUnit {
David Blaikie319a05f2013-12-02 19:33:10 +0000512public:
Eric Christopher4287a492013-12-09 23:57:44 +0000513 DwarfCompileUnit(unsigned UID, DIE *D, DICompileUnit Node, AsmPrinter *A,
514 DwarfDebug *DW, DwarfFile *DWU);
Juergen Ributzkadb9ee002013-12-14 12:23:14 +0000515 virtual ~DwarfCompileUnit() LLVM_OVERRIDE;
David Blaikie319a05f2013-12-02 19:33:10 +0000516
517 /// createGlobalVariableDIE - create global variable DIE.
518 void createGlobalVariableDIE(DIGlobalVariable GV);
519
520 /// addLabelAddress - Add a dwarf label attribute data and value using
521 /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
522 void addLabelAddress(DIE *Die, dwarf::Attribute Attribute, MCSymbol *Label);
523
David Blaikie3332d4c2013-12-11 21:14:02 +0000524 uint16_t getLanguage() const LLVM_OVERRIDE { return getNode().getLanguage(); }
David Blaikie319a05f2013-12-02 19:33:10 +0000525};
526
Eric Christopher4287a492013-12-09 23:57:44 +0000527class DwarfTypeUnit : public DwarfUnit {
David Blaikie319a05f2013-12-02 19:33:10 +0000528private:
529 uint16_t Language;
David Blaikiebc563272013-12-13 21:33:40 +0000530 uint64_t TypeSignature;
531 const DIE *Ty;
David Blaikie319a05f2013-12-02 19:33:10 +0000532
533public:
Eric Christopher4287a492013-12-09 23:57:44 +0000534 DwarfTypeUnit(unsigned UID, DIE *D, uint16_t Language, AsmPrinter *A,
535 DwarfDebug *DW, DwarfFile *DWU);
Juergen Ributzkadb9ee002013-12-14 12:23:14 +0000536 virtual ~DwarfTypeUnit() LLVM_OVERRIDE;
David Blaikie319a05f2013-12-02 19:33:10 +0000537
David Blaikiebc563272013-12-13 21:33:40 +0000538 void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
David Blaikie47f615e2013-12-17 23:32:35 +0000539 uint64_t getTypeSignature() const { return TypeSignature; }
David Blaikiebc563272013-12-13 21:33:40 +0000540 void setType(const DIE *Ty) { this->Ty = Ty; }
541
David Blaikie3332d4c2013-12-11 21:14:02 +0000542 uint16_t getLanguage() const LLVM_OVERRIDE { return Language; }
David Blaikiebc563272013-12-13 21:33:40 +0000543 /// Emit the header for this unit, not including the initial length field.
544 void emitHeader(const MCSection *ASection, const MCSymbol *ASectionSym) const
545 LLVM_OVERRIDE;
546 unsigned getHeaderSize() const LLVM_OVERRIDE {
547 return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature
548 sizeof(uint32_t); // Type DIE Offset
549 }
550 void initSection(const MCSection *Section);
David Blaikie319a05f2013-12-02 19:33:10 +0000551};
Devang Patel5eb43192011-04-12 17:40:32 +0000552} // end llvm namespace
553#endif