blob: ce9faf0250943005b558cf3fe02581b44c0e2bbb [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"
Devang Patel5eb43192011-04-12 17:40:32 +000025
26namespace llvm {
27
Devang Patelf20c4f72011-04-12 22:53:02 +000028class MachineLocation;
29class MachineOperand;
30class ConstantInt;
David Blaikiea39a76e2013-01-20 01:18:01 +000031class ConstantFP;
Devang Patelf20c4f72011-04-12 22:53:02 +000032class DbgVariable;
33
Eric Christopher0f63d062013-12-03 00:45:45 +000034// Data structure to hold a range for range lists.
35class RangeSpan {
36public:
37 RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {}
Eric Christopher270ba4a2013-12-04 19:06:58 +000038 const MCSymbol *getStart() const { return Start; }
39 const MCSymbol *getEnd() const { return End; }
Eric Christopher0f63d062013-12-03 00:45:45 +000040
41private:
42 const MCSymbol *Start, *End;
43};
44
45class RangeSpanList {
46private:
47 // Index for locating within the debug_range section this particular span.
48 unsigned Index;
49 // List of ranges.
50 SmallVector<RangeSpan, 2> Ranges;
51
52public:
53 RangeSpanList(unsigned Idx) : Index(Idx) {}
54 unsigned getIndex() const { return Index; }
55 const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
56 void addRange(RangeSpan Range) { Ranges.push_back(Range); }
57};
58
Devang Patel5eb43192011-04-12 17:40:32 +000059//===----------------------------------------------------------------------===//
David Blaikie319a05f2013-12-02 19:33:10 +000060/// Unit - This dwarf writer support class manages information associated
Devang Patel5eb43192011-04-12 17:40:32 +000061/// with a source file.
David Blaikie319a05f2013-12-02 19:33:10 +000062class Unit {
63protected:
Eli Benderskyb42d1462012-12-03 18:45:45 +000064 /// UniqueID - a numeric ID unique among all CUs in the module
Eli Benderskyb42d1462012-12-03 18:45:45 +000065 unsigned UniqueID;
Devang Patel5eb43192011-04-12 17:40:32 +000066
Eric Christopherbfceb2f2013-08-26 23:50:38 +000067 /// Node - MDNode for the compile unit.
David Blaikie5a152402013-11-15 23:52:02 +000068 DICompileUnit Node;
Eric Christopher3a2656b2012-02-22 08:46:13 +000069
David Blaikie2a80e442013-12-02 22:09:48 +000070 /// Unit debug information entry.
71 const OwningPtr<DIE> UnitDie;
Devang Patel5eb43192011-04-12 17:40:32 +000072
David Blaikie2a80e442013-12-02 22:09:48 +000073 /// Offset of the UnitDie from beginning of debug info section.
Eric Christophera16725b2013-11-21 01:29:16 +000074 unsigned DebugInfoOffset;
75
Devang Patelf20c4f72011-04-12 22:53:02 +000076 /// Asm - Target of Dwarf emission.
77 AsmPrinter *Asm;
78
Eric Christophere698f532012-12-20 21:58:36 +000079 // Holders for some common dwarf information.
Devang Patelf20c4f72011-04-12 22:53:02 +000080 DwarfDebug *DD;
Eric Christophere698f532012-12-20 21:58:36 +000081 DwarfUnits *DU;
Devang Patelf20c4f72011-04-12 22:53:02 +000082
David Blaikie2a80e442013-12-02 22:09:48 +000083 /// IndexTyDie - An anonymous type for index type. Owned by UnitDie.
Devang Patel5eb43192011-04-12 17:40:32 +000084 DIE *IndexTyDie;
85
Eric Christopher61560112013-05-08 00:11:10 +000086 /// MDNodeToDieMap - Tracks the mapping of unit level debug information
Devang Patel5eb43192011-04-12 17:40:32 +000087 /// variables to debug information entries.
88 DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
89
Eric Christopher61560112013-05-08 00:11:10 +000090 /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug information
Devang Patel5eb43192011-04-12 17:40:32 +000091 /// descriptors to debug information entries using a DIEEntry proxy.
92 DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
93
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +000094 /// GlobalNames - A map of globally visible named entities for this unit.
Eric Christopher0fe676a2013-11-21 00:48:22 +000095 StringMap<const DIE *> GlobalNames;
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +000096
Devang Patel5eb43192011-04-12 17:40:32 +000097 /// GlobalTypes - A map of globally visible types for this unit.
Eric Christopher0fe676a2013-11-21 00:48:22 +000098 StringMap<const DIE *> GlobalTypes;
Devang Patel5eb43192011-04-12 17:40:32 +000099
Eric Christopher4996c702011-11-07 09:24:32 +0000100 /// AccelNames - A map of names for the name accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000101 StringMap<std::vector<const DIE *> > AccelNames;
Eric Christopher4affe8c2013-11-21 01:29:13 +0000102
103 /// AccelObjC - A map of objc spec for the objc accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000104 StringMap<std::vector<const DIE *> > AccelObjC;
Eric Christopher4affe8c2013-11-21 01:29:13 +0000105
106 /// AccelNamespace - A map of names for the namespace accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000107 StringMap<std::vector<const DIE *> > AccelNamespace;
Eric Christopher4affe8c2013-11-21 01:29:13 +0000108
109 /// AccelTypes - A map of names for the type accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000110 StringMap<std::vector<std::pair<const DIE *, unsigned> > > AccelTypes;
Eric Christopher4996c702011-11-07 09:24:32 +0000111
Devang Patelf20c4f72011-04-12 22:53:02 +0000112 /// DIEBlocks - A list of all the DIEBlocks in use.
113 std::vector<DIEBlock *> DIEBlocks;
114
Devang Patel89543712011-08-15 17:24:54 +0000115 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
116 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
117 /// corresponds to the MDNode mapped with the subprogram DIE.
118 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
119
Eric Christopher0f63d062013-12-03 00:45:45 +0000120 // List of range lists for a given compile unit, separate from the ranges for
121 // the CU itself.
Eric Christopher270ba4a2013-12-04 19:06:58 +0000122 SmallVector<RangeSpanList, 1> CURangeLists;
Eric Christopher0f63d062013-12-03 00:45:45 +0000123
Eric Christopher3264a482013-10-05 00:39:55 +0000124 // DIEValueAllocator - All DIEValues are allocated through this allocator.
125 BumpPtrAllocator DIEValueAllocator;
126
127 // DIEIntegerOne - A preallocated DIEValue because 1 is used frequently.
128 DIEInteger *DIEIntegerOne;
129
David Blaikie319a05f2013-12-02 19:33:10 +0000130 Unit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A, DwarfDebug *DW,
131 DwarfUnits *DWU);
132
Devang Patel5eb43192011-04-12 17:40:32 +0000133public:
David Blaikie319a05f2013-12-02 19:33:10 +0000134 virtual ~Unit();
Devang Patel5eb43192011-04-12 17:40:32 +0000135
136 // Accessors.
Eric Christopherca68bbf2013-08-26 23:58:22 +0000137 unsigned getUniqueID() const { return UniqueID; }
David Blaikie319a05f2013-12-02 19:33:10 +0000138 virtual uint16_t getLanguage() const = 0;
David Blaikieb01f13e2013-11-15 23:54:45 +0000139 DICompileUnit getNode() const { return Node; }
David Blaikie2a80e442013-12-02 22:09:48 +0000140 DIE *getUnitDie() const { return UnitDie.get(); }
Eric Christopher0fe676a2013-11-21 00:48:22 +0000141 const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; }
142 const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; }
Devang Patel5eb43192011-04-12 17:40:32 +0000143
David Blaikie2ea848b2013-11-19 22:51:04 +0000144 const StringMap<std::vector<const DIE *> > &getAccelNames() const {
Eric Christopherd9843b32011-11-10 19:25:34 +0000145 return AccelNames;
146 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000147 const StringMap<std::vector<const DIE *> > &getAccelObjC() const {
Eric Christopher4996c702011-11-07 09:24:32 +0000148 return AccelObjC;
149 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000150 const StringMap<std::vector<const DIE *> > &getAccelNamespace() const {
Eric Christopher66b37db2011-11-10 21:47:55 +0000151 return AccelNamespace;
152 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000153 const StringMap<std::vector<std::pair<const DIE *, unsigned> > > &
Eric Christopherca68bbf2013-08-26 23:58:22 +0000154 getAccelTypes() const {
Eric Christopher66b37db2011-11-10 21:47:55 +0000155 return AccelTypes;
156 }
Eric Christopher48fef592012-12-20 21:58:40 +0000157
Manman Rence20d462013-10-29 22:57:10 +0000158 unsigned getDebugInfoOffset() const { return DebugInfoOffset; }
159 void setDebugInfoOffset(unsigned DbgInfoOff) { DebugInfoOffset = DbgInfoOff; }
160
Devang Patel5eb43192011-04-12 17:40:32 +0000161 /// hasContent - Return true if this compile unit has something to write out.
David Blaikie2a80e442013-12-02 22:09:48 +0000162 bool hasContent() const { return !UnitDie->getChildren().empty(); }
Devang Patel5eb43192011-04-12 17:40:32 +0000163
Eric Christopher0f63d062013-12-03 00:45:45 +0000164 /// addRangeList - Add an address range list to the list of range lists.
Eric Christopher270ba4a2013-12-04 19:06:58 +0000165 void addRangeList(RangeSpanList Ranges) { CURangeLists.push_back(Ranges); }
Eric Christopher0f63d062013-12-03 00:45:45 +0000166
167 /// getRangeLists - Get the vector of range lists.
Eric Christopher270ba4a2013-12-04 19:06:58 +0000168 const SmallVectorImpl<RangeSpanList> &getRangeLists() const {
Eric Christopher0f63d062013-12-03 00:45:45 +0000169 return CURangeLists;
170 }
Eric Christopher270ba4a2013-12-04 19:06:58 +0000171 SmallVectorImpl<RangeSpanList> &getRangeLists() { return CURangeLists; }
Eric Christopher0f63d062013-12-03 00:45:45 +0000172
Eric Christopher2c8b7902013-10-17 02:06:06 +0000173 /// getParentContextString - Get a string containing the language specific
174 /// context for a global name.
175 std::string getParentContextString(DIScope Context) const;
176
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000177 /// addGlobalName - Add a new global entity to the compile unit.
178 ///
Eric Christopher2c8b7902013-10-17 02:06:06 +0000179 void addGlobalName(StringRef Name, DIE *Die, DIScope Context);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000180
Eric Christopher4996c702011-11-07 09:24:32 +0000181 /// addAccelName - Add a new name to the name accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000182 void addAccelName(StringRef Name, const DIE *Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000183
184 /// addAccelObjC - Add a new name to the ObjC accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000185 void addAccelObjC(StringRef Name, const DIE *Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000186
187 /// addAccelNamespace - Add a new name to the namespace accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000188 void addAccelNamespace(StringRef Name, const DIE *Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000189
190 /// addAccelType - Add a new type to the type accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000191 void addAccelType(StringRef Name, std::pair<const DIE *, unsigned> Die);
Eric Christopher48fef592012-12-20 21:58:40 +0000192
Devang Patel5eb43192011-04-12 17:40:32 +0000193 /// getDIE - Returns the debug information entry map slot for the
Manman Ren4dbdc902013-10-31 17:54:35 +0000194 /// specified debug variable. We delegate the request to DwarfDebug
195 /// when the MDNode can be part of the type system, since DIEs for
196 /// the type system can be shared across CUs and the mappings are
197 /// kept in DwarfDebug.
David Blaikie2ad00162013-11-15 23:09:13 +0000198 DIE *getDIE(DIDescriptor D) const;
Devang Patel5eb43192011-04-12 17:40:32 +0000199
Eric Christopher4affe8c2013-11-21 01:29:13 +0000200 /// getDIEBlock - Returns a fresh newly allocated DIEBlock.
Eric Christopherf0388b72013-10-04 23:49:29 +0000201 DIEBlock *getDIEBlock() { return new (DIEValueAllocator) DIEBlock(); }
Devang Patelf20c4f72011-04-12 22:53:02 +0000202
Manman Ren4dbdc902013-10-31 17:54:35 +0000203 /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug
204 /// when the MDNode can be part of the type system, since DIEs for
205 /// the type system can be shared across CUs and the mappings are
206 /// kept in DwarfDebug.
David Blaikie2ad00162013-11-15 23:09:13 +0000207 void insertDIE(DIDescriptor Desc, DIE *D);
Devang Patel5eb43192011-04-12 17:40:32 +0000208
Devang Patel5eb43192011-04-12 17:40:32 +0000209 /// addDie - Adds or interns the DIE to the compile unit.
210 ///
David Blaikie2a80e442013-12-02 22:09:48 +0000211 void addDie(DIE *Buffer) { UnitDie->addChild(Buffer); }
Devang Patel5eb43192011-04-12 17:40:32 +0000212
Eric Christopherbb69a272012-08-24 01:14:27 +0000213 /// addFlag - Add a flag that is true to the DIE.
David Blaikief2443192013-10-21 17:28:37 +0000214 void addFlag(DIE *Die, dwarf::Attribute Attribute);
Eric Christopher48fef592012-12-20 21:58:40 +0000215
Devang Patelf20c4f72011-04-12 22:53:02 +0000216 /// addUInt - Add an unsigned integer attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000217 void addUInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
218 uint64_t Integer);
219
220 void addUInt(DIEBlock *Block, dwarf::Form Form, uint64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000221
222 /// addSInt - Add an signed integer attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000223 void addSInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
224 int64_t Integer);
225
226 void addSInt(DIEBlock *Die, Optional<dwarf::Form> Form, int64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000227
228 /// addString - Add a string attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000229 void addString(DIE *Die, dwarf::Attribute Attribute, const StringRef Str);
Devang Patelf20c4f72011-04-12 22:53:02 +0000230
Eric Christopher2cbd5762013-01-07 19:32:41 +0000231 /// addLocalString - Add a string attribute data and value.
Eric Christophera07e4f52013-11-19 09:28:34 +0000232 void addLocalString(DIE *Die, dwarf::Attribute Attribute,
233 const StringRef Str);
Eric Christopher2cbd5762013-01-07 19:32:41 +0000234
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000235 /// addExpr - Add a Dwarf expression attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000236 void addExpr(DIEBlock *Die, dwarf::Form Form, const MCExpr *Expr);
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000237
Devang Patelf20c4f72011-04-12 22:53:02 +0000238 /// addLabel - Add a Dwarf label attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000239 void addLabel(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form,
Devang Patelf20c4f72011-04-12 22:53:02 +0000240 const MCSymbol *Label);
241
David Blaikief2443192013-10-21 17:28:37 +0000242 void addLabel(DIEBlock *Die, dwarf::Form Form, const MCSymbol *Label);
243
Eric Christopher33ff6972013-11-21 23:46:41 +0000244 /// addSectionLabel - Add a Dwarf section label attribute data and value.
245 ///
Eric Christopherf52eddf2013-11-26 22:23:27 +0000246 void addSectionLabel(DIE *Die, dwarf::Attribute Attribute,
247 const MCSymbol *Label);
Eric Christopher33ff6972013-11-21 23:46:41 +0000248
249 /// addSectionOffset - Add an offset into a section attribute data and value.
250 ///
251 void addSectionOffset(DIE *Die, dwarf::Attribute Attribute, uint64_t Integer);
252
Eric Christophere9ec2452013-01-18 22:11:33 +0000253 /// addOpAddress - Add a dwarf op address data and value using the
254 /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
David Blaikief2443192013-10-21 17:28:37 +0000255 void addOpAddress(DIEBlock *Die, const MCSymbol *Label);
Eric Christophere9ec2452013-01-18 22:11:33 +0000256
Eric Christopher33ff6972013-11-21 23:46:41 +0000257 /// addSectionDelta - Add a label delta attribute data and value.
258 void addSectionDelta(DIE *Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
259 const MCSymbol *Lo);
Devang Patelf20c4f72011-04-12 22:53:02 +0000260
261 /// addDIEEntry - Add a DIE attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000262 void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry);
Eric Christopher48fef592012-12-20 21:58:40 +0000263
Manman Ren4dbdc902013-10-31 17:54:35 +0000264 /// addDIEEntry - Add a DIE attribute data and value.
Manman Ren4dbdc902013-10-31 17:54:35 +0000265 void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIEEntry *Entry);
266
Devang Patelf20c4f72011-04-12 22:53:02 +0000267 /// addBlock - Add block data.
David Blaikief2443192013-10-21 17:28:37 +0000268 void addBlock(DIE *Die, dwarf::Attribute Attribute, DIEBlock *Block);
Devang Patelf20c4f72011-04-12 22:53:02 +0000269
270 /// addSourceLine - Add location information to specified debug information
271 /// entry.
272 void addSourceLine(DIE *Die, DIVariable V);
273 void addSourceLine(DIE *Die, DIGlobalVariable G);
274 void addSourceLine(DIE *Die, DISubprogram SP);
275 void addSourceLine(DIE *Die, DIType Ty);
276 void addSourceLine(DIE *Die, DINameSpace NS);
Eric Christopher70e1bd82012-03-29 08:42:56 +0000277 void addSourceLine(DIE *Die, DIObjCProperty Ty);
Devang Patelf20c4f72011-04-12 22:53:02 +0000278
279 /// addAddress - Add an address attribute to a die based on the location
280 /// provided.
Eric Christophera07e4f52013-11-19 09:28:34 +0000281 void addAddress(DIE *Die, dwarf::Attribute Attribute,
282 const MachineLocation &Location, bool Indirect = false);
Devang Patelf20c4f72011-04-12 22:53:02 +0000283
Devang Patelf20c4f72011-04-12 22:53:02 +0000284 /// addConstantValue - Add constant value entry in variable DIE.
Eric Christopher78fcf4902013-07-03 01:08:30 +0000285 void addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
286 void addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
287 void addConstantValue(DIE *Die, const APInt &Val, bool Unsigned);
Devang Patelf20c4f72011-04-12 22:53:02 +0000288
289 /// addConstantFPValue - Add constant value entry in variable DIE.
Eric Christopher78fcf4902013-07-03 01:08:30 +0000290 void addConstantFPValue(DIE *Die, const MachineOperand &MO);
291 void addConstantFPValue(DIE *Die, const ConstantFP *CFP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000292
293 /// addTemplateParams - Add template parameters in buffer.
294 void addTemplateParams(DIE &Buffer, DIArray TParams);
295
Devang Patelba5fbf12011-04-26 19:06:18 +0000296 /// addRegisterOp - Add register operand.
David Blaikief2443192013-10-21 17:28:37 +0000297 void addRegisterOp(DIEBlock *TheDie, unsigned Reg);
Devang Patelba5fbf12011-04-26 19:06:18 +0000298
299 /// addRegisterOffset - Add register offset.
David Blaikief2443192013-10-21 17:28:37 +0000300 void addRegisterOffset(DIEBlock *TheDie, unsigned Reg, int64_t Offset);
Devang Patelba5fbf12011-04-26 19:06:18 +0000301
Devang Patelf20c4f72011-04-12 22:53:02 +0000302 /// addComplexAddress - Start with the address based on the location provided,
303 /// and generate the DWARF information necessary to find the actual variable
304 /// (navigating the extra location information encoded in the type) based on
305 /// the starting location. Add the DWARF information to the die.
Eric Christophera07e4f52013-11-19 09:28:34 +0000306 void addComplexAddress(const DbgVariable &DV, DIE *Die,
307 dwarf::Attribute Attribute,
Devang Patelf20c4f72011-04-12 22:53:02 +0000308 const MachineLocation &Location);
309
310 // FIXME: Should be reformulated in terms of addComplexAddress.
311 /// addBlockByrefAddress - Start with the address based on the location
312 /// provided, and generate the DWARF information necessary to find the
313 /// actual Block variable (navigating the Block struct) based on the
314 /// starting location. Add the DWARF information to the die. Obsolete,
315 /// please use addComplexAddress instead.
Eric Christophera07e4f52013-11-19 09:28:34 +0000316 void addBlockByrefAddress(const DbgVariable &DV, DIE *Die,
317 dwarf::Attribute Attribute,
Devang Patelf20c4f72011-04-12 22:53:02 +0000318 const MachineLocation &Location);
319
Eric Christopher48fef592012-12-20 21:58:40 +0000320 /// addVariableAddress - Add DW_AT_location attribute for a
Devang Patel77dc5412011-04-27 22:45:24 +0000321 /// DbgVariable based on provided MachineLocation.
Eric Christopherbf2d23c2013-06-24 21:07:27 +0000322 void addVariableAddress(const DbgVariable &DV, DIE *Die,
323 MachineLocation Location);
Devang Patelf20c4f72011-04-12 22:53:02 +0000324
Eric Christopher7285c7d2012-03-28 07:34:31 +0000325 /// addType - Add a new type attribute to the specified entity. This takes
326 /// and attribute parameter because DW_AT_friend attributes are also
327 /// type references.
Eric Christophera07e4f52013-11-19 09:28:34 +0000328 void addType(DIE *Entity, DIType Ty,
329 dwarf::Attribute Attribute = dwarf::DW_AT_type);
Devang Patelf20c4f72011-04-12 22:53:02 +0000330
331 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
332 DIE *getOrCreateNameSpace(DINameSpace NS);
333
Devang Patel89543712011-08-15 17:24:54 +0000334 /// getOrCreateSubprogramDIE - Create new DIE using SP.
335 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
336
Devang Patelf20c4f72011-04-12 22:53:02 +0000337 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
338 /// given DIType.
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000339 DIE *getOrCreateTypeDIE(const MDNode *N);
Devang Patelf20c4f72011-04-12 22:53:02 +0000340
Eric Christopherfa205ca2013-10-05 00:05:51 +0000341 /// getOrCreateContextDIE - Get context owner's DIE.
David Blaikie409dd9c2013-11-19 23:08:21 +0000342 DIE *createTypeDIE(DICompositeType Ty);
343
344 /// getOrCreateContextDIE - Get context owner's DIE.
Eric Christopherfa205ca2013-10-05 00:05:51 +0000345 DIE *getOrCreateContextDIE(DIScope Context);
Devang Patelf20c4f72011-04-12 22:53:02 +0000346
Eric Christopherfa205ca2013-10-05 00:05:51 +0000347 /// constructContainingTypeDIEs - Construct DIEs for types that contain
348 /// vtables.
349 void constructContainingTypeDIEs();
Devang Patelf20c4f72011-04-12 22:53:02 +0000350
Eric Christopherfa205ca2013-10-05 00:05:51 +0000351 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
Eric Christopher34a2c872013-11-15 01:43:19 +0000352 DIE *constructVariableDIE(DbgVariable &DV, bool isScopeAbstract);
Eric Christopherfa205ca2013-10-05 00:05:51 +0000353
Manman Renb987e512013-10-29 00:53:03 +0000354 /// Create a DIE with the given Tag, add the DIE to its parent, and
355 /// call insertDIE if MD is not null.
Eric Christophera07e4f52013-11-19 09:28:34 +0000356 DIE *createAndAddDIE(unsigned Tag, DIE &Parent,
357 DIDescriptor N = DIDescriptor());
Manman Renb987e512013-10-29 00:53:03 +0000358
David Blaikie6b288cf2013-10-30 20:42:41 +0000359 /// Compute the size of a header for this unit, not including the initial
360 /// length field.
361 unsigned getHeaderSize() const {
362 return sizeof(int16_t) + // DWARF version number
363 sizeof(int32_t) + // Offset Into Abbrev. Section
364 sizeof(int8_t); // Pointer Size (in bytes)
365 }
366
367 /// Emit the header for this unit, not including the initial length field.
368 void emitHeader(const MCSection *ASection, const MCSymbol *ASectionSym);
369
David Blaikie319a05f2013-12-02 19:33:10 +0000370protected:
371 /// getOrCreateStaticMemberDIE - Create new static data member DIE.
372 DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
373
Eric Christopherfa205ca2013-10-05 00:05:51 +0000374private:
Devang Patelf20c4f72011-04-12 22:53:02 +0000375 /// constructTypeDIE - Construct basic type die from DIBasicType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000376 void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000377
378 /// constructTypeDIE - Construct derived type die from DIDerivedType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000379 void constructTypeDIE(DIE &Buffer, DIDerivedType DTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000380
381 /// constructTypeDIE - Construct type DIE from DICompositeType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000382 void constructTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000383
384 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
385 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
386
387 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
Eric Christopherdf9955d2013-11-11 18:52:31 +0000388 void constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000389
390 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
Eric Christopheraeb105f2013-11-11 18:52:39 +0000391 void constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000392
Manman Ren230ec862013-10-23 23:00:44 +0000393 /// constructMemberDIE - Construct member DIE from DIDerivedType.
394 void constructMemberDIE(DIE &Buffer, DIDerivedType DT);
Manman Ren7cc62702013-10-18 21:14:19 +0000395
Manman Renffc9a712013-10-23 23:05:28 +0000396 /// constructTemplateTypeParameterDIE - Construct new DIE for the given
397 /// DITemplateTypeParameter.
398 void constructTemplateTypeParameterDIE(DIE &Buffer,
399 DITemplateTypeParameter TP);
Manman Ren7cc62702013-10-18 21:14:19 +0000400
Manman Renffc9a712013-10-23 23:05:28 +0000401 /// constructTemplateValueParameterDIE - Construct new DIE for the given
402 /// DITemplateValueParameter.
403 void constructTemplateValueParameterDIE(DIE &Buffer,
404 DITemplateValueParameter TVP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000405
Eric Christopherfa205ca2013-10-05 00:05:51 +0000406 /// getLowerBoundDefault - Return the default lower bound for an array. If the
407 /// DWARF version doesn't handle the language, return -1.
408 int64_t getDefaultLowerBound() const;
409
410 /// getDIEEntry - Returns the debug information entry for the specified
411 /// debug variable.
412 DIEEntry *getDIEEntry(const MDNode *N) const {
413 return MDNodeToDIEEntryMap.lookup(N);
414 }
415
416 /// insertDIEEntry - Insert debug information entry into the map.
417 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
418 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
419 }
420
421 // getIndexTyDie - Get an anonymous type for index type.
422 DIE *getIndexTyDie() { return IndexTyDie; }
423
424 // setIndexTyDie - Set D as anonymous type for index which can be reused
425 // later.
426 void setIndexTyDie(DIE *D) { IndexTyDie = D; }
427
428 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
429 /// information entry.
430 DIEEntry *createDIEEntry(DIE *Entry);
David Blaikie684fc532013-05-06 23:33:07 +0000431
Eric Christopher9e429ae2013-10-05 00:27:02 +0000432 /// resolve - Look in the DwarfDebug map for the MDNode that
Eric Christopher87b9c492013-10-05 00:32:34 +0000433 /// corresponds to the reference.
Eric Christopher9e429ae2013-10-05 00:27:02 +0000434 template <typename T> T resolve(DIRef<T> Ref) const {
435 return DD->resolve(Ref);
436 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000437
438 /// If this is a named finished type then include it in the list of types for
439 /// the accelerator tables.
David Blaikie9d861be2013-11-26 00:15:27 +0000440 void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE *TyDIE);
Devang Patel5eb43192011-04-12 17:40:32 +0000441};
442
David Blaikie319a05f2013-12-02 19:33:10 +0000443class CompileUnit : public Unit {
444public:
445 CompileUnit(unsigned UID, DIE *D, DICompileUnit Node, AsmPrinter *A,
446 DwarfDebug *DW, DwarfUnits *DWU);
447
448 /// createGlobalVariableDIE - create global variable DIE.
449 void createGlobalVariableDIE(DIGlobalVariable GV);
450
451 /// addLabelAddress - Add a dwarf label attribute data and value using
452 /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
453 void addLabelAddress(DIE *Die, dwarf::Attribute Attribute, MCSymbol *Label);
454
455 uint16_t getLanguage() const { return getNode().getLanguage(); }
456};
457
458class TypeUnit : public Unit {
459private:
460 uint16_t Language;
461
462public:
463 TypeUnit(unsigned UID, DIE *D, uint16_t Language, AsmPrinter *A,
464 DwarfDebug *DW, DwarfUnits *DWU);
465
466 uint16_t getLanguage() const { return Language; }
467};
Devang Patel5eb43192011-04-12 17:40:32 +0000468} // end llvm namespace
469#endif