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 {
78 if (auto *Typed = dyn_cast<T>(MD))
79 return const_cast<T *>(Typed);
81 auto *S = cast<MDString>(MD);
83 assert(I != Map.end() && "Missing identifier in type map");
84 return cast<T>(I->second);
88 typedef TypedDebugNodeRef<DebugNode> DebugNodeRef;
89 typedef TypedDebugNodeRef<MDScope> MDScopeRef;
90 typedef TypedDebugNodeRef<MDType> MDTypeRef;
92 class MDTypeRefArray {
93 const MDTuple *N = nullptr;
96 MDTypeRefArray(const MDTuple *N) : N(N) {}
97 operator MDTuple *() const { return const_cast<MDTuple *>(N); }
98 MDTuple *operator->() const { return const_cast<MDTuple *>(N); }
99 MDTuple &operator*() const { return *const_cast<MDTuple *>(N); }
101 unsigned size() const { return N->getNumOperands(); }
102 MDTypeRef operator[](unsigned I) const { return MDTypeRef(N->getOperand(I)); }
104 class iterator : std::iterator<std::input_iterator_tag, MDTypeRef,
105 std::ptrdiff_t, void, MDTypeRef> {
106 MDNode::op_iterator I;
109 explicit iterator(MDNode::op_iterator I) : I(I) {}
110 MDTypeRef operator*() const { return MDTypeRef(*I); }
111 iterator &operator++() {
115 iterator operator++(int) {
116 iterator Temp(*this);
120 bool operator==(const iterator &X) const { return I == X.I; }
121 bool operator!=(const iterator &X) const { return I != X.I; }
124 iterator begin() const { return iterator(N->op_begin()); }
125 iterator end() const { return iterator(N->op_end()); }
128 /// \brief Tagged DWARF-like metadata node.
130 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
131 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
132 /// potentially used for non-DWARF output.
133 class DebugNode : public MDNode {
134 friend class LLVMContextImpl;
138 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
139 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
140 : MDNode(C, ID, Storage, Ops1, Ops2) {
141 assert(Tag < 1u << 16);
142 SubclassData16 = Tag;
146 template <class Ty> Ty *getOperandAs(unsigned I) const {
147 return cast_or_null<Ty>(getOperand(I));
150 StringRef getStringOperand(unsigned I) const {
151 if (auto *S = getOperandAs<MDString>(I))
152 return S->getString();
156 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
159 return MDString::get(Context, S);
163 unsigned getTag() const { return SubclassData16; }
165 /// \brief Debug info flags.
167 /// The three accessibility flags are mutually exclusive and rolled together
168 /// in the first two bits.
170 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
171 #include "llvm/IR/DebugInfoFlags.def"
172 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
175 DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
177 static bool classof(const Metadata *MD) {
178 switch (MD->getMetadataID()) {
181 case GenericDebugNodeKind:
183 case MDEnumeratorKind:
184 case MDBasicTypeKind:
185 case MDDerivedTypeKind:
186 case MDCompositeTypeKind:
187 case MDSubroutineTypeKind:
189 case MDCompileUnitKind:
190 case MDSubprogramKind:
191 case MDLexicalBlockKind:
192 case MDLexicalBlockFileKind:
193 case MDNamespaceKind:
194 case MDTemplateTypeParameterKind:
195 case MDTemplateValueParameterKind:
196 case MDGlobalVariableKind:
197 case MDLocalVariableKind:
198 case MDObjCPropertyKind:
199 case MDImportedEntityKind:
206 struct simplify_type<const TypedDebugNodeRef<T>> {
207 typedef Metadata *SimpleType;
208 static SimpleType getSimplifiedValue(const TypedDebugNodeRef<T> &MD) {
214 struct simplify_type<TypedDebugNodeRef<T>>
215 : simplify_type<const TypedDebugNodeRef<T>> {};
217 /// \brief Generic tagged DWARF-like metadata node.
219 /// An un-specialized DWARF-like metadata node. The first operand is a
220 /// (possibly empty) null-separated \a MDString header that contains arbitrary
221 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
222 /// to other metadata.
223 class GenericDebugNode : public DebugNode {
224 friend class LLVMContextImpl;
227 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
228 unsigned Tag, ArrayRef<Metadata *> Ops1,
229 ArrayRef<Metadata *> Ops2)
230 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
233 ~GenericDebugNode() { dropAllReferences(); }
235 void setHash(unsigned Hash) { SubclassData32 = Hash; }
236 void recalculateHash();
238 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
240 ArrayRef<Metadata *> DwarfOps,
242 bool ShouldCreate = true) {
243 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
244 DwarfOps, Storage, ShouldCreate);
247 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
249 ArrayRef<Metadata *> DwarfOps,
251 bool ShouldCreate = true);
253 TempGenericDebugNode cloneImpl() const {
255 getContext(), getTag(), getHeader(),
256 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
260 unsigned getHash() const { return SubclassData32; }
262 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
263 ArrayRef<Metadata *> DwarfOps),
264 (Tag, Header, DwarfOps))
265 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
266 ArrayRef<Metadata *> DwarfOps),
267 (Tag, Header, DwarfOps))
269 /// \brief Return a (temporary) clone of this.
270 TempGenericDebugNode clone() const { return cloneImpl(); }
272 unsigned getTag() const { return SubclassData16; }
273 StringRef getHeader() const { return getStringOperand(0); }
275 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
276 op_iterator dwarf_op_end() const { return op_end(); }
277 op_range dwarf_operands() const {
278 return op_range(dwarf_op_begin(), dwarf_op_end());
281 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
282 const MDOperand &getDwarfOperand(unsigned I) const {
283 return getOperand(I + 1);
285 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
286 replaceOperandWith(I + 1, New);
289 static bool classof(const Metadata *MD) {
290 return MD->getMetadataID() == GenericDebugNodeKind;
294 /// \brief Array subrange.
296 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
298 class MDSubrange : public DebugNode {
299 friend class LLVMContextImpl;
305 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count, int64_t Lo)
306 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
308 Count(Count), Lo(Lo) {}
311 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
312 StorageType Storage, bool ShouldCreate = true);
314 TempMDSubrange cloneImpl() const {
315 return getTemporary(getContext(), getCount(), getLo());
319 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t Lo = 0), (Count, Lo))
321 TempMDSubrange clone() const { return cloneImpl(); }
323 int64_t getLo() const { return Lo; }
324 int64_t getCount() const { return Count; }
326 static bool classof(const Metadata *MD) {
327 return MD->getMetadataID() == MDSubrangeKind;
331 /// \brief Enumeration value.
333 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
334 /// longer creates a type cycle.
335 class MDEnumerator : public DebugNode {
336 friend class LLVMContextImpl;
341 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
342 ArrayRef<Metadata *> Ops)
343 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
347 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
348 StringRef Name, StorageType Storage,
349 bool ShouldCreate = true) {
350 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
353 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
354 MDString *Name, StorageType Storage,
355 bool ShouldCreate = true);
357 TempMDEnumerator cloneImpl() const {
358 return getTemporary(getContext(), getValue(), getName());
362 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
364 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
367 TempMDEnumerator clone() const { return cloneImpl(); }
369 int64_t getValue() const { return Value; }
370 StringRef getName() const { return getStringOperand(0); }
372 MDString *getRawName() const { return getOperandAs<MDString>(0); }
374 static bool classof(const Metadata *MD) {
375 return MD->getMetadataID() == MDEnumeratorKind;
379 /// \brief Base class for scope-like contexts.
381 /// Base class for lexical scopes and types (which are also declaration
384 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
385 class MDScope : public DebugNode {
387 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
388 ArrayRef<Metadata *> Ops)
389 : DebugNode(C, ID, Storage, Tag, Ops) {}
393 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
395 /// \brief Return the raw underlying file.
397 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
398 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
399 /// this. Otherwise, return the first operand, which is where all other
400 /// subclasses store their file pointer.
401 Metadata *getRawFile() const {
402 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
403 : static_cast<Metadata *>(getOperand(0));
406 MDScopeRef getRef() const { return MDScopeRef::get(this); }
408 static bool classof(const Metadata *MD) {
409 switch (MD->getMetadataID()) {
412 case MDBasicTypeKind:
413 case MDDerivedTypeKind:
414 case MDCompositeTypeKind:
415 case MDSubroutineTypeKind:
417 case MDCompileUnitKind:
418 case MDSubprogramKind:
419 case MDLexicalBlockKind:
420 case MDLexicalBlockFileKind:
421 case MDNamespaceKind:
429 /// TODO: Merge with directory/file node (including users).
430 /// TODO: Canonicalize paths on creation.
431 class MDFile : public MDScope {
432 friend class LLVMContextImpl;
435 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
436 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
439 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
440 StringRef Directory, StorageType Storage,
441 bool ShouldCreate = true) {
442 return getImpl(Context, getCanonicalMDString(Context, Filename),
443 getCanonicalMDString(Context, Directory), Storage,
446 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
447 MDString *Directory, StorageType Storage,
448 bool ShouldCreate = true);
450 TempMDFile cloneImpl() const {
451 return getTemporary(getContext(), getFilename(), getDirectory());
455 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
456 (Filename, Directory))
457 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
458 (Filename, Directory))
460 TempMDFile clone() const { return cloneImpl(); }
462 StringRef getFilename() const { return getStringOperand(0); }
463 StringRef getDirectory() const { return getStringOperand(1); }
465 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
466 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
468 static bool classof(const Metadata *MD) {
469 return MD->getMetadataID() == MDFileKind;
473 /// \brief Base class for types.
475 /// TODO: Remove the hardcoded name and context, since many types don't use
477 /// TODO: Split up flags.
478 class MDType : public MDScope {
482 uint64_t AlignInBits;
483 uint64_t OffsetInBits;
486 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
487 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
488 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
489 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
490 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
491 OffsetInBits(OffsetInBits) {}
495 TempMDType clone() const {
496 return TempMDType(cast<MDType>(MDNode::clone().release()));
499 unsigned getLine() const { return Line; }
500 uint64_t getSizeInBits() const { return SizeInBits; }
501 uint64_t getAlignInBits() const { return AlignInBits; }
502 uint64_t getOffsetInBits() const { return OffsetInBits; }
503 unsigned getFlags() const { return Flags; }
505 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
506 StringRef getName() const { return getStringOperand(2); }
509 Metadata *getRawScope() const { return getOperand(1); }
510 MDString *getRawName() const { return getOperandAs<MDString>(2); }
512 void setFlags(unsigned NewFlags) {
513 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
517 MDTypeRef getRef() const { return MDTypeRef::get(this); }
519 static bool classof(const Metadata *MD) {
520 switch (MD->getMetadataID()) {
523 case MDBasicTypeKind:
524 case MDDerivedTypeKind:
525 case MDCompositeTypeKind:
526 case MDSubroutineTypeKind:
532 /// \brief Basic type.
534 /// TODO: Split out DW_TAG_unspecified_type.
535 /// TODO: Drop unused accessors.
536 class MDBasicType : public MDType {
537 friend class LLVMContextImpl;
542 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
543 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
544 ArrayRef<Metadata *> Ops)
545 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
547 Encoding(Encoding) {}
550 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
551 StringRef Name, uint64_t SizeInBits,
552 uint64_t AlignInBits, unsigned Encoding,
553 StorageType Storage, bool ShouldCreate = true) {
554 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
555 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
557 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
558 MDString *Name, uint64_t SizeInBits,
559 uint64_t AlignInBits, unsigned Encoding,
560 StorageType Storage, bool ShouldCreate = true);
562 TempMDBasicType cloneImpl() const {
563 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
564 getAlignInBits(), getEncoding());
568 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
569 (Tag, Name, 0, 0, 0))
570 DEFINE_MDNODE_GET(MDBasicType,
571 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
572 uint64_t AlignInBits, unsigned Encoding),
573 (Tag, Name, SizeInBits, AlignInBits, Encoding))
574 DEFINE_MDNODE_GET(MDBasicType,
575 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
576 uint64_t AlignInBits, unsigned Encoding),
577 (Tag, Name, SizeInBits, AlignInBits, Encoding))
579 TempMDBasicType clone() const { return cloneImpl(); }
581 unsigned getEncoding() const { return Encoding; }
583 static bool classof(const Metadata *MD) {
584 return MD->getMetadataID() == MDBasicTypeKind;
588 /// \brief Base class for MDDerivedType and MDCompositeType.
590 /// TODO: Delete; they're not really related.
591 class MDDerivedTypeBase : public MDType {
593 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
594 unsigned Tag, unsigned Line, uint64_t SizeInBits,
595 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
596 ArrayRef<Metadata *> Ops)
597 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
599 ~MDDerivedTypeBase() {}
602 MDTypeRef getBaseType() const { return MDTypeRef(getRawBaseType()); }
603 Metadata *getRawBaseType() const { return getOperand(3); }
605 static bool classof(const Metadata *MD) {
606 return MD->getMetadataID() == MDDerivedTypeKind ||
607 MD->getMetadataID() == MDCompositeTypeKind ||
608 MD->getMetadataID() == MDSubroutineTypeKind;
612 /// \brief Derived types.
614 /// This includes qualified types, pointers, references, friends, typedefs, and
617 /// TODO: Split out members (inheritance, fields, methods, etc.).
618 class MDDerivedType : public MDDerivedTypeBase {
619 friend class LLVMContextImpl;
622 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
623 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
624 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
625 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
626 AlignInBits, OffsetInBits, Flags, Ops) {}
629 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
630 StringRef Name, MDFile *File, unsigned Line,
631 MDScopeRef Scope, MDTypeRef BaseType,
632 uint64_t SizeInBits, uint64_t AlignInBits,
633 uint64_t OffsetInBits, unsigned Flags,
634 Metadata *ExtraData, StorageType Storage,
635 bool ShouldCreate = true) {
636 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
637 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
638 Flags, ExtraData, Storage, ShouldCreate);
640 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
641 MDString *Name, Metadata *File, unsigned Line,
642 Metadata *Scope, Metadata *BaseType,
643 uint64_t SizeInBits, uint64_t AlignInBits,
644 uint64_t OffsetInBits, unsigned Flags,
645 Metadata *ExtraData, StorageType Storage,
646 bool ShouldCreate = true);
648 TempMDDerivedType cloneImpl() const {
649 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
650 getScope(), getBaseType(), getSizeInBits(),
651 getAlignInBits(), getOffsetInBits(), getFlags(),
656 DEFINE_MDNODE_GET(MDDerivedType,
657 (unsigned Tag, MDString *Name, Metadata *File,
658 unsigned Line, Metadata *Scope, Metadata *BaseType,
659 uint64_t SizeInBits, uint64_t AlignInBits,
660 uint64_t OffsetInBits, unsigned Flags,
661 Metadata *ExtraData = nullptr),
662 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
663 AlignInBits, OffsetInBits, Flags, ExtraData))
664 DEFINE_MDNODE_GET(MDDerivedType,
665 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
666 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
667 uint64_t AlignInBits, uint64_t OffsetInBits,
668 unsigned Flags, Metadata *ExtraData = nullptr),
669 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
670 AlignInBits, OffsetInBits, Flags, ExtraData))
672 TempMDDerivedType clone() const { return cloneImpl(); }
674 /// \brief Get extra data associated with this derived type.
676 /// Class type for pointer-to-members, objective-c property node for ivars,
677 /// or global constant wrapper for static members.
679 /// TODO: Separate out types that need this extra operand: pointer-to-member
680 /// types and member fields (static members and ivars).
681 Metadata *getExtraData() const { return getRawExtraData(); }
682 Metadata *getRawExtraData() const { return getOperand(4); }
684 static bool classof(const Metadata *MD) {
685 return MD->getMetadataID() == MDDerivedTypeKind;
689 /// \brief Base class for MDCompositeType and MDSubroutineType.
691 /// TODO: Delete; they're not really related.
692 class MDCompositeTypeBase : public MDDerivedTypeBase {
693 unsigned RuntimeLang;
696 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
697 unsigned Tag, unsigned Line, unsigned RuntimeLang,
698 uint64_t SizeInBits, uint64_t AlignInBits,
699 uint64_t OffsetInBits, unsigned Flags,
700 ArrayRef<Metadata *> Ops)
701 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
702 OffsetInBits, Flags, Ops),
703 RuntimeLang(RuntimeLang) {}
704 ~MDCompositeTypeBase() {}
707 MDTuple *getElements() const {
708 return cast_or_null<MDTuple>(getRawElements());
710 MDTypeRef getVTableHolder() const { return MDTypeRef(getRawVTableHolder()); }
711 MDTemplateParameterArray getTemplateParams() const {
712 return cast_or_null<MDTuple>(getRawTemplateParams());
714 StringRef getIdentifier() const { return getStringOperand(7); }
715 unsigned getRuntimeLang() const { return RuntimeLang; }
717 Metadata *getRawElements() const { return getOperand(4); }
718 Metadata *getRawVTableHolder() const { return getOperand(5); }
719 Metadata *getRawTemplateParams() const { return getOperand(6); }
720 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
722 /// \brief Replace operands.
724 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
725 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
726 /// of its movement if necessary.
728 void replaceElements(MDTuple *Elements) {
730 if (auto *Old = cast_or_null<MDTuple>(getElements()))
731 for (const auto &Op : Old->operands())
732 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
733 "Lost a member during member list replacement");
735 replaceOperandWith(4, Elements);
737 void replaceVTableHolder(MDTypeRef VTableHolder) {
738 replaceOperandWith(5, VTableHolder);
740 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
741 replaceOperandWith(6, TemplateParams);
745 static bool classof(const Metadata *MD) {
746 return MD->getMetadataID() == MDCompositeTypeKind ||
747 MD->getMetadataID() == MDSubroutineTypeKind;
751 /// \brief Composite types.
753 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
754 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
755 class MDCompositeType : public MDCompositeTypeBase {
756 friend class LLVMContextImpl;
759 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
760 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
761 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
762 ArrayRef<Metadata *> Ops)
763 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
764 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
766 ~MDCompositeType() {}
768 static MDCompositeType *
769 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
770 unsigned Line, MDScopeRef Scope, MDTypeRef BaseType,
771 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
772 uint64_t Flags, MDTuple *Elements, unsigned RuntimeLang,
773 MDTypeRef VTableHolder, MDTemplateParameterArray TemplateParams,
774 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
775 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
776 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
777 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
778 getCanonicalMDString(Context, Identifier), Storage,
781 static MDCompositeType *
782 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
783 unsigned Line, Metadata *Scope, Metadata *BaseType,
784 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
785 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
786 Metadata *VTableHolder, Metadata *TemplateParams,
787 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
789 TempMDCompositeType cloneImpl() const {
790 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
791 getScope(), getBaseType(), getSizeInBits(),
792 getAlignInBits(), getOffsetInBits(), getFlags(),
793 getElements(), getRuntimeLang(), getVTableHolder(),
794 getTemplateParams(), getIdentifier());
798 DEFINE_MDNODE_GET(MDCompositeType,
799 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
800 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
801 uint64_t AlignInBits, uint64_t OffsetInBits,
802 unsigned Flags, MDTuple *Elements, unsigned RuntimeLang,
803 MDTypeRef VTableHolder,
804 MDTemplateParameterArray TemplateParams = nullptr,
805 StringRef Identifier = ""),
806 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
807 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
808 VTableHolder, TemplateParams, Identifier))
809 DEFINE_MDNODE_GET(MDCompositeType,
810 (unsigned Tag, MDString *Name, Metadata *File,
811 unsigned Line, Metadata *Scope, Metadata *BaseType,
812 uint64_t SizeInBits, uint64_t AlignInBits,
813 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
814 unsigned RuntimeLang, Metadata *VTableHolder,
815 Metadata *TemplateParams = nullptr,
816 MDString *Identifier = nullptr),
817 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
818 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
819 VTableHolder, TemplateParams, Identifier))
821 TempMDCompositeType clone() const { return cloneImpl(); }
823 static bool classof(const Metadata *MD) {
824 return MD->getMetadataID() == MDCompositeTypeKind;
828 template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) {
830 if (auto *Composite = dyn_cast<MDCompositeType>(N))
831 if (auto *S = Composite->getRawIdentifier())
832 return TypedDebugNodeRef<T>(S);
833 return TypedDebugNodeRef<T>(N);
836 /// \brief Type array for a subprogram.
838 /// TODO: Detach from CompositeType, and fold the array of types in directly
840 class MDSubroutineType : public MDCompositeTypeBase {
841 friend class LLVMContextImpl;
844 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
845 ArrayRef<Metadata *> Ops)
846 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
847 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
849 ~MDSubroutineType() {}
851 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
852 Metadata *TypeArray, StorageType Storage,
853 bool ShouldCreate = true);
855 TempMDSubroutineType cloneImpl() const {
856 return getTemporary(getContext(), getFlags(), getTypeArray());
860 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
863 TempMDSubroutineType clone() const { return cloneImpl(); }
865 MDTypeRefArray getTypeArray() const { return getElements(); }
866 Metadata *getRawTypeArray() const { return getRawElements(); }
868 static bool classof(const Metadata *MD) {
869 return MD->getMetadataID() == MDSubroutineTypeKind;
873 /// \brief Compile unit.
874 class MDCompileUnit : public MDScope {
875 friend class LLVMContextImpl;
878 unsigned SourceLanguage;
880 unsigned RuntimeVersion;
881 unsigned EmissionKind;
883 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
884 bool IsOptimized, unsigned RuntimeVersion,
885 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
886 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
887 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
888 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
891 static MDCompileUnit *
892 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
893 StringRef Producer, bool IsOptimized, StringRef Flags,
894 unsigned RuntimeVersion, StringRef SplitDebugFilename,
895 unsigned EmissionKind, MDTuple *EnumTypes, MDTuple *RetainedTypes,
896 MDTuple *Subprograms, MDTuple *GlobalVariables,
897 MDTuple *ImportedEntities, StorageType Storage,
898 bool ShouldCreate = true) {
899 return getImpl(Context, SourceLanguage, File,
900 getCanonicalMDString(Context, Producer), IsOptimized,
901 getCanonicalMDString(Context, Flags), RuntimeVersion,
902 getCanonicalMDString(Context, SplitDebugFilename),
903 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
904 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
906 static MDCompileUnit *
907 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
908 MDString *Producer, bool IsOptimized, MDString *Flags,
909 unsigned RuntimeVersion, MDString *SplitDebugFilename,
910 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
911 Metadata *Subprograms, Metadata *GlobalVariables,
912 Metadata *ImportedEntities, StorageType Storage,
913 bool ShouldCreate = true);
915 TempMDCompileUnit cloneImpl() const {
917 getContext(), getSourceLanguage(), getFile(), getProducer(),
918 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
919 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
920 getGlobalVariables(), getImportedEntities());
924 DEFINE_MDNODE_GET(MDCompileUnit,
925 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
926 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
927 StringRef SplitDebugFilename, unsigned EmissionKind,
928 MDTuple *EnumTypes, MDTuple *RetainedTypes,
929 MDTuple *Subprograms, MDTuple *GlobalVariables,
930 MDTuple *ImportedEntities),
931 (SourceLanguage, File, Producer, IsOptimized, Flags,
932 RuntimeVersion, SplitDebugFilename, EmissionKind,
933 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
935 DEFINE_MDNODE_GET(MDCompileUnit,
936 (unsigned SourceLanguage, Metadata *File,
937 MDString *Producer, bool IsOptimized, MDString *Flags,
938 unsigned RuntimeVersion, MDString *SplitDebugFilename,
939 unsigned EmissionKind, Metadata *EnumTypes,
940 Metadata *RetainedTypes, Metadata *Subprograms,
941 Metadata *GlobalVariables, Metadata *ImportedEntities),
942 (SourceLanguage, File, Producer, IsOptimized, Flags,
943 RuntimeVersion, SplitDebugFilename, EmissionKind,
944 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
947 TempMDCompileUnit clone() const { return cloneImpl(); }
949 unsigned getSourceLanguage() const { return SourceLanguage; }
950 bool isOptimized() const { return IsOptimized; }
951 unsigned getRuntimeVersion() const { return RuntimeVersion; }
952 unsigned getEmissionKind() const { return EmissionKind; }
953 StringRef getProducer() const { return getStringOperand(1); }
954 StringRef getFlags() const { return getStringOperand(2); }
955 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
956 MDCompositeTypeArray getEnumTypes() const {
957 return cast_or_null<MDTuple>(getRawEnumTypes());
959 MDTypeArray getRetainedTypes() const {
960 return cast_or_null<MDTuple>(getRawRetainedTypes());
962 MDSubprogramArray getSubprograms() const {
963 return cast_or_null<MDTuple>(getRawSubprograms());
965 MDGlobalVariableArray getGlobalVariables() const {
966 return cast_or_null<MDTuple>(getRawGlobalVariables());
968 MDImportedEntityArray getImportedEntities() const {
969 return cast_or_null<MDTuple>(getRawImportedEntities());
972 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
973 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
974 MDString *getRawSplitDebugFilename() const {
975 return getOperandAs<MDString>(3);
977 Metadata *getRawEnumTypes() const { return getOperand(4); }
978 Metadata *getRawRetainedTypes() const { return getOperand(5); }
979 Metadata *getRawSubprograms() const { return getOperand(6); }
980 Metadata *getRawGlobalVariables() const { return getOperand(7); }
981 Metadata *getRawImportedEntities() const { return getOperand(8); }
983 /// \brief Replace arrays.
985 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
986 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
987 /// MDCompileUnit should be fairly rare.
989 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
990 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
993 static bool classof(const Metadata *MD) {
994 return MD->getMetadataID() == MDCompileUnitKind;
998 /// \brief A scope for locals.
1000 /// A legal scope for lexical blocks, local variables, and debug info
1001 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
1002 /// MDLexicalBlockFile.
1003 class MDLocalScope : public MDScope {
1005 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1006 ArrayRef<Metadata *> Ops)
1007 : MDScope(C, ID, Storage, Tag, Ops) {}
1011 /// \brief Get the subprogram for this scope.
1013 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
1015 MDSubprogram *getSubprogram() const;
1017 static bool classof(const Metadata *MD) {
1018 return MD->getMetadataID() == MDSubprogramKind ||
1019 MD->getMetadataID() == MDLexicalBlockKind ||
1020 MD->getMetadataID() == MDLexicalBlockFileKind;
1024 /// \brief Debug location.
1026 /// A debug location in source code, used for debug info and otherwise.
1027 class MDLocation : public MDNode {
1028 friend class LLVMContextImpl;
1029 friend class MDNode;
1031 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
1032 unsigned Column, ArrayRef<Metadata *> MDs);
1033 ~MDLocation() { dropAllReferences(); }
1035 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1036 unsigned Column, Metadata *Scope,
1037 Metadata *InlinedAt, StorageType Storage,
1038 bool ShouldCreate = true);
1039 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1040 unsigned Column, MDLocalScope *Scope,
1041 MDLocation *InlinedAt, StorageType Storage,
1042 bool ShouldCreate = true) {
1043 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1044 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1047 TempMDLocation cloneImpl() const {
1048 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
1052 // Disallow replacing operands.
1053 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1056 DEFINE_MDNODE_GET(MDLocation,
1057 (unsigned Line, unsigned Column, Metadata *Scope,
1058 Metadata *InlinedAt = nullptr),
1059 (Line, Column, Scope, InlinedAt))
1060 DEFINE_MDNODE_GET(MDLocation,
1061 (unsigned Line, unsigned Column, MDLocalScope *Scope,
1062 MDLocation *InlinedAt = nullptr),
1063 (Line, Column, Scope, InlinedAt))
1065 /// \brief Return a (temporary) clone of this.
1066 TempMDLocation clone() const { return cloneImpl(); }
1068 unsigned getLine() const { return SubclassData32; }
1069 unsigned getColumn() const { return SubclassData16; }
1070 MDLocalScope *getScope() const {
1071 return cast<MDLocalScope>(getRawScope());
1073 MDLocation *getInlinedAt() const {
1074 return cast_or_null<MDLocation>(getRawInlinedAt());
1077 /// \brief Get the scope where this is inlined.
1079 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1081 MDLocalScope *getInlinedAtScope() const {
1082 if (auto *IA = getInlinedAt())
1083 return IA->getInlinedAtScope();
1087 Metadata *getRawScope() const { return getOperand(0); }
1088 Metadata *getRawInlinedAt() const {
1089 if (getNumOperands() == 2)
1090 return getOperand(1);
1094 static bool classof(const Metadata *MD) {
1095 return MD->getMetadataID() == MDLocationKind;
1099 /// \brief Subprogram description.
1101 /// TODO: Remove DisplayName. It's always equal to Name.
1102 /// TODO: Split up flags.
1103 class MDSubprogram : public MDLocalScope {
1104 friend class LLVMContextImpl;
1105 friend class MDNode;
1109 unsigned Virtuality;
1110 unsigned VirtualIndex;
1116 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1117 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1118 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
1119 bool IsOptimized, ArrayRef<Metadata *> Ops)
1120 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1122 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
1123 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
1124 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
1127 static MDSubprogram *
1128 getImpl(LLVMContext &Context, MDScopeRef Scope, StringRef Name,
1129 StringRef LinkageName, MDFile *File, unsigned Line,
1130 MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1131 unsigned ScopeLine, MDTypeRef ContainingType, unsigned Virtuality,
1132 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1133 ConstantAsMetadata *Function, MDTemplateParameterArray TemplateParams,
1134 MDSubprogram *Declaration, MDLocalVariableArray Variables,
1135 StorageType Storage, bool ShouldCreate = true) {
1136 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1137 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1138 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1139 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1140 TemplateParams, Declaration, Variables, Storage,
1143 static MDSubprogram *
1144 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1145 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1146 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1147 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1148 unsigned Flags, bool IsOptimized, Metadata *Function,
1149 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1150 StorageType Storage, bool ShouldCreate = true);
1152 TempMDSubprogram cloneImpl() const {
1153 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1154 getFile(), getLine(), getType(), isLocalToUnit(),
1155 isDefinition(), getScopeLine(), getContainingType(),
1156 getVirtuality(), getVirtualIndex(), getFlags(),
1157 isOptimized(), getFunction(), getTemplateParams(),
1158 getDeclaration(), getVariables());
1162 DEFINE_MDNODE_GET(MDSubprogram,
1163 (MDScopeRef Scope, StringRef Name, StringRef LinkageName,
1164 MDFile *File, unsigned Line, MDSubroutineType *Type,
1165 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1166 MDTypeRef ContainingType, unsigned Virtuality,
1167 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1168 ConstantAsMetadata *Function = nullptr,
1169 MDTemplateParameterArray TemplateParams = nullptr,
1170 MDSubprogram *Declaration = nullptr,
1171 MDLocalVariableArray Variables = nullptr),
1172 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1173 IsDefinition, ScopeLine, ContainingType, Virtuality,
1174 VirtualIndex, Flags, IsOptimized, Function, TemplateParams,
1175 Declaration, Variables))
1178 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1179 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1180 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1181 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1182 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1183 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1184 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1185 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1186 Function, TemplateParams, Declaration, Variables))
1188 TempMDSubprogram clone() const { return cloneImpl(); }
1191 unsigned getLine() const { return Line; }
1192 unsigned getVirtuality() const { return Virtuality; }
1193 unsigned getVirtualIndex() const { return VirtualIndex; }
1194 unsigned getScopeLine() const { return ScopeLine; }
1195 unsigned getFlags() const { return Flags; }
1196 bool isLocalToUnit() const { return IsLocalToUnit; }
1197 bool isDefinition() const { return IsDefinition; }
1198 bool isOptimized() const { return IsOptimized; }
1200 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
1202 StringRef getName() const { return getStringOperand(2); }
1203 StringRef getDisplayName() const { return getStringOperand(3); }
1204 StringRef getLinkageName() const { return getStringOperand(4); }
1206 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1207 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1209 MDSubroutineType *getType() const {
1210 return cast_or_null<MDSubroutineType>(getRawType());
1212 MDTypeRef getContainingType() const {
1213 return MDTypeRef(getRawContainingType());
1216 ConstantAsMetadata *getFunction() const {
1217 return cast_or_null<ConstantAsMetadata>(getRawFunction());
1219 MDTemplateParameterArray getTemplateParams() const {
1220 return cast_or_null<MDTuple>(getRawTemplateParams());
1222 MDSubprogram *getDeclaration() const {
1223 return cast_or_null<MDSubprogram>(getRawDeclaration());
1225 MDLocalVariableArray getVariables() const {
1226 return cast_or_null<MDTuple>(getRawVariables());
1229 Metadata *getRawScope() const { return getOperand(1); }
1230 Metadata *getRawType() const { return getOperand(5); }
1231 Metadata *getRawContainingType() const { return getOperand(6); }
1232 Metadata *getRawFunction() const { return getOperand(7); }
1233 Metadata *getRawTemplateParams() const { return getOperand(8); }
1234 Metadata *getRawDeclaration() const { return getOperand(9); }
1235 Metadata *getRawVariables() const { return getOperand(10); }
1237 /// \brief Replace the function.
1239 /// If \a isUniqued() and not \a isResolved(), this could node will be
1240 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1241 /// that's a problem.
1243 void replaceFunction(Function *F);
1244 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1245 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1248 static bool classof(const Metadata *MD) {
1249 return MD->getMetadataID() == MDSubprogramKind;
1253 class MDLexicalBlockBase : public MDLocalScope {
1255 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1256 ArrayRef<Metadata *> Ops)
1257 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1258 ~MDLexicalBlockBase() {}
1261 MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
1263 Metadata *getRawScope() const { return getOperand(1); }
1265 static bool classof(const Metadata *MD) {
1266 return MD->getMetadataID() == MDLexicalBlockKind ||
1267 MD->getMetadataID() == MDLexicalBlockFileKind;
1271 class MDLexicalBlock : public MDLexicalBlockBase {
1272 friend class LLVMContextImpl;
1273 friend class MDNode;
1278 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1279 unsigned Column, ArrayRef<Metadata *> Ops)
1280 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1282 ~MDLexicalBlock() {}
1284 static MDLexicalBlock *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1285 MDFile *File, unsigned Line, unsigned Column,
1286 StorageType Storage,
1287 bool ShouldCreate = true) {
1288 return getImpl(Context, static_cast<Metadata *>(Scope),
1289 static_cast<Metadata *>(File), Line, Column, Storage,
1293 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1294 Metadata *File, unsigned Line, unsigned Column,
1295 StorageType Storage, bool ShouldCreate = true);
1297 TempMDLexicalBlock cloneImpl() const {
1298 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1303 DEFINE_MDNODE_GET(MDLexicalBlock, (MDLocalScope * Scope, MDFile *File,
1304 unsigned Line, unsigned Column),
1305 (Scope, File, Line, Column))
1306 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1307 unsigned Line, unsigned Column),
1308 (Scope, File, Line, Column))
1310 TempMDLexicalBlock clone() const { return cloneImpl(); }
1312 unsigned getLine() const { return Line; }
1313 unsigned getColumn() const { return Column; }
1315 static bool classof(const Metadata *MD) {
1316 return MD->getMetadataID() == MDLexicalBlockKind;
1320 class MDLexicalBlockFile : public MDLexicalBlockBase {
1321 friend class LLVMContextImpl;
1322 friend class MDNode;
1324 unsigned Discriminator;
1326 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1327 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1328 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1329 Discriminator(Discriminator) {}
1330 ~MDLexicalBlockFile() {}
1332 static MDLexicalBlockFile *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1333 MDFile *File, unsigned Discriminator,
1334 StorageType Storage,
1335 bool ShouldCreate = true) {
1336 return getImpl(Context, static_cast<Metadata *>(Scope),
1337 static_cast<Metadata *>(File), Discriminator, Storage,
1341 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1342 Metadata *File, unsigned Discriminator,
1343 StorageType Storage,
1344 bool ShouldCreate = true);
1346 TempMDLexicalBlockFile cloneImpl() const {
1347 return getTemporary(getContext(), getScope(), getFile(),
1348 getDiscriminator());
1352 DEFINE_MDNODE_GET(MDLexicalBlockFile, (MDLocalScope * Scope, MDFile *File,
1353 unsigned Discriminator),
1354 (Scope, File, Discriminator))
1355 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1356 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1357 (Scope, File, Discriminator))
1359 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1361 unsigned getDiscriminator() const { return Discriminator; }
1363 static bool classof(const Metadata *MD) {
1364 return MD->getMetadataID() == MDLexicalBlockFileKind;
1368 class MDNamespace : public MDScope {
1369 friend class LLVMContextImpl;
1370 friend class MDNode;
1374 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1375 ArrayRef<Metadata *> Ops)
1376 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1381 static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
1382 MDFile *File, StringRef Name, unsigned Line,
1383 StorageType Storage, bool ShouldCreate = true) {
1384 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1385 Line, Storage, ShouldCreate);
1387 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1388 Metadata *File, MDString *Name, unsigned Line,
1389 StorageType Storage, bool ShouldCreate = true);
1391 TempMDNamespace cloneImpl() const {
1392 return getTemporary(getContext(), getScope(), getFile(), getName(),
1397 DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
1399 (Scope, File, Name, Line))
1400 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1401 MDString *Name, unsigned Line),
1402 (Scope, File, Name, Line))
1404 TempMDNamespace clone() const { return cloneImpl(); }
1406 unsigned getLine() const { return Line; }
1407 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1408 StringRef getName() const { return getStringOperand(2); }
1410 Metadata *getRawScope() const { return getOperand(1); }
1411 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1413 static bool classof(const Metadata *MD) {
1414 return MD->getMetadataID() == MDNamespaceKind;
1418 /// \brief Base class for template parameters.
1419 class MDTemplateParameter : public DebugNode {
1421 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1422 unsigned Tag, ArrayRef<Metadata *> Ops)
1423 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1424 ~MDTemplateParameter() {}
1427 StringRef getName() const { return getStringOperand(0); }
1428 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1430 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1431 Metadata *getRawType() const { return getOperand(1); }
1433 static bool classof(const Metadata *MD) {
1434 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1435 MD->getMetadataID() == MDTemplateValueParameterKind;
1439 class MDTemplateTypeParameter : public MDTemplateParameter {
1440 friend class LLVMContextImpl;
1441 friend class MDNode;
1443 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1444 ArrayRef<Metadata *> Ops)
1445 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1446 dwarf::DW_TAG_template_type_parameter, Ops) {}
1447 ~MDTemplateTypeParameter() {}
1449 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1450 MDTypeRef Type, StorageType Storage,
1451 bool ShouldCreate = true) {
1452 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1455 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1456 Metadata *Type, StorageType Storage,
1457 bool ShouldCreate = true);
1459 TempMDTemplateTypeParameter cloneImpl() const {
1460 return getTemporary(getContext(), getName(), getType());
1464 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, MDTypeRef Type),
1466 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1469 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1471 static bool classof(const Metadata *MD) {
1472 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1476 class MDTemplateValueParameter : public MDTemplateParameter {
1477 friend class LLVMContextImpl;
1478 friend class MDNode;
1480 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1481 unsigned Tag, ArrayRef<Metadata *> Ops)
1482 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1484 ~MDTemplateValueParameter() {}
1486 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1487 StringRef Name, MDTypeRef Type,
1488 Metadata *Value, StorageType Storage,
1489 bool ShouldCreate = true) {
1490 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1491 Value, Storage, ShouldCreate);
1493 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1494 MDString *Name, Metadata *Type,
1495 Metadata *Value, StorageType Storage,
1496 bool ShouldCreate = true);
1498 TempMDTemplateValueParameter cloneImpl() const {
1499 return getTemporary(getContext(), getTag(), getName(), getType(),
1504 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1505 MDTypeRef Type, Metadata *Value),
1506 (Tag, Name, Type, Value))
1507 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1508 Metadata *Type, Metadata *Value),
1509 (Tag, Name, Type, Value))
1511 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1513 Metadata *getValue() const { return getOperand(2); }
1515 static bool classof(const Metadata *MD) {
1516 return MD->getMetadataID() == MDTemplateValueParameterKind;
1520 /// \brief Base class for variables.
1522 /// TODO: Hardcode to DW_TAG_variable.
1523 class MDVariable : public DebugNode {
1527 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1528 unsigned Line, ArrayRef<Metadata *> Ops)
1529 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1533 unsigned getLine() const { return Line; }
1534 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1535 StringRef getName() const { return getStringOperand(1); }
1536 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1537 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1539 Metadata *getRawScope() const { return getOperand(0); }
1540 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1541 Metadata *getRawFile() const { return getOperand(2); }
1542 Metadata *getRawType() const { return getOperand(3); }
1544 static bool classof(const Metadata *MD) {
1545 return MD->getMetadataID() == MDLocalVariableKind ||
1546 MD->getMetadataID() == MDGlobalVariableKind;
1550 /// \brief Global variables.
1552 /// TODO: Remove DisplayName. It's always equal to Name.
1553 class MDGlobalVariable : public MDVariable {
1554 friend class LLVMContextImpl;
1555 friend class MDNode;
1560 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1561 bool IsLocalToUnit, bool IsDefinition,
1562 ArrayRef<Metadata *> Ops)
1563 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1565 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1566 ~MDGlobalVariable() {}
1568 static MDGlobalVariable *
1569 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1570 StringRef LinkageName, MDFile *File, unsigned Line, MDTypeRef Type,
1571 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1572 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1573 bool ShouldCreate = true) {
1574 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1575 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1576 IsLocalToUnit, IsDefinition, Variable,
1577 StaticDataMemberDeclaration, Storage, ShouldCreate);
1579 static MDGlobalVariable *
1580 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1581 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1582 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1583 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1584 bool ShouldCreate = true);
1586 TempMDGlobalVariable cloneImpl() const {
1587 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1588 getFile(), getLine(), getType(), isLocalToUnit(),
1589 isDefinition(), getVariable(),
1590 getStaticDataMemberDeclaration());
1594 DEFINE_MDNODE_GET(MDGlobalVariable,
1595 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1596 MDFile *File, unsigned Line, MDTypeRef Type,
1597 bool IsLocalToUnit, bool IsDefinition,
1598 ConstantAsMetadata *Variable,
1599 MDDerivedType *StaticDataMemberDeclaration),
1600 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1601 IsDefinition, Variable, StaticDataMemberDeclaration))
1602 DEFINE_MDNODE_GET(MDGlobalVariable,
1603 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1604 Metadata *File, unsigned Line, Metadata *Type,
1605 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1606 Metadata *StaticDataMemberDeclaration),
1607 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1608 IsDefinition, Variable, StaticDataMemberDeclaration))
1610 TempMDGlobalVariable clone() const { return cloneImpl(); }
1612 bool isLocalToUnit() const { return IsLocalToUnit; }
1613 bool isDefinition() const { return IsDefinition; }
1614 StringRef getDisplayName() const { return getStringOperand(4); }
1615 StringRef getLinkageName() const { return getStringOperand(5); }
1616 ConstantAsMetadata *getVariable() const {
1617 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1619 MDDerivedType *getStaticDataMemberDeclaration() const {
1620 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1623 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1624 Metadata *getRawVariable() const { return getOperand(6); }
1625 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1627 static bool classof(const Metadata *MD) {
1628 return MD->getMetadataID() == MDGlobalVariableKind;
1632 /// \brief Local variable.
1634 /// TODO: Split between arguments and otherwise.
1635 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1636 /// TODO: Split up flags.
1637 class MDLocalVariable : public MDVariable {
1638 friend class LLVMContextImpl;
1639 friend class MDNode;
1644 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1645 unsigned Line, unsigned Arg, unsigned Flags,
1646 ArrayRef<Metadata *> Ops)
1647 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1649 ~MDLocalVariable() {}
1651 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1652 MDScope *Scope, StringRef Name, MDFile *File,
1653 unsigned Line, MDTypeRef Type, unsigned Arg,
1654 unsigned Flags, MDLocation *InlinedAt,
1655 StorageType Storage,
1656 bool ShouldCreate = true) {
1657 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1658 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1661 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1662 Metadata *Scope, MDString *Name,
1663 Metadata *File, unsigned Line, Metadata *Type,
1664 unsigned Arg, unsigned Flags,
1665 Metadata *InlinedAt, StorageType Storage,
1666 bool ShouldCreate = true);
1668 TempMDLocalVariable cloneImpl() const {
1669 return getTemporary(getContext(), getTag(), getScope(), getName(),
1670 getFile(), getLine(), getType(), getArg(), getFlags(),
1675 DEFINE_MDNODE_GET(MDLocalVariable,
1676 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1677 MDFile *File, unsigned Line, MDTypeRef Type, unsigned Arg,
1678 unsigned Flags, MDLocation *InlinedAt = nullptr),
1679 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1680 DEFINE_MDNODE_GET(MDLocalVariable,
1681 (unsigned Tag, Metadata *Scope, MDString *Name,
1682 Metadata *File, unsigned Line, Metadata *Type,
1683 unsigned Arg, unsigned Flags,
1684 Metadata *InlinedAt = nullptr),
1685 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1687 TempMDLocalVariable clone() const { return cloneImpl(); }
1689 /// \brief Get the local scope for this variable.
1691 /// Variables must be defined in a local scope.
1692 MDLocalScope *getScope() const {
1693 return cast<MDLocalScope>(MDVariable::getScope());
1696 unsigned getArg() const { return Arg; }
1697 unsigned getFlags() const { return Flags; }
1698 MDLocation *getInlinedAt() const {
1699 return cast_or_null<MDLocation>(getRawInlinedAt());
1702 Metadata *getRawInlinedAt() const { return getOperand(4); }
1704 /// \brief Check that a location is valid for this variable.
1706 /// Check that \c DL has the same inlined-at location as this variable,
1707 /// making them valid for the same \a DbgInfoIntrinsic.
1708 bool isValidLocationForIntrinsic(const MDLocation *DL) const {
1709 return getInlinedAt() == (DL ? DL->getInlinedAt() : nullptr);
1712 /// \brief Get an inlined version of this variable.
1714 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1715 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1716 if (InlinedAt == getInlinedAt())
1717 return const_cast<MDLocalVariable *>(this);
1718 auto Temp = clone();
1719 Temp->replaceOperandWith(4, InlinedAt);
1720 return replaceWithUniqued(std::move(Temp));
1722 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1724 static bool classof(const Metadata *MD) {
1725 return MD->getMetadataID() == MDLocalVariableKind;
1729 /// \brief DWARF expression.
1731 /// TODO: Co-allocate the expression elements.
1732 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1734 class MDExpression : public MDNode {
1735 friend class LLVMContextImpl;
1736 friend class MDNode;
1738 std::vector<uint64_t> Elements;
1740 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1741 : MDNode(C, MDExpressionKind, Storage, None),
1742 Elements(Elements.begin(), Elements.end()) {}
1745 static MDExpression *getImpl(LLVMContext &Context,
1746 ArrayRef<uint64_t> Elements, StorageType Storage,
1747 bool ShouldCreate = true);
1749 TempMDExpression cloneImpl() const {
1750 return getTemporary(getContext(), getElements());
1754 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1756 TempMDExpression clone() const { return cloneImpl(); }
1758 ArrayRef<uint64_t> getElements() const { return Elements; }
1760 unsigned getNumElements() const { return Elements.size(); }
1761 uint64_t getElement(unsigned I) const {
1762 assert(I < Elements.size() && "Index out of range");
1766 typedef ArrayRef<uint64_t>::iterator element_iterator;
1767 element_iterator elements_begin() const { return getElements().begin(); }
1768 element_iterator elements_end() const { return getElements().end(); }
1770 /// \brief A lightweight wrapper around an expression operand.
1772 /// TODO: Store arguments directly and change \a MDExpression to store a
1778 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1780 const uint64_t *get() const { return Op; }
1782 /// \brief Get the operand code.
1783 uint64_t getOp() const { return *Op; }
1785 /// \brief Get an argument to the operand.
1787 /// Never returns the operand itself.
1788 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1790 unsigned getNumArgs() const { return getSize() - 1; }
1792 /// \brief Return the size of the operand.
1794 /// Return the number of elements in the operand (1 + args).
1795 unsigned getSize() const;
1798 /// \brief An iterator for expression operands.
1799 class expr_op_iterator
1800 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1804 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1806 element_iterator getBase() const { return Op.get(); }
1807 const ExprOperand &operator*() const { return Op; }
1808 const ExprOperand *operator->() const { return &Op; }
1810 expr_op_iterator &operator++() {
1814 expr_op_iterator operator++(int) {
1815 expr_op_iterator T(*this);
1820 bool operator==(const expr_op_iterator &X) const {
1821 return getBase() == X.getBase();
1823 bool operator!=(const expr_op_iterator &X) const {
1824 return getBase() != X.getBase();
1828 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1831 /// \brief Visit the elements via ExprOperand wrappers.
1833 /// These range iterators visit elements through \a ExprOperand wrappers.
1834 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1837 /// \pre \a isValid() gives \c true.
1839 expr_op_iterator expr_op_begin() const {
1840 return expr_op_iterator(elements_begin());
1842 expr_op_iterator expr_op_end() const {
1843 return expr_op_iterator(elements_end());
1847 bool isValid() const;
1849 static bool classof(const Metadata *MD) {
1850 return MD->getMetadataID() == MDExpressionKind;
1854 class MDObjCProperty : public DebugNode {
1855 friend class LLVMContextImpl;
1856 friend class MDNode;
1859 unsigned Attributes;
1861 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1862 unsigned Attributes, ArrayRef<Metadata *> Ops)
1863 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1865 Line(Line), Attributes(Attributes) {}
1866 ~MDObjCProperty() {}
1868 static MDObjCProperty *
1869 getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
1870 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1871 MDType *Type, StorageType Storage, bool ShouldCreate = true) {
1872 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1873 getCanonicalMDString(Context, GetterName),
1874 getCanonicalMDString(Context, SetterName), Attributes, Type,
1875 Storage, ShouldCreate);
1877 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1878 Metadata *File, unsigned Line,
1879 MDString *GetterName, MDString *SetterName,
1880 unsigned Attributes, Metadata *Type,
1881 StorageType Storage, bool ShouldCreate = true);
1883 TempMDObjCProperty cloneImpl() const {
1884 return getTemporary(getContext(), getName(), getFile(), getLine(),
1885 getGetterName(), getSetterName(), getAttributes(),
1890 DEFINE_MDNODE_GET(MDObjCProperty,
1891 (StringRef Name, MDFile *File, unsigned Line,
1892 StringRef GetterName, StringRef SetterName,
1893 unsigned Attributes, MDType *Type),
1894 (Name, File, Line, GetterName, SetterName, Attributes,
1896 DEFINE_MDNODE_GET(MDObjCProperty,
1897 (MDString * Name, Metadata *File, unsigned Line,
1898 MDString *GetterName, MDString *SetterName,
1899 unsigned Attributes, Metadata *Type),
1900 (Name, File, Line, GetterName, SetterName, Attributes,
1903 TempMDObjCProperty clone() const { return cloneImpl(); }
1905 unsigned getLine() const { return Line; }
1906 unsigned getAttributes() const { return Attributes; }
1907 StringRef getName() const { return getStringOperand(0); }
1908 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1909 StringRef getGetterName() const { return getStringOperand(2); }
1910 StringRef getSetterName() const { return getStringOperand(3); }
1911 MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
1913 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1914 Metadata *getRawFile() const { return getOperand(1); }
1915 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1916 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1917 Metadata *getRawType() const { return getOperand(4); }
1919 static bool classof(const Metadata *MD) {
1920 return MD->getMetadataID() == MDObjCPropertyKind;
1924 class MDImportedEntity : public DebugNode {
1925 friend class LLVMContextImpl;
1926 friend class MDNode;
1930 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1931 unsigned Line, ArrayRef<Metadata *> Ops)
1932 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1933 ~MDImportedEntity() {}
1935 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1936 MDScope *Scope, Metadata *Entity,
1937 unsigned Line, StringRef Name,
1938 StorageType Storage,
1939 bool ShouldCreate = true) {
1940 return getImpl(Context, Tag, Scope, Entity, Line,
1941 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1943 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1944 Metadata *Scope, Metadata *Entity,
1945 unsigned Line, MDString *Name,
1946 StorageType Storage,
1947 bool ShouldCreate = true);
1949 TempMDImportedEntity cloneImpl() const {
1950 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1951 getLine(), getName());
1955 DEFINE_MDNODE_GET(MDImportedEntity,
1956 (unsigned Tag, MDScope *Scope, Metadata *Entity,
1957 unsigned Line, StringRef Name = ""),
1958 (Tag, Scope, Entity, Line, Name))
1959 DEFINE_MDNODE_GET(MDImportedEntity,
1960 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1961 unsigned Line, MDString *Name),
1962 (Tag, Scope, Entity, Line, Name))
1964 TempMDImportedEntity clone() const { return cloneImpl(); }
1966 unsigned getLine() const { return Line; }
1967 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1968 Metadata *getEntity() const { return getRawEntity(); }
1969 StringRef getName() const { return getStringOperand(2); }
1971 Metadata *getRawScope() const { return getOperand(0); }
1972 Metadata *getRawEntity() const { return getOperand(1); }
1973 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1975 static bool classof(const Metadata *MD) {
1976 return MD->getMetadataID() == MDImportedEntityKind;
1980 } // end namespace llvm
1982 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1983 #undef DEFINE_MDNODE_GET_UNPACK
1984 #undef DEFINE_MDNODE_GET