1 //===--- llvm/Analysis/DIBuilder.h - Debug Information Builder --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a DIBuilder that is useful for creating debugging
11 // information entries in LLVM IR form.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_DIBUILDER_H
16 #define LLVM_ANALYSIS_DIBUILDER_H
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/StringRef.h"
36 class DIGlobalVariable;
42 class DITemplateTypeParameter;
43 class DITemplateValueParameter;
48 LLVMContext & VMContext;
51 MDNode *TempEnumTypes;
52 MDNode *TempRetainTypes;
53 MDNode *TempSubprograms;
56 Function *DeclareFn; // llvm.dbg.declare
57 Function *ValueFn; // llvm.dbg.value
59 SmallVector<Value *, 4> AllEnumTypes;
60 SmallVector<Value *, 4> AllRetainTypes;
61 SmallVector<Value *, 4> AllSubprograms;
62 SmallVector<Value *, 4> AllGVs;
64 DIBuilder(const DIBuilder &); // DO NOT IMPLEMENT
65 void operator=(const DIBuilder &); // DO NOT IMPLEMENT
68 explicit DIBuilder(Module &M);
69 const MDNode *getCU() { return TheCU; }
70 enum ComplexAddrKind { OpPlus=1, OpDeref };
72 /// finalize - Construct any deferred debug info descriptors.
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
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
89 void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
91 bool isOptimized, StringRef Flags, unsigned RV);
93 /// createFile - Create a file descriptor to hold debugging information
95 DIFile createFile(StringRef Filename, StringRef Directory);
97 /// createEnumerator - Create a single enumerator value.
98 DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
100 /// createNullPtrType - Create C++0x nullptr type.
101 DIType createNullPtrType(StringRef Name);
103 /// createBasicType - Create debugging information entry for a basic
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);
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);
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());
127 /// createReferenceType - Create debugging information entry for a c++
129 DIType createReferenceType(DIType RTy);
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);
140 /// createFriend - Create debugging information entry for a 'friend'.
141 DIType createFriend(DIType Ty, DIType FriendTy);
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,
150 DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
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);
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
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);
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
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);
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);
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);
244 /// createTemplateTypeParameter - Create debugging information for template
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);
257 /// createTemplateValueParameter - Create debugging information for template
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,
269 MDNode *File = 0, unsigned LineNo = 0,
270 unsigned ColumnNo = 0);
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);
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);
288 /// createEnumerationType - Create debugging information entry for an
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,
300 uint64_t AlignInBits, DIArray Elements);
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);
308 /// createArtificialType - Create a new DIType with "artificial" flag set.
309 DIType createArtificialType(DIType Ty);
311 /// createTemporaryType - Create a temporary forward-declared type.
312 DIType createTemporaryType();
313 DIType createTemporaryType(DIFile F);
315 /// retainType - Retain DIType in a module even if it is not referenced
316 /// through debug info anchors.
317 void retainType(DIType T);
319 /// createUnspecifiedParameter - Create unspeicified type descriptor
320 /// for a subroutine type.
321 DIDescriptor createUnspecifiedParameter();
323 /// getOrCreateArray - Get a DIArray, create one if required.
324 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
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);
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.
339 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
340 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
343 /// createStaticVariable - Create a new descriptor for the specified
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.
355 createStaticVariable(DIDescriptor Context, StringRef Name,
356 StringRef LinkageName, DIFile File, unsigned LineNo,
357 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
360 /// createLocalVariable - Create a new descriptor for the specified
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,
376 DIFile File, unsigned LineNo,
377 DIType Ty, bool AlwaysPreserve = false,
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,
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,
420 bool isOptimized = false,
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,
449 unsigned Virtuality = 0, unsigned VTableIndex = 0,
450 MDNode *VTableHolder = 0,
452 bool isOptimized = false,
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);
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);
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);
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);
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,
497 BasicBlock *InsertAtEnd);
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,
506 Instruction *InsertBefore);
509 } // end namespace llvm