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