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(CLASS, FORMAL, ARGS) \
24 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
25 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
27 static CLASS *getIfExists(LLVMContext &Context, \
28 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
29 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
30 /* ShouldCreate */ false); \
32 static CLASS *getDistinct(LLVMContext &Context, \
33 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
34 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
36 static Temp##CLASS getTemporary(LLVMContext &Context, \
37 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
39 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
44 /// \brief Pointer union between a subclass of DebugNode and MDString.
46 /// \a MDCompositeType can be referenced via an \a MDString unique identifier.
47 /// This class allows some type safety in the face of that, requiring either a
48 /// node of a particular type or an \a MDString.
49 template <class T> class TypedDebugNodeRef {
50 const Metadata *MD = nullptr;
53 TypedDebugNodeRef(std::nullptr_t) {}
55 /// \brief Construct from a raw pointer.
56 explicit TypedDebugNodeRef(const Metadata *MD) : MD(MD) {
57 assert((!MD || isa<MDString>(MD) || isa<T>(MD)) && "Expected valid ref");
62 const TypedDebugNodeRef<U> &X,
63 typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
67 operator Metadata *() const { return const_cast<Metadata *>(MD); }
69 bool operator==(const TypedDebugNodeRef<T> &X) const { return MD == X.MD; };
70 bool operator!=(const TypedDebugNodeRef<T> &X) const { return MD != X.MD; };
72 /// \brief Create a reference.
74 /// Get a reference to \c N, using an \a MDString reference if available.
75 static TypedDebugNodeRef get(const T *N);
77 template <class MapTy> T *resolve(const MapTy &Map) const {
81 if (auto *Typed = dyn_cast<T>(MD))
82 return const_cast<T *>(Typed);
84 auto *S = cast<MDString>(MD);
86 assert(I != Map.end() && "Missing identifier in type map");
87 return cast<T>(I->second);
91 typedef TypedDebugNodeRef<DebugNode> DebugNodeRef;
92 typedef TypedDebugNodeRef<MDScope> MDScopeRef;
93 typedef TypedDebugNodeRef<MDType> MDTypeRef;
95 class MDTypeRefArray {
96 const MDTuple *N = nullptr;
99 MDTypeRefArray(const MDTuple *N) : N(N) {}
100 operator MDTuple *() const { return const_cast<MDTuple *>(N); }
101 MDTuple *operator->() const { return const_cast<MDTuple *>(N); }
102 MDTuple &operator*() const { return *const_cast<MDTuple *>(N); }
104 unsigned size() const { return N->getNumOperands(); }
105 MDTypeRef operator[](unsigned I) const { return MDTypeRef(N->getOperand(I)); }
107 class iterator : std::iterator<std::input_iterator_tag, MDTypeRef,
108 std::ptrdiff_t, void, MDTypeRef> {
109 MDNode::op_iterator I;
112 explicit iterator(MDNode::op_iterator I) : I(I) {}
113 MDTypeRef operator*() const { return MDTypeRef(*I); }
114 iterator &operator++() {
118 iterator operator++(int) {
119 iterator Temp(*this);
123 bool operator==(const iterator &X) const { return I == X.I; }
124 bool operator!=(const iterator &X) const { return I != X.I; }
127 iterator begin() const { return iterator(N->op_begin()); }
128 iterator end() const { return iterator(N->op_end()); }
131 /// \brief Tagged DWARF-like metadata node.
133 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
134 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
135 /// potentially used for non-DWARF output.
136 class DebugNode : public MDNode {
137 friend class LLVMContextImpl;
141 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
142 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
143 : MDNode(C, ID, Storage, Ops1, Ops2) {
144 assert(Tag < 1u << 16);
145 SubclassData16 = Tag;
149 template <class Ty> Ty *getOperandAs(unsigned I) const {
150 return cast_or_null<Ty>(getOperand(I));
153 StringRef getStringOperand(unsigned I) const {
154 if (auto *S = getOperandAs<MDString>(I))
155 return S->getString();
159 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
162 return MDString::get(Context, S);
166 unsigned getTag() const { return SubclassData16; }
168 /// \brief Debug info flags.
170 /// The three accessibility flags are mutually exclusive and rolled together
171 /// in the first two bits.
173 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
174 #include "llvm/IR/DebugInfoFlags.def"
175 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
178 static unsigned getFlag(StringRef Flag);
179 static const char *getFlagString(unsigned Flag);
181 /// \brief Split up a flags bitfield.
183 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
184 /// any remaining (unrecognized) bits.
185 static unsigned splitFlags(unsigned Flags,
186 SmallVectorImpl<unsigned> &SplitFlags);
188 DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
190 static bool classof(const Metadata *MD) {
191 switch (MD->getMetadataID()) {
194 case GenericDebugNodeKind:
196 case MDEnumeratorKind:
197 case MDBasicTypeKind:
198 case MDDerivedTypeKind:
199 case MDCompositeTypeKind:
200 case MDSubroutineTypeKind:
202 case MDCompileUnitKind:
203 case MDSubprogramKind:
204 case MDLexicalBlockKind:
205 case MDLexicalBlockFileKind:
206 case MDNamespaceKind:
207 case MDTemplateTypeParameterKind:
208 case MDTemplateValueParameterKind:
209 case MDGlobalVariableKind:
210 case MDLocalVariableKind:
211 case MDObjCPropertyKind:
212 case MDImportedEntityKind:
219 struct simplify_type<const TypedDebugNodeRef<T>> {
220 typedef Metadata *SimpleType;
221 static SimpleType getSimplifiedValue(const TypedDebugNodeRef<T> &MD) {
227 struct simplify_type<TypedDebugNodeRef<T>>
228 : simplify_type<const TypedDebugNodeRef<T>> {};
230 /// \brief Generic tagged DWARF-like metadata node.
232 /// An un-specialized DWARF-like metadata node. The first operand is a
233 /// (possibly empty) null-separated \a MDString header that contains arbitrary
234 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
235 /// to other metadata.
236 class GenericDebugNode : public DebugNode {
237 friend class LLVMContextImpl;
240 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
241 unsigned Tag, ArrayRef<Metadata *> Ops1,
242 ArrayRef<Metadata *> Ops2)
243 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
246 ~GenericDebugNode() { dropAllReferences(); }
248 void setHash(unsigned Hash) { SubclassData32 = Hash; }
249 void recalculateHash();
251 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
253 ArrayRef<Metadata *> DwarfOps,
255 bool ShouldCreate = true) {
256 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
257 DwarfOps, Storage, ShouldCreate);
260 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
262 ArrayRef<Metadata *> DwarfOps,
264 bool ShouldCreate = true);
266 TempGenericDebugNode cloneImpl() const {
268 getContext(), getTag(), getHeader(),
269 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
273 unsigned getHash() const { return SubclassData32; }
275 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
276 ArrayRef<Metadata *> DwarfOps),
277 (Tag, Header, DwarfOps))
278 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
279 ArrayRef<Metadata *> DwarfOps),
280 (Tag, Header, DwarfOps))
282 /// \brief Return a (temporary) clone of this.
283 TempGenericDebugNode clone() const { return cloneImpl(); }
285 unsigned getTag() const { return SubclassData16; }
286 StringRef getHeader() const { return getStringOperand(0); }
288 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
289 op_iterator dwarf_op_end() const { return op_end(); }
290 op_range dwarf_operands() const {
291 return op_range(dwarf_op_begin(), dwarf_op_end());
294 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
295 const MDOperand &getDwarfOperand(unsigned I) const {
296 return getOperand(I + 1);
298 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
299 replaceOperandWith(I + 1, New);
302 static bool classof(const Metadata *MD) {
303 return MD->getMetadataID() == GenericDebugNodeKind;
307 /// \brief Array subrange.
309 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
311 class MDSubrange : public DebugNode {
312 friend class LLVMContextImpl;
318 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count,
320 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
322 Count(Count), LowerBound(LowerBound) {}
325 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count,
326 int64_t LowerBound, StorageType Storage,
327 bool ShouldCreate = true);
329 TempMDSubrange cloneImpl() const {
330 return getTemporary(getContext(), getCount(), getLowerBound());
334 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t LowerBound = 0),
337 TempMDSubrange clone() const { return cloneImpl(); }
339 int64_t getLowerBound() const { return LowerBound; }
340 int64_t getCount() const { return Count; }
342 static bool classof(const Metadata *MD) {
343 return MD->getMetadataID() == MDSubrangeKind;
347 /// \brief Enumeration value.
349 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
350 /// longer creates a type cycle.
351 class MDEnumerator : public DebugNode {
352 friend class LLVMContextImpl;
357 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
358 ArrayRef<Metadata *> Ops)
359 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
363 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
364 StringRef Name, StorageType Storage,
365 bool ShouldCreate = true) {
366 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
369 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
370 MDString *Name, StorageType Storage,
371 bool ShouldCreate = true);
373 TempMDEnumerator cloneImpl() const {
374 return getTemporary(getContext(), getValue(), getName());
378 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
380 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
383 TempMDEnumerator clone() const { return cloneImpl(); }
385 int64_t getValue() const { return Value; }
386 StringRef getName() const { return getStringOperand(0); }
388 MDString *getRawName() const { return getOperandAs<MDString>(0); }
390 static bool classof(const Metadata *MD) {
391 return MD->getMetadataID() == MDEnumeratorKind;
395 /// \brief Base class for scope-like contexts.
397 /// Base class for lexical scopes and types (which are also declaration
400 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
401 class MDScope : public DebugNode {
403 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
404 ArrayRef<Metadata *> Ops)
405 : DebugNode(C, ID, Storage, Tag, Ops) {}
409 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
411 /// \brief Return the raw underlying file.
413 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
414 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
415 /// this. Otherwise, return the first operand, which is where all other
416 /// subclasses store their file pointer.
417 Metadata *getRawFile() const {
418 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
419 : static_cast<Metadata *>(getOperand(0));
422 MDScopeRef getRef() const { return MDScopeRef::get(this); }
424 static bool classof(const Metadata *MD) {
425 switch (MD->getMetadataID()) {
428 case MDBasicTypeKind:
429 case MDDerivedTypeKind:
430 case MDCompositeTypeKind:
431 case MDSubroutineTypeKind:
433 case MDCompileUnitKind:
434 case MDSubprogramKind:
435 case MDLexicalBlockKind:
436 case MDLexicalBlockFileKind:
437 case MDNamespaceKind:
445 /// TODO: Merge with directory/file node (including users).
446 /// TODO: Canonicalize paths on creation.
447 class MDFile : public MDScope {
448 friend class LLVMContextImpl;
451 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
452 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
455 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
456 StringRef Directory, StorageType Storage,
457 bool ShouldCreate = true) {
458 return getImpl(Context, getCanonicalMDString(Context, Filename),
459 getCanonicalMDString(Context, Directory), Storage,
462 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
463 MDString *Directory, StorageType Storage,
464 bool ShouldCreate = true);
466 TempMDFile cloneImpl() const {
467 return getTemporary(getContext(), getFilename(), getDirectory());
471 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
472 (Filename, Directory))
473 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
474 (Filename, Directory))
476 TempMDFile clone() const { return cloneImpl(); }
478 StringRef getFilename() const { return getStringOperand(0); }
479 StringRef getDirectory() const { return getStringOperand(1); }
481 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
482 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
484 static bool classof(const Metadata *MD) {
485 return MD->getMetadataID() == MDFileKind;
489 /// \brief Base class for types.
491 /// TODO: Remove the hardcoded name and context, since many types don't use
493 /// TODO: Split up flags.
494 class MDType : public MDScope {
498 uint64_t AlignInBits;
499 uint64_t OffsetInBits;
502 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
503 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
504 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
505 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
506 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
507 OffsetInBits(OffsetInBits) {}
511 TempMDType clone() const {
512 return TempMDType(cast<MDType>(MDNode::clone().release()));
515 unsigned getLine() const { return Line; }
516 uint64_t getSizeInBits() const { return SizeInBits; }
517 uint64_t getAlignInBits() const { return AlignInBits; }
518 uint64_t getOffsetInBits() const { return OffsetInBits; }
519 unsigned getFlags() const { return Flags; }
521 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
522 StringRef getName() const { return getStringOperand(2); }
525 Metadata *getRawScope() const { return getOperand(1); }
526 MDString *getRawName() const { return getOperandAs<MDString>(2); }
528 void setFlags(unsigned NewFlags) {
529 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
533 bool isPrivate() const {
534 return (getFlags() & FlagAccessibility) == FlagPrivate;
536 bool isProtected() const {
537 return (getFlags() & FlagAccessibility) == FlagProtected;
539 bool isPublic() const {
540 return (getFlags() & FlagAccessibility) == FlagPublic;
542 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
543 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
544 bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; }
545 bool isVirtual() const { return getFlags() & FlagVirtual; }
546 bool isArtificial() const { return getFlags() & FlagArtificial; }
547 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
548 bool isObjcClassComplete() const {
549 return getFlags() & FlagObjcClassComplete;
551 bool isVector() const { return getFlags() & FlagVector; }
552 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
553 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
554 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
556 MDTypeRef getRef() const { return MDTypeRef::get(this); }
558 static bool classof(const Metadata *MD) {
559 switch (MD->getMetadataID()) {
562 case MDBasicTypeKind:
563 case MDDerivedTypeKind:
564 case MDCompositeTypeKind:
565 case MDSubroutineTypeKind:
571 /// \brief Basic type.
573 /// TODO: Split out DW_TAG_unspecified_type.
574 /// TODO: Drop unused accessors.
575 class MDBasicType : public MDType {
576 friend class LLVMContextImpl;
581 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
582 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
583 ArrayRef<Metadata *> Ops)
584 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
586 Encoding(Encoding) {}
589 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
590 StringRef Name, uint64_t SizeInBits,
591 uint64_t AlignInBits, unsigned Encoding,
592 StorageType Storage, bool ShouldCreate = true) {
593 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
594 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
596 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
597 MDString *Name, uint64_t SizeInBits,
598 uint64_t AlignInBits, unsigned Encoding,
599 StorageType Storage, bool ShouldCreate = true);
601 TempMDBasicType cloneImpl() const {
602 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
603 getAlignInBits(), getEncoding());
607 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
608 (Tag, Name, 0, 0, 0))
609 DEFINE_MDNODE_GET(MDBasicType,
610 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
611 uint64_t AlignInBits, unsigned Encoding),
612 (Tag, Name, SizeInBits, AlignInBits, Encoding))
613 DEFINE_MDNODE_GET(MDBasicType,
614 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
615 uint64_t AlignInBits, unsigned Encoding),
616 (Tag, Name, SizeInBits, AlignInBits, Encoding))
618 TempMDBasicType clone() const { return cloneImpl(); }
620 unsigned getEncoding() const { return Encoding; }
622 static bool classof(const Metadata *MD) {
623 return MD->getMetadataID() == MDBasicTypeKind;
627 /// \brief Base class for MDDerivedType and MDCompositeType.
629 /// TODO: Delete; they're not really related.
630 class MDDerivedTypeBase : public MDType {
632 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
633 unsigned Tag, unsigned Line, uint64_t SizeInBits,
634 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
635 ArrayRef<Metadata *> Ops)
636 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
638 ~MDDerivedTypeBase() {}
641 MDTypeRef getBaseType() const { return MDTypeRef(getRawBaseType()); }
642 Metadata *getRawBaseType() const { return getOperand(3); }
644 static bool classof(const Metadata *MD) {
645 return MD->getMetadataID() == MDDerivedTypeKind ||
646 MD->getMetadataID() == MDCompositeTypeKind ||
647 MD->getMetadataID() == MDSubroutineTypeKind;
651 /// \brief Derived types.
653 /// This includes qualified types, pointers, references, friends, typedefs, and
656 /// TODO: Split out members (inheritance, fields, methods, etc.).
657 class MDDerivedType : public MDDerivedTypeBase {
658 friend class LLVMContextImpl;
661 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
662 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
663 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
664 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
665 AlignInBits, OffsetInBits, Flags, Ops) {}
668 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
669 StringRef Name, MDFile *File, unsigned Line,
670 MDScopeRef Scope, MDTypeRef BaseType,
671 uint64_t SizeInBits, uint64_t AlignInBits,
672 uint64_t OffsetInBits, unsigned Flags,
673 Metadata *ExtraData, StorageType Storage,
674 bool ShouldCreate = true) {
675 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
676 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
677 Flags, ExtraData, Storage, ShouldCreate);
679 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
680 MDString *Name, Metadata *File, unsigned Line,
681 Metadata *Scope, Metadata *BaseType,
682 uint64_t SizeInBits, uint64_t AlignInBits,
683 uint64_t OffsetInBits, unsigned Flags,
684 Metadata *ExtraData, StorageType Storage,
685 bool ShouldCreate = true);
687 TempMDDerivedType cloneImpl() const {
688 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
689 getScope(), getBaseType(), getSizeInBits(),
690 getAlignInBits(), getOffsetInBits(), getFlags(),
695 DEFINE_MDNODE_GET(MDDerivedType,
696 (unsigned Tag, MDString *Name, Metadata *File,
697 unsigned Line, Metadata *Scope, Metadata *BaseType,
698 uint64_t SizeInBits, uint64_t AlignInBits,
699 uint64_t OffsetInBits, unsigned Flags,
700 Metadata *ExtraData = nullptr),
701 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
702 AlignInBits, OffsetInBits, Flags, ExtraData))
703 DEFINE_MDNODE_GET(MDDerivedType,
704 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
705 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
706 uint64_t AlignInBits, uint64_t OffsetInBits,
707 unsigned Flags, Metadata *ExtraData = nullptr),
708 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
709 AlignInBits, OffsetInBits, Flags, ExtraData))
711 TempMDDerivedType clone() const { return cloneImpl(); }
713 /// \brief Get extra data associated with this derived type.
715 /// Class type for pointer-to-members, objective-c property node for ivars,
716 /// or global constant wrapper for static members.
718 /// TODO: Separate out types that need this extra operand: pointer-to-member
719 /// types and member fields (static members and ivars).
720 Metadata *getExtraData() const { return getRawExtraData(); }
721 Metadata *getRawExtraData() const { return getOperand(4); }
723 static bool classof(const Metadata *MD) {
724 return MD->getMetadataID() == MDDerivedTypeKind;
728 /// \brief Base class for MDCompositeType and MDSubroutineType.
730 /// TODO: Delete; they're not really related.
731 class MDCompositeTypeBase : public MDDerivedTypeBase {
732 unsigned RuntimeLang;
735 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
736 unsigned Tag, unsigned Line, unsigned RuntimeLang,
737 uint64_t SizeInBits, uint64_t AlignInBits,
738 uint64_t OffsetInBits, unsigned Flags,
739 ArrayRef<Metadata *> Ops)
740 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
741 OffsetInBits, Flags, Ops),
742 RuntimeLang(RuntimeLang) {}
743 ~MDCompositeTypeBase() {}
746 MDTuple *getElements() const {
747 return cast_or_null<MDTuple>(getRawElements());
749 MDTypeRef getVTableHolder() const { return MDTypeRef(getRawVTableHolder()); }
750 MDTemplateParameterArray getTemplateParams() const {
751 return cast_or_null<MDTuple>(getRawTemplateParams());
753 StringRef getIdentifier() const { return getStringOperand(7); }
754 unsigned getRuntimeLang() const { return RuntimeLang; }
756 Metadata *getRawElements() const { return getOperand(4); }
757 Metadata *getRawVTableHolder() const { return getOperand(5); }
758 Metadata *getRawTemplateParams() const { return getOperand(6); }
759 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
761 /// \brief Replace operands.
763 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
764 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
765 /// of its movement if necessary.
767 void replaceElements(MDTuple *Elements) {
769 if (auto *Old = cast_or_null<MDTuple>(getElements()))
770 for (const auto &Op : Old->operands())
771 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
772 "Lost a member during member list replacement");
774 replaceOperandWith(4, Elements);
776 void replaceVTableHolder(MDTypeRef VTableHolder) {
777 replaceOperandWith(5, VTableHolder);
779 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
780 replaceOperandWith(6, TemplateParams);
784 static bool classof(const Metadata *MD) {
785 return MD->getMetadataID() == MDCompositeTypeKind ||
786 MD->getMetadataID() == MDSubroutineTypeKind;
790 /// \brief Composite types.
792 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
793 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
794 class MDCompositeType : public MDCompositeTypeBase {
795 friend class LLVMContextImpl;
798 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
799 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
800 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
801 ArrayRef<Metadata *> Ops)
802 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
803 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
805 ~MDCompositeType() {}
807 static MDCompositeType *
808 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
809 unsigned Line, MDScopeRef Scope, MDTypeRef BaseType,
810 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
811 uint64_t Flags, MDTuple *Elements, unsigned RuntimeLang,
812 MDTypeRef VTableHolder, MDTemplateParameterArray TemplateParams,
813 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
814 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
815 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
816 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
817 getCanonicalMDString(Context, Identifier), Storage,
820 static MDCompositeType *
821 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
822 unsigned Line, Metadata *Scope, Metadata *BaseType,
823 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
824 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
825 Metadata *VTableHolder, Metadata *TemplateParams,
826 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
828 TempMDCompositeType cloneImpl() const {
829 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
830 getScope(), getBaseType(), getSizeInBits(),
831 getAlignInBits(), getOffsetInBits(), getFlags(),
832 getElements(), getRuntimeLang(), getVTableHolder(),
833 getTemplateParams(), getIdentifier());
837 DEFINE_MDNODE_GET(MDCompositeType,
838 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
839 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
840 uint64_t AlignInBits, uint64_t OffsetInBits,
841 unsigned Flags, MDTuple *Elements, unsigned RuntimeLang,
842 MDTypeRef VTableHolder,
843 MDTemplateParameterArray TemplateParams = nullptr,
844 StringRef Identifier = ""),
845 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
846 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
847 VTableHolder, TemplateParams, Identifier))
848 DEFINE_MDNODE_GET(MDCompositeType,
849 (unsigned Tag, MDString *Name, Metadata *File,
850 unsigned Line, Metadata *Scope, Metadata *BaseType,
851 uint64_t SizeInBits, uint64_t AlignInBits,
852 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
853 unsigned RuntimeLang, Metadata *VTableHolder,
854 Metadata *TemplateParams = nullptr,
855 MDString *Identifier = nullptr),
856 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
857 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
858 VTableHolder, TemplateParams, Identifier))
860 TempMDCompositeType clone() const { return cloneImpl(); }
862 static bool classof(const Metadata *MD) {
863 return MD->getMetadataID() == MDCompositeTypeKind;
867 template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) {
869 if (auto *Composite = dyn_cast<MDCompositeType>(N))
870 if (auto *S = Composite->getRawIdentifier())
871 return TypedDebugNodeRef<T>(S);
872 return TypedDebugNodeRef<T>(N);
875 /// \brief Type array for a subprogram.
877 /// TODO: Detach from CompositeType, and fold the array of types in directly
879 class MDSubroutineType : public MDCompositeTypeBase {
880 friend class LLVMContextImpl;
883 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
884 ArrayRef<Metadata *> Ops)
885 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
886 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
888 ~MDSubroutineType() {}
890 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
891 Metadata *TypeArray, StorageType Storage,
892 bool ShouldCreate = true);
894 TempMDSubroutineType cloneImpl() const {
895 return getTemporary(getContext(), getFlags(), getTypeArray());
899 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
902 TempMDSubroutineType clone() const { return cloneImpl(); }
904 MDTypeRefArray getTypeArray() const { return getElements(); }
905 Metadata *getRawTypeArray() const { return getRawElements(); }
907 static bool classof(const Metadata *MD) {
908 return MD->getMetadataID() == MDSubroutineTypeKind;
912 /// \brief Compile unit.
913 class MDCompileUnit : public MDScope {
914 friend class LLVMContextImpl;
917 unsigned SourceLanguage;
919 unsigned RuntimeVersion;
920 unsigned EmissionKind;
922 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
923 bool IsOptimized, unsigned RuntimeVersion,
924 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
925 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
926 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
927 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
930 static MDCompileUnit *
931 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
932 StringRef Producer, bool IsOptimized, StringRef Flags,
933 unsigned RuntimeVersion, StringRef SplitDebugFilename,
934 unsigned EmissionKind, MDTuple *EnumTypes, MDTuple *RetainedTypes,
935 MDTuple *Subprograms, MDTuple *GlobalVariables,
936 MDTuple *ImportedEntities, StorageType Storage,
937 bool ShouldCreate = true) {
938 return getImpl(Context, SourceLanguage, File,
939 getCanonicalMDString(Context, Producer), IsOptimized,
940 getCanonicalMDString(Context, Flags), RuntimeVersion,
941 getCanonicalMDString(Context, SplitDebugFilename),
942 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
943 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
945 static MDCompileUnit *
946 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
947 MDString *Producer, bool IsOptimized, MDString *Flags,
948 unsigned RuntimeVersion, MDString *SplitDebugFilename,
949 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
950 Metadata *Subprograms, Metadata *GlobalVariables,
951 Metadata *ImportedEntities, StorageType Storage,
952 bool ShouldCreate = true);
954 TempMDCompileUnit cloneImpl() const {
956 getContext(), getSourceLanguage(), getFile(), getProducer(),
957 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
958 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
959 getGlobalVariables(), getImportedEntities());
963 DEFINE_MDNODE_GET(MDCompileUnit,
964 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
965 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
966 StringRef SplitDebugFilename, unsigned EmissionKind,
967 MDTuple *EnumTypes, MDTuple *RetainedTypes,
968 MDTuple *Subprograms, MDTuple *GlobalVariables,
969 MDTuple *ImportedEntities),
970 (SourceLanguage, File, Producer, IsOptimized, Flags,
971 RuntimeVersion, SplitDebugFilename, EmissionKind,
972 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
974 DEFINE_MDNODE_GET(MDCompileUnit,
975 (unsigned SourceLanguage, Metadata *File,
976 MDString *Producer, bool IsOptimized, MDString *Flags,
977 unsigned RuntimeVersion, MDString *SplitDebugFilename,
978 unsigned EmissionKind, Metadata *EnumTypes,
979 Metadata *RetainedTypes, Metadata *Subprograms,
980 Metadata *GlobalVariables, Metadata *ImportedEntities),
981 (SourceLanguage, File, Producer, IsOptimized, Flags,
982 RuntimeVersion, SplitDebugFilename, EmissionKind,
983 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
986 TempMDCompileUnit clone() const { return cloneImpl(); }
988 unsigned getSourceLanguage() const { return SourceLanguage; }
989 bool isOptimized() const { return IsOptimized; }
990 unsigned getRuntimeVersion() const { return RuntimeVersion; }
991 unsigned getEmissionKind() const { return EmissionKind; }
992 StringRef getProducer() const { return getStringOperand(1); }
993 StringRef getFlags() const { return getStringOperand(2); }
994 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
995 MDCompositeTypeArray getEnumTypes() const {
996 return cast_or_null<MDTuple>(getRawEnumTypes());
998 MDTypeArray getRetainedTypes() const {
999 return cast_or_null<MDTuple>(getRawRetainedTypes());
1001 MDSubprogramArray getSubprograms() const {
1002 return cast_or_null<MDTuple>(getRawSubprograms());
1004 MDGlobalVariableArray getGlobalVariables() const {
1005 return cast_or_null<MDTuple>(getRawGlobalVariables());
1007 MDImportedEntityArray getImportedEntities() const {
1008 return cast_or_null<MDTuple>(getRawImportedEntities());
1011 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1012 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1013 MDString *getRawSplitDebugFilename() const {
1014 return getOperandAs<MDString>(3);
1016 Metadata *getRawEnumTypes() const { return getOperand(4); }
1017 Metadata *getRawRetainedTypes() const { return getOperand(5); }
1018 Metadata *getRawSubprograms() const { return getOperand(6); }
1019 Metadata *getRawGlobalVariables() const { return getOperand(7); }
1020 Metadata *getRawImportedEntities() const { return getOperand(8); }
1022 /// \brief Replace arrays.
1024 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1025 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1026 /// MDCompileUnit should be fairly rare.
1028 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
1029 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
1032 static bool classof(const Metadata *MD) {
1033 return MD->getMetadataID() == MDCompileUnitKind;
1037 /// \brief A scope for locals.
1039 /// A legal scope for lexical blocks, local variables, and debug info
1040 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
1041 /// MDLexicalBlockFile.
1042 class MDLocalScope : public MDScope {
1044 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1045 ArrayRef<Metadata *> Ops)
1046 : MDScope(C, ID, Storage, Tag, Ops) {}
1050 /// \brief Get the subprogram for this scope.
1052 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
1054 MDSubprogram *getSubprogram() const;
1056 static bool classof(const Metadata *MD) {
1057 return MD->getMetadataID() == MDSubprogramKind ||
1058 MD->getMetadataID() == MDLexicalBlockKind ||
1059 MD->getMetadataID() == MDLexicalBlockFileKind;
1063 /// \brief Debug location.
1065 /// A debug location in source code, used for debug info and otherwise.
1066 class MDLocation : public MDNode {
1067 friend class LLVMContextImpl;
1068 friend class MDNode;
1070 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
1071 unsigned Column, ArrayRef<Metadata *> MDs);
1072 ~MDLocation() { dropAllReferences(); }
1074 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1075 unsigned Column, Metadata *Scope,
1076 Metadata *InlinedAt, StorageType Storage,
1077 bool ShouldCreate = true);
1078 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1079 unsigned Column, MDLocalScope *Scope,
1080 MDLocation *InlinedAt, StorageType Storage,
1081 bool ShouldCreate = true) {
1082 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1083 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1086 TempMDLocation cloneImpl() const {
1087 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
1091 // Disallow replacing operands.
1092 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1095 DEFINE_MDNODE_GET(MDLocation,
1096 (unsigned Line, unsigned Column, Metadata *Scope,
1097 Metadata *InlinedAt = nullptr),
1098 (Line, Column, Scope, InlinedAt))
1099 DEFINE_MDNODE_GET(MDLocation,
1100 (unsigned Line, unsigned Column, MDLocalScope *Scope,
1101 MDLocation *InlinedAt = nullptr),
1102 (Line, Column, Scope, InlinedAt))
1104 /// \brief Return a (temporary) clone of this.
1105 TempMDLocation clone() const { return cloneImpl(); }
1107 unsigned getLine() const { return SubclassData32; }
1108 unsigned getColumn() const { return SubclassData16; }
1109 MDLocalScope *getScope() const {
1110 return cast<MDLocalScope>(getRawScope());
1112 MDLocation *getInlinedAt() const {
1113 return cast_or_null<MDLocation>(getRawInlinedAt());
1116 /// \brief Get the scope where this is inlined.
1118 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1120 MDLocalScope *getInlinedAtScope() const {
1121 if (auto *IA = getInlinedAt())
1122 return IA->getInlinedAtScope();
1126 Metadata *getRawScope() const { return getOperand(0); }
1127 Metadata *getRawInlinedAt() const {
1128 if (getNumOperands() == 2)
1129 return getOperand(1);
1133 static bool classof(const Metadata *MD) {
1134 return MD->getMetadataID() == MDLocationKind;
1138 /// \brief Subprogram description.
1140 /// TODO: Remove DisplayName. It's always equal to Name.
1141 /// TODO: Split up flags.
1142 class MDSubprogram : public MDLocalScope {
1143 friend class LLVMContextImpl;
1144 friend class MDNode;
1148 unsigned Virtuality;
1149 unsigned VirtualIndex;
1155 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1156 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1157 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
1158 bool IsOptimized, ArrayRef<Metadata *> Ops)
1159 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1161 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
1162 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
1163 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
1166 static MDSubprogram *
1167 getImpl(LLVMContext &Context, MDScopeRef Scope, StringRef Name,
1168 StringRef LinkageName, MDFile *File, unsigned Line,
1169 MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1170 unsigned ScopeLine, MDTypeRef ContainingType, unsigned Virtuality,
1171 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1172 ConstantAsMetadata *Function, MDTemplateParameterArray TemplateParams,
1173 MDSubprogram *Declaration, MDLocalVariableArray Variables,
1174 StorageType Storage, bool ShouldCreate = true) {
1175 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1176 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1177 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1178 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1179 TemplateParams, Declaration, Variables, Storage,
1182 static MDSubprogram *
1183 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1184 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1185 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1186 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1187 unsigned Flags, bool IsOptimized, Metadata *Function,
1188 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1189 StorageType Storage, bool ShouldCreate = true);
1191 TempMDSubprogram cloneImpl() const {
1192 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1193 getFile(), getLine(), getType(), isLocalToUnit(),
1194 isDefinition(), getScopeLine(), getContainingType(),
1195 getVirtuality(), getVirtualIndex(), getFlags(),
1196 isOptimized(), getFunction(), getTemplateParams(),
1197 getDeclaration(), getVariables());
1201 DEFINE_MDNODE_GET(MDSubprogram,
1202 (MDScopeRef Scope, StringRef Name, StringRef LinkageName,
1203 MDFile *File, unsigned Line, MDSubroutineType *Type,
1204 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1205 MDTypeRef ContainingType, unsigned Virtuality,
1206 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1207 ConstantAsMetadata *Function = nullptr,
1208 MDTemplateParameterArray TemplateParams = nullptr,
1209 MDSubprogram *Declaration = nullptr,
1210 MDLocalVariableArray Variables = nullptr),
1211 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1212 IsDefinition, ScopeLine, ContainingType, Virtuality,
1213 VirtualIndex, Flags, IsOptimized, Function, TemplateParams,
1214 Declaration, Variables))
1217 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1218 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1219 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1220 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1221 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1222 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1223 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1224 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1225 Function, TemplateParams, Declaration, Variables))
1227 TempMDSubprogram clone() const { return cloneImpl(); }
1230 unsigned getLine() const { return Line; }
1231 unsigned getVirtuality() const { return Virtuality; }
1232 unsigned getVirtualIndex() const { return VirtualIndex; }
1233 unsigned getScopeLine() const { return ScopeLine; }
1234 unsigned getFlags() const { return Flags; }
1235 bool isLocalToUnit() const { return IsLocalToUnit; }
1236 bool isDefinition() const { return IsDefinition; }
1237 bool isOptimized() const { return IsOptimized; }
1239 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
1241 StringRef getName() const { return getStringOperand(2); }
1242 StringRef getDisplayName() const { return getStringOperand(3); }
1243 StringRef getLinkageName() const { return getStringOperand(4); }
1245 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1246 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1248 MDSubroutineType *getType() const {
1249 return cast_or_null<MDSubroutineType>(getRawType());
1251 MDTypeRef getContainingType() const {
1252 return MDTypeRef(getRawContainingType());
1255 ConstantAsMetadata *getFunction() const {
1256 return cast_or_null<ConstantAsMetadata>(getRawFunction());
1258 MDTemplateParameterArray getTemplateParams() const {
1259 return cast_or_null<MDTuple>(getRawTemplateParams());
1261 MDSubprogram *getDeclaration() const {
1262 return cast_or_null<MDSubprogram>(getRawDeclaration());
1264 MDLocalVariableArray getVariables() const {
1265 return cast_or_null<MDTuple>(getRawVariables());
1268 Metadata *getRawScope() const { return getOperand(1); }
1269 Metadata *getRawType() const { return getOperand(5); }
1270 Metadata *getRawContainingType() const { return getOperand(6); }
1271 Metadata *getRawFunction() const { return getOperand(7); }
1272 Metadata *getRawTemplateParams() const { return getOperand(8); }
1273 Metadata *getRawDeclaration() const { return getOperand(9); }
1274 Metadata *getRawVariables() const { return getOperand(10); }
1276 /// \brief Replace the function.
1278 /// If \a isUniqued() and not \a isResolved(), this could node will be
1279 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1280 /// that's a problem.
1282 void replaceFunction(Function *F);
1283 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1284 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1287 static bool classof(const Metadata *MD) {
1288 return MD->getMetadataID() == MDSubprogramKind;
1292 class MDLexicalBlockBase : public MDLocalScope {
1294 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1295 ArrayRef<Metadata *> Ops)
1296 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1297 ~MDLexicalBlockBase() {}
1300 MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
1302 Metadata *getRawScope() const { return getOperand(1); }
1304 static bool classof(const Metadata *MD) {
1305 return MD->getMetadataID() == MDLexicalBlockKind ||
1306 MD->getMetadataID() == MDLexicalBlockFileKind;
1310 class MDLexicalBlock : public MDLexicalBlockBase {
1311 friend class LLVMContextImpl;
1312 friend class MDNode;
1317 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1318 unsigned Column, ArrayRef<Metadata *> Ops)
1319 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1321 ~MDLexicalBlock() {}
1323 static MDLexicalBlock *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1324 MDFile *File, unsigned Line, unsigned Column,
1325 StorageType Storage,
1326 bool ShouldCreate = true) {
1327 return getImpl(Context, static_cast<Metadata *>(Scope),
1328 static_cast<Metadata *>(File), Line, Column, Storage,
1332 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1333 Metadata *File, unsigned Line, unsigned Column,
1334 StorageType Storage, bool ShouldCreate = true);
1336 TempMDLexicalBlock cloneImpl() const {
1337 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1342 DEFINE_MDNODE_GET(MDLexicalBlock, (MDLocalScope * Scope, MDFile *File,
1343 unsigned Line, unsigned Column),
1344 (Scope, File, Line, Column))
1345 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1346 unsigned Line, unsigned Column),
1347 (Scope, File, Line, Column))
1349 TempMDLexicalBlock clone() const { return cloneImpl(); }
1351 unsigned getLine() const { return Line; }
1352 unsigned getColumn() const { return Column; }
1354 static bool classof(const Metadata *MD) {
1355 return MD->getMetadataID() == MDLexicalBlockKind;
1359 class MDLexicalBlockFile : public MDLexicalBlockBase {
1360 friend class LLVMContextImpl;
1361 friend class MDNode;
1363 unsigned Discriminator;
1365 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1366 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1367 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1368 Discriminator(Discriminator) {}
1369 ~MDLexicalBlockFile() {}
1371 static MDLexicalBlockFile *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1372 MDFile *File, unsigned Discriminator,
1373 StorageType Storage,
1374 bool ShouldCreate = true) {
1375 return getImpl(Context, static_cast<Metadata *>(Scope),
1376 static_cast<Metadata *>(File), Discriminator, Storage,
1380 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1381 Metadata *File, unsigned Discriminator,
1382 StorageType Storage,
1383 bool ShouldCreate = true);
1385 TempMDLexicalBlockFile cloneImpl() const {
1386 return getTemporary(getContext(), getScope(), getFile(),
1387 getDiscriminator());
1391 DEFINE_MDNODE_GET(MDLexicalBlockFile, (MDLocalScope * Scope, MDFile *File,
1392 unsigned Discriminator),
1393 (Scope, File, Discriminator))
1394 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1395 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1396 (Scope, File, Discriminator))
1398 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1400 unsigned getDiscriminator() const { return Discriminator; }
1402 static bool classof(const Metadata *MD) {
1403 return MD->getMetadataID() == MDLexicalBlockFileKind;
1407 class MDNamespace : public MDScope {
1408 friend class LLVMContextImpl;
1409 friend class MDNode;
1413 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1414 ArrayRef<Metadata *> Ops)
1415 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1420 static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
1421 MDFile *File, StringRef Name, unsigned Line,
1422 StorageType Storage, bool ShouldCreate = true) {
1423 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1424 Line, Storage, ShouldCreate);
1426 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1427 Metadata *File, MDString *Name, unsigned Line,
1428 StorageType Storage, bool ShouldCreate = true);
1430 TempMDNamespace cloneImpl() const {
1431 return getTemporary(getContext(), getScope(), getFile(), getName(),
1436 DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
1438 (Scope, File, Name, Line))
1439 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1440 MDString *Name, unsigned Line),
1441 (Scope, File, Name, Line))
1443 TempMDNamespace clone() const { return cloneImpl(); }
1445 unsigned getLine() const { return Line; }
1446 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1447 StringRef getName() const { return getStringOperand(2); }
1449 Metadata *getRawScope() const { return getOperand(1); }
1450 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1452 static bool classof(const Metadata *MD) {
1453 return MD->getMetadataID() == MDNamespaceKind;
1457 /// \brief Base class for template parameters.
1458 class MDTemplateParameter : public DebugNode {
1460 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1461 unsigned Tag, ArrayRef<Metadata *> Ops)
1462 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1463 ~MDTemplateParameter() {}
1466 StringRef getName() const { return getStringOperand(0); }
1467 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1469 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1470 Metadata *getRawType() const { return getOperand(1); }
1472 static bool classof(const Metadata *MD) {
1473 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1474 MD->getMetadataID() == MDTemplateValueParameterKind;
1478 class MDTemplateTypeParameter : public MDTemplateParameter {
1479 friend class LLVMContextImpl;
1480 friend class MDNode;
1482 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1483 ArrayRef<Metadata *> Ops)
1484 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1485 dwarf::DW_TAG_template_type_parameter, Ops) {}
1486 ~MDTemplateTypeParameter() {}
1488 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1489 MDTypeRef Type, StorageType Storage,
1490 bool ShouldCreate = true) {
1491 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1494 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1495 Metadata *Type, StorageType Storage,
1496 bool ShouldCreate = true);
1498 TempMDTemplateTypeParameter cloneImpl() const {
1499 return getTemporary(getContext(), getName(), getType());
1503 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, MDTypeRef Type),
1505 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1508 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1510 static bool classof(const Metadata *MD) {
1511 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1515 class MDTemplateValueParameter : public MDTemplateParameter {
1516 friend class LLVMContextImpl;
1517 friend class MDNode;
1519 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1520 unsigned Tag, ArrayRef<Metadata *> Ops)
1521 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1523 ~MDTemplateValueParameter() {}
1525 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1526 StringRef Name, MDTypeRef Type,
1527 Metadata *Value, StorageType Storage,
1528 bool ShouldCreate = true) {
1529 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1530 Value, Storage, ShouldCreate);
1532 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1533 MDString *Name, Metadata *Type,
1534 Metadata *Value, StorageType Storage,
1535 bool ShouldCreate = true);
1537 TempMDTemplateValueParameter cloneImpl() const {
1538 return getTemporary(getContext(), getTag(), getName(), getType(),
1543 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1544 MDTypeRef Type, Metadata *Value),
1545 (Tag, Name, Type, Value))
1546 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1547 Metadata *Type, Metadata *Value),
1548 (Tag, Name, Type, Value))
1550 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1552 Metadata *getValue() const { return getOperand(2); }
1554 static bool classof(const Metadata *MD) {
1555 return MD->getMetadataID() == MDTemplateValueParameterKind;
1559 /// \brief Base class for variables.
1561 /// TODO: Hardcode to DW_TAG_variable.
1562 class MDVariable : public DebugNode {
1566 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1567 unsigned Line, ArrayRef<Metadata *> Ops)
1568 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1572 unsigned getLine() const { return Line; }
1573 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1574 StringRef getName() const { return getStringOperand(1); }
1575 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1576 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1578 Metadata *getRawScope() const { return getOperand(0); }
1579 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1580 Metadata *getRawFile() const { return getOperand(2); }
1581 Metadata *getRawType() const { return getOperand(3); }
1583 static bool classof(const Metadata *MD) {
1584 return MD->getMetadataID() == MDLocalVariableKind ||
1585 MD->getMetadataID() == MDGlobalVariableKind;
1589 /// \brief Global variables.
1591 /// TODO: Remove DisplayName. It's always equal to Name.
1592 class MDGlobalVariable : public MDVariable {
1593 friend class LLVMContextImpl;
1594 friend class MDNode;
1599 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1600 bool IsLocalToUnit, bool IsDefinition,
1601 ArrayRef<Metadata *> Ops)
1602 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1604 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1605 ~MDGlobalVariable() {}
1607 static MDGlobalVariable *
1608 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1609 StringRef LinkageName, MDFile *File, unsigned Line, MDTypeRef Type,
1610 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1611 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1612 bool ShouldCreate = true) {
1613 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1614 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1615 IsLocalToUnit, IsDefinition, Variable,
1616 StaticDataMemberDeclaration, Storage, ShouldCreate);
1618 static MDGlobalVariable *
1619 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1620 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1621 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1622 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1623 bool ShouldCreate = true);
1625 TempMDGlobalVariable cloneImpl() const {
1626 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1627 getFile(), getLine(), getType(), isLocalToUnit(),
1628 isDefinition(), getVariable(),
1629 getStaticDataMemberDeclaration());
1633 DEFINE_MDNODE_GET(MDGlobalVariable,
1634 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1635 MDFile *File, unsigned Line, MDTypeRef Type,
1636 bool IsLocalToUnit, bool IsDefinition,
1637 ConstantAsMetadata *Variable,
1638 MDDerivedType *StaticDataMemberDeclaration),
1639 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1640 IsDefinition, Variable, StaticDataMemberDeclaration))
1641 DEFINE_MDNODE_GET(MDGlobalVariable,
1642 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1643 Metadata *File, unsigned Line, Metadata *Type,
1644 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1645 Metadata *StaticDataMemberDeclaration),
1646 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1647 IsDefinition, Variable, StaticDataMemberDeclaration))
1649 TempMDGlobalVariable clone() const { return cloneImpl(); }
1651 bool isLocalToUnit() const { return IsLocalToUnit; }
1652 bool isDefinition() const { return IsDefinition; }
1653 StringRef getDisplayName() const { return getStringOperand(4); }
1654 StringRef getLinkageName() const { return getStringOperand(5); }
1655 ConstantAsMetadata *getVariable() const {
1656 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1658 MDDerivedType *getStaticDataMemberDeclaration() const {
1659 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1662 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1663 Metadata *getRawVariable() const { return getOperand(6); }
1664 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1666 static bool classof(const Metadata *MD) {
1667 return MD->getMetadataID() == MDGlobalVariableKind;
1671 /// \brief Local variable.
1673 /// TODO: Split between arguments and otherwise.
1674 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1675 /// TODO: Split up flags.
1676 class MDLocalVariable : public MDVariable {
1677 friend class LLVMContextImpl;
1678 friend class MDNode;
1683 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1684 unsigned Line, unsigned Arg, unsigned Flags,
1685 ArrayRef<Metadata *> Ops)
1686 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1688 ~MDLocalVariable() {}
1690 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1691 MDScope *Scope, StringRef Name, MDFile *File,
1692 unsigned Line, MDTypeRef Type, unsigned Arg,
1693 unsigned Flags, MDLocation *InlinedAt,
1694 StorageType Storage,
1695 bool ShouldCreate = true) {
1696 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1697 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1700 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1701 Metadata *Scope, MDString *Name,
1702 Metadata *File, unsigned Line, Metadata *Type,
1703 unsigned Arg, unsigned Flags,
1704 Metadata *InlinedAt, StorageType Storage,
1705 bool ShouldCreate = true);
1707 TempMDLocalVariable cloneImpl() const {
1708 return getTemporary(getContext(), getTag(), getScope(), getName(),
1709 getFile(), getLine(), getType(), getArg(), getFlags(),
1714 DEFINE_MDNODE_GET(MDLocalVariable,
1715 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1716 MDFile *File, unsigned Line, MDTypeRef Type, unsigned Arg,
1717 unsigned Flags, MDLocation *InlinedAt = nullptr),
1718 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1719 DEFINE_MDNODE_GET(MDLocalVariable,
1720 (unsigned Tag, Metadata *Scope, MDString *Name,
1721 Metadata *File, unsigned Line, Metadata *Type,
1722 unsigned Arg, unsigned Flags,
1723 Metadata *InlinedAt = nullptr),
1724 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1726 TempMDLocalVariable clone() const { return cloneImpl(); }
1728 /// \brief Get the local scope for this variable.
1730 /// Variables must be defined in a local scope.
1731 MDLocalScope *getScope() const {
1732 return cast<MDLocalScope>(MDVariable::getScope());
1735 unsigned getArg() const { return Arg; }
1736 unsigned getFlags() const { return Flags; }
1737 MDLocation *getInlinedAt() const {
1738 return cast_or_null<MDLocation>(getRawInlinedAt());
1741 Metadata *getRawInlinedAt() const { return getOperand(4); }
1743 /// \brief Check that a location is valid for this variable.
1745 /// Check that \c DL has the same inlined-at location as this variable,
1746 /// making them valid for the same \a DbgInfoIntrinsic.
1747 bool isValidLocationForIntrinsic(const MDLocation *DL) const {
1748 return getInlinedAt() == (DL ? DL->getInlinedAt() : nullptr);
1751 /// \brief Get an inlined version of this variable.
1753 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1754 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1755 if (InlinedAt == getInlinedAt())
1756 return const_cast<MDLocalVariable *>(this);
1757 auto Temp = clone();
1758 Temp->replaceOperandWith(4, InlinedAt);
1759 return replaceWithUniqued(std::move(Temp));
1761 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1763 static bool classof(const Metadata *MD) {
1764 return MD->getMetadataID() == MDLocalVariableKind;
1768 /// \brief DWARF expression.
1770 /// TODO: Co-allocate the expression elements.
1771 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1773 class MDExpression : public MDNode {
1774 friend class LLVMContextImpl;
1775 friend class MDNode;
1777 std::vector<uint64_t> Elements;
1779 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1780 : MDNode(C, MDExpressionKind, Storage, None),
1781 Elements(Elements.begin(), Elements.end()) {}
1784 static MDExpression *getImpl(LLVMContext &Context,
1785 ArrayRef<uint64_t> Elements, StorageType Storage,
1786 bool ShouldCreate = true);
1788 TempMDExpression cloneImpl() const {
1789 return getTemporary(getContext(), getElements());
1793 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1795 TempMDExpression clone() const { return cloneImpl(); }
1797 ArrayRef<uint64_t> getElements() const { return Elements; }
1799 unsigned getNumElements() const { return Elements.size(); }
1800 uint64_t getElement(unsigned I) const {
1801 assert(I < Elements.size() && "Index out of range");
1805 typedef ArrayRef<uint64_t>::iterator element_iterator;
1806 element_iterator elements_begin() const { return getElements().begin(); }
1807 element_iterator elements_end() const { return getElements().end(); }
1809 /// \brief A lightweight wrapper around an expression operand.
1811 /// TODO: Store arguments directly and change \a MDExpression to store a
1817 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1819 const uint64_t *get() const { return Op; }
1821 /// \brief Get the operand code.
1822 uint64_t getOp() const { return *Op; }
1824 /// \brief Get an argument to the operand.
1826 /// Never returns the operand itself.
1827 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1829 unsigned getNumArgs() const { return getSize() - 1; }
1831 /// \brief Return the size of the operand.
1833 /// Return the number of elements in the operand (1 + args).
1834 unsigned getSize() const;
1837 /// \brief An iterator for expression operands.
1838 class expr_op_iterator
1839 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1843 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1845 element_iterator getBase() const { return Op.get(); }
1846 const ExprOperand &operator*() const { return Op; }
1847 const ExprOperand *operator->() const { return &Op; }
1849 expr_op_iterator &operator++() {
1853 expr_op_iterator operator++(int) {
1854 expr_op_iterator T(*this);
1859 bool operator==(const expr_op_iterator &X) const {
1860 return getBase() == X.getBase();
1862 bool operator!=(const expr_op_iterator &X) const {
1863 return getBase() != X.getBase();
1867 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1870 /// \brief Visit the elements via ExprOperand wrappers.
1872 /// These range iterators visit elements through \a ExprOperand wrappers.
1873 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1876 /// \pre \a isValid() gives \c true.
1878 expr_op_iterator expr_op_begin() const {
1879 return expr_op_iterator(elements_begin());
1881 expr_op_iterator expr_op_end() const {
1882 return expr_op_iterator(elements_end());
1886 bool isValid() const;
1888 static bool classof(const Metadata *MD) {
1889 return MD->getMetadataID() == MDExpressionKind;
1893 class MDObjCProperty : public DebugNode {
1894 friend class LLVMContextImpl;
1895 friend class MDNode;
1898 unsigned Attributes;
1900 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1901 unsigned Attributes, ArrayRef<Metadata *> Ops)
1902 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1904 Line(Line), Attributes(Attributes) {}
1905 ~MDObjCProperty() {}
1907 static MDObjCProperty *
1908 getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
1909 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1910 MDType *Type, StorageType Storage, bool ShouldCreate = true) {
1911 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1912 getCanonicalMDString(Context, GetterName),
1913 getCanonicalMDString(Context, SetterName), Attributes, Type,
1914 Storage, ShouldCreate);
1916 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1917 Metadata *File, unsigned Line,
1918 MDString *GetterName, MDString *SetterName,
1919 unsigned Attributes, Metadata *Type,
1920 StorageType Storage, bool ShouldCreate = true);
1922 TempMDObjCProperty cloneImpl() const {
1923 return getTemporary(getContext(), getName(), getFile(), getLine(),
1924 getGetterName(), getSetterName(), getAttributes(),
1929 DEFINE_MDNODE_GET(MDObjCProperty,
1930 (StringRef Name, MDFile *File, unsigned Line,
1931 StringRef GetterName, StringRef SetterName,
1932 unsigned Attributes, MDType *Type),
1933 (Name, File, Line, GetterName, SetterName, Attributes,
1935 DEFINE_MDNODE_GET(MDObjCProperty,
1936 (MDString * Name, Metadata *File, unsigned Line,
1937 MDString *GetterName, MDString *SetterName,
1938 unsigned Attributes, Metadata *Type),
1939 (Name, File, Line, GetterName, SetterName, Attributes,
1942 TempMDObjCProperty clone() const { return cloneImpl(); }
1944 unsigned getLine() const { return Line; }
1945 unsigned getAttributes() const { return Attributes; }
1946 StringRef getName() const { return getStringOperand(0); }
1947 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1948 StringRef getGetterName() const { return getStringOperand(2); }
1949 StringRef getSetterName() const { return getStringOperand(3); }
1950 MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
1952 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1953 Metadata *getRawFile() const { return getOperand(1); }
1954 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1955 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1956 Metadata *getRawType() const { return getOperand(4); }
1958 static bool classof(const Metadata *MD) {
1959 return MD->getMetadataID() == MDObjCPropertyKind;
1963 class MDImportedEntity : public DebugNode {
1964 friend class LLVMContextImpl;
1965 friend class MDNode;
1969 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1970 unsigned Line, ArrayRef<Metadata *> Ops)
1971 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1972 ~MDImportedEntity() {}
1974 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1975 MDScope *Scope, Metadata *Entity,
1976 unsigned Line, StringRef Name,
1977 StorageType Storage,
1978 bool ShouldCreate = true) {
1979 return getImpl(Context, Tag, Scope, Entity, Line,
1980 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1982 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1983 Metadata *Scope, Metadata *Entity,
1984 unsigned Line, MDString *Name,
1985 StorageType Storage,
1986 bool ShouldCreate = true);
1988 TempMDImportedEntity cloneImpl() const {
1989 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1990 getLine(), getName());
1994 DEFINE_MDNODE_GET(MDImportedEntity,
1995 (unsigned Tag, MDScope *Scope, Metadata *Entity,
1996 unsigned Line, StringRef Name = ""),
1997 (Tag, Scope, Entity, Line, Name))
1998 DEFINE_MDNODE_GET(MDImportedEntity,
1999 (unsigned Tag, Metadata *Scope, Metadata *Entity,
2000 unsigned Line, MDString *Name),
2001 (Tag, Scope, Entity, Line, Name))
2003 TempMDImportedEntity clone() const { return cloneImpl(); }
2005 unsigned getLine() const { return Line; }
2006 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
2007 Metadata *getEntity() const { return getRawEntity(); }
2008 StringRef getName() const { return getStringOperand(2); }
2010 Metadata *getRawScope() const { return getOperand(0); }
2011 Metadata *getRawEntity() const { return getOperand(1); }
2012 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2014 static bool classof(const Metadata *MD) {
2015 return MD->getMetadataID() == MDImportedEntityKind;
2019 } // end namespace llvm
2021 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
2022 #undef DEFINE_MDNODE_GET_UNPACK
2023 #undef DEFINE_MDNODE_GET