]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - include/llvm/DebugInfo.h
Debug Info: Use DIScopeRef for DIType::getContext.
[opencl/llvm.git] / include / llvm / DebugInfo.h
1 //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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
13 // DWARF information.
14 //
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"
26 namespace llvm {
27   class BasicBlock;
28   class Constant;
29   class Function;
30   class GlobalVariable;
31   class Module;
32   class Type;
33   class Value;
34   class DbgDeclareInst;
35   class DbgValueInst;
36   class Instruction;
37   class MDNode;
38   class MDString;
39   class NamedMDNode;
40   class LLVMContext;
41   class raw_ostream;
43   class DIFile;
44   class DISubprogram;
45   class DILexicalBlock;
46   class DILexicalBlockFile;
47   class DIVariable;
48   class DIType;
49   class DIScopeRef;
50   class DIObjCProperty;
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.
58   class DIDescriptor {
59     // Befriends DIScopeRef so DIScopeRef can befriend the protected member
60     // function: getFieldAs<DIScopeRef>.
61     friend class DIScopeRef;
62   public:
63     enum {
64       FlagPrivate            = 1 << 0,
65       FlagProtected          = 1 << 1,
66       FlagFwdDecl            = 1 << 2,
67       FlagAppleBlock         = 1 << 3,
68       FlagBlockByrefStruct   = 1 << 4,
69       FlagVirtual            = 1 << 5,
70       FlagArtificial         = 1 << 6,
71       FlagExplicit           = 1 << 7,
72       FlagPrototyped         = 1 << 8,
73       FlagObjcClassComplete  = 1 << 9,
74       FlagObjectPointer      = 1 << 10,
75       FlagVector             = 1 << 11,
76       FlagStaticMember       = 1 << 12,
77       FlagIndirectVariable   = 1 << 13
78     };
79   protected:
80     const MDNode *DbgNode;
82     StringRef getStringField(unsigned Elt) const;
83     unsigned getUnsignedField(unsigned Elt) const {
84       return (unsigned)getUInt64Field(Elt);
85     }
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));
93     }
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);
100   public:
101     explicit DIDescriptor(const MDNode *N = 0) : DbgNode(N) {}
103     bool Verify() const;
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
109     // easily.
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;
117     }
118     bool operator!=(DIDescriptor Other) const {
119       return !operator==(Other);
120     }
122     uint16_t getTag() const {
123       return getUnsignedField(0) & ~LLVMDebugVersionMask;
124     }
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;
133     bool isFile() 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;
140     bool isType() 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.
151     void dump() const;
152   };
154   /// npecialize getFieldAs to handle fields that are references to DIScopes.
155   template <>
156   DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(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;
162   public:
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); }
167     bool Verify() const;
168   };
170   /// DIArray - This descriptor holds an array of descriptors.
171   class DIArray : public DIDescriptor {
172   public:
173     explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
175     unsigned getNumElements() const;
176     DIDescriptor getElement(unsigned Idx) const {
177       return getDescriptorField(Idx);
178     }
179   };
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;
187   public:
188     explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
190     StringRef getName() const        { return getStringField(1); }
191     int64_t getEnumValue() const      { return getInt64Field(2); }
192     bool Verify() const;
193   };
195   /// DIScope - A base class for various scopes.
196   class DIScope : public DIDescriptor {
197   protected:
198     friend class DIDescriptor;
199     void printInternal(raw_ostream &OS) const;
200   public:
201     explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
203     StringRef getFilename() const;
204     StringRef getDirectory() const;
206     /// Generate a reference to this DIScope. Uses the type identifier instead
207     /// of the actual MDNode if possible, to help type uniquing.
208     Value *generateRef();
209   };
211   /// Represents reference to a DIScope, abstracts over direct and
212   /// identifier-based metadata scope references.
213   class DIScopeRef {
214     template <typename DescTy>
215     friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
217     /// Val can be either a MDNode or a MDString, in the latter,
218     /// MDString specifies the type identifier.
219     const Value *Val;
220     explicit DIScopeRef(const Value *V);
221   public:
222     DIScope resolve(const DITypeIdentifierMap &Map) const;
223     operator Value *() const { return const_cast<Value*>(Val); }
224   };
226   /// DIType - This is a wrapper for a type.
227   /// FIXME: Types should be factored much better so that CV qualifiers and
228   /// others do not require a huge and empty descriptor full of zeros.
229   class DIType : public DIScope {
230   protected:
231     friend class DIDescriptor;
232     void printInternal(raw_ostream &OS) const;
234   public:
235     DIType(const MDNode *N = 0) : DIScope(N) {}
237     /// Verify - Verify that a type descriptor is well formed.
238     bool Verify() const;
240     DIScopeRef getContext() const       { return getFieldAs<DIScopeRef>(2); }
241     StringRef getName() const           { return getStringField(3);     }
242     unsigned getLineNumber() const      { return getUnsignedField(4); }
243     uint64_t getSizeInBits() const      { return getUInt64Field(5); }
244     uint64_t getAlignInBits() const     { return getUInt64Field(6); }
245     // FIXME: Offset is only used for DW_TAG_member nodes.  Making every type
246     // carry this is just plain insane.
247     uint64_t getOffsetInBits() const    { return getUInt64Field(7); }
248     unsigned getFlags() const           { return getUnsignedField(8); }
249     bool isPrivate() const {
250       return (getFlags() & FlagPrivate) != 0;
251     }
252     bool isProtected() const {
253       return (getFlags() & FlagProtected) != 0;
254     }
255     bool isForwardDecl() const {
256       return (getFlags() & FlagFwdDecl) != 0;
257     }
258     // isAppleBlock - Return true if this is the Apple Blocks extension.
259     bool isAppleBlockExtension() const {
260       return (getFlags() & FlagAppleBlock) != 0;
261     }
262     bool isBlockByrefStruct() const {
263       return (getFlags() & FlagBlockByrefStruct) != 0;
264     }
265     bool isVirtual() const {
266       return (getFlags() & FlagVirtual) != 0;
267     }
268     bool isArtificial() const {
269       return (getFlags() & FlagArtificial) != 0;
270     }
271     bool isObjectPointer() const {
272       return (getFlags() & FlagObjectPointer) != 0;
273     }
274     bool isObjcClassComplete() const {
275       return (getFlags() & FlagObjcClassComplete) != 0;
276     }
277     bool isVector() const {
278       return (getFlags() & FlagVector) != 0;
279     }
280     bool isStaticMember() const {
281       return (getFlags() & FlagStaticMember) != 0;
282     }
283     bool isValid() const {
284       return DbgNode && isType();
285     }
287     /// isUnsignedDIType - Return true if type encoding is unsigned.
288     bool isUnsignedDIType();
290     /// replaceAllUsesWith - Replace all uses of debug info referenced by
291     /// this descriptor.
292     void replaceAllUsesWith(DIDescriptor &D);
293     void replaceAllUsesWith(MDNode *D);
294   };
296   /// DIBasicType - A basic type, like 'int' or 'float'.
297   class DIBasicType : public DIType {
298   public:
299     explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
301     unsigned getEncoding() const { return getUnsignedField(9); }
303     /// Verify - Verify that a basic type descriptor is well formed.
304     bool Verify() const;
305   };
307   /// DIDerivedType - A simple derived type, like a const qualified type,
308   /// a typedef, a pointer or reference, et cetera.  Or, a data member of
309   /// a class/struct/union.
310   class DIDerivedType : public DIType {
311     friend class DIDescriptor;
312     void printInternal(raw_ostream &OS) const;
314   public:
315     explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
317     DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
319     /// getOriginalTypeSize - If this type is derived from a base type then
320     /// return base type size.
321     uint64_t getOriginalTypeSize() const;
323     /// getObjCProperty - Return property node, if this ivar is
324     /// associated with one.
325     MDNode *getObjCProperty() const;
327     DIScopeRef getClassType() const {
328       assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
329       return getFieldAs<DIScopeRef>(10);
330     }
332     Constant *getConstant() const {
333       assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
334       return getConstantField(10);
335     }
337     /// Verify - Verify that a derived type descriptor is well formed.
338     bool Verify() const;
339   };
341   /// DICompositeType - This descriptor holds a type that can refer to multiple
342   /// other types, like a function or struct.
343   /// DICompositeType is derived from DIDerivedType because some
344   /// composite types (such as enums) can be derived from basic types
345   // FIXME: Make this derive from DIType directly & just store the
346   // base type in a single DIType field.
347   class DICompositeType : public DIDerivedType {
348     friend class DIDescriptor;
349     void printInternal(raw_ostream &OS) const;
350   public:
351     explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
353     DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
354     void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
355     void addMember(DIDescriptor D);
356     unsigned getRunTimeLang() const { return getUnsignedField(11); }
357     DIScopeRef getContainingType() const {
358       return getFieldAs<DIScopeRef>(12);
359     }
360     void setContainingType(DICompositeType ContainingType);
361     DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
362     MDString *getIdentifier() const;
364     /// Verify - Verify that a composite type descriptor is well formed.
365     bool Verify() const;
366   };
368   /// DIFile - This is a wrapper for a file.
369   class DIFile : public DIScope {
370     friend class DIDescriptor;
371   public:
372     explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
373     MDNode *getFileNode() const;
374     bool Verify() const;
375   };
377   /// DICompileUnit - A wrapper for a compile unit.
378   class DICompileUnit : public DIScope {
379     friend class DIDescriptor;
380     void printInternal(raw_ostream &OS) const;
381   public:
382     explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
384     unsigned getLanguage() const { return getUnsignedField(2); }
385     StringRef getProducer() const { return getStringField(3); }
387     bool isOptimized() const { return getUnsignedField(4) != 0; }
388     StringRef getFlags() const { return getStringField(5); }
389     unsigned getRunTimeVersion() const { return getUnsignedField(6); }
391     DIArray getEnumTypes() const;
392     DIArray getRetainedTypes() const;
393     DIArray getSubprograms() const;
394     DIArray getGlobalVariables() const;
395     DIArray getImportedEntities() const;
397     StringRef getSplitDebugFilename() const { return getStringField(12); }
399     /// Verify - Verify that a compile unit is well formed.
400     bool Verify() const;
401   };
403   /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
404   class DISubprogram : public DIScope {
405     friend class DIDescriptor;
406     void printInternal(raw_ostream &OS) const;
407   public:
408     explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
410     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
411     StringRef getName() const         { return getStringField(3); }
412     StringRef getDisplayName() const  { return getStringField(4); }
413     StringRef getLinkageName() const  { return getStringField(5); }
414     unsigned getLineNumber() const      { return getUnsignedField(6); }
415     DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
417     /// isLocalToUnit - Return true if this subprogram is local to the current
418     /// compile unit, like 'static' in C.
419     unsigned isLocalToUnit() const     { return getUnsignedField(8); }
420     unsigned isDefinition() const      { return getUnsignedField(9); }
422     unsigned getVirtuality() const { return getUnsignedField(10); }
423     unsigned getVirtualIndex() const { return getUnsignedField(11); }
425     DIScopeRef getContainingType() const {
426       return getFieldAs<DIScopeRef>(12);
427     }
429     unsigned getFlags() const {
430       return getUnsignedField(13);
431     }
433     unsigned isArtificial() const    {
434       return (getUnsignedField(13) & FlagArtificial) != 0;
435     }
436     /// isPrivate - Return true if this subprogram has "private"
437     /// access specifier.
438     bool isPrivate() const    {
439       return (getUnsignedField(13) & FlagPrivate) != 0;
440     }
441     /// isProtected - Return true if this subprogram has "protected"
442     /// access specifier.
443     bool isProtected() const    {
444       return (getUnsignedField(13) & FlagProtected) != 0;
445     }
446     /// isExplicit - Return true if this subprogram is marked as explicit.
447     bool isExplicit() const    {
448       return (getUnsignedField(13) & FlagExplicit) != 0;
449     }
450     /// isPrototyped - Return true if this subprogram is prototyped.
451     bool isPrototyped() const    {
452       return (getUnsignedField(13) & FlagPrototyped) != 0;
453     }
455     unsigned isOptimized() const;
457     /// Verify - Verify that a subprogram descriptor is well formed.
458     bool Verify() const;
460     /// describes - Return true if this subprogram provides debugging
461     /// information for the function F.
462     bool describes(const Function *F);
464     Function *getFunction() const { return getFunctionField(15); }
465     void replaceFunction(Function *F) { replaceFunctionField(15, F); }
466     DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
467     DISubprogram getFunctionDeclaration() const {
468       return getFieldAs<DISubprogram>(17);
469     }
470     MDNode *getVariablesNodes() const;
471     DIArray getVariables() const;
473     /// getScopeLineNumber - Get the beginning of the scope of the
474     /// function, not necessarily where the name of the program
475     /// starts.
476     unsigned getScopeLineNumber() const { return getUnsignedField(19); }
477   };
479   /// DILexicalBlock - This is a wrapper for a lexical block.
480   class DILexicalBlock : public DIScope {
481   public:
482     explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
483     DIScope getContext() const       { return getFieldAs<DIScope>(2);      }
484     unsigned getLineNumber() const   { return getUnsignedField(3);         }
485     unsigned getColumnNumber() const { return getUnsignedField(4);         }
486     bool Verify() const;
487   };
489   /// DILexicalBlockFile - This is a wrapper for a lexical block with
490   /// a filename change.
491   class DILexicalBlockFile : public DIScope {
492   public:
493     explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
494     DIScope getContext() const {
495       if (getScope().isSubprogram())
496         return getScope();
497       return getScope().getContext();
498     }
499     unsigned getLineNumber() const { return getScope().getLineNumber(); }
500     unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
501     DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
502     bool Verify() const;
503   };
505   /// DINameSpace - A wrapper for a C++ style name space.
506   class DINameSpace : public DIScope {
507     friend class DIDescriptor;
508     void printInternal(raw_ostream &OS) const;
509   public:
510     explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
511     DIScope getContext() const     { return getFieldAs<DIScope>(2);      }
512     StringRef getName() const      { return getStringField(3);           }
513     unsigned getLineNumber() const { return getUnsignedField(4);         }
514     bool Verify() const;
515   };
517   /// DITemplateTypeParameter - This is a wrapper for template type parameter.
518   class DITemplateTypeParameter : public DIDescriptor {
519   public:
520     explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
522     DIScope getContext() const       { return getFieldAs<DIScope>(1); }
523     StringRef getName() const        { return getStringField(2); }
524     DIType getType() const           { return getFieldAs<DIType>(3); }
525     StringRef getFilename() const    {
526       return getFieldAs<DIFile>(4).getFilename();
527     }
528     StringRef getDirectory() const   {
529       return getFieldAs<DIFile>(4).getDirectory();
530     }
531     unsigned getLineNumber() const   { return getUnsignedField(5); }
532     unsigned getColumnNumber() const { return getUnsignedField(6); }
533     bool Verify() const;
534   };
536   /// DITemplateValueParameter - This is a wrapper for template value parameter.
537   class DITemplateValueParameter : public DIDescriptor {
538   public:
539     explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
541     DIScope getContext() const       { return getFieldAs<DIScope>(1); }
542     StringRef getName() const        { return getStringField(2); }
543     DIType getType() const           { return getFieldAs<DIType>(3); }
544     Value *getValue() const;
545     StringRef getFilename() const    {
546       return getFieldAs<DIFile>(5).getFilename();
547     }
548     StringRef getDirectory() const   {
549       return getFieldAs<DIFile>(5).getDirectory();
550     }
551     unsigned getLineNumber() const   { return getUnsignedField(6); }
552     unsigned getColumnNumber() const { return getUnsignedField(7); }
553     bool Verify() const;
554   };
556   /// DIGlobalVariable - This is a wrapper for a global variable.
557   class DIGlobalVariable : public DIDescriptor {
558     friend class DIDescriptor;
559     void printInternal(raw_ostream &OS) const;
560   public:
561     explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
563     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
564     StringRef getName() const         { return getStringField(3); }
565     StringRef getDisplayName() const  { return getStringField(4); }
566     StringRef getLinkageName() const  { return getStringField(5); }
567     StringRef getFilename() const {
568       return getFieldAs<DIFile>(6).getFilename();
569     }
570     StringRef getDirectory() const {
571       return getFieldAs<DIFile>(6).getDirectory();
573     }
575     unsigned getLineNumber() const      { return getUnsignedField(7); }
576     DIType getType() const              { return getFieldAs<DIType>(8); }
577     unsigned isLocalToUnit() const      { return getUnsignedField(9); }
578     unsigned isDefinition() const       { return getUnsignedField(10); }
580     GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
581     Constant *getConstant() const   { return getConstantField(11); }
582     DIDerivedType getStaticDataMemberDeclaration() const {
583       return getFieldAs<DIDerivedType>(12);
584     }
586     /// Verify - Verify that a global variable descriptor is well formed.
587     bool Verify() const;
588   };
590   /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
591   /// global etc).
592   class DIVariable : public DIDescriptor {
593     friend class DIDescriptor;
594     void printInternal(raw_ostream &OS) const;
595   public:
596     explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
598     DIScope getContext() const          { return getFieldAs<DIScope>(1); }
599     StringRef getName() const           { return getStringField(2);     }
600     DIFile getFile() const              { return getFieldAs<DIFile>(3); }
601     unsigned getLineNumber() const      {
602       return (getUnsignedField(4) << 8) >> 8;
603     }
604     unsigned getArgNumber() const       {
605       unsigned L = getUnsignedField(4);
606       return L >> 24;
607     }
608     DIType getType() const              { return getFieldAs<DIType>(5); }
610     /// isArtificial - Return true if this variable is marked as "artificial".
611     bool isArtificial() const    {
612       return (getUnsignedField(6) & FlagArtificial) != 0;
613     }
615     bool isObjectPointer() const {
616       return (getUnsignedField(6) & FlagObjectPointer) != 0;
617     }
619     /// \brief Return true if this variable is represented as a pointer.
620     bool isIndirect() const {
621       return (getUnsignedField(6) & FlagIndirectVariable) != 0;
622     }
624     /// getInlinedAt - If this variable is inlined then return inline location.
625     MDNode *getInlinedAt() const;
627     /// Verify - Verify that a variable descriptor is well formed.
628     bool Verify() const;
630     /// HasComplexAddr - Return true if the variable has a complex address.
631     bool hasComplexAddress() const {
632       return getNumAddrElements() > 0;
633     }
635     unsigned getNumAddrElements() const;
637     uint64_t getAddrElement(unsigned Idx) const {
638       return getUInt64Field(Idx+8);
639     }
641     /// isBlockByrefVariable - Return true if the variable was declared as
642     /// a "__block" variable (Apple Blocks).
643     bool isBlockByrefVariable() const {
644       return getType().isBlockByrefStruct();
645     }
647     /// isInlinedFnArgument - Return true if this variable provides debugging
648     /// information for an inlined function arguments.
649     bool isInlinedFnArgument(const Function *CurFn);
651     void printExtendedName(raw_ostream &OS) const;
652   };
654   /// DILocation - This object holds location information. This object
655   /// is not associated with any DWARF tag.
656   class DILocation : public DIDescriptor {
657   public:
658     explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
660     unsigned getLineNumber() const     { return getUnsignedField(0); }
661     unsigned getColumnNumber() const   { return getUnsignedField(1); }
662     DIScope  getScope() const          { return getFieldAs<DIScope>(2); }
663     DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
664     StringRef getFilename() const    { return getScope().getFilename(); }
665     StringRef getDirectory() const   { return getScope().getDirectory(); }
666     bool Verify() const;
667   };
669   class DIObjCProperty : public DIDescriptor {
670     friend class DIDescriptor;
671     void printInternal(raw_ostream &OS) const;
672   public:
673     explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
675     StringRef getObjCPropertyName() const { return getStringField(1); }
676     DIFile getFile() const { return getFieldAs<DIFile>(2); }
677     unsigned getLineNumber() const { return getUnsignedField(3); }
679     StringRef getObjCPropertyGetterName() const {
680       return getStringField(4);
681     }
682     StringRef getObjCPropertySetterName() const {
683       return getStringField(5);
684     }
685     bool isReadOnlyObjCProperty() const {
686       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
687     }
688     bool isReadWriteObjCProperty() const {
689       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
690     }
691     bool isAssignObjCProperty() const {
692       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
693     }
694     bool isRetainObjCProperty() const {
695       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
696     }
697     bool isCopyObjCProperty() const {
698       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
699     }
700     bool isNonAtomicObjCProperty() const {
701       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
702     }
704     DIType getType() const { return getFieldAs<DIType>(7); }
706     /// Verify - Verify that a derived type descriptor is well formed.
707     bool Verify() const;
708   };
710   /// \brief An imported module (C++ using directive or similar).
711   class DIImportedEntity : public DIDescriptor {
712     friend class DIDescriptor;
713     void printInternal(raw_ostream &OS) const;
714   public:
715     explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
716     DIScope getContext() const { return getFieldAs<DIScope>(1); }
717     DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
718     unsigned getLineNumber() const { return getUnsignedField(3); }
719     StringRef getName() const { return getStringField(4); }
720     bool Verify() const;
721   };
723   /// getDISubprogram - Find subprogram that is enclosing this scope.
724   DISubprogram getDISubprogram(const MDNode *Scope);
726   /// getDICompositeType - Find underlying composite type.
727   DICompositeType getDICompositeType(DIType T);
729   /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
730   /// to hold function specific information.
731   NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
733   /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
734   /// suitable to hold function specific information.
735   NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
737   /// createInlinedVariable - Create a new inlined variable based on current
738   /// variable.
739   /// @param DV            Current Variable.
740   /// @param InlinedScope  Location at current variable is inlined.
741   DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
742                                    LLVMContext &VMContext);
744   /// cleanseInlinedVariable - Remove inlined scope from the variable.
745   DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
747   /// Construct DITypeIdentifierMap by going through retained types of each CU.
748   DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
750   /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
751   /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
752   /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
753   /// DbgValueInst and DbgLoc attached to instructions. processModule will go
754   /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
755   /// used by the CUs.
756   class DebugInfoFinder {
757   public:
758     /// processModule - Process entire module and collect debug info
759     /// anchors.
760     void processModule(const Module &M);
762     /// processDeclare - Process DbgDeclareInst.
763     void processDeclare(const DbgDeclareInst *DDI);
764     /// Process DbgValueInst.
765     void processValue(const DbgValueInst *DVI);
766     /// processLocation - Process DILocation.
767     void processLocation(DILocation Loc);
769     /// Clear all lists.
770     void reset();
771   private:
772     /// processType - Process DIType.
773     void processType(DIType DT);
775     /// processLexicalBlock - Process DILexicalBlock.
776     void processLexicalBlock(DILexicalBlock LB);
778     /// processSubprogram - Process DISubprogram.
779     void processSubprogram(DISubprogram SP);
781     void processScope(DIScope Scope);
783     /// addCompileUnit - Add compile unit into CUs.
784     bool addCompileUnit(DICompileUnit CU);
786     /// addGlobalVariable - Add global variable into GVs.
787     bool addGlobalVariable(DIGlobalVariable DIG);
789     // addSubprogram - Add subprogram into SPs.
790     bool addSubprogram(DISubprogram SP);
792     /// addType - Add type into Tys.
793     bool addType(DIType DT);
795     bool addScope(DIScope Scope);
797   public:
798     typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
799     iterator compile_unit_begin()    const { return CUs.begin(); }
800     iterator compile_unit_end()      const { return CUs.end(); }
801     iterator subprogram_begin()      const { return SPs.begin(); }
802     iterator subprogram_end()        const { return SPs.end(); }
803     iterator global_variable_begin() const { return GVs.begin(); }
804     iterator global_variable_end()   const { return GVs.end(); }
805     iterator type_begin()            const { return TYs.begin(); }
806     iterator type_end()              const { return TYs.end(); }
807     iterator scope_begin()           const { return Scopes.begin(); }
808     iterator scope_end()             const { return Scopes.end(); }
810     unsigned compile_unit_count()    const { return CUs.size(); }
811     unsigned global_variable_count() const { return GVs.size(); }
812     unsigned subprogram_count()      const { return SPs.size(); }
813     unsigned type_count()            const { return TYs.size(); }
814     unsigned scope_count()           const { return Scopes.size(); }
816   private:
817     SmallVector<MDNode *, 8> CUs;  // Compile Units
818     SmallVector<MDNode *, 8> SPs;  // Subprograms
819     SmallVector<MDNode *, 8> GVs;  // Global Variables;
820     SmallVector<MDNode *, 8> TYs;  // Types
821     SmallVector<MDNode *, 8> Scopes; // Scopes
822     SmallPtrSet<MDNode *, 64> NodesSeen;
823     DITypeIdentifierMap TypeIdentifierMap;
824   };
825 } // end namespace llvm
827 #endif