Derive DICompileUnit from DIScope.
[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/Metadata.h"
21 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/SmallPtrSet.h"
26 #include "llvm/Support/Dwarf.h"
27
28 namespace llvm {
29   class BasicBlock;
30   class Constant;
31   class Function;
32   class GlobalVariable;
33   class Module;
34   class Type;
35   class Value;
36   struct DbgStopPointInst;
37   struct DbgDeclareInst;
38   struct DbgFuncStartInst;
39   struct DbgRegionStartInst;
40   struct DbgRegionEndInst;
41   class DebugLoc;
42   struct DebugLocTracker;
43   class Instruction;
44   class LLVMContext;
45
46   class DIDescriptor {
47   protected:    
48     MDNode *DbgNode;
49
50     /// DIDescriptor constructor.  If the specified node is non-null, check
51     /// to make sure that the tag in the descriptor matches 'RequiredTag'.  If
52     /// not, the debug info is corrupt and we ignore it.
53     DIDescriptor(MDNode *N, unsigned RequiredTag);
54
55     const std::string &getStringField(unsigned Elt, std::string &Result) const;
56     unsigned getUnsignedField(unsigned Elt) const {
57       return (unsigned)getUInt64Field(Elt);
58     }
59     uint64_t getUInt64Field(unsigned Elt) const;
60     DIDescriptor getDescriptorField(unsigned Elt) const;
61
62     template <typename DescTy>
63     DescTy getFieldAs(unsigned Elt) const {
64       return DescTy(getDescriptorField(Elt).getNode());
65     }
66
67     GlobalVariable *getGlobalVariableField(unsigned Elt) const;
68
69   public:
70     explicit DIDescriptor() : DbgNode(0) {}
71     explicit DIDescriptor(MDNode *N) : DbgNode(N) {}
72
73     bool isNull() const { return DbgNode == 0; }
74
75     MDNode *getNode() const { return DbgNode; }
76
77     unsigned getVersion() const {
78       return getUnsignedField(0) & LLVMDebugVersionMask;
79     }
80
81     unsigned getTag() const {
82       return getUnsignedField(0) & ~LLVMDebugVersionMask;
83     }
84
85     /// ValidDebugInfo - Return true if N represents valid debug info value.
86     static bool ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel);
87
88     /// dump - print descriptor.
89     void dump() const;
90
91     bool isDerivedType() const;
92     bool isCompositeType() const;
93     bool isBasicType() const;
94     bool isVariable() const;
95     bool isSubprogram() const;
96     bool isGlobalVariable() const;
97     bool isScope() const;
98     bool isCompileUnit() const;
99   };
100
101   /// DISubrange - This is used to represent ranges, for array bounds.
102   class DISubrange : public DIDescriptor {
103   public:
104     explicit DISubrange(MDNode *N = 0)
105       : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {}
106
107     int64_t getLo() const { return (int64_t)getUInt64Field(1); }
108     int64_t getHi() const { return (int64_t)getUInt64Field(2); }
109   };
110
111   /// DIArray - This descriptor holds an array of descriptors.
112   class DIArray : public DIDescriptor {
113   public:
114     explicit DIArray(MDNode *N = 0) 
115       : DIDescriptor(N) {}
116
117     unsigned getNumElements() const;
118     DIDescriptor getElement(unsigned Idx) const {
119       return getDescriptorField(Idx);
120     }
121   };
122
123   /// DIScope - A base class for various scopes.
124   class DIScope : public DIDescriptor {
125   public:
126     explicit DIScope(MDNode *N = 0) : DIDescriptor (N) {
127       if (DbgNode && !isScope())
128         DbgNode = 0;
129     }
130   };
131
132   /// DICompileUnit - A wrapper for a compile unit.
133   class DICompileUnit : public DIScope {
134   public:
135     explicit DICompileUnit(MDNode *N = 0) {
136       DbgNode = N;
137       if (DbgNode && !isCompileUnit())
138         DbgNode = 0;
139     }
140
141     unsigned getLanguage() const     { return getUnsignedField(2); }
142     const std::string &getFilename(std::string &F) const {
143       return getStringField(3, F);
144     }
145     const std::string &getDirectory(std::string &F) const {
146       return getStringField(4, F);
147     }
148     const std::string &getProducer(std::string &F) const {
149       return getStringField(5, F);
150     }
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     const std::string &getFlags(std::string &F) const {
164       return getStringField(8, F);
165     }
166     unsigned getRunTimeVersion() const { return getUnsignedField(9); }
167
168     /// Verify - Verify that a compile unit is well formed.
169     bool Verify() const;
170
171     /// dump - print compile unit.
172     void dump() const;
173   };
174
175   /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
176   /// FIXME: it seems strange that this doesn't have either a reference to the
177   /// type/precision or a file/line pair for location info.
178   class DIEnumerator : public DIDescriptor {
179   public:
180     explicit DIEnumerator(MDNode *N = 0)
181       : DIDescriptor(N, dwarf::DW_TAG_enumerator) {}
182
183     const std::string &getName(std::string &F) const {
184       return getStringField(1, F);
185     }
186     uint64_t getEnumValue() const { return getUInt64Field(2); }
187   };
188
189   /// DIType - This is a wrapper for a type.
190   /// FIXME: Types should be factored much better so that CV qualifiers and
191   /// others do not require a huge and empty descriptor full of zeros.
192   class DIType : public DIDescriptor {
193   public:
194     enum {
195       FlagPrivate    = 1 << 0,
196       FlagProtected  = 1 << 1,
197       FlagFwdDecl    = 1 << 2,
198       FlagAppleBlock = 1 << 3,
199       FlagBlockByrefStruct = 1 << 4
200     };
201
202   protected:
203     DIType(MDNode *N, unsigned Tag) 
204       : DIDescriptor(N, Tag) {}
205     // This ctor is used when the Tag has already been validated by a derived
206     // ctor.
207     DIType(MDNode *N, bool, bool) : DIDescriptor(N) {}
208
209   public:
210
211     /// Verify - Verify that a type descriptor is well formed.
212     bool Verify() const;
213   public:
214     explicit DIType(MDNode *N);
215     explicit DIType() {}
216     virtual ~DIType() {}
217
218     DIDescriptor getContext() const     { return getDescriptorField(1); }
219     const std::string &getName(std::string &F) const {
220       return getStringField(2, F);
221     }
222     DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
223     unsigned getLineNumber() const      { return getUnsignedField(4); }
224     uint64_t getSizeInBits() const      { return getUInt64Field(5); }
225     uint64_t getAlignInBits() const     { return getUInt64Field(6); }
226     // FIXME: Offset is only used for DW_TAG_member nodes.  Making every type
227     // carry this is just plain insane.
228     uint64_t getOffsetInBits() const    { return getUInt64Field(7); }
229     unsigned getFlags() const           { return getUnsignedField(8); }
230     bool isPrivate() const {
231       return (getFlags() & FlagPrivate) != 0; 
232     }
233     bool isProtected() const {
234       return (getFlags() & FlagProtected) != 0; 
235     }
236     bool isForwardDecl() const {
237       return (getFlags() & FlagFwdDecl) != 0; 
238     }
239     // isAppleBlock - Return true if this is the Apple Blocks extension.
240     bool isAppleBlockExtension() const {
241       return (getFlags() & FlagAppleBlock) != 0; 
242     }
243     bool isBlockByrefStruct() const {
244       return (getFlags() & FlagBlockByrefStruct) != 0;
245     }
246
247     /// dump - print type.
248     void dump() const;
249   };
250
251   /// DIBasicType - A basic type, like 'int' or 'float'.
252   class DIBasicType : public DIType {
253   public:
254     explicit DIBasicType(MDNode *N = 0)
255       : DIType(N, dwarf::DW_TAG_base_type) {}
256
257     unsigned getEncoding() const { return getUnsignedField(9); }
258
259     /// dump - print basic type.
260     void dump() const;
261   };
262
263   /// DIDerivedType - A simple derived type, like a const qualified type,
264   /// a typedef, a pointer or reference, etc.
265   class DIDerivedType : public DIType {
266   protected:
267     explicit DIDerivedType(MDNode *N, bool, bool)
268       : DIType(N, true, true) {}
269   public:
270     explicit DIDerivedType(MDNode *N = 0)
271       : DIType(N, true, true) {
272       if (DbgNode && !isDerivedType())
273         DbgNode = 0;
274     }
275
276     DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
277
278     /// getOriginalTypeSize - If this type is derived from a base type then
279     /// return base type size.
280     uint64_t getOriginalTypeSize() const;
281     /// dump - print derived type.
282     void dump() const;
283
284     /// replaceAllUsesWith - Replace all uses of debug info referenced by
285     /// this descriptor. After this completes, the current debug info value
286     /// is erased.
287     void replaceAllUsesWith(DIDescriptor &D);
288   };
289
290   /// DICompositeType - This descriptor holds a type that can refer to multiple
291   /// other types, like a function or struct.
292   /// FIXME: Why is this a DIDerivedType??
293   class DICompositeType : public DIDerivedType {
294   public:
295     explicit DICompositeType(MDNode *N = 0)
296       : DIDerivedType(N, true, true) {
297       if (N && !isCompositeType())
298         DbgNode = 0;
299     }
300
301     DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
302     unsigned getRunTimeLang() const { return getUnsignedField(11); }
303
304     /// Verify - Verify that a composite type descriptor is well formed.
305     bool Verify() const;
306
307     /// dump - print composite type.
308     void dump() const;
309   };
310
311   /// DIGlobal - This is a common class for global variables and subprograms.
312   class DIGlobal : public DIDescriptor {
313   protected:
314     explicit DIGlobal(MDNode *N, unsigned RequiredTag)
315       : DIDescriptor(N, RequiredTag) {}
316
317   public:
318     virtual ~DIGlobal() {}
319
320     DIDescriptor getContext() const     { return getDescriptorField(2); }
321     const std::string &getName(std::string &F) const {
322       return getStringField(3, F);
323     }
324     const std::string &getDisplayName(std::string &F) const {
325       return getStringField(4, F);
326     }
327     const std::string &getLinkageName(std::string &F) const {
328       return getStringField(5, F);
329     }
330     DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
331     unsigned getLineNumber() const      { return getUnsignedField(7); }
332     DIType getType() const              { return getFieldAs<DIType>(8); }
333
334     /// isLocalToUnit - Return true if this subprogram is local to the current
335     /// compile unit, like 'static' in C.
336     unsigned isLocalToUnit() const      { return getUnsignedField(9); }
337     unsigned isDefinition() const       { return getUnsignedField(10); }
338
339     /// dump - print global.
340     void dump() const;
341   };
342
343   /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
344   class DISubprogram : public DIGlobal {
345   public:
346     explicit DISubprogram(MDNode *N = 0)
347       : DIGlobal(N, dwarf::DW_TAG_subprogram) {}
348
349     DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
350
351     /// getReturnTypeName - Subprogram return types are encoded either as
352     /// DIType or as DICompositeType.
353     const std::string &getReturnTypeName(std::string &F) 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(F);
359       }
360       DIType T(getFieldAs<DIType>(8));
361       return T.getName(F);
362     }
363
364     /// Verify - Verify that a subprogram descriptor is well formed.
365     bool Verify() const;
366
367     /// dump - print subprogram.
368     void dump() const;
369
370     /// describes - Return true if this subprogram provides debugging
371     /// information for the function F.
372     bool describes(const Function *F);
373   };
374
375   /// DIGlobalVariable - This is a wrapper for a global variable.
376   class DIGlobalVariable : public DIGlobal {
377   public:
378     explicit DIGlobalVariable(MDNode *N = 0)
379       : DIGlobal(N, dwarf::DW_TAG_variable) {}
380
381     GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
382
383     /// Verify - Verify that a global variable descriptor is well formed.
384     bool Verify() const;
385
386     /// dump - print global variable.
387     void dump() const;
388   };
389
390   /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
391   /// global etc).
392   class DIVariable : public DIDescriptor {
393   public:
394     explicit DIVariable(MDNode *N = 0)
395       : DIDescriptor(N) {
396       if (DbgNode && !isVariable())
397         DbgNode = 0;
398     }
399
400     DIDescriptor getContext() const { return getDescriptorField(1); }
401     const std::string &getName(std::string &F) const {
402       return getStringField(2, F);
403     }
404     DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
405     unsigned getLineNumber() const      { return getUnsignedField(4); }
406     DIType getType() const              { return getFieldAs<DIType>(5); }
407
408
409     /// Verify - Verify that a variable descriptor is well formed.
410     bool Verify() const;
411
412     /// isBlockByrefVariable - Return true if the variable was declared as
413     /// a "__block" variable (Apple Blocks).
414     bool isBlockByrefVariable() const { 
415       return getType().isBlockByrefStruct(); 
416     }
417
418     /// dump - print variable.
419     void dump() const;
420   };
421
422   /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
423   class DIBlock : public DIDescriptor {
424   public:
425     explicit DIBlock(MDNode *N = 0)
426       : DIDescriptor(N, dwarf::DW_TAG_lexical_block) {}
427
428     DIDescriptor getContext() const { return getDescriptorField(1); }
429   };
430
431   /// DIFactory - This object assists with the construction of the various
432   /// descriptors.
433   class DIFactory {
434     Module &M;
435     LLVMContext& VMContext;
436     
437     // Cached values for uniquing and faster lookups.
438     const Type *EmptyStructPtr; // "{}*".
439     Function *StopPointFn;   // llvm.dbg.stoppoint
440     Function *FuncStartFn;   // llvm.dbg.func.start
441     Function *RegionStartFn; // llvm.dbg.region.start
442     Function *RegionEndFn;   // llvm.dbg.region.end
443     Function *DeclareFn;     // llvm.dbg.declare
444     StringMap<Constant*> StringCache;
445     DenseMap<Constant*, DIDescriptor> SimpleConstantCache;
446
447     DIFactory(const DIFactory &);     // DO NOT IMPLEMENT
448     void operator=(const DIFactory&); // DO NOT IMPLEMENT
449   public:
450     explicit DIFactory(Module &m);
451
452     /// GetOrCreateArray - Create an descriptor for an array of descriptors. 
453     /// This implicitly uniques the arrays created.
454     DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
455
456     /// GetOrCreateSubrange - Create a descriptor for a value range.  This
457     /// implicitly uniques the values returned.
458     DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
459
460     /// CreateCompileUnit - Create a new descriptor for the specified compile
461     /// unit.
462     DICompileUnit CreateCompileUnit(unsigned LangID,
463                                     const std::string &Filename,
464                                     const std::string &Directory,
465                                     const std::string &Producer,
466                                     bool isMain = false,
467                                     bool isOptimized = false,
468                                     const char *Flags = "",
469                                     unsigned RunTimeVer = 0);
470
471     /// CreateEnumerator - Create a single enumerator value.
472     DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val);
473
474     /// CreateBasicType - Create a basic type like int, float, etc.
475     DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name,
476                                 DICompileUnit CompileUnit, unsigned LineNumber,
477                                 uint64_t SizeInBits, uint64_t AlignInBits,
478                                 uint64_t OffsetInBits, unsigned Flags,
479                                 unsigned Encoding);
480
481     /// CreateDerivedType - Create a derived type like const qualified type,
482     /// pointer, typedef, etc.
483     DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
484                                     const std::string &Name,
485                                     DICompileUnit CompileUnit,
486                                     unsigned LineNumber,
487                                     uint64_t SizeInBits, uint64_t AlignInBits,
488                                     uint64_t OffsetInBits, unsigned Flags,
489                                     DIType DerivedFrom);
490
491     /// CreateCompositeType - Create a composite type like array, struct, etc.
492     DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
493                                         const std::string &Name,
494                                         DICompileUnit CompileUnit,
495                                         unsigned LineNumber,
496                                         uint64_t SizeInBits,
497                                         uint64_t AlignInBits,
498                                         uint64_t OffsetInBits, unsigned Flags,
499                                         DIType DerivedFrom,
500                                         DIArray Elements,
501                                         unsigned RunTimeLang = 0);
502
503     /// CreateSubprogram - Create a new descriptor for the specified subprogram.
504     /// See comments in DISubprogram for descriptions of these fields.
505     DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name,
506                                   const std::string &DisplayName,
507                                   const std::string &LinkageName,
508                                   DICompileUnit CompileUnit, unsigned LineNo,
509                                   DIType Type, bool isLocalToUnit,
510                                   bool isDefinition);
511
512     /// CreateGlobalVariable - Create a new descriptor for the specified global.
513     DIGlobalVariable
514     CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
515                          const std::string &DisplayName,
516                          const std::string &LinkageName, 
517                          DICompileUnit CompileUnit,
518                          unsigned LineNo, DIType Type, bool isLocalToUnit,
519                          bool isDefinition, llvm::GlobalVariable *GV);
520
521     /// CreateVariable - Create a new descriptor for the specified variable.
522     DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
523                               const std::string &Name,
524                               DICompileUnit CompileUnit, unsigned LineNo,
525                               DIType Type);
526
527     /// CreateBlock - This creates a descriptor for a lexical block with the
528     /// specified parent context.
529     DIBlock CreateBlock(DIDescriptor Context);
530
531     /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
532     /// inserting it at the end of the specified basic block.
533     void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo,
534                          BasicBlock *BB);
535
536     /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
537     /// mark the start of the specified subprogram.
538     void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB);
539
540     /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
541     /// mark the start of a region for the specified scoping descriptor.
542     void InsertRegionStart(DIDescriptor D, BasicBlock *BB);
543
544     /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
545     /// mark the end of a region for the specified scoping descriptor.
546     void InsertRegionEnd(DIDescriptor D, BasicBlock *BB);
547
548     /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
549     void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB);
550
551   private:
552     Constant *GetTagConstant(unsigned TAG);
553   };
554
555   /// Finds the stoppoint coressponding to this instruction, that is the
556   /// stoppoint that dominates this instruction 
557   const DbgStopPointInst *findStopPoint(const Instruction *Inst);
558
559   /// Finds the stoppoint corresponding to first real (non-debug intrinsic) 
560   /// instruction in this Basic Block, and returns the stoppoint for it.
561   const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
562
563   /// Finds the dbg.declare intrinsic corresponding to this value if any.
564   /// It looks through pointer casts too.
565   const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
566
567   /// Find the debug info descriptor corresponding to this global variable.
568   Value *findDbgGlobalDeclare(GlobalVariable *V);
569
570   bool getLocationInfo(const Value *V, std::string &DisplayName, 
571                        std::string &Type, unsigned &LineNo, std::string &File,
572                        std::string &Dir); 
573
574   /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug 
575   /// info intrinsic.
576   bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI, 
577                                  CodeGenOpt::Level OptLev);
578
579   /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug 
580   /// info intrinsic.
581   bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI,
582                                  CodeGenOpt::Level OptLev);
583
584   /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug 
585   /// info intrinsic.
586   bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI,
587                                  CodeGenOpt::Level OptLev);
588
589   /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug 
590   /// info intrinsic.
591   bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI,
592                                  CodeGenOpt::Level OptLev);
593
594   /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug 
595   /// info intrinsic.
596   bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI,
597                                  CodeGenOpt::Level OptLev);
598
599   /// ExtractDebugLocation - Extract debug location information 
600   /// from llvm.dbg.stoppoint intrinsic.
601   DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI,
602                                 DebugLocTracker &DebugLocInfo);
603
604   /// ExtractDebugLocation - Extract debug location information 
605   /// from llvm.dbg.func_start intrinsic.
606   DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI,
607                                 DebugLocTracker &DebugLocInfo);
608
609   /// isInlinedFnStart - Return true if FSI is starting an inlined function.
610   bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn);
611
612   /// isInlinedFnEnd - Return true if REI is ending an inlined function.
613   bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn);
614   /// DebugInfoFinder - This object collects DebugInfo from a module.
615   class DebugInfoFinder {
616
617   public:
618     /// processModule - Process entire module and collect debug info
619     /// anchors.
620     void processModule(Module &M);
621     
622   private:
623     /// processType - Process DIType.
624     void processType(DIType DT);
625
626     /// processSubprogram - Enumberate DISubprogram.
627     void processSubprogram(DISubprogram SP);
628
629     /// processStopPoint - Process DbgStopPointInst.
630     void processStopPoint(DbgStopPointInst *SPI);
631
632     /// processFuncStart - Process DbgFuncStartInst.
633     void processFuncStart(DbgFuncStartInst *FSI);
634
635     /// processRegionStart - Process DbgRegionStart.
636     void processRegionStart(DbgRegionStartInst *DRS);
637
638     /// processRegionEnd - Process DbgRegionEnd.
639     void processRegionEnd(DbgRegionEndInst *DRE);
640
641     /// processDeclare - Process DbgDeclareInst.
642     void processDeclare(DbgDeclareInst *DDI);
643
644     /// addCompileUnit - Add compile unit into CUs.
645     bool addCompileUnit(DICompileUnit CU);
646     
647     /// addGlobalVariable - Add global variable into GVs.
648     bool addGlobalVariable(DIGlobalVariable DIG);
649
650     // addSubprogram - Add subprgoram into SPs.
651     bool addSubprogram(DISubprogram SP);
652
653     /// addType - Add type into Tys.
654     bool addType(DIType DT);
655
656   public:
657     typedef SmallVector<MDNode *, 8>::iterator iterator;
658     iterator compile_unit_begin()    { return CUs.begin(); }
659     iterator compile_unit_end()      { return CUs.end(); }
660     iterator subprogram_begin()      { return SPs.begin(); }
661     iterator subprogram_end()        { return SPs.end(); }
662     iterator global_variable_begin() { return GVs.begin(); }
663     iterator global_variable_end()   { return GVs.end(); }
664     iterator type_begin()            { return TYs.begin(); }
665     iterator type_end()              { return TYs.end(); }
666
667     unsigned compile_unit_count()    { return CUs.size(); }
668     unsigned global_variable_count() { return GVs.size(); }
669     unsigned subprogram_count()      { return SPs.size(); }
670     unsigned type_count()            { return TYs.size(); }
671
672   private:
673     SmallVector<MDNode *, 8> CUs;  // Compile Units
674     SmallVector<MDNode *, 8> SPs;  // Subprograms
675     SmallVector<MDNode *, 8> GVs;  // Global Variables;
676     SmallVector<MDNode *, 8> TYs;  // Types
677     SmallPtrSet<MDNode *, 64> NodesSeen;
678   };
679 } // end namespace llvm
680
681 #endif