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