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;
125 bool isTemplateTypeParameter() const;
126 bool isTemplateValueParameter() const;
129 /// DISubrange - This is used to represent ranges, for array bounds.
130 class DISubrange : public DIDescriptor {
132 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
134 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
135 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
138 /// DIArray - This descriptor holds an array of descriptors.
139 class DIArray : public DIDescriptor {
141 explicit DIArray(const MDNode *N = 0)
144 unsigned getNumElements() const;
145 DIDescriptor getElement(unsigned Idx) const {
146 return getDescriptorField(Idx);
150 /// DIScope - A base class for various scopes.
151 class DIScope : public DIDescriptor {
153 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
154 virtual ~DIScope() {}
156 StringRef getFilename() const;
157 StringRef getDirectory() const;
160 /// DICompileUnit - A wrapper for a compile unit.
161 class DICompileUnit : public DIScope {
163 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
165 unsigned getLanguage() const { return getUnsignedField(2); }
166 StringRef getFilename() const { return getStringField(3); }
167 StringRef getDirectory() const { return getStringField(4); }
168 StringRef getProducer() const { return getStringField(5); }
170 /// isMain - Each input file is encoded as a separate compile unit in LLVM
171 /// debugging information output. However, many target specific tool chains
172 /// prefer to encode only one compile unit in an object file. In this
173 /// situation, the LLVM code generator will include debugging information
174 /// entities in the compile unit that is marked as main compile unit. The
175 /// code generator accepts maximum one main compile unit per module. If a
176 /// module does not contain any main compile unit then the code generator
177 /// will emit multiple compile units in the output object file.
179 bool isMain() const { return getUnsignedField(6) != 0; }
180 bool isOptimized() const { return getUnsignedField(7) != 0; }
181 StringRef getFlags() const { return getStringField(8); }
182 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
184 /// Verify - Verify that a compile unit is well formed.
187 /// print - print compile unit.
188 void print(raw_ostream &OS) const;
190 /// dump - print compile unit to dbgs() with a newline.
194 /// DIFile - This is a wrapper for a file.
195 class DIFile : public DIScope {
197 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
198 if (DbgNode && !isFile())
201 StringRef getFilename() const { return getStringField(1); }
202 StringRef getDirectory() const { return getStringField(2); }
203 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
206 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
207 /// FIXME: it seems strange that this doesn't have either a reference to the
208 /// type/precision or a file/line pair for location info.
209 class DIEnumerator : public DIDescriptor {
211 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
213 StringRef getName() const { return getStringField(1); }
214 uint64_t getEnumValue() const { return getUInt64Field(2); }
217 /// DIType - This is a wrapper for a type.
218 /// FIXME: Types should be factored much better so that CV qualifiers and
219 /// others do not require a huge and empty descriptor full of zeros.
220 class DIType : public DIScope {
223 // This ctor is used when the Tag has already been validated by a derived
225 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
229 /// Verify - Verify that a type descriptor is well formed.
232 explicit DIType(const MDNode *N);
236 DIScope getContext() const { return getFieldAs<DIScope>(1); }
237 StringRef getName() const { return getStringField(2); }
238 DICompileUnit getCompileUnit() const{
239 if (getVersion() == llvm::LLVMDebugVersion7)
240 return getFieldAs<DICompileUnit>(3);
242 return getFieldAs<DIFile>(3).getCompileUnit();
244 DIFile getFile() const { return getFieldAs<DIFile>(3); }
245 unsigned getLineNumber() const { return getUnsignedField(4); }
246 uint64_t getSizeInBits() const { return getUInt64Field(5); }
247 uint64_t getAlignInBits() const { return getUInt64Field(6); }
248 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
249 // carry this is just plain insane.
250 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
251 unsigned getFlags() const { return getUnsignedField(8); }
252 bool isPrivate() const {
253 return (getFlags() & FlagPrivate) != 0;
255 bool isProtected() const {
256 return (getFlags() & FlagProtected) != 0;
258 bool isForwardDecl() const {
259 return (getFlags() & FlagFwdDecl) != 0;
261 // isAppleBlock - Return true if this is the Apple Blocks extension.
262 bool isAppleBlockExtension() const {
263 return (getFlags() & FlagAppleBlock) != 0;
265 bool isBlockByrefStruct() const {
266 return (getFlags() & FlagBlockByrefStruct) != 0;
268 bool isVirtual() const {
269 return (getFlags() & FlagVirtual) != 0;
271 bool isArtificial() const {
272 return (getFlags() & FlagArtificial) != 0;
274 bool isValid() const {
275 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
277 StringRef getDirectory() const {
278 if (getVersion() == llvm::LLVMDebugVersion7)
279 return getCompileUnit().getDirectory();
281 return getFieldAs<DIFile>(3).getDirectory();
283 StringRef getFilename() const {
284 if (getVersion() == llvm::LLVMDebugVersion7)
285 return getCompileUnit().getFilename();
287 return getFieldAs<DIFile>(3).getFilename();
290 /// replaceAllUsesWith - Replace all uses of debug info referenced by
292 void replaceAllUsesWith(DIDescriptor &D);
293 void replaceAllUsesWith(MDNode *D);
295 /// print - print type.
296 void print(raw_ostream &OS) const;
298 /// dump - print type to dbgs() with a newline.
302 /// DIBasicType - A basic type, like 'int' or 'float'.
303 class DIBasicType : public DIType {
305 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
307 unsigned getEncoding() const { return getUnsignedField(9); }
309 /// Verify - Verify that a basic type descriptor is well formed.
312 /// print - print basic type.
313 void print(raw_ostream &OS) const;
315 /// dump - print basic type to dbgs() with a newline.
319 /// DIDerivedType - A simple derived type, like a const qualified type,
320 /// a typedef, a pointer or reference, etc.
321 class DIDerivedType : public DIType {
323 explicit DIDerivedType(const MDNode *N, bool, bool)
324 : DIType(N, true, true) {}
326 explicit DIDerivedType(const MDNode *N = 0)
327 : DIType(N, true, true) {}
329 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
331 /// getOriginalTypeSize - If this type is derived from a base type then
332 /// return base type size.
333 uint64_t getOriginalTypeSize() const;
335 /// Verify - Verify that a derived type descriptor is well formed.
338 /// print - print derived type.
339 void print(raw_ostream &OS) const;
341 /// dump - print derived type to dbgs() with a newline.
345 /// DICompositeType - This descriptor holds a type that can refer to multiple
346 /// other types, like a function or struct.
347 /// FIXME: Why is this a DIDerivedType??
348 class DICompositeType : public DIDerivedType {
350 explicit DICompositeType(const MDNode *N = 0)
351 : DIDerivedType(N, true, true) {
352 if (N && !isCompositeType())
356 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
357 unsigned getRunTimeLang() const { return getUnsignedField(11); }
358 DICompositeType getContainingType() const {
359 return getFieldAs<DICompositeType>(12);
361 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
363 /// Verify - Verify that a composite type descriptor is well formed.
366 /// print - print composite type.
367 void print(raw_ostream &OS) const;
369 /// dump - print composite type to dbgs() with a newline.
373 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
374 class DITemplateTypeParameter : public DIDescriptor {
376 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
378 DIScope getContext() const { return getFieldAs<DIScope>(1); }
379 StringRef getName() const { return getStringField(2); }
380 DIType getType() const { return getFieldAs<DIType>(3); }
381 StringRef getFilename() const {
382 return getFieldAs<DIFile>(4).getFilename();
384 StringRef getDirectory() const {
385 return getFieldAs<DIFile>(4).getDirectory();
387 unsigned getLineNumber() const { return getUnsignedField(5); }
388 unsigned getColumnNumber() const { return getUnsignedField(6); }
391 /// DITemplateValueParameter - This is a wrapper for template value parameter.
392 class DITemplateValueParameter : public DIDescriptor {
394 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
396 DIScope getContext() const { return getFieldAs<DIScope>(1); }
397 StringRef getName() const { return getStringField(2); }
398 DIType getType() const { return getFieldAs<DIType>(3); }
399 uint64_t getValue() const { return getUInt64Field(4); }
400 StringRef getFilename() const {
401 return getFieldAs<DIFile>(5).getFilename();
403 StringRef getDirectory() const {
404 return getFieldAs<DIFile>(5).getDirectory();
406 unsigned getLineNumber() const { return getUnsignedField(6); }
407 unsigned getColumnNumber() const { return getUnsignedField(7); }
410 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
411 class DISubprogram : public DIScope {
413 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
415 DIScope getContext() const { return getFieldAs<DIScope>(2); }
416 StringRef getName() const { return getStringField(3); }
417 StringRef getDisplayName() const { return getStringField(4); }
418 StringRef getLinkageName() const { return getStringField(5); }
419 DICompileUnit getCompileUnit() const{
420 if (getVersion() == llvm::LLVMDebugVersion7)
421 return getFieldAs<DICompileUnit>(6);
423 return getFieldAs<DIFile>(6).getCompileUnit();
425 unsigned getLineNumber() const { return getUnsignedField(7); }
426 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
428 /// getReturnTypeName - Subprogram return types are encoded either as
429 /// DIType or as DICompositeType.
430 StringRef getReturnTypeName() const {
431 DICompositeType DCT(getFieldAs<DICompositeType>(8));
433 DIArray A = DCT.getTypeArray();
434 DIType T(A.getElement(0));
437 DIType T(getFieldAs<DIType>(8));
441 /// isLocalToUnit - Return true if this subprogram is local to the current
442 /// compile unit, like 'static' in C.
443 unsigned isLocalToUnit() const { return getUnsignedField(9); }
444 unsigned isDefinition() const { return getUnsignedField(10); }
446 unsigned getVirtuality() const { return getUnsignedField(11); }
447 unsigned getVirtualIndex() const { return getUnsignedField(12); }
449 DICompositeType getContainingType() const {
450 return getFieldAs<DICompositeType>(13);
452 unsigned isArtificial() const {
453 if (getVersion() <= llvm::LLVMDebugVersion8)
454 return getUnsignedField(14);
455 return (getUnsignedField(14) & FlagArtificial) != 0;
457 /// isPrivate - Return true if this subprogram has "private"
458 /// access specifier.
459 bool isPrivate() const {
460 if (getVersion() <= llvm::LLVMDebugVersion8)
462 return (getUnsignedField(14) & FlagPrivate) != 0;
464 /// isProtected - Return true if this subprogram has "protected"
465 /// access specifier.
466 bool isProtected() const {
467 if (getVersion() <= llvm::LLVMDebugVersion8)
469 return (getUnsignedField(14) & FlagProtected) != 0;
471 /// isExplicit - Return true if this subprogram is marked as explicit.
472 bool isExplicit() const {
473 if (getVersion() <= llvm::LLVMDebugVersion8)
475 return (getUnsignedField(14) & FlagExplicit) != 0;
477 /// isPrototyped - Return true if this subprogram is prototyped.
478 bool isPrototyped() const {
479 if (getVersion() <= llvm::LLVMDebugVersion8)
481 return (getUnsignedField(14) & FlagPrototyped) != 0;
484 unsigned isOptimized() const;
486 StringRef getFilename() const {
487 if (getVersion() == llvm::LLVMDebugVersion7)
488 return getCompileUnit().getFilename();
490 return getFieldAs<DIFile>(6).getFilename();
493 StringRef getDirectory() const {
494 if (getVersion() == llvm::LLVMDebugVersion7)
495 return getCompileUnit().getFilename();
497 return getFieldAs<DIFile>(6).getDirectory();
500 /// Verify - Verify that a subprogram descriptor is well formed.
503 /// print - print subprogram.
504 void print(raw_ostream &OS) const;
506 /// dump - print subprogram to dbgs() with a newline.
509 /// describes - Return true if this subprogram provides debugging
510 /// information for the function F.
511 bool describes(const Function *F);
513 Function *getFunction() const { return getFunctionField(16); }
516 /// DIGlobalVariable - This is a wrapper for a global variable.
517 class DIGlobalVariable : public DIDescriptor {
519 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
521 DIScope getContext() const { return getFieldAs<DIScope>(2); }
522 StringRef getName() const { return getStringField(3); }
523 StringRef getDisplayName() const { return getStringField(4); }
524 StringRef getLinkageName() const { return getStringField(5); }
525 DICompileUnit getCompileUnit() const{
526 if (getVersion() == llvm::LLVMDebugVersion7)
527 return getFieldAs<DICompileUnit>(6);
529 DIFile F = getFieldAs<DIFile>(6);
530 return F.getCompileUnit();
533 unsigned getLineNumber() const { return getUnsignedField(7); }
534 DIType getType() const { return getFieldAs<DIType>(8); }
535 unsigned isLocalToUnit() const { return getUnsignedField(9); }
536 unsigned isDefinition() const { return getUnsignedField(10); }
538 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
539 Constant *getConstant() const { return getConstantField(11); }
541 /// Verify - Verify that a global variable descriptor is well formed.
544 /// print - print global variable.
545 void print(raw_ostream &OS) const;
547 /// dump - print global variable to dbgs() with a newline.
551 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
553 class DIVariable : public DIDescriptor {
555 explicit DIVariable(const MDNode *N = 0)
558 DIScope getContext() const { return getFieldAs<DIScope>(1); }
559 StringRef getName() const { return getStringField(2); }
560 DICompileUnit getCompileUnit() const{
561 if (getVersion() == llvm::LLVMDebugVersion7)
562 return getFieldAs<DICompileUnit>(3);
564 DIFile F = getFieldAs<DIFile>(3);
565 return F.getCompileUnit();
567 unsigned getLineNumber() const { return getUnsignedField(4); }
568 DIType getType() const { return getFieldAs<DIType>(5); }
570 /// isArtificial - Return true if this variable is marked as "artificial".
571 bool isArtificial() const {
572 if (getVersion() <= llvm::LLVMDebugVersion8)
574 return (getUnsignedField(6) & FlagArtificial) != 0;
578 /// Verify - Verify that a variable descriptor is well formed.
581 /// HasComplexAddr - Return true if the variable has a complex address.
582 bool hasComplexAddress() const {
583 return getNumAddrElements() > 0;
586 unsigned getNumAddrElements() const;
588 uint64_t getAddrElement(unsigned Idx) const {
589 return getUInt64Field(Idx+6);
592 /// isBlockByrefVariable - Return true if the variable was declared as
593 /// a "__block" variable (Apple Blocks).
594 bool isBlockByrefVariable() const {
595 return getType().isBlockByrefStruct();
598 /// isInlinedFnArgument - Return trule if this variable provides debugging
599 /// information for an inlined function arguments.
600 bool isInlinedFnArgument(const Function *CurFn);
602 /// print - print variable.
603 void print(raw_ostream &OS) const;
605 /// dump - print variable to dbgs() with a newline.
609 /// DILexicalBlock - This is a wrapper for a lexical block.
610 class DILexicalBlock : public DIScope {
612 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
613 DIScope getContext() const { return getFieldAs<DIScope>(1); }
614 unsigned getLineNumber() const { return getUnsignedField(2); }
615 unsigned getColumnNumber() const { return getUnsignedField(3); }
616 StringRef getDirectory() const {
617 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
618 return !dir.empty() ? dir : getContext().getDirectory();
620 StringRef getFilename() const {
621 StringRef filename = getFieldAs<DIFile>(4).getFilename();
622 return !filename.empty() ? filename : getContext().getFilename();
626 /// DINameSpace - A wrapper for a C++ style name space.
627 class DINameSpace : public DIScope {
629 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
630 DIScope getContext() const { return getFieldAs<DIScope>(1); }
631 StringRef getName() const { return getStringField(2); }
632 StringRef getDirectory() const {
633 return getFieldAs<DIFile>(3).getDirectory();
635 StringRef getFilename() const {
636 return getFieldAs<DIFile>(3).getFilename();
638 DICompileUnit getCompileUnit() const{
639 if (getVersion() == llvm::LLVMDebugVersion7)
640 return getFieldAs<DICompileUnit>(3);
642 return getFieldAs<DIFile>(3).getCompileUnit();
644 unsigned getLineNumber() const { return getUnsignedField(4); }
648 /// DILocation - This object holds location information. This object
649 /// is not associated with any DWARF tag.
650 class DILocation : public DIDescriptor {
652 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
654 unsigned getLineNumber() const { return getUnsignedField(0); }
655 unsigned getColumnNumber() const { return getUnsignedField(1); }
656 DIScope getScope() const { return getFieldAs<DIScope>(2); }
657 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
658 StringRef getFilename() const { return getScope().getFilename(); }
659 StringRef getDirectory() const { return getScope().getDirectory(); }
663 /// DIFactory - This object assists with the construction of the various
667 LLVMContext& VMContext;
669 Function *DeclareFn; // llvm.dbg.declare
670 Function *ValueFn; // llvm.dbg.value
672 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
673 void operator=(const DIFactory&); // DO NOT IMPLEMENT
675 enum ComplexAddrKind { OpPlus=1, OpDeref };
677 explicit DIFactory(Module &m);
679 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
680 /// This implicitly uniques the arrays created.
681 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
683 /// GetOrCreateSubrange - Create a descriptor for a value range. This
684 /// implicitly uniques the values returned.
685 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
687 /// CreateUnspecifiedParameter - Create unspeicified type descriptor
688 /// for a subroutine type.
689 DIDescriptor CreateUnspecifiedParameter();
691 /// CreateCompileUnit - Create a new descriptor for the specified compile
693 DICompileUnit CreateCompileUnit(unsigned LangID,
698 bool isOptimized = false,
699 StringRef Flags = "",
700 unsigned RunTimeVer = 0);
702 /// CreateFile - Create a new descriptor for the specified file.
703 DIFile CreateFile(StringRef Filename, StringRef Directory,
706 /// CreateEnumerator - Create a single enumerator value.
707 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
709 /// CreateBasicType - Create a basic type like int, float, etc.
710 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
711 DIFile F, unsigned LineNumber,
712 uint64_t SizeInBits, uint64_t AlignInBits,
713 uint64_t OffsetInBits, unsigned Flags,
716 /// CreateBasicType - Create a basic type like int, float, etc.
717 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
718 DIFile F, unsigned LineNumber,
719 Constant *SizeInBits, Constant *AlignInBits,
720 Constant *OffsetInBits, unsigned Flags,
723 /// CreateDerivedType - Create a derived type like const qualified type,
724 /// pointer, typedef, etc.
725 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
729 uint64_t SizeInBits, uint64_t AlignInBits,
730 uint64_t OffsetInBits, unsigned Flags,
733 /// CreateDerivedType - Create a derived type like const qualified type,
734 /// pointer, typedef, etc.
735 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
739 Constant *SizeInBits,
740 Constant *AlignInBits,
741 Constant *OffsetInBits, unsigned Flags,
744 /// CreateCompositeType - Create a composite type like array, struct, etc.
745 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
750 uint64_t AlignInBits,
751 uint64_t OffsetInBits, unsigned Flags,
754 unsigned RunTimeLang = 0,
755 MDNode *ContainingType = 0);
757 /// CreateTemporaryType - Create a temporary forward-declared type.
758 DIType CreateTemporaryType();
759 DIType CreateTemporaryType(DIFile F);
761 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
762 DIType CreateArtificialType(DIType Ty);
764 /// CreateCompositeType - Create a composite type like array, struct, etc.
765 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
769 Constant *SizeInBits,
770 Constant *AlignInBits,
771 Constant *OffsetInBits,
775 unsigned RunTimeLang = 0,
776 MDNode *ContainingType = 0);
778 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
779 /// See comments in DISubprogram for descriptions of these fields.
780 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
781 StringRef DisplayName,
782 StringRef LinkageName,
783 DIFile F, unsigned LineNo,
784 DIType Ty, bool isLocalToUnit,
788 DIType ContainingType = DIType(),
790 bool isOptimized = false,
793 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
794 /// given declaration.
795 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
797 /// CreateGlobalVariable - Create a new descriptor for the specified global.
799 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
800 StringRef DisplayName,
801 StringRef LinkageName,
803 unsigned LineNo, DIType Ty, bool isLocalToUnit,
804 bool isDefinition, llvm::GlobalVariable *GV);
806 /// CreateGlobalVariable - Create a new descriptor for the specified constant.
808 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
809 StringRef DisplayName,
810 StringRef LinkageName,
812 unsigned LineNo, DIType Ty, bool isLocalToUnit,
813 bool isDefinition, llvm::Constant *C);
815 /// CreateVariable - Create a new descriptor for the specified variable.
816 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
818 DIFile F, unsigned LineNo,
819 DIType Ty, bool AlwaysPreserve = false,
822 /// CreateComplexVariable - Create a new descriptor for the specified
823 /// variable which has a complex address expression for its address.
824 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
825 StringRef Name, DIFile F, unsigned LineNo,
826 DIType Ty, Value *const *Addr,
829 /// CreateLexicalBlock - This creates a descriptor for a lexical block
830 /// with the specified parent context.
831 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
832 unsigned Line = 0, unsigned Col = 0);
834 /// CreateNameSpace - This creates new descriptor for a namespace
835 /// with the specified parent context.
836 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
837 DIFile F, unsigned LineNo);
839 /// CreateLocation - Creates a debug info location.
840 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
841 DIScope S, DILocation OrigLoc);
843 /// CreateLocation - Creates a debug info location.
844 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
845 DIScope S, MDNode *OrigLoc = 0);
847 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
848 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
849 BasicBlock *InsertAtEnd);
851 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
852 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
853 Instruction *InsertBefore);
855 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
856 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
857 DIVariable D, BasicBlock *InsertAtEnd);
859 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
860 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
861 DIVariable D, Instruction *InsertBefore);
863 // RecordType - Record DIType in a module such that it is not lost even if
864 // it is not referenced through debug info anchors.
865 void RecordType(DIType T);
868 Constant *GetTagConstant(unsigned TAG);
871 /// getDISubprogram - Find subprogram that is enclosing this scope.
872 DISubprogram getDISubprogram(const MDNode *Scope);
874 /// getDICompositeType - Find underlying composite type.
875 DICompositeType getDICompositeType(DIType T);
877 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
878 /// to hold function specific information.
879 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, StringRef Name);
881 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
882 /// suitable to hold function specific information.
883 NamedMDNode *getFnSpecificMDNode(const Module &M, StringRef Name);
885 class DebugInfoFinder {
887 /// processModule - Process entire module and collect debug info
889 void processModule(Module &M);
892 /// processType - Process DIType.
893 void processType(DIType DT);
895 /// processLexicalBlock - Process DILexicalBlock.
896 void processLexicalBlock(DILexicalBlock LB);
898 /// processSubprogram - Process DISubprogram.
899 void processSubprogram(DISubprogram SP);
901 /// processDeclare - Process DbgDeclareInst.
902 void processDeclare(DbgDeclareInst *DDI);
904 /// processLocation - Process DILocation.
905 void processLocation(DILocation Loc);
907 /// addCompileUnit - Add compile unit into CUs.
908 bool addCompileUnit(DICompileUnit CU);
910 /// addGlobalVariable - Add global variable into GVs.
911 bool addGlobalVariable(DIGlobalVariable DIG);
913 // addSubprogram - Add subprgoram into SPs.
914 bool addSubprogram(DISubprogram SP);
916 /// addType - Add type into Tys.
917 bool addType(DIType DT);
920 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
921 iterator compile_unit_begin() const { return CUs.begin(); }
922 iterator compile_unit_end() const { return CUs.end(); }
923 iterator subprogram_begin() const { return SPs.begin(); }
924 iterator subprogram_end() const { return SPs.end(); }
925 iterator global_variable_begin() const { return GVs.begin(); }
926 iterator global_variable_end() const { return GVs.end(); }
927 iterator type_begin() const { return TYs.begin(); }
928 iterator type_end() const { return TYs.end(); }
930 unsigned compile_unit_count() const { return CUs.size(); }
931 unsigned global_variable_count() const { return GVs.size(); }
932 unsigned subprogram_count() const { return SPs.size(); }
933 unsigned type_count() const { return TYs.size(); }
936 SmallVector<MDNode *, 8> CUs; // Compile Units
937 SmallVector<MDNode *, 8> SPs; // Subprograms
938 SmallVector<MDNode *, 8> GVs; // Global Variables;
939 SmallVector<MDNode *, 8> TYs; // Types
940 SmallPtrSet<MDNode *, 64> NodesSeen;
942 } // end namespace llvm