blob: 033aef411a1240bb8cb603f6abda97c182b1a0c4 [file] [log] [blame]
Chris Lattnera45664f2008-11-10 02:56:27 +00001//===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- 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 defines a bunch of datatypes that are useful for creating and
11// walking debug info in LLVM IR form.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_SUPPORT_DEBUGINFO_H
16#define LLVM_SUPPORT_DEBUGINFO_H
17
18#include "llvm/ADT/StringMap.h"
19#include "llvm/ADT/DenseMap.h"
Devang Patel486938f2009-01-12 21:38:43 +000020#include "llvm/Support/Dwarf.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000021
22namespace llvm {
23 class BasicBlock;
24 class Constant;
25 class Function;
26 class GlobalVariable;
27 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000028 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000029 class Value;
Torok Edwin620f2802008-12-16 09:07:36 +000030 class DbgStopPointInst;
31 class DbgDeclareInst;
32 class Instruction;
Chris Lattnera45664f2008-11-10 02:56:27 +000033
34 class DIDescriptor {
35 public:
36 enum {
Devang Patel854967e2008-12-17 22:39:29 +000037 Version7 = 7 << 16, // Current version of debug information.
38 Version6 = 6 << 16, // Constant for version 6.
Chris Lattnera45664f2008-11-10 02:56:27 +000039 Version5 = 5 << 16, // Constant for version 5.
40 Version4 = 4 << 16, // Constant for version 4.
41 VersionMask = 0xffff0000 // Mask for version number.
42 };
43
44 protected:
45 GlobalVariable *GV;
46
47 /// DIDescriptor constructor. If the specified GV is non-null, this checks
48 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If
49 /// not, the debug info is corrupt and we ignore it.
50 DIDescriptor(GlobalVariable *GV, unsigned RequiredTag);
51
Chris Lattnera45664f2008-11-10 02:56:27 +000052 std::string getStringField(unsigned Elt) const;
53 unsigned getUnsignedField(unsigned Elt) const {
54 return (unsigned)getUInt64Field(Elt);
55 }
56 uint64_t getUInt64Field(unsigned Elt) const;
57 DIDescriptor getDescriptorField(unsigned Elt) const;
58
59 template <typename DescTy>
60 DescTy getFieldAs(unsigned Elt) const {
Torok Edwinb07fbd92008-12-13 08:25:29 +000061 return DescTy(getDescriptorField(Elt).getGV());
Chris Lattnera45664f2008-11-10 02:56:27 +000062 }
63
64 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
65
66 public:
67 explicit DIDescriptor() : GV(0) {}
68 explicit DIDescriptor(GlobalVariable *gv) : GV(gv) {}
69
70 bool isNull() const { return GV == 0; }
71
72 GlobalVariable *getGV() const { return GV; }
Devang Patel2c1623a2009-01-05 18:06:21 +000073
Devang Patel8526cc02009-01-05 22:35:52 +000074 unsigned getVersion() const {
75 return getUnsignedField(0) & VersionMask;
76 }
77
Devang Patel2c1623a2009-01-05 18:06:21 +000078 unsigned getTag() const {
79 return getUnsignedField(0) & ~VersionMask;
80 }
Devang Patela22d57d2009-01-05 19:55:07 +000081 static inline bool classof(const DIDescriptor *D) { return true; }
Chris Lattnera45664f2008-11-10 02:56:27 +000082 };
83
84 /// DIAnchor - A wrapper for various anchor descriptors.
85 class DIAnchor : public DIDescriptor {
86 public:
87 explicit DIAnchor(GlobalVariable *GV = 0);
88
89 unsigned getAnchorTag() const { return getUnsignedField(1); }
90 };
Devang Patel68afdc32009-01-05 18:33:01 +000091
92 /// DISubrange - This is used to represent ranges, for array bounds.
93 class DISubrange : public DIDescriptor {
94 public:
95 explicit DISubrange(GlobalVariable *GV = 0);
96
97 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
98 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
Devang Patela22d57d2009-01-05 19:55:07 +000099 static inline bool classof(const DISubrange *) { return true; }
100 static inline bool classof(const DIDescriptor *D) {
Devang Patel486938f2009-01-12 21:38:43 +0000101 return D->getTag() == dwarf::DW_TAG_subrange_type;
Devang Patela22d57d2009-01-05 19:55:07 +0000102 }
Devang Patel68afdc32009-01-05 18:33:01 +0000103 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000104
105 /// DIArray - This descriptor holds an array of descriptors.
106 class DIArray : public DIDescriptor {
107 public:
108 explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {}
109
110 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000111 DIDescriptor getElement(unsigned Idx) const {
112 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000113 }
Devang Patel486938f2009-01-12 21:38:43 +0000114
115 static inline bool classof(const DIArray *) { return true; }
116 static inline bool classof(const DIDescriptor *D) {
117 return D->getTag() == dwarf::DW_TAG_array_type
118 || D->getTag() == dwarf::DW_AT_GNU_vector;
119 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000120 };
121
122 /// DICompileUnit - A wrapper for a compile unit.
123 class DICompileUnit : public DIDescriptor {
124 public:
125 explicit DICompileUnit(GlobalVariable *GV = 0);
126
127 unsigned getLanguage() const { return getUnsignedField(2); }
128 std::string getFilename() const { return getStringField(3); }
129 std::string getDirectory() const { return getStringField(4); }
130 std::string getProducer() const { return getStringField(5); }
Devang Patel486938f2009-01-12 21:38:43 +0000131
132 static inline bool classof(const DICompileUnit *) { return true; }
133 static inline bool classof(const DIDescriptor *D) {
134 return D->getTag() == dwarf::DW_TAG_compile_unit;
135 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000136 };
137
138 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
139 /// FIXME: it seems strange that this doesn't have either a reference to the
140 /// type/precision or a file/line pair for location info.
141 class DIEnumerator : public DIDescriptor {
142 public:
143 explicit DIEnumerator(GlobalVariable *GV = 0);
144
145 std::string getName() const { return getStringField(1); }
Devang Patelc69bf2c2009-01-05 18:38:38 +0000146 uint64_t getEnumValue() const { return getUInt64Field(2); }
Devang Patel486938f2009-01-12 21:38:43 +0000147 static inline bool classof(const DIEnumerator *) { return true; }
148 static inline bool classof(const DIDescriptor *D) {
149 return D->getTag() == dwarf::DW_TAG_enumerator;
150 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000151 };
152
Chris Lattnera45664f2008-11-10 02:56:27 +0000153 /// DIType - This is a wrapper for a type.
154 /// FIXME: Types should be factored much better so that CV qualifiers and
155 /// others do not require a huge and empty descriptor full of zeros.
156 class DIType : public DIDescriptor {
157 protected:
158 DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {}
159 // This ctor is used when the Tag has already been validated by a derived
160 // ctor.
161 DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {}
Devang Patel486938f2009-01-12 21:38:43 +0000162
163 /// isDerivedType - Return true if the specified tag is legal for
164 /// DIDerivedType.
165 static bool isDerivedType(unsigned TAG);
166
167 /// isCompositeType - Return true if the specified tag is legal for
168 /// DICompositeType.
169 static bool isCompositeType(unsigned TAG);
170
171 /// isBasicType - Return true if the specified tag is legal for
172 /// DIBasicType.
173 static bool isBasicType(unsigned TAG) {
174 return TAG == dwarf::DW_TAG_base_type;
175 }
176
Chris Lattnera45664f2008-11-10 02:56:27 +0000177 public:
178 explicit DIType(GlobalVariable *GV);
179 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000180 virtual ~DIType() {}
181
Chris Lattnera45664f2008-11-10 02:56:27 +0000182 DIDescriptor getContext() const { return getDescriptorField(1); }
183 std::string getName() const { return getStringField(2); }
184 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
185 unsigned getLineNumber() const { return getUnsignedField(4); }
186 uint64_t getSizeInBits() const { return getUInt64Field(5); }
187 uint64_t getAlignInBits() const { return getUInt64Field(6); }
188 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
189 // carry this is just plain insane.
190 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
191 unsigned getFlags() const { return getUnsignedField(8); }
Devang Patel8526cc02009-01-05 22:35:52 +0000192
193 virtual std::string getFilename() const {
194 assert (0 && "Invalid DIDescriptor");
195 return "";
196 }
197
198 virtual std::string getDirectory() const {
199 assert (0 && "Invalid DIDescriptor");
200 return "";
201 }
Devang Patel486938f2009-01-12 21:38:43 +0000202
203 static inline bool classof(const DIType *) { return true; }
204 static inline bool classof(const DIDescriptor *D) {
205 unsigned Tag = D->getTag();
206 return isBasicType(Tag) || isDerivedType(Tag) || isCompositeType(Tag);
207 }
208
Chris Lattnera45664f2008-11-10 02:56:27 +0000209 };
210
211 /// DIBasicType - A basic type, like 'int' or 'float'.
212 class DIBasicType : public DIType {
213 public:
214 explicit DIBasicType(GlobalVariable *GV);
215
216 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patel8526cc02009-01-05 22:35:52 +0000217 std::string getFilename() const { return getStringField(10); }
Devang Patel854967e2008-12-17 22:39:29 +0000218 std::string getDirectory() const { return getStringField(11); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000219 };
220
221 /// DIDerivedType - A simple derived type, like a const qualified type,
222 /// a typedef, a pointer or reference, etc.
223 class DIDerivedType : public DIType {
224 protected:
225 explicit DIDerivedType(GlobalVariable *GV, bool, bool)
226 : DIType(GV, true, true) {}
227 public:
228 explicit DIDerivedType(GlobalVariable *GV);
229
230 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patel8526cc02009-01-05 22:35:52 +0000231 std::string getFilename() const { return getStringField(10); }
Devang Patel854967e2008-12-17 22:39:29 +0000232 std::string getDirectory() const { return getStringField(11); }
233
Devang Patela22d57d2009-01-05 19:55:07 +0000234 static inline bool classof(const DIDerivedType *) { return true; }
235 static inline bool classof(const DIDescriptor *D) {
236 return isDerivedType(D->getTag());
237 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000238 };
239
240
241 /// DICompositeType - This descriptor holds a type that can refer to multiple
242 /// other types, like a function or struct.
243 /// FIXME: Why is this a DIDerivedType??
244 class DICompositeType : public DIDerivedType {
245 public:
246 explicit DICompositeType(GlobalVariable *GV);
247
248 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000249 std::string getFilename() const { return getStringField(11); }
Devang Patel854967e2008-12-17 22:39:29 +0000250 std::string getDirectory() const { return getStringField(12); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000251
Devang Patela22d57d2009-01-05 19:55:07 +0000252 static inline bool classof(const DIDerivedType *) { return true; }
253 static inline bool classof(const DIDescriptor *D) {
254 return isCompositeType(D->getTag());
255 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000256 };
257
258 /// DIGlobal - This is a common class for global variables and subprograms.
259 class DIGlobal : public DIDescriptor {
260 protected:
Chris Lattner3b781852008-11-10 03:11:39 +0000261 explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag)
Chris Lattnera45664f2008-11-10 02:56:27 +0000262 : DIDescriptor(GV, RequiredTag) {}
Devang Patel486938f2009-01-12 21:38:43 +0000263
264 /// isSubprogram - Return true if the specified tag is legal for
265 /// DISubprogram.
266 static bool isSubprogram(unsigned TAG) {
267 return TAG == dwarf::DW_TAG_subprogram;
268 }
269
270 /// isGlobalVariable - Return true if the specified tag is legal for
271 /// DIGlobalVariable.
272 static bool isGlobalVariable(unsigned TAG) {
273 return TAG == dwarf::DW_TAG_variable;
274 }
275
Chris Lattnera45664f2008-11-10 02:56:27 +0000276 public:
Devang Patel8526cc02009-01-05 22:35:52 +0000277 virtual ~DIGlobal() {}
278
Chris Lattnera45664f2008-11-10 02:56:27 +0000279 DIDescriptor getContext() const { return getDescriptorField(2); }
280 std::string getName() const { return getStringField(3); }
281 std::string getDisplayName() const { return getStringField(4); }
282 std::string getLinkageName() const { return getStringField(5); }
283
284 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
285 unsigned getLineNumber() const { return getUnsignedField(7); }
286 DIType getType() const { return getFieldAs<DIType>(8); }
287
288 /// isLocalToUnit - Return true if this subprogram is local to the current
289 /// compile unit, like 'static' in C.
290 unsigned isLocalToUnit() const { return getUnsignedField(9); }
291 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000292
293 virtual std::string getFilename() const {
294 assert (0 && "Invalid DIDescriptor");
295 return "";
296 }
297
298 virtual std::string getDirectory() const {
299 assert (0 && "Invalid DIDescriptor");
300 return "";
301 }
Devang Patel486938f2009-01-12 21:38:43 +0000302
303 static inline bool classof(const DIGlobal *) { return true; }
304 static inline bool classof(const DIDescriptor *D) {
305 unsigned Tag = D->getTag();
306 return isSubprogram(Tag) || isGlobalVariable(Tag);
307 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000308 };
309
310
311 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
312 class DISubprogram : public DIGlobal {
313 public:
314 explicit DISubprogram(GlobalVariable *GV = 0);
Devang Patel854967e2008-12-17 22:39:29 +0000315 std::string getFilename() const { return getStringField(11); }
316 std::string getDirectory() const { return getStringField(12); }
Devang Patel86ae1422009-01-05 18:59:44 +0000317 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patel486938f2009-01-12 21:38:43 +0000318 static inline bool classof(const DISubprogram *) { return true; }
319 static inline bool classof(const DIDescriptor *D) {
320 return isSubprogram(D->getTag());
321 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000322 };
323
324 /// DIGlobalVariable - This is a wrapper for a global variable.
325 class DIGlobalVariable : public DIGlobal {
326 public:
327 explicit DIGlobalVariable(GlobalVariable *GV = 0);
328
329 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patel854967e2008-12-17 22:39:29 +0000330 std::string getFilename() const { return getStringField(12); }
331 std::string getDirectory() const { return getStringField(13); }
Devang Patel486938f2009-01-12 21:38:43 +0000332 static inline bool classof(const DIGlobalVariable *) { return true; }
333 static inline bool classof(const DIDescriptor *D) {
334 return isGlobalVariable(D->getTag());
335 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000336 };
337
338
339 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
340 /// global etc).
341 class DIVariable : public DIDescriptor {
342 public:
343 explicit DIVariable(GlobalVariable *GV = 0);
344
345 DIDescriptor getContext() const { return getDescriptorField(1); }
346 std::string getName() const { return getStringField(2); }
347
348 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
349 unsigned getLineNumber() const { return getUnsignedField(4); }
350 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patel854967e2008-12-17 22:39:29 +0000351 std::string getFilename() const { return getStringField(6); }
352 std::string getDirectory() const { return getStringField(7); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000353
354 /// isVariable - Return true if the specified tag is legal for DIVariable.
355 static bool isVariable(unsigned Tag);
Devang Patel486938f2009-01-12 21:38:43 +0000356 static inline bool classof(const DIVariable *) { return true; }
357 static inline bool classof(const DIDescriptor *D) {
358 return isVariable(D->getTag());
359 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000360 };
361
362
363 /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
364 class DIBlock : public DIDescriptor {
365 public:
366 explicit DIBlock(GlobalVariable *GV = 0);
367
368 DIDescriptor getContext() const { return getDescriptorField(1); }
Devang Patel486938f2009-01-12 21:38:43 +0000369 static inline bool classof(const DIBlock *) { return true; }
370 static inline bool classof(const DIDescriptor *D) {
371 return D->getTag() == dwarf::DW_TAG_lexical_block;
372 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000373 };
374
375 /// DIFactory - This object assists with the construction of the various
376 /// descriptors.
377 class DIFactory {
378 Module &M;
379 // Cached values for uniquing and faster lookups.
380 DIAnchor CompileUnitAnchor, SubProgramAnchor, GlobalVariableAnchor;
Chris Lattner497a7a82008-11-10 04:10:34 +0000381 const Type *EmptyStructPtr; // "{}*".
Chris Lattnera45664f2008-11-10 02:56:27 +0000382 Function *StopPointFn; // llvm.dbg.stoppoint
383 Function *FuncStartFn; // llvm.dbg.func.start
384 Function *RegionStartFn; // llvm.dbg.region.start
385 Function *RegionEndFn; // llvm.dbg.region.end
386 Function *DeclareFn; // llvm.dbg.declare
387 StringMap<Constant*> StringCache;
388 DenseMap<Constant*, DIDescriptor> SimpleConstantCache;
389
390 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
391 void operator=(const DIFactory&); // DO NOT IMPLEMENT
392 public:
Chris Lattner497a7a82008-11-10 04:10:34 +0000393 explicit DIFactory(Module &m);
Chris Lattnera45664f2008-11-10 02:56:27 +0000394
395 /// GetOrCreateCompileUnitAnchor - Return the anchor for compile units,
396 /// creating a new one if there isn't already one in the module.
397 DIAnchor GetOrCreateCompileUnitAnchor();
398
399 /// GetOrCreateSubprogramAnchor - Return the anchor for subprograms,
400 /// creating a new one if there isn't already one in the module.
401 DIAnchor GetOrCreateSubprogramAnchor();
402
403 /// GetOrCreateGlobalVariableAnchor - Return the anchor for globals,
404 /// creating a new one if there isn't already one in the module.
405 DIAnchor GetOrCreateGlobalVariableAnchor();
406
407 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
408 /// This implicitly uniques the arrays created.
409 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
410
411 /// GetOrCreateSubrange - Create a descriptor for a value range. This
412 /// implicitly uniques the values returned.
413 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
414
415
416 /// CreateCompileUnit - Create a new descriptor for the specified compile
417 /// unit.
418 DICompileUnit CreateCompileUnit(unsigned LangID,
419 const std::string &Filename,
420 const std::string &Directory,
421 const std::string &Producer);
422
423 /// CreateEnumerator - Create a single enumerator value.
424 DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val);
425
426 /// CreateBasicType - Create a basic type like int, float, etc.
427 DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name,
428 DICompileUnit CompileUnit, unsigned LineNumber,
429 uint64_t SizeInBits, uint64_t AlignInBits,
430 uint64_t OffsetInBits, unsigned Flags,
Devang Patel854967e2008-12-17 22:39:29 +0000431 unsigned Encoding,
432 const std::string *FileName = 0,
433 const std::string *Directory = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000434
435 /// CreateDerivedType - Create a derived type like const qualified type,
436 /// pointer, typedef, etc.
437 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
438 const std::string &Name,
439 DICompileUnit CompileUnit,
440 unsigned LineNumber,
441 uint64_t SizeInBits, uint64_t AlignInBits,
442 uint64_t OffsetInBits, unsigned Flags,
Devang Patel854967e2008-12-17 22:39:29 +0000443 DIType DerivedFrom,
444 const std::string *FileName = 0,
445 const std::string *Directory = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000446
447 /// CreateCompositeType - Create a composite type like array, struct, etc.
448 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
449 const std::string &Name,
450 DICompileUnit CompileUnit,
451 unsigned LineNumber,
452 uint64_t SizeInBits,
453 uint64_t AlignInBits,
454 uint64_t OffsetInBits, unsigned Flags,
455 DIType DerivedFrom,
Devang Patel854967e2008-12-17 22:39:29 +0000456 DIArray Elements,
457 const std::string *FileName = 0,
458 const std::string *Directory = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000459
460 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
461 /// See comments in DISubprogram for descriptions of these fields.
462 DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name,
463 const std::string &DisplayName,
464 const std::string &LinkageName,
465 DICompileUnit CompileUnit, unsigned LineNo,
466 DIType Type, bool isLocalToUnit,
Devang Patel854967e2008-12-17 22:39:29 +0000467 bool isDefinition,
468 const std::string *FileName = 0,
469 const std::string *Directory = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000470
471 /// CreateGlobalVariable - Create a new descriptor for the specified global.
472 DIGlobalVariable
473 CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
474 const std::string &DisplayName,
475 const std::string &LinkageName,
476 DICompileUnit CompileUnit,
477 unsigned LineNo, DIType Type, bool isLocalToUnit,
Devang Patel854967e2008-12-17 22:39:29 +0000478 bool isDefinition, llvm::GlobalVariable *GV,
479 const std::string *FileName = 0,
480 const std::string *Directory = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000481
482
483 /// CreateVariable - Create a new descriptor for the specified variable.
484 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
485 const std::string &Name,
486 DICompileUnit CompileUnit, unsigned LineNo,
Devang Patel854967e2008-12-17 22:39:29 +0000487 DIType Type,
488 const std::string *FileName = 0,
489 const std::string *Directory = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000490
491 /// CreateBlock - This creates a descriptor for a lexical block with the
492 /// specified parent context.
493 DIBlock CreateBlock(DIDescriptor Context);
494
495 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
496 /// inserting it at the end of the specified basic block.
497 void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo,
498 BasicBlock *BB);
499
500 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
501 /// mark the start of the specified subprogram.
502 void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB);
503
504 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
505 /// mark the start of a region for the specified scoping descriptor.
506 void InsertRegionStart(DIDescriptor D, BasicBlock *BB);
507
508 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
509 /// mark the end of a region for the specified scoping descriptor.
510 void InsertRegionEnd(DIDescriptor D, BasicBlock *BB);
511
512 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
513 void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB);
514
515 private:
516 Constant *GetTagConstant(unsigned TAG);
517 Constant *GetStringConstant(const std::string &String);
518 DIAnchor GetOrCreateAnchor(unsigned TAG, const char *Name);
Chris Lattner497a7a82008-11-10 04:10:34 +0000519
520 /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'.
521 Constant *getCastToEmpty(DIDescriptor D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000522 };
523
Torok Edwin620f2802008-12-16 09:07:36 +0000524 /// Finds the stoppoint coressponding to this instruction, that is the
525 /// stoppoint that dominates this instruction
526 const DbgStopPointInst *findStopPoint(const Instruction *Inst);
527
528 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
529 /// instruction in this Basic Block, and returns the stoppoint for it.
530 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
531
532 /// Finds the dbg.declare intrinsic corresponding to this value if any.
533 /// It looks through pointer casts too.
534 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
Chris Lattnera45664f2008-11-10 02:56:27 +0000535} // end namespace llvm
536
537#endif