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