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