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