blob: b994ce373450dff208cb0503dc0acd9cfb89406f [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
59 /// Globals - A map of globally visible named entities for this unit.
60 ///
61 StringMap<DIE*> Globals;
62
63 /// GlobalTypes - A map of globally visible types for this unit.
64 ///
65 StringMap<DIE*> GlobalTypes;
66
Eric Christopher09ac3d82011-11-07 09:24:32 +000067 /// AccelNames - A map of names for the name accelerator table.
68 ///
69 StringMap<DIE*> AccelNames;
70 StringMap<std::vector<DIE*> > AccelObjC;
71 StringMap<DIE*> AccelNamespace;
72 StringMap<DIE*> AccelTypes;
73
Devang Patel3cbee302011-04-12 22:53:02 +000074 /// DIEBlocks - A list of all the DIEBlocks in use.
75 std::vector<DIEBlock *> DIEBlocks;
76
Devang Pateldbc64af2011-08-15 17:24:54 +000077 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
78 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
79 /// corresponds to the MDNode mapped with the subprogram DIE.
80 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
81
Devang Patel8b9df622011-04-12 17:40:32 +000082public:
Devang Patel5d607632011-04-12 23:09:06 +000083 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW);
Devang Patel3cbee302011-04-12 22:53:02 +000084 ~CompileUnit();
Devang Patel8b9df622011-04-12 17:40:32 +000085
86 // Accessors.
87 unsigned getID() const { return ID; }
88 DIE* getCUDie() const { return CUDie.get(); }
89 const StringMap<DIE*> &getGlobals() const { return Globals; }
90 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
91
Eric Christopher09ac3d82011-11-07 09:24:32 +000092 const StringMap<DIE*> &getAccelNames() const { return AccelNames; }
93 const StringMap<std::vector<DIE*> > &getAccelObjC() const {
94 return AccelObjC;
95 }
96 const StringMap<DIE*> &getAccelNamespace() const { return AccelNamespace; }
97 const StringMap<DIE*> &getAccelTypes() const { return AccelTypes; }
98
Devang Patel8b9df622011-04-12 17:40:32 +000099 /// hasContent - Return true if this compile unit has something to write out.
100 ///
101 bool hasContent() const { return !CUDie->getChildren().empty(); }
102
103 /// addGlobal - Add a new global entity to the compile unit.
104 ///
105 void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; }
106
107 /// addGlobalType - Add a new global type to the compile unit.
108 ///
Devang Patelc20bdf12011-06-01 00:23:24 +0000109 void addGlobalType(DIType Ty);
Devang Patel8b9df622011-04-12 17:40:32 +0000110
Eric Christopher09ac3d82011-11-07 09:24:32 +0000111
112 /// addAccelName - Add a new name to the name accelerator table.
113 void addAccelName(StringRef Name, DIE *Die) { AccelNames[Name] = Die; }
114 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) {
119 AccelNamespace[Name] = Die;
120 }
121 void addAccelType(StringRef Name, DIE *Die) {
122 AccelTypes[Name] = Die;
123 }
124
Devang Patel8b9df622011-04-12 17:40:32 +0000125 /// getDIE - Returns the debug information entry map slot for the
126 /// specified debug variable.
127 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
128
Devang Patel3cbee302011-04-12 22:53:02 +0000129 DIEBlock *getDIEBlock() {
130 return new (DIEValueAllocator) DIEBlock();
131 }
132
Devang Patel8b9df622011-04-12 17:40:32 +0000133 /// insertDIE - Insert DIE into the map.
134 void insertDIE(const MDNode *N, DIE *D) {
135 MDNodeToDieMap.insert(std::make_pair(N, D));
136 }
137
Jim Grosbach1585ce72011-05-20 21:35:39 +0000138 /// getDIEEntry - Returns the debug information entry for the specified
Devang Patel8b9df622011-04-12 17:40:32 +0000139 /// debug variable.
140 DIEEntry *getDIEEntry(const MDNode *N) {
141 DenseMap<const MDNode *, DIEEntry *>::iterator I =
142 MDNodeToDIEEntryMap.find(N);
143 if (I == MDNodeToDIEEntryMap.end())
144 return NULL;
145 return I->second;
146 }
147
148 /// insertDIEEntry - Insert debug information entry into the map.
149 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
150 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
151 }
152
153 /// addDie - Adds or interns the DIE to the compile unit.
154 ///
155 void addDie(DIE *Buffer) {
156 this->CUDie->addChild(Buffer);
157 }
158
159 // getIndexTyDie - Get an anonymous type for index type.
160 DIE *getIndexTyDie() {
161 return IndexTyDie;
162 }
163
164 // setIndexTyDie - Set D as anonymous type for index which can be reused
165 // later.
166 void setIndexTyDie(DIE *D) {
167 IndexTyDie = D;
168 }
Devang Patel3cbee302011-04-12 22:53:02 +0000169public:
Devang Patel8b9df622011-04-12 17:40:32 +0000170
Devang Patel3cbee302011-04-12 22:53:02 +0000171 /// addUInt - Add an unsigned integer attribute data and value.
172 ///
173 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
174
175 /// addSInt - Add an signed integer attribute data and value.
176 ///
177 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
178
179 /// addString - Add a string attribute data and value.
180 ///
Nick Lewycky390c40d2011-10-27 06:44:11 +0000181 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
Devang Patel3cbee302011-04-12 22:53:02 +0000182
183 /// addLabel - Add a Dwarf label attribute data and value.
184 ///
185 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
186 const MCSymbol *Label);
187
188 /// addDelta - Add a label delta attribute data and value.
189 ///
190 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
191 const MCSymbol *Hi, const MCSymbol *Lo);
192
193 /// addDIEEntry - Add a DIE attribute data and value.
194 ///
195 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
196
197 /// addBlock - Add block data.
198 ///
199 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
200
201 /// addSourceLine - Add location information to specified debug information
202 /// entry.
203 void addSourceLine(DIE *Die, DIVariable V);
204 void addSourceLine(DIE *Die, DIGlobalVariable G);
205 void addSourceLine(DIE *Die, DISubprogram SP);
206 void addSourceLine(DIE *Die, DIType Ty);
207 void addSourceLine(DIE *Die, DINameSpace NS);
208
209 /// addAddress - Add an address attribute to a die based on the location
210 /// provided.
211 void addAddress(DIE *Die, unsigned Attribute,
212 const MachineLocation &Location);
213
Devang Patel3cbee302011-04-12 22:53:02 +0000214 /// addConstantValue - Add constant value entry in variable DIE.
Devang Patelb58128e2011-05-27 16:45:18 +0000215 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
Devang Patel8594d422011-06-24 20:46:11 +0000216 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
Devang Patel3cbee302011-04-12 22:53:02 +0000217
218 /// addConstantFPValue - Add constant value entry in variable DIE.
219 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
220
221 /// addTemplateParams - Add template parameters in buffer.
222 void addTemplateParams(DIE &Buffer, DIArray TParams);
223
Devang Patel116da2f2011-04-26 19:06:18 +0000224 /// addRegisterOp - Add register operand.
225 void addRegisterOp(DIE *TheDie, unsigned Reg);
226
227 /// addRegisterOffset - Add register offset.
228 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
229
Devang Patel3cbee302011-04-12 22:53:02 +0000230 /// addComplexAddress - Start with the address based on the location provided,
231 /// and generate the DWARF information necessary to find the actual variable
232 /// (navigating the extra location information encoded in the type) based on
233 /// the starting location. Add the DWARF information to the die.
234 ///
235 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
236 const MachineLocation &Location);
237
238 // FIXME: Should be reformulated in terms of addComplexAddress.
239 /// addBlockByrefAddress - Start with the address based on the location
240 /// provided, and generate the DWARF information necessary to find the
241 /// actual Block variable (navigating the Block struct) based on the
242 /// starting location. Add the DWARF information to the die. Obsolete,
243 /// please use addComplexAddress instead.
244 ///
245 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
246 const MachineLocation &Location);
247
Devang Patele1cdf842011-04-27 22:45:24 +0000248 /// addVariableAddress - Add DW_AT_location attribute for a
249 /// DbgVariable based on provided MachineLocation.
250 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
Devang Patel3cbee302011-04-12 22:53:02 +0000251
252 /// addToContextOwner - Add Die into the list of its context owner's children.
253 void addToContextOwner(DIE *Die, DIDescriptor Context);
254
255 /// addType - Add a new type attribute to the specified entity.
256 void addType(DIE *Entity, DIType Ty);
257
258 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
259 DIE *getOrCreateNameSpace(DINameSpace NS);
260
Devang Pateldbc64af2011-08-15 17:24:54 +0000261 /// getOrCreateSubprogramDIE - Create new DIE using SP.
262 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
263
Devang Patel3cbee302011-04-12 22:53:02 +0000264 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
265 /// given DIType.
Devang Patel94c7ddb2011-08-16 22:09:43 +0000266 DIE *getOrCreateTypeDIE(const MDNode *N);
Devang Patel3cbee302011-04-12 22:53:02 +0000267
268 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
269 /// for the given DITemplateTypeParameter.
270 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
271
272 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
273 /// for the given DITemplateValueParameter.
274 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
275
276 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
277 /// information entry.
278 DIEEntry *createDIEEntry(DIE *Entry);
279
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000280 /// createGlobalVariableDIE - create global variable DIE.
281 void createGlobalVariableDIE(const MDNode *N);
282
Devang Patel3cbee302011-04-12 22:53:02 +0000283 void addPubTypes(DISubprogram SP);
284
285 /// constructTypeDIE - Construct basic type die from DIBasicType.
286 void constructTypeDIE(DIE &Buffer,
287 DIBasicType BTy);
288
289 /// constructTypeDIE - Construct derived type die from DIDerivedType.
290 void constructTypeDIE(DIE &Buffer,
291 DIDerivedType DTy);
292
293 /// constructTypeDIE - Construct type DIE from DICompositeType.
294 void constructTypeDIE(DIE &Buffer,
295 DICompositeType CTy);
296
297 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
298 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
299
300 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
301 void constructArrayTypeDIE(DIE &Buffer,
302 DICompositeType *CTy);
303
304 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
305 DIE *constructEnumTypeDIE(DIEnumerator ETy);
306
Devang Pateldbc64af2011-08-15 17:24:54 +0000307 /// constructContainingTypeDIEs - Construct DIEs for types that contain
308 /// vtables.
309 void constructContainingTypeDIEs();
310
Devang Pateld0b5a5e2011-08-15 22:04:40 +0000311 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
312 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
313
Devang Patel3cbee302011-04-12 22:53:02 +0000314 /// createMemberDIE - Create new member DIE.
315 DIE *createMemberDIE(DIDerivedType DT);
316
317private:
318
319 // DIEValueAllocator - All DIEValues are allocated through this allocator.
320 BumpPtrAllocator DIEValueAllocator;
321 DIEInteger *DIEIntegerOne;
Devang Patel8b9df622011-04-12 17:40:32 +0000322};
323
324} // end llvm namespace
325#endif