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 Subprogram description.
899 /// TODO: Remove DisplayName. It's always equal to Name.
900 /// TODO: Split up flags.
901 class MDSubprogram : public MDScope {
902 friend class LLVMContextImpl;
908 unsigned VirtualIndex;
914 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
915 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
916 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
917 bool IsOptimized, ArrayRef<Metadata *> Ops)
918 : MDScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
919 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
920 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
921 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
924 static MDSubprogram *
925 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
926 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
927 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
928 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
929 unsigned Flags, bool IsOptimized, Metadata *Function,
930 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
931 StorageType Storage, bool ShouldCreate = true) {
932 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
933 getCanonicalMDString(Context, LinkageName), File, Line, Type,
934 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
935 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
936 TemplateParams, Declaration, Variables, Storage,
939 static MDSubprogram *
940 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
941 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
942 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
943 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
944 unsigned Flags, bool IsOptimized, Metadata *Function,
945 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
946 StorageType Storage, bool ShouldCreate = true);
948 TempMDSubprogram cloneImpl() const {
949 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
950 getFile(), getLine(), getType(), isLocalToUnit(),
951 isDefinition(), getScopeLine(), getContainingType(),
952 getVirtuality(), getVirtualIndex(), getFlags(),
953 isOptimized(), getFunction(), getTemplateParams(),
954 getDeclaration(), getVariables());
960 (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
961 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
962 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
963 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
964 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
965 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
966 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
967 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
968 Function, TemplateParams, Declaration, Variables))
971 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
972 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
973 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
974 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
975 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
976 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
977 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
978 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
979 Function, TemplateParams, Declaration, Variables))
981 TempMDSubprogram clone() const { return cloneImpl(); }
984 unsigned getLine() const { return Line; }
985 unsigned getVirtuality() const { return Virtuality; }
986 unsigned getVirtualIndex() const { return VirtualIndex; }
987 unsigned getScopeLine() const { return ScopeLine; }
988 unsigned getFlags() const { return Flags; }
989 bool isLocalToUnit() const { return IsLocalToUnit; }
990 bool isDefinition() const { return IsDefinition; }
991 bool isOptimized() const { return IsOptimized; }
993 Metadata *getScope() const { return getOperand(1); }
995 StringRef getName() const { return getStringOperand(2); }
996 StringRef getDisplayName() const { return getStringOperand(3); }
997 StringRef getLinkageName() const { return getStringOperand(4); }
999 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1000 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1002 Metadata *getType() const { return getOperand(5); }
1003 Metadata *getContainingType() const { return getOperand(6); }
1005 Metadata *getFunction() const { return getOperand(7); }
1006 Metadata *getTemplateParams() const { return getOperand(8); }
1007 Metadata *getDeclaration() const { return getOperand(9); }
1008 Metadata *getVariables() const { return getOperand(10); }
1010 /// \brief Replace the function.
1012 /// If \a isUniqued() and not \a isResolved(), this could node will be
1013 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1014 /// that's a problem.
1016 void replaceFunction(Function *F);
1017 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1018 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1021 static bool classof(const Metadata *MD) {
1022 return MD->getMetadataID() == MDSubprogramKind;
1026 class MDLexicalBlockBase : public MDScope {
1028 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1029 ArrayRef<Metadata *> Ops)
1030 : MDScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1031 ~MDLexicalBlockBase() {}
1034 Metadata *getScope() const { return getOperand(1); }
1036 static bool classof(const Metadata *MD) {
1037 return MD->getMetadataID() == MDLexicalBlockKind ||
1038 MD->getMetadataID() == MDLexicalBlockFileKind;
1042 class MDLexicalBlock : public MDLexicalBlockBase {
1043 friend class LLVMContextImpl;
1044 friend class MDNode;
1049 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1050 unsigned Column, ArrayRef<Metadata *> Ops)
1051 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1053 ~MDLexicalBlock() {}
1055 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1056 Metadata *File, unsigned Line, unsigned Column,
1057 StorageType Storage, bool ShouldCreate = true);
1059 TempMDLexicalBlock cloneImpl() const {
1060 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1065 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1066 unsigned Line, unsigned Column),
1067 (Scope, File, Line, Column))
1069 TempMDLexicalBlock clone() const { return cloneImpl(); }
1071 unsigned getLine() const { return Line; }
1072 unsigned getColumn() const { return Column; }
1074 static bool classof(const Metadata *MD) {
1075 return MD->getMetadataID() == MDLexicalBlockKind;
1079 class MDLexicalBlockFile : public MDLexicalBlockBase {
1080 friend class LLVMContextImpl;
1081 friend class MDNode;
1083 unsigned Discriminator;
1085 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1086 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1087 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1088 Discriminator(Discriminator) {}
1089 ~MDLexicalBlockFile() {}
1091 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1092 Metadata *File, unsigned Discriminator,
1093 StorageType Storage,
1094 bool ShouldCreate = true);
1096 TempMDLexicalBlockFile cloneImpl() const {
1097 return getTemporary(getContext(), getScope(), getFile(),
1098 getDiscriminator());
1102 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1103 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1104 (Scope, File, Discriminator))
1106 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1108 unsigned getDiscriminator() const { return Discriminator; }
1110 static bool classof(const Metadata *MD) {
1111 return MD->getMetadataID() == MDLexicalBlockFileKind;
1115 class MDNamespace : public MDScope {
1116 friend class LLVMContextImpl;
1117 friend class MDNode;
1121 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1122 ArrayRef<Metadata *> Ops)
1123 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1128 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1129 Metadata *File, StringRef Name, unsigned Line,
1130 StorageType Storage, bool ShouldCreate = true) {
1131 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1132 Line, Storage, ShouldCreate);
1134 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1135 Metadata *File, MDString *Name, unsigned Line,
1136 StorageType Storage, bool ShouldCreate = true);
1138 TempMDNamespace cloneImpl() const {
1139 return getTemporary(getContext(), getScope(), getFile(), getName(),
1144 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1145 StringRef Name, unsigned Line),
1146 (Scope, File, Name, Line))
1147 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1148 MDString *Name, unsigned Line),
1149 (Scope, File, Name, Line))
1151 TempMDNamespace clone() const { return cloneImpl(); }
1153 unsigned getLine() const { return Line; }
1154 Metadata *getScope() const { return getOperand(1); }
1155 StringRef getName() const { return getStringOperand(2); }
1157 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1159 static bool classof(const Metadata *MD) {
1160 return MD->getMetadataID() == MDNamespaceKind;
1164 /// \brief Base class for template parameters.
1165 class MDTemplateParameter : public DebugNode {
1167 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1168 unsigned Tag, ArrayRef<Metadata *> Ops)
1169 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1170 ~MDTemplateParameter() {}
1173 StringRef getName() const { return getStringOperand(0); }
1174 Metadata *getType() const { return getOperand(1); }
1176 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1178 static bool classof(const Metadata *MD) {
1179 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1180 MD->getMetadataID() == MDTemplateValueParameterKind;
1184 class MDTemplateTypeParameter : public MDTemplateParameter {
1185 friend class LLVMContextImpl;
1186 friend class MDNode;
1188 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1189 ArrayRef<Metadata *> Ops)
1190 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1191 dwarf::DW_TAG_template_type_parameter, Ops) {}
1192 ~MDTemplateTypeParameter() {}
1194 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1195 Metadata *Type, StorageType Storage,
1196 bool ShouldCreate = true) {
1197 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1200 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1201 Metadata *Type, StorageType Storage,
1202 bool ShouldCreate = true);
1204 TempMDTemplateTypeParameter cloneImpl() const {
1205 return getTemporary(getContext(), getName(), getType());
1209 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1211 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1214 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1216 static bool classof(const Metadata *MD) {
1217 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1221 class MDTemplateValueParameter : public MDTemplateParameter {
1222 friend class LLVMContextImpl;
1223 friend class MDNode;
1225 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1226 unsigned Tag, ArrayRef<Metadata *> Ops)
1227 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1229 ~MDTemplateValueParameter() {}
1231 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1232 StringRef Name, Metadata *Type,
1233 Metadata *Value, StorageType Storage,
1234 bool ShouldCreate = true) {
1235 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1236 Value, Storage, ShouldCreate);
1238 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1239 MDString *Name, Metadata *Type,
1240 Metadata *Value, StorageType Storage,
1241 bool ShouldCreate = true);
1243 TempMDTemplateValueParameter cloneImpl() const {
1244 return getTemporary(getContext(), getTag(), getName(), getType(),
1249 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1250 Metadata *Type, Metadata *Value),
1251 (Tag, Name, Type, Value))
1252 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1253 Metadata *Type, Metadata *Value),
1254 (Tag, Name, Type, Value))
1256 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1258 Metadata *getValue() const { return getOperand(2); }
1260 static bool classof(const Metadata *MD) {
1261 return MD->getMetadataID() == MDTemplateValueParameterKind;
1265 /// \brief Base class for variables.
1267 /// TODO: Hardcode to DW_TAG_variable.
1268 class MDVariable : public DebugNode {
1272 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1273 unsigned Line, ArrayRef<Metadata *> Ops)
1274 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1278 unsigned getLine() const { return Line; }
1279 Metadata *getScope() const { return getOperand(0); }
1280 StringRef getName() const { return getStringOperand(1); }
1281 Metadata *getFile() const { return getOperand(2); }
1282 Metadata *getType() const { return getOperand(3); }
1284 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1286 static bool classof(const Metadata *MD) {
1287 return MD->getMetadataID() == MDLocalVariableKind ||
1288 MD->getMetadataID() == MDGlobalVariableKind;
1292 /// \brief Global variables.
1294 /// TODO: Remove DisplayName. It's always equal to Name.
1295 class MDGlobalVariable : public MDVariable {
1296 friend class LLVMContextImpl;
1297 friend class MDNode;
1302 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1303 bool IsLocalToUnit, bool IsDefinition,
1304 ArrayRef<Metadata *> Ops)
1305 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1307 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1308 ~MDGlobalVariable() {}
1310 static MDGlobalVariable *
1311 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1312 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1313 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1314 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1315 bool ShouldCreate = true) {
1316 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1317 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1318 IsLocalToUnit, IsDefinition, Variable,
1319 StaticDataMemberDeclaration, Storage, ShouldCreate);
1321 static MDGlobalVariable *
1322 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1323 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1324 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1325 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1326 bool ShouldCreate = true);
1328 TempMDGlobalVariable cloneImpl() const {
1329 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1330 getFile(), getLine(), getType(), isLocalToUnit(),
1331 isDefinition(), getVariable(),
1332 getStaticDataMemberDeclaration());
1336 DEFINE_MDNODE_GET(MDGlobalVariable,
1337 (Metadata * Scope, StringRef Name, StringRef LinkageName,
1338 Metadata *File, unsigned Line, Metadata *Type,
1339 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1340 Metadata *StaticDataMemberDeclaration),
1341 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1342 IsDefinition, Variable, StaticDataMemberDeclaration))
1343 DEFINE_MDNODE_GET(MDGlobalVariable,
1344 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1345 Metadata *File, unsigned Line, Metadata *Type,
1346 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1347 Metadata *StaticDataMemberDeclaration),
1348 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1349 IsDefinition, Variable, StaticDataMemberDeclaration))
1351 TempMDGlobalVariable clone() const { return cloneImpl(); }
1353 bool isLocalToUnit() const { return IsLocalToUnit; }
1354 bool isDefinition() const { return IsDefinition; }
1355 StringRef getDisplayName() const { return getStringOperand(4); }
1356 StringRef getLinkageName() const { return getStringOperand(5); }
1357 Metadata *getVariable() const { return getOperand(6); }
1358 Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1360 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1362 static bool classof(const Metadata *MD) {
1363 return MD->getMetadataID() == MDGlobalVariableKind;
1367 /// \brief Local variable.
1369 /// TODO: Split between arguments and otherwise.
1370 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1371 /// TODO: Split up flags.
1372 class MDLocalVariable : public MDVariable {
1373 friend class LLVMContextImpl;
1374 friend class MDNode;
1379 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1380 unsigned Line, unsigned Arg, unsigned Flags,
1381 ArrayRef<Metadata *> Ops)
1382 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1384 ~MDLocalVariable() {}
1386 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1387 Metadata *Scope, StringRef Name,
1388 Metadata *File, unsigned Line, Metadata *Type,
1389 unsigned Arg, unsigned Flags,
1390 Metadata *InlinedAt, StorageType Storage,
1391 bool ShouldCreate = true) {
1392 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1393 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1396 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1397 Metadata *Scope, MDString *Name,
1398 Metadata *File, unsigned Line, Metadata *Type,
1399 unsigned Arg, unsigned Flags,
1400 Metadata *InlinedAt, StorageType Storage,
1401 bool ShouldCreate = true);
1403 TempMDLocalVariable cloneImpl() const {
1404 return getTemporary(getContext(), getTag(), getScope(), getName(),
1405 getFile(), getLine(), getType(), getArg(), getFlags(),
1410 DEFINE_MDNODE_GET(MDLocalVariable,
1411 (unsigned Tag, Metadata *Scope, StringRef Name,
1412 Metadata *File, unsigned Line, Metadata *Type,
1413 unsigned Arg, unsigned Flags,
1414 Metadata *InlinedAt = nullptr),
1415 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1416 DEFINE_MDNODE_GET(MDLocalVariable,
1417 (unsigned Tag, Metadata *Scope, MDString *Name,
1418 Metadata *File, unsigned Line, Metadata *Type,
1419 unsigned Arg, unsigned Flags,
1420 Metadata *InlinedAt = nullptr),
1421 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1423 TempMDLocalVariable clone() const { return cloneImpl(); }
1425 unsigned getArg() const { return Arg; }
1426 unsigned getFlags() const { return Flags; }
1427 Metadata *getInlinedAt() const { return getOperand(4); }
1429 /// \brief Get an inlined version of this variable.
1431 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1432 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1433 if (InlinedAt == getInlinedAt())
1434 return const_cast<MDLocalVariable *>(this);
1435 auto Temp = clone();
1436 Temp->replaceOperandWith(4, InlinedAt);
1437 return replaceWithUniqued(std::move(Temp));
1439 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1441 static bool classof(const Metadata *MD) {
1442 return MD->getMetadataID() == MDLocalVariableKind;
1446 /// \brief DWARF expression.
1448 /// TODO: Co-allocate the expression elements.
1449 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1451 class MDExpression : public MDNode {
1452 friend class LLVMContextImpl;
1453 friend class MDNode;
1455 std::vector<uint64_t> Elements;
1457 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1458 : MDNode(C, MDExpressionKind, Storage, None),
1459 Elements(Elements.begin(), Elements.end()) {}
1462 static MDExpression *getImpl(LLVMContext &Context,
1463 ArrayRef<uint64_t> Elements, StorageType Storage,
1464 bool ShouldCreate = true);
1466 TempMDExpression cloneImpl() const {
1467 return getTemporary(getContext(), getElements());
1471 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1473 TempMDExpression clone() const { return cloneImpl(); }
1475 ArrayRef<uint64_t> getElements() const { return Elements; }
1477 unsigned getNumElements() const { return Elements.size(); }
1478 uint64_t getElement(unsigned I) const {
1479 assert(I < Elements.size() && "Index out of range");
1483 typedef ArrayRef<uint64_t>::iterator element_iterator;
1484 element_iterator elements_begin() const { return getElements().begin(); }
1485 element_iterator elements_end() const { return getElements().end(); }
1487 /// \brief A lightweight wrapper around an expression operand.
1489 /// TODO: Store arguments directly and change \a MDExpression to store a
1495 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1497 const uint64_t *get() const { return Op; }
1499 /// \brief Get the operand code.
1500 uint64_t getOp() const { return *Op; }
1502 /// \brief Get an argument to the operand.
1504 /// Never returns the operand itself.
1505 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1507 unsigned getNumArgs() const { return getSize() - 1; }
1509 /// \brief Return the size of the operand.
1511 /// Return the number of elements in the operand (1 + args).
1512 unsigned getSize() const;
1515 /// \brief An iterator for expression operands.
1516 class expr_op_iterator
1517 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1521 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1523 element_iterator getBase() const { return Op.get(); }
1524 const ExprOperand &operator*() const { return Op; }
1525 const ExprOperand *operator->() const { return &Op; }
1527 expr_op_iterator &operator++() {
1531 expr_op_iterator operator++(int) {
1532 expr_op_iterator T(*this);
1537 bool operator==(const expr_op_iterator &X) const {
1538 return getBase() == X.getBase();
1540 bool operator!=(const expr_op_iterator &X) const {
1541 return getBase() != X.getBase();
1545 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1548 /// \brief Visit the elements via ExprOperand wrappers.
1550 /// These range iterators visit elements through \a ExprOperand wrappers.
1551 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1554 /// \pre \a isValid() gives \c true.
1556 expr_op_iterator expr_op_begin() const {
1557 return expr_op_iterator(elements_begin());
1559 expr_op_iterator expr_op_end() const {
1560 return expr_op_iterator(elements_end());
1564 bool isValid() const;
1566 static bool classof(const Metadata *MD) {
1567 return MD->getMetadataID() == MDExpressionKind;
1571 class MDObjCProperty : public DebugNode {
1572 friend class LLVMContextImpl;
1573 friend class MDNode;
1576 unsigned Attributes;
1578 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1579 unsigned Attributes, ArrayRef<Metadata *> Ops)
1580 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1582 Line(Line), Attributes(Attributes) {}
1583 ~MDObjCProperty() {}
1585 static MDObjCProperty *
1586 getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1587 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1588 Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1589 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1590 getCanonicalMDString(Context, GetterName),
1591 getCanonicalMDString(Context, SetterName), Attributes, Type,
1592 Storage, ShouldCreate);
1594 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1595 Metadata *File, unsigned Line,
1596 MDString *GetterName, MDString *SetterName,
1597 unsigned Attributes, Metadata *Type,
1598 StorageType Storage, bool ShouldCreate = true);
1600 TempMDObjCProperty cloneImpl() const {
1601 return getTemporary(getContext(), getName(), getFile(), getLine(),
1602 getGetterName(), getSetterName(), getAttributes(),
1607 DEFINE_MDNODE_GET(MDObjCProperty,
1608 (StringRef Name, Metadata *File, unsigned Line,
1609 StringRef GetterName, StringRef SetterName,
1610 unsigned Attributes, Metadata *Type),
1611 (Name, File, Line, GetterName, SetterName, Attributes,
1613 DEFINE_MDNODE_GET(MDObjCProperty,
1614 (MDString * Name, Metadata *File, unsigned Line,
1615 MDString *GetterName, MDString *SetterName,
1616 unsigned Attributes, Metadata *Type),
1617 (Name, File, Line, GetterName, SetterName, Attributes,
1620 TempMDObjCProperty clone() const { return cloneImpl(); }
1622 unsigned getLine() const { return Line; }
1623 unsigned getAttributes() const { return Attributes; }
1624 StringRef getName() const { return getStringOperand(0); }
1625 Metadata *getFile() const { return getOperand(1); }
1626 StringRef getGetterName() const { return getStringOperand(2); }
1627 StringRef getSetterName() const { return getStringOperand(3); }
1628 Metadata *getType() const { return getOperand(4); }
1630 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1631 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1632 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1634 static bool classof(const Metadata *MD) {
1635 return MD->getMetadataID() == MDObjCPropertyKind;
1639 class MDImportedEntity : public DebugNode {
1640 friend class LLVMContextImpl;
1641 friend class MDNode;
1645 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1646 unsigned Line, ArrayRef<Metadata *> Ops)
1647 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1648 ~MDImportedEntity() {}
1650 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1651 Metadata *Scope, Metadata *Entity,
1652 unsigned Line, StringRef Name,
1653 StorageType Storage,
1654 bool ShouldCreate = true) {
1655 return getImpl(Context, Tag, Scope, Entity, Line,
1656 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1658 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1659 Metadata *Scope, Metadata *Entity,
1660 unsigned Line, MDString *Name,
1661 StorageType Storage,
1662 bool ShouldCreate = true);
1664 TempMDImportedEntity cloneImpl() const {
1665 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1666 getLine(), getName());
1670 DEFINE_MDNODE_GET(MDImportedEntity,
1671 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1672 unsigned Line, StringRef Name = ""),
1673 (Tag, Scope, Entity, Line, Name))
1674 DEFINE_MDNODE_GET(MDImportedEntity,
1675 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1676 unsigned Line, MDString *Name),
1677 (Tag, Scope, Entity, Line, Name))
1679 TempMDImportedEntity clone() const { return cloneImpl(); }
1681 unsigned getLine() const { return Line; }
1682 Metadata *getScope() const { return getOperand(0); }
1683 Metadata *getEntity() const { return getOperand(1); }
1684 StringRef getName() const { return getStringOperand(2); }
1686 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1688 static bool classof(const Metadata *MD) {
1689 return MD->getMetadataID() == MDImportedEntityKind;
1693 } // end namespace llvm
1695 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1696 #undef DEFINE_MDNODE_GET_UNPACK
1697 #undef DEFINE_MDNODE_GET