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_DEBUGINFO_H
18 #define LLVM_DEBUGINFO_H
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/Dwarf.h"
46 class DILexicalBlockFile;
52 /// Maps from type identifier to the actual MDNode.
53 typedef DenseMap<const MDString *, MDNode*> DITypeIdentifierMap;
55 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
56 /// This should not be stored in a container, because the underlying MDNode
57 /// may change in certain situations.
59 // Befriends DITypeRef so DITypeRef can befriend the protected member
60 // function: getFieldAs<DITypeRef>.
61 friend class DITypeRef;
65 FlagProtected = 1 << 1,
67 FlagAppleBlock = 1 << 3,
68 FlagBlockByrefStruct = 1 << 4,
70 FlagArtificial = 1 << 6,
71 FlagExplicit = 1 << 7,
72 FlagPrototyped = 1 << 8,
73 FlagObjcClassComplete = 1 << 9,
74 FlagObjectPointer = 1 << 10,
76 FlagStaticMember = 1 << 12,
77 FlagIndirectVariable = 1 << 13
80 const MDNode *DbgNode;
82 StringRef getStringField(unsigned Elt) const;
83 unsigned getUnsignedField(unsigned Elt) const {
84 return (unsigned)getUInt64Field(Elt);
86 uint64_t getUInt64Field(unsigned Elt) const;
87 int64_t getInt64Field(unsigned Elt) const;
88 DIDescriptor getDescriptorField(unsigned Elt) const;
90 template <typename DescTy>
91 DescTy getFieldAs(unsigned Elt) const {
92 return DescTy(getDescriptorField(Elt));
95 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
96 Constant *getConstantField(unsigned Elt) const;
97 Function *getFunctionField(unsigned Elt) const;
98 void replaceFunctionField(unsigned Elt, Function *F);
101 explicit DIDescriptor(const MDNode *N = 0) : DbgNode(N) {}
105 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
106 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
108 // An explicit operator bool so that we can do testing of DI values
110 // FIXME: This operator bool isn't actually protecting anything at the
111 // moment due to the conversion operator above making DIDescriptor nodes
112 // implicitly convertable to bool.
113 LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
115 bool operator==(DIDescriptor Other) const {
116 return DbgNode == Other.DbgNode;
118 bool operator!=(DIDescriptor Other) const {
119 return !operator==(Other);
122 uint16_t getTag() const {
123 return getUnsignedField(0) & ~LLVMDebugVersionMask;
126 bool isDerivedType() const;
127 bool isCompositeType() const;
128 bool isBasicType() const;
129 bool isVariable() const;
130 bool isSubprogram() const;
131 bool isGlobalVariable() const;
132 bool isScope() const;
134 bool isCompileUnit() const;
135 bool isNameSpace() const;
136 bool isLexicalBlockFile() const;
137 bool isLexicalBlock() const;
138 bool isSubrange() const;
139 bool isEnumerator() const;
141 bool isUnspecifiedParameter() const;
142 bool isTemplateTypeParameter() const;
143 bool isTemplateValueParameter() const;
144 bool isObjCProperty() const;
145 bool isImportedEntity() const;
147 /// print - print descriptor.
148 void print(raw_ostream &OS) const;
150 /// dump - print descriptor to dbgs() with a newline.
154 /// Specialize getFieldAs to handle fields that are references to DITypes.
156 DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
158 /// DISubrange - This is used to represent ranges, for array bounds.
159 class DISubrange : public DIDescriptor {
160 friend class DIDescriptor;
161 void printInternal(raw_ostream &OS) const;
163 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
165 int64_t getLo() const { return getInt64Field(1); }
166 int64_t getCount() const { return getInt64Field(2); }
170 /// DIArray - This descriptor holds an array of descriptors.
171 class DIArray : public DIDescriptor {
173 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
175 unsigned getNumElements() const;
176 DIDescriptor getElement(unsigned Idx) const {
177 return getDescriptorField(Idx);
181 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
182 /// FIXME: it seems strange that this doesn't have either a reference to the
183 /// type/precision or a file/line pair for location info.
184 class DIEnumerator : public DIDescriptor {
185 friend class DIDescriptor;
186 void printInternal(raw_ostream &OS) const;
188 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
190 StringRef getName() const { return getStringField(1); }
191 int64_t getEnumValue() const { return getInt64Field(2); }
195 /// DIScope - A base class for various scopes.
196 class DIScope : public DIDescriptor {
198 friend class DIDescriptor;
199 void printInternal(raw_ostream &OS) const;
201 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
203 /// Gets the parent scope for this scope node or returns a
204 /// default constructed scope.
205 DIScope getContext() const;
206 StringRef getFilename() const;
207 StringRef getDirectory() const;
210 /// DIType - This is a wrapper for a type.
211 /// FIXME: Types should be factored much better so that CV qualifiers and
212 /// others do not require a huge and empty descriptor full of zeros.
213 class DIType : public DIScope {
215 friend class DIDescriptor;
216 void printInternal(raw_ostream &OS) const;
219 DIType(const MDNode *N = 0) : DIScope(N) {}
221 /// Verify - Verify that a type descriptor is well formed.
224 DIScope getContext() const { return getFieldAs<DIScope>(2); }
225 StringRef getName() const { return getStringField(3); }
226 unsigned getLineNumber() const { return getUnsignedField(4); }
227 uint64_t getSizeInBits() const { return getUInt64Field(5); }
228 uint64_t getAlignInBits() const { return getUInt64Field(6); }
229 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
230 // carry this is just plain insane.
231 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
232 unsigned getFlags() const { return getUnsignedField(8); }
233 bool isPrivate() const {
234 return (getFlags() & FlagPrivate) != 0;
236 bool isProtected() const {
237 return (getFlags() & FlagProtected) != 0;
239 bool isForwardDecl() const {
240 return (getFlags() & FlagFwdDecl) != 0;
242 // isAppleBlock - Return true if this is the Apple Blocks extension.
243 bool isAppleBlockExtension() const {
244 return (getFlags() & FlagAppleBlock) != 0;
246 bool isBlockByrefStruct() const {
247 return (getFlags() & FlagBlockByrefStruct) != 0;
249 bool isVirtual() const {
250 return (getFlags() & FlagVirtual) != 0;
252 bool isArtificial() const {
253 return (getFlags() & FlagArtificial) != 0;
255 bool isObjectPointer() const {
256 return (getFlags() & FlagObjectPointer) != 0;
258 bool isObjcClassComplete() const {
259 return (getFlags() & FlagObjcClassComplete) != 0;
261 bool isVector() const {
262 return (getFlags() & FlagVector) != 0;
264 bool isStaticMember() const {
265 return (getFlags() & FlagStaticMember) != 0;
267 bool isValid() const {
268 return DbgNode && isType();
271 /// isUnsignedDIType - Return true if type encoding is unsigned.
272 bool isUnsignedDIType();
274 /// Generate a reference to this DIType. Uses the type identifier instead
275 /// of the actual MDNode if possible, to help type uniquing.
276 DITypeRef generateRef();
278 /// replaceAllUsesWith - Replace all uses of debug info referenced by
280 void replaceAllUsesWith(DIDescriptor &D);
281 void replaceAllUsesWith(MDNode *D);
284 /// Represents reference to a DIType, abstracts over direct and
285 /// identifier-based metadata type references.
287 template <typename DescTy>
288 friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
289 friend DITypeRef DIType::generateRef();
291 /// TypeVal can be either a MDNode or a MDString, in the latter,
292 /// MDString specifies the type identifier.
293 const Value *TypeVal;
294 explicit DITypeRef(const Value *V);
296 DIType resolve(const DITypeIdentifierMap &Map) const;
297 operator Value *() const { return const_cast<Value*>(TypeVal); }
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.
311 /// DIDerivedType - A simple derived type, like a const qualified type,
312 /// a typedef, a pointer or reference, et cetera. Or, a data member of
313 /// a class/struct/union.
314 class DIDerivedType : public DIType {
315 friend class DIDescriptor;
316 void printInternal(raw_ostream &OS) const;
319 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
321 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
323 /// getOriginalTypeSize - If this type is derived from a base type then
324 /// return base type size.
325 uint64_t getOriginalTypeSize() const;
327 /// getObjCProperty - Return property node, if this ivar is
328 /// associated with one.
329 MDNode *getObjCProperty() const;
331 DITypeRef getClassType() const {
332 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
333 return getFieldAs<DITypeRef>(10);
336 Constant *getConstant() const {
337 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
338 return getConstantField(10);
341 /// Verify - Verify that a derived type descriptor is well formed.
345 /// DICompositeType - This descriptor holds a type that can refer to multiple
346 /// other types, like a function or struct.
347 /// DICompositeType is derived from DIDerivedType because some
348 /// composite types (such as enums) can be derived from basic types
349 // FIXME: Make this derive from DIType directly & just store the
350 // base type in a single DIType field.
351 class DICompositeType : public DIDerivedType {
352 friend class DIDescriptor;
353 void printInternal(raw_ostream &OS) const;
355 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
357 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
358 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
359 void addMember(DIDescriptor D);
360 unsigned getRunTimeLang() const { return getUnsignedField(11); }
361 DITypeRef getContainingType() const {
362 return getFieldAs<DITypeRef>(12);
364 void setContainingType(DICompositeType ContainingType);
365 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
366 MDString *getIdentifier() const;
368 /// Verify - Verify that a composite type descriptor is well formed.
372 /// DIFile - This is a wrapper for a file.
373 class DIFile : public DIScope {
374 friend class DIDescriptor;
376 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
377 MDNode *getFileNode() const;
381 /// DICompileUnit - A wrapper for a compile unit.
382 class DICompileUnit : public DIScope {
383 friend class DIDescriptor;
384 void printInternal(raw_ostream &OS) const;
386 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
388 unsigned getLanguage() const { return getUnsignedField(2); }
389 StringRef getProducer() const { return getStringField(3); }
391 bool isOptimized() const { return getUnsignedField(4) != 0; }
392 StringRef getFlags() const { return getStringField(5); }
393 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
395 DIArray getEnumTypes() const;
396 DIArray getRetainedTypes() const;
397 DIArray getSubprograms() const;
398 DIArray getGlobalVariables() const;
399 DIArray getImportedEntities() const;
401 StringRef getSplitDebugFilename() const { return getStringField(12); }
403 /// Verify - Verify that a compile unit is well formed.
407 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
408 class DISubprogram : public DIScope {
409 friend class DIDescriptor;
410 void printInternal(raw_ostream &OS) const;
412 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
414 DIScope getContext() const { return getFieldAs<DIScope>(2); }
415 StringRef getName() const { return getStringField(3); }
416 StringRef getDisplayName() const { return getStringField(4); }
417 StringRef getLinkageName() const { return getStringField(5); }
418 unsigned getLineNumber() const { return getUnsignedField(6); }
419 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
421 /// isLocalToUnit - Return true if this subprogram is local to the current
422 /// compile unit, like 'static' in C.
423 unsigned isLocalToUnit() const { return getUnsignedField(8); }
424 unsigned isDefinition() const { return getUnsignedField(9); }
426 unsigned getVirtuality() const { return getUnsignedField(10); }
427 unsigned getVirtualIndex() const { return getUnsignedField(11); }
429 DICompositeType getContainingType() const {
430 return getFieldAs<DICompositeType>(12);
433 unsigned getFlags() const {
434 return getUnsignedField(13);
437 unsigned isArtificial() const {
438 return (getUnsignedField(13) & FlagArtificial) != 0;
440 /// isPrivate - Return true if this subprogram has "private"
441 /// access specifier.
442 bool isPrivate() const {
443 return (getUnsignedField(13) & FlagPrivate) != 0;
445 /// isProtected - Return true if this subprogram has "protected"
446 /// access specifier.
447 bool isProtected() const {
448 return (getUnsignedField(13) & FlagProtected) != 0;
450 /// isExplicit - Return true if this subprogram is marked as explicit.
451 bool isExplicit() const {
452 return (getUnsignedField(13) & FlagExplicit) != 0;
454 /// isPrototyped - Return true if this subprogram is prototyped.
455 bool isPrototyped() const {
456 return (getUnsignedField(13) & FlagPrototyped) != 0;
459 unsigned isOptimized() const;
461 /// Verify - Verify that a subprogram descriptor is well formed.
464 /// describes - Return true if this subprogram provides debugging
465 /// information for the function F.
466 bool describes(const Function *F);
468 Function *getFunction() const { return getFunctionField(15); }
469 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
470 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
471 DISubprogram getFunctionDeclaration() const {
472 return getFieldAs<DISubprogram>(17);
474 MDNode *getVariablesNodes() const;
475 DIArray getVariables() const;
477 /// getScopeLineNumber - Get the beginning of the scope of the
478 /// function, not necessarily where the name of the program
480 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
483 /// DILexicalBlock - This is a wrapper for a lexical block.
484 class DILexicalBlock : public DIScope {
486 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
487 DIScope getContext() const { return getFieldAs<DIScope>(2); }
488 unsigned getLineNumber() const { return getUnsignedField(3); }
489 unsigned getColumnNumber() const { return getUnsignedField(4); }
493 /// DILexicalBlockFile - This is a wrapper for a lexical block with
494 /// a filename change.
495 class DILexicalBlockFile : public DIScope {
497 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
498 DIScope getContext() const {
499 if (getScope().isSubprogram())
501 return getScope().getContext();
503 unsigned getLineNumber() const { return getScope().getLineNumber(); }
504 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
505 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
509 /// DINameSpace - A wrapper for a C++ style name space.
510 class DINameSpace : public DIScope {
511 friend class DIDescriptor;
512 void printInternal(raw_ostream &OS) const;
514 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
515 DIScope getContext() const { return getFieldAs<DIScope>(2); }
516 StringRef getName() const { return getStringField(3); }
517 unsigned getLineNumber() const { return getUnsignedField(4); }
521 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
522 class DITemplateTypeParameter : public DIDescriptor {
524 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
526 DIScope getContext() const { return getFieldAs<DIScope>(1); }
527 StringRef getName() const { return getStringField(2); }
528 DIType getType() const { return getFieldAs<DIType>(3); }
529 StringRef getFilename() const {
530 return getFieldAs<DIFile>(4).getFilename();
532 StringRef getDirectory() const {
533 return getFieldAs<DIFile>(4).getDirectory();
535 unsigned getLineNumber() const { return getUnsignedField(5); }
536 unsigned getColumnNumber() const { return getUnsignedField(6); }
540 /// DITemplateValueParameter - This is a wrapper for template value parameter.
541 class DITemplateValueParameter : public DIDescriptor {
543 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
545 DIScope getContext() const { return getFieldAs<DIScope>(1); }
546 StringRef getName() const { return getStringField(2); }
547 DIType getType() const { return getFieldAs<DIType>(3); }
548 Value *getValue() const;
549 StringRef getFilename() const {
550 return getFieldAs<DIFile>(5).getFilename();
552 StringRef getDirectory() const {
553 return getFieldAs<DIFile>(5).getDirectory();
555 unsigned getLineNumber() const { return getUnsignedField(6); }
556 unsigned getColumnNumber() const { return getUnsignedField(7); }
560 /// DIGlobalVariable - This is a wrapper for a global variable.
561 class DIGlobalVariable : public DIDescriptor {
562 friend class DIDescriptor;
563 void printInternal(raw_ostream &OS) const;
565 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
567 DIScope getContext() const { return getFieldAs<DIScope>(2); }
568 StringRef getName() const { return getStringField(3); }
569 StringRef getDisplayName() const { return getStringField(4); }
570 StringRef getLinkageName() const { return getStringField(5); }
571 StringRef getFilename() const {
572 return getFieldAs<DIFile>(6).getFilename();
574 StringRef getDirectory() const {
575 return getFieldAs<DIFile>(6).getDirectory();
579 unsigned getLineNumber() const { return getUnsignedField(7); }
580 DIType getType() const { return getFieldAs<DIType>(8); }
581 unsigned isLocalToUnit() const { return getUnsignedField(9); }
582 unsigned isDefinition() const { return getUnsignedField(10); }
584 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
585 Constant *getConstant() const { return getConstantField(11); }
586 DIDerivedType getStaticDataMemberDeclaration() const {
587 return getFieldAs<DIDerivedType>(12);
590 /// Verify - Verify that a global variable descriptor is well formed.
594 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
596 class DIVariable : public DIDescriptor {
597 friend class DIDescriptor;
598 void printInternal(raw_ostream &OS) const;
600 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
602 DIScope getContext() const { return getFieldAs<DIScope>(1); }
603 StringRef getName() const { return getStringField(2); }
604 DIFile getFile() const { return getFieldAs<DIFile>(3); }
605 unsigned getLineNumber() const {
606 return (getUnsignedField(4) << 8) >> 8;
608 unsigned getArgNumber() const {
609 unsigned L = getUnsignedField(4);
612 DIType getType() const { return getFieldAs<DIType>(5); }
614 /// isArtificial - Return true if this variable is marked as "artificial".
615 bool isArtificial() const {
616 return (getUnsignedField(6) & FlagArtificial) != 0;
619 bool isObjectPointer() const {
620 return (getUnsignedField(6) & FlagObjectPointer) != 0;
623 /// \brief Return true if this variable is represented as a pointer.
624 bool isIndirect() const {
625 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
628 /// getInlinedAt - If this variable is inlined then return inline location.
629 MDNode *getInlinedAt() const;
631 /// Verify - Verify that a variable descriptor is well formed.
634 /// HasComplexAddr - Return true if the variable has a complex address.
635 bool hasComplexAddress() const {
636 return getNumAddrElements() > 0;
639 unsigned getNumAddrElements() const;
641 uint64_t getAddrElement(unsigned Idx) const {
642 return getUInt64Field(Idx+8);
645 /// isBlockByrefVariable - Return true if the variable was declared as
646 /// a "__block" variable (Apple Blocks).
647 bool isBlockByrefVariable() const {
648 return getType().isBlockByrefStruct();
651 /// isInlinedFnArgument - Return true if this variable provides debugging
652 /// information for an inlined function arguments.
653 bool isInlinedFnArgument(const Function *CurFn);
655 void printExtendedName(raw_ostream &OS) const;
658 /// DILocation - This object holds location information. This object
659 /// is not associated with any DWARF tag.
660 class DILocation : public DIDescriptor {
662 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
664 unsigned getLineNumber() const { return getUnsignedField(0); }
665 unsigned getColumnNumber() const { return getUnsignedField(1); }
666 DIScope getScope() const { return getFieldAs<DIScope>(2); }
667 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
668 StringRef getFilename() const { return getScope().getFilename(); }
669 StringRef getDirectory() const { return getScope().getDirectory(); }
673 class DIObjCProperty : public DIDescriptor {
674 friend class DIDescriptor;
675 void printInternal(raw_ostream &OS) const;
677 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
679 StringRef getObjCPropertyName() const { return getStringField(1); }
680 DIFile getFile() const { return getFieldAs<DIFile>(2); }
681 unsigned getLineNumber() const { return getUnsignedField(3); }
683 StringRef getObjCPropertyGetterName() const {
684 return getStringField(4);
686 StringRef getObjCPropertySetterName() const {
687 return getStringField(5);
689 bool isReadOnlyObjCProperty() const {
690 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
692 bool isReadWriteObjCProperty() const {
693 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
695 bool isAssignObjCProperty() const {
696 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
698 bool isRetainObjCProperty() const {
699 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
701 bool isCopyObjCProperty() const {
702 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
704 bool isNonAtomicObjCProperty() const {
705 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
708 DIType getType() const { return getFieldAs<DIType>(7); }
710 /// Verify - Verify that a derived type descriptor is well formed.
714 /// \brief An imported module (C++ using directive or similar).
715 class DIImportedEntity : public DIDescriptor {
716 friend class DIDescriptor;
717 void printInternal(raw_ostream &OS) const;
719 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
720 DIScope getContext() const { return getFieldAs<DIScope>(1); }
721 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
722 unsigned getLineNumber() const { return getUnsignedField(3); }
723 StringRef getName() const { return getStringField(4); }
727 /// getDISubprogram - Find subprogram that is enclosing this scope.
728 DISubprogram getDISubprogram(const MDNode *Scope);
730 /// getDICompositeType - Find underlying composite type.
731 DICompositeType getDICompositeType(DIType T);
733 /// isSubprogramContext - Return true if Context is either a subprogram
734 /// or another context nested inside a subprogram.
735 bool isSubprogramContext(const MDNode *Context);
737 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
738 /// to hold function specific information.
739 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
741 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
742 /// suitable to hold function specific information.
743 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
745 /// createInlinedVariable - Create a new inlined variable based on current
747 /// @param DV Current Variable.
748 /// @param InlinedScope Location at current variable is inlined.
749 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
750 LLVMContext &VMContext);
752 /// cleanseInlinedVariable - Remove inlined scope from the variable.
753 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
755 /// Construct DITypeIdentifierMap by going through retained types of each CU.
756 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
758 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
759 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
760 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
761 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
762 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
764 class DebugInfoFinder {
766 /// processModule - Process entire module and collect debug info
768 void processModule(const Module &M);
770 /// processDeclare - Process DbgDeclareInst.
771 void processDeclare(const DbgDeclareInst *DDI);
772 /// Process DbgValueInst.
773 void processValue(const DbgValueInst *DVI);
774 /// processLocation - Process DILocation.
775 void processLocation(DILocation Loc);
780 /// processType - Process DIType.
781 void processType(DIType DT);
783 /// processLexicalBlock - Process DILexicalBlock.
784 void processLexicalBlock(DILexicalBlock LB);
786 /// processSubprogram - Process DISubprogram.
787 void processSubprogram(DISubprogram SP);
789 void processScope(DIScope Scope);
791 /// addCompileUnit - Add compile unit into CUs.
792 bool addCompileUnit(DICompileUnit CU);
794 /// addGlobalVariable - Add global variable into GVs.
795 bool addGlobalVariable(DIGlobalVariable DIG);
797 // addSubprogram - Add subprogram into SPs.
798 bool addSubprogram(DISubprogram SP);
800 /// addType - Add type into Tys.
801 bool addType(DIType DT);
803 bool addScope(DIScope Scope);
806 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
807 iterator compile_unit_begin() const { return CUs.begin(); }
808 iterator compile_unit_end() const { return CUs.end(); }
809 iterator subprogram_begin() const { return SPs.begin(); }
810 iterator subprogram_end() const { return SPs.end(); }
811 iterator global_variable_begin() const { return GVs.begin(); }
812 iterator global_variable_end() const { return GVs.end(); }
813 iterator type_begin() const { return TYs.begin(); }
814 iterator type_end() const { return TYs.end(); }
815 iterator scope_begin() const { return Scopes.begin(); }
816 iterator scope_end() const { return Scopes.end(); }
818 unsigned compile_unit_count() const { return CUs.size(); }
819 unsigned global_variable_count() const { return GVs.size(); }
820 unsigned subprogram_count() const { return SPs.size(); }
821 unsigned type_count() const { return TYs.size(); }
822 unsigned scope_count() const { return Scopes.size(); }
825 SmallVector<MDNode *, 8> CUs; // Compile Units
826 SmallVector<MDNode *, 8> SPs; // Subprograms
827 SmallVector<MDNode *, 8> GVs; // Global Variables;
828 SmallVector<MDNode *, 8> TYs; // Types
829 SmallVector<MDNode *, 8> Scopes; // Scopes
830 SmallPtrSet<MDNode *, 64> NodesSeen;
832 } // end namespace llvm