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/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Dwarf.h"
44 class DILexicalBlockFile;
49 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
50 /// This should not be stored in a container, because the underlying MDNode
51 /// may change in certain situations.
56 FlagProtected = 1 << 1,
58 FlagAppleBlock = 1 << 3,
59 FlagBlockByrefStruct = 1 << 4,
61 FlagArtificial = 1 << 6,
62 FlagExplicit = 1 << 7,
63 FlagPrototyped = 1 << 8,
64 FlagObjcClassComplete = 1 << 9,
65 FlagObjectPointer = 1 << 10,
67 FlagStaticMember = 1 << 12,
68 FlagIndirectVariable = 1 << 13
71 const MDNode *DbgNode;
73 StringRef getStringField(unsigned Elt) const;
74 unsigned getUnsignedField(unsigned Elt) const {
75 return (unsigned)getUInt64Field(Elt);
77 uint64_t getUInt64Field(unsigned Elt) const;
78 int64_t getInt64Field(unsigned Elt) const;
79 DIDescriptor getDescriptorField(unsigned Elt) const;
81 template <typename DescTy>
82 DescTy getFieldAs(unsigned Elt) const {
83 return DescTy(getDescriptorField(Elt));
86 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
87 Constant *getConstantField(unsigned Elt) const;
88 Function *getFunctionField(unsigned Elt) const;
89 void replaceFunctionField(unsigned Elt, Function *F);
92 explicit DIDescriptor() : DbgNode(0) {}
93 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
94 explicit DIDescriptor(const DIFile F);
95 explicit DIDescriptor(const DISubprogram F);
96 explicit DIDescriptor(const DILexicalBlockFile F);
97 explicit DIDescriptor(const DILexicalBlock F);
98 explicit DIDescriptor(const DIVariable F);
99 explicit DIDescriptor(const DIType F);
103 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
104 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
106 // An explicit operator bool so that we can do testing of DI values
108 // FIXME: This operator bool isn't actually protecting anything at the
109 // moment due to the conversion operator above making DIDescriptor nodes
110 // implicitly convertable to bool.
111 LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
113 bool operator==(DIDescriptor Other) const {
114 return DbgNode == Other.DbgNode;
116 bool operator!=(DIDescriptor Other) const {
117 return !operator==(Other);
120 unsigned getTag() const {
121 return getUnsignedField(0) & ~LLVMDebugVersionMask;
124 bool isDerivedType() const;
125 bool isCompositeType() const;
126 bool isBasicType() const;
127 bool isVariable() const;
128 bool isSubprogram() const;
129 bool isGlobalVariable() const;
130 bool isScope() const;
132 bool isCompileUnit() const;
133 bool isNameSpace() const;
134 bool isLexicalBlockFile() const;
135 bool isLexicalBlock() const;
136 bool isSubrange() const;
137 bool isEnumerator() const;
139 bool isGlobal() const;
140 bool isUnspecifiedParameter() const;
141 bool isTemplateTypeParameter() const;
142 bool isTemplateValueParameter() const;
143 bool isObjCProperty() const;
144 bool isImportedEntity() const;
146 /// print - print descriptor.
147 void print(raw_ostream &OS) const;
149 /// dump - print descriptor to dbgs() with a newline.
153 /// DISubrange - This is used to represent ranges, for array bounds.
154 class DISubrange : public DIDescriptor {
155 friend class DIDescriptor;
156 void printInternal(raw_ostream &OS) const;
158 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
160 int64_t getLo() const { return getInt64Field(1); }
161 int64_t getCount() const { return getInt64Field(2); }
165 /// DIArray - This descriptor holds an array of descriptors.
166 class DIArray : public DIDescriptor {
168 explicit DIArray(const MDNode *N = 0)
171 unsigned getNumElements() const;
172 DIDescriptor getElement(unsigned Idx) const {
173 return getDescriptorField(Idx);
177 /// DIScope - A base class for various scopes.
178 class DIScope : public DIDescriptor {
180 friend class DIDescriptor;
181 void printInternal(raw_ostream &OS) const;
183 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
185 /// Set the filename by allocating a new string MDNode for
186 /// it and attaching it to the underlying node.
187 void setFilename(StringRef Name, LLVMContext &Context);
188 StringRef getFilename() const;
189 StringRef getDirectory() const;
192 /// DIFile - This is a wrapper for a file.
193 class DIFile : public DIScope {
194 friend class DIDescriptor;
196 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
197 if (DbgNode && !isFile())
200 MDNode *getFileNode() const;
204 /// DICompileUnit - A wrapper for a compile unit.
205 class DICompileUnit : public DIScope {
206 friend class DIDescriptor;
207 void printInternal(raw_ostream &OS) const;
209 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
211 unsigned getLanguage() const { return getUnsignedField(2); }
212 StringRef getProducer() const { return getStringField(3); }
214 bool isOptimized() const { return getUnsignedField(4) != 0; }
215 StringRef getFlags() const { return getStringField(5); }
216 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
218 DIArray getEnumTypes() const;
219 DIArray getRetainedTypes() const;
220 DIArray getSubprograms() const;
221 DIArray getGlobalVariables() const;
222 DIArray getImportedEntities() const;
224 StringRef getSplitDebugFilename() const { return getStringField(12); }
226 /// Verify - Verify that a compile unit is well formed.
230 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
231 /// FIXME: it seems strange that this doesn't have either a reference to the
232 /// type/precision or a file/line pair for location info.
233 class DIEnumerator : public DIDescriptor {
234 friend class DIDescriptor;
235 void printInternal(raw_ostream &OS) const;
237 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
239 StringRef getName() const { return getStringField(1); }
240 int64_t getEnumValue() const { return getInt64Field(2); }
244 /// DIType - This is a wrapper for a type.
245 /// FIXME: Types should be factored much better so that CV qualifiers and
246 /// others do not require a huge and empty descriptor full of zeros.
247 class DIType : public DIScope {
249 friend class DIDescriptor;
250 void printInternal(raw_ostream &OS) const;
251 // This ctor is used when the Tag has already been validated by a derived
253 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
255 /// Verify - Verify that a type descriptor is well formed.
257 explicit DIType(const MDNode *N);
260 DIScope getContext() const { return getFieldAs<DIScope>(2); }
261 StringRef getName() const { return getStringField(3); }
262 unsigned getLineNumber() const { return getUnsignedField(4); }
263 uint64_t getSizeInBits() const { return getUInt64Field(5); }
264 uint64_t getAlignInBits() const { return getUInt64Field(6); }
265 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
266 // carry this is just plain insane.
267 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
268 unsigned getFlags() const { return getUnsignedField(8); }
269 bool isPrivate() const {
270 return (getFlags() & FlagPrivate) != 0;
272 bool isProtected() const {
273 return (getFlags() & FlagProtected) != 0;
275 bool isForwardDecl() const {
276 return (getFlags() & FlagFwdDecl) != 0;
278 // isAppleBlock - Return true if this is the Apple Blocks extension.
279 bool isAppleBlockExtension() const {
280 return (getFlags() & FlagAppleBlock) != 0;
282 bool isBlockByrefStruct() const {
283 return (getFlags() & FlagBlockByrefStruct) != 0;
285 bool isVirtual() const {
286 return (getFlags() & FlagVirtual) != 0;
288 bool isArtificial() const {
289 return (getFlags() & FlagArtificial) != 0;
291 bool isObjectPointer() const {
292 return (getFlags() & FlagObjectPointer) != 0;
294 bool isObjcClassComplete() const {
295 return (getFlags() & FlagObjcClassComplete) != 0;
297 bool isVector() const {
298 return (getFlags() & FlagVector) != 0;
300 bool isStaticMember() const {
301 return (getFlags() & FlagStaticMember) != 0;
303 bool isValid() const {
304 return DbgNode && isType();
307 /// isUnsignedDIType - Return true if type encoding is unsigned.
308 bool isUnsignedDIType();
310 /// replaceAllUsesWith - Replace all uses of debug info referenced by
312 void replaceAllUsesWith(DIDescriptor &D);
313 void replaceAllUsesWith(MDNode *D);
316 /// DIBasicType - A basic type, like 'int' or 'float'.
317 class DIBasicType : public DIType {
319 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
321 unsigned getEncoding() const { return getUnsignedField(9); }
323 /// Verify - Verify that a basic type descriptor is well formed.
327 /// DIDerivedType - A simple derived type, like a const qualified type,
328 /// a typedef, a pointer or reference, et cetera. Or, a data member of
329 /// a class/struct/union.
330 class DIDerivedType : public DIType {
331 friend class DIDescriptor;
332 void printInternal(raw_ostream &OS) const;
334 explicit DIDerivedType(const MDNode *N, bool, bool)
335 : DIType(N, true, true) {}
337 explicit DIDerivedType(const MDNode *N = 0)
338 : DIType(N, true, true) {}
340 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
342 /// getOriginalTypeSize - If this type is derived from a base type then
343 /// return base type size.
344 uint64_t getOriginalTypeSize() const;
346 /// getObjCProperty - Return property node, if this ivar is
347 /// associated with one.
348 MDNode *getObjCProperty() const;
350 DIType getClassType() const {
351 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
352 return getFieldAs<DIType>(10);
355 Constant *getConstant() const {
356 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
357 return getConstantField(10);
360 /// Verify - Verify that a derived type descriptor is well formed.
364 /// DICompositeType - This descriptor holds a type that can refer to multiple
365 /// other types, like a function or struct.
366 /// DICompositeType is derived from DIDerivedType because some
367 /// composite types (such as enums) can be derived from basic types
368 // FIXME: Make this derive from DIType directly & just store the
369 // base type in a single DIType field.
370 class DICompositeType : public DIDerivedType {
371 friend class DIDescriptor;
372 void printInternal(raw_ostream &OS) const;
374 explicit DICompositeType(const MDNode *N = 0)
375 : DIDerivedType(N, true, true) {
376 if (N && !isCompositeType())
380 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
381 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
382 unsigned getRunTimeLang() const { return getUnsignedField(11); }
383 DICompositeType getContainingType() const {
384 return getFieldAs<DICompositeType>(12);
386 void setContainingType(DICompositeType ContainingType);
387 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
389 /// Verify - Verify that a composite type descriptor is well formed.
393 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
394 class DITemplateTypeParameter : public DIDescriptor {
396 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
398 DIScope getContext() const { return getFieldAs<DIScope>(1); }
399 StringRef getName() const { return getStringField(2); }
400 DIType getType() const { return getFieldAs<DIType>(3); }
401 StringRef getFilename() const {
402 return getFieldAs<DIFile>(4).getFilename();
404 StringRef getDirectory() const {
405 return getFieldAs<DIFile>(4).getDirectory();
407 unsigned getLineNumber() const { return getUnsignedField(5); }
408 unsigned getColumnNumber() const { return getUnsignedField(6); }
412 /// DITemplateValueParameter - This is a wrapper for template value parameter.
413 class DITemplateValueParameter : public DIDescriptor {
415 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
417 DIScope getContext() const { return getFieldAs<DIScope>(1); }
418 StringRef getName() const { return getStringField(2); }
419 DIType getType() const { return getFieldAs<DIType>(3); }
420 Value *getValue() const;
421 StringRef getFilename() const {
422 return getFieldAs<DIFile>(5).getFilename();
424 StringRef getDirectory() const {
425 return getFieldAs<DIFile>(5).getDirectory();
427 unsigned getLineNumber() const { return getUnsignedField(6); }
428 unsigned getColumnNumber() const { return getUnsignedField(7); }
432 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
433 class DISubprogram : public DIScope {
434 friend class DIDescriptor;
435 void printInternal(raw_ostream &OS) const;
437 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
439 DIScope getContext() const { return getFieldAs<DIScope>(2); }
440 StringRef getName() const { return getStringField(3); }
441 StringRef getDisplayName() const { return getStringField(4); }
442 StringRef getLinkageName() const { return getStringField(5); }
443 unsigned getLineNumber() const { return getUnsignedField(6); }
444 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
446 /// isLocalToUnit - Return true if this subprogram is local to the current
447 /// compile unit, like 'static' in C.
448 unsigned isLocalToUnit() const { return getUnsignedField(8); }
449 unsigned isDefinition() const { return getUnsignedField(9); }
451 unsigned getVirtuality() const { return getUnsignedField(10); }
452 unsigned getVirtualIndex() const { return getUnsignedField(11); }
454 DICompositeType getContainingType() const {
455 return getFieldAs<DICompositeType>(12);
458 unsigned getFlags() const {
459 return getUnsignedField(13);
462 unsigned isArtificial() const {
463 return (getUnsignedField(13) & FlagArtificial) != 0;
465 /// isPrivate - Return true if this subprogram has "private"
466 /// access specifier.
467 bool isPrivate() const {
468 return (getUnsignedField(13) & FlagPrivate) != 0;
470 /// isProtected - Return true if this subprogram has "protected"
471 /// access specifier.
472 bool isProtected() const {
473 return (getUnsignedField(13) & FlagProtected) != 0;
475 /// isExplicit - Return true if this subprogram is marked as explicit.
476 bool isExplicit() const {
477 return (getUnsignedField(13) & FlagExplicit) != 0;
479 /// isPrototyped - Return true if this subprogram is prototyped.
480 bool isPrototyped() const {
481 return (getUnsignedField(13) & FlagPrototyped) != 0;
484 unsigned isOptimized() const;
486 /// Verify - Verify that a subprogram descriptor is well formed.
489 /// describes - Return true if this subprogram provides debugging
490 /// information for the function F.
491 bool describes(const Function *F);
493 Function *getFunction() const { return getFunctionField(15); }
494 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
495 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
496 DISubprogram getFunctionDeclaration() const {
497 return getFieldAs<DISubprogram>(17);
499 MDNode *getVariablesNodes() const;
500 DIArray getVariables() const;
502 /// getScopeLineNumber - Get the beginning of the scope of the
503 /// function, not necessarily where the name of the program
505 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
508 /// DIGlobalVariable - This is a wrapper for a global variable.
509 class DIGlobalVariable : public DIDescriptor {
510 friend class DIDescriptor;
511 void printInternal(raw_ostream &OS) const;
513 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
515 DIScope getContext() const { return getFieldAs<DIScope>(2); }
516 StringRef getName() const { return getStringField(3); }
517 StringRef getDisplayName() const { return getStringField(4); }
518 StringRef getLinkageName() const { return getStringField(5); }
519 StringRef getFilename() const {
520 return getFieldAs<DIFile>(6).getFilename();
522 StringRef getDirectory() const {
523 return getFieldAs<DIFile>(6).getDirectory();
527 unsigned getLineNumber() const { return getUnsignedField(7); }
528 DIType getType() const { return getFieldAs<DIType>(8); }
529 unsigned isLocalToUnit() const { return getUnsignedField(9); }
530 unsigned isDefinition() const { return getUnsignedField(10); }
532 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
533 Constant *getConstant() const { return getConstantField(11); }
534 DIDerivedType getStaticDataMemberDeclaration() const {
535 return getFieldAs<DIDerivedType>(12);
538 /// Verify - Verify that a global variable descriptor is well formed.
542 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
544 class DIVariable : public DIDescriptor {
545 friend class DIDescriptor;
546 void printInternal(raw_ostream &OS) const;
548 explicit DIVariable(const MDNode *N = 0)
551 DIScope getContext() const { return getFieldAs<DIScope>(1); }
552 StringRef getName() const { return getStringField(2); }
553 DIFile getFile() const { return getFieldAs<DIFile>(3); }
554 unsigned getLineNumber() const {
555 return (getUnsignedField(4) << 8) >> 8;
557 unsigned getArgNumber() const {
558 unsigned L = getUnsignedField(4);
561 DIType getType() const { return getFieldAs<DIType>(5); }
563 /// isArtificial - Return true if this variable is marked as "artificial".
564 bool isArtificial() const {
565 return (getUnsignedField(6) & FlagArtificial) != 0;
568 bool isObjectPointer() const {
569 return (getUnsignedField(6) & FlagObjectPointer) != 0;
572 /// \brief Return true if this variable is represented as a pointer.
573 bool isIndirect() const {
574 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
577 /// getInlinedAt - If this variable is inlined then return inline location.
578 MDNode *getInlinedAt() const;
580 /// Verify - Verify that a variable descriptor is well formed.
583 /// HasComplexAddr - Return true if the variable has a complex address.
584 bool hasComplexAddress() const {
585 return getNumAddrElements() > 0;
588 unsigned getNumAddrElements() const;
590 uint64_t getAddrElement(unsigned Idx) const {
591 return getUInt64Field(Idx+8);
594 /// isBlockByrefVariable - Return true if the variable was declared as
595 /// a "__block" variable (Apple Blocks).
596 bool isBlockByrefVariable() const {
597 return getType().isBlockByrefStruct();
600 /// isInlinedFnArgument - Return true if this variable provides debugging
601 /// information for an inlined function arguments.
602 bool isInlinedFnArgument(const Function *CurFn);
604 void printExtendedName(raw_ostream &OS) const;
607 /// DILexicalBlock - This is a wrapper for a lexical block.
608 class DILexicalBlock : public DIScope {
610 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
611 DIScope getContext() const { return getFieldAs<DIScope>(2); }
612 unsigned getLineNumber() const { return getUnsignedField(3); }
613 unsigned getColumnNumber() const { return getUnsignedField(4); }
617 /// DILexicalBlockFile - This is a wrapper for a lexical block with
618 /// a filename change.
619 class DILexicalBlockFile : public DIScope {
621 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
622 DIScope getContext() const { if (getScope().isSubprogram()) return getScope(); return getScope().getContext(); }
623 unsigned getLineNumber() const { return getScope().getLineNumber(); }
624 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
625 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
629 /// DINameSpace - A wrapper for a C++ style name space.
630 class DINameSpace : public DIScope {
631 friend class DIDescriptor;
632 void printInternal(raw_ostream &OS) const;
634 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
635 DIScope getContext() const { return getFieldAs<DIScope>(2); }
636 StringRef getName() const { return getStringField(3); }
637 unsigned getLineNumber() const { return getUnsignedField(4); }
641 /// DILocation - This object holds location information. This object
642 /// is not associated with any DWARF tag.
643 class DILocation : public DIDescriptor {
645 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
647 unsigned getLineNumber() const { return getUnsignedField(0); }
648 unsigned getColumnNumber() const { return getUnsignedField(1); }
649 DIScope getScope() const { return getFieldAs<DIScope>(2); }
650 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
651 StringRef getFilename() const { return getScope().getFilename(); }
652 StringRef getDirectory() const { return getScope().getDirectory(); }
656 class DIObjCProperty : public DIDescriptor {
657 friend class DIDescriptor;
658 void printInternal(raw_ostream &OS) const;
660 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
662 StringRef getObjCPropertyName() const { return getStringField(1); }
663 DIFile getFile() const { return getFieldAs<DIFile>(2); }
664 unsigned getLineNumber() const { return getUnsignedField(3); }
666 StringRef getObjCPropertyGetterName() const {
667 return getStringField(4);
669 StringRef getObjCPropertySetterName() const {
670 return getStringField(5);
672 bool isReadOnlyObjCProperty() const {
673 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
675 bool isReadWriteObjCProperty() const {
676 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
678 bool isAssignObjCProperty() const {
679 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
681 bool isRetainObjCProperty() const {
682 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
684 bool isCopyObjCProperty() const {
685 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
687 bool isNonAtomicObjCProperty() const {
688 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
691 DIType getType() const { return getFieldAs<DIType>(7); }
693 /// Verify - Verify that a derived type descriptor is well formed.
697 /// \brief An imported module (C++ using directive or similar).
698 class DIImportedEntity : public DIDescriptor {
699 friend class DIDescriptor;
700 void printInternal(raw_ostream &OS) const;
702 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
703 DIScope getContext() const { return getFieldAs<DIScope>(1); }
704 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
705 unsigned getLineNumber() const { return getUnsignedField(3); }
706 StringRef getName() const { return getStringField(4); }
710 /// getDISubprogram - Find subprogram that is enclosing this scope.
711 DISubprogram getDISubprogram(const MDNode *Scope);
713 /// getDICompositeType - Find underlying composite type.
714 DICompositeType getDICompositeType(DIType T);
716 /// isSubprogramContext - Return true if Context is either a subprogram
717 /// or another context nested inside a subprogram.
718 bool isSubprogramContext(const MDNode *Context);
720 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
721 /// to hold function specific information.
722 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
724 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
725 /// suitable to hold function specific information.
726 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
728 /// createInlinedVariable - Create a new inlined variable based on current
730 /// @param DV Current Variable.
731 /// @param InlinedScope Location at current variable is inlined.
732 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
733 LLVMContext &VMContext);
735 /// cleanseInlinedVariable - Remove inlined scope from the variable.
736 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
738 /// DebugInfoFinder tries to list all debug info MDNodes in a module. To
739 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
740 /// processDeclare and processValue. processModule will go through
741 /// all DICompileUnits and list debug info MDNodes used by the CUs.
742 class DebugInfoFinder {
744 /// processModule - Process entire module and collect debug info
746 void processModule(const Module &M);
748 /// processDeclare - Process DbgDeclareInst.
749 void processDeclare(const DbgDeclareInst *DDI);
750 /// Process DbgValueInst.
751 void processValue(const DbgValueInst *DVI);
756 /// processType - Process DIType.
757 void processType(DIType DT);
759 /// processLexicalBlock - Process DILexicalBlock.
760 void processLexicalBlock(DILexicalBlock LB);
762 /// processSubprogram - Process DISubprogram.
763 void processSubprogram(DISubprogram SP);
765 /// processLocation - Process DILocation.
766 void processLocation(DILocation Loc);
768 void processScope(DIScope Scope);
770 /// addCompileUnit - Add compile unit into CUs.
771 bool addCompileUnit(DICompileUnit CU);
773 /// addGlobalVariable - Add global variable into GVs.
774 bool addGlobalVariable(DIGlobalVariable DIG);
776 // addSubprogram - Add subprogram into SPs.
777 bool addSubprogram(DISubprogram SP);
779 /// addType - Add type into Tys.
780 bool addType(DIType DT);
782 bool addScope(DIScope Scope);
785 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
786 iterator compile_unit_begin() const { return CUs.begin(); }
787 iterator compile_unit_end() const { return CUs.end(); }
788 iterator subprogram_begin() const { return SPs.begin(); }
789 iterator subprogram_end() const { return SPs.end(); }
790 iterator global_variable_begin() const { return GVs.begin(); }
791 iterator global_variable_end() const { return GVs.end(); }
792 iterator type_begin() const { return TYs.begin(); }
793 iterator type_end() const { return TYs.end(); }
794 iterator scope_begin() const { return Scopes.begin(); }
795 iterator scope_end() const { return Scopes.end(); }
797 unsigned compile_unit_count() const { return CUs.size(); }
798 unsigned global_variable_count() const { return GVs.size(); }
799 unsigned subprogram_count() const { return SPs.size(); }
800 unsigned type_count() const { return TYs.size(); }
801 unsigned scope_count() const { return Scopes.size(); }
804 SmallVector<MDNode *, 8> CUs; // Compile Units
805 SmallVector<MDNode *, 8> SPs; // Subprograms
806 SmallVector<MDNode *, 8> GVs; // Global Variables;
807 SmallVector<MDNode *, 8> TYs; // Types
808 SmallVector<MDNode *, 8> Scopes; // Scopes
809 SmallPtrSet<MDNode *, 64> NodesSeen;
811 } // end namespace llvm