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;
40 class DILexicalBlockFile;
43 class DITemplateTypeParameter;
44 class DITemplateValueParameter;
50 LLVMContext & VMContext;
53 MDNode *TempEnumTypes;
54 MDNode *TempRetainTypes;
55 MDNode *TempSubprograms;
58 Function *DeclareFn; // llvm.dbg.declare
59 Function *ValueFn; // llvm.dbg.value
61 SmallVector<Value *, 4> AllEnumTypes;
62 SmallVector<Value *, 4> AllRetainTypes;
63 SmallVector<Value *, 4> AllSubprograms;
64 SmallVector<Value *, 4> AllGVs;
66 DIBuilder(const DIBuilder &); // DO NOT IMPLEMENT
67 void operator=(const DIBuilder &); // DO NOT IMPLEMENT
70 explicit DIBuilder(Module &M);
71 const MDNode *getCU() { return TheCU; }
72 enum ComplexAddrKind { OpPlus=1, OpDeref };
74 /// finalize - Construct any deferred debug info descriptors.
77 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
78 /// information generated during this instance of compilation.
79 /// @param Lang Source programming language, eg. dwarf::DW_LANG_C99
80 /// @param File File name
81 /// @param Dir Directory
82 /// @param Producer String identify producer of debugging information.
83 /// Usuall this is a compiler version string.
84 /// @param isOptimized A boolean flag which indicates whether optimization
86 /// @param Flags This string lists command line options. This string is
87 /// directly embedded in debug info output which may be used
88 /// by a tool analyzing generated debugging information.
89 /// @param RV This indicates runtime version for languages like
91 void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
93 bool isOptimized, StringRef Flags, unsigned RV);
95 /// createFile - Create a file descriptor to hold debugging information
97 DIFile createFile(StringRef Filename, StringRef Directory);
99 /// createEnumerator - Create a single enumerator value.
100 DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
102 /// createNullPtrType - Create C++0x nullptr type.
103 DIType createNullPtrType(StringRef Name);
105 /// createBasicType - Create debugging information entry for a basic
107 /// @param Name Type name.
108 /// @param SizeInBits Size of the type.
109 /// @param AlignInBits Type alignment.
110 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
111 DIType createBasicType(StringRef Name, uint64_t SizeInBits,
112 uint64_t AlignInBits, unsigned Encoding);
114 /// createQualifiedType - Create debugging information entry for a qualified
115 /// type, e.g. 'const int'.
116 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
117 /// @param FromTy Base Type.
118 DIType createQualifiedType(unsigned Tag, DIType FromTy);
120 /// createPointerType - Create debugging information entry for a pointer.
121 /// @param PointeeTy Type pointed by this pointer.
122 /// @param SizeInBits Size.
123 /// @param AlignInBits Alignment. (optional)
124 /// @param Name Pointer type name. (optional)
125 DIType createPointerType(DIType PointeeTy, uint64_t SizeInBits,
126 uint64_t AlignInBits = 0,
127 StringRef Name = StringRef());
129 /// createReferenceType - Create debugging information entry for a c++
131 DIType createReferenceType(DIType RTy);
133 /// createTypedef - Create debugging information entry for a typedef.
134 /// @param Ty Original type.
135 /// @param Name Typedef name.
136 /// @param File File where this type is defined.
137 /// @param LineNo Line number.
138 /// @param Context The surrounding context for the typedef.
139 DIType createTypedef(DIType Ty, StringRef Name, DIFile File,
140 unsigned LineNo, DIDescriptor Context);
142 /// createFriend - Create debugging information entry for a 'friend'.
143 DIType createFriend(DIType Ty, DIType FriendTy);
145 /// createInheritance - Create debugging information entry to establish
146 /// inheritance relationship between two types.
147 /// @param Ty Original type.
148 /// @param BaseTy Base type. Ty is inherits from base.
149 /// @param BaseOffset Base offset.
150 /// @param Flags Flags to describe inheritance attribute,
152 DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
155 /// createMemberType - Create debugging information entry for a member.
156 /// @param Scope Member scope.
157 /// @param Name Member name.
158 /// @param File File where this member is defined.
159 /// @param LineNo Line number.
160 /// @param SizeInBits Member size.
161 /// @param AlignInBits Member alignment.
162 /// @param OffsetInBits Member offset.
163 /// @param Flags Flags to encode member attribute, e.g. private
164 /// @param Ty Parent type.
165 DIType createMemberType(DIDescriptor Scope, StringRef Name, DIFile File,
166 unsigned LineNo, uint64_t SizeInBits,
167 uint64_t AlignInBits, uint64_t OffsetInBits,
168 unsigned Flags, DIType Ty);
170 /// createObjCIVar - Create debugging information entry for Objective-C
171 /// instance variable.
172 /// @param Name Member name.
173 /// @param File File where this member is defined.
174 /// @param LineNo Line number.
175 /// @param SizeInBits Member size.
176 /// @param AlignInBits Member alignment.
177 /// @param OffsetInBits Member offset.
178 /// @param Flags Flags to encode member attribute, e.g. private
179 /// @param Ty Parent type.
180 /// @param PropertyName Name of the Objective C property assoicated with
182 /// @param GetterName Name of the Objective C property getter selector.
183 /// @param SetterName Name of the Objective C property setter selector.
184 /// @param PropertyAttributes Objective C property attributes.
185 DIType createObjCIVar(StringRef Name, DIFile File,
186 unsigned LineNo, uint64_t SizeInBits,
187 uint64_t AlignInBits, uint64_t OffsetInBits,
188 unsigned Flags, DIType Ty,
189 StringRef PropertyName = StringRef(),
190 StringRef PropertyGetterName = StringRef(),
191 StringRef PropertySetterName = StringRef(),
192 unsigned PropertyAttributes = 0);
194 /// createObjCIVar - Create debugging information entry for Objective-C
195 /// instance variable.
196 /// @param Name Member name.
197 /// @param File File where this member is defined.
198 /// @param LineNo Line number.
199 /// @param SizeInBits Member size.
200 /// @param AlignInBits Member alignment.
201 /// @param OffsetInBits Member offset.
202 /// @param Flags Flags to encode member attribute, e.g. private
203 /// @param Ty Parent type.
204 /// @param Property Property associated with this ivar.
205 DIType createObjCIVar(StringRef Name, DIFile File,
206 unsigned LineNo, uint64_t SizeInBits,
207 uint64_t AlignInBits, uint64_t OffsetInBits,
208 unsigned Flags, DIType Ty,
209 MDNode *PropertyNode);
211 /// createObjCProperty - Create debugging information entry for Objective-C
213 /// @param Name Property name.
214 /// @param File File where this property is defined.
215 /// @param LineNumber Line number.
216 /// @param GetterName Name of the Objective C property getter selector.
217 /// @param SetterName Name of the Objective C property setter selector.
218 /// @param PropertyAttributes Objective C property attributes.
220 DIObjCProperty createObjCProperty(StringRef Name,
221 DIFile File, unsigned LineNumber,
222 StringRef GetterName,
223 StringRef SetterName,
224 unsigned PropertyAttributes,
227 /// createClassType - Create debugging information entry for a class.
228 /// @param Scope Scope in which this class is defined.
229 /// @param Name class name.
230 /// @param File File where this member is defined.
231 /// @param LineNo Line number.
232 /// @param SizeInBits Member size.
233 /// @param AlignInBits Member alignment.
234 /// @param OffsetInBits Member offset.
235 /// @param Flags Flags to encode member attribute, e.g. private
236 /// @param Elements class members.
237 /// @param VTableHolder Debug info of the base class that contains vtable
238 /// for this type. This is used in
239 /// DW_AT_containing_type. See DWARF documentation
241 /// @param TemplateParms Template type parameters.
242 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
243 unsigned LineNumber, uint64_t SizeInBits,
244 uint64_t AlignInBits, uint64_t OffsetInBits,
245 unsigned Flags, DIType DerivedFrom,
246 DIArray Elements, MDNode *VTableHolder = 0,
247 MDNode *TemplateParms = 0);
249 /// createStructType - Create debugging information entry for a struct.
250 /// @param Scope Scope in which this struct is defined.
251 /// @param Name Struct name.
252 /// @param File File where this member is defined.
253 /// @param LineNo Line number.
254 /// @param SizeInBits Member size.
255 /// @param AlignInBits Member alignment.
256 /// @param Flags Flags to encode member attribute, e.g. private
257 /// @param Elements Struct elements.
258 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
259 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
260 unsigned LineNumber, uint64_t SizeInBits,
261 uint64_t AlignInBits, unsigned Flags,
262 DIArray Elements, unsigned RunTimeLang = 0);
264 /// createUnionType - Create debugging information entry for an union.
265 /// @param Scope Scope in which this union is defined.
266 /// @param Name Union name.
267 /// @param File File where this member is defined.
268 /// @param LineNo Line number.
269 /// @param SizeInBits Member size.
270 /// @param AlignInBits Member alignment.
271 /// @param Flags Flags to encode member attribute, e.g. private
272 /// @param Elements Union elements.
273 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
274 DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
275 unsigned LineNumber, uint64_t SizeInBits,
276 uint64_t AlignInBits, unsigned Flags,
277 DIArray Elements, unsigned RunTimeLang = 0);
279 /// createTemplateTypeParameter - Create debugging information for template
281 /// @param Scope Scope in which this type is defined.
282 /// @param Name Type parameter name.
283 /// @param Ty Parameter type.
284 /// @param File File where this type parameter is defined.
285 /// @param LineNo Line number.
286 /// @param ColumnNo Column Number.
287 DITemplateTypeParameter
288 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
289 MDNode *File = 0, unsigned LineNo = 0,
290 unsigned ColumnNo = 0);
292 /// createTemplateValueParameter - Create debugging information for template
294 /// @param Scope Scope in which this type is defined.
295 /// @param Name Value parameter name.
296 /// @param Ty Parameter type.
297 /// @param Value Constant parameter value.
298 /// @param File File where this type parameter is defined.
299 /// @param LineNo Line number.
300 /// @param ColumnNo Column Number.
301 DITemplateValueParameter
302 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
304 MDNode *File = 0, unsigned LineNo = 0,
305 unsigned ColumnNo = 0);
307 /// createArrayType - Create debugging information entry for an array.
308 /// @param Size Array size.
309 /// @param AlignInBits Alignment.
310 /// @param Ty Element type.
311 /// @param Subscripts Subscripts.
312 DIType createArrayType(uint64_t Size, uint64_t AlignInBits,
313 DIType Ty, DIArray Subscripts);
315 /// createVectorType - Create debugging information entry for a vector type.
316 /// @param Size Array size.
317 /// @param AlignInBits Alignment.
318 /// @param Ty Element type.
319 /// @param Subscripts Subscripts.
320 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
321 DIType Ty, DIArray Subscripts);
323 /// createEnumerationType - Create debugging information entry for an
325 /// @param Scope Scope in which this enumeration is defined.
326 /// @param Name Union name.
327 /// @param File File where this member is defined.
328 /// @param LineNo Line number.
329 /// @param SizeInBits Member size.
330 /// @param AlignInBits Member alignment.
331 /// @param Elements Enumeration elements.
332 DIType createEnumerationType(DIDescriptor Scope, StringRef Name,
333 DIFile File, unsigned LineNumber,
335 uint64_t AlignInBits, DIArray Elements);
337 /// createSubroutineType - Create subroutine type.
338 /// @param File File in which this subroutine is defined.
339 /// @param ParamterTypes An array of subroutine parameter types. This
340 /// includes return type at 0th index.
341 DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
343 /// createArtificialType - Create a new DIType with "artificial" flag set.
344 DIType createArtificialType(DIType Ty);
346 /// createTemporaryType - Create a temporary forward-declared type.
347 DIType createTemporaryType();
348 DIType createTemporaryType(DIFile F);
350 /// createForwardDecl - Create a temporary forward-declared type.
351 DIType createForwardDecl(unsigned Tag, StringRef Name, DIFile F,
352 unsigned Line, unsigned RuntimeLang = 0);
354 /// retainType - Retain DIType in a module even if it is not referenced
355 /// through debug info anchors.
356 void retainType(DIType T);
358 /// createUnspecifiedParameter - Create unspeicified type descriptor
359 /// for a subroutine type.
360 DIDescriptor createUnspecifiedParameter();
362 /// getOrCreateArray - Get a DIArray, create one if required.
363 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
365 /// getOrCreateSubrange - Create a descriptor for a value range. This
366 /// implicitly uniques the values returned.
367 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Hi);
369 /// createGlobalVariable - Create a new descriptor for the specified global.
370 /// @param Name Name of the variable.
371 /// @param File File where this variable is defined.
372 /// @param LineNo Line number.
373 /// @param Ty Variable Type.
374 /// @param isLocalToUnit Boolean flag indicate whether this variable is
375 /// externally visible or not.
376 /// @param Val llvm::Value of the variable.
378 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
379 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
382 /// createStaticVariable - Create a new descriptor for the specified
384 /// @param Conext Variable scope.
385 /// @param Name Name of the variable.
386 /// @param LinakgeName Mangled name of the variable.
387 /// @param File File where this variable is defined.
388 /// @param LineNo Line number.
389 /// @param Ty Variable Type.
390 /// @param isLocalToUnit Boolean flag indicate whether this variable is
391 /// externally visible or not.
392 /// @param Val llvm::Value of the variable.
394 createStaticVariable(DIDescriptor Context, StringRef Name,
395 StringRef LinkageName, DIFile File, unsigned LineNo,
396 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
399 /// createLocalVariable - Create a new descriptor for the specified
401 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
402 /// DW_TAG_arg_variable.
403 /// @param Scope Variable scope.
404 /// @param Name Variable name.
405 /// @param File File where this variable is defined.
406 /// @param LineNo Line number.
407 /// @param Ty Variable Type
408 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
409 /// variable should be preserved in optimized build.
410 /// @param Flags Flags, e.g. artificial variable.
411 /// @param ArgNo If this variable is an arugment then this argument's
412 /// number. 1 indicates 1st argument.
413 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
415 DIFile File, unsigned LineNo,
416 DIType Ty, bool AlwaysPreserve = false,
421 /// createComplexVariable - Create a new descriptor for the specified
422 /// variable which has a complex address expression for its address.
423 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
424 /// DW_TAG_arg_variable.
425 /// @param Scope Variable scope.
426 /// @param Name Variable name.
427 /// @param File File where this variable is defined.
428 /// @param LineNo Line number.
429 /// @param Ty Variable Type
430 /// @param Addr An array of complex address operations.
431 /// @param ArgNo If this variable is an arugment then this argument's
432 /// number. 1 indicates 1st argument.
433 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
434 StringRef Name, DIFile F, unsigned LineNo,
435 DIType Ty, ArrayRef<Value *> Addr,
438 /// createFunction - Create a new descriptor for the specified subprogram.
439 /// See comments in DISubprogram for descriptions of these fields.
440 /// @param Scope Function scope.
441 /// @param Name Function name.
442 /// @param LinkageName Mangled function name.
443 /// @param File File where this variable is defined.
444 /// @param LineNo Line number.
445 /// @param Ty Function type.
446 /// @param isLocalToUnit True if this function is not externally visible..
447 /// @param isDefinition True if this is a function definition.
448 /// @param ScopeLine Set to the beginning of the scope this starts
449 /// @param Flags e.g. is this function prototyped or not.
450 /// This flags are used to emit dwarf attributes.
451 /// @param isOptimized True if optimization is ON.
452 /// @param Fn llvm::Function pointer.
453 /// @param TParam Function template parameters.
454 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
455 StringRef LinkageName,
456 DIFile File, unsigned LineNo,
457 DIType Ty, bool isLocalToUnit,
461 bool isOptimized = false,
466 /// createMethod - Create a new descriptor for the specified C++ method.
467 /// See comments in DISubprogram for descriptions of these fields.
468 /// @param Scope Function scope.
469 /// @param Name Function name.
470 /// @param LinkageName Mangled function name.
471 /// @param File File where this variable is defined.
472 /// @param LineNo Line number.
473 /// @param Ty Function type.
474 /// @param isLocalToUnit True if this function is not externally visible..
475 /// @param isDefinition True if this is a function definition.
476 /// @param Virtuality Attributes describing virtualness. e.g. pure
477 /// virtual function.
478 /// @param VTableIndex Index no of this method in virtual table.
479 /// @param VTableHolder Type that holds vtable.
480 /// @param Flags e.g. is this function prototyped or not.
481 /// This flags are used to emit dwarf attributes.
482 /// @param isOptimized True if optimization is ON.
483 /// @param Fn llvm::Function pointer.
484 /// @param TParam Function template parameters.
485 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
486 StringRef LinkageName,
487 DIFile File, unsigned LineNo,
488 DIType Ty, bool isLocalToUnit,
490 unsigned Virtuality = 0, unsigned VTableIndex = 0,
491 MDNode *VTableHolder = 0,
493 bool isOptimized = false,
497 /// createNameSpace - This creates new descriptor for a namespace
498 /// with the specified parent scope.
499 /// @param Scope Namespace scope
500 /// @param Name Name of this namespace
501 /// @param File Source file
502 /// @param LineNo Line number
503 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
504 DIFile File, unsigned LineNo);
507 /// createLexicalBlockFile - This creates a descriptor for a lexical
508 /// block with a new file attached. This merely extends the existing
509 /// lexical block as it crosses a file.
510 /// @param Scope Lexical block.
511 /// @param File Source file.
512 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
515 /// createLexicalBlock - This creates a descriptor for a lexical block
516 /// with the specified parent context.
517 /// @param Scope Parent lexical scope.
518 /// @param File Source file
519 /// @param Line Line number
520 /// @param Col Column number
521 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
522 unsigned Line, unsigned Col);
524 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
525 /// @param Storage llvm::Value of the variable
526 /// @param VarInfo Variable's debug info descriptor.
527 /// @param InsertAtEnd Location for the new intrinsic.
528 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
529 BasicBlock *InsertAtEnd);
531 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
532 /// @param Storage llvm::Value of the variable
533 /// @param VarInfo Variable's debug info descriptor.
534 /// @param InsertBefore Location for the new intrinsic.
535 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
536 Instruction *InsertBefore);
539 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
540 /// @param Val llvm::Value of the variable
541 /// @param Offset Offset
542 /// @param VarInfo Variable's debug info descriptor.
543 /// @param InsertAtEnd Location for the new intrinsic.
544 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
546 BasicBlock *InsertAtEnd);
548 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
549 /// @param Val llvm::Value of the variable
550 /// @param Offset Offset
551 /// @param VarInfo Variable's debug info descriptor.
552 /// @param InsertBefore Location for the new intrinsic.
553 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
555 Instruction *InsertBefore);
558 } // end namespace llvm