blob: 42ec482fd193a004310e79c07db9769d4bd3f3a6 [file] [log] [blame]
John Bauman89401822014-05-06 15:04:28 -04001//===--- 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. They essentially provide wrappers around
12// the information in the global variables that's needed when constructing the
13// DWARF information.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_ANALYSIS_DEBUGINFO_H
18#define LLVM_ANALYSIS_DEBUGINFO_H
19
20#include "llvm/ADT/SmallVector.h"
21#include "llvm/ADT/SmallPtrSet.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/Dwarf.h"
24
25namespace llvm {
26 class BasicBlock;
27 class Constant;
28 class Function;
29 class GlobalVariable;
30 class Module;
31 class Type;
32 class Value;
33 class Instruction;
34 class MDNode;
35 class LLVMContext;
36 class raw_ostream;
37
38 class DIFile;
39 class DISubprogram;
40 class DILexicalBlock;
41 class DIVariable;
42 class DIType;
43
44 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
45 /// This should not be stored in a container, because underly MDNode may
46 /// change in certain situations.
47 class DIDescriptor {
48 protected:
49 const MDNode *DbgNode;
50
51 StringRef getStringField(unsigned Elt) const;
52 unsigned getUnsignedField(unsigned Elt) const {
53 return (unsigned)getUInt64Field(Elt);
54 }
55 uint64_t getUInt64Field(unsigned Elt) const;
56 DIDescriptor getDescriptorField(unsigned Elt) const;
57
58 template <typename DescTy>
59 DescTy getFieldAs(unsigned Elt) const {
60 return DescTy(getDescriptorField(Elt));
61 }
62
63 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
64 Constant *getConstantField(unsigned Elt) const;
65 Function *getFunctionField(unsigned Elt) const;
66
67 public:
68 explicit DIDescriptor() : DbgNode(0) {}
69 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
70 explicit DIDescriptor(const DIFile F);
71 explicit DIDescriptor(const DISubprogram F);
72 explicit DIDescriptor(const DILexicalBlock F);
73 explicit DIDescriptor(const DIVariable F);
74 explicit DIDescriptor(const DIType F);
75
76 bool Verify() const { return DbgNode != 0; }
77
78 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
79 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
80
81 unsigned getVersion() const {
82 return getUnsignedField(0) & LLVMDebugVersionMask;
83 }
84
85 unsigned getTag() const {
86 return getUnsignedField(0) & ~LLVMDebugVersionMask;
87 }
88
89 /// print - print descriptor.
90 void print(raw_ostream &OS) const;
91
92 /// dump - print descriptor to dbgs() with a newline.
93 void dump() const;
94
95 bool isDerivedType() const;
96 bool isCompositeType() const;
97 bool isBasicType() const;
98 bool isVariable() const;
99 bool isSubprogram() const;
100 bool isGlobalVariable() const;
101 bool isScope() const;
102 bool isFile() const;
103 bool isCompileUnit() const;
104 bool isNameSpace() const;
105 bool isLexicalBlock() const;
106 bool isSubrange() const;
107 bool isEnumerator() const;
108 bool isType() const;
109 bool isGlobal() const;
110 };
111
112 /// DISubrange - This is used to represent ranges, for array bounds.
113 class DISubrange : public DIDescriptor {
114 public:
115 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
116
117 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
118 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
119 };
120
121 /// DIArray - This descriptor holds an array of descriptors.
122 class DIArray : public DIDescriptor {
123 public:
124 explicit DIArray(const MDNode *N = 0)
125 : DIDescriptor(N) {}
126
127 unsigned getNumElements() const;
128 DIDescriptor getElement(unsigned Idx) const {
129 return getDescriptorField(Idx);
130 }
131 };
132
133 /// DIScope - A base class for various scopes.
134 class DIScope : public DIDescriptor {
135 public:
136 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
137 virtual ~DIScope() {}
138
139 StringRef getFilename() const;
140 StringRef getDirectory() const;
141 };
142
143 /// DICompileUnit - A wrapper for a compile unit.
144 class DICompileUnit : public DIScope {
145 public:
146 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
147
148 unsigned getLanguage() const { return getUnsignedField(2); }
149 StringRef getFilename() const { return getStringField(3); }
150 StringRef getDirectory() const { return getStringField(4); }
151 StringRef getProducer() const { return getStringField(5); }
152
153 /// isMain - Each input file is encoded as a separate compile unit in LLVM
154 /// debugging information output. However, many target specific tool chains
155 /// prefer to encode only one compile unit in an object file. In this
156 /// situation, the LLVM code generator will include debugging information
157 /// entities in the compile unit that is marked as main compile unit. The
158 /// code generator accepts maximum one main compile unit per module. If a
159 /// module does not contain any main compile unit then the code generator
160 /// will emit multiple compile units in the output object file.
161
162 bool isMain() const { return getUnsignedField(6); }
163 bool isOptimized() const { return getUnsignedField(7); }
164 StringRef getFlags() const { return getStringField(8); }
165 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
166
167 /// Verify - Verify that a compile unit is well formed.
168 bool Verify() const;
169
170 /// print - print compile unit.
171 void print(raw_ostream &OS) const;
172
173 /// dump - print compile unit to dbgs() with a newline.
174 void dump() const;
175 };
176
177 /// DIFile - This is a wrapper for a file.
178 class DIFile : public DIScope {
179 public:
180 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
181 if (DbgNode && !isFile())
182 DbgNode = 0;
183 }
184 StringRef getFilename() const { return getStringField(1); }
185 StringRef getDirectory() const { return getStringField(2); }
186 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
187 };
188
189 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
190 /// FIXME: it seems strange that this doesn't have either a reference to the
191 /// type/precision or a file/line pair for location info.
192 class DIEnumerator : public DIDescriptor {
193 public:
194 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
195
196 StringRef getName() const { return getStringField(1); }
197 uint64_t getEnumValue() const { return getUInt64Field(2); }
198 };
199
200 /// DIType - This is a wrapper for a type.
201 /// FIXME: Types should be factored much better so that CV qualifiers and
202 /// others do not require a huge and empty descriptor full of zeros.
203 class DIType : public DIScope {
204 public:
205 enum {
206 FlagPrivate = 1 << 0,
207 FlagProtected = 1 << 1,
208 FlagFwdDecl = 1 << 2,
209 FlagAppleBlock = 1 << 3,
210 FlagBlockByrefStruct = 1 << 4,
211 FlagVirtual = 1 << 5,
212 FlagArtificial = 1 << 6 // To identify artificial arguments in
213 // a subroutine type. e.g. "this" in c++.
214 };
215
216 protected:
217 // This ctor is used when the Tag has already been validated by a derived
218 // ctor.
219 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
220
221 public:
222
223 /// Verify - Verify that a type descriptor is well formed.
224 bool Verify() const;
225 public:
226 explicit DIType(const MDNode *N);
227 explicit DIType() {}
228 virtual ~DIType() {}
229
230 DIScope getContext() const { return getFieldAs<DIScope>(1); }
231 StringRef getName() const { return getStringField(2); }
232 DICompileUnit getCompileUnit() const{
233 if (getVersion() == llvm::LLVMDebugVersion7)
234 return getFieldAs<DICompileUnit>(3);
235
236 DIFile F = getFieldAs<DIFile>(3);
237 return F.getCompileUnit();
238 }
239 unsigned getLineNumber() const { return getUnsignedField(4); }
240 uint64_t getSizeInBits() const { return getUInt64Field(5); }
241 uint64_t getAlignInBits() const { return getUInt64Field(6); }
242 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
243 // carry this is just plain insane.
244 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
245 unsigned getFlags() const { return getUnsignedField(8); }
246 bool isPrivate() const {
247 return (getFlags() & FlagPrivate) != 0;
248 }
249 bool isProtected() const {
250 return (getFlags() & FlagProtected) != 0;
251 }
252 bool isForwardDecl() const {
253 return (getFlags() & FlagFwdDecl) != 0;
254 }
255 // isAppleBlock - Return true if this is the Apple Blocks extension.
256 bool isAppleBlockExtension() const {
257 return (getFlags() & FlagAppleBlock) != 0;
258 }
259 bool isBlockByrefStruct() const {
260 return (getFlags() & FlagBlockByrefStruct) != 0;
261 }
262 bool isVirtual() const {
263 return (getFlags() & FlagVirtual) != 0;
264 }
265 bool isArtificial() const {
266 return (getFlags() & FlagArtificial) != 0;
267 }
268 bool isValid() const {
269 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
270 }
271 StringRef getFilename() const { return getCompileUnit().getFilename();}
272 StringRef getDirectory() const { return getCompileUnit().getDirectory();}
273
274 /// print - print type.
275 void print(raw_ostream &OS) const;
276
277 /// dump - print type to dbgs() with a newline.
278 void dump() const;
279 };
280
281 /// DIBasicType - A basic type, like 'int' or 'float'.
282 class DIBasicType : public DIType {
283 public:
284 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
285
286 unsigned getEncoding() const { return getUnsignedField(9); }
287
288 /// print - print basic type.
289 void print(raw_ostream &OS) const;
290
291 /// dump - print basic type to dbgs() with a newline.
292 void dump() const;
293 };
294
295 /// DIDerivedType - A simple derived type, like a const qualified type,
296 /// a typedef, a pointer or reference, etc.
297 class DIDerivedType : public DIType {
298 protected:
299 explicit DIDerivedType(const MDNode *N, bool, bool)
300 : DIType(N, true, true) {}
301 public:
302 explicit DIDerivedType(const MDNode *N = 0)
303 : DIType(N, true, true) {}
304
305 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
306
307 /// getOriginalTypeSize - If this type is derived from a base type then
308 /// return base type size.
309 uint64_t getOriginalTypeSize() const;
310
311 /// print - print derived type.
312 void print(raw_ostream &OS) const;
313
314 /// dump - print derived type to dbgs() with a newline.
315 void dump() const;
316
317 /// replaceAllUsesWith - Replace all uses of debug info referenced by
318 /// this descriptor.
319 void replaceAllUsesWith(DIDescriptor &D);
320 };
321
322 /// DICompositeType - This descriptor holds a type that can refer to multiple
323 /// other types, like a function or struct.
324 /// FIXME: Why is this a DIDerivedType??
325 class DICompositeType : public DIDerivedType {
326 public:
327 explicit DICompositeType(const MDNode *N = 0)
328 : DIDerivedType(N, true, true) {
329 if (N && !isCompositeType())
330 DbgNode = 0;
331 }
332
333 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
334 unsigned getRunTimeLang() const { return getUnsignedField(11); }
335 DICompositeType getContainingType() const {
336 return getFieldAs<DICompositeType>(12);
337 }
338
339 /// Verify - Verify that a composite type descriptor is well formed.
340 bool Verify() const;
341
342 /// print - print composite type.
343 void print(raw_ostream &OS) const;
344
345 /// dump - print composite type to dbgs() with a newline.
346 void dump() const;
347 };
348
349 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
350 class DISubprogram : public DIScope {
351 public:
352 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
353
354 DIScope getContext() const { return getFieldAs<DIScope>(2); }
355 StringRef getName() const { return getStringField(3); }
356 StringRef getDisplayName() const { return getStringField(4); }
357 StringRef getLinkageName() const { return getStringField(5); }
358 DICompileUnit getCompileUnit() const{
359 if (getVersion() == llvm::LLVMDebugVersion7)
360 return getFieldAs<DICompileUnit>(6);
361
362 DIFile F = getFieldAs<DIFile>(6);
363 return F.getCompileUnit();
364 }
365 unsigned getLineNumber() const { return getUnsignedField(7); }
366 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
367
368 /// getReturnTypeName - Subprogram return types are encoded either as
369 /// DIType or as DICompositeType.
370 StringRef getReturnTypeName() const {
371 DICompositeType DCT(getFieldAs<DICompositeType>(8));
372 if (DCT.Verify()) {
373 DIArray A = DCT.getTypeArray();
374 DIType T(A.getElement(0));
375 return T.getName();
376 }
377 DIType T(getFieldAs<DIType>(8));
378 return T.getName();
379 }
380
381 /// isLocalToUnit - Return true if this subprogram is local to the current
382 /// compile unit, like 'static' in C.
383 unsigned isLocalToUnit() const { return getUnsignedField(9); }
384 unsigned isDefinition() const { return getUnsignedField(10); }
385
386 unsigned getVirtuality() const { return getUnsignedField(11); }
387 unsigned getVirtualIndex() const { return getUnsignedField(12); }
388
389 DICompositeType getContainingType() const {
390 return getFieldAs<DICompositeType>(13);
391 }
392 unsigned isArtificial() const { return getUnsignedField(14); }
393 unsigned isOptimized() const;
394
395 StringRef getFilename() const {
396 if (getVersion() == llvm::LLVMDebugVersion7)
397 return getCompileUnit().getFilename();
398
399 DIFile F = getFieldAs<DIFile>(6);
400 return F.getFilename();
401 }
402
403 StringRef getDirectory() const {
404 if (getVersion() == llvm::LLVMDebugVersion7)
405 return getCompileUnit().getFilename();
406
407 DIFile F = getFieldAs<DIFile>(6);
408 return F.getDirectory();
409 }
410
411 /// Verify - Verify that a subprogram descriptor is well formed.
412 bool Verify() const;
413
414 /// print - print subprogram.
415 void print(raw_ostream &OS) const;
416
417 /// dump - print subprogram to dbgs() with a newline.
418 void dump() const;
419
420 /// describes - Return true if this subprogram provides debugging
421 /// information for the function F.
422 bool describes(const Function *F);
423
424 Function *getFunction() const { return getFunctionField(16); }
425 };
426
427 /// DIGlobalVariable - This is a wrapper for a global variable.
428 class DIGlobalVariable : public DIDescriptor {
429 public:
430 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
431
432 DIScope getContext() const { return getFieldAs<DIScope>(2); }
433 StringRef getName() const { return getStringField(3); }
434 StringRef getDisplayName() const { return getStringField(4); }
435 StringRef getLinkageName() const { return getStringField(5); }
436 DICompileUnit getCompileUnit() const{
437 if (getVersion() == llvm::LLVMDebugVersion7)
438 return getFieldAs<DICompileUnit>(6);
439
440 DIFile F = getFieldAs<DIFile>(6);
441 return F.getCompileUnit();
442 }
443
444 unsigned getLineNumber() const { return getUnsignedField(7); }
445 DIType getType() const { return getFieldAs<DIType>(8); }
446 unsigned isLocalToUnit() const { return getUnsignedField(9); }
447 unsigned isDefinition() const { return getUnsignedField(10); }
448
449 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
450 Constant *getConstant() const { return getConstantField(11); }
451
452 /// Verify - Verify that a global variable descriptor is well formed.
453 bool Verify() const;
454
455 /// print - print global variable.
456 void print(raw_ostream &OS) const;
457
458 /// dump - print global variable to dbgs() with a newline.
459 void dump() const;
460 };
461
462 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
463 /// global etc).
464 class DIVariable : public DIDescriptor {
465 public:
466 explicit DIVariable(const MDNode *N = 0)
467 : DIDescriptor(N) {}
468
469 DIScope getContext() const { return getFieldAs<DIScope>(1); }
470 StringRef getName() const { return getStringField(2); }
471 DICompileUnit getCompileUnit() const{
472 if (getVersion() == llvm::LLVMDebugVersion7)
473 return getFieldAs<DICompileUnit>(3);
474
475 DIFile F = getFieldAs<DIFile>(3);
476 return F.getCompileUnit();
477 }
478 unsigned getLineNumber() const { return getUnsignedField(4); }
479 DIType getType() const { return getFieldAs<DIType>(5); }
480
481
482 /// Verify - Verify that a variable descriptor is well formed.
483 bool Verify() const;
484
485 /// HasComplexAddr - Return true if the variable has a complex address.
486 bool hasComplexAddress() const {
487 return getNumAddrElements() > 0;
488 }
489
490 unsigned getNumAddrElements() const;
491
492 uint64_t getAddrElement(unsigned Idx) const {
493 return getUInt64Field(Idx+6);
494 }
495
496 /// isBlockByrefVariable - Return true if the variable was declared as
497 /// a "__block" variable (Apple Blocks).
498 bool isBlockByrefVariable() const {
499 return getType().isBlockByrefStruct();
500 }
501
502 /// isInlinedFnArgument - Return trule if this variable provides debugging
503 /// information for an inlined function arguments.
504 bool isInlinedFnArgument(const Function *CurFn);
505
506 /// print - print variable.
507 void print(raw_ostream &OS) const;
508
509 /// dump - print variable to dbgs() with a newline.
510 void dump() const;
511 };
512
513 /// DILexicalBlock - This is a wrapper for a lexical block.
514 class DILexicalBlock : public DIScope {
515 public:
516 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
517 DIScope getContext() const { return getFieldAs<DIScope>(1); }
518 unsigned getLineNumber() const { return getUnsignedField(2); }
519 unsigned getColumnNumber() const { return getUnsignedField(3); }
520 StringRef getDirectory() const {
521 DIFile F = getFieldAs<DIFile>(4);
522 StringRef dir = F.getDirectory();
523 return !dir.empty() ? dir : getContext().getDirectory();
524 }
525 StringRef getFilename() const {
526 DIFile F = getFieldAs<DIFile>(4);
527 StringRef filename = F.getFilename();
528 return !filename.empty() ? filename : getContext().getFilename();
529 }
530 };
531
532 /// DINameSpace - A wrapper for a C++ style name space.
533 class DINameSpace : public DIScope {
534 public:
535 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
536 DIScope getContext() const { return getFieldAs<DIScope>(1); }
537 StringRef getName() const { return getStringField(2); }
538 StringRef getDirectory() const { return getContext().getDirectory(); }
539 StringRef getFilename() const { return getContext().getFilename(); }
540 DICompileUnit getCompileUnit() const{
541 if (getVersion() == llvm::LLVMDebugVersion7)
542 return getFieldAs<DICompileUnit>(3);
543
544 DIFile F = getFieldAs<DIFile>(3);
545 return F.getCompileUnit();
546 }
547 unsigned getLineNumber() const { return getUnsignedField(4); }
548 bool Verify() const;
549 };
550
551 /// DILocation - This object holds location information. This object
552 /// is not associated with any DWARF tag.
553 class DILocation : public DIDescriptor {
554 public:
555 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
556
557 unsigned getLineNumber() const { return getUnsignedField(0); }
558 unsigned getColumnNumber() const { return getUnsignedField(1); }
559 DIScope getScope() const { return getFieldAs<DIScope>(2); }
560 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
561 StringRef getFilename() const { return getScope().getFilename(); }
562 StringRef getDirectory() const { return getScope().getDirectory(); }
563 bool Verify() const;
564 };
565
566 /// DIFactory - This object assists with the construction of the various
567 /// descriptors.
568 class DIFactory {
569 Module &M;
570 LLVMContext& VMContext;
571
572 Function *DeclareFn; // llvm.dbg.declare
573 Function *ValueFn; // llvm.dbg.value
574
575 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
576 void operator=(const DIFactory&); // DO NOT IMPLEMENT
577 public:
578 enum ComplexAddrKind { OpPlus=1, OpDeref };
579
580 explicit DIFactory(Module &m);
581
582 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
583 /// This implicitly uniques the arrays created.
584 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
585
586 /// GetOrCreateSubrange - Create a descriptor for a value range. This
587 /// implicitly uniques the values returned.
588 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
589
590 /// CreateCompileUnit - Create a new descriptor for the specified compile
591 /// unit.
592 DICompileUnit CreateCompileUnit(unsigned LangID,
593 StringRef Filename,
594 StringRef Directory,
595 StringRef Producer,
596 bool isMain = false,
597 bool isOptimized = false,
598 StringRef Flags = "",
599 unsigned RunTimeVer = 0);
600
601 /// CreateFile - Create a new descriptor for the specified file.
602 DIFile CreateFile(StringRef Filename, StringRef Directory,
603 DICompileUnit CU);
604
605 /// CreateEnumerator - Create a single enumerator value.
606 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
607
608 /// CreateBasicType - Create a basic type like int, float, etc.
609 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
610 DIFile F, unsigned LineNumber,
611 uint64_t SizeInBits, uint64_t AlignInBits,
612 uint64_t OffsetInBits, unsigned Flags,
613 unsigned Encoding);
614
615 /// CreateBasicType - Create a basic type like int, float, etc.
616 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
617 DIFile F, unsigned LineNumber,
618 Constant *SizeInBits, Constant *AlignInBits,
619 Constant *OffsetInBits, unsigned Flags,
620 unsigned Encoding);
621
622 /// CreateDerivedType - Create a derived type like const qualified type,
623 /// pointer, typedef, etc.
624 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
625 StringRef Name,
626 DIFile F,
627 unsigned LineNumber,
628 uint64_t SizeInBits, uint64_t AlignInBits,
629 uint64_t OffsetInBits, unsigned Flags,
630 DIType DerivedFrom);
631
632 /// CreateDerivedType - Create a derived type like const qualified type,
633 /// pointer, typedef, etc.
634 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
635 StringRef Name,
636 DIFile F,
637 unsigned LineNumber,
638 Constant *SizeInBits,
639 Constant *AlignInBits,
640 Constant *OffsetInBits, unsigned Flags,
641 DIType DerivedFrom);
642
643 /// CreateCompositeType - Create a composite type like array, struct, etc.
644 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
645 StringRef Name,
646 DIFile F,
647 unsigned LineNumber,
648 uint64_t SizeInBits,
649 uint64_t AlignInBits,
650 uint64_t OffsetInBits, unsigned Flags,
651 DIType DerivedFrom,
652 DIArray Elements,
653 unsigned RunTimeLang = 0,
654 MDNode *ContainingType = 0);
655
656 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
657 DIType CreateArtificialType(DIType Ty);
658
659 /// CreateCompositeType - Create a composite type like array, struct, etc.
660 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
661 StringRef Name,
662 DIFile F,
663 unsigned LineNumber,
664 Constant *SizeInBits,
665 Constant *AlignInBits,
666 Constant *OffsetInBits,
667 unsigned Flags,
668 DIType DerivedFrom,
669 DIArray Elements,
670 unsigned RunTimeLang = 0,
671 MDNode *ContainingType = 0);
672
673 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
674 /// See comments in DISubprogram for descriptions of these fields.
675 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
676 StringRef DisplayName,
677 StringRef LinkageName,
678 DIFile F, unsigned LineNo,
679 DIType Ty, bool isLocalToUnit,
680 bool isDefinition,
681 unsigned VK = 0,
682 unsigned VIndex = 0,
683 DIType = DIType(),
684 bool isArtificial = 0,
685 bool isOptimized = false,
686 Function *Fn = 0);
687
688 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
689 /// given declaration.
690 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
691
692 /// CreateGlobalVariable - Create a new descriptor for the specified global.
693 DIGlobalVariable
694 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
695 StringRef DisplayName,
696 StringRef LinkageName,
697 DIFile F,
698 unsigned LineNo, DIType Ty, bool isLocalToUnit,
699 bool isDefinition, llvm::GlobalVariable *GV);
700
701 /// CreateGlobalVariable - Create a new descriptor for the specified constant.
702 DIGlobalVariable
703 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
704 StringRef DisplayName,
705 StringRef LinkageName,
706 DIFile F,
707 unsigned LineNo, DIType Ty, bool isLocalToUnit,
708 bool isDefinition, llvm::Constant *C);
709
710 /// CreateVariable - Create a new descriptor for the specified variable.
711 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
712 StringRef Name,
713 DIFile F, unsigned LineNo,
714 DIType Ty, bool AlwaysPreserve = false);
715
716 /// CreateComplexVariable - Create a new descriptor for the specified
717 /// variable which has a complex address expression for its address.
718 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
719 const std::string &Name,
720 DIFile F, unsigned LineNo,
721 DIType Ty,
722 SmallVector<Value *, 9> &addr);
723
724 /// CreateLexicalBlock - This creates a descriptor for a lexical block
725 /// with the specified parent context.
726 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
727 unsigned Line = 0, unsigned Col = 0);
728
729 /// CreateNameSpace - This creates new descriptor for a namespace
730 /// with the specified parent context.
731 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
732 DIFile F, unsigned LineNo);
733
734 /// CreateLocation - Creates a debug info location.
735 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
736 DIScope S, DILocation OrigLoc);
737
738 /// CreateLocation - Creates a debug info location.
739 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
740 DIScope S, MDNode *OrigLoc = 0);
741
742 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
743 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
744 BasicBlock *InsertAtEnd);
745
746 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
747 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
748 Instruction *InsertBefore);
749
750 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
751 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
752 DIVariable D, BasicBlock *InsertAtEnd);
753
754 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
755 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
756 DIVariable D, Instruction *InsertBefore);
757 private:
758 Constant *GetTagConstant(unsigned TAG);
759 };
760
761 bool getLocationInfo(const Value *V, std::string &DisplayName,
762 std::string &Type, unsigned &LineNo, std::string &File,
763 std::string &Dir);
764
765 /// getDISubprogram - Find subprogram that is enclosing this scope.
766 DISubprogram getDISubprogram(const MDNode *Scope);
767
768 /// getDICompositeType - Find underlying composite type.
769 DICompositeType getDICompositeType(DIType T);
770
771 class DebugInfoFinder {
772 public:
773 /// processModule - Process entire module and collect debug info
774 /// anchors.
775 void processModule(Module &M);
776
777 private:
778 /// processType - Process DIType.
779 void processType(DIType DT);
780
781 /// processLexicalBlock - Process DILexicalBlock.
782 void processLexicalBlock(DILexicalBlock LB);
783
784 /// processSubprogram - Process DISubprogram.
785 void processSubprogram(DISubprogram SP);
786
787 /// processLocation - Process DILocation.
788 void processLocation(DILocation Loc);
789
790 /// addCompileUnit - Add compile unit into CUs.
791 bool addCompileUnit(DICompileUnit CU);
792
793 /// addGlobalVariable - Add global variable into GVs.
794 bool addGlobalVariable(DIGlobalVariable DIG);
795
796 // addSubprogram - Add subprgoram into SPs.
797 bool addSubprogram(DISubprogram SP);
798
799 /// addType - Add type into Tys.
800 bool addType(DIType DT);
801
802 public:
803 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
804 iterator compile_unit_begin() const { return CUs.begin(); }
805 iterator compile_unit_end() const { return CUs.end(); }
806 iterator subprogram_begin() const { return SPs.begin(); }
807 iterator subprogram_end() const { return SPs.end(); }
808 iterator global_variable_begin() const { return GVs.begin(); }
809 iterator global_variable_end() const { return GVs.end(); }
810 iterator type_begin() const { return TYs.begin(); }
811 iterator type_end() const { return TYs.end(); }
812
813 unsigned compile_unit_count() const { return CUs.size(); }
814 unsigned global_variable_count() const { return GVs.size(); }
815 unsigned subprogram_count() const { return SPs.size(); }
816 unsigned type_count() const { return TYs.size(); }
817
818 private:
819 SmallVector<MDNode *, 8> CUs; // Compile Units
820 SmallVector<MDNode *, 8> SPs; // Subprograms
821 SmallVector<MDNode *, 8> GVs; // Global Variables;
822 SmallVector<MDNode *, 8> TYs; // Types
823 SmallPtrSet<MDNode *, 64> NodesSeen;
824 };
825} // end namespace llvm
826
827#endif