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