blob: 453e898579206860a3f48ae30e733b5a1c661d72 [file] [log] [blame]
Devang Patel8b9df622011-04-12 17:40:32 +00001//===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
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"
Devang Patel3cbee302011-04-12 22:53:02 +000018#include "llvm/Analysis/DebugInfo.h"
Devang Patel8b9df622011-04-12 17:40:32 +000019#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/OwningPtr.h"
22
23namespace llvm {
24
Devang Patel3cbee302011-04-12 22:53:02 +000025class DwarfDebug;
26class MachineLocation;
27class MachineOperand;
28class ConstantInt;
29class DbgVariable;
30
Devang Patel8b9df622011-04-12 17:40:32 +000031//===----------------------------------------------------------------------===//
Eric Christopher33aa20f2011-11-07 09:18:32 +000032/// CompileUnit - This dwarf writer support class manages information associated
Devang Patel8b9df622011-04-12 17:40:32 +000033/// with a source file.
34class CompileUnit {
35 /// ID - File identifier for source.
36 ///
37 unsigned ID;
38
39 /// Die - Compile unit debug information entry.
40 ///
41 const OwningPtr<DIE> CUDie;
42
Devang Patel3cbee302011-04-12 22:53:02 +000043 /// Asm - Target of Dwarf emission.
44 AsmPrinter *Asm;
45
46 DwarfDebug *DD;
47
Devang Patel8b9df622011-04-12 17:40:32 +000048 /// IndexTyDie - An anonymous type for index type. Owned by CUDie.
49 DIE *IndexTyDie;
50
51 /// MDNodeToDieMap - Tracks the mapping of unit level debug informaton
52 /// variables to debug information entries.
53 DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
54
55 /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug informaton
56 /// descriptors to debug information entries using a DIEEntry proxy.
57 DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
58
Devang Patel8b9df622011-04-12 17:40:32 +000059 /// GlobalTypes - A map of globally visible types for this unit.
60 ///
61 StringMap<DIE*> GlobalTypes;
62
Eric Christopher09ac3d82011-11-07 09:24:32 +000063 /// AccelNames - A map of names for the name accelerator table.
64 ///
Eric Christopher0ffe2b42011-11-10 19:25:34 +000065 StringMap<std::vector<DIE*> > AccelNames;
Eric Christopher09ac3d82011-11-07 09:24:32 +000066 StringMap<std::vector<DIE*> > AccelObjC;
67 StringMap<DIE*> AccelNamespace;
68 StringMap<DIE*> AccelTypes;
69
Devang Patel3cbee302011-04-12 22:53:02 +000070 /// DIEBlocks - A list of all the DIEBlocks in use.
71 std::vector<DIEBlock *> DIEBlocks;
72
Devang Pateldbc64af2011-08-15 17:24:54 +000073 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
74 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
75 /// corresponds to the MDNode mapped with the subprogram DIE.
76 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
77
Devang Patel8b9df622011-04-12 17:40:32 +000078public:
Devang Patel5d607632011-04-12 23:09:06 +000079 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW);
Devang Patel3cbee302011-04-12 22:53:02 +000080 ~CompileUnit();
Devang Patel8b9df622011-04-12 17:40:32 +000081
82 // Accessors.
83 unsigned getID() const { return ID; }
84 DIE* getCUDie() const { return CUDie.get(); }
Devang Patel8b9df622011-04-12 17:40:32 +000085 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
86
Eric Christopher0ffe2b42011-11-10 19:25:34 +000087 const StringMap<std::vector<DIE*> > &getAccelNames() const {
88 return AccelNames;
89 }
Eric Christopher09ac3d82011-11-07 09:24:32 +000090 const StringMap<std::vector<DIE*> > &getAccelObjC() const {
91 return AccelObjC;
92 }
93 const StringMap<DIE*> &getAccelNamespace() const { return AccelNamespace; }
94 const StringMap<DIE*> &getAccelTypes() const { return AccelTypes; }
95
Devang Patel8b9df622011-04-12 17:40:32 +000096 /// hasContent - Return true if this compile unit has something to write out.
97 ///
98 bool hasContent() const { return !CUDie->getChildren().empty(); }
99
Devang Patel8b9df622011-04-12 17:40:32 +0000100 /// addGlobalType - Add a new global type to the compile unit.
101 ///
Devang Patelc20bdf12011-06-01 00:23:24 +0000102 void addGlobalType(DIType Ty);
Devang Patel8b9df622011-04-12 17:40:32 +0000103
Eric Christopher09ac3d82011-11-07 09:24:32 +0000104
105 /// addAccelName - Add a new name to the name accelerator table.
Eric Christopher0ffe2b42011-11-10 19:25:34 +0000106 void addAccelName(StringRef Name, DIE *Die) {
107 std::vector<DIE*> &DIEs = AccelNames[Name];
108 DIEs.push_back(Die);
109 }
Eric Christopher09ac3d82011-11-07 09:24:32 +0000110 void addAccelObjC(StringRef Name, DIE *Die) {
111 std::vector<DIE*> &DIEs = AccelObjC[Name];
112 DIEs.push_back(Die);
113 }
114 void addAccelNamespace(StringRef Name, DIE *Die) {
115 AccelNamespace[Name] = Die;
116 }
117 void addAccelType(StringRef Name, DIE *Die) {
118 AccelTypes[Name] = Die;
119 }
120
Devang Patel8b9df622011-04-12 17:40:32 +0000121 /// getDIE - Returns the debug information entry map slot for the
122 /// specified debug variable.
123 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
124
Devang Patel3cbee302011-04-12 22:53:02 +0000125 DIEBlock *getDIEBlock() {
126 return new (DIEValueAllocator) DIEBlock();
127 }
128
Devang Patel8b9df622011-04-12 17:40:32 +0000129 /// insertDIE - Insert DIE into the map.
130 void insertDIE(const MDNode *N, DIE *D) {
131 MDNodeToDieMap.insert(std::make_pair(N, D));
132 }
133
Jim Grosbach1585ce72011-05-20 21:35:39 +0000134 /// getDIEEntry - Returns the debug information entry for the specified
Devang Patel8b9df622011-04-12 17:40:32 +0000135 /// debug variable.
136 DIEEntry *getDIEEntry(const MDNode *N) {
137 DenseMap<const MDNode *, DIEEntry *>::iterator I =
138 MDNodeToDIEEntryMap.find(N);
139 if (I == MDNodeToDIEEntryMap.end())
140 return NULL;
141 return I->second;
142 }
143
144 /// insertDIEEntry - Insert debug information entry into the map.
145 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
146 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
147 }
148
149 /// addDie - Adds or interns the DIE to the compile unit.
150 ///
151 void addDie(DIE *Buffer) {
152 this->CUDie->addChild(Buffer);
153 }
154
155 // getIndexTyDie - Get an anonymous type for index type.
156 DIE *getIndexTyDie() {
157 return IndexTyDie;
158 }
159
160 // setIndexTyDie - Set D as anonymous type for index which can be reused
161 // later.
162 void setIndexTyDie(DIE *D) {
163 IndexTyDie = D;
164 }
Devang Patel3cbee302011-04-12 22:53:02 +0000165public:
Devang Patel8b9df622011-04-12 17:40:32 +0000166
Devang Patel3cbee302011-04-12 22:53:02 +0000167 /// addUInt - Add an unsigned integer attribute data and value.
168 ///
169 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
170
171 /// addSInt - Add an signed integer attribute data and value.
172 ///
173 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
174
175 /// addString - Add a string attribute data and value.
176 ///
Nick Lewycky390c40d2011-10-27 06:44:11 +0000177 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
Devang Patel3cbee302011-04-12 22:53:02 +0000178
179 /// addLabel - Add a Dwarf label attribute data and value.
180 ///
181 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
182 const MCSymbol *Label);
183
184 /// addDelta - Add a label delta attribute data and value.
185 ///
186 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
187 const MCSymbol *Hi, const MCSymbol *Lo);
188
189 /// addDIEEntry - Add a DIE attribute data and value.
190 ///
191 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
192
193 /// addBlock - Add block data.
194 ///
195 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
196
197 /// addSourceLine - Add location information to specified debug information
198 /// entry.
199 void addSourceLine(DIE *Die, DIVariable V);
200 void addSourceLine(DIE *Die, DIGlobalVariable G);
201 void addSourceLine(DIE *Die, DISubprogram SP);
202 void addSourceLine(DIE *Die, DIType Ty);
203 void addSourceLine(DIE *Die, DINameSpace NS);
204
205 /// addAddress - Add an address attribute to a die based on the location
206 /// provided.
207 void addAddress(DIE *Die, unsigned Attribute,
208 const MachineLocation &Location);
209
Devang Patel3cbee302011-04-12 22:53:02 +0000210 /// addConstantValue - Add constant value entry in variable DIE.
Devang Patelb58128e2011-05-27 16:45:18 +0000211 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
Devang Patel8594d422011-06-24 20:46:11 +0000212 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
Devang Patel3cbee302011-04-12 22:53:02 +0000213
214 /// addConstantFPValue - Add constant value entry in variable DIE.
215 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
216
217 /// addTemplateParams - Add template parameters in buffer.
218 void addTemplateParams(DIE &Buffer, DIArray TParams);
219
Devang Patel116da2f2011-04-26 19:06:18 +0000220 /// addRegisterOp - Add register operand.
221 void addRegisterOp(DIE *TheDie, unsigned Reg);
222
223 /// addRegisterOffset - Add register offset.
224 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
225
Devang Patel3cbee302011-04-12 22:53:02 +0000226 /// addComplexAddress - Start with the address based on the location provided,
227 /// and generate the DWARF information necessary to find the actual variable
228 /// (navigating the extra location information encoded in the type) based on
229 /// the starting location. Add the DWARF information to the die.
230 ///
231 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
232 const MachineLocation &Location);
233
234 // FIXME: Should be reformulated in terms of addComplexAddress.
235 /// addBlockByrefAddress - Start with the address based on the location
236 /// provided, and generate the DWARF information necessary to find the
237 /// actual Block variable (navigating the Block struct) based on the
238 /// starting location. Add the DWARF information to the die. Obsolete,
239 /// please use addComplexAddress instead.
240 ///
241 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
242 const MachineLocation &Location);
243
Devang Patele1cdf842011-04-27 22:45:24 +0000244 /// addVariableAddress - Add DW_AT_location attribute for a
245 /// DbgVariable based on provided MachineLocation.
246 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
Devang Patel3cbee302011-04-12 22:53:02 +0000247
248 /// addToContextOwner - Add Die into the list of its context owner's children.
249 void addToContextOwner(DIE *Die, DIDescriptor Context);
250
251 /// addType - Add a new type attribute to the specified entity.
252 void addType(DIE *Entity, DIType Ty);
253
254 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
255 DIE *getOrCreateNameSpace(DINameSpace NS);
256
Devang Pateldbc64af2011-08-15 17:24:54 +0000257 /// getOrCreateSubprogramDIE - Create new DIE using SP.
258 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
259
Devang Patel3cbee302011-04-12 22:53:02 +0000260 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
261 /// given DIType.
Devang Patel94c7ddb2011-08-16 22:09:43 +0000262 DIE *getOrCreateTypeDIE(const MDNode *N);
Devang Patel3cbee302011-04-12 22:53:02 +0000263
264 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
265 /// for the given DITemplateTypeParameter.
266 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
267
268 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
269 /// for the given DITemplateValueParameter.
270 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
271
272 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
273 /// information entry.
274 DIEEntry *createDIEEntry(DIE *Entry);
275
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000276 /// createGlobalVariableDIE - create global variable DIE.
277 void createGlobalVariableDIE(const MDNode *N);
278
Devang Patel3cbee302011-04-12 22:53:02 +0000279 void addPubTypes(DISubprogram SP);
280
281 /// constructTypeDIE - Construct basic type die from DIBasicType.
282 void constructTypeDIE(DIE &Buffer,
283 DIBasicType BTy);
284
285 /// constructTypeDIE - Construct derived type die from DIDerivedType.
286 void constructTypeDIE(DIE &Buffer,
287 DIDerivedType DTy);
288
289 /// constructTypeDIE - Construct type DIE from DICompositeType.
290 void constructTypeDIE(DIE &Buffer,
291 DICompositeType CTy);
292
293 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
294 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
295
296 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
297 void constructArrayTypeDIE(DIE &Buffer,
298 DICompositeType *CTy);
299
300 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
301 DIE *constructEnumTypeDIE(DIEnumerator ETy);
302
Devang Pateldbc64af2011-08-15 17:24:54 +0000303 /// constructContainingTypeDIEs - Construct DIEs for types that contain
304 /// vtables.
305 void constructContainingTypeDIEs();
306
Devang Pateld0b5a5e2011-08-15 22:04:40 +0000307 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
308 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
309
Devang Patel3cbee302011-04-12 22:53:02 +0000310 /// createMemberDIE - Create new member DIE.
311 DIE *createMemberDIE(DIDerivedType DT);
312
313private:
314
315 // DIEValueAllocator - All DIEValues are allocated through this allocator.
316 BumpPtrAllocator DIEValueAllocator;
317 DIEInteger *DIEIntegerOne;
Devang Patel8b9df622011-04-12 17:40:32 +0000318};
319
320} // end llvm namespace
321#endif