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 DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
180 static bool classof(const Metadata *MD) {
181 switch (MD->getMetadataID()) {
184 case GenericDebugNodeKind:
186 case MDEnumeratorKind:
187 case MDBasicTypeKind:
188 case MDDerivedTypeKind:
189 case MDCompositeTypeKind:
190 case MDSubroutineTypeKind:
192 case MDCompileUnitKind:
193 case MDSubprogramKind:
194 case MDLexicalBlockKind:
195 case MDLexicalBlockFileKind:
196 case MDNamespaceKind:
197 case MDTemplateTypeParameterKind:
198 case MDTemplateValueParameterKind:
199 case MDGlobalVariableKind:
200 case MDLocalVariableKind:
201 case MDObjCPropertyKind:
202 case MDImportedEntityKind:
209 struct simplify_type<const TypedDebugNodeRef<T>> {
210 typedef Metadata *SimpleType;
211 static SimpleType getSimplifiedValue(const TypedDebugNodeRef<T> &MD) {
217 struct simplify_type<TypedDebugNodeRef<T>>
218 : simplify_type<const TypedDebugNodeRef<T>> {};
220 /// \brief Generic tagged DWARF-like metadata node.
222 /// An un-specialized DWARF-like metadata node. The first operand is a
223 /// (possibly empty) null-separated \a MDString header that contains arbitrary
224 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
225 /// to other metadata.
226 class GenericDebugNode : public DebugNode {
227 friend class LLVMContextImpl;
230 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
231 unsigned Tag, ArrayRef<Metadata *> Ops1,
232 ArrayRef<Metadata *> Ops2)
233 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
236 ~GenericDebugNode() { dropAllReferences(); }
238 void setHash(unsigned Hash) { SubclassData32 = Hash; }
239 void recalculateHash();
241 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
243 ArrayRef<Metadata *> DwarfOps,
245 bool ShouldCreate = true) {
246 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
247 DwarfOps, Storage, ShouldCreate);
250 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
252 ArrayRef<Metadata *> DwarfOps,
254 bool ShouldCreate = true);
256 TempGenericDebugNode cloneImpl() const {
258 getContext(), getTag(), getHeader(),
259 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
263 unsigned getHash() const { return SubclassData32; }
265 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
266 ArrayRef<Metadata *> DwarfOps),
267 (Tag, Header, DwarfOps))
268 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
269 ArrayRef<Metadata *> DwarfOps),
270 (Tag, Header, DwarfOps))
272 /// \brief Return a (temporary) clone of this.
273 TempGenericDebugNode clone() const { return cloneImpl(); }
275 unsigned getTag() const { return SubclassData16; }
276 StringRef getHeader() const { return getStringOperand(0); }
278 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
279 op_iterator dwarf_op_end() const { return op_end(); }
280 op_range dwarf_operands() const {
281 return op_range(dwarf_op_begin(), dwarf_op_end());
284 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
285 const MDOperand &getDwarfOperand(unsigned I) const {
286 return getOperand(I + 1);
288 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
289 replaceOperandWith(I + 1, New);
292 static bool classof(const Metadata *MD) {
293 return MD->getMetadataID() == GenericDebugNodeKind;
297 /// \brief Array subrange.
299 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
301 class MDSubrange : public DebugNode {
302 friend class LLVMContextImpl;
308 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count,
310 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
312 Count(Count), LowerBound(LowerBound) {}
315 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count,
316 int64_t LowerBound, StorageType Storage,
317 bool ShouldCreate = true);
319 TempMDSubrange cloneImpl() const {
320 return getTemporary(getContext(), getCount(), getLowerBound());
324 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t LowerBound = 0),
327 TempMDSubrange clone() const { return cloneImpl(); }
329 int64_t getLowerBound() const { return LowerBound; }
330 int64_t getCount() const { return Count; }
332 static bool classof(const Metadata *MD) {
333 return MD->getMetadataID() == MDSubrangeKind;
337 /// \brief Enumeration value.
339 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
340 /// longer creates a type cycle.
341 class MDEnumerator : public DebugNode {
342 friend class LLVMContextImpl;
347 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
348 ArrayRef<Metadata *> Ops)
349 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
353 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
354 StringRef Name, StorageType Storage,
355 bool ShouldCreate = true) {
356 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
359 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
360 MDString *Name, StorageType Storage,
361 bool ShouldCreate = true);
363 TempMDEnumerator cloneImpl() const {
364 return getTemporary(getContext(), getValue(), getName());
368 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
370 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
373 TempMDEnumerator clone() const { return cloneImpl(); }
375 int64_t getValue() const { return Value; }
376 StringRef getName() const { return getStringOperand(0); }
378 MDString *getRawName() const { return getOperandAs<MDString>(0); }
380 static bool classof(const Metadata *MD) {
381 return MD->getMetadataID() == MDEnumeratorKind;
385 /// \brief Base class for scope-like contexts.
387 /// Base class for lexical scopes and types (which are also declaration
390 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
391 class MDScope : public DebugNode {
393 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
394 ArrayRef<Metadata *> Ops)
395 : DebugNode(C, ID, Storage, Tag, Ops) {}
399 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
401 /// \brief Return the raw underlying file.
403 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
404 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
405 /// this. Otherwise, return the first operand, which is where all other
406 /// subclasses store their file pointer.
407 Metadata *getRawFile() const {
408 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
409 : static_cast<Metadata *>(getOperand(0));
412 MDScopeRef getRef() const { return MDScopeRef::get(this); }
414 static bool classof(const Metadata *MD) {
415 switch (MD->getMetadataID()) {
418 case MDBasicTypeKind:
419 case MDDerivedTypeKind:
420 case MDCompositeTypeKind:
421 case MDSubroutineTypeKind:
423 case MDCompileUnitKind:
424 case MDSubprogramKind:
425 case MDLexicalBlockKind:
426 case MDLexicalBlockFileKind:
427 case MDNamespaceKind:
435 /// TODO: Merge with directory/file node (including users).
436 /// TODO: Canonicalize paths on creation.
437 class MDFile : public MDScope {
438 friend class LLVMContextImpl;
441 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
442 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
445 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
446 StringRef Directory, StorageType Storage,
447 bool ShouldCreate = true) {
448 return getImpl(Context, getCanonicalMDString(Context, Filename),
449 getCanonicalMDString(Context, Directory), Storage,
452 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
453 MDString *Directory, StorageType Storage,
454 bool ShouldCreate = true);
456 TempMDFile cloneImpl() const {
457 return getTemporary(getContext(), getFilename(), getDirectory());
461 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
462 (Filename, Directory))
463 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
464 (Filename, Directory))
466 TempMDFile clone() const { return cloneImpl(); }
468 StringRef getFilename() const { return getStringOperand(0); }
469 StringRef getDirectory() const { return getStringOperand(1); }
471 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
472 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
474 static bool classof(const Metadata *MD) {
475 return MD->getMetadataID() == MDFileKind;
479 /// \brief Base class for types.
481 /// TODO: Remove the hardcoded name and context, since many types don't use
483 /// TODO: Split up flags.
484 class MDType : public MDScope {
488 uint64_t AlignInBits;
489 uint64_t OffsetInBits;
492 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
493 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
494 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
495 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
496 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
497 OffsetInBits(OffsetInBits) {}
501 TempMDType clone() const {
502 return TempMDType(cast<MDType>(MDNode::clone().release()));
505 unsigned getLine() const { return Line; }
506 uint64_t getSizeInBits() const { return SizeInBits; }
507 uint64_t getAlignInBits() const { return AlignInBits; }
508 uint64_t getOffsetInBits() const { return OffsetInBits; }
509 unsigned getFlags() const { return Flags; }
511 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
512 StringRef getName() const { return getStringOperand(2); }
515 Metadata *getRawScope() const { return getOperand(1); }
516 MDString *getRawName() const { return getOperandAs<MDString>(2); }
518 void setFlags(unsigned NewFlags) {
519 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
523 MDTypeRef getRef() const { return MDTypeRef::get(this); }
525 static bool classof(const Metadata *MD) {
526 switch (MD->getMetadataID()) {
529 case MDBasicTypeKind:
530 case MDDerivedTypeKind:
531 case MDCompositeTypeKind:
532 case MDSubroutineTypeKind:
538 /// \brief Basic type.
540 /// TODO: Split out DW_TAG_unspecified_type.
541 /// TODO: Drop unused accessors.
542 class MDBasicType : public MDType {
543 friend class LLVMContextImpl;
548 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
549 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
550 ArrayRef<Metadata *> Ops)
551 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
553 Encoding(Encoding) {}
556 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
557 StringRef Name, uint64_t SizeInBits,
558 uint64_t AlignInBits, unsigned Encoding,
559 StorageType Storage, bool ShouldCreate = true) {
560 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
561 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
563 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
564 MDString *Name, uint64_t SizeInBits,
565 uint64_t AlignInBits, unsigned Encoding,
566 StorageType Storage, bool ShouldCreate = true);
568 TempMDBasicType cloneImpl() const {
569 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
570 getAlignInBits(), getEncoding());
574 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
575 (Tag, Name, 0, 0, 0))
576 DEFINE_MDNODE_GET(MDBasicType,
577 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
578 uint64_t AlignInBits, unsigned Encoding),
579 (Tag, Name, SizeInBits, AlignInBits, Encoding))
580 DEFINE_MDNODE_GET(MDBasicType,
581 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
582 uint64_t AlignInBits, unsigned Encoding),
583 (Tag, Name, SizeInBits, AlignInBits, Encoding))
585 TempMDBasicType clone() const { return cloneImpl(); }
587 unsigned getEncoding() const { return Encoding; }
589 static bool classof(const Metadata *MD) {
590 return MD->getMetadataID() == MDBasicTypeKind;
594 /// \brief Base class for MDDerivedType and MDCompositeType.
596 /// TODO: Delete; they're not really related.
597 class MDDerivedTypeBase : public MDType {
599 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
600 unsigned Tag, unsigned Line, uint64_t SizeInBits,
601 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
602 ArrayRef<Metadata *> Ops)
603 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
605 ~MDDerivedTypeBase() {}
608 MDTypeRef getBaseType() const { return MDTypeRef(getRawBaseType()); }
609 Metadata *getRawBaseType() const { return getOperand(3); }
611 static bool classof(const Metadata *MD) {
612 return MD->getMetadataID() == MDDerivedTypeKind ||
613 MD->getMetadataID() == MDCompositeTypeKind ||
614 MD->getMetadataID() == MDSubroutineTypeKind;
618 /// \brief Derived types.
620 /// This includes qualified types, pointers, references, friends, typedefs, and
623 /// TODO: Split out members (inheritance, fields, methods, etc.).
624 class MDDerivedType : public MDDerivedTypeBase {
625 friend class LLVMContextImpl;
628 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
629 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
630 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
631 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
632 AlignInBits, OffsetInBits, Flags, Ops) {}
635 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
636 StringRef Name, MDFile *File, unsigned Line,
637 MDScopeRef Scope, MDTypeRef BaseType,
638 uint64_t SizeInBits, uint64_t AlignInBits,
639 uint64_t OffsetInBits, unsigned Flags,
640 Metadata *ExtraData, StorageType Storage,
641 bool ShouldCreate = true) {
642 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
643 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
644 Flags, ExtraData, Storage, ShouldCreate);
646 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
647 MDString *Name, Metadata *File, unsigned Line,
648 Metadata *Scope, Metadata *BaseType,
649 uint64_t SizeInBits, uint64_t AlignInBits,
650 uint64_t OffsetInBits, unsigned Flags,
651 Metadata *ExtraData, StorageType Storage,
652 bool ShouldCreate = true);
654 TempMDDerivedType cloneImpl() const {
655 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
656 getScope(), getBaseType(), getSizeInBits(),
657 getAlignInBits(), getOffsetInBits(), getFlags(),
662 DEFINE_MDNODE_GET(MDDerivedType,
663 (unsigned Tag, MDString *Name, Metadata *File,
664 unsigned Line, Metadata *Scope, Metadata *BaseType,
665 uint64_t SizeInBits, uint64_t AlignInBits,
666 uint64_t OffsetInBits, unsigned Flags,
667 Metadata *ExtraData = nullptr),
668 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
669 AlignInBits, OffsetInBits, Flags, ExtraData))
670 DEFINE_MDNODE_GET(MDDerivedType,
671 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
672 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
673 uint64_t AlignInBits, uint64_t OffsetInBits,
674 unsigned Flags, Metadata *ExtraData = nullptr),
675 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
676 AlignInBits, OffsetInBits, Flags, ExtraData))
678 TempMDDerivedType clone() const { return cloneImpl(); }
680 /// \brief Get extra data associated with this derived type.
682 /// Class type for pointer-to-members, objective-c property node for ivars,
683 /// or global constant wrapper for static members.
685 /// TODO: Separate out types that need this extra operand: pointer-to-member
686 /// types and member fields (static members and ivars).
687 Metadata *getExtraData() const { return getRawExtraData(); }
688 Metadata *getRawExtraData() const { return getOperand(4); }
690 static bool classof(const Metadata *MD) {
691 return MD->getMetadataID() == MDDerivedTypeKind;
695 /// \brief Base class for MDCompositeType and MDSubroutineType.
697 /// TODO: Delete; they're not really related.
698 class MDCompositeTypeBase : public MDDerivedTypeBase {
699 unsigned RuntimeLang;
702 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
703 unsigned Tag, unsigned Line, unsigned RuntimeLang,
704 uint64_t SizeInBits, uint64_t AlignInBits,
705 uint64_t OffsetInBits, unsigned Flags,
706 ArrayRef<Metadata *> Ops)
707 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
708 OffsetInBits, Flags, Ops),
709 RuntimeLang(RuntimeLang) {}
710 ~MDCompositeTypeBase() {}
713 MDTuple *getElements() const {
714 return cast_or_null<MDTuple>(getRawElements());
716 MDTypeRef getVTableHolder() const { return MDTypeRef(getRawVTableHolder()); }
717 MDTemplateParameterArray getTemplateParams() const {
718 return cast_or_null<MDTuple>(getRawTemplateParams());
720 StringRef getIdentifier() const { return getStringOperand(7); }
721 unsigned getRuntimeLang() const { return RuntimeLang; }
723 Metadata *getRawElements() const { return getOperand(4); }
724 Metadata *getRawVTableHolder() const { return getOperand(5); }
725 Metadata *getRawTemplateParams() const { return getOperand(6); }
726 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
728 /// \brief Replace operands.
730 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
731 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
732 /// of its movement if necessary.
734 void replaceElements(MDTuple *Elements) {
736 if (auto *Old = cast_or_null<MDTuple>(getElements()))
737 for (const auto &Op : Old->operands())
738 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
739 "Lost a member during member list replacement");
741 replaceOperandWith(4, Elements);
743 void replaceVTableHolder(MDTypeRef VTableHolder) {
744 replaceOperandWith(5, VTableHolder);
746 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
747 replaceOperandWith(6, TemplateParams);
751 static bool classof(const Metadata *MD) {
752 return MD->getMetadataID() == MDCompositeTypeKind ||
753 MD->getMetadataID() == MDSubroutineTypeKind;
757 /// \brief Composite types.
759 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
760 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
761 class MDCompositeType : public MDCompositeTypeBase {
762 friend class LLVMContextImpl;
765 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
766 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
767 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
768 ArrayRef<Metadata *> Ops)
769 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
770 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
772 ~MDCompositeType() {}
774 static MDCompositeType *
775 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
776 unsigned Line, MDScopeRef Scope, MDTypeRef BaseType,
777 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
778 uint64_t Flags, MDTuple *Elements, unsigned RuntimeLang,
779 MDTypeRef VTableHolder, MDTemplateParameterArray TemplateParams,
780 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
781 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
782 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
783 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
784 getCanonicalMDString(Context, Identifier), Storage,
787 static MDCompositeType *
788 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
789 unsigned Line, Metadata *Scope, Metadata *BaseType,
790 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
791 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
792 Metadata *VTableHolder, Metadata *TemplateParams,
793 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
795 TempMDCompositeType cloneImpl() const {
796 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
797 getScope(), getBaseType(), getSizeInBits(),
798 getAlignInBits(), getOffsetInBits(), getFlags(),
799 getElements(), getRuntimeLang(), getVTableHolder(),
800 getTemplateParams(), getIdentifier());
804 DEFINE_MDNODE_GET(MDCompositeType,
805 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
806 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
807 uint64_t AlignInBits, uint64_t OffsetInBits,
808 unsigned Flags, MDTuple *Elements, unsigned RuntimeLang,
809 MDTypeRef VTableHolder,
810 MDTemplateParameterArray TemplateParams = nullptr,
811 StringRef Identifier = ""),
812 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
813 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
814 VTableHolder, TemplateParams, Identifier))
815 DEFINE_MDNODE_GET(MDCompositeType,
816 (unsigned Tag, MDString *Name, Metadata *File,
817 unsigned Line, Metadata *Scope, Metadata *BaseType,
818 uint64_t SizeInBits, uint64_t AlignInBits,
819 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
820 unsigned RuntimeLang, Metadata *VTableHolder,
821 Metadata *TemplateParams = nullptr,
822 MDString *Identifier = nullptr),
823 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
824 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
825 VTableHolder, TemplateParams, Identifier))
827 TempMDCompositeType clone() const { return cloneImpl(); }
829 static bool classof(const Metadata *MD) {
830 return MD->getMetadataID() == MDCompositeTypeKind;
834 template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) {
836 if (auto *Composite = dyn_cast<MDCompositeType>(N))
837 if (auto *S = Composite->getRawIdentifier())
838 return TypedDebugNodeRef<T>(S);
839 return TypedDebugNodeRef<T>(N);
842 /// \brief Type array for a subprogram.
844 /// TODO: Detach from CompositeType, and fold the array of types in directly
846 class MDSubroutineType : public MDCompositeTypeBase {
847 friend class LLVMContextImpl;
850 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
851 ArrayRef<Metadata *> Ops)
852 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
853 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
855 ~MDSubroutineType() {}
857 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
858 Metadata *TypeArray, StorageType Storage,
859 bool ShouldCreate = true);
861 TempMDSubroutineType cloneImpl() const {
862 return getTemporary(getContext(), getFlags(), getTypeArray());
866 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
869 TempMDSubroutineType clone() const { return cloneImpl(); }
871 MDTypeRefArray getTypeArray() const { return getElements(); }
872 Metadata *getRawTypeArray() const { return getRawElements(); }
874 static bool classof(const Metadata *MD) {
875 return MD->getMetadataID() == MDSubroutineTypeKind;
879 /// \brief Compile unit.
880 class MDCompileUnit : public MDScope {
881 friend class LLVMContextImpl;
884 unsigned SourceLanguage;
886 unsigned RuntimeVersion;
887 unsigned EmissionKind;
889 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
890 bool IsOptimized, unsigned RuntimeVersion,
891 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
892 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
893 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
894 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
897 static MDCompileUnit *
898 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
899 StringRef Producer, bool IsOptimized, StringRef Flags,
900 unsigned RuntimeVersion, StringRef SplitDebugFilename,
901 unsigned EmissionKind, MDTuple *EnumTypes, MDTuple *RetainedTypes,
902 MDTuple *Subprograms, MDTuple *GlobalVariables,
903 MDTuple *ImportedEntities, StorageType Storage,
904 bool ShouldCreate = true) {
905 return getImpl(Context, SourceLanguage, File,
906 getCanonicalMDString(Context, Producer), IsOptimized,
907 getCanonicalMDString(Context, Flags), RuntimeVersion,
908 getCanonicalMDString(Context, SplitDebugFilename),
909 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
910 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
912 static MDCompileUnit *
913 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
914 MDString *Producer, bool IsOptimized, MDString *Flags,
915 unsigned RuntimeVersion, MDString *SplitDebugFilename,
916 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
917 Metadata *Subprograms, Metadata *GlobalVariables,
918 Metadata *ImportedEntities, StorageType Storage,
919 bool ShouldCreate = true);
921 TempMDCompileUnit cloneImpl() const {
923 getContext(), getSourceLanguage(), getFile(), getProducer(),
924 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
925 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
926 getGlobalVariables(), getImportedEntities());
930 DEFINE_MDNODE_GET(MDCompileUnit,
931 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
932 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
933 StringRef SplitDebugFilename, unsigned EmissionKind,
934 MDTuple *EnumTypes, MDTuple *RetainedTypes,
935 MDTuple *Subprograms, MDTuple *GlobalVariables,
936 MDTuple *ImportedEntities),
937 (SourceLanguage, File, Producer, IsOptimized, Flags,
938 RuntimeVersion, SplitDebugFilename, EmissionKind,
939 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
941 DEFINE_MDNODE_GET(MDCompileUnit,
942 (unsigned SourceLanguage, Metadata *File,
943 MDString *Producer, bool IsOptimized, MDString *Flags,
944 unsigned RuntimeVersion, MDString *SplitDebugFilename,
945 unsigned EmissionKind, Metadata *EnumTypes,
946 Metadata *RetainedTypes, Metadata *Subprograms,
947 Metadata *GlobalVariables, Metadata *ImportedEntities),
948 (SourceLanguage, File, Producer, IsOptimized, Flags,
949 RuntimeVersion, SplitDebugFilename, EmissionKind,
950 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
953 TempMDCompileUnit clone() const { return cloneImpl(); }
955 unsigned getSourceLanguage() const { return SourceLanguage; }
956 bool isOptimized() const { return IsOptimized; }
957 unsigned getRuntimeVersion() const { return RuntimeVersion; }
958 unsigned getEmissionKind() const { return EmissionKind; }
959 StringRef getProducer() const { return getStringOperand(1); }
960 StringRef getFlags() const { return getStringOperand(2); }
961 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
962 MDCompositeTypeArray getEnumTypes() const {
963 return cast_or_null<MDTuple>(getRawEnumTypes());
965 MDTypeArray getRetainedTypes() const {
966 return cast_or_null<MDTuple>(getRawRetainedTypes());
968 MDSubprogramArray getSubprograms() const {
969 return cast_or_null<MDTuple>(getRawSubprograms());
971 MDGlobalVariableArray getGlobalVariables() const {
972 return cast_or_null<MDTuple>(getRawGlobalVariables());
974 MDImportedEntityArray getImportedEntities() const {
975 return cast_or_null<MDTuple>(getRawImportedEntities());
978 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
979 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
980 MDString *getRawSplitDebugFilename() const {
981 return getOperandAs<MDString>(3);
983 Metadata *getRawEnumTypes() const { return getOperand(4); }
984 Metadata *getRawRetainedTypes() const { return getOperand(5); }
985 Metadata *getRawSubprograms() const { return getOperand(6); }
986 Metadata *getRawGlobalVariables() const { return getOperand(7); }
987 Metadata *getRawImportedEntities() const { return getOperand(8); }
989 /// \brief Replace arrays.
991 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
992 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
993 /// MDCompileUnit should be fairly rare.
995 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
996 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
999 static bool classof(const Metadata *MD) {
1000 return MD->getMetadataID() == MDCompileUnitKind;
1004 /// \brief A scope for locals.
1006 /// A legal scope for lexical blocks, local variables, and debug info
1007 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
1008 /// MDLexicalBlockFile.
1009 class MDLocalScope : public MDScope {
1011 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1012 ArrayRef<Metadata *> Ops)
1013 : MDScope(C, ID, Storage, Tag, Ops) {}
1017 /// \brief Get the subprogram for this scope.
1019 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
1021 MDSubprogram *getSubprogram() const;
1023 static bool classof(const Metadata *MD) {
1024 return MD->getMetadataID() == MDSubprogramKind ||
1025 MD->getMetadataID() == MDLexicalBlockKind ||
1026 MD->getMetadataID() == MDLexicalBlockFileKind;
1030 /// \brief Debug location.
1032 /// A debug location in source code, used for debug info and otherwise.
1033 class MDLocation : public MDNode {
1034 friend class LLVMContextImpl;
1035 friend class MDNode;
1037 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
1038 unsigned Column, ArrayRef<Metadata *> MDs);
1039 ~MDLocation() { dropAllReferences(); }
1041 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1042 unsigned Column, Metadata *Scope,
1043 Metadata *InlinedAt, StorageType Storage,
1044 bool ShouldCreate = true);
1045 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1046 unsigned Column, MDLocalScope *Scope,
1047 MDLocation *InlinedAt, StorageType Storage,
1048 bool ShouldCreate = true) {
1049 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1050 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1053 TempMDLocation cloneImpl() const {
1054 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
1058 // Disallow replacing operands.
1059 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1062 DEFINE_MDNODE_GET(MDLocation,
1063 (unsigned Line, unsigned Column, Metadata *Scope,
1064 Metadata *InlinedAt = nullptr),
1065 (Line, Column, Scope, InlinedAt))
1066 DEFINE_MDNODE_GET(MDLocation,
1067 (unsigned Line, unsigned Column, MDLocalScope *Scope,
1068 MDLocation *InlinedAt = nullptr),
1069 (Line, Column, Scope, InlinedAt))
1071 /// \brief Return a (temporary) clone of this.
1072 TempMDLocation clone() const { return cloneImpl(); }
1074 unsigned getLine() const { return SubclassData32; }
1075 unsigned getColumn() const { return SubclassData16; }
1076 MDLocalScope *getScope() const {
1077 return cast<MDLocalScope>(getRawScope());
1079 MDLocation *getInlinedAt() const {
1080 return cast_or_null<MDLocation>(getRawInlinedAt());
1083 /// \brief Get the scope where this is inlined.
1085 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1087 MDLocalScope *getInlinedAtScope() const {
1088 if (auto *IA = getInlinedAt())
1089 return IA->getInlinedAtScope();
1093 Metadata *getRawScope() const { return getOperand(0); }
1094 Metadata *getRawInlinedAt() const {
1095 if (getNumOperands() == 2)
1096 return getOperand(1);
1100 static bool classof(const Metadata *MD) {
1101 return MD->getMetadataID() == MDLocationKind;
1105 /// \brief Subprogram description.
1107 /// TODO: Remove DisplayName. It's always equal to Name.
1108 /// TODO: Split up flags.
1109 class MDSubprogram : public MDLocalScope {
1110 friend class LLVMContextImpl;
1111 friend class MDNode;
1115 unsigned Virtuality;
1116 unsigned VirtualIndex;
1122 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1123 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1124 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
1125 bool IsOptimized, ArrayRef<Metadata *> Ops)
1126 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1128 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
1129 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
1130 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
1133 static MDSubprogram *
1134 getImpl(LLVMContext &Context, MDScopeRef Scope, StringRef Name,
1135 StringRef LinkageName, MDFile *File, unsigned Line,
1136 MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1137 unsigned ScopeLine, MDTypeRef ContainingType, unsigned Virtuality,
1138 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1139 ConstantAsMetadata *Function, MDTemplateParameterArray TemplateParams,
1140 MDSubprogram *Declaration, MDLocalVariableArray Variables,
1141 StorageType Storage, bool ShouldCreate = true) {
1142 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1143 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1144 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1145 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1146 TemplateParams, Declaration, Variables, Storage,
1149 static MDSubprogram *
1150 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1151 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1152 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1153 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1154 unsigned Flags, bool IsOptimized, Metadata *Function,
1155 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1156 StorageType Storage, bool ShouldCreate = true);
1158 TempMDSubprogram cloneImpl() const {
1159 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1160 getFile(), getLine(), getType(), isLocalToUnit(),
1161 isDefinition(), getScopeLine(), getContainingType(),
1162 getVirtuality(), getVirtualIndex(), getFlags(),
1163 isOptimized(), getFunction(), getTemplateParams(),
1164 getDeclaration(), getVariables());
1168 DEFINE_MDNODE_GET(MDSubprogram,
1169 (MDScopeRef Scope, StringRef Name, StringRef LinkageName,
1170 MDFile *File, unsigned Line, MDSubroutineType *Type,
1171 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1172 MDTypeRef ContainingType, unsigned Virtuality,
1173 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1174 ConstantAsMetadata *Function = nullptr,
1175 MDTemplateParameterArray TemplateParams = nullptr,
1176 MDSubprogram *Declaration = nullptr,
1177 MDLocalVariableArray Variables = nullptr),
1178 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1179 IsDefinition, ScopeLine, ContainingType, Virtuality,
1180 VirtualIndex, Flags, IsOptimized, Function, TemplateParams,
1181 Declaration, Variables))
1184 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1185 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1186 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1187 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1188 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1189 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1190 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1191 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1192 Function, TemplateParams, Declaration, Variables))
1194 TempMDSubprogram clone() const { return cloneImpl(); }
1197 unsigned getLine() const { return Line; }
1198 unsigned getVirtuality() const { return Virtuality; }
1199 unsigned getVirtualIndex() const { return VirtualIndex; }
1200 unsigned getScopeLine() const { return ScopeLine; }
1201 unsigned getFlags() const { return Flags; }
1202 bool isLocalToUnit() const { return IsLocalToUnit; }
1203 bool isDefinition() const { return IsDefinition; }
1204 bool isOptimized() const { return IsOptimized; }
1206 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
1208 StringRef getName() const { return getStringOperand(2); }
1209 StringRef getDisplayName() const { return getStringOperand(3); }
1210 StringRef getLinkageName() const { return getStringOperand(4); }
1212 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1213 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1215 MDSubroutineType *getType() const {
1216 return cast_or_null<MDSubroutineType>(getRawType());
1218 MDTypeRef getContainingType() const {
1219 return MDTypeRef(getRawContainingType());
1222 ConstantAsMetadata *getFunction() const {
1223 return cast_or_null<ConstantAsMetadata>(getRawFunction());
1225 MDTemplateParameterArray getTemplateParams() const {
1226 return cast_or_null<MDTuple>(getRawTemplateParams());
1228 MDSubprogram *getDeclaration() const {
1229 return cast_or_null<MDSubprogram>(getRawDeclaration());
1231 MDLocalVariableArray getVariables() const {
1232 return cast_or_null<MDTuple>(getRawVariables());
1235 Metadata *getRawScope() const { return getOperand(1); }
1236 Metadata *getRawType() const { return getOperand(5); }
1237 Metadata *getRawContainingType() const { return getOperand(6); }
1238 Metadata *getRawFunction() const { return getOperand(7); }
1239 Metadata *getRawTemplateParams() const { return getOperand(8); }
1240 Metadata *getRawDeclaration() const { return getOperand(9); }
1241 Metadata *getRawVariables() const { return getOperand(10); }
1243 /// \brief Replace the function.
1245 /// If \a isUniqued() and not \a isResolved(), this could node will be
1246 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1247 /// that's a problem.
1249 void replaceFunction(Function *F);
1250 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1251 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1254 static bool classof(const Metadata *MD) {
1255 return MD->getMetadataID() == MDSubprogramKind;
1259 class MDLexicalBlockBase : public MDLocalScope {
1261 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1262 ArrayRef<Metadata *> Ops)
1263 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1264 ~MDLexicalBlockBase() {}
1267 MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
1269 Metadata *getRawScope() const { return getOperand(1); }
1271 static bool classof(const Metadata *MD) {
1272 return MD->getMetadataID() == MDLexicalBlockKind ||
1273 MD->getMetadataID() == MDLexicalBlockFileKind;
1277 class MDLexicalBlock : public MDLexicalBlockBase {
1278 friend class LLVMContextImpl;
1279 friend class MDNode;
1284 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1285 unsigned Column, ArrayRef<Metadata *> Ops)
1286 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1288 ~MDLexicalBlock() {}
1290 static MDLexicalBlock *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1291 MDFile *File, unsigned Line, unsigned Column,
1292 StorageType Storage,
1293 bool ShouldCreate = true) {
1294 return getImpl(Context, static_cast<Metadata *>(Scope),
1295 static_cast<Metadata *>(File), Line, Column, Storage,
1299 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1300 Metadata *File, unsigned Line, unsigned Column,
1301 StorageType Storage, bool ShouldCreate = true);
1303 TempMDLexicalBlock cloneImpl() const {
1304 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1309 DEFINE_MDNODE_GET(MDLexicalBlock, (MDLocalScope * Scope, MDFile *File,
1310 unsigned Line, unsigned Column),
1311 (Scope, File, Line, Column))
1312 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1313 unsigned Line, unsigned Column),
1314 (Scope, File, Line, Column))
1316 TempMDLexicalBlock clone() const { return cloneImpl(); }
1318 unsigned getLine() const { return Line; }
1319 unsigned getColumn() const { return Column; }
1321 static bool classof(const Metadata *MD) {
1322 return MD->getMetadataID() == MDLexicalBlockKind;
1326 class MDLexicalBlockFile : public MDLexicalBlockBase {
1327 friend class LLVMContextImpl;
1328 friend class MDNode;
1330 unsigned Discriminator;
1332 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1333 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1334 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1335 Discriminator(Discriminator) {}
1336 ~MDLexicalBlockFile() {}
1338 static MDLexicalBlockFile *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1339 MDFile *File, unsigned Discriminator,
1340 StorageType Storage,
1341 bool ShouldCreate = true) {
1342 return getImpl(Context, static_cast<Metadata *>(Scope),
1343 static_cast<Metadata *>(File), Discriminator, Storage,
1347 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1348 Metadata *File, unsigned Discriminator,
1349 StorageType Storage,
1350 bool ShouldCreate = true);
1352 TempMDLexicalBlockFile cloneImpl() const {
1353 return getTemporary(getContext(), getScope(), getFile(),
1354 getDiscriminator());
1358 DEFINE_MDNODE_GET(MDLexicalBlockFile, (MDLocalScope * Scope, MDFile *File,
1359 unsigned Discriminator),
1360 (Scope, File, Discriminator))
1361 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1362 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1363 (Scope, File, Discriminator))
1365 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1367 unsigned getDiscriminator() const { return Discriminator; }
1369 static bool classof(const Metadata *MD) {
1370 return MD->getMetadataID() == MDLexicalBlockFileKind;
1374 class MDNamespace : public MDScope {
1375 friend class LLVMContextImpl;
1376 friend class MDNode;
1380 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1381 ArrayRef<Metadata *> Ops)
1382 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1387 static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
1388 MDFile *File, StringRef Name, unsigned Line,
1389 StorageType Storage, bool ShouldCreate = true) {
1390 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1391 Line, Storage, ShouldCreate);
1393 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1394 Metadata *File, MDString *Name, unsigned Line,
1395 StorageType Storage, bool ShouldCreate = true);
1397 TempMDNamespace cloneImpl() const {
1398 return getTemporary(getContext(), getScope(), getFile(), getName(),
1403 DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
1405 (Scope, File, Name, Line))
1406 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1407 MDString *Name, unsigned Line),
1408 (Scope, File, Name, Line))
1410 TempMDNamespace clone() const { return cloneImpl(); }
1412 unsigned getLine() const { return Line; }
1413 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1414 StringRef getName() const { return getStringOperand(2); }
1416 Metadata *getRawScope() const { return getOperand(1); }
1417 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1419 static bool classof(const Metadata *MD) {
1420 return MD->getMetadataID() == MDNamespaceKind;
1424 /// \brief Base class for template parameters.
1425 class MDTemplateParameter : public DebugNode {
1427 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1428 unsigned Tag, ArrayRef<Metadata *> Ops)
1429 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1430 ~MDTemplateParameter() {}
1433 StringRef getName() const { return getStringOperand(0); }
1434 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1436 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1437 Metadata *getRawType() const { return getOperand(1); }
1439 static bool classof(const Metadata *MD) {
1440 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1441 MD->getMetadataID() == MDTemplateValueParameterKind;
1445 class MDTemplateTypeParameter : public MDTemplateParameter {
1446 friend class LLVMContextImpl;
1447 friend class MDNode;
1449 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1450 ArrayRef<Metadata *> Ops)
1451 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1452 dwarf::DW_TAG_template_type_parameter, Ops) {}
1453 ~MDTemplateTypeParameter() {}
1455 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1456 MDTypeRef Type, StorageType Storage,
1457 bool ShouldCreate = true) {
1458 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1461 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1462 Metadata *Type, StorageType Storage,
1463 bool ShouldCreate = true);
1465 TempMDTemplateTypeParameter cloneImpl() const {
1466 return getTemporary(getContext(), getName(), getType());
1470 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, MDTypeRef Type),
1472 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1475 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1477 static bool classof(const Metadata *MD) {
1478 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1482 class MDTemplateValueParameter : public MDTemplateParameter {
1483 friend class LLVMContextImpl;
1484 friend class MDNode;
1486 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1487 unsigned Tag, ArrayRef<Metadata *> Ops)
1488 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1490 ~MDTemplateValueParameter() {}
1492 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1493 StringRef Name, MDTypeRef Type,
1494 Metadata *Value, StorageType Storage,
1495 bool ShouldCreate = true) {
1496 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1497 Value, Storage, ShouldCreate);
1499 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1500 MDString *Name, Metadata *Type,
1501 Metadata *Value, StorageType Storage,
1502 bool ShouldCreate = true);
1504 TempMDTemplateValueParameter cloneImpl() const {
1505 return getTemporary(getContext(), getTag(), getName(), getType(),
1510 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1511 MDTypeRef Type, Metadata *Value),
1512 (Tag, Name, Type, Value))
1513 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1514 Metadata *Type, Metadata *Value),
1515 (Tag, Name, Type, Value))
1517 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1519 Metadata *getValue() const { return getOperand(2); }
1521 static bool classof(const Metadata *MD) {
1522 return MD->getMetadataID() == MDTemplateValueParameterKind;
1526 /// \brief Base class for variables.
1528 /// TODO: Hardcode to DW_TAG_variable.
1529 class MDVariable : public DebugNode {
1533 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1534 unsigned Line, ArrayRef<Metadata *> Ops)
1535 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1539 unsigned getLine() const { return Line; }
1540 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1541 StringRef getName() const { return getStringOperand(1); }
1542 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1543 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1545 Metadata *getRawScope() const { return getOperand(0); }
1546 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1547 Metadata *getRawFile() const { return getOperand(2); }
1548 Metadata *getRawType() const { return getOperand(3); }
1550 static bool classof(const Metadata *MD) {
1551 return MD->getMetadataID() == MDLocalVariableKind ||
1552 MD->getMetadataID() == MDGlobalVariableKind;
1556 /// \brief Global variables.
1558 /// TODO: Remove DisplayName. It's always equal to Name.
1559 class MDGlobalVariable : public MDVariable {
1560 friend class LLVMContextImpl;
1561 friend class MDNode;
1566 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1567 bool IsLocalToUnit, bool IsDefinition,
1568 ArrayRef<Metadata *> Ops)
1569 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1571 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1572 ~MDGlobalVariable() {}
1574 static MDGlobalVariable *
1575 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1576 StringRef LinkageName, MDFile *File, unsigned Line, MDTypeRef Type,
1577 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1578 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1579 bool ShouldCreate = true) {
1580 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1581 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1582 IsLocalToUnit, IsDefinition, Variable,
1583 StaticDataMemberDeclaration, Storage, ShouldCreate);
1585 static MDGlobalVariable *
1586 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1587 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1588 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1589 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1590 bool ShouldCreate = true);
1592 TempMDGlobalVariable cloneImpl() const {
1593 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1594 getFile(), getLine(), getType(), isLocalToUnit(),
1595 isDefinition(), getVariable(),
1596 getStaticDataMemberDeclaration());
1600 DEFINE_MDNODE_GET(MDGlobalVariable,
1601 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1602 MDFile *File, unsigned Line, MDTypeRef Type,
1603 bool IsLocalToUnit, bool IsDefinition,
1604 ConstantAsMetadata *Variable,
1605 MDDerivedType *StaticDataMemberDeclaration),
1606 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1607 IsDefinition, Variable, StaticDataMemberDeclaration))
1608 DEFINE_MDNODE_GET(MDGlobalVariable,
1609 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1610 Metadata *File, unsigned Line, Metadata *Type,
1611 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1612 Metadata *StaticDataMemberDeclaration),
1613 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1614 IsDefinition, Variable, StaticDataMemberDeclaration))
1616 TempMDGlobalVariable clone() const { return cloneImpl(); }
1618 bool isLocalToUnit() const { return IsLocalToUnit; }
1619 bool isDefinition() const { return IsDefinition; }
1620 StringRef getDisplayName() const { return getStringOperand(4); }
1621 StringRef getLinkageName() const { return getStringOperand(5); }
1622 ConstantAsMetadata *getVariable() const {
1623 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1625 MDDerivedType *getStaticDataMemberDeclaration() const {
1626 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1629 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1630 Metadata *getRawVariable() const { return getOperand(6); }
1631 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1633 static bool classof(const Metadata *MD) {
1634 return MD->getMetadataID() == MDGlobalVariableKind;
1638 /// \brief Local variable.
1640 /// TODO: Split between arguments and otherwise.
1641 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1642 /// TODO: Split up flags.
1643 class MDLocalVariable : public MDVariable {
1644 friend class LLVMContextImpl;
1645 friend class MDNode;
1650 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1651 unsigned Line, unsigned Arg, unsigned Flags,
1652 ArrayRef<Metadata *> Ops)
1653 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1655 ~MDLocalVariable() {}
1657 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1658 MDScope *Scope, StringRef Name, MDFile *File,
1659 unsigned Line, MDTypeRef Type, unsigned Arg,
1660 unsigned Flags, MDLocation *InlinedAt,
1661 StorageType Storage,
1662 bool ShouldCreate = true) {
1663 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1664 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1667 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1668 Metadata *Scope, MDString *Name,
1669 Metadata *File, unsigned Line, Metadata *Type,
1670 unsigned Arg, unsigned Flags,
1671 Metadata *InlinedAt, StorageType Storage,
1672 bool ShouldCreate = true);
1674 TempMDLocalVariable cloneImpl() const {
1675 return getTemporary(getContext(), getTag(), getScope(), getName(),
1676 getFile(), getLine(), getType(), getArg(), getFlags(),
1681 DEFINE_MDNODE_GET(MDLocalVariable,
1682 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1683 MDFile *File, unsigned Line, MDTypeRef Type, unsigned Arg,
1684 unsigned Flags, MDLocation *InlinedAt = nullptr),
1685 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1686 DEFINE_MDNODE_GET(MDLocalVariable,
1687 (unsigned Tag, Metadata *Scope, MDString *Name,
1688 Metadata *File, unsigned Line, Metadata *Type,
1689 unsigned Arg, unsigned Flags,
1690 Metadata *InlinedAt = nullptr),
1691 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1693 TempMDLocalVariable clone() const { return cloneImpl(); }
1695 /// \brief Get the local scope for this variable.
1697 /// Variables must be defined in a local scope.
1698 MDLocalScope *getScope() const {
1699 return cast<MDLocalScope>(MDVariable::getScope());
1702 unsigned getArg() const { return Arg; }
1703 unsigned getFlags() const { return Flags; }
1704 MDLocation *getInlinedAt() const {
1705 return cast_or_null<MDLocation>(getRawInlinedAt());
1708 Metadata *getRawInlinedAt() const { return getOperand(4); }
1710 /// \brief Check that a location is valid for this variable.
1712 /// Check that \c DL has the same inlined-at location as this variable,
1713 /// making them valid for the same \a DbgInfoIntrinsic.
1714 bool isValidLocationForIntrinsic(const MDLocation *DL) const {
1715 return getInlinedAt() == (DL ? DL->getInlinedAt() : nullptr);
1718 /// \brief Get an inlined version of this variable.
1720 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1721 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1722 if (InlinedAt == getInlinedAt())
1723 return const_cast<MDLocalVariable *>(this);
1724 auto Temp = clone();
1725 Temp->replaceOperandWith(4, InlinedAt);
1726 return replaceWithUniqued(std::move(Temp));
1728 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1730 static bool classof(const Metadata *MD) {
1731 return MD->getMetadataID() == MDLocalVariableKind;
1735 /// \brief DWARF expression.
1737 /// TODO: Co-allocate the expression elements.
1738 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1740 class MDExpression : public MDNode {
1741 friend class LLVMContextImpl;
1742 friend class MDNode;
1744 std::vector<uint64_t> Elements;
1746 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1747 : MDNode(C, MDExpressionKind, Storage, None),
1748 Elements(Elements.begin(), Elements.end()) {}
1751 static MDExpression *getImpl(LLVMContext &Context,
1752 ArrayRef<uint64_t> Elements, StorageType Storage,
1753 bool ShouldCreate = true);
1755 TempMDExpression cloneImpl() const {
1756 return getTemporary(getContext(), getElements());
1760 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1762 TempMDExpression clone() const { return cloneImpl(); }
1764 ArrayRef<uint64_t> getElements() const { return Elements; }
1766 unsigned getNumElements() const { return Elements.size(); }
1767 uint64_t getElement(unsigned I) const {
1768 assert(I < Elements.size() && "Index out of range");
1772 typedef ArrayRef<uint64_t>::iterator element_iterator;
1773 element_iterator elements_begin() const { return getElements().begin(); }
1774 element_iterator elements_end() const { return getElements().end(); }
1776 /// \brief A lightweight wrapper around an expression operand.
1778 /// TODO: Store arguments directly and change \a MDExpression to store a
1784 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1786 const uint64_t *get() const { return Op; }
1788 /// \brief Get the operand code.
1789 uint64_t getOp() const { return *Op; }
1791 /// \brief Get an argument to the operand.
1793 /// Never returns the operand itself.
1794 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1796 unsigned getNumArgs() const { return getSize() - 1; }
1798 /// \brief Return the size of the operand.
1800 /// Return the number of elements in the operand (1 + args).
1801 unsigned getSize() const;
1804 /// \brief An iterator for expression operands.
1805 class expr_op_iterator
1806 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1810 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1812 element_iterator getBase() const { return Op.get(); }
1813 const ExprOperand &operator*() const { return Op; }
1814 const ExprOperand *operator->() const { return &Op; }
1816 expr_op_iterator &operator++() {
1820 expr_op_iterator operator++(int) {
1821 expr_op_iterator T(*this);
1826 bool operator==(const expr_op_iterator &X) const {
1827 return getBase() == X.getBase();
1829 bool operator!=(const expr_op_iterator &X) const {
1830 return getBase() != X.getBase();
1834 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1837 /// \brief Visit the elements via ExprOperand wrappers.
1839 /// These range iterators visit elements through \a ExprOperand wrappers.
1840 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1843 /// \pre \a isValid() gives \c true.
1845 expr_op_iterator expr_op_begin() const {
1846 return expr_op_iterator(elements_begin());
1848 expr_op_iterator expr_op_end() const {
1849 return expr_op_iterator(elements_end());
1853 bool isValid() const;
1855 static bool classof(const Metadata *MD) {
1856 return MD->getMetadataID() == MDExpressionKind;
1860 class MDObjCProperty : public DebugNode {
1861 friend class LLVMContextImpl;
1862 friend class MDNode;
1865 unsigned Attributes;
1867 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1868 unsigned Attributes, ArrayRef<Metadata *> Ops)
1869 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1871 Line(Line), Attributes(Attributes) {}
1872 ~MDObjCProperty() {}
1874 static MDObjCProperty *
1875 getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
1876 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1877 MDType *Type, StorageType Storage, bool ShouldCreate = true) {
1878 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1879 getCanonicalMDString(Context, GetterName),
1880 getCanonicalMDString(Context, SetterName), Attributes, Type,
1881 Storage, ShouldCreate);
1883 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1884 Metadata *File, unsigned Line,
1885 MDString *GetterName, MDString *SetterName,
1886 unsigned Attributes, Metadata *Type,
1887 StorageType Storage, bool ShouldCreate = true);
1889 TempMDObjCProperty cloneImpl() const {
1890 return getTemporary(getContext(), getName(), getFile(), getLine(),
1891 getGetterName(), getSetterName(), getAttributes(),
1896 DEFINE_MDNODE_GET(MDObjCProperty,
1897 (StringRef Name, MDFile *File, unsigned Line,
1898 StringRef GetterName, StringRef SetterName,
1899 unsigned Attributes, MDType *Type),
1900 (Name, File, Line, GetterName, SetterName, Attributes,
1902 DEFINE_MDNODE_GET(MDObjCProperty,
1903 (MDString * Name, Metadata *File, unsigned Line,
1904 MDString *GetterName, MDString *SetterName,
1905 unsigned Attributes, Metadata *Type),
1906 (Name, File, Line, GetterName, SetterName, Attributes,
1909 TempMDObjCProperty clone() const { return cloneImpl(); }
1911 unsigned getLine() const { return Line; }
1912 unsigned getAttributes() const { return Attributes; }
1913 StringRef getName() const { return getStringOperand(0); }
1914 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1915 StringRef getGetterName() const { return getStringOperand(2); }
1916 StringRef getSetterName() const { return getStringOperand(3); }
1917 MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
1919 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1920 Metadata *getRawFile() const { return getOperand(1); }
1921 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1922 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1923 Metadata *getRawType() const { return getOperand(4); }
1925 static bool classof(const Metadata *MD) {
1926 return MD->getMetadataID() == MDObjCPropertyKind;
1930 class MDImportedEntity : public DebugNode {
1931 friend class LLVMContextImpl;
1932 friend class MDNode;
1936 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1937 unsigned Line, ArrayRef<Metadata *> Ops)
1938 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1939 ~MDImportedEntity() {}
1941 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1942 MDScope *Scope, Metadata *Entity,
1943 unsigned Line, StringRef Name,
1944 StorageType Storage,
1945 bool ShouldCreate = true) {
1946 return getImpl(Context, Tag, Scope, Entity, Line,
1947 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1949 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1950 Metadata *Scope, Metadata *Entity,
1951 unsigned Line, MDString *Name,
1952 StorageType Storage,
1953 bool ShouldCreate = true);
1955 TempMDImportedEntity cloneImpl() const {
1956 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1957 getLine(), getName());
1961 DEFINE_MDNODE_GET(MDImportedEntity,
1962 (unsigned Tag, MDScope *Scope, Metadata *Entity,
1963 unsigned Line, StringRef Name = ""),
1964 (Tag, Scope, Entity, Line, Name))
1965 DEFINE_MDNODE_GET(MDImportedEntity,
1966 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1967 unsigned Line, MDString *Name),
1968 (Tag, Scope, Entity, Line, Name))
1970 TempMDImportedEntity clone() const { return cloneImpl(); }
1972 unsigned getLine() const { return Line; }
1973 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1974 Metadata *getEntity() const { return getRawEntity(); }
1975 StringRef getName() const { return getStringOperand(2); }
1977 Metadata *getRawScope() const { return getOperand(0); }
1978 Metadata *getRawEntity() const { return getOperand(1); }
1979 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1981 static bool classof(const Metadata *MD) {
1982 return MD->getMetadataID() == MDImportedEntityKind;
1986 } // end namespace llvm
1988 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1989 #undef DEFINE_MDNODE_GET_UNPACK
1990 #undef DEFINE_MDNODE_GET