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