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