xref: /openbsd/gnu/llvm/llvm/include/llvm/IR/DIBuilder.h (revision d415bd75)
1 //===- DIBuilder.h - Debug Information Builder ------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a DIBuilder that is useful for creating debugging
10 // information entries in LLVM IR form.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_DIBUILDER_H
15 #define LLVM_IR_DIBUILDER_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/MapVector.h"
20 #include "llvm/ADT/SetVector.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/BinaryFormat/Dwarf.h"
24 #include "llvm/IR/DebugInfoMetadata.h"
25 #include "llvm/IR/TrackingMDRef.h"
26 #include "llvm/Support/Casting.h"
27 #include <algorithm>
28 #include <cstdint>
29 #include <optional>
30 
31 namespace llvm {
32 
33   class BasicBlock;
34   class Constant;
35   class Function;
36   class Instruction;
37   class LLVMContext;
38   class Module;
39   class Value;
40   class DbgAssignIntrinsic;
41 
42   class DIBuilder {
43     Module &M;
44     LLVMContext &VMContext;
45 
46     DICompileUnit *CUNode;   ///< The one compile unit created by this DIBuiler.
47     Function *DeclareFn;     ///< llvm.dbg.declare
48     Function *ValueFn;       ///< llvm.dbg.value
49     Function *LabelFn;       ///< llvm.dbg.label
50     Function *AddrFn;        ///< llvm.dbg.addr
51     Function *AssignFn;      ///< llvm.dbg.assign
52 
53     SmallVector<TrackingMDNodeRef, 4> AllEnumTypes;
54     /// Track the RetainTypes, since they can be updated later on.
55     SmallVector<TrackingMDNodeRef, 4> AllRetainTypes;
56     SmallVector<Metadata *, 4> AllSubprograms;
57     SmallVector<Metadata *, 4> AllGVs;
58     SmallVector<TrackingMDNodeRef, 4> AllImportedModules;
59     /// Map Macro parent (which can be DIMacroFile or nullptr) to a list of
60     /// Metadata all of type DIMacroNode.
61     /// DIMacroNode's with nullptr parent are DICompileUnit direct children.
62     MapVector<MDNode *, SetVector<Metadata *>> AllMacrosPerParent;
63 
64     /// Track nodes that may be unresolved.
65     SmallVector<TrackingMDNodeRef, 4> UnresolvedNodes;
66     bool AllowUnresolvedNodes;
67 
68     /// Each subprogram's preserved local variables.
69     ///
70     /// Do not use a std::vector.  Some versions of libc++ apparently copy
71     /// instead of move on grow operations, and TrackingMDRef is expensive to
72     /// copy.
73     DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> PreservedVariables;
74 
75     /// Each subprogram's preserved labels.
76     DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> PreservedLabels;
77 
78     /// Create a temporary.
79     ///
80     /// Create an \a temporary node and track it in \a UnresolvedNodes.
81     void trackIfUnresolved(MDNode *N);
82 
83     /// Internal helper for insertDeclare.
84     Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
85                                DIExpression *Expr, const DILocation *DL,
86                                BasicBlock *InsertBB, Instruction *InsertBefore);
87 
88     /// Internal helper for insertLabel.
89     Instruction *insertLabel(DILabel *LabelInfo, const DILocation *DL,
90                              BasicBlock *InsertBB, Instruction *InsertBefore);
91 
92     /// Internal helper with common code used by insertDbg{Value,Addr}Intrinsic.
93     Instruction *insertDbgIntrinsic(llvm::Function *Intrinsic, llvm::Value *Val,
94                                     DILocalVariable *VarInfo,
95                                     DIExpression *Expr, const DILocation *DL,
96                                     BasicBlock *InsertBB,
97                                     Instruction *InsertBefore);
98 
99     /// Internal helper for insertDbgValueIntrinsic.
100     Instruction *
101     insertDbgValueIntrinsic(llvm::Value *Val, DILocalVariable *VarInfo,
102                             DIExpression *Expr, const DILocation *DL,
103                             BasicBlock *InsertBB, Instruction *InsertBefore);
104 
105     /// Internal helper for insertDbgAddrIntrinsic.
106     Instruction *
107     insertDbgAddrIntrinsic(llvm::Value *Val, DILocalVariable *VarInfo,
108                            DIExpression *Expr, const DILocation *DL,
109                            BasicBlock *InsertBB, Instruction *InsertBefore);
110 
111   public:
112     /// Construct a builder for a module.
113     ///
114     /// If \c AllowUnresolved, collect unresolved nodes attached to the module
115     /// in order to resolve cycles during \a finalize().
116     ///
117     /// If \p CU is given a value other than nullptr, then set \p CUNode to CU.
118     explicit DIBuilder(Module &M, bool AllowUnresolved = true,
119                        DICompileUnit *CU = nullptr);
120     DIBuilder(const DIBuilder &) = delete;
121     DIBuilder &operator=(const DIBuilder &) = delete;
122 
123     /// Construct any deferred debug info descriptors.
124     void finalize();
125 
126     /// Finalize a specific subprogram - no new variables may be added to this
127     /// subprogram afterwards.
128     void finalizeSubprogram(DISubprogram *SP);
129 
130     /// A CompileUnit provides an anchor for all debugging
131     /// information generated during this instance of compilation.
132     /// \param Lang          Source programming language, eg. dwarf::DW_LANG_C99
133     /// \param File          File info.
134     /// \param Producer      Identify the producer of debugging information
135     ///                      and code.  Usually this is a compiler
136     ///                      version string.
137     /// \param isOptimized   A boolean flag which indicates whether optimization
138     ///                      is enabled or not.
139     /// \param Flags         This string lists command line options. This
140     ///                      string is directly embedded in debug info
141     ///                      output which may be used by a tool
142     ///                      analyzing generated debugging information.
143     /// \param RV            This indicates runtime version for languages like
144     ///                      Objective-C.
145     /// \param SplitName     The name of the file that we'll split debug info
146     ///                      out into.
147     /// \param Kind          The kind of debug information to generate.
148     /// \param DWOId         The DWOId if this is a split skeleton compile unit.
149     /// \param SplitDebugInlining    Whether to emit inline debug info.
150     /// \param DebugInfoForProfiling Whether to emit extra debug info for
151     ///                              profile collection.
152     /// \param NameTableKind  Whether to emit .debug_gnu_pubnames,
153     ///                      .debug_pubnames, or no pubnames at all.
154     /// \param SysRoot       The clang system root (value of -isysroot).
155     /// \param SDK           The SDK name. On Darwin, this is the last component
156     ///                      of the sysroot.
157     DICompileUnit *
158     createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
159                       bool isOptimized, StringRef Flags, unsigned RV,
160                       StringRef SplitName = StringRef(),
161                       DICompileUnit::DebugEmissionKind Kind =
162                           DICompileUnit::DebugEmissionKind::FullDebug,
163                       uint64_t DWOId = 0, bool SplitDebugInlining = true,
164                       bool DebugInfoForProfiling = false,
165                       DICompileUnit::DebugNameTableKind NameTableKind =
166                           DICompileUnit::DebugNameTableKind::Default,
167                       bool RangesBaseAddress = false, StringRef SysRoot = {},
168                       StringRef SDK = {});
169 
170     /// Create a file descriptor to hold debugging information for a file.
171     /// \param Filename  File name.
172     /// \param Directory Directory.
173     /// \param Checksum  Optional checksum kind (e.g. CSK_MD5, CSK_SHA1, etc.)
174     ///                  and value.
175     /// \param Source    Optional source text.
176     DIFile *createFile(
177         StringRef Filename, StringRef Directory,
178         std::optional<DIFile::ChecksumInfo<StringRef>> Checksum = std::nullopt,
179         std::optional<StringRef> Source = std::nullopt);
180 
181     /// Create debugging information entry for a macro.
182     /// \param Parent     Macro parent (could be nullptr).
183     /// \param Line       Source line number where the macro is defined.
184     /// \param MacroType  DW_MACINFO_define or DW_MACINFO_undef.
185     /// \param Name       Macro name.
186     /// \param Value      Macro value.
187     DIMacro *createMacro(DIMacroFile *Parent, unsigned Line, unsigned MacroType,
188                          StringRef Name, StringRef Value = StringRef());
189 
190     /// Create debugging information temporary entry for a macro file.
191     /// List of macro node direct children will be calculated by DIBuilder,
192     /// using the \p Parent relationship.
193     /// \param Parent     Macro file parent (could be nullptr).
194     /// \param Line       Source line number where the macro file is included.
195     /// \param File       File descriptor containing the name of the macro file.
196     DIMacroFile *createTempMacroFile(DIMacroFile *Parent, unsigned Line,
197                                      DIFile *File);
198 
199     /// Create a single enumerator value.
200     DIEnumerator *createEnumerator(StringRef Name, const APSInt &Value);
201     DIEnumerator *createEnumerator(StringRef Name, uint64_t Val,
202                                    bool IsUnsigned = false);
203 
204     /// Create a DWARF unspecified type.
205     DIBasicType *createUnspecifiedType(StringRef Name);
206 
207     /// Create C++11 nullptr type.
208     DIBasicType *createNullPtrType();
209 
210     /// Create debugging information entry for a basic
211     /// type.
212     /// \param Name        Type name.
213     /// \param SizeInBits  Size of the type.
214     /// \param Encoding    DWARF encoding code, e.g., dwarf::DW_ATE_float.
215     /// \param Flags       Optional DWARF attributes, e.g., DW_AT_endianity.
216     DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
217                                  unsigned Encoding,
218                                  DINode::DIFlags Flags = DINode::FlagZero);
219 
220     /// Create debugging information entry for a string
221     /// type.
222     /// \param Name        Type name.
223     /// \param SizeInBits  Size of the type.
224     DIStringType *createStringType(StringRef Name, uint64_t SizeInBits);
225 
226     /// Create debugging information entry for Fortran
227     /// assumed length string type.
228     /// \param Name            Type name.
229     /// \param StringLength    String length expressed as DIVariable *.
230     /// \param StrLocationExp  Optional memory location of the string.
231     DIStringType *createStringType(StringRef Name, DIVariable *StringLength,
232                                    DIExpression *StrLocationExp = nullptr);
233 
234     /// Create debugging information entry for Fortran
235     /// assumed length string type.
236     /// \param Name             Type name.
237     /// \param StringLengthExp  String length expressed in DIExpression form.
238     /// \param StrLocationExp   Optional memory location of the string.
239     DIStringType *createStringType(StringRef Name,
240                                    DIExpression *StringLengthExp,
241                                    DIExpression *StrLocationExp = nullptr);
242 
243     /// Create debugging information entry for a qualified
244     /// type, e.g. 'const int'.
245     /// \param Tag         Tag identifing type, e.g. dwarf::TAG_volatile_type
246     /// \param FromTy      Base Type.
247     DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy);
248 
249     /// Create debugging information entry for a pointer.
250     /// \param PointeeTy         Type pointed by this pointer.
251     /// \param SizeInBits        Size.
252     /// \param AlignInBits       Alignment. (optional)
253     /// \param DWARFAddressSpace DWARF address space. (optional)
254     /// \param Name              Pointer type name. (optional)
255     /// \param Annotations       Member annotations.
256     DIDerivedType *
257     createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
258                       uint32_t AlignInBits = 0,
259                       std::optional<unsigned> DWARFAddressSpace = std::nullopt,
260                       StringRef Name = "", DINodeArray Annotations = nullptr);
261 
262     /// Create debugging information entry for a pointer to member.
263     /// \param PointeeTy Type pointed to by this pointer.
264     /// \param SizeInBits  Size.
265     /// \param AlignInBits Alignment. (optional)
266     /// \param Class Type for which this pointer points to members of.
267     DIDerivedType *
268     createMemberPointerType(DIType *PointeeTy, DIType *Class,
269                             uint64_t SizeInBits, uint32_t AlignInBits = 0,
270                             DINode::DIFlags Flags = DINode::FlagZero);
271 
272     /// Create debugging information entry for a c++
273     /// style reference or rvalue reference type.
274     DIDerivedType *createReferenceType(
275         unsigned Tag, DIType *RTy, uint64_t SizeInBits = 0,
276         uint32_t AlignInBits = 0,
277         std::optional<unsigned> DWARFAddressSpace = std::nullopt);
278 
279     /// Create debugging information entry for a typedef.
280     /// \param Ty          Original type.
281     /// \param Name        Typedef name.
282     /// \param File        File where this type is defined.
283     /// \param LineNo      Line number.
284     /// \param Context     The surrounding context for the typedef.
285     /// \param AlignInBits Alignment. (optional)
286     /// \param Flags       Flags to describe inheritance attribute, e.g. private
287     /// \param Annotations Annotations. (optional)
288     DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File,
289                                  unsigned LineNo, DIScope *Context,
290                                  uint32_t AlignInBits = 0,
291                                  DINode::DIFlags Flags = DINode::FlagZero,
292                                  DINodeArray Annotations = nullptr);
293 
294     /// Create debugging information entry for a 'friend'.
295     DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy);
296 
297     /// Create debugging information entry to establish
298     /// inheritance relationship between two types.
299     /// \param Ty           Original type.
300     /// \param BaseTy       Base type. Ty is inherits from base.
301     /// \param BaseOffset   Base offset.
302     /// \param VBPtrOffset  Virtual base pointer offset.
303     /// \param Flags        Flags to describe inheritance attribute,
304     ///                     e.g. private
305     DIDerivedType *createInheritance(DIType *Ty, DIType *BaseTy,
306                                      uint64_t BaseOffset, uint32_t VBPtrOffset,
307                                      DINode::DIFlags Flags);
308 
309     /// Create debugging information entry for a member.
310     /// \param Scope        Member scope.
311     /// \param Name         Member name.
312     /// \param File         File where this member is defined.
313     /// \param LineNo       Line number.
314     /// \param SizeInBits   Member size.
315     /// \param AlignInBits  Member alignment.
316     /// \param OffsetInBits Member offset.
317     /// \param Flags        Flags to encode member attribute, e.g. private
318     /// \param Ty           Parent type.
319     /// \param Annotations  Member annotations.
320     DIDerivedType *createMemberType(DIScope *Scope, StringRef Name,
321                                     DIFile *File, unsigned LineNo,
322                                     uint64_t SizeInBits, uint32_t AlignInBits,
323                                     uint64_t OffsetInBits,
324                                     DINode::DIFlags Flags, DIType *Ty,
325                                     DINodeArray Annotations = nullptr);
326 
327     /// Create debugging information entry for a variant.  A variant
328     /// normally should be a member of a variant part.
329     /// \param Scope        Member scope.
330     /// \param Name         Member name.
331     /// \param File         File where this member is defined.
332     /// \param LineNo       Line number.
333     /// \param SizeInBits   Member size.
334     /// \param AlignInBits  Member alignment.
335     /// \param OffsetInBits Member offset.
336     /// \param Flags        Flags to encode member attribute, e.g. private
337     /// \param Discriminant The discriminant for this branch; null for
338     ///                     the default branch
339     /// \param Ty           Parent type.
340     DIDerivedType *createVariantMemberType(DIScope *Scope, StringRef Name,
341 					   DIFile *File, unsigned LineNo,
342 					   uint64_t SizeInBits,
343 					   uint32_t AlignInBits,
344 					   uint64_t OffsetInBits,
345 					   Constant *Discriminant,
346 					   DINode::DIFlags Flags, DIType *Ty);
347 
348     /// Create debugging information entry for a bit field member.
349     /// \param Scope               Member scope.
350     /// \param Name                Member name.
351     /// \param File                File where this member is defined.
352     /// \param LineNo              Line number.
353     /// \param SizeInBits          Member size.
354     /// \param OffsetInBits        Member offset.
355     /// \param StorageOffsetInBits Member storage offset.
356     /// \param Flags               Flags to encode member attribute.
357     /// \param Ty                  Parent type.
358     /// \param Annotations         Member annotations.
359     DIDerivedType *createBitFieldMemberType(DIScope *Scope, StringRef Name,
360                                             DIFile *File, unsigned LineNo,
361                                             uint64_t SizeInBits,
362                                             uint64_t OffsetInBits,
363                                             uint64_t StorageOffsetInBits,
364                                             DINode::DIFlags Flags, DIType *Ty,
365                                             DINodeArray Annotations = nullptr);
366 
367     /// Create debugging information entry for a
368     /// C++ static data member.
369     /// \param Scope      Member scope.
370     /// \param Name       Member name.
371     /// \param File       File where this member is declared.
372     /// \param LineNo     Line number.
373     /// \param Ty         Type of the static member.
374     /// \param Flags      Flags to encode member attribute, e.g. private.
375     /// \param Val        Const initializer of the member.
376     /// \param AlignInBits  Member alignment.
377     DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
378                                           DIFile *File, unsigned LineNo,
379                                           DIType *Ty, DINode::DIFlags Flags,
380                                           Constant *Val,
381                                           uint32_t AlignInBits = 0);
382 
383     /// Create debugging information entry for Objective-C
384     /// instance variable.
385     /// \param Name         Member name.
386     /// \param File         File where this member is defined.
387     /// \param LineNo       Line number.
388     /// \param SizeInBits   Member size.
389     /// \param AlignInBits  Member alignment.
390     /// \param OffsetInBits Member offset.
391     /// \param Flags        Flags to encode member attribute, e.g. private
392     /// \param Ty           Parent type.
393     /// \param PropertyNode Property associated with this ivar.
394     DIDerivedType *createObjCIVar(StringRef Name, DIFile *File, unsigned LineNo,
395                                   uint64_t SizeInBits, uint32_t AlignInBits,
396                                   uint64_t OffsetInBits, DINode::DIFlags Flags,
397                                   DIType *Ty, MDNode *PropertyNode);
398 
399     /// Create debugging information entry for Objective-C
400     /// property.
401     /// \param Name         Property name.
402     /// \param File         File where this property is defined.
403     /// \param LineNumber   Line number.
404     /// \param GetterName   Name of the Objective C property getter selector.
405     /// \param SetterName   Name of the Objective C property setter selector.
406     /// \param PropertyAttributes Objective C property attributes.
407     /// \param Ty           Type.
408     DIObjCProperty *createObjCProperty(StringRef Name, DIFile *File,
409                                        unsigned LineNumber,
410                                        StringRef GetterName,
411                                        StringRef SetterName,
412                                        unsigned PropertyAttributes, DIType *Ty);
413 
414     /// Create debugging information entry for a class.
415     /// \param Scope        Scope in which this class is defined.
416     /// \param Name         class name.
417     /// \param File         File where this member is defined.
418     /// \param LineNumber   Line number.
419     /// \param SizeInBits   Member size.
420     /// \param AlignInBits  Member alignment.
421     /// \param OffsetInBits Member offset.
422     /// \param Flags        Flags to encode member attribute, e.g. private
423     /// \param Elements     class members.
424     /// \param VTableHolder Debug info of the base class that contains vtable
425     ///                     for this type. This is used in
426     ///                     DW_AT_containing_type. See DWARF documentation
427     ///                     for more info.
428     /// \param TemplateParms Template type parameters.
429     /// \param UniqueIdentifier A unique identifier for the class.
430     DICompositeType *createClassType(
431         DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
432         uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
433         DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
434         DIType *VTableHolder = nullptr, MDNode *TemplateParms = nullptr,
435         StringRef UniqueIdentifier = "");
436 
437     /// Create debugging information entry for a struct.
438     /// \param Scope        Scope in which this struct is defined.
439     /// \param Name         Struct name.
440     /// \param File         File where this member is defined.
441     /// \param LineNumber   Line number.
442     /// \param SizeInBits   Member size.
443     /// \param AlignInBits  Member alignment.
444     /// \param Flags        Flags to encode member attribute, e.g. private
445     /// \param Elements     Struct elements.
446     /// \param RunTimeLang  Optional parameter, Objective-C runtime version.
447     /// \param UniqueIdentifier A unique identifier for the struct.
448     DICompositeType *createStructType(
449         DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
450         uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
451         DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0,
452         DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
453 
454     /// Create debugging information entry for an union.
455     /// \param Scope        Scope in which this union is defined.
456     /// \param Name         Union name.
457     /// \param File         File where this member is defined.
458     /// \param LineNumber   Line number.
459     /// \param SizeInBits   Member size.
460     /// \param AlignInBits  Member alignment.
461     /// \param Flags        Flags to encode member attribute, e.g. private
462     /// \param Elements     Union elements.
463     /// \param RunTimeLang  Optional parameter, Objective-C runtime version.
464     /// \param UniqueIdentifier A unique identifier for the union.
465     DICompositeType *createUnionType(DIScope *Scope, StringRef Name,
466                                      DIFile *File, unsigned LineNumber,
467                                      uint64_t SizeInBits, uint32_t AlignInBits,
468                                      DINode::DIFlags Flags,
469                                      DINodeArray Elements,
470                                      unsigned RunTimeLang = 0,
471                                      StringRef UniqueIdentifier = "");
472 
473     /// Create debugging information entry for a variant part.  A
474     /// variant part normally has a discriminator (though this is not
475     /// required) and a number of variant children.
476     /// \param Scope        Scope in which this union is defined.
477     /// \param Name         Union name.
478     /// \param File         File where this member is defined.
479     /// \param LineNumber   Line number.
480     /// \param SizeInBits   Member size.
481     /// \param AlignInBits  Member alignment.
482     /// \param Flags        Flags to encode member attribute, e.g. private
483     /// \param Discriminator Discriminant member
484     /// \param Elements     Variant elements.
485     /// \param UniqueIdentifier A unique identifier for the union.
486     DICompositeType *createVariantPart(DIScope *Scope, StringRef Name,
487 				       DIFile *File, unsigned LineNumber,
488 				       uint64_t SizeInBits, uint32_t AlignInBits,
489 				       DINode::DIFlags Flags,
490 				       DIDerivedType *Discriminator,
491 				       DINodeArray Elements,
492 				       StringRef UniqueIdentifier = "");
493 
494     /// Create debugging information for template
495     /// type parameter.
496     /// \param Scope        Scope in which this type is defined.
497     /// \param Name         Type parameter name.
498     /// \param Ty           Parameter type.
499     /// \param IsDefault    Parameter is default or not
500     DITemplateTypeParameter *createTemplateTypeParameter(DIScope *Scope,
501                                                          StringRef Name,
502                                                          DIType *Ty,
503                                                          bool IsDefault);
504 
505     /// Create debugging information for template
506     /// value parameter.
507     /// \param Scope        Scope in which this type is defined.
508     /// \param Name         Value parameter name.
509     /// \param Ty           Parameter type.
510     /// \param IsDefault    Parameter is default or not
511     /// \param Val          Constant parameter value.
512     DITemplateValueParameter *
513     createTemplateValueParameter(DIScope *Scope, StringRef Name, DIType *Ty,
514                                  bool IsDefault, Constant *Val);
515 
516     /// Create debugging information for a template template parameter.
517     /// \param Scope        Scope in which this type is defined.
518     /// \param Name         Value parameter name.
519     /// \param Ty           Parameter type.
520     /// \param Val          The fully qualified name of the template.
521     /// \param IsDefault    Parameter is default or not.
522     DITemplateValueParameter *
523     createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty,
524                                     StringRef Val, bool IsDefault = false);
525 
526     /// Create debugging information for a template parameter pack.
527     /// \param Scope        Scope in which this type is defined.
528     /// \param Name         Value parameter name.
529     /// \param Ty           Parameter type.
530     /// \param Val          An array of types in the pack.
531     DITemplateValueParameter *createTemplateParameterPack(DIScope *Scope,
532                                                           StringRef Name,
533                                                           DIType *Ty,
534                                                           DINodeArray Val);
535 
536     /// Create debugging information entry for an array.
537     /// \param Size         Array size.
538     /// \param AlignInBits  Alignment.
539     /// \param Ty           Element type.
540     /// \param Subscripts   Subscripts.
541     /// \param DataLocation The location of the raw data of a descriptor-based
542     ///                     Fortran array, either a DIExpression* or
543     ///                     a DIVariable*.
544     /// \param Associated   The associated attribute of a descriptor-based
545     ///                     Fortran array, either a DIExpression* or
546     ///                     a DIVariable*.
547     /// \param Allocated    The allocated attribute of a descriptor-based
548     ///                     Fortran array, either a DIExpression* or
549     ///                     a DIVariable*.
550     /// \param Rank         The rank attribute of a descriptor-based
551     ///                     Fortran array, either a DIExpression* or
552     ///                     a DIVariable*.
553     DICompositeType *createArrayType(
554         uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
555         PointerUnion<DIExpression *, DIVariable *> DataLocation = nullptr,
556         PointerUnion<DIExpression *, DIVariable *> Associated = nullptr,
557         PointerUnion<DIExpression *, DIVariable *> Allocated = nullptr,
558         PointerUnion<DIExpression *, DIVariable *> Rank = nullptr);
559 
560     /// Create debugging information entry for a vector type.
561     /// \param Size         Array size.
562     /// \param AlignInBits  Alignment.
563     /// \param Ty           Element type.
564     /// \param Subscripts   Subscripts.
565     DICompositeType *createVectorType(uint64_t Size, uint32_t AlignInBits,
566                                       DIType *Ty, DINodeArray Subscripts);
567 
568     /// Create debugging information entry for an
569     /// enumeration.
570     /// \param Scope          Scope in which this enumeration is defined.
571     /// \param Name           Union name.
572     /// \param File           File where this member is defined.
573     /// \param LineNumber     Line number.
574     /// \param SizeInBits     Member size.
575     /// \param AlignInBits    Member alignment.
576     /// \param Elements       Enumeration elements.
577     /// \param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
578     /// \param UniqueIdentifier A unique identifier for the enum.
579     /// \param IsScoped Boolean flag indicate if this is C++11/ObjC 'enum class'.
580     DICompositeType *createEnumerationType(
581         DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
582         uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
583         DIType *UnderlyingType, StringRef UniqueIdentifier = "", bool IsScoped = false);
584 
585     /// Create debugging information entry for a set.
586     /// \param Scope          Scope in which this set is defined.
587     /// \param Name           Set name.
588     /// \param File           File where this set is defined.
589     /// \param LineNo         Line number.
590     /// \param SizeInBits     Set size.
591     /// \param AlignInBits    Set alignment.
592     /// \param Ty             Base type of the set.
593     DIDerivedType *createSetType(DIScope *Scope, StringRef Name, DIFile *File,
594                                  unsigned LineNo, uint64_t SizeInBits,
595                                  uint32_t AlignInBits, DIType *Ty);
596 
597     /// Create subroutine type.
598     /// \param ParameterTypes  An array of subroutine parameter types. This
599     ///                        includes return type at 0th index.
600     /// \param Flags           E.g.: LValueReference.
601     ///                        These flags are used to emit dwarf attributes.
602     /// \param CC              Calling convention, e.g. dwarf::DW_CC_normal
603     DISubroutineType *
604     createSubroutineType(DITypeRefArray ParameterTypes,
605                          DINode::DIFlags Flags = DINode::FlagZero,
606                          unsigned CC = 0);
607 
608     /// Create a distinct clone of \p SP with FlagArtificial set.
609     static DISubprogram *createArtificialSubprogram(DISubprogram *SP);
610 
611     /// Create a uniqued clone of \p Ty with FlagArtificial set.
612     static DIType *createArtificialType(DIType *Ty);
613 
614     /// Create a uniqued clone of \p Ty with FlagObjectPointer and
615     /// FlagArtificial set.
616     static DIType *createObjectPointerType(DIType *Ty);
617 
618     /// Create a permanent forward-declared type.
619     DICompositeType *createForwardDecl(unsigned Tag, StringRef Name,
620                                        DIScope *Scope, DIFile *F, unsigned Line,
621                                        unsigned RuntimeLang = 0,
622                                        uint64_t SizeInBits = 0,
623                                        uint32_t AlignInBits = 0,
624                                        StringRef UniqueIdentifier = "");
625 
626     /// Create a temporary forward-declared type.
627     DICompositeType *createReplaceableCompositeType(
628         unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
629         unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
630         uint32_t AlignInBits = 0, DINode::DIFlags Flags = DINode::FlagFwdDecl,
631         StringRef UniqueIdentifier = "", DINodeArray Annotations = nullptr);
632 
633     /// Retain DIScope* in a module even if it is not referenced
634     /// through debug info anchors.
635     void retainType(DIScope *T);
636 
637     /// Create unspecified parameter type
638     /// for a subroutine type.
639     DIBasicType *createUnspecifiedParameter();
640 
641     /// Get a DINodeArray, create one if required.
642     DINodeArray getOrCreateArray(ArrayRef<Metadata *> Elements);
643 
644     /// Get a DIMacroNodeArray, create one if required.
645     DIMacroNodeArray getOrCreateMacroArray(ArrayRef<Metadata *> Elements);
646 
647     /// Get a DITypeRefArray, create one if required.
648     DITypeRefArray getOrCreateTypeArray(ArrayRef<Metadata *> Elements);
649 
650     /// Create a descriptor for a value range.  This
651     /// implicitly uniques the values returned.
652     DISubrange *getOrCreateSubrange(int64_t Lo, int64_t Count);
653     DISubrange *getOrCreateSubrange(int64_t Lo, Metadata *CountNode);
654     DISubrange *getOrCreateSubrange(Metadata *Count, Metadata *LowerBound,
655                                     Metadata *UpperBound, Metadata *Stride);
656 
657     DIGenericSubrange *
658     getOrCreateGenericSubrange(DIGenericSubrange::BoundType Count,
659                                DIGenericSubrange::BoundType LowerBound,
660                                DIGenericSubrange::BoundType UpperBound,
661                                DIGenericSubrange::BoundType Stride);
662 
663     /// Create a new descriptor for the specified variable.
664     /// \param Context     Variable scope.
665     /// \param Name        Name of the variable.
666     /// \param LinkageName Mangled  name of the variable.
667     /// \param File        File where this variable is defined.
668     /// \param LineNo      Line number.
669     /// \param Ty          Variable Type.
670     /// \param IsLocalToUnit Boolean flag indicate whether this variable is
671     ///                      externally visible or not.
672     /// \param Expr        The location of the global relative to the attached
673     ///                    GlobalVariable.
674     /// \param Decl        Reference to the corresponding declaration.
675     /// \param AlignInBits Variable alignment(or 0 if no alignment attr was
676     ///                    specified)
677     DIGlobalVariableExpression *createGlobalVariableExpression(
678         DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
679         unsigned LineNo, DIType *Ty, bool IsLocalToUnit, bool isDefined = true,
680         DIExpression *Expr = nullptr, MDNode *Decl = nullptr,
681         MDTuple *TemplateParams = nullptr, uint32_t AlignInBits = 0,
682         DINodeArray Annotations = nullptr);
683 
684     /// Identical to createGlobalVariable
685     /// except that the resulting DbgNode is temporary and meant to be RAUWed.
686     DIGlobalVariable *createTempGlobalVariableFwdDecl(
687         DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
688         unsigned LineNo, DIType *Ty, bool IsLocalToUnit, MDNode *Decl = nullptr,
689         MDTuple *TemplateParams = nullptr, uint32_t AlignInBits = 0);
690 
691     /// Create a new descriptor for an auto variable.  This is a local variable
692     /// that is not a subprogram parameter.
693     ///
694     /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
695     /// leads to a \a DISubprogram.
696     ///
697     /// If \c AlwaysPreserve, this variable will be referenced from its
698     /// containing subprogram, and will survive some optimizations.
699     DILocalVariable *
700     createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File,
701                        unsigned LineNo, DIType *Ty, bool AlwaysPreserve = false,
702                        DINode::DIFlags Flags = DINode::FlagZero,
703                        uint32_t AlignInBits = 0);
704 
705     /// Create a new descriptor for an label.
706     ///
707     /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
708     /// leads to a \a DISubprogram.
709     DILabel *
710     createLabel(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo,
711                 bool AlwaysPreserve = false);
712 
713     /// Create a new descriptor for a parameter variable.
714     ///
715     /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
716     /// leads to a \a DISubprogram.
717     ///
718     /// \c ArgNo is the index (starting from \c 1) of this variable in the
719     /// subprogram parameters.  \c ArgNo should not conflict with other
720     /// parameters of the same subprogram.
721     ///
722     /// If \c AlwaysPreserve, this variable will be referenced from its
723     /// containing subprogram, and will survive some optimizations.
724     DILocalVariable *
725     createParameterVariable(DIScope *Scope, StringRef Name, unsigned ArgNo,
726                             DIFile *File, unsigned LineNo, DIType *Ty,
727                             bool AlwaysPreserve = false,
728                             DINode::DIFlags Flags = DINode::FlagZero,
729                             DINodeArray Annotations = nullptr);
730 
731     /// Create a new descriptor for the specified
732     /// variable which has a complex address expression for its address.
733     /// \param Addr        An array of complex address operations.
734     DIExpression *createExpression(ArrayRef<uint64_t> Addr = std::nullopt);
735 
736     /// Create an expression for a variable that does not have an address, but
737     /// does have a constant value.
createConstantValueExpression(uint64_t Val)738     DIExpression *createConstantValueExpression(uint64_t Val) {
739       return DIExpression::get(
740           VMContext, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_stack_value});
741     }
742 
743     /// Create a new descriptor for the specified subprogram.
744     /// See comments in DISubprogram* for descriptions of these fields.
745     /// \param Scope         Function scope.
746     /// \param Name          Function name.
747     /// \param LinkageName   Mangled function name.
748     /// \param File          File where this variable is defined.
749     /// \param LineNo        Line number.
750     /// \param Ty            Function type.
751     /// \param ScopeLine     Set to the beginning of the scope this starts
752     /// \param Flags         e.g. is this function prototyped or not.
753     ///                      These flags are used to emit dwarf attributes.
754     /// \param SPFlags       Additional flags specific to subprograms.
755     /// \param TParams       Function template parameters.
756     /// \param ThrownTypes   Exception types this function may throw.
757     /// \param Annotations   Attribute Annotations.
758     /// \param TargetFuncName The name of the target function if this is
759     ///                       a trampoline.
760     DISubprogram *
761     createFunction(DIScope *Scope, StringRef Name, StringRef LinkageName,
762                    DIFile *File, unsigned LineNo, DISubroutineType *Ty,
763                    unsigned ScopeLine, DINode::DIFlags Flags = DINode::FlagZero,
764                    DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagZero,
765                    DITemplateParameterArray TParams = nullptr,
766                    DISubprogram *Decl = nullptr,
767                    DITypeArray ThrownTypes = nullptr,
768                    DINodeArray Annotations = nullptr,
769                    StringRef TargetFuncName = "");
770 
771     /// Identical to createFunction,
772     /// except that the resulting DbgNode is meant to be RAUWed.
773     DISubprogram *createTempFunctionFwdDecl(
774         DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
775         unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
776         DINode::DIFlags Flags = DINode::FlagZero,
777         DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagZero,
778         DITemplateParameterArray TParams = nullptr,
779         DISubprogram *Decl = nullptr, DITypeArray ThrownTypes = nullptr);
780 
781     /// Create a new descriptor for the specified C++ method.
782     /// See comments in \a DISubprogram* for descriptions of these fields.
783     /// \param Scope         Function scope.
784     /// \param Name          Function name.
785     /// \param LinkageName   Mangled function name.
786     /// \param File          File where this variable is defined.
787     /// \param LineNo        Line number.
788     /// \param Ty            Function type.
789     /// \param VTableIndex   Index no of this method in virtual table, or -1u if
790     ///                      unrepresentable.
791     /// \param ThisAdjustment
792     ///                      MS ABI-specific adjustment of 'this' that occurs
793     ///                      in the prologue.
794     /// \param VTableHolder  Type that holds vtable.
795     /// \param Flags         e.g. is this function prototyped or not.
796     ///                      This flags are used to emit dwarf attributes.
797     /// \param SPFlags       Additional flags specific to subprograms.
798     /// \param TParams       Function template parameters.
799     /// \param ThrownTypes   Exception types this function may throw.
800     DISubprogram *
801     createMethod(DIScope *Scope, StringRef Name, StringRef LinkageName,
802                  DIFile *File, unsigned LineNo, DISubroutineType *Ty,
803                  unsigned VTableIndex = 0, int ThisAdjustment = 0,
804                  DIType *VTableHolder = nullptr,
805                  DINode::DIFlags Flags = DINode::FlagZero,
806                  DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagZero,
807                  DITemplateParameterArray TParams = nullptr,
808                  DITypeArray ThrownTypes = nullptr);
809 
810     /// Create common block entry for a Fortran common block.
811     /// \param Scope       Scope of this common block.
812     /// \param decl        Global variable declaration.
813     /// \param Name        The name of this common block.
814     /// \param File        The file this common block is defined.
815     /// \param LineNo      Line number.
816     DICommonBlock *createCommonBlock(DIScope *Scope, DIGlobalVariable *decl,
817                                      StringRef Name, DIFile *File,
818                                      unsigned LineNo);
819 
820     /// This creates new descriptor for a namespace with the specified
821     /// parent scope.
822     /// \param Scope       Namespace scope
823     /// \param Name        Name of this namespace
824     /// \param ExportSymbols True for C++ inline namespaces.
825     DINamespace *createNameSpace(DIScope *Scope, StringRef Name,
826                                  bool ExportSymbols);
827 
828     /// This creates new descriptor for a module with the specified
829     /// parent scope.
830     /// \param Scope       Parent scope
831     /// \param Name        Name of this module
832     /// \param ConfigurationMacros
833     ///                    A space-separated shell-quoted list of -D macro
834     ///                    definitions as they would appear on a command line.
835     /// \param IncludePath The path to the module map file.
836     /// \param APINotesFile The path to an API notes file for this module.
837     /// \param File        Source file of the module.
838     ///                    Used for Fortran modules.
839     /// \param LineNo      Source line number of the module.
840     ///                    Used for Fortran modules.
841     /// \param IsDecl      This is a module declaration; default to false;
842     ///                    when set to true, only Scope and Name are required
843     ///                    as this entry is just a hint for the debugger to find
844     ///                    the corresponding definition in the global scope.
845     DIModule *createModule(DIScope *Scope, StringRef Name,
846                            StringRef ConfigurationMacros, StringRef IncludePath,
847                            StringRef APINotesFile = {}, DIFile *File = nullptr,
848                            unsigned LineNo = 0, bool IsDecl = false);
849 
850     /// This creates a descriptor for a lexical block with a new file
851     /// attached. This merely extends the existing
852     /// lexical block as it crosses a file.
853     /// \param Scope       Lexical block.
854     /// \param File        Source file.
855     /// \param Discriminator DWARF path discriminator value.
856     DILexicalBlockFile *createLexicalBlockFile(DIScope *Scope, DIFile *File,
857                                                unsigned Discriminator = 0);
858 
859     /// This creates a descriptor for a lexical block with the
860     /// specified parent context.
861     /// \param Scope         Parent lexical scope.
862     /// \param File          Source file.
863     /// \param Line          Line number.
864     /// \param Col           Column number.
865     DILexicalBlock *createLexicalBlock(DIScope *Scope, DIFile *File,
866                                        unsigned Line, unsigned Col);
867 
868     /// Create a descriptor for an imported module.
869     /// \param Context        The scope this module is imported into
870     /// \param NS             The namespace being imported here.
871     /// \param File           File where the declaration is located.
872     /// \param Line           Line number of the declaration.
873     /// \param Elements       Renamed elements.
874     DIImportedEntity *createImportedModule(DIScope *Context, DINamespace *NS,
875                                            DIFile *File, unsigned Line,
876                                            DINodeArray Elements = nullptr);
877 
878     /// Create a descriptor for an imported module.
879     /// \param Context The scope this module is imported into.
880     /// \param NS      An aliased namespace.
881     /// \param File    File where the declaration is located.
882     /// \param Line    Line number of the declaration.
883     /// \param Elements       Renamed elements.
884     DIImportedEntity *createImportedModule(DIScope *Context,
885                                            DIImportedEntity *NS, DIFile *File,
886                                            unsigned Line,
887                                            DINodeArray Elements = nullptr);
888 
889     /// Create a descriptor for an imported module.
890     /// \param Context        The scope this module is imported into.
891     /// \param M              The module being imported here
892     /// \param File           File where the declaration is located.
893     /// \param Line           Line number of the declaration.
894     /// \param Elements       Renamed elements.
895     DIImportedEntity *createImportedModule(DIScope *Context, DIModule *M,
896                                            DIFile *File, unsigned Line,
897                                            DINodeArray Elements = nullptr);
898 
899     /// Create a descriptor for an imported function.
900     /// \param Context The scope this module is imported into.
901     /// \param Decl    The declaration (or definition) of a function, type, or
902     ///                variable.
903     /// \param File    File where the declaration is located.
904     /// \param Line    Line number of the declaration.
905     /// \param Elements       Renamed elements.
906     DIImportedEntity *createImportedDeclaration(DIScope *Context, DINode *Decl,
907                                                 DIFile *File, unsigned Line,
908                                                 StringRef Name = "",
909                                                 DINodeArray Elements = nullptr);
910 
911     /// Insert a new llvm.dbg.declare intrinsic call.
912     /// \param Storage     llvm::Value of the variable
913     /// \param VarInfo     Variable's debug info descriptor.
914     /// \param Expr        A complex location expression.
915     /// \param DL          Debug info location.
916     /// \param InsertAtEnd Location for the new intrinsic.
917     Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
918                                DIExpression *Expr, const DILocation *DL,
919                                BasicBlock *InsertAtEnd);
920 
921     /// Insert a new llvm.dbg.assign intrinsic call.
922     /// \param LinkedInstr   Instruction with a DIAssignID to link with the new
923     ///                      intrinsic. The intrinsic will be inserted after
924     ///                      this instruction.
925     /// \param Val           The value component of this dbg.assign.
926     /// \param SrcVar        Variable's debug info descriptor.
927     /// \param ValExpr       A complex location expression to modify \p Val.
928     /// \param Addr          The address component (store destination).
929     /// \param AddrExpr      A complex location expression to modify \p Addr.
930     ///                      NOTE: \p ValExpr carries the FragInfo for the
931     ///                      variable.
932     /// \param DL            Debug info location, usually: (line: 0,
933     ///                      column: 0, scope: var-decl-scope). See
934     ///                      getDebugValueLoc.
935     DbgAssignIntrinsic *insertDbgAssign(Instruction *LinkedInstr, Value *Val,
936                                         DILocalVariable *SrcVar,
937                                         DIExpression *ValExpr, Value *Addr,
938                                         DIExpression *AddrExpr,
939                                         const DILocation *DL);
940 
941     /// Insert a new llvm.dbg.declare intrinsic call.
942     /// \param Storage      llvm::Value of the variable
943     /// \param VarInfo      Variable's debug info descriptor.
944     /// \param Expr         A complex location expression.
945     /// \param DL           Debug info location.
946     /// \param InsertBefore Location for the new intrinsic.
947     Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
948                                DIExpression *Expr, const DILocation *DL,
949                                Instruction *InsertBefore);
950 
951     /// Insert a new llvm.dbg.label intrinsic call.
952     /// \param LabelInfo    Label's debug info descriptor.
953     /// \param DL           Debug info location.
954     /// \param InsertBefore Location for the new intrinsic.
955     Instruction *insertLabel(DILabel *LabelInfo, const DILocation *DL,
956                              Instruction *InsertBefore);
957 
958     /// Insert a new llvm.dbg.label intrinsic call.
959     /// \param LabelInfo    Label's debug info descriptor.
960     /// \param DL           Debug info location.
961     /// \param InsertAtEnd Location for the new intrinsic.
962     Instruction *insertLabel(DILabel *LabelInfo, const DILocation *DL,
963                              BasicBlock *InsertAtEnd);
964 
965     /// Insert a new llvm.dbg.value intrinsic call.
966     /// \param Val          llvm::Value of the variable
967     /// \param VarInfo      Variable's debug info descriptor.
968     /// \param Expr         A complex location expression.
969     /// \param DL           Debug info location.
970     /// \param InsertAtEnd Location for the new intrinsic.
971     Instruction *insertDbgValueIntrinsic(llvm::Value *Val,
972                                          DILocalVariable *VarInfo,
973                                          DIExpression *Expr,
974                                          const DILocation *DL,
975                                          BasicBlock *InsertAtEnd);
976 
977     /// Insert a new llvm.dbg.value intrinsic call.
978     /// \param Val          llvm::Value of the variable
979     /// \param VarInfo      Variable's debug info descriptor.
980     /// \param Expr         A complex location expression.
981     /// \param DL           Debug info location.
982     /// \param InsertBefore Location for the new intrinsic.
983     Instruction *insertDbgValueIntrinsic(llvm::Value *Val,
984                                          DILocalVariable *VarInfo,
985                                          DIExpression *Expr,
986                                          const DILocation *DL,
987                                          Instruction *InsertBefore);
988 
989     /// Insert a new llvm.dbg.addr intrinsic call.
990     /// \param Addr          llvm::Value of the address
991     /// \param VarInfo      Variable's debug info descriptor.
992     /// \param Expr         A complex location expression.
993     /// \param DL           Debug info location.
994     /// \param InsertAtEnd Location for the new intrinsic.
995     Instruction *insertDbgAddrIntrinsic(llvm::Value *Addr,
996                                         DILocalVariable *VarInfo,
997                                         DIExpression *Expr,
998                                         const DILocation *DL,
999                                         BasicBlock *InsertAtEnd);
1000 
1001     /// Insert a new llvm.dbg.addr intrinsic call.
1002     /// \param Addr         llvm::Value of the address.
1003     /// \param VarInfo      Variable's debug info descriptor.
1004     /// \param Expr         A complex location expression.
1005     /// \param DL           Debug info location.
1006     /// \param InsertBefore Location for the new intrinsic.
1007     Instruction *insertDbgAddrIntrinsic(llvm::Value *Addr,
1008                                         DILocalVariable *VarInfo,
1009                                         DIExpression *Expr,
1010                                         const DILocation *DL,
1011                                         Instruction *InsertBefore);
1012 
1013     /// Replace the vtable holder in the given type.
1014     ///
1015     /// If this creates a self reference, it may orphan some unresolved cycles
1016     /// in the operands of \c T, so \a DIBuilder needs to track that.
1017     void replaceVTableHolder(DICompositeType *&T,
1018                              DIType *VTableHolder);
1019 
1020     /// Replace arrays on a composite type.
1021     ///
1022     /// If \c T is resolved, but the arrays aren't -- which can happen if \c T
1023     /// has a self-reference -- \a DIBuilder needs to track the array to
1024     /// resolve cycles.
1025     void replaceArrays(DICompositeType *&T, DINodeArray Elements,
1026                        DINodeArray TParams = DINodeArray());
1027 
1028     /// Replace a temporary node.
1029     ///
1030     /// Call \a MDNode::replaceAllUsesWith() on \c N, replacing it with \c
1031     /// Replacement.
1032     ///
1033     /// If \c Replacement is the same as \c N.get(), instead call \a
1034     /// MDNode::replaceWithUniqued().  In this case, the uniqued node could
1035     /// have a different address, so we return the final address.
1036     template <class NodeTy>
replaceTemporary(TempMDNode && N,NodeTy * Replacement)1037     NodeTy *replaceTemporary(TempMDNode &&N, NodeTy *Replacement) {
1038       if (N.get() == Replacement)
1039         return cast<NodeTy>(MDNode::replaceWithUniqued(std::move(N)));
1040 
1041       N->replaceAllUsesWith(Replacement);
1042       return Replacement;
1043     }
1044   };
1045 
1046   // Create wrappers for C Binding types (see CBindingWrapping.h).
1047   DEFINE_ISA_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
1048 
1049 } // end namespace llvm
1050 
1051 #endif // LLVM_IR_DIBUILDER_H
1052