Debian Codegraph @

suite/synctools/tablegen/include/llvm/IR/DIBuilder.h

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