Add support to emit debug info for C++0x nullptr type.
[oota-llvm.git] / include / llvm / Analysis / DIBuilder.h
1 //===--- llvm/Analysis/DIBuilder.h - Debug Information Builder --*- 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 DIBuilder that is useful for creating debugging 
11 // information entries in LLVM IR form.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_ANALYSIS_DIBUILDER_H
16 #define LLVM_ANALYSIS_DIBUILDER_H
17
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/StringRef.h"
21
22 namespace llvm {
23   class BasicBlock;
24   class Instruction;
25   class Function;
26   class Module;
27   class Value;
28   class LLVMContext;
29   class MDNode;
30   class StringRef;
31   class DIDescriptor;
32   class DIFile;
33   class DIEnumerator;
34   class DIType;
35   class DIArray;
36   class DIGlobalVariable;
37   class DINameSpace;
38   class DIVariable;
39   class DISubrange;
40   class DILexicalBlock;
41   class DISubprogram;
42   class DITemplateTypeParameter;
43   class DITemplateValueParameter;
44
45   class DIBuilder {
46     private:
47     Module &M;
48     LLVMContext & VMContext;
49     MDNode *TheCU;
50
51     MDNode *TempEnumTypes;
52     MDNode *TempRetainTypes;
53     MDNode *TempSubprograms;
54     MDNode *TempGVs;
55
56     Function *DeclareFn;     // llvm.dbg.declare
57     Function *ValueFn;       // llvm.dbg.value
58
59     SmallVector<Value *, 4> AllEnumTypes;
60     SmallVector<Value *, 4> AllRetainTypes;
61     SmallVector<Value *, 4> AllSubprograms;
62     SmallVector<Value *, 4> AllGVs;
63
64     DIBuilder(const DIBuilder &);       // DO NOT IMPLEMENT
65     void operator=(const DIBuilder &);  // DO NOT IMPLEMENT
66
67     public:
68     explicit DIBuilder(Module &M);
69     const MDNode *getCU() { return TheCU; }
70     enum ComplexAddrKind { OpPlus=1, OpDeref };
71
72     /// finalize - Construct any deferred debug info descriptors.
73     void finalize();
74
75     /// createCompileUnit - A CompileUnit provides an anchor for all debugging
76     /// information generated during this instance of compilation.
77     /// @param Lang     Source programming language, eg. dwarf::DW_LANG_C99
78     /// @param File     File name
79     /// @param Dir      Directory
80     /// @param Producer String identify producer of debugging information. 
81     ///                 Usuall this is a compiler version string.
82     /// @param isOptimized A boolean flag which indicates whether optimization
83     ///                    is ON or not.
84     /// @param Flags    This string lists command line options. This string is 
85     ///                 directly embedded in debug info output which may be used
86     ///                 by a tool analyzing generated debugging information.
87     /// @param RV       This indicates runtime version for languages like 
88     ///                 Objective-C.
89     void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir, 
90                            StringRef Producer,
91                            bool isOptimized, StringRef Flags, unsigned RV);
92
93     /// createFile - Create a file descriptor to hold debugging information
94     /// for a file.
95     DIFile createFile(StringRef Filename, StringRef Directory);
96                            
97     /// createEnumerator - Create a single enumerator value.
98     DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
99
100     /// createNullPtrType - Create C++0x nullptr type.
101     DIType createNullPtrType(StringRef Name);
102
103     /// createBasicType - Create debugging information entry for a basic 
104     /// type.
105     /// @param Name        Type name.
106     /// @param SizeInBits  Size of the type.
107     /// @param AlignInBits Type alignment.
108     /// @param Encoding    DWARF encoding code, e.g. dwarf::DW_ATE_float.
109     DIType createBasicType(StringRef Name, uint64_t SizeInBits, 
110                            uint64_t AlignInBits, unsigned Encoding);
111
112     /// createQualifiedType - Create debugging information entry for a qualified
113     /// type, e.g. 'const int'.
114     /// @param Tag         Tag identifing type, e.g. dwarf::TAG_volatile_type
115     /// @param FromTy      Base Type.
116     DIType createQualifiedType(unsigned Tag, DIType FromTy);
117
118     /// createPointerType - Create debugging information entry for a pointer.
119     /// @param PointeeTy   Type pointed by this pointer.
120     /// @param SizeInBits  Size.
121     /// @param AlignInBits Alignment. (optional)
122     /// @param Name        Pointer type name. (optional)
123     DIType createPointerType(DIType PointeeTy, uint64_t SizeInBits,
124                              uint64_t AlignInBits = 0, 
125                              StringRef Name = StringRef());
126
127     /// createReferenceType - Create debugging information entry for a c++
128     /// style reference.
129     DIType createReferenceType(DIType RTy);
130
131     /// createTypedef - Create debugging information entry for a typedef.
132     /// @param Ty          Original type.
133     /// @param Name        Typedef name.
134     /// @param File        File where this type is defined.
135     /// @param LineNo      Line number.
136     /// @param Context     The surrounding context for the typedef.
137     DIType createTypedef(DIType Ty, StringRef Name, DIFile File, 
138                          unsigned LineNo, DIDescriptor Context);
139
140     /// createFriend - Create debugging information entry for a 'friend'.
141     DIType createFriend(DIType Ty, DIType FriendTy);
142
143     /// createInheritance - Create debugging information entry to establish
144     /// inheritance relationship between two types.
145     /// @param Ty           Original type.
146     /// @param BaseTy       Base type. Ty is inherits from base.
147     /// @param BaseOffset   Base offset.
148     /// @param Flags        Flags to describe inheritance attribute, 
149     ///                     e.g. private
150     DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
151                              unsigned Flags);
152
153     /// createMemberType - Create debugging information entry for a member.
154     /// @param Scope        Member scope.
155     /// @param Name         Member name.
156     /// @param File         File where this member is defined.
157     /// @param LineNo       Line number.
158     /// @param SizeInBits   Member size.
159     /// @param AlignInBits  Member alignment.
160     /// @param OffsetInBits Member offset.
161     /// @param Flags        Flags to encode member attribute, e.g. private
162     /// @param Ty           Parent type.
163     DIType createMemberType(DIDescriptor Scope, StringRef Name, DIFile File,
164                             unsigned LineNo, uint64_t SizeInBits, 
165                             uint64_t AlignInBits, uint64_t OffsetInBits, 
166                             unsigned Flags, DIType Ty);
167
168     /// createObjCIVar - Create debugging information entry for Objective-C
169     /// instance variable.
170     /// @param Name         Member name.
171     /// @param File         File where this member is defined.
172     /// @param LineNo       Line number.
173     /// @param SizeInBits   Member size.
174     /// @param AlignInBits  Member alignment.
175     /// @param OffsetInBits Member offset.
176     /// @param Flags        Flags to encode member attribute, e.g. private
177     /// @param Ty           Parent type.
178     /// @param PropertyName Name of the Objective C property assoicated with
179     ///                     this ivar.
180     /// @param GetterName   Name of the Objective C property getter selector.
181     /// @param SetterName   Name of the Objective C property setter selector.
182     /// @param PropertyAttributes Objective C property attributes.
183     DIType createObjCIVar(StringRef Name, DIFile File,
184                           unsigned LineNo, uint64_t SizeInBits, 
185                           uint64_t AlignInBits, uint64_t OffsetInBits, 
186                           unsigned Flags, DIType Ty,
187                           StringRef PropertyName = StringRef(),
188                           StringRef PropertyGetterName = StringRef(),
189                           StringRef PropertySetterName = StringRef(),
190                           unsigned PropertyAttributes = 0);
191
192     /// createClassType - Create debugging information entry for a class.
193     /// @param Scope        Scope in which this class is defined.
194     /// @param Name         class name.
195     /// @param File         File where this member is defined.
196     /// @param LineNo       Line number.
197     /// @param SizeInBits   Member size.
198     /// @param AlignInBits  Member alignment.
199     /// @param OffsetInBits Member offset.
200     /// @param Flags        Flags to encode member attribute, e.g. private
201     /// @param Elements     class members.
202     /// @param VTableHolder Debug info of the base class that contains vtable
203     ///                     for this type. This is used in 
204     ///                     DW_AT_containing_type. See DWARF documentation
205     ///                     for more info.
206     /// @param TemplateParms Template type parameters.
207     DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
208                            unsigned LineNumber, uint64_t SizeInBits,
209                            uint64_t AlignInBits, uint64_t OffsetInBits,
210                            unsigned Flags, DIType DerivedFrom, 
211                            DIArray Elements, MDNode *VTableHolder = 0,
212                            MDNode *TemplateParms = 0);
213
214     /// createStructType - Create debugging information entry for a struct.
215     /// @param Scope        Scope in which this struct is defined.
216     /// @param Name         Struct name.
217     /// @param File         File where this member is defined.
218     /// @param LineNo       Line number.
219     /// @param SizeInBits   Member size.
220     /// @param AlignInBits  Member alignment.
221     /// @param Flags        Flags to encode member attribute, e.g. private
222     /// @param Elements     Struct elements.
223     /// @param RunTimeLang  Optional parameter, Objective-C runtime version.
224     DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
225                             unsigned LineNumber, uint64_t SizeInBits,
226                             uint64_t AlignInBits, unsigned Flags,
227                             DIArray Elements, unsigned RunTimeLang = 0);
228
229     /// createUnionType - Create debugging information entry for an union.
230     /// @param Scope        Scope in which this union is defined.
231     /// @param Name         Union name.
232     /// @param File         File where this member is defined.
233     /// @param LineNo       Line number.
234     /// @param SizeInBits   Member size.
235     /// @param AlignInBits  Member alignment.
236     /// @param Flags        Flags to encode member attribute, e.g. private
237     /// @param Elements     Union elements.
238     /// @param RunTimeLang  Optional parameter, Objective-C runtime version.
239     DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
240                            unsigned LineNumber, uint64_t SizeInBits,
241                            uint64_t AlignInBits, unsigned Flags,
242                            DIArray Elements, unsigned RunTimeLang = 0);
243
244     /// createTemplateTypeParameter - Create debugging information for template
245     /// type parameter.
246     /// @param Scope        Scope in which this type is defined.
247     /// @param Name         Type parameter name.
248     /// @param Ty           Parameter type.
249     /// @param File         File where this type parameter is defined.
250     /// @param LineNo       Line number.
251     /// @param ColumnNo     Column Number.
252     DITemplateTypeParameter
253     createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
254                                 MDNode *File = 0, unsigned LineNo = 0,
255                                 unsigned ColumnNo = 0);
256
257     /// createTemplateValueParameter - Create debugging information for template
258     /// value parameter.
259     /// @param Scope        Scope in which this type is defined.
260     /// @param Name         Value parameter name.
261     /// @param Ty           Parameter type.
262     /// @param Value        Constant parameter value.
263     /// @param File         File where this type parameter is defined.
264     /// @param LineNo       Line number.
265     /// @param ColumnNo     Column Number.
266     DITemplateValueParameter
267     createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
268                                  uint64_t Value,
269                                  MDNode *File = 0, unsigned LineNo = 0,
270                                  unsigned ColumnNo = 0);
271
272     /// createArrayType - Create debugging information entry for an array.
273     /// @param Size         Array size.
274     /// @param AlignInBits  Alignment.
275     /// @param Ty           Element type.
276     /// @param Subscripts   Subscripts.
277     DIType createArrayType(uint64_t Size, uint64_t AlignInBits, 
278                            DIType Ty, DIArray Subscripts);
279
280     /// createVectorType - Create debugging information entry for a vector type.
281     /// @param Size         Array size.
282     /// @param AlignInBits  Alignment.
283     /// @param Ty           Element type.
284     /// @param Subscripts   Subscripts.
285     DIType createVectorType(uint64_t Size, uint64_t AlignInBits, 
286                             DIType Ty, DIArray Subscripts);
287
288     /// createEnumerationType - Create debugging information entry for an 
289     /// enumeration.
290     /// @param Scope        Scope in which this enumeration is defined.
291     /// @param Name         Union name.
292     /// @param File         File where this member is defined.
293     /// @param LineNo       Line number.
294     /// @param SizeInBits   Member size.
295     /// @param AlignInBits  Member alignment.
296     /// @param Elements     Enumeration elements.
297     DIType createEnumerationType(DIDescriptor Scope, StringRef Name, 
298                                  DIFile File, unsigned LineNumber, 
299                                  uint64_t SizeInBits, 
300                                  uint64_t AlignInBits, DIArray Elements);
301
302     /// createSubroutineType - Create subroutine type.
303     /// @param File          File in which this subroutine is defined.
304     /// @param ParamterTypes An array of subroutine parameter types. This
305     ///                      includes return type at 0th index.
306     DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
307
308     /// createArtificialType - Create a new DIType with "artificial" flag set.
309     DIType createArtificialType(DIType Ty);
310
311     /// createTemporaryType - Create a temporary forward-declared type.
312     DIType createTemporaryType();
313     DIType createTemporaryType(DIFile F);
314
315     /// retainType - Retain DIType in a module even if it is not referenced 
316     /// through debug info anchors.
317     void retainType(DIType T);
318
319     /// createUnspecifiedParameter - Create unspeicified type descriptor
320     /// for a subroutine type.
321     DIDescriptor createUnspecifiedParameter();
322
323     /// getOrCreateArray - Get a DIArray, create one if required.
324     DIArray getOrCreateArray(ArrayRef<Value *> Elements);
325
326     /// getOrCreateSubrange - Create a descriptor for a value range.  This
327     /// implicitly uniques the values returned.
328     DISubrange getOrCreateSubrange(int64_t Lo, int64_t Hi);
329
330     /// createGlobalVariable - Create a new descriptor for the specified global.
331     /// @param Name        Name of the variable.
332     /// @param File        File where this variable is defined.
333     /// @param LineNo      Line number.
334     /// @param Ty          Variable Type.
335     /// @param isLocalToUnit Boolean flag indicate whether this variable is
336     ///                      externally visible or not.
337     /// @param Val         llvm::Value of the variable.
338     DIGlobalVariable
339     createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
340                          DIType Ty, bool isLocalToUnit, llvm::Value *Val);
341
342
343     /// createStaticVariable - Create a new descriptor for the specified 
344     /// variable.
345     /// @param Conext      Variable scope. 
346     /// @param Name        Name of the variable.
347     /// @param LinakgeName Mangled  name of the variable.
348     /// @param File        File where this variable is defined.
349     /// @param LineNo      Line number.
350     /// @param Ty          Variable Type.
351     /// @param isLocalToUnit Boolean flag indicate whether this variable is
352     ///                      externally visible or not.
353     /// @param Val         llvm::Value of the variable.
354     DIGlobalVariable
355     createStaticVariable(DIDescriptor Context, StringRef Name, 
356                          StringRef LinkageName, DIFile File, unsigned LineNo, 
357                          DIType Ty, bool isLocalToUnit, llvm::Value *Val);
358
359
360     /// createLocalVariable - Create a new descriptor for the specified 
361     /// local variable.
362     /// @param Tag         Dwarf TAG. Usually DW_TAG_auto_variable or
363     ///                    DW_TAG_arg_variable.
364     /// @param Scope       Variable scope.
365     /// @param Name        Variable name.
366     /// @param File        File where this variable is defined.
367     /// @param LineNo      Line number.
368     /// @param Ty          Variable Type
369     /// @param AlwaysPreserve Boolean. Set to true if debug info for this
370     ///                       variable should be preserved in optimized build.
371     /// @param Flags          Flags, e.g. artificial variable.
372     /// @param ArgNo       If this variable is an arugment then this argument's
373     ///                    number. 1 indicates 1st argument.
374     DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
375                                    StringRef Name,
376                                    DIFile File, unsigned LineNo,
377                                    DIType Ty, bool AlwaysPreserve = false,
378                                    unsigned Flags = 0,
379                                    unsigned ArgNo = 0);
380
381
382     /// createComplexVariable - Create a new descriptor for the specified
383     /// variable which has a complex address expression for its address.
384     /// @param Tag         Dwarf TAG. Usually DW_TAG_auto_variable or
385     ///                    DW_TAG_arg_variable.
386     /// @param Scope       Variable scope.
387     /// @param Name        Variable name.
388     /// @param File        File where this variable is defined.
389     /// @param LineNo      Line number.
390     /// @param Ty          Variable Type
391     /// @param Addr        An array of complex address operations.
392     /// @param ArgNo       If this variable is an arugment then this argument's
393     ///                    number. 1 indicates 1st argument.
394     DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
395                                      StringRef Name, DIFile F, unsigned LineNo,
396                                      DIType Ty, ArrayRef<Value *> Addr,
397                                      unsigned ArgNo = 0);
398
399     /// createFunction - Create a new descriptor for the specified subprogram.
400     /// See comments in DISubprogram for descriptions of these fields.
401     /// @param Scope         Function scope.
402     /// @param Name          Function name.
403     /// @param LinkageName   Mangled function name.
404     /// @param File          File where this variable is defined.
405     /// @param LineNo        Line number.
406     /// @param Ty            Function type.
407     /// @param isLocalToUnit True if this function is not externally visible..
408     /// @param isDefinition  True if this is a function definition.
409     /// @param Flags         e.g. is this function prototyped or not.
410     ///                      This flags are used to emit dwarf attributes.
411     /// @param isOptimized   True if optimization is ON.
412     /// @param Fn            llvm::Function pointer.
413     /// @param TParam        Function template parameters.
414     DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
415                                 StringRef LinkageName,
416                                 DIFile File, unsigned LineNo,
417                                 DIType Ty, bool isLocalToUnit,
418                                 bool isDefinition,
419                                 unsigned Flags = 0,
420                                 bool isOptimized = false,
421                                 Function *Fn = 0,
422                                 MDNode *TParam = 0,
423                                 MDNode *Decl = 0);
424
425     /// createMethod - Create a new descriptor for the specified C++ method.
426     /// See comments in DISubprogram for descriptions of these fields.
427     /// @param Scope         Function scope.
428     /// @param Name          Function name.
429     /// @param LinkageName   Mangled function name.
430     /// @param File          File where this variable is defined.
431     /// @param LineNo        Line number.
432     /// @param Ty            Function type.
433     /// @param isLocalToUnit True if this function is not externally visible..
434     /// @param isDefinition  True if this is a function definition.
435     /// @param Virtuality    Attributes describing virtualness. e.g. pure 
436     ///                      virtual function.
437     /// @param VTableIndex   Index no of this method in virtual table.
438     /// @param VTableHolder  Type that holds vtable.
439     /// @param Flags         e.g. is this function prototyped or not.
440     ///                      This flags are used to emit dwarf attributes.
441     /// @param isOptimized   True if optimization is ON.
442     /// @param Fn            llvm::Function pointer.
443     /// @param TParam        Function template parameters.
444     DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
445                               StringRef LinkageName,
446                               DIFile File, unsigned LineNo,
447                               DIType Ty, bool isLocalToUnit,
448                               bool isDefinition,
449                               unsigned Virtuality = 0, unsigned VTableIndex = 0,
450                               MDNode *VTableHolder = 0,
451                               unsigned Flags = 0,
452                               bool isOptimized = false,
453                               Function *Fn = 0,
454                               MDNode *TParam = 0);
455
456     /// createNameSpace - This creates new descriptor for a namespace
457     /// with the specified parent scope.
458     /// @param Scope       Namespace scope
459     /// @param Name        Name of this namespace
460     /// @param File        Source file
461     /// @param LineNo      Line number
462     DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
463                                 DIFile File, unsigned LineNo);
464
465
466     /// createLexicalBlock - This creates a descriptor for a lexical block
467     /// with the specified parent context.
468     /// @param Scope       Parent lexical scope.
469     /// @param File        Source file
470     /// @param Line        Line number
471     /// @param Col         Column number
472     DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
473                                       unsigned Line, unsigned Col);
474
475     /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
476     /// @param Storage     llvm::Value of the variable
477     /// @param VarInfo     Variable's debug info descriptor.
478     /// @param InsertAtEnd Location for the new intrinsic.
479     Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
480                                BasicBlock *InsertAtEnd);
481
482     /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
483     /// @param Storage      llvm::Value of the variable
484     /// @param VarInfo      Variable's debug info descriptor.
485     /// @param InsertBefore Location for the new intrinsic.
486     Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
487                                Instruction *InsertBefore);
488
489
490     /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
491     /// @param Val          llvm::Value of the variable
492     /// @param Offset       Offset
493     /// @param VarInfo      Variable's debug info descriptor.
494     /// @param InsertAtEnd Location for the new intrinsic.
495     Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
496                                          DIVariable VarInfo, 
497                                          BasicBlock *InsertAtEnd);
498     
499     /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
500     /// @param Val          llvm::Value of the variable
501     /// @param Offset       Offset
502     /// @param VarInfo      Variable's debug info descriptor.
503     /// @param InsertBefore Location for the new intrinsic.
504     Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
505                                          DIVariable VarInfo, 
506                                          Instruction *InsertBefore);
507
508   };
509 } // end namespace llvm
510
511 #endif