blob: 96d7902f06ecfaae483c58e38ebabc6fbb4d23bf [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//===----------------------------------------------------------------------===//
32/// CompileUnit - This dwarf writer support class manages information associate
33/// 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
Devang Patel3cbee302011-04-12 22:53:02 +000067 /// DIEBlocks - A list of all the DIEBlocks in use.
68 std::vector<DIEBlock *> DIEBlocks;
69
Devang Pateldbc64af2011-08-15 17:24:54 +000070 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
71 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
72 /// corresponds to the MDNode mapped with the subprogram DIE.
73 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
74
Devang Patel8b9df622011-04-12 17:40:32 +000075public:
Devang Patel5d607632011-04-12 23:09:06 +000076 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW);
Devang Patel3cbee302011-04-12 22:53:02 +000077 ~CompileUnit();
Devang Patel8b9df622011-04-12 17:40:32 +000078
79 // Accessors.
80 unsigned getID() const { return ID; }
81 DIE* getCUDie() const { return CUDie.get(); }
82 const StringMap<DIE*> &getGlobals() const { return Globals; }
83 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
84
85 /// hasContent - Return true if this compile unit has something to write out.
86 ///
87 bool hasContent() const { return !CUDie->getChildren().empty(); }
88
89 /// addGlobal - Add a new global entity to the compile unit.
90 ///
91 void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; }
92
93 /// addGlobalType - Add a new global type to the compile unit.
94 ///
Devang Patelc20bdf12011-06-01 00:23:24 +000095 void addGlobalType(DIType Ty);
Devang Patel8b9df622011-04-12 17:40:32 +000096
97 /// getDIE - Returns the debug information entry map slot for the
98 /// specified debug variable.
99 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
100
Devang Patel3cbee302011-04-12 22:53:02 +0000101 DIEBlock *getDIEBlock() {
102 return new (DIEValueAllocator) DIEBlock();
103 }
104
Devang Patel8b9df622011-04-12 17:40:32 +0000105 /// insertDIE - Insert DIE into the map.
106 void insertDIE(const MDNode *N, DIE *D) {
107 MDNodeToDieMap.insert(std::make_pair(N, D));
108 }
109
Jim Grosbach1585ce72011-05-20 21:35:39 +0000110 /// getDIEEntry - Returns the debug information entry for the specified
Devang Patel8b9df622011-04-12 17:40:32 +0000111 /// debug variable.
112 DIEEntry *getDIEEntry(const MDNode *N) {
113 DenseMap<const MDNode *, DIEEntry *>::iterator I =
114 MDNodeToDIEEntryMap.find(N);
115 if (I == MDNodeToDIEEntryMap.end())
116 return NULL;
117 return I->second;
118 }
119
120 /// insertDIEEntry - Insert debug information entry into the map.
121 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
122 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
123 }
124
125 /// addDie - Adds or interns the DIE to the compile unit.
126 ///
127 void addDie(DIE *Buffer) {
128 this->CUDie->addChild(Buffer);
129 }
130
131 // getIndexTyDie - Get an anonymous type for index type.
132 DIE *getIndexTyDie() {
133 return IndexTyDie;
134 }
135
136 // setIndexTyDie - Set D as anonymous type for index which can be reused
137 // later.
138 void setIndexTyDie(DIE *D) {
139 IndexTyDie = D;
140 }
Devang Patel3cbee302011-04-12 22:53:02 +0000141public:
Devang Patel8b9df622011-04-12 17:40:32 +0000142
Devang Patel3cbee302011-04-12 22:53:02 +0000143 /// addUInt - Add an unsigned integer attribute data and value.
144 ///
145 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
146
147 /// addSInt - Add an signed integer attribute data and value.
148 ///
149 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
150
151 /// addString - Add a string attribute data and value.
152 ///
Nick Lewycky390c40d2011-10-27 06:44:11 +0000153 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
Devang Patel3cbee302011-04-12 22:53:02 +0000154
155 /// addLabel - Add a Dwarf label attribute data and value.
156 ///
157 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
158 const MCSymbol *Label);
159
160 /// addDelta - Add a label delta attribute data and value.
161 ///
162 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
163 const MCSymbol *Hi, const MCSymbol *Lo);
164
165 /// addDIEEntry - Add a DIE attribute data and value.
166 ///
167 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
168
169 /// addBlock - Add block data.
170 ///
171 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
172
173 /// addSourceLine - Add location information to specified debug information
174 /// entry.
175 void addSourceLine(DIE *Die, DIVariable V);
176 void addSourceLine(DIE *Die, DIGlobalVariable G);
177 void addSourceLine(DIE *Die, DISubprogram SP);
178 void addSourceLine(DIE *Die, DIType Ty);
179 void addSourceLine(DIE *Die, DINameSpace NS);
180
181 /// addAddress - Add an address attribute to a die based on the location
182 /// provided.
183 void addAddress(DIE *Die, unsigned Attribute,
184 const MachineLocation &Location);
185
Devang Patel3cbee302011-04-12 22:53:02 +0000186 /// addConstantValue - Add constant value entry in variable DIE.
Devang Patelb58128e2011-05-27 16:45:18 +0000187 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
Devang Patel8594d422011-06-24 20:46:11 +0000188 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
Devang Patel3cbee302011-04-12 22:53:02 +0000189
190 /// addConstantFPValue - Add constant value entry in variable DIE.
191 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
192
193 /// addTemplateParams - Add template parameters in buffer.
194 void addTemplateParams(DIE &Buffer, DIArray TParams);
195
Devang Patel116da2f2011-04-26 19:06:18 +0000196 /// addRegisterOp - Add register operand.
197 void addRegisterOp(DIE *TheDie, unsigned Reg);
198
199 /// addRegisterOffset - Add register offset.
200 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
201
Devang Patel3cbee302011-04-12 22:53:02 +0000202 /// addComplexAddress - Start with the address based on the location provided,
203 /// and generate the DWARF information necessary to find the actual variable
204 /// (navigating the extra location information encoded in the type) based on
205 /// the starting location. Add the DWARF information to the die.
206 ///
207 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
208 const MachineLocation &Location);
209
210 // FIXME: Should be reformulated in terms of addComplexAddress.
211 /// addBlockByrefAddress - Start with the address based on the location
212 /// provided, and generate the DWARF information necessary to find the
213 /// actual Block variable (navigating the Block struct) based on the
214 /// starting location. Add the DWARF information to the die. Obsolete,
215 /// please use addComplexAddress instead.
216 ///
217 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
218 const MachineLocation &Location);
219
Devang Patele1cdf842011-04-27 22:45:24 +0000220 /// addVariableAddress - Add DW_AT_location attribute for a
221 /// DbgVariable based on provided MachineLocation.
222 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
Devang Patel3cbee302011-04-12 22:53:02 +0000223
224 /// addToContextOwner - Add Die into the list of its context owner's children.
225 void addToContextOwner(DIE *Die, DIDescriptor Context);
226
227 /// addType - Add a new type attribute to the specified entity.
228 void addType(DIE *Entity, DIType Ty);
229
230 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
231 DIE *getOrCreateNameSpace(DINameSpace NS);
232
Devang Pateldbc64af2011-08-15 17:24:54 +0000233 /// getOrCreateSubprogramDIE - Create new DIE using SP.
234 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
235
Devang Patel3cbee302011-04-12 22:53:02 +0000236 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
237 /// given DIType.
Devang Patel94c7ddb2011-08-16 22:09:43 +0000238 DIE *getOrCreateTypeDIE(const MDNode *N);
Devang Patel3cbee302011-04-12 22:53:02 +0000239
240 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
241 /// for the given DITemplateTypeParameter.
242 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
243
244 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
245 /// for the given DITemplateValueParameter.
246 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
247
248 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
249 /// information entry.
250 DIEEntry *createDIEEntry(DIE *Entry);
251
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000252 /// createGlobalVariableDIE - create global variable DIE.
253 void createGlobalVariableDIE(const MDNode *N);
254
Devang Patel3cbee302011-04-12 22:53:02 +0000255 void addPubTypes(DISubprogram SP);
256
257 /// constructTypeDIE - Construct basic type die from DIBasicType.
258 void constructTypeDIE(DIE &Buffer,
259 DIBasicType BTy);
260
261 /// constructTypeDIE - Construct derived type die from DIDerivedType.
262 void constructTypeDIE(DIE &Buffer,
263 DIDerivedType DTy);
264
265 /// constructTypeDIE - Construct type DIE from DICompositeType.
266 void constructTypeDIE(DIE &Buffer,
267 DICompositeType CTy);
268
269 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
270 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
271
272 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
273 void constructArrayTypeDIE(DIE &Buffer,
274 DICompositeType *CTy);
275
276 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
277 DIE *constructEnumTypeDIE(DIEnumerator ETy);
278
Devang Pateldbc64af2011-08-15 17:24:54 +0000279 /// constructContainingTypeDIEs - Construct DIEs for types that contain
280 /// vtables.
281 void constructContainingTypeDIEs();
282
Devang Pateld0b5a5e2011-08-15 22:04:40 +0000283 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
284 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
285
Devang Patel3cbee302011-04-12 22:53:02 +0000286 /// createMemberDIE - Create new member DIE.
287 DIE *createMemberDIE(DIDerivedType DT);
288
289private:
290
291 // DIEValueAllocator - All DIEValues are allocated through this allocator.
292 BumpPtrAllocator DIEValueAllocator;
293 DIEInteger *DIEIntegerOne;
Devang Patel8b9df622011-04-12 17:40:32 +0000294};
295
296} // end llvm namespace
297#endif