1 //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Declarations for metadata specific to debug info.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_DEBUGINFOMETADATA_H
15 #define LLVM_IR_DEBUGINFOMETADATA_H
17 #include "llvm/IR/Metadata.h"
18 #include "llvm/Support/Dwarf.h"
20 // Helper macros for defining get() overrides.
21 #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
22 #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
23 #define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
24 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
25 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
27 static CLASS *getIfExists(LLVMContext &Context, \
28 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
29 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
30 /* ShouldCreate */ false); \
32 static CLASS *getDistinct(LLVMContext &Context, \
33 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
34 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
36 static Temp##CLASS getTemporary(LLVMContext &Context, \
37 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
39 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
44 /// \brief Pointer union between a subclass of DebugNode and MDString.
46 /// \a MDCompositeType can be referenced via an \a MDString unique identifier.
47 /// This class allows some type safety in the face of that, requiring either a
48 /// node of a particular type or an \a MDString.
49 template <class T> class TypedDebugNodeRef {
50 const Metadata *MD = nullptr;
53 TypedDebugNodeRef(std::nullptr_t) {}
55 /// \brief Construct from a raw pointer.
56 explicit TypedDebugNodeRef(const Metadata *MD) : MD(MD) {
57 assert((!MD || isa<MDString>(MD) || isa<T>(MD)) && "Expected valid ref");
62 const TypedDebugNodeRef<U> &X,
63 typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
67 operator Metadata *() const { return const_cast<Metadata *>(MD); }
69 bool operator==(const TypedDebugNodeRef<T> &X) const { return MD == X.MD; };
70 bool operator!=(const TypedDebugNodeRef<T> &X) const { return MD != X.MD; };
72 /// \brief Create a reference.
74 /// Get a reference to \c N, using an \a MDString reference if available.
75 static TypedDebugNodeRef get(const T *N);
77 template <class MapTy> T *resolve(const MapTy &Map) const {
81 if (auto *Typed = dyn_cast<T>(MD))
82 return const_cast<T *>(Typed);
84 auto *S = cast<MDString>(MD);
86 assert(I != Map.end() && "Missing identifier in type map");
87 return cast<T>(I->second);
91 typedef TypedDebugNodeRef<DebugNode> DebugNodeRef;
92 typedef TypedDebugNodeRef<MDScope> MDScopeRef;
93 typedef TypedDebugNodeRef<MDType> MDTypeRef;
95 class MDTypeRefArray {
96 const MDTuple *N = nullptr;
99 MDTypeRefArray(const MDTuple *N) : N(N) {}
100 operator MDTuple *() const { return const_cast<MDTuple *>(N); }
101 MDTuple *operator->() const { return const_cast<MDTuple *>(N); }
102 MDTuple &operator*() const { return *const_cast<MDTuple *>(N); }
104 unsigned size() const { return N->getNumOperands(); }
105 MDTypeRef operator[](unsigned I) const { return MDTypeRef(N->getOperand(I)); }
107 class iterator : std::iterator<std::input_iterator_tag, MDTypeRef,
108 std::ptrdiff_t, void, MDTypeRef> {
109 MDNode::op_iterator I;
112 explicit iterator(MDNode::op_iterator I) : I(I) {}
113 MDTypeRef operator*() const { return MDTypeRef(*I); }
114 iterator &operator++() {
118 iterator operator++(int) {
119 iterator Temp(*this);
123 bool operator==(const iterator &X) const { return I == X.I; }
124 bool operator!=(const iterator &X) const { return I != X.I; }
127 iterator begin() const { return iterator(N->op_begin()); }
128 iterator end() const { return iterator(N->op_end()); }
131 /// \brief Tagged DWARF-like metadata node.
133 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
134 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
135 /// potentially used for non-DWARF output.
136 class DebugNode : public MDNode {
137 friend class LLVMContextImpl;
141 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
142 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
143 : MDNode(C, ID, Storage, Ops1, Ops2) {
144 assert(Tag < 1u << 16);
145 SubclassData16 = Tag;
149 template <class Ty> Ty *getOperandAs(unsigned I) const {
150 return cast_or_null<Ty>(getOperand(I));
153 StringRef getStringOperand(unsigned I) const {
154 if (auto *S = getOperandAs<MDString>(I))
155 return S->getString();
159 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
162 return MDString::get(Context, S);
166 unsigned getTag() const { return SubclassData16; }
168 /// \brief Debug info flags.
170 /// The three accessibility flags are mutually exclusive and rolled together
171 /// in the first two bits.
173 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
174 #include "llvm/IR/DebugInfoFlags.def"
175 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
178 static unsigned getFlag(StringRef Flag);
179 static const char *getFlagString(unsigned Flag);
181 /// \brief Split up a flags bitfield.
183 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
184 /// any remaining (unrecognized) bits.
185 static unsigned splitFlags(unsigned Flags,
186 SmallVectorImpl<unsigned> &SplitFlags);
188 DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
190 static bool classof(const Metadata *MD) {
191 switch (MD->getMetadataID()) {
194 case GenericDebugNodeKind:
196 case MDEnumeratorKind:
197 case MDBasicTypeKind:
198 case MDDerivedTypeKind:
199 case MDCompositeTypeKind:
200 case MDSubroutineTypeKind:
202 case MDCompileUnitKind:
203 case MDSubprogramKind:
204 case MDLexicalBlockKind:
205 case MDLexicalBlockFileKind:
206 case MDNamespaceKind:
207 case MDTemplateTypeParameterKind:
208 case MDTemplateValueParameterKind:
209 case MDGlobalVariableKind:
210 case MDLocalVariableKind:
211 case MDObjCPropertyKind:
212 case MDImportedEntityKind:
219 struct simplify_type<const TypedDebugNodeRef<T>> {
220 typedef Metadata *SimpleType;
221 static SimpleType getSimplifiedValue(const TypedDebugNodeRef<T> &MD) {
227 struct simplify_type<TypedDebugNodeRef<T>>
228 : simplify_type<const TypedDebugNodeRef<T>> {};
230 /// \brief Generic tagged DWARF-like metadata node.
232 /// An un-specialized DWARF-like metadata node. The first operand is a
233 /// (possibly empty) null-separated \a MDString header that contains arbitrary
234 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
235 /// to other metadata.
236 class GenericDebugNode : public DebugNode {
237 friend class LLVMContextImpl;
240 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
241 unsigned Tag, ArrayRef<Metadata *> Ops1,
242 ArrayRef<Metadata *> Ops2)
243 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
246 ~GenericDebugNode() { dropAllReferences(); }
248 void setHash(unsigned Hash) { SubclassData32 = Hash; }
249 void recalculateHash();
251 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
253 ArrayRef<Metadata *> DwarfOps,
255 bool ShouldCreate = true) {
256 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
257 DwarfOps, Storage, ShouldCreate);
260 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
262 ArrayRef<Metadata *> DwarfOps,
264 bool ShouldCreate = true);
266 TempGenericDebugNode cloneImpl() const {
268 getContext(), getTag(), getHeader(),
269 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
273 unsigned getHash() const { return SubclassData32; }
275 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
276 ArrayRef<Metadata *> DwarfOps),
277 (Tag, Header, DwarfOps))
278 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
279 ArrayRef<Metadata *> DwarfOps),
280 (Tag, Header, DwarfOps))
282 /// \brief Return a (temporary) clone of this.
283 TempGenericDebugNode clone() const { return cloneImpl(); }
285 unsigned getTag() const { return SubclassData16; }
286 StringRef getHeader() const { return getStringOperand(0); }
288 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
289 op_iterator dwarf_op_end() const { return op_end(); }
290 op_range dwarf_operands() const {
291 return op_range(dwarf_op_begin(), dwarf_op_end());
294 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
295 const MDOperand &getDwarfOperand(unsigned I) const {
296 return getOperand(I + 1);
298 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
299 replaceOperandWith(I + 1, New);
302 static bool classof(const Metadata *MD) {
303 return MD->getMetadataID() == GenericDebugNodeKind;
307 /// \brief Array subrange.
309 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
311 class MDSubrange : public DebugNode {
312 friend class LLVMContextImpl;
318 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count,
320 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
322 Count(Count), LowerBound(LowerBound) {}
325 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count,
326 int64_t LowerBound, StorageType Storage,
327 bool ShouldCreate = true);
329 TempMDSubrange cloneImpl() const {
330 return getTemporary(getContext(), getCount(), getLowerBound());
334 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t LowerBound = 0),
337 TempMDSubrange clone() const { return cloneImpl(); }
339 int64_t getLowerBound() const { return LowerBound; }
340 int64_t getCount() const { return Count; }
342 static bool classof(const Metadata *MD) {
343 return MD->getMetadataID() == MDSubrangeKind;
347 /// \brief Enumeration value.
349 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
350 /// longer creates a type cycle.
351 class MDEnumerator : public DebugNode {
352 friend class LLVMContextImpl;
357 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
358 ArrayRef<Metadata *> Ops)
359 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
363 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
364 StringRef Name, StorageType Storage,
365 bool ShouldCreate = true) {
366 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
369 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
370 MDString *Name, StorageType Storage,
371 bool ShouldCreate = true);
373 TempMDEnumerator cloneImpl() const {
374 return getTemporary(getContext(), getValue(), getName());
378 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
380 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
383 TempMDEnumerator clone() const { return cloneImpl(); }
385 int64_t getValue() const { return Value; }
386 StringRef getName() const { return getStringOperand(0); }
388 MDString *getRawName() const { return getOperandAs<MDString>(0); }
390 static bool classof(const Metadata *MD) {
391 return MD->getMetadataID() == MDEnumeratorKind;
395 /// \brief Base class for scope-like contexts.
397 /// Base class for lexical scopes and types (which are also declaration
400 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
401 class MDScope : public DebugNode {
403 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
404 ArrayRef<Metadata *> Ops)
405 : DebugNode(C, ID, Storage, Tag, Ops) {}
409 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
411 /// \brief Return the raw underlying file.
413 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
414 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
415 /// this. Otherwise, return the first operand, which is where all other
416 /// subclasses store their file pointer.
417 Metadata *getRawFile() const {
418 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
419 : static_cast<Metadata *>(getOperand(0));
422 MDScopeRef getRef() const { return MDScopeRef::get(this); }
424 static bool classof(const Metadata *MD) {
425 switch (MD->getMetadataID()) {
428 case MDBasicTypeKind:
429 case MDDerivedTypeKind:
430 case MDCompositeTypeKind:
431 case MDSubroutineTypeKind:
433 case MDCompileUnitKind:
434 case MDSubprogramKind:
435 case MDLexicalBlockKind:
436 case MDLexicalBlockFileKind:
437 case MDNamespaceKind:
445 /// TODO: Merge with directory/file node (including users).
446 /// TODO: Canonicalize paths on creation.
447 class MDFile : public MDScope {
448 friend class LLVMContextImpl;
451 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
452 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
455 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
456 StringRef Directory, StorageType Storage,
457 bool ShouldCreate = true) {
458 return getImpl(Context, getCanonicalMDString(Context, Filename),
459 getCanonicalMDString(Context, Directory), Storage,
462 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
463 MDString *Directory, StorageType Storage,
464 bool ShouldCreate = true);
466 TempMDFile cloneImpl() const {
467 return getTemporary(getContext(), getFilename(), getDirectory());
471 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
472 (Filename, Directory))
473 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
474 (Filename, Directory))
476 TempMDFile clone() const { return cloneImpl(); }
478 StringRef getFilename() const { return getStringOperand(0); }
479 StringRef getDirectory() const { return getStringOperand(1); }
481 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
482 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
484 static bool classof(const Metadata *MD) {
485 return MD->getMetadataID() == MDFileKind;
489 /// \brief Base class for types.
491 /// TODO: Remove the hardcoded name and context, since many types don't use
493 /// TODO: Split up flags.
494 class MDType : public MDScope {
498 uint64_t AlignInBits;
499 uint64_t OffsetInBits;
502 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
503 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
504 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
505 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
506 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
507 OffsetInBits(OffsetInBits) {}
511 TempMDType clone() const {
512 return TempMDType(cast<MDType>(MDNode::clone().release()));
515 unsigned getLine() const { return Line; }
516 uint64_t getSizeInBits() const { return SizeInBits; }
517 uint64_t getAlignInBits() const { return AlignInBits; }
518 uint64_t getOffsetInBits() const { return OffsetInBits; }
519 unsigned getFlags() const { return Flags; }
521 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
522 StringRef getName() const { return getStringOperand(2); }
525 Metadata *getRawScope() const { return getOperand(1); }
526 MDString *getRawName() const { return getOperandAs<MDString>(2); }
528 void setFlags(unsigned NewFlags) {
529 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
533 bool isPrivate() const {
534 return (getFlags() & FlagAccessibility) == FlagPrivate;
536 bool isProtected() const {
537 return (getFlags() & FlagAccessibility) == FlagProtected;
539 bool isPublic() const {
540 return (getFlags() & FlagAccessibility) == FlagPublic;
542 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
543 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
544 bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; }
545 bool isVirtual() const { return getFlags() & FlagVirtual; }
546 bool isArtificial() const { return getFlags() & FlagArtificial; }
547 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
548 bool isObjcClassComplete() const {
549 return getFlags() & FlagObjcClassComplete;
551 bool isVector() const { return getFlags() & FlagVector; }
552 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
553 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
554 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
556 MDTypeRef getRef() const { return MDTypeRef::get(this); }
558 static bool classof(const Metadata *MD) {
559 switch (MD->getMetadataID()) {
562 case MDBasicTypeKind:
563 case MDDerivedTypeKind:
564 case MDCompositeTypeKind:
565 case MDSubroutineTypeKind:
571 /// \brief Basic type.
573 /// TODO: Split out DW_TAG_unspecified_type.
574 /// TODO: Drop unused accessors.
575 class MDBasicType : public MDType {
576 friend class LLVMContextImpl;
581 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
582 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
583 ArrayRef<Metadata *> Ops)
584 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
586 Encoding(Encoding) {}
589 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
590 StringRef Name, uint64_t SizeInBits,
591 uint64_t AlignInBits, unsigned Encoding,
592 StorageType Storage, bool ShouldCreate = true) {
593 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
594 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
596 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
597 MDString *Name, uint64_t SizeInBits,
598 uint64_t AlignInBits, unsigned Encoding,
599 StorageType Storage, bool ShouldCreate = true);
601 TempMDBasicType cloneImpl() const {
602 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
603 getAlignInBits(), getEncoding());
607 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
608 (Tag, Name, 0, 0, 0))
609 DEFINE_MDNODE_GET(MDBasicType,
610 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
611 uint64_t AlignInBits, unsigned Encoding),
612 (Tag, Name, SizeInBits, AlignInBits, Encoding))
613 DEFINE_MDNODE_GET(MDBasicType,
614 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
615 uint64_t AlignInBits, unsigned Encoding),
616 (Tag, Name, SizeInBits, AlignInBits, Encoding))
618 TempMDBasicType clone() const { return cloneImpl(); }
620 unsigned getEncoding() const { return Encoding; }
622 static bool classof(const Metadata *MD) {
623 return MD->getMetadataID() == MDBasicTypeKind;
627 /// \brief Base class for MDDerivedType and MDCompositeType.
629 /// TODO: Delete; they're not really related.
630 class MDDerivedTypeBase : public MDType {
632 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
633 unsigned Tag, unsigned Line, uint64_t SizeInBits,
634 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
635 ArrayRef<Metadata *> Ops)
636 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
638 ~MDDerivedTypeBase() {}
641 MDTypeRef getBaseType() const { return MDTypeRef(getRawBaseType()); }
642 Metadata *getRawBaseType() const { return getOperand(3); }
644 static bool classof(const Metadata *MD) {
645 return MD->getMetadataID() == MDDerivedTypeKind ||
646 MD->getMetadataID() == MDCompositeTypeKind ||
647 MD->getMetadataID() == MDSubroutineTypeKind;
651 /// \brief Derived types.
653 /// This includes qualified types, pointers, references, friends, typedefs, and
656 /// TODO: Split out members (inheritance, fields, methods, etc.).
657 class MDDerivedType : public MDDerivedTypeBase {
658 friend class LLVMContextImpl;
661 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
662 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
663 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
664 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
665 AlignInBits, OffsetInBits, Flags, Ops) {}
668 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
669 StringRef Name, MDFile *File, unsigned Line,
670 MDScopeRef Scope, MDTypeRef BaseType,
671 uint64_t SizeInBits, uint64_t AlignInBits,
672 uint64_t OffsetInBits, unsigned Flags,
673 Metadata *ExtraData, StorageType Storage,
674 bool ShouldCreate = true) {
675 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
676 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
677 Flags, ExtraData, Storage, ShouldCreate);
679 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
680 MDString *Name, Metadata *File, unsigned Line,
681 Metadata *Scope, Metadata *BaseType,
682 uint64_t SizeInBits, uint64_t AlignInBits,
683 uint64_t OffsetInBits, unsigned Flags,
684 Metadata *ExtraData, StorageType Storage,
685 bool ShouldCreate = true);
687 TempMDDerivedType cloneImpl() const {
688 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
689 getScope(), getBaseType(), getSizeInBits(),
690 getAlignInBits(), getOffsetInBits(), getFlags(),
695 DEFINE_MDNODE_GET(MDDerivedType,
696 (unsigned Tag, MDString *Name, Metadata *File,
697 unsigned Line, Metadata *Scope, Metadata *BaseType,
698 uint64_t SizeInBits, uint64_t AlignInBits,
699 uint64_t OffsetInBits, unsigned Flags,
700 Metadata *ExtraData = nullptr),
701 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
702 AlignInBits, OffsetInBits, Flags, ExtraData))
703 DEFINE_MDNODE_GET(MDDerivedType,
704 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
705 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
706 uint64_t AlignInBits, uint64_t OffsetInBits,
707 unsigned Flags, Metadata *ExtraData = nullptr),
708 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
709 AlignInBits, OffsetInBits, Flags, ExtraData))
711 TempMDDerivedType clone() const { return cloneImpl(); }
713 /// \brief Get extra data associated with this derived type.
715 /// Class type for pointer-to-members, objective-c property node for ivars,
716 /// or global constant wrapper for static members.
718 /// TODO: Separate out types that need this extra operand: pointer-to-member
719 /// types and member fields (static members and ivars).
720 Metadata *getExtraData() const { return getRawExtraData(); }
721 Metadata *getRawExtraData() const { return getOperand(4); }
723 static bool classof(const Metadata *MD) {
724 return MD->getMetadataID() == MDDerivedTypeKind;
728 /// \brief Base class for MDCompositeType and MDSubroutineType.
730 /// TODO: Delete; they're not really related.
731 class MDCompositeTypeBase : public MDDerivedTypeBase {
732 unsigned RuntimeLang;
735 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
736 unsigned Tag, unsigned Line, unsigned RuntimeLang,
737 uint64_t SizeInBits, uint64_t AlignInBits,
738 uint64_t OffsetInBits, unsigned Flags,
739 ArrayRef<Metadata *> Ops)
740 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
741 OffsetInBits, Flags, Ops),
742 RuntimeLang(RuntimeLang) {}
743 ~MDCompositeTypeBase() {}
746 MDTuple *getElements() const {
747 return cast_or_null<MDTuple>(getRawElements());
749 MDTypeRef getVTableHolder() const { return MDTypeRef(getRawVTableHolder()); }
750 MDTemplateParameterArray getTemplateParams() const {
751 return cast_or_null<MDTuple>(getRawTemplateParams());
753 StringRef getIdentifier() const { return getStringOperand(7); }
754 unsigned getRuntimeLang() const { return RuntimeLang; }
756 Metadata *getRawElements() const { return getOperand(4); }
757 Metadata *getRawVTableHolder() const { return getOperand(5); }
758 Metadata *getRawTemplateParams() const { return getOperand(6); }
759 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
761 /// \brief Replace operands.
763 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
764 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
765 /// of its movement if necessary.
767 void replaceElements(MDTuple *Elements) {
769 if (auto *Old = cast_or_null<MDTuple>(getElements()))
770 for (const auto &Op : Old->operands())
771 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
772 "Lost a member during member list replacement");
774 replaceOperandWith(4, Elements);
776 void replaceVTableHolder(MDTypeRef VTableHolder) {
777 replaceOperandWith(5, VTableHolder);
779 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
780 replaceOperandWith(6, TemplateParams);
784 static bool classof(const Metadata *MD) {
785 return MD->getMetadataID() == MDCompositeTypeKind ||
786 MD->getMetadataID() == MDSubroutineTypeKind;
790 /// \brief Composite types.
792 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
793 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
794 class MDCompositeType : public MDCompositeTypeBase {
795 friend class LLVMContextImpl;
798 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
799 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
800 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
801 ArrayRef<Metadata *> Ops)
802 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
803 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
805 ~MDCompositeType() {}
807 static MDCompositeType *
808 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
809 unsigned Line, MDScopeRef Scope, MDTypeRef BaseType,
810 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
811 uint64_t Flags, MDTuple *Elements, unsigned RuntimeLang,
812 MDTypeRef VTableHolder, MDTemplateParameterArray TemplateParams,
813 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
814 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
815 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
816 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
817 getCanonicalMDString(Context, Identifier), Storage,
820 static MDCompositeType *
821 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
822 unsigned Line, Metadata *Scope, Metadata *BaseType,
823 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
824 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
825 Metadata *VTableHolder, Metadata *TemplateParams,
826 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
828 TempMDCompositeType cloneImpl() const {
829 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
830 getScope(), getBaseType(), getSizeInBits(),
831 getAlignInBits(), getOffsetInBits(), getFlags(),
832 getElements(), getRuntimeLang(), getVTableHolder(),
833 getTemplateParams(), getIdentifier());
837 DEFINE_MDNODE_GET(MDCompositeType,
838 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
839 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
840 uint64_t AlignInBits, uint64_t OffsetInBits,
841 unsigned Flags, MDTuple *Elements, unsigned RuntimeLang,
842 MDTypeRef VTableHolder,
843 MDTemplateParameterArray TemplateParams = nullptr,
844 StringRef Identifier = ""),
845 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
846 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
847 VTableHolder, TemplateParams, Identifier))
848 DEFINE_MDNODE_GET(MDCompositeType,
849 (unsigned Tag, MDString *Name, Metadata *File,
850 unsigned Line, Metadata *Scope, Metadata *BaseType,
851 uint64_t SizeInBits, uint64_t AlignInBits,
852 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
853 unsigned RuntimeLang, Metadata *VTableHolder,
854 Metadata *TemplateParams = nullptr,
855 MDString *Identifier = nullptr),
856 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
857 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
858 VTableHolder, TemplateParams, Identifier))
860 TempMDCompositeType clone() const { return cloneImpl(); }
862 static bool classof(const Metadata *MD) {
863 return MD->getMetadataID() == MDCompositeTypeKind;
867 template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) {
869 if (auto *Composite = dyn_cast<MDCompositeType>(N))
870 if (auto *S = Composite->getRawIdentifier())
871 return TypedDebugNodeRef<T>(S);
872 return TypedDebugNodeRef<T>(N);
875 /// \brief Type array for a subprogram.
877 /// TODO: Detach from CompositeType, and fold the array of types in directly
879 class MDSubroutineType : public MDCompositeTypeBase {
880 friend class LLVMContextImpl;
883 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
884 ArrayRef<Metadata *> Ops)
885 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
886 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
888 ~MDSubroutineType() {}
890 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
891 Metadata *TypeArray, StorageType Storage,
892 bool ShouldCreate = true);
894 TempMDSubroutineType cloneImpl() const {
895 return getTemporary(getContext(), getFlags(), getTypeArray());
899 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
902 TempMDSubroutineType clone() const { return cloneImpl(); }
904 MDTypeRefArray getTypeArray() const { return getElements(); }
905 Metadata *getRawTypeArray() const { return getRawElements(); }
907 static bool classof(const Metadata *MD) {
908 return MD->getMetadataID() == MDSubroutineTypeKind;
912 /// \brief Compile unit.
913 class MDCompileUnit : public MDScope {
914 friend class LLVMContextImpl;
917 unsigned SourceLanguage;
919 unsigned RuntimeVersion;
920 unsigned EmissionKind;
922 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
923 bool IsOptimized, unsigned RuntimeVersion,
924 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
925 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
926 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
927 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
930 static MDCompileUnit *
931 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
932 StringRef Producer, bool IsOptimized, StringRef Flags,
933 unsigned RuntimeVersion, StringRef SplitDebugFilename,
934 unsigned EmissionKind, MDTuple *EnumTypes, MDTuple *RetainedTypes,
935 MDTuple *Subprograms, MDTuple *GlobalVariables,
936 MDTuple *ImportedEntities, StorageType Storage,
937 bool ShouldCreate = true) {
938 return getImpl(Context, SourceLanguage, File,
939 getCanonicalMDString(Context, Producer), IsOptimized,
940 getCanonicalMDString(Context, Flags), RuntimeVersion,
941 getCanonicalMDString(Context, SplitDebugFilename),
942 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
943 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
945 static MDCompileUnit *
946 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
947 MDString *Producer, bool IsOptimized, MDString *Flags,
948 unsigned RuntimeVersion, MDString *SplitDebugFilename,
949 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
950 Metadata *Subprograms, Metadata *GlobalVariables,
951 Metadata *ImportedEntities, StorageType Storage,
952 bool ShouldCreate = true);
954 TempMDCompileUnit cloneImpl() const {
956 getContext(), getSourceLanguage(), getFile(), getProducer(),
957 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
958 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
959 getGlobalVariables(), getImportedEntities());
963 DEFINE_MDNODE_GET(MDCompileUnit,
964 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
965 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
966 StringRef SplitDebugFilename, unsigned EmissionKind,
967 MDTuple *EnumTypes, MDTuple *RetainedTypes,
968 MDTuple *Subprograms, MDTuple *GlobalVariables,
969 MDTuple *ImportedEntities),
970 (SourceLanguage, File, Producer, IsOptimized, Flags,
971 RuntimeVersion, SplitDebugFilename, EmissionKind,
972 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
974 DEFINE_MDNODE_GET(MDCompileUnit,
975 (unsigned SourceLanguage, Metadata *File,
976 MDString *Producer, bool IsOptimized, MDString *Flags,
977 unsigned RuntimeVersion, MDString *SplitDebugFilename,
978 unsigned EmissionKind, Metadata *EnumTypes,
979 Metadata *RetainedTypes, Metadata *Subprograms,
980 Metadata *GlobalVariables, Metadata *ImportedEntities),
981 (SourceLanguage, File, Producer, IsOptimized, Flags,
982 RuntimeVersion, SplitDebugFilename, EmissionKind,
983 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
986 TempMDCompileUnit clone() const { return cloneImpl(); }
988 unsigned getSourceLanguage() const { return SourceLanguage; }
989 bool isOptimized() const { return IsOptimized; }
990 unsigned getRuntimeVersion() const { return RuntimeVersion; }
991 unsigned getEmissionKind() const { return EmissionKind; }
992 StringRef getProducer() const { return getStringOperand(1); }
993 StringRef getFlags() const { return getStringOperand(2); }
994 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
995 MDCompositeTypeArray getEnumTypes() const {
996 return cast_or_null<MDTuple>(getRawEnumTypes());
998 MDTypeArray getRetainedTypes() const {
999 return cast_or_null<MDTuple>(getRawRetainedTypes());
1001 MDSubprogramArray getSubprograms() const {
1002 return cast_or_null<MDTuple>(getRawSubprograms());
1004 MDGlobalVariableArray getGlobalVariables() const {
1005 return cast_or_null<MDTuple>(getRawGlobalVariables());
1007 MDImportedEntityArray getImportedEntities() const {
1008 return cast_or_null<MDTuple>(getRawImportedEntities());
1011 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1012 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1013 MDString *getRawSplitDebugFilename() const {
1014 return getOperandAs<MDString>(3);
1016 Metadata *getRawEnumTypes() const { return getOperand(4); }
1017 Metadata *getRawRetainedTypes() const { return getOperand(5); }
1018 Metadata *getRawSubprograms() const { return getOperand(6); }
1019 Metadata *getRawGlobalVariables() const { return getOperand(7); }
1020 Metadata *getRawImportedEntities() const { return getOperand(8); }
1022 /// \brief Replace arrays.
1024 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1025 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1026 /// MDCompileUnit should be fairly rare.
1028 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
1029 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
1032 static bool classof(const Metadata *MD) {
1033 return MD->getMetadataID() == MDCompileUnitKind;
1037 /// \brief A scope for locals.
1039 /// A legal scope for lexical blocks, local variables, and debug info
1040 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
1041 /// MDLexicalBlockFile.
1042 class MDLocalScope : public MDScope {
1044 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1045 ArrayRef<Metadata *> Ops)
1046 : MDScope(C, ID, Storage, Tag, Ops) {}
1050 /// \brief Get the subprogram for this scope.
1052 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
1054 MDSubprogram *getSubprogram() const;
1056 static bool classof(const Metadata *MD) {
1057 return MD->getMetadataID() == MDSubprogramKind ||
1058 MD->getMetadataID() == MDLexicalBlockKind ||
1059 MD->getMetadataID() == MDLexicalBlockFileKind;
1063 /// \brief Debug location.
1065 /// A debug location in source code, used for debug info and otherwise.
1066 class MDLocation : public MDNode {
1067 friend class LLVMContextImpl;
1068 friend class MDNode;
1070 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
1071 unsigned Column, ArrayRef<Metadata *> MDs);
1072 ~MDLocation() { dropAllReferences(); }
1074 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1075 unsigned Column, Metadata *Scope,
1076 Metadata *InlinedAt, StorageType Storage,
1077 bool ShouldCreate = true);
1078 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1079 unsigned Column, MDLocalScope *Scope,
1080 MDLocation *InlinedAt, StorageType Storage,
1081 bool ShouldCreate = true) {
1082 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1083 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1086 TempMDLocation cloneImpl() const {
1087 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
1091 // Disallow replacing operands.
1092 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1095 DEFINE_MDNODE_GET(MDLocation,
1096 (unsigned Line, unsigned Column, Metadata *Scope,
1097 Metadata *InlinedAt = nullptr),
1098 (Line, Column, Scope, InlinedAt))
1099 DEFINE_MDNODE_GET(MDLocation,
1100 (unsigned Line, unsigned Column, MDLocalScope *Scope,
1101 MDLocation *InlinedAt = nullptr),
1102 (Line, Column, Scope, InlinedAt))
1104 /// \brief Return a (temporary) clone of this.
1105 TempMDLocation clone() const { return cloneImpl(); }
1107 unsigned getLine() const { return SubclassData32; }
1108 unsigned getColumn() const { return SubclassData16; }
1109 MDLocalScope *getScope() const {
1110 return cast<MDLocalScope>(getRawScope());
1112 MDLocation *getInlinedAt() const {
1113 return cast_or_null<MDLocation>(getRawInlinedAt());
1116 /// \brief Get the scope where this is inlined.
1118 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1120 MDLocalScope *getInlinedAtScope() const {
1121 if (auto *IA = getInlinedAt())
1122 return IA->getInlinedAtScope();
1126 Metadata *getRawScope() const { return getOperand(0); }
1127 Metadata *getRawInlinedAt() const {
1128 if (getNumOperands() == 2)
1129 return getOperand(1);
1133 static bool classof(const Metadata *MD) {
1134 return MD->getMetadataID() == MDLocationKind;
1138 /// \brief Subprogram description.
1140 /// TODO: Remove DisplayName. It's always equal to Name.
1141 /// TODO: Split up flags.
1142 class MDSubprogram : public MDLocalScope {
1143 friend class LLVMContextImpl;
1144 friend class MDNode;
1148 unsigned Virtuality;
1149 unsigned VirtualIndex;
1155 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1156 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1157 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
1158 bool IsOptimized, ArrayRef<Metadata *> Ops)
1159 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1161 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
1162 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
1163 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
1166 static MDSubprogram *
1167 getImpl(LLVMContext &Context, MDScopeRef Scope, StringRef Name,
1168 StringRef LinkageName, MDFile *File, unsigned Line,
1169 MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1170 unsigned ScopeLine, MDTypeRef ContainingType, unsigned Virtuality,
1171 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1172 ConstantAsMetadata *Function, MDTemplateParameterArray TemplateParams,
1173 MDSubprogram *Declaration, MDLocalVariableArray Variables,
1174 StorageType Storage, bool ShouldCreate = true) {
1175 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1176 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1177 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1178 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1179 TemplateParams, Declaration, Variables, Storage,
1182 static MDSubprogram *
1183 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1184 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1185 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1186 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1187 unsigned Flags, bool IsOptimized, Metadata *Function,
1188 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1189 StorageType Storage, bool ShouldCreate = true);
1191 TempMDSubprogram cloneImpl() const {
1192 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1193 getFile(), getLine(), getType(), isLocalToUnit(),
1194 isDefinition(), getScopeLine(), getContainingType(),
1195 getVirtuality(), getVirtualIndex(), getFlags(),
1196 isOptimized(), getFunction(), getTemplateParams(),
1197 getDeclaration(), getVariables());
1201 DEFINE_MDNODE_GET(MDSubprogram,
1202 (MDScopeRef Scope, StringRef Name, StringRef LinkageName,
1203 MDFile *File, unsigned Line, MDSubroutineType *Type,
1204 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1205 MDTypeRef ContainingType, unsigned Virtuality,
1206 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1207 ConstantAsMetadata *Function = nullptr,
1208 MDTemplateParameterArray TemplateParams = nullptr,
1209 MDSubprogram *Declaration = nullptr,
1210 MDLocalVariableArray Variables = nullptr),
1211 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1212 IsDefinition, ScopeLine, ContainingType, Virtuality,
1213 VirtualIndex, Flags, IsOptimized, Function, TemplateParams,
1214 Declaration, Variables))
1217 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1218 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1219 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1220 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1221 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1222 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1223 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1224 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1225 Function, TemplateParams, Declaration, Variables))
1227 TempMDSubprogram clone() const { return cloneImpl(); }
1230 unsigned getLine() const { return Line; }
1231 unsigned getVirtuality() const { return Virtuality; }
1232 unsigned getVirtualIndex() const { return VirtualIndex; }
1233 unsigned getScopeLine() const { return ScopeLine; }
1234 unsigned getFlags() const { return Flags; }
1235 bool isLocalToUnit() const { return IsLocalToUnit; }
1236 bool isDefinition() const { return IsDefinition; }
1237 bool isOptimized() const { return IsOptimized; }
1239 unsigned isArtificial() const { return getFlags() & FlagArtificial; }
1240 bool isPrivate() const {
1241 return (getFlags() & FlagAccessibility) == FlagPrivate;
1243 bool isProtected() const {
1244 return (getFlags() & FlagAccessibility) == FlagProtected;
1246 bool isPublic() const {
1247 return (getFlags() & FlagAccessibility) == FlagPublic;
1249 bool isExplicit() const { return getFlags() & FlagExplicit; }
1250 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
1252 /// \brief Check if this is reference-qualified.
1254 /// Return true if this subprogram is a C++11 reference-qualified non-static
1255 /// member function (void foo() &).
1256 unsigned isLValueReference() const {
1257 return getFlags() & FlagLValueReference;
1260 /// \brief Check if this is rvalue-reference-qualified.
1262 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
1263 /// non-static member function (void foo() &&).
1264 unsigned isRValueReference() const {
1265 return getFlags() & FlagRValueReference;
1268 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
1270 StringRef getName() const { return getStringOperand(2); }
1271 StringRef getDisplayName() const { return getStringOperand(3); }
1272 StringRef getLinkageName() const { return getStringOperand(4); }
1274 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1275 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1277 MDSubroutineType *getType() const {
1278 return cast_or_null<MDSubroutineType>(getRawType());
1280 MDTypeRef getContainingType() const {
1281 return MDTypeRef(getRawContainingType());
1284 ConstantAsMetadata *getFunction() const {
1285 return cast_or_null<ConstantAsMetadata>(getRawFunction());
1287 MDTemplateParameterArray getTemplateParams() const {
1288 return cast_or_null<MDTuple>(getRawTemplateParams());
1290 MDSubprogram *getDeclaration() const {
1291 return cast_or_null<MDSubprogram>(getRawDeclaration());
1293 MDLocalVariableArray getVariables() const {
1294 return cast_or_null<MDTuple>(getRawVariables());
1297 Metadata *getRawScope() const { return getOperand(1); }
1298 Metadata *getRawType() const { return getOperand(5); }
1299 Metadata *getRawContainingType() const { return getOperand(6); }
1300 Metadata *getRawFunction() const { return getOperand(7); }
1301 Metadata *getRawTemplateParams() const { return getOperand(8); }
1302 Metadata *getRawDeclaration() const { return getOperand(9); }
1303 Metadata *getRawVariables() const { return getOperand(10); }
1305 /// \brief Replace the function.
1307 /// If \a isUniqued() and not \a isResolved(), this could node will be
1308 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1309 /// that's a problem.
1311 void replaceFunction(Function *F);
1312 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1313 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1316 static bool classof(const Metadata *MD) {
1317 return MD->getMetadataID() == MDSubprogramKind;
1321 class MDLexicalBlockBase : public MDLocalScope {
1323 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1324 ArrayRef<Metadata *> Ops)
1325 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1326 ~MDLexicalBlockBase() {}
1329 MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
1331 Metadata *getRawScope() const { return getOperand(1); }
1333 static bool classof(const Metadata *MD) {
1334 return MD->getMetadataID() == MDLexicalBlockKind ||
1335 MD->getMetadataID() == MDLexicalBlockFileKind;
1339 class MDLexicalBlock : public MDLexicalBlockBase {
1340 friend class LLVMContextImpl;
1341 friend class MDNode;
1346 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1347 unsigned Column, ArrayRef<Metadata *> Ops)
1348 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1350 ~MDLexicalBlock() {}
1352 static MDLexicalBlock *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1353 MDFile *File, unsigned Line, unsigned Column,
1354 StorageType Storage,
1355 bool ShouldCreate = true) {
1356 return getImpl(Context, static_cast<Metadata *>(Scope),
1357 static_cast<Metadata *>(File), Line, Column, Storage,
1361 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1362 Metadata *File, unsigned Line, unsigned Column,
1363 StorageType Storage, bool ShouldCreate = true);
1365 TempMDLexicalBlock cloneImpl() const {
1366 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1371 DEFINE_MDNODE_GET(MDLexicalBlock, (MDLocalScope * Scope, MDFile *File,
1372 unsigned Line, unsigned Column),
1373 (Scope, File, Line, Column))
1374 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1375 unsigned Line, unsigned Column),
1376 (Scope, File, Line, Column))
1378 TempMDLexicalBlock clone() const { return cloneImpl(); }
1380 unsigned getLine() const { return Line; }
1381 unsigned getColumn() const { return Column; }
1383 static bool classof(const Metadata *MD) {
1384 return MD->getMetadataID() == MDLexicalBlockKind;
1388 class MDLexicalBlockFile : public MDLexicalBlockBase {
1389 friend class LLVMContextImpl;
1390 friend class MDNode;
1392 unsigned Discriminator;
1394 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1395 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1396 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1397 Discriminator(Discriminator) {}
1398 ~MDLexicalBlockFile() {}
1400 static MDLexicalBlockFile *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1401 MDFile *File, unsigned Discriminator,
1402 StorageType Storage,
1403 bool ShouldCreate = true) {
1404 return getImpl(Context, static_cast<Metadata *>(Scope),
1405 static_cast<Metadata *>(File), Discriminator, Storage,
1409 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1410 Metadata *File, unsigned Discriminator,
1411 StorageType Storage,
1412 bool ShouldCreate = true);
1414 TempMDLexicalBlockFile cloneImpl() const {
1415 return getTemporary(getContext(), getScope(), getFile(),
1416 getDiscriminator());
1420 DEFINE_MDNODE_GET(MDLexicalBlockFile, (MDLocalScope * Scope, MDFile *File,
1421 unsigned Discriminator),
1422 (Scope, File, Discriminator))
1423 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1424 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1425 (Scope, File, Discriminator))
1427 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1429 unsigned getDiscriminator() const { return Discriminator; }
1431 static bool classof(const Metadata *MD) {
1432 return MD->getMetadataID() == MDLexicalBlockFileKind;
1436 class MDNamespace : public MDScope {
1437 friend class LLVMContextImpl;
1438 friend class MDNode;
1442 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1443 ArrayRef<Metadata *> Ops)
1444 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1449 static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
1450 MDFile *File, StringRef Name, unsigned Line,
1451 StorageType Storage, bool ShouldCreate = true) {
1452 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1453 Line, Storage, ShouldCreate);
1455 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1456 Metadata *File, MDString *Name, unsigned Line,
1457 StorageType Storage, bool ShouldCreate = true);
1459 TempMDNamespace cloneImpl() const {
1460 return getTemporary(getContext(), getScope(), getFile(), getName(),
1465 DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
1467 (Scope, File, Name, Line))
1468 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1469 MDString *Name, unsigned Line),
1470 (Scope, File, Name, Line))
1472 TempMDNamespace clone() const { return cloneImpl(); }
1474 unsigned getLine() const { return Line; }
1475 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1476 StringRef getName() const { return getStringOperand(2); }
1478 Metadata *getRawScope() const { return getOperand(1); }
1479 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1481 static bool classof(const Metadata *MD) {
1482 return MD->getMetadataID() == MDNamespaceKind;
1486 /// \brief Base class for template parameters.
1487 class MDTemplateParameter : public DebugNode {
1489 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1490 unsigned Tag, ArrayRef<Metadata *> Ops)
1491 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1492 ~MDTemplateParameter() {}
1495 StringRef getName() const { return getStringOperand(0); }
1496 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1498 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1499 Metadata *getRawType() const { return getOperand(1); }
1501 static bool classof(const Metadata *MD) {
1502 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1503 MD->getMetadataID() == MDTemplateValueParameterKind;
1507 class MDTemplateTypeParameter : public MDTemplateParameter {
1508 friend class LLVMContextImpl;
1509 friend class MDNode;
1511 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1512 ArrayRef<Metadata *> Ops)
1513 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1514 dwarf::DW_TAG_template_type_parameter, Ops) {}
1515 ~MDTemplateTypeParameter() {}
1517 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1518 MDTypeRef Type, StorageType Storage,
1519 bool ShouldCreate = true) {
1520 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1523 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1524 Metadata *Type, StorageType Storage,
1525 bool ShouldCreate = true);
1527 TempMDTemplateTypeParameter cloneImpl() const {
1528 return getTemporary(getContext(), getName(), getType());
1532 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, MDTypeRef Type),
1534 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1537 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1539 static bool classof(const Metadata *MD) {
1540 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1544 class MDTemplateValueParameter : public MDTemplateParameter {
1545 friend class LLVMContextImpl;
1546 friend class MDNode;
1548 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1549 unsigned Tag, ArrayRef<Metadata *> Ops)
1550 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1552 ~MDTemplateValueParameter() {}
1554 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1555 StringRef Name, MDTypeRef Type,
1556 Metadata *Value, StorageType Storage,
1557 bool ShouldCreate = true) {
1558 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1559 Value, Storage, ShouldCreate);
1561 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1562 MDString *Name, Metadata *Type,
1563 Metadata *Value, StorageType Storage,
1564 bool ShouldCreate = true);
1566 TempMDTemplateValueParameter cloneImpl() const {
1567 return getTemporary(getContext(), getTag(), getName(), getType(),
1572 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1573 MDTypeRef Type, Metadata *Value),
1574 (Tag, Name, Type, Value))
1575 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1576 Metadata *Type, Metadata *Value),
1577 (Tag, Name, Type, Value))
1579 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1581 Metadata *getValue() const { return getOperand(2); }
1583 static bool classof(const Metadata *MD) {
1584 return MD->getMetadataID() == MDTemplateValueParameterKind;
1588 /// \brief Base class for variables.
1590 /// TODO: Hardcode to DW_TAG_variable.
1591 class MDVariable : public DebugNode {
1595 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1596 unsigned Line, ArrayRef<Metadata *> Ops)
1597 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1601 unsigned getLine() const { return Line; }
1602 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1603 StringRef getName() const { return getStringOperand(1); }
1604 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1605 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1607 Metadata *getRawScope() const { return getOperand(0); }
1608 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1609 Metadata *getRawFile() const { return getOperand(2); }
1610 Metadata *getRawType() const { return getOperand(3); }
1612 static bool classof(const Metadata *MD) {
1613 return MD->getMetadataID() == MDLocalVariableKind ||
1614 MD->getMetadataID() == MDGlobalVariableKind;
1618 /// \brief Global variables.
1620 /// TODO: Remove DisplayName. It's always equal to Name.
1621 class MDGlobalVariable : public MDVariable {
1622 friend class LLVMContextImpl;
1623 friend class MDNode;
1628 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1629 bool IsLocalToUnit, bool IsDefinition,
1630 ArrayRef<Metadata *> Ops)
1631 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1633 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1634 ~MDGlobalVariable() {}
1636 static MDGlobalVariable *
1637 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1638 StringRef LinkageName, MDFile *File, unsigned Line, MDTypeRef Type,
1639 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1640 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1641 bool ShouldCreate = true) {
1642 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1643 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1644 IsLocalToUnit, IsDefinition, Variable,
1645 StaticDataMemberDeclaration, Storage, ShouldCreate);
1647 static MDGlobalVariable *
1648 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1649 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1650 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1651 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1652 bool ShouldCreate = true);
1654 TempMDGlobalVariable cloneImpl() const {
1655 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1656 getFile(), getLine(), getType(), isLocalToUnit(),
1657 isDefinition(), getVariable(),
1658 getStaticDataMemberDeclaration());
1662 DEFINE_MDNODE_GET(MDGlobalVariable,
1663 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1664 MDFile *File, unsigned Line, MDTypeRef Type,
1665 bool IsLocalToUnit, bool IsDefinition,
1666 ConstantAsMetadata *Variable,
1667 MDDerivedType *StaticDataMemberDeclaration),
1668 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1669 IsDefinition, Variable, StaticDataMemberDeclaration))
1670 DEFINE_MDNODE_GET(MDGlobalVariable,
1671 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1672 Metadata *File, unsigned Line, Metadata *Type,
1673 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1674 Metadata *StaticDataMemberDeclaration),
1675 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1676 IsDefinition, Variable, StaticDataMemberDeclaration))
1678 TempMDGlobalVariable clone() const { return cloneImpl(); }
1680 bool isLocalToUnit() const { return IsLocalToUnit; }
1681 bool isDefinition() const { return IsDefinition; }
1682 StringRef getDisplayName() const { return getStringOperand(4); }
1683 StringRef getLinkageName() const { return getStringOperand(5); }
1684 ConstantAsMetadata *getVariable() const {
1685 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1687 MDDerivedType *getStaticDataMemberDeclaration() const {
1688 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1691 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1692 Metadata *getRawVariable() const { return getOperand(6); }
1693 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1695 static bool classof(const Metadata *MD) {
1696 return MD->getMetadataID() == MDGlobalVariableKind;
1700 /// \brief Local variable.
1702 /// TODO: Split between arguments and otherwise.
1703 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1704 /// TODO: Split up flags.
1705 class MDLocalVariable : public MDVariable {
1706 friend class LLVMContextImpl;
1707 friend class MDNode;
1712 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1713 unsigned Line, unsigned Arg, unsigned Flags,
1714 ArrayRef<Metadata *> Ops)
1715 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1717 ~MDLocalVariable() {}
1719 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1720 MDScope *Scope, StringRef Name, MDFile *File,
1721 unsigned Line, MDTypeRef Type, unsigned Arg,
1722 unsigned Flags, MDLocation *InlinedAt,
1723 StorageType Storage,
1724 bool ShouldCreate = true) {
1725 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1726 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1729 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1730 Metadata *Scope, MDString *Name,
1731 Metadata *File, unsigned Line, Metadata *Type,
1732 unsigned Arg, unsigned Flags,
1733 Metadata *InlinedAt, StorageType Storage,
1734 bool ShouldCreate = true);
1736 TempMDLocalVariable cloneImpl() const {
1737 return getTemporary(getContext(), getTag(), getScope(), getName(),
1738 getFile(), getLine(), getType(), getArg(), getFlags(),
1743 DEFINE_MDNODE_GET(MDLocalVariable,
1744 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1745 MDFile *File, unsigned Line, MDTypeRef Type, unsigned Arg,
1746 unsigned Flags, MDLocation *InlinedAt = nullptr),
1747 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1748 DEFINE_MDNODE_GET(MDLocalVariable,
1749 (unsigned Tag, Metadata *Scope, MDString *Name,
1750 Metadata *File, unsigned Line, Metadata *Type,
1751 unsigned Arg, unsigned Flags,
1752 Metadata *InlinedAt = nullptr),
1753 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1755 TempMDLocalVariable clone() const { return cloneImpl(); }
1757 /// \brief Get the local scope for this variable.
1759 /// Variables must be defined in a local scope.
1760 MDLocalScope *getScope() const {
1761 return cast<MDLocalScope>(MDVariable::getScope());
1764 unsigned getArg() const { return Arg; }
1765 unsigned getFlags() const { return Flags; }
1766 MDLocation *getInlinedAt() const {
1767 return cast_or_null<MDLocation>(getRawInlinedAt());
1770 Metadata *getRawInlinedAt() const { return getOperand(4); }
1772 bool isArtificial() const { return getFlags() & FlagArtificial; }
1773 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
1775 /// \brief Check that a location is valid for this variable.
1777 /// Check that \c DL has the same inlined-at location as this variable,
1778 /// making them valid for the same \a DbgInfoIntrinsic.
1779 bool isValidLocationForIntrinsic(const MDLocation *DL) const {
1780 return getInlinedAt() == (DL ? DL->getInlinedAt() : nullptr);
1783 /// \brief Get an inlined version of this variable.
1785 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1786 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1787 if (InlinedAt == getInlinedAt())
1788 return const_cast<MDLocalVariable *>(this);
1789 auto Temp = clone();
1790 Temp->replaceOperandWith(4, InlinedAt);
1791 return replaceWithUniqued(std::move(Temp));
1793 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1795 static bool classof(const Metadata *MD) {
1796 return MD->getMetadataID() == MDLocalVariableKind;
1800 /// \brief DWARF expression.
1802 /// TODO: Co-allocate the expression elements.
1803 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1805 class MDExpression : public MDNode {
1806 friend class LLVMContextImpl;
1807 friend class MDNode;
1809 std::vector<uint64_t> Elements;
1811 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1812 : MDNode(C, MDExpressionKind, Storage, None),
1813 Elements(Elements.begin(), Elements.end()) {}
1816 static MDExpression *getImpl(LLVMContext &Context,
1817 ArrayRef<uint64_t> Elements, StorageType Storage,
1818 bool ShouldCreate = true);
1820 TempMDExpression cloneImpl() const {
1821 return getTemporary(getContext(), getElements());
1825 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1827 TempMDExpression clone() const { return cloneImpl(); }
1829 ArrayRef<uint64_t> getElements() const { return Elements; }
1831 unsigned getNumElements() const { return Elements.size(); }
1832 uint64_t getElement(unsigned I) const {
1833 assert(I < Elements.size() && "Index out of range");
1837 /// \brief Return whether this is a piece of an aggregate variable.
1838 bool isBitPiece() const;
1840 /// \brief Return the offset of this piece in bits.
1841 uint64_t getBitPieceOffset() const;
1843 /// \brief Return the size of this piece in bits.
1844 uint64_t getBitPieceSize() const;
1846 typedef ArrayRef<uint64_t>::iterator element_iterator;
1847 element_iterator elements_begin() const { return getElements().begin(); }
1848 element_iterator elements_end() const { return getElements().end(); }
1850 /// \brief A lightweight wrapper around an expression operand.
1852 /// TODO: Store arguments directly and change \a MDExpression to store a
1858 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1860 const uint64_t *get() const { return Op; }
1862 /// \brief Get the operand code.
1863 uint64_t getOp() const { return *Op; }
1865 /// \brief Get an argument to the operand.
1867 /// Never returns the operand itself.
1868 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1870 unsigned getNumArgs() const { return getSize() - 1; }
1872 /// \brief Return the size of the operand.
1874 /// Return the number of elements in the operand (1 + args).
1875 unsigned getSize() const;
1878 /// \brief An iterator for expression operands.
1879 class expr_op_iterator
1880 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1884 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1886 element_iterator getBase() const { return Op.get(); }
1887 const ExprOperand &operator*() const { return Op; }
1888 const ExprOperand *operator->() const { return &Op; }
1890 expr_op_iterator &operator++() {
1894 expr_op_iterator operator++(int) {
1895 expr_op_iterator T(*this);
1900 /// \brief Get the next iterator.
1902 /// \a std::next() doesn't work because this is technically an
1903 /// input_iterator, but it's a perfectly valid operation. This is an
1904 /// accessor to provide the same functionality.
1905 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
1907 bool operator==(const expr_op_iterator &X) const {
1908 return getBase() == X.getBase();
1910 bool operator!=(const expr_op_iterator &X) const {
1911 return getBase() != X.getBase();
1915 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1918 /// \brief Visit the elements via ExprOperand wrappers.
1920 /// These range iterators visit elements through \a ExprOperand wrappers.
1921 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1924 /// \pre \a isValid() gives \c true.
1926 expr_op_iterator expr_op_begin() const {
1927 return expr_op_iterator(elements_begin());
1929 expr_op_iterator expr_op_end() const {
1930 return expr_op_iterator(elements_end());
1934 bool isValid() const;
1936 static bool classof(const Metadata *MD) {
1937 return MD->getMetadataID() == MDExpressionKind;
1941 class MDObjCProperty : public DebugNode {
1942 friend class LLVMContextImpl;
1943 friend class MDNode;
1946 unsigned Attributes;
1948 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1949 unsigned Attributes, ArrayRef<Metadata *> Ops)
1950 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1952 Line(Line), Attributes(Attributes) {}
1953 ~MDObjCProperty() {}
1955 static MDObjCProperty *
1956 getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
1957 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1958 MDType *Type, StorageType Storage, bool ShouldCreate = true) {
1959 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1960 getCanonicalMDString(Context, GetterName),
1961 getCanonicalMDString(Context, SetterName), Attributes, Type,
1962 Storage, ShouldCreate);
1964 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1965 Metadata *File, unsigned Line,
1966 MDString *GetterName, MDString *SetterName,
1967 unsigned Attributes, Metadata *Type,
1968 StorageType Storage, bool ShouldCreate = true);
1970 TempMDObjCProperty cloneImpl() const {
1971 return getTemporary(getContext(), getName(), getFile(), getLine(),
1972 getGetterName(), getSetterName(), getAttributes(),
1977 DEFINE_MDNODE_GET(MDObjCProperty,
1978 (StringRef Name, MDFile *File, unsigned Line,
1979 StringRef GetterName, StringRef SetterName,
1980 unsigned Attributes, MDType *Type),
1981 (Name, File, Line, GetterName, SetterName, Attributes,
1983 DEFINE_MDNODE_GET(MDObjCProperty,
1984 (MDString * Name, Metadata *File, unsigned Line,
1985 MDString *GetterName, MDString *SetterName,
1986 unsigned Attributes, Metadata *Type),
1987 (Name, File, Line, GetterName, SetterName, Attributes,
1990 TempMDObjCProperty clone() const { return cloneImpl(); }
1992 unsigned getLine() const { return Line; }
1993 unsigned getAttributes() const { return Attributes; }
1994 StringRef getName() const { return getStringOperand(0); }
1995 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1996 StringRef getGetterName() const { return getStringOperand(2); }
1997 StringRef getSetterName() const { return getStringOperand(3); }
1998 MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
2000 MDString *getRawName() const { return getOperandAs<MDString>(0); }
2001 Metadata *getRawFile() const { return getOperand(1); }
2002 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
2003 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
2004 Metadata *getRawType() const { return getOperand(4); }
2006 static bool classof(const Metadata *MD) {
2007 return MD->getMetadataID() == MDObjCPropertyKind;
2011 class MDImportedEntity : public DebugNode {
2012 friend class LLVMContextImpl;
2013 friend class MDNode;
2017 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
2018 unsigned Line, ArrayRef<Metadata *> Ops)
2019 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
2020 ~MDImportedEntity() {}
2022 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2023 MDScope *Scope, Metadata *Entity,
2024 unsigned Line, StringRef Name,
2025 StorageType Storage,
2026 bool ShouldCreate = true) {
2027 return getImpl(Context, Tag, Scope, Entity, Line,
2028 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
2030 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2031 Metadata *Scope, Metadata *Entity,
2032 unsigned Line, MDString *Name,
2033 StorageType Storage,
2034 bool ShouldCreate = true);
2036 TempMDImportedEntity cloneImpl() const {
2037 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
2038 getLine(), getName());
2042 DEFINE_MDNODE_GET(MDImportedEntity,
2043 (unsigned Tag, MDScope *Scope, Metadata *Entity,
2044 unsigned Line, StringRef Name = ""),
2045 (Tag, Scope, Entity, Line, Name))
2046 DEFINE_MDNODE_GET(MDImportedEntity,
2047 (unsigned Tag, Metadata *Scope, Metadata *Entity,
2048 unsigned Line, MDString *Name),
2049 (Tag, Scope, Entity, Line, Name))
2051 TempMDImportedEntity clone() const { return cloneImpl(); }
2053 unsigned getLine() const { return Line; }
2054 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
2055 Metadata *getEntity() const { return getRawEntity(); }
2056 StringRef getName() const { return getStringOperand(2); }
2058 Metadata *getRawScope() const { return getOperand(0); }
2059 Metadata *getRawEntity() const { return getOperand(1); }
2060 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2062 static bool classof(const Metadata *MD) {
2063 return MD->getMetadataID() == MDImportedEntityKind;
2067 } // end namespace llvm
2069 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
2070 #undef DEFINE_MDNODE_GET_UNPACK
2071 #undef DEFINE_MDNODE_GET