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