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() = default;
54 TypedDebugNodeRef(std::nullptr_t) {}
56 /// \brief Construct from a raw pointer.
57 explicit TypedDebugNodeRef(const Metadata *MD) : MD(MD) {
58 assert((!MD || isa<MDString>(MD) || isa<T>(MD)) && "Expected valid ref");
63 const TypedDebugNodeRef<U> &X,
64 typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
68 operator Metadata *() const { return const_cast<Metadata *>(MD); }
70 bool operator==(const TypedDebugNodeRef<T> &X) const { return MD == X.MD; };
71 bool operator!=(const TypedDebugNodeRef<T> &X) const { return MD != X.MD; };
73 /// \brief Create a reference.
75 /// Get a reference to \c N, using an \a MDString reference if available.
76 static TypedDebugNodeRef get(const T *N);
78 template <class MapTy> T *resolve(const MapTy &Map) const {
82 if (auto *Typed = dyn_cast<T>(MD))
83 return const_cast<T *>(Typed);
85 auto *S = cast<MDString>(MD);
87 assert(I != Map.end() && "Missing identifier in type map");
88 return cast<T>(I->second);
92 typedef TypedDebugNodeRef<DebugNode> DebugNodeRef;
93 typedef TypedDebugNodeRef<MDScope> MDScopeRef;
94 typedef TypedDebugNodeRef<MDType> MDTypeRef;
96 class MDTypeRefArray {
97 const MDTuple *N = nullptr;
100 MDTypeRefArray(const MDTuple *N) : N(N) {}
102 explicit operator bool() const { return get(); }
103 explicit operator MDTuple *() const { return get(); }
105 MDTuple *get() const { return const_cast<MDTuple *>(N); }
106 MDTuple *operator->() const { return get(); }
107 MDTuple &operator*() const { return *get(); }
109 // FIXME: Fix callers and remove condition on N.
110 unsigned size() const { return N ? N->getNumOperands() : 0u; }
111 MDTypeRef operator[](unsigned I) const { return MDTypeRef(N->getOperand(I)); }
113 class iterator : std::iterator<std::input_iterator_tag, MDTypeRef,
114 std::ptrdiff_t, void, MDTypeRef> {
115 MDNode::op_iterator I = nullptr;
118 iterator() = default;
119 explicit iterator(MDNode::op_iterator I) : I(I) {}
120 MDTypeRef operator*() const { return MDTypeRef(*I); }
121 iterator &operator++() {
125 iterator operator++(int) {
126 iterator Temp(*this);
130 bool operator==(const iterator &X) const { return I == X.I; }
131 bool operator!=(const iterator &X) const { return I != X.I; }
134 // FIXME: Fix callers and remove condition on N.
135 iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
136 iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
139 /// \brief Tagged DWARF-like metadata node.
141 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
142 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
143 /// potentially used for non-DWARF output.
144 class DebugNode : public MDNode {
145 friend class LLVMContextImpl;
149 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
150 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
151 : MDNode(C, ID, Storage, Ops1, Ops2) {
152 assert(Tag < 1u << 16);
153 SubclassData16 = Tag;
155 ~DebugNode() = default;
157 template <class Ty> Ty *getOperandAs(unsigned I) const {
158 return cast_or_null<Ty>(getOperand(I));
161 StringRef getStringOperand(unsigned I) const {
162 if (auto *S = getOperandAs<MDString>(I))
163 return S->getString();
167 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
170 return MDString::get(Context, S);
174 unsigned getTag() const { return SubclassData16; }
176 /// \brief Debug info flags.
178 /// The three accessibility flags are mutually exclusive and rolled together
179 /// in the first two bits.
181 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
182 #include "llvm/IR/DebugInfoFlags.def"
183 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
186 static unsigned getFlag(StringRef Flag);
187 static const char *getFlagString(unsigned Flag);
189 /// \brief Split up a flags bitfield.
191 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
192 /// any remaining (unrecognized) bits.
193 static unsigned splitFlags(unsigned Flags,
194 SmallVectorImpl<unsigned> &SplitFlags);
196 DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
198 static bool classof(const Metadata *MD) {
199 switch (MD->getMetadataID()) {
202 case GenericDebugNodeKind:
204 case MDEnumeratorKind:
205 case MDBasicTypeKind:
206 case MDDerivedTypeKind:
207 case MDCompositeTypeKind:
208 case MDSubroutineTypeKind:
210 case MDCompileUnitKind:
211 case MDSubprogramKind:
212 case MDLexicalBlockKind:
213 case MDLexicalBlockFileKind:
214 case MDNamespaceKind:
215 case MDTemplateTypeParameterKind:
216 case MDTemplateValueParameterKind:
217 case MDGlobalVariableKind:
218 case MDLocalVariableKind:
219 case MDObjCPropertyKind:
220 case MDImportedEntityKind:
227 struct simplify_type<const TypedDebugNodeRef<T>> {
228 typedef Metadata *SimpleType;
229 static SimpleType getSimplifiedValue(const TypedDebugNodeRef<T> &MD) {
235 struct simplify_type<TypedDebugNodeRef<T>>
236 : simplify_type<const TypedDebugNodeRef<T>> {};
238 /// \brief Generic tagged DWARF-like metadata node.
240 /// An un-specialized DWARF-like metadata node. The first operand is a
241 /// (possibly empty) null-separated \a MDString header that contains arbitrary
242 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
243 /// to other metadata.
244 class GenericDebugNode : public DebugNode {
245 friend class LLVMContextImpl;
248 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
249 unsigned Tag, ArrayRef<Metadata *> Ops1,
250 ArrayRef<Metadata *> Ops2)
251 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
254 ~GenericDebugNode() { dropAllReferences(); }
256 void setHash(unsigned Hash) { SubclassData32 = Hash; }
257 void recalculateHash();
259 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
261 ArrayRef<Metadata *> DwarfOps,
263 bool ShouldCreate = true) {
264 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
265 DwarfOps, Storage, ShouldCreate);
268 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
270 ArrayRef<Metadata *> DwarfOps,
272 bool ShouldCreate = true);
274 TempGenericDebugNode cloneImpl() const {
276 getContext(), getTag(), getHeader(),
277 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
281 unsigned getHash() const { return SubclassData32; }
283 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
284 ArrayRef<Metadata *> DwarfOps),
285 (Tag, Header, DwarfOps))
286 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
287 ArrayRef<Metadata *> DwarfOps),
288 (Tag, Header, DwarfOps))
290 /// \brief Return a (temporary) clone of this.
291 TempGenericDebugNode clone() const { return cloneImpl(); }
293 unsigned getTag() const { return SubclassData16; }
294 StringRef getHeader() const { return getStringOperand(0); }
296 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
297 op_iterator dwarf_op_end() const { return op_end(); }
298 op_range dwarf_operands() const {
299 return op_range(dwarf_op_begin(), dwarf_op_end());
302 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
303 const MDOperand &getDwarfOperand(unsigned I) const {
304 return getOperand(I + 1);
306 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
307 replaceOperandWith(I + 1, New);
310 static bool classof(const Metadata *MD) {
311 return MD->getMetadataID() == GenericDebugNodeKind;
315 /// \brief Array subrange.
317 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
319 class MDSubrange : public DebugNode {
320 friend class LLVMContextImpl;
326 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count,
328 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
330 Count(Count), LowerBound(LowerBound) {}
331 ~MDSubrange() = default;
333 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count,
334 int64_t LowerBound, StorageType Storage,
335 bool ShouldCreate = true);
337 TempMDSubrange cloneImpl() const {
338 return getTemporary(getContext(), getCount(), getLowerBound());
342 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t LowerBound = 0),
345 TempMDSubrange clone() const { return cloneImpl(); }
347 int64_t getLowerBound() const { return LowerBound; }
348 int64_t getCount() const { return Count; }
350 static bool classof(const Metadata *MD) {
351 return MD->getMetadataID() == MDSubrangeKind;
355 /// \brief Enumeration value.
357 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
358 /// longer creates a type cycle.
359 class MDEnumerator : public DebugNode {
360 friend class LLVMContextImpl;
365 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
366 ArrayRef<Metadata *> Ops)
367 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
369 ~MDEnumerator() = default;
371 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
372 StringRef Name, StorageType Storage,
373 bool ShouldCreate = true) {
374 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
377 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
378 MDString *Name, StorageType Storage,
379 bool ShouldCreate = true);
381 TempMDEnumerator cloneImpl() const {
382 return getTemporary(getContext(), getValue(), getName());
386 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
388 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
391 TempMDEnumerator clone() const { return cloneImpl(); }
393 int64_t getValue() const { return Value; }
394 StringRef getName() const { return getStringOperand(0); }
396 MDString *getRawName() const { return getOperandAs<MDString>(0); }
398 static bool classof(const Metadata *MD) {
399 return MD->getMetadataID() == MDEnumeratorKind;
403 /// \brief Base class for scope-like contexts.
405 /// Base class for lexical scopes and types (which are also declaration
408 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
409 class MDScope : public DebugNode {
411 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
412 ArrayRef<Metadata *> Ops)
413 : DebugNode(C, ID, Storage, Tag, Ops) {}
414 ~MDScope() = default;
417 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
419 inline StringRef getFilename() const;
420 inline StringRef getDirectory() const;
422 StringRef getName() const;
423 MDScopeRef getScope() const;
425 /// \brief Return the raw underlying file.
427 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
428 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
429 /// this. Otherwise, return the first operand, which is where all other
430 /// subclasses store their file pointer.
431 Metadata *getRawFile() const {
432 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
433 : static_cast<Metadata *>(getOperand(0));
436 MDScopeRef getRef() const { return MDScopeRef::get(this); }
438 static bool classof(const Metadata *MD) {
439 switch (MD->getMetadataID()) {
442 case MDBasicTypeKind:
443 case MDDerivedTypeKind:
444 case MDCompositeTypeKind:
445 case MDSubroutineTypeKind:
447 case MDCompileUnitKind:
448 case MDSubprogramKind:
449 case MDLexicalBlockKind:
450 case MDLexicalBlockFileKind:
451 case MDNamespaceKind:
459 /// TODO: Merge with directory/file node (including users).
460 /// TODO: Canonicalize paths on creation.
461 class MDFile : public MDScope {
462 friend class LLVMContextImpl;
465 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
466 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
469 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
470 StringRef Directory, StorageType Storage,
471 bool ShouldCreate = true) {
472 return getImpl(Context, getCanonicalMDString(Context, Filename),
473 getCanonicalMDString(Context, Directory), Storage,
476 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
477 MDString *Directory, StorageType Storage,
478 bool ShouldCreate = true);
480 TempMDFile cloneImpl() const {
481 return getTemporary(getContext(), getFilename(), getDirectory());
485 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
486 (Filename, Directory))
487 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
488 (Filename, Directory))
490 TempMDFile clone() const { return cloneImpl(); }
492 StringRef getFilename() const { return getStringOperand(0); }
493 StringRef getDirectory() const { return getStringOperand(1); }
495 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
496 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
498 static bool classof(const Metadata *MD) {
499 return MD->getMetadataID() == MDFileKind;
503 StringRef MDScope::getFilename() const {
504 if (auto *F = getFile())
505 return F->getFilename();
509 StringRef MDScope::getDirectory() const {
510 if (auto *F = getFile())
511 return F->getDirectory();
515 /// \brief Base class for types.
517 /// TODO: Remove the hardcoded name and context, since many types don't use
519 /// TODO: Split up flags.
520 class MDType : public MDScope {
524 uint64_t AlignInBits;
525 uint64_t OffsetInBits;
528 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
529 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
530 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
531 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
532 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
533 OffsetInBits(OffsetInBits) {}
537 TempMDType clone() const {
538 return TempMDType(cast<MDType>(MDNode::clone().release()));
541 unsigned getLine() const { return Line; }
542 uint64_t getSizeInBits() const { return SizeInBits; }
543 uint64_t getAlignInBits() const { return AlignInBits; }
544 uint64_t getOffsetInBits() const { return OffsetInBits; }
545 unsigned getFlags() const { return Flags; }
547 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
548 StringRef getName() const { return getStringOperand(2); }
551 Metadata *getRawScope() const { return getOperand(1); }
552 MDString *getRawName() const { return getOperandAs<MDString>(2); }
554 void setFlags(unsigned NewFlags) {
555 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
559 bool isPrivate() const {
560 return (getFlags() & FlagAccessibility) == FlagPrivate;
562 bool isProtected() const {
563 return (getFlags() & FlagAccessibility) == FlagProtected;
565 bool isPublic() const {
566 return (getFlags() & FlagAccessibility) == FlagPublic;
568 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
569 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
570 bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; }
571 bool isVirtual() const { return getFlags() & FlagVirtual; }
572 bool isArtificial() const { return getFlags() & FlagArtificial; }
573 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
574 bool isObjcClassComplete() const {
575 return getFlags() & FlagObjcClassComplete;
577 bool isVector() const { return getFlags() & FlagVector; }
578 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
579 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
580 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
582 MDTypeRef getRef() const { return MDTypeRef::get(this); }
584 static bool classof(const Metadata *MD) {
585 switch (MD->getMetadataID()) {
588 case MDBasicTypeKind:
589 case MDDerivedTypeKind:
590 case MDCompositeTypeKind:
591 case MDSubroutineTypeKind:
597 /// \brief Basic type.
599 /// TODO: Split out DW_TAG_unspecified_type.
600 /// TODO: Drop unused accessors.
601 class MDBasicType : public MDType {
602 friend class LLVMContextImpl;
607 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
608 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
609 ArrayRef<Metadata *> Ops)
610 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
612 Encoding(Encoding) {}
613 ~MDBasicType() = default;
615 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
616 StringRef Name, uint64_t SizeInBits,
617 uint64_t AlignInBits, unsigned Encoding,
618 StorageType Storage, bool ShouldCreate = true) {
619 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
620 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
622 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
623 MDString *Name, uint64_t SizeInBits,
624 uint64_t AlignInBits, unsigned Encoding,
625 StorageType Storage, bool ShouldCreate = true);
627 TempMDBasicType cloneImpl() const {
628 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
629 getAlignInBits(), getEncoding());
633 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
634 (Tag, Name, 0, 0, 0))
635 DEFINE_MDNODE_GET(MDBasicType,
636 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
637 uint64_t AlignInBits, unsigned Encoding),
638 (Tag, Name, SizeInBits, AlignInBits, Encoding))
639 DEFINE_MDNODE_GET(MDBasicType,
640 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
641 uint64_t AlignInBits, unsigned Encoding),
642 (Tag, Name, SizeInBits, AlignInBits, Encoding))
644 TempMDBasicType clone() const { return cloneImpl(); }
646 unsigned getEncoding() const { return Encoding; }
648 static bool classof(const Metadata *MD) {
649 return MD->getMetadataID() == MDBasicTypeKind;
653 /// \brief Base class for MDDerivedType and MDCompositeType.
655 /// TODO: Delete; they're not really related.
656 class MDDerivedTypeBase : public MDType {
658 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
659 unsigned Tag, unsigned Line, uint64_t SizeInBits,
660 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
661 ArrayRef<Metadata *> Ops)
662 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
664 ~MDDerivedTypeBase() = default;
667 MDTypeRef getBaseType() const { return MDTypeRef(getRawBaseType()); }
668 Metadata *getRawBaseType() const { return getOperand(3); }
670 static bool classof(const Metadata *MD) {
671 return MD->getMetadataID() == MDDerivedTypeKind ||
672 MD->getMetadataID() == MDCompositeTypeKind ||
673 MD->getMetadataID() == MDSubroutineTypeKind;
677 /// \brief Derived types.
679 /// This includes qualified types, pointers, references, friends, typedefs, and
682 /// TODO: Split out members (inheritance, fields, methods, etc.).
683 class MDDerivedType : public MDDerivedTypeBase {
684 friend class LLVMContextImpl;
687 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
688 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
689 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
690 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
691 AlignInBits, OffsetInBits, Flags, Ops) {}
692 ~MDDerivedType() = default;
694 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
695 StringRef Name, MDFile *File, unsigned Line,
696 MDScopeRef Scope, MDTypeRef BaseType,
697 uint64_t SizeInBits, uint64_t AlignInBits,
698 uint64_t OffsetInBits, unsigned Flags,
699 Metadata *ExtraData, StorageType Storage,
700 bool ShouldCreate = true) {
701 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
702 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
703 Flags, ExtraData, Storage, ShouldCreate);
705 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
706 MDString *Name, Metadata *File, unsigned Line,
707 Metadata *Scope, Metadata *BaseType,
708 uint64_t SizeInBits, uint64_t AlignInBits,
709 uint64_t OffsetInBits, unsigned Flags,
710 Metadata *ExtraData, StorageType Storage,
711 bool ShouldCreate = true);
713 TempMDDerivedType cloneImpl() const {
714 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
715 getScope(), getBaseType(), getSizeInBits(),
716 getAlignInBits(), getOffsetInBits(), getFlags(),
721 DEFINE_MDNODE_GET(MDDerivedType,
722 (unsigned Tag, MDString *Name, Metadata *File,
723 unsigned Line, Metadata *Scope, Metadata *BaseType,
724 uint64_t SizeInBits, uint64_t AlignInBits,
725 uint64_t OffsetInBits, unsigned Flags,
726 Metadata *ExtraData = nullptr),
727 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
728 AlignInBits, OffsetInBits, Flags, ExtraData))
729 DEFINE_MDNODE_GET(MDDerivedType,
730 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
731 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
732 uint64_t AlignInBits, uint64_t OffsetInBits,
733 unsigned Flags, Metadata *ExtraData = nullptr),
734 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
735 AlignInBits, OffsetInBits, Flags, ExtraData))
737 TempMDDerivedType clone() const { return cloneImpl(); }
739 /// \brief Get extra data associated with this derived type.
741 /// Class type for pointer-to-members, objective-c property node for ivars,
742 /// or global constant wrapper for static members.
744 /// TODO: Separate out types that need this extra operand: pointer-to-member
745 /// types and member fields (static members and ivars).
746 Metadata *getExtraData() const { return getRawExtraData(); }
747 Metadata *getRawExtraData() const { return getOperand(4); }
749 static bool classof(const Metadata *MD) {
750 return MD->getMetadataID() == MDDerivedTypeKind;
754 /// \brief Base class for MDCompositeType and MDSubroutineType.
756 /// TODO: Delete; they're not really related.
757 class MDCompositeTypeBase : public MDDerivedTypeBase {
758 unsigned RuntimeLang;
761 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
762 unsigned Tag, unsigned Line, unsigned RuntimeLang,
763 uint64_t SizeInBits, uint64_t AlignInBits,
764 uint64_t OffsetInBits, unsigned Flags,
765 ArrayRef<Metadata *> Ops)
766 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
767 OffsetInBits, Flags, Ops),
768 RuntimeLang(RuntimeLang) {}
769 ~MDCompositeTypeBase() = default;
772 DebugNodeArray getElements() const {
773 return cast_or_null<MDTuple>(getRawElements());
775 MDTypeRef getVTableHolder() const { return MDTypeRef(getRawVTableHolder()); }
776 MDTemplateParameterArray getTemplateParams() const {
777 return cast_or_null<MDTuple>(getRawTemplateParams());
779 StringRef getIdentifier() const { return getStringOperand(7); }
780 unsigned getRuntimeLang() const { return RuntimeLang; }
782 Metadata *getRawElements() const { return getOperand(4); }
783 Metadata *getRawVTableHolder() const { return getOperand(5); }
784 Metadata *getRawTemplateParams() const { return getOperand(6); }
785 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
787 /// \brief Replace operands.
789 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
790 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
791 /// of its movement if necessary.
793 void replaceElements(DebugNodeArray Elements) {
795 for (DebugNode *Op : getElements())
796 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
797 "Lost a member during member list replacement");
799 replaceOperandWith(4, Elements.get());
801 void replaceVTableHolder(MDTypeRef VTableHolder) {
802 replaceOperandWith(5, VTableHolder);
804 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
805 replaceOperandWith(6, TemplateParams.get());
809 static bool classof(const Metadata *MD) {
810 return MD->getMetadataID() == MDCompositeTypeKind ||
811 MD->getMetadataID() == MDSubroutineTypeKind;
815 /// \brief Composite types.
817 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
818 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
819 class MDCompositeType : public MDCompositeTypeBase {
820 friend class LLVMContextImpl;
823 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
824 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
825 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
826 ArrayRef<Metadata *> Ops)
827 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
828 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
830 ~MDCompositeType() = default;
832 static MDCompositeType *
833 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
834 unsigned Line, MDScopeRef Scope, MDTypeRef BaseType,
835 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
836 uint64_t Flags, DebugNodeArray Elements, unsigned RuntimeLang,
837 MDTypeRef VTableHolder, MDTemplateParameterArray TemplateParams,
838 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
840 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
841 BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
842 RuntimeLang, VTableHolder, TemplateParams.get(),
843 getCanonicalMDString(Context, Identifier), Storage, ShouldCreate);
845 static MDCompositeType *
846 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
847 unsigned Line, Metadata *Scope, Metadata *BaseType,
848 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
849 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
850 Metadata *VTableHolder, Metadata *TemplateParams,
851 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
853 TempMDCompositeType cloneImpl() const {
854 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
855 getScope(), getBaseType(), getSizeInBits(),
856 getAlignInBits(), getOffsetInBits(), getFlags(),
857 getElements(), getRuntimeLang(), getVTableHolder(),
858 getTemplateParams(), getIdentifier());
862 DEFINE_MDNODE_GET(MDCompositeType,
863 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
864 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
865 uint64_t AlignInBits, uint64_t OffsetInBits,
866 unsigned Flags, DebugNodeArray Elements,
867 unsigned RuntimeLang, MDTypeRef VTableHolder,
868 MDTemplateParameterArray TemplateParams = nullptr,
869 StringRef Identifier = ""),
870 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
871 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
872 VTableHolder, TemplateParams, Identifier))
873 DEFINE_MDNODE_GET(MDCompositeType,
874 (unsigned Tag, MDString *Name, Metadata *File,
875 unsigned Line, Metadata *Scope, Metadata *BaseType,
876 uint64_t SizeInBits, uint64_t AlignInBits,
877 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
878 unsigned RuntimeLang, Metadata *VTableHolder,
879 Metadata *TemplateParams = nullptr,
880 MDString *Identifier = nullptr),
881 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
882 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
883 VTableHolder, TemplateParams, Identifier))
885 TempMDCompositeType clone() const { return cloneImpl(); }
887 static bool classof(const Metadata *MD) {
888 return MD->getMetadataID() == MDCompositeTypeKind;
892 template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) {
894 if (auto *Composite = dyn_cast<MDCompositeType>(N))
895 if (auto *S = Composite->getRawIdentifier())
896 return TypedDebugNodeRef<T>(S);
897 return TypedDebugNodeRef<T>(N);
900 /// \brief Type array for a subprogram.
902 /// TODO: Detach from CompositeType, and fold the array of types in directly
904 class MDSubroutineType : public MDCompositeTypeBase {
905 friend class LLVMContextImpl;
908 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
909 ArrayRef<Metadata *> Ops)
910 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
911 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
913 ~MDSubroutineType() = default;
915 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
916 MDTypeRefArray TypeArray,
918 bool ShouldCreate = true) {
919 return getImpl(Context, Flags, TypeArray.get(), Storage, ShouldCreate);
921 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
922 Metadata *TypeArray, StorageType Storage,
923 bool ShouldCreate = true);
925 TempMDSubroutineType cloneImpl() const {
926 return getTemporary(getContext(), getFlags(), getTypeArray());
930 DEFINE_MDNODE_GET(MDSubroutineType,
931 (unsigned Flags, MDTypeRefArray TypeArray),
933 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
936 TempMDSubroutineType clone() const { return cloneImpl(); }
938 MDTypeRefArray getTypeArray() const {
939 return cast_or_null<MDTuple>(getRawTypeArray());
941 Metadata *getRawTypeArray() const { return getRawElements(); }
943 static bool classof(const Metadata *MD) {
944 return MD->getMetadataID() == MDSubroutineTypeKind;
948 /// \brief Compile unit.
949 class MDCompileUnit : public MDScope {
950 friend class LLVMContextImpl;
953 unsigned SourceLanguage;
955 unsigned RuntimeVersion;
956 unsigned EmissionKind;
958 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
959 bool IsOptimized, unsigned RuntimeVersion,
960 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
961 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
962 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
963 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
964 ~MDCompileUnit() = default;
966 static MDCompileUnit *
967 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
968 StringRef Producer, bool IsOptimized, StringRef Flags,
969 unsigned RuntimeVersion, StringRef SplitDebugFilename,
970 unsigned EmissionKind, MDCompositeTypeArray EnumTypes,
971 MDTypeArray RetainedTypes, MDSubprogramArray Subprograms,
972 MDGlobalVariableArray GlobalVariables,
973 MDImportedEntityArray ImportedEntities, StorageType Storage,
974 bool ShouldCreate = true) {
976 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
977 IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
978 getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
979 EnumTypes.get(), RetainedTypes.get(), Subprograms.get(),
980 GlobalVariables.get(), ImportedEntities.get(), Storage, ShouldCreate);
982 static MDCompileUnit *
983 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
984 MDString *Producer, bool IsOptimized, MDString *Flags,
985 unsigned RuntimeVersion, MDString *SplitDebugFilename,
986 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
987 Metadata *Subprograms, Metadata *GlobalVariables,
988 Metadata *ImportedEntities, StorageType Storage,
989 bool ShouldCreate = true);
991 TempMDCompileUnit cloneImpl() const {
993 getContext(), getSourceLanguage(), getFile(), getProducer(),
994 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
995 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
996 getGlobalVariables(), getImportedEntities());
1000 DEFINE_MDNODE_GET(MDCompileUnit,
1001 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
1002 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
1003 StringRef SplitDebugFilename, unsigned EmissionKind,
1004 MDCompositeTypeArray EnumTypes, MDTypeArray RetainedTypes,
1005 MDSubprogramArray Subprograms,
1006 MDGlobalVariableArray GlobalVariables,
1007 MDImportedEntityArray ImportedEntities),
1008 (SourceLanguage, File, Producer, IsOptimized, Flags,
1009 RuntimeVersion, SplitDebugFilename, EmissionKind,
1010 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
1012 DEFINE_MDNODE_GET(MDCompileUnit,
1013 (unsigned SourceLanguage, Metadata *File,
1014 MDString *Producer, bool IsOptimized, MDString *Flags,
1015 unsigned RuntimeVersion, MDString *SplitDebugFilename,
1016 unsigned EmissionKind, Metadata *EnumTypes,
1017 Metadata *RetainedTypes, Metadata *Subprograms,
1018 Metadata *GlobalVariables, Metadata *ImportedEntities),
1019 (SourceLanguage, File, Producer, IsOptimized, Flags,
1020 RuntimeVersion, SplitDebugFilename, EmissionKind,
1021 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
1024 TempMDCompileUnit clone() const { return cloneImpl(); }
1026 unsigned getSourceLanguage() const { return SourceLanguage; }
1027 bool isOptimized() const { return IsOptimized; }
1028 unsigned getRuntimeVersion() const { return RuntimeVersion; }
1029 unsigned getEmissionKind() const { return EmissionKind; }
1030 StringRef getProducer() const { return getStringOperand(1); }
1031 StringRef getFlags() const { return getStringOperand(2); }
1032 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
1033 MDCompositeTypeArray getEnumTypes() const {
1034 return cast_or_null<MDTuple>(getRawEnumTypes());
1036 MDTypeArray getRetainedTypes() const {
1037 return cast_or_null<MDTuple>(getRawRetainedTypes());
1039 MDSubprogramArray getSubprograms() const {
1040 return cast_or_null<MDTuple>(getRawSubprograms());
1042 MDGlobalVariableArray getGlobalVariables() const {
1043 return cast_or_null<MDTuple>(getRawGlobalVariables());
1045 MDImportedEntityArray getImportedEntities() const {
1046 return cast_or_null<MDTuple>(getRawImportedEntities());
1049 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1050 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1051 MDString *getRawSplitDebugFilename() const {
1052 return getOperandAs<MDString>(3);
1054 Metadata *getRawEnumTypes() const { return getOperand(4); }
1055 Metadata *getRawRetainedTypes() const { return getOperand(5); }
1056 Metadata *getRawSubprograms() const { return getOperand(6); }
1057 Metadata *getRawGlobalVariables() const { return getOperand(7); }
1058 Metadata *getRawImportedEntities() const { return getOperand(8); }
1060 /// \brief Replace arrays.
1062 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1063 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1064 /// MDCompileUnit should be fairly rare.
1066 void replaceSubprograms(MDSubprogramArray N) {
1067 replaceOperandWith(6, N.get());
1069 void replaceGlobalVariables(MDGlobalVariableArray N) {
1070 replaceOperandWith(7, N.get());
1074 static bool classof(const Metadata *MD) {
1075 return MD->getMetadataID() == MDCompileUnitKind;
1079 /// \brief A scope for locals.
1081 /// A legal scope for lexical blocks, local variables, and debug info
1082 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
1083 /// MDLexicalBlockFile.
1084 class MDLocalScope : public MDScope {
1086 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1087 ArrayRef<Metadata *> Ops)
1088 : MDScope(C, ID, Storage, Tag, Ops) {}
1089 ~MDLocalScope() = default;
1092 /// \brief Get the subprogram for this scope.
1094 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
1096 MDSubprogram *getSubprogram() const;
1098 static bool classof(const Metadata *MD) {
1099 return MD->getMetadataID() == MDSubprogramKind ||
1100 MD->getMetadataID() == MDLexicalBlockKind ||
1101 MD->getMetadataID() == MDLexicalBlockFileKind;
1105 /// \brief Debug location.
1107 /// A debug location in source code, used for debug info and otherwise.
1108 class MDLocation : public MDNode {
1109 friend class LLVMContextImpl;
1110 friend class MDNode;
1112 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
1113 unsigned Column, ArrayRef<Metadata *> MDs);
1114 ~MDLocation() { dropAllReferences(); }
1116 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1117 unsigned Column, Metadata *Scope,
1118 Metadata *InlinedAt, StorageType Storage,
1119 bool ShouldCreate = true);
1120 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1121 unsigned Column, MDLocalScope *Scope,
1122 MDLocation *InlinedAt, StorageType Storage,
1123 bool ShouldCreate = true) {
1124 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1125 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1128 TempMDLocation cloneImpl() const {
1129 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
1133 // Disallow replacing operands.
1134 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1137 DEFINE_MDNODE_GET(MDLocation,
1138 (unsigned Line, unsigned Column, Metadata *Scope,
1139 Metadata *InlinedAt = nullptr),
1140 (Line, Column, Scope, InlinedAt))
1141 DEFINE_MDNODE_GET(MDLocation,
1142 (unsigned Line, unsigned Column, MDLocalScope *Scope,
1143 MDLocation *InlinedAt = nullptr),
1144 (Line, Column, Scope, InlinedAt))
1146 /// \brief Return a (temporary) clone of this.
1147 TempMDLocation clone() const { return cloneImpl(); }
1149 unsigned getLine() const { return SubclassData32; }
1150 unsigned getColumn() const { return SubclassData16; }
1151 MDLocalScope *getScope() const {
1152 return cast<MDLocalScope>(getRawScope());
1154 MDLocation *getInlinedAt() const {
1155 return cast_or_null<MDLocation>(getRawInlinedAt());
1158 MDFile *getFile() const { return getScope()->getFile(); }
1159 StringRef getFilename() const { return getScope()->getFilename(); }
1160 StringRef getDirectory() const { return getScope()->getDirectory(); }
1162 /// \brief Get the scope where this is inlined.
1164 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1166 MDLocalScope *getInlinedAtScope() const {
1167 if (auto *IA = getInlinedAt())
1168 return IA->getInlinedAtScope();
1172 /// \brief Check whether this can be discriminated from another location.
1174 /// Check \c this can be discriminated from \c RHS in a linetable entry.
1175 /// Scope and inlined-at chains are not recorded in the linetable, so they
1176 /// cannot be used to distinguish basic blocks.
1178 /// The current implementation is weaker than it should be, since it just
1179 /// checks filename and line.
1181 /// FIXME: Add a check for getDiscriminator().
1182 /// FIXME: Add a check for getColumn().
1183 /// FIXME: Change the getFilename() check to getFile() (or add one for
1184 /// getDirectory()).
1185 bool canDiscriminate(const MDLocation &RHS) const {
1186 return getFilename() != RHS.getFilename() || getLine() != RHS.getLine();
1189 Metadata *getRawScope() const { return getOperand(0); }
1190 Metadata *getRawInlinedAt() const {
1191 if (getNumOperands() == 2)
1192 return getOperand(1);
1196 static bool classof(const Metadata *MD) {
1197 return MD->getMetadataID() == MDLocationKind;
1201 /// \brief Subprogram description.
1203 /// TODO: Remove DisplayName. It's always equal to Name.
1204 /// TODO: Split up flags.
1205 class MDSubprogram : public MDLocalScope {
1206 friend class LLVMContextImpl;
1207 friend class MDNode;
1211 unsigned Virtuality;
1212 unsigned VirtualIndex;
1218 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1219 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1220 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
1221 bool IsOptimized, ArrayRef<Metadata *> Ops)
1222 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1224 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
1225 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
1226 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
1227 ~MDSubprogram() = default;
1229 static MDSubprogram *
1230 getImpl(LLVMContext &Context, MDScopeRef Scope, StringRef Name,
1231 StringRef LinkageName, MDFile *File, unsigned Line,
1232 MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1233 unsigned ScopeLine, MDTypeRef ContainingType, unsigned Virtuality,
1234 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1235 ConstantAsMetadata *Function, MDTemplateParameterArray TemplateParams,
1236 MDSubprogram *Declaration, MDLocalVariableArray Variables,
1237 StorageType Storage, bool ShouldCreate = true) {
1238 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1239 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1240 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1241 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1242 TemplateParams.get(), Declaration, Variables.get(), Storage,
1245 static MDSubprogram *
1246 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1247 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1248 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1249 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1250 unsigned Flags, bool IsOptimized, Metadata *Function,
1251 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1252 StorageType Storage, bool ShouldCreate = true);
1254 TempMDSubprogram cloneImpl() const {
1255 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1256 getFile(), getLine(), getType(), isLocalToUnit(),
1257 isDefinition(), getScopeLine(), getContainingType(),
1258 getVirtuality(), getVirtualIndex(), getFlags(),
1259 isOptimized(), getFunction(), getTemplateParams(),
1260 getDeclaration(), getVariables());
1264 DEFINE_MDNODE_GET(MDSubprogram,
1265 (MDScopeRef Scope, StringRef Name, StringRef LinkageName,
1266 MDFile *File, unsigned Line, MDSubroutineType *Type,
1267 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1268 MDTypeRef ContainingType, unsigned Virtuality,
1269 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1270 ConstantAsMetadata *Function = nullptr,
1271 MDTemplateParameterArray TemplateParams = nullptr,
1272 MDSubprogram *Declaration = nullptr,
1273 MDLocalVariableArray Variables = nullptr),
1274 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1275 IsDefinition, ScopeLine, ContainingType, Virtuality,
1276 VirtualIndex, Flags, IsOptimized, Function, TemplateParams,
1277 Declaration, Variables))
1280 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1281 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1282 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1283 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1284 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1285 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1286 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1287 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1288 Function, TemplateParams, Declaration, Variables))
1290 TempMDSubprogram clone() const { return cloneImpl(); }
1293 unsigned getLine() const { return Line; }
1294 unsigned getVirtuality() const { return Virtuality; }
1295 unsigned getVirtualIndex() const { return VirtualIndex; }
1296 unsigned getScopeLine() const { return ScopeLine; }
1297 unsigned getFlags() const { return Flags; }
1298 bool isLocalToUnit() const { return IsLocalToUnit; }
1299 bool isDefinition() const { return IsDefinition; }
1300 bool isOptimized() const { return IsOptimized; }
1302 unsigned isArtificial() const { return getFlags() & FlagArtificial; }
1303 bool isPrivate() const {
1304 return (getFlags() & FlagAccessibility) == FlagPrivate;
1306 bool isProtected() const {
1307 return (getFlags() & FlagAccessibility) == FlagProtected;
1309 bool isPublic() const {
1310 return (getFlags() & FlagAccessibility) == FlagPublic;
1312 bool isExplicit() const { return getFlags() & FlagExplicit; }
1313 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
1315 /// \brief Check if this is reference-qualified.
1317 /// Return true if this subprogram is a C++11 reference-qualified non-static
1318 /// member function (void foo() &).
1319 unsigned isLValueReference() const {
1320 return getFlags() & FlagLValueReference;
1323 /// \brief Check if this is rvalue-reference-qualified.
1325 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
1326 /// non-static member function (void foo() &&).
1327 unsigned isRValueReference() const {
1328 return getFlags() & FlagRValueReference;
1331 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
1333 StringRef getName() const { return getStringOperand(2); }
1334 StringRef getDisplayName() const { return getStringOperand(3); }
1335 StringRef getLinkageName() const { return getStringOperand(4); }
1337 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1338 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1340 MDSubroutineType *getType() const {
1341 return cast_or_null<MDSubroutineType>(getRawType());
1343 MDTypeRef getContainingType() const {
1344 return MDTypeRef(getRawContainingType());
1347 ConstantAsMetadata *getFunction() const {
1348 return cast_or_null<ConstantAsMetadata>(getRawFunction());
1350 MDTemplateParameterArray getTemplateParams() const {
1351 return cast_or_null<MDTuple>(getRawTemplateParams());
1353 MDSubprogram *getDeclaration() const {
1354 return cast_or_null<MDSubprogram>(getRawDeclaration());
1356 MDLocalVariableArray getVariables() const {
1357 return cast_or_null<MDTuple>(getRawVariables());
1360 Metadata *getRawScope() const { return getOperand(1); }
1361 Metadata *getRawType() const { return getOperand(5); }
1362 Metadata *getRawContainingType() const { return getOperand(6); }
1363 Metadata *getRawFunction() const { return getOperand(7); }
1364 Metadata *getRawTemplateParams() const { return getOperand(8); }
1365 Metadata *getRawDeclaration() const { return getOperand(9); }
1366 Metadata *getRawVariables() const { return getOperand(10); }
1368 /// \brief Replace the function.
1370 /// If \a isUniqued() and not \a isResolved(), this could node will be
1371 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1372 /// that's a problem.
1374 void replaceFunction(Function *F);
1375 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1376 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1379 static bool classof(const Metadata *MD) {
1380 return MD->getMetadataID() == MDSubprogramKind;
1384 class MDLexicalBlockBase : public MDLocalScope {
1386 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1387 ArrayRef<Metadata *> Ops)
1388 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1389 ~MDLexicalBlockBase() = default;
1392 MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
1394 Metadata *getRawScope() const { return getOperand(1); }
1396 static bool classof(const Metadata *MD) {
1397 return MD->getMetadataID() == MDLexicalBlockKind ||
1398 MD->getMetadataID() == MDLexicalBlockFileKind;
1402 class MDLexicalBlock : public MDLexicalBlockBase {
1403 friend class LLVMContextImpl;
1404 friend class MDNode;
1409 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1410 unsigned Column, ArrayRef<Metadata *> Ops)
1411 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1413 ~MDLexicalBlock() = default;
1415 static MDLexicalBlock *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1416 MDFile *File, unsigned Line, unsigned Column,
1417 StorageType Storage,
1418 bool ShouldCreate = true) {
1419 return getImpl(Context, static_cast<Metadata *>(Scope),
1420 static_cast<Metadata *>(File), Line, Column, Storage,
1424 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1425 Metadata *File, unsigned Line, unsigned Column,
1426 StorageType Storage, bool ShouldCreate = true);
1428 TempMDLexicalBlock cloneImpl() const {
1429 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1434 DEFINE_MDNODE_GET(MDLexicalBlock, (MDLocalScope * Scope, MDFile *File,
1435 unsigned Line, unsigned Column),
1436 (Scope, File, Line, Column))
1437 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1438 unsigned Line, unsigned Column),
1439 (Scope, File, Line, Column))
1441 TempMDLexicalBlock clone() const { return cloneImpl(); }
1443 unsigned getLine() const { return Line; }
1444 unsigned getColumn() const { return Column; }
1446 static bool classof(const Metadata *MD) {
1447 return MD->getMetadataID() == MDLexicalBlockKind;
1451 class MDLexicalBlockFile : public MDLexicalBlockBase {
1452 friend class LLVMContextImpl;
1453 friend class MDNode;
1455 unsigned Discriminator;
1457 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1458 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1459 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1460 Discriminator(Discriminator) {}
1461 ~MDLexicalBlockFile() = default;
1463 static MDLexicalBlockFile *getImpl(LLVMContext &Context, MDLocalScope *Scope,
1464 MDFile *File, unsigned Discriminator,
1465 StorageType Storage,
1466 bool ShouldCreate = true) {
1467 return getImpl(Context, static_cast<Metadata *>(Scope),
1468 static_cast<Metadata *>(File), Discriminator, Storage,
1472 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1473 Metadata *File, unsigned Discriminator,
1474 StorageType Storage,
1475 bool ShouldCreate = true);
1477 TempMDLexicalBlockFile cloneImpl() const {
1478 return getTemporary(getContext(), getScope(), getFile(),
1479 getDiscriminator());
1483 DEFINE_MDNODE_GET(MDLexicalBlockFile, (MDLocalScope * Scope, MDFile *File,
1484 unsigned Discriminator),
1485 (Scope, File, Discriminator))
1486 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1487 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1488 (Scope, File, Discriminator))
1490 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1492 unsigned getDiscriminator() const { return Discriminator; }
1494 static bool classof(const Metadata *MD) {
1495 return MD->getMetadataID() == MDLexicalBlockFileKind;
1499 class MDNamespace : public MDScope {
1500 friend class LLVMContextImpl;
1501 friend class MDNode;
1505 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1506 ArrayRef<Metadata *> Ops)
1507 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1510 ~MDNamespace() = default;
1512 static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
1513 MDFile *File, StringRef Name, unsigned Line,
1514 StorageType Storage, bool ShouldCreate = true) {
1515 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1516 Line, Storage, ShouldCreate);
1518 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1519 Metadata *File, MDString *Name, unsigned Line,
1520 StorageType Storage, bool ShouldCreate = true);
1522 TempMDNamespace cloneImpl() const {
1523 return getTemporary(getContext(), getScope(), getFile(), getName(),
1528 DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
1530 (Scope, File, Name, Line))
1531 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1532 MDString *Name, unsigned Line),
1533 (Scope, File, Name, Line))
1535 TempMDNamespace clone() const { return cloneImpl(); }
1537 unsigned getLine() const { return Line; }
1538 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1539 StringRef getName() const { return getStringOperand(2); }
1541 Metadata *getRawScope() const { return getOperand(1); }
1542 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1544 static bool classof(const Metadata *MD) {
1545 return MD->getMetadataID() == MDNamespaceKind;
1549 /// \brief Base class for template parameters.
1550 class MDTemplateParameter : public DebugNode {
1552 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1553 unsigned Tag, ArrayRef<Metadata *> Ops)
1554 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1555 ~MDTemplateParameter() = default;
1558 StringRef getName() const { return getStringOperand(0); }
1559 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1561 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1562 Metadata *getRawType() const { return getOperand(1); }
1564 static bool classof(const Metadata *MD) {
1565 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1566 MD->getMetadataID() == MDTemplateValueParameterKind;
1570 class MDTemplateTypeParameter : public MDTemplateParameter {
1571 friend class LLVMContextImpl;
1572 friend class MDNode;
1574 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1575 ArrayRef<Metadata *> Ops)
1576 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1577 dwarf::DW_TAG_template_type_parameter, Ops) {}
1578 ~MDTemplateTypeParameter() = default;
1580 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1581 MDTypeRef Type, StorageType Storage,
1582 bool ShouldCreate = true) {
1583 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1586 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1587 Metadata *Type, StorageType Storage,
1588 bool ShouldCreate = true);
1590 TempMDTemplateTypeParameter cloneImpl() const {
1591 return getTemporary(getContext(), getName(), getType());
1595 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, MDTypeRef Type),
1597 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1600 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1602 static bool classof(const Metadata *MD) {
1603 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1607 class MDTemplateValueParameter : public MDTemplateParameter {
1608 friend class LLVMContextImpl;
1609 friend class MDNode;
1611 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1612 unsigned Tag, ArrayRef<Metadata *> Ops)
1613 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1615 ~MDTemplateValueParameter() = default;
1617 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1618 StringRef Name, MDTypeRef Type,
1619 Metadata *Value, StorageType Storage,
1620 bool ShouldCreate = true) {
1621 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1622 Value, Storage, ShouldCreate);
1624 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1625 MDString *Name, Metadata *Type,
1626 Metadata *Value, StorageType Storage,
1627 bool ShouldCreate = true);
1629 TempMDTemplateValueParameter cloneImpl() const {
1630 return getTemporary(getContext(), getTag(), getName(), getType(),
1635 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1636 MDTypeRef Type, Metadata *Value),
1637 (Tag, Name, Type, Value))
1638 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1639 Metadata *Type, Metadata *Value),
1640 (Tag, Name, Type, Value))
1642 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1644 Metadata *getValue() const { return getOperand(2); }
1646 static bool classof(const Metadata *MD) {
1647 return MD->getMetadataID() == MDTemplateValueParameterKind;
1651 /// \brief Base class for variables.
1653 /// TODO: Hardcode to DW_TAG_variable.
1654 class MDVariable : public DebugNode {
1658 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1659 unsigned Line, ArrayRef<Metadata *> Ops)
1660 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1661 ~MDVariable() = default;
1664 unsigned getLine() const { return Line; }
1665 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1666 StringRef getName() const { return getStringOperand(1); }
1667 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1668 MDTypeRef getType() const { return MDTypeRef(getRawType()); }
1670 StringRef getFilename() const {
1671 if (auto *F = getFile())
1672 return F->getFilename();
1675 StringRef getDirectory() const {
1676 if (auto *F = getFile())
1677 return F->getDirectory();
1681 Metadata *getRawScope() const { return getOperand(0); }
1682 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1683 Metadata *getRawFile() const { return getOperand(2); }
1684 Metadata *getRawType() const { return getOperand(3); }
1686 static bool classof(const Metadata *MD) {
1687 return MD->getMetadataID() == MDLocalVariableKind ||
1688 MD->getMetadataID() == MDGlobalVariableKind;
1692 /// \brief Global variables.
1694 /// TODO: Remove DisplayName. It's always equal to Name.
1695 class MDGlobalVariable : public MDVariable {
1696 friend class LLVMContextImpl;
1697 friend class MDNode;
1702 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1703 bool IsLocalToUnit, bool IsDefinition,
1704 ArrayRef<Metadata *> Ops)
1705 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1707 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1708 ~MDGlobalVariable() = default;
1710 static MDGlobalVariable *
1711 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1712 StringRef LinkageName, MDFile *File, unsigned Line, MDTypeRef Type,
1713 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1714 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1715 bool ShouldCreate = true) {
1716 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1717 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1718 IsLocalToUnit, IsDefinition, Variable,
1719 StaticDataMemberDeclaration, Storage, ShouldCreate);
1721 static MDGlobalVariable *
1722 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1723 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1724 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1725 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1726 bool ShouldCreate = true);
1728 TempMDGlobalVariable cloneImpl() const {
1729 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1730 getFile(), getLine(), getType(), isLocalToUnit(),
1731 isDefinition(), getVariable(),
1732 getStaticDataMemberDeclaration());
1736 DEFINE_MDNODE_GET(MDGlobalVariable,
1737 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1738 MDFile *File, unsigned Line, MDTypeRef Type,
1739 bool IsLocalToUnit, bool IsDefinition,
1740 ConstantAsMetadata *Variable,
1741 MDDerivedType *StaticDataMemberDeclaration),
1742 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1743 IsDefinition, Variable, StaticDataMemberDeclaration))
1744 DEFINE_MDNODE_GET(MDGlobalVariable,
1745 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1746 Metadata *File, unsigned Line, Metadata *Type,
1747 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1748 Metadata *StaticDataMemberDeclaration),
1749 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1750 IsDefinition, Variable, StaticDataMemberDeclaration))
1752 TempMDGlobalVariable clone() const { return cloneImpl(); }
1754 bool isLocalToUnit() const { return IsLocalToUnit; }
1755 bool isDefinition() const { return IsDefinition; }
1756 StringRef getDisplayName() const { return getStringOperand(4); }
1757 StringRef getLinkageName() const { return getStringOperand(5); }
1758 ConstantAsMetadata *getVariable() const {
1759 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1761 MDDerivedType *getStaticDataMemberDeclaration() const {
1762 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1765 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1766 Metadata *getRawVariable() const { return getOperand(6); }
1767 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1769 static bool classof(const Metadata *MD) {
1770 return MD->getMetadataID() == MDGlobalVariableKind;
1774 /// \brief Local variable.
1776 /// TODO: Split between arguments and otherwise.
1777 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1778 /// TODO: Split up flags.
1779 class MDLocalVariable : public MDVariable {
1780 friend class LLVMContextImpl;
1781 friend class MDNode;
1786 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1787 unsigned Line, unsigned Arg, unsigned Flags,
1788 ArrayRef<Metadata *> Ops)
1789 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1791 ~MDLocalVariable() = default;
1793 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1794 MDScope *Scope, StringRef Name, MDFile *File,
1795 unsigned Line, MDTypeRef Type, unsigned Arg,
1796 unsigned Flags, MDLocation *InlinedAt,
1797 StorageType Storage,
1798 bool ShouldCreate = true) {
1799 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1800 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1803 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1804 Metadata *Scope, MDString *Name,
1805 Metadata *File, unsigned Line, Metadata *Type,
1806 unsigned Arg, unsigned Flags,
1807 Metadata *InlinedAt, StorageType Storage,
1808 bool ShouldCreate = true);
1810 TempMDLocalVariable cloneImpl() const {
1811 return getTemporary(getContext(), getTag(), getScope(), getName(),
1812 getFile(), getLine(), getType(), getArg(), getFlags(),
1817 DEFINE_MDNODE_GET(MDLocalVariable,
1818 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1819 MDFile *File, unsigned Line, MDTypeRef Type, unsigned Arg,
1820 unsigned Flags, MDLocation *InlinedAt = nullptr),
1821 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1822 DEFINE_MDNODE_GET(MDLocalVariable,
1823 (unsigned Tag, Metadata *Scope, MDString *Name,
1824 Metadata *File, unsigned Line, Metadata *Type,
1825 unsigned Arg, unsigned Flags,
1826 Metadata *InlinedAt = nullptr),
1827 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1829 TempMDLocalVariable clone() const { return cloneImpl(); }
1831 /// \brief Get the local scope for this variable.
1833 /// Variables must be defined in a local scope.
1834 MDLocalScope *getScope() const {
1835 return cast<MDLocalScope>(MDVariable::getScope());
1838 unsigned getArg() const { return Arg; }
1839 unsigned getFlags() const { return Flags; }
1840 MDLocation *getInlinedAt() const {
1841 return cast_or_null<MDLocation>(getRawInlinedAt());
1844 Metadata *getRawInlinedAt() const { return getOperand(4); }
1846 bool isArtificial() const { return getFlags() & FlagArtificial; }
1847 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
1849 /// \brief Check that a location is valid for this variable.
1851 /// Check that \c DL has the same inlined-at location as this variable,
1852 /// making them valid for the same \a DbgInfoIntrinsic.
1853 bool isValidLocationForIntrinsic(const MDLocation *DL) const {
1854 return getInlinedAt() == (DL ? DL->getInlinedAt() : nullptr);
1857 /// \brief Get an inlined version of this variable.
1859 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1860 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1861 if (InlinedAt == getInlinedAt())
1862 return const_cast<MDLocalVariable *>(this);
1863 auto Temp = clone();
1864 Temp->replaceOperandWith(4, InlinedAt);
1865 return replaceWithUniqued(std::move(Temp));
1867 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1869 static bool classof(const Metadata *MD) {
1870 return MD->getMetadataID() == MDLocalVariableKind;
1874 /// \brief DWARF expression.
1876 /// TODO: Co-allocate the expression elements.
1877 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1879 class MDExpression : public MDNode {
1880 friend class LLVMContextImpl;
1881 friend class MDNode;
1883 std::vector<uint64_t> Elements;
1885 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1886 : MDNode(C, MDExpressionKind, Storage, None),
1887 Elements(Elements.begin(), Elements.end()) {}
1888 ~MDExpression() = default;
1890 static MDExpression *getImpl(LLVMContext &Context,
1891 ArrayRef<uint64_t> Elements, StorageType Storage,
1892 bool ShouldCreate = true);
1894 TempMDExpression cloneImpl() const {
1895 return getTemporary(getContext(), getElements());
1899 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1901 TempMDExpression clone() const { return cloneImpl(); }
1903 ArrayRef<uint64_t> getElements() const { return Elements; }
1905 unsigned getNumElements() const { return Elements.size(); }
1906 uint64_t getElement(unsigned I) const {
1907 assert(I < Elements.size() && "Index out of range");
1911 /// \brief Return whether this is a piece of an aggregate variable.
1912 bool isBitPiece() const;
1914 /// \brief Return the offset of this piece in bits.
1915 uint64_t getBitPieceOffset() const;
1917 /// \brief Return the size of this piece in bits.
1918 uint64_t getBitPieceSize() const;
1920 typedef ArrayRef<uint64_t>::iterator element_iterator;
1921 element_iterator elements_begin() const { return getElements().begin(); }
1922 element_iterator elements_end() const { return getElements().end(); }
1924 /// \brief A lightweight wrapper around an expression operand.
1926 /// TODO: Store arguments directly and change \a MDExpression to store a
1932 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1934 const uint64_t *get() const { return Op; }
1936 /// \brief Get the operand code.
1937 uint64_t getOp() const { return *Op; }
1939 /// \brief Get an argument to the operand.
1941 /// Never returns the operand itself.
1942 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1944 unsigned getNumArgs() const { return getSize() - 1; }
1946 /// \brief Return the size of the operand.
1948 /// Return the number of elements in the operand (1 + args).
1949 unsigned getSize() const;
1952 /// \brief An iterator for expression operands.
1953 class expr_op_iterator
1954 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1958 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1960 element_iterator getBase() const { return Op.get(); }
1961 const ExprOperand &operator*() const { return Op; }
1962 const ExprOperand *operator->() const { return &Op; }
1964 expr_op_iterator &operator++() {
1968 expr_op_iterator operator++(int) {
1969 expr_op_iterator T(*this);
1974 /// \brief Get the next iterator.
1976 /// \a std::next() doesn't work because this is technically an
1977 /// input_iterator, but it's a perfectly valid operation. This is an
1978 /// accessor to provide the same functionality.
1979 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
1981 bool operator==(const expr_op_iterator &X) const {
1982 return getBase() == X.getBase();
1984 bool operator!=(const expr_op_iterator &X) const {
1985 return getBase() != X.getBase();
1989 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1992 /// \brief Visit the elements via ExprOperand wrappers.
1994 /// These range iterators visit elements through \a ExprOperand wrappers.
1995 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1998 /// \pre \a isValid() gives \c true.
2000 expr_op_iterator expr_op_begin() const {
2001 return expr_op_iterator(elements_begin());
2003 expr_op_iterator expr_op_end() const {
2004 return expr_op_iterator(elements_end());
2008 bool isValid() const;
2010 static bool classof(const Metadata *MD) {
2011 return MD->getMetadataID() == MDExpressionKind;
2015 class MDObjCProperty : public DebugNode {
2016 friend class LLVMContextImpl;
2017 friend class MDNode;
2020 unsigned Attributes;
2022 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
2023 unsigned Attributes, ArrayRef<Metadata *> Ops)
2024 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
2026 Line(Line), Attributes(Attributes) {}
2027 ~MDObjCProperty() = default;
2029 static MDObjCProperty *
2030 getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
2031 StringRef GetterName, StringRef SetterName, unsigned Attributes,
2032 MDType *Type, StorageType Storage, bool ShouldCreate = true) {
2033 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
2034 getCanonicalMDString(Context, GetterName),
2035 getCanonicalMDString(Context, SetterName), Attributes, Type,
2036 Storage, ShouldCreate);
2038 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
2039 Metadata *File, unsigned Line,
2040 MDString *GetterName, MDString *SetterName,
2041 unsigned Attributes, Metadata *Type,
2042 StorageType Storage, bool ShouldCreate = true);
2044 TempMDObjCProperty cloneImpl() const {
2045 return getTemporary(getContext(), getName(), getFile(), getLine(),
2046 getGetterName(), getSetterName(), getAttributes(),
2051 DEFINE_MDNODE_GET(MDObjCProperty,
2052 (StringRef Name, MDFile *File, unsigned Line,
2053 StringRef GetterName, StringRef SetterName,
2054 unsigned Attributes, MDType *Type),
2055 (Name, File, Line, GetterName, SetterName, Attributes,
2057 DEFINE_MDNODE_GET(MDObjCProperty,
2058 (MDString * Name, Metadata *File, unsigned Line,
2059 MDString *GetterName, MDString *SetterName,
2060 unsigned Attributes, Metadata *Type),
2061 (Name, File, Line, GetterName, SetterName, Attributes,
2064 TempMDObjCProperty clone() const { return cloneImpl(); }
2066 unsigned getLine() const { return Line; }
2067 unsigned getAttributes() const { return Attributes; }
2068 StringRef getName() const { return getStringOperand(0); }
2069 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
2070 StringRef getGetterName() const { return getStringOperand(2); }
2071 StringRef getSetterName() const { return getStringOperand(3); }
2072 MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
2074 StringRef getFilename() const {
2075 if (auto *F = getFile())
2076 return F->getFilename();
2079 StringRef getDirectory() const {
2080 if (auto *F = getFile())
2081 return F->getDirectory();
2085 MDString *getRawName() const { return getOperandAs<MDString>(0); }
2086 Metadata *getRawFile() const { return getOperand(1); }
2087 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
2088 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
2089 Metadata *getRawType() const { return getOperand(4); }
2091 static bool classof(const Metadata *MD) {
2092 return MD->getMetadataID() == MDObjCPropertyKind;
2096 class MDImportedEntity : public DebugNode {
2097 friend class LLVMContextImpl;
2098 friend class MDNode;
2102 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
2103 unsigned Line, ArrayRef<Metadata *> Ops)
2104 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
2105 ~MDImportedEntity() = default;
2107 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2108 MDScope *Scope, DebugNodeRef Entity,
2109 unsigned Line, StringRef Name,
2110 StorageType Storage,
2111 bool ShouldCreate = true) {
2112 return getImpl(Context, Tag, Scope, Entity, Line,
2113 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
2115 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2116 Metadata *Scope, Metadata *Entity,
2117 unsigned Line, MDString *Name,
2118 StorageType Storage,
2119 bool ShouldCreate = true);
2121 TempMDImportedEntity cloneImpl() const {
2122 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
2123 getLine(), getName());
2127 DEFINE_MDNODE_GET(MDImportedEntity,
2128 (unsigned Tag, MDScope *Scope, DebugNodeRef Entity,
2129 unsigned Line, StringRef Name = ""),
2130 (Tag, Scope, Entity, Line, Name))
2131 DEFINE_MDNODE_GET(MDImportedEntity,
2132 (unsigned Tag, Metadata *Scope, Metadata *Entity,
2133 unsigned Line, MDString *Name),
2134 (Tag, Scope, Entity, Line, Name))
2136 TempMDImportedEntity clone() const { return cloneImpl(); }
2138 unsigned getLine() const { return Line; }
2139 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
2140 DebugNodeRef getEntity() const { return DebugNodeRef(getRawEntity()); }
2141 StringRef getName() const { return getStringOperand(2); }
2143 Metadata *getRawScope() const { return getOperand(0); }
2144 Metadata *getRawEntity() const { return getOperand(1); }
2145 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2147 static bool classof(const Metadata *MD) {
2148 return MD->getMetadataID() == MDImportedEntityKind;
2152 } // end namespace llvm
2154 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
2155 #undef DEFINE_MDNODE_GET_UNPACK
2156 #undef DEFINE_MDNODE_GET