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