1 //===- DIBuilder.h - Debug Information Builder ------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines a DIBuilder that is useful for creating debugging 11 // information entries in LLVM IR form. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_IR_DIBUILDER_H 16 #define LLVM_IR_DIBUILDER_H 17 18 #include "llvm/IR/DebugInfo.h" 19 #include "llvm/IR/TrackingMDRef.h" 20 #include "llvm/IR/ValueHandle.h" 21 #include "llvm/Support/DataTypes.h" 22 23 namespace llvm { 24 class BasicBlock; 25 class Instruction; 26 class Function; 27 class Module; 28 class Value; 29 class Constant; 30 class LLVMContext; 31 class StringRef; 32 template <typename T> class ArrayRef; 33 34 class DIBuilder { 35 Module &M; 36 LLVMContext &VMContext; 37 38 DICompileUnit *CUNode; ///< The one compile unit created by this DIBuiler. 39 Function *DeclareFn; ///< llvm.dbg.declare 40 Function *ValueFn; ///< llvm.dbg.value 41 42 SmallVector<Metadata *, 4> AllEnumTypes; 43 /// Track the RetainTypes, since they can be updated later on. 44 SmallVector<TrackingMDNodeRef, 4> AllRetainTypes; 45 SmallVector<Metadata *, 4> AllSubprograms; 46 SmallVector<Metadata *, 4> AllGVs; 47 SmallVector<TrackingMDNodeRef, 4> AllImportedModules; 48 49 /// Track nodes that may be unresolved. 50 SmallVector<TrackingMDNodeRef, 4> UnresolvedNodes; 51 bool AllowUnresolvedNodes; 52 53 /// Each subprogram's preserved local variables. 54 /// 55 /// Do not use a std::vector. Some versions of libc++ apparently copy 56 /// instead of move on grow operations, and TrackingMDRef is expensive to 57 /// copy. 58 DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> PreservedVariables; 59 60 DIBuilder(const DIBuilder &) = delete; 61 void operator=(const DIBuilder &) = delete; 62 63 /// Create a temporary. 64 /// 65 /// Create an \a temporary node and track it in \a UnresolvedNodes. 66 void trackIfUnresolved(MDNode *N); 67 68 public: 69 /// Construct a builder for a module. 70 /// 71 /// If \c AllowUnresolved, collect unresolved nodes attached to the module 72 /// in order to resolve cycles during \a finalize(). 73 explicit DIBuilder(Module &M, bool AllowUnresolved = true); 74 75 /// Construct any deferred debug info descriptors. 76 void finalize(); 77 78 /// A CompileUnit provides an anchor for all debugging 79 /// information generated during this instance of compilation. 80 /// \param Lang Source programming language, eg. dwarf::DW_LANG_C99 81 /// \param File File name 82 /// \param Dir Directory 83 /// \param Producer Identify the producer of debugging information 84 /// and code. Usually this is a compiler 85 /// version string. 86 /// \param isOptimized A boolean flag which indicates whether optimization 87 /// is enabled or not. 88 /// \param Flags This string lists command line options. This 89 /// string is directly embedded in debug info 90 /// output which may be used by a tool 91 /// analyzing generated debugging information. 92 /// \param RV This indicates runtime version for languages like 93 /// Objective-C. 94 /// \param SplitName The name of the file that we'll split debug info 95 /// out into. 96 /// \param Kind The kind of debug information to generate. 97 /// \param DWOId The DWOId if this is a split skeleton compile unit. 98 DICompileUnit * 99 createCompileUnit(unsigned Lang, StringRef File, StringRef Dir, 100 StringRef Producer, bool isOptimized, StringRef Flags, 101 unsigned RV, StringRef SplitName = StringRef(), 102 DICompileUnit::DebugEmissionKind Kind = 103 DICompileUnit::DebugEmissionKind::FullDebug, 104 uint64_t DWOId = 0); 105 106 /// Create a file descriptor to hold debugging information 107 /// for a file. 108 DIFile *createFile(StringRef Filename, StringRef Directory); 109 110 /// Create a single enumerator value. 111 DIEnumerator *createEnumerator(StringRef Name, int64_t Val); 112 113 /// Create a DWARF unspecified type. 114 DIBasicType *createUnspecifiedType(StringRef Name); 115 116 /// Create C++11 nullptr type. 117 DIBasicType *createNullPtrType(); 118 119 /// Create debugging information entry for a basic 120 /// type. 121 /// \param Name Type name. 122 /// \param SizeInBits Size of the type. 123 /// \param AlignInBits Type alignment. 124 /// \param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float. 125 DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits, 126 uint64_t AlignInBits, unsigned Encoding); 127 128 /// Create debugging information entry for a qualified 129 /// type, e.g. 'const int'. 130 /// \param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type 131 /// \param FromTy Base Type. 132 DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy); 133 134 /// Create debugging information entry for a pointer. 135 /// \param PointeeTy Type pointed by this pointer. 136 /// \param SizeInBits Size. 137 /// \param AlignInBits Alignment. (optional) 138 /// \param Name Pointer type name. (optional) 139 DIDerivedType *createPointerType(DIType *PointeeTy, uint64_t SizeInBits, 140 uint64_t AlignInBits = 0, 141 StringRef Name = ""); 142 143 /// Create debugging information entry for a pointer to member. 144 /// \param PointeeTy Type pointed to by this pointer. 145 /// \param SizeInBits Size. 146 /// \param AlignInBits Alignment. (optional) 147 /// \param Class Type for which this pointer points to members of. 148 DIDerivedType *createMemberPointerType(DIType *PointeeTy, DIType *Class, 149 uint64_t SizeInBits, 150 uint64_t AlignInBits = 0, 151 unsigned Flags = 0); 152 153 /// Create debugging information entry for a c++ 154 /// style reference or rvalue reference type. 155 DIDerivedType *createReferenceType(unsigned Tag, DIType *RTy, 156 uint64_t SizeInBits = 0, 157 uint64_t AlignInBits = 0); 158 159 /// Create debugging information entry for a typedef. 160 /// \param Ty Original type. 161 /// \param Name Typedef name. 162 /// \param File File where this type is defined. 163 /// \param LineNo Line number. 164 /// \param Context The surrounding context for the typedef. 165 DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File, 166 unsigned LineNo, DIScope *Context); 167 168 /// Create debugging information entry for a 'friend'. 169 DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy); 170 171 /// Create debugging information entry to establish 172 /// inheritance relationship between two types. 173 /// \param Ty Original type. 174 /// \param BaseTy Base type. Ty is inherits from base. 175 /// \param BaseOffset Base offset. 176 /// \param Flags Flags to describe inheritance attribute, 177 /// e.g. private 178 DIDerivedType *createInheritance(DIType *Ty, DIType *BaseTy, 179 uint64_t BaseOffset, unsigned Flags); 180 181 /// Create debugging information entry for a member. 182 /// \param Scope Member scope. 183 /// \param Name Member name. 184 /// \param File File where this member is defined. 185 /// \param LineNo Line number. 186 /// \param SizeInBits Member size. 187 /// \param AlignInBits Member alignment. 188 /// \param OffsetInBits Member offset. 189 /// \param Flags Flags to encode member attribute, e.g. private 190 /// \param Ty Parent type. 191 DIDerivedType *createMemberType(DIScope *Scope, StringRef Name, 192 DIFile *File, unsigned LineNo, 193 uint64_t SizeInBits, uint64_t AlignInBits, 194 uint64_t OffsetInBits, unsigned Flags, 195 DIType *Ty); 196 197 /// Create debugging information entry for a bit field member. 198 /// \param Scope Member scope. 199 /// \param Name Member name. 200 /// \param File File where this member is defined. 201 /// \param LineNo Line number. 202 /// \param SizeInBits Member size. 203 /// \param AlignInBits Member alignment. 204 /// \param OffsetInBits Member offset. 205 /// \param StorageOffsetInBits Member storage offset. 206 /// \param Flags Flags to encode member attribute. 207 /// \param Ty Parent type. 208 DIDerivedType *createBitFieldMemberType( 209 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, 210 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, 211 uint64_t StorageOffsetInBits, unsigned Flags, DIType *Ty); 212 213 /// Create debugging information entry for a 214 /// C++ static data member. 215 /// \param Scope Member scope. 216 /// \param Name Member name. 217 /// \param File File where this member is declared. 218 /// \param LineNo Line number. 219 /// \param Ty Type of the static member. 220 /// \param Flags Flags to encode member attribute, e.g. private. 221 /// \param Val Const initializer of the member. 222 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name, 223 DIFile *File, unsigned LineNo, 224 DIType *Ty, unsigned Flags, 225 llvm::Constant *Val); 226 227 /// Create debugging information entry for Objective-C 228 /// instance variable. 229 /// \param Name Member name. 230 /// \param File File where this member is defined. 231 /// \param LineNo Line number. 232 /// \param SizeInBits Member size. 233 /// \param AlignInBits Member alignment. 234 /// \param OffsetInBits Member offset. 235 /// \param Flags Flags to encode member attribute, e.g. private 236 /// \param Ty Parent type. 237 /// \param PropertyNode Property associated with this ivar. 238 DIDerivedType *createObjCIVar(StringRef Name, DIFile *File, unsigned LineNo, 239 uint64_t SizeInBits, uint64_t AlignInBits, 240 uint64_t OffsetInBits, unsigned Flags, 241 DIType *Ty, MDNode *PropertyNode); 242 243 /// Create debugging information entry for Objective-C 244 /// property. 245 /// \param Name Property name. 246 /// \param File File where this property is defined. 247 /// \param LineNumber Line number. 248 /// \param GetterName Name of the Objective C property getter selector. 249 /// \param SetterName Name of the Objective C property setter selector. 250 /// \param PropertyAttributes Objective C property attributes. 251 /// \param Ty Type. 252 DIObjCProperty *createObjCProperty(StringRef Name, DIFile *File, 253 unsigned LineNumber, 254 StringRef GetterName, 255 StringRef SetterName, 256 unsigned PropertyAttributes, DIType *Ty); 257 258 /// Create debugging information entry for a class. 259 /// \param Scope Scope in which this class is defined. 260 /// \param Name class name. 261 /// \param File File where this member is defined. 262 /// \param LineNumber Line number. 263 /// \param SizeInBits Member size. 264 /// \param AlignInBits Member alignment. 265 /// \param OffsetInBits Member offset. 266 /// \param Flags Flags to encode member attribute, e.g. private 267 /// \param Elements class members. 268 /// \param VTableHolder Debug info of the base class that contains vtable 269 /// for this type. This is used in 270 /// DW_AT_containing_type. See DWARF documentation 271 /// for more info. 272 /// \param TemplateParms Template type parameters. 273 /// \param UniqueIdentifier A unique identifier for the class. 274 DICompositeType *createClassType(DIScope *Scope, StringRef Name, 275 DIFile *File, unsigned LineNumber, 276 uint64_t SizeInBits, uint64_t AlignInBits, 277 uint64_t OffsetInBits, unsigned Flags, 278 DIType *DerivedFrom, DINodeArray Elements, 279 DIType *VTableHolder = nullptr, 280 MDNode *TemplateParms = nullptr, 281 StringRef UniqueIdentifier = ""); 282 283 /// Create debugging information entry for a struct. 284 /// \param Scope Scope in which this struct is defined. 285 /// \param Name Struct name. 286 /// \param File File where this member is defined. 287 /// \param LineNumber Line number. 288 /// \param SizeInBits Member size. 289 /// \param AlignInBits Member alignment. 290 /// \param Flags Flags to encode member attribute, e.g. private 291 /// \param Elements Struct elements. 292 /// \param RunTimeLang Optional parameter, Objective-C runtime version. 293 /// \param UniqueIdentifier A unique identifier for the struct. 294 DICompositeType *createStructType( 295 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 296 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags, 297 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0, 298 DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = ""); 299 300 /// Create debugging information entry for an union. 301 /// \param Scope Scope in which this union is defined. 302 /// \param Name Union name. 303 /// \param File File where this member is defined. 304 /// \param LineNumber Line number. 305 /// \param SizeInBits Member size. 306 /// \param AlignInBits Member alignment. 307 /// \param Flags Flags to encode member attribute, e.g. private 308 /// \param Elements Union elements. 309 /// \param RunTimeLang Optional parameter, Objective-C runtime version. 310 /// \param UniqueIdentifier A unique identifier for the union. 311 DICompositeType *createUnionType(DIScope *Scope, StringRef Name, 312 DIFile *File, unsigned LineNumber, 313 uint64_t SizeInBits, uint64_t AlignInBits, 314 unsigned Flags, DINodeArray Elements, 315 unsigned RunTimeLang = 0, 316 StringRef UniqueIdentifier = ""); 317 318 /// Create debugging information for template 319 /// type parameter. 320 /// \param Scope Scope in which this type is defined. 321 /// \param Name Type parameter name. 322 /// \param Ty Parameter type. 323 DITemplateTypeParameter * 324 createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty); 325 326 /// Create debugging information for template 327 /// value parameter. 328 /// \param Scope Scope in which this type is defined. 329 /// \param Name Value parameter name. 330 /// \param Ty Parameter type. 331 /// \param Val Constant parameter value. 332 DITemplateValueParameter *createTemplateValueParameter(DIScope *Scope, 333 StringRef Name, 334 DIType *Ty, 335 Constant *Val); 336 337 /// Create debugging information for a template template parameter. 338 /// \param Scope Scope in which this type is defined. 339 /// \param Name Value parameter name. 340 /// \param Ty Parameter type. 341 /// \param Val The fully qualified name of the template. 342 DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope, 343 StringRef Name, 344 DIType *Ty, 345 StringRef Val); 346 347 /// Create debugging information for a template parameter pack. 348 /// \param Scope Scope in which this type is defined. 349 /// \param Name Value parameter name. 350 /// \param Ty Parameter type. 351 /// \param Val An array of types in the pack. 352 DITemplateValueParameter *createTemplateParameterPack(DIScope *Scope, 353 StringRef Name, 354 DIType *Ty, 355 DINodeArray Val); 356 357 /// Create debugging information entry for an array. 358 /// \param Size Array size. 359 /// \param AlignInBits Alignment. 360 /// \param Ty Element type. 361 /// \param Subscripts Subscripts. 362 DICompositeType *createArrayType(uint64_t Size, uint64_t AlignInBits, 363 DIType *Ty, DINodeArray Subscripts); 364 365 /// Create debugging information entry for a vector type. 366 /// \param Size Array size. 367 /// \param AlignInBits Alignment. 368 /// \param Ty Element type. 369 /// \param Subscripts Subscripts. 370 DICompositeType *createVectorType(uint64_t Size, uint64_t AlignInBits, 371 DIType *Ty, DINodeArray Subscripts); 372 373 /// Create debugging information entry for an 374 /// enumeration. 375 /// \param Scope Scope in which this enumeration is defined. 376 /// \param Name Union name. 377 /// \param File File where this member is defined. 378 /// \param LineNumber Line number. 379 /// \param SizeInBits Member size. 380 /// \param AlignInBits Member alignment. 381 /// \param Elements Enumeration elements. 382 /// \param UnderlyingType Underlying type of a C++11/ObjC fixed enum. 383 /// \param UniqueIdentifier A unique identifier for the enum. 384 DICompositeType *createEnumerationType( 385 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 386 uint64_t SizeInBits, uint64_t AlignInBits, DINodeArray Elements, 387 DIType *UnderlyingType, StringRef UniqueIdentifier = ""); 388 389 /// Create subroutine type. 390 /// \param ParameterTypes An array of subroutine parameter types. This 391 /// includes return type at 0th index. 392 /// \param Flags E.g.: LValueReference. 393 /// These flags are used to emit dwarf attributes. 394 /// \param CC Calling convention, e.g. dwarf::DW_CC_normal 395 DISubroutineType *createSubroutineType(DITypeRefArray ParameterTypes, 396 unsigned Flags = 0, unsigned CC = 0); 397 398 /// Create an external type reference. 399 /// \param Tag Dwarf TAG. 400 /// \param File File in which the type is defined. 401 /// \param UniqueIdentifier A unique identifier for the type. 402 DICompositeType *createExternalTypeRef(unsigned Tag, DIFile *File, 403 StringRef UniqueIdentifier); 404 405 /// Create a new DIType* with "artificial" flag set. 406 DIType *createArtificialType(DIType *Ty); 407 408 /// Create a new DIType* with the "object pointer" 409 /// flag set. 410 DIType *createObjectPointerType(DIType *Ty); 411 412 /// Create a permanent forward-declared type. 413 DICompositeType *createForwardDecl(unsigned Tag, StringRef Name, 414 DIScope *Scope, DIFile *F, unsigned Line, 415 unsigned RuntimeLang = 0, 416 uint64_t SizeInBits = 0, 417 uint64_t AlignInBits = 0, 418 StringRef UniqueIdentifier = ""); 419 420 /// Create a temporary forward-declared type. 421 DICompositeType *createReplaceableCompositeType( 422 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, 423 unsigned RuntimeLang = 0, uint64_t SizeInBits = 0, 424 uint64_t AlignInBits = 0, unsigned Flags = DINode::FlagFwdDecl, 425 StringRef UniqueIdentifier = ""); 426 427 /// Retain DIScope* in a module even if it is not referenced 428 /// through debug info anchors. 429 void retainType(DIScope *T); 430 431 /// Create unspecified parameter type 432 /// for a subroutine type. 433 DIBasicType *createUnspecifiedParameter(); 434 435 /// Get a DINodeArray, create one if required. 436 DINodeArray getOrCreateArray(ArrayRef<Metadata *> Elements); 437 438 /// Get a DITypeRefArray, create one if required. 439 DITypeRefArray getOrCreateTypeArray(ArrayRef<Metadata *> Elements); 440 441 /// Create a descriptor for a value range. This 442 /// implicitly uniques the values returned. 443 DISubrange *getOrCreateSubrange(int64_t Lo, int64_t Count); 444 445 /// Create a new descriptor for the specified 446 /// variable. 447 /// \param Context Variable scope. 448 /// \param Name Name of the variable. 449 /// \param LinkageName Mangled name of the variable. 450 /// \param File File where this variable is defined. 451 /// \param LineNo Line number. 452 /// \param Ty Variable Type. 453 /// \param isLocalToUnit Boolean flag indicate whether this variable is 454 /// externally visible or not. 455 /// \param Val llvm::Value of the variable. 456 /// \param Decl Reference to the corresponding declaration. 457 DIGlobalVariable *createGlobalVariable(DIScope *Context, StringRef Name, 458 StringRef LinkageName, DIFile *File, 459 unsigned LineNo, DIType *Ty, 460 bool isLocalToUnit, 461 llvm::Constant *Val, 462 MDNode *Decl = nullptr); 463 464 /// Identical to createGlobalVariable 465 /// except that the resulting DbgNode is temporary and meant to be RAUWed. 466 DIGlobalVariable *createTempGlobalVariableFwdDecl( 467 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, 468 unsigned LineNo, DIType *Ty, bool isLocalToUnit, llvm::Constant *Val, 469 MDNode *Decl = nullptr); 470 471 /// Create a new descriptor for an auto variable. This is a local variable 472 /// that is not a subprogram parameter. 473 /// 474 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually 475 /// leads to a \a DISubprogram. 476 /// 477 /// If \c AlwaysPreserve, this variable will be referenced from its 478 /// containing subprogram, and will survive some optimizations. 479 DILocalVariable *createAutoVariable(DIScope *Scope, StringRef Name, 480 DIFile *File, unsigned LineNo, 481 DIType *Ty, 482 bool AlwaysPreserve = false, 483 unsigned Flags = 0); 484 485 /// Create a new descriptor for a parameter variable. 486 /// 487 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually 488 /// leads to a \a DISubprogram. 489 /// 490 /// \c ArgNo is the index (starting from \c 1) of this variable in the 491 /// subprogram parameters. \c ArgNo should not conflict with other 492 /// parameters of the same subprogram. 493 /// 494 /// If \c AlwaysPreserve, this variable will be referenced from its 495 /// containing subprogram, and will survive some optimizations. 496 DILocalVariable *createParameterVariable(DIScope *Scope, StringRef Name, 497 unsigned ArgNo, DIFile *File, 498 unsigned LineNo, DIType *Ty, 499 bool AlwaysPreserve = false, 500 unsigned Flags = 0); 501 502 /// Create a new descriptor for the specified 503 /// variable which has a complex address expression for its address. 504 /// \param Addr An array of complex address operations. 505 DIExpression *createExpression(ArrayRef<uint64_t> Addr = None); 506 DIExpression *createExpression(ArrayRef<int64_t> Addr); 507 508 /// Create a descriptor to describe one part 509 /// of aggregate variable that is fragmented across multiple Values. 510 /// 511 /// \param OffsetInBits Offset of the piece in bits. 512 /// \param SizeInBits Size of the piece in bits. 513 DIExpression *createBitPieceExpression(unsigned OffsetInBits, 514 unsigned SizeInBits); 515 516 /// Create a new descriptor for the specified subprogram. 517 /// See comments in DISubprogram* for descriptions of these fields. 518 /// \param Scope Function scope. 519 /// \param Name Function name. 520 /// \param LinkageName Mangled function name. 521 /// \param File File where this variable is defined. 522 /// \param LineNo Line number. 523 /// \param Ty Function type. 524 /// \param isLocalToUnit True if this function is not externally visible. 525 /// \param isDefinition True if this is a function definition. 526 /// \param ScopeLine Set to the beginning of the scope this starts 527 /// \param Flags e.g. is this function prototyped or not. 528 /// These flags are used to emit dwarf attributes. 529 /// \param isOptimized True if optimization is ON. 530 /// \param TParams Function template parameters. 531 DISubprogram *createFunction(DIScope *Scope, StringRef Name, 532 StringRef LinkageName, DIFile *File, 533 unsigned LineNo, DISubroutineType *Ty, 534 bool isLocalToUnit, bool isDefinition, 535 unsigned ScopeLine, unsigned Flags = 0, 536 bool isOptimized = false, 537 DITemplateParameterArray TParams = nullptr, 538 DISubprogram *Decl = nullptr); 539 540 /// Identical to createFunction, 541 /// except that the resulting DbgNode is meant to be RAUWed. 542 DISubprogram *createTempFunctionFwdDecl( 543 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, 544 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, 545 bool isDefinition, unsigned ScopeLine, unsigned Flags = 0, 546 bool isOptimized = false, DITemplateParameterArray TParams = nullptr, 547 DISubprogram *Decl = nullptr); 548 549 /// Create a new descriptor for the specified C++ method. 550 /// See comments in \a DISubprogram* for descriptions of these fields. 551 /// \param Scope Function scope. 552 /// \param Name Function name. 553 /// \param LinkageName Mangled function name. 554 /// \param File File where this variable is defined. 555 /// \param LineNo Line number. 556 /// \param Ty Function type. 557 /// \param isLocalToUnit True if this function is not externally visible.. 558 /// \param isDefinition True if this is a function definition. 559 /// \param Virtuality Attributes describing virtualness. e.g. pure 560 /// virtual function. 561 /// \param VTableIndex Index no of this method in virtual table, or -1u if 562 /// unrepresentable. 563 /// \param ThisAdjustment 564 /// MS ABI-specific adjustment of 'this' that occurs 565 /// in the prologue. 566 /// \param VTableHolder Type that holds vtable. 567 /// \param Flags e.g. is this function prototyped or not. 568 /// This flags are used to emit dwarf attributes. 569 /// \param isOptimized True if optimization is ON. 570 /// \param TParams Function template parameters. 571 DISubprogram * 572 createMethod(DIScope *Scope, StringRef Name, StringRef LinkageName, 573 DIFile *File, unsigned LineNo, DISubroutineType *Ty, 574 bool isLocalToUnit, bool isDefinition, unsigned Virtuality = 0, 575 unsigned VTableIndex = 0, int ThisAdjustment = 0, 576 DIType *VTableHolder = nullptr, unsigned Flags = 0, 577 bool isOptimized = false, 578 DITemplateParameterArray TParams = nullptr); 579 580 /// This creates new descriptor for a namespace with the specified 581 /// parent scope. 582 /// \param Scope Namespace scope 583 /// \param Name Name of this namespace 584 /// \param File Source file 585 /// \param LineNo Line number 586 DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File, 587 unsigned LineNo); 588 589 /// This creates new descriptor for a module with the specified 590 /// parent scope. 591 /// \param Scope Parent scope 592 /// \param Name Name of this module 593 /// \param ConfigurationMacros 594 /// A space-separated shell-quoted list of -D macro 595 /// definitions as they would appear on a command line. 596 /// \param IncludePath The path to the module map file. 597 /// \param ISysRoot The clang system root (value of -isysroot). 598 DIModule *createModule(DIScope *Scope, StringRef Name, 599 StringRef ConfigurationMacros, 600 StringRef IncludePath, 601 StringRef ISysRoot); 602 603 /// This creates a descriptor for a lexical block with a new file 604 /// attached. This merely extends the existing 605 /// lexical block as it crosses a file. 606 /// \param Scope Lexical block. 607 /// \param File Source file. 608 /// \param Discriminator DWARF path discriminator value. 609 DILexicalBlockFile *createLexicalBlockFile(DIScope *Scope, DIFile *File, 610 unsigned Discriminator = 0); 611 612 /// This creates a descriptor for a lexical block with the 613 /// specified parent context. 614 /// \param Scope Parent lexical scope. 615 /// \param File Source file. 616 /// \param Line Line number. 617 /// \param Col Column number. 618 DILexicalBlock *createLexicalBlock(DIScope *Scope, DIFile *File, 619 unsigned Line, unsigned Col); 620 621 /// Create a descriptor for an imported module. 622 /// \param Context The scope this module is imported into 623 /// \param NS The namespace being imported here 624 /// \param Line Line number 625 DIImportedEntity *createImportedModule(DIScope *Context, DINamespace *NS, 626 unsigned Line); 627 628 /// Create a descriptor for an imported module. 629 /// \param Context The scope this module is imported into 630 /// \param NS An aliased namespace 631 /// \param Line Line number 632 DIImportedEntity *createImportedModule(DIScope *Context, 633 DIImportedEntity *NS, unsigned Line); 634 635 /// Create a descriptor for an imported module. 636 /// \param Context The scope this module is imported into 637 /// \param M The module being imported here 638 /// \param Line Line number 639 DIImportedEntity *createImportedModule(DIScope *Context, DIModule *M, 640 unsigned Line); 641 642 /// Create a descriptor for an imported function. 643 /// \param Context The scope this module is imported into 644 /// \param Decl The declaration (or definition) of a function, type, or 645 /// variable 646 /// \param Line Line number 647 DIImportedEntity *createImportedDeclaration(DIScope *Context, DINode *Decl, 648 unsigned Line, 649 StringRef Name = ""); 650 651 /// Insert a new llvm.dbg.declare intrinsic call. 652 /// \param Storage llvm::Value of the variable 653 /// \param VarInfo Variable's debug info descriptor. 654 /// \param Expr A complex location expression. 655 /// \param DL Debug info location. 656 /// \param InsertAtEnd Location for the new intrinsic. 657 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo, 658 DIExpression *Expr, const DILocation *DL, 659 BasicBlock *InsertAtEnd); 660 661 /// Insert a new llvm.dbg.declare intrinsic call. 662 /// \param Storage llvm::Value of the variable 663 /// \param VarInfo Variable's debug info descriptor. 664 /// \param Expr A complex location expression. 665 /// \param DL Debug info location. 666 /// \param InsertBefore Location for the new intrinsic. 667 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo, 668 DIExpression *Expr, const DILocation *DL, 669 Instruction *InsertBefore); 670 671 /// Insert a new llvm.dbg.value intrinsic call. 672 /// \param Val llvm::Value of the variable 673 /// \param Offset Offset 674 /// \param VarInfo Variable's debug info descriptor. 675 /// \param Expr A complex location expression. 676 /// \param DL Debug info location. 677 /// \param InsertAtEnd Location for the new intrinsic. 678 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset, 679 DILocalVariable *VarInfo, 680 DIExpression *Expr, 681 const DILocation *DL, 682 BasicBlock *InsertAtEnd); 683 684 /// Insert a new llvm.dbg.value intrinsic call. 685 /// \param Val llvm::Value of the variable 686 /// \param Offset Offset 687 /// \param VarInfo Variable's debug info descriptor. 688 /// \param Expr A complex location expression. 689 /// \param DL Debug info location. 690 /// \param InsertBefore Location for the new intrinsic. 691 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset, 692 DILocalVariable *VarInfo, 693 DIExpression *Expr, 694 const DILocation *DL, 695 Instruction *InsertBefore); 696 697 /// Replace the vtable holder in the given composite type. 698 /// 699 /// If this creates a self reference, it may orphan some unresolved cycles 700 /// in the operands of \c T, so \a DIBuilder needs to track that. 701 void replaceVTableHolder(DICompositeType *&T, 702 DICompositeType *VTableHolder); 703 704 /// Replace arrays on a composite type. 705 /// 706 /// If \c T is resolved, but the arrays aren't -- which can happen if \c T 707 /// has a self-reference -- \a DIBuilder needs to track the array to 708 /// resolve cycles. 709 void replaceArrays(DICompositeType *&T, DINodeArray Elements, 710 DINodeArray TParams = DINodeArray()); 711 712 /// Replace a temporary node. 713 /// 714 /// Call \a MDNode::replaceAllUsesWith() on \c N, replacing it with \c 715 /// Replacement. 716 /// 717 /// If \c Replacement is the same as \c N.get(), instead call \a 718 /// MDNode::replaceWithUniqued(). In this case, the uniqued node could 719 /// have a different address, so we return the final address. 720 template <class NodeTy> replaceTemporary(TempMDNode && N,NodeTy * Replacement)721 NodeTy *replaceTemporary(TempMDNode &&N, NodeTy *Replacement) { 722 if (N.get() == Replacement) 723 return cast<NodeTy>(MDNode::replaceWithUniqued(std::move(N))); 724 725 N->replaceAllUsesWith(Replacement); 726 return Replacement; 727 } 728 }; 729 } // end namespace llvm 730 731 #endif 732