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