Make findDbgDeclare/findDbgGlobalDeclare local static functions; avoid Elts array
[oota-llvm.git] / include / llvm / Analysis / 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_ANALYSIS_DEBUGINFO_H
18 #define LLVM_ANALYSIS_DEBUGINFO_H
19
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/SmallPtrSet.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 DebugLoc;
35   struct DebugLocTracker;
36   class Instruction;
37   class MDNode;
38   class LLVMContext;
39
40   /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
41   /// This should not be stored in a container, because underly MDNode may
42   /// change in certain situations.
43   class DIDescriptor {
44   protected:
45     MDNode *DbgNode;
46
47     /// DIDescriptor constructor.  If the specified node is non-null, check
48     /// to make sure that the tag in the descriptor matches 'RequiredTag'.  If
49     /// not, the debug info is corrupt and we ignore it.
50     DIDescriptor(MDNode *N, unsigned RequiredTag);
51
52     StringRef getStringField(unsigned Elt) const;
53     unsigned getUnsignedField(unsigned Elt) const {
54       return (unsigned)getUInt64Field(Elt);
55     }
56     uint64_t getUInt64Field(unsigned Elt) const;
57     DIDescriptor getDescriptorField(unsigned Elt) const;
58
59     template <typename DescTy>
60     DescTy getFieldAs(unsigned Elt) const {
61       return DescTy(getDescriptorField(Elt).getNode());
62     }
63
64     GlobalVariable *getGlobalVariableField(unsigned Elt) const;
65
66   public:
67     explicit DIDescriptor() : DbgNode(0) {}
68     explicit DIDescriptor(MDNode *N) : DbgNode(N) {}
69
70     bool isNull() const { return DbgNode == 0; }
71
72     MDNode *getNode() const { return DbgNode; }
73
74     unsigned getVersion() const {
75       return getUnsignedField(0) & LLVMDebugVersionMask;
76     }
77
78     unsigned getTag() const {
79       return getUnsignedField(0) & ~LLVMDebugVersionMask;
80     }
81
82     /// ValidDebugInfo - Return true if N represents valid debug info value.
83     static bool ValidDebugInfo(MDNode *N, unsigned OptLevel);
84
85     /// dump - print descriptor.
86     void dump() const;
87
88     bool isDerivedType() const;
89     bool isCompositeType() const;
90     bool isBasicType() const;
91     bool isVariable() const;
92     bool isSubprogram() const;
93     bool isGlobalVariable() const;
94     bool isScope() const;
95     bool isCompileUnit() const;
96     bool isNameSpace() const;
97     bool isLexicalBlock() const;
98     bool isSubrange() const;
99     bool isEnumerator() const;
100     bool isType() const;
101     bool isGlobal() const;
102   };
103
104   /// DISubrange - This is used to represent ranges, for array bounds.
105   class DISubrange : public DIDescriptor {
106   public:
107     explicit DISubrange(MDNode *N = 0)
108       : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {}
109
110     int64_t getLo() const { return (int64_t)getUInt64Field(1); }
111     int64_t getHi() const { return (int64_t)getUInt64Field(2); }
112   };
113
114   /// DIArray - This descriptor holds an array of descriptors.
115   class DIArray : public DIDescriptor {
116   public:
117     explicit DIArray(MDNode *N = 0)
118       : DIDescriptor(N) {}
119
120     unsigned getNumElements() const;
121     DIDescriptor getElement(unsigned Idx) const {
122       return getDescriptorField(Idx);
123     }
124   };
125
126   /// DIScope - A base class for various scopes.
127   class DIScope : public DIDescriptor {
128   public:
129     explicit DIScope(MDNode *N = 0) : DIDescriptor (N) {
130       if (DbgNode && !isScope())
131         DbgNode = 0;
132     }
133     virtual ~DIScope() {}
134
135     StringRef getFilename() const;
136     StringRef getDirectory() const;
137   };
138
139   /// DICompileUnit - A wrapper for a compile unit.
140   class DICompileUnit : public DIScope {
141   public:
142     explicit DICompileUnit(MDNode *N = 0) : DIScope(N) {
143       if (DbgNode && !isCompileUnit())
144         DbgNode = 0;
145     }
146
147     unsigned getLanguage() const     { return getUnsignedField(2); }
148     StringRef getFilename() const  { return getStringField(3);   }
149     StringRef getDirectory() const { return getStringField(4);   }
150     StringRef getProducer() const  { return getStringField(5);   }
151
152     /// isMain - Each input file is encoded as a separate compile unit in LLVM
153     /// debugging information output. However, many target specific tool chains
154     /// prefer to encode only one compile unit in an object file. In this
155     /// situation, the LLVM code generator will include  debugging information
156     /// entities in the compile unit that is marked as main compile unit. The
157     /// code generator accepts maximum one main compile unit per module. If a
158     /// module does not contain any main compile unit then the code generator
159     /// will emit multiple compile units in the output object file.
160
161     bool isMain() const                { return getUnsignedField(6); }
162     bool isOptimized() const           { return getUnsignedField(7); }
163     StringRef getFlags() const       { return getStringField(8);   }
164     unsigned getRunTimeVersion() const { return getUnsignedField(9); }
165
166     /// Verify - Verify that a compile unit is well formed.
167     bool Verify() const;
168
169     /// dump - print compile unit.
170     void dump() const;
171   };
172
173   /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
174   /// FIXME: it seems strange that this doesn't have either a reference to the
175   /// type/precision or a file/line pair for location info.
176   class DIEnumerator : public DIDescriptor {
177   public:
178     explicit DIEnumerator(MDNode *N = 0)
179       : DIDescriptor(N, dwarf::DW_TAG_enumerator) {}
180
181     StringRef getName() const        { return getStringField(1); }
182     uint64_t getEnumValue() const      { return getUInt64Field(2); }
183   };
184
185   /// DIType - This is a wrapper for a type.
186   /// FIXME: Types should be factored much better so that CV qualifiers and
187   /// others do not require a huge and empty descriptor full of zeros.
188   class DIType : public DIDescriptor {
189   public:
190     enum {
191       FlagPrivate          = 1 << 0,
192       FlagProtected        = 1 << 1,
193       FlagFwdDecl          = 1 << 2,
194       FlagAppleBlock       = 1 << 3,
195       FlagBlockByrefStruct = 1 << 4,
196       FlagVirtual          = 1 << 5
197     };
198
199   protected:
200     DIType(MDNode *N, unsigned Tag)
201       : DIDescriptor(N, Tag) {}
202     // This ctor is used when the Tag has already been validated by a derived
203     // ctor.
204     DIType(MDNode *N, bool, bool) : DIDescriptor(N) {}
205
206   public:
207
208     /// Verify - Verify that a type descriptor is well formed.
209     bool Verify() const;
210   public:
211     explicit DIType(MDNode *N);
212     explicit DIType() {}
213     virtual ~DIType() {}
214
215     DIDescriptor getContext() const     { return getDescriptorField(1); }
216     StringRef getName() const           { return getStringField(2);     }
217     DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
218     unsigned getLineNumber() const      { return getUnsignedField(4); }
219     uint64_t getSizeInBits() const      { return getUInt64Field(5); }
220     uint64_t getAlignInBits() const     { return getUInt64Field(6); }
221     // FIXME: Offset is only used for DW_TAG_member nodes.  Making every type
222     // carry this is just plain insane.
223     uint64_t getOffsetInBits() const    { return getUInt64Field(7); }
224     unsigned getFlags() const           { return getUnsignedField(8); }
225     bool isPrivate() const {
226       return (getFlags() & FlagPrivate) != 0;
227     }
228     bool isProtected() const {
229       return (getFlags() & FlagProtected) != 0;
230     }
231     bool isForwardDecl() const {
232       return (getFlags() & FlagFwdDecl) != 0;
233     }
234     // isAppleBlock - Return true if this is the Apple Blocks extension.
235     bool isAppleBlockExtension() const {
236       return (getFlags() & FlagAppleBlock) != 0;
237     }
238     bool isBlockByrefStruct() const {
239       return (getFlags() & FlagBlockByrefStruct) != 0;
240     }
241     bool isVirtual() const {
242       return (getFlags() & FlagVirtual) != 0;
243     }
244
245     /// dump - print type.
246     void dump() const;
247   };
248
249   /// DIBasicType - A basic type, like 'int' or 'float'.
250   class DIBasicType : public DIType {
251   public:
252     explicit DIBasicType(MDNode *N = 0)
253       : DIType(N, dwarf::DW_TAG_base_type) {}
254
255     unsigned getEncoding() const { return getUnsignedField(9); }
256
257     /// dump - print basic type.
258     void dump() const;
259   };
260
261   /// DIDerivedType - A simple derived type, like a const qualified type,
262   /// a typedef, a pointer or reference, etc.
263   class DIDerivedType : public DIType {
264   protected:
265     explicit DIDerivedType(MDNode *N, bool, bool)
266       : DIType(N, true, true) {}
267   public:
268     explicit DIDerivedType(MDNode *N = 0)
269       : DIType(N, true, true) {
270       if (DbgNode && !isDerivedType())
271         DbgNode = 0;
272     }
273
274     DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
275
276     /// getOriginalTypeSize - If this type is derived from a base type then
277     /// return base type size.
278     uint64_t getOriginalTypeSize() const;
279     /// dump - print derived type.
280     void dump() const;
281
282     /// replaceAllUsesWith - Replace all uses of debug info referenced by
283     /// this descriptor. After this completes, the current debug info value
284     /// is erased.
285     void replaceAllUsesWith(DIDescriptor &D);
286   };
287
288   /// DICompositeType - This descriptor holds a type that can refer to multiple
289   /// other types, like a function or struct.
290   /// FIXME: Why is this a DIDerivedType??
291   class DICompositeType : public DIDerivedType {
292   public:
293     explicit DICompositeType(MDNode *N = 0)
294       : DIDerivedType(N, true, true) {
295       if (N && !isCompositeType())
296         DbgNode = 0;
297     }
298
299     DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
300     unsigned getRunTimeLang() const { return getUnsignedField(11); }
301
302     /// Verify - Verify that a composite type descriptor is well formed.
303     bool Verify() const;
304
305     /// dump - print composite type.
306     void dump() const;
307   };
308
309   /// DIGlobal - This is a common class for global variables and subprograms.
310   class DIGlobal : public DIDescriptor {
311   protected:
312     explicit DIGlobal(MDNode *N, unsigned RequiredTag)
313       : DIDescriptor(N, RequiredTag) {}
314
315   public:
316     virtual ~DIGlobal() {}
317
318     DIDescriptor getContext() const     { return getDescriptorField(2); }
319     StringRef getName() const         { return getStringField(3); }
320     StringRef getDisplayName() const  { return getStringField(4); }
321     StringRef getLinkageName() const  { return getStringField(5); }
322     DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
323     unsigned getLineNumber() const      { return getUnsignedField(7); }
324     DIType getType() const              { return getFieldAs<DIType>(8); }
325
326     /// isLocalToUnit - Return true if this subprogram is local to the current
327     /// compile unit, like 'static' in C.
328     unsigned isLocalToUnit() const      { return getUnsignedField(9); }
329     unsigned isDefinition() const       { return getUnsignedField(10); }
330
331     /// dump - print global.
332     void dump() const;
333   };
334
335   /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
336   class DISubprogram : public DIScope {
337   public:
338     explicit DISubprogram(MDNode *N = 0) : DIScope(N) {
339       if (DbgNode && !isSubprogram())
340         DbgNode = 0;
341     }
342
343     DIDescriptor getContext() const     { return getDescriptorField(2); }
344     StringRef getName() const         { return getStringField(3); }
345     StringRef getDisplayName() const  { return getStringField(4); }
346     StringRef getLinkageName() const  { return getStringField(5); }
347     DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
348     unsigned getLineNumber() const      { return getUnsignedField(7); }
349     DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
350
351     /// getReturnTypeName - Subprogram return types are encoded either as
352     /// DIType or as DICompositeType.
353     StringRef getReturnTypeName() const {
354       DICompositeType DCT(getFieldAs<DICompositeType>(8));
355       if (!DCT.isNull()) {
356         DIArray A = DCT.getTypeArray();
357         DIType T(A.getElement(0).getNode());
358         return T.getName();
359       }
360       DIType T(getFieldAs<DIType>(8));
361       return T.getName();
362     }
363
364     /// isLocalToUnit - Return true if this subprogram is local to the current
365     /// compile unit, like 'static' in C.
366     unsigned isLocalToUnit() const     { return getUnsignedField(9); }
367     unsigned isDefinition() const      { return getUnsignedField(10); }
368
369     unsigned getVirtuality() const { return getUnsignedField(11); }
370     unsigned getVirtualIndex() const { return getUnsignedField(12); }
371
372     DICompositeType getContainingType() const {
373       return getFieldAs<DICompositeType>(13);
374     }
375
376     StringRef getFilename() const    { return getCompileUnit().getFilename();}
377     StringRef getDirectory() const   { return getCompileUnit().getDirectory();}
378
379     /// Verify - Verify that a subprogram descriptor is well formed.
380     bool Verify() const;
381
382     /// dump - print subprogram.
383     void dump() const;
384
385     /// describes - Return true if this subprogram provides debugging
386     /// information for the function F.
387     bool describes(const Function *F);
388   };
389
390   /// DIGlobalVariable - This is a wrapper for a global variable.
391   class DIGlobalVariable : public DIGlobal {
392   public:
393     explicit DIGlobalVariable(MDNode *N = 0)
394       : DIGlobal(N, dwarf::DW_TAG_variable) {}
395
396     GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
397
398     /// Verify - Verify that a global variable descriptor is well formed.
399     bool Verify() const;
400
401     /// dump - print global variable.
402     void dump() const;
403   };
404
405   /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
406   /// global etc).
407   class DIVariable : public DIDescriptor {
408   public:
409     explicit DIVariable(MDNode *N = 0)
410       : DIDescriptor(N) {
411       if (DbgNode && !isVariable())
412         DbgNode = 0;
413     }
414
415     DIDescriptor getContext() const { return getDescriptorField(1); }
416     StringRef getName() const     { return getStringField(2);     }
417     DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
418     unsigned getLineNumber() const      { return getUnsignedField(4); }
419     DIType getType() const              { return getFieldAs<DIType>(5); }
420
421
422     /// Verify - Verify that a variable descriptor is well formed.
423     bool Verify() const;
424
425     /// HasComplexAddr - Return true if the variable has a complex address.
426     bool hasComplexAddress() const {
427       return getNumAddrElements() > 0;
428     }
429
430     unsigned getNumAddrElements() const;
431     
432     uint64_t getAddrElement(unsigned Idx) const {
433       return getUInt64Field(Idx+6);
434     }
435
436     /// isBlockByrefVariable - Return true if the variable was declared as
437     /// a "__block" variable (Apple Blocks).
438     bool isBlockByrefVariable() const {
439       return getType().isBlockByrefStruct();
440     }
441
442     /// dump - print variable.
443     void dump() const;
444   };
445
446   /// DILexicalBlock - This is a wrapper for a lexical block.
447   class DILexicalBlock : public DIScope {
448   public:
449     explicit DILexicalBlock(MDNode *N = 0) : DIScope(N) {
450       if (DbgNode && !isLexicalBlock())
451         DbgNode = 0;
452     }
453     DIScope getContext() const       { return getFieldAs<DIScope>(1); }
454     StringRef getDirectory() const { return getContext().getDirectory(); }
455     StringRef getFilename() const  { return getContext().getFilename(); }
456   };
457
458   /// DINameSpace - A wrapper for a C++ style name space.
459   class DINameSpace : public DIScope { 
460   public:
461     explicit DINameSpace(MDNode *N = 0) : DIScope(N) {
462       if (DbgNode && !isNameSpace())
463         DbgNode = 0;
464     }
465
466     DIScope getContext() const     { return getFieldAs<DIScope>(1);      }
467     StringRef getName() const      { return getStringField(2);           }
468     StringRef getDirectory() const { return getContext().getDirectory(); }
469     StringRef getFilename() const  { return getContext().getFilename();  }
470     DICompileUnit getCompileUnit() const { return getFieldAs<DICompileUnit>(3);}
471     unsigned getLineNumber() const { return getUnsignedField(4);         }
472   };
473
474   /// DILocation - This object holds location information. This object
475   /// is not associated with any DWARF tag.
476   class DILocation : public DIDescriptor {
477   public:
478     explicit DILocation(MDNode *N) : DIDescriptor(N) { ; }
479
480     unsigned getLineNumber() const     { return getUnsignedField(0); }
481     unsigned getColumnNumber() const   { return getUnsignedField(1); }
482     DIScope  getScope() const          { return getFieldAs<DIScope>(2); }
483     DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
484     StringRef getFilename() const    { return getScope().getFilename(); }
485     StringRef getDirectory() const   { return getScope().getDirectory(); }
486   };
487
488   /// DIFactory - This object assists with the construction of the various
489   /// descriptors.
490   class DIFactory {
491     Module &M;
492     LLVMContext& VMContext;
493
494     Function *DeclareFn;     // llvm.dbg.declare
495     Function *ValueFn;       // llvm.dbg.value
496
497     DIFactory(const DIFactory &);     // DO NOT IMPLEMENT
498     void operator=(const DIFactory&); // DO NOT IMPLEMENT
499   public:
500     enum ComplexAddrKind { OpPlus=1, OpDeref };
501
502     explicit DIFactory(Module &m);
503
504     /// GetOrCreateArray - Create an descriptor for an array of descriptors.
505     /// This implicitly uniques the arrays created.
506     DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
507
508     /// GetOrCreateSubrange - Create a descriptor for a value range.  This
509     /// implicitly uniques the values returned.
510     DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
511
512     /// CreateCompileUnit - Create a new descriptor for the specified compile
513     /// unit.
514     DICompileUnit CreateCompileUnit(unsigned LangID,
515                                     StringRef Filename,
516                                     StringRef Directory,
517                                     StringRef Producer,
518                                     bool isMain = false,
519                                     bool isOptimized = false,
520                                     StringRef Flags = "",
521                                     unsigned RunTimeVer = 0);
522
523     /// CreateEnumerator - Create a single enumerator value.
524     DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
525
526     /// CreateBasicType - Create a basic type like int, float, etc.
527     DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
528                                 DICompileUnit CompileUnit, unsigned LineNumber,
529                                 uint64_t SizeInBits, uint64_t AlignInBits,
530                                 uint64_t OffsetInBits, unsigned Flags,
531                                 unsigned Encoding);
532
533     /// CreateBasicType - Create a basic type like int, float, etc.
534     DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
535                                 DICompileUnit CompileUnit, unsigned LineNumber,
536                                 Constant *SizeInBits, Constant *AlignInBits,
537                                 Constant *OffsetInBits, unsigned Flags,
538                                 unsigned Encoding);
539
540     /// CreateDerivedType - Create a derived type like const qualified type,
541     /// pointer, typedef, etc.
542     DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
543                                     StringRef Name,
544                                     DICompileUnit CompileUnit,
545                                     unsigned LineNumber,
546                                     uint64_t SizeInBits, uint64_t AlignInBits,
547                                     uint64_t OffsetInBits, unsigned Flags,
548                                     DIType DerivedFrom);
549
550     /// CreateDerivedType - Create a derived type like const qualified type,
551     /// pointer, typedef, etc.
552     DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
553                                         StringRef Name,
554                                     DICompileUnit CompileUnit,
555                                     unsigned LineNumber,
556                                     Constant *SizeInBits, Constant *AlignInBits,
557                                     Constant *OffsetInBits, unsigned Flags,
558                                     DIType DerivedFrom);
559
560     /// CreateCompositeType - Create a composite type like array, struct, etc.
561     DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
562                                         StringRef Name,
563                                         DICompileUnit CompileUnit,
564                                         unsigned LineNumber,
565                                         uint64_t SizeInBits,
566                                         uint64_t AlignInBits,
567                                         uint64_t OffsetInBits, unsigned Flags,
568                                         DIType DerivedFrom,
569                                         DIArray Elements,
570                                         unsigned RunTimeLang = 0);
571
572     /// CreateCompositeType - Create a composite type like array, struct, etc.
573     DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
574                                         StringRef Name,
575                                         DICompileUnit CompileUnit,
576                                         unsigned LineNumber,
577                                         Constant *SizeInBits,
578                                         Constant *AlignInBits,
579                                         Constant *OffsetInBits, unsigned Flags,
580                                         DIType DerivedFrom,
581                                         DIArray Elements,
582                                         unsigned RunTimeLang = 0);
583
584     /// CreateSubprogram - Create a new descriptor for the specified subprogram.
585     /// See comments in DISubprogram for descriptions of these fields.
586     DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
587                                   StringRef DisplayName,
588                                   StringRef LinkageName,
589                                   DICompileUnit CompileUnit, unsigned LineNo,
590                                   DIType Type, bool isLocalToUnit,
591                                   bool isDefinition,
592                                   unsigned VK = 0,
593                                   unsigned VIndex = 0,
594                                   DIType = DIType());
595
596     /// CreateSubprogramDefinition - Create new subprogram descriptor for the
597     /// given declaration. 
598     DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
599
600     /// CreateGlobalVariable - Create a new descriptor for the specified global.
601     DIGlobalVariable
602     CreateGlobalVariable(DIDescriptor Context, StringRef Name,
603                          StringRef DisplayName,
604                          StringRef LinkageName,
605                          DICompileUnit CompileUnit,
606                          unsigned LineNo, DIType Type, bool isLocalToUnit,
607                          bool isDefinition, llvm::GlobalVariable *GV);
608
609     /// CreateVariable - Create a new descriptor for the specified variable.
610     DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
611                               StringRef Name,
612                               DICompileUnit CompileUnit, unsigned LineNo,
613                               DIType Type);
614
615     /// CreateComplexVariable - Create a new descriptor for the specified
616     /// variable which has a complex address expression for its address.
617     DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
618                                      const std::string &Name,
619                                      DICompileUnit CompileUnit, unsigned LineNo,
620                                      DIType Type,
621                                      SmallVector<Value *, 9> &addr);
622
623     /// CreateLexicalBlock - This creates a descriptor for a lexical block
624     /// with the specified parent context.
625     DILexicalBlock CreateLexicalBlock(DIDescriptor Context);
626
627     /// CreateNameSpace - This creates new descriptor for a namespace
628     /// with the specified parent context.
629     DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
630                                 DICompileUnit CU, unsigned LineNo);
631
632     /// CreateLocation - Creates a debug info location.
633     DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
634                               DIScope S, DILocation OrigLoc);
635
636     /// CreateLocation - Creates a debug info location.
637     DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
638                               DIScope S, MDNode *OrigLoc = 0);
639
640     /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
641     Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
642                                BasicBlock *InsertAtEnd);
643
644     /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
645     Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
646                                Instruction *InsertBefore);
647
648     /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
649     Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
650                                          DIVariable D, BasicBlock *InsertAtEnd);
651
652     /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
653     Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
654                                        DIVariable D, Instruction *InsertBefore);
655   private:
656     Constant *GetTagConstant(unsigned TAG);
657   };
658
659   bool getLocationInfo(const Value *V, std::string &DisplayName,
660                        std::string &Type, unsigned &LineNo, std::string &File,
661                        std::string &Dir);
662
663   /// ExtractDebugLocation - Extract debug location information
664   /// from DILocation.
665   DebugLoc ExtractDebugLocation(DILocation &Loc,
666                                 DebugLocTracker &DebugLocInfo);
667
668   /// getDISubprogram - Find subprogram that is enclosing this scope.
669   DISubprogram getDISubprogram(MDNode *Scope);
670
671   /// getDICompositeType - Find underlying composite type.
672   DICompositeType getDICompositeType(DIType T);
673
674   class DebugInfoFinder {
675   public:
676     /// processModule - Process entire module and collect debug info
677     /// anchors.
678     void processModule(Module &M);
679
680   private:
681     /// processType - Process DIType.
682     void processType(DIType DT);
683
684     /// processLexicalBlock - Process DILexicalBlock.
685     void processLexicalBlock(DILexicalBlock LB);
686
687     /// processSubprogram - Process DISubprogram.
688     void processSubprogram(DISubprogram SP);
689
690     /// processDeclare - Process DbgDeclareInst.
691     void processDeclare(DbgDeclareInst *DDI);
692
693     /// processLocation - Process DILocation.
694     void processLocation(DILocation Loc);
695
696     /// addCompileUnit - Add compile unit into CUs.
697     bool addCompileUnit(DICompileUnit CU);
698
699     /// addGlobalVariable - Add global variable into GVs.
700     bool addGlobalVariable(DIGlobalVariable DIG);
701
702     // addSubprogram - Add subprgoram into SPs.
703     bool addSubprogram(DISubprogram SP);
704
705     /// addType - Add type into Tys.
706     bool addType(DIType DT);
707
708   public:
709     typedef SmallVector<MDNode *, 8>::iterator iterator;
710     iterator compile_unit_begin()    { return CUs.begin(); }
711     iterator compile_unit_end()      { return CUs.end(); }
712     iterator subprogram_begin()      { return SPs.begin(); }
713     iterator subprogram_end()        { return SPs.end(); }
714     iterator global_variable_begin() { return GVs.begin(); }
715     iterator global_variable_end()   { return GVs.end(); }
716     iterator type_begin()            { return TYs.begin(); }
717     iterator type_end()              { return TYs.end(); }
718
719     unsigned compile_unit_count()    { return CUs.size(); }
720     unsigned global_variable_count() { return GVs.size(); }
721     unsigned subprogram_count()      { return SPs.size(); }
722     unsigned type_count()            { return TYs.size(); }
723
724   private:
725     SmallVector<MDNode *, 8> CUs;  // Compile Units
726     SmallVector<MDNode *, 8> SPs;  // Subprograms
727     SmallVector<MDNode *, 8> GVs;  // Global Variables;
728     SmallVector<MDNode *, 8> TYs;  // Types
729     SmallPtrSet<MDNode *, 64> NodesSeen;
730   };
731 } // end namespace llvm
732
733 #endif