1 //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Declarations for metadata specific to debug info.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_DEBUGINFOMETADATA_H
15 #define LLVM_IR_DEBUGINFOMETADATA_H
17 #include "llvm/IR/Metadata.h"
18 #include "llvm/Support/Dwarf.h"
20 // Helper macros for defining get() overrides.
21 #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
22 #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
23 #define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
24 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
25 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
27 static CLASS *getIfExists(LLVMContext &Context, \
28 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
29 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
30 /* ShouldCreate */ false); \
32 static CLASS *getDistinct(LLVMContext &Context, \
33 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
34 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
36 static Temp##CLASS getTemporary(LLVMContext &Context, \
37 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
39 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
44 /// \brief Pointer union between a subclass of DebugNode and MDString.
46 /// \a MDCompositeType can be referenced via an \a MDString unique identifier.
47 /// This class allows some type safety in the face of that, requiring either a
48 /// node of a particular type or an \a MDString.
49 template <class T> class TypedDebugNodeRef {
50 const Metadata *MD = nullptr;
53 TypedDebugNodeRef(std::nullptr_t) {}
55 /// \brief Construct from a raw pointer.
56 explicit TypedDebugNodeRef(const Metadata *MD) : MD(MD) {
57 assert((!MD || isa<MDString>(MD) || isa<T>(MD)) && "Expected valid ref");
62 const TypedDebugNodeRef<U> &X,
63 typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
67 operator Metadata *() const { return const_cast<Metadata *>(MD); }
69 bool operator==(const TypedDebugNodeRef<T> &X) const { return MD == X.MD; };
70 bool operator!=(const TypedDebugNodeRef<T> &X) const { return MD != X.MD; };
72 /// \brief Create a reference.
74 /// Get a reference to \c N, using an \a MDString reference if available.
75 static TypedDebugNodeRef get(const T *N);
77 template <class MapTy> T *resolve(const MapTy &Map) const {
81 if (auto *Typed = dyn_cast<T>(MD))
82 return const_cast<T *>(Typed);
84 auto *S = cast<MDString>(MD);
86 assert(I != Map.end() && "Missing identifier in type map");
87 return cast<T>(I->second);
91 typedef TypedDebugNodeRef<DebugNode> DebugNodeRef;
92 typedef TypedDebugNodeRef<MDScope> MDScopeRef;
93 typedef TypedDebugNodeRef<MDType> MDTypeRef;
95 class MDTypeRefArray {
96 const MDTuple *N = nullptr;
99 MDTypeRefArray(const MDTuple *N) : N(N) {}
100 operator MDTuple *() const { return const_cast<MDTuple *>(N); }
101 MDTuple *operator->() const { return const_cast<MDTuple *>(N); }
102 MDTuple &operator*() const { return *const_cast<MDTuple *>(N); }
104 unsigned size() const { return N->getNumOperands(); }
105 MDTypeRef operator[](unsigned I) const { return MDTypeRef(N->getOperand(I)); }
107 class iterator : std::iterator<std::input_iterator_tag, MDTypeRef,
108 std::ptrdiff_t, void, MDTypeRef> {
109 MDNode::op_iterator I;
112 explicit iterator(MDNode::op_iterator I) : I(I) {}
113 MDTypeRef operator*() const { return MDTypeRef(*I); }
114 iterator &operator++() {
118 iterator operator++(int) {
119 iterator Temp(*this);
123 bool operator==(const iterator &X) const { return I == X.I; }
124 bool operator!=(const iterator &X) const { return I != X.I; }
127 iterator begin() const { return iterator(N->op_begin()); }
128 iterator end() const { return iterator(N->op_end()); }
131 /// \brief Tagged DWARF-like metadata node.
133 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
134 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
135 /// potentially used for non-DWARF output.
136 class DebugNode : public MDNode {
137 friend class LLVMContextImpl;
141 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
142 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
143 : MDNode(C, ID, Storage, Ops1, Ops2) {
144 assert(Tag < 1u << 16);
145 SubclassData16 = Tag;
149 template <class Ty> Ty *getOperandAs(unsigned I) const {
150 return cast_or_null<Ty>(getOperand(I));
153 StringRef getStringOperand(unsigned I) const {
154 if (auto *S = getOperandAs<MDString>(I))
155 return S->getString();
159 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
162 return MDString::get(Context, S);
166 unsigned getTag() const { return SubclassData16; }
168 /// \brief Debug info flags.
170 /// The three accessibility flags are mutually exclusive and rolled together
171 /// in the first two bits.
173 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
174 #include "llvm/IR/DebugInfoFlags.def"
175 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
178 static unsigned getFlag(StringRef Flag);
179 static const char *getFlagString(unsigned Flag);
181 /// \brief Split up a flags bitfield.
183 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
184 /// any remaining (unrecognized) bits.
185 static unsigned splitFlags(unsigned Flags,
186 SmallVectorImpl<unsigned> &SplitFlags);
188 DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
190 static bool classof(const Metadata *MD) {
191 switch (MD->getMetadataID()) {
194 case GenericDebugNodeKind:
196 case MDEnumeratorKind:
197 case MDBasicTypeKind:
198 case MDDerivedTypeKind:
199 case MDCompositeTypeKind:
200 case MDSubroutineTypeKind:
202 case MDCompileUnitKind:
203 case MDSubprogramKind:
204 case MDLexicalBlockKind:
205 case MDLexicalBlockFileKind:
206 case MDNamespaceKind:
207 case MDTemplateTypeParameterKind:
208 case MDTemplateValueParameterKind:
209 case MDGlobalVariableKind:
210 case MDLocalVariableKind:
211 case MDObjCPropertyKind:
212 case MDImportedEntityKind:
219 struct simplify_type<const TypedDebugNodeRef<T>> {
220 typedef Metadata *SimpleType;
221 static SimpleType getSimplifiedValue(const TypedDebugNodeRef<T> &MD) {
227 struct simplify_type<TypedDebugNodeRef<T>>
228 : simplify_type<const TypedDebugNodeRef<T>> {};
230 /// \brief Generic tagged DWARF-like metadata node.
232 /// An un-specialized DWARF-like metadata node. The first operand is a
233 /// (possibly empty) null-separated \a MDString header that contains arbitrary
234 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
235 /// to other metadata.
236 class GenericDebugNode : public DebugNode {
237 friend class LLVMContextImpl;
240 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
241 unsigned Tag, ArrayRef<Metadata *> Ops1,
242 ArrayRef<Metadata *> Ops2)
243 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
246 ~GenericDebugNode() { dropAllReferences(); }
248 void setHash(unsigned Hash) { SubclassData32 = Hash; }
249 void recalculateHash();
251 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
253 ArrayRef<Metadata *> DwarfOps,
255 bool ShouldCreate = true) {
256 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
257 DwarfOps, Storage, ShouldCreate);
260 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
262 ArrayRef<Metadata *> DwarfOps,
264 bool ShouldCreate = true);
266 TempGenericDebugNode cloneImpl() const {
268 getContext(), getTag(), getHeader(),
269 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
273 unsigned getHash() const { return SubclassData32; }
275 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
276 ArrayRef<Metadata *> DwarfOps),
277 (Tag, Header, DwarfOps))
278 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
279 ArrayRef<Metadata *> DwarfOps),
280 (Tag, Header, DwarfOps))
282 /// \brief Return a (temporary) clone of this.
283 TempGenericDebugNode clone() const { return cloneImpl(); }
285 unsigned getTag() const { return SubclassData16; }
286 StringRef getHeader() const { return getStringOperand(0); }
288 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
289 op_iterator dwarf_op_end() const { return op_end(); }
290 op_range dwarf_operands() const {
291 return op_range(dwarf_op_begin(), dwarf_op_end());
294 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
295 const MDOperand &getDwarfOperand(unsigned I) const {
296 return getOperand(I + 1);
298 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
299 replaceOperandWith(I + 1, New);
302 static bool classof(const Metadata *MD) {
303 return MD->getMetadataID() == GenericDebugNodeKind;
307 /// \brief Array subrange.
309 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
311 class MDSubrange : public DebugNode {
312 friend class LLVMContextImpl;
318 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count,
320 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
322 Count(Count), LowerBound(LowerBound) {}
325 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count,
326 int64_t LowerBound, StorageType Storage,
327 bool ShouldCreate = true);
329 TempMDSubrange cloneImpl() const {
330 return getTemporary(getContext(), getCount(), getLowerBound());
334 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t LowerBound = 0),
337 TempMDSubrange clone() const { return cloneImpl(); }
339 int64_t getLowerBound() const { return LowerBound; }
340 int64_t getCount() const { return Count; }
342 static bool classof(const Metadata *MD) {
343 return MD->getMetadataID() == MDSubrangeKind;
347 /// \brief Enumeration value.
349 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
350 /// longer creates a type cycle.
351 class MDEnumerator : public DebugNode {
352 friend class LLVMContextImpl;
357 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
358 ArrayRef<Metadata *> Ops)
359 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
363 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
364 StringRef Name, StorageType Storage,
365 bool ShouldCreate = true) {
366 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
369 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
370 MDString *Name, StorageType Storage,
371 bool ShouldCreate = true);
373 TempMDEnumerator cloneImpl() const {
374 return getTemporary(getContext(), getValue(), getName());
378 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
380 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
383 TempMDEnumerator clone() const { return cloneImpl(); }
385 int64_t getValue() const { return Value; }
386 StringRef getName() const { return getStringOperand(0); }
388 MDString *getRawName() const { return getOperandAs<MDString>(0); }
390 static bool classof(const Metadata *MD) {
391 return MD->getMetadataID() == MDEnumeratorKind;
395 /// \brief Base class for scope-like contexts.
397 /// Base class for lexical scopes and types (which are also declaration
400 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
401 class MDScope : public DebugNode {
403 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
404 ArrayRef<Metadata *> Ops)
405 : DebugNode(C, ID, Storage, Tag, Ops) {}
409 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
411 /// \brief Return the raw underlying file.
413 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
414 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
415 /// this. Otherwise, return the first operand, which is where all other
416 /// subclasses store their file pointer.
417 Metadata *getRawFile() const {
418 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
419 : static_cast<Metadata *>(getOperand(0));
422 MDScopeRef getRef() const { return MDScopeRef::get(this); }
424 static bool classof(const Metadata *MD) {
425 switch (MD->getMetadataID()) {
428 case MDBasicTypeKind:
429 case MDDerivedTypeKind:
430 case MDCompositeTypeKind:
431 case MDSubroutineTypeKind:
433 case MDCompileUnitKind:
434 case MDSubprogramKind:
435 case MDLexicalBlockKind:
436 case MDLexicalBlockFileKind:
437 case MDNamespaceKind:
445 /// TODO: Merge with directory/file node (including users).
446 /// TODO: Canonicalize paths on creation.
447 class MDFile : public MDScope {
448 friend class LLVMContextImpl;
451 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
452 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
455 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
456 StringRef Directory, StorageType Storage,
457 bool ShouldCreate = true) {
458 return getImpl(Context, getCanonicalMDString(Context, Filename),
459 getCanonicalMDString(Context, Directory), Storage,
462 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
463 MDString *Directory, StorageType Storage,
464 bool ShouldCreate = true);
466 TempMDFile cloneImpl() const {
467 return getTemporary(getContext(), getFilename(), getDirectory());
471 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
472 (Filename, Directory))
473 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
474 (Filename, Directory))
476 TempMDFile clone() const { return cloneImpl(); }
478 StringRef getFilename() const { return getStringOperand(0); }
479 StringRef getDirectory() const { return getStringOperand(1); }
481 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
482 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
484 static bool classof(const Metadata *MD) {
485 return MD->getMetadataID() == MDFileKind;
489 /// \brief Base class for types.
491 /// TODO: Remove the hardcoded name and context, since many types don't use
493 /// TODO: Split up flags.
494 class MDType : public MDScope {
498 uint64_t AlignInBits;
499 uint64_t OffsetInBits;
502 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
503 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
504 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
505 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
506 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
507 OffsetInBits(OffsetInBits) {}
511 TempMDType clone() const {
512 return TempMDType(cast<MDType>(MDNode::clone().release()));
515 unsigned getLine() const { return Line; }
516 uint64_t getSizeInBits() const { return SizeInBits; }
517 uint64_t getAlignInBits() const { return AlignInBits; }
518 uint64_t getOffsetInBits() const { return OffsetInBits; }
519 unsigned getFlags() const { return Flags; }
521 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
522 StringRef getName() const { return getStringOperand(2); }
525 Metadata *getRawScope() const { return getOperand(1); }
526 MDString *getRawName() const { return getOperandAs<MDString>(2); }
528 void setFlags(unsigned NewFlags) {
529 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
533 MDTypeRef getRef() const { return MDTypeRef::get(this); }
535 static bool classof(const Metadata *MD) {
536 switch (MD->getMetadataID()) {
539 case MDBasicTypeKind:
540 case MDDerivedTypeKind:
541 case MDCompositeTypeKind:
542 case MDSubroutineTypeKind:
548 /// \brief Basic type.
550 /// TODO: Split out DW_TAG_unspecified_type.
551 /// TODO: Drop unused accessors.
552 class MDBasicType : public MDType {
553 friend class LLVMContextImpl;
558 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
559 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
560 ArrayRef<Metadata *> Ops)
561 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
563 Encoding(Encoding) {}
566 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
567 StringRef Name, uint64_t SizeInBits,
568 uint64_t AlignInBits, unsigned Encoding,
569 StorageType Storage, bool ShouldCreate = true) {
570 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
571 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
573 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
574 MDString *Name, uint64_t SizeInBits,
575 uint64_t AlignInBits, unsigned Encoding,
576 StorageType Storage, bool ShouldCreate = true);
578 TempMDBasicType cloneImpl() const {
579 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
580 getAlignInBits(), getEncoding());
584 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
585 (Tag, Name, 0, 0, 0))
586 DEFINE_MDNODE_GET(MDBasicType,
587 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
588 uint64_t AlignInBits, unsigned Encoding),
589 (Tag, Name, SizeInBits, AlignInBits, Encoding))
590 DEFINE_MDNODE_GET(MDBasicType,
591 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
592 uint64_t AlignInBits, unsigned Encoding),
593 (Tag, Name, SizeInBits, AlignInBits, Encoding))
595 TempMDBasicType clone() const { return cloneImpl(); }
597 unsigned getEncoding() const { return Encoding; }
599 static bool classof(const Metadata *MD) {
600 return MD->getMetadataID() == MDBasicTypeKind;
604 /// \brief Base class for MDDerivedType and MDCompositeType.
606 /// TODO: Delete; they're not really related.
607 class MDDerivedTypeBase : public MDType {
609 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
610 unsigned Tag, unsigned Line, uint64_t SizeInBits,
611 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
612 ArrayRef<Metadata *> Ops)
613 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
615 ~MDDerivedTypeBase() {}
618 MDTypeRef getBaseType() const { return MDTypeRef(getRawBaseType()); }
619 Metadata *getRawBaseType() const { return getOperand(3); }
621 static bool classof(const Metadata *MD) {
622 return MD->getMetadataID() == MDDerivedTypeKind ||
623 MD->getMetadataID() == MDCompositeTypeKind ||
624 MD->getMetadataID() == MDSubroutineTypeKind;
628 /// \brief Derived types.
630 /// This includes qualified types, pointers, references, friends, typedefs, and
633 /// TODO: Split out members (inheritance, fields, methods, etc.).
634 class MDDerivedType : public MDDerivedTypeBase {
635 friend class LLVMContextImpl;
638 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
639 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
640 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
641 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
642 AlignInBits, OffsetInBits, Flags, Ops) {}
645 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
646 StringRef Name, MDFile *File, unsigned Line,
647 MDScopeRef Scope, MDTypeRef BaseType,
648 uint64_t SizeInBits, uint64_t AlignInBits,
649 uint64_t OffsetInBits, unsigned Flags,
650 Metadata *ExtraData, StorageType Storage,
651 bool ShouldCreate = true) {
652 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
653 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
654 Flags, ExtraData, Storage, ShouldCreate);
656 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
657 MDString *Name, Metadata *File, unsigned Line,
658 Metadata *Scope, Metadata *BaseType,
659 uint64_t SizeInBits, uint64_t AlignInBits,
660 uint64_t OffsetInBits, unsigned Flags,
661 Metadata *ExtraData, StorageType Storage,
662 bool ShouldCreate = true);
664 TempMDDerivedType cloneImpl() const {
665 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
666 getScope(), getBaseType(), getSizeInBits(),
667 getAlignInBits(), getOffsetInBits(), getFlags(),
672 DEFINE_MDNODE_GET(MDDerivedType,
673 (unsigned Tag, MDString *Name, Metadata *File,
674 unsigned Line, Metadata *Scope, Metadata *BaseType,
675 uint64_t SizeInBits, uint64_t AlignInBits,
676 uint64_t OffsetInBits, unsigned Flags,
677 Metadata *ExtraData = nullptr),
678 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
679 AlignInBits, OffsetInBits, Flags, ExtraData))
680 DEFINE_MDNODE_GET(MDDerivedType,
681 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
682 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
683 uint64_t AlignInBits, uint64_t OffsetInBits,
684 unsigned Flags, Metadata *ExtraData = nullptr),
685 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
686 AlignInBits, OffsetInBits, Flags, ExtraData))
688 TempMDDerivedType clone() const { return cloneImpl(); }
690 /// \brief Get extra data associated with this derived type.
692 /// Class type for pointer-to-members, objective-c property node for ivars,
693 /// or global constant wrapper for static members.
695 /// TODO: Separate out types that need this extra operand: pointer-to-member
696 /// types and member fields (static members and ivars).
697 Metadata *getExtraData() const { return getRawExtraData(); }
698 Metadata *getRawExtraData() const { return getOperand(4); }
700 static bool classof(const Metadata *MD) {
701 return MD->getMetadataID() == MDDerivedTypeKind;
705 /// \brief Base class for MDCompositeType and MDSubroutineType.
707 /// TODO: Delete; they're not really related.
708 class MDCompositeTypeBase : public MDDerivedTypeBase {
709 unsigned RuntimeLang;
712 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
713 unsigned Tag, unsigned Line, unsigned RuntimeLang,
714 uint64_t SizeInBits, uint64_t AlignInBits,
715 uint64_t OffsetInBits, unsigned Flags,
716 ArrayRef<Metadata *> Ops)
717 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
718 OffsetInBits, Flags, Ops),
719 RuntimeLang(RuntimeLang) {}
720 ~MDCompositeTypeBase() {}
723 MDTuple *getElements() const {
724 return cast_or_null<MDTuple>(getRawElements());
726 MDTypeRef getVTableHolder() const { return MDTypeRef(getRawVTableHolder()); }
727 MDTemplateParameterArray getTemplateParams() const {
728 return cast_or_null<MDTuple>(getRawTemplateParams());
730 StringRef getIdentifier() const { return getStringOperand(7); }
731 unsigned getRuntimeLang() const { return RuntimeLang; }
733 Metadata *getRawElements() const { return getOperand(4); }
734 Metadata *getRawVTableHolder() const { return getOperand(5); }
735 Metadata *getRawTemplateParams() const { return getOperand(6); }
736 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
738 /// \brief Replace operands.
740 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
741 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
742 /// of its movement if necessary.
744 void replaceElements(MDTuple *Elements) {
746 if (auto *Old = cast_or_null<MDTuple>(getElements()))
747 for (const auto &Op : Old->operands())
748 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
749 "Lost a member during member list replacement");
751 replaceOperandWith(4, Elements);
753 void replaceVTableHolder(MDTypeRef VTableHolder) {
754 replaceOperandWith(5, VTableHolder);
756 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
757 replaceOperandWith(6, TemplateParams);
761 static bool classof(const Metadata *MD) {
762 return MD->getMetadataID() == MDCompositeTypeKind ||
763 MD->getMetadataID() == MDSubroutineTypeKind;
767 /// \brief Composite types.
769 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
770 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
771 class MDCompositeType : public MDCompositeTypeBase {
772 friend class LLVMContextImpl;
775 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
776 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
777 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
778 ArrayRef<Metadata *> Ops)
779 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
780 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
782 ~MDCompositeType() {}
784 static MDCompositeType *
785 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
786 unsigned Line, MDScopeRef Scope, MDTypeRef BaseType,
787 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
788 uint64_t Flags, MDTuple *Elements, unsigned RuntimeLang,
789 MDTypeRef VTableHolder, MDTemplateParameterArray TemplateParams,
790 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
791 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
792 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
793 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
794 getCanonicalMDString(Context, Identifier), Storage,
797 static MDCompositeType *
798 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
799 unsigned Line, Metadata *Scope, Metadata *BaseType,
800 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
801 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
802 Metadata *VTableHolder, Metadata *TemplateParams,
803 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
805 TempMDCompositeType cloneImpl() const {
806 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
807 getScope(), getBaseType(), getSizeInBits(),
808 getAlignInBits(), getOffsetInBits(), getFlags(),
809 getElements(), getRuntimeLang(), getVTableHolder(),
810 getTemplateParams(), getIdentifier());
814 DEFINE_MDNODE_GET(MDCompositeType,
815 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
816 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
817 uint64_t AlignInBits, uint64_t OffsetInBits,
818 unsigned Flags, MDTuple *Elements, unsigned RuntimeLang,
819 MDTypeRef VTableHolder,
820 MDTemplateParameterArray TemplateParams = nullptr,
821 StringRef Identifier = ""),
822 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
823 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
824 VTableHolder, TemplateParams, Identifier))
825 DEFINE_MDNODE_GET(MDCompositeType,
826 (unsigned Tag, MDString *Name, Metadata *File,
827 unsigned Line, Metadata *Scope, Metadata *BaseType,
828 uint64_t SizeInBits, uint64_t AlignInBits,
829 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
830 unsigned RuntimeLang, Metadata *VTableHolder,
831 Metadata *TemplateParams = nullptr,
832 MDString *Identifier = nullptr),
833 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
834 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
835 VTableHolder, TemplateParams, Identifier))
837 TempMDCompositeType clone() const { return cloneImpl(); }
839 static bool classof(const Metadata *MD) {
840 return MD->getMetadataID() == MDCompositeTypeKind;
844 template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) {
846 if (auto *Composite = dyn_cast<MDCompositeType>(N))
847 if (auto *S = Composite->getRawIdentifier())
848 return TypedDebugNodeRef<T>(S);
849 return TypedDebugNodeRef<T>(N);
852 /// \brief Type array for a subprogram.
854 /// TODO: Detach from CompositeType, and fold the array of types in directly
856 class MDSubroutineType : public MDCompositeTypeBase {
857 friend class LLVMContextImpl;
860 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
861 ArrayRef<Metadata *> Ops)
862 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
863 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
865 ~MDSubroutineType() {}
867 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
868 Metadata *TypeArray, StorageType Storage,
869 bool ShouldCreate = true);
871 TempMDSubroutineType cloneImpl() const {
872 return getTemporary(getContext(), getFlags(), getTypeArray());
876 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
879 TempMDSubroutineType clone() const { return cloneImpl(); }
881 MDTypeRefArray getTypeArray() const { return getElements(); }
882 Metadata *getRawTypeArray() const { return getRawElements(); }
884 static bool classof(const Metadata *MD) {
885 return MD->getMetadataID() == MDSubroutineTypeKind;
889 /// \brief Compile unit.
890 class MDCompileUnit : public MDScope {
891 friend class LLVMContextImpl;
894 unsigned SourceLanguage;
896 unsigned RuntimeVersion;
897 unsigned EmissionKind;
899 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
900 bool IsOptimized, unsigned RuntimeVersion,
901 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
902 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
903 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
904 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
907 static MDCompileUnit *
908 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
909 StringRef Producer, bool IsOptimized, StringRef Flags,
910 unsigned RuntimeVersion, StringRef SplitDebugFilename,
911 unsigned EmissionKind, MDTuple *EnumTypes, MDTuple *RetainedTypes,
912 MDTuple *Subprograms, MDTuple *GlobalVariables,
913 MDTuple *ImportedEntities, StorageType Storage,
914 bool ShouldCreate = true) {
915 return getImpl(Context, SourceLanguage, File,
916 getCanonicalMDString(Context, Producer), IsOptimized,
917 getCanonicalMDString(Context, Flags), RuntimeVersion,
918 getCanonicalMDString(Context, SplitDebugFilename),
919 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
920 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
922 static MDCompileUnit *
923 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
924 MDString *Producer, bool IsOptimized, MDString *Flags,
925 unsigned RuntimeVersion, MDString *SplitDebugFilename,
926 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
927 Metadata *Subprograms, Metadata *GlobalVariables,
928 Metadata *ImportedEntities, StorageType Storage,
929 bool ShouldCreate = true);
931 TempMDCompileUnit cloneImpl() const {
933 getContext(), getSourceLanguage(), getFile(), getProducer(),
934 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
935 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
936 getGlobalVariables(), getImportedEntities());
940 DEFINE_MDNODE_GET(MDCompileUnit,
941 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
942 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
943 StringRef SplitDebugFilename, unsigned EmissionKind,
944 MDTuple *EnumTypes, MDTuple *RetainedTypes,
945 MDTuple *Subprograms, MDTuple *GlobalVariables,
946 MDTuple *ImportedEntities),
947 (SourceLanguage, File, Producer, IsOptimized, Flags,
948 RuntimeVersion, SplitDebugFilename, EmissionKind,
949 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
951 DEFINE_MDNODE_GET(MDCompileUnit,
952 (unsigned SourceLanguage, Metadata *File,
953 MDString *Producer, bool IsOptimized, MDString *Flags,
954 unsigned RuntimeVersion, MDString *SplitDebugFilename,
955 unsigned EmissionKind, Metadata *EnumTypes,
956 Metadata *RetainedTypes, Metadata *Subprograms,
957 Metadata *GlobalVariables, Metadata *ImportedEntities),
958 (SourceLanguage, File, Producer, IsOptimized, Flags,
959 RuntimeVersion, SplitDebugFilename, EmissionKind,
960 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
963 TempMDCompileUnit clone() const { return cloneImpl(); }
965 unsigned getSourceLanguage() const { return SourceLanguage; }
966 bool isOptimized() const { return IsOptimized; }
967 unsigned getRuntimeVersion() const { return RuntimeVersion; }
968 unsigned getEmissionKind() const { return EmissionKind; }
969 StringRef getProducer() const { return getStringOperand(1); }
970 StringRef getFlags() const { return getStringOperand(2); }
971 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
972 MDCompositeTypeArray getEnumTypes() const {
973 return cast_or_null<MDTuple>(getRawEnumTypes());
975 MDTypeArray getRetainedTypes() const {
976 return cast_or_null<MDTuple>(getRawRetainedTypes());
978 MDSubprogramArray getSubprograms() const {
979 return cast_or_null<MDTuple>(getRawSubprograms());
981 MDGlobalVariableArray getGlobalVariables() const {
982 return cast_or_null<MDTuple>(getRawGlobalVariables());
984 MDImportedEntityArray getImportedEntities() const {
985 return cast_or_null<MDTuple>(getRawImportedEntities());
988 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
989 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
990 MDString *getRawSplitDebugFilename() const {
991 return getOperandAs<MDString>(3);
993 Metadata *getRawEnumTypes() const { return getOperand(4); }
994 Metadata *getRawRetainedTypes() const { return getOperand(5); }
995 Metadata *getRawSubprograms() const { return getOperand(6); }
996 Metadata *getRawGlobalVariables() const { return getOperand(7); }
997 Metadata *getRawImportedEntities() const { return getOperand(8); }
999 /// \brief Replace arrays.
1001 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1002 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1003 /// MDCompileUnit should be fairly rare.
1005 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
1006 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
1009 static bool classof(const Metadata *MD) {
1010 return MD->getMetadataID() == MDCompileUnitKind;
1014 /// \brief A scope for locals.
1016 /// A legal scope for lexical blocks, local variables, and debug info
1017 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
1018 /// MDLexicalBlockFile.
1019 class MDLocalScope : public MDScope {
1021 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1022 ArrayRef<Metadata *> Ops)
1023 : MDScope(C, ID, Storage, Tag, Ops) {}
1027 /// \brief Get the subprogram for this scope.
1029 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
1031 MDSubprogram *getSubprogram() const;
1033 static bool classof(const Metadata *MD) {
1034 return MD->getMetadataID() == MDSubprogramKind ||
1035 MD->getMetadataID() == MDLexicalBlockKind ||
1036 MD->getMetadataID() == MDLexicalBlockFileKind;
1040 /// \brief Debug location.
1042 /// A debug location in source code, used for debug info and otherwise.
1043 class MDLocation : public MDNode {
1044 friend class LLVMContextImpl;
1045 friend class MDNode;
1047 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
1048 unsigned Column, ArrayRef<Metadata *> MDs);
1049 ~MDLocation() { dropAllReferences(); }
1051 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1052 unsigned Column, Metadata *Scope,
1053 Metadata *InlinedAt, StorageType Storage,
1054 bool ShouldCreate = true);
1055 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1056 unsigned Column, MDLocalScope *Scope,
1057 MDLocation *InlinedAt, StorageType Storage,
1058 bool ShouldCreate = true) {
1059 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1060 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1063 TempMDLocation cloneImpl() const {
1064 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
1068 // Disallow replacing operands.
1069 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1072 DEFINE_MDNODE_GET(MDLocation,
1073 (unsigned Line, unsigned Column, Metadata *Scope,
1074 Metadata *InlinedAt = nullptr),
1075 (Line, Column, Scope, InlinedAt))
1076 DEFINE_MDNODE_GET(MDLocation,
1077 (unsigned Line, unsigned Column, MDLocalScope *Scope,
1078 MDLocation *InlinedAt = nullptr),
1079 (Line, Column, Scope, InlinedAt))
1081 /// \brief Return a (temporary) clone of this.
1082 TempMDLocation clone() const { return cloneImpl(); }
1084 unsigned getLine() const { return SubclassData32; }
1085 unsigned getColumn() const { return SubclassData16; }
1086 MDLocalScope *getScope() const {
1087 return cast<MDLocalScope>(getRawScope());
1089 MDLocation *getInlinedAt() const {
1090 return cast_or_null<MDLocation>(getRawInlinedAt());
1093 /// \brief Get the scope where this is inlined.
1095 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1097 MDLocalScope *getInlinedAtScope() const {
1098 if (auto *IA = getInlinedAt())
1099 return IA->getInlinedAtScope();
1103 Metadata *getRawScope() const { return getOperand(0); }
1104 Metadata *getRawInlinedAt() const {
1105 if (getNumOperands() == 2)
1106 return getOperand(1);
1110 static bool classof(const Metadata *MD) {
1111 return MD->getMetadataID() == MDLocationKind;
1115 /// \brief Subprogram description.
1117 /// TODO: Remove DisplayName. It's always equal to Name.
1118 /// TODO: Split up flags.
1119 class MDSubprogram : public MDLocalScope {
1120 friend class LLVMContextImpl;
1121 friend class MDNode;
1125 unsigned Virtuality;
1126 unsigned VirtualIndex;
1132 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1133 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1134 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
1135 bool IsOptimized, ArrayRef<Metadata *> Ops)
1136 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1138 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
1139 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
1140 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
1143 static MDSubprogram *
1144 getImpl(LLVMContext &Context, MDScopeRef Scope, StringRef Name,
1145 StringRef LinkageName, MDFile *File, unsigned Line,
1146 MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1147 unsigned ScopeLine, MDTypeRef ContainingType, unsigned Virtuality,
1148 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1149 ConstantAsMetadata *Function, MDTemplateParameterArray TemplateParams,
1150 MDSubprogram *Declaration, MDLocalVariableArray Variables,
1151 StorageType Storage, bool ShouldCreate = true) {
1152 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1153 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1154 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1155 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1156 TemplateParams, Declaration, Variables, Storage,
1159 static MDSubprogram *
1160 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1161 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1162 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1163 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1164 unsigned Flags, bool IsOptimized, Metadata *Function,
1165 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1166 StorageType Storage, bool ShouldCreate = true);
1168 TempMDSubprogram cloneImpl() const {
1169 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1170 getFile(), getLine(), getType(), isLocalToUnit(),
1171 isDefinition(), getScopeLine(), getContainingType(),
1172 getVirtuality(), getVirtualIndex(), getFlags(),
1173 isOptimized(), getFunction(), getTemplateParams(),
1174 getDeclaration(), getVariables());
1178 DEFINE_MDNODE_GET(MDSubprogram,
1179 (MDScopeRef Scope, StringRef Name, StringRef LinkageName,
1180 MDFile *File, unsigned Line, MDSubroutineType *Type,
1181 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1182 MDTypeRef ContainingType, unsigned Virtuality,
1183 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1184 ConstantAsMetadata *Function = nullptr,
1185 MDTemplateParameterArray TemplateParams = nullptr,
1186 MDSubprogram *Declaration = nullptr,
1187 MDLocalVariableArray Variables = nullptr),
1188 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1189 IsDefinition, ScopeLine, ContainingType, Virtuality,
1190 VirtualIndex, Flags, IsOptimized, Function, TemplateParams,
1191 Declaration, Variables))
1194 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1195 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1196 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1197 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1198 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1199 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1200 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1201 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1202 Function, TemplateParams, Declaration, Variables))
1204 TempMDSubprogram clone() const { return cloneImpl(); }
1207 unsigned getLine() const { return Line; }
1208 unsigned getVirtuality() const { return Virtuality; }
1209 unsigned getVirtualIndex() const { return VirtualIndex; }
1210 unsigned getScopeLine() const { return ScopeLine; }
1211 unsigned getFlags() const { return Flags; }
1212 bool isLocalToUnit() const { return IsLocalToUnit; }
1213 bool isDefinition() const { return IsDefinition; }
1214 bool isOptimized() const { return IsOptimized; }
1216 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
1218 StringRef getName() const { return getStringOperand(2); }
1219 StringRef getDisplayName() const { return getStringOperand(3); }
1220 StringRef getLinkageName() const { return getStringOperand(4); }
1222 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1223 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1225 MDSubroutineType *getType() const {
1226 return cast_or_null<MDSubroutineType>(getRawType());
1228 MDTypeRef getContainingType() const {
1229 return MDTypeRef(getRawContainingType());
1232 ConstantAsMetadata *getFunction() const {
1233 return cast_or_null<ConstantAsMetadata>(getRawFunction());
1235 MDTemplateParameterArray getTemplateParams() const {
1236 return cast_or_null<MDTuple>(getRawTemplateParams());
1238 MDSubprogram *getDeclaration() const {
1239 return cast_or_null<MDSubprogram>(getRawDeclaration());
1241 MDLocalVariableArray getVariables() const {
1242 return cast_or_null<MDTuple>(getRawVariables());
1245 Metadata *getRawScope() const { return getOperand(1); }
1246 Metadata *getRawType() const { return getOperand(5); }
1247 Metadata *getRawContainingType() const { return getOperand(6); }
1248 Metadata *getRawFunction() const { return getOperand(7); }
1249 Metadata *getRawTemplateParams() const { return getOperand(8); }
1250 Metadata *getRawDeclaration() const { return getOperand(9); }
1251 Metadata *getRawVariables() const { return getOperand(10); }
1253 /// \brief Replace the function.
1255 /// If \a isUniqued() and not \a isResolved(), this could node will be
1256 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1257 /// that's a problem.
1259 void replaceFunction(Function *F);
1260 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1261 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1264 static bool classof(const Metadata *MD) {
1265 return MD->getMetadataID() == MDSubprogramKind;
1269 class MDLexicalBlockBase : public MDLocalScope {
1271 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1272 ArrayRef<Metadata *> Ops)
1273 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1274 ~MDLexicalBlockBase() {}
1277 MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
1279 Metadata *getRawScope() const { return getOperand(1); }
1281 static bool classof(const Metadata *MD) {
1282 return MD->getMetadataID() == MDLexicalBlockKind ||
1283 MD->getMetadataID() == MDLexicalBlockFileKind;
1287 class MDLexicalBlock : public MDLexicalBlockBase {
1288 friend class LLVMContextImpl;
1289 friend class MDNode;
1294 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1295 unsigned Column, ArrayRef<Metadata *> Ops)
1296 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1298 ~MDLexicalBlock() {}
1300 static MDLexicalBlock *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1301 MDFile *File, unsigned Line, unsigned Column,
1302 StorageType Storage,
1303 bool ShouldCreate = true) {
1304 return getImpl(Context, static_cast<Metadata *>(Scope),
1305 static_cast<Metadata *>(File), Line, Column, Storage,
1309 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1310 Metadata *File, unsigned Line, unsigned Column,
1311 StorageType Storage, bool ShouldCreate = true);
1313 TempMDLexicalBlock cloneImpl() const {
1314 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1319 DEFINE_MDNODE_GET(MDLexicalBlock, (MDLocalScope * Scope, MDFile *File,
1320 unsigned Line, unsigned Column),
1321 (Scope, File, Line, Column))
1322 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1323 unsigned Line, unsigned Column),
1324 (Scope, File, Line, Column))
1326 TempMDLexicalBlock clone() const { return cloneImpl(); }
1328 unsigned getLine() const { return Line; }
1329 unsigned getColumn() const { return Column; }
1331 static bool classof(const Metadata *MD) {
1332 return MD->getMetadataID() == MDLexicalBlockKind;
1336 class MDLexicalBlockFile : public MDLexicalBlockBase {
1337 friend class LLVMContextImpl;
1338 friend class MDNode;
1340 unsigned Discriminator;
1342 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1343 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1344 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1345 Discriminator(Discriminator) {}
1346 ~MDLexicalBlockFile() {}
1348 static MDLexicalBlockFile *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1349 MDFile *File, unsigned Discriminator,
1350 StorageType Storage,
1351 bool ShouldCreate = true) {
1352 return getImpl(Context, static_cast<Metadata *>(Scope),
1353 static_cast<Metadata *>(File), Discriminator, Storage,
1357 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1358 Metadata *File, unsigned Discriminator,
1359 StorageType Storage,
1360 bool ShouldCreate = true);
1362 TempMDLexicalBlockFile cloneImpl() const {
1363 return getTemporary(getContext(), getScope(), getFile(),
1364 getDiscriminator());
1368 DEFINE_MDNODE_GET(MDLexicalBlockFile, (MDLocalScope * Scope, MDFile *File,
1369 unsigned Discriminator),
1370 (Scope, File, Discriminator))
1371 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1372 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1373 (Scope, File, Discriminator))
1375 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1377 unsigned getDiscriminator() const { return Discriminator; }
1379 static bool classof(const Metadata *MD) {
1380 return MD->getMetadataID() == MDLexicalBlockFileKind;
1384 class MDNamespace : public MDScope {
1385 friend class LLVMContextImpl;
1386 friend class MDNode;
1390 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1391 ArrayRef<Metadata *> Ops)
1392 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1397 static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
1398 MDFile *File, StringRef Name, unsigned Line,
1399 StorageType Storage, bool ShouldCreate = true) {
1400 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1401 Line, Storage, ShouldCreate);
1403 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1404 Metadata *File, MDString *Name, unsigned Line,
1405 StorageType Storage, bool ShouldCreate = true);
1407 TempMDNamespace cloneImpl() const {
1408 return getTemporary(getContext(), getScope(), getFile(), getName(),
1413 DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
1415 (Scope, File, Name, Line))
1416 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1417 MDString *Name, unsigned Line),
1418 (Scope, File, Name, Line))
1420 TempMDNamespace clone() const { return cloneImpl(); }
1422 unsigned getLine() const { return Line; }
1423 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1424 StringRef getName() const { return getStringOperand(2); }
1426 Metadata *getRawScope() const { return getOperand(1); }
1427 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1429 static bool classof(const Metadata *MD) {
1430 return MD->getMetadataID() == MDNamespaceKind;
1434 /// \brief Base class for template parameters.
1435 class MDTemplateParameter : public DebugNode {
1437 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1438 unsigned Tag, ArrayRef<Metadata *> Ops)
1439 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1440 ~MDTemplateParameter() {}
1443 StringRef getName() const { return getStringOperand(0); }
1444 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1446 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1447 Metadata *getRawType() const { return getOperand(1); }
1449 static bool classof(const Metadata *MD) {
1450 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1451 MD->getMetadataID() == MDTemplateValueParameterKind;
1455 class MDTemplateTypeParameter : public MDTemplateParameter {
1456 friend class LLVMContextImpl;
1457 friend class MDNode;
1459 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1460 ArrayRef<Metadata *> Ops)
1461 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1462 dwarf::DW_TAG_template_type_parameter, Ops) {}
1463 ~MDTemplateTypeParameter() {}
1465 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1466 MDTypeRef Type, StorageType Storage,
1467 bool ShouldCreate = true) {
1468 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1471 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1472 Metadata *Type, StorageType Storage,
1473 bool ShouldCreate = true);
1475 TempMDTemplateTypeParameter cloneImpl() const {
1476 return getTemporary(getContext(), getName(), getType());
1480 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, MDTypeRef Type),
1482 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1485 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1487 static bool classof(const Metadata *MD) {
1488 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1492 class MDTemplateValueParameter : public MDTemplateParameter {
1493 friend class LLVMContextImpl;
1494 friend class MDNode;
1496 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1497 unsigned Tag, ArrayRef<Metadata *> Ops)
1498 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1500 ~MDTemplateValueParameter() {}
1502 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1503 StringRef Name, MDTypeRef Type,
1504 Metadata *Value, StorageType Storage,
1505 bool ShouldCreate = true) {
1506 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1507 Value, Storage, ShouldCreate);
1509 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1510 MDString *Name, Metadata *Type,
1511 Metadata *Value, StorageType Storage,
1512 bool ShouldCreate = true);
1514 TempMDTemplateValueParameter cloneImpl() const {
1515 return getTemporary(getContext(), getTag(), getName(), getType(),
1520 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1521 MDTypeRef Type, Metadata *Value),
1522 (Tag, Name, Type, Value))
1523 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1524 Metadata *Type, Metadata *Value),
1525 (Tag, Name, Type, Value))
1527 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1529 Metadata *getValue() const { return getOperand(2); }
1531 static bool classof(const Metadata *MD) {
1532 return MD->getMetadataID() == MDTemplateValueParameterKind;
1536 /// \brief Base class for variables.
1538 /// TODO: Hardcode to DW_TAG_variable.
1539 class MDVariable : public DebugNode {
1543 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1544 unsigned Line, ArrayRef<Metadata *> Ops)
1545 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1549 unsigned getLine() const { return Line; }
1550 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1551 StringRef getName() const { return getStringOperand(1); }
1552 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1553 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1555 Metadata *getRawScope() const { return getOperand(0); }
1556 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1557 Metadata *getRawFile() const { return getOperand(2); }
1558 Metadata *getRawType() const { return getOperand(3); }
1560 static bool classof(const Metadata *MD) {
1561 return MD->getMetadataID() == MDLocalVariableKind ||
1562 MD->getMetadataID() == MDGlobalVariableKind;
1566 /// \brief Global variables.
1568 /// TODO: Remove DisplayName. It's always equal to Name.
1569 class MDGlobalVariable : public MDVariable {
1570 friend class LLVMContextImpl;
1571 friend class MDNode;
1576 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1577 bool IsLocalToUnit, bool IsDefinition,
1578 ArrayRef<Metadata *> Ops)
1579 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1581 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1582 ~MDGlobalVariable() {}
1584 static MDGlobalVariable *
1585 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1586 StringRef LinkageName, MDFile *File, unsigned Line, MDTypeRef Type,
1587 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1588 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1589 bool ShouldCreate = true) {
1590 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1591 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1592 IsLocalToUnit, IsDefinition, Variable,
1593 StaticDataMemberDeclaration, Storage, ShouldCreate);
1595 static MDGlobalVariable *
1596 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1597 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1598 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1599 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1600 bool ShouldCreate = true);
1602 TempMDGlobalVariable cloneImpl() const {
1603 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1604 getFile(), getLine(), getType(), isLocalToUnit(),
1605 isDefinition(), getVariable(),
1606 getStaticDataMemberDeclaration());
1610 DEFINE_MDNODE_GET(MDGlobalVariable,
1611 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1612 MDFile *File, unsigned Line, MDTypeRef Type,
1613 bool IsLocalToUnit, bool IsDefinition,
1614 ConstantAsMetadata *Variable,
1615 MDDerivedType *StaticDataMemberDeclaration),
1616 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1617 IsDefinition, Variable, StaticDataMemberDeclaration))
1618 DEFINE_MDNODE_GET(MDGlobalVariable,
1619 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1620 Metadata *File, unsigned Line, Metadata *Type,
1621 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1622 Metadata *StaticDataMemberDeclaration),
1623 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1624 IsDefinition, Variable, StaticDataMemberDeclaration))
1626 TempMDGlobalVariable clone() const { return cloneImpl(); }
1628 bool isLocalToUnit() const { return IsLocalToUnit; }
1629 bool isDefinition() const { return IsDefinition; }
1630 StringRef getDisplayName() const { return getStringOperand(4); }
1631 StringRef getLinkageName() const { return getStringOperand(5); }
1632 ConstantAsMetadata *getVariable() const {
1633 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1635 MDDerivedType *getStaticDataMemberDeclaration() const {
1636 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1639 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1640 Metadata *getRawVariable() const { return getOperand(6); }
1641 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1643 static bool classof(const Metadata *MD) {
1644 return MD->getMetadataID() == MDGlobalVariableKind;
1648 /// \brief Local variable.
1650 /// TODO: Split between arguments and otherwise.
1651 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1652 /// TODO: Split up flags.
1653 class MDLocalVariable : public MDVariable {
1654 friend class LLVMContextImpl;
1655 friend class MDNode;
1660 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1661 unsigned Line, unsigned Arg, unsigned Flags,
1662 ArrayRef<Metadata *> Ops)
1663 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1665 ~MDLocalVariable() {}
1667 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1668 MDScope *Scope, StringRef Name, MDFile *File,
1669 unsigned Line, MDTypeRef Type, unsigned Arg,
1670 unsigned Flags, MDLocation *InlinedAt,
1671 StorageType Storage,
1672 bool ShouldCreate = true) {
1673 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1674 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1677 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1678 Metadata *Scope, MDString *Name,
1679 Metadata *File, unsigned Line, Metadata *Type,
1680 unsigned Arg, unsigned Flags,
1681 Metadata *InlinedAt, StorageType Storage,
1682 bool ShouldCreate = true);
1684 TempMDLocalVariable cloneImpl() const {
1685 return getTemporary(getContext(), getTag(), getScope(), getName(),
1686 getFile(), getLine(), getType(), getArg(), getFlags(),
1691 DEFINE_MDNODE_GET(MDLocalVariable,
1692 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1693 MDFile *File, unsigned Line, MDTypeRef Type, unsigned Arg,
1694 unsigned Flags, MDLocation *InlinedAt = nullptr),
1695 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1696 DEFINE_MDNODE_GET(MDLocalVariable,
1697 (unsigned Tag, Metadata *Scope, MDString *Name,
1698 Metadata *File, unsigned Line, Metadata *Type,
1699 unsigned Arg, unsigned Flags,
1700 Metadata *InlinedAt = nullptr),
1701 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1703 TempMDLocalVariable clone() const { return cloneImpl(); }
1705 /// \brief Get the local scope for this variable.
1707 /// Variables must be defined in a local scope.
1708 MDLocalScope *getScope() const {
1709 return cast<MDLocalScope>(MDVariable::getScope());
1712 unsigned getArg() const { return Arg; }
1713 unsigned getFlags() const { return Flags; }
1714 MDLocation *getInlinedAt() const {
1715 return cast_or_null<MDLocation>(getRawInlinedAt());
1718 Metadata *getRawInlinedAt() const { return getOperand(4); }
1720 /// \brief Check that a location is valid for this variable.
1722 /// Check that \c DL has the same inlined-at location as this variable,
1723 /// making them valid for the same \a DbgInfoIntrinsic.
1724 bool isValidLocationForIntrinsic(const MDLocation *DL) const {
1725 return getInlinedAt() == (DL ? DL->getInlinedAt() : nullptr);
1728 /// \brief Get an inlined version of this variable.
1730 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1731 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1732 if (InlinedAt == getInlinedAt())
1733 return const_cast<MDLocalVariable *>(this);
1734 auto Temp = clone();
1735 Temp->replaceOperandWith(4, InlinedAt);
1736 return replaceWithUniqued(std::move(Temp));
1738 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1740 static bool classof(const Metadata *MD) {
1741 return MD->getMetadataID() == MDLocalVariableKind;
1745 /// \brief DWARF expression.
1747 /// TODO: Co-allocate the expression elements.
1748 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1750 class MDExpression : public MDNode {
1751 friend class LLVMContextImpl;
1752 friend class MDNode;
1754 std::vector<uint64_t> Elements;
1756 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1757 : MDNode(C, MDExpressionKind, Storage, None),
1758 Elements(Elements.begin(), Elements.end()) {}
1761 static MDExpression *getImpl(LLVMContext &Context,
1762 ArrayRef<uint64_t> Elements, StorageType Storage,
1763 bool ShouldCreate = true);
1765 TempMDExpression cloneImpl() const {
1766 return getTemporary(getContext(), getElements());
1770 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1772 TempMDExpression clone() const { return cloneImpl(); }
1774 ArrayRef<uint64_t> getElements() const { return Elements; }
1776 unsigned getNumElements() const { return Elements.size(); }
1777 uint64_t getElement(unsigned I) const {
1778 assert(I < Elements.size() && "Index out of range");
1782 typedef ArrayRef<uint64_t>::iterator element_iterator;
1783 element_iterator elements_begin() const { return getElements().begin(); }
1784 element_iterator elements_end() const { return getElements().end(); }
1786 /// \brief A lightweight wrapper around an expression operand.
1788 /// TODO: Store arguments directly and change \a MDExpression to store a
1794 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1796 const uint64_t *get() const { return Op; }
1798 /// \brief Get the operand code.
1799 uint64_t getOp() const { return *Op; }
1801 /// \brief Get an argument to the operand.
1803 /// Never returns the operand itself.
1804 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1806 unsigned getNumArgs() const { return getSize() - 1; }
1808 /// \brief Return the size of the operand.
1810 /// Return the number of elements in the operand (1 + args).
1811 unsigned getSize() const;
1814 /// \brief An iterator for expression operands.
1815 class expr_op_iterator
1816 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1820 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1822 element_iterator getBase() const { return Op.get(); }
1823 const ExprOperand &operator*() const { return Op; }
1824 const ExprOperand *operator->() const { return &Op; }
1826 expr_op_iterator &operator++() {
1830 expr_op_iterator operator++(int) {
1831 expr_op_iterator T(*this);
1836 bool operator==(const expr_op_iterator &X) const {
1837 return getBase() == X.getBase();
1839 bool operator!=(const expr_op_iterator &X) const {
1840 return getBase() != X.getBase();
1844 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1847 /// \brief Visit the elements via ExprOperand wrappers.
1849 /// These range iterators visit elements through \a ExprOperand wrappers.
1850 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1853 /// \pre \a isValid() gives \c true.
1855 expr_op_iterator expr_op_begin() const {
1856 return expr_op_iterator(elements_begin());
1858 expr_op_iterator expr_op_end() const {
1859 return expr_op_iterator(elements_end());
1863 bool isValid() const;
1865 static bool classof(const Metadata *MD) {
1866 return MD->getMetadataID() == MDExpressionKind;
1870 class MDObjCProperty : public DebugNode {
1871 friend class LLVMContextImpl;
1872 friend class MDNode;
1875 unsigned Attributes;
1877 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1878 unsigned Attributes, ArrayRef<Metadata *> Ops)
1879 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1881 Line(Line), Attributes(Attributes) {}
1882 ~MDObjCProperty() {}
1884 static MDObjCProperty *
1885 getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
1886 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1887 MDType *Type, StorageType Storage, bool ShouldCreate = true) {
1888 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1889 getCanonicalMDString(Context, GetterName),
1890 getCanonicalMDString(Context, SetterName), Attributes, Type,
1891 Storage, ShouldCreate);
1893 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1894 Metadata *File, unsigned Line,
1895 MDString *GetterName, MDString *SetterName,
1896 unsigned Attributes, Metadata *Type,
1897 StorageType Storage, bool ShouldCreate = true);
1899 TempMDObjCProperty cloneImpl() const {
1900 return getTemporary(getContext(), getName(), getFile(), getLine(),
1901 getGetterName(), getSetterName(), getAttributes(),
1906 DEFINE_MDNODE_GET(MDObjCProperty,
1907 (StringRef Name, MDFile *File, unsigned Line,
1908 StringRef GetterName, StringRef SetterName,
1909 unsigned Attributes, MDType *Type),
1910 (Name, File, Line, GetterName, SetterName, Attributes,
1912 DEFINE_MDNODE_GET(MDObjCProperty,
1913 (MDString * Name, Metadata *File, unsigned Line,
1914 MDString *GetterName, MDString *SetterName,
1915 unsigned Attributes, Metadata *Type),
1916 (Name, File, Line, GetterName, SetterName, Attributes,
1919 TempMDObjCProperty clone() const { return cloneImpl(); }
1921 unsigned getLine() const { return Line; }
1922 unsigned getAttributes() const { return Attributes; }
1923 StringRef getName() const { return getStringOperand(0); }
1924 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1925 StringRef getGetterName() const { return getStringOperand(2); }
1926 StringRef getSetterName() const { return getStringOperand(3); }
1927 MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
1929 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1930 Metadata *getRawFile() const { return getOperand(1); }
1931 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1932 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1933 Metadata *getRawType() const { return getOperand(4); }
1935 static bool classof(const Metadata *MD) {
1936 return MD->getMetadataID() == MDObjCPropertyKind;
1940 class MDImportedEntity : public DebugNode {
1941 friend class LLVMContextImpl;
1942 friend class MDNode;
1946 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1947 unsigned Line, ArrayRef<Metadata *> Ops)
1948 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1949 ~MDImportedEntity() {}
1951 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1952 MDScope *Scope, Metadata *Entity,
1953 unsigned Line, StringRef Name,
1954 StorageType Storage,
1955 bool ShouldCreate = true) {
1956 return getImpl(Context, Tag, Scope, Entity, Line,
1957 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1959 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1960 Metadata *Scope, Metadata *Entity,
1961 unsigned Line, MDString *Name,
1962 StorageType Storage,
1963 bool ShouldCreate = true);
1965 TempMDImportedEntity cloneImpl() const {
1966 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1967 getLine(), getName());
1971 DEFINE_MDNODE_GET(MDImportedEntity,
1972 (unsigned Tag, MDScope *Scope, Metadata *Entity,
1973 unsigned Line, StringRef Name = ""),
1974 (Tag, Scope, Entity, Line, Name))
1975 DEFINE_MDNODE_GET(MDImportedEntity,
1976 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1977 unsigned Line, MDString *Name),
1978 (Tag, Scope, Entity, Line, Name))
1980 TempMDImportedEntity clone() const { return cloneImpl(); }
1982 unsigned getLine() const { return Line; }
1983 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1984 Metadata *getEntity() const { return getRawEntity(); }
1985 StringRef getName() const { return getStringOperand(2); }
1987 Metadata *getRawScope() const { return getOperand(0); }
1988 Metadata *getRawEntity() const { return getOperand(1); }
1989 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1991 static bool classof(const Metadata *MD) {
1992 return MD->getMetadataID() == MDImportedEntityKind;
1996 } // end namespace llvm
1998 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1999 #undef DEFINE_MDNODE_GET_UNPACK
2000 #undef DEFINE_MDNODE_GET