Add a AccessesArgumentsReadonly ModRefBehavior value, so that the intrinsic
[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/ADT/SmallVector.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Dwarf.h"
24
25 namespace llvm {
26   class BasicBlock;
27   class Constant;
28   class Function;
29   class GlobalVariable;
30   class Module;
31   class Type;
32   class Value;
33   class DbgDeclareInst;
34   class Instruction;
35   class MDNode;
36   class LLVMContext;
37   class raw_ostream;
38
39   class DIFile;
40   class DISubprogram;
41   class DILexicalBlock;
42   class DIVariable;
43   class DIType;
44
45   /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
46   /// This should not be stored in a container, because underly MDNode may
47   /// change in certain situations.
48   class DIDescriptor {
49   public:
50     enum {
51       FlagPrivate          = 1 << 0,
52       FlagProtected        = 1 << 1,
53       FlagFwdDecl          = 1 << 2,
54       FlagAppleBlock       = 1 << 3,
55       FlagBlockByrefStruct = 1 << 4,
56       FlagVirtual          = 1 << 5,
57       FlagArtificial       = 1 << 6,
58       FlagExplicit         = 1 << 7,
59       FlagPrototyped       = 1 << 8
60     };
61   protected:
62     const MDNode *DbgNode;
63
64     StringRef getStringField(unsigned Elt) const;
65     unsigned getUnsignedField(unsigned Elt) const {
66       return (unsigned)getUInt64Field(Elt);
67     }
68     uint64_t getUInt64Field(unsigned Elt) const;
69     DIDescriptor getDescriptorField(unsigned Elt) const;
70
71     template <typename DescTy>
72     DescTy getFieldAs(unsigned Elt) const {
73       return DescTy(getDescriptorField(Elt));
74     }
75
76     GlobalVariable *getGlobalVariableField(unsigned Elt) const;
77     Constant *getConstantField(unsigned Elt) const;
78     Function *getFunctionField(unsigned Elt) const;
79
80   public:
81     explicit DIDescriptor() : DbgNode(0) {}
82     explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
83     explicit DIDescriptor(const DIFile F);
84     explicit DIDescriptor(const DISubprogram F);
85     explicit DIDescriptor(const DILexicalBlock F);
86     explicit DIDescriptor(const DIVariable F);
87     explicit DIDescriptor(const DIType F);
88
89     bool Verify() const { return DbgNode != 0; }
90
91     operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
92     MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
93
94     unsigned getVersion() const {
95       return getUnsignedField(0) & LLVMDebugVersionMask;
96     }
97
98     unsigned getTag() const {
99       return getUnsignedField(0) & ~LLVMDebugVersionMask;
100     }
101
102     /// print - print descriptor.
103     void print(raw_ostream &OS) const;
104
105     /// dump - print descriptor to dbgs() with a newline.
106     void dump() const;
107
108     bool isDerivedType() const;
109     bool isCompositeType() const;
110     bool isBasicType() const;
111     bool isVariable() const;
112     bool isSubprogram() const;
113     bool isGlobalVariable() const;
114     bool isScope() const;
115     bool isFile() const;
116     bool isCompileUnit() const;
117     bool isNameSpace() const;
118     bool isLexicalBlock() const;
119     bool isSubrange() const;
120     bool isEnumerator() const;
121     bool isType() const;
122     bool isGlobal() const;
123     bool isUnspecifiedParameter() const;
124   };
125
126   /// DISubrange - This is used to represent ranges, for array bounds.
127   class DISubrange : public DIDescriptor {
128   public:
129     explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
130
131     int64_t getLo() const { return (int64_t)getUInt64Field(1); }
132     int64_t getHi() const { return (int64_t)getUInt64Field(2); }
133   };
134
135   /// DIArray - This descriptor holds an array of descriptors.
136   class DIArray : public DIDescriptor {
137   public:
138     explicit DIArray(const MDNode *N = 0)
139       : DIDescriptor(N) {}
140
141     unsigned getNumElements() const;
142     DIDescriptor getElement(unsigned Idx) const {
143       return getDescriptorField(Idx);
144     }
145   };
146
147   /// DIScope - A base class for various scopes.
148   class DIScope : public DIDescriptor {
149   public:
150     explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
151     virtual ~DIScope() {}
152
153     StringRef getFilename() const;
154     StringRef getDirectory() const;
155   };
156
157   /// DICompileUnit - A wrapper for a compile unit.
158   class DICompileUnit : public DIScope {
159   public:
160     explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
161
162     unsigned getLanguage() const   { return getUnsignedField(2); }
163     StringRef getFilename() const  { return getStringField(3);   }
164     StringRef getDirectory() const { return getStringField(4);   }
165     StringRef getProducer() const  { return getStringField(5);   }
166
167     /// isMain - Each input file is encoded as a separate compile unit in LLVM
168     /// debugging information output. However, many target specific tool chains
169     /// prefer to encode only one compile unit in an object file. In this
170     /// situation, the LLVM code generator will include  debugging information
171     /// entities in the compile unit that is marked as main compile unit. The
172     /// code generator accepts maximum one main compile unit per module. If a
173     /// module does not contain any main compile unit then the code generator
174     /// will emit multiple compile units in the output object file.
175
176     bool isMain() const                { return getUnsignedField(6) != 0; }
177     bool isOptimized() const           { return getUnsignedField(7) != 0; }
178     StringRef getFlags() const       { return getStringField(8);   }
179     unsigned getRunTimeVersion() const { return getUnsignedField(9); }
180
181     /// Verify - Verify that a compile unit is well formed.
182     bool Verify() const;
183
184     /// print - print compile unit.
185     void print(raw_ostream &OS) const;
186
187     /// dump - print compile unit to dbgs() with a newline.
188     void dump() const;
189   };
190
191   /// DIFile - This is a wrapper for a file.
192   class DIFile : public DIScope {
193   public:
194     explicit DIFile(const MDNode *N = 0) : DIScope(N) {
195       if (DbgNode && !isFile())
196         DbgNode = 0;
197     }
198     StringRef getFilename() const  { return getStringField(1);   }
199     StringRef getDirectory() const { return getStringField(2);   }
200     DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
201   };
202
203   /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
204   /// FIXME: it seems strange that this doesn't have either a reference to the
205   /// type/precision or a file/line pair for location info.
206   class DIEnumerator : public DIDescriptor {
207   public:
208     explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
209
210     StringRef getName() const        { return getStringField(1); }
211     uint64_t getEnumValue() const      { return getUInt64Field(2); }
212   };
213
214   /// DIType - This is a wrapper for a type.
215   /// FIXME: Types should be factored much better so that CV qualifiers and
216   /// others do not require a huge and empty descriptor full of zeros.
217   class DIType : public DIScope {
218   public:
219   protected:
220     // This ctor is used when the Tag has already been validated by a derived
221     // ctor.
222     DIType(const MDNode *N, bool, bool) : DIScope(N) {}
223
224   public:
225
226     /// Verify - Verify that a type descriptor is well formed.
227     bool Verify() const;
228   public:
229     explicit DIType(const MDNode *N);
230     explicit DIType() {}
231     virtual ~DIType() {}
232
233     DIScope getContext() const          { return getFieldAs<DIScope>(1); }
234     StringRef getName() const           { return getStringField(2);     }
235     DICompileUnit getCompileUnit() const{ 
236      if (getVersion() == llvm::LLVMDebugVersion7)
237        return getFieldAs<DICompileUnit>(3);
238      
239      return getFieldAs<DIFile>(3).getCompileUnit();
240     }
241     DIFile getFile() const              { return getFieldAs<DIFile>(3); }
242     unsigned getLineNumber() const      { return getUnsignedField(4); }
243     uint64_t getSizeInBits() const      { return getUInt64Field(5); }
244     uint64_t getAlignInBits() const     { return getUInt64Field(6); }
245     // FIXME: Offset is only used for DW_TAG_member nodes.  Making every type
246     // carry this is just plain insane.
247     uint64_t getOffsetInBits() const    { return getUInt64Field(7); }
248     unsigned getFlags() const           { return getUnsignedField(8); }
249     bool isPrivate() const {
250       return (getFlags() & FlagPrivate) != 0;
251     }
252     bool isProtected() const {
253       return (getFlags() & FlagProtected) != 0;
254     }
255     bool isForwardDecl() const {
256       return (getFlags() & FlagFwdDecl) != 0;
257     }
258     // isAppleBlock - Return true if this is the Apple Blocks extension.
259     bool isAppleBlockExtension() const {
260       return (getFlags() & FlagAppleBlock) != 0;
261     }
262     bool isBlockByrefStruct() const {
263       return (getFlags() & FlagBlockByrefStruct) != 0;
264     }
265     bool isVirtual() const {
266       return (getFlags() & FlagVirtual) != 0;
267     }
268     bool isArtificial() const {
269       return (getFlags() & FlagArtificial) != 0;
270     }
271     bool isValid() const {
272       return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
273     }
274     StringRef getDirectory() const  { 
275       if (getVersion() == llvm::LLVMDebugVersion7)
276         return getCompileUnit().getDirectory();
277
278       return getFieldAs<DIFile>(3).getDirectory();
279     }
280     StringRef getFilename() const  { 
281       if (getVersion() == llvm::LLVMDebugVersion7)
282         return getCompileUnit().getFilename();
283
284       return getFieldAs<DIFile>(3).getFilename();
285     }
286
287     /// replaceAllUsesWith - Replace all uses of debug info referenced by
288     /// this descriptor.
289     void replaceAllUsesWith(DIDescriptor &D);
290
291     /// print - print type.
292     void print(raw_ostream &OS) const;
293
294     /// dump - print type to dbgs() with a newline.
295     void dump() const;
296   };
297
298   /// DIBasicType - A basic type, like 'int' or 'float'.
299   class DIBasicType : public DIType {
300   public:
301     explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
302
303     unsigned getEncoding() const { return getUnsignedField(9); }
304
305     /// Verify - Verify that a basic type descriptor is well formed.
306     bool Verify() const;
307
308     /// print - print basic type.
309     void print(raw_ostream &OS) const;
310
311     /// dump - print basic type to dbgs() with a newline.
312     void dump() const;
313   };
314
315   /// DIDerivedType - A simple derived type, like a const qualified type,
316   /// a typedef, a pointer or reference, etc.
317   class DIDerivedType : public DIType {
318   protected:
319     explicit DIDerivedType(const MDNode *N, bool, bool)
320       : DIType(N, true, true) {}
321   public:
322     explicit DIDerivedType(const MDNode *N = 0)
323       : DIType(N, true, true) {}
324
325     DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
326
327     /// getOriginalTypeSize - If this type is derived from a base type then
328     /// return base type size.
329     uint64_t getOriginalTypeSize() const;
330
331     /// Verify - Verify that a derived type descriptor is well formed.
332     bool Verify() const;
333
334     /// print - print derived type.
335     void print(raw_ostream &OS) const;
336
337     /// dump - print derived type to dbgs() with a newline.
338     void dump() const;
339   };
340
341   /// DICompositeType - This descriptor holds a type that can refer to multiple
342   /// other types, like a function or struct.
343   /// FIXME: Why is this a DIDerivedType??
344   class DICompositeType : public DIDerivedType {
345   public:
346     explicit DICompositeType(const MDNode *N = 0)
347       : DIDerivedType(N, true, true) {
348       if (N && !isCompositeType())
349         DbgNode = 0;
350     }
351
352     DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
353     unsigned getRunTimeLang() const { return getUnsignedField(11); }
354     DICompositeType getContainingType() const {
355       return getFieldAs<DICompositeType>(12);
356     }
357
358     /// Verify - Verify that a composite type descriptor is well formed.
359     bool Verify() const;
360
361     /// print - print composite type.
362     void print(raw_ostream &OS) const;
363
364     /// dump - print composite type to dbgs() with a newline.
365     void dump() const;
366   };
367
368   /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
369   class DISubprogram : public DIScope {
370   public:
371     explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
372
373     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
374     StringRef getName() const         { return getStringField(3); }
375     StringRef getDisplayName() const  { return getStringField(4); }
376     StringRef getLinkageName() const  { return getStringField(5); }
377     DICompileUnit getCompileUnit() const{ 
378       if (getVersion() == llvm::LLVMDebugVersion7)
379         return getFieldAs<DICompileUnit>(6);
380
381       return getFieldAs<DIFile>(6).getCompileUnit(); 
382     }
383     unsigned getLineNumber() const      { return getUnsignedField(7); }
384     DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
385
386     /// getReturnTypeName - Subprogram return types are encoded either as
387     /// DIType or as DICompositeType.
388     StringRef getReturnTypeName() const {
389       DICompositeType DCT(getFieldAs<DICompositeType>(8));
390       if (DCT.Verify()) {
391         DIArray A = DCT.getTypeArray();
392         DIType T(A.getElement(0));
393         return T.getName();
394       }
395       DIType T(getFieldAs<DIType>(8));
396       return T.getName();
397     }
398
399     /// isLocalToUnit - Return true if this subprogram is local to the current
400     /// compile unit, like 'static' in C.
401     unsigned isLocalToUnit() const     { return getUnsignedField(9); }
402     unsigned isDefinition() const      { return getUnsignedField(10); }
403
404     unsigned getVirtuality() const { return getUnsignedField(11); }
405     unsigned getVirtualIndex() const { return getUnsignedField(12); }
406
407     DICompositeType getContainingType() const {
408       return getFieldAs<DICompositeType>(13);
409     }
410     unsigned isArtificial() const    { 
411       if (getVersion() <= llvm::LLVMDebugVersion8)
412         return getUnsignedField(14); 
413       return (getUnsignedField(14) & FlagArtificial) != 0;
414     }
415     /// isPrivate - Return true if this subprogram has "private"
416     /// access specifier.
417     bool isPrivate() const    { 
418       if (getVersion() <= llvm::LLVMDebugVersion8)
419         return false;
420       return (getUnsignedField(14) & FlagPrivate) != 0;
421     }
422     /// isProtected - Return true if this subprogram has "protected"
423     /// access specifier.
424     bool isProtected() const    { 
425       if (getVersion() <= llvm::LLVMDebugVersion8)
426         return false;
427       return (getUnsignedField(14) & FlagProtected) != 0;
428     }
429     /// isExplicit - Return true if this subprogram is marked as explicit.
430     bool isExplicit() const    { 
431       if (getVersion() <= llvm::LLVMDebugVersion8)
432         return false;
433       return (getUnsignedField(14) & FlagExplicit) != 0;
434     }
435     /// isPrototyped - Return true if this subprogram is prototyped.
436     bool isPrototyped() const    { 
437       if (getVersion() <= llvm::LLVMDebugVersion8)
438         return false;
439       return (getUnsignedField(14) & FlagPrototyped) != 0;
440     }
441
442     unsigned isOptimized() const;
443
444     StringRef getFilename() const    { 
445       if (getVersion() == llvm::LLVMDebugVersion7)
446         return getCompileUnit().getFilename();
447
448       return getFieldAs<DIFile>(6).getFilename(); 
449     }
450
451     StringRef getDirectory() const   { 
452       if (getVersion() == llvm::LLVMDebugVersion7)
453         return getCompileUnit().getFilename();
454
455       return getFieldAs<DIFile>(6).getDirectory(); 
456     }
457
458     /// Verify - Verify that a subprogram descriptor is well formed.
459     bool Verify() const;
460
461     /// print - print subprogram.
462     void print(raw_ostream &OS) const;
463
464     /// dump - print subprogram to dbgs() with a newline.
465     void dump() const;
466
467     /// describes - Return true if this subprogram provides debugging
468     /// information for the function F.
469     bool describes(const Function *F);
470
471     Function *getFunction() const { return getFunctionField(16); }
472   };
473
474   /// DIGlobalVariable - This is a wrapper for a global variable.
475   class DIGlobalVariable : public DIDescriptor {
476   public:
477     explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
478
479     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
480     StringRef getName() const         { return getStringField(3); }
481     StringRef getDisplayName() const  { return getStringField(4); }
482     StringRef getLinkageName() const  { return getStringField(5); }
483     DICompileUnit getCompileUnit() const{ 
484       if (getVersion() == llvm::LLVMDebugVersion7)
485         return getFieldAs<DICompileUnit>(6);
486
487       DIFile F = getFieldAs<DIFile>(6); 
488       return F.getCompileUnit();
489     }
490
491     unsigned getLineNumber() const      { return getUnsignedField(7); }
492     DIType getType() const              { return getFieldAs<DIType>(8); }
493     unsigned isLocalToUnit() const      { return getUnsignedField(9); }
494     unsigned isDefinition() const       { return getUnsignedField(10); }
495
496     GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
497     Constant *getConstant() const   { return getConstantField(11); }
498
499     /// Verify - Verify that a global variable descriptor is well formed.
500     bool Verify() const;
501
502     /// print - print global variable.
503     void print(raw_ostream &OS) const;
504
505     /// dump - print global variable to dbgs() with a newline.
506     void dump() const;
507   };
508
509   /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
510   /// global etc).
511   class DIVariable : public DIDescriptor {
512   public:
513     explicit DIVariable(const MDNode *N = 0)
514       : DIDescriptor(N) {}
515
516     DIScope getContext() const          { return getFieldAs<DIScope>(1); }
517     StringRef getName() const           { return getStringField(2);     }
518     DICompileUnit getCompileUnit() const{ 
519       if (getVersion() == llvm::LLVMDebugVersion7)
520         return getFieldAs<DICompileUnit>(3);
521
522       DIFile F = getFieldAs<DIFile>(3); 
523       return F.getCompileUnit();
524     }
525     unsigned getLineNumber() const      { return getUnsignedField(4); }
526     DIType getType() const              { return getFieldAs<DIType>(5); }
527     
528     /// isArtificial - Return true if this variable is marked as "artificial".
529     bool isArtificial() const    { 
530       if (getVersion() <= llvm::LLVMDebugVersion8)
531         return false;
532       return (getUnsignedField(6) & FlagArtificial) != 0;
533     }
534
535
536     /// Verify - Verify that a variable descriptor is well formed.
537     bool Verify() const;
538
539     /// HasComplexAddr - Return true if the variable has a complex address.
540     bool hasComplexAddress() const {
541       return getNumAddrElements() > 0;
542     }
543
544     unsigned getNumAddrElements() const;
545     
546     uint64_t getAddrElement(unsigned Idx) const {
547       return getUInt64Field(Idx+6);
548     }
549
550     /// isBlockByrefVariable - Return true if the variable was declared as
551     /// a "__block" variable (Apple Blocks).
552     bool isBlockByrefVariable() const {
553       return getType().isBlockByrefStruct();
554     }
555
556     /// isInlinedFnArgument - Return trule if this variable provides debugging
557     /// information for an inlined function arguments.
558     bool isInlinedFnArgument(const Function *CurFn);
559
560     /// print - print variable.
561     void print(raw_ostream &OS) const;
562
563     /// dump - print variable to dbgs() with a newline.
564     void dump() const;
565   };
566
567   /// DILexicalBlock - This is a wrapper for a lexical block.
568   class DILexicalBlock : public DIScope {
569   public:
570     explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
571     DIScope getContext() const       { return getFieldAs<DIScope>(1);      }
572     unsigned getLineNumber() const   { return getUnsignedField(2);         }
573     unsigned getColumnNumber() const { return getUnsignedField(3);         }
574     StringRef getDirectory() const {
575       StringRef dir = getFieldAs<DIFile>(4).getDirectory();
576       return !dir.empty() ? dir : getContext().getDirectory();
577     }
578     StringRef getFilename() const {
579       StringRef filename = getFieldAs<DIFile>(4).getFilename();
580       return !filename.empty() ? filename : getContext().getFilename();
581     }
582   };
583
584   /// DINameSpace - A wrapper for a C++ style name space.
585   class DINameSpace : public DIScope { 
586   public:
587     explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
588     DIScope getContext() const     { return getFieldAs<DIScope>(1);      }
589     StringRef getName() const      { return getStringField(2);           }
590     StringRef getDirectory() const  { 
591       return getFieldAs<DIFile>(3).getDirectory();
592     }
593     StringRef getFilename() const  { 
594       return getFieldAs<DIFile>(3).getFilename();
595     }
596     DICompileUnit getCompileUnit() const{ 
597       if (getVersion() == llvm::LLVMDebugVersion7)
598         return getFieldAs<DICompileUnit>(3);
599
600       return getFieldAs<DIFile>(3).getCompileUnit(); 
601     }
602     unsigned getLineNumber() const { return getUnsignedField(4);         }
603     bool Verify() const;
604   };
605
606   /// DILocation - This object holds location information. This object
607   /// is not associated with any DWARF tag.
608   class DILocation : public DIDescriptor {
609   public:
610     explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
611
612     unsigned getLineNumber() const     { return getUnsignedField(0); }
613     unsigned getColumnNumber() const   { return getUnsignedField(1); }
614     DIScope  getScope() const          { return getFieldAs<DIScope>(2); }
615     DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
616     StringRef getFilename() const    { return getScope().getFilename(); }
617     StringRef getDirectory() const   { return getScope().getDirectory(); }
618     bool Verify() const;
619   };
620
621   /// DIFactory - This object assists with the construction of the various
622   /// descriptors.
623   class DIFactory {
624     Module &M;
625     LLVMContext& VMContext;
626
627     Function *DeclareFn;     // llvm.dbg.declare
628     Function *ValueFn;       // llvm.dbg.value
629
630     DIFactory(const DIFactory &);     // DO NOT IMPLEMENT
631     void operator=(const DIFactory&); // DO NOT IMPLEMENT
632   public:
633     enum ComplexAddrKind { OpPlus=1, OpDeref };
634
635     explicit DIFactory(Module &m);
636
637     /// GetOrCreateArray - Create an descriptor for an array of descriptors.
638     /// This implicitly uniques the arrays created.
639     DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
640
641     /// GetOrCreateSubrange - Create a descriptor for a value range.  This
642     /// implicitly uniques the values returned.
643     DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
644
645     /// CreateUnspecifiedParameter - Create unspeicified type descriptor
646     /// for a subroutine type.
647     DIDescriptor CreateUnspecifiedParameter();
648
649     /// CreateCompileUnit - Create a new descriptor for the specified compile
650     /// unit.
651     DICompileUnit CreateCompileUnit(unsigned LangID,
652                                     StringRef Filename,
653                                     StringRef Directory,
654                                     StringRef Producer,
655                                     bool isMain = false,
656                                     bool isOptimized = false,
657                                     StringRef Flags = "",
658                                     unsigned RunTimeVer = 0);
659
660     /// CreateFile -  Create a new descriptor for the specified file.
661     DIFile CreateFile(StringRef Filename, StringRef Directory,
662                       DICompileUnit CU);
663
664     /// CreateEnumerator - Create a single enumerator value.
665     DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
666
667     /// CreateBasicType - Create a basic type like int, float, etc.
668     DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
669                                 DIFile F, unsigned LineNumber,
670                                 uint64_t SizeInBits, uint64_t AlignInBits,
671                                 uint64_t OffsetInBits, unsigned Flags,
672                                 unsigned Encoding);
673
674     /// CreateBasicType - Create a basic type like int, float, etc.
675     DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
676                                 DIFile F, unsigned LineNumber,
677                                 Constant *SizeInBits, Constant *AlignInBits,
678                                 Constant *OffsetInBits, unsigned Flags,
679                                 unsigned Encoding);
680
681     /// CreateDerivedType - Create a derived type like const qualified type,
682     /// pointer, typedef, etc.
683     DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
684                                     StringRef Name,
685                                     DIFile F,
686                                     unsigned LineNumber,
687                                     uint64_t SizeInBits, uint64_t AlignInBits,
688                                     uint64_t OffsetInBits, unsigned Flags,
689                                     DIType DerivedFrom);
690
691     /// CreateDerivedType - Create a derived type like const qualified type,
692     /// pointer, typedef, etc.
693     DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
694                                       StringRef Name,
695                                       DIFile F,
696                                       unsigned LineNumber,
697                                       Constant *SizeInBits, 
698                                       Constant *AlignInBits,
699                                       Constant *OffsetInBits, unsigned Flags,
700                                       DIType DerivedFrom);
701
702     /// CreateCompositeType - Create a composite type like array, struct, etc.
703     DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
704                                         StringRef Name,
705                                         DIFile F,
706                                         unsigned LineNumber,
707                                         uint64_t SizeInBits,
708                                         uint64_t AlignInBits,
709                                         uint64_t OffsetInBits, unsigned Flags,
710                                         DIType DerivedFrom,
711                                         DIArray Elements,
712                                         unsigned RunTimeLang = 0,
713                                         MDNode *ContainingType = 0);
714
715     /// CreateTemporaryType - Create a temporary forward-declared type.
716     DIType CreateTemporaryType();
717
718     /// CreateArtificialType - Create a new DIType with "artificial" flag set.
719     DIType CreateArtificialType(DIType Ty);
720
721     /// CreateCompositeType - Create a composite type like array, struct, etc.
722     DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
723                                           StringRef Name,
724                                           DIFile F,
725                                           unsigned LineNumber,
726                                           Constant *SizeInBits,
727                                           Constant *AlignInBits,
728                                           Constant *OffsetInBits, 
729                                           unsigned Flags,
730                                           DIType DerivedFrom,
731                                           DIArray Elements,
732                                           unsigned RunTimeLang = 0,
733                                           MDNode *ContainingType = 0);
734
735     /// CreateSubprogram - Create a new descriptor for the specified subprogram.
736     /// See comments in DISubprogram for descriptions of these fields.
737     DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
738                                   StringRef DisplayName,
739                                   StringRef LinkageName,
740                                   DIFile F, unsigned LineNo,
741                                   DIType Ty, bool isLocalToUnit,
742                                   bool isDefinition,
743                                   unsigned VK = 0,
744                                   unsigned VIndex = 0,
745                                   DIType ContainingType = DIType(),
746                                   unsigned Flags = 0,
747                                   bool isOptimized = false,
748                                   Function *Fn = 0);
749
750     /// CreateSubprogramDefinition - Create new subprogram descriptor for the
751     /// given declaration. 
752     DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
753
754     /// CreateGlobalVariable - Create a new descriptor for the specified global.
755     DIGlobalVariable
756     CreateGlobalVariable(DIDescriptor Context, StringRef Name,
757                          StringRef DisplayName,
758                          StringRef LinkageName,
759                          DIFile F,
760                          unsigned LineNo, DIType Ty, bool isLocalToUnit,
761                          bool isDefinition, llvm::GlobalVariable *GV);
762
763     /// CreateGlobalVariable - Create a new descriptor for the specified constant.
764     DIGlobalVariable
765     CreateGlobalVariable(DIDescriptor Context, StringRef Name,
766                          StringRef DisplayName,
767                          StringRef LinkageName,
768                          DIFile F,
769                          unsigned LineNo, DIType Ty, bool isLocalToUnit,
770                          bool isDefinition, llvm::Constant *C);
771
772     /// CreateVariable - Create a new descriptor for the specified variable.
773     DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
774                               StringRef Name,
775                               DIFile F, unsigned LineNo,
776                               DIType Ty, bool AlwaysPreserve = false,
777                               unsigned Flags = 0);
778
779     /// CreateComplexVariable - Create a new descriptor for the specified
780     /// variable which has a complex address expression for its address.
781     DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
782                                      StringRef Name, DIFile F, unsigned LineNo,
783                                      DIType Ty, Value *const *Addr,
784                                      unsigned NumAddr);
785
786     /// CreateLexicalBlock - This creates a descriptor for a lexical block
787     /// with the specified parent context.
788     DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
789                                       unsigned Line = 0, unsigned Col = 0);
790
791     /// CreateNameSpace - This creates new descriptor for a namespace
792     /// with the specified parent context.
793     DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
794                                 DIFile F, unsigned LineNo);
795
796     /// CreateLocation - Creates a debug info location.
797     DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
798                               DIScope S, DILocation OrigLoc);
799
800     /// CreateLocation - Creates a debug info location.
801     DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
802                               DIScope S, MDNode *OrigLoc = 0);
803
804     /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
805     Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
806                                BasicBlock *InsertAtEnd);
807
808     /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
809     Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
810                                Instruction *InsertBefore);
811
812     /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
813     Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
814                                          DIVariable D, BasicBlock *InsertAtEnd);
815
816     /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
817     Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
818                                        DIVariable D, Instruction *InsertBefore);
819
820     // RecordType - Record DIType in a module such that it is not lost even if
821     // it is not referenced through debug info anchors.
822     void RecordType(DIType T);
823
824   private:
825     Constant *GetTagConstant(unsigned TAG);
826   };
827
828   bool getLocationInfo(const Value *V, std::string &DisplayName,
829                        std::string &Type, unsigned &LineNo, std::string &File,
830                        std::string &Dir);
831
832   /// getDISubprogram - Find subprogram that is enclosing this scope.
833   DISubprogram getDISubprogram(const MDNode *Scope);
834
835   /// getDICompositeType - Find underlying composite type.
836   DICompositeType getDICompositeType(DIType T);
837
838   class DebugInfoFinder {
839   public:
840     /// processModule - Process entire module and collect debug info
841     /// anchors.
842     void processModule(Module &M);
843
844   private:
845     /// processType - Process DIType.
846     void processType(DIType DT);
847
848     /// processLexicalBlock - Process DILexicalBlock.
849     void processLexicalBlock(DILexicalBlock LB);
850
851     /// processSubprogram - Process DISubprogram.
852     void processSubprogram(DISubprogram SP);
853
854     /// processDeclare - Process DbgDeclareInst.
855     void processDeclare(DbgDeclareInst *DDI);
856
857     /// processLocation - Process DILocation.
858     void processLocation(DILocation Loc);
859
860     /// addCompileUnit - Add compile unit into CUs.
861     bool addCompileUnit(DICompileUnit CU);
862
863     /// addGlobalVariable - Add global variable into GVs.
864     bool addGlobalVariable(DIGlobalVariable DIG);
865
866     // addSubprogram - Add subprgoram into SPs.
867     bool addSubprogram(DISubprogram SP);
868
869     /// addType - Add type into Tys.
870     bool addType(DIType DT);
871
872   public:
873     typedef SmallVector<MDNode *, 8>::const_iterator iterator;
874     iterator compile_unit_begin()    const { return CUs.begin(); }
875     iterator compile_unit_end()      const { return CUs.end(); }
876     iterator subprogram_begin()      const { return SPs.begin(); }
877     iterator subprogram_end()        const { return SPs.end(); }
878     iterator global_variable_begin() const { return GVs.begin(); }
879     iterator global_variable_end()   const { return GVs.end(); }
880     iterator type_begin()            const { return TYs.begin(); }
881     iterator type_end()              const { return TYs.end(); }
882
883     unsigned compile_unit_count()    const { return CUs.size(); }
884     unsigned global_variable_count() const { return GVs.size(); }
885     unsigned subprogram_count()      const { return SPs.size(); }
886     unsigned type_count()            const { return TYs.size(); }
887
888   private:
889     SmallVector<MDNode *, 8> CUs;  // Compile Units
890     SmallVector<MDNode *, 8> SPs;  // Subprograms
891     SmallVector<MDNode *, 8> GVs;  // Global Variables;
892     SmallVector<MDNode *, 8> TYs;  // Types
893     SmallPtrSet<MDNode *, 64> NodesSeen;
894   };
895 } // end namespace llvm
896
897 #endif