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