1 //===- 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_IR_DIBUILDER_H
16 #define LLVM_IR_DIBUILDER_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/MapVector.h"
21 #include "llvm/ADT/None.h"
22 #include "llvm/ADT/SetVector.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/IR/DebugInfo.h"
26 #include "llvm/IR/DebugInfoMetadata.h"
27 #include "llvm/IR/TrackingMDRef.h"
28 #include "llvm/Support/Casting.h"
44 LLVMContext &VMContext;
46 DICompileUnit *CUNode; ///< The one compile unit created by this DIBuiler.
47 Function *DeclareFn; ///< llvm.dbg.declare
48 Function *ValueFn; ///< llvm.dbg.value
50 SmallVector<Metadata *, 4> AllEnumTypes;
51 /// Track the RetainTypes, since they can be updated later on.
52 SmallVector<TrackingMDNodeRef, 4> AllRetainTypes;
53 SmallVector<Metadata *, 4> AllSubprograms;
54 SmallVector<Metadata *, 4> AllGVs;
55 SmallVector<TrackingMDNodeRef, 4> AllImportedModules;
56 /// Map Macro parent (which can be DIMacroFile or nullptr) to a list of
57 /// Metadata all of type DIMacroNode.
58 /// DIMacroNode's with nullptr parent are DICompileUnit direct children.
59 MapVector<MDNode *, SetVector<Metadata *>> AllMacrosPerParent;
61 /// Track nodes that may be unresolved.
62 SmallVector<TrackingMDNodeRef, 4> UnresolvedNodes;
63 bool AllowUnresolvedNodes;
65 /// Each subprogram's preserved local variables.
67 /// Do not use a std::vector. Some versions of libc++ apparently copy
68 /// instead of move on grow operations, and TrackingMDRef is expensive to
70 DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> PreservedVariables;
72 /// Create a temporary.
74 /// Create an \a temporary node and track it in \a UnresolvedNodes.
75 void trackIfUnresolved(MDNode *N);
78 /// Construct a builder for a module.
80 /// If \c AllowUnresolved, collect unresolved nodes attached to the module
81 /// in order to resolve cycles during \a finalize().
82 explicit DIBuilder(Module &M, bool AllowUnresolved = true);
83 DIBuilder(const DIBuilder &) = delete;
84 DIBuilder &operator=(const DIBuilder &) = delete;
86 /// Construct any deferred debug info descriptors.
89 /// A CompileUnit provides an anchor for all debugging
90 /// information generated during this instance of compilation.
91 /// \param Lang Source programming language, eg. dwarf::DW_LANG_C99
92 /// \param File File info.
93 /// \param Producer Identify the producer of debugging information
94 /// and code. Usually this is a compiler
96 /// \param isOptimized A boolean flag which indicates whether optimization
97 /// is enabled or not.
98 /// \param Flags This string lists command line options. This
99 /// string is directly embedded in debug info
100 /// output which may be used by a tool
101 /// analyzing generated debugging information.
102 /// \param RV This indicates runtime version for languages like
104 /// \param SplitName The name of the file that we'll split debug info
106 /// \param Kind The kind of debug information to generate.
107 /// \param DWOId The DWOId if this is a split skeleton compile unit.
109 createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
110 bool isOptimized, StringRef Flags, unsigned RV,
111 StringRef SplitName = StringRef(),
112 DICompileUnit::DebugEmissionKind Kind =
113 DICompileUnit::DebugEmissionKind::FullDebug,
114 uint64_t DWOId = 0, bool SplitDebugInlining = true);
116 /// Create a file descriptor to hold debugging information for a file.
117 /// \param Filename File name.
118 /// \param Directory Directory.
119 /// \param CSKind Checksum kind (e.g. CSK_None, CSK_MD5, CSK_SHA1, etc.).
120 /// \param Checksum Checksum data.
121 DIFile *createFile(StringRef Filename, StringRef Directory,
122 DIFile::ChecksumKind CSKind = DIFile::CSK_None,
123 StringRef Checksum = StringRef());
125 /// Create debugging information entry for a macro.
126 /// \param Parent Macro parent (could be nullptr).
127 /// \param Line Source line number where the macro is defined.
128 /// \param MacroType DW_MACINFO_define or DW_MACINFO_undef.
129 /// \param Name Macro name.
130 /// \param Value Macro value.
131 DIMacro *createMacro(DIMacroFile *Parent, unsigned Line, unsigned MacroType,
132 StringRef Name, StringRef Value = StringRef());
134 /// Create debugging information temporary entry for a macro file.
135 /// List of macro node direct children will be calculated by DIBuilder,
136 /// using the \p Parent relationship.
137 /// \param Parent Macro file parent (could be nullptr).
138 /// \param Line Source line number where the macro file is included.
139 /// \param File File descriptor containing the name of the macro file.
140 DIMacroFile *createTempMacroFile(DIMacroFile *Parent, unsigned Line,
143 /// Create a single enumerator value.
144 DIEnumerator *createEnumerator(StringRef Name, int64_t Val);
146 /// Create a DWARF unspecified type.
147 DIBasicType *createUnspecifiedType(StringRef Name);
149 /// Create C++11 nullptr type.
150 DIBasicType *createNullPtrType();
152 /// Create debugging information entry for a basic
154 /// \param Name Type name.
155 /// \param SizeInBits Size of the type.
156 /// \param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
157 DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
160 /// Create debugging information entry for a qualified
161 /// type, e.g. 'const int'.
162 /// \param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
163 /// \param FromTy Base Type.
164 DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy);
166 /// Create debugging information entry for a pointer.
167 /// \param PointeeTy Type pointed by this pointer.
168 /// \param SizeInBits Size.
169 /// \param AlignInBits Alignment. (optional)
170 /// \param Name Pointer type name. (optional)
171 DIDerivedType *createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
172 uint32_t AlignInBits = 0,
173 StringRef Name = "");
175 /// Create debugging information entry for a pointer to member.
176 /// \param PointeeTy Type pointed to by this pointer.
177 /// \param SizeInBits Size.
178 /// \param AlignInBits Alignment. (optional)
179 /// \param Class Type for which this pointer points to members of.
181 createMemberPointerType(DIType *PointeeTy, DIType *Class,
182 uint64_t SizeInBits, uint32_t AlignInBits = 0,
183 DINode::DIFlags Flags = DINode::FlagZero);
185 /// Create debugging information entry for a c++
186 /// style reference or rvalue reference type.
187 DIDerivedType *createReferenceType(unsigned Tag, DIType *RTy,
188 uint64_t SizeInBits = 0,
189 uint32_t AlignInBits = 0);
191 /// Create debugging information entry for a typedef.
192 /// \param Ty Original type.
193 /// \param Name Typedef name.
194 /// \param File File where this type is defined.
195 /// \param LineNo Line number.
196 /// \param Context The surrounding context for the typedef.
197 DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File,
198 unsigned LineNo, DIScope *Context);
200 /// Create debugging information entry for a 'friend'.
201 DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy);
203 /// Create debugging information entry to establish
204 /// inheritance relationship between two types.
205 /// \param Ty Original type.
206 /// \param BaseTy Base type. Ty is inherits from base.
207 /// \param BaseOffset Base offset.
208 /// \param Flags Flags to describe inheritance attribute,
210 DIDerivedType *createInheritance(DIType *Ty, DIType *BaseTy,
212 DINode::DIFlags Flags);
214 /// Create debugging information entry for a member.
215 /// \param Scope Member scope.
216 /// \param Name Member 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 OffsetInBits Member offset.
222 /// \param Flags Flags to encode member attribute, e.g. private
223 /// \param Ty Parent type.
224 DIDerivedType *createMemberType(DIScope *Scope, StringRef Name,
225 DIFile *File, unsigned LineNo,
227 uint32_t AlignInBits,
228 uint64_t OffsetInBits,
229 DINode::DIFlags Flags, DIType *Ty);
231 /// Create debugging information entry for a bit field member.
232 /// \param Scope Member scope.
233 /// \param Name Member name.
234 /// \param File File where this member is defined.
235 /// \param LineNo Line number.
236 /// \param SizeInBits Member size.
237 /// \param OffsetInBits Member offset.
238 /// \param StorageOffsetInBits Member storage offset.
239 /// \param Flags Flags to encode member attribute.
240 /// \param Ty Parent type.
241 DIDerivedType *createBitFieldMemberType(
242 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo,
243 uint64_t SizeInBits, uint64_t OffsetInBits,
244 uint64_t StorageOffsetInBits, DINode::DIFlags Flags, DIType *Ty);
246 /// Create debugging information entry for a
247 /// C++ static data member.
248 /// \param Scope Member scope.
249 /// \param Name Member name.
250 /// \param File File where this member is declared.
251 /// \param LineNo Line number.
252 /// \param Ty Type of the static member.
253 /// \param Flags Flags to encode member attribute, e.g. private.
254 /// \param Val Const initializer of the member.
255 /// \param AlignInBits Member alignment.
256 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
257 DIFile *File, unsigned LineNo,
258 DIType *Ty, DINode::DIFlags Flags,
260 uint32_t AlignInBits = 0);
262 /// Create debugging information entry for Objective-C
263 /// instance variable.
264 /// \param Name Member name.
265 /// \param File File where this member is defined.
266 /// \param LineNo Line number.
267 /// \param SizeInBits Member size.
268 /// \param AlignInBits Member alignment.
269 /// \param OffsetInBits Member offset.
270 /// \param Flags Flags to encode member attribute, e.g. private
271 /// \param Ty Parent type.
272 /// \param PropertyNode Property associated with this ivar.
273 DIDerivedType *createObjCIVar(StringRef Name, DIFile *File, unsigned LineNo,
274 uint64_t SizeInBits, uint32_t AlignInBits,
275 uint64_t OffsetInBits, DINode::DIFlags Flags,
276 DIType *Ty, MDNode *PropertyNode);
278 /// Create debugging information entry for Objective-C
280 /// \param Name Property name.
281 /// \param File File where this property is defined.
282 /// \param LineNumber Line number.
283 /// \param GetterName Name of the Objective C property getter selector.
284 /// \param SetterName Name of the Objective C property setter selector.
285 /// \param PropertyAttributes Objective C property attributes.
287 DIObjCProperty *createObjCProperty(StringRef Name, DIFile *File,
289 StringRef GetterName,
290 StringRef SetterName,
291 unsigned PropertyAttributes, DIType *Ty);
293 /// Create debugging information entry for a class.
294 /// \param Scope Scope in which this class is defined.
295 /// \param Name class name.
296 /// \param File File where this member is defined.
297 /// \param LineNumber Line number.
298 /// \param SizeInBits Member size.
299 /// \param AlignInBits Member alignment.
300 /// \param OffsetInBits Member offset.
301 /// \param Flags Flags to encode member attribute, e.g. private
302 /// \param Elements class members.
303 /// \param VTableHolder Debug info of the base class that contains vtable
304 /// for this type. This is used in
305 /// DW_AT_containing_type. See DWARF documentation
307 /// \param TemplateParms Template type parameters.
308 /// \param UniqueIdentifier A unique identifier for the class.
309 DICompositeType *createClassType(
310 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
311 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
312 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
313 DIType *VTableHolder = nullptr, MDNode *TemplateParms = nullptr,
314 StringRef UniqueIdentifier = "");
316 /// Create debugging information entry for a struct.
317 /// \param Scope Scope in which this struct is defined.
318 /// \param Name Struct name.
319 /// \param File File where this member is defined.
320 /// \param LineNumber Line number.
321 /// \param SizeInBits Member size.
322 /// \param AlignInBits Member alignment.
323 /// \param Flags Flags to encode member attribute, e.g. private
324 /// \param Elements Struct elements.
325 /// \param RunTimeLang Optional parameter, Objective-C runtime version.
326 /// \param UniqueIdentifier A unique identifier for the struct.
327 DICompositeType *createStructType(
328 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
329 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
330 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0,
331 DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
333 /// Create debugging information entry for an union.
334 /// \param Scope Scope in which this union is defined.
335 /// \param Name Union name.
336 /// \param File File where this member is defined.
337 /// \param LineNumber Line number.
338 /// \param SizeInBits Member size.
339 /// \param AlignInBits Member alignment.
340 /// \param Flags Flags to encode member attribute, e.g. private
341 /// \param Elements Union elements.
342 /// \param RunTimeLang Optional parameter, Objective-C runtime version.
343 /// \param UniqueIdentifier A unique identifier for the union.
344 DICompositeType *createUnionType(DIScope *Scope, StringRef Name,
345 DIFile *File, unsigned LineNumber,
346 uint64_t SizeInBits, uint32_t AlignInBits,
347 DINode::DIFlags Flags,
348 DINodeArray Elements,
349 unsigned RunTimeLang = 0,
350 StringRef UniqueIdentifier = "");
352 /// Create debugging information for template
354 /// \param Scope Scope in which this type is defined.
355 /// \param Name Type parameter name.
356 /// \param Ty Parameter type.
357 DITemplateTypeParameter *
358 createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty);
360 /// Create debugging information for template
362 /// \param Scope Scope in which this type is defined.
363 /// \param Name Value parameter name.
364 /// \param Ty Parameter type.
365 /// \param Val Constant parameter value.
366 DITemplateValueParameter *createTemplateValueParameter(DIScope *Scope,
371 /// Create debugging information for a template template parameter.
372 /// \param Scope Scope in which this type is defined.
373 /// \param Name Value parameter name.
374 /// \param Ty Parameter type.
375 /// \param Val The fully qualified name of the template.
376 DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
381 /// Create debugging information for a template parameter pack.
382 /// \param Scope Scope in which this type is defined.
383 /// \param Name Value parameter name.
384 /// \param Ty Parameter type.
385 /// \param Val An array of types in the pack.
386 DITemplateValueParameter *createTemplateParameterPack(DIScope *Scope,
391 /// Create debugging information entry for an array.
392 /// \param Size Array size.
393 /// \param AlignInBits Alignment.
394 /// \param Ty Element type.
395 /// \param Subscripts Subscripts.
396 DICompositeType *createArrayType(uint64_t Size, uint32_t AlignInBits,
397 DIType *Ty, DINodeArray Subscripts);
399 /// Create debugging information entry for a vector type.
400 /// \param Size Array size.
401 /// \param AlignInBits Alignment.
402 /// \param Ty Element type.
403 /// \param Subscripts Subscripts.
404 DICompositeType *createVectorType(uint64_t Size, uint32_t AlignInBits,
405 DIType *Ty, DINodeArray Subscripts);
407 /// Create debugging information entry for an
409 /// \param Scope Scope in which this enumeration is defined.
410 /// \param Name Union name.
411 /// \param File File where this member is defined.
412 /// \param LineNumber Line number.
413 /// \param SizeInBits Member size.
414 /// \param AlignInBits Member alignment.
415 /// \param Elements Enumeration elements.
416 /// \param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
417 /// \param UniqueIdentifier A unique identifier for the enum.
418 DICompositeType *createEnumerationType(
419 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
420 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
421 DIType *UnderlyingType, StringRef UniqueIdentifier = "");
423 /// Create subroutine type.
424 /// \param ParameterTypes An array of subroutine parameter types. This
425 /// includes return type at 0th index.
426 /// \param Flags E.g.: LValueReference.
427 /// These flags are used to emit dwarf attributes.
428 /// \param CC Calling convention, e.g. dwarf::DW_CC_normal
430 createSubroutineType(DITypeRefArray ParameterTypes,
431 DINode::DIFlags Flags = DINode::FlagZero,
434 /// Create an external type reference.
435 /// \param Tag Dwarf TAG.
436 /// \param File File in which the type is defined.
437 /// \param UniqueIdentifier A unique identifier for the type.
438 DICompositeType *createExternalTypeRef(unsigned Tag, DIFile *File,
439 StringRef UniqueIdentifier);
441 /// Create a new DIType* with "artificial" flag set.
442 DIType *createArtificialType(DIType *Ty);
444 /// Create a new DIType* with the "object pointer"
446 DIType *createObjectPointerType(DIType *Ty);
448 /// Create a permanent forward-declared type.
449 DICompositeType *createForwardDecl(unsigned Tag, StringRef Name,
450 DIScope *Scope, DIFile *F, unsigned Line,
451 unsigned RuntimeLang = 0,
452 uint64_t SizeInBits = 0,
453 uint32_t AlignInBits = 0,
454 StringRef UniqueIdentifier = "");
456 /// Create a temporary forward-declared type.
457 DICompositeType *createReplaceableCompositeType(
458 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
459 unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
460 uint32_t AlignInBits = 0, DINode::DIFlags Flags = DINode::FlagFwdDecl,
461 StringRef UniqueIdentifier = "");
463 /// Retain DIScope* in a module even if it is not referenced
464 /// through debug info anchors.
465 void retainType(DIScope *T);
467 /// Create unspecified parameter type
468 /// for a subroutine type.
469 DIBasicType *createUnspecifiedParameter();
471 /// Get a DINodeArray, create one if required.
472 DINodeArray getOrCreateArray(ArrayRef<Metadata *> Elements);
474 /// Get a DIMacroNodeArray, create one if required.
475 DIMacroNodeArray getOrCreateMacroArray(ArrayRef<Metadata *> Elements);
477 /// Get a DITypeRefArray, create one if required.
478 DITypeRefArray getOrCreateTypeArray(ArrayRef<Metadata *> Elements);
480 /// Create a descriptor for a value range. This
481 /// implicitly uniques the values returned.
482 DISubrange *getOrCreateSubrange(int64_t Lo, int64_t Count);
484 /// Create a new descriptor for the specified variable.
485 /// \param Context Variable scope.
486 /// \param Name Name of the variable.
487 /// \param LinkageName Mangled name of the variable.
488 /// \param File File where this variable is defined.
489 /// \param LineNo Line number.
490 /// \param Ty Variable Type.
491 /// \param isLocalToUnit Boolean flag indicate whether this variable is
492 /// externally visible or not.
493 /// \param Expr The location of the global relative to the attached
495 /// \param Decl Reference to the corresponding declaration.
496 /// \param AlignInBits Variable alignment(or 0 if no alignment attr was
498 DIGlobalVariableExpression *createGlobalVariableExpression(
499 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
500 unsigned LineNo, DIType *Ty, bool isLocalToUnit,
501 DIExpression *Expr = nullptr, MDNode *Decl = nullptr,
502 uint32_t AlignInBits = 0);
504 /// Identical to createGlobalVariable
505 /// except that the resulting DbgNode is temporary and meant to be RAUWed.
506 DIGlobalVariable *createTempGlobalVariableFwdDecl(
507 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
508 unsigned LineNo, DIType *Ty, bool isLocalToUnit, MDNode *Decl = nullptr,
509 uint32_t AlignInBits = 0);
511 /// Create a new descriptor for an auto variable. This is a local variable
512 /// that is not a subprogram parameter.
514 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
515 /// leads to a \a DISubprogram.
517 /// If \c AlwaysPreserve, this variable will be referenced from its
518 /// containing subprogram, and will survive some optimizations.
520 createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File,
521 unsigned LineNo, DIType *Ty, bool AlwaysPreserve = false,
522 DINode::DIFlags Flags = DINode::FlagZero,
523 uint32_t AlignInBits = 0);
525 /// Create a new descriptor for a parameter variable.
527 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
528 /// leads to a \a DISubprogram.
530 /// \c ArgNo is the index (starting from \c 1) of this variable in the
531 /// subprogram parameters. \c ArgNo should not conflict with other
532 /// parameters of the same subprogram.
534 /// If \c AlwaysPreserve, this variable will be referenced from its
535 /// containing subprogram, and will survive some optimizations.
537 createParameterVariable(DIScope *Scope, StringRef Name, unsigned ArgNo,
538 DIFile *File, unsigned LineNo, DIType *Ty,
539 bool AlwaysPreserve = false,
540 DINode::DIFlags Flags = DINode::FlagZero);
542 /// Create a new descriptor for the specified
543 /// variable which has a complex address expression for its address.
544 /// \param Addr An array of complex address operations.
545 DIExpression *createExpression(ArrayRef<uint64_t> Addr = None);
546 DIExpression *createExpression(ArrayRef<int64_t> Addr);
548 /// Create a descriptor to describe one part
549 /// of aggregate variable that is fragmented across multiple Values.
551 /// \param OffsetInBits Offset of the piece in bits.
552 /// \param SizeInBits Size of the piece in bits.
553 DIExpression *createFragmentExpression(unsigned OffsetInBits,
554 unsigned SizeInBits);
556 /// Create an expression for a variable that does not have an address, but
557 /// does have a constant value.
558 DIExpression *createConstantValueExpression(uint64_t Val) {
559 return DIExpression::get(
560 VMContext, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_stack_value});
563 /// Create a new descriptor for the specified subprogram.
564 /// See comments in DISubprogram* for descriptions of these fields.
565 /// \param Scope Function scope.
566 /// \param Name Function name.
567 /// \param LinkageName Mangled function name.
568 /// \param File File where this variable is defined.
569 /// \param LineNo Line number.
570 /// \param Ty Function type.
571 /// \param isLocalToUnit True if this function is not externally visible.
572 /// \param isDefinition True if this is a function definition.
573 /// \param ScopeLine Set to the beginning of the scope this starts
574 /// \param Flags e.g. is this function prototyped or not.
575 /// These flags are used to emit dwarf attributes.
576 /// \param isOptimized True if optimization is ON.
577 /// \param TParams Function template parameters.
578 DISubprogram *createFunction(DIScope *Scope, StringRef Name,
579 StringRef LinkageName, DIFile *File,
580 unsigned LineNo, DISubroutineType *Ty,
581 bool isLocalToUnit, bool isDefinition,
583 DINode::DIFlags Flags = DINode::FlagZero,
584 bool isOptimized = false,
585 DITemplateParameterArray TParams = nullptr,
586 DISubprogram *Decl = nullptr);
588 /// Identical to createFunction,
589 /// except that the resulting DbgNode is meant to be RAUWed.
590 DISubprogram *createTempFunctionFwdDecl(
591 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
592 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
593 bool isDefinition, unsigned ScopeLine,
594 DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
595 DITemplateParameterArray TParams = nullptr,
596 DISubprogram *Decl = nullptr);
598 /// Create a new descriptor for the specified C++ method.
599 /// See comments in \a DISubprogram* for descriptions of these fields.
600 /// \param Scope Function scope.
601 /// \param Name Function name.
602 /// \param LinkageName Mangled function name.
603 /// \param File File where this variable is defined.
604 /// \param LineNo Line number.
605 /// \param Ty Function type.
606 /// \param isLocalToUnit True if this function is not externally visible..
607 /// \param isDefinition True if this is a function definition.
608 /// \param Virtuality Attributes describing virtualness. e.g. pure
609 /// virtual function.
610 /// \param VTableIndex Index no of this method in virtual table, or -1u if
612 /// \param ThisAdjustment
613 /// MS ABI-specific adjustment of 'this' that occurs
615 /// \param VTableHolder Type that holds vtable.
616 /// \param Flags e.g. is this function prototyped or not.
617 /// This flags are used to emit dwarf attributes.
618 /// \param isOptimized True if optimization is ON.
619 /// \param TParams Function template parameters.
620 DISubprogram *createMethod(
621 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
622 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
623 bool isDefinition, unsigned Virtuality = 0, unsigned VTableIndex = 0,
624 int ThisAdjustment = 0, DIType *VTableHolder = nullptr,
625 DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
626 DITemplateParameterArray TParams = nullptr);
628 /// This creates new descriptor for a namespace with the specified
630 /// \param Scope Namespace scope
631 /// \param Name Name of this namespace
632 /// \param File Source file
633 /// \param LineNo Line number
634 /// \param ExportSymbols True for C++ inline namespaces.
635 DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File,
636 unsigned LineNo, bool ExportSymbols);
638 /// This creates new descriptor for a module with the specified
640 /// \param Scope Parent scope
641 /// \param Name Name of this module
642 /// \param ConfigurationMacros
643 /// A space-separated shell-quoted list of -D macro
644 /// definitions as they would appear on a command line.
645 /// \param IncludePath The path to the module map file.
646 /// \param ISysRoot The clang system root (value of -isysroot).
647 DIModule *createModule(DIScope *Scope, StringRef Name,
648 StringRef ConfigurationMacros,
649 StringRef IncludePath,
652 /// This creates a descriptor for a lexical block with a new file
653 /// attached. This merely extends the existing
654 /// lexical block as it crosses a file.
655 /// \param Scope Lexical block.
656 /// \param File Source file.
657 /// \param Discriminator DWARF path discriminator value.
658 DILexicalBlockFile *createLexicalBlockFile(DIScope *Scope, DIFile *File,
659 unsigned Discriminator = 0);
661 /// This creates a descriptor for a lexical block with the
662 /// specified parent context.
663 /// \param Scope Parent lexical scope.
664 /// \param File Source file.
665 /// \param Line Line number.
666 /// \param Col Column number.
667 DILexicalBlock *createLexicalBlock(DIScope *Scope, DIFile *File,
668 unsigned Line, unsigned Col);
670 /// Create a descriptor for an imported module.
671 /// \param Context The scope this module is imported into
672 /// \param NS The namespace being imported here
673 /// \param Line Line number
674 DIImportedEntity *createImportedModule(DIScope *Context, DINamespace *NS,
677 /// Create a descriptor for an imported module.
678 /// \param Context The scope this module is imported into
679 /// \param NS An aliased namespace
680 /// \param Line Line number
681 DIImportedEntity *createImportedModule(DIScope *Context,
682 DIImportedEntity *NS, unsigned Line);
684 /// Create a descriptor for an imported module.
685 /// \param Context The scope this module is imported into
686 /// \param M The module being imported here
687 /// \param Line Line number
688 DIImportedEntity *createImportedModule(DIScope *Context, DIModule *M,
691 /// Create a descriptor for an imported function.
692 /// \param Context The scope this module is imported into
693 /// \param Decl The declaration (or definition) of a function, type, or
695 /// \param Line Line number
696 DIImportedEntity *createImportedDeclaration(DIScope *Context, DINode *Decl,
698 StringRef Name = "");
700 /// Insert a new llvm.dbg.declare intrinsic call.
701 /// \param Storage llvm::Value of the variable
702 /// \param VarInfo Variable's debug info descriptor.
703 /// \param Expr A complex location expression.
704 /// \param DL Debug info location.
705 /// \param InsertAtEnd Location for the new intrinsic.
706 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
707 DIExpression *Expr, const DILocation *DL,
708 BasicBlock *InsertAtEnd);
710 /// Insert a new llvm.dbg.declare intrinsic call.
711 /// \param Storage llvm::Value of the variable
712 /// \param VarInfo Variable's debug info descriptor.
713 /// \param Expr A complex location expression.
714 /// \param DL Debug info location.
715 /// \param InsertBefore Location for the new intrinsic.
716 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
717 DIExpression *Expr, const DILocation *DL,
718 Instruction *InsertBefore);
720 /// Insert a new llvm.dbg.value intrinsic call.
721 /// \param Val llvm::Value of the variable
722 /// \param Offset Offset
723 /// \param VarInfo Variable's debug info descriptor.
724 /// \param Expr A complex location expression.
725 /// \param DL Debug info location.
726 /// \param InsertAtEnd Location for the new intrinsic.
727 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
728 DILocalVariable *VarInfo,
730 const DILocation *DL,
731 BasicBlock *InsertAtEnd);
733 /// Insert a new llvm.dbg.value intrinsic call.
734 /// \param Val llvm::Value of the variable
735 /// \param Offset Offset
736 /// \param VarInfo Variable's debug info descriptor.
737 /// \param Expr A complex location expression.
738 /// \param DL Debug info location.
739 /// \param InsertBefore Location for the new intrinsic.
740 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
741 DILocalVariable *VarInfo,
743 const DILocation *DL,
744 Instruction *InsertBefore);
746 /// Replace the vtable holder in the given composite type.
748 /// If this creates a self reference, it may orphan some unresolved cycles
749 /// in the operands of \c T, so \a DIBuilder needs to track that.
750 void replaceVTableHolder(DICompositeType *&T,
751 DICompositeType *VTableHolder);
753 /// Replace arrays on a composite type.
755 /// If \c T is resolved, but the arrays aren't -- which can happen if \c T
756 /// has a self-reference -- \a DIBuilder needs to track the array to
758 void replaceArrays(DICompositeType *&T, DINodeArray Elements,
759 DINodeArray TParams = DINodeArray());
761 /// Replace a temporary node.
763 /// Call \a MDNode::replaceAllUsesWith() on \c N, replacing it with \c
766 /// If \c Replacement is the same as \c N.get(), instead call \a
767 /// MDNode::replaceWithUniqued(). In this case, the uniqued node could
768 /// have a different address, so we return the final address.
769 template <class NodeTy>
770 NodeTy *replaceTemporary(TempMDNode &&N, NodeTy *Replacement) {
771 if (N.get() == Replacement)
772 return cast<NodeTy>(MDNode::replaceWithUniqued(std::move(N)));
774 N->replaceAllUsesWith(Replacement);
779 } // end namespace llvm
781 #endif // LLVM_IR_DIBUILDER_H