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);
77 /// Internal helper for insertDeclare.
78 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
79 DIExpression *Expr, const DILocation *DL,
80 BasicBlock *InsertBB, Instruction *InsertBefore);
82 /// Internal helper for insertDbgValueIntrinsic.
84 insertDbgValueIntrinsic(llvm::Value *Val, DILocalVariable *VarInfo,
85 DIExpression *Expr, const DILocation *DL,
86 BasicBlock *InsertBB, Instruction *InsertBefore);
89 /// Construct a builder for a module.
91 /// If \c AllowUnresolved, collect unresolved nodes attached to the module
92 /// in order to resolve cycles during \a finalize().
93 explicit DIBuilder(Module &M, bool AllowUnresolved = true);
94 DIBuilder(const DIBuilder &) = delete;
95 DIBuilder &operator=(const DIBuilder &) = delete;
97 /// Construct any deferred debug info descriptors.
100 /// Finalize a specific subprogram - no new variables may be added to this
101 /// subprogram afterwards.
102 void finalizeSubprogram(DISubprogram *SP);
104 /// A CompileUnit provides an anchor for all debugging
105 /// information generated during this instance of compilation.
106 /// \param Lang Source programming language, eg. dwarf::DW_LANG_C99
107 /// \param File File info.
108 /// \param Producer Identify the producer of debugging information
109 /// and code. Usually this is a compiler
111 /// \param isOptimized A boolean flag which indicates whether optimization
112 /// is enabled or not.
113 /// \param Flags This string lists command line options. This
114 /// string is directly embedded in debug info
115 /// output which may be used by a tool
116 /// analyzing generated debugging information.
117 /// \param RV This indicates runtime version for languages like
119 /// \param SplitName The name of the file that we'll split debug info
121 /// \param Kind The kind of debug information to generate.
122 /// \param DWOId The DWOId if this is a split skeleton compile unit.
123 /// \param SplitDebugInlining Whether to emit inline debug info.
124 /// \param DebugInfoForProfiling Whether to emit extra debug info for
125 /// profile collection.
126 /// \param GnuPubnames Whether to emit .debug_gnu_pubnames section instead
127 /// of .debug_pubnames.
129 createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
130 bool isOptimized, StringRef Flags, unsigned RV,
131 StringRef SplitName = StringRef(),
132 DICompileUnit::DebugEmissionKind Kind =
133 DICompileUnit::DebugEmissionKind::FullDebug,
134 uint64_t DWOId = 0, bool SplitDebugInlining = true,
135 bool DebugInfoForProfiling = false,
136 bool GnuPubnames = false);
138 /// Create a file descriptor to hold debugging information for a file.
139 /// \param Filename File name.
140 /// \param Directory Directory.
141 /// \param CSKind Checksum kind (e.g. CSK_None, CSK_MD5, CSK_SHA1, etc.).
142 /// \param Checksum Checksum data.
143 DIFile *createFile(StringRef Filename, StringRef Directory,
144 DIFile::ChecksumKind CSKind = DIFile::CSK_None,
145 StringRef Checksum = StringRef());
147 /// Create debugging information entry for a macro.
148 /// \param Parent Macro parent (could be nullptr).
149 /// \param Line Source line number where the macro is defined.
150 /// \param MacroType DW_MACINFO_define or DW_MACINFO_undef.
151 /// \param Name Macro name.
152 /// \param Value Macro value.
153 DIMacro *createMacro(DIMacroFile *Parent, unsigned Line, unsigned MacroType,
154 StringRef Name, StringRef Value = StringRef());
156 /// Create debugging information temporary entry for a macro file.
157 /// List of macro node direct children will be calculated by DIBuilder,
158 /// using the \p Parent relationship.
159 /// \param Parent Macro file parent (could be nullptr).
160 /// \param Line Source line number where the macro file is included.
161 /// \param File File descriptor containing the name of the macro file.
162 DIMacroFile *createTempMacroFile(DIMacroFile *Parent, unsigned Line,
165 /// Create a single enumerator value.
166 DIEnumerator *createEnumerator(StringRef Name, int64_t Val);
168 /// Create a DWARF unspecified type.
169 DIBasicType *createUnspecifiedType(StringRef Name);
171 /// Create C++11 nullptr type.
172 DIBasicType *createNullPtrType();
174 /// Create debugging information entry for a basic
176 /// \param Name Type name.
177 /// \param SizeInBits Size of the type.
178 /// \param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
179 DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
182 /// Create debugging information entry for a qualified
183 /// type, e.g. 'const int'.
184 /// \param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
185 /// \param FromTy Base Type.
186 DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy);
188 /// Create debugging information entry for a pointer.
189 /// \param PointeeTy Type pointed by this pointer.
190 /// \param SizeInBits Size.
191 /// \param AlignInBits Alignment. (optional)
192 /// \param DWARFAddressSpace DWARF address space. (optional)
193 /// \param Name Pointer type name. (optional)
194 DIDerivedType *createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
195 uint32_t AlignInBits = 0,
196 Optional<unsigned> DWARFAddressSpace =
198 StringRef Name = "");
200 /// Create debugging information entry for a pointer to member.
201 /// \param PointeeTy Type pointed to by this pointer.
202 /// \param SizeInBits Size.
203 /// \param AlignInBits Alignment. (optional)
204 /// \param Class Type for which this pointer points to members of.
206 createMemberPointerType(DIType *PointeeTy, DIType *Class,
207 uint64_t SizeInBits, uint32_t AlignInBits = 0,
208 DINode::DIFlags Flags = DINode::FlagZero);
210 /// Create debugging information entry for a c++
211 /// style reference or rvalue reference type.
212 DIDerivedType *createReferenceType(unsigned Tag, DIType *RTy,
213 uint64_t SizeInBits = 0,
214 uint32_t AlignInBits = 0,
215 Optional<unsigned> DWARFAddressSpace =
218 /// Create debugging information entry for a typedef.
219 /// \param Ty Original type.
220 /// \param Name Typedef name.
221 /// \param File File where this type is defined.
222 /// \param LineNo Line number.
223 /// \param Context The surrounding context for the typedef.
224 DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File,
225 unsigned LineNo, DIScope *Context);
227 /// Create debugging information entry for a 'friend'.
228 DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy);
230 /// Create debugging information entry to establish
231 /// inheritance relationship between two types.
232 /// \param Ty Original type.
233 /// \param BaseTy Base type. Ty is inherits from base.
234 /// \param BaseOffset Base offset.
235 /// \param Flags Flags to describe inheritance attribute,
237 DIDerivedType *createInheritance(DIType *Ty, DIType *BaseTy,
239 DINode::DIFlags Flags);
241 /// Create debugging information entry for a member.
242 /// \param Scope Member scope.
243 /// \param Name Member name.
244 /// \param File File where this member is defined.
245 /// \param LineNo Line number.
246 /// \param SizeInBits Member size.
247 /// \param AlignInBits Member alignment.
248 /// \param OffsetInBits Member offset.
249 /// \param Flags Flags to encode member attribute, e.g. private
250 /// \param Ty Parent type.
251 DIDerivedType *createMemberType(DIScope *Scope, StringRef Name,
252 DIFile *File, unsigned LineNo,
254 uint32_t AlignInBits,
255 uint64_t OffsetInBits,
256 DINode::DIFlags Flags, DIType *Ty);
258 /// Create debugging information entry for a bit field member.
259 /// \param Scope Member scope.
260 /// \param Name Member name.
261 /// \param File File where this member is defined.
262 /// \param LineNo Line number.
263 /// \param SizeInBits Member size.
264 /// \param OffsetInBits Member offset.
265 /// \param StorageOffsetInBits Member storage offset.
266 /// \param Flags Flags to encode member attribute.
267 /// \param Ty Parent type.
268 DIDerivedType *createBitFieldMemberType(
269 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo,
270 uint64_t SizeInBits, uint64_t OffsetInBits,
271 uint64_t StorageOffsetInBits, DINode::DIFlags Flags, DIType *Ty);
273 /// Create debugging information entry for a
274 /// C++ static data member.
275 /// \param Scope Member scope.
276 /// \param Name Member name.
277 /// \param File File where this member is declared.
278 /// \param LineNo Line number.
279 /// \param Ty Type of the static member.
280 /// \param Flags Flags to encode member attribute, e.g. private.
281 /// \param Val Const initializer of the member.
282 /// \param AlignInBits Member alignment.
283 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
284 DIFile *File, unsigned LineNo,
285 DIType *Ty, DINode::DIFlags Flags,
287 uint32_t AlignInBits = 0);
289 /// Create debugging information entry for Objective-C
290 /// instance variable.
291 /// \param Name Member 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 OffsetInBits Member offset.
297 /// \param Flags Flags to encode member attribute, e.g. private
298 /// \param Ty Parent type.
299 /// \param PropertyNode Property associated with this ivar.
300 DIDerivedType *createObjCIVar(StringRef Name, DIFile *File, unsigned LineNo,
301 uint64_t SizeInBits, uint32_t AlignInBits,
302 uint64_t OffsetInBits, DINode::DIFlags Flags,
303 DIType *Ty, MDNode *PropertyNode);
305 /// Create debugging information entry for Objective-C
307 /// \param Name Property name.
308 /// \param File File where this property is defined.
309 /// \param LineNumber Line number.
310 /// \param GetterName Name of the Objective C property getter selector.
311 /// \param SetterName Name of the Objective C property setter selector.
312 /// \param PropertyAttributes Objective C property attributes.
314 DIObjCProperty *createObjCProperty(StringRef Name, DIFile *File,
316 StringRef GetterName,
317 StringRef SetterName,
318 unsigned PropertyAttributes, DIType *Ty);
320 /// Create debugging information entry for a class.
321 /// \param Scope Scope in which this class is defined.
322 /// \param Name class name.
323 /// \param File File where this member is defined.
324 /// \param LineNumber Line number.
325 /// \param SizeInBits Member size.
326 /// \param AlignInBits Member alignment.
327 /// \param OffsetInBits Member offset.
328 /// \param Flags Flags to encode member attribute, e.g. private
329 /// \param Elements class members.
330 /// \param VTableHolder Debug info of the base class that contains vtable
331 /// for this type. This is used in
332 /// DW_AT_containing_type. See DWARF documentation
334 /// \param TemplateParms Template type parameters.
335 /// \param UniqueIdentifier A unique identifier for the class.
336 DICompositeType *createClassType(
337 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
338 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
339 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
340 DIType *VTableHolder = nullptr, MDNode *TemplateParms = nullptr,
341 StringRef UniqueIdentifier = "");
343 /// Create debugging information entry for a struct.
344 /// \param Scope Scope in which this struct is defined.
345 /// \param Name Struct name.
346 /// \param File File where this member is defined.
347 /// \param LineNumber Line number.
348 /// \param SizeInBits Member size.
349 /// \param AlignInBits Member alignment.
350 /// \param Flags Flags to encode member attribute, e.g. private
351 /// \param Elements Struct elements.
352 /// \param RunTimeLang Optional parameter, Objective-C runtime version.
353 /// \param UniqueIdentifier A unique identifier for the struct.
354 DICompositeType *createStructType(
355 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
356 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
357 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0,
358 DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
360 /// Create debugging information entry for an union.
361 /// \param Scope Scope in which this union is defined.
362 /// \param Name Union name.
363 /// \param File File where this member is defined.
364 /// \param LineNumber Line number.
365 /// \param SizeInBits Member size.
366 /// \param AlignInBits Member alignment.
367 /// \param Flags Flags to encode member attribute, e.g. private
368 /// \param Elements Union elements.
369 /// \param RunTimeLang Optional parameter, Objective-C runtime version.
370 /// \param UniqueIdentifier A unique identifier for the union.
371 DICompositeType *createUnionType(DIScope *Scope, StringRef Name,
372 DIFile *File, unsigned LineNumber,
373 uint64_t SizeInBits, uint32_t AlignInBits,
374 DINode::DIFlags Flags,
375 DINodeArray Elements,
376 unsigned RunTimeLang = 0,
377 StringRef UniqueIdentifier = "");
379 /// Create debugging information for template
381 /// \param Scope Scope in which this type is defined.
382 /// \param Name Type parameter name.
383 /// \param Ty Parameter type.
384 DITemplateTypeParameter *
385 createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty);
387 /// Create debugging information for template
389 /// \param Scope Scope in which this type is defined.
390 /// \param Name Value parameter name.
391 /// \param Ty Parameter type.
392 /// \param Val Constant parameter value.
393 DITemplateValueParameter *createTemplateValueParameter(DIScope *Scope,
398 /// Create debugging information for a template template parameter.
399 /// \param Scope Scope in which this type is defined.
400 /// \param Name Value parameter name.
401 /// \param Ty Parameter type.
402 /// \param Val The fully qualified name of the template.
403 DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
408 /// Create debugging information for a template parameter pack.
409 /// \param Scope Scope in which this type is defined.
410 /// \param Name Value parameter name.
411 /// \param Ty Parameter type.
412 /// \param Val An array of types in the pack.
413 DITemplateValueParameter *createTemplateParameterPack(DIScope *Scope,
418 /// Create debugging information entry for an array.
419 /// \param Size Array size.
420 /// \param AlignInBits Alignment.
421 /// \param Ty Element type.
422 /// \param Subscripts Subscripts.
423 DICompositeType *createArrayType(uint64_t Size, uint32_t AlignInBits,
424 DIType *Ty, DINodeArray Subscripts);
426 /// Create debugging information entry for a vector type.
427 /// \param Size Array size.
428 /// \param AlignInBits Alignment.
429 /// \param Ty Element type.
430 /// \param Subscripts Subscripts.
431 DICompositeType *createVectorType(uint64_t Size, uint32_t AlignInBits,
432 DIType *Ty, DINodeArray Subscripts);
434 /// Create debugging information entry for an
436 /// \param Scope Scope in which this enumeration is defined.
437 /// \param Name Union name.
438 /// \param File File where this member is defined.
439 /// \param LineNumber Line number.
440 /// \param SizeInBits Member size.
441 /// \param AlignInBits Member alignment.
442 /// \param Elements Enumeration elements.
443 /// \param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
444 /// \param UniqueIdentifier A unique identifier for the enum.
445 DICompositeType *createEnumerationType(
446 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
447 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
448 DIType *UnderlyingType, StringRef UniqueIdentifier = "");
450 /// Create subroutine type.
451 /// \param ParameterTypes An array of subroutine parameter types. This
452 /// includes return type at 0th index.
453 /// \param Flags E.g.: LValueReference.
454 /// These flags are used to emit dwarf attributes.
455 /// \param CC Calling convention, e.g. dwarf::DW_CC_normal
457 createSubroutineType(DITypeRefArray ParameterTypes,
458 DINode::DIFlags Flags = DINode::FlagZero,
461 /// Create a new DIType* with "artificial" flag set.
462 DIType *createArtificialType(DIType *Ty);
464 /// Create a new DIType* with the "object pointer"
466 DIType *createObjectPointerType(DIType *Ty);
468 /// Create a permanent forward-declared type.
469 DICompositeType *createForwardDecl(unsigned Tag, StringRef Name,
470 DIScope *Scope, DIFile *F, unsigned Line,
471 unsigned RuntimeLang = 0,
472 uint64_t SizeInBits = 0,
473 uint32_t AlignInBits = 0,
474 StringRef UniqueIdentifier = "");
476 /// Create a temporary forward-declared type.
477 DICompositeType *createReplaceableCompositeType(
478 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
479 unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
480 uint32_t AlignInBits = 0, DINode::DIFlags Flags = DINode::FlagFwdDecl,
481 StringRef UniqueIdentifier = "");
483 /// Retain DIScope* in a module even if it is not referenced
484 /// through debug info anchors.
485 void retainType(DIScope *T);
487 /// Create unspecified parameter type
488 /// for a subroutine type.
489 DIBasicType *createUnspecifiedParameter();
491 /// Get a DINodeArray, create one if required.
492 DINodeArray getOrCreateArray(ArrayRef<Metadata *> Elements);
494 /// Get a DIMacroNodeArray, create one if required.
495 DIMacroNodeArray getOrCreateMacroArray(ArrayRef<Metadata *> Elements);
497 /// Get a DITypeRefArray, create one if required.
498 DITypeRefArray getOrCreateTypeArray(ArrayRef<Metadata *> Elements);
500 /// Create a descriptor for a value range. This
501 /// implicitly uniques the values returned.
502 DISubrange *getOrCreateSubrange(int64_t Lo, int64_t Count);
504 /// Create a new descriptor for the specified variable.
505 /// \param Context Variable scope.
506 /// \param Name Name of the variable.
507 /// \param LinkageName Mangled name of the variable.
508 /// \param File File where this variable is defined.
509 /// \param LineNo Line number.
510 /// \param Ty Variable Type.
511 /// \param isLocalToUnit Boolean flag indicate whether this variable is
512 /// externally visible or not.
513 /// \param Expr The location of the global relative to the attached
515 /// \param Decl Reference to the corresponding declaration.
516 /// \param AlignInBits Variable alignment(or 0 if no alignment attr was
518 DIGlobalVariableExpression *createGlobalVariableExpression(
519 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
520 unsigned LineNo, DIType *Ty, bool isLocalToUnit,
521 DIExpression *Expr = nullptr, MDNode *Decl = nullptr,
522 uint32_t AlignInBits = 0);
524 /// Identical to createGlobalVariable
525 /// except that the resulting DbgNode is temporary and meant to be RAUWed.
526 DIGlobalVariable *createTempGlobalVariableFwdDecl(
527 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
528 unsigned LineNo, DIType *Ty, bool isLocalToUnit, MDNode *Decl = nullptr,
529 uint32_t AlignInBits = 0);
531 /// Create a new descriptor for an auto variable. This is a local variable
532 /// that is not a subprogram parameter.
534 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
535 /// leads to a \a DISubprogram.
537 /// If \c AlwaysPreserve, this variable will be referenced from its
538 /// containing subprogram, and will survive some optimizations.
540 createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File,
541 unsigned LineNo, DIType *Ty, bool AlwaysPreserve = false,
542 DINode::DIFlags Flags = DINode::FlagZero,
543 uint32_t AlignInBits = 0);
545 /// Create a new descriptor for a parameter variable.
547 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
548 /// leads to a \a DISubprogram.
550 /// \c ArgNo is the index (starting from \c 1) of this variable in the
551 /// subprogram parameters. \c ArgNo should not conflict with other
552 /// parameters of the same subprogram.
554 /// If \c AlwaysPreserve, this variable will be referenced from its
555 /// containing subprogram, and will survive some optimizations.
557 createParameterVariable(DIScope *Scope, StringRef Name, unsigned ArgNo,
558 DIFile *File, unsigned LineNo, DIType *Ty,
559 bool AlwaysPreserve = false,
560 DINode::DIFlags Flags = DINode::FlagZero);
562 /// Create a new descriptor for the specified
563 /// variable which has a complex address expression for its address.
564 /// \param Addr An array of complex address operations.
565 DIExpression *createExpression(ArrayRef<uint64_t> Addr = None);
566 DIExpression *createExpression(ArrayRef<int64_t> Addr);
568 /// Create an expression for a variable that does not have an address, but
569 /// does have a constant value.
570 DIExpression *createConstantValueExpression(uint64_t Val) {
571 return DIExpression::get(
572 VMContext, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_stack_value});
575 /// Create a new descriptor for the specified subprogram.
576 /// See comments in DISubprogram* for descriptions of these fields.
577 /// \param Scope Function scope.
578 /// \param Name Function name.
579 /// \param LinkageName Mangled function name.
580 /// \param File File where this variable is defined.
581 /// \param LineNo Line number.
582 /// \param Ty Function type.
583 /// \param isLocalToUnit True if this function is not externally visible.
584 /// \param isDefinition True if this is a function definition.
585 /// \param ScopeLine Set to the beginning of the scope this starts
586 /// \param Flags e.g. is this function prototyped or not.
587 /// These flags are used to emit dwarf attributes.
588 /// \param isOptimized True if optimization is ON.
589 /// \param TParams Function template parameters.
590 /// \param ThrownTypes Exception types this function may throw.
591 DISubprogram *createFunction(
592 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
593 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
594 bool isDefinition, unsigned ScopeLine,
595 DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
596 DITemplateParameterArray TParams = nullptr,
597 DISubprogram *Decl = nullptr, DITypeArray ThrownTypes = nullptr);
599 /// Identical to createFunction,
600 /// except that the resulting DbgNode is meant to be RAUWed.
601 DISubprogram *createTempFunctionFwdDecl(
602 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
603 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
604 bool isDefinition, unsigned ScopeLine,
605 DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
606 DITemplateParameterArray TParams = nullptr,
607 DISubprogram *Decl = nullptr, DITypeArray ThrownTypes = nullptr);
609 /// Create a new descriptor for the specified C++ method.
610 /// See comments in \a DISubprogram* for descriptions of these fields.
611 /// \param Scope Function scope.
612 /// \param Name Function name.
613 /// \param LinkageName Mangled function name.
614 /// \param File File where this variable is defined.
615 /// \param LineNo Line number.
616 /// \param Ty Function type.
617 /// \param isLocalToUnit True if this function is not externally visible..
618 /// \param isDefinition True if this is a function definition.
619 /// \param Virtuality Attributes describing virtualness. e.g. pure
620 /// virtual function.
621 /// \param VTableIndex Index no of this method in virtual table, or -1u if
623 /// \param ThisAdjustment
624 /// MS ABI-specific adjustment of 'this' that occurs
626 /// \param VTableHolder Type that holds vtable.
627 /// \param Flags e.g. is this function prototyped or not.
628 /// This flags are used to emit dwarf attributes.
629 /// \param isOptimized True if optimization is ON.
630 /// \param TParams Function template parameters.
631 /// \param ThrownTypes Exception types this function may throw.
632 DISubprogram *createMethod(
633 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
634 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
635 bool isDefinition, unsigned Virtuality = 0, unsigned VTableIndex = 0,
636 int ThisAdjustment = 0, DIType *VTableHolder = nullptr,
637 DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
638 DITemplateParameterArray TParams = nullptr,
639 DITypeArray ThrownTypes = nullptr);
641 /// This creates new descriptor for a namespace with the specified
643 /// \param Scope Namespace scope
644 /// \param Name Name of this namespace
645 /// \param ExportSymbols True for C++ inline namespaces.
646 DINamespace *createNameSpace(DIScope *Scope, StringRef Name,
649 /// This creates new descriptor for a module with the specified
651 /// \param Scope Parent scope
652 /// \param Name Name of this module
653 /// \param ConfigurationMacros
654 /// A space-separated shell-quoted list of -D macro
655 /// definitions as they would appear on a command line.
656 /// \param IncludePath The path to the module map file.
657 /// \param ISysRoot The clang system root (value of -isysroot).
658 DIModule *createModule(DIScope *Scope, StringRef Name,
659 StringRef ConfigurationMacros,
660 StringRef IncludePath,
663 /// This creates a descriptor for a lexical block with a new file
664 /// attached. This merely extends the existing
665 /// lexical block as it crosses a file.
666 /// \param Scope Lexical block.
667 /// \param File Source file.
668 /// \param Discriminator DWARF path discriminator value.
669 DILexicalBlockFile *createLexicalBlockFile(DIScope *Scope, DIFile *File,
670 unsigned Discriminator = 0);
672 /// This creates a descriptor for a lexical block with the
673 /// specified parent context.
674 /// \param Scope Parent lexical scope.
675 /// \param File Source file.
676 /// \param Line Line number.
677 /// \param Col Column number.
678 DILexicalBlock *createLexicalBlock(DIScope *Scope, DIFile *File,
679 unsigned Line, unsigned Col);
681 /// Create a descriptor for an imported module.
682 /// \param Context The scope this module is imported into
683 /// \param NS The namespace being imported here.
684 /// \param File File where the declaration is located.
685 /// \param Line Line number of the declaration.
686 DIImportedEntity *createImportedModule(DIScope *Context, DINamespace *NS,
687 DIFile *File, unsigned Line);
689 /// Create a descriptor for an imported module.
690 /// \param Context The scope this module is imported into.
691 /// \param NS An aliased namespace.
692 /// \param File File where the declaration is located.
693 /// \param Line Line number of the declaration.
694 DIImportedEntity *createImportedModule(DIScope *Context,
695 DIImportedEntity *NS, DIFile *File,
698 /// Create a descriptor for an imported module.
699 /// \param Context The scope this module is imported into.
700 /// \param M The module being imported here
701 /// \param File File where the declaration is located.
702 /// \param Line Line number of the declaration.
703 DIImportedEntity *createImportedModule(DIScope *Context, DIModule *M,
704 DIFile *File, unsigned Line);
706 /// Create a descriptor for an imported function.
707 /// \param Context The scope this module is imported into.
708 /// \param Decl The declaration (or definition) of a function, type, or
710 /// \param File File where the declaration is located.
711 /// \param Line Line number of the declaration.
712 DIImportedEntity *createImportedDeclaration(DIScope *Context, DINode *Decl,
713 DIFile *File, unsigned Line,
714 StringRef Name = "");
716 /// Insert a new llvm.dbg.declare intrinsic call.
717 /// \param Storage llvm::Value of the variable
718 /// \param VarInfo Variable's debug info descriptor.
719 /// \param Expr A complex location expression.
720 /// \param DL Debug info location.
721 /// \param InsertAtEnd Location for the new intrinsic.
722 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
723 DIExpression *Expr, const DILocation *DL,
724 BasicBlock *InsertAtEnd);
726 /// Insert a new llvm.dbg.declare intrinsic call.
727 /// \param Storage llvm::Value of the variable
728 /// \param VarInfo Variable's debug info descriptor.
729 /// \param Expr A complex location expression.
730 /// \param DL Debug info location.
731 /// \param InsertBefore Location for the new intrinsic.
732 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
733 DIExpression *Expr, const DILocation *DL,
734 Instruction *InsertBefore);
736 /// Insert a new llvm.dbg.value intrinsic call.
737 /// \param Val llvm::Value of the variable
738 /// \param VarInfo Variable's debug info descriptor.
739 /// \param Expr A complex location expression.
740 /// \param DL Debug info location.
741 /// \param InsertAtEnd Location for the new intrinsic.
742 Instruction *insertDbgValueIntrinsic(llvm::Value *Val,
743 DILocalVariable *VarInfo,
745 const DILocation *DL,
746 BasicBlock *InsertAtEnd);
748 /// Insert a new llvm.dbg.value intrinsic call.
749 /// \param Val llvm::Value of the variable
750 /// \param VarInfo Variable's debug info descriptor.
751 /// \param Expr A complex location expression.
752 /// \param DL Debug info location.
753 /// \param InsertBefore Location for the new intrinsic.
754 Instruction *insertDbgValueIntrinsic(llvm::Value *Val,
755 DILocalVariable *VarInfo,
757 const DILocation *DL,
758 Instruction *InsertBefore);
760 /// Replace the vtable holder in the given type.
762 /// If this creates a self reference, it may orphan some unresolved cycles
763 /// in the operands of \c T, so \a DIBuilder needs to track that.
764 void replaceVTableHolder(DICompositeType *&T,
765 DIType *VTableHolder);
767 /// Replace arrays on a composite type.
769 /// If \c T is resolved, but the arrays aren't -- which can happen if \c T
770 /// has a self-reference -- \a DIBuilder needs to track the array to
772 void replaceArrays(DICompositeType *&T, DINodeArray Elements,
773 DINodeArray TParams = DINodeArray());
775 /// Replace a temporary node.
777 /// Call \a MDNode::replaceAllUsesWith() on \c N, replacing it with \c
780 /// If \c Replacement is the same as \c N.get(), instead call \a
781 /// MDNode::replaceWithUniqued(). In this case, the uniqued node could
782 /// have a different address, so we return the final address.
783 template <class NodeTy>
784 NodeTy *replaceTemporary(TempMDNode &&N, NodeTy *Replacement) {
785 if (N.get() == Replacement)
786 return cast<NodeTy>(MDNode::replaceWithUniqued(std::move(N)));
788 N->replaceAllUsesWith(Replacement);
793 // Create wrappers for C Binding types (see CBindingWrapping.h).
794 DEFINE_ISA_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
796 } // end namespace llvm
798 #endif // LLVM_IR_DIBUILDER_H