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 Debug location.
46 /// A debug location in source code, used for debug info and otherwise.
47 class MDLocation : public MDNode {
48 friend class LLVMContextImpl;
51 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
52 unsigned Column, ArrayRef<Metadata *> MDs);
53 ~MDLocation() { dropAllReferences(); }
55 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
56 unsigned Column, Metadata *Scope,
57 Metadata *InlinedAt, StorageType Storage,
58 bool ShouldCreate = true);
60 TempMDLocation cloneImpl() const {
61 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
65 // Disallow replacing operands.
66 void replaceOperandWith(unsigned I, Metadata *New) = delete;
69 DEFINE_MDNODE_GET(MDLocation,
70 (unsigned Line, unsigned Column, Metadata *Scope,
71 Metadata *InlinedAt = nullptr),
72 (Line, Column, Scope, InlinedAt))
74 /// \brief Return a (temporary) clone of this.
75 TempMDLocation clone() const { return cloneImpl(); }
77 unsigned getLine() const { return SubclassData32; }
78 unsigned getColumn() const { return SubclassData16; }
79 Metadata *getScope() const { return getOperand(0); }
80 Metadata *getInlinedAt() const {
81 if (getNumOperands() == 2)
86 static bool classof(const Metadata *MD) {
87 return MD->getMetadataID() == MDLocationKind;
91 /// \brief Tagged DWARF-like metadata node.
93 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
94 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
95 /// potentially used for non-DWARF output.
96 class DebugNode : public MDNode {
97 friend class LLVMContextImpl;
101 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
102 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
103 : MDNode(C, ID, Storage, Ops1, Ops2) {
104 assert(Tag < 1u << 16);
105 SubclassData16 = Tag;
109 template <class Ty> Ty *getOperandAs(unsigned I) const {
110 return cast_or_null<Ty>(getOperand(I));
113 StringRef getStringOperand(unsigned I) const {
114 if (auto *S = getOperandAs<MDString>(I))
115 return S->getString();
119 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
122 return MDString::get(Context, S);
126 unsigned getTag() const { return SubclassData16; }
128 static bool classof(const Metadata *MD) {
129 switch (MD->getMetadataID()) {
132 case GenericDebugNodeKind:
134 case MDEnumeratorKind:
135 case MDBasicTypeKind:
136 case MDDerivedTypeKind:
137 case MDCompositeTypeKind:
138 case MDSubroutineTypeKind:
140 case MDCompileUnitKind:
141 case MDSubprogramKind:
142 case MDLexicalBlockKind:
143 case MDLexicalBlockFileKind:
144 case MDNamespaceKind:
145 case MDTemplateTypeParameterKind:
146 case MDTemplateValueParameterKind:
147 case MDGlobalVariableKind:
148 case MDLocalVariableKind:
149 case MDExpressionKind:
150 case MDObjCPropertyKind:
151 case MDImportedEntityKind:
157 /// \brief Generic tagged DWARF-like metadata node.
159 /// An un-specialized DWARF-like metadata node. The first operand is a
160 /// (possibly empty) null-separated \a MDString header that contains arbitrary
161 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
162 /// to other metadata.
163 class GenericDebugNode : public DebugNode {
164 friend class LLVMContextImpl;
167 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
168 unsigned Tag, ArrayRef<Metadata *> Ops1,
169 ArrayRef<Metadata *> Ops2)
170 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
173 ~GenericDebugNode() { dropAllReferences(); }
175 void setHash(unsigned Hash) { SubclassData32 = Hash; }
176 void recalculateHash();
178 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
180 ArrayRef<Metadata *> DwarfOps,
182 bool ShouldCreate = true) {
183 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
184 DwarfOps, Storage, ShouldCreate);
187 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
189 ArrayRef<Metadata *> DwarfOps,
191 bool ShouldCreate = true);
193 TempGenericDebugNode cloneImpl() const {
195 getContext(), getTag(), getHeader(),
196 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
200 unsigned getHash() const { return SubclassData32; }
202 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
203 ArrayRef<Metadata *> DwarfOps),
204 (Tag, Header, DwarfOps))
205 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
206 ArrayRef<Metadata *> DwarfOps),
207 (Tag, Header, DwarfOps))
209 /// \brief Return a (temporary) clone of this.
210 TempGenericDebugNode clone() const { return cloneImpl(); }
212 unsigned getTag() const { return SubclassData16; }
213 StringRef getHeader() const { return getStringOperand(0); }
215 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
216 op_iterator dwarf_op_end() const { return op_end(); }
217 op_range dwarf_operands() const {
218 return op_range(dwarf_op_begin(), dwarf_op_end());
221 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
222 const MDOperand &getDwarfOperand(unsigned I) const {
223 return getOperand(I + 1);
225 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
226 replaceOperandWith(I + 1, New);
229 static bool classof(const Metadata *MD) {
230 return MD->getMetadataID() == GenericDebugNodeKind;
234 /// \brief Array subrange.
236 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
238 class MDSubrange : public DebugNode {
239 friend class LLVMContextImpl;
245 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count, int64_t Lo)
246 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
248 Count(Count), Lo(Lo) {}
251 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
252 StorageType Storage, bool ShouldCreate = true);
254 TempMDSubrange cloneImpl() const {
255 return getTemporary(getContext(), getCount(), getLo());
259 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t Lo = 0), (Count, Lo))
261 TempMDSubrange clone() const { return cloneImpl(); }
263 int64_t getLo() const { return Lo; }
264 int64_t getCount() const { return Count; }
266 static bool classof(const Metadata *MD) {
267 return MD->getMetadataID() == MDSubrangeKind;
271 /// \brief Enumeration value.
273 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
274 /// longer creates a type cycle.
275 class MDEnumerator : public DebugNode {
276 friend class LLVMContextImpl;
281 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
282 ArrayRef<Metadata *> Ops)
283 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
287 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
288 StringRef Name, StorageType Storage,
289 bool ShouldCreate = true) {
290 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
293 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
294 MDString *Name, StorageType Storage,
295 bool ShouldCreate = true);
297 TempMDEnumerator cloneImpl() const {
298 return getTemporary(getContext(), getValue(), getName());
302 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
304 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
307 TempMDEnumerator clone() const { return cloneImpl(); }
309 int64_t getValue() const { return Value; }
310 StringRef getName() const { return getStringOperand(0); }
312 MDString *getRawName() const { return getOperandAs<MDString>(0); }
314 static bool classof(const Metadata *MD) {
315 return MD->getMetadataID() == MDEnumeratorKind;
319 /// \brief Base class for scope-like contexts.
321 /// Base class for lexical scopes and types (which are also declaration
324 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
325 class MDScope : public DebugNode {
327 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
328 ArrayRef<Metadata *> Ops)
329 : DebugNode(C, ID, Storage, Tag, Ops) {}
333 Metadata *getFile() const { return getOperand(0); }
335 static bool classof(const Metadata *MD) {
336 switch (MD->getMetadataID()) {
339 case MDBasicTypeKind:
340 case MDDerivedTypeKind:
341 case MDCompositeTypeKind:
342 case MDSubroutineTypeKind:
344 case MDCompileUnitKind:
345 case MDSubprogramKind:
346 case MDLexicalBlockKind:
347 case MDLexicalBlockFileKind:
348 case MDNamespaceKind:
354 /// \brief Base class for types.
356 /// TODO: Remove the hardcoded name and context, since many types don't use
358 /// TODO: Split up flags.
359 class MDType : public MDScope {
363 uint64_t AlignInBits;
364 uint64_t OffsetInBits;
367 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
368 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
369 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
370 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
371 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
372 OffsetInBits(OffsetInBits) {}
376 unsigned getLine() const { return Line; }
377 uint64_t getSizeInBits() const { return SizeInBits; }
378 uint64_t getAlignInBits() const { return AlignInBits; }
379 uint64_t getOffsetInBits() const { return OffsetInBits; }
380 unsigned getFlags() const { return Flags; }
382 Metadata *getScope() const { return getOperand(1); }
383 StringRef getName() const { return getStringOperand(2); }
385 MDString *getRawName() const { return getOperandAs<MDString>(2); }
387 static bool classof(const Metadata *MD) {
388 switch (MD->getMetadataID()) {
391 case MDBasicTypeKind:
392 case MDDerivedTypeKind:
393 case MDCompositeTypeKind:
394 case MDSubroutineTypeKind:
400 /// \brief Basic type.
402 /// TODO: Split out DW_TAG_unspecified_type.
403 /// TODO: Drop unused accessors.
404 class MDBasicType : public MDType {
405 friend class LLVMContextImpl;
410 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
411 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
412 ArrayRef<Metadata *> Ops)
413 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
415 Encoding(Encoding) {}
418 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
419 StringRef Name, uint64_t SizeInBits,
420 uint64_t AlignInBits, unsigned Encoding,
421 StorageType Storage, bool ShouldCreate = true) {
422 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
423 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
425 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
426 MDString *Name, uint64_t SizeInBits,
427 uint64_t AlignInBits, unsigned Encoding,
428 StorageType Storage, bool ShouldCreate = true);
430 TempMDBasicType cloneImpl() const {
431 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
432 getAlignInBits(), getEncoding());
436 DEFINE_MDNODE_GET(MDBasicType,
437 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
438 uint64_t AlignInBits, unsigned Encoding),
439 (Tag, Name, SizeInBits, AlignInBits, Encoding))
440 DEFINE_MDNODE_GET(MDBasicType,
441 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
442 uint64_t AlignInBits, unsigned Encoding),
443 (Tag, Name, SizeInBits, AlignInBits, Encoding))
445 TempMDBasicType clone() const { return cloneImpl(); }
447 unsigned getEncoding() const { return Encoding; }
449 static bool classof(const Metadata *MD) {
450 return MD->getMetadataID() == MDBasicTypeKind;
454 /// \brief Base class for MDDerivedType and MDCompositeType.
456 /// TODO: Delete; they're not really related.
457 class MDDerivedTypeBase : public MDType {
459 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
460 unsigned Tag, unsigned Line, uint64_t SizeInBits,
461 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
462 ArrayRef<Metadata *> Ops)
463 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
465 ~MDDerivedTypeBase() {}
468 Metadata *getBaseType() const { return getOperand(3); }
470 static bool classof(const Metadata *MD) {
471 return MD->getMetadataID() == MDDerivedTypeKind ||
472 MD->getMetadataID() == MDCompositeTypeKind ||
473 MD->getMetadataID() == MDSubroutineTypeKind;
477 /// \brief Derived types.
479 /// This includes qualified types, pointers, references, friends, typedefs, and
482 /// TODO: Split out members (inheritance, fields, methods, etc.).
483 class MDDerivedType : public MDDerivedTypeBase {
484 friend class LLVMContextImpl;
487 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
488 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
489 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
490 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
491 AlignInBits, OffsetInBits, Flags, Ops) {}
494 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
495 StringRef Name, Metadata *File, unsigned Line,
496 Metadata *Scope, Metadata *BaseType,
497 uint64_t SizeInBits, uint64_t AlignInBits,
498 uint64_t OffsetInBits, unsigned Flags,
499 Metadata *ExtraData, StorageType Storage,
500 bool ShouldCreate = true) {
501 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
502 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
503 Flags, ExtraData, Storage, ShouldCreate);
505 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
506 MDString *Name, Metadata *File, unsigned Line,
507 Metadata *Scope, Metadata *BaseType,
508 uint64_t SizeInBits, uint64_t AlignInBits,
509 uint64_t OffsetInBits, unsigned Flags,
510 Metadata *ExtraData, StorageType Storage,
511 bool ShouldCreate = true);
513 TempMDDerivedType cloneImpl() const {
514 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
515 getScope(), getBaseType(), getSizeInBits(),
516 getAlignInBits(), getOffsetInBits(), getFlags(),
521 DEFINE_MDNODE_GET(MDDerivedType,
522 (unsigned Tag, MDString *Name, Metadata *File,
523 unsigned Line, Metadata *Scope, Metadata *BaseType,
524 uint64_t SizeInBits, uint64_t AlignInBits,
525 uint64_t OffsetInBits, unsigned Flags,
526 Metadata *ExtraData = nullptr),
527 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
528 AlignInBits, OffsetInBits, Flags, ExtraData))
529 DEFINE_MDNODE_GET(MDDerivedType,
530 (unsigned Tag, StringRef Name, Metadata *File,
531 unsigned Line, Metadata *Scope, Metadata *BaseType,
532 uint64_t SizeInBits, uint64_t AlignInBits,
533 uint64_t OffsetInBits, unsigned Flags,
534 Metadata *ExtraData = nullptr),
535 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
536 AlignInBits, OffsetInBits, Flags, ExtraData))
538 TempMDDerivedType clone() const { return cloneImpl(); }
540 /// \brief Get extra data associated with this derived type.
542 /// Class type for pointer-to-members, objective-c property node for ivars,
543 /// or global constant wrapper for static members.
545 /// TODO: Separate out types that need this extra operand: pointer-to-member
546 /// types and member fields (static members and ivars).
547 Metadata *getExtraData() const { return getOperand(4); }
549 static bool classof(const Metadata *MD) {
550 return MD->getMetadataID() == MDDerivedTypeKind;
554 /// \brief Base class for MDCompositeType and MDSubroutineType.
556 /// TODO: Delete; they're not really related.
557 class MDCompositeTypeBase : public MDDerivedTypeBase {
558 unsigned RuntimeLang;
561 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
562 unsigned Tag, unsigned Line, unsigned RuntimeLang,
563 uint64_t SizeInBits, uint64_t AlignInBits,
564 uint64_t OffsetInBits, unsigned Flags,
565 ArrayRef<Metadata *> Ops)
566 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
567 OffsetInBits, Flags, Ops),
568 RuntimeLang(RuntimeLang) {}
569 ~MDCompositeTypeBase() {}
572 Metadata *getElements() const { return getOperand(4); }
573 Metadata *getVTableHolder() const { return getOperand(5); }
574 Metadata *getTemplateParams() const { return getOperand(6); }
575 StringRef getIdentifier() const { return getStringOperand(7); }
576 unsigned getRuntimeLang() const { return RuntimeLang; }
578 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
580 /// \brief Replace operands.
582 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
583 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
584 /// of its movement if necessary.
586 void replaceElements(MDTuple *Elements) {
588 if (auto *Old = cast_or_null<MDTuple>(getElements()))
589 for (const auto &Op : Old->operands())
590 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
591 "Lost a member during member list replacement");
593 replaceOperandWith(4, Elements);
595 void replaceVTableHolder(Metadata *VTableHolder) {
596 replaceOperandWith(5, VTableHolder);
598 void replaceTemplateParams(MDTuple *TemplateParams) {
599 replaceOperandWith(6, TemplateParams);
603 static bool classof(const Metadata *MD) {
604 return MD->getMetadataID() == MDCompositeTypeKind ||
605 MD->getMetadataID() == MDSubroutineTypeKind;
609 /// \brief Composite types.
611 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
612 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
613 class MDCompositeType : public MDCompositeTypeBase {
614 friend class LLVMContextImpl;
617 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
618 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
619 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
620 ArrayRef<Metadata *> Ops)
621 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
622 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
624 ~MDCompositeType() {}
626 static MDCompositeType *
627 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
628 unsigned Line, Metadata *Scope, Metadata *BaseType,
629 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
630 uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
631 Metadata *VTableHolder, Metadata *TemplateParams,
632 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
633 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
634 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
635 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
636 getCanonicalMDString(Context, Identifier), Storage,
639 static MDCompositeType *
640 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
641 unsigned Line, Metadata *Scope, Metadata *BaseType,
642 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
643 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
644 Metadata *VTableHolder, Metadata *TemplateParams,
645 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
647 TempMDCompositeType cloneImpl() const {
648 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
649 getScope(), getBaseType(), getSizeInBits(),
650 getAlignInBits(), getOffsetInBits(), getFlags(),
651 getElements(), getRuntimeLang(), getVTableHolder(),
652 getTemplateParams(), getIdentifier());
656 DEFINE_MDNODE_GET(MDCompositeType,
657 (unsigned Tag, StringRef Name, Metadata *File,
658 unsigned Line, Metadata *Scope, Metadata *BaseType,
659 uint64_t SizeInBits, uint64_t AlignInBits,
660 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
661 unsigned RuntimeLang, Metadata *VTableHolder,
662 Metadata *TemplateParams = nullptr,
663 StringRef Identifier = ""),
664 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
665 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
666 VTableHolder, TemplateParams, Identifier))
667 DEFINE_MDNODE_GET(MDCompositeType,
668 (unsigned Tag, MDString *Name, Metadata *File,
669 unsigned Line, Metadata *Scope, Metadata *BaseType,
670 uint64_t SizeInBits, uint64_t AlignInBits,
671 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
672 unsigned RuntimeLang, Metadata *VTableHolder,
673 Metadata *TemplateParams = nullptr,
674 MDString *Identifier = nullptr),
675 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
676 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
677 VTableHolder, TemplateParams, Identifier))
679 TempMDCompositeType clone() const { return cloneImpl(); }
681 static bool classof(const Metadata *MD) {
682 return MD->getMetadataID() == MDCompositeTypeKind;
686 /// \brief Type array for a subprogram.
688 /// TODO: Detach from CompositeType, and fold the array of types in directly
690 class MDSubroutineType : public MDCompositeTypeBase {
691 friend class LLVMContextImpl;
694 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
695 ArrayRef<Metadata *> Ops)
696 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
697 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
699 ~MDSubroutineType() {}
701 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
702 Metadata *TypeArray, StorageType Storage,
703 bool ShouldCreate = true);
705 TempMDSubroutineType cloneImpl() const {
706 return getTemporary(getContext(), getFlags(), getTypeArray());
710 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
713 TempMDSubroutineType clone() const { return cloneImpl(); }
715 Metadata *getTypeArray() const { return getElements(); }
717 static bool classof(const Metadata *MD) {
718 return MD->getMetadataID() == MDSubroutineTypeKind;
724 /// TODO: Merge with directory/file node (including users).
725 /// TODO: Canonicalize paths on creation.
726 class MDFile : public MDScope {
727 friend class LLVMContextImpl;
730 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
731 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
734 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
735 StringRef Directory, StorageType Storage,
736 bool ShouldCreate = true) {
737 return getImpl(Context, getCanonicalMDString(Context, Filename),
738 getCanonicalMDString(Context, Directory), Storage,
741 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
742 MDString *Directory, StorageType Storage,
743 bool ShouldCreate = true);
745 TempMDFile cloneImpl() const {
746 return getTemporary(getContext(), getFilename(), getDirectory());
750 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
751 (Filename, Directory))
752 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
753 (Filename, Directory))
755 TempMDFile clone() const { return cloneImpl(); }
757 StringRef getFilename() const { return getStringOperand(0); }
758 StringRef getDirectory() const { return getStringOperand(1); }
760 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
761 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
763 static bool classof(const Metadata *MD) {
764 return MD->getMetadataID() == MDFileKind;
768 /// \brief Compile unit.
769 class MDCompileUnit : public MDScope {
770 friend class LLVMContextImpl;
773 unsigned SourceLanguage;
775 unsigned RuntimeVersion;
776 unsigned EmissionKind;
778 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
779 bool IsOptimized, unsigned RuntimeVersion,
780 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
781 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
782 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
783 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
786 static MDCompileUnit *
787 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
788 StringRef Producer, bool IsOptimized, StringRef Flags,
789 unsigned RuntimeVersion, StringRef SplitDebugFilename,
790 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
791 Metadata *Subprograms, Metadata *GlobalVariables,
792 Metadata *ImportedEntities, StorageType Storage,
793 bool ShouldCreate = true) {
794 return getImpl(Context, SourceLanguage, File,
795 getCanonicalMDString(Context, Producer), IsOptimized,
796 getCanonicalMDString(Context, Flags), RuntimeVersion,
797 getCanonicalMDString(Context, SplitDebugFilename),
798 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
799 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
801 static MDCompileUnit *
802 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
803 MDString *Producer, bool IsOptimized, MDString *Flags,
804 unsigned RuntimeVersion, MDString *SplitDebugFilename,
805 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
806 Metadata *Subprograms, Metadata *GlobalVariables,
807 Metadata *ImportedEntities, StorageType Storage,
808 bool ShouldCreate = true);
810 TempMDCompileUnit cloneImpl() const {
812 getContext(), getSourceLanguage(), getFile(), getProducer(),
813 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
814 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
815 getGlobalVariables(), getImportedEntities());
819 DEFINE_MDNODE_GET(MDCompileUnit,
820 (unsigned SourceLanguage, Metadata *File,
821 StringRef Producer, bool IsOptimized, StringRef Flags,
822 unsigned RuntimeVersion, StringRef SplitDebugFilename,
823 unsigned EmissionKind, Metadata *EnumTypes,
824 Metadata *RetainedTypes, Metadata *Subprograms,
825 Metadata *GlobalVariables, Metadata *ImportedEntities),
826 (SourceLanguage, File, Producer, IsOptimized, Flags,
827 RuntimeVersion, SplitDebugFilename, EmissionKind,
828 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
830 DEFINE_MDNODE_GET(MDCompileUnit,
831 (unsigned SourceLanguage, Metadata *File,
832 MDString *Producer, bool IsOptimized, MDString *Flags,
833 unsigned RuntimeVersion, MDString *SplitDebugFilename,
834 unsigned EmissionKind, Metadata *EnumTypes,
835 Metadata *RetainedTypes, Metadata *Subprograms,
836 Metadata *GlobalVariables, Metadata *ImportedEntities),
837 (SourceLanguage, File, Producer, IsOptimized, Flags,
838 RuntimeVersion, SplitDebugFilename, EmissionKind,
839 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
842 TempMDCompileUnit clone() const { return cloneImpl(); }
844 unsigned getSourceLanguage() const { return SourceLanguage; }
845 bool isOptimized() const { return IsOptimized; }
846 unsigned getRuntimeVersion() const { return RuntimeVersion; }
847 unsigned getEmissionKind() const { return EmissionKind; }
848 StringRef getProducer() const { return getStringOperand(1); }
849 StringRef getFlags() const { return getStringOperand(2); }
850 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
851 Metadata *getEnumTypes() const { return getOperand(4); }
852 Metadata *getRetainedTypes() const { return getOperand(5); }
853 Metadata *getSubprograms() const { return getOperand(6); }
854 Metadata *getGlobalVariables() const { return getOperand(7); }
855 Metadata *getImportedEntities() const { return getOperand(8); }
857 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
858 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
859 MDString *getRawSplitDebugFilename() const {
860 return getOperandAs<MDString>(3);
863 /// \brief Replace arrays.
865 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
866 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
867 /// MDCompileUnit should be fairly rare.
869 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
870 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
873 static bool classof(const Metadata *MD) {
874 return MD->getMetadataID() == MDCompileUnitKind;
878 /// \brief Subprogram description.
880 /// TODO: Remove DisplayName. It's always equal to Name.
881 /// TODO: Split up flags.
882 class MDSubprogram : public MDScope {
883 friend class LLVMContextImpl;
889 unsigned VirtualIndex;
895 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
896 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
897 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
898 bool IsOptimized, ArrayRef<Metadata *> Ops)
899 : MDScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
900 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
901 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
902 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
905 static MDSubprogram *
906 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
907 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
908 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
909 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
910 unsigned Flags, bool IsOptimized, Metadata *Function,
911 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
912 StorageType Storage, bool ShouldCreate = true) {
913 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
914 getCanonicalMDString(Context, LinkageName), File, Line, Type,
915 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
916 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
917 TemplateParams, Declaration, Variables, Storage,
920 static MDSubprogram *
921 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
922 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
923 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
924 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
925 unsigned Flags, bool IsOptimized, Metadata *Function,
926 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
927 StorageType Storage, bool ShouldCreate = true);
929 TempMDSubprogram cloneImpl() const {
930 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
931 getFile(), getLine(), getType(), isLocalToUnit(),
932 isDefinition(), getScopeLine(), getContainingType(),
933 getVirtuality(), getVirtualIndex(), getFlags(),
934 isOptimized(), getFunction(), getTemplateParams(),
935 getDeclaration(), getVariables());
941 (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
942 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
943 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
944 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
945 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
946 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
947 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
948 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
949 Function, TemplateParams, Declaration, Variables))
952 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
953 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
954 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
955 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
956 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
957 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
958 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
959 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
960 Function, TemplateParams, Declaration, Variables))
962 TempMDSubprogram clone() const { return cloneImpl(); }
965 unsigned getLine() const { return Line; }
966 unsigned getVirtuality() const { return Virtuality; }
967 unsigned getVirtualIndex() const { return VirtualIndex; }
968 unsigned getScopeLine() const { return ScopeLine; }
969 unsigned getFlags() const { return Flags; }
970 bool isLocalToUnit() const { return IsLocalToUnit; }
971 bool isDefinition() const { return IsDefinition; }
972 bool isOptimized() const { return IsOptimized; }
974 Metadata *getScope() const { return getOperand(1); }
976 StringRef getName() const { return getStringOperand(2); }
977 StringRef getDisplayName() const { return getStringOperand(3); }
978 StringRef getLinkageName() const { return getStringOperand(4); }
980 MDString *getRawName() const { return getOperandAs<MDString>(2); }
981 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
983 Metadata *getType() const { return getOperand(5); }
984 Metadata *getContainingType() const { return getOperand(6); }
986 Metadata *getFunction() const { return getOperand(7); }
987 Metadata *getTemplateParams() const { return getOperand(8); }
988 Metadata *getDeclaration() const { return getOperand(9); }
989 Metadata *getVariables() const { return getOperand(10); }
991 /// \brief Replace the function.
993 /// If \a isUniqued() and not \a isResolved(), this could node will be
994 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
995 /// that's a problem.
997 void replaceFunction(Function *F);
998 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
999 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1002 static bool classof(const Metadata *MD) {
1003 return MD->getMetadataID() == MDSubprogramKind;
1007 class MDLexicalBlockBase : public MDScope {
1009 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1010 ArrayRef<Metadata *> Ops)
1011 : MDScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1012 ~MDLexicalBlockBase() {}
1015 Metadata *getScope() const { return getOperand(1); }
1017 static bool classof(const Metadata *MD) {
1018 return MD->getMetadataID() == MDLexicalBlockKind ||
1019 MD->getMetadataID() == MDLexicalBlockFileKind;
1023 class MDLexicalBlock : public MDLexicalBlockBase {
1024 friend class LLVMContextImpl;
1025 friend class MDNode;
1030 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1031 unsigned Column, ArrayRef<Metadata *> Ops)
1032 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1034 ~MDLexicalBlock() {}
1036 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1037 Metadata *File, unsigned Line, unsigned Column,
1038 StorageType Storage, bool ShouldCreate = true);
1040 TempMDLexicalBlock cloneImpl() const {
1041 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1046 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1047 unsigned Line, unsigned Column),
1048 (Scope, File, Line, Column))
1050 TempMDLexicalBlock clone() const { return cloneImpl(); }
1052 unsigned getLine() const { return Line; }
1053 unsigned getColumn() const { return Column; }
1055 static bool classof(const Metadata *MD) {
1056 return MD->getMetadataID() == MDLexicalBlockKind;
1060 class MDLexicalBlockFile : public MDLexicalBlockBase {
1061 friend class LLVMContextImpl;
1062 friend class MDNode;
1064 unsigned Discriminator;
1066 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1067 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1068 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1069 Discriminator(Discriminator) {}
1070 ~MDLexicalBlockFile() {}
1072 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1073 Metadata *File, unsigned Discriminator,
1074 StorageType Storage,
1075 bool ShouldCreate = true);
1077 TempMDLexicalBlockFile cloneImpl() const {
1078 return getTemporary(getContext(), getScope(), getFile(),
1079 getDiscriminator());
1083 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1084 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1085 (Scope, File, Discriminator))
1087 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1089 unsigned getDiscriminator() const { return Discriminator; }
1091 static bool classof(const Metadata *MD) {
1092 return MD->getMetadataID() == MDLexicalBlockFileKind;
1096 class MDNamespace : public MDScope {
1097 friend class LLVMContextImpl;
1098 friend class MDNode;
1102 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1103 ArrayRef<Metadata *> Ops)
1104 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1109 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1110 Metadata *File, StringRef Name, unsigned Line,
1111 StorageType Storage, bool ShouldCreate = true) {
1112 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1113 Line, Storage, ShouldCreate);
1115 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1116 Metadata *File, MDString *Name, unsigned Line,
1117 StorageType Storage, bool ShouldCreate = true);
1119 TempMDNamespace cloneImpl() const {
1120 return getTemporary(getContext(), getScope(), getFile(), getName(),
1125 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1126 StringRef Name, unsigned Line),
1127 (Scope, File, Name, Line))
1128 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1129 MDString *Name, unsigned Line),
1130 (Scope, File, Name, Line))
1132 TempMDNamespace clone() const { return cloneImpl(); }
1134 unsigned getLine() const { return Line; }
1135 Metadata *getScope() const { return getOperand(1); }
1136 StringRef getName() const { return getStringOperand(2); }
1138 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1140 static bool classof(const Metadata *MD) {
1141 return MD->getMetadataID() == MDNamespaceKind;
1145 /// \brief Base class for template parameters.
1146 class MDTemplateParameter : public DebugNode {
1148 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1149 unsigned Tag, ArrayRef<Metadata *> Ops)
1150 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1151 ~MDTemplateParameter() {}
1154 StringRef getName() const { return getStringOperand(0); }
1155 Metadata *getType() const { return getOperand(1); }
1157 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1159 static bool classof(const Metadata *MD) {
1160 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1161 MD->getMetadataID() == MDTemplateValueParameterKind;
1165 class MDTemplateTypeParameter : public MDTemplateParameter {
1166 friend class LLVMContextImpl;
1167 friend class MDNode;
1169 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1170 ArrayRef<Metadata *> Ops)
1171 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1172 dwarf::DW_TAG_template_type_parameter, Ops) {}
1173 ~MDTemplateTypeParameter() {}
1175 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1176 Metadata *Type, StorageType Storage,
1177 bool ShouldCreate = true) {
1178 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1181 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1182 Metadata *Type, StorageType Storage,
1183 bool ShouldCreate = true);
1185 TempMDTemplateTypeParameter cloneImpl() const {
1186 return getTemporary(getContext(), getName(), getType());
1190 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1192 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1195 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1197 static bool classof(const Metadata *MD) {
1198 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1202 class MDTemplateValueParameter : public MDTemplateParameter {
1203 friend class LLVMContextImpl;
1204 friend class MDNode;
1206 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1207 unsigned Tag, ArrayRef<Metadata *> Ops)
1208 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1210 ~MDTemplateValueParameter() {}
1212 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1213 StringRef Name, Metadata *Type,
1214 Metadata *Value, StorageType Storage,
1215 bool ShouldCreate = true) {
1216 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1217 Value, Storage, ShouldCreate);
1219 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1220 MDString *Name, Metadata *Type,
1221 Metadata *Value, StorageType Storage,
1222 bool ShouldCreate = true);
1224 TempMDTemplateValueParameter cloneImpl() const {
1225 return getTemporary(getContext(), getTag(), getName(), getType(),
1230 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1231 Metadata *Type, Metadata *Value),
1232 (Tag, Name, Type, Value))
1233 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1234 Metadata *Type, Metadata *Value),
1235 (Tag, Name, Type, Value))
1237 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1239 Metadata *getValue() const { return getOperand(2); }
1241 static bool classof(const Metadata *MD) {
1242 return MD->getMetadataID() == MDTemplateValueParameterKind;
1246 /// \brief Base class for variables.
1248 /// TODO: Hardcode to DW_TAG_variable.
1249 class MDVariable : public DebugNode {
1253 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1254 unsigned Line, ArrayRef<Metadata *> Ops)
1255 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1259 unsigned getLine() const { return Line; }
1260 Metadata *getScope() const { return getOperand(0); }
1261 StringRef getName() const { return getStringOperand(1); }
1262 Metadata *getFile() const { return getOperand(2); }
1263 Metadata *getType() const { return getOperand(3); }
1265 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1267 static bool classof(const Metadata *MD) {
1268 return MD->getMetadataID() == MDLocalVariableKind ||
1269 MD->getMetadataID() == MDGlobalVariableKind;
1273 /// \brief Global variables.
1275 /// TODO: Remove DisplayName. It's always equal to Name.
1276 class MDGlobalVariable : public MDVariable {
1277 friend class LLVMContextImpl;
1278 friend class MDNode;
1283 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1284 bool IsLocalToUnit, bool IsDefinition,
1285 ArrayRef<Metadata *> Ops)
1286 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1288 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1289 ~MDGlobalVariable() {}
1291 static MDGlobalVariable *
1292 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1293 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1294 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1295 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1296 bool ShouldCreate = true) {
1297 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1298 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1299 IsLocalToUnit, IsDefinition, Variable,
1300 StaticDataMemberDeclaration, Storage, ShouldCreate);
1302 static MDGlobalVariable *
1303 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1304 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1305 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1306 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1307 bool ShouldCreate = true);
1309 TempMDGlobalVariable cloneImpl() const {
1310 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1311 getFile(), getLine(), getType(), isLocalToUnit(),
1312 isDefinition(), getVariable(),
1313 getStaticDataMemberDeclaration());
1317 DEFINE_MDNODE_GET(MDGlobalVariable,
1318 (Metadata * Scope, StringRef Name, StringRef LinkageName,
1319 Metadata *File, unsigned Line, Metadata *Type,
1320 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1321 Metadata *StaticDataMemberDeclaration),
1322 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1323 IsDefinition, Variable, StaticDataMemberDeclaration))
1324 DEFINE_MDNODE_GET(MDGlobalVariable,
1325 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1326 Metadata *File, unsigned Line, Metadata *Type,
1327 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1328 Metadata *StaticDataMemberDeclaration),
1329 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1330 IsDefinition, Variable, StaticDataMemberDeclaration))
1332 TempMDGlobalVariable clone() const { return cloneImpl(); }
1334 bool isLocalToUnit() const { return IsLocalToUnit; }
1335 bool isDefinition() const { return IsDefinition; }
1336 StringRef getDisplayName() const { return getStringOperand(4); }
1337 StringRef getLinkageName() const { return getStringOperand(5); }
1338 Metadata *getVariable() const { return getOperand(6); }
1339 Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1341 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1343 static bool classof(const Metadata *MD) {
1344 return MD->getMetadataID() == MDGlobalVariableKind;
1348 /// \brief Local variable.
1350 /// TODO: Split between arguments and otherwise.
1351 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1352 /// TODO: Split up flags.
1353 class MDLocalVariable : public MDVariable {
1354 friend class LLVMContextImpl;
1355 friend class MDNode;
1360 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1361 unsigned Line, unsigned Arg, unsigned Flags,
1362 ArrayRef<Metadata *> Ops)
1363 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1365 ~MDLocalVariable() {}
1367 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1368 Metadata *Scope, StringRef Name,
1369 Metadata *File, unsigned Line, Metadata *Type,
1370 unsigned Arg, unsigned Flags,
1371 Metadata *InlinedAt, StorageType Storage,
1372 bool ShouldCreate = true) {
1373 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1374 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1377 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1378 Metadata *Scope, MDString *Name,
1379 Metadata *File, unsigned Line, Metadata *Type,
1380 unsigned Arg, unsigned Flags,
1381 Metadata *InlinedAt, StorageType Storage,
1382 bool ShouldCreate = true);
1384 TempMDLocalVariable cloneImpl() const {
1385 return getTemporary(getContext(), getTag(), getScope(), getName(),
1386 getFile(), getLine(), getType(), getArg(), getFlags(),
1391 DEFINE_MDNODE_GET(MDLocalVariable,
1392 (unsigned Tag, Metadata *Scope, StringRef Name,
1393 Metadata *File, unsigned Line, Metadata *Type,
1394 unsigned Arg, unsigned Flags,
1395 Metadata *InlinedAt = nullptr),
1396 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1397 DEFINE_MDNODE_GET(MDLocalVariable,
1398 (unsigned Tag, Metadata *Scope, MDString *Name,
1399 Metadata *File, unsigned Line, Metadata *Type,
1400 unsigned Arg, unsigned Flags,
1401 Metadata *InlinedAt = nullptr),
1402 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1404 TempMDLocalVariable clone() const { return cloneImpl(); }
1406 unsigned getArg() const { return Arg; }
1407 unsigned getFlags() const { return Flags; }
1408 Metadata *getInlinedAt() const { return getOperand(4); }
1410 static bool classof(const Metadata *MD) {
1411 return MD->getMetadataID() == MDLocalVariableKind;
1415 /// \brief DWARF expression.
1417 /// TODO: Co-allocate the expression elements.
1418 /// TODO: Drop fake DW_TAG_expression and separate from DebugNode.
1419 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1421 class MDExpression : public DebugNode {
1422 friend class LLVMContextImpl;
1423 friend class MDNode;
1425 std::vector<uint64_t> Elements;
1427 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1428 : DebugNode(C, MDExpressionKind, Storage, dwarf::DW_TAG_expression, None),
1429 Elements(Elements.begin(), Elements.end()) {}
1432 static MDExpression *getImpl(LLVMContext &Context,
1433 ArrayRef<uint64_t> Elements, StorageType Storage,
1434 bool ShouldCreate = true);
1436 TempMDExpression cloneImpl() const {
1437 return getTemporary(getContext(), getElements());
1441 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1443 TempMDExpression clone() const { return cloneImpl(); }
1445 ArrayRef<uint64_t> getElements() const { return Elements; }
1447 unsigned getNumElements() const { return Elements.size(); }
1448 uint64_t getElement(unsigned I) const {
1449 assert(I < Elements.size() && "Index out of range");
1453 typedef ArrayRef<uint64_t>::iterator element_iterator;
1454 element_iterator elements_begin() const { return getElements().begin(); }
1455 element_iterator elements_end() const { return getElements().end(); }
1457 /// \brief A lightweight wrapper around an expression operand.
1459 /// TODO: Store arguments directly and change \a MDExpression to store a
1465 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1467 const uint64_t *get() const { return Op; }
1469 /// \brief Get the operand code.
1470 uint64_t getOp() const { return *Op; }
1472 /// \brief Get an argument to the operand.
1474 /// Never returns the operand itself.
1475 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1477 unsigned getNumArgs() const { return getSize() - 1; }
1479 /// \brief Return the size of the operand.
1481 /// Return the number of elements in the operand (1 + args).
1482 unsigned getSize() const;
1485 /// \brief An iterator for expression operands.
1486 class expr_op_iterator
1487 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1491 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1493 element_iterator getBase() const { return Op.get(); }
1494 const ExprOperand &operator*() const { return Op; }
1495 const ExprOperand *operator->() const { return &Op; }
1497 expr_op_iterator &operator++() {
1501 expr_op_iterator operator++(int) {
1502 expr_op_iterator T(*this);
1507 bool operator==(const expr_op_iterator &X) const {
1508 return getBase() == X.getBase();
1510 bool operator!=(const expr_op_iterator &X) const {
1511 return getBase() != X.getBase();
1515 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1518 /// \brief Visit the elements via ExprOperand wrappers.
1520 /// These range iterators visit elements through \a ExprOperand wrappers.
1521 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1524 /// \pre \a isValid() gives \c true.
1526 expr_op_iterator expr_op_begin() const {
1527 return expr_op_iterator(elements_begin());
1529 expr_op_iterator expr_op_end() const {
1530 return expr_op_iterator(elements_end());
1534 bool isValid() const;
1536 static bool classof(const Metadata *MD) {
1537 return MD->getMetadataID() == MDExpressionKind;
1541 class MDObjCProperty : public DebugNode {
1542 friend class LLVMContextImpl;
1543 friend class MDNode;
1546 unsigned Attributes;
1548 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1549 unsigned Attributes, ArrayRef<Metadata *> Ops)
1550 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1552 Line(Line), Attributes(Attributes) {}
1553 ~MDObjCProperty() {}
1555 static MDObjCProperty *
1556 getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1557 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1558 Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1559 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1560 getCanonicalMDString(Context, GetterName),
1561 getCanonicalMDString(Context, SetterName), Attributes, Type,
1562 Storage, ShouldCreate);
1564 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1565 Metadata *File, unsigned Line,
1566 MDString *GetterName, MDString *SetterName,
1567 unsigned Attributes, Metadata *Type,
1568 StorageType Storage, bool ShouldCreate = true);
1570 TempMDObjCProperty cloneImpl() const {
1571 return getTemporary(getContext(), getName(), getFile(), getLine(),
1572 getGetterName(), getSetterName(), getAttributes(),
1577 DEFINE_MDNODE_GET(MDObjCProperty,
1578 (StringRef Name, Metadata *File, unsigned Line,
1579 StringRef GetterName, StringRef SetterName,
1580 unsigned Attributes, Metadata *Type),
1581 (Name, File, Line, GetterName, SetterName, Attributes,
1583 DEFINE_MDNODE_GET(MDObjCProperty,
1584 (MDString * Name, Metadata *File, unsigned Line,
1585 MDString *GetterName, MDString *SetterName,
1586 unsigned Attributes, Metadata *Type),
1587 (Name, File, Line, GetterName, SetterName, Attributes,
1590 TempMDObjCProperty clone() const { return cloneImpl(); }
1592 unsigned getLine() const { return Line; }
1593 unsigned getAttributes() const { return Attributes; }
1594 StringRef getName() const { return getStringOperand(0); }
1595 Metadata *getFile() const { return getOperand(1); }
1596 StringRef getGetterName() const { return getStringOperand(2); }
1597 StringRef getSetterName() const { return getStringOperand(3); }
1598 Metadata *getType() const { return getOperand(4); }
1600 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1601 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1602 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1604 static bool classof(const Metadata *MD) {
1605 return MD->getMetadataID() == MDObjCPropertyKind;
1609 class MDImportedEntity : public DebugNode {
1610 friend class LLVMContextImpl;
1611 friend class MDNode;
1615 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1616 unsigned Line, ArrayRef<Metadata *> Ops)
1617 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1618 ~MDImportedEntity() {}
1620 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1621 Metadata *Scope, Metadata *Entity,
1622 unsigned Line, StringRef Name,
1623 StorageType Storage,
1624 bool ShouldCreate = true) {
1625 return getImpl(Context, Tag, Scope, Entity, Line,
1626 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1628 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1629 Metadata *Scope, Metadata *Entity,
1630 unsigned Line, MDString *Name,
1631 StorageType Storage,
1632 bool ShouldCreate = true);
1634 TempMDImportedEntity cloneImpl() const {
1635 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1636 getLine(), getName());
1640 DEFINE_MDNODE_GET(MDImportedEntity,
1641 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1642 unsigned Line, StringRef Name = ""),
1643 (Tag, Scope, Entity, Line, Name))
1644 DEFINE_MDNODE_GET(MDImportedEntity,
1645 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1646 unsigned Line, MDString *Name),
1647 (Tag, Scope, Entity, Line, Name))
1649 TempMDImportedEntity clone() const { return cloneImpl(); }
1651 unsigned getLine() const { return Line; }
1652 Metadata *getScope() const { return getOperand(0); }
1653 Metadata *getEntity() const { return getOperand(1); }
1654 StringRef getName() const { return getStringOperand(2); }
1656 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1658 static bool classof(const Metadata *MD) {
1659 return MD->getMetadataID() == MDImportedEntityKind;
1663 } // end namespace llvm
1665 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1666 #undef DEFINE_MDNODE_GET_UNPACK
1667 #undef DEFINE_MDNODE_GET