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 MDObjCPropertyKind:
150 case MDImportedEntityKind:
156 /// \brief Generic tagged DWARF-like metadata node.
158 /// An un-specialized DWARF-like metadata node. The first operand is a
159 /// (possibly empty) null-separated \a MDString header that contains arbitrary
160 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
161 /// to other metadata.
162 class GenericDebugNode : public DebugNode {
163 friend class LLVMContextImpl;
166 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
167 unsigned Tag, ArrayRef<Metadata *> Ops1,
168 ArrayRef<Metadata *> Ops2)
169 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
172 ~GenericDebugNode() { dropAllReferences(); }
174 void setHash(unsigned Hash) { SubclassData32 = Hash; }
175 void recalculateHash();
177 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
179 ArrayRef<Metadata *> DwarfOps,
181 bool ShouldCreate = true) {
182 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
183 DwarfOps, Storage, ShouldCreate);
186 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
188 ArrayRef<Metadata *> DwarfOps,
190 bool ShouldCreate = true);
192 TempGenericDebugNode cloneImpl() const {
194 getContext(), getTag(), getHeader(),
195 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
199 unsigned getHash() const { return SubclassData32; }
201 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
202 ArrayRef<Metadata *> DwarfOps),
203 (Tag, Header, DwarfOps))
204 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
205 ArrayRef<Metadata *> DwarfOps),
206 (Tag, Header, DwarfOps))
208 /// \brief Return a (temporary) clone of this.
209 TempGenericDebugNode clone() const { return cloneImpl(); }
211 unsigned getTag() const { return SubclassData16; }
212 StringRef getHeader() const { return getStringOperand(0); }
214 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
215 op_iterator dwarf_op_end() const { return op_end(); }
216 op_range dwarf_operands() const {
217 return op_range(dwarf_op_begin(), dwarf_op_end());
220 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
221 const MDOperand &getDwarfOperand(unsigned I) const {
222 return getOperand(I + 1);
224 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
225 replaceOperandWith(I + 1, New);
228 static bool classof(const Metadata *MD) {
229 return MD->getMetadataID() == GenericDebugNodeKind;
233 /// \brief Array subrange.
235 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
237 class MDSubrange : public DebugNode {
238 friend class LLVMContextImpl;
244 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count, int64_t Lo)
245 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
247 Count(Count), Lo(Lo) {}
250 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
251 StorageType Storage, bool ShouldCreate = true);
253 TempMDSubrange cloneImpl() const {
254 return getTemporary(getContext(), getCount(), getLo());
258 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t Lo = 0), (Count, Lo))
260 TempMDSubrange clone() const { return cloneImpl(); }
262 int64_t getLo() const { return Lo; }
263 int64_t getCount() const { return Count; }
265 static bool classof(const Metadata *MD) {
266 return MD->getMetadataID() == MDSubrangeKind;
270 /// \brief Enumeration value.
272 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
273 /// longer creates a type cycle.
274 class MDEnumerator : public DebugNode {
275 friend class LLVMContextImpl;
280 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
281 ArrayRef<Metadata *> Ops)
282 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
286 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
287 StringRef Name, StorageType Storage,
288 bool ShouldCreate = true) {
289 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
292 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
293 MDString *Name, StorageType Storage,
294 bool ShouldCreate = true);
296 TempMDEnumerator cloneImpl() const {
297 return getTemporary(getContext(), getValue(), getName());
301 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
303 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
306 TempMDEnumerator clone() const { return cloneImpl(); }
308 int64_t getValue() const { return Value; }
309 StringRef getName() const { return getStringOperand(0); }
311 MDString *getRawName() const { return getOperandAs<MDString>(0); }
313 static bool classof(const Metadata *MD) {
314 return MD->getMetadataID() == MDEnumeratorKind;
318 /// \brief Base class for scope-like contexts.
320 /// Base class for lexical scopes and types (which are also declaration
323 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
324 class MDScope : public DebugNode {
326 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
327 ArrayRef<Metadata *> Ops)
328 : DebugNode(C, ID, Storage, Tag, Ops) {}
332 /// \brief Return the underlying file.
334 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
335 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
336 /// this. Otherwise, return the first operand, which is where all other
337 /// subclasses store their file pointer.
338 Metadata *getFile() const {
339 return isa<MDFile>(this) ? const_cast<MDScope *>(this)
340 : static_cast<Metadata *>(getOperand(0));
343 static bool classof(const Metadata *MD) {
344 switch (MD->getMetadataID()) {
347 case MDBasicTypeKind:
348 case MDDerivedTypeKind:
349 case MDCompositeTypeKind:
350 case MDSubroutineTypeKind:
352 case MDCompileUnitKind:
353 case MDSubprogramKind:
354 case MDLexicalBlockKind:
355 case MDLexicalBlockFileKind:
356 case MDNamespaceKind:
362 /// \brief Base class for types.
364 /// TODO: Remove the hardcoded name and context, since many types don't use
366 /// TODO: Split up flags.
367 class MDType : public MDScope {
371 uint64_t AlignInBits;
372 uint64_t OffsetInBits;
375 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
376 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
377 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
378 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
379 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
380 OffsetInBits(OffsetInBits) {}
384 TempMDType clone() const {
385 return TempMDType(cast<MDType>(MDNode::clone().release()));
388 unsigned getLine() const { return Line; }
389 uint64_t getSizeInBits() const { return SizeInBits; }
390 uint64_t getAlignInBits() const { return AlignInBits; }
391 uint64_t getOffsetInBits() const { return OffsetInBits; }
392 unsigned getFlags() const { return Flags; }
394 Metadata *getScope() const { return getOperand(1); }
395 StringRef getName() const { return getStringOperand(2); }
397 MDString *getRawName() const { return getOperandAs<MDString>(2); }
399 void setFlags(unsigned NewFlags) {
400 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
404 static bool classof(const Metadata *MD) {
405 switch (MD->getMetadataID()) {
408 case MDBasicTypeKind:
409 case MDDerivedTypeKind:
410 case MDCompositeTypeKind:
411 case MDSubroutineTypeKind:
417 /// \brief Basic type.
419 /// TODO: Split out DW_TAG_unspecified_type.
420 /// TODO: Drop unused accessors.
421 class MDBasicType : public MDType {
422 friend class LLVMContextImpl;
427 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
428 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
429 ArrayRef<Metadata *> Ops)
430 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
432 Encoding(Encoding) {}
435 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
436 StringRef Name, uint64_t SizeInBits,
437 uint64_t AlignInBits, unsigned Encoding,
438 StorageType Storage, bool ShouldCreate = true) {
439 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
440 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
442 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
443 MDString *Name, uint64_t SizeInBits,
444 uint64_t AlignInBits, unsigned Encoding,
445 StorageType Storage, bool ShouldCreate = true);
447 TempMDBasicType cloneImpl() const {
448 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
449 getAlignInBits(), getEncoding());
453 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
454 (Tag, Name, 0, 0, 0))
455 DEFINE_MDNODE_GET(MDBasicType,
456 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
457 uint64_t AlignInBits, unsigned Encoding),
458 (Tag, Name, SizeInBits, AlignInBits, Encoding))
459 DEFINE_MDNODE_GET(MDBasicType,
460 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
461 uint64_t AlignInBits, unsigned Encoding),
462 (Tag, Name, SizeInBits, AlignInBits, Encoding))
464 TempMDBasicType clone() const { return cloneImpl(); }
466 unsigned getEncoding() const { return Encoding; }
468 static bool classof(const Metadata *MD) {
469 return MD->getMetadataID() == MDBasicTypeKind;
473 /// \brief Base class for MDDerivedType and MDCompositeType.
475 /// TODO: Delete; they're not really related.
476 class MDDerivedTypeBase : public MDType {
478 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
479 unsigned Tag, unsigned Line, uint64_t SizeInBits,
480 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
481 ArrayRef<Metadata *> Ops)
482 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
484 ~MDDerivedTypeBase() {}
487 Metadata *getBaseType() const { return getOperand(3); }
489 static bool classof(const Metadata *MD) {
490 return MD->getMetadataID() == MDDerivedTypeKind ||
491 MD->getMetadataID() == MDCompositeTypeKind ||
492 MD->getMetadataID() == MDSubroutineTypeKind;
496 /// \brief Derived types.
498 /// This includes qualified types, pointers, references, friends, typedefs, and
501 /// TODO: Split out members (inheritance, fields, methods, etc.).
502 class MDDerivedType : public MDDerivedTypeBase {
503 friend class LLVMContextImpl;
506 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
507 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
508 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
509 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
510 AlignInBits, OffsetInBits, Flags, Ops) {}
513 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
514 StringRef Name, Metadata *File, unsigned Line,
515 Metadata *Scope, Metadata *BaseType,
516 uint64_t SizeInBits, uint64_t AlignInBits,
517 uint64_t OffsetInBits, unsigned Flags,
518 Metadata *ExtraData, StorageType Storage,
519 bool ShouldCreate = true) {
520 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
521 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
522 Flags, ExtraData, Storage, ShouldCreate);
524 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
525 MDString *Name, Metadata *File, unsigned Line,
526 Metadata *Scope, Metadata *BaseType,
527 uint64_t SizeInBits, uint64_t AlignInBits,
528 uint64_t OffsetInBits, unsigned Flags,
529 Metadata *ExtraData, StorageType Storage,
530 bool ShouldCreate = true);
532 TempMDDerivedType cloneImpl() const {
533 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
534 getScope(), getBaseType(), getSizeInBits(),
535 getAlignInBits(), getOffsetInBits(), getFlags(),
540 DEFINE_MDNODE_GET(MDDerivedType,
541 (unsigned Tag, MDString *Name, Metadata *File,
542 unsigned Line, Metadata *Scope, Metadata *BaseType,
543 uint64_t SizeInBits, uint64_t AlignInBits,
544 uint64_t OffsetInBits, unsigned Flags,
545 Metadata *ExtraData = nullptr),
546 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
547 AlignInBits, OffsetInBits, Flags, ExtraData))
548 DEFINE_MDNODE_GET(MDDerivedType,
549 (unsigned Tag, StringRef 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))
557 TempMDDerivedType clone() const { return cloneImpl(); }
559 /// \brief Get extra data associated with this derived type.
561 /// Class type for pointer-to-members, objective-c property node for ivars,
562 /// or global constant wrapper for static members.
564 /// TODO: Separate out types that need this extra operand: pointer-to-member
565 /// types and member fields (static members and ivars).
566 Metadata *getExtraData() const { return getOperand(4); }
568 static bool classof(const Metadata *MD) {
569 return MD->getMetadataID() == MDDerivedTypeKind;
573 /// \brief Base class for MDCompositeType and MDSubroutineType.
575 /// TODO: Delete; they're not really related.
576 class MDCompositeTypeBase : public MDDerivedTypeBase {
577 unsigned RuntimeLang;
580 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
581 unsigned Tag, unsigned Line, unsigned RuntimeLang,
582 uint64_t SizeInBits, uint64_t AlignInBits,
583 uint64_t OffsetInBits, unsigned Flags,
584 ArrayRef<Metadata *> Ops)
585 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
586 OffsetInBits, Flags, Ops),
587 RuntimeLang(RuntimeLang) {}
588 ~MDCompositeTypeBase() {}
591 Metadata *getElements() const { return getOperand(4); }
592 Metadata *getVTableHolder() const { return getOperand(5); }
593 Metadata *getTemplateParams() const { return getOperand(6); }
594 StringRef getIdentifier() const { return getStringOperand(7); }
595 unsigned getRuntimeLang() const { return RuntimeLang; }
597 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
599 /// \brief Replace operands.
601 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
602 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
603 /// of its movement if necessary.
605 void replaceElements(MDTuple *Elements) {
607 if (auto *Old = cast_or_null<MDTuple>(getElements()))
608 for (const auto &Op : Old->operands())
609 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
610 "Lost a member during member list replacement");
612 replaceOperandWith(4, Elements);
614 void replaceVTableHolder(Metadata *VTableHolder) {
615 replaceOperandWith(5, VTableHolder);
617 void replaceTemplateParams(MDTuple *TemplateParams) {
618 replaceOperandWith(6, TemplateParams);
622 static bool classof(const Metadata *MD) {
623 return MD->getMetadataID() == MDCompositeTypeKind ||
624 MD->getMetadataID() == MDSubroutineTypeKind;
628 /// \brief Composite types.
630 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
631 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
632 class MDCompositeType : public MDCompositeTypeBase {
633 friend class LLVMContextImpl;
636 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
637 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
638 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
639 ArrayRef<Metadata *> Ops)
640 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
641 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
643 ~MDCompositeType() {}
645 static MDCompositeType *
646 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
647 unsigned Line, Metadata *Scope, Metadata *BaseType,
648 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
649 uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
650 Metadata *VTableHolder, Metadata *TemplateParams,
651 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
652 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
653 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
654 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
655 getCanonicalMDString(Context, Identifier), Storage,
658 static MDCompositeType *
659 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
660 unsigned Line, Metadata *Scope, Metadata *BaseType,
661 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
662 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
663 Metadata *VTableHolder, Metadata *TemplateParams,
664 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
666 TempMDCompositeType cloneImpl() const {
667 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
668 getScope(), getBaseType(), getSizeInBits(),
669 getAlignInBits(), getOffsetInBits(), getFlags(),
670 getElements(), getRuntimeLang(), getVTableHolder(),
671 getTemplateParams(), getIdentifier());
675 DEFINE_MDNODE_GET(MDCompositeType,
676 (unsigned Tag, StringRef Name, Metadata *File,
677 unsigned Line, Metadata *Scope, Metadata *BaseType,
678 uint64_t SizeInBits, uint64_t AlignInBits,
679 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
680 unsigned RuntimeLang, Metadata *VTableHolder,
681 Metadata *TemplateParams = nullptr,
682 StringRef Identifier = ""),
683 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
684 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
685 VTableHolder, TemplateParams, Identifier))
686 DEFINE_MDNODE_GET(MDCompositeType,
687 (unsigned Tag, MDString *Name, Metadata *File,
688 unsigned Line, Metadata *Scope, Metadata *BaseType,
689 uint64_t SizeInBits, uint64_t AlignInBits,
690 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
691 unsigned RuntimeLang, Metadata *VTableHolder,
692 Metadata *TemplateParams = nullptr,
693 MDString *Identifier = nullptr),
694 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
695 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
696 VTableHolder, TemplateParams, Identifier))
698 TempMDCompositeType clone() const { return cloneImpl(); }
700 static bool classof(const Metadata *MD) {
701 return MD->getMetadataID() == MDCompositeTypeKind;
705 /// \brief Type array for a subprogram.
707 /// TODO: Detach from CompositeType, and fold the array of types in directly
709 class MDSubroutineType : public MDCompositeTypeBase {
710 friend class LLVMContextImpl;
713 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
714 ArrayRef<Metadata *> Ops)
715 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
716 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
718 ~MDSubroutineType() {}
720 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
721 Metadata *TypeArray, StorageType Storage,
722 bool ShouldCreate = true);
724 TempMDSubroutineType cloneImpl() const {
725 return getTemporary(getContext(), getFlags(), getTypeArray());
729 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
732 TempMDSubroutineType clone() const { return cloneImpl(); }
734 Metadata *getTypeArray() const { return getElements(); }
736 static bool classof(const Metadata *MD) {
737 return MD->getMetadataID() == MDSubroutineTypeKind;
743 /// TODO: Merge with directory/file node (including users).
744 /// TODO: Canonicalize paths on creation.
745 class MDFile : public MDScope {
746 friend class LLVMContextImpl;
749 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
750 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
753 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
754 StringRef Directory, StorageType Storage,
755 bool ShouldCreate = true) {
756 return getImpl(Context, getCanonicalMDString(Context, Filename),
757 getCanonicalMDString(Context, Directory), Storage,
760 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
761 MDString *Directory, StorageType Storage,
762 bool ShouldCreate = true);
764 TempMDFile cloneImpl() const {
765 return getTemporary(getContext(), getFilename(), getDirectory());
769 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
770 (Filename, Directory))
771 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
772 (Filename, Directory))
774 TempMDFile clone() const { return cloneImpl(); }
776 StringRef getFilename() const { return getStringOperand(0); }
777 StringRef getDirectory() const { return getStringOperand(1); }
779 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
780 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
782 static bool classof(const Metadata *MD) {
783 return MD->getMetadataID() == MDFileKind;
787 /// \brief Compile unit.
788 class MDCompileUnit : public MDScope {
789 friend class LLVMContextImpl;
792 unsigned SourceLanguage;
794 unsigned RuntimeVersion;
795 unsigned EmissionKind;
797 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
798 bool IsOptimized, unsigned RuntimeVersion,
799 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
800 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
801 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
802 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
805 static MDCompileUnit *
806 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
807 StringRef Producer, bool IsOptimized, StringRef Flags,
808 unsigned RuntimeVersion, StringRef SplitDebugFilename,
809 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
810 Metadata *Subprograms, Metadata *GlobalVariables,
811 Metadata *ImportedEntities, StorageType Storage,
812 bool ShouldCreate = true) {
813 return getImpl(Context, SourceLanguage, File,
814 getCanonicalMDString(Context, Producer), IsOptimized,
815 getCanonicalMDString(Context, Flags), RuntimeVersion,
816 getCanonicalMDString(Context, SplitDebugFilename),
817 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
818 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
820 static MDCompileUnit *
821 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
822 MDString *Producer, bool IsOptimized, MDString *Flags,
823 unsigned RuntimeVersion, MDString *SplitDebugFilename,
824 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
825 Metadata *Subprograms, Metadata *GlobalVariables,
826 Metadata *ImportedEntities, StorageType Storage,
827 bool ShouldCreate = true);
829 TempMDCompileUnit cloneImpl() const {
831 getContext(), getSourceLanguage(), getFile(), getProducer(),
832 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
833 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
834 getGlobalVariables(), getImportedEntities());
838 DEFINE_MDNODE_GET(MDCompileUnit,
839 (unsigned SourceLanguage, Metadata *File,
840 StringRef Producer, bool IsOptimized, StringRef Flags,
841 unsigned RuntimeVersion, StringRef SplitDebugFilename,
842 unsigned EmissionKind, Metadata *EnumTypes,
843 Metadata *RetainedTypes, Metadata *Subprograms,
844 Metadata *GlobalVariables, Metadata *ImportedEntities),
845 (SourceLanguage, File, Producer, IsOptimized, Flags,
846 RuntimeVersion, SplitDebugFilename, EmissionKind,
847 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
849 DEFINE_MDNODE_GET(MDCompileUnit,
850 (unsigned SourceLanguage, Metadata *File,
851 MDString *Producer, bool IsOptimized, MDString *Flags,
852 unsigned RuntimeVersion, MDString *SplitDebugFilename,
853 unsigned EmissionKind, Metadata *EnumTypes,
854 Metadata *RetainedTypes, Metadata *Subprograms,
855 Metadata *GlobalVariables, Metadata *ImportedEntities),
856 (SourceLanguage, File, Producer, IsOptimized, Flags,
857 RuntimeVersion, SplitDebugFilename, EmissionKind,
858 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
861 TempMDCompileUnit clone() const { return cloneImpl(); }
863 unsigned getSourceLanguage() const { return SourceLanguage; }
864 bool isOptimized() const { return IsOptimized; }
865 unsigned getRuntimeVersion() const { return RuntimeVersion; }
866 unsigned getEmissionKind() const { return EmissionKind; }
867 StringRef getProducer() const { return getStringOperand(1); }
868 StringRef getFlags() const { return getStringOperand(2); }
869 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
870 Metadata *getEnumTypes() const { return getOperand(4); }
871 Metadata *getRetainedTypes() const { return getOperand(5); }
872 Metadata *getSubprograms() const { return getOperand(6); }
873 Metadata *getGlobalVariables() const { return getOperand(7); }
874 Metadata *getImportedEntities() const { return getOperand(8); }
876 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
877 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
878 MDString *getRawSplitDebugFilename() const {
879 return getOperandAs<MDString>(3);
882 /// \brief Replace arrays.
884 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
885 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
886 /// MDCompileUnit should be fairly rare.
888 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
889 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
892 static bool classof(const Metadata *MD) {
893 return MD->getMetadataID() == MDCompileUnitKind;
897 /// \brief A scope for locals.
899 /// A legal scope for lexical blocks, local variables, and debug info
900 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
901 /// MDLexicalBlockFile.
902 class MDLocalScope : public MDScope {
904 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
905 ArrayRef<Metadata *> Ops)
906 : MDScope(C, ID, Storage, Tag, Ops) {}
910 static bool classof(const Metadata *MD) {
911 return MD->getMetadataID() == MDSubprogramKind ||
912 MD->getMetadataID() == MDLexicalBlockKind ||
913 MD->getMetadataID() == MDLexicalBlockFileKind;
917 /// \brief Subprogram description.
919 /// TODO: Remove DisplayName. It's always equal to Name.
920 /// TODO: Split up flags.
921 class MDSubprogram : public MDLocalScope {
922 friend class LLVMContextImpl;
928 unsigned VirtualIndex;
934 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
935 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
936 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
937 bool IsOptimized, ArrayRef<Metadata *> Ops)
938 : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
940 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
941 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
942 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
945 static MDSubprogram *
946 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
947 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
948 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
949 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
950 unsigned Flags, bool IsOptimized, Metadata *Function,
951 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
952 StorageType Storage, bool ShouldCreate = true) {
953 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
954 getCanonicalMDString(Context, LinkageName), File, Line, Type,
955 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
956 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
957 TemplateParams, Declaration, Variables, Storage,
960 static MDSubprogram *
961 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
962 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
963 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
964 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
965 unsigned Flags, bool IsOptimized, Metadata *Function,
966 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
967 StorageType Storage, bool ShouldCreate = true);
969 TempMDSubprogram cloneImpl() const {
970 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
971 getFile(), getLine(), getType(), isLocalToUnit(),
972 isDefinition(), getScopeLine(), getContainingType(),
973 getVirtuality(), getVirtualIndex(), getFlags(),
974 isOptimized(), getFunction(), getTemplateParams(),
975 getDeclaration(), getVariables());
981 (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
982 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
983 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
984 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
985 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
986 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
987 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
988 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
989 Function, TemplateParams, Declaration, Variables))
992 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
993 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
994 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
995 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
996 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
997 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
998 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
999 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1000 Function, TemplateParams, Declaration, Variables))
1002 TempMDSubprogram clone() const { return cloneImpl(); }
1005 unsigned getLine() const { return Line; }
1006 unsigned getVirtuality() const { return Virtuality; }
1007 unsigned getVirtualIndex() const { return VirtualIndex; }
1008 unsigned getScopeLine() const { return ScopeLine; }
1009 unsigned getFlags() const { return Flags; }
1010 bool isLocalToUnit() const { return IsLocalToUnit; }
1011 bool isDefinition() const { return IsDefinition; }
1012 bool isOptimized() const { return IsOptimized; }
1014 Metadata *getScope() const { return getOperand(1); }
1016 StringRef getName() const { return getStringOperand(2); }
1017 StringRef getDisplayName() const { return getStringOperand(3); }
1018 StringRef getLinkageName() const { return getStringOperand(4); }
1020 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1021 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1023 Metadata *getType() const { return getOperand(5); }
1024 Metadata *getContainingType() const { return getOperand(6); }
1026 Metadata *getFunction() const { return getOperand(7); }
1027 Metadata *getTemplateParams() const { return getOperand(8); }
1028 Metadata *getDeclaration() const { return getOperand(9); }
1029 Metadata *getVariables() const { return getOperand(10); }
1031 /// \brief Replace the function.
1033 /// If \a isUniqued() and not \a isResolved(), this could node will be
1034 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1035 /// that's a problem.
1037 void replaceFunction(Function *F);
1038 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1039 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1042 static bool classof(const Metadata *MD) {
1043 return MD->getMetadataID() == MDSubprogramKind;
1047 class MDLexicalBlockBase : public MDLocalScope {
1049 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1050 ArrayRef<Metadata *> Ops)
1051 : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1052 ~MDLexicalBlockBase() {}
1055 Metadata *getScope() const { return getOperand(1); }
1057 static bool classof(const Metadata *MD) {
1058 return MD->getMetadataID() == MDLexicalBlockKind ||
1059 MD->getMetadataID() == MDLexicalBlockFileKind;
1063 class MDLexicalBlock : public MDLexicalBlockBase {
1064 friend class LLVMContextImpl;
1065 friend class MDNode;
1070 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1071 unsigned Column, ArrayRef<Metadata *> Ops)
1072 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1074 ~MDLexicalBlock() {}
1076 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1077 Metadata *File, unsigned Line, unsigned Column,
1078 StorageType Storage, bool ShouldCreate = true);
1080 TempMDLexicalBlock cloneImpl() const {
1081 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1086 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1087 unsigned Line, unsigned Column),
1088 (Scope, File, Line, Column))
1090 TempMDLexicalBlock clone() const { return cloneImpl(); }
1092 unsigned getLine() const { return Line; }
1093 unsigned getColumn() const { return Column; }
1095 static bool classof(const Metadata *MD) {
1096 return MD->getMetadataID() == MDLexicalBlockKind;
1100 class MDLexicalBlockFile : public MDLexicalBlockBase {
1101 friend class LLVMContextImpl;
1102 friend class MDNode;
1104 unsigned Discriminator;
1106 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1107 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1108 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1109 Discriminator(Discriminator) {}
1110 ~MDLexicalBlockFile() {}
1112 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1113 Metadata *File, unsigned Discriminator,
1114 StorageType Storage,
1115 bool ShouldCreate = true);
1117 TempMDLexicalBlockFile cloneImpl() const {
1118 return getTemporary(getContext(), getScope(), getFile(),
1119 getDiscriminator());
1123 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1124 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1125 (Scope, File, Discriminator))
1127 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1129 unsigned getDiscriminator() const { return Discriminator; }
1131 static bool classof(const Metadata *MD) {
1132 return MD->getMetadataID() == MDLexicalBlockFileKind;
1136 class MDNamespace : public MDScope {
1137 friend class LLVMContextImpl;
1138 friend class MDNode;
1142 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1143 ArrayRef<Metadata *> Ops)
1144 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1149 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1150 Metadata *File, StringRef Name, unsigned Line,
1151 StorageType Storage, bool ShouldCreate = true) {
1152 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1153 Line, Storage, ShouldCreate);
1155 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1156 Metadata *File, MDString *Name, unsigned Line,
1157 StorageType Storage, bool ShouldCreate = true);
1159 TempMDNamespace cloneImpl() const {
1160 return getTemporary(getContext(), getScope(), getFile(), getName(),
1165 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1166 StringRef Name, unsigned Line),
1167 (Scope, File, Name, Line))
1168 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1169 MDString *Name, unsigned Line),
1170 (Scope, File, Name, Line))
1172 TempMDNamespace clone() const { return cloneImpl(); }
1174 unsigned getLine() const { return Line; }
1175 Metadata *getScope() const { return getOperand(1); }
1176 StringRef getName() const { return getStringOperand(2); }
1178 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1180 static bool classof(const Metadata *MD) {
1181 return MD->getMetadataID() == MDNamespaceKind;
1185 /// \brief Base class for template parameters.
1186 class MDTemplateParameter : public DebugNode {
1188 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1189 unsigned Tag, ArrayRef<Metadata *> Ops)
1190 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1191 ~MDTemplateParameter() {}
1194 StringRef getName() const { return getStringOperand(0); }
1195 Metadata *getType() const { return getOperand(1); }
1197 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1199 static bool classof(const Metadata *MD) {
1200 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1201 MD->getMetadataID() == MDTemplateValueParameterKind;
1205 class MDTemplateTypeParameter : public MDTemplateParameter {
1206 friend class LLVMContextImpl;
1207 friend class MDNode;
1209 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1210 ArrayRef<Metadata *> Ops)
1211 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1212 dwarf::DW_TAG_template_type_parameter, Ops) {}
1213 ~MDTemplateTypeParameter() {}
1215 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1216 Metadata *Type, StorageType Storage,
1217 bool ShouldCreate = true) {
1218 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1221 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1222 Metadata *Type, StorageType Storage,
1223 bool ShouldCreate = true);
1225 TempMDTemplateTypeParameter cloneImpl() const {
1226 return getTemporary(getContext(), getName(), getType());
1230 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1232 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1235 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1237 static bool classof(const Metadata *MD) {
1238 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1242 class MDTemplateValueParameter : public MDTemplateParameter {
1243 friend class LLVMContextImpl;
1244 friend class MDNode;
1246 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1247 unsigned Tag, ArrayRef<Metadata *> Ops)
1248 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1250 ~MDTemplateValueParameter() {}
1252 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1253 StringRef Name, Metadata *Type,
1254 Metadata *Value, StorageType Storage,
1255 bool ShouldCreate = true) {
1256 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1257 Value, Storage, ShouldCreate);
1259 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1260 MDString *Name, Metadata *Type,
1261 Metadata *Value, StorageType Storage,
1262 bool ShouldCreate = true);
1264 TempMDTemplateValueParameter cloneImpl() const {
1265 return getTemporary(getContext(), getTag(), getName(), getType(),
1270 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1271 Metadata *Type, Metadata *Value),
1272 (Tag, Name, Type, Value))
1273 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1274 Metadata *Type, Metadata *Value),
1275 (Tag, Name, Type, Value))
1277 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1279 Metadata *getValue() const { return getOperand(2); }
1281 static bool classof(const Metadata *MD) {
1282 return MD->getMetadataID() == MDTemplateValueParameterKind;
1286 /// \brief Base class for variables.
1288 /// TODO: Hardcode to DW_TAG_variable.
1289 class MDVariable : public DebugNode {
1293 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1294 unsigned Line, ArrayRef<Metadata *> Ops)
1295 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1299 unsigned getLine() const { return Line; }
1300 Metadata *getScope() const { return getOperand(0); }
1301 StringRef getName() const { return getStringOperand(1); }
1302 Metadata *getFile() const { return getOperand(2); }
1303 Metadata *getType() const { return getOperand(3); }
1305 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1307 static bool classof(const Metadata *MD) {
1308 return MD->getMetadataID() == MDLocalVariableKind ||
1309 MD->getMetadataID() == MDGlobalVariableKind;
1313 /// \brief Global variables.
1315 /// TODO: Remove DisplayName. It's always equal to Name.
1316 class MDGlobalVariable : public MDVariable {
1317 friend class LLVMContextImpl;
1318 friend class MDNode;
1323 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1324 bool IsLocalToUnit, bool IsDefinition,
1325 ArrayRef<Metadata *> Ops)
1326 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1328 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1329 ~MDGlobalVariable() {}
1331 static MDGlobalVariable *
1332 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1333 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1334 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1335 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1336 bool ShouldCreate = true) {
1337 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1338 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1339 IsLocalToUnit, IsDefinition, Variable,
1340 StaticDataMemberDeclaration, Storage, ShouldCreate);
1342 static MDGlobalVariable *
1343 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1344 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1345 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1346 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1347 bool ShouldCreate = true);
1349 TempMDGlobalVariable cloneImpl() const {
1350 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1351 getFile(), getLine(), getType(), isLocalToUnit(),
1352 isDefinition(), getVariable(),
1353 getStaticDataMemberDeclaration());
1357 DEFINE_MDNODE_GET(MDGlobalVariable,
1358 (Metadata * Scope, StringRef Name, StringRef LinkageName,
1359 Metadata *File, unsigned Line, Metadata *Type,
1360 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1361 Metadata *StaticDataMemberDeclaration),
1362 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1363 IsDefinition, Variable, StaticDataMemberDeclaration))
1364 DEFINE_MDNODE_GET(MDGlobalVariable,
1365 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1366 Metadata *File, unsigned Line, Metadata *Type,
1367 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1368 Metadata *StaticDataMemberDeclaration),
1369 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1370 IsDefinition, Variable, StaticDataMemberDeclaration))
1372 TempMDGlobalVariable clone() const { return cloneImpl(); }
1374 bool isLocalToUnit() const { return IsLocalToUnit; }
1375 bool isDefinition() const { return IsDefinition; }
1376 StringRef getDisplayName() const { return getStringOperand(4); }
1377 StringRef getLinkageName() const { return getStringOperand(5); }
1378 Metadata *getVariable() const { return getOperand(6); }
1379 Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1381 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1383 static bool classof(const Metadata *MD) {
1384 return MD->getMetadataID() == MDGlobalVariableKind;
1388 /// \brief Local variable.
1390 /// TODO: Split between arguments and otherwise.
1391 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1392 /// TODO: Split up flags.
1393 class MDLocalVariable : public MDVariable {
1394 friend class LLVMContextImpl;
1395 friend class MDNode;
1400 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1401 unsigned Line, unsigned Arg, unsigned Flags,
1402 ArrayRef<Metadata *> Ops)
1403 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1405 ~MDLocalVariable() {}
1407 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1408 Metadata *Scope, StringRef Name,
1409 Metadata *File, unsigned Line, Metadata *Type,
1410 unsigned Arg, unsigned Flags,
1411 Metadata *InlinedAt, StorageType Storage,
1412 bool ShouldCreate = true) {
1413 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1414 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1417 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1418 Metadata *Scope, MDString *Name,
1419 Metadata *File, unsigned Line, Metadata *Type,
1420 unsigned Arg, unsigned Flags,
1421 Metadata *InlinedAt, StorageType Storage,
1422 bool ShouldCreate = true);
1424 TempMDLocalVariable cloneImpl() const {
1425 return getTemporary(getContext(), getTag(), getScope(), getName(),
1426 getFile(), getLine(), getType(), getArg(), getFlags(),
1431 DEFINE_MDNODE_GET(MDLocalVariable,
1432 (unsigned Tag, Metadata *Scope, StringRef Name,
1433 Metadata *File, unsigned Line, Metadata *Type,
1434 unsigned Arg, unsigned Flags,
1435 Metadata *InlinedAt = nullptr),
1436 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1437 DEFINE_MDNODE_GET(MDLocalVariable,
1438 (unsigned Tag, Metadata *Scope, MDString *Name,
1439 Metadata *File, unsigned Line, Metadata *Type,
1440 unsigned Arg, unsigned Flags,
1441 Metadata *InlinedAt = nullptr),
1442 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1444 TempMDLocalVariable clone() const { return cloneImpl(); }
1446 unsigned getArg() const { return Arg; }
1447 unsigned getFlags() const { return Flags; }
1448 Metadata *getInlinedAt() const { return getOperand(4); }
1450 /// \brief Get an inlined version of this variable.
1452 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1453 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1454 if (InlinedAt == getInlinedAt())
1455 return const_cast<MDLocalVariable *>(this);
1456 auto Temp = clone();
1457 Temp->replaceOperandWith(4, InlinedAt);
1458 return replaceWithUniqued(std::move(Temp));
1460 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1462 static bool classof(const Metadata *MD) {
1463 return MD->getMetadataID() == MDLocalVariableKind;
1467 /// \brief DWARF expression.
1469 /// TODO: Co-allocate the expression elements.
1470 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1472 class MDExpression : public MDNode {
1473 friend class LLVMContextImpl;
1474 friend class MDNode;
1476 std::vector<uint64_t> Elements;
1478 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1479 : MDNode(C, MDExpressionKind, Storage, None),
1480 Elements(Elements.begin(), Elements.end()) {}
1483 static MDExpression *getImpl(LLVMContext &Context,
1484 ArrayRef<uint64_t> Elements, StorageType Storage,
1485 bool ShouldCreate = true);
1487 TempMDExpression cloneImpl() const {
1488 return getTemporary(getContext(), getElements());
1492 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1494 TempMDExpression clone() const { return cloneImpl(); }
1496 ArrayRef<uint64_t> getElements() const { return Elements; }
1498 unsigned getNumElements() const { return Elements.size(); }
1499 uint64_t getElement(unsigned I) const {
1500 assert(I < Elements.size() && "Index out of range");
1504 typedef ArrayRef<uint64_t>::iterator element_iterator;
1505 element_iterator elements_begin() const { return getElements().begin(); }
1506 element_iterator elements_end() const { return getElements().end(); }
1508 /// \brief A lightweight wrapper around an expression operand.
1510 /// TODO: Store arguments directly and change \a MDExpression to store a
1516 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1518 const uint64_t *get() const { return Op; }
1520 /// \brief Get the operand code.
1521 uint64_t getOp() const { return *Op; }
1523 /// \brief Get an argument to the operand.
1525 /// Never returns the operand itself.
1526 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1528 unsigned getNumArgs() const { return getSize() - 1; }
1530 /// \brief Return the size of the operand.
1532 /// Return the number of elements in the operand (1 + args).
1533 unsigned getSize() const;
1536 /// \brief An iterator for expression operands.
1537 class expr_op_iterator
1538 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1542 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1544 element_iterator getBase() const { return Op.get(); }
1545 const ExprOperand &operator*() const { return Op; }
1546 const ExprOperand *operator->() const { return &Op; }
1548 expr_op_iterator &operator++() {
1552 expr_op_iterator operator++(int) {
1553 expr_op_iterator T(*this);
1558 bool operator==(const expr_op_iterator &X) const {
1559 return getBase() == X.getBase();
1561 bool operator!=(const expr_op_iterator &X) const {
1562 return getBase() != X.getBase();
1566 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1569 /// \brief Visit the elements via ExprOperand wrappers.
1571 /// These range iterators visit elements through \a ExprOperand wrappers.
1572 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1575 /// \pre \a isValid() gives \c true.
1577 expr_op_iterator expr_op_begin() const {
1578 return expr_op_iterator(elements_begin());
1580 expr_op_iterator expr_op_end() const {
1581 return expr_op_iterator(elements_end());
1585 bool isValid() const;
1587 static bool classof(const Metadata *MD) {
1588 return MD->getMetadataID() == MDExpressionKind;
1592 class MDObjCProperty : public DebugNode {
1593 friend class LLVMContextImpl;
1594 friend class MDNode;
1597 unsigned Attributes;
1599 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1600 unsigned Attributes, ArrayRef<Metadata *> Ops)
1601 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1603 Line(Line), Attributes(Attributes) {}
1604 ~MDObjCProperty() {}
1606 static MDObjCProperty *
1607 getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1608 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1609 Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1610 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1611 getCanonicalMDString(Context, GetterName),
1612 getCanonicalMDString(Context, SetterName), Attributes, Type,
1613 Storage, ShouldCreate);
1615 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1616 Metadata *File, unsigned Line,
1617 MDString *GetterName, MDString *SetterName,
1618 unsigned Attributes, Metadata *Type,
1619 StorageType Storage, bool ShouldCreate = true);
1621 TempMDObjCProperty cloneImpl() const {
1622 return getTemporary(getContext(), getName(), getFile(), getLine(),
1623 getGetterName(), getSetterName(), getAttributes(),
1628 DEFINE_MDNODE_GET(MDObjCProperty,
1629 (StringRef Name, Metadata *File, unsigned Line,
1630 StringRef GetterName, StringRef SetterName,
1631 unsigned Attributes, Metadata *Type),
1632 (Name, File, Line, GetterName, SetterName, Attributes,
1634 DEFINE_MDNODE_GET(MDObjCProperty,
1635 (MDString * Name, Metadata *File, unsigned Line,
1636 MDString *GetterName, MDString *SetterName,
1637 unsigned Attributes, Metadata *Type),
1638 (Name, File, Line, GetterName, SetterName, Attributes,
1641 TempMDObjCProperty clone() const { return cloneImpl(); }
1643 unsigned getLine() const { return Line; }
1644 unsigned getAttributes() const { return Attributes; }
1645 StringRef getName() const { return getStringOperand(0); }
1646 Metadata *getFile() const { return getOperand(1); }
1647 StringRef getGetterName() const { return getStringOperand(2); }
1648 StringRef getSetterName() const { return getStringOperand(3); }
1649 Metadata *getType() const { return getOperand(4); }
1651 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1652 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1653 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1655 static bool classof(const Metadata *MD) {
1656 return MD->getMetadataID() == MDObjCPropertyKind;
1660 class MDImportedEntity : public DebugNode {
1661 friend class LLVMContextImpl;
1662 friend class MDNode;
1666 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1667 unsigned Line, ArrayRef<Metadata *> Ops)
1668 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1669 ~MDImportedEntity() {}
1671 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1672 Metadata *Scope, Metadata *Entity,
1673 unsigned Line, StringRef Name,
1674 StorageType Storage,
1675 bool ShouldCreate = true) {
1676 return getImpl(Context, Tag, Scope, Entity, Line,
1677 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1679 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1680 Metadata *Scope, Metadata *Entity,
1681 unsigned Line, MDString *Name,
1682 StorageType Storage,
1683 bool ShouldCreate = true);
1685 TempMDImportedEntity cloneImpl() const {
1686 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1687 getLine(), getName());
1691 DEFINE_MDNODE_GET(MDImportedEntity,
1692 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1693 unsigned Line, StringRef Name = ""),
1694 (Tag, Scope, Entity, Line, Name))
1695 DEFINE_MDNODE_GET(MDImportedEntity,
1696 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1697 unsigned Line, MDString *Name),
1698 (Tag, Scope, Entity, Line, Name))
1700 TempMDImportedEntity clone() const { return cloneImpl(); }
1702 unsigned getLine() const { return Line; }
1703 Metadata *getScope() const { return getOperand(0); }
1704 Metadata *getEntity() const { return getOperand(1); }
1705 StringRef getName() const { return getStringOperand(2); }
1707 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1709 static bool classof(const Metadata *MD) {
1710 return MD->getMetadataID() == MDImportedEntityKind;
1714 } // end namespace llvm
1716 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1717 #undef DEFINE_MDNODE_GET_UNPACK
1718 #undef DEFINE_MDNODE_GET