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.
108 /// \param SplitDebugInlining Whether to emit inline debug info.
109 /// \param DebugInfoForProfiling Whether to emit extra debug info for
110 /// profile collection.
112 createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
113 bool isOptimized, StringRef Flags, unsigned RV,
114 StringRef SplitName = StringRef(),
115 DICompileUnit::DebugEmissionKind Kind =
116 DICompileUnit::DebugEmissionKind::FullDebug,
117 uint64_t DWOId = 0, bool SplitDebugInlining = true,
118 bool DebugInfoForProfiling = false);
120 /// Create a file descriptor to hold debugging information for a file.
121 /// \param Filename File name.
122 /// \param Directory Directory.
123 /// \param CSKind Checksum kind (e.g. CSK_None, CSK_MD5, CSK_SHA1, etc.).
124 /// \param Checksum Checksum data.
125 DIFile *createFile(StringRef Filename, StringRef Directory,
126 DIFile::ChecksumKind CSKind = DIFile::CSK_None,
127 StringRef Checksum = StringRef());
129 /// Create debugging information entry for a macro.
130 /// \param Parent Macro parent (could be nullptr).
131 /// \param Line Source line number where the macro is defined.
132 /// \param MacroType DW_MACINFO_define or DW_MACINFO_undef.
133 /// \param Name Macro name.
134 /// \param Value Macro value.
135 DIMacro *createMacro(DIMacroFile *Parent, unsigned Line, unsigned MacroType,
136 StringRef Name, StringRef Value = StringRef());
138 /// Create debugging information temporary entry for a macro file.
139 /// List of macro node direct children will be calculated by DIBuilder,
140 /// using the \p Parent relationship.
141 /// \param Parent Macro file parent (could be nullptr).
142 /// \param Line Source line number where the macro file is included.
143 /// \param File File descriptor containing the name of the macro file.
144 DIMacroFile *createTempMacroFile(DIMacroFile *Parent, unsigned Line,
147 /// Create a single enumerator value.
148 DIEnumerator *createEnumerator(StringRef Name, int64_t Val);
150 /// Create a DWARF unspecified type.
151 DIBasicType *createUnspecifiedType(StringRef Name);
153 /// Create C++11 nullptr type.
154 DIBasicType *createNullPtrType();
156 /// Create debugging information entry for a basic
158 /// \param Name Type name.
159 /// \param SizeInBits Size of the type.
160 /// \param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
161 DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
164 /// Create debugging information entry for a qualified
165 /// type, e.g. 'const int'.
166 /// \param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
167 /// \param FromTy Base Type.
168 DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy);
170 /// Create debugging information entry for a pointer.
171 /// \param PointeeTy Type pointed by this pointer.
172 /// \param SizeInBits Size.
173 /// \param AlignInBits Alignment. (optional)
174 /// \param DWARFAddressSpace DWARF address space. (optional)
175 /// \param Name Pointer type name. (optional)
176 DIDerivedType *createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
177 uint32_t AlignInBits = 0,
178 Optional<unsigned> DWARFAddressSpace =
180 StringRef Name = "");
182 /// Create debugging information entry for a pointer to member.
183 /// \param PointeeTy Type pointed to by this pointer.
184 /// \param SizeInBits Size.
185 /// \param AlignInBits Alignment. (optional)
186 /// \param Class Type for which this pointer points to members of.
188 createMemberPointerType(DIType *PointeeTy, DIType *Class,
189 uint64_t SizeInBits, uint32_t AlignInBits = 0,
190 DINode::DIFlags Flags = DINode::FlagZero);
192 /// Create debugging information entry for a c++
193 /// style reference or rvalue reference type.
194 DIDerivedType *createReferenceType(unsigned Tag, DIType *RTy,
195 uint64_t SizeInBits = 0,
196 uint32_t AlignInBits = 0,
197 Optional<unsigned> DWARFAddressSpace =
200 /// Create debugging information entry for a typedef.
201 /// \param Ty Original type.
202 /// \param Name Typedef name.
203 /// \param File File where this type is defined.
204 /// \param LineNo Line number.
205 /// \param Context The surrounding context for the typedef.
206 DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File,
207 unsigned LineNo, DIScope *Context);
209 /// Create debugging information entry for a 'friend'.
210 DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy);
212 /// Create debugging information entry to establish
213 /// inheritance relationship between two types.
214 /// \param Ty Original type.
215 /// \param BaseTy Base type. Ty is inherits from base.
216 /// \param BaseOffset Base offset.
217 /// \param Flags Flags to describe inheritance attribute,
219 DIDerivedType *createInheritance(DIType *Ty, DIType *BaseTy,
221 DINode::DIFlags Flags);
223 /// Create debugging information entry for a member.
224 /// \param Scope Member scope.
225 /// \param Name Member name.
226 /// \param File File where this member is defined.
227 /// \param LineNo Line number.
228 /// \param SizeInBits Member size.
229 /// \param AlignInBits Member alignment.
230 /// \param OffsetInBits Member offset.
231 /// \param Flags Flags to encode member attribute, e.g. private
232 /// \param Ty Parent type.
233 DIDerivedType *createMemberType(DIScope *Scope, StringRef Name,
234 DIFile *File, unsigned LineNo,
236 uint32_t AlignInBits,
237 uint64_t OffsetInBits,
238 DINode::DIFlags Flags, DIType *Ty);
240 /// Create debugging information entry for a bit field member.
241 /// \param Scope Member scope.
242 /// \param Name Member name.
243 /// \param File File where this member is defined.
244 /// \param LineNo Line number.
245 /// \param SizeInBits Member size.
246 /// \param OffsetInBits Member offset.
247 /// \param StorageOffsetInBits Member storage offset.
248 /// \param Flags Flags to encode member attribute.
249 /// \param Ty Parent type.
250 DIDerivedType *createBitFieldMemberType(
251 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo,
252 uint64_t SizeInBits, uint64_t OffsetInBits,
253 uint64_t StorageOffsetInBits, DINode::DIFlags Flags, DIType *Ty);
255 /// Create debugging information entry for a
256 /// C++ static data member.
257 /// \param Scope Member scope.
258 /// \param Name Member name.
259 /// \param File File where this member is declared.
260 /// \param LineNo Line number.
261 /// \param Ty Type of the static member.
262 /// \param Flags Flags to encode member attribute, e.g. private.
263 /// \param Val Const initializer of the member.
264 /// \param AlignInBits Member alignment.
265 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
266 DIFile *File, unsigned LineNo,
267 DIType *Ty, DINode::DIFlags Flags,
269 uint32_t AlignInBits = 0);
271 /// Create debugging information entry for Objective-C
272 /// instance variable.
273 /// \param Name Member name.
274 /// \param File File where this member is defined.
275 /// \param LineNo Line number.
276 /// \param SizeInBits Member size.
277 /// \param AlignInBits Member alignment.
278 /// \param OffsetInBits Member offset.
279 /// \param Flags Flags to encode member attribute, e.g. private
280 /// \param Ty Parent type.
281 /// \param PropertyNode Property associated with this ivar.
282 DIDerivedType *createObjCIVar(StringRef Name, DIFile *File, unsigned LineNo,
283 uint64_t SizeInBits, uint32_t AlignInBits,
284 uint64_t OffsetInBits, DINode::DIFlags Flags,
285 DIType *Ty, MDNode *PropertyNode);
287 /// Create debugging information entry for Objective-C
289 /// \param Name Property name.
290 /// \param File File where this property is defined.
291 /// \param LineNumber Line number.
292 /// \param GetterName Name of the Objective C property getter selector.
293 /// \param SetterName Name of the Objective C property setter selector.
294 /// \param PropertyAttributes Objective C property attributes.
296 DIObjCProperty *createObjCProperty(StringRef Name, DIFile *File,
298 StringRef GetterName,
299 StringRef SetterName,
300 unsigned PropertyAttributes, DIType *Ty);
302 /// Create debugging information entry for a class.
303 /// \param Scope Scope in which this class is defined.
304 /// \param Name class name.
305 /// \param File File where this member is defined.
306 /// \param LineNumber Line number.
307 /// \param SizeInBits Member size.
308 /// \param AlignInBits Member alignment.
309 /// \param OffsetInBits Member offset.
310 /// \param Flags Flags to encode member attribute, e.g. private
311 /// \param Elements class members.
312 /// \param VTableHolder Debug info of the base class that contains vtable
313 /// for this type. This is used in
314 /// DW_AT_containing_type. See DWARF documentation
316 /// \param TemplateParms Template type parameters.
317 /// \param UniqueIdentifier A unique identifier for the class.
318 DICompositeType *createClassType(
319 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
320 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
321 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
322 DIType *VTableHolder = nullptr, MDNode *TemplateParms = nullptr,
323 StringRef UniqueIdentifier = "");
325 /// Create debugging information entry for a struct.
326 /// \param Scope Scope in which this struct is defined.
327 /// \param Name Struct name.
328 /// \param File File where this member is defined.
329 /// \param LineNumber Line number.
330 /// \param SizeInBits Member size.
331 /// \param AlignInBits Member alignment.
332 /// \param Flags Flags to encode member attribute, e.g. private
333 /// \param Elements Struct elements.
334 /// \param RunTimeLang Optional parameter, Objective-C runtime version.
335 /// \param UniqueIdentifier A unique identifier for the struct.
336 DICompositeType *createStructType(
337 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
338 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
339 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0,
340 DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
342 /// Create debugging information entry for an union.
343 /// \param Scope Scope in which this union is defined.
344 /// \param Name Union name.
345 /// \param File File where this member is defined.
346 /// \param LineNumber Line number.
347 /// \param SizeInBits Member size.
348 /// \param AlignInBits Member alignment.
349 /// \param Flags Flags to encode member attribute, e.g. private
350 /// \param Elements Union elements.
351 /// \param RunTimeLang Optional parameter, Objective-C runtime version.
352 /// \param UniqueIdentifier A unique identifier for the union.
353 DICompositeType *createUnionType(DIScope *Scope, StringRef Name,
354 DIFile *File, unsigned LineNumber,
355 uint64_t SizeInBits, uint32_t AlignInBits,
356 DINode::DIFlags Flags,
357 DINodeArray Elements,
358 unsigned RunTimeLang = 0,
359 StringRef UniqueIdentifier = "");
361 /// Create debugging information for template
363 /// \param Scope Scope in which this type is defined.
364 /// \param Name Type parameter name.
365 /// \param Ty Parameter type.
366 DITemplateTypeParameter *
367 createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty);
369 /// Create debugging information for template
371 /// \param Scope Scope in which this type is defined.
372 /// \param Name Value parameter name.
373 /// \param Ty Parameter type.
374 /// \param Val Constant parameter value.
375 DITemplateValueParameter *createTemplateValueParameter(DIScope *Scope,
380 /// Create debugging information for a template template parameter.
381 /// \param Scope Scope in which this type is defined.
382 /// \param Name Value parameter name.
383 /// \param Ty Parameter type.
384 /// \param Val The fully qualified name of the template.
385 DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
390 /// Create debugging information for a template parameter pack.
391 /// \param Scope Scope in which this type is defined.
392 /// \param Name Value parameter name.
393 /// \param Ty Parameter type.
394 /// \param Val An array of types in the pack.
395 DITemplateValueParameter *createTemplateParameterPack(DIScope *Scope,
400 /// Create debugging information entry for an array.
401 /// \param Size Array size.
402 /// \param AlignInBits Alignment.
403 /// \param Ty Element type.
404 /// \param Subscripts Subscripts.
405 DICompositeType *createArrayType(uint64_t Size, uint32_t AlignInBits,
406 DIType *Ty, DINodeArray Subscripts);
408 /// Create debugging information entry for a vector type.
409 /// \param Size Array size.
410 /// \param AlignInBits Alignment.
411 /// \param Ty Element type.
412 /// \param Subscripts Subscripts.
413 DICompositeType *createVectorType(uint64_t Size, uint32_t AlignInBits,
414 DIType *Ty, DINodeArray Subscripts);
416 /// Create debugging information entry for an
418 /// \param Scope Scope in which this enumeration is defined.
419 /// \param Name Union name.
420 /// \param File File where this member is defined.
421 /// \param LineNumber Line number.
422 /// \param SizeInBits Member size.
423 /// \param AlignInBits Member alignment.
424 /// \param Elements Enumeration elements.
425 /// \param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
426 /// \param UniqueIdentifier A unique identifier for the enum.
427 DICompositeType *createEnumerationType(
428 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
429 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
430 DIType *UnderlyingType, StringRef UniqueIdentifier = "");
432 /// Create subroutine type.
433 /// \param ParameterTypes An array of subroutine parameter types. This
434 /// includes return type at 0th index.
435 /// \param Flags E.g.: LValueReference.
436 /// These flags are used to emit dwarf attributes.
437 /// \param CC Calling convention, e.g. dwarf::DW_CC_normal
439 createSubroutineType(DITypeRefArray ParameterTypes,
440 DINode::DIFlags Flags = DINode::FlagZero,
443 /// Create a new DIType* with "artificial" flag set.
444 DIType *createArtificialType(DIType *Ty);
446 /// Create a new DIType* with the "object pointer"
448 DIType *createObjectPointerType(DIType *Ty);
450 /// Create a permanent forward-declared type.
451 DICompositeType *createForwardDecl(unsigned Tag, StringRef Name,
452 DIScope *Scope, DIFile *F, unsigned Line,
453 unsigned RuntimeLang = 0,
454 uint64_t SizeInBits = 0,
455 uint32_t AlignInBits = 0,
456 StringRef UniqueIdentifier = "");
458 /// Create a temporary forward-declared type.
459 DICompositeType *createReplaceableCompositeType(
460 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
461 unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
462 uint32_t AlignInBits = 0, DINode::DIFlags Flags = DINode::FlagFwdDecl,
463 StringRef UniqueIdentifier = "");
465 /// Retain DIScope* in a module even if it is not referenced
466 /// through debug info anchors.
467 void retainType(DIScope *T);
469 /// Create unspecified parameter type
470 /// for a subroutine type.
471 DIBasicType *createUnspecifiedParameter();
473 /// Get a DINodeArray, create one if required.
474 DINodeArray getOrCreateArray(ArrayRef<Metadata *> Elements);
476 /// Get a DIMacroNodeArray, create one if required.
477 DIMacroNodeArray getOrCreateMacroArray(ArrayRef<Metadata *> Elements);
479 /// Get a DITypeRefArray, create one if required.
480 DITypeRefArray getOrCreateTypeArray(ArrayRef<Metadata *> Elements);
482 /// Create a descriptor for a value range. This
483 /// implicitly uniques the values returned.
484 DISubrange *getOrCreateSubrange(int64_t Lo, int64_t Count);
486 /// Create a new descriptor for the specified variable.
487 /// \param Context Variable scope.
488 /// \param Name Name of the variable.
489 /// \param LinkageName Mangled name of the variable.
490 /// \param File File where this variable is defined.
491 /// \param LineNo Line number.
492 /// \param Ty Variable Type.
493 /// \param isLocalToUnit Boolean flag indicate whether this variable is
494 /// externally visible or not.
495 /// \param Expr The location of the global relative to the attached
497 /// \param Decl Reference to the corresponding declaration.
498 /// \param AlignInBits Variable alignment(or 0 if no alignment attr was
500 DIGlobalVariableExpression *createGlobalVariableExpression(
501 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
502 unsigned LineNo, DIType *Ty, bool isLocalToUnit,
503 DIExpression *Expr = nullptr, MDNode *Decl = nullptr,
504 uint32_t AlignInBits = 0);
506 /// Identical to createGlobalVariable
507 /// except that the resulting DbgNode is temporary and meant to be RAUWed.
508 DIGlobalVariable *createTempGlobalVariableFwdDecl(
509 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
510 unsigned LineNo, DIType *Ty, bool isLocalToUnit, MDNode *Decl = nullptr,
511 uint32_t AlignInBits = 0);
513 /// Create a new descriptor for an auto variable. This is a local variable
514 /// that is not a subprogram parameter.
516 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
517 /// leads to a \a DISubprogram.
519 /// If \c AlwaysPreserve, this variable will be referenced from its
520 /// containing subprogram, and will survive some optimizations.
522 createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File,
523 unsigned LineNo, DIType *Ty, bool AlwaysPreserve = false,
524 DINode::DIFlags Flags = DINode::FlagZero,
525 uint32_t AlignInBits = 0);
527 /// Create a new descriptor for a parameter variable.
529 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
530 /// leads to a \a DISubprogram.
532 /// \c ArgNo is the index (starting from \c 1) of this variable in the
533 /// subprogram parameters. \c ArgNo should not conflict with other
534 /// parameters of the same subprogram.
536 /// If \c AlwaysPreserve, this variable will be referenced from its
537 /// containing subprogram, and will survive some optimizations.
539 createParameterVariable(DIScope *Scope, StringRef Name, unsigned ArgNo,
540 DIFile *File, unsigned LineNo, DIType *Ty,
541 bool AlwaysPreserve = false,
542 DINode::DIFlags Flags = DINode::FlagZero);
544 /// Create a new descriptor for the specified
545 /// variable which has a complex address expression for its address.
546 /// \param Addr An array of complex address operations.
547 DIExpression *createExpression(ArrayRef<uint64_t> Addr = None);
548 DIExpression *createExpression(ArrayRef<int64_t> Addr);
550 /// Create a descriptor to describe one part
551 /// of aggregate variable that is fragmented across multiple Values.
553 /// \param OffsetInBits Offset of the piece in bits.
554 /// \param SizeInBits Size of the piece in bits.
555 DIExpression *createFragmentExpression(unsigned OffsetInBits,
556 unsigned SizeInBits);
558 /// Create an expression for a variable that does not have an address, but
559 /// does have a constant value.
560 DIExpression *createConstantValueExpression(uint64_t Val) {
561 return DIExpression::get(
562 VMContext, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_stack_value});
565 /// Create a new descriptor for the specified subprogram.
566 /// See comments in DISubprogram* for descriptions of these fields.
567 /// \param Scope Function scope.
568 /// \param Name Function name.
569 /// \param LinkageName Mangled function name.
570 /// \param File File where this variable is defined.
571 /// \param LineNo Line number.
572 /// \param Ty Function type.
573 /// \param isLocalToUnit True if this function is not externally visible.
574 /// \param isDefinition True if this is a function definition.
575 /// \param ScopeLine Set to the beginning of the scope this starts
576 /// \param Flags e.g. is this function prototyped or not.
577 /// These flags are used to emit dwarf attributes.
578 /// \param isOptimized True if optimization is ON.
579 /// \param TParams Function template parameters.
580 /// \param ThrownTypes Exception types this function may throw.
581 DISubprogram *createFunction(
582 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
583 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
584 bool isDefinition, unsigned ScopeLine,
585 DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
586 DITemplateParameterArray TParams = nullptr,
587 DISubprogram *Decl = nullptr, DITypeArray ThrownTypes = nullptr);
589 /// Identical to createFunction,
590 /// except that the resulting DbgNode is meant to be RAUWed.
591 DISubprogram *createTempFunctionFwdDecl(
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 /// Create a new descriptor for the specified C++ method.
600 /// See comments in \a DISubprogram* for descriptions of these fields.
601 /// \param Scope Function scope.
602 /// \param Name Function name.
603 /// \param LinkageName Mangled function name.
604 /// \param File File where this variable is defined.
605 /// \param LineNo Line number.
606 /// \param Ty Function type.
607 /// \param isLocalToUnit True if this function is not externally visible..
608 /// \param isDefinition True if this is a function definition.
609 /// \param Virtuality Attributes describing virtualness. e.g. pure
610 /// virtual function.
611 /// \param VTableIndex Index no of this method in virtual table, or -1u if
613 /// \param ThisAdjustment
614 /// MS ABI-specific adjustment of 'this' that occurs
616 /// \param VTableHolder Type that holds vtable.
617 /// \param Flags e.g. is this function prototyped or not.
618 /// This flags are used to emit dwarf attributes.
619 /// \param isOptimized True if optimization is ON.
620 /// \param TParams Function template parameters.
621 /// \param ThrownTypes Exception types this function may throw.
622 DISubprogram *createMethod(
623 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
624 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
625 bool isDefinition, unsigned Virtuality = 0, unsigned VTableIndex = 0,
626 int ThisAdjustment = 0, DIType *VTableHolder = nullptr,
627 DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
628 DITemplateParameterArray TParams = nullptr,
629 DITypeArray ThrownTypes = nullptr);
631 /// This creates new descriptor for a namespace with the specified
633 /// \param Scope Namespace scope
634 /// \param Name Name of this namespace
635 /// \param ExportSymbols True for C++ inline namespaces.
636 DINamespace *createNameSpace(DIScope *Scope, StringRef Name,
639 /// This creates new descriptor for a module with the specified
641 /// \param Scope Parent scope
642 /// \param Name Name of this module
643 /// \param ConfigurationMacros
644 /// A space-separated shell-quoted list of -D macro
645 /// definitions as they would appear on a command line.
646 /// \param IncludePath The path to the module map file.
647 /// \param ISysRoot The clang system root (value of -isysroot).
648 DIModule *createModule(DIScope *Scope, StringRef Name,
649 StringRef ConfigurationMacros,
650 StringRef IncludePath,
653 /// This creates a descriptor for a lexical block with a new file
654 /// attached. This merely extends the existing
655 /// lexical block as it crosses a file.
656 /// \param Scope Lexical block.
657 /// \param File Source file.
658 /// \param Discriminator DWARF path discriminator value.
659 DILexicalBlockFile *createLexicalBlockFile(DIScope *Scope, DIFile *File,
660 unsigned Discriminator = 0);
662 /// This creates a descriptor for a lexical block with the
663 /// specified parent context.
664 /// \param Scope Parent lexical scope.
665 /// \param File Source file.
666 /// \param Line Line number.
667 /// \param Col Column number.
668 DILexicalBlock *createLexicalBlock(DIScope *Scope, DIFile *File,
669 unsigned Line, unsigned Col);
671 /// Create a descriptor for an imported module.
672 /// \param Context The scope this module is imported into
673 /// \param NS The namespace being imported here
674 /// \param Line Line number
675 DIImportedEntity *createImportedModule(DIScope *Context, DINamespace *NS,
678 /// Create a descriptor for an imported module.
679 /// \param Context The scope this module is imported into
680 /// \param NS An aliased namespace
681 /// \param Line Line number
682 DIImportedEntity *createImportedModule(DIScope *Context,
683 DIImportedEntity *NS, unsigned Line);
685 /// Create a descriptor for an imported module.
686 /// \param Context The scope this module is imported into
687 /// \param M The module being imported here
688 /// \param Line Line number
689 DIImportedEntity *createImportedModule(DIScope *Context, DIModule *M,
692 /// Create a descriptor for an imported function.
693 /// \param Context The scope this module is imported into
694 /// \param Decl The declaration (or definition) of a function, type, or
696 /// \param Line Line number
697 DIImportedEntity *createImportedDeclaration(DIScope *Context, DINode *Decl,
699 StringRef Name = "");
701 /// Insert a new llvm.dbg.declare intrinsic call.
702 /// \param Storage llvm::Value of the variable
703 /// \param VarInfo Variable's debug info descriptor.
704 /// \param Expr A complex location expression.
705 /// \param DL Debug info location.
706 /// \param InsertAtEnd Location for the new intrinsic.
707 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
708 DIExpression *Expr, const DILocation *DL,
709 BasicBlock *InsertAtEnd);
711 /// Insert a new llvm.dbg.declare intrinsic call.
712 /// \param Storage llvm::Value of the variable
713 /// \param VarInfo Variable's debug info descriptor.
714 /// \param Expr A complex location expression.
715 /// \param DL Debug info location.
716 /// \param InsertBefore Location for the new intrinsic.
717 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
718 DIExpression *Expr, const DILocation *DL,
719 Instruction *InsertBefore);
721 /// Insert a new llvm.dbg.value intrinsic call.
722 /// \param Val llvm::Value of the variable
723 /// \param Offset Offset
724 /// \param VarInfo Variable's debug info descriptor.
725 /// \param Expr A complex location expression.
726 /// \param DL Debug info location.
727 /// \param InsertAtEnd Location for the new intrinsic.
728 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
729 DILocalVariable *VarInfo,
731 const DILocation *DL,
732 BasicBlock *InsertAtEnd);
734 /// Insert a new llvm.dbg.value intrinsic call.
735 /// \param Val llvm::Value of the variable
736 /// \param Offset Offset
737 /// \param VarInfo Variable's debug info descriptor.
738 /// \param Expr A complex location expression.
739 /// \param DL Debug info location.
740 /// \param InsertBefore Location for the new intrinsic.
741 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
742 DILocalVariable *VarInfo,
744 const DILocation *DL,
745 Instruction *InsertBefore);
747 /// Replace the vtable holder in the given composite type.
749 /// If this creates a self reference, it may orphan some unresolved cycles
750 /// in the operands of \c T, so \a DIBuilder needs to track that.
751 void replaceVTableHolder(DICompositeType *&T,
752 DICompositeType *VTableHolder);
754 /// Replace arrays on a composite type.
756 /// If \c T is resolved, but the arrays aren't -- which can happen if \c T
757 /// has a self-reference -- \a DIBuilder needs to track the array to
759 void replaceArrays(DICompositeType *&T, DINodeArray Elements,
760 DINodeArray TParams = DINodeArray());
762 /// Replace a temporary node.
764 /// Call \a MDNode::replaceAllUsesWith() on \c N, replacing it with \c
767 /// If \c Replacement is the same as \c N.get(), instead call \a
768 /// MDNode::replaceWithUniqued(). In this case, the uniqued node could
769 /// have a different address, so we return the final address.
770 template <class NodeTy>
771 NodeTy *replaceTemporary(TempMDNode &&N, NodeTy *Replacement) {
772 if (N.get() == Replacement)
773 return cast<NodeTy>(MDNode::replaceWithUniqued(std::move(N)));
775 N->replaceAllUsesWith(Replacement);
780 // Create wrappers for C Binding types (see CBindingWrapping.h).
781 DEFINE_ISA_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
783 } // end namespace llvm
785 #endif // LLVM_IR_DIBUILDER_H