DIBuilder.h 46 KB

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