blob: 07a772338ee9e05a2a866bcc33196ebdb0066465 [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;
Eric Christopher8bd36ea2011-11-10 21:47:55 +000067 StringMap<std::vector<DIE*> > AccelNamespace;
68 StringMap<std::vector<DIE*> > AccelTypes;
Eric Christopher09ac3d82011-11-07 09:24:32 +000069
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 }
Eric Christopher8bd36ea2011-11-10 21:47:55 +000093 const StringMap<std::vector<DIE*> > &getAccelNamespace() const {
94 return AccelNamespace;
95 }
96 const StringMap<std::vector<DIE*> > &getAccelTypes() const {
97 return AccelTypes;
98 }
Eric Christopher09ac3d82011-11-07 09:24:32 +000099
Devang Patel8b9df622011-04-12 17:40:32 +0000100 /// hasContent - Return true if this compile unit has something to write out.
101 ///
102 bool hasContent() const { return !CUDie->getChildren().empty(); }
103
Devang Patel8b9df622011-04-12 17:40:32 +0000104 /// addGlobalType - Add a new global type to the compile unit.
105 ///
Devang Patelc20bdf12011-06-01 00:23:24 +0000106 void addGlobalType(DIType Ty);
Devang Patel8b9df622011-04-12 17:40:32 +0000107
Eric Christopher09ac3d82011-11-07 09:24:32 +0000108
109 /// addAccelName - Add a new name to the name accelerator table.
Eric Christopher0ffe2b42011-11-10 19:25:34 +0000110 void addAccelName(StringRef Name, DIE *Die) {
111 std::vector<DIE*> &DIEs = AccelNames[Name];
112 DIEs.push_back(Die);
113 }
Eric Christopher09ac3d82011-11-07 09:24:32 +0000114 void addAccelObjC(StringRef Name, DIE *Die) {
115 std::vector<DIE*> &DIEs = AccelObjC[Name];
116 DIEs.push_back(Die);
117 }
118 void addAccelNamespace(StringRef Name, DIE *Die) {
Eric Christopher8bd36ea2011-11-10 21:47:55 +0000119 std::vector<DIE*> &DIEs = AccelNamespace[Name];
120 DIEs.push_back(Die);
Eric Christopher09ac3d82011-11-07 09:24:32 +0000121 }
122 void addAccelType(StringRef Name, DIE *Die) {
Eric Christopher8bd36ea2011-11-10 21:47:55 +0000123 std::vector<DIE*> &DIEs = AccelTypes[Name];
124 DIEs.push_back(Die);
Eric Christopher09ac3d82011-11-07 09:24:32 +0000125 }
126
Devang Patel8b9df622011-04-12 17:40:32 +0000127 /// getDIE - Returns the debug information entry map slot for the
128 /// specified debug variable.
129 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
130
Devang Patel3cbee302011-04-12 22:53:02 +0000131 DIEBlock *getDIEBlock() {
132 return new (DIEValueAllocator) DIEBlock();
133 }
134
Devang Patel8b9df622011-04-12 17:40:32 +0000135 /// insertDIE - Insert DIE into the map.
136 void insertDIE(const MDNode *N, DIE *D) {
137 MDNodeToDieMap.insert(std::make_pair(N, D));
138 }
139
Jim Grosbach1585ce72011-05-20 21:35:39 +0000140 /// getDIEEntry - Returns the debug information entry for the specified
Devang Patel8b9df622011-04-12 17:40:32 +0000141 /// debug variable.
142 DIEEntry *getDIEEntry(const MDNode *N) {
143 DenseMap<const MDNode *, DIEEntry *>::iterator I =
144 MDNodeToDIEEntryMap.find(N);
145 if (I == MDNodeToDIEEntryMap.end())
146 return NULL;
147 return I->second;
148 }
149
150 /// insertDIEEntry - Insert debug information entry into the map.
151 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
152 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
153 }
154
155 /// addDie - Adds or interns the DIE to the compile unit.
156 ///
157 void addDie(DIE *Buffer) {
158 this->CUDie->addChild(Buffer);
159 }
160
161 // getIndexTyDie - Get an anonymous type for index type.
162 DIE *getIndexTyDie() {
163 return IndexTyDie;
164 }
165
166 // setIndexTyDie - Set D as anonymous type for index which can be reused
167 // later.
168 void setIndexTyDie(DIE *D) {
169 IndexTyDie = D;
170 }
Devang Patel3cbee302011-04-12 22:53:02 +0000171public:
Devang Patel8b9df622011-04-12 17:40:32 +0000172
Devang Patel3cbee302011-04-12 22:53:02 +0000173 /// addUInt - Add an unsigned integer attribute data and value.
174 ///
175 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
176
177 /// addSInt - Add an signed integer attribute data and value.
178 ///
179 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
180
181 /// addString - Add a string attribute data and value.
182 ///
Nick Lewycky390c40d2011-10-27 06:44:11 +0000183 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
Devang Patel3cbee302011-04-12 22:53:02 +0000184
185 /// addLabel - Add a Dwarf label attribute data and value.
186 ///
187 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
188 const MCSymbol *Label);
189
190 /// addDelta - Add a label delta attribute data and value.
191 ///
192 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
193 const MCSymbol *Hi, const MCSymbol *Lo);
194
195 /// addDIEEntry - Add a DIE attribute data and value.
196 ///
197 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
198
199 /// addBlock - Add block data.
200 ///
201 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
202
203 /// addSourceLine - Add location information to specified debug information
204 /// entry.
205 void addSourceLine(DIE *Die, DIVariable V);
206 void addSourceLine(DIE *Die, DIGlobalVariable G);
207 void addSourceLine(DIE *Die, DISubprogram SP);
208 void addSourceLine(DIE *Die, DIType Ty);
209 void addSourceLine(DIE *Die, DINameSpace NS);
210
211 /// addAddress - Add an address attribute to a die based on the location
212 /// provided.
213 void addAddress(DIE *Die, unsigned Attribute,
214 const MachineLocation &Location);
215
Devang Patel3cbee302011-04-12 22:53:02 +0000216 /// addConstantValue - Add constant value entry in variable DIE.
Devang Patelb58128e2011-05-27 16:45:18 +0000217 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
Devang Patel8594d422011-06-24 20:46:11 +0000218 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
Devang Patel3cbee302011-04-12 22:53:02 +0000219
220 /// addConstantFPValue - Add constant value entry in variable DIE.
221 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
222
223 /// addTemplateParams - Add template parameters in buffer.
224 void addTemplateParams(DIE &Buffer, DIArray TParams);
225
Devang Patel116da2f2011-04-26 19:06:18 +0000226 /// addRegisterOp - Add register operand.
227 void addRegisterOp(DIE *TheDie, unsigned Reg);
228
229 /// addRegisterOffset - Add register offset.
230 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
231
Devang Patel3cbee302011-04-12 22:53:02 +0000232 /// addComplexAddress - Start with the address based on the location provided,
233 /// and generate the DWARF information necessary to find the actual variable
234 /// (navigating the extra location information encoded in the type) based on
235 /// the starting location. Add the DWARF information to the die.
236 ///
237 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
238 const MachineLocation &Location);
239
240 // FIXME: Should be reformulated in terms of addComplexAddress.
241 /// addBlockByrefAddress - Start with the address based on the location
242 /// provided, and generate the DWARF information necessary to find the
243 /// actual Block variable (navigating the Block struct) based on the
244 /// starting location. Add the DWARF information to the die. Obsolete,
245 /// please use addComplexAddress instead.
246 ///
247 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
248 const MachineLocation &Location);
249
Devang Patele1cdf842011-04-27 22:45:24 +0000250 /// addVariableAddress - Add DW_AT_location attribute for a
251 /// DbgVariable based on provided MachineLocation.
252 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
Devang Patel3cbee302011-04-12 22:53:02 +0000253
254 /// addToContextOwner - Add Die into the list of its context owner's children.
255 void addToContextOwner(DIE *Die, DIDescriptor Context);
256
257 /// addType - Add a new type attribute to the specified entity.
258 void addType(DIE *Entity, DIType Ty);
259
260 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
261 DIE *getOrCreateNameSpace(DINameSpace NS);
262
Devang Pateldbc64af2011-08-15 17:24:54 +0000263 /// getOrCreateSubprogramDIE - Create new DIE using SP.
264 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
265
Devang Patel3cbee302011-04-12 22:53:02 +0000266 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
267 /// given DIType.
Devang Patel94c7ddb2011-08-16 22:09:43 +0000268 DIE *getOrCreateTypeDIE(const MDNode *N);
Devang Patel3cbee302011-04-12 22:53:02 +0000269
270 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
271 /// for the given DITemplateTypeParameter.
272 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
273
274 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
275 /// for the given DITemplateValueParameter.
276 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
277
278 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
279 /// information entry.
280 DIEEntry *createDIEEntry(DIE *Entry);
281
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000282 /// createGlobalVariableDIE - create global variable DIE.
283 void createGlobalVariableDIE(const MDNode *N);
284
Devang Patel3cbee302011-04-12 22:53:02 +0000285 void addPubTypes(DISubprogram SP);
286
287 /// constructTypeDIE - Construct basic type die from DIBasicType.
288 void constructTypeDIE(DIE &Buffer,
289 DIBasicType BTy);
290
291 /// constructTypeDIE - Construct derived type die from DIDerivedType.
292 void constructTypeDIE(DIE &Buffer,
293 DIDerivedType DTy);
294
295 /// constructTypeDIE - Construct type DIE from DICompositeType.
296 void constructTypeDIE(DIE &Buffer,
297 DICompositeType CTy);
298
299 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
300 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
301
302 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
303 void constructArrayTypeDIE(DIE &Buffer,
304 DICompositeType *CTy);
305
306 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
307 DIE *constructEnumTypeDIE(DIEnumerator ETy);
308
Devang Pateldbc64af2011-08-15 17:24:54 +0000309 /// constructContainingTypeDIEs - Construct DIEs for types that contain
310 /// vtables.
311 void constructContainingTypeDIEs();
312
Devang Pateld0b5a5e2011-08-15 22:04:40 +0000313 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
314 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
315
Devang Patel3cbee302011-04-12 22:53:02 +0000316 /// createMemberDIE - Create new member DIE.
317 DIE *createMemberDIE(DIDerivedType DT);
318
319private:
320
321 // DIEValueAllocator - All DIEValues are allocated through this allocator.
322 BumpPtrAllocator DIEValueAllocator;
323 DIEInteger *DIEIntegerOne;
Devang Patel8b9df622011-04-12 17:40:32 +0000324};
325
326} // end llvm namespace
327#endif