1 //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_ANALYSIS_DEBUGINFO_H
18 #define LLVM_ANALYSIS_DEBUGINFO_H
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Dwarf.h"
46 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
47 /// This should not be stored in a container, because underly MDNode may
48 /// change in certain situations.
53 FlagProtected = 1 << 1,
55 FlagAppleBlock = 1 << 3,
56 FlagBlockByrefStruct = 1 << 4,
58 FlagArtificial = 1 << 6,
59 FlagExplicit = 1 << 7,
60 FlagPrototyped = 1 << 8
63 const MDNode *DbgNode;
65 StringRef getStringField(unsigned Elt) const;
66 unsigned getUnsignedField(unsigned Elt) const {
67 return (unsigned)getUInt64Field(Elt);
69 uint64_t getUInt64Field(unsigned Elt) const;
70 DIDescriptor getDescriptorField(unsigned Elt) const;
72 template <typename DescTy>
73 DescTy getFieldAs(unsigned Elt) const {
74 return DescTy(getDescriptorField(Elt));
77 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
78 Constant *getConstantField(unsigned Elt) const;
79 Function *getFunctionField(unsigned Elt) const;
82 explicit DIDescriptor() : DbgNode(0) {}
83 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
84 explicit DIDescriptor(const DIFile F);
85 explicit DIDescriptor(const DISubprogram F);
86 explicit DIDescriptor(const DILexicalBlock F);
87 explicit DIDescriptor(const DIVariable F);
88 explicit DIDescriptor(const DIType F);
90 bool Verify() const { return DbgNode != 0; }
92 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
93 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
95 unsigned getVersion() const {
96 return getUnsignedField(0) & LLVMDebugVersionMask;
99 unsigned getTag() const {
100 return getUnsignedField(0) & ~LLVMDebugVersionMask;
103 /// print - print descriptor.
104 void print(raw_ostream &OS) const;
106 /// dump - print descriptor to dbgs() with a newline.
109 bool isDerivedType() const;
110 bool isCompositeType() const;
111 bool isBasicType() const;
112 bool isVariable() const;
113 bool isSubprogram() const;
114 bool isGlobalVariable() const;
115 bool isScope() const;
117 bool isCompileUnit() const;
118 bool isNameSpace() const;
119 bool isLexicalBlock() const;
120 bool isSubrange() const;
121 bool isEnumerator() const;
123 bool isGlobal() const;
124 bool isUnspecifiedParameter() const;
127 /// DISubrange - This is used to represent ranges, for array bounds.
128 class DISubrange : public DIDescriptor {
130 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
132 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
133 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
136 /// DIArray - This descriptor holds an array of descriptors.
137 class DIArray : public DIDescriptor {
139 explicit DIArray(const MDNode *N = 0)
142 unsigned getNumElements() const;
143 DIDescriptor getElement(unsigned Idx) const {
144 return getDescriptorField(Idx);
148 /// DIScope - A base class for various scopes.
149 class DIScope : public DIDescriptor {
151 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
152 virtual ~DIScope() {}
154 StringRef getFilename() const;
155 StringRef getDirectory() const;
158 /// DICompileUnit - A wrapper for a compile unit.
159 class DICompileUnit : public DIScope {
161 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
163 unsigned getLanguage() const { return getUnsignedField(2); }
164 StringRef getFilename() const { return getStringField(3); }
165 StringRef getDirectory() const { return getStringField(4); }
166 StringRef getProducer() const { return getStringField(5); }
168 /// isMain - Each input file is encoded as a separate compile unit in LLVM
169 /// debugging information output. However, many target specific tool chains
170 /// prefer to encode only one compile unit in an object file. In this
171 /// situation, the LLVM code generator will include debugging information
172 /// entities in the compile unit that is marked as main compile unit. The
173 /// code generator accepts maximum one main compile unit per module. If a
174 /// module does not contain any main compile unit then the code generator
175 /// will emit multiple compile units in the output object file.
177 bool isMain() const { return getUnsignedField(6) != 0; }
178 bool isOptimized() const { return getUnsignedField(7) != 0; }
179 StringRef getFlags() const { return getStringField(8); }
180 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
182 /// Verify - Verify that a compile unit is well formed.
185 /// print - print compile unit.
186 void print(raw_ostream &OS) const;
188 /// dump - print compile unit to dbgs() with a newline.
192 /// DIFile - This is a wrapper for a file.
193 class DIFile : public DIScope {
195 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
196 if (DbgNode && !isFile())
199 StringRef getFilename() const { return getStringField(1); }
200 StringRef getDirectory() const { return getStringField(2); }
201 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
204 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
205 /// FIXME: it seems strange that this doesn't have either a reference to the
206 /// type/precision or a file/line pair for location info.
207 class DIEnumerator : public DIDescriptor {
209 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
211 StringRef getName() const { return getStringField(1); }
212 uint64_t getEnumValue() const { return getUInt64Field(2); }
215 /// DIType - This is a wrapper for a type.
216 /// FIXME: Types should be factored much better so that CV qualifiers and
217 /// others do not require a huge and empty descriptor full of zeros.
218 class DIType : public DIScope {
221 // This ctor is used when the Tag has already been validated by a derived
223 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
227 /// Verify - Verify that a type descriptor is well formed.
230 explicit DIType(const MDNode *N);
234 DIScope getContext() const { return getFieldAs<DIScope>(1); }
235 StringRef getName() const { return getStringField(2); }
236 DICompileUnit getCompileUnit() const{
237 if (getVersion() == llvm::LLVMDebugVersion7)
238 return getFieldAs<DICompileUnit>(3);
240 return getFieldAs<DIFile>(3).getCompileUnit();
242 DIFile getFile() const { return getFieldAs<DIFile>(3); }
243 unsigned getLineNumber() const { return getUnsignedField(4); }
244 uint64_t getSizeInBits() const { return getUInt64Field(5); }
245 uint64_t getAlignInBits() const { return getUInt64Field(6); }
246 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
247 // carry this is just plain insane.
248 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
249 unsigned getFlags() const { return getUnsignedField(8); }
250 bool isPrivate() const {
251 return (getFlags() & FlagPrivate) != 0;
253 bool isProtected() const {
254 return (getFlags() & FlagProtected) != 0;
256 bool isForwardDecl() const {
257 return (getFlags() & FlagFwdDecl) != 0;
259 // isAppleBlock - Return true if this is the Apple Blocks extension.
260 bool isAppleBlockExtension() const {
261 return (getFlags() & FlagAppleBlock) != 0;
263 bool isBlockByrefStruct() const {
264 return (getFlags() & FlagBlockByrefStruct) != 0;
266 bool isVirtual() const {
267 return (getFlags() & FlagVirtual) != 0;
269 bool isArtificial() const {
270 return (getFlags() & FlagArtificial) != 0;
272 bool isValid() const {
273 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
275 StringRef getDirectory() const {
276 if (getVersion() == llvm::LLVMDebugVersion7)
277 return getCompileUnit().getDirectory();
279 return getFieldAs<DIFile>(3).getDirectory();
281 StringRef getFilename() const {
282 if (getVersion() == llvm::LLVMDebugVersion7)
283 return getCompileUnit().getFilename();
285 return getFieldAs<DIFile>(3).getFilename();
288 /// replaceAllUsesWith - Replace all uses of debug info referenced by
290 void replaceAllUsesWith(DIDescriptor &D);
291 void replaceAllUsesWith(MDNode *D);
293 /// print - print type.
294 void print(raw_ostream &OS) const;
296 /// dump - print type to dbgs() with a newline.
300 /// DIBasicType - A basic type, like 'int' or 'float'.
301 class DIBasicType : public DIType {
303 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
305 unsigned getEncoding() const { return getUnsignedField(9); }
307 /// Verify - Verify that a basic type descriptor is well formed.
310 /// print - print basic type.
311 void print(raw_ostream &OS) const;
313 /// dump - print basic type to dbgs() with a newline.
317 /// DIDerivedType - A simple derived type, like a const qualified type,
318 /// a typedef, a pointer or reference, etc.
319 class DIDerivedType : public DIType {
321 explicit DIDerivedType(const MDNode *N, bool, bool)
322 : DIType(N, true, true) {}
324 explicit DIDerivedType(const MDNode *N = 0)
325 : DIType(N, true, true) {}
327 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
329 /// getOriginalTypeSize - If this type is derived from a base type then
330 /// return base type size.
331 uint64_t getOriginalTypeSize() const;
333 /// Verify - Verify that a derived type descriptor is well formed.
336 /// print - print derived type.
337 void print(raw_ostream &OS) const;
339 /// dump - print derived type to dbgs() with a newline.
343 /// DICompositeType - This descriptor holds a type that can refer to multiple
344 /// other types, like a function or struct.
345 /// FIXME: Why is this a DIDerivedType??
346 class DICompositeType : public DIDerivedType {
348 explicit DICompositeType(const MDNode *N = 0)
349 : DIDerivedType(N, true, true) {
350 if (N && !isCompositeType())
354 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
355 unsigned getRunTimeLang() const { return getUnsignedField(11); }
356 DICompositeType getContainingType() const {
357 return getFieldAs<DICompositeType>(12);
360 /// Verify - Verify that a composite type descriptor is well formed.
363 /// print - print composite type.
364 void print(raw_ostream &OS) const;
366 /// dump - print composite type to dbgs() with a newline.
370 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
371 class DISubprogram : public DIScope {
373 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
375 DIScope getContext() const { return getFieldAs<DIScope>(2); }
376 StringRef getName() const { return getStringField(3); }
377 StringRef getDisplayName() const { return getStringField(4); }
378 StringRef getLinkageName() const { return getStringField(5); }
379 DICompileUnit getCompileUnit() const{
380 if (getVersion() == llvm::LLVMDebugVersion7)
381 return getFieldAs<DICompileUnit>(6);
383 return getFieldAs<DIFile>(6).getCompileUnit();
385 unsigned getLineNumber() const { return getUnsignedField(7); }
386 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
388 /// getReturnTypeName - Subprogram return types are encoded either as
389 /// DIType or as DICompositeType.
390 StringRef getReturnTypeName() const {
391 DICompositeType DCT(getFieldAs<DICompositeType>(8));
393 DIArray A = DCT.getTypeArray();
394 DIType T(A.getElement(0));
397 DIType T(getFieldAs<DIType>(8));
401 /// isLocalToUnit - Return true if this subprogram is local to the current
402 /// compile unit, like 'static' in C.
403 unsigned isLocalToUnit() const { return getUnsignedField(9); }
404 unsigned isDefinition() const { return getUnsignedField(10); }
406 unsigned getVirtuality() const { return getUnsignedField(11); }
407 unsigned getVirtualIndex() const { return getUnsignedField(12); }
409 DICompositeType getContainingType() const {
410 return getFieldAs<DICompositeType>(13);
412 unsigned isArtificial() const {
413 if (getVersion() <= llvm::LLVMDebugVersion8)
414 return getUnsignedField(14);
415 return (getUnsignedField(14) & FlagArtificial) != 0;
417 /// isPrivate - Return true if this subprogram has "private"
418 /// access specifier.
419 bool isPrivate() const {
420 if (getVersion() <= llvm::LLVMDebugVersion8)
422 return (getUnsignedField(14) & FlagPrivate) != 0;
424 /// isProtected - Return true if this subprogram has "protected"
425 /// access specifier.
426 bool isProtected() const {
427 if (getVersion() <= llvm::LLVMDebugVersion8)
429 return (getUnsignedField(14) & FlagProtected) != 0;
431 /// isExplicit - Return true if this subprogram is marked as explicit.
432 bool isExplicit() const {
433 if (getVersion() <= llvm::LLVMDebugVersion8)
435 return (getUnsignedField(14) & FlagExplicit) != 0;
437 /// isPrototyped - Return true if this subprogram is prototyped.
438 bool isPrototyped() const {
439 if (getVersion() <= llvm::LLVMDebugVersion8)
441 return (getUnsignedField(14) & FlagPrototyped) != 0;
444 unsigned isOptimized() const;
446 StringRef getFilename() const {
447 if (getVersion() == llvm::LLVMDebugVersion7)
448 return getCompileUnit().getFilename();
450 return getFieldAs<DIFile>(6).getFilename();
453 StringRef getDirectory() const {
454 if (getVersion() == llvm::LLVMDebugVersion7)
455 return getCompileUnit().getFilename();
457 return getFieldAs<DIFile>(6).getDirectory();
460 /// Verify - Verify that a subprogram descriptor is well formed.
463 /// print - print subprogram.
464 void print(raw_ostream &OS) const;
466 /// dump - print subprogram to dbgs() with a newline.
469 /// describes - Return true if this subprogram provides debugging
470 /// information for the function F.
471 bool describes(const Function *F);
473 Function *getFunction() const { return getFunctionField(16); }
476 /// DIGlobalVariable - This is a wrapper for a global variable.
477 class DIGlobalVariable : public DIDescriptor {
479 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
481 DIScope getContext() const { return getFieldAs<DIScope>(2); }
482 StringRef getName() const { return getStringField(3); }
483 StringRef getDisplayName() const { return getStringField(4); }
484 StringRef getLinkageName() const { return getStringField(5); }
485 DICompileUnit getCompileUnit() const{
486 if (getVersion() == llvm::LLVMDebugVersion7)
487 return getFieldAs<DICompileUnit>(6);
489 DIFile F = getFieldAs<DIFile>(6);
490 return F.getCompileUnit();
493 unsigned getLineNumber() const { return getUnsignedField(7); }
494 DIType getType() const { return getFieldAs<DIType>(8); }
495 unsigned isLocalToUnit() const { return getUnsignedField(9); }
496 unsigned isDefinition() const { return getUnsignedField(10); }
498 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
499 Constant *getConstant() const { return getConstantField(11); }
501 /// Verify - Verify that a global variable descriptor is well formed.
504 /// print - print global variable.
505 void print(raw_ostream &OS) const;
507 /// dump - print global variable to dbgs() with a newline.
511 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
513 class DIVariable : public DIDescriptor {
515 explicit DIVariable(const MDNode *N = 0)
518 DIScope getContext() const { return getFieldAs<DIScope>(1); }
519 StringRef getName() const { return getStringField(2); }
520 DICompileUnit getCompileUnit() const{
521 if (getVersion() == llvm::LLVMDebugVersion7)
522 return getFieldAs<DICompileUnit>(3);
524 DIFile F = getFieldAs<DIFile>(3);
525 return F.getCompileUnit();
527 unsigned getLineNumber() const { return getUnsignedField(4); }
528 DIType getType() const { return getFieldAs<DIType>(5); }
530 /// isArtificial - Return true if this variable is marked as "artificial".
531 bool isArtificial() const {
532 if (getVersion() <= llvm::LLVMDebugVersion8)
534 return (getUnsignedField(6) & FlagArtificial) != 0;
538 /// Verify - Verify that a variable descriptor is well formed.
541 /// HasComplexAddr - Return true if the variable has a complex address.
542 bool hasComplexAddress() const {
543 return getNumAddrElements() > 0;
546 unsigned getNumAddrElements() const;
548 uint64_t getAddrElement(unsigned Idx) const {
549 return getUInt64Field(Idx+6);
552 /// isBlockByrefVariable - Return true if the variable was declared as
553 /// a "__block" variable (Apple Blocks).
554 bool isBlockByrefVariable() const {
555 return getType().isBlockByrefStruct();
558 /// isInlinedFnArgument - Return trule if this variable provides debugging
559 /// information for an inlined function arguments.
560 bool isInlinedFnArgument(const Function *CurFn);
562 /// print - print variable.
563 void print(raw_ostream &OS) const;
565 /// dump - print variable to dbgs() with a newline.
569 /// DILexicalBlock - This is a wrapper for a lexical block.
570 class DILexicalBlock : public DIScope {
572 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
573 DIScope getContext() const { return getFieldAs<DIScope>(1); }
574 unsigned getLineNumber() const { return getUnsignedField(2); }
575 unsigned getColumnNumber() const { return getUnsignedField(3); }
576 StringRef getDirectory() const {
577 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
578 return !dir.empty() ? dir : getContext().getDirectory();
580 StringRef getFilename() const {
581 StringRef filename = getFieldAs<DIFile>(4).getFilename();
582 return !filename.empty() ? filename : getContext().getFilename();
586 /// DINameSpace - A wrapper for a C++ style name space.
587 class DINameSpace : public DIScope {
589 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
590 DIScope getContext() const { return getFieldAs<DIScope>(1); }
591 StringRef getName() const { return getStringField(2); }
592 StringRef getDirectory() const {
593 return getFieldAs<DIFile>(3).getDirectory();
595 StringRef getFilename() const {
596 return getFieldAs<DIFile>(3).getFilename();
598 DICompileUnit getCompileUnit() const{
599 if (getVersion() == llvm::LLVMDebugVersion7)
600 return getFieldAs<DICompileUnit>(3);
602 return getFieldAs<DIFile>(3).getCompileUnit();
604 unsigned getLineNumber() const { return getUnsignedField(4); }
608 /// DILocation - This object holds location information. This object
609 /// is not associated with any DWARF tag.
610 class DILocation : public DIDescriptor {
612 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
614 unsigned getLineNumber() const { return getUnsignedField(0); }
615 unsigned getColumnNumber() const { return getUnsignedField(1); }
616 DIScope getScope() const { return getFieldAs<DIScope>(2); }
617 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
618 StringRef getFilename() const { return getScope().getFilename(); }
619 StringRef getDirectory() const { return getScope().getDirectory(); }
623 /// DIFactory - This object assists with the construction of the various
627 LLVMContext& VMContext;
629 Function *DeclareFn; // llvm.dbg.declare
630 Function *ValueFn; // llvm.dbg.value
632 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
633 void operator=(const DIFactory&); // DO NOT IMPLEMENT
635 enum ComplexAddrKind { OpPlus=1, OpDeref };
637 explicit DIFactory(Module &m);
639 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
640 /// This implicitly uniques the arrays created.
641 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
643 /// GetOrCreateSubrange - Create a descriptor for a value range. This
644 /// implicitly uniques the values returned.
645 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
647 /// CreateUnspecifiedParameter - Create unspeicified type descriptor
648 /// for a subroutine type.
649 DIDescriptor CreateUnspecifiedParameter();
651 /// CreateCompileUnit - Create a new descriptor for the specified compile
653 DICompileUnit CreateCompileUnit(unsigned LangID,
658 bool isOptimized = false,
659 StringRef Flags = "",
660 unsigned RunTimeVer = 0);
662 /// CreateFile - Create a new descriptor for the specified file.
663 DIFile CreateFile(StringRef Filename, StringRef Directory,
666 /// CreateEnumerator - Create a single enumerator value.
667 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
669 /// CreateBasicType - Create a basic type like int, float, etc.
670 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
671 DIFile F, unsigned LineNumber,
672 uint64_t SizeInBits, uint64_t AlignInBits,
673 uint64_t OffsetInBits, unsigned Flags,
676 /// CreateBasicType - Create a basic type like int, float, etc.
677 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
678 DIFile F, unsigned LineNumber,
679 Constant *SizeInBits, Constant *AlignInBits,
680 Constant *OffsetInBits, unsigned Flags,
683 /// CreateDerivedType - Create a derived type like const qualified type,
684 /// pointer, typedef, etc.
685 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
689 uint64_t SizeInBits, uint64_t AlignInBits,
690 uint64_t OffsetInBits, unsigned Flags,
693 /// CreateDerivedType - Create a derived type like const qualified type,
694 /// pointer, typedef, etc.
695 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
699 Constant *SizeInBits,
700 Constant *AlignInBits,
701 Constant *OffsetInBits, unsigned Flags,
704 /// CreateCompositeType - Create a composite type like array, struct, etc.
705 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
710 uint64_t AlignInBits,
711 uint64_t OffsetInBits, unsigned Flags,
714 unsigned RunTimeLang = 0,
715 MDNode *ContainingType = 0);
717 /// CreateTemporaryType - Create a temporary forward-declared type.
718 DIType CreateTemporaryType();
719 DIType CreateTemporaryType(DIFile F);
721 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
722 DIType CreateArtificialType(DIType Ty);
724 /// CreateCompositeType - Create a composite type like array, struct, etc.
725 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
729 Constant *SizeInBits,
730 Constant *AlignInBits,
731 Constant *OffsetInBits,
735 unsigned RunTimeLang = 0,
736 MDNode *ContainingType = 0);
738 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
739 /// See comments in DISubprogram for descriptions of these fields.
740 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
741 StringRef DisplayName,
742 StringRef LinkageName,
743 DIFile F, unsigned LineNo,
744 DIType Ty, bool isLocalToUnit,
748 DIType ContainingType = DIType(),
750 bool isOptimized = false,
753 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
754 /// given declaration.
755 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
757 /// CreateGlobalVariable - Create a new descriptor for the specified global.
759 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
760 StringRef DisplayName,
761 StringRef LinkageName,
763 unsigned LineNo, DIType Ty, bool isLocalToUnit,
764 bool isDefinition, llvm::GlobalVariable *GV);
766 /// CreateGlobalVariable - Create a new descriptor for the specified constant.
768 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
769 StringRef DisplayName,
770 StringRef LinkageName,
772 unsigned LineNo, DIType Ty, bool isLocalToUnit,
773 bool isDefinition, llvm::Constant *C);
775 /// CreateVariable - Create a new descriptor for the specified variable.
776 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
778 DIFile F, unsigned LineNo,
779 DIType Ty, bool AlwaysPreserve = false,
782 /// CreateComplexVariable - Create a new descriptor for the specified
783 /// variable which has a complex address expression for its address.
784 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
785 StringRef Name, DIFile F, unsigned LineNo,
786 DIType Ty, Value *const *Addr,
789 /// CreateLexicalBlock - This creates a descriptor for a lexical block
790 /// with the specified parent context.
791 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
792 unsigned Line = 0, unsigned Col = 0);
794 /// CreateNameSpace - This creates new descriptor for a namespace
795 /// with the specified parent context.
796 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
797 DIFile F, unsigned LineNo);
799 /// CreateLocation - Creates a debug info location.
800 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
801 DIScope S, DILocation OrigLoc);
803 /// CreateLocation - Creates a debug info location.
804 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
805 DIScope S, MDNode *OrigLoc = 0);
807 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
808 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
809 BasicBlock *InsertAtEnd);
811 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
812 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
813 Instruction *InsertBefore);
815 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
816 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
817 DIVariable D, BasicBlock *InsertAtEnd);
819 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
820 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
821 DIVariable D, Instruction *InsertBefore);
823 // RecordType - Record DIType in a module such that it is not lost even if
824 // it is not referenced through debug info anchors.
825 void RecordType(DIType T);
828 Constant *GetTagConstant(unsigned TAG);
831 bool getLocationInfo(const Value *V, std::string &DisplayName,
832 std::string &Type, unsigned &LineNo, std::string &File,
835 /// getDISubprogram - Find subprogram that is enclosing this scope.
836 DISubprogram getDISubprogram(const MDNode *Scope);
838 /// getDICompositeType - Find underlying composite type.
839 DICompositeType getDICompositeType(DIType T);
841 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
842 /// to hold function specific information.
843 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, StringRef Name);
845 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
846 /// suitable to hold function specific information.
847 NamedMDNode *getFnSpecificMDNode(const Module &M, StringRef Name);
849 class DebugInfoFinder {
851 /// processModule - Process entire module and collect debug info
853 void processModule(Module &M);
856 /// processType - Process DIType.
857 void processType(DIType DT);
859 /// processLexicalBlock - Process DILexicalBlock.
860 void processLexicalBlock(DILexicalBlock LB);
862 /// processSubprogram - Process DISubprogram.
863 void processSubprogram(DISubprogram SP);
865 /// processDeclare - Process DbgDeclareInst.
866 void processDeclare(DbgDeclareInst *DDI);
868 /// processLocation - Process DILocation.
869 void processLocation(DILocation Loc);
871 /// addCompileUnit - Add compile unit into CUs.
872 bool addCompileUnit(DICompileUnit CU);
874 /// addGlobalVariable - Add global variable into GVs.
875 bool addGlobalVariable(DIGlobalVariable DIG);
877 // addSubprogram - Add subprgoram into SPs.
878 bool addSubprogram(DISubprogram SP);
880 /// addType - Add type into Tys.
881 bool addType(DIType DT);
884 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
885 iterator compile_unit_begin() const { return CUs.begin(); }
886 iterator compile_unit_end() const { return CUs.end(); }
887 iterator subprogram_begin() const { return SPs.begin(); }
888 iterator subprogram_end() const { return SPs.end(); }
889 iterator global_variable_begin() const { return GVs.begin(); }
890 iterator global_variable_end() const { return GVs.end(); }
891 iterator type_begin() const { return TYs.begin(); }
892 iterator type_end() const { return TYs.end(); }
894 unsigned compile_unit_count() const { return CUs.size(); }
895 unsigned global_variable_count() const { return GVs.size(); }
896 unsigned subprogram_count() const { return SPs.size(); }
897 unsigned type_count() const { return TYs.size(); }
900 SmallVector<MDNode *, 8> CUs; // Compile Units
901 SmallVector<MDNode *, 8> SPs; // Subprograms
902 SmallVector<MDNode *, 8> GVs; // Global Variables;
903 SmallVector<MDNode *, 8> TYs; // Types
904 SmallPtrSet<MDNode *, 64> NodesSeen;
906 } // end namespace llvm