1 //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Declarations for metadata specific to debug info.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_DEBUGINFOMETADATA_H
15 #define LLVM_IR_DEBUGINFOMETADATA_H
17 #include "llvm/IR/Metadata.h"
18 #include "llvm/Support/Dwarf.h"
20 // Helper macros for defining get() overrides.
21 #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
22 #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
23 #define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
24 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
25 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
27 static CLASS *getIfExists(LLVMContext &Context, \
28 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
29 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
30 /* ShouldCreate */ false); \
32 static CLASS *getDistinct(LLVMContext &Context, \
33 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
34 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
36 static Temp##CLASS getTemporary(LLVMContext &Context, \
37 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
39 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
44 /// \brief Pointer union between a subclass of DebugNode and MDString.
46 /// \a MDCompositeType can be referenced via an \a MDString unique identifier.
47 /// This class allows some type safety in the face of that, requiring either a
48 /// node of a particular type or an \a MDString.
49 template <class T> class TypedDebugNodeRef {
50 const Metadata *MD = nullptr;
53 TypedDebugNodeRef(std::nullptr_t) {}
55 /// \brief Construct from a raw pointer.
56 explicit TypedDebugNodeRef(const Metadata *MD) : MD(MD) {
57 assert((!MD || isa<MDString>(MD) || isa<T>(MD)) && "Expected valid ref");
62 const TypedDebugNodeRef<U> &X,
63 typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
67 operator Metadata *() const { return const_cast<Metadata *>(MD); }
69 bool operator==(const TypedDebugNodeRef<T> &X) const { return MD == X.MD; };
70 bool operator!=(const TypedDebugNodeRef<T> &X) const { return MD != X.MD; };
72 /// \brief Create a reference.
74 /// Get a reference to \c N, using an \a MDString reference if available.
75 static TypedDebugNodeRef get(const T *N);
77 template <class MapTy> T *resolve(const MapTy &Map) const {
78 if (auto *Typed = dyn_cast<T>(MD))
79 return const_cast<T *>(Typed);
81 auto *S = cast<MDString>(MD);
83 assert(I != Map.end() && "Missing identifier in type map");
84 return cast<T>(I->second);
88 typedef TypedDebugNodeRef<DebugNode> DebugNodeRef;
89 typedef TypedDebugNodeRef<MDScope> MDScopeRef;
90 typedef TypedDebugNodeRef<MDType> MDTypeRef;
92 /// \brief Tagged DWARF-like metadata node.
94 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
95 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
96 /// potentially used for non-DWARF output.
97 class DebugNode : public MDNode {
98 friend class LLVMContextImpl;
102 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
103 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
104 : MDNode(C, ID, Storage, Ops1, Ops2) {
105 assert(Tag < 1u << 16);
106 SubclassData16 = Tag;
110 template <class Ty> Ty *getOperandAs(unsigned I) const {
111 return cast_or_null<Ty>(getOperand(I));
114 StringRef getStringOperand(unsigned I) const {
115 if (auto *S = getOperandAs<MDString>(I))
116 return S->getString();
120 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
123 return MDString::get(Context, S);
127 unsigned getTag() const { return SubclassData16; }
129 /// \brief Debug info flags.
131 /// The three accessibility flags are mutually exclusive and rolled together
132 /// in the first two bits.
134 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
135 #include "llvm/IR/DebugInfoFlags.def"
136 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
139 DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
141 static bool classof(const Metadata *MD) {
142 switch (MD->getMetadataID()) {
145 case GenericDebugNodeKind:
147 case MDEnumeratorKind:
148 case MDBasicTypeKind:
149 case MDDerivedTypeKind:
150 case MDCompositeTypeKind:
151 case MDSubroutineTypeKind:
153 case MDCompileUnitKind:
154 case MDSubprogramKind:
155 case MDLexicalBlockKind:
156 case MDLexicalBlockFileKind:
157 case MDNamespaceKind:
158 case MDTemplateTypeParameterKind:
159 case MDTemplateValueParameterKind:
160 case MDGlobalVariableKind:
161 case MDLocalVariableKind:
162 case MDObjCPropertyKind:
163 case MDImportedEntityKind:
170 struct simplify_type<const TypedDebugNodeRef<T>> {
171 typedef Metadata *SimpleType;
172 static SimpleType getSimplifiedValue(const TypedDebugNodeRef<T> &MD) {
178 struct simplify_type<TypedDebugNodeRef<T>>
179 : simplify_type<const TypedDebugNodeRef<T>> {};
181 /// \brief Generic tagged DWARF-like metadata node.
183 /// An un-specialized DWARF-like metadata node. The first operand is a
184 /// (possibly empty) null-separated \a MDString header that contains arbitrary
185 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
186 /// to other metadata.
187 class GenericDebugNode : public DebugNode {
188 friend class LLVMContextImpl;
191 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
192 unsigned Tag, ArrayRef<Metadata *> Ops1,
193 ArrayRef<Metadata *> Ops2)
194 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
197 ~GenericDebugNode() { dropAllReferences(); }
199 void setHash(unsigned Hash) { SubclassData32 = Hash; }
200 void recalculateHash();
202 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
204 ArrayRef<Metadata *> DwarfOps,
206 bool ShouldCreate = true) {
207 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
208 DwarfOps, Storage, ShouldCreate);
211 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
213 ArrayRef<Metadata *> DwarfOps,
215 bool ShouldCreate = true);
217 TempGenericDebugNode cloneImpl() const {
219 getContext(), getTag(), getHeader(),
220 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
224 unsigned getHash() const { return SubclassData32; }
226 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
227 ArrayRef<Metadata *> DwarfOps),
228 (Tag, Header, DwarfOps))
229 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
230 ArrayRef<Metadata *> DwarfOps),
231 (Tag, Header, DwarfOps))
233 /// \brief Return a (temporary) clone of this.
234 TempGenericDebugNode clone() const { return cloneImpl(); }
236 unsigned getTag() const { return SubclassData16; }
237 StringRef getHeader() const { return getStringOperand(0); }
239 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
240 op_iterator dwarf_op_end() const { return op_end(); }
241 op_range dwarf_operands() const {
242 return op_range(dwarf_op_begin(), dwarf_op_end());
245 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
246 const MDOperand &getDwarfOperand(unsigned I) const {
247 return getOperand(I + 1);
249 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
250 replaceOperandWith(I + 1, New);
253 static bool classof(const Metadata *MD) {
254 return MD->getMetadataID() == GenericDebugNodeKind;
258 /// \brief Array subrange.
260 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
262 class MDSubrange : public DebugNode {
263 friend class LLVMContextImpl;
269 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count, int64_t Lo)
270 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
272 Count(Count), Lo(Lo) {}
275 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
276 StorageType Storage, bool ShouldCreate = true);
278 TempMDSubrange cloneImpl() const {
279 return getTemporary(getContext(), getCount(), getLo());
283 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t Lo = 0), (Count, Lo))
285 TempMDSubrange clone() const { return cloneImpl(); }
287 int64_t getLo() const { return Lo; }
288 int64_t getCount() const { return Count; }
290 static bool classof(const Metadata *MD) {
291 return MD->getMetadataID() == MDSubrangeKind;
295 /// \brief Enumeration value.
297 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
298 /// longer creates a type cycle.
299 class MDEnumerator : public DebugNode {
300 friend class LLVMContextImpl;
305 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
306 ArrayRef<Metadata *> Ops)
307 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
311 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
312 StringRef Name, StorageType Storage,
313 bool ShouldCreate = true) {
314 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
317 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
318 MDString *Name, StorageType Storage,
319 bool ShouldCreate = true);
321 TempMDEnumerator cloneImpl() const {
322 return getTemporary(getContext(), getValue(), getName());
326 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
328 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
331 TempMDEnumerator clone() const { return cloneImpl(); }
333 int64_t getValue() const { return Value; }
334 StringRef getName() const { return getStringOperand(0); }
336 MDString *getRawName() const { return getOperandAs<MDString>(0); }
338 static bool classof(const Metadata *MD) {
339 return MD->getMetadataID() == MDEnumeratorKind;
343 /// \brief Base class for scope-like contexts.
345 /// Base class for lexical scopes and types (which are also declaration
348 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
349 class MDScope : public DebugNode {
351 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
352 ArrayRef<Metadata *> Ops)
353 : DebugNode(C, ID, Storage, Tag, Ops) {}
357 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
359 /// \brief Return the raw underlying file.
361 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
362 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
363 /// this. Otherwise, return the first operand, which is where all other
364 /// subclasses store their file pointer.
365 Metadata *getRawFile() const {
366 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
367 : static_cast<Metadata *>(getOperand(0));
370 MDScopeRef getRef() const { return MDScopeRef::get(this); }
372 static bool classof(const Metadata *MD) {
373 switch (MD->getMetadataID()) {
376 case MDBasicTypeKind:
377 case MDDerivedTypeKind:
378 case MDCompositeTypeKind:
379 case MDSubroutineTypeKind:
381 case MDCompileUnitKind:
382 case MDSubprogramKind:
383 case MDLexicalBlockKind:
384 case MDLexicalBlockFileKind:
385 case MDNamespaceKind:
393 /// TODO: Merge with directory/file node (including users).
394 /// TODO: Canonicalize paths on creation.
395 class MDFile : public MDScope {
396 friend class LLVMContextImpl;
399 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
400 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
403 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
404 StringRef Directory, StorageType Storage,
405 bool ShouldCreate = true) {
406 return getImpl(Context, getCanonicalMDString(Context, Filename),
407 getCanonicalMDString(Context, Directory), Storage,
410 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
411 MDString *Directory, StorageType Storage,
412 bool ShouldCreate = true);
414 TempMDFile cloneImpl() const {
415 return getTemporary(getContext(), getFilename(), getDirectory());
419 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
420 (Filename, Directory))
421 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
422 (Filename, Directory))
424 TempMDFile clone() const { return cloneImpl(); }
426 StringRef getFilename() const { return getStringOperand(0); }
427 StringRef getDirectory() const { return getStringOperand(1); }
429 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
430 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
432 static bool classof(const Metadata *MD) {
433 return MD->getMetadataID() == MDFileKind;
437 /// \brief Base class for types.
439 /// TODO: Remove the hardcoded name and context, since many types don't use
441 /// TODO: Split up flags.
442 class MDType : public MDScope {
446 uint64_t AlignInBits;
447 uint64_t OffsetInBits;
450 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
451 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
452 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
453 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
454 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
455 OffsetInBits(OffsetInBits) {}
459 TempMDType clone() const {
460 return TempMDType(cast<MDType>(MDNode::clone().release()));
463 unsigned getLine() const { return Line; }
464 uint64_t getSizeInBits() const { return SizeInBits; }
465 uint64_t getAlignInBits() const { return AlignInBits; }
466 uint64_t getOffsetInBits() const { return OffsetInBits; }
467 unsigned getFlags() const { return Flags; }
469 Metadata *getScope() const { return getRawScope(); }
470 StringRef getName() const { return getStringOperand(2); }
473 Metadata *getRawScope() const { return getOperand(1); }
474 MDString *getRawName() const { return getOperandAs<MDString>(2); }
476 void setFlags(unsigned NewFlags) {
477 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
481 MDTypeRef getRef() const { return MDTypeRef::get(this); }
483 static bool classof(const Metadata *MD) {
484 switch (MD->getMetadataID()) {
487 case MDBasicTypeKind:
488 case MDDerivedTypeKind:
489 case MDCompositeTypeKind:
490 case MDSubroutineTypeKind:
496 /// \brief Basic type.
498 /// TODO: Split out DW_TAG_unspecified_type.
499 /// TODO: Drop unused accessors.
500 class MDBasicType : public MDType {
501 friend class LLVMContextImpl;
506 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
507 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
508 ArrayRef<Metadata *> Ops)
509 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
511 Encoding(Encoding) {}
514 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
515 StringRef Name, uint64_t SizeInBits,
516 uint64_t AlignInBits, unsigned Encoding,
517 StorageType Storage, bool ShouldCreate = true) {
518 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
519 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
521 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
522 MDString *Name, uint64_t SizeInBits,
523 uint64_t AlignInBits, unsigned Encoding,
524 StorageType Storage, bool ShouldCreate = true);
526 TempMDBasicType cloneImpl() const {
527 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
528 getAlignInBits(), getEncoding());
532 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
533 (Tag, Name, 0, 0, 0))
534 DEFINE_MDNODE_GET(MDBasicType,
535 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
536 uint64_t AlignInBits, unsigned Encoding),
537 (Tag, Name, SizeInBits, AlignInBits, Encoding))
538 DEFINE_MDNODE_GET(MDBasicType,
539 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
540 uint64_t AlignInBits, unsigned Encoding),
541 (Tag, Name, SizeInBits, AlignInBits, Encoding))
543 TempMDBasicType clone() const { return cloneImpl(); }
545 unsigned getEncoding() const { return Encoding; }
547 static bool classof(const Metadata *MD) {
548 return MD->getMetadataID() == MDBasicTypeKind;
552 /// \brief Base class for MDDerivedType and MDCompositeType.
554 /// TODO: Delete; they're not really related.
555 class MDDerivedTypeBase : public MDType {
557 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
558 unsigned Tag, unsigned Line, uint64_t SizeInBits,
559 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
560 ArrayRef<Metadata *> Ops)
561 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
563 ~MDDerivedTypeBase() {}
566 Metadata *getBaseType() const { return getRawBaseType(); }
567 Metadata *getRawBaseType() const { return getOperand(3); }
569 static bool classof(const Metadata *MD) {
570 return MD->getMetadataID() == MDDerivedTypeKind ||
571 MD->getMetadataID() == MDCompositeTypeKind ||
572 MD->getMetadataID() == MDSubroutineTypeKind;
576 /// \brief Derived types.
578 /// This includes qualified types, pointers, references, friends, typedefs, and
581 /// TODO: Split out members (inheritance, fields, methods, etc.).
582 class MDDerivedType : public MDDerivedTypeBase {
583 friend class LLVMContextImpl;
586 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
587 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
588 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
589 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
590 AlignInBits, OffsetInBits, Flags, Ops) {}
593 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
594 StringRef Name, MDFile *File, unsigned Line,
595 Metadata *Scope, Metadata *BaseType,
596 uint64_t SizeInBits, uint64_t AlignInBits,
597 uint64_t OffsetInBits, unsigned Flags,
598 Metadata *ExtraData, StorageType Storage,
599 bool ShouldCreate = true) {
600 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
601 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
602 Flags, ExtraData, Storage, ShouldCreate);
604 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
605 MDString *Name, Metadata *File, unsigned Line,
606 Metadata *Scope, Metadata *BaseType,
607 uint64_t SizeInBits, uint64_t AlignInBits,
608 uint64_t OffsetInBits, unsigned Flags,
609 Metadata *ExtraData, StorageType Storage,
610 bool ShouldCreate = true);
612 TempMDDerivedType cloneImpl() const {
613 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
614 getScope(), getBaseType(), getSizeInBits(),
615 getAlignInBits(), getOffsetInBits(), getFlags(),
620 DEFINE_MDNODE_GET(MDDerivedType,
621 (unsigned Tag, MDString *Name, Metadata *File,
622 unsigned Line, Metadata *Scope, Metadata *BaseType,
623 uint64_t SizeInBits, uint64_t AlignInBits,
624 uint64_t OffsetInBits, unsigned Flags,
625 Metadata *ExtraData = nullptr),
626 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
627 AlignInBits, OffsetInBits, Flags, ExtraData))
628 DEFINE_MDNODE_GET(MDDerivedType,
629 (unsigned Tag, StringRef Name, MDFile *File,
630 unsigned Line, Metadata *Scope, Metadata *BaseType,
631 uint64_t SizeInBits, uint64_t AlignInBits,
632 uint64_t OffsetInBits, unsigned Flags,
633 Metadata *ExtraData = nullptr),
634 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
635 AlignInBits, OffsetInBits, Flags, ExtraData))
637 TempMDDerivedType clone() const { return cloneImpl(); }
639 /// \brief Get extra data associated with this derived type.
641 /// Class type for pointer-to-members, objective-c property node for ivars,
642 /// or global constant wrapper for static members.
644 /// TODO: Separate out types that need this extra operand: pointer-to-member
645 /// types and member fields (static members and ivars).
646 Metadata *getExtraData() const { return getRawExtraData(); }
647 Metadata *getRawExtraData() const { return getOperand(4); }
649 static bool classof(const Metadata *MD) {
650 return MD->getMetadataID() == MDDerivedTypeKind;
654 /// \brief Base class for MDCompositeType and MDSubroutineType.
656 /// TODO: Delete; they're not really related.
657 class MDCompositeTypeBase : public MDDerivedTypeBase {
658 unsigned RuntimeLang;
661 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
662 unsigned Tag, unsigned Line, unsigned RuntimeLang,
663 uint64_t SizeInBits, uint64_t AlignInBits,
664 uint64_t OffsetInBits, unsigned Flags,
665 ArrayRef<Metadata *> Ops)
666 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
667 OffsetInBits, Flags, Ops),
668 RuntimeLang(RuntimeLang) {}
669 ~MDCompositeTypeBase() {}
672 MDTuple *getElements() const {
673 return cast_or_null<MDTuple>(getRawElements());
675 Metadata *getVTableHolder() const { return getRawVTableHolder(); }
676 MDTemplateParameterArray getTemplateParams() const {
677 return cast_or_null<MDTuple>(getRawTemplateParams());
679 StringRef getIdentifier() const { return getStringOperand(7); }
680 unsigned getRuntimeLang() const { return RuntimeLang; }
682 Metadata *getRawElements() const { return getOperand(4); }
683 Metadata *getRawVTableHolder() const { return getOperand(5); }
684 Metadata *getRawTemplateParams() const { return getOperand(6); }
685 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
687 /// \brief Replace operands.
689 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
690 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
691 /// of its movement if necessary.
693 void replaceElements(MDTuple *Elements) {
695 if (auto *Old = cast_or_null<MDTuple>(getElements()))
696 for (const auto &Op : Old->operands())
697 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
698 "Lost a member during member list replacement");
700 replaceOperandWith(4, Elements);
702 void replaceVTableHolder(Metadata *VTableHolder) {
703 replaceOperandWith(5, VTableHolder);
705 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
706 replaceOperandWith(6, TemplateParams);
710 static bool classof(const Metadata *MD) {
711 return MD->getMetadataID() == MDCompositeTypeKind ||
712 MD->getMetadataID() == MDSubroutineTypeKind;
716 /// \brief Composite types.
718 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
719 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
720 class MDCompositeType : public MDCompositeTypeBase {
721 friend class LLVMContextImpl;
724 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
725 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
726 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
727 ArrayRef<Metadata *> Ops)
728 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
729 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
731 ~MDCompositeType() {}
733 static MDCompositeType *
734 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
735 unsigned Line, Metadata *Scope, Metadata *BaseType,
736 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
737 uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
738 Metadata *VTableHolder, Metadata *TemplateParams,
739 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
740 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
741 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
742 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
743 getCanonicalMDString(Context, Identifier), Storage,
746 static MDCompositeType *
747 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
748 unsigned Line, Metadata *Scope, Metadata *BaseType,
749 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
750 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
751 Metadata *VTableHolder, Metadata *TemplateParams,
752 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
754 TempMDCompositeType cloneImpl() const {
755 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
756 getScope(), getBaseType(), getSizeInBits(),
757 getAlignInBits(), getOffsetInBits(), getFlags(),
758 getElements(), getRuntimeLang(), getVTableHolder(),
759 getTemplateParams(), getIdentifier());
763 DEFINE_MDNODE_GET(MDCompositeType,
764 (unsigned Tag, StringRef Name, Metadata *File,
765 unsigned Line, Metadata *Scope, Metadata *BaseType,
766 uint64_t SizeInBits, uint64_t AlignInBits,
767 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
768 unsigned RuntimeLang, Metadata *VTableHolder,
769 Metadata *TemplateParams = nullptr,
770 StringRef Identifier = ""),
771 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
772 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
773 VTableHolder, TemplateParams, Identifier))
774 DEFINE_MDNODE_GET(MDCompositeType,
775 (unsigned Tag, MDString *Name, Metadata *File,
776 unsigned Line, Metadata *Scope, Metadata *BaseType,
777 uint64_t SizeInBits, uint64_t AlignInBits,
778 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
779 unsigned RuntimeLang, Metadata *VTableHolder,
780 Metadata *TemplateParams = nullptr,
781 MDString *Identifier = nullptr),
782 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
783 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
784 VTableHolder, TemplateParams, Identifier))
786 TempMDCompositeType clone() const { return cloneImpl(); }
788 static bool classof(const Metadata *MD) {
789 return MD->getMetadataID() == MDCompositeTypeKind;
793 template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) {
795 if (auto *Composite = dyn_cast<MDCompositeType>(N))
796 if (auto *S = Composite->getRawIdentifier())
797 return TypedDebugNodeRef<T>(S);
798 return TypedDebugNodeRef<T>(N);
801 /// \brief Type array for a subprogram.
803 /// TODO: Detach from CompositeType, and fold the array of types in directly
805 class MDSubroutineType : public MDCompositeTypeBase {
806 friend class LLVMContextImpl;
809 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
810 ArrayRef<Metadata *> Ops)
811 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
812 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
814 ~MDSubroutineType() {}
816 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
817 Metadata *TypeArray, StorageType Storage,
818 bool ShouldCreate = true);
820 TempMDSubroutineType cloneImpl() const {
821 return getTemporary(getContext(), getFlags(), getTypeArray());
825 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
828 TempMDSubroutineType clone() const { return cloneImpl(); }
830 MDTuple *getTypeArray() const { return getElements(); }
831 Metadata *getRawTypeArray() const { return getRawElements(); }
833 static bool classof(const Metadata *MD) {
834 return MD->getMetadataID() == MDSubroutineTypeKind;
838 /// \brief Compile unit.
839 class MDCompileUnit : public MDScope {
840 friend class LLVMContextImpl;
843 unsigned SourceLanguage;
845 unsigned RuntimeVersion;
846 unsigned EmissionKind;
848 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
849 bool IsOptimized, unsigned RuntimeVersion,
850 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
851 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
852 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
853 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
856 static MDCompileUnit *
857 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
858 StringRef Producer, bool IsOptimized, StringRef Flags,
859 unsigned RuntimeVersion, StringRef SplitDebugFilename,
860 unsigned EmissionKind, MDTuple *EnumTypes, MDTuple *RetainedTypes,
861 MDTuple *Subprograms, MDTuple *GlobalVariables,
862 MDTuple *ImportedEntities, StorageType Storage,
863 bool ShouldCreate = true) {
864 return getImpl(Context, SourceLanguage, File,
865 getCanonicalMDString(Context, Producer), IsOptimized,
866 getCanonicalMDString(Context, Flags), RuntimeVersion,
867 getCanonicalMDString(Context, SplitDebugFilename),
868 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
869 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
871 static MDCompileUnit *
872 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
873 MDString *Producer, bool IsOptimized, MDString *Flags,
874 unsigned RuntimeVersion, MDString *SplitDebugFilename,
875 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
876 Metadata *Subprograms, Metadata *GlobalVariables,
877 Metadata *ImportedEntities, StorageType Storage,
878 bool ShouldCreate = true);
880 TempMDCompileUnit cloneImpl() const {
882 getContext(), getSourceLanguage(), getFile(), getProducer(),
883 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
884 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
885 getGlobalVariables(), getImportedEntities());
889 DEFINE_MDNODE_GET(MDCompileUnit,
890 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
891 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
892 StringRef SplitDebugFilename, unsigned EmissionKind,
893 MDTuple *EnumTypes, MDTuple *RetainedTypes,
894 MDTuple *Subprograms, MDTuple *GlobalVariables,
895 MDTuple *ImportedEntities),
896 (SourceLanguage, File, Producer, IsOptimized, Flags,
897 RuntimeVersion, SplitDebugFilename, EmissionKind,
898 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
900 DEFINE_MDNODE_GET(MDCompileUnit,
901 (unsigned SourceLanguage, Metadata *File,
902 MDString *Producer, bool IsOptimized, MDString *Flags,
903 unsigned RuntimeVersion, MDString *SplitDebugFilename,
904 unsigned EmissionKind, Metadata *EnumTypes,
905 Metadata *RetainedTypes, Metadata *Subprograms,
906 Metadata *GlobalVariables, Metadata *ImportedEntities),
907 (SourceLanguage, File, Producer, IsOptimized, Flags,
908 RuntimeVersion, SplitDebugFilename, EmissionKind,
909 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
912 TempMDCompileUnit clone() const { return cloneImpl(); }
914 unsigned getSourceLanguage() const { return SourceLanguage; }
915 bool isOptimized() const { return IsOptimized; }
916 unsigned getRuntimeVersion() const { return RuntimeVersion; }
917 unsigned getEmissionKind() const { return EmissionKind; }
918 StringRef getProducer() const { return getStringOperand(1); }
919 StringRef getFlags() const { return getStringOperand(2); }
920 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
921 MDCompositeTypeArray getEnumTypes() const {
922 return cast_or_null<MDTuple>(getRawEnumTypes());
924 MDTypeArray getRetainedTypes() const {
925 return cast_or_null<MDTuple>(getRawRetainedTypes());
927 MDSubprogramArray getSubprograms() const {
928 return cast_or_null<MDTuple>(getRawSubprograms());
930 MDGlobalVariableArray getGlobalVariables() const {
931 return cast_or_null<MDTuple>(getRawGlobalVariables());
933 MDImportedEntityArray getImportedEntities() const {
934 return cast_or_null<MDTuple>(getRawImportedEntities());
937 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
938 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
939 MDString *getRawSplitDebugFilename() const {
940 return getOperandAs<MDString>(3);
942 Metadata *getRawEnumTypes() const { return getOperand(4); }
943 Metadata *getRawRetainedTypes() const { return getOperand(5); }
944 Metadata *getRawSubprograms() const { return getOperand(6); }
945 Metadata *getRawGlobalVariables() const { return getOperand(7); }
946 Metadata *getRawImportedEntities() const { return getOperand(8); }
948 /// \brief Replace arrays.
950 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
951 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
952 /// MDCompileUnit should be fairly rare.
954 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
955 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
958 static bool classof(const Metadata *MD) {
959 return MD->getMetadataID() == MDCompileUnitKind;
963 /// \brief A scope for locals.
965 /// A legal scope for lexical blocks, local variables, and debug info
966 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
967 /// MDLexicalBlockFile.
968 class MDLocalScope : public MDScope {
970 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
971 ArrayRef<Metadata *> Ops)
972 : MDScope(C, ID, Storage, Tag, Ops) {}
976 /// \brief Get the subprogram for this scope.
978 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
980 MDSubprogram *getSubprogram() const;
982 static bool classof(const Metadata *MD) {
983 return MD->getMetadataID() == MDSubprogramKind ||
984 MD->getMetadataID() == MDLexicalBlockKind ||
985 MD->getMetadataID() == MDLexicalBlockFileKind;
989 /// \brief Debug location.
991 /// A debug location in source code, used for debug info and otherwise.
992 class MDLocation : public MDNode {
993 friend class LLVMContextImpl;
996 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
997 unsigned Column, ArrayRef<Metadata *> MDs);
998 ~MDLocation() { dropAllReferences(); }
1000 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1001 unsigned Column, Metadata *Scope,
1002 Metadata *InlinedAt, StorageType Storage,
1003 bool ShouldCreate = true);
1004 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1005 unsigned Column, MDLocalScope *Scope,
1006 MDLocation *InlinedAt, StorageType Storage,
1007 bool ShouldCreate = true) {
1008 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1009 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1012 TempMDLocation cloneImpl() const {
1013 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
1017 // Disallow replacing operands.
1018 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1021 DEFINE_MDNODE_GET(MDLocation,
1022 (unsigned Line, unsigned Column, Metadata *Scope,
1023 Metadata *InlinedAt = nullptr),
1024 (Line, Column, Scope, InlinedAt))
1025 DEFINE_MDNODE_GET(MDLocation,
1026 (unsigned Line, unsigned Column, MDLocalScope *Scope,
1027 MDLocation *InlinedAt = nullptr),
1028 (Line, Column, Scope, InlinedAt))
1030 /// \brief Return a (temporary) clone of this.
1031 TempMDLocation clone() const { return cloneImpl(); }
1033 unsigned getLine() const { return SubclassData32; }
1034 unsigned getColumn() const { return SubclassData16; }
1035 MDLocalScope *getScope() const {
1036 return cast_or_null<MDLocalScope>(getRawScope());
1038 MDLocation *getInlinedAt() const {
1039 return cast_or_null<MDLocation>(getRawInlinedAt());
1042 /// \brief Get the scope where this is inlined.
1044 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1046 MDLocalScope *getInlinedAtScope() const {
1047 if (auto *IA = getInlinedAt())
1048 return IA->getInlinedAtScope();
1052 Metadata *getRawScope() const { return getOperand(0); }
1053 Metadata *getRawInlinedAt() const {
1054 if (getNumOperands() == 2)
1055 return getOperand(1);
1059 static bool classof(const Metadata *MD) {
1060 return MD->getMetadataID() == MDLocationKind;
1064 /// \brief Subprogram description.
1066 /// TODO: Remove DisplayName. It's always equal to Name.
1067 /// TODO: Split up flags.
1068 class MDSubprogram : public MDLocalScope {
1069 friend class LLVMContextImpl;
1070 friend class MDNode;
1074 unsigned Virtuality;
1075 unsigned VirtualIndex;
1081 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1082 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1083 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
1084 bool IsOptimized, ArrayRef<Metadata *> Ops)
1085 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1087 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
1088 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
1089 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
1092 static MDSubprogram *
1093 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1094 StringRef LinkageName, MDFile *File, unsigned Line,
1095 MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1096 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1097 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1098 ConstantAsMetadata *Function, MDTuple *TemplateParams,
1099 MDSubprogram *Declaration, MDTuple *Variables, StorageType Storage,
1100 bool ShouldCreate = true) {
1101 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1102 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1103 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1104 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1105 TemplateParams, Declaration, Variables, Storage,
1108 static MDSubprogram *
1109 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1110 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1111 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1112 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1113 unsigned Flags, bool IsOptimized, Metadata *Function,
1114 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1115 StorageType Storage, bool ShouldCreate = true);
1117 TempMDSubprogram cloneImpl() const {
1118 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1119 getFile(), getLine(), getType(), isLocalToUnit(),
1120 isDefinition(), getScopeLine(), getContainingType(),
1121 getVirtuality(), getVirtualIndex(), getFlags(),
1122 isOptimized(), getFunction(), getTemplateParams(),
1123 getDeclaration(), getVariables());
1129 (Metadata * Scope, StringRef Name, StringRef LinkageName, MDFile *File,
1130 unsigned Line, MDSubroutineType *Type, bool IsLocalToUnit,
1131 bool IsDefinition, unsigned ScopeLine, Metadata *ContainingType,
1132 unsigned Virtuality, unsigned VirtualIndex, unsigned Flags,
1133 bool IsOptimized, ConstantAsMetadata *Function = nullptr,
1134 MDTuple *TemplateParams = nullptr, MDSubprogram *Declaration = nullptr,
1135 MDTuple *Variables = nullptr),
1136 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1137 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1138 Function, TemplateParams, Declaration, Variables))
1141 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1142 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1143 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1144 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1145 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1146 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1147 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1148 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1149 Function, TemplateParams, Declaration, Variables))
1151 TempMDSubprogram clone() const { return cloneImpl(); }
1154 unsigned getLine() const { return Line; }
1155 unsigned getVirtuality() const { return Virtuality; }
1156 unsigned getVirtualIndex() const { return VirtualIndex; }
1157 unsigned getScopeLine() const { return ScopeLine; }
1158 unsigned getFlags() const { return Flags; }
1159 bool isLocalToUnit() const { return IsLocalToUnit; }
1160 bool isDefinition() const { return IsDefinition; }
1161 bool isOptimized() const { return IsOptimized; }
1163 Metadata *getScope() const { return getRawScope(); }
1165 StringRef getName() const { return getStringOperand(2); }
1166 StringRef getDisplayName() const { return getStringOperand(3); }
1167 StringRef getLinkageName() const { return getStringOperand(4); }
1169 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1170 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1172 MDSubroutineType *getType() const {
1173 return cast_or_null<MDSubroutineType>(getRawType());
1175 Metadata *getContainingType() const { return getRawContainingType(); }
1177 ConstantAsMetadata *getFunction() const {
1178 return cast_or_null<ConstantAsMetadata>(getRawFunction());
1180 MDTemplateParameterArray getTemplateParams() const {
1181 return cast_or_null<MDTuple>(getRawTemplateParams());
1183 MDSubprogram *getDeclaration() const {
1184 return cast_or_null<MDSubprogram>(getRawDeclaration());
1186 MDLocalVariableArray getVariables() const {
1187 return cast_or_null<MDTuple>(getRawVariables());
1190 Metadata *getRawScope() const { return getOperand(1); }
1191 Metadata *getRawType() const { return getOperand(5); }
1192 Metadata *getRawContainingType() const { return getOperand(6); }
1193 Metadata *getRawFunction() const { return getOperand(7); }
1194 Metadata *getRawTemplateParams() const { return getOperand(8); }
1195 Metadata *getRawDeclaration() const { return getOperand(9); }
1196 Metadata *getRawVariables() const { return getOperand(10); }
1198 /// \brief Replace the function.
1200 /// If \a isUniqued() and not \a isResolved(), this could node will be
1201 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1202 /// that's a problem.
1204 void replaceFunction(Function *F);
1205 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1206 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1209 static bool classof(const Metadata *MD) {
1210 return MD->getMetadataID() == MDSubprogramKind;
1214 class MDLexicalBlockBase : public MDLocalScope {
1216 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1217 ArrayRef<Metadata *> Ops)
1218 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1219 ~MDLexicalBlockBase() {}
1222 MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
1224 Metadata *getRawScope() const { return getOperand(1); }
1226 static bool classof(const Metadata *MD) {
1227 return MD->getMetadataID() == MDLexicalBlockKind ||
1228 MD->getMetadataID() == MDLexicalBlockFileKind;
1232 class MDLexicalBlock : public MDLexicalBlockBase {
1233 friend class LLVMContextImpl;
1234 friend class MDNode;
1239 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1240 unsigned Column, ArrayRef<Metadata *> Ops)
1241 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1243 ~MDLexicalBlock() {}
1245 static MDLexicalBlock *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1246 MDFile *File, unsigned Line, unsigned Column,
1247 StorageType Storage,
1248 bool ShouldCreate = true) {
1249 return getImpl(Context, static_cast<Metadata *>(Scope),
1250 static_cast<Metadata *>(File), Line, Column, Storage,
1254 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1255 Metadata *File, unsigned Line, unsigned Column,
1256 StorageType Storage, bool ShouldCreate = true);
1258 TempMDLexicalBlock cloneImpl() const {
1259 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1264 DEFINE_MDNODE_GET(MDLexicalBlock, (MDLocalScope * Scope, MDFile *File,
1265 unsigned Line, unsigned Column),
1266 (Scope, File, Line, Column))
1267 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1268 unsigned Line, unsigned Column),
1269 (Scope, File, Line, Column))
1271 TempMDLexicalBlock clone() const { return cloneImpl(); }
1273 unsigned getLine() const { return Line; }
1274 unsigned getColumn() const { return Column; }
1276 static bool classof(const Metadata *MD) {
1277 return MD->getMetadataID() == MDLexicalBlockKind;
1281 class MDLexicalBlockFile : public MDLexicalBlockBase {
1282 friend class LLVMContextImpl;
1283 friend class MDNode;
1285 unsigned Discriminator;
1287 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1288 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1289 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1290 Discriminator(Discriminator) {}
1291 ~MDLexicalBlockFile() {}
1293 static MDLexicalBlockFile *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1294 MDFile *File, unsigned Discriminator,
1295 StorageType Storage,
1296 bool ShouldCreate = true) {
1297 return getImpl(Context, static_cast<Metadata *>(Scope),
1298 static_cast<Metadata *>(File), Discriminator, Storage,
1302 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1303 Metadata *File, unsigned Discriminator,
1304 StorageType Storage,
1305 bool ShouldCreate = true);
1307 TempMDLexicalBlockFile cloneImpl() const {
1308 return getTemporary(getContext(), getScope(), getFile(),
1309 getDiscriminator());
1313 DEFINE_MDNODE_GET(MDLexicalBlockFile, (MDLocalScope * Scope, MDFile *File,
1314 unsigned Discriminator),
1315 (Scope, File, Discriminator))
1316 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1317 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1318 (Scope, File, Discriminator))
1320 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1322 unsigned getDiscriminator() const { return Discriminator; }
1324 static bool classof(const Metadata *MD) {
1325 return MD->getMetadataID() == MDLexicalBlockFileKind;
1329 class MDNamespace : public MDScope {
1330 friend class LLVMContextImpl;
1331 friend class MDNode;
1335 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1336 ArrayRef<Metadata *> Ops)
1337 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1342 static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
1343 MDFile *File, StringRef Name, unsigned Line,
1344 StorageType Storage, bool ShouldCreate = true) {
1345 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1346 Line, Storage, ShouldCreate);
1348 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1349 Metadata *File, MDString *Name, unsigned Line,
1350 StorageType Storage, bool ShouldCreate = true);
1352 TempMDNamespace cloneImpl() const {
1353 return getTemporary(getContext(), getScope(), getFile(), getName(),
1358 DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
1360 (Scope, File, Name, Line))
1361 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1362 MDString *Name, unsigned Line),
1363 (Scope, File, Name, Line))
1365 TempMDNamespace clone() const { return cloneImpl(); }
1367 unsigned getLine() const { return Line; }
1368 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1369 StringRef getName() const { return getStringOperand(2); }
1371 Metadata *getRawScope() const { return getOperand(1); }
1372 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1374 static bool classof(const Metadata *MD) {
1375 return MD->getMetadataID() == MDNamespaceKind;
1379 /// \brief Base class for template parameters.
1380 class MDTemplateParameter : public DebugNode {
1382 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1383 unsigned Tag, ArrayRef<Metadata *> Ops)
1384 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1385 ~MDTemplateParameter() {}
1388 StringRef getName() const { return getStringOperand(0); }
1389 Metadata *getType() const { return getOperand(1); }
1391 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1393 static bool classof(const Metadata *MD) {
1394 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1395 MD->getMetadataID() == MDTemplateValueParameterKind;
1399 class MDTemplateTypeParameter : public MDTemplateParameter {
1400 friend class LLVMContextImpl;
1401 friend class MDNode;
1403 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1404 ArrayRef<Metadata *> Ops)
1405 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1406 dwarf::DW_TAG_template_type_parameter, Ops) {}
1407 ~MDTemplateTypeParameter() {}
1409 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1410 Metadata *Type, StorageType Storage,
1411 bool ShouldCreate = true) {
1412 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1415 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1416 Metadata *Type, StorageType Storage,
1417 bool ShouldCreate = true);
1419 TempMDTemplateTypeParameter cloneImpl() const {
1420 return getTemporary(getContext(), getName(), getType());
1424 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1426 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1429 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1431 static bool classof(const Metadata *MD) {
1432 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1436 class MDTemplateValueParameter : public MDTemplateParameter {
1437 friend class LLVMContextImpl;
1438 friend class MDNode;
1440 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1441 unsigned Tag, ArrayRef<Metadata *> Ops)
1442 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1444 ~MDTemplateValueParameter() {}
1446 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1447 StringRef Name, Metadata *Type,
1448 Metadata *Value, StorageType Storage,
1449 bool ShouldCreate = true) {
1450 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1451 Value, Storage, ShouldCreate);
1453 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1454 MDString *Name, Metadata *Type,
1455 Metadata *Value, StorageType Storage,
1456 bool ShouldCreate = true);
1458 TempMDTemplateValueParameter cloneImpl() const {
1459 return getTemporary(getContext(), getTag(), getName(), getType(),
1464 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1465 Metadata *Type, Metadata *Value),
1466 (Tag, Name, Type, Value))
1467 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1468 Metadata *Type, Metadata *Value),
1469 (Tag, Name, Type, Value))
1471 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1473 Metadata *getValue() const { return getOperand(2); }
1475 static bool classof(const Metadata *MD) {
1476 return MD->getMetadataID() == MDTemplateValueParameterKind;
1480 /// \brief Base class for variables.
1482 /// TODO: Hardcode to DW_TAG_variable.
1483 class MDVariable : public DebugNode {
1487 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1488 unsigned Line, ArrayRef<Metadata *> Ops)
1489 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1493 unsigned getLine() const { return Line; }
1494 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1495 StringRef getName() const { return getStringOperand(1); }
1496 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1497 Metadata *getType() const { return getRawType(); }
1499 Metadata *getRawScope() const { return getOperand(0); }
1500 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1501 Metadata *getRawFile() const { return getOperand(2); }
1502 Metadata *getRawType() const { return getOperand(3); }
1504 static bool classof(const Metadata *MD) {
1505 return MD->getMetadataID() == MDLocalVariableKind ||
1506 MD->getMetadataID() == MDGlobalVariableKind;
1510 /// \brief Global variables.
1512 /// TODO: Remove DisplayName. It's always equal to Name.
1513 class MDGlobalVariable : public MDVariable {
1514 friend class LLVMContextImpl;
1515 friend class MDNode;
1520 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1521 bool IsLocalToUnit, bool IsDefinition,
1522 ArrayRef<Metadata *> Ops)
1523 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1525 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1526 ~MDGlobalVariable() {}
1528 static MDGlobalVariable *
1529 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1530 StringRef LinkageName, MDFile *File, unsigned Line, Metadata *Type,
1531 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1532 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1533 bool ShouldCreate = true) {
1534 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1535 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1536 IsLocalToUnit, IsDefinition, Variable,
1537 StaticDataMemberDeclaration, Storage, ShouldCreate);
1539 static MDGlobalVariable *
1540 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1541 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1542 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1543 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1544 bool ShouldCreate = true);
1546 TempMDGlobalVariable cloneImpl() const {
1547 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1548 getFile(), getLine(), getType(), isLocalToUnit(),
1549 isDefinition(), getVariable(),
1550 getStaticDataMemberDeclaration());
1554 DEFINE_MDNODE_GET(MDGlobalVariable,
1555 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1556 MDFile *File, unsigned Line, Metadata *Type,
1557 bool IsLocalToUnit, bool IsDefinition,
1558 ConstantAsMetadata *Variable,
1559 MDDerivedType *StaticDataMemberDeclaration),
1560 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1561 IsDefinition, Variable, StaticDataMemberDeclaration))
1562 DEFINE_MDNODE_GET(MDGlobalVariable,
1563 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1564 Metadata *File, unsigned Line, Metadata *Type,
1565 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1566 Metadata *StaticDataMemberDeclaration),
1567 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1568 IsDefinition, Variable, StaticDataMemberDeclaration))
1570 TempMDGlobalVariable clone() const { return cloneImpl(); }
1572 bool isLocalToUnit() const { return IsLocalToUnit; }
1573 bool isDefinition() const { return IsDefinition; }
1574 StringRef getDisplayName() const { return getStringOperand(4); }
1575 StringRef getLinkageName() const { return getStringOperand(5); }
1576 ConstantAsMetadata *getVariable() const {
1577 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1579 MDDerivedType *getStaticDataMemberDeclaration() const {
1580 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1583 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1584 Metadata *getRawVariable() const { return getOperand(6); }
1585 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1587 static bool classof(const Metadata *MD) {
1588 return MD->getMetadataID() == MDGlobalVariableKind;
1592 /// \brief Local variable.
1594 /// TODO: Split between arguments and otherwise.
1595 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1596 /// TODO: Split up flags.
1597 class MDLocalVariable : public MDVariable {
1598 friend class LLVMContextImpl;
1599 friend class MDNode;
1604 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1605 unsigned Line, unsigned Arg, unsigned Flags,
1606 ArrayRef<Metadata *> Ops)
1607 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1609 ~MDLocalVariable() {}
1611 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1612 MDScope *Scope, StringRef Name, MDFile *File,
1613 unsigned Line, Metadata *Type, unsigned Arg,
1614 unsigned Flags, MDLocation *InlinedAt,
1615 StorageType Storage,
1616 bool ShouldCreate = true) {
1617 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1618 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1621 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1622 Metadata *Scope, MDString *Name,
1623 Metadata *File, unsigned Line, Metadata *Type,
1624 unsigned Arg, unsigned Flags,
1625 Metadata *InlinedAt, StorageType Storage,
1626 bool ShouldCreate = true);
1628 TempMDLocalVariable cloneImpl() const {
1629 return getTemporary(getContext(), getTag(), getScope(), getName(),
1630 getFile(), getLine(), getType(), getArg(), getFlags(),
1635 DEFINE_MDNODE_GET(MDLocalVariable,
1636 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1637 MDFile *File, unsigned Line, Metadata *Type, unsigned Arg,
1638 unsigned Flags, MDLocation *InlinedAt = nullptr),
1639 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1640 DEFINE_MDNODE_GET(MDLocalVariable,
1641 (unsigned Tag, Metadata *Scope, MDString *Name,
1642 Metadata *File, unsigned Line, Metadata *Type,
1643 unsigned Arg, unsigned Flags,
1644 Metadata *InlinedAt = nullptr),
1645 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1647 TempMDLocalVariable clone() const { return cloneImpl(); }
1649 /// \brief Get the local scope for this variable.
1651 /// Variables must be defined in a local scope.
1652 MDLocalScope *getScope() const {
1653 return cast<MDLocalScope>(MDVariable::getScope());
1656 unsigned getArg() const { return Arg; }
1657 unsigned getFlags() const { return Flags; }
1658 MDLocation *getInlinedAt() const {
1659 return cast_or_null<MDLocation>(getRawInlinedAt());
1662 Metadata *getRawInlinedAt() const { return getOperand(4); }
1664 /// \brief Check that a location is valid for this variable.
1666 /// Check that \c DL has the same inlined-at location as this variable,
1667 /// making them valid for the same \a DbgInfoIntrinsic.
1668 bool isValidLocationForIntrinsic(const MDLocation *DL) const {
1669 return getInlinedAt() == (DL ? DL->getInlinedAt() : nullptr);
1672 /// \brief Get an inlined version of this variable.
1674 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1675 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1676 if (InlinedAt == getInlinedAt())
1677 return const_cast<MDLocalVariable *>(this);
1678 auto Temp = clone();
1679 Temp->replaceOperandWith(4, InlinedAt);
1680 return replaceWithUniqued(std::move(Temp));
1682 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1684 static bool classof(const Metadata *MD) {
1685 return MD->getMetadataID() == MDLocalVariableKind;
1689 /// \brief DWARF expression.
1691 /// TODO: Co-allocate the expression elements.
1692 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1694 class MDExpression : public MDNode {
1695 friend class LLVMContextImpl;
1696 friend class MDNode;
1698 std::vector<uint64_t> Elements;
1700 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1701 : MDNode(C, MDExpressionKind, Storage, None),
1702 Elements(Elements.begin(), Elements.end()) {}
1705 static MDExpression *getImpl(LLVMContext &Context,
1706 ArrayRef<uint64_t> Elements, StorageType Storage,
1707 bool ShouldCreate = true);
1709 TempMDExpression cloneImpl() const {
1710 return getTemporary(getContext(), getElements());
1714 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1716 TempMDExpression clone() const { return cloneImpl(); }
1718 ArrayRef<uint64_t> getElements() const { return Elements; }
1720 unsigned getNumElements() const { return Elements.size(); }
1721 uint64_t getElement(unsigned I) const {
1722 assert(I < Elements.size() && "Index out of range");
1726 typedef ArrayRef<uint64_t>::iterator element_iterator;
1727 element_iterator elements_begin() const { return getElements().begin(); }
1728 element_iterator elements_end() const { return getElements().end(); }
1730 /// \brief A lightweight wrapper around an expression operand.
1732 /// TODO: Store arguments directly and change \a MDExpression to store a
1738 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1740 const uint64_t *get() const { return Op; }
1742 /// \brief Get the operand code.
1743 uint64_t getOp() const { return *Op; }
1745 /// \brief Get an argument to the operand.
1747 /// Never returns the operand itself.
1748 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1750 unsigned getNumArgs() const { return getSize() - 1; }
1752 /// \brief Return the size of the operand.
1754 /// Return the number of elements in the operand (1 + args).
1755 unsigned getSize() const;
1758 /// \brief An iterator for expression operands.
1759 class expr_op_iterator
1760 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1764 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1766 element_iterator getBase() const { return Op.get(); }
1767 const ExprOperand &operator*() const { return Op; }
1768 const ExprOperand *operator->() const { return &Op; }
1770 expr_op_iterator &operator++() {
1774 expr_op_iterator operator++(int) {
1775 expr_op_iterator T(*this);
1780 bool operator==(const expr_op_iterator &X) const {
1781 return getBase() == X.getBase();
1783 bool operator!=(const expr_op_iterator &X) const {
1784 return getBase() != X.getBase();
1788 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1791 /// \brief Visit the elements via ExprOperand wrappers.
1793 /// These range iterators visit elements through \a ExprOperand wrappers.
1794 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1797 /// \pre \a isValid() gives \c true.
1799 expr_op_iterator expr_op_begin() const {
1800 return expr_op_iterator(elements_begin());
1802 expr_op_iterator expr_op_end() const {
1803 return expr_op_iterator(elements_end());
1807 bool isValid() const;
1809 static bool classof(const Metadata *MD) {
1810 return MD->getMetadataID() == MDExpressionKind;
1814 class MDObjCProperty : public DebugNode {
1815 friend class LLVMContextImpl;
1816 friend class MDNode;
1819 unsigned Attributes;
1821 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1822 unsigned Attributes, ArrayRef<Metadata *> Ops)
1823 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1825 Line(Line), Attributes(Attributes) {}
1826 ~MDObjCProperty() {}
1828 static MDObjCProperty *
1829 getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
1830 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1831 MDType *Type, StorageType Storage, bool ShouldCreate = true) {
1832 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1833 getCanonicalMDString(Context, GetterName),
1834 getCanonicalMDString(Context, SetterName), Attributes, Type,
1835 Storage, ShouldCreate);
1837 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1838 Metadata *File, unsigned Line,
1839 MDString *GetterName, MDString *SetterName,
1840 unsigned Attributes, Metadata *Type,
1841 StorageType Storage, bool ShouldCreate = true);
1843 TempMDObjCProperty cloneImpl() const {
1844 return getTemporary(getContext(), getName(), getFile(), getLine(),
1845 getGetterName(), getSetterName(), getAttributes(),
1850 DEFINE_MDNODE_GET(MDObjCProperty,
1851 (StringRef Name, MDFile *File, unsigned Line,
1852 StringRef GetterName, StringRef SetterName,
1853 unsigned Attributes, MDType *Type),
1854 (Name, File, Line, GetterName, SetterName, Attributes,
1856 DEFINE_MDNODE_GET(MDObjCProperty,
1857 (MDString * Name, Metadata *File, unsigned Line,
1858 MDString *GetterName, MDString *SetterName,
1859 unsigned Attributes, Metadata *Type),
1860 (Name, File, Line, GetterName, SetterName, Attributes,
1863 TempMDObjCProperty clone() const { return cloneImpl(); }
1865 unsigned getLine() const { return Line; }
1866 unsigned getAttributes() const { return Attributes; }
1867 StringRef getName() const { return getStringOperand(0); }
1868 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1869 StringRef getGetterName() const { return getStringOperand(2); }
1870 StringRef getSetterName() const { return getStringOperand(3); }
1871 MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
1873 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1874 Metadata *getRawFile() const { return getOperand(1); }
1875 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1876 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1877 Metadata *getRawType() const { return getOperand(4); }
1879 static bool classof(const Metadata *MD) {
1880 return MD->getMetadataID() == MDObjCPropertyKind;
1884 class MDImportedEntity : public DebugNode {
1885 friend class LLVMContextImpl;
1886 friend class MDNode;
1890 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1891 unsigned Line, ArrayRef<Metadata *> Ops)
1892 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1893 ~MDImportedEntity() {}
1895 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1896 MDScope *Scope, Metadata *Entity,
1897 unsigned Line, StringRef Name,
1898 StorageType Storage,
1899 bool ShouldCreate = true) {
1900 return getImpl(Context, Tag, Scope, Entity, Line,
1901 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1903 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1904 Metadata *Scope, Metadata *Entity,
1905 unsigned Line, MDString *Name,
1906 StorageType Storage,
1907 bool ShouldCreate = true);
1909 TempMDImportedEntity cloneImpl() const {
1910 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1911 getLine(), getName());
1915 DEFINE_MDNODE_GET(MDImportedEntity,
1916 (unsigned Tag, MDScope *Scope, Metadata *Entity,
1917 unsigned Line, StringRef Name = ""),
1918 (Tag, Scope, Entity, Line, Name))
1919 DEFINE_MDNODE_GET(MDImportedEntity,
1920 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1921 unsigned Line, MDString *Name),
1922 (Tag, Scope, Entity, Line, Name))
1924 TempMDImportedEntity clone() const { return cloneImpl(); }
1926 unsigned getLine() const { return Line; }
1927 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1928 Metadata *getEntity() const { return getRawEntity(); }
1929 StringRef getName() const { return getStringOperand(2); }
1931 Metadata *getRawScope() const { return getOperand(0); }
1932 Metadata *getRawEntity() const { return getOperand(1); }
1933 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1935 static bool classof(const Metadata *MD) {
1936 return MD->getMetadataID() == MDImportedEntityKind;
1940 } // end namespace llvm
1942 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1943 #undef DEFINE_MDNODE_GET_UNPACK
1944 #undef DEFINE_MDNODE_GET