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 Tagged DWARF-like metadata node.
46 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
47 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
48 /// potentially used for non-DWARF output.
49 class DebugNode : public MDNode {
50 friend class LLVMContextImpl;
54 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
55 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
56 : MDNode(C, ID, Storage, Ops1, Ops2) {
57 assert(Tag < 1u << 16);
62 template <class Ty> Ty *getOperandAs(unsigned I) const {
63 return cast_or_null<Ty>(getOperand(I));
66 StringRef getStringOperand(unsigned I) const {
67 if (auto *S = getOperandAs<MDString>(I))
68 return S->getString();
72 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
75 return MDString::get(Context, S);
79 unsigned getTag() const { return SubclassData16; }
81 static bool classof(const Metadata *MD) {
82 switch (MD->getMetadataID()) {
85 case GenericDebugNodeKind:
87 case MDEnumeratorKind:
89 case MDDerivedTypeKind:
90 case MDCompositeTypeKind:
91 case MDSubroutineTypeKind:
93 case MDCompileUnitKind:
94 case MDSubprogramKind:
95 case MDLexicalBlockKind:
96 case MDLexicalBlockFileKind:
98 case MDTemplateTypeParameterKind:
99 case MDTemplateValueParameterKind:
100 case MDGlobalVariableKind:
101 case MDLocalVariableKind:
102 case MDObjCPropertyKind:
103 case MDImportedEntityKind:
109 /// \brief Generic tagged DWARF-like metadata node.
111 /// An un-specialized DWARF-like metadata node. The first operand is a
112 /// (possibly empty) null-separated \a MDString header that contains arbitrary
113 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
114 /// to other metadata.
115 class GenericDebugNode : public DebugNode {
116 friend class LLVMContextImpl;
119 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
120 unsigned Tag, ArrayRef<Metadata *> Ops1,
121 ArrayRef<Metadata *> Ops2)
122 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
125 ~GenericDebugNode() { dropAllReferences(); }
127 void setHash(unsigned Hash) { SubclassData32 = Hash; }
128 void recalculateHash();
130 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
132 ArrayRef<Metadata *> DwarfOps,
134 bool ShouldCreate = true) {
135 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
136 DwarfOps, Storage, ShouldCreate);
139 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
141 ArrayRef<Metadata *> DwarfOps,
143 bool ShouldCreate = true);
145 TempGenericDebugNode cloneImpl() const {
147 getContext(), getTag(), getHeader(),
148 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
152 unsigned getHash() const { return SubclassData32; }
154 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
155 ArrayRef<Metadata *> DwarfOps),
156 (Tag, Header, DwarfOps))
157 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
158 ArrayRef<Metadata *> DwarfOps),
159 (Tag, Header, DwarfOps))
161 /// \brief Return a (temporary) clone of this.
162 TempGenericDebugNode clone() const { return cloneImpl(); }
164 unsigned getTag() const { return SubclassData16; }
165 StringRef getHeader() const { return getStringOperand(0); }
167 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
168 op_iterator dwarf_op_end() const { return op_end(); }
169 op_range dwarf_operands() const {
170 return op_range(dwarf_op_begin(), dwarf_op_end());
173 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
174 const MDOperand &getDwarfOperand(unsigned I) const {
175 return getOperand(I + 1);
177 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
178 replaceOperandWith(I + 1, New);
181 static bool classof(const Metadata *MD) {
182 return MD->getMetadataID() == GenericDebugNodeKind;
186 /// \brief Array subrange.
188 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
190 class MDSubrange : public DebugNode {
191 friend class LLVMContextImpl;
197 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count, int64_t Lo)
198 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
200 Count(Count), Lo(Lo) {}
203 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
204 StorageType Storage, bool ShouldCreate = true);
206 TempMDSubrange cloneImpl() const {
207 return getTemporary(getContext(), getCount(), getLo());
211 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t Lo = 0), (Count, Lo))
213 TempMDSubrange clone() const { return cloneImpl(); }
215 int64_t getLo() const { return Lo; }
216 int64_t getCount() const { return Count; }
218 static bool classof(const Metadata *MD) {
219 return MD->getMetadataID() == MDSubrangeKind;
223 /// \brief Enumeration value.
225 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
226 /// longer creates a type cycle.
227 class MDEnumerator : public DebugNode {
228 friend class LLVMContextImpl;
233 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
234 ArrayRef<Metadata *> Ops)
235 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
239 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
240 StringRef Name, StorageType Storage,
241 bool ShouldCreate = true) {
242 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
245 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
246 MDString *Name, StorageType Storage,
247 bool ShouldCreate = true);
249 TempMDEnumerator cloneImpl() const {
250 return getTemporary(getContext(), getValue(), getName());
254 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
256 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
259 TempMDEnumerator clone() const { return cloneImpl(); }
261 int64_t getValue() const { return Value; }
262 StringRef getName() const { return getStringOperand(0); }
264 MDString *getRawName() const { return getOperandAs<MDString>(0); }
266 static bool classof(const Metadata *MD) {
267 return MD->getMetadataID() == MDEnumeratorKind;
271 /// \brief Base class for scope-like contexts.
273 /// Base class for lexical scopes and types (which are also declaration
276 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
277 class MDScope : public DebugNode {
279 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
280 ArrayRef<Metadata *> Ops)
281 : DebugNode(C, ID, Storage, Tag, Ops) {}
285 // FIXME: Downcast to MDFile once we've verified all subclasses.
286 Metadata *getFile() const { return getRawFile(); }
288 /// \brief Return the raw underlying file.
290 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
291 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
292 /// this. Otherwise, return the first operand, which is where all other
293 /// subclasses store their file pointer.
294 Metadata *getRawFile() const {
295 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
296 : static_cast<Metadata *>(getOperand(0));
299 static bool classof(const Metadata *MD) {
300 switch (MD->getMetadataID()) {
303 case MDBasicTypeKind:
304 case MDDerivedTypeKind:
305 case MDCompositeTypeKind:
306 case MDSubroutineTypeKind:
308 case MDCompileUnitKind:
309 case MDSubprogramKind:
310 case MDLexicalBlockKind:
311 case MDLexicalBlockFileKind:
312 case MDNamespaceKind:
320 /// TODO: Merge with directory/file node (including users).
321 /// TODO: Canonicalize paths on creation.
322 class MDFile : public MDScope {
323 friend class LLVMContextImpl;
326 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
327 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
330 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
331 StringRef Directory, StorageType Storage,
332 bool ShouldCreate = true) {
333 return getImpl(Context, getCanonicalMDString(Context, Filename),
334 getCanonicalMDString(Context, Directory), Storage,
337 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
338 MDString *Directory, StorageType Storage,
339 bool ShouldCreate = true);
341 TempMDFile cloneImpl() const {
342 return getTemporary(getContext(), getFilename(), getDirectory());
346 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
347 (Filename, Directory))
348 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
349 (Filename, Directory))
351 TempMDFile clone() const { return cloneImpl(); }
353 StringRef getFilename() const { return getStringOperand(0); }
354 StringRef getDirectory() const { return getStringOperand(1); }
356 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
357 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
359 static bool classof(const Metadata *MD) {
360 return MD->getMetadataID() == MDFileKind;
364 /// \brief Base class for types.
366 /// TODO: Remove the hardcoded name and context, since many types don't use
368 /// TODO: Split up flags.
369 class MDType : public MDScope {
373 uint64_t AlignInBits;
374 uint64_t OffsetInBits;
377 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
378 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
379 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
380 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
381 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
382 OffsetInBits(OffsetInBits) {}
386 TempMDType clone() const {
387 return TempMDType(cast<MDType>(MDNode::clone().release()));
390 unsigned getLine() const { return Line; }
391 uint64_t getSizeInBits() const { return SizeInBits; }
392 uint64_t getAlignInBits() const { return AlignInBits; }
393 uint64_t getOffsetInBits() const { return OffsetInBits; }
394 unsigned getFlags() const { return Flags; }
396 // FIXME: Remove this once MDScope::getFile() does the same.
397 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
399 Metadata *getScope() const { return getRawScope(); }
400 StringRef getName() const { return getStringOperand(2); }
403 Metadata *getRawScope() const { return getOperand(1); }
404 MDString *getRawName() const { return getOperandAs<MDString>(2); }
406 void setFlags(unsigned NewFlags) {
407 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
411 static bool classof(const Metadata *MD) {
412 switch (MD->getMetadataID()) {
415 case MDBasicTypeKind:
416 case MDDerivedTypeKind:
417 case MDCompositeTypeKind:
418 case MDSubroutineTypeKind:
424 /// \brief Basic type.
426 /// TODO: Split out DW_TAG_unspecified_type.
427 /// TODO: Drop unused accessors.
428 class MDBasicType : public MDType {
429 friend class LLVMContextImpl;
434 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
435 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
436 ArrayRef<Metadata *> Ops)
437 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
439 Encoding(Encoding) {}
442 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
443 StringRef Name, uint64_t SizeInBits,
444 uint64_t AlignInBits, unsigned Encoding,
445 StorageType Storage, bool ShouldCreate = true) {
446 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
447 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
449 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
450 MDString *Name, uint64_t SizeInBits,
451 uint64_t AlignInBits, unsigned Encoding,
452 StorageType Storage, bool ShouldCreate = true);
454 TempMDBasicType cloneImpl() const {
455 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
456 getAlignInBits(), getEncoding());
460 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
461 (Tag, Name, 0, 0, 0))
462 DEFINE_MDNODE_GET(MDBasicType,
463 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
464 uint64_t AlignInBits, unsigned Encoding),
465 (Tag, Name, SizeInBits, AlignInBits, Encoding))
466 DEFINE_MDNODE_GET(MDBasicType,
467 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
468 uint64_t AlignInBits, unsigned Encoding),
469 (Tag, Name, SizeInBits, AlignInBits, Encoding))
471 TempMDBasicType clone() const { return cloneImpl(); }
473 unsigned getEncoding() const { return Encoding; }
475 static bool classof(const Metadata *MD) {
476 return MD->getMetadataID() == MDBasicTypeKind;
480 /// \brief Base class for MDDerivedType and MDCompositeType.
482 /// TODO: Delete; they're not really related.
483 class MDDerivedTypeBase : public MDType {
485 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
486 unsigned Tag, unsigned Line, uint64_t SizeInBits,
487 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
488 ArrayRef<Metadata *> Ops)
489 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
491 ~MDDerivedTypeBase() {}
494 Metadata *getBaseType() const { return getRawBaseType(); }
495 Metadata *getRawBaseType() const { return getOperand(3); }
497 static bool classof(const Metadata *MD) {
498 return MD->getMetadataID() == MDDerivedTypeKind ||
499 MD->getMetadataID() == MDCompositeTypeKind ||
500 MD->getMetadataID() == MDSubroutineTypeKind;
504 /// \brief Derived types.
506 /// This includes qualified types, pointers, references, friends, typedefs, and
509 /// TODO: Split out members (inheritance, fields, methods, etc.).
510 class MDDerivedType : public MDDerivedTypeBase {
511 friend class LLVMContextImpl;
514 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
515 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
516 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
517 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
518 AlignInBits, OffsetInBits, Flags, Ops) {}
521 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
522 StringRef Name, MDFile *File, unsigned Line,
523 Metadata *Scope, Metadata *BaseType,
524 uint64_t SizeInBits, uint64_t AlignInBits,
525 uint64_t OffsetInBits, unsigned Flags,
526 Metadata *ExtraData, StorageType Storage,
527 bool ShouldCreate = true) {
528 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
529 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
530 Flags, ExtraData, Storage, ShouldCreate);
532 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
533 MDString *Name, Metadata *File, unsigned Line,
534 Metadata *Scope, Metadata *BaseType,
535 uint64_t SizeInBits, uint64_t AlignInBits,
536 uint64_t OffsetInBits, unsigned Flags,
537 Metadata *ExtraData, StorageType Storage,
538 bool ShouldCreate = true);
540 TempMDDerivedType cloneImpl() const {
541 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
542 getScope(), getBaseType(), getSizeInBits(),
543 getAlignInBits(), getOffsetInBits(), getFlags(),
548 DEFINE_MDNODE_GET(MDDerivedType,
549 (unsigned Tag, MDString *Name, Metadata *File,
550 unsigned Line, Metadata *Scope, Metadata *BaseType,
551 uint64_t SizeInBits, uint64_t AlignInBits,
552 uint64_t OffsetInBits, unsigned Flags,
553 Metadata *ExtraData = nullptr),
554 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
555 AlignInBits, OffsetInBits, Flags, ExtraData))
556 DEFINE_MDNODE_GET(MDDerivedType,
557 (unsigned Tag, StringRef Name, MDFile *File,
558 unsigned Line, Metadata *Scope, Metadata *BaseType,
559 uint64_t SizeInBits, uint64_t AlignInBits,
560 uint64_t OffsetInBits, unsigned Flags,
561 Metadata *ExtraData = nullptr),
562 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
563 AlignInBits, OffsetInBits, Flags, ExtraData))
565 TempMDDerivedType clone() const { return cloneImpl(); }
567 /// \brief Get extra data associated with this derived type.
569 /// Class type for pointer-to-members, objective-c property node for ivars,
570 /// or global constant wrapper for static members.
572 /// TODO: Separate out types that need this extra operand: pointer-to-member
573 /// types and member fields (static members and ivars).
574 Metadata *getExtraData() const { return getRawExtraData(); }
575 Metadata *getRawExtraData() const { return getOperand(4); }
577 static bool classof(const Metadata *MD) {
578 return MD->getMetadataID() == MDDerivedTypeKind;
582 /// \brief Base class for MDCompositeType and MDSubroutineType.
584 /// TODO: Delete; they're not really related.
585 class MDCompositeTypeBase : public MDDerivedTypeBase {
586 unsigned RuntimeLang;
589 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
590 unsigned Tag, unsigned Line, unsigned RuntimeLang,
591 uint64_t SizeInBits, uint64_t AlignInBits,
592 uint64_t OffsetInBits, unsigned Flags,
593 ArrayRef<Metadata *> Ops)
594 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
595 OffsetInBits, Flags, Ops),
596 RuntimeLang(RuntimeLang) {}
597 ~MDCompositeTypeBase() {}
600 MDTuple *getElements() const {
601 return cast_or_null<MDTuple>(getRawElements());
603 Metadata *getVTableHolder() const { return getRawVTableHolder(); }
604 MDTuple *getTemplateParams() const {
605 return cast_or_null<MDTuple>(getRawTemplateParams());
607 StringRef getIdentifier() const { return getStringOperand(7); }
608 unsigned getRuntimeLang() const { return RuntimeLang; }
610 Metadata *getRawElements() const { return getOperand(4); }
611 Metadata *getRawVTableHolder() const { return getOperand(5); }
612 Metadata *getRawTemplateParams() const { return getOperand(6); }
613 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
615 /// \brief Replace operands.
617 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
618 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
619 /// of its movement if necessary.
621 void replaceElements(MDTuple *Elements) {
623 if (auto *Old = cast_or_null<MDTuple>(getElements()))
624 for (const auto &Op : Old->operands())
625 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
626 "Lost a member during member list replacement");
628 replaceOperandWith(4, Elements);
630 void replaceVTableHolder(Metadata *VTableHolder) {
631 replaceOperandWith(5, VTableHolder);
633 void replaceTemplateParams(MDTuple *TemplateParams) {
634 replaceOperandWith(6, TemplateParams);
638 static bool classof(const Metadata *MD) {
639 return MD->getMetadataID() == MDCompositeTypeKind ||
640 MD->getMetadataID() == MDSubroutineTypeKind;
644 /// \brief Composite types.
646 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
647 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
648 class MDCompositeType : public MDCompositeTypeBase {
649 friend class LLVMContextImpl;
652 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
653 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
654 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
655 ArrayRef<Metadata *> Ops)
656 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
657 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
659 ~MDCompositeType() {}
661 static MDCompositeType *
662 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
663 unsigned Line, Metadata *Scope, Metadata *BaseType,
664 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
665 uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
666 Metadata *VTableHolder, Metadata *TemplateParams,
667 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
668 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
669 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
670 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
671 getCanonicalMDString(Context, Identifier), Storage,
674 static MDCompositeType *
675 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
676 unsigned Line, Metadata *Scope, Metadata *BaseType,
677 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
678 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
679 Metadata *VTableHolder, Metadata *TemplateParams,
680 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
682 TempMDCompositeType cloneImpl() const {
683 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
684 getScope(), getBaseType(), getSizeInBits(),
685 getAlignInBits(), getOffsetInBits(), getFlags(),
686 getElements(), getRuntimeLang(), getVTableHolder(),
687 getTemplateParams(), getIdentifier());
691 DEFINE_MDNODE_GET(MDCompositeType,
692 (unsigned Tag, StringRef Name, Metadata *File,
693 unsigned Line, Metadata *Scope, Metadata *BaseType,
694 uint64_t SizeInBits, uint64_t AlignInBits,
695 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
696 unsigned RuntimeLang, Metadata *VTableHolder,
697 Metadata *TemplateParams = nullptr,
698 StringRef Identifier = ""),
699 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
700 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
701 VTableHolder, TemplateParams, Identifier))
702 DEFINE_MDNODE_GET(MDCompositeType,
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, Metadata *Elements,
707 unsigned RuntimeLang, Metadata *VTableHolder,
708 Metadata *TemplateParams = nullptr,
709 MDString *Identifier = nullptr),
710 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
711 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
712 VTableHolder, TemplateParams, Identifier))
714 TempMDCompositeType clone() const { return cloneImpl(); }
716 static bool classof(const Metadata *MD) {
717 return MD->getMetadataID() == MDCompositeTypeKind;
721 /// \brief Type array for a subprogram.
723 /// TODO: Detach from CompositeType, and fold the array of types in directly
725 class MDSubroutineType : public MDCompositeTypeBase {
726 friend class LLVMContextImpl;
729 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
730 ArrayRef<Metadata *> Ops)
731 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
732 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
734 ~MDSubroutineType() {}
736 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
737 Metadata *TypeArray, StorageType Storage,
738 bool ShouldCreate = true);
740 TempMDSubroutineType cloneImpl() const {
741 return getTemporary(getContext(), getFlags(), getTypeArray());
745 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
748 TempMDSubroutineType clone() const { return cloneImpl(); }
750 MDTuple *getTypeArray() const { return getElements(); }
751 Metadata *getRawTypeArray() const { return getRawElements(); }
753 static bool classof(const Metadata *MD) {
754 return MD->getMetadataID() == MDSubroutineTypeKind;
758 /// \brief Compile unit.
759 class MDCompileUnit : public MDScope {
760 friend class LLVMContextImpl;
763 unsigned SourceLanguage;
765 unsigned RuntimeVersion;
766 unsigned EmissionKind;
768 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
769 bool IsOptimized, unsigned RuntimeVersion,
770 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
771 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
772 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
773 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
776 static MDCompileUnit *
777 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
778 StringRef Producer, bool IsOptimized, StringRef Flags,
779 unsigned RuntimeVersion, StringRef SplitDebugFilename,
780 unsigned EmissionKind, MDTuple *EnumTypes, MDTuple *RetainedTypes,
781 MDTuple *Subprograms, MDTuple *GlobalVariables,
782 MDTuple *ImportedEntities, StorageType Storage,
783 bool ShouldCreate = true) {
784 return getImpl(Context, SourceLanguage, File,
785 getCanonicalMDString(Context, Producer), IsOptimized,
786 getCanonicalMDString(Context, Flags), RuntimeVersion,
787 getCanonicalMDString(Context, SplitDebugFilename),
788 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
789 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
791 static MDCompileUnit *
792 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
793 MDString *Producer, bool IsOptimized, MDString *Flags,
794 unsigned RuntimeVersion, MDString *SplitDebugFilename,
795 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
796 Metadata *Subprograms, Metadata *GlobalVariables,
797 Metadata *ImportedEntities, StorageType Storage,
798 bool ShouldCreate = true);
800 TempMDCompileUnit cloneImpl() const {
802 getContext(), getSourceLanguage(), getFile(), getProducer(),
803 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
804 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
805 getGlobalVariables(), getImportedEntities());
809 DEFINE_MDNODE_GET(MDCompileUnit,
810 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
811 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
812 StringRef SplitDebugFilename, unsigned EmissionKind,
813 MDTuple *EnumTypes, MDTuple *RetainedTypes,
814 MDTuple *Subprograms, MDTuple *GlobalVariables,
815 MDTuple *ImportedEntities),
816 (SourceLanguage, File, Producer, IsOptimized, Flags,
817 RuntimeVersion, SplitDebugFilename, EmissionKind,
818 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
820 DEFINE_MDNODE_GET(MDCompileUnit,
821 (unsigned SourceLanguage, Metadata *File,
822 MDString *Producer, bool IsOptimized, MDString *Flags,
823 unsigned RuntimeVersion, MDString *SplitDebugFilename,
824 unsigned EmissionKind, Metadata *EnumTypes,
825 Metadata *RetainedTypes, Metadata *Subprograms,
826 Metadata *GlobalVariables, Metadata *ImportedEntities),
827 (SourceLanguage, File, Producer, IsOptimized, Flags,
828 RuntimeVersion, SplitDebugFilename, EmissionKind,
829 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
832 TempMDCompileUnit clone() const { return cloneImpl(); }
834 // FIXME: Remove this once MDScope::getFile() does the same.
835 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
837 unsigned getSourceLanguage() const { return SourceLanguage; }
838 bool isOptimized() const { return IsOptimized; }
839 unsigned getRuntimeVersion() const { return RuntimeVersion; }
840 unsigned getEmissionKind() const { return EmissionKind; }
841 StringRef getProducer() const { return getStringOperand(1); }
842 StringRef getFlags() const { return getStringOperand(2); }
843 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
844 MDTuple *getEnumTypes() const {
845 return cast_or_null<MDTuple>(getRawEnumTypes());
847 MDTuple *getRetainedTypes() const {
848 return cast_or_null<MDTuple>(getRawRetainedTypes());
850 MDTuple *getSubprograms() const {
851 return cast_or_null<MDTuple>(getRawSubprograms());
853 MDTuple *getGlobalVariables() const {
854 return cast_or_null<MDTuple>(getRawGlobalVariables());
856 MDTuple *getImportedEntities() const {
857 return cast_or_null<MDTuple>(getRawImportedEntities());
860 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
861 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
862 MDString *getRawSplitDebugFilename() const {
863 return getOperandAs<MDString>(3);
865 Metadata *getRawEnumTypes() const { return getOperand(4); }
866 Metadata *getRawRetainedTypes() const { return getOperand(5); }
867 Metadata *getRawSubprograms() const { return getOperand(6); }
868 Metadata *getRawGlobalVariables() const { return getOperand(7); }
869 Metadata *getRawImportedEntities() const { return getOperand(8); }
871 /// \brief Replace arrays.
873 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
874 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
875 /// MDCompileUnit should be fairly rare.
877 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
878 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
881 static bool classof(const Metadata *MD) {
882 return MD->getMetadataID() == MDCompileUnitKind;
886 /// \brief A scope for locals.
888 /// A legal scope for lexical blocks, local variables, and debug info
889 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
890 /// MDLexicalBlockFile.
891 class MDLocalScope : public MDScope {
893 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
894 ArrayRef<Metadata *> Ops)
895 : MDScope(C, ID, Storage, Tag, Ops) {}
899 static bool classof(const Metadata *MD) {
900 return MD->getMetadataID() == MDSubprogramKind ||
901 MD->getMetadataID() == MDLexicalBlockKind ||
902 MD->getMetadataID() == MDLexicalBlockFileKind;
906 /// \brief Debug location.
908 /// A debug location in source code, used for debug info and otherwise.
909 class MDLocation : public MDNode {
910 friend class LLVMContextImpl;
913 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
914 unsigned Column, ArrayRef<Metadata *> MDs);
915 ~MDLocation() { dropAllReferences(); }
917 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
918 unsigned Column, Metadata *Scope,
919 Metadata *InlinedAt, StorageType Storage,
920 bool ShouldCreate = true);
921 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
922 unsigned Column, MDLocalScope *Scope,
923 MDLocation *InlinedAt, StorageType Storage,
924 bool ShouldCreate = true) {
925 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
926 static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
929 TempMDLocation cloneImpl() const {
930 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
934 // Disallow replacing operands.
935 void replaceOperandWith(unsigned I, Metadata *New) = delete;
938 DEFINE_MDNODE_GET(MDLocation,
939 (unsigned Line, unsigned Column, Metadata *Scope,
940 Metadata *InlinedAt = nullptr),
941 (Line, Column, Scope, InlinedAt))
942 DEFINE_MDNODE_GET(MDLocation,
943 (unsigned Line, unsigned Column, MDLocalScope *Scope,
944 MDLocation *InlinedAt = nullptr),
945 (Line, Column, Scope, InlinedAt))
947 /// \brief Return a (temporary) clone of this.
948 TempMDLocation clone() const { return cloneImpl(); }
950 unsigned getLine() const { return SubclassData32; }
951 unsigned getColumn() const { return SubclassData16; }
952 MDLocalScope *getScope() const {
953 return cast_or_null<MDLocalScope>(getRawScope());
955 MDLocation *getInlinedAt() const {
956 return cast_or_null<MDLocation>(getRawInlinedAt());
959 Metadata *getRawScope() const { return getOperand(0); }
960 Metadata *getRawInlinedAt() const {
961 if (getNumOperands() == 2)
962 return getOperand(1);
966 static bool classof(const Metadata *MD) {
967 return MD->getMetadataID() == MDLocationKind;
971 /// \brief Subprogram description.
973 /// TODO: Remove DisplayName. It's always equal to Name.
974 /// TODO: Split up flags.
975 class MDSubprogram : public MDLocalScope {
976 friend class LLVMContextImpl;
982 unsigned VirtualIndex;
988 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
989 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
990 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
991 bool IsOptimized, ArrayRef<Metadata *> Ops)
992 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
994 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
995 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
996 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
999 static MDSubprogram *
1000 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1001 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1002 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1003 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1004 unsigned Flags, bool IsOptimized, Metadata *Function,
1005 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1006 StorageType Storage, bool ShouldCreate = true) {
1007 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1008 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1009 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1010 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
1011 TemplateParams, Declaration, Variables, Storage,
1014 static MDSubprogram *
1015 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1016 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1017 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1018 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1019 unsigned Flags, bool IsOptimized, Metadata *Function,
1020 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1021 StorageType Storage, bool ShouldCreate = true);
1023 TempMDSubprogram cloneImpl() const {
1024 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1025 getFile(), getLine(), getType(), isLocalToUnit(),
1026 isDefinition(), getScopeLine(), getContainingType(),
1027 getVirtuality(), getVirtualIndex(), getFlags(),
1028 isOptimized(), getFunction(), getTemplateParams(),
1029 getDeclaration(), getVariables());
1035 (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
1036 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1037 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1038 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1039 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1040 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1041 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1042 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1043 Function, TemplateParams, Declaration, Variables))
1046 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1047 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1048 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1049 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1050 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1051 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1052 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1053 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1054 Function, TemplateParams, Declaration, Variables))
1056 TempMDSubprogram clone() const { return cloneImpl(); }
1059 unsigned getLine() const { return Line; }
1060 unsigned getVirtuality() const { return Virtuality; }
1061 unsigned getVirtualIndex() const { return VirtualIndex; }
1062 unsigned getScopeLine() const { return ScopeLine; }
1063 unsigned getFlags() const { return Flags; }
1064 bool isLocalToUnit() const { return IsLocalToUnit; }
1065 bool isDefinition() const { return IsDefinition; }
1066 bool isOptimized() const { return IsOptimized; }
1068 Metadata *getScope() const { return getOperand(1); }
1070 StringRef getName() const { return getStringOperand(2); }
1071 StringRef getDisplayName() const { return getStringOperand(3); }
1072 StringRef getLinkageName() const { return getStringOperand(4); }
1074 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1075 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1077 Metadata *getType() const { return getOperand(5); }
1078 Metadata *getContainingType() const { return getOperand(6); }
1080 Metadata *getFunction() const { return getOperand(7); }
1081 Metadata *getTemplateParams() const { return getOperand(8); }
1082 Metadata *getDeclaration() const { return getOperand(9); }
1083 Metadata *getVariables() const { return getOperand(10); }
1085 /// \brief Replace the function.
1087 /// If \a isUniqued() and not \a isResolved(), this could node will be
1088 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1089 /// that's a problem.
1091 void replaceFunction(Function *F);
1092 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1093 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1096 static bool classof(const Metadata *MD) {
1097 return MD->getMetadataID() == MDSubprogramKind;
1101 class MDLexicalBlockBase : public MDLocalScope {
1103 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1104 ArrayRef<Metadata *> Ops)
1105 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1106 ~MDLexicalBlockBase() {}
1109 Metadata *getScope() const { return getOperand(1); }
1111 static bool classof(const Metadata *MD) {
1112 return MD->getMetadataID() == MDLexicalBlockKind ||
1113 MD->getMetadataID() == MDLexicalBlockFileKind;
1117 class MDLexicalBlock : public MDLexicalBlockBase {
1118 friend class LLVMContextImpl;
1119 friend class MDNode;
1124 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1125 unsigned Column, ArrayRef<Metadata *> Ops)
1126 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1128 ~MDLexicalBlock() {}
1130 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1131 Metadata *File, unsigned Line, unsigned Column,
1132 StorageType Storage, bool ShouldCreate = true);
1134 TempMDLexicalBlock cloneImpl() const {
1135 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1140 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1141 unsigned Line, unsigned Column),
1142 (Scope, File, Line, Column))
1144 TempMDLexicalBlock clone() const { return cloneImpl(); }
1146 unsigned getLine() const { return Line; }
1147 unsigned getColumn() const { return Column; }
1149 static bool classof(const Metadata *MD) {
1150 return MD->getMetadataID() == MDLexicalBlockKind;
1154 class MDLexicalBlockFile : public MDLexicalBlockBase {
1155 friend class LLVMContextImpl;
1156 friend class MDNode;
1158 unsigned Discriminator;
1160 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1161 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1162 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1163 Discriminator(Discriminator) {}
1164 ~MDLexicalBlockFile() {}
1166 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1167 Metadata *File, unsigned Discriminator,
1168 StorageType Storage,
1169 bool ShouldCreate = true);
1171 TempMDLexicalBlockFile cloneImpl() const {
1172 return getTemporary(getContext(), getScope(), getFile(),
1173 getDiscriminator());
1177 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1178 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1179 (Scope, File, Discriminator))
1181 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1183 unsigned getDiscriminator() const { return Discriminator; }
1185 static bool classof(const Metadata *MD) {
1186 return MD->getMetadataID() == MDLexicalBlockFileKind;
1190 class MDNamespace : public MDScope {
1191 friend class LLVMContextImpl;
1192 friend class MDNode;
1196 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1197 ArrayRef<Metadata *> Ops)
1198 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1203 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1204 Metadata *File, StringRef Name, unsigned Line,
1205 StorageType Storage, bool ShouldCreate = true) {
1206 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1207 Line, Storage, ShouldCreate);
1209 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1210 Metadata *File, MDString *Name, unsigned Line,
1211 StorageType Storage, bool ShouldCreate = true);
1213 TempMDNamespace cloneImpl() const {
1214 return getTemporary(getContext(), getScope(), getFile(), getName(),
1219 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1220 StringRef Name, unsigned Line),
1221 (Scope, File, Name, Line))
1222 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1223 MDString *Name, unsigned Line),
1224 (Scope, File, Name, Line))
1226 TempMDNamespace clone() const { return cloneImpl(); }
1228 unsigned getLine() const { return Line; }
1229 Metadata *getScope() const { return getOperand(1); }
1230 StringRef getName() const { return getStringOperand(2); }
1232 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1234 static bool classof(const Metadata *MD) {
1235 return MD->getMetadataID() == MDNamespaceKind;
1239 /// \brief Base class for template parameters.
1240 class MDTemplateParameter : public DebugNode {
1242 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1243 unsigned Tag, ArrayRef<Metadata *> Ops)
1244 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1245 ~MDTemplateParameter() {}
1248 StringRef getName() const { return getStringOperand(0); }
1249 Metadata *getType() const { return getOperand(1); }
1251 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1253 static bool classof(const Metadata *MD) {
1254 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1255 MD->getMetadataID() == MDTemplateValueParameterKind;
1259 class MDTemplateTypeParameter : public MDTemplateParameter {
1260 friend class LLVMContextImpl;
1261 friend class MDNode;
1263 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1264 ArrayRef<Metadata *> Ops)
1265 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1266 dwarf::DW_TAG_template_type_parameter, Ops) {}
1267 ~MDTemplateTypeParameter() {}
1269 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1270 Metadata *Type, StorageType Storage,
1271 bool ShouldCreate = true) {
1272 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1275 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1276 Metadata *Type, StorageType Storage,
1277 bool ShouldCreate = true);
1279 TempMDTemplateTypeParameter cloneImpl() const {
1280 return getTemporary(getContext(), getName(), getType());
1284 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1286 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1289 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1291 static bool classof(const Metadata *MD) {
1292 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1296 class MDTemplateValueParameter : public MDTemplateParameter {
1297 friend class LLVMContextImpl;
1298 friend class MDNode;
1300 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1301 unsigned Tag, ArrayRef<Metadata *> Ops)
1302 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1304 ~MDTemplateValueParameter() {}
1306 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1307 StringRef Name, Metadata *Type,
1308 Metadata *Value, StorageType Storage,
1309 bool ShouldCreate = true) {
1310 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1311 Value, Storage, ShouldCreate);
1313 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1314 MDString *Name, Metadata *Type,
1315 Metadata *Value, StorageType Storage,
1316 bool ShouldCreate = true);
1318 TempMDTemplateValueParameter cloneImpl() const {
1319 return getTemporary(getContext(), getTag(), getName(), getType(),
1324 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1325 Metadata *Type, Metadata *Value),
1326 (Tag, Name, Type, Value))
1327 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1328 Metadata *Type, Metadata *Value),
1329 (Tag, Name, Type, Value))
1331 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1333 Metadata *getValue() const { return getOperand(2); }
1335 static bool classof(const Metadata *MD) {
1336 return MD->getMetadataID() == MDTemplateValueParameterKind;
1340 /// \brief Base class for variables.
1342 /// TODO: Hardcode to DW_TAG_variable.
1343 class MDVariable : public DebugNode {
1347 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1348 unsigned Line, ArrayRef<Metadata *> Ops)
1349 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1353 unsigned getLine() const { return Line; }
1354 MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
1355 StringRef getName() const { return getStringOperand(1); }
1356 MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
1357 Metadata *getType() const { return getRawType(); }
1359 Metadata *getRawScope() const { return getOperand(0); }
1360 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1361 Metadata *getRawFile() const { return getOperand(2); }
1362 Metadata *getRawType() const { return getOperand(3); }
1364 static bool classof(const Metadata *MD) {
1365 return MD->getMetadataID() == MDLocalVariableKind ||
1366 MD->getMetadataID() == MDGlobalVariableKind;
1370 /// \brief Global variables.
1372 /// TODO: Remove DisplayName. It's always equal to Name.
1373 class MDGlobalVariable : public MDVariable {
1374 friend class LLVMContextImpl;
1375 friend class MDNode;
1380 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1381 bool IsLocalToUnit, bool IsDefinition,
1382 ArrayRef<Metadata *> Ops)
1383 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1385 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1386 ~MDGlobalVariable() {}
1388 static MDGlobalVariable *
1389 getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
1390 StringRef LinkageName, MDFile *File, unsigned Line, Metadata *Type,
1391 bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
1392 MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
1393 bool ShouldCreate = true) {
1394 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1395 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1396 IsLocalToUnit, IsDefinition, Variable,
1397 StaticDataMemberDeclaration, Storage, ShouldCreate);
1399 static MDGlobalVariable *
1400 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1401 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1402 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1403 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1404 bool ShouldCreate = true);
1406 TempMDGlobalVariable cloneImpl() const {
1407 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1408 getFile(), getLine(), getType(), isLocalToUnit(),
1409 isDefinition(), getVariable(),
1410 getStaticDataMemberDeclaration());
1414 DEFINE_MDNODE_GET(MDGlobalVariable,
1415 (MDScope * Scope, StringRef Name, StringRef LinkageName,
1416 MDFile *File, unsigned Line, Metadata *Type,
1417 bool IsLocalToUnit, bool IsDefinition,
1418 ConstantAsMetadata *Variable,
1419 MDDerivedType *StaticDataMemberDeclaration),
1420 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1421 IsDefinition, Variable, StaticDataMemberDeclaration))
1422 DEFINE_MDNODE_GET(MDGlobalVariable,
1423 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1424 Metadata *File, unsigned Line, Metadata *Type,
1425 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1426 Metadata *StaticDataMemberDeclaration),
1427 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1428 IsDefinition, Variable, StaticDataMemberDeclaration))
1430 TempMDGlobalVariable clone() const { return cloneImpl(); }
1432 bool isLocalToUnit() const { return IsLocalToUnit; }
1433 bool isDefinition() const { return IsDefinition; }
1434 StringRef getDisplayName() const { return getStringOperand(4); }
1435 StringRef getLinkageName() const { return getStringOperand(5); }
1436 ConstantAsMetadata *getVariable() const {
1437 return cast_or_null<ConstantAsMetadata>(getRawVariable());
1439 MDDerivedType *getStaticDataMemberDeclaration() const {
1440 return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
1443 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1444 Metadata *getRawVariable() const { return getOperand(6); }
1445 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
1447 static bool classof(const Metadata *MD) {
1448 return MD->getMetadataID() == MDGlobalVariableKind;
1452 /// \brief Local variable.
1454 /// TODO: Split between arguments and otherwise.
1455 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1456 /// TODO: Split up flags.
1457 class MDLocalVariable : public MDVariable {
1458 friend class LLVMContextImpl;
1459 friend class MDNode;
1464 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1465 unsigned Line, unsigned Arg, unsigned Flags,
1466 ArrayRef<Metadata *> Ops)
1467 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1469 ~MDLocalVariable() {}
1471 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1472 MDScope *Scope, StringRef Name, MDFile *File,
1473 unsigned Line, Metadata *Type, unsigned Arg,
1474 unsigned Flags, MDLocation *InlinedAt,
1475 StorageType Storage,
1476 bool ShouldCreate = true) {
1477 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1478 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1481 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1482 Metadata *Scope, MDString *Name,
1483 Metadata *File, unsigned Line, Metadata *Type,
1484 unsigned Arg, unsigned Flags,
1485 Metadata *InlinedAt, StorageType Storage,
1486 bool ShouldCreate = true);
1488 TempMDLocalVariable cloneImpl() const {
1489 return getTemporary(getContext(), getTag(), getScope(), getName(),
1490 getFile(), getLine(), getType(), getArg(), getFlags(),
1495 DEFINE_MDNODE_GET(MDLocalVariable,
1496 (unsigned Tag, MDLocalScope *Scope, StringRef Name,
1497 MDFile *File, unsigned Line, Metadata *Type, unsigned Arg,
1498 unsigned Flags, MDLocation *InlinedAt = nullptr),
1499 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1500 DEFINE_MDNODE_GET(MDLocalVariable,
1501 (unsigned Tag, Metadata *Scope, MDString *Name,
1502 Metadata *File, unsigned Line, Metadata *Type,
1503 unsigned Arg, unsigned Flags,
1504 Metadata *InlinedAt = nullptr),
1505 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1507 TempMDLocalVariable clone() const { return cloneImpl(); }
1509 /// \brief Get the local scope for this variable.
1511 /// Variables must be defined in a local scope.
1512 MDLocalScope *getScope() const {
1513 return cast<MDLocalScope>(MDVariable::getScope());
1516 unsigned getArg() const { return Arg; }
1517 unsigned getFlags() const { return Flags; }
1518 MDLocation *getInlinedAt() const {
1519 return cast_or_null<MDLocation>(getRawInlinedAt());
1522 Metadata *getRawInlinedAt() const { return getOperand(4); }
1524 /// \brief Get an inlined version of this variable.
1526 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1527 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1528 if (InlinedAt == getInlinedAt())
1529 return const_cast<MDLocalVariable *>(this);
1530 auto Temp = clone();
1531 Temp->replaceOperandWith(4, InlinedAt);
1532 return replaceWithUniqued(std::move(Temp));
1534 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1536 static bool classof(const Metadata *MD) {
1537 return MD->getMetadataID() == MDLocalVariableKind;
1541 /// \brief DWARF expression.
1543 /// TODO: Co-allocate the expression elements.
1544 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1546 class MDExpression : public MDNode {
1547 friend class LLVMContextImpl;
1548 friend class MDNode;
1550 std::vector<uint64_t> Elements;
1552 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1553 : MDNode(C, MDExpressionKind, Storage, None),
1554 Elements(Elements.begin(), Elements.end()) {}
1557 static MDExpression *getImpl(LLVMContext &Context,
1558 ArrayRef<uint64_t> Elements, StorageType Storage,
1559 bool ShouldCreate = true);
1561 TempMDExpression cloneImpl() const {
1562 return getTemporary(getContext(), getElements());
1566 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1568 TempMDExpression clone() const { return cloneImpl(); }
1570 ArrayRef<uint64_t> getElements() const { return Elements; }
1572 unsigned getNumElements() const { return Elements.size(); }
1573 uint64_t getElement(unsigned I) const {
1574 assert(I < Elements.size() && "Index out of range");
1578 typedef ArrayRef<uint64_t>::iterator element_iterator;
1579 element_iterator elements_begin() const { return getElements().begin(); }
1580 element_iterator elements_end() const { return getElements().end(); }
1582 /// \brief A lightweight wrapper around an expression operand.
1584 /// TODO: Store arguments directly and change \a MDExpression to store a
1590 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1592 const uint64_t *get() const { return Op; }
1594 /// \brief Get the operand code.
1595 uint64_t getOp() const { return *Op; }
1597 /// \brief Get an argument to the operand.
1599 /// Never returns the operand itself.
1600 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1602 unsigned getNumArgs() const { return getSize() - 1; }
1604 /// \brief Return the size of the operand.
1606 /// Return the number of elements in the operand (1 + args).
1607 unsigned getSize() const;
1610 /// \brief An iterator for expression operands.
1611 class expr_op_iterator
1612 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1616 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1618 element_iterator getBase() const { return Op.get(); }
1619 const ExprOperand &operator*() const { return Op; }
1620 const ExprOperand *operator->() const { return &Op; }
1622 expr_op_iterator &operator++() {
1626 expr_op_iterator operator++(int) {
1627 expr_op_iterator T(*this);
1632 bool operator==(const expr_op_iterator &X) const {
1633 return getBase() == X.getBase();
1635 bool operator!=(const expr_op_iterator &X) const {
1636 return getBase() != X.getBase();
1640 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1643 /// \brief Visit the elements via ExprOperand wrappers.
1645 /// These range iterators visit elements through \a ExprOperand wrappers.
1646 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1649 /// \pre \a isValid() gives \c true.
1651 expr_op_iterator expr_op_begin() const {
1652 return expr_op_iterator(elements_begin());
1654 expr_op_iterator expr_op_end() const {
1655 return expr_op_iterator(elements_end());
1659 bool isValid() const;
1661 static bool classof(const Metadata *MD) {
1662 return MD->getMetadataID() == MDExpressionKind;
1666 class MDObjCProperty : public DebugNode {
1667 friend class LLVMContextImpl;
1668 friend class MDNode;
1671 unsigned Attributes;
1673 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1674 unsigned Attributes, ArrayRef<Metadata *> Ops)
1675 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1677 Line(Line), Attributes(Attributes) {}
1678 ~MDObjCProperty() {}
1680 static MDObjCProperty *
1681 getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1682 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1683 Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1684 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1685 getCanonicalMDString(Context, GetterName),
1686 getCanonicalMDString(Context, SetterName), Attributes, Type,
1687 Storage, ShouldCreate);
1689 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1690 Metadata *File, unsigned Line,
1691 MDString *GetterName, MDString *SetterName,
1692 unsigned Attributes, Metadata *Type,
1693 StorageType Storage, bool ShouldCreate = true);
1695 TempMDObjCProperty cloneImpl() const {
1696 return getTemporary(getContext(), getName(), getFile(), getLine(),
1697 getGetterName(), getSetterName(), getAttributes(),
1702 DEFINE_MDNODE_GET(MDObjCProperty,
1703 (StringRef Name, Metadata *File, unsigned Line,
1704 StringRef GetterName, StringRef SetterName,
1705 unsigned Attributes, Metadata *Type),
1706 (Name, File, Line, GetterName, SetterName, Attributes,
1708 DEFINE_MDNODE_GET(MDObjCProperty,
1709 (MDString * Name, Metadata *File, unsigned Line,
1710 MDString *GetterName, MDString *SetterName,
1711 unsigned Attributes, Metadata *Type),
1712 (Name, File, Line, GetterName, SetterName, Attributes,
1715 TempMDObjCProperty clone() const { return cloneImpl(); }
1717 unsigned getLine() const { return Line; }
1718 unsigned getAttributes() const { return Attributes; }
1719 StringRef getName() const { return getStringOperand(0); }
1720 Metadata *getFile() const { return getOperand(1); }
1721 StringRef getGetterName() const { return getStringOperand(2); }
1722 StringRef getSetterName() const { return getStringOperand(3); }
1723 Metadata *getType() const { return getOperand(4); }
1725 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1726 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1727 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1729 static bool classof(const Metadata *MD) {
1730 return MD->getMetadataID() == MDObjCPropertyKind;
1734 class MDImportedEntity : public DebugNode {
1735 friend class LLVMContextImpl;
1736 friend class MDNode;
1740 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1741 unsigned Line, ArrayRef<Metadata *> Ops)
1742 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1743 ~MDImportedEntity() {}
1745 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1746 Metadata *Scope, Metadata *Entity,
1747 unsigned Line, StringRef Name,
1748 StorageType Storage,
1749 bool ShouldCreate = true) {
1750 return getImpl(Context, Tag, Scope, Entity, Line,
1751 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1753 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1754 Metadata *Scope, Metadata *Entity,
1755 unsigned Line, MDString *Name,
1756 StorageType Storage,
1757 bool ShouldCreate = true);
1759 TempMDImportedEntity cloneImpl() const {
1760 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1761 getLine(), getName());
1765 DEFINE_MDNODE_GET(MDImportedEntity,
1766 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1767 unsigned Line, StringRef Name = ""),
1768 (Tag, Scope, Entity, Line, Name))
1769 DEFINE_MDNODE_GET(MDImportedEntity,
1770 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1771 unsigned Line, MDString *Name),
1772 (Tag, Scope, Entity, Line, Name))
1774 TempMDImportedEntity clone() const { return cloneImpl(); }
1776 unsigned getLine() const { return Line; }
1777 Metadata *getScope() const { return getOperand(0); }
1778 Metadata *getEntity() const { return getOperand(1); }
1779 StringRef getName() const { return getStringOperand(2); }
1781 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1783 static bool classof(const Metadata *MD) {
1784 return MD->getMetadataID() == MDImportedEntityKind;
1788 } // end namespace llvm
1790 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1791 #undef DEFINE_MDNODE_GET_UNPACK
1792 #undef DEFINE_MDNODE_GET