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 /// Represents reference to a DIType, abstracts over direct and
159 /// identifier-based metadata type references.
161 friend DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
163 /// TypeVal can be either a MDNode or a MDString, in the latter,
164 /// MDString specifies the type identifier.
165 const Value *TypeVal;
166 explicit DITypeRef(const Value *V);
168 DIType resolve(const DITypeIdentifierMap &Map) const;
171 /// DISubrange - This is used to represent ranges, for array bounds.
172 class DISubrange : public DIDescriptor {
173 friend class DIDescriptor;
174 void printInternal(raw_ostream &OS) const;
176 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
178 int64_t getLo() const { return getInt64Field(1); }
179 int64_t getCount() const { return getInt64Field(2); }
183 /// DIArray - This descriptor holds an array of descriptors.
184 class DIArray : public DIDescriptor {
186 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
188 unsigned getNumElements() const;
189 DIDescriptor getElement(unsigned Idx) const {
190 return getDescriptorField(Idx);
194 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
195 /// FIXME: it seems strange that this doesn't have either a reference to the
196 /// type/precision or a file/line pair for location info.
197 class DIEnumerator : public DIDescriptor {
198 friend class DIDescriptor;
199 void printInternal(raw_ostream &OS) const;
201 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
203 StringRef getName() const { return getStringField(1); }
204 int64_t getEnumValue() const { return getInt64Field(2); }
208 /// DIScope - A base class for various scopes.
209 class DIScope : public DIDescriptor {
211 friend class DIDescriptor;
212 void printInternal(raw_ostream &OS) const;
214 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
216 /// Gets the parent scope for this scope node or returns a
217 /// default constructed scope.
218 DIScope getContext() const;
219 StringRef getFilename() const;
220 StringRef getDirectory() const;
223 /// DIType - This is a wrapper for a type.
224 /// FIXME: Types should be factored much better so that CV qualifiers and
225 /// others do not require a huge and empty descriptor full of zeros.
226 class DIType : public DIScope {
228 friend class DIDescriptor;
229 void printInternal(raw_ostream &OS) const;
232 DIType(const MDNode *N = 0) : DIScope(N) {}
234 /// Verify - Verify that a type descriptor is well formed.
237 DIScope getContext() const { return getFieldAs<DIScope>(2); }
238 StringRef getName() const { return getStringField(3); }
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;
249 bool isProtected() const {
250 return (getFlags() & FlagProtected) != 0;
252 bool isForwardDecl() const {
253 return (getFlags() & FlagFwdDecl) != 0;
255 // isAppleBlock - Return true if this is the Apple Blocks extension.
256 bool isAppleBlockExtension() const {
257 return (getFlags() & FlagAppleBlock) != 0;
259 bool isBlockByrefStruct() const {
260 return (getFlags() & FlagBlockByrefStruct) != 0;
262 bool isVirtual() const {
263 return (getFlags() & FlagVirtual) != 0;
265 bool isArtificial() const {
266 return (getFlags() & FlagArtificial) != 0;
268 bool isObjectPointer() const {
269 return (getFlags() & FlagObjectPointer) != 0;
271 bool isObjcClassComplete() const {
272 return (getFlags() & FlagObjcClassComplete) != 0;
274 bool isVector() const {
275 return (getFlags() & FlagVector) != 0;
277 bool isStaticMember() const {
278 return (getFlags() & FlagStaticMember) != 0;
280 bool isValid() const {
281 return DbgNode && isType();
284 /// isUnsignedDIType - Return true if type encoding is unsigned.
285 bool isUnsignedDIType();
287 /// replaceAllUsesWith - Replace all uses of debug info referenced by
289 void replaceAllUsesWith(DIDescriptor &D);
290 void replaceAllUsesWith(MDNode *D);
293 /// DIBasicType - A basic type, like 'int' or 'float'.
294 class DIBasicType : public DIType {
296 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
298 unsigned getEncoding() const { return getUnsignedField(9); }
300 /// Verify - Verify that a basic type descriptor is well formed.
304 /// DIDerivedType - A simple derived type, like a const qualified type,
305 /// a typedef, a pointer or reference, et cetera. Or, a data member of
306 /// a class/struct/union.
307 class DIDerivedType : public DIType {
308 friend class DIDescriptor;
309 void printInternal(raw_ostream &OS) const;
312 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
314 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
316 /// getOriginalTypeSize - If this type is derived from a base type then
317 /// return base type size.
318 uint64_t getOriginalTypeSize() const;
320 /// getObjCProperty - Return property node, if this ivar is
321 /// associated with one.
322 MDNode *getObjCProperty() const;
324 DITypeRef getClassType() const {
325 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
326 return getFieldAs<DITypeRef>(10);
329 Constant *getConstant() const {
330 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
331 return getConstantField(10);
334 /// Verify - Verify that a derived type descriptor is well formed.
338 /// DICompositeType - This descriptor holds a type that can refer to multiple
339 /// other types, like a function or struct.
340 /// DICompositeType is derived from DIDerivedType because some
341 /// composite types (such as enums) can be derived from basic types
342 // FIXME: Make this derive from DIType directly & just store the
343 // base type in a single DIType field.
344 class DICompositeType : public DIDerivedType {
345 friend class DIDescriptor;
346 void printInternal(raw_ostream &OS) const;
348 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
350 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
351 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
352 void addMember(DIDescriptor D);
353 unsigned getRunTimeLang() const { return getUnsignedField(11); }
354 DICompositeType getContainingType() const {
355 return getFieldAs<DICompositeType>(12);
357 void setContainingType(DICompositeType ContainingType);
358 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
359 MDString *getIdentifier() const;
361 /// Verify - Verify that a composite type descriptor is well formed.
365 /// DIFile - This is a wrapper for a file.
366 class DIFile : public DIScope {
367 friend class DIDescriptor;
369 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
370 MDNode *getFileNode() const;
374 /// DICompileUnit - A wrapper for a compile unit.
375 class DICompileUnit : public DIScope {
376 friend class DIDescriptor;
377 void printInternal(raw_ostream &OS) const;
379 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
381 unsigned getLanguage() const { return getUnsignedField(2); }
382 StringRef getProducer() const { return getStringField(3); }
384 bool isOptimized() const { return getUnsignedField(4) != 0; }
385 StringRef getFlags() const { return getStringField(5); }
386 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
388 DIArray getEnumTypes() const;
389 DIArray getRetainedTypes() const;
390 DIArray getSubprograms() const;
391 DIArray getGlobalVariables() const;
392 DIArray getImportedEntities() const;
394 StringRef getSplitDebugFilename() const { return getStringField(12); }
396 /// Verify - Verify that a compile unit is well formed.
400 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
401 class DISubprogram : public DIScope {
402 friend class DIDescriptor;
403 void printInternal(raw_ostream &OS) const;
405 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
407 DIScope getContext() const { return getFieldAs<DIScope>(2); }
408 StringRef getName() const { return getStringField(3); }
409 StringRef getDisplayName() const { return getStringField(4); }
410 StringRef getLinkageName() const { return getStringField(5); }
411 unsigned getLineNumber() const { return getUnsignedField(6); }
412 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
414 /// isLocalToUnit - Return true if this subprogram is local to the current
415 /// compile unit, like 'static' in C.
416 unsigned isLocalToUnit() const { return getUnsignedField(8); }
417 unsigned isDefinition() const { return getUnsignedField(9); }
419 unsigned getVirtuality() const { return getUnsignedField(10); }
420 unsigned getVirtualIndex() const { return getUnsignedField(11); }
422 DICompositeType getContainingType() const {
423 return getFieldAs<DICompositeType>(12);
426 unsigned getFlags() const {
427 return getUnsignedField(13);
430 unsigned isArtificial() const {
431 return (getUnsignedField(13) & FlagArtificial) != 0;
433 /// isPrivate - Return true if this subprogram has "private"
434 /// access specifier.
435 bool isPrivate() const {
436 return (getUnsignedField(13) & FlagPrivate) != 0;
438 /// isProtected - Return true if this subprogram has "protected"
439 /// access specifier.
440 bool isProtected() const {
441 return (getUnsignedField(13) & FlagProtected) != 0;
443 /// isExplicit - Return true if this subprogram is marked as explicit.
444 bool isExplicit() const {
445 return (getUnsignedField(13) & FlagExplicit) != 0;
447 /// isPrototyped - Return true if this subprogram is prototyped.
448 bool isPrototyped() const {
449 return (getUnsignedField(13) & FlagPrototyped) != 0;
452 unsigned isOptimized() const;
454 /// Verify - Verify that a subprogram descriptor is well formed.
457 /// describes - Return true if this subprogram provides debugging
458 /// information for the function F.
459 bool describes(const Function *F);
461 Function *getFunction() const { return getFunctionField(15); }
462 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
463 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
464 DISubprogram getFunctionDeclaration() const {
465 return getFieldAs<DISubprogram>(17);
467 MDNode *getVariablesNodes() const;
468 DIArray getVariables() const;
470 /// getScopeLineNumber - Get the beginning of the scope of the
471 /// function, not necessarily where the name of the program
473 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
476 /// DILexicalBlock - This is a wrapper for a lexical block.
477 class DILexicalBlock : public DIScope {
479 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
480 DIScope getContext() const { return getFieldAs<DIScope>(2); }
481 unsigned getLineNumber() const { return getUnsignedField(3); }
482 unsigned getColumnNumber() const { return getUnsignedField(4); }
486 /// DILexicalBlockFile - This is a wrapper for a lexical block with
487 /// a filename change.
488 class DILexicalBlockFile : public DIScope {
490 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
491 DIScope getContext() const {
492 if (getScope().isSubprogram())
494 return getScope().getContext();
496 unsigned getLineNumber() const { return getScope().getLineNumber(); }
497 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
498 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
502 /// DINameSpace - A wrapper for a C++ style name space.
503 class DINameSpace : public DIScope {
504 friend class DIDescriptor;
505 void printInternal(raw_ostream &OS) const;
507 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
508 DIScope getContext() const { return getFieldAs<DIScope>(2); }
509 StringRef getName() const { return getStringField(3); }
510 unsigned getLineNumber() const { return getUnsignedField(4); }
514 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
515 class DITemplateTypeParameter : public DIDescriptor {
517 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
519 DIScope getContext() const { return getFieldAs<DIScope>(1); }
520 StringRef getName() const { return getStringField(2); }
521 DIType getType() const { return getFieldAs<DIType>(3); }
522 StringRef getFilename() const {
523 return getFieldAs<DIFile>(4).getFilename();
525 StringRef getDirectory() const {
526 return getFieldAs<DIFile>(4).getDirectory();
528 unsigned getLineNumber() const { return getUnsignedField(5); }
529 unsigned getColumnNumber() const { return getUnsignedField(6); }
533 /// DITemplateValueParameter - This is a wrapper for template value parameter.
534 class DITemplateValueParameter : public DIDescriptor {
536 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
538 DIScope getContext() const { return getFieldAs<DIScope>(1); }
539 StringRef getName() const { return getStringField(2); }
540 DIType getType() const { return getFieldAs<DIType>(3); }
541 Value *getValue() const;
542 StringRef getFilename() const {
543 return getFieldAs<DIFile>(5).getFilename();
545 StringRef getDirectory() const {
546 return getFieldAs<DIFile>(5).getDirectory();
548 unsigned getLineNumber() const { return getUnsignedField(6); }
549 unsigned getColumnNumber() const { return getUnsignedField(7); }
553 /// DIGlobalVariable - This is a wrapper for a global variable.
554 class DIGlobalVariable : public DIDescriptor {
555 friend class DIDescriptor;
556 void printInternal(raw_ostream &OS) const;
558 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
560 DIScope getContext() const { return getFieldAs<DIScope>(2); }
561 StringRef getName() const { return getStringField(3); }
562 StringRef getDisplayName() const { return getStringField(4); }
563 StringRef getLinkageName() const { return getStringField(5); }
564 StringRef getFilename() const {
565 return getFieldAs<DIFile>(6).getFilename();
567 StringRef getDirectory() const {
568 return getFieldAs<DIFile>(6).getDirectory();
572 unsigned getLineNumber() const { return getUnsignedField(7); }
573 DIType getType() const { return getFieldAs<DIType>(8); }
574 unsigned isLocalToUnit() const { return getUnsignedField(9); }
575 unsigned isDefinition() const { return getUnsignedField(10); }
577 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
578 Constant *getConstant() const { return getConstantField(11); }
579 DIDerivedType getStaticDataMemberDeclaration() const {
580 return getFieldAs<DIDerivedType>(12);
583 /// Verify - Verify that a global variable descriptor is well formed.
587 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
589 class DIVariable : public DIDescriptor {
590 friend class DIDescriptor;
591 void printInternal(raw_ostream &OS) const;
593 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
595 DIScope getContext() const { return getFieldAs<DIScope>(1); }
596 StringRef getName() const { return getStringField(2); }
597 DIFile getFile() const { return getFieldAs<DIFile>(3); }
598 unsigned getLineNumber() const {
599 return (getUnsignedField(4) << 8) >> 8;
601 unsigned getArgNumber() const {
602 unsigned L = getUnsignedField(4);
605 DIType getType() const { return getFieldAs<DIType>(5); }
607 /// isArtificial - Return true if this variable is marked as "artificial".
608 bool isArtificial() const {
609 return (getUnsignedField(6) & FlagArtificial) != 0;
612 bool isObjectPointer() const {
613 return (getUnsignedField(6) & FlagObjectPointer) != 0;
616 /// \brief Return true if this variable is represented as a pointer.
617 bool isIndirect() const {
618 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
621 /// getInlinedAt - If this variable is inlined then return inline location.
622 MDNode *getInlinedAt() const;
624 /// Verify - Verify that a variable descriptor is well formed.
627 /// HasComplexAddr - Return true if the variable has a complex address.
628 bool hasComplexAddress() const {
629 return getNumAddrElements() > 0;
632 unsigned getNumAddrElements() const;
634 uint64_t getAddrElement(unsigned Idx) const {
635 return getUInt64Field(Idx+8);
638 /// isBlockByrefVariable - Return true if the variable was declared as
639 /// a "__block" variable (Apple Blocks).
640 bool isBlockByrefVariable() const {
641 return getType().isBlockByrefStruct();
644 /// isInlinedFnArgument - Return true if this variable provides debugging
645 /// information for an inlined function arguments.
646 bool isInlinedFnArgument(const Function *CurFn);
648 void printExtendedName(raw_ostream &OS) const;
651 /// DILocation - This object holds location information. This object
652 /// is not associated with any DWARF tag.
653 class DILocation : public DIDescriptor {
655 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
657 unsigned getLineNumber() const { return getUnsignedField(0); }
658 unsigned getColumnNumber() const { return getUnsignedField(1); }
659 DIScope getScope() const { return getFieldAs<DIScope>(2); }
660 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
661 StringRef getFilename() const { return getScope().getFilename(); }
662 StringRef getDirectory() const { return getScope().getDirectory(); }
666 class DIObjCProperty : public DIDescriptor {
667 friend class DIDescriptor;
668 void printInternal(raw_ostream &OS) const;
670 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
672 StringRef getObjCPropertyName() const { return getStringField(1); }
673 DIFile getFile() const { return getFieldAs<DIFile>(2); }
674 unsigned getLineNumber() const { return getUnsignedField(3); }
676 StringRef getObjCPropertyGetterName() const {
677 return getStringField(4);
679 StringRef getObjCPropertySetterName() const {
680 return getStringField(5);
682 bool isReadOnlyObjCProperty() const {
683 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
685 bool isReadWriteObjCProperty() const {
686 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
688 bool isAssignObjCProperty() const {
689 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
691 bool isRetainObjCProperty() const {
692 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
694 bool isCopyObjCProperty() const {
695 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
697 bool isNonAtomicObjCProperty() const {
698 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
701 DIType getType() const { return getFieldAs<DIType>(7); }
703 /// Verify - Verify that a derived type descriptor is well formed.
707 /// \brief An imported module (C++ using directive or similar).
708 class DIImportedEntity : public DIDescriptor {
709 friend class DIDescriptor;
710 void printInternal(raw_ostream &OS) const;
712 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
713 DIScope getContext() const { return getFieldAs<DIScope>(1); }
714 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
715 unsigned getLineNumber() const { return getUnsignedField(3); }
716 StringRef getName() const { return getStringField(4); }
720 /// getDISubprogram - Find subprogram that is enclosing this scope.
721 DISubprogram getDISubprogram(const MDNode *Scope);
723 /// getDICompositeType - Find underlying composite type.
724 DICompositeType getDICompositeType(DIType T);
726 /// isSubprogramContext - Return true if Context is either a subprogram
727 /// or another context nested inside a subprogram.
728 bool isSubprogramContext(const MDNode *Context);
730 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
731 /// to hold function specific information.
732 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
734 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
735 /// suitable to hold function specific information.
736 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
738 /// createInlinedVariable - Create a new inlined variable based on current
740 /// @param DV Current Variable.
741 /// @param InlinedScope Location at current variable is inlined.
742 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
743 LLVMContext &VMContext);
745 /// cleanseInlinedVariable - Remove inlined scope from the variable.
746 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
748 /// Construct DITypeIdentifierMap by going through retained types of each CU.
749 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
751 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
752 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
753 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
754 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
755 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
757 class DebugInfoFinder {
759 /// processModule - Process entire module and collect debug info
761 void processModule(const Module &M);
763 /// processDeclare - Process DbgDeclareInst.
764 void processDeclare(const DbgDeclareInst *DDI);
765 /// Process DbgValueInst.
766 void processValue(const DbgValueInst *DVI);
767 /// processLocation - Process DILocation.
768 void processLocation(DILocation Loc);
773 /// processType - Process DIType.
774 void processType(DIType DT);
776 /// processLexicalBlock - Process DILexicalBlock.
777 void processLexicalBlock(DILexicalBlock LB);
779 /// processSubprogram - Process DISubprogram.
780 void processSubprogram(DISubprogram SP);
782 void processScope(DIScope Scope);
784 /// addCompileUnit - Add compile unit into CUs.
785 bool addCompileUnit(DICompileUnit CU);
787 /// addGlobalVariable - Add global variable into GVs.
788 bool addGlobalVariable(DIGlobalVariable DIG);
790 // addSubprogram - Add subprogram into SPs.
791 bool addSubprogram(DISubprogram SP);
793 /// addType - Add type into Tys.
794 bool addType(DIType DT);
796 bool addScope(DIScope Scope);
799 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
800 iterator compile_unit_begin() const { return CUs.begin(); }
801 iterator compile_unit_end() const { return CUs.end(); }
802 iterator subprogram_begin() const { return SPs.begin(); }
803 iterator subprogram_end() const { return SPs.end(); }
804 iterator global_variable_begin() const { return GVs.begin(); }
805 iterator global_variable_end() const { return GVs.end(); }
806 iterator type_begin() const { return TYs.begin(); }
807 iterator type_end() const { return TYs.end(); }
808 iterator scope_begin() const { return Scopes.begin(); }
809 iterator scope_end() const { return Scopes.end(); }
811 unsigned compile_unit_count() const { return CUs.size(); }
812 unsigned global_variable_count() const { return GVs.size(); }
813 unsigned subprogram_count() const { return SPs.size(); }
814 unsigned type_count() const { return TYs.size(); }
815 unsigned scope_count() const { return Scopes.size(); }
818 SmallVector<MDNode *, 8> CUs; // Compile Units
819 SmallVector<MDNode *, 8> SPs; // Subprograms
820 SmallVector<MDNode *, 8> GVs; // Global Variables;
821 SmallVector<MDNode *, 8> TYs; // Types
822 SmallVector<MDNode *, 8> Scopes; // Scopes
823 SmallPtrSet<MDNode *, 64> NodesSeen;
825 } // end namespace llvm