1 //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Declarations for metadata specific to debug info.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_DEBUGINFOMETADATA_H
15 #define LLVM_IR_DEBUGINFOMETADATA_H
17 #include "llvm/IR/Metadata.h"
18 #include "llvm/Support/Dwarf.h"
20 // Helper macros for defining get() overrides.
21 #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
22 #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
23 #define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) \
24 static CLASS *getDistinct(LLVMContext &Context, \
25 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
26 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
28 static Temp##CLASS getTemporary(LLVMContext &Context, \
29 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
31 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
33 #define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
34 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
35 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
37 static CLASS *getIfExists(LLVMContext &Context, \
38 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
39 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
40 /* ShouldCreate */ false); \
42 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
46 template <typename T> class Optional;
48 /// Holds a subclass of DINode.
50 /// FIXME: This class doesn't currently make much sense. Previously it was a
51 /// union beteen MDString (for ODR-uniqued types) and things like DIType. To
52 /// support CodeView work, it wasn't deleted outright when MDString-based type
53 /// references were deleted; we'll soon need a similar concept for CodeView
55 template <class T> class TypedDINodeRef {
56 const Metadata *MD = nullptr;
59 TypedDINodeRef() = default;
60 TypedDINodeRef(std::nullptr_t) {}
61 TypedDINodeRef(const T *MD) : MD(MD) {}
63 explicit TypedDINodeRef(const Metadata *MD) : MD(MD) {
64 assert((!MD || isa<T>(MD)) && "Expected valid type ref");
69 const TypedDINodeRef<U> &X,
70 typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
74 operator Metadata *() const { return const_cast<Metadata *>(MD); }
76 T *resolve() const { return const_cast<T *>(cast_or_null<T>(MD)); }
78 bool operator==(const TypedDINodeRef<T> &X) const { return MD == X.MD; }
79 bool operator!=(const TypedDINodeRef<T> &X) const { return MD != X.MD; }
82 typedef TypedDINodeRef<DINode> DINodeRef;
83 typedef TypedDINodeRef<DIScope> DIScopeRef;
84 typedef TypedDINodeRef<DIType> DITypeRef;
86 class DITypeRefArray {
87 const MDTuple *N = nullptr;
90 DITypeRefArray() = default;
91 DITypeRefArray(const MDTuple *N) : N(N) {}
93 explicit operator bool() const { return get(); }
94 explicit operator MDTuple *() const { return get(); }
96 MDTuple *get() const { return const_cast<MDTuple *>(N); }
97 MDTuple *operator->() const { return get(); }
98 MDTuple &operator*() const { return *get(); }
100 // FIXME: Fix callers and remove condition on N.
101 unsigned size() const { return N ? N->getNumOperands() : 0u; }
102 DITypeRef operator[](unsigned I) const { return DITypeRef(N->getOperand(I)); }
104 class iterator : std::iterator<std::input_iterator_tag, DITypeRef,
105 std::ptrdiff_t, void, DITypeRef> {
106 MDNode::op_iterator I = nullptr;
109 iterator() = default;
110 explicit iterator(MDNode::op_iterator I) : I(I) {}
111 DITypeRef operator*() const { return DITypeRef(*I); }
112 iterator &operator++() {
116 iterator operator++(int) {
117 iterator Temp(*this);
121 bool operator==(const iterator &X) const { return I == X.I; }
122 bool operator!=(const iterator &X) const { return I != X.I; }
125 // FIXME: Fix callers and remove condition on N.
126 iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
127 iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
130 /// \brief Tagged DWARF-like metadata node.
132 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
133 /// defined in llvm/Support/Dwarf.h). Called \a DINode because it's
134 /// potentially used for non-DWARF output.
135 class DINode : public MDNode {
136 friend class LLVMContextImpl;
140 DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
141 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
142 : MDNode(C, ID, Storage, Ops1, Ops2) {
143 assert(Tag < 1u << 16);
144 SubclassData16 = Tag;
148 template <class Ty> Ty *getOperandAs(unsigned I) const {
149 return cast_or_null<Ty>(getOperand(I));
152 StringRef getStringOperand(unsigned I) const {
153 if (auto *S = getOperandAs<MDString>(I))
154 return S->getString();
158 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
161 return MDString::get(Context, S);
164 /// Allow subclasses to mutate the tag.
165 void setTag(unsigned Tag) { SubclassData16 = Tag; }
168 unsigned getTag() const { return SubclassData16; }
170 /// \brief Debug info flags.
172 /// The three accessibility flags are mutually exclusive and rolled together
173 /// in the first two bits.
175 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
176 #include "llvm/IR/DebugInfoFlags.def"
177 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
178 FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
179 FlagVirtualInheritance,
182 static unsigned getFlag(StringRef Flag);
183 static const char *getFlagString(unsigned Flag);
185 /// \brief Split up a flags bitfield.
187 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
188 /// any remaining (unrecognized) bits.
189 static unsigned splitFlags(unsigned Flags,
190 SmallVectorImpl<unsigned> &SplitFlags);
192 static bool classof(const Metadata *MD) {
193 switch (MD->getMetadataID()) {
196 case GenericDINodeKind:
198 case DIEnumeratorKind:
199 case DIBasicTypeKind:
200 case DIDerivedTypeKind:
201 case DICompositeTypeKind:
202 case DISubroutineTypeKind:
204 case DICompileUnitKind:
205 case DISubprogramKind:
206 case DILexicalBlockKind:
207 case DILexicalBlockFileKind:
208 case DINamespaceKind:
209 case DITemplateTypeParameterKind:
210 case DITemplateValueParameterKind:
211 case DIGlobalVariableKind:
212 case DILocalVariableKind:
213 case DIObjCPropertyKind:
214 case DIImportedEntityKind:
221 template <class T> struct simplify_type<const TypedDINodeRef<T>> {
222 typedef Metadata *SimpleType;
223 static SimpleType getSimplifiedValue(const TypedDINodeRef<T> &MD) {
229 struct simplify_type<TypedDINodeRef<T>>
230 : simplify_type<const TypedDINodeRef<T>> {};
232 /// \brief Generic tagged DWARF-like metadata node.
234 /// An un-specialized DWARF-like metadata node. The first operand is a
235 /// (possibly empty) null-separated \a MDString header that contains arbitrary
236 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
237 /// to other metadata.
238 class GenericDINode : public DINode {
239 friend class LLVMContextImpl;
242 GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
243 unsigned Tag, ArrayRef<Metadata *> Ops1,
244 ArrayRef<Metadata *> Ops2)
245 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
248 ~GenericDINode() { dropAllReferences(); }
250 void setHash(unsigned Hash) { SubclassData32 = Hash; }
251 void recalculateHash();
253 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
254 StringRef Header, ArrayRef<Metadata *> DwarfOps,
255 StorageType Storage, bool ShouldCreate = true) {
256 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
257 DwarfOps, Storage, ShouldCreate);
260 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
261 MDString *Header, ArrayRef<Metadata *> DwarfOps,
262 StorageType Storage, bool ShouldCreate = true);
264 TempGenericDINode cloneImpl() const {
266 getContext(), getTag(), getHeader(),
267 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
271 unsigned getHash() const { return SubclassData32; }
273 DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, StringRef Header,
274 ArrayRef<Metadata *> DwarfOps),
275 (Tag, Header, DwarfOps))
276 DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, MDString *Header,
277 ArrayRef<Metadata *> DwarfOps),
278 (Tag, Header, DwarfOps))
280 /// \brief Return a (temporary) clone of this.
281 TempGenericDINode clone() const { return cloneImpl(); }
283 unsigned getTag() const { return SubclassData16; }
284 StringRef getHeader() const { return getStringOperand(0); }
285 MDString *getRawHeader() const { return getOperandAs<MDString>(0); }
287 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
288 op_iterator dwarf_op_end() const { return op_end(); }
289 op_range dwarf_operands() const {
290 return op_range(dwarf_op_begin(), dwarf_op_end());
293 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
294 const MDOperand &getDwarfOperand(unsigned I) const {
295 return getOperand(I + 1);
297 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
298 replaceOperandWith(I + 1, New);
301 static bool classof(const Metadata *MD) {
302 return MD->getMetadataID() == GenericDINodeKind;
306 /// \brief Array subrange.
308 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
310 class DISubrange : public DINode {
311 friend class LLVMContextImpl;
317 DISubrange(LLVMContext &C, StorageType Storage, int64_t Count,
319 : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, None),
320 Count(Count), LowerBound(LowerBound) {}
321 ~DISubrange() = default;
323 static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
324 int64_t LowerBound, StorageType Storage,
325 bool ShouldCreate = true);
327 TempDISubrange cloneImpl() const {
328 return getTemporary(getContext(), getCount(), getLowerBound());
332 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
335 TempDISubrange clone() const { return cloneImpl(); }
337 int64_t getLowerBound() const { return LowerBound; }
338 int64_t getCount() const { return Count; }
340 static bool classof(const Metadata *MD) {
341 return MD->getMetadataID() == DISubrangeKind;
345 /// \brief Enumeration value.
347 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
348 /// longer creates a type cycle.
349 class DIEnumerator : public DINode {
350 friend class LLVMContextImpl;
355 DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
356 ArrayRef<Metadata *> Ops)
357 : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
359 ~DIEnumerator() = default;
361 static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
362 StringRef Name, StorageType Storage,
363 bool ShouldCreate = true) {
364 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
367 static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
368 MDString *Name, StorageType Storage,
369 bool ShouldCreate = true);
371 TempDIEnumerator cloneImpl() const {
372 return getTemporary(getContext(), getValue(), getName());
376 DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, StringRef Name),
378 DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, MDString *Name),
381 TempDIEnumerator clone() const { return cloneImpl(); }
383 int64_t getValue() const { return Value; }
384 StringRef getName() const { return getStringOperand(0); }
386 MDString *getRawName() const { return getOperandAs<MDString>(0); }
388 static bool classof(const Metadata *MD) {
389 return MD->getMetadataID() == DIEnumeratorKind;
393 /// \brief Base class for scope-like contexts.
395 /// Base class for lexical scopes and types (which are also declaration
398 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
399 class DIScope : public DINode {
401 DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
402 ArrayRef<Metadata *> Ops)
403 : DINode(C, ID, Storage, Tag, Ops) {}
404 ~DIScope() = default;
407 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
409 inline StringRef getFilename() const;
410 inline StringRef getDirectory() const;
412 StringRef getName() const;
413 DIScopeRef getScope() const;
415 /// \brief Return the raw underlying file.
417 /// An \a DIFile is an \a DIScope, but it doesn't point at a separate file
418 /// (it\em is the file). If \c this is an \a DIFile, we need to return \c
419 /// this. Otherwise, return the first operand, which is where all other
420 /// subclasses store their file pointer.
421 Metadata *getRawFile() const {
422 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
423 : static_cast<Metadata *>(getOperand(0));
426 static bool classof(const Metadata *MD) {
427 switch (MD->getMetadataID()) {
430 case DIBasicTypeKind:
431 case DIDerivedTypeKind:
432 case DICompositeTypeKind:
433 case DISubroutineTypeKind:
435 case DICompileUnitKind:
436 case DISubprogramKind:
437 case DILexicalBlockKind:
438 case DILexicalBlockFileKind:
439 case DINamespaceKind:
448 /// TODO: Merge with directory/file node (including users).
449 /// TODO: Canonicalize paths on creation.
450 class DIFile : public DIScope {
451 friend class LLVMContextImpl;
454 DIFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
455 : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
458 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
459 StringRef Directory, StorageType Storage,
460 bool ShouldCreate = true) {
461 return getImpl(Context, getCanonicalMDString(Context, Filename),
462 getCanonicalMDString(Context, Directory), Storage,
465 static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
466 MDString *Directory, StorageType Storage,
467 bool ShouldCreate = true);
469 TempDIFile cloneImpl() const {
470 return getTemporary(getContext(), getFilename(), getDirectory());
474 DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory),
475 (Filename, Directory))
476 DEFINE_MDNODE_GET(DIFile, (MDString * Filename, MDString *Directory),
477 (Filename, Directory))
479 TempDIFile clone() const { return cloneImpl(); }
481 StringRef getFilename() const { return getStringOperand(0); }
482 StringRef getDirectory() const { return getStringOperand(1); }
484 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
485 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
487 static bool classof(const Metadata *MD) {
488 return MD->getMetadataID() == DIFileKind;
492 StringRef DIScope::getFilename() const {
493 if (auto *F = getFile())
494 return F->getFilename();
498 StringRef DIScope::getDirectory() const {
499 if (auto *F = getFile())
500 return F->getDirectory();
504 /// \brief Base class for types.
506 /// TODO: Remove the hardcoded name and context, since many types don't use
508 /// TODO: Split up flags.
509 class DIType : public DIScope {
513 uint64_t AlignInBits;
514 uint64_t OffsetInBits;
517 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
518 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
519 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
520 : DIScope(C, ID, Storage, Tag, Ops) {
521 init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
525 void init(unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
526 uint64_t OffsetInBits, unsigned Flags) {
529 this->SizeInBits = SizeInBits;
530 this->AlignInBits = AlignInBits;
531 this->OffsetInBits = OffsetInBits;
534 /// Change fields in place.
535 void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits,
536 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags) {
537 assert(isDistinct() && "Only distinct nodes can mutate");
539 init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
543 TempDIType clone() const {
544 return TempDIType(cast<DIType>(MDNode::clone().release()));
547 unsigned getLine() const { return Line; }
548 uint64_t getSizeInBits() const { return SizeInBits; }
549 uint64_t getAlignInBits() const { return AlignInBits; }
550 uint64_t getOffsetInBits() const { return OffsetInBits; }
551 unsigned getFlags() const { return Flags; }
553 DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
554 StringRef getName() const { return getStringOperand(2); }
557 Metadata *getRawScope() const { return getOperand(1); }
558 MDString *getRawName() const { return getOperandAs<MDString>(2); }
560 void setFlags(unsigned NewFlags) {
561 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
565 bool isPrivate() const {
566 return (getFlags() & FlagAccessibility) == FlagPrivate;
568 bool isProtected() const {
569 return (getFlags() & FlagAccessibility) == FlagProtected;
571 bool isPublic() const {
572 return (getFlags() & FlagAccessibility) == FlagPublic;
574 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
575 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
576 bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; }
577 bool isVirtual() const { return getFlags() & FlagVirtual; }
578 bool isArtificial() const { return getFlags() & FlagArtificial; }
579 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
580 bool isObjcClassComplete() const {
581 return getFlags() & FlagObjcClassComplete;
583 bool isVector() const { return getFlags() & FlagVector; }
584 bool isBitField() const { return getFlags() & FlagBitField; }
585 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
586 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
587 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
588 bool isExternalTypeRef() const { return getFlags() & FlagExternalTypeRef; }
590 static bool classof(const Metadata *MD) {
591 switch (MD->getMetadataID()) {
594 case DIBasicTypeKind:
595 case DIDerivedTypeKind:
596 case DICompositeTypeKind:
597 case DISubroutineTypeKind:
603 /// \brief Basic type, like 'int' or 'float'.
605 /// TODO: Split out DW_TAG_unspecified_type.
606 /// TODO: Drop unused accessors.
607 class DIBasicType : public DIType {
608 friend class LLVMContextImpl;
613 DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
614 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
615 ArrayRef<Metadata *> Ops)
616 : DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
618 Encoding(Encoding) {}
619 ~DIBasicType() = default;
621 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
622 StringRef Name, uint64_t SizeInBits,
623 uint64_t AlignInBits, unsigned Encoding,
624 StorageType Storage, bool ShouldCreate = true) {
625 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
626 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
628 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
629 MDString *Name, uint64_t SizeInBits,
630 uint64_t AlignInBits, unsigned Encoding,
631 StorageType Storage, bool ShouldCreate = true);
633 TempDIBasicType cloneImpl() const {
634 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
635 getAlignInBits(), getEncoding());
639 DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
640 (Tag, Name, 0, 0, 0))
641 DEFINE_MDNODE_GET(DIBasicType,
642 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
643 uint64_t AlignInBits, unsigned Encoding),
644 (Tag, Name, SizeInBits, AlignInBits, Encoding))
645 DEFINE_MDNODE_GET(DIBasicType,
646 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
647 uint64_t AlignInBits, unsigned Encoding),
648 (Tag, Name, SizeInBits, AlignInBits, Encoding))
650 TempDIBasicType clone() const { return cloneImpl(); }
652 unsigned getEncoding() const { return Encoding; }
654 static bool classof(const Metadata *MD) {
655 return MD->getMetadataID() == DIBasicTypeKind;
659 /// \brief Derived types.
661 /// This includes qualified types, pointers, references, friends, typedefs, and
664 /// TODO: Split out members (inheritance, fields, methods, etc.).
665 class DIDerivedType : public DIType {
666 friend class LLVMContextImpl;
669 DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
670 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
671 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
672 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits,
673 AlignInBits, OffsetInBits, Flags, Ops) {}
674 ~DIDerivedType() = default;
676 static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
677 StringRef Name, DIFile *File, unsigned Line,
678 DIScopeRef Scope, DITypeRef BaseType,
679 uint64_t SizeInBits, uint64_t AlignInBits,
680 uint64_t OffsetInBits, unsigned Flags,
681 Metadata *ExtraData, StorageType Storage,
682 bool ShouldCreate = true) {
683 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
684 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
685 Flags, ExtraData, Storage, ShouldCreate);
687 static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
688 MDString *Name, Metadata *File, unsigned Line,
689 Metadata *Scope, Metadata *BaseType,
690 uint64_t SizeInBits, uint64_t AlignInBits,
691 uint64_t OffsetInBits, unsigned Flags,
692 Metadata *ExtraData, StorageType Storage,
693 bool ShouldCreate = true);
695 TempDIDerivedType cloneImpl() const {
696 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
697 getScope(), getBaseType(), getSizeInBits(),
698 getAlignInBits(), getOffsetInBits(), getFlags(),
703 DEFINE_MDNODE_GET(DIDerivedType,
704 (unsigned Tag, MDString *Name, Metadata *File,
705 unsigned Line, Metadata *Scope, Metadata *BaseType,
706 uint64_t SizeInBits, uint64_t AlignInBits,
707 uint64_t OffsetInBits, unsigned Flags,
708 Metadata *ExtraData = nullptr),
709 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
710 AlignInBits, OffsetInBits, Flags, ExtraData))
711 DEFINE_MDNODE_GET(DIDerivedType,
712 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
713 DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
714 uint64_t AlignInBits, uint64_t OffsetInBits,
715 unsigned Flags, Metadata *ExtraData = nullptr),
716 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
717 AlignInBits, OffsetInBits, Flags, ExtraData))
719 TempDIDerivedType clone() const { return cloneImpl(); }
721 //// Get the base type this is derived from.
722 DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
723 Metadata *getRawBaseType() const { return getOperand(3); }
725 /// \brief Get extra data associated with this derived type.
727 /// Class type for pointer-to-members, objective-c property node for ivars,
728 /// or global constant wrapper for static members.
730 /// TODO: Separate out types that need this extra operand: pointer-to-member
731 /// types and member fields (static members and ivars).
732 Metadata *getExtraData() const { return getRawExtraData(); }
733 Metadata *getRawExtraData() const { return getOperand(4); }
735 /// \brief Get casted version of extra data.
737 DITypeRef getClassType() const {
738 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
739 return DITypeRef(getExtraData());
741 DIObjCProperty *getObjCProperty() const {
742 return dyn_cast_or_null<DIObjCProperty>(getExtraData());
744 Constant *getStorageOffsetInBits() const {
745 assert(getTag() == dwarf::DW_TAG_member && isBitField());
746 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
747 return C->getValue();
750 Constant *getConstant() const {
751 assert(getTag() == dwarf::DW_TAG_member && isStaticMember());
752 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
753 return C->getValue();
758 static bool classof(const Metadata *MD) {
759 return MD->getMetadataID() == DIDerivedTypeKind;
763 /// \brief Composite types.
765 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
766 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
767 class DICompositeType : public DIType {
768 friend class LLVMContextImpl;
771 unsigned RuntimeLang;
773 DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
774 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
775 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
776 ArrayRef<Metadata *> Ops)
777 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, SizeInBits,
778 AlignInBits, OffsetInBits, Flags, Ops),
779 RuntimeLang(RuntimeLang) {}
780 ~DICompositeType() = default;
782 /// Change fields in place.
783 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
784 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
786 assert(isDistinct() && "Only distinct nodes can mutate");
787 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
788 this->RuntimeLang = RuntimeLang;
789 DIType::mutate(Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
792 static DICompositeType *
793 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
794 unsigned Line, DIScopeRef Scope, DITypeRef BaseType,
795 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
796 uint64_t Flags, DINodeArray Elements, unsigned RuntimeLang,
797 DITypeRef VTableHolder, DITemplateParameterArray TemplateParams,
798 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
800 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
801 BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
802 RuntimeLang, VTableHolder, TemplateParams.get(),
803 getCanonicalMDString(Context, Identifier), Storage, ShouldCreate);
805 static DICompositeType *
806 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
807 unsigned Line, Metadata *Scope, Metadata *BaseType,
808 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
809 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
810 Metadata *VTableHolder, Metadata *TemplateParams,
811 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
813 TempDICompositeType cloneImpl() const {
814 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
815 getScope(), getBaseType(), getSizeInBits(),
816 getAlignInBits(), getOffsetInBits(), getFlags(),
817 getElements(), getRuntimeLang(), getVTableHolder(),
818 getTemplateParams(), getIdentifier());
822 DEFINE_MDNODE_GET(DICompositeType,
823 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
824 DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
825 uint64_t AlignInBits, uint64_t OffsetInBits,
826 unsigned Flags, DINodeArray Elements, unsigned RuntimeLang,
827 DITypeRef VTableHolder,
828 DITemplateParameterArray TemplateParams = nullptr,
829 StringRef Identifier = ""),
830 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
831 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
832 VTableHolder, TemplateParams, Identifier))
833 DEFINE_MDNODE_GET(DICompositeType,
834 (unsigned Tag, MDString *Name, Metadata *File,
835 unsigned Line, Metadata *Scope, Metadata *BaseType,
836 uint64_t SizeInBits, uint64_t AlignInBits,
837 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
838 unsigned RuntimeLang, Metadata *VTableHolder,
839 Metadata *TemplateParams = nullptr,
840 MDString *Identifier = nullptr),
841 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
842 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
843 VTableHolder, TemplateParams, Identifier))
845 TempDICompositeType clone() const { return cloneImpl(); }
847 /// Get a DICompositeType with the given ODR identifier.
849 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
850 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
853 /// Else, returns \c nullptr.
854 static DICompositeType *
855 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
856 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
857 Metadata *BaseType, uint64_t SizeInBits, uint64_t AlignInBits,
858 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
859 unsigned RuntimeLang, Metadata *VTableHolder,
860 Metadata *TemplateParams);
861 static DICompositeType *getODRTypeIfExists(LLVMContext &Context,
862 MDString &Identifier);
864 /// Build a DICompositeType with the given ODR identifier.
866 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
867 /// it doesn't exist, creates a new one. If it does exist and \a
868 /// isForwardDecl(), and the new arguments would be a definition, mutates the
869 /// the type in place. In either case, returns the type.
871 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
873 static DICompositeType *
874 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
875 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
876 Metadata *BaseType, uint64_t SizeInBits, uint64_t AlignInBits,
877 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
878 unsigned RuntimeLang, Metadata *VTableHolder,
879 Metadata *TemplateParams);
881 DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
882 DINodeArray getElements() const {
883 return cast_or_null<MDTuple>(getRawElements());
885 DITypeRef getVTableHolder() const { return DITypeRef(getRawVTableHolder()); }
886 DITemplateParameterArray getTemplateParams() const {
887 return cast_or_null<MDTuple>(getRawTemplateParams());
889 StringRef getIdentifier() const { return getStringOperand(7); }
890 unsigned getRuntimeLang() const { return RuntimeLang; }
892 Metadata *getRawBaseType() const { return getOperand(3); }
893 Metadata *getRawElements() const { return getOperand(4); }
894 Metadata *getRawVTableHolder() const { return getOperand(5); }
895 Metadata *getRawTemplateParams() const { return getOperand(6); }
896 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
898 /// \brief Replace operands.
900 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
901 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
902 /// of its movement if necessary.
904 void replaceElements(DINodeArray Elements) {
906 for (DINode *Op : getElements())
907 assert(is_contained(Elements->operands(), Op) &&
908 "Lost a member during member list replacement");
910 replaceOperandWith(4, Elements.get());
912 void replaceVTableHolder(DITypeRef VTableHolder) {
913 replaceOperandWith(5, VTableHolder);
915 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
916 replaceOperandWith(6, TemplateParams.get());
920 static bool classof(const Metadata *MD) {
921 return MD->getMetadataID() == DICompositeTypeKind;
925 /// \brief Type array for a subprogram.
927 /// TODO: Fold the array of types in directly as operands.
928 class DISubroutineType : public DIType {
929 friend class LLVMContextImpl;
932 /// The calling convention used with DW_AT_calling_convention. Actually of
933 /// type dwarf::CallingConvention.
936 DISubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
937 uint8_t CC, ArrayRef<Metadata *> Ops)
938 : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type,
939 0, 0, 0, 0, Flags, Ops),
941 ~DISubroutineType() = default;
943 static DISubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
944 uint8_t CC, DITypeRefArray TypeArray,
946 bool ShouldCreate = true) {
947 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
949 static DISubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
950 uint8_t CC, Metadata *TypeArray,
952 bool ShouldCreate = true);
954 TempDISubroutineType cloneImpl() const {
955 return getTemporary(getContext(), getFlags(), getCC(), getTypeArray());
959 DEFINE_MDNODE_GET(DISubroutineType,
960 (unsigned Flags, uint8_t CC, DITypeRefArray TypeArray),
961 (Flags, CC, TypeArray))
962 DEFINE_MDNODE_GET(DISubroutineType,
963 (unsigned Flags, uint8_t CC, Metadata *TypeArray),
964 (Flags, CC, TypeArray))
966 TempDISubroutineType clone() const { return cloneImpl(); }
968 uint8_t getCC() const { return CC; }
970 DITypeRefArray getTypeArray() const {
971 return cast_or_null<MDTuple>(getRawTypeArray());
973 Metadata *getRawTypeArray() const { return getOperand(3); }
975 static bool classof(const Metadata *MD) {
976 return MD->getMetadataID() == DISubroutineTypeKind;
980 /// \brief Compile unit.
981 class DICompileUnit : public DIScope {
982 friend class LLVMContextImpl;
985 enum DebugEmissionKind : unsigned {
989 LastEmissionKind = LineTablesOnly
991 static Optional<DebugEmissionKind> getEmissionKind(StringRef Str);
992 static const char *EmissionKindString(DebugEmissionKind EK);
995 unsigned SourceLanguage;
997 unsigned RuntimeVersion;
998 unsigned EmissionKind;
1000 bool SplitDebugInlining;
1002 DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
1003 bool IsOptimized, unsigned RuntimeVersion,
1004 unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
1005 ArrayRef<Metadata *> Ops)
1006 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
1007 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
1008 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
1009 DWOId(DWOId), SplitDebugInlining(SplitDebugInlining) {
1010 assert(Storage != Uniqued);
1012 ~DICompileUnit() = default;
1014 static DICompileUnit *
1015 getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
1016 StringRef Producer, bool IsOptimized, StringRef Flags,
1017 unsigned RuntimeVersion, StringRef SplitDebugFilename,
1018 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
1019 DIScopeArray RetainedTypes, DIGlobalVariableArray GlobalVariables,
1020 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1021 uint64_t DWOId, bool SplitDebugInlining, StorageType Storage,
1022 bool ShouldCreate = true) {
1023 return getImpl(Context, SourceLanguage, File,
1024 getCanonicalMDString(Context, Producer), IsOptimized,
1025 getCanonicalMDString(Context, Flags), RuntimeVersion,
1026 getCanonicalMDString(Context, SplitDebugFilename),
1027 EmissionKind, EnumTypes.get(), RetainedTypes.get(),
1028 GlobalVariables.get(), ImportedEntities.get(), Macros.get(),
1029 DWOId, SplitDebugInlining, Storage, ShouldCreate);
1031 static DICompileUnit *
1032 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
1033 MDString *Producer, bool IsOptimized, MDString *Flags,
1034 unsigned RuntimeVersion, MDString *SplitDebugFilename,
1035 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
1036 Metadata *GlobalVariables, Metadata *ImportedEntities,
1037 Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
1038 StorageType Storage, bool ShouldCreate = true);
1040 TempDICompileUnit cloneImpl() const {
1041 return getTemporary(getContext(), getSourceLanguage(), getFile(),
1042 getProducer(), isOptimized(), getFlags(),
1043 getRuntimeVersion(), getSplitDebugFilename(),
1044 getEmissionKind(), getEnumTypes(), getRetainedTypes(),
1045 getGlobalVariables(), getImportedEntities(),
1046 getMacros(), DWOId, getSplitDebugInlining());
1049 static void get() = delete;
1050 static void getIfExists() = delete;
1053 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
1055 (unsigned SourceLanguage, DIFile *File, StringRef Producer,
1056 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
1057 StringRef SplitDebugFilename, DebugEmissionKind EmissionKind,
1058 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
1059 DIGlobalVariableArray GlobalVariables,
1060 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1061 uint64_t DWOId, bool SplitDebugInlining),
1062 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1063 SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
1064 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining))
1065 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
1067 (unsigned SourceLanguage, Metadata *File, MDString *Producer,
1068 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
1069 MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
1070 Metadata *RetainedTypes, Metadata *GlobalVariables,
1071 Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
1072 bool SplitDebugInlining),
1073 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1074 SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
1075 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining))
1077 TempDICompileUnit clone() const { return cloneImpl(); }
1079 unsigned getSourceLanguage() const { return SourceLanguage; }
1080 bool isOptimized() const { return IsOptimized; }
1081 unsigned getRuntimeVersion() const { return RuntimeVersion; }
1082 DebugEmissionKind getEmissionKind() const {
1083 return (DebugEmissionKind)EmissionKind;
1085 StringRef getProducer() const { return getStringOperand(1); }
1086 StringRef getFlags() const { return getStringOperand(2); }
1087 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
1088 DICompositeTypeArray getEnumTypes() const {
1089 return cast_or_null<MDTuple>(getRawEnumTypes());
1091 DIScopeArray getRetainedTypes() const {
1092 return cast_or_null<MDTuple>(getRawRetainedTypes());
1094 DIGlobalVariableArray getGlobalVariables() const {
1095 return cast_or_null<MDTuple>(getRawGlobalVariables());
1097 DIImportedEntityArray getImportedEntities() const {
1098 return cast_or_null<MDTuple>(getRawImportedEntities());
1100 DIMacroNodeArray getMacros() const {
1101 return cast_or_null<MDTuple>(getRawMacros());
1103 uint64_t getDWOId() const { return DWOId; }
1104 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
1105 bool getSplitDebugInlining() const { return SplitDebugInlining; }
1106 void setSplitDebugInlining(bool SplitDebugInlining) {
1107 this->SplitDebugInlining = SplitDebugInlining;
1110 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1111 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1112 MDString *getRawSplitDebugFilename() const {
1113 return getOperandAs<MDString>(3);
1115 Metadata *getRawEnumTypes() const { return getOperand(4); }
1116 Metadata *getRawRetainedTypes() const { return getOperand(5); }
1117 Metadata *getRawGlobalVariables() const { return getOperand(6); }
1118 Metadata *getRawImportedEntities() const { return getOperand(7); }
1119 Metadata *getRawMacros() const { return getOperand(8); }
1121 /// \brief Replace arrays.
1123 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1124 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1125 /// DICompileUnit should be fairly rare.
1127 void replaceEnumTypes(DICompositeTypeArray N) {
1128 replaceOperandWith(4, N.get());
1130 void replaceRetainedTypes(DITypeArray N) {
1131 replaceOperandWith(5, N.get());
1133 void replaceGlobalVariables(DIGlobalVariableArray N) {
1134 replaceOperandWith(6, N.get());
1136 void replaceImportedEntities(DIImportedEntityArray N) {
1137 replaceOperandWith(7, N.get());
1139 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
1142 static bool classof(const Metadata *MD) {
1143 return MD->getMetadataID() == DICompileUnitKind;
1147 /// \brief A scope for locals.
1149 /// A legal scope for lexical blocks, local variables, and debug info
1150 /// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
1151 /// DILexicalBlockFile.
1152 class DILocalScope : public DIScope {
1154 DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1155 ArrayRef<Metadata *> Ops)
1156 : DIScope(C, ID, Storage, Tag, Ops) {}
1157 ~DILocalScope() = default;
1160 /// \brief Get the subprogram for this scope.
1162 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
1164 DISubprogram *getSubprogram() const;
1166 /// Get the first non DILexicalBlockFile scope of this scope.
1168 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
1170 DILocalScope *getNonLexicalBlockFileScope() const;
1172 static bool classof(const Metadata *MD) {
1173 return MD->getMetadataID() == DISubprogramKind ||
1174 MD->getMetadataID() == DILexicalBlockKind ||
1175 MD->getMetadataID() == DILexicalBlockFileKind;
1179 /// \brief Debug location.
1181 /// A debug location in source code, used for debug info and otherwise.
1182 class DILocation : public MDNode {
1183 friend class LLVMContextImpl;
1184 friend class MDNode;
1186 DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
1187 unsigned Column, ArrayRef<Metadata *> MDs);
1188 ~DILocation() { dropAllReferences(); }
1190 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1191 unsigned Column, Metadata *Scope,
1192 Metadata *InlinedAt, StorageType Storage,
1193 bool ShouldCreate = true);
1194 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1195 unsigned Column, DILocalScope *Scope,
1196 DILocation *InlinedAt, StorageType Storage,
1197 bool ShouldCreate = true) {
1198 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1199 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1202 TempDILocation cloneImpl() const {
1203 // Get the raw scope/inlinedAt since it is possible to invoke this on
1204 // a DILocation containing temporary metadata.
1205 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
1209 // Disallow replacing operands.
1210 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1213 DEFINE_MDNODE_GET(DILocation,
1214 (unsigned Line, unsigned Column, Metadata *Scope,
1215 Metadata *InlinedAt = nullptr),
1216 (Line, Column, Scope, InlinedAt))
1217 DEFINE_MDNODE_GET(DILocation,
1218 (unsigned Line, unsigned Column, DILocalScope *Scope,
1219 DILocation *InlinedAt = nullptr),
1220 (Line, Column, Scope, InlinedAt))
1222 /// \brief Return a (temporary) clone of this.
1223 TempDILocation clone() const { return cloneImpl(); }
1225 unsigned getLine() const { return SubclassData32; }
1226 unsigned getColumn() const { return SubclassData16; }
1227 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
1228 DILocation *getInlinedAt() const {
1229 return cast_or_null<DILocation>(getRawInlinedAt());
1232 DIFile *getFile() const { return getScope()->getFile(); }
1233 StringRef getFilename() const { return getScope()->getFilename(); }
1234 StringRef getDirectory() const { return getScope()->getDirectory(); }
1236 /// \brief Get the scope where this is inlined.
1238 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1240 DILocalScope *getInlinedAtScope() const {
1241 if (auto *IA = getInlinedAt())
1242 return IA->getInlinedAtScope();
1246 /// \brief Check whether this can be discriminated from another location.
1248 /// Check \c this can be discriminated from \c RHS in a linetable entry.
1249 /// Scope and inlined-at chains are not recorded in the linetable, so they
1250 /// cannot be used to distinguish basic blocks.
1252 /// The current implementation is weaker than it should be, since it just
1253 /// checks filename and line.
1255 /// FIXME: Add a check for getDiscriminator().
1256 /// FIXME: Add a check for getColumn().
1257 /// FIXME: Change the getFilename() check to getFile() (or add one for
1258 /// getDirectory()).
1259 bool canDiscriminate(const DILocation &RHS) const {
1260 return getFilename() != RHS.getFilename() || getLine() != RHS.getLine();
1263 /// \brief Get the DWARF discriminator.
1265 /// DWARF discriminators distinguish identical file locations between
1266 /// instructions that are on different basic blocks.
1267 inline unsigned getDiscriminator() const;
1269 Metadata *getRawScope() const { return getOperand(0); }
1270 Metadata *getRawInlinedAt() const {
1271 if (getNumOperands() == 2)
1272 return getOperand(1);
1276 static bool classof(const Metadata *MD) {
1277 return MD->getMetadataID() == DILocationKind;
1281 /// \brief Subprogram description.
1283 /// TODO: Remove DisplayName. It's always equal to Name.
1284 /// TODO: Split up flags.
1285 class DISubprogram : public DILocalScope {
1286 friend class LLVMContextImpl;
1287 friend class MDNode;
1291 unsigned VirtualIndex;
1293 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
1294 /// of method overrides from secondary bases by this amount. It may be
1298 // Virtuality can only assume three values, so we can pack
1299 // in 2 bits (none/pure/pure_virtual).
1300 unsigned Virtuality : 2;
1302 unsigned Flags : 27;
1304 // These are boolean flags so one bit is enough.
1305 // MSVC starts a new container field every time the base
1306 // type changes so we can't use 'bool' to ensure these bits
1308 unsigned IsLocalToUnit : 1;
1309 unsigned IsDefinition : 1;
1310 unsigned IsOptimized : 1;
1312 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1313 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1314 int ThisAdjustment, unsigned Flags, bool IsLocalToUnit,
1315 bool IsDefinition, bool IsOptimized, ArrayRef<Metadata *> Ops)
1316 : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1318 Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1319 ThisAdjustment(ThisAdjustment), Virtuality(Virtuality), Flags(Flags),
1320 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition),
1321 IsOptimized(IsOptimized) {
1322 static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1323 assert(Virtuality < 4 && "Virtuality out of range");
1324 assert((Flags < (1 << 27)) && "Flags out of range");
1326 ~DISubprogram() = default;
1328 static DISubprogram *
1329 getImpl(LLVMContext &Context, DIScopeRef Scope, StringRef Name,
1330 StringRef LinkageName, DIFile *File, unsigned Line,
1331 DISubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1332 unsigned ScopeLine, DITypeRef ContainingType, unsigned Virtuality,
1333 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
1334 bool IsOptimized, DICompileUnit *Unit,
1335 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
1336 DILocalVariableArray Variables, StorageType Storage,
1337 bool ShouldCreate = true) {
1338 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1339 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1340 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1341 Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized,
1342 Unit, TemplateParams.get(), Declaration, Variables.get(),
1343 Storage, ShouldCreate);
1345 static DISubprogram *
1346 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1347 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1348 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1349 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1350 int ThisAdjustment, unsigned Flags, bool IsOptimized, Metadata *Unit,
1351 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1352 StorageType Storage, bool ShouldCreate = true);
1354 TempDISubprogram cloneImpl() const {
1355 return getTemporary(
1356 getContext(), getScope(), getName(), getLinkageName(), getFile(),
1357 getLine(), getType(), isLocalToUnit(), isDefinition(), getScopeLine(),
1358 getContainingType(), getVirtuality(), getVirtualIndex(),
1359 getThisAdjustment(), getFlags(), isOptimized(), getUnit(),
1360 getTemplateParams(), getDeclaration(), getVariables());
1364 DEFINE_MDNODE_GET(DISubprogram,
1365 (DIScopeRef Scope, StringRef Name, StringRef LinkageName,
1366 DIFile *File, unsigned Line, DISubroutineType *Type,
1367 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1368 DITypeRef ContainingType, unsigned Virtuality,
1369 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
1370 bool IsOptimized, DICompileUnit *Unit,
1371 DITemplateParameterArray TemplateParams = nullptr,
1372 DISubprogram *Declaration = nullptr,
1373 DILocalVariableArray Variables = nullptr),
1374 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1375 IsDefinition, ScopeLine, ContainingType, Virtuality,
1376 VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
1377 TemplateParams, Declaration, Variables))
1380 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1381 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1382 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1383 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
1384 bool IsOptimized, Metadata *Unit, Metadata *TemplateParams = nullptr,
1385 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1386 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1387 ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment,
1388 Flags, IsOptimized, Unit, TemplateParams, Declaration, Variables))
1390 TempDISubprogram clone() const { return cloneImpl(); }
1393 unsigned getLine() const { return Line; }
1394 unsigned getVirtuality() const { return Virtuality; }
1395 unsigned getVirtualIndex() const { return VirtualIndex; }
1396 int getThisAdjustment() const { return ThisAdjustment; }
1397 unsigned getScopeLine() const { return ScopeLine; }
1398 unsigned getFlags() const { return Flags; }
1399 bool isLocalToUnit() const { return IsLocalToUnit; }
1400 bool isDefinition() const { return IsDefinition; }
1401 bool isOptimized() const { return IsOptimized; }
1403 unsigned isArtificial() const { return getFlags() & FlagArtificial; }
1404 bool isPrivate() const {
1405 return (getFlags() & FlagAccessibility) == FlagPrivate;
1407 bool isProtected() const {
1408 return (getFlags() & FlagAccessibility) == FlagProtected;
1410 bool isPublic() const {
1411 return (getFlags() & FlagAccessibility) == FlagPublic;
1413 bool isExplicit() const { return getFlags() & FlagExplicit; }
1414 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
1416 /// \brief Check if this is reference-qualified.
1418 /// Return true if this subprogram is a C++11 reference-qualified non-static
1419 /// member function (void foo() &).
1420 unsigned isLValueReference() const {
1421 return getFlags() & FlagLValueReference;
1424 /// \brief Check if this is rvalue-reference-qualified.
1426 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
1427 /// non-static member function (void foo() &&).
1428 unsigned isRValueReference() const {
1429 return getFlags() & FlagRValueReference;
1432 /// \brief Check if this is marked as noreturn.
1434 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
1435 unsigned isNoReturn() const {
1436 return getFlags() & FlagNoReturn;
1439 DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
1441 StringRef getName() const { return getStringOperand(2); }
1442 StringRef getDisplayName() const { return getStringOperand(3); }
1443 StringRef getLinkageName() const { return getStringOperand(4); }
1445 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1446 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1448 DISubroutineType *getType() const {
1449 return cast_or_null<DISubroutineType>(getRawType());
1451 DITypeRef getContainingType() const {
1452 return DITypeRef(getRawContainingType());
1455 DICompileUnit *getUnit() const {
1456 return cast_or_null<DICompileUnit>(getRawUnit());
1458 void replaceUnit(DICompileUnit *CU) {
1459 replaceOperandWith(7, CU);
1461 DITemplateParameterArray getTemplateParams() const {
1462 return cast_or_null<MDTuple>(getRawTemplateParams());
1464 DISubprogram *getDeclaration() const {
1465 return cast_or_null<DISubprogram>(getRawDeclaration());
1467 DILocalVariableArray getVariables() const {
1468 return cast_or_null<MDTuple>(getRawVariables());
1471 Metadata *getRawScope() const { return getOperand(1); }
1472 Metadata *getRawType() const { return getOperand(5); }
1473 Metadata *getRawContainingType() const { return getOperand(6); }
1474 Metadata *getRawUnit() const { return getOperand(7); }
1475 Metadata *getRawTemplateParams() const { return getOperand(8); }
1476 Metadata *getRawDeclaration() const { return getOperand(9); }
1477 Metadata *getRawVariables() const { return getOperand(10); }
1479 /// \brief Check if this subprogram describes the given function.
1481 /// FIXME: Should this be looking through bitcasts?
1482 bool describes(const Function *F) const;
1484 static bool classof(const Metadata *MD) {
1485 return MD->getMetadataID() == DISubprogramKind;
1489 class DILexicalBlockBase : public DILocalScope {
1491 DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1492 ArrayRef<Metadata *> Ops)
1493 : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1494 ~DILexicalBlockBase() = default;
1497 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
1499 Metadata *getRawScope() const { return getOperand(1); }
1501 static bool classof(const Metadata *MD) {
1502 return MD->getMetadataID() == DILexicalBlockKind ||
1503 MD->getMetadataID() == DILexicalBlockFileKind;
1507 class DILexicalBlock : public DILexicalBlockBase {
1508 friend class LLVMContextImpl;
1509 friend class MDNode;
1514 DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1515 unsigned Column, ArrayRef<Metadata *> Ops)
1516 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
1518 assert(Column < (1u << 16) && "Expected 16-bit column");
1520 ~DILexicalBlock() = default;
1522 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
1523 DIFile *File, unsigned Line, unsigned Column,
1524 StorageType Storage,
1525 bool ShouldCreate = true) {
1526 return getImpl(Context, static_cast<Metadata *>(Scope),
1527 static_cast<Metadata *>(File), Line, Column, Storage,
1531 static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1532 Metadata *File, unsigned Line, unsigned Column,
1533 StorageType Storage, bool ShouldCreate = true);
1535 TempDILexicalBlock cloneImpl() const {
1536 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1541 DEFINE_MDNODE_GET(DILexicalBlock, (DILocalScope * Scope, DIFile *File,
1542 unsigned Line, unsigned Column),
1543 (Scope, File, Line, Column))
1544 DEFINE_MDNODE_GET(DILexicalBlock, (Metadata * Scope, Metadata *File,
1545 unsigned Line, unsigned Column),
1546 (Scope, File, Line, Column))
1548 TempDILexicalBlock clone() const { return cloneImpl(); }
1550 unsigned getLine() const { return Line; }
1551 unsigned getColumn() const { return Column; }
1553 static bool classof(const Metadata *MD) {
1554 return MD->getMetadataID() == DILexicalBlockKind;
1558 class DILexicalBlockFile : public DILexicalBlockBase {
1559 friend class LLVMContextImpl;
1560 friend class MDNode;
1562 unsigned Discriminator;
1564 DILexicalBlockFile(LLVMContext &C, StorageType Storage,
1565 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1566 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops),
1567 Discriminator(Discriminator) {}
1568 ~DILexicalBlockFile() = default;
1570 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
1571 DIFile *File, unsigned Discriminator,
1572 StorageType Storage,
1573 bool ShouldCreate = true) {
1574 return getImpl(Context, static_cast<Metadata *>(Scope),
1575 static_cast<Metadata *>(File), Discriminator, Storage,
1579 static DILexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1580 Metadata *File, unsigned Discriminator,
1581 StorageType Storage,
1582 bool ShouldCreate = true);
1584 TempDILexicalBlockFile cloneImpl() const {
1585 return getTemporary(getContext(), getScope(), getFile(),
1586 getDiscriminator());
1590 DEFINE_MDNODE_GET(DILexicalBlockFile, (DILocalScope * Scope, DIFile *File,
1591 unsigned Discriminator),
1592 (Scope, File, Discriminator))
1593 DEFINE_MDNODE_GET(DILexicalBlockFile,
1594 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1595 (Scope, File, Discriminator))
1597 TempDILexicalBlockFile clone() const { return cloneImpl(); }
1599 // TODO: Remove these once they're gone from DILexicalBlockBase.
1600 unsigned getLine() const = delete;
1601 unsigned getColumn() const = delete;
1603 unsigned getDiscriminator() const { return Discriminator; }
1605 static bool classof(const Metadata *MD) {
1606 return MD->getMetadataID() == DILexicalBlockFileKind;
1610 unsigned DILocation::getDiscriminator() const {
1611 if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
1612 return F->getDiscriminator();
1616 class DINamespace : public DIScope {
1617 friend class LLVMContextImpl;
1618 friend class MDNode;
1622 DINamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1623 ArrayRef<Metadata *> Ops)
1624 : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace,
1627 ~DINamespace() = default;
1629 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
1630 DIFile *File, StringRef Name, unsigned Line,
1631 StorageType Storage, bool ShouldCreate = true) {
1632 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1633 Line, Storage, ShouldCreate);
1635 static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1636 Metadata *File, MDString *Name, unsigned Line,
1637 StorageType Storage, bool ShouldCreate = true);
1639 TempDINamespace cloneImpl() const {
1640 return getTemporary(getContext(), getScope(), getFile(), getName(),
1645 DEFINE_MDNODE_GET(DINamespace, (DIScope * Scope, DIFile *File, StringRef Name,
1647 (Scope, File, Name, Line))
1648 DEFINE_MDNODE_GET(DINamespace, (Metadata * Scope, Metadata *File,
1649 MDString *Name, unsigned Line),
1650 (Scope, File, Name, Line))
1652 TempDINamespace clone() const { return cloneImpl(); }
1654 unsigned getLine() const { return Line; }
1655 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
1656 StringRef getName() const { return getStringOperand(2); }
1658 Metadata *getRawScope() const { return getOperand(1); }
1659 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1661 static bool classof(const Metadata *MD) {
1662 return MD->getMetadataID() == DINamespaceKind;
1666 /// \brief A (clang) module that has been imported by the compile unit.
1668 class DIModule : public DIScope {
1669 friend class LLVMContextImpl;
1670 friend class MDNode;
1672 DIModule(LLVMContext &Context, StorageType Storage, ArrayRef<Metadata *> Ops)
1673 : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
1676 static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
1677 StringRef Name, StringRef ConfigurationMacros,
1678 StringRef IncludePath, StringRef ISysRoot,
1679 StorageType Storage, bool ShouldCreate = true) {
1680 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1681 getCanonicalMDString(Context, ConfigurationMacros),
1682 getCanonicalMDString(Context, IncludePath),
1683 getCanonicalMDString(Context, ISysRoot),
1684 Storage, ShouldCreate);
1686 static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
1687 MDString *Name, MDString *ConfigurationMacros,
1688 MDString *IncludePath, MDString *ISysRoot,
1689 StorageType Storage, bool ShouldCreate = true);
1691 TempDIModule cloneImpl() const {
1692 return getTemporary(getContext(), getScope(), getName(),
1693 getConfigurationMacros(), getIncludePath(),
1698 DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name,
1699 StringRef ConfigurationMacros, StringRef IncludePath,
1700 StringRef ISysRoot),
1701 (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
1702 DEFINE_MDNODE_GET(DIModule,
1703 (Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
1704 MDString *IncludePath, MDString *ISysRoot),
1705 (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
1707 TempDIModule clone() const { return cloneImpl(); }
1709 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
1710 StringRef getName() const { return getStringOperand(1); }
1711 StringRef getConfigurationMacros() const { return getStringOperand(2); }
1712 StringRef getIncludePath() const { return getStringOperand(3); }
1713 StringRef getISysRoot() const { return getStringOperand(4); }
1715 Metadata *getRawScope() const { return getOperand(0); }
1716 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1717 MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
1718 MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
1719 MDString *getRawISysRoot() const { return getOperandAs<MDString>(4); }
1721 static bool classof(const Metadata *MD) {
1722 return MD->getMetadataID() == DIModuleKind;
1726 /// \brief Base class for template parameters.
1727 class DITemplateParameter : public DINode {
1729 DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1730 unsigned Tag, ArrayRef<Metadata *> Ops)
1731 : DINode(Context, ID, Storage, Tag, Ops) {}
1732 ~DITemplateParameter() = default;
1735 StringRef getName() const { return getStringOperand(0); }
1736 DITypeRef getType() const { return DITypeRef(getRawType()); }
1738 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1739 Metadata *getRawType() const { return getOperand(1); }
1741 static bool classof(const Metadata *MD) {
1742 return MD->getMetadataID() == DITemplateTypeParameterKind ||
1743 MD->getMetadataID() == DITemplateValueParameterKind;
1747 class DITemplateTypeParameter : public DITemplateParameter {
1748 friend class LLVMContextImpl;
1749 friend class MDNode;
1751 DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1752 ArrayRef<Metadata *> Ops)
1753 : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
1754 dwarf::DW_TAG_template_type_parameter, Ops) {}
1755 ~DITemplateTypeParameter() = default;
1757 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1758 DITypeRef Type, StorageType Storage,
1759 bool ShouldCreate = true) {
1760 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1763 static DITemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1764 Metadata *Type, StorageType Storage,
1765 bool ShouldCreate = true);
1767 TempDITemplateTypeParameter cloneImpl() const {
1768 return getTemporary(getContext(), getName(), getType());
1772 DEFINE_MDNODE_GET(DITemplateTypeParameter, (StringRef Name, DITypeRef Type),
1774 DEFINE_MDNODE_GET(DITemplateTypeParameter, (MDString * Name, Metadata *Type),
1777 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
1779 static bool classof(const Metadata *MD) {
1780 return MD->getMetadataID() == DITemplateTypeParameterKind;
1784 class DITemplateValueParameter : public DITemplateParameter {
1785 friend class LLVMContextImpl;
1786 friend class MDNode;
1788 DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
1789 unsigned Tag, ArrayRef<Metadata *> Ops)
1790 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
1792 ~DITemplateValueParameter() = default;
1794 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1795 StringRef Name, DITypeRef Type,
1796 Metadata *Value, StorageType Storage,
1797 bool ShouldCreate = true) {
1798 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1799 Value, Storage, ShouldCreate);
1801 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1802 MDString *Name, Metadata *Type,
1803 Metadata *Value, StorageType Storage,
1804 bool ShouldCreate = true);
1806 TempDITemplateValueParameter cloneImpl() const {
1807 return getTemporary(getContext(), getTag(), getName(), getType(),
1812 DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, StringRef Name,
1813 DITypeRef Type, Metadata *Value),
1814 (Tag, Name, Type, Value))
1815 DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, MDString *Name,
1816 Metadata *Type, Metadata *Value),
1817 (Tag, Name, Type, Value))
1819 TempDITemplateValueParameter clone() const { return cloneImpl(); }
1821 Metadata *getValue() const { return getOperand(2); }
1823 static bool classof(const Metadata *MD) {
1824 return MD->getMetadataID() == DITemplateValueParameterKind;
1828 /// \brief Base class for variables.
1829 class DIVariable : public DINode {
1833 DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line,
1834 ArrayRef<Metadata *> Ops)
1835 : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line) {}
1836 ~DIVariable() = default;
1839 unsigned getLine() const { return Line; }
1840 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
1841 StringRef getName() const { return getStringOperand(1); }
1842 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
1843 DITypeRef getType() const { return DITypeRef(getRawType()); }
1845 StringRef getFilename() const {
1846 if (auto *F = getFile())
1847 return F->getFilename();
1850 StringRef getDirectory() const {
1851 if (auto *F = getFile())
1852 return F->getDirectory();
1856 Metadata *getRawScope() const { return getOperand(0); }
1857 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1858 Metadata *getRawFile() const { return getOperand(2); }
1859 Metadata *getRawType() const { return getOperand(3); }
1861 static bool classof(const Metadata *MD) {
1862 return MD->getMetadataID() == DILocalVariableKind ||
1863 MD->getMetadataID() == DIGlobalVariableKind;
1867 /// \brief Global variables.
1869 /// TODO: Remove DisplayName. It's always equal to Name.
1870 class DIGlobalVariable : public DIVariable {
1871 friend class LLVMContextImpl;
1872 friend class MDNode;
1877 DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1878 bool IsLocalToUnit, bool IsDefinition,
1879 ArrayRef<Metadata *> Ops)
1880 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops),
1881 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1882 ~DIGlobalVariable() = default;
1884 static DIGlobalVariable *
1885 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
1886 StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type,
1887 bool IsLocalToUnit, bool IsDefinition, Constant *Variable,
1888 DIDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1889 bool ShouldCreate = true) {
1890 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1891 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1892 IsLocalToUnit, IsDefinition,
1893 Variable ? ConstantAsMetadata::get(Variable) : nullptr,
1894 StaticDataMemberDeclaration, Storage, ShouldCreate);
1896 static DIGlobalVariable *
1897 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1898 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1899 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1900 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1901 bool ShouldCreate = true);
1903 TempDIGlobalVariable cloneImpl() const {
1904 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1905 getFile(), getLine(), getType(), isLocalToUnit(),
1906 isDefinition(), getVariable(),
1907 getStaticDataMemberDeclaration());
1911 DEFINE_MDNODE_GET(DIGlobalVariable,
1912 (DIScope * Scope, StringRef Name, StringRef LinkageName,
1913 DIFile *File, unsigned Line, DITypeRef Type,
1914 bool IsLocalToUnit, bool IsDefinition, Constant *Variable,
1915 DIDerivedType *StaticDataMemberDeclaration),
1916 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1917 IsDefinition, Variable, StaticDataMemberDeclaration))
1918 DEFINE_MDNODE_GET(DIGlobalVariable,
1919 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1920 Metadata *File, unsigned Line, Metadata *Type,
1921 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1922 Metadata *StaticDataMemberDeclaration),
1923 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1924 IsDefinition, Variable, StaticDataMemberDeclaration))
1926 TempDIGlobalVariable clone() const { return cloneImpl(); }
1928 bool isLocalToUnit() const { return IsLocalToUnit; }
1929 bool isDefinition() const { return IsDefinition; }
1930 StringRef getDisplayName() const { return getStringOperand(4); }
1931 StringRef getLinkageName() const { return getStringOperand(5); }
1932 Constant *getVariable() const {
1933 if (auto *C = cast_or_null<ConstantAsMetadata>(getRawVariable()))
1934 return dyn_cast<Constant>(C->getValue());
1937 DIDerivedType *getStaticDataMemberDeclaration() const {
1938 return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration());
1941 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1942 Metadata *getRawVariable() const { return getOperand(6); }
1943 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1945 static bool classof(const Metadata *MD) {
1946 return MD->getMetadataID() == DIGlobalVariableKind;
1950 /// \brief Local variable.
1952 /// TODO: Split up flags.
1953 class DILocalVariable : public DIVariable {
1954 friend class LLVMContextImpl;
1955 friend class MDNode;
1958 unsigned Flags : 16;
1960 DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1961 unsigned Arg, unsigned Flags, ArrayRef<Metadata *> Ops)
1962 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops), Arg(Arg),
1964 assert(Flags < (1 << 16) && "DILocalVariable: Flags out of range");
1965 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
1967 ~DILocalVariable() = default;
1969 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
1970 StringRef Name, DIFile *File, unsigned Line,
1971 DITypeRef Type, unsigned Arg, unsigned Flags,
1972 StorageType Storage,
1973 bool ShouldCreate = true) {
1974 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
1975 Line, Type, Arg, Flags, Storage, ShouldCreate);
1977 static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope,
1978 MDString *Name, Metadata *File, unsigned Line,
1979 Metadata *Type, unsigned Arg, unsigned Flags,
1980 StorageType Storage,
1981 bool ShouldCreate = true);
1983 TempDILocalVariable cloneImpl() const {
1984 return getTemporary(getContext(), getScope(), getName(), getFile(),
1985 getLine(), getType(), getArg(), getFlags());
1989 DEFINE_MDNODE_GET(DILocalVariable,
1990 (DILocalScope * Scope, StringRef Name, DIFile *File,
1991 unsigned Line, DITypeRef Type, unsigned Arg,
1993 (Scope, Name, File, Line, Type, Arg, Flags))
1994 DEFINE_MDNODE_GET(DILocalVariable,
1995 (Metadata * Scope, MDString *Name, Metadata *File,
1996 unsigned Line, Metadata *Type, unsigned Arg,
1998 (Scope, Name, File, Line, Type, Arg, Flags))
2000 TempDILocalVariable clone() const { return cloneImpl(); }
2002 /// \brief Get the local scope for this variable.
2004 /// Variables must be defined in a local scope.
2005 DILocalScope *getScope() const {
2006 return cast<DILocalScope>(DIVariable::getScope());
2009 bool isParameter() const { return Arg; }
2010 unsigned getArg() const { return Arg; }
2011 unsigned getFlags() const { return Flags; }
2013 bool isArtificial() const { return getFlags() & FlagArtificial; }
2014 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
2016 /// \brief Check that a location is valid for this variable.
2018 /// Check that \c DL exists, is in the same subprogram, and has the same
2019 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
2020 /// to a \a DbgInfoIntrinsic.)
2021 bool isValidLocationForIntrinsic(const DILocation *DL) const {
2022 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
2025 static bool classof(const Metadata *MD) {
2026 return MD->getMetadataID() == DILocalVariableKind;
2030 /// \brief DWARF expression.
2032 /// This is (almost) a DWARF expression that modifies the location of a
2033 /// variable or (or the location of a single piece of a variable).
2035 /// FIXME: Instead of DW_OP_plus taking an argument, this should use DW_OP_const
2036 /// and have DW_OP_plus consume the topmost elements on the stack.
2038 /// TODO: Co-allocate the expression elements.
2039 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
2041 class DIExpression : public MDNode {
2042 friend class LLVMContextImpl;
2043 friend class MDNode;
2045 std::vector<uint64_t> Elements;
2047 DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
2048 : MDNode(C, DIExpressionKind, Storage, None),
2049 Elements(Elements.begin(), Elements.end()) {}
2050 ~DIExpression() = default;
2052 static DIExpression *getImpl(LLVMContext &Context,
2053 ArrayRef<uint64_t> Elements, StorageType Storage,
2054 bool ShouldCreate = true);
2056 TempDIExpression cloneImpl() const {
2057 return getTemporary(getContext(), getElements());
2061 DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
2063 TempDIExpression clone() const { return cloneImpl(); }
2065 ArrayRef<uint64_t> getElements() const { return Elements; }
2067 unsigned getNumElements() const { return Elements.size(); }
2068 uint64_t getElement(unsigned I) const {
2069 assert(I < Elements.size() && "Index out of range");
2073 /// \brief Return whether this is a piece of an aggregate variable.
2074 bool isBitPiece() const;
2076 /// \brief Return the offset of this piece in bits.
2077 uint64_t getBitPieceOffset() const;
2079 /// \brief Return the size of this piece in bits.
2080 uint64_t getBitPieceSize() const;
2082 typedef ArrayRef<uint64_t>::iterator element_iterator;
2083 element_iterator elements_begin() const { return getElements().begin(); }
2084 element_iterator elements_end() const { return getElements().end(); }
2086 /// \brief A lightweight wrapper around an expression operand.
2088 /// TODO: Store arguments directly and change \a DIExpression to store a
2094 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
2096 const uint64_t *get() const { return Op; }
2098 /// \brief Get the operand code.
2099 uint64_t getOp() const { return *Op; }
2101 /// \brief Get an argument to the operand.
2103 /// Never returns the operand itself.
2104 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
2106 unsigned getNumArgs() const { return getSize() - 1; }
2108 /// \brief Return the size of the operand.
2110 /// Return the number of elements in the operand (1 + args).
2111 unsigned getSize() const;
2114 /// \brief An iterator for expression operands.
2115 class expr_op_iterator
2116 : public std::iterator<std::input_iterator_tag, ExprOperand> {
2120 explicit expr_op_iterator(element_iterator I) : Op(I) {}
2122 element_iterator getBase() const { return Op.get(); }
2123 const ExprOperand &operator*() const { return Op; }
2124 const ExprOperand *operator->() const { return &Op; }
2126 expr_op_iterator &operator++() {
2130 expr_op_iterator operator++(int) {
2131 expr_op_iterator T(*this);
2136 /// \brief Get the next iterator.
2138 /// \a std::next() doesn't work because this is technically an
2139 /// input_iterator, but it's a perfectly valid operation. This is an
2140 /// accessor to provide the same functionality.
2141 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
2143 bool operator==(const expr_op_iterator &X) const {
2144 return getBase() == X.getBase();
2146 bool operator!=(const expr_op_iterator &X) const {
2147 return getBase() != X.getBase();
2151 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
2154 /// \brief Visit the elements via ExprOperand wrappers.
2156 /// These range iterators visit elements through \a ExprOperand wrappers.
2157 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
2160 /// \pre \a isValid() gives \c true.
2162 expr_op_iterator expr_op_begin() const {
2163 return expr_op_iterator(elements_begin());
2165 expr_op_iterator expr_op_end() const {
2166 return expr_op_iterator(elements_end());
2170 bool isValid() const;
2172 static bool classof(const Metadata *MD) {
2173 return MD->getMetadataID() == DIExpressionKind;
2176 /// \brief Is the first element a DW_OP_deref?.
2177 bool startsWithDeref() const {
2178 return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
2182 class DIObjCProperty : public DINode {
2183 friend class LLVMContextImpl;
2184 friend class MDNode;
2187 unsigned Attributes;
2189 DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
2190 unsigned Attributes, ArrayRef<Metadata *> Ops)
2191 : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
2193 Line(Line), Attributes(Attributes) {}
2194 ~DIObjCProperty() = default;
2196 static DIObjCProperty *
2197 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
2198 StringRef GetterName, StringRef SetterName, unsigned Attributes,
2199 DITypeRef Type, StorageType Storage, bool ShouldCreate = true) {
2200 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
2201 getCanonicalMDString(Context, GetterName),
2202 getCanonicalMDString(Context, SetterName), Attributes, Type,
2203 Storage, ShouldCreate);
2205 static DIObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
2206 Metadata *File, unsigned Line,
2207 MDString *GetterName, MDString *SetterName,
2208 unsigned Attributes, Metadata *Type,
2209 StorageType Storage, bool ShouldCreate = true);
2211 TempDIObjCProperty cloneImpl() const {
2212 return getTemporary(getContext(), getName(), getFile(), getLine(),
2213 getGetterName(), getSetterName(), getAttributes(),
2218 DEFINE_MDNODE_GET(DIObjCProperty,
2219 (StringRef Name, DIFile *File, unsigned Line,
2220 StringRef GetterName, StringRef SetterName,
2221 unsigned Attributes, DITypeRef Type),
2222 (Name, File, Line, GetterName, SetterName, Attributes,
2224 DEFINE_MDNODE_GET(DIObjCProperty,
2225 (MDString * Name, Metadata *File, unsigned Line,
2226 MDString *GetterName, MDString *SetterName,
2227 unsigned Attributes, Metadata *Type),
2228 (Name, File, Line, GetterName, SetterName, Attributes,
2231 TempDIObjCProperty clone() const { return cloneImpl(); }
2233 unsigned getLine() const { return Line; }
2234 unsigned getAttributes() const { return Attributes; }
2235 StringRef getName() const { return getStringOperand(0); }
2236 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2237 StringRef getGetterName() const { return getStringOperand(2); }
2238 StringRef getSetterName() const { return getStringOperand(3); }
2239 DITypeRef getType() const { return DITypeRef(getRawType()); }
2241 StringRef getFilename() const {
2242 if (auto *F = getFile())
2243 return F->getFilename();
2246 StringRef getDirectory() const {
2247 if (auto *F = getFile())
2248 return F->getDirectory();
2252 MDString *getRawName() const { return getOperandAs<MDString>(0); }
2253 Metadata *getRawFile() const { return getOperand(1); }
2254 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
2255 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
2256 Metadata *getRawType() const { return getOperand(4); }
2258 static bool classof(const Metadata *MD) {
2259 return MD->getMetadataID() == DIObjCPropertyKind;
2263 /// \brief An imported module (C++ using directive or similar).
2264 class DIImportedEntity : public DINode {
2265 friend class LLVMContextImpl;
2266 friend class MDNode;
2270 DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
2271 unsigned Line, ArrayRef<Metadata *> Ops)
2272 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
2273 ~DIImportedEntity() = default;
2275 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2276 DIScope *Scope, DINodeRef Entity,
2277 unsigned Line, StringRef Name,
2278 StorageType Storage,
2279 bool ShouldCreate = true) {
2280 return getImpl(Context, Tag, Scope, Entity, Line,
2281 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
2283 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2284 Metadata *Scope, Metadata *Entity,
2285 unsigned Line, MDString *Name,
2286 StorageType Storage,
2287 bool ShouldCreate = true);
2289 TempDIImportedEntity cloneImpl() const {
2290 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
2291 getLine(), getName());
2295 DEFINE_MDNODE_GET(DIImportedEntity,
2296 (unsigned Tag, DIScope *Scope, DINodeRef Entity,
2297 unsigned Line, StringRef Name = ""),
2298 (Tag, Scope, Entity, Line, Name))
2299 DEFINE_MDNODE_GET(DIImportedEntity,
2300 (unsigned Tag, Metadata *Scope, Metadata *Entity,
2301 unsigned Line, MDString *Name),
2302 (Tag, Scope, Entity, Line, Name))
2304 TempDIImportedEntity clone() const { return cloneImpl(); }
2306 unsigned getLine() const { return Line; }
2307 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2308 DINodeRef getEntity() const { return DINodeRef(getRawEntity()); }
2309 StringRef getName() const { return getStringOperand(2); }
2311 Metadata *getRawScope() const { return getOperand(0); }
2312 Metadata *getRawEntity() const { return getOperand(1); }
2313 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2315 static bool classof(const Metadata *MD) {
2316 return MD->getMetadataID() == DIImportedEntityKind;
2320 /// \brief Macro Info DWARF-like metadata node.
2322 /// A metadata node with a DWARF macro info (i.e., a constant named
2323 /// \c DW_MACINFO_*, defined in llvm/Support/Dwarf.h). Called \a DIMacroNode
2324 /// because it's potentially used for non-DWARF output.
2325 class DIMacroNode : public MDNode {
2326 friend class LLVMContextImpl;
2327 friend class MDNode;
2330 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
2331 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
2332 : MDNode(C, ID, Storage, Ops1, Ops2) {
2333 assert(MIType < 1u << 16);
2334 SubclassData16 = MIType;
2336 ~DIMacroNode() = default;
2338 template <class Ty> Ty *getOperandAs(unsigned I) const {
2339 return cast_or_null<Ty>(getOperand(I));
2342 StringRef getStringOperand(unsigned I) const {
2343 if (auto *S = getOperandAs<MDString>(I))
2344 return S->getString();
2348 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
2351 return MDString::get(Context, S);
2355 unsigned getMacinfoType() const { return SubclassData16; }
2357 static bool classof(const Metadata *MD) {
2358 switch (MD->getMetadataID()) {
2362 case DIMacroFileKind:
2368 class DIMacro : public DIMacroNode {
2369 friend class LLVMContextImpl;
2370 friend class MDNode;
2374 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
2375 ArrayRef<Metadata *> Ops)
2376 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops), Line(Line) {}
2377 ~DIMacro() = default;
2379 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
2380 StringRef Name, StringRef Value, StorageType Storage,
2381 bool ShouldCreate = true) {
2382 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
2383 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
2385 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
2386 MDString *Name, MDString *Value, StorageType Storage,
2387 bool ShouldCreate = true);
2389 TempDIMacro cloneImpl() const {
2390 return getTemporary(getContext(), getMacinfoType(), getLine(), getName(),
2395 DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, StringRef Name,
2396 StringRef Value = ""),
2397 (MIType, Line, Name, Value))
2398 DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, MDString *Name,
2400 (MIType, Line, Name, Value))
2402 TempDIMacro clone() const { return cloneImpl(); }
2404 unsigned getLine() const { return Line; }
2406 StringRef getName() const { return getStringOperand(0); }
2407 StringRef getValue() const { return getStringOperand(1); }
2409 MDString *getRawName() const { return getOperandAs<MDString>(0); }
2410 MDString *getRawValue() const { return getOperandAs<MDString>(1); }
2412 static bool classof(const Metadata *MD) {
2413 return MD->getMetadataID() == DIMacroKind;
2417 class DIMacroFile : public DIMacroNode {
2418 friend class LLVMContextImpl;
2419 friend class MDNode;
2423 DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
2424 unsigned Line, ArrayRef<Metadata *> Ops)
2425 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops), Line(Line) {}
2426 ~DIMacroFile() = default;
2428 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
2429 unsigned Line, DIFile *File,
2430 DIMacroNodeArray Elements, StorageType Storage,
2431 bool ShouldCreate = true) {
2432 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
2433 Elements.get(), Storage, ShouldCreate);
2436 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
2437 unsigned Line, Metadata *File, Metadata *Elements,
2438 StorageType Storage, bool ShouldCreate = true);
2440 TempDIMacroFile cloneImpl() const {
2441 return getTemporary(getContext(), getMacinfoType(), getLine(), getFile(),
2446 DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line, DIFile *File,
2447 DIMacroNodeArray Elements),
2448 (MIType, Line, File, Elements))
2449 DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line,
2450 Metadata *File, Metadata *Elements),
2451 (MIType, Line, File, Elements))
2453 TempDIMacroFile clone() const { return cloneImpl(); }
2455 void replaceElements(DIMacroNodeArray Elements) {
2457 for (DIMacroNode *Op : getElements())
2458 assert(is_contained(Elements->operands(), Op) &&
2459 "Lost a macro node during macro node list replacement");
2461 replaceOperandWith(1, Elements.get());
2464 unsigned getLine() const { return Line; }
2465 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2467 DIMacroNodeArray getElements() const {
2468 return cast_or_null<MDTuple>(getRawElements());
2471 Metadata *getRawFile() const { return getOperand(0); }
2472 Metadata *getRawElements() const { return getOperand(1); }
2474 static bool classof(const Metadata *MD) {
2475 return MD->getMetadataID() == DIMacroFileKind;
2479 } // end namespace llvm
2481 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
2482 #undef DEFINE_MDNODE_GET_UNPACK
2483 #undef DEFINE_MDNODE_GET