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 MDScopeRef getScope() const { return MDScopeRef(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 MDTypeRef getBaseType() const { return MDTypeRef(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 MDScopeRef Scope, MDTypeRef 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, unsigned Line,
630 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
631 uint64_t AlignInBits, uint64_t OffsetInBits,
632 unsigned Flags, Metadata *ExtraData = nullptr),
633 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
634 AlignInBits, OffsetInBits, Flags, ExtraData))
636 TempMDDerivedType clone() const { return cloneImpl(); }
638 /// \brief Get extra data associated with this derived type.
640 /// Class type for pointer-to-members, objective-c property node for ivars,
641 /// or global constant wrapper for static members.
643 /// TODO: Separate out types that need this extra operand: pointer-to-member
644 /// types and member fields (static members and ivars).
645 Metadata *getExtraData() const { return getRawExtraData(); }
646 Metadata *getRawExtraData() const { return getOperand(4); }
648 static bool classof(const Metadata *MD) {
649 return MD->getMetadataID() == MDDerivedTypeKind;
653 /// \brief Base class for MDCompositeType and MDSubroutineType.
655 /// TODO: Delete; they're not really related.
656 class MDCompositeTypeBase : public MDDerivedTypeBase {
657 unsigned RuntimeLang;
660 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
661 unsigned Tag, unsigned Line, unsigned RuntimeLang,
662 uint64_t SizeInBits, uint64_t AlignInBits,
663 uint64_t OffsetInBits, unsigned Flags,
664 ArrayRef<Metadata *> Ops)
665 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
666 OffsetInBits, Flags, Ops),
667 RuntimeLang(RuntimeLang) {}
668 ~MDCompositeTypeBase() {}
671 MDTuple *getElements() const {
672 return cast_or_null<MDTuple>(getRawElements());
674 MDTypeRef getVTableHolder() const { return MDTypeRef(getRawVTableHolder()); }
675 MDTemplateParameterArray getTemplateParams() const {
676 return cast_or_null<MDTuple>(getRawTemplateParams());
678 StringRef getIdentifier() const { return getStringOperand(7); }
679 unsigned getRuntimeLang() const { return RuntimeLang; }
681 Metadata *getRawElements() const { return getOperand(4); }
682 Metadata *getRawVTableHolder() const { return getOperand(5); }
683 Metadata *getRawTemplateParams() const { return getOperand(6); }
684 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
686 /// \brief Replace operands.
688 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
689 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
690 /// of its movement if necessary.
692 void replaceElements(MDTuple *Elements) {
694 if (auto *Old = cast_or_null<MDTuple>(getElements()))
695 for (const auto &Op : Old->operands())
696 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
697 "Lost a member during member list replacement");
699 replaceOperandWith(4, Elements);
701 void replaceVTableHolder(MDTypeRef VTableHolder) {
702 replaceOperandWith(5, VTableHolder);
704 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
705 replaceOperandWith(6, TemplateParams);
709 static bool classof(const Metadata *MD) {
710 return MD->getMetadataID() == MDCompositeTypeKind ||
711 MD->getMetadataID() == MDSubroutineTypeKind;
715 /// \brief Composite types.
717 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
718 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
719 class MDCompositeType : public MDCompositeTypeBase {
720 friend class LLVMContextImpl;
723 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
724 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
725 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
726 ArrayRef<Metadata *> Ops)
727 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
728 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
730 ~MDCompositeType() {}
732 static MDCompositeType *
733 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
734 unsigned Line, MDScopeRef Scope, MDTypeRef BaseType,
735 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
736 uint64_t Flags, MDTuple *Elements, unsigned RuntimeLang,
737 MDTypeRef VTableHolder, MDTemplateParameterArray TemplateParams,
738 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
739 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
740 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
741 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
742 getCanonicalMDString(Context, Identifier), Storage,
745 static MDCompositeType *
746 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
747 unsigned Line, Metadata *Scope, Metadata *BaseType,
748 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
749 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
750 Metadata *VTableHolder, Metadata *TemplateParams,
751 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
753 TempMDCompositeType cloneImpl() const {
754 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
755 getScope(), getBaseType(), getSizeInBits(),
756 getAlignInBits(), getOffsetInBits(), getFlags(),
757 getElements(), getRuntimeLang(), getVTableHolder(),
758 getTemplateParams(), getIdentifier());
762 DEFINE_MDNODE_GET(MDCompositeType,
763 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
764 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
765 uint64_t AlignInBits, uint64_t OffsetInBits,
766 unsigned Flags, MDTuple *Elements, unsigned RuntimeLang,
767 MDTypeRef VTableHolder,
768 MDTemplateParameterArray TemplateParams = nullptr,
769 StringRef Identifier = ""),
770 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
771 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
772 VTableHolder, TemplateParams, Identifier))
773 DEFINE_MDNODE_GET(MDCompositeType,
774 (unsigned Tag, MDString *Name, Metadata *File,
775 unsigned Line, Metadata *Scope, Metadata *BaseType,
776 uint64_t SizeInBits, uint64_t AlignInBits,
777 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
778 unsigned RuntimeLang, Metadata *VTableHolder,
779 Metadata *TemplateParams = nullptr,
780 MDString *Identifier = nullptr),
781 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
782 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
783 VTableHolder, TemplateParams, Identifier))
785 TempMDCompositeType clone() const { return cloneImpl(); }
787 static bool classof(const Metadata *MD) {
788 return MD->getMetadataID() == MDCompositeTypeKind;
792 template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) {
794 if (auto *Composite = dyn_cast<MDCompositeType>(N))
795 if (auto *S = Composite->getRawIdentifier())
796 return TypedDebugNodeRef<T>(S);
797 return TypedDebugNodeRef<T>(N);
800 /// \brief Type array for a subprogram.
802 /// TODO: Detach from CompositeType, and fold the array of types in directly
804 class MDSubroutineType : public MDCompositeTypeBase {
805 friend class LLVMContextImpl;
808 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
809 ArrayRef<Metadata *> Ops)
810 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
811 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
813 ~MDSubroutineType() {}
815 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
816 Metadata *TypeArray, StorageType Storage,
817 bool ShouldCreate = true);
819 TempMDSubroutineType cloneImpl() const {
820 return getTemporary(getContext(), getFlags(), getTypeArray());
824 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
827 TempMDSubroutineType clone() const { return cloneImpl(); }
829 MDTuple *getTypeArray() const { return getElements(); }
830 Metadata *getRawTypeArray() const { return getRawElements(); }
832 static bool classof(const Metadata *MD) {
833 return MD->getMetadataID() == MDSubroutineTypeKind;
837 /// \brief Compile unit.
838 class MDCompileUnit : public MDScope {
839 friend class LLVMContextImpl;
842 unsigned SourceLanguage;
844 unsigned RuntimeVersion;
845 unsigned EmissionKind;
847 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
848 bool IsOptimized, unsigned RuntimeVersion,
849 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
850 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
851 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
852 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
855 static MDCompileUnit *
856 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
857 StringRef Producer, bool IsOptimized, StringRef Flags,
858 unsigned RuntimeVersion, StringRef SplitDebugFilename,
859 unsigned EmissionKind, MDTuple *EnumTypes, MDTuple *RetainedTypes,
860 MDTuple *Subprograms, MDTuple *GlobalVariables,
861 MDTuple *ImportedEntities, StorageType Storage,
862 bool ShouldCreate = true) {
863 return getImpl(Context, SourceLanguage, File,
864 getCanonicalMDString(Context, Producer), IsOptimized,
865 getCanonicalMDString(Context, Flags), RuntimeVersion,
866 getCanonicalMDString(Context, SplitDebugFilename),
867 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
868 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
870 static MDCompileUnit *
871 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
872 MDString *Producer, bool IsOptimized, MDString *Flags,
873 unsigned RuntimeVersion, MDString *SplitDebugFilename,
874 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
875 Metadata *Subprograms, Metadata *GlobalVariables,
876 Metadata *ImportedEntities, StorageType Storage,
877 bool ShouldCreate = true);
879 TempMDCompileUnit cloneImpl() const {
881 getContext(), getSourceLanguage(), getFile(), getProducer(),
882 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
883 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
884 getGlobalVariables(), getImportedEntities());
888 DEFINE_MDNODE_GET(MDCompileUnit,
889 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
890 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
891 StringRef SplitDebugFilename, unsigned EmissionKind,
892 MDTuple *EnumTypes, MDTuple *RetainedTypes,
893 MDTuple *Subprograms, MDTuple *GlobalVariables,
894 MDTuple *ImportedEntities),
895 (SourceLanguage, File, Producer, IsOptimized, Flags,
896 RuntimeVersion, SplitDebugFilename, EmissionKind,
897 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
899 DEFINE_MDNODE_GET(MDCompileUnit,
900 (unsigned SourceLanguage, Metadata *File,
901 MDString *Producer, bool IsOptimized, MDString *Flags,
902 unsigned RuntimeVersion, MDString *SplitDebugFilename,
903 unsigned EmissionKind, Metadata *EnumTypes,
904 Metadata *RetainedTypes, Metadata *Subprograms,
905 Metadata *GlobalVariables, Metadata *ImportedEntities),
906 (SourceLanguage, File, Producer, IsOptimized, Flags,
907 RuntimeVersion, SplitDebugFilename, EmissionKind,
908 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
911 TempMDCompileUnit clone() const { return cloneImpl(); }
913 unsigned getSourceLanguage() const { return SourceLanguage; }
914 bool isOptimized() const { return IsOptimized; }
915 unsigned getRuntimeVersion() const { return RuntimeVersion; }
916 unsigned getEmissionKind() const { return EmissionKind; }
917 StringRef getProducer() const { return getStringOperand(1); }
918 StringRef getFlags() const { return getStringOperand(2); }
919 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
920 MDCompositeTypeArray getEnumTypes() const {
921 return cast_or_null<MDTuple>(getRawEnumTypes());
923 MDTypeArray getRetainedTypes() const {
924 return cast_or_null<MDTuple>(getRawRetainedTypes());
926 MDSubprogramArray getSubprograms() const {
927 return cast_or_null<MDTuple>(getRawSubprograms());
929 MDGlobalVariableArray getGlobalVariables() const {
930 return cast_or_null<MDTuple>(getRawGlobalVariables());
932 MDImportedEntityArray getImportedEntities() const {
933 return cast_or_null<MDTuple>(getRawImportedEntities());
936 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
937 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
938 MDString *getRawSplitDebugFilename() const {
939 return getOperandAs<MDString>(3);
941 Metadata *getRawEnumTypes() const { return getOperand(4); }
942 Metadata *getRawRetainedTypes() const { return getOperand(5); }
943 Metadata *getRawSubprograms() const { return getOperand(6); }
944 Metadata *getRawGlobalVariables() const { return getOperand(7); }
945 Metadata *getRawImportedEntities() const { return getOperand(8); }
947 /// \brief Replace arrays.
949 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
950 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
951 /// MDCompileUnit should be fairly rare.
953 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
954 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
957 static bool classof(const Metadata *MD) {
958 return MD->getMetadataID() == MDCompileUnitKind;
962 /// \brief A scope for locals.
964 /// A legal scope for lexical blocks, local variables, and debug info
965 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
966 /// MDLexicalBlockFile.
967 class MDLocalScope : public MDScope {
969 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
970 ArrayRef<Metadata *> Ops)
971 : MDScope(C, ID, Storage, Tag, Ops) {}
975 /// \brief Get the subprogram for this scope.
977 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
979 MDSubprogram *getSubprogram() const;
981 static bool classof(const Metadata *MD) {
982 return MD->getMetadataID() == MDSubprogramKind ||
983 MD->getMetadataID() == MDLexicalBlockKind ||
984 MD->getMetadataID() == MDLexicalBlockFileKind;
988 /// \brief Debug location.
990 /// A debug location in source code, used for debug info and otherwise.
991 class MDLocation : public MDNode {
992 friend class LLVMContextImpl;
995 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
996 unsigned Column, ArrayRef<Metadata *> MDs);
997 ~MDLocation() { dropAllReferences(); }
999 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1000 unsigned Column, Metadata *Scope,
1001 Metadata *InlinedAt, StorageType Storage,
1002 bool ShouldCreate = true);
1003 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1004 unsigned Column, MDLocalScope *Scope,
1005 MDLocation *InlinedAt, StorageType Storage,
1006 bool ShouldCreate = true) {
1007 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1008 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1011 TempMDLocation cloneImpl() const {
1012 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
1016 // Disallow replacing operands.
1017 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1020 DEFINE_MDNODE_GET(MDLocation,
1021 (unsigned Line, unsigned Column, Metadata *Scope,
1022 Metadata *InlinedAt = nullptr),
1023 (Line, Column, Scope, InlinedAt))
1024 DEFINE_MDNODE_GET(MDLocation,
1025 (unsigned Line, unsigned Column, MDLocalScope *Scope,
1026 MDLocation *InlinedAt = nullptr),
1027 (Line, Column, Scope, InlinedAt))
1029 /// \brief Return a (temporary) clone of this.
1030 TempMDLocation clone() const { return cloneImpl(); }
1032 unsigned getLine() const { return SubclassData32; }
1033 unsigned getColumn() const { return SubclassData16; }
1034 MDLocalScope *getScope() const {
1035 return cast<MDLocalScope>(getRawScope());
1037 MDLocation *getInlinedAt() const {
1038 return cast_or_null<MDLocation>(getRawInlinedAt());
1041 /// \brief Get the scope where this is inlined.
1043 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1045 MDLocalScope *getInlinedAtScope() const {
1046 if (auto *IA = getInlinedAt())
1047 return IA->getInlinedAtScope();
1051 Metadata *getRawScope() const { return getOperand(0); }
1052 Metadata *getRawInlinedAt() const {
1053 if (getNumOperands() == 2)
1054 return getOperand(1);
1058 static bool classof(const Metadata *MD) {
1059 return MD->getMetadataID() == MDLocationKind;
1063 /// \brief Subprogram description.
1065 /// TODO: Remove DisplayName. It's always equal to Name.
1066 /// TODO: Split up flags.
1067 class MDSubprogram : public MDLocalScope {
1068 friend class LLVMContextImpl;
1069 friend class MDNode;
1073 unsigned Virtuality;
1074 unsigned VirtualIndex;
1080 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1081 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1082 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
1083 bool IsOptimized, ArrayRef<Metadata *> Ops)
1084 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1086 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
1087 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
1088 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
1091 static MDSubprogram *
1092 getImpl(LLVMContext &Context, MDScopeRef Scope, StringRef Name,
1093 StringRef LinkageName, MDFile *File, unsigned Line,
1094 MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1095 unsigned ScopeLine, MDTypeRef ContainingType, unsigned Virtuality,
1096 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1097 ConstantAsMetadata *Function, MDTemplateParameterArray TemplateParams,
1098 MDSubprogram *Declaration, MDLocalVariableArray Variables,
1099 StorageType Storage, bool ShouldCreate = true) {
1100 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1101 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1102 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1103 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1104 TemplateParams, Declaration, Variables, Storage,
1107 static MDSubprogram *
1108 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1109 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1110 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1111 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1112 unsigned Flags, bool IsOptimized, Metadata *Function,
1113 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1114 StorageType Storage, bool ShouldCreate = true);
1116 TempMDSubprogram cloneImpl() const {
1117 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1118 getFile(), getLine(), getType(), isLocalToUnit(),
1119 isDefinition(), getScopeLine(), getContainingType(),
1120 getVirtuality(), getVirtualIndex(), getFlags(),
1121 isOptimized(), getFunction(), getTemplateParams(),
1122 getDeclaration(), getVariables());
1126 DEFINE_MDNODE_GET(MDSubprogram,
1127 (MDScopeRef Scope, StringRef Name, StringRef LinkageName,
1128 MDFile *File, unsigned Line, MDSubroutineType *Type,
1129 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1130 MDTypeRef ContainingType, unsigned Virtuality,
1131 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1132 ConstantAsMetadata *Function = nullptr,
1133 MDTemplateParameterArray TemplateParams = nullptr,
1134 MDSubprogram *Declaration = nullptr,
1135 MDLocalVariableArray Variables = nullptr),
1136 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1137 IsDefinition, ScopeLine, ContainingType, Virtuality,
1138 VirtualIndex, Flags, IsOptimized, Function, TemplateParams,
1139 Declaration, Variables))
1142 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1143 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1144 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1145 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1146 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1147 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1148 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1149 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1150 Function, TemplateParams, Declaration, Variables))
1152 TempMDSubprogram clone() const { return cloneImpl(); }
1155 unsigned getLine() const { return Line; }
1156 unsigned getVirtuality() const { return Virtuality; }
1157 unsigned getVirtualIndex() const { return VirtualIndex; }
1158 unsigned getScopeLine() const { return ScopeLine; }
1159 unsigned getFlags() const { return Flags; }
1160 bool isLocalToUnit() const { return IsLocalToUnit; }
1161 bool isDefinition() const { return IsDefinition; }
1162 bool isOptimized() const { return IsOptimized; }
1164 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
1166 StringRef getName() const { return getStringOperand(2); }
1167 StringRef getDisplayName() const { return getStringOperand(3); }
1168 StringRef getLinkageName() const { return getStringOperand(4); }
1170 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1171 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1173 MDSubroutineType *getType() const {
1174 return cast_or_null<MDSubroutineType>(getRawType());
1176 MDTypeRef getContainingType() const {
1177 return MDTypeRef(getRawContainingType());
1180 ConstantAsMetadata *getFunction() const {
1181 return cast_or_null<ConstantAsMetadata>(getRawFunction());
1183 MDTemplateParameterArray getTemplateParams() const {
1184 return cast_or_null<MDTuple>(getRawTemplateParams());
1186 MDSubprogram *getDeclaration() const {
1187 return cast_or_null<MDSubprogram>(getRawDeclaration());
1189 MDLocalVariableArray getVariables() const {
1190 return cast_or_null<MDTuple>(getRawVariables());
1193 Metadata *getRawScope() const { return getOperand(1); }
1194 Metadata *getRawType() const { return getOperand(5); }
1195 Metadata *getRawContainingType() const { return getOperand(6); }
1196 Metadata *getRawFunction() const { return getOperand(7); }
1197 Metadata *getRawTemplateParams() const { return getOperand(8); }
1198 Metadata *getRawDeclaration() const { return getOperand(9); }
1199 Metadata *getRawVariables() const { return getOperand(10); }
1201 /// \brief Replace the function.
1203 /// If \a isUniqued() and not \a isResolved(), this could node will be
1204 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1205 /// that's a problem.
1207 void replaceFunction(Function *F);
1208 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1209 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1212 static bool classof(const Metadata *MD) {
1213 return MD->getMetadataID() == MDSubprogramKind;
1217 class MDLexicalBlockBase : public MDLocalScope {
1219 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1220 ArrayRef<Metadata *> Ops)
1221 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1222 ~MDLexicalBlockBase() {}
1225 MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
1227 Metadata *getRawScope() const { return getOperand(1); }
1229 static bool classof(const Metadata *MD) {
1230 return MD->getMetadataID() == MDLexicalBlockKind ||
1231 MD->getMetadataID() == MDLexicalBlockFileKind;
1235 class MDLexicalBlock : public MDLexicalBlockBase {
1236 friend class LLVMContextImpl;
1237 friend class MDNode;
1242 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1243 unsigned Column, ArrayRef<Metadata *> Ops)
1244 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1246 ~MDLexicalBlock() {}
1248 static MDLexicalBlock *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1249 MDFile *File, unsigned Line, unsigned Column,
1250 StorageType Storage,
1251 bool ShouldCreate = true) {
1252 return getImpl(Context, static_cast<Metadata *>(Scope),
1253 static_cast<Metadata *>(File), Line, Column, Storage,
1257 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1258 Metadata *File, unsigned Line, unsigned Column,
1259 StorageType Storage, bool ShouldCreate = true);
1261 TempMDLexicalBlock cloneImpl() const {
1262 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1267 DEFINE_MDNODE_GET(MDLexicalBlock, (MDLocalScope * Scope, MDFile *File,
1268 unsigned Line, unsigned Column),
1269 (Scope, File, Line, Column))
1270 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1271 unsigned Line, unsigned Column),
1272 (Scope, File, Line, Column))
1274 TempMDLexicalBlock clone() const { return cloneImpl(); }
1276 unsigned getLine() const { return Line; }
1277 unsigned getColumn() const { return Column; }
1279 static bool classof(const Metadata *MD) {
1280 return MD->getMetadataID() == MDLexicalBlockKind;
1284 class MDLexicalBlockFile : public MDLexicalBlockBase {
1285 friend class LLVMContextImpl;
1286 friend class MDNode;
1288 unsigned Discriminator;
1290 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1291 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1292 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1293 Discriminator(Discriminator) {}
1294 ~MDLexicalBlockFile() {}
1296 static MDLexicalBlockFile *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1297 MDFile *File, unsigned Discriminator,
1298 StorageType Storage,
1299 bool ShouldCreate = true) {
1300 return getImpl(Context, static_cast<Metadata *>(Scope),
1301 static_cast<Metadata *>(File), Discriminator, Storage,
1305 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1306 Metadata *File, unsigned Discriminator,
1307 StorageType Storage,
1308 bool ShouldCreate = true);
1310 TempMDLexicalBlockFile cloneImpl() const {
1311 return getTemporary(getContext(), getScope(), getFile(),
1312 getDiscriminator());
1316 DEFINE_MDNODE_GET(MDLexicalBlockFile, (MDLocalScope * Scope, MDFile *File,
1317 unsigned Discriminator),
1318 (Scope, File, Discriminator))
1319 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1320 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1321 (Scope, File, Discriminator))
1323 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1325 unsigned getDiscriminator() const { return Discriminator; }
1327 static bool classof(const Metadata *MD) {
1328 return MD->getMetadataID() == MDLexicalBlockFileKind;
1332 class MDNamespace : public MDScope {
1333 friend class LLVMContextImpl;
1334 friend class MDNode;
1338 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1339 ArrayRef<Metadata *> Ops)
1340 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1345 static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
1346 MDFile *File, StringRef Name, unsigned Line,
1347 StorageType Storage, bool ShouldCreate = true) {
1348 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1349 Line, Storage, ShouldCreate);
1351 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1352 Metadata *File, MDString *Name, unsigned Line,
1353 StorageType Storage, bool ShouldCreate = true);
1355 TempMDNamespace cloneImpl() const {
1356 return getTemporary(getContext(), getScope(), getFile(), getName(),
1361 DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
1363 (Scope, File, Name, Line))
1364 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1365 MDString *Name, unsigned Line),
1366 (Scope, File, Name, Line))
1368 TempMDNamespace clone() const { return cloneImpl(); }
1370 unsigned getLine() const { return Line; }
1371 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1372 StringRef getName() const { return getStringOperand(2); }
1374 Metadata *getRawScope() const { return getOperand(1); }
1375 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1377 static bool classof(const Metadata *MD) {
1378 return MD->getMetadataID() == MDNamespaceKind;
1382 /// \brief Base class for template parameters.
1383 class MDTemplateParameter : public DebugNode {
1385 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1386 unsigned Tag, ArrayRef<Metadata *> Ops)
1387 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1388 ~MDTemplateParameter() {}
1391 StringRef getName() const { return getStringOperand(0); }
1392 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1394 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1395 Metadata *getRawType() const { return getOperand(1); }
1397 static bool classof(const Metadata *MD) {
1398 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1399 MD->getMetadataID() == MDTemplateValueParameterKind;
1403 class MDTemplateTypeParameter : public MDTemplateParameter {
1404 friend class LLVMContextImpl;
1405 friend class MDNode;
1407 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1408 ArrayRef<Metadata *> Ops)
1409 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1410 dwarf::DW_TAG_template_type_parameter, Ops) {}
1411 ~MDTemplateTypeParameter() {}
1413 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1414 MDTypeRef Type, StorageType Storage,
1415 bool ShouldCreate = true) {
1416 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1419 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1420 Metadata *Type, StorageType Storage,
1421 bool ShouldCreate = true);
1423 TempMDTemplateTypeParameter cloneImpl() const {
1424 return getTemporary(getContext(), getName(), getType());
1428 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, MDTypeRef Type),
1430 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1433 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1435 static bool classof(const Metadata *MD) {
1436 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1440 class MDTemplateValueParameter : public MDTemplateParameter {
1441 friend class LLVMContextImpl;
1442 friend class MDNode;
1444 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1445 unsigned Tag, ArrayRef<Metadata *> Ops)
1446 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1448 ~MDTemplateValueParameter() {}
1450 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1451 StringRef Name, MDTypeRef Type,
1452 Metadata *Value, StorageType Storage,
1453 bool ShouldCreate = true) {
1454 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1455 Value, Storage, ShouldCreate);
1457 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1458 MDString *Name, Metadata *Type,
1459 Metadata *Value, StorageType Storage,
1460 bool ShouldCreate = true);
1462 TempMDTemplateValueParameter cloneImpl() const {
1463 return getTemporary(getContext(), getTag(), getName(), getType(),
1468 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1469 MDTypeRef Type, Metadata *Value),
1470 (Tag, Name, Type, Value))
1471 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1472 Metadata *Type, Metadata *Value),
1473 (Tag, Name, Type, Value))
1475 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1477 Metadata *getValue() const { return getOperand(2); }
1479 static bool classof(const Metadata *MD) {
1480 return MD->getMetadataID() == MDTemplateValueParameterKind;
1484 /// \brief Base class for variables.
1486 /// TODO: Hardcode to DW_TAG_variable.
1487 class MDVariable : public DebugNode {
1491 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1492 unsigned Line, ArrayRef<Metadata *> Ops)
1493 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1497 unsigned getLine() const { return Line; }
1498 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1499 StringRef getName() const { return getStringOperand(1); }
1500 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1501 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1503 Metadata *getRawScope() const { return getOperand(0); }
1504 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1505 Metadata *getRawFile() const { return getOperand(2); }
1506 Metadata *getRawType() const { return getOperand(3); }
1508 static bool classof(const Metadata *MD) {
1509 return MD->getMetadataID() == MDLocalVariableKind ||
1510 MD->getMetadataID() == MDGlobalVariableKind;
1514 /// \brief Global variables.
1516 /// TODO: Remove DisplayName. It's always equal to Name.
1517 class MDGlobalVariable : public MDVariable {
1518 friend class LLVMContextImpl;
1519 friend class MDNode;
1524 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1525 bool IsLocalToUnit, bool IsDefinition,
1526 ArrayRef<Metadata *> Ops)
1527 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1529 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1530 ~MDGlobalVariable() {}
1532 static MDGlobalVariable *
1533 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1534 StringRef LinkageName, MDFile *File, unsigned Line, MDTypeRef Type,
1535 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1536 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1537 bool ShouldCreate = true) {
1538 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1539 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1540 IsLocalToUnit, IsDefinition, Variable,
1541 StaticDataMemberDeclaration, Storage, ShouldCreate);
1543 static MDGlobalVariable *
1544 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1545 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1546 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1547 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1548 bool ShouldCreate = true);
1550 TempMDGlobalVariable cloneImpl() const {
1551 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1552 getFile(), getLine(), getType(), isLocalToUnit(),
1553 isDefinition(), getVariable(),
1554 getStaticDataMemberDeclaration());
1558 DEFINE_MDNODE_GET(MDGlobalVariable,
1559 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1560 MDFile *File, unsigned Line, MDTypeRef Type,
1561 bool IsLocalToUnit, bool IsDefinition,
1562 ConstantAsMetadata *Variable,
1563 MDDerivedType *StaticDataMemberDeclaration),
1564 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1565 IsDefinition, Variable, StaticDataMemberDeclaration))
1566 DEFINE_MDNODE_GET(MDGlobalVariable,
1567 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1568 Metadata *File, unsigned Line, Metadata *Type,
1569 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1570 Metadata *StaticDataMemberDeclaration),
1571 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1572 IsDefinition, Variable, StaticDataMemberDeclaration))
1574 TempMDGlobalVariable clone() const { return cloneImpl(); }
1576 bool isLocalToUnit() const { return IsLocalToUnit; }
1577 bool isDefinition() const { return IsDefinition; }
1578 StringRef getDisplayName() const { return getStringOperand(4); }
1579 StringRef getLinkageName() const { return getStringOperand(5); }
1580 ConstantAsMetadata *getVariable() const {
1581 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1583 MDDerivedType *getStaticDataMemberDeclaration() const {
1584 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1587 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1588 Metadata *getRawVariable() const { return getOperand(6); }
1589 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1591 static bool classof(const Metadata *MD) {
1592 return MD->getMetadataID() == MDGlobalVariableKind;
1596 /// \brief Local variable.
1598 /// TODO: Split between arguments and otherwise.
1599 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1600 /// TODO: Split up flags.
1601 class MDLocalVariable : public MDVariable {
1602 friend class LLVMContextImpl;
1603 friend class MDNode;
1608 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1609 unsigned Line, unsigned Arg, unsigned Flags,
1610 ArrayRef<Metadata *> Ops)
1611 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1613 ~MDLocalVariable() {}
1615 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1616 MDScope *Scope, StringRef Name, MDFile *File,
1617 unsigned Line, MDTypeRef Type, unsigned Arg,
1618 unsigned Flags, MDLocation *InlinedAt,
1619 StorageType Storage,
1620 bool ShouldCreate = true) {
1621 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1622 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1625 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1626 Metadata *Scope, MDString *Name,
1627 Metadata *File, unsigned Line, Metadata *Type,
1628 unsigned Arg, unsigned Flags,
1629 Metadata *InlinedAt, StorageType Storage,
1630 bool ShouldCreate = true);
1632 TempMDLocalVariable cloneImpl() const {
1633 return getTemporary(getContext(), getTag(), getScope(), getName(),
1634 getFile(), getLine(), getType(), getArg(), getFlags(),
1639 DEFINE_MDNODE_GET(MDLocalVariable,
1640 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1641 MDFile *File, unsigned Line, MDTypeRef Type, unsigned Arg,
1642 unsigned Flags, MDLocation *InlinedAt = nullptr),
1643 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1644 DEFINE_MDNODE_GET(MDLocalVariable,
1645 (unsigned Tag, Metadata *Scope, MDString *Name,
1646 Metadata *File, unsigned Line, Metadata *Type,
1647 unsigned Arg, unsigned Flags,
1648 Metadata *InlinedAt = nullptr),
1649 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1651 TempMDLocalVariable clone() const { return cloneImpl(); }
1653 /// \brief Get the local scope for this variable.
1655 /// Variables must be defined in a local scope.
1656 MDLocalScope *getScope() const {
1657 return cast<MDLocalScope>(MDVariable::getScope());
1660 unsigned getArg() const { return Arg; }
1661 unsigned getFlags() const { return Flags; }
1662 MDLocation *getInlinedAt() const {
1663 return cast_or_null<MDLocation>(getRawInlinedAt());
1666 Metadata *getRawInlinedAt() const { return getOperand(4); }
1668 /// \brief Check that a location is valid for this variable.
1670 /// Check that \c DL has the same inlined-at location as this variable,
1671 /// making them valid for the same \a DbgInfoIntrinsic.
1672 bool isValidLocationForIntrinsic(const MDLocation *DL) const {
1673 return getInlinedAt() == (DL ? DL->getInlinedAt() : nullptr);
1676 /// \brief Get an inlined version of this variable.
1678 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1679 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1680 if (InlinedAt == getInlinedAt())
1681 return const_cast<MDLocalVariable *>(this);
1682 auto Temp = clone();
1683 Temp->replaceOperandWith(4, InlinedAt);
1684 return replaceWithUniqued(std::move(Temp));
1686 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1688 static bool classof(const Metadata *MD) {
1689 return MD->getMetadataID() == MDLocalVariableKind;
1693 /// \brief DWARF expression.
1695 /// TODO: Co-allocate the expression elements.
1696 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1698 class MDExpression : public MDNode {
1699 friend class LLVMContextImpl;
1700 friend class MDNode;
1702 std::vector<uint64_t> Elements;
1704 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1705 : MDNode(C, MDExpressionKind, Storage, None),
1706 Elements(Elements.begin(), Elements.end()) {}
1709 static MDExpression *getImpl(LLVMContext &Context,
1710 ArrayRef<uint64_t> Elements, StorageType Storage,
1711 bool ShouldCreate = true);
1713 TempMDExpression cloneImpl() const {
1714 return getTemporary(getContext(), getElements());
1718 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1720 TempMDExpression clone() const { return cloneImpl(); }
1722 ArrayRef<uint64_t> getElements() const { return Elements; }
1724 unsigned getNumElements() const { return Elements.size(); }
1725 uint64_t getElement(unsigned I) const {
1726 assert(I < Elements.size() && "Index out of range");
1730 typedef ArrayRef<uint64_t>::iterator element_iterator;
1731 element_iterator elements_begin() const { return getElements().begin(); }
1732 element_iterator elements_end() const { return getElements().end(); }
1734 /// \brief A lightweight wrapper around an expression operand.
1736 /// TODO: Store arguments directly and change \a MDExpression to store a
1742 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1744 const uint64_t *get() const { return Op; }
1746 /// \brief Get the operand code.
1747 uint64_t getOp() const { return *Op; }
1749 /// \brief Get an argument to the operand.
1751 /// Never returns the operand itself.
1752 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1754 unsigned getNumArgs() const { return getSize() - 1; }
1756 /// \brief Return the size of the operand.
1758 /// Return the number of elements in the operand (1 + args).
1759 unsigned getSize() const;
1762 /// \brief An iterator for expression operands.
1763 class expr_op_iterator
1764 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1768 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1770 element_iterator getBase() const { return Op.get(); }
1771 const ExprOperand &operator*() const { return Op; }
1772 const ExprOperand *operator->() const { return &Op; }
1774 expr_op_iterator &operator++() {
1778 expr_op_iterator operator++(int) {
1779 expr_op_iterator T(*this);
1784 bool operator==(const expr_op_iterator &X) const {
1785 return getBase() == X.getBase();
1787 bool operator!=(const expr_op_iterator &X) const {
1788 return getBase() != X.getBase();
1792 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1795 /// \brief Visit the elements via ExprOperand wrappers.
1797 /// These range iterators visit elements through \a ExprOperand wrappers.
1798 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1801 /// \pre \a isValid() gives \c true.
1803 expr_op_iterator expr_op_begin() const {
1804 return expr_op_iterator(elements_begin());
1806 expr_op_iterator expr_op_end() const {
1807 return expr_op_iterator(elements_end());
1811 bool isValid() const;
1813 static bool classof(const Metadata *MD) {
1814 return MD->getMetadataID() == MDExpressionKind;
1818 class MDObjCProperty : public DebugNode {
1819 friend class LLVMContextImpl;
1820 friend class MDNode;
1823 unsigned Attributes;
1825 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1826 unsigned Attributes, ArrayRef<Metadata *> Ops)
1827 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1829 Line(Line), Attributes(Attributes) {}
1830 ~MDObjCProperty() {}
1832 static MDObjCProperty *
1833 getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
1834 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1835 MDType *Type, StorageType Storage, bool ShouldCreate = true) {
1836 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1837 getCanonicalMDString(Context, GetterName),
1838 getCanonicalMDString(Context, SetterName), Attributes, Type,
1839 Storage, ShouldCreate);
1841 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1842 Metadata *File, unsigned Line,
1843 MDString *GetterName, MDString *SetterName,
1844 unsigned Attributes, Metadata *Type,
1845 StorageType Storage, bool ShouldCreate = true);
1847 TempMDObjCProperty cloneImpl() const {
1848 return getTemporary(getContext(), getName(), getFile(), getLine(),
1849 getGetterName(), getSetterName(), getAttributes(),
1854 DEFINE_MDNODE_GET(MDObjCProperty,
1855 (StringRef Name, MDFile *File, unsigned Line,
1856 StringRef GetterName, StringRef SetterName,
1857 unsigned Attributes, MDType *Type),
1858 (Name, File, Line, GetterName, SetterName, Attributes,
1860 DEFINE_MDNODE_GET(MDObjCProperty,
1861 (MDString * Name, Metadata *File, unsigned Line,
1862 MDString *GetterName, MDString *SetterName,
1863 unsigned Attributes, Metadata *Type),
1864 (Name, File, Line, GetterName, SetterName, Attributes,
1867 TempMDObjCProperty clone() const { return cloneImpl(); }
1869 unsigned getLine() const { return Line; }
1870 unsigned getAttributes() const { return Attributes; }
1871 StringRef getName() const { return getStringOperand(0); }
1872 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1873 StringRef getGetterName() const { return getStringOperand(2); }
1874 StringRef getSetterName() const { return getStringOperand(3); }
1875 MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
1877 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1878 Metadata *getRawFile() const { return getOperand(1); }
1879 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1880 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1881 Metadata *getRawType() const { return getOperand(4); }
1883 static bool classof(const Metadata *MD) {
1884 return MD->getMetadataID() == MDObjCPropertyKind;
1888 class MDImportedEntity : public DebugNode {
1889 friend class LLVMContextImpl;
1890 friend class MDNode;
1894 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1895 unsigned Line, ArrayRef<Metadata *> Ops)
1896 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1897 ~MDImportedEntity() {}
1899 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1900 MDScope *Scope, Metadata *Entity,
1901 unsigned Line, StringRef Name,
1902 StorageType Storage,
1903 bool ShouldCreate = true) {
1904 return getImpl(Context, Tag, Scope, Entity, Line,
1905 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1907 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1908 Metadata *Scope, Metadata *Entity,
1909 unsigned Line, MDString *Name,
1910 StorageType Storage,
1911 bool ShouldCreate = true);
1913 TempMDImportedEntity cloneImpl() const {
1914 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1915 getLine(), getName());
1919 DEFINE_MDNODE_GET(MDImportedEntity,
1920 (unsigned Tag, MDScope *Scope, Metadata *Entity,
1921 unsigned Line, StringRef Name = ""),
1922 (Tag, Scope, Entity, Line, Name))
1923 DEFINE_MDNODE_GET(MDImportedEntity,
1924 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1925 unsigned Line, MDString *Name),
1926 (Tag, Scope, Entity, Line, Name))
1928 TempMDImportedEntity clone() const { return cloneImpl(); }
1930 unsigned getLine() const { return Line; }
1931 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1932 Metadata *getEntity() const { return getRawEntity(); }
1933 StringRef getName() const { return getStringOperand(2); }
1935 Metadata *getRawScope() const { return getOperand(0); }
1936 Metadata *getRawEntity() const { return getOperand(1); }
1937 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1939 static bool classof(const Metadata *MD) {
1940 return MD->getMetadataID() == MDImportedEntityKind;
1944 } // end namespace llvm
1946 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1947 #undef DEFINE_MDNODE_GET_UNPACK
1948 #undef DEFINE_MDNODE_GET