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) {}
101 explicit operator bool() const { return get(); }
102 explicit operator MDTuple *() const { return get(); }
104 MDTuple *get() const { return const_cast<MDTuple *>(N); }
105 MDTuple *operator->() const { return get(); }
106 MDTuple &operator*() const { return *get(); }
108 // FIXME: Fix callers and remove condition on N.
109 unsigned size() const { return N ? N->getNumOperands() : 0u; }
110 MDTypeRef operator[](unsigned I) const { return MDTypeRef(N->getOperand(I)); }
112 class iterator : std::iterator<std::input_iterator_tag, MDTypeRef,
113 std::ptrdiff_t, void, MDTypeRef> {
114 MDNode::op_iterator I = nullptr;
117 iterator() = default;
118 explicit iterator(MDNode::op_iterator I) : I(I) {}
119 MDTypeRef operator*() const { return MDTypeRef(*I); }
120 iterator &operator++() {
124 iterator operator++(int) {
125 iterator Temp(*this);
129 bool operator==(const iterator &X) const { return I == X.I; }
130 bool operator!=(const iterator &X) const { return I != X.I; }
133 // FIXME: Fix callers and remove condition on N.
134 iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
135 iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
138 /// \brief Tagged DWARF-like metadata node.
140 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
141 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
142 /// potentially used for non-DWARF output.
143 class DebugNode : public MDNode {
144 friend class LLVMContextImpl;
148 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
149 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
150 : MDNode(C, ID, Storage, Ops1, Ops2) {
151 assert(Tag < 1u << 16);
152 SubclassData16 = Tag;
156 template <class Ty> Ty *getOperandAs(unsigned I) const {
157 return cast_or_null<Ty>(getOperand(I));
160 StringRef getStringOperand(unsigned I) const {
161 if (auto *S = getOperandAs<MDString>(I))
162 return S->getString();
166 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
169 return MDString::get(Context, S);
173 unsigned getTag() const { return SubclassData16; }
175 /// \brief Debug info flags.
177 /// The three accessibility flags are mutually exclusive and rolled together
178 /// in the first two bits.
180 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
181 #include "llvm/IR/DebugInfoFlags.def"
182 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
185 static unsigned getFlag(StringRef Flag);
186 static const char *getFlagString(unsigned Flag);
188 /// \brief Split up a flags bitfield.
190 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
191 /// any remaining (unrecognized) bits.
192 static unsigned splitFlags(unsigned Flags,
193 SmallVectorImpl<unsigned> &SplitFlags);
195 DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
197 static bool classof(const Metadata *MD) {
198 switch (MD->getMetadataID()) {
201 case GenericDebugNodeKind:
203 case MDEnumeratorKind:
204 case MDBasicTypeKind:
205 case MDDerivedTypeKind:
206 case MDCompositeTypeKind:
207 case MDSubroutineTypeKind:
209 case MDCompileUnitKind:
210 case MDSubprogramKind:
211 case MDLexicalBlockKind:
212 case MDLexicalBlockFileKind:
213 case MDNamespaceKind:
214 case MDTemplateTypeParameterKind:
215 case MDTemplateValueParameterKind:
216 case MDGlobalVariableKind:
217 case MDLocalVariableKind:
218 case MDObjCPropertyKind:
219 case MDImportedEntityKind:
226 struct simplify_type<const TypedDebugNodeRef<T>> {
227 typedef Metadata *SimpleType;
228 static SimpleType getSimplifiedValue(const TypedDebugNodeRef<T> &MD) {
234 struct simplify_type<TypedDebugNodeRef<T>>
235 : simplify_type<const TypedDebugNodeRef<T>> {};
237 /// \brief Generic tagged DWARF-like metadata node.
239 /// An un-specialized DWARF-like metadata node. The first operand is a
240 /// (possibly empty) null-separated \a MDString header that contains arbitrary
241 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
242 /// to other metadata.
243 class GenericDebugNode : public DebugNode {
244 friend class LLVMContextImpl;
247 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
248 unsigned Tag, ArrayRef<Metadata *> Ops1,
249 ArrayRef<Metadata *> Ops2)
250 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
253 ~GenericDebugNode() { dropAllReferences(); }
255 void setHash(unsigned Hash) { SubclassData32 = Hash; }
256 void recalculateHash();
258 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
260 ArrayRef<Metadata *> DwarfOps,
262 bool ShouldCreate = true) {
263 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
264 DwarfOps, Storage, ShouldCreate);
267 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
269 ArrayRef<Metadata *> DwarfOps,
271 bool ShouldCreate = true);
273 TempGenericDebugNode cloneImpl() const {
275 getContext(), getTag(), getHeader(),
276 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
280 unsigned getHash() const { return SubclassData32; }
282 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
283 ArrayRef<Metadata *> DwarfOps),
284 (Tag, Header, DwarfOps))
285 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
286 ArrayRef<Metadata *> DwarfOps),
287 (Tag, Header, DwarfOps))
289 /// \brief Return a (temporary) clone of this.
290 TempGenericDebugNode clone() const { return cloneImpl(); }
292 unsigned getTag() const { return SubclassData16; }
293 StringRef getHeader() const { return getStringOperand(0); }
295 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
296 op_iterator dwarf_op_end() const { return op_end(); }
297 op_range dwarf_operands() const {
298 return op_range(dwarf_op_begin(), dwarf_op_end());
301 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
302 const MDOperand &getDwarfOperand(unsigned I) const {
303 return getOperand(I + 1);
305 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
306 replaceOperandWith(I + 1, New);
309 static bool classof(const Metadata *MD) {
310 return MD->getMetadataID() == GenericDebugNodeKind;
314 /// \brief Array subrange.
316 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
318 class MDSubrange : public DebugNode {
319 friend class LLVMContextImpl;
325 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count,
327 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
329 Count(Count), LowerBound(LowerBound) {}
332 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count,
333 int64_t LowerBound, StorageType Storage,
334 bool ShouldCreate = true);
336 TempMDSubrange cloneImpl() const {
337 return getTemporary(getContext(), getCount(), getLowerBound());
341 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t LowerBound = 0),
344 TempMDSubrange clone() const { return cloneImpl(); }
346 int64_t getLowerBound() const { return LowerBound; }
347 int64_t getCount() const { return Count; }
349 static bool classof(const Metadata *MD) {
350 return MD->getMetadataID() == MDSubrangeKind;
354 /// \brief Enumeration value.
356 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
357 /// longer creates a type cycle.
358 class MDEnumerator : public DebugNode {
359 friend class LLVMContextImpl;
364 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
365 ArrayRef<Metadata *> Ops)
366 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
370 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
371 StringRef Name, StorageType Storage,
372 bool ShouldCreate = true) {
373 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
376 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
377 MDString *Name, StorageType Storage,
378 bool ShouldCreate = true);
380 TempMDEnumerator cloneImpl() const {
381 return getTemporary(getContext(), getValue(), getName());
385 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
387 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
390 TempMDEnumerator clone() const { return cloneImpl(); }
392 int64_t getValue() const { return Value; }
393 StringRef getName() const { return getStringOperand(0); }
395 MDString *getRawName() const { return getOperandAs<MDString>(0); }
397 static bool classof(const Metadata *MD) {
398 return MD->getMetadataID() == MDEnumeratorKind;
402 /// \brief Base class for scope-like contexts.
404 /// Base class for lexical scopes and types (which are also declaration
407 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
408 class MDScope : public DebugNode {
410 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
411 ArrayRef<Metadata *> Ops)
412 : DebugNode(C, ID, Storage, Tag, Ops) {}
416 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
418 /// \brief Return the raw underlying file.
420 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
421 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
422 /// this. Otherwise, return the first operand, which is where all other
423 /// subclasses store their file pointer.
424 Metadata *getRawFile() const {
425 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
426 : static_cast<Metadata *>(getOperand(0));
429 MDScopeRef getRef() const { return MDScopeRef::get(this); }
431 static bool classof(const Metadata *MD) {
432 switch (MD->getMetadataID()) {
435 case MDBasicTypeKind:
436 case MDDerivedTypeKind:
437 case MDCompositeTypeKind:
438 case MDSubroutineTypeKind:
440 case MDCompileUnitKind:
441 case MDSubprogramKind:
442 case MDLexicalBlockKind:
443 case MDLexicalBlockFileKind:
444 case MDNamespaceKind:
452 /// TODO: Merge with directory/file node (including users).
453 /// TODO: Canonicalize paths on creation.
454 class MDFile : public MDScope {
455 friend class LLVMContextImpl;
458 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
459 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
462 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
463 StringRef Directory, StorageType Storage,
464 bool ShouldCreate = true) {
465 return getImpl(Context, getCanonicalMDString(Context, Filename),
466 getCanonicalMDString(Context, Directory), Storage,
469 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
470 MDString *Directory, StorageType Storage,
471 bool ShouldCreate = true);
473 TempMDFile cloneImpl() const {
474 return getTemporary(getContext(), getFilename(), getDirectory());
478 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
479 (Filename, Directory))
480 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
481 (Filename, Directory))
483 TempMDFile clone() const { return cloneImpl(); }
485 StringRef getFilename() const { return getStringOperand(0); }
486 StringRef getDirectory() const { return getStringOperand(1); }
488 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
489 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
491 static bool classof(const Metadata *MD) {
492 return MD->getMetadataID() == MDFileKind;
496 /// \brief Base class for types.
498 /// TODO: Remove the hardcoded name and context, since many types don't use
500 /// TODO: Split up flags.
501 class MDType : public MDScope {
505 uint64_t AlignInBits;
506 uint64_t OffsetInBits;
509 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
510 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
511 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
512 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
513 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
514 OffsetInBits(OffsetInBits) {}
518 TempMDType clone() const {
519 return TempMDType(cast<MDType>(MDNode::clone().release()));
522 unsigned getLine() const { return Line; }
523 uint64_t getSizeInBits() const { return SizeInBits; }
524 uint64_t getAlignInBits() const { return AlignInBits; }
525 uint64_t getOffsetInBits() const { return OffsetInBits; }
526 unsigned getFlags() const { return Flags; }
528 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
529 StringRef getName() const { return getStringOperand(2); }
532 Metadata *getRawScope() const { return getOperand(1); }
533 MDString *getRawName() const { return getOperandAs<MDString>(2); }
535 void setFlags(unsigned NewFlags) {
536 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
540 bool isPrivate() const {
541 return (getFlags() & FlagAccessibility) == FlagPrivate;
543 bool isProtected() const {
544 return (getFlags() & FlagAccessibility) == FlagProtected;
546 bool isPublic() const {
547 return (getFlags() & FlagAccessibility) == FlagPublic;
549 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
550 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
551 bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; }
552 bool isVirtual() const { return getFlags() & FlagVirtual; }
553 bool isArtificial() const { return getFlags() & FlagArtificial; }
554 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
555 bool isObjcClassComplete() const {
556 return getFlags() & FlagObjcClassComplete;
558 bool isVector() const { return getFlags() & FlagVector; }
559 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
560 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
561 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
563 MDTypeRef getRef() const { return MDTypeRef::get(this); }
565 static bool classof(const Metadata *MD) {
566 switch (MD->getMetadataID()) {
569 case MDBasicTypeKind:
570 case MDDerivedTypeKind:
571 case MDCompositeTypeKind:
572 case MDSubroutineTypeKind:
578 /// \brief Basic type.
580 /// TODO: Split out DW_TAG_unspecified_type.
581 /// TODO: Drop unused accessors.
582 class MDBasicType : public MDType {
583 friend class LLVMContextImpl;
588 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
589 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
590 ArrayRef<Metadata *> Ops)
591 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
593 Encoding(Encoding) {}
596 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
597 StringRef Name, uint64_t SizeInBits,
598 uint64_t AlignInBits, unsigned Encoding,
599 StorageType Storage, bool ShouldCreate = true) {
600 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
601 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
603 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
604 MDString *Name, uint64_t SizeInBits,
605 uint64_t AlignInBits, unsigned Encoding,
606 StorageType Storage, bool ShouldCreate = true);
608 TempMDBasicType cloneImpl() const {
609 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
610 getAlignInBits(), getEncoding());
614 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
615 (Tag, Name, 0, 0, 0))
616 DEFINE_MDNODE_GET(MDBasicType,
617 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
618 uint64_t AlignInBits, unsigned Encoding),
619 (Tag, Name, SizeInBits, AlignInBits, Encoding))
620 DEFINE_MDNODE_GET(MDBasicType,
621 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
622 uint64_t AlignInBits, unsigned Encoding),
623 (Tag, Name, SizeInBits, AlignInBits, Encoding))
625 TempMDBasicType clone() const { return cloneImpl(); }
627 unsigned getEncoding() const { return Encoding; }
629 static bool classof(const Metadata *MD) {
630 return MD->getMetadataID() == MDBasicTypeKind;
634 /// \brief Base class for MDDerivedType and MDCompositeType.
636 /// TODO: Delete; they're not really related.
637 class MDDerivedTypeBase : public MDType {
639 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
640 unsigned Tag, unsigned Line, uint64_t SizeInBits,
641 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
642 ArrayRef<Metadata *> Ops)
643 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
645 ~MDDerivedTypeBase() {}
648 MDTypeRef getBaseType() const { return MDTypeRef(getRawBaseType()); }
649 Metadata *getRawBaseType() const { return getOperand(3); }
651 static bool classof(const Metadata *MD) {
652 return MD->getMetadataID() == MDDerivedTypeKind ||
653 MD->getMetadataID() == MDCompositeTypeKind ||
654 MD->getMetadataID() == MDSubroutineTypeKind;
658 /// \brief Derived types.
660 /// This includes qualified types, pointers, references, friends, typedefs, and
663 /// TODO: Split out members (inheritance, fields, methods, etc.).
664 class MDDerivedType : public MDDerivedTypeBase {
665 friend class LLVMContextImpl;
668 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
669 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
670 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
671 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
672 AlignInBits, OffsetInBits, Flags, Ops) {}
675 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
676 StringRef Name, MDFile *File, unsigned Line,
677 MDScopeRef Scope, MDTypeRef BaseType,
678 uint64_t SizeInBits, uint64_t AlignInBits,
679 uint64_t OffsetInBits, unsigned Flags,
680 Metadata *ExtraData, StorageType Storage,
681 bool ShouldCreate = true) {
682 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
683 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
684 Flags, ExtraData, Storage, ShouldCreate);
686 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
687 MDString *Name, Metadata *File, unsigned Line,
688 Metadata *Scope, Metadata *BaseType,
689 uint64_t SizeInBits, uint64_t AlignInBits,
690 uint64_t OffsetInBits, unsigned Flags,
691 Metadata *ExtraData, StorageType Storage,
692 bool ShouldCreate = true);
694 TempMDDerivedType cloneImpl() const {
695 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
696 getScope(), getBaseType(), getSizeInBits(),
697 getAlignInBits(), getOffsetInBits(), getFlags(),
702 DEFINE_MDNODE_GET(MDDerivedType,
703 (unsigned Tag, MDString *Name, Metadata *File,
704 unsigned Line, Metadata *Scope, Metadata *BaseType,
705 uint64_t SizeInBits, uint64_t AlignInBits,
706 uint64_t OffsetInBits, unsigned Flags,
707 Metadata *ExtraData = nullptr),
708 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
709 AlignInBits, OffsetInBits, Flags, ExtraData))
710 DEFINE_MDNODE_GET(MDDerivedType,
711 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
712 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
713 uint64_t AlignInBits, uint64_t OffsetInBits,
714 unsigned Flags, Metadata *ExtraData = nullptr),
715 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
716 AlignInBits, OffsetInBits, Flags, ExtraData))
718 TempMDDerivedType clone() const { return cloneImpl(); }
720 /// \brief Get extra data associated with this derived type.
722 /// Class type for pointer-to-members, objective-c property node for ivars,
723 /// or global constant wrapper for static members.
725 /// TODO: Separate out types that need this extra operand: pointer-to-member
726 /// types and member fields (static members and ivars).
727 Metadata *getExtraData() const { return getRawExtraData(); }
728 Metadata *getRawExtraData() const { return getOperand(4); }
730 static bool classof(const Metadata *MD) {
731 return MD->getMetadataID() == MDDerivedTypeKind;
735 /// \brief Base class for MDCompositeType and MDSubroutineType.
737 /// TODO: Delete; they're not really related.
738 class MDCompositeTypeBase : public MDDerivedTypeBase {
739 unsigned RuntimeLang;
742 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
743 unsigned Tag, unsigned Line, unsigned RuntimeLang,
744 uint64_t SizeInBits, uint64_t AlignInBits,
745 uint64_t OffsetInBits, unsigned Flags,
746 ArrayRef<Metadata *> Ops)
747 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
748 OffsetInBits, Flags, Ops),
749 RuntimeLang(RuntimeLang) {}
750 ~MDCompositeTypeBase() {}
753 DebugNodeArray getElements() const {
754 return cast_or_null<MDTuple>(getRawElements());
756 MDTypeRef getVTableHolder() const { return MDTypeRef(getRawVTableHolder()); }
757 MDTemplateParameterArray getTemplateParams() const {
758 return cast_or_null<MDTuple>(getRawTemplateParams());
760 StringRef getIdentifier() const { return getStringOperand(7); }
761 unsigned getRuntimeLang() const { return RuntimeLang; }
763 Metadata *getRawElements() const { return getOperand(4); }
764 Metadata *getRawVTableHolder() const { return getOperand(5); }
765 Metadata *getRawTemplateParams() const { return getOperand(6); }
766 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
768 /// \brief Replace operands.
770 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
771 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
772 /// of its movement if necessary.
774 void replaceElements(DebugNodeArray Elements) {
776 for (DebugNode *Op : getElements())
777 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
778 "Lost a member during member list replacement");
780 replaceOperandWith(4, Elements.get());
782 void replaceVTableHolder(MDTypeRef VTableHolder) {
783 replaceOperandWith(5, VTableHolder);
785 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
786 replaceOperandWith(6, TemplateParams.get());
790 static bool classof(const Metadata *MD) {
791 return MD->getMetadataID() == MDCompositeTypeKind ||
792 MD->getMetadataID() == MDSubroutineTypeKind;
796 /// \brief Composite types.
798 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
799 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
800 class MDCompositeType : public MDCompositeTypeBase {
801 friend class LLVMContextImpl;
804 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
805 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
806 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
807 ArrayRef<Metadata *> Ops)
808 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
809 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
811 ~MDCompositeType() {}
813 static MDCompositeType *
814 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
815 unsigned Line, MDScopeRef Scope, MDTypeRef BaseType,
816 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
817 uint64_t Flags, DebugNodeArray Elements, unsigned RuntimeLang,
818 MDTypeRef VTableHolder, MDTemplateParameterArray TemplateParams,
819 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
821 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
822 BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
823 RuntimeLang, VTableHolder, TemplateParams.get(),
824 getCanonicalMDString(Context, Identifier), Storage, ShouldCreate);
826 static MDCompositeType *
827 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
828 unsigned Line, Metadata *Scope, Metadata *BaseType,
829 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
830 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
831 Metadata *VTableHolder, Metadata *TemplateParams,
832 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
834 TempMDCompositeType cloneImpl() const {
835 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
836 getScope(), getBaseType(), getSizeInBits(),
837 getAlignInBits(), getOffsetInBits(), getFlags(),
838 getElements(), getRuntimeLang(), getVTableHolder(),
839 getTemplateParams(), getIdentifier());
843 DEFINE_MDNODE_GET(MDCompositeType,
844 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
845 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
846 uint64_t AlignInBits, uint64_t OffsetInBits,
847 unsigned Flags, DebugNodeArray Elements,
848 unsigned RuntimeLang, MDTypeRef VTableHolder,
849 MDTemplateParameterArray TemplateParams = nullptr,
850 StringRef Identifier = ""),
851 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
852 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
853 VTableHolder, TemplateParams, Identifier))
854 DEFINE_MDNODE_GET(MDCompositeType,
855 (unsigned Tag, MDString *Name, Metadata *File,
856 unsigned Line, Metadata *Scope, Metadata *BaseType,
857 uint64_t SizeInBits, uint64_t AlignInBits,
858 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
859 unsigned RuntimeLang, Metadata *VTableHolder,
860 Metadata *TemplateParams = nullptr,
861 MDString *Identifier = nullptr),
862 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
863 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
864 VTableHolder, TemplateParams, Identifier))
866 TempMDCompositeType clone() const { return cloneImpl(); }
868 static bool classof(const Metadata *MD) {
869 return MD->getMetadataID() == MDCompositeTypeKind;
873 template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) {
875 if (auto *Composite = dyn_cast<MDCompositeType>(N))
876 if (auto *S = Composite->getRawIdentifier())
877 return TypedDebugNodeRef<T>(S);
878 return TypedDebugNodeRef<T>(N);
881 /// \brief Type array for a subprogram.
883 /// TODO: Detach from CompositeType, and fold the array of types in directly
885 class MDSubroutineType : public MDCompositeTypeBase {
886 friend class LLVMContextImpl;
889 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
890 ArrayRef<Metadata *> Ops)
891 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
892 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
894 ~MDSubroutineType() {}
896 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
897 MDTypeRefArray TypeArray,
899 bool ShouldCreate = true) {
900 return getImpl(Context, Flags, TypeArray.get(), Storage, ShouldCreate);
902 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
903 Metadata *TypeArray, StorageType Storage,
904 bool ShouldCreate = true);
906 TempMDSubroutineType cloneImpl() const {
907 return getTemporary(getContext(), getFlags(), getTypeArray());
911 DEFINE_MDNODE_GET(MDSubroutineType,
912 (unsigned Flags, MDTypeRefArray TypeArray),
914 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
917 TempMDSubroutineType clone() const { return cloneImpl(); }
919 MDTypeRefArray getTypeArray() const {
920 return cast_or_null<MDTuple>(getRawTypeArray());
922 Metadata *getRawTypeArray() const { return getRawElements(); }
924 static bool classof(const Metadata *MD) {
925 return MD->getMetadataID() == MDSubroutineTypeKind;
929 /// \brief Compile unit.
930 class MDCompileUnit : public MDScope {
931 friend class LLVMContextImpl;
934 unsigned SourceLanguage;
936 unsigned RuntimeVersion;
937 unsigned EmissionKind;
939 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
940 bool IsOptimized, unsigned RuntimeVersion,
941 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
942 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
943 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
944 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
947 static MDCompileUnit *
948 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
949 StringRef Producer, bool IsOptimized, StringRef Flags,
950 unsigned RuntimeVersion, StringRef SplitDebugFilename,
951 unsigned EmissionKind, MDCompositeTypeArray EnumTypes,
952 MDTypeArray RetainedTypes, MDSubprogramArray Subprograms,
953 MDGlobalVariableArray GlobalVariables,
954 MDImportedEntityArray ImportedEntities, StorageType Storage,
955 bool ShouldCreate = true) {
957 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
958 IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
959 getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
960 EnumTypes.get(), RetainedTypes.get(), Subprograms.get(),
961 GlobalVariables.get(), ImportedEntities.get(), Storage, ShouldCreate);
963 static MDCompileUnit *
964 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
965 MDString *Producer, bool IsOptimized, MDString *Flags,
966 unsigned RuntimeVersion, MDString *SplitDebugFilename,
967 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
968 Metadata *Subprograms, Metadata *GlobalVariables,
969 Metadata *ImportedEntities, StorageType Storage,
970 bool ShouldCreate = true);
972 TempMDCompileUnit cloneImpl() const {
974 getContext(), getSourceLanguage(), getFile(), getProducer(),
975 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
976 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
977 getGlobalVariables(), getImportedEntities());
981 DEFINE_MDNODE_GET(MDCompileUnit,
982 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
983 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
984 StringRef SplitDebugFilename, unsigned EmissionKind,
985 MDCompositeTypeArray EnumTypes, MDTypeArray RetainedTypes,
986 MDSubprogramArray Subprograms,
987 MDGlobalVariableArray GlobalVariables,
988 MDImportedEntityArray ImportedEntities),
989 (SourceLanguage, File, Producer, IsOptimized, Flags,
990 RuntimeVersion, SplitDebugFilename, EmissionKind,
991 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
993 DEFINE_MDNODE_GET(MDCompileUnit,
994 (unsigned SourceLanguage, Metadata *File,
995 MDString *Producer, bool IsOptimized, MDString *Flags,
996 unsigned RuntimeVersion, MDString *SplitDebugFilename,
997 unsigned EmissionKind, Metadata *EnumTypes,
998 Metadata *RetainedTypes, Metadata *Subprograms,
999 Metadata *GlobalVariables, Metadata *ImportedEntities),
1000 (SourceLanguage, File, Producer, IsOptimized, Flags,
1001 RuntimeVersion, SplitDebugFilename, EmissionKind,
1002 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
1005 TempMDCompileUnit clone() const { return cloneImpl(); }
1007 unsigned getSourceLanguage() const { return SourceLanguage; }
1008 bool isOptimized() const { return IsOptimized; }
1009 unsigned getRuntimeVersion() const { return RuntimeVersion; }
1010 unsigned getEmissionKind() const { return EmissionKind; }
1011 StringRef getProducer() const { return getStringOperand(1); }
1012 StringRef getFlags() const { return getStringOperand(2); }
1013 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
1014 MDCompositeTypeArray getEnumTypes() const {
1015 return cast_or_null<MDTuple>(getRawEnumTypes());
1017 MDTypeArray getRetainedTypes() const {
1018 return cast_or_null<MDTuple>(getRawRetainedTypes());
1020 MDSubprogramArray getSubprograms() const {
1021 return cast_or_null<MDTuple>(getRawSubprograms());
1023 MDGlobalVariableArray getGlobalVariables() const {
1024 return cast_or_null<MDTuple>(getRawGlobalVariables());
1026 MDImportedEntityArray getImportedEntities() const {
1027 return cast_or_null<MDTuple>(getRawImportedEntities());
1030 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1031 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1032 MDString *getRawSplitDebugFilename() const {
1033 return getOperandAs<MDString>(3);
1035 Metadata *getRawEnumTypes() const { return getOperand(4); }
1036 Metadata *getRawRetainedTypes() const { return getOperand(5); }
1037 Metadata *getRawSubprograms() const { return getOperand(6); }
1038 Metadata *getRawGlobalVariables() const { return getOperand(7); }
1039 Metadata *getRawImportedEntities() const { return getOperand(8); }
1041 /// \brief Replace arrays.
1043 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1044 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1045 /// MDCompileUnit should be fairly rare.
1047 void replaceSubprograms(MDSubprogramArray N) {
1048 replaceOperandWith(6, N.get());
1050 void replaceGlobalVariables(MDGlobalVariableArray N) {
1051 replaceOperandWith(7, N.get());
1055 static bool classof(const Metadata *MD) {
1056 return MD->getMetadataID() == MDCompileUnitKind;
1060 /// \brief A scope for locals.
1062 /// A legal scope for lexical blocks, local variables, and debug info
1063 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
1064 /// MDLexicalBlockFile.
1065 class MDLocalScope : public MDScope {
1067 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1068 ArrayRef<Metadata *> Ops)
1069 : MDScope(C, ID, Storage, Tag, Ops) {}
1073 /// \brief Get the subprogram for this scope.
1075 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
1077 MDSubprogram *getSubprogram() const;
1079 static bool classof(const Metadata *MD) {
1080 return MD->getMetadataID() == MDSubprogramKind ||
1081 MD->getMetadataID() == MDLexicalBlockKind ||
1082 MD->getMetadataID() == MDLexicalBlockFileKind;
1086 /// \brief Debug location.
1088 /// A debug location in source code, used for debug info and otherwise.
1089 class MDLocation : public MDNode {
1090 friend class LLVMContextImpl;
1091 friend class MDNode;
1093 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
1094 unsigned Column, ArrayRef<Metadata *> MDs);
1095 ~MDLocation() { dropAllReferences(); }
1097 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1098 unsigned Column, Metadata *Scope,
1099 Metadata *InlinedAt, StorageType Storage,
1100 bool ShouldCreate = true);
1101 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1102 unsigned Column, MDLocalScope *Scope,
1103 MDLocation *InlinedAt, StorageType Storage,
1104 bool ShouldCreate = true) {
1105 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1106 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1109 TempMDLocation cloneImpl() const {
1110 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
1114 // Disallow replacing operands.
1115 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1118 DEFINE_MDNODE_GET(MDLocation,
1119 (unsigned Line, unsigned Column, Metadata *Scope,
1120 Metadata *InlinedAt = nullptr),
1121 (Line, Column, Scope, InlinedAt))
1122 DEFINE_MDNODE_GET(MDLocation,
1123 (unsigned Line, unsigned Column, MDLocalScope *Scope,
1124 MDLocation *InlinedAt = nullptr),
1125 (Line, Column, Scope, InlinedAt))
1127 /// \brief Return a (temporary) clone of this.
1128 TempMDLocation clone() const { return cloneImpl(); }
1130 unsigned getLine() const { return SubclassData32; }
1131 unsigned getColumn() const { return SubclassData16; }
1132 MDLocalScope *getScope() const {
1133 return cast<MDLocalScope>(getRawScope());
1135 MDLocation *getInlinedAt() const {
1136 return cast_or_null<MDLocation>(getRawInlinedAt());
1139 /// \brief Get the scope where this is inlined.
1141 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1143 MDLocalScope *getInlinedAtScope() const {
1144 if (auto *IA = getInlinedAt())
1145 return IA->getInlinedAtScope();
1149 Metadata *getRawScope() const { return getOperand(0); }
1150 Metadata *getRawInlinedAt() const {
1151 if (getNumOperands() == 2)
1152 return getOperand(1);
1156 static bool classof(const Metadata *MD) {
1157 return MD->getMetadataID() == MDLocationKind;
1161 /// \brief Subprogram description.
1163 /// TODO: Remove DisplayName. It's always equal to Name.
1164 /// TODO: Split up flags.
1165 class MDSubprogram : public MDLocalScope {
1166 friend class LLVMContextImpl;
1167 friend class MDNode;
1171 unsigned Virtuality;
1172 unsigned VirtualIndex;
1178 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1179 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1180 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
1181 bool IsOptimized, ArrayRef<Metadata *> Ops)
1182 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1184 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
1185 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
1186 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
1189 static MDSubprogram *
1190 getImpl(LLVMContext &Context, MDScopeRef Scope, StringRef Name,
1191 StringRef LinkageName, MDFile *File, unsigned Line,
1192 MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1193 unsigned ScopeLine, MDTypeRef ContainingType, unsigned Virtuality,
1194 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1195 ConstantAsMetadata *Function, MDTemplateParameterArray TemplateParams,
1196 MDSubprogram *Declaration, MDLocalVariableArray Variables,
1197 StorageType Storage, bool ShouldCreate = true) {
1198 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1199 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1200 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1201 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1202 TemplateParams.get(), Declaration, Variables.get(), Storage,
1205 static MDSubprogram *
1206 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1207 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1208 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1209 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1210 unsigned Flags, bool IsOptimized, Metadata *Function,
1211 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1212 StorageType Storage, bool ShouldCreate = true);
1214 TempMDSubprogram cloneImpl() const {
1215 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1216 getFile(), getLine(), getType(), isLocalToUnit(),
1217 isDefinition(), getScopeLine(), getContainingType(),
1218 getVirtuality(), getVirtualIndex(), getFlags(),
1219 isOptimized(), getFunction(), getTemplateParams(),
1220 getDeclaration(), getVariables());
1224 DEFINE_MDNODE_GET(MDSubprogram,
1225 (MDScopeRef Scope, StringRef Name, StringRef LinkageName,
1226 MDFile *File, unsigned Line, MDSubroutineType *Type,
1227 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1228 MDTypeRef ContainingType, unsigned Virtuality,
1229 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1230 ConstantAsMetadata *Function = nullptr,
1231 MDTemplateParameterArray TemplateParams = nullptr,
1232 MDSubprogram *Declaration = nullptr,
1233 MDLocalVariableArray Variables = nullptr),
1234 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1235 IsDefinition, ScopeLine, ContainingType, Virtuality,
1236 VirtualIndex, Flags, IsOptimized, Function, TemplateParams,
1237 Declaration, Variables))
1240 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1241 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1242 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1243 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1244 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1245 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1246 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1247 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1248 Function, TemplateParams, Declaration, Variables))
1250 TempMDSubprogram clone() const { return cloneImpl(); }
1253 unsigned getLine() const { return Line; }
1254 unsigned getVirtuality() const { return Virtuality; }
1255 unsigned getVirtualIndex() const { return VirtualIndex; }
1256 unsigned getScopeLine() const { return ScopeLine; }
1257 unsigned getFlags() const { return Flags; }
1258 bool isLocalToUnit() const { return IsLocalToUnit; }
1259 bool isDefinition() const { return IsDefinition; }
1260 bool isOptimized() const { return IsOptimized; }
1262 unsigned isArtificial() const { return getFlags() & FlagArtificial; }
1263 bool isPrivate() const {
1264 return (getFlags() & FlagAccessibility) == FlagPrivate;
1266 bool isProtected() const {
1267 return (getFlags() & FlagAccessibility) == FlagProtected;
1269 bool isPublic() const {
1270 return (getFlags() & FlagAccessibility) == FlagPublic;
1272 bool isExplicit() const { return getFlags() & FlagExplicit; }
1273 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
1275 /// \brief Check if this is reference-qualified.
1277 /// Return true if this subprogram is a C++11 reference-qualified non-static
1278 /// member function (void foo() &).
1279 unsigned isLValueReference() const {
1280 return getFlags() & FlagLValueReference;
1283 /// \brief Check if this is rvalue-reference-qualified.
1285 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
1286 /// non-static member function (void foo() &&).
1287 unsigned isRValueReference() const {
1288 return getFlags() & FlagRValueReference;
1291 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
1293 StringRef getName() const { return getStringOperand(2); }
1294 StringRef getDisplayName() const { return getStringOperand(3); }
1295 StringRef getLinkageName() const { return getStringOperand(4); }
1297 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1298 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1300 MDSubroutineType *getType() const {
1301 return cast_or_null<MDSubroutineType>(getRawType());
1303 MDTypeRef getContainingType() const {
1304 return MDTypeRef(getRawContainingType());
1307 ConstantAsMetadata *getFunction() const {
1308 return cast_or_null<ConstantAsMetadata>(getRawFunction());
1310 MDTemplateParameterArray getTemplateParams() const {
1311 return cast_or_null<MDTuple>(getRawTemplateParams());
1313 MDSubprogram *getDeclaration() const {
1314 return cast_or_null<MDSubprogram>(getRawDeclaration());
1316 MDLocalVariableArray getVariables() const {
1317 return cast_or_null<MDTuple>(getRawVariables());
1320 Metadata *getRawScope() const { return getOperand(1); }
1321 Metadata *getRawType() const { return getOperand(5); }
1322 Metadata *getRawContainingType() const { return getOperand(6); }
1323 Metadata *getRawFunction() const { return getOperand(7); }
1324 Metadata *getRawTemplateParams() const { return getOperand(8); }
1325 Metadata *getRawDeclaration() const { return getOperand(9); }
1326 Metadata *getRawVariables() const { return getOperand(10); }
1328 /// \brief Replace the function.
1330 /// If \a isUniqued() and not \a isResolved(), this could node will be
1331 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1332 /// that's a problem.
1334 void replaceFunction(Function *F);
1335 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1336 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1339 static bool classof(const Metadata *MD) {
1340 return MD->getMetadataID() == MDSubprogramKind;
1344 class MDLexicalBlockBase : public MDLocalScope {
1346 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1347 ArrayRef<Metadata *> Ops)
1348 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1349 ~MDLexicalBlockBase() {}
1352 MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
1354 Metadata *getRawScope() const { return getOperand(1); }
1356 static bool classof(const Metadata *MD) {
1357 return MD->getMetadataID() == MDLexicalBlockKind ||
1358 MD->getMetadataID() == MDLexicalBlockFileKind;
1362 class MDLexicalBlock : public MDLexicalBlockBase {
1363 friend class LLVMContextImpl;
1364 friend class MDNode;
1369 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1370 unsigned Column, ArrayRef<Metadata *> Ops)
1371 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1373 ~MDLexicalBlock() {}
1375 static MDLexicalBlock *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1376 MDFile *File, unsigned Line, unsigned Column,
1377 StorageType Storage,
1378 bool ShouldCreate = true) {
1379 return getImpl(Context, static_cast<Metadata *>(Scope),
1380 static_cast<Metadata *>(File), Line, Column, Storage,
1384 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1385 Metadata *File, unsigned Line, unsigned Column,
1386 StorageType Storage, bool ShouldCreate = true);
1388 TempMDLexicalBlock cloneImpl() const {
1389 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1394 DEFINE_MDNODE_GET(MDLexicalBlock, (MDLocalScope * Scope, MDFile *File,
1395 unsigned Line, unsigned Column),
1396 (Scope, File, Line, Column))
1397 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1398 unsigned Line, unsigned Column),
1399 (Scope, File, Line, Column))
1401 TempMDLexicalBlock clone() const { return cloneImpl(); }
1403 unsigned getLine() const { return Line; }
1404 unsigned getColumn() const { return Column; }
1406 static bool classof(const Metadata *MD) {
1407 return MD->getMetadataID() == MDLexicalBlockKind;
1411 class MDLexicalBlockFile : public MDLexicalBlockBase {
1412 friend class LLVMContextImpl;
1413 friend class MDNode;
1415 unsigned Discriminator;
1417 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1418 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1419 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1420 Discriminator(Discriminator) {}
1421 ~MDLexicalBlockFile() {}
1423 static MDLexicalBlockFile *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1424 MDFile *File, unsigned Discriminator,
1425 StorageType Storage,
1426 bool ShouldCreate = true) {
1427 return getImpl(Context, static_cast<Metadata *>(Scope),
1428 static_cast<Metadata *>(File), Discriminator, Storage,
1432 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1433 Metadata *File, unsigned Discriminator,
1434 StorageType Storage,
1435 bool ShouldCreate = true);
1437 TempMDLexicalBlockFile cloneImpl() const {
1438 return getTemporary(getContext(), getScope(), getFile(),
1439 getDiscriminator());
1443 DEFINE_MDNODE_GET(MDLexicalBlockFile, (MDLocalScope * Scope, MDFile *File,
1444 unsigned Discriminator),
1445 (Scope, File, Discriminator))
1446 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1447 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1448 (Scope, File, Discriminator))
1450 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1452 unsigned getDiscriminator() const { return Discriminator; }
1454 static bool classof(const Metadata *MD) {
1455 return MD->getMetadataID() == MDLexicalBlockFileKind;
1459 class MDNamespace : public MDScope {
1460 friend class LLVMContextImpl;
1461 friend class MDNode;
1465 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1466 ArrayRef<Metadata *> Ops)
1467 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1472 static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
1473 MDFile *File, StringRef Name, unsigned Line,
1474 StorageType Storage, bool ShouldCreate = true) {
1475 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1476 Line, Storage, ShouldCreate);
1478 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1479 Metadata *File, MDString *Name, unsigned Line,
1480 StorageType Storage, bool ShouldCreate = true);
1482 TempMDNamespace cloneImpl() const {
1483 return getTemporary(getContext(), getScope(), getFile(), getName(),
1488 DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
1490 (Scope, File, Name, Line))
1491 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1492 MDString *Name, unsigned Line),
1493 (Scope, File, Name, Line))
1495 TempMDNamespace clone() const { return cloneImpl(); }
1497 unsigned getLine() const { return Line; }
1498 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1499 StringRef getName() const { return getStringOperand(2); }
1501 Metadata *getRawScope() const { return getOperand(1); }
1502 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1504 static bool classof(const Metadata *MD) {
1505 return MD->getMetadataID() == MDNamespaceKind;
1509 /// \brief Base class for template parameters.
1510 class MDTemplateParameter : public DebugNode {
1512 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1513 unsigned Tag, ArrayRef<Metadata *> Ops)
1514 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1515 ~MDTemplateParameter() {}
1518 StringRef getName() const { return getStringOperand(0); }
1519 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1521 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1522 Metadata *getRawType() const { return getOperand(1); }
1524 static bool classof(const Metadata *MD) {
1525 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1526 MD->getMetadataID() == MDTemplateValueParameterKind;
1530 class MDTemplateTypeParameter : public MDTemplateParameter {
1531 friend class LLVMContextImpl;
1532 friend class MDNode;
1534 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1535 ArrayRef<Metadata *> Ops)
1536 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1537 dwarf::DW_TAG_template_type_parameter, Ops) {}
1538 ~MDTemplateTypeParameter() {}
1540 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1541 MDTypeRef Type, StorageType Storage,
1542 bool ShouldCreate = true) {
1543 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1546 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1547 Metadata *Type, StorageType Storage,
1548 bool ShouldCreate = true);
1550 TempMDTemplateTypeParameter cloneImpl() const {
1551 return getTemporary(getContext(), getName(), getType());
1555 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, MDTypeRef Type),
1557 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1560 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1562 static bool classof(const Metadata *MD) {
1563 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1567 class MDTemplateValueParameter : public MDTemplateParameter {
1568 friend class LLVMContextImpl;
1569 friend class MDNode;
1571 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1572 unsigned Tag, ArrayRef<Metadata *> Ops)
1573 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1575 ~MDTemplateValueParameter() {}
1577 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1578 StringRef Name, MDTypeRef Type,
1579 Metadata *Value, StorageType Storage,
1580 bool ShouldCreate = true) {
1581 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1582 Value, Storage, ShouldCreate);
1584 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1585 MDString *Name, Metadata *Type,
1586 Metadata *Value, StorageType Storage,
1587 bool ShouldCreate = true);
1589 TempMDTemplateValueParameter cloneImpl() const {
1590 return getTemporary(getContext(), getTag(), getName(), getType(),
1595 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1596 MDTypeRef Type, Metadata *Value),
1597 (Tag, Name, Type, Value))
1598 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1599 Metadata *Type, Metadata *Value),
1600 (Tag, Name, Type, Value))
1602 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1604 Metadata *getValue() const { return getOperand(2); }
1606 static bool classof(const Metadata *MD) {
1607 return MD->getMetadataID() == MDTemplateValueParameterKind;
1611 /// \brief Base class for variables.
1613 /// TODO: Hardcode to DW_TAG_variable.
1614 class MDVariable : public DebugNode {
1618 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1619 unsigned Line, ArrayRef<Metadata *> Ops)
1620 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1624 unsigned getLine() const { return Line; }
1625 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1626 StringRef getName() const { return getStringOperand(1); }
1627 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1628 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1630 Metadata *getRawScope() const { return getOperand(0); }
1631 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1632 Metadata *getRawFile() const { return getOperand(2); }
1633 Metadata *getRawType() const { return getOperand(3); }
1635 static bool classof(const Metadata *MD) {
1636 return MD->getMetadataID() == MDLocalVariableKind ||
1637 MD->getMetadataID() == MDGlobalVariableKind;
1641 /// \brief Global variables.
1643 /// TODO: Remove DisplayName. It's always equal to Name.
1644 class MDGlobalVariable : public MDVariable {
1645 friend class LLVMContextImpl;
1646 friend class MDNode;
1651 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1652 bool IsLocalToUnit, bool IsDefinition,
1653 ArrayRef<Metadata *> Ops)
1654 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1656 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1657 ~MDGlobalVariable() {}
1659 static MDGlobalVariable *
1660 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1661 StringRef LinkageName, MDFile *File, unsigned Line, MDTypeRef Type,
1662 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1663 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1664 bool ShouldCreate = true) {
1665 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1666 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1667 IsLocalToUnit, IsDefinition, Variable,
1668 StaticDataMemberDeclaration, Storage, ShouldCreate);
1670 static MDGlobalVariable *
1671 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1672 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1673 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1674 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1675 bool ShouldCreate = true);
1677 TempMDGlobalVariable cloneImpl() const {
1678 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1679 getFile(), getLine(), getType(), isLocalToUnit(),
1680 isDefinition(), getVariable(),
1681 getStaticDataMemberDeclaration());
1685 DEFINE_MDNODE_GET(MDGlobalVariable,
1686 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1687 MDFile *File, unsigned Line, MDTypeRef Type,
1688 bool IsLocalToUnit, bool IsDefinition,
1689 ConstantAsMetadata *Variable,
1690 MDDerivedType *StaticDataMemberDeclaration),
1691 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1692 IsDefinition, Variable, StaticDataMemberDeclaration))
1693 DEFINE_MDNODE_GET(MDGlobalVariable,
1694 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1695 Metadata *File, unsigned Line, Metadata *Type,
1696 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1697 Metadata *StaticDataMemberDeclaration),
1698 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1699 IsDefinition, Variable, StaticDataMemberDeclaration))
1701 TempMDGlobalVariable clone() const { return cloneImpl(); }
1703 bool isLocalToUnit() const { return IsLocalToUnit; }
1704 bool isDefinition() const { return IsDefinition; }
1705 StringRef getDisplayName() const { return getStringOperand(4); }
1706 StringRef getLinkageName() const { return getStringOperand(5); }
1707 ConstantAsMetadata *getVariable() const {
1708 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1710 MDDerivedType *getStaticDataMemberDeclaration() const {
1711 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1714 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1715 Metadata *getRawVariable() const { return getOperand(6); }
1716 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1718 static bool classof(const Metadata *MD) {
1719 return MD->getMetadataID() == MDGlobalVariableKind;
1723 /// \brief Local variable.
1725 /// TODO: Split between arguments and otherwise.
1726 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1727 /// TODO: Split up flags.
1728 class MDLocalVariable : public MDVariable {
1729 friend class LLVMContextImpl;
1730 friend class MDNode;
1735 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1736 unsigned Line, unsigned Arg, unsigned Flags,
1737 ArrayRef<Metadata *> Ops)
1738 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1740 ~MDLocalVariable() {}
1742 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1743 MDScope *Scope, StringRef Name, MDFile *File,
1744 unsigned Line, MDTypeRef Type, unsigned Arg,
1745 unsigned Flags, MDLocation *InlinedAt,
1746 StorageType Storage,
1747 bool ShouldCreate = true) {
1748 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1749 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1752 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1753 Metadata *Scope, MDString *Name,
1754 Metadata *File, unsigned Line, Metadata *Type,
1755 unsigned Arg, unsigned Flags,
1756 Metadata *InlinedAt, StorageType Storage,
1757 bool ShouldCreate = true);
1759 TempMDLocalVariable cloneImpl() const {
1760 return getTemporary(getContext(), getTag(), getScope(), getName(),
1761 getFile(), getLine(), getType(), getArg(), getFlags(),
1766 DEFINE_MDNODE_GET(MDLocalVariable,
1767 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1768 MDFile *File, unsigned Line, MDTypeRef Type, unsigned Arg,
1769 unsigned Flags, MDLocation *InlinedAt = nullptr),
1770 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1771 DEFINE_MDNODE_GET(MDLocalVariable,
1772 (unsigned Tag, Metadata *Scope, MDString *Name,
1773 Metadata *File, unsigned Line, Metadata *Type,
1774 unsigned Arg, unsigned Flags,
1775 Metadata *InlinedAt = nullptr),
1776 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1778 TempMDLocalVariable clone() const { return cloneImpl(); }
1780 /// \brief Get the local scope for this variable.
1782 /// Variables must be defined in a local scope.
1783 MDLocalScope *getScope() const {
1784 return cast<MDLocalScope>(MDVariable::getScope());
1787 unsigned getArg() const { return Arg; }
1788 unsigned getFlags() const { return Flags; }
1789 MDLocation *getInlinedAt() const {
1790 return cast_or_null<MDLocation>(getRawInlinedAt());
1793 Metadata *getRawInlinedAt() const { return getOperand(4); }
1795 bool isArtificial() const { return getFlags() & FlagArtificial; }
1796 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
1798 /// \brief Check that a location is valid for this variable.
1800 /// Check that \c DL has the same inlined-at location as this variable,
1801 /// making them valid for the same \a DbgInfoIntrinsic.
1802 bool isValidLocationForIntrinsic(const MDLocation *DL) const {
1803 return getInlinedAt() == (DL ? DL->getInlinedAt() : nullptr);
1806 /// \brief Get an inlined version of this variable.
1808 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1809 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1810 if (InlinedAt == getInlinedAt())
1811 return const_cast<MDLocalVariable *>(this);
1812 auto Temp = clone();
1813 Temp->replaceOperandWith(4, InlinedAt);
1814 return replaceWithUniqued(std::move(Temp));
1816 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1818 static bool classof(const Metadata *MD) {
1819 return MD->getMetadataID() == MDLocalVariableKind;
1823 /// \brief DWARF expression.
1825 /// TODO: Co-allocate the expression elements.
1826 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1828 class MDExpression : public MDNode {
1829 friend class LLVMContextImpl;
1830 friend class MDNode;
1832 std::vector<uint64_t> Elements;
1834 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1835 : MDNode(C, MDExpressionKind, Storage, None),
1836 Elements(Elements.begin(), Elements.end()) {}
1839 static MDExpression *getImpl(LLVMContext &Context,
1840 ArrayRef<uint64_t> Elements, StorageType Storage,
1841 bool ShouldCreate = true);
1843 TempMDExpression cloneImpl() const {
1844 return getTemporary(getContext(), getElements());
1848 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1850 TempMDExpression clone() const { return cloneImpl(); }
1852 ArrayRef<uint64_t> getElements() const { return Elements; }
1854 unsigned getNumElements() const { return Elements.size(); }
1855 uint64_t getElement(unsigned I) const {
1856 assert(I < Elements.size() && "Index out of range");
1860 /// \brief Return whether this is a piece of an aggregate variable.
1861 bool isBitPiece() const;
1863 /// \brief Return the offset of this piece in bits.
1864 uint64_t getBitPieceOffset() const;
1866 /// \brief Return the size of this piece in bits.
1867 uint64_t getBitPieceSize() const;
1869 typedef ArrayRef<uint64_t>::iterator element_iterator;
1870 element_iterator elements_begin() const { return getElements().begin(); }
1871 element_iterator elements_end() const { return getElements().end(); }
1873 /// \brief A lightweight wrapper around an expression operand.
1875 /// TODO: Store arguments directly and change \a MDExpression to store a
1881 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1883 const uint64_t *get() const { return Op; }
1885 /// \brief Get the operand code.
1886 uint64_t getOp() const { return *Op; }
1888 /// \brief Get an argument to the operand.
1890 /// Never returns the operand itself.
1891 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1893 unsigned getNumArgs() const { return getSize() - 1; }
1895 /// \brief Return the size of the operand.
1897 /// Return the number of elements in the operand (1 + args).
1898 unsigned getSize() const;
1901 /// \brief An iterator for expression operands.
1902 class expr_op_iterator
1903 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1907 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1909 element_iterator getBase() const { return Op.get(); }
1910 const ExprOperand &operator*() const { return Op; }
1911 const ExprOperand *operator->() const { return &Op; }
1913 expr_op_iterator &operator++() {
1917 expr_op_iterator operator++(int) {
1918 expr_op_iterator T(*this);
1923 /// \brief Get the next iterator.
1925 /// \a std::next() doesn't work because this is technically an
1926 /// input_iterator, but it's a perfectly valid operation. This is an
1927 /// accessor to provide the same functionality.
1928 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
1930 bool operator==(const expr_op_iterator &X) const {
1931 return getBase() == X.getBase();
1933 bool operator!=(const expr_op_iterator &X) const {
1934 return getBase() != X.getBase();
1938 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1941 /// \brief Visit the elements via ExprOperand wrappers.
1943 /// These range iterators visit elements through \a ExprOperand wrappers.
1944 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1947 /// \pre \a isValid() gives \c true.
1949 expr_op_iterator expr_op_begin() const {
1950 return expr_op_iterator(elements_begin());
1952 expr_op_iterator expr_op_end() const {
1953 return expr_op_iterator(elements_end());
1957 bool isValid() const;
1959 static bool classof(const Metadata *MD) {
1960 return MD->getMetadataID() == MDExpressionKind;
1964 class MDObjCProperty : public DebugNode {
1965 friend class LLVMContextImpl;
1966 friend class MDNode;
1969 unsigned Attributes;
1971 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1972 unsigned Attributes, ArrayRef<Metadata *> Ops)
1973 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1975 Line(Line), Attributes(Attributes) {}
1976 ~MDObjCProperty() {}
1978 static MDObjCProperty *
1979 getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
1980 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1981 MDType *Type, StorageType Storage, bool ShouldCreate = true) {
1982 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1983 getCanonicalMDString(Context, GetterName),
1984 getCanonicalMDString(Context, SetterName), Attributes, Type,
1985 Storage, ShouldCreate);
1987 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1988 Metadata *File, unsigned Line,
1989 MDString *GetterName, MDString *SetterName,
1990 unsigned Attributes, Metadata *Type,
1991 StorageType Storage, bool ShouldCreate = true);
1993 TempMDObjCProperty cloneImpl() const {
1994 return getTemporary(getContext(), getName(), getFile(), getLine(),
1995 getGetterName(), getSetterName(), getAttributes(),
2000 DEFINE_MDNODE_GET(MDObjCProperty,
2001 (StringRef Name, MDFile *File, unsigned Line,
2002 StringRef GetterName, StringRef SetterName,
2003 unsigned Attributes, MDType *Type),
2004 (Name, File, Line, GetterName, SetterName, Attributes,
2006 DEFINE_MDNODE_GET(MDObjCProperty,
2007 (MDString * Name, Metadata *File, unsigned Line,
2008 MDString *GetterName, MDString *SetterName,
2009 unsigned Attributes, Metadata *Type),
2010 (Name, File, Line, GetterName, SetterName, Attributes,
2013 TempMDObjCProperty clone() const { return cloneImpl(); }
2015 unsigned getLine() const { return Line; }
2016 unsigned getAttributes() const { return Attributes; }
2017 StringRef getName() const { return getStringOperand(0); }
2018 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
2019 StringRef getGetterName() const { return getStringOperand(2); }
2020 StringRef getSetterName() const { return getStringOperand(3); }
2021 MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
2023 MDString *getRawName() const { return getOperandAs<MDString>(0); }
2024 Metadata *getRawFile() const { return getOperand(1); }
2025 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
2026 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
2027 Metadata *getRawType() const { return getOperand(4); }
2029 static bool classof(const Metadata *MD) {
2030 return MD->getMetadataID() == MDObjCPropertyKind;
2034 class MDImportedEntity : public DebugNode {
2035 friend class LLVMContextImpl;
2036 friend class MDNode;
2040 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
2041 unsigned Line, ArrayRef<Metadata *> Ops)
2042 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
2043 ~MDImportedEntity() {}
2045 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2046 MDScope *Scope, DebugNodeRef Entity,
2047 unsigned Line, StringRef Name,
2048 StorageType Storage,
2049 bool ShouldCreate = true) {
2050 return getImpl(Context, Tag, Scope, Entity, Line,
2051 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
2053 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2054 Metadata *Scope, Metadata *Entity,
2055 unsigned Line, MDString *Name,
2056 StorageType Storage,
2057 bool ShouldCreate = true);
2059 TempMDImportedEntity cloneImpl() const {
2060 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
2061 getLine(), getName());
2065 DEFINE_MDNODE_GET(MDImportedEntity,
2066 (unsigned Tag, MDScope *Scope, DebugNodeRef Entity,
2067 unsigned Line, StringRef Name = ""),
2068 (Tag, Scope, Entity, Line, Name))
2069 DEFINE_MDNODE_GET(MDImportedEntity,
2070 (unsigned Tag, Metadata *Scope, Metadata *Entity,
2071 unsigned Line, MDString *Name),
2072 (Tag, Scope, Entity, Line, Name))
2074 TempMDImportedEntity clone() const { return cloneImpl(); }
2076 unsigned getLine() const { return Line; }
2077 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
2078 DebugNodeRef getEntity() const { return DebugNodeRef(getRawEntity()); }
2079 StringRef getName() const { return getStringOperand(2); }
2081 Metadata *getRawScope() const { return getOperand(0); }
2082 Metadata *getRawEntity() const { return getOperand(1); }
2083 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2085 static bool classof(const Metadata *MD) {
2086 return MD->getMetadataID() == MDImportedEntityKind;
2090 } // end namespace llvm
2092 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
2093 #undef DEFINE_MDNODE_GET_UNPACK
2094 #undef DEFINE_MDNODE_GET