1 //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Declarations for metadata specific to debug info.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_DEBUGINFOMETADATA_H
15 #define LLVM_IR_DEBUGINFOMETADATA_H
17 #include "llvm/IR/Metadata.h"
18 #include "llvm/Support/Dwarf.h"
20 // Helper macros for defining get() overrides.
21 #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
22 #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
23 #define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
24 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
25 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
27 static CLASS *getIfExists(LLVMContext &Context, \
28 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
29 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
30 /* ShouldCreate */ false); \
32 static CLASS *getDistinct(LLVMContext &Context, \
33 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
34 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
36 static Temp##CLASS getTemporary(LLVMContext &Context, \
37 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
39 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
44 /// \brief Debug location.
46 /// A debug location in source code, used for debug info and otherwise.
47 class MDLocation : public MDNode {
48 friend class LLVMContextImpl;
51 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
52 unsigned Column, ArrayRef<Metadata *> MDs);
53 ~MDLocation() { dropAllReferences(); }
55 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
56 unsigned Column, Metadata *Scope,
57 Metadata *InlinedAt, StorageType Storage,
58 bool ShouldCreate = true);
60 TempMDLocation cloneImpl() const {
61 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
65 // Disallow replacing operands.
66 void replaceOperandWith(unsigned I, Metadata *New) = delete;
69 DEFINE_MDNODE_GET(MDLocation,
70 (unsigned Line, unsigned Column, Metadata *Scope,
71 Metadata *InlinedAt = nullptr),
72 (Line, Column, Scope, InlinedAt))
74 /// \brief Return a (temporary) clone of this.
75 TempMDLocation clone() const { return cloneImpl(); }
77 unsigned getLine() const { return SubclassData32; }
78 unsigned getColumn() const { return SubclassData16; }
79 Metadata *getScope() const { return getOperand(0); }
80 Metadata *getInlinedAt() const {
81 if (getNumOperands() == 2)
86 static bool classof(const Metadata *MD) {
87 return MD->getMetadataID() == MDLocationKind;
91 /// \brief Tagged DWARF-like metadata node.
93 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
94 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
95 /// potentially used for non-DWARF output.
96 class DebugNode : public MDNode {
97 friend class LLVMContextImpl;
101 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
102 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
103 : MDNode(C, ID, Storage, Ops1, Ops2) {
104 assert(Tag < 1u << 16);
105 SubclassData16 = Tag;
109 template <class Ty> Ty *getOperandAs(unsigned I) const {
110 return cast_or_null<Ty>(getOperand(I));
113 StringRef getStringOperand(unsigned I) const {
114 if (auto *S = getOperandAs<MDString>(I))
115 return S->getString();
119 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
122 return MDString::get(Context, S);
126 unsigned getTag() const { return SubclassData16; }
128 static bool classof(const Metadata *MD) {
129 switch (MD->getMetadataID()) {
132 case GenericDebugNodeKind:
134 case MDEnumeratorKind:
135 case MDBasicTypeKind:
136 case MDDerivedTypeKind:
137 case MDCompositeTypeKind:
138 case MDSubroutineTypeKind:
140 case MDCompileUnitKind:
141 case MDSubprogramKind:
142 case MDLexicalBlockKind:
143 case MDLexicalBlockFileKind:
144 case MDNamespaceKind:
145 case MDTemplateTypeParameterKind:
146 case MDTemplateValueParameterKind:
147 case MDGlobalVariableKind:
148 case MDLocalVariableKind:
149 case MDExpressionKind:
150 case MDObjCPropertyKind:
151 case MDImportedEntityKind:
157 /// \brief Generic tagged DWARF-like metadata node.
159 /// An un-specialized DWARF-like metadata node. The first operand is a
160 /// (possibly empty) null-separated \a MDString header that contains arbitrary
161 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
162 /// to other metadata.
163 class GenericDebugNode : public DebugNode {
164 friend class LLVMContextImpl;
167 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
168 unsigned Tag, ArrayRef<Metadata *> Ops1,
169 ArrayRef<Metadata *> Ops2)
170 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
173 ~GenericDebugNode() { dropAllReferences(); }
175 void setHash(unsigned Hash) { SubclassData32 = Hash; }
176 void recalculateHash();
178 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
180 ArrayRef<Metadata *> DwarfOps,
182 bool ShouldCreate = true) {
183 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
184 DwarfOps, Storage, ShouldCreate);
187 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
189 ArrayRef<Metadata *> DwarfOps,
191 bool ShouldCreate = true);
193 TempGenericDebugNode cloneImpl() const {
195 getContext(), getTag(), getHeader(),
196 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
200 unsigned getHash() const { return SubclassData32; }
202 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
203 ArrayRef<Metadata *> DwarfOps),
204 (Tag, Header, DwarfOps))
205 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
206 ArrayRef<Metadata *> DwarfOps),
207 (Tag, Header, DwarfOps))
209 /// \brief Return a (temporary) clone of this.
210 TempGenericDebugNode clone() const { return cloneImpl(); }
212 unsigned getTag() const { return SubclassData16; }
213 StringRef getHeader() const { return getStringOperand(0); }
215 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
216 op_iterator dwarf_op_end() const { return op_end(); }
217 op_range dwarf_operands() const {
218 return op_range(dwarf_op_begin(), dwarf_op_end());
221 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
222 const MDOperand &getDwarfOperand(unsigned I) const {
223 return getOperand(I + 1);
225 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
226 replaceOperandWith(I + 1, New);
229 static bool classof(const Metadata *MD) {
230 return MD->getMetadataID() == GenericDebugNodeKind;
234 /// \brief Array subrange.
236 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
238 class MDSubrange : public DebugNode {
239 friend class LLVMContextImpl;
245 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count, int64_t Lo)
246 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
248 Count(Count), Lo(Lo) {}
251 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
252 StorageType Storage, bool ShouldCreate = true);
254 TempMDSubrange cloneImpl() const {
255 return getTemporary(getContext(), getCount(), getLo());
259 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t Lo = 0), (Count, Lo))
261 TempMDSubrange clone() const { return cloneImpl(); }
263 int64_t getLo() const { return Lo; }
264 int64_t getCount() const { return Count; }
266 static bool classof(const Metadata *MD) {
267 return MD->getMetadataID() == MDSubrangeKind;
271 /// \brief Enumeration value.
273 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
274 /// longer creates a type cycle.
275 class MDEnumerator : public DebugNode {
276 friend class LLVMContextImpl;
281 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
282 ArrayRef<Metadata *> Ops)
283 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
287 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
288 StringRef Name, StorageType Storage,
289 bool ShouldCreate = true) {
290 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
293 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
294 MDString *Name, StorageType Storage,
295 bool ShouldCreate = true);
297 TempMDEnumerator cloneImpl() const {
298 return getTemporary(getContext(), getValue(), getName());
302 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
304 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
307 TempMDEnumerator clone() const { return cloneImpl(); }
309 int64_t getValue() const { return Value; }
310 StringRef getName() const { return getStringOperand(0); }
312 MDString *getRawName() const { return getOperandAs<MDString>(0); }
314 static bool classof(const Metadata *MD) {
315 return MD->getMetadataID() == MDEnumeratorKind;
319 /// \brief Base class for scope-like contexts.
321 /// Base class for lexical scopes and types (which are also declaration
324 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
325 class MDScope : public DebugNode {
327 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
328 ArrayRef<Metadata *> Ops)
329 : DebugNode(C, ID, Storage, Tag, Ops) {}
333 /// \brief Return the underlying file.
335 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
336 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
337 /// this. Otherwise, return the first operand, which is where all other
338 /// subclasses store their file pointer.
339 Metadata *getFile() const {
340 return isa<MDFile>(this) ? const_cast<MDScope *>(this) : 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 unsigned getLine() const { return Line; }
385 uint64_t getSizeInBits() const { return SizeInBits; }
386 uint64_t getAlignInBits() const { return AlignInBits; }
387 uint64_t getOffsetInBits() const { return OffsetInBits; }
388 unsigned getFlags() const { return Flags; }
390 Metadata *getScope() const { return getOperand(1); }
391 StringRef getName() const { return getStringOperand(2); }
393 MDString *getRawName() const { return getOperandAs<MDString>(2); }
395 static bool classof(const Metadata *MD) {
396 switch (MD->getMetadataID()) {
399 case MDBasicTypeKind:
400 case MDDerivedTypeKind:
401 case MDCompositeTypeKind:
402 case MDSubroutineTypeKind:
408 /// \brief Basic type.
410 /// TODO: Split out DW_TAG_unspecified_type.
411 /// TODO: Drop unused accessors.
412 class MDBasicType : public MDType {
413 friend class LLVMContextImpl;
418 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
419 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
420 ArrayRef<Metadata *> Ops)
421 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
423 Encoding(Encoding) {}
426 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
427 StringRef Name, uint64_t SizeInBits,
428 uint64_t AlignInBits, unsigned Encoding,
429 StorageType Storage, bool ShouldCreate = true) {
430 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
431 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
433 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
434 MDString *Name, uint64_t SizeInBits,
435 uint64_t AlignInBits, unsigned Encoding,
436 StorageType Storage, bool ShouldCreate = true);
438 TempMDBasicType cloneImpl() const {
439 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
440 getAlignInBits(), getEncoding());
444 DEFINE_MDNODE_GET(MDBasicType,
445 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
446 uint64_t AlignInBits, unsigned Encoding),
447 (Tag, Name, SizeInBits, AlignInBits, Encoding))
448 DEFINE_MDNODE_GET(MDBasicType,
449 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
450 uint64_t AlignInBits, unsigned Encoding),
451 (Tag, Name, SizeInBits, AlignInBits, Encoding))
453 TempMDBasicType clone() const { return cloneImpl(); }
455 unsigned getEncoding() const { return Encoding; }
457 static bool classof(const Metadata *MD) {
458 return MD->getMetadataID() == MDBasicTypeKind;
462 /// \brief Base class for MDDerivedType and MDCompositeType.
464 /// TODO: Delete; they're not really related.
465 class MDDerivedTypeBase : public MDType {
467 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
468 unsigned Tag, unsigned Line, uint64_t SizeInBits,
469 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
470 ArrayRef<Metadata *> Ops)
471 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
473 ~MDDerivedTypeBase() {}
476 Metadata *getBaseType() const { return getOperand(3); }
478 static bool classof(const Metadata *MD) {
479 return MD->getMetadataID() == MDDerivedTypeKind ||
480 MD->getMetadataID() == MDCompositeTypeKind ||
481 MD->getMetadataID() == MDSubroutineTypeKind;
485 /// \brief Derived types.
487 /// This includes qualified types, pointers, references, friends, typedefs, and
490 /// TODO: Split out members (inheritance, fields, methods, etc.).
491 class MDDerivedType : public MDDerivedTypeBase {
492 friend class LLVMContextImpl;
495 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
496 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
497 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
498 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
499 AlignInBits, OffsetInBits, Flags, Ops) {}
502 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
503 StringRef Name, Metadata *File, unsigned Line,
504 Metadata *Scope, Metadata *BaseType,
505 uint64_t SizeInBits, uint64_t AlignInBits,
506 uint64_t OffsetInBits, unsigned Flags,
507 Metadata *ExtraData, StorageType Storage,
508 bool ShouldCreate = true) {
509 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
510 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
511 Flags, ExtraData, Storage, ShouldCreate);
513 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
514 MDString *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);
521 TempMDDerivedType cloneImpl() const {
522 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
523 getScope(), getBaseType(), getSizeInBits(),
524 getAlignInBits(), getOffsetInBits(), getFlags(),
529 DEFINE_MDNODE_GET(MDDerivedType,
530 (unsigned Tag, MDString *Name, Metadata *File,
531 unsigned Line, Metadata *Scope, Metadata *BaseType,
532 uint64_t SizeInBits, uint64_t AlignInBits,
533 uint64_t OffsetInBits, unsigned Flags,
534 Metadata *ExtraData = nullptr),
535 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
536 AlignInBits, OffsetInBits, Flags, ExtraData))
537 DEFINE_MDNODE_GET(MDDerivedType,
538 (unsigned Tag, StringRef Name, Metadata *File,
539 unsigned Line, Metadata *Scope, Metadata *BaseType,
540 uint64_t SizeInBits, uint64_t AlignInBits,
541 uint64_t OffsetInBits, unsigned Flags,
542 Metadata *ExtraData = nullptr),
543 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
544 AlignInBits, OffsetInBits, Flags, ExtraData))
546 TempMDDerivedType clone() const { return cloneImpl(); }
548 /// \brief Get extra data associated with this derived type.
550 /// Class type for pointer-to-members, objective-c property node for ivars,
551 /// or global constant wrapper for static members.
553 /// TODO: Separate out types that need this extra operand: pointer-to-member
554 /// types and member fields (static members and ivars).
555 Metadata *getExtraData() const { return getOperand(4); }
557 static bool classof(const Metadata *MD) {
558 return MD->getMetadataID() == MDDerivedTypeKind;
562 /// \brief Base class for MDCompositeType and MDSubroutineType.
564 /// TODO: Delete; they're not really related.
565 class MDCompositeTypeBase : public MDDerivedTypeBase {
566 unsigned RuntimeLang;
569 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
570 unsigned Tag, unsigned Line, unsigned RuntimeLang,
571 uint64_t SizeInBits, uint64_t AlignInBits,
572 uint64_t OffsetInBits, unsigned Flags,
573 ArrayRef<Metadata *> Ops)
574 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
575 OffsetInBits, Flags, Ops),
576 RuntimeLang(RuntimeLang) {}
577 ~MDCompositeTypeBase() {}
580 Metadata *getElements() const { return getOperand(4); }
581 Metadata *getVTableHolder() const { return getOperand(5); }
582 Metadata *getTemplateParams() const { return getOperand(6); }
583 StringRef getIdentifier() const { return getStringOperand(7); }
584 unsigned getRuntimeLang() const { return RuntimeLang; }
586 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
588 /// \brief Replace operands.
590 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
591 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
592 /// of its movement if necessary.
594 void replaceElements(MDTuple *Elements) {
596 if (auto *Old = cast_or_null<MDTuple>(getElements()))
597 for (const auto &Op : Old->operands())
598 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
599 "Lost a member during member list replacement");
601 replaceOperandWith(4, Elements);
603 void replaceVTableHolder(Metadata *VTableHolder) {
604 replaceOperandWith(5, VTableHolder);
606 void replaceTemplateParams(MDTuple *TemplateParams) {
607 replaceOperandWith(6, TemplateParams);
611 static bool classof(const Metadata *MD) {
612 return MD->getMetadataID() == MDCompositeTypeKind ||
613 MD->getMetadataID() == MDSubroutineTypeKind;
617 /// \brief Composite types.
619 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
620 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
621 class MDCompositeType : public MDCompositeTypeBase {
622 friend class LLVMContextImpl;
625 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
626 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
627 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
628 ArrayRef<Metadata *> Ops)
629 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
630 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
632 ~MDCompositeType() {}
634 static MDCompositeType *
635 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
636 unsigned Line, Metadata *Scope, Metadata *BaseType,
637 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
638 uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
639 Metadata *VTableHolder, Metadata *TemplateParams,
640 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
641 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
642 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
643 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
644 getCanonicalMDString(Context, Identifier), Storage,
647 static MDCompositeType *
648 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
649 unsigned Line, Metadata *Scope, Metadata *BaseType,
650 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
651 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
652 Metadata *VTableHolder, Metadata *TemplateParams,
653 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
655 TempMDCompositeType cloneImpl() const {
656 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
657 getScope(), getBaseType(), getSizeInBits(),
658 getAlignInBits(), getOffsetInBits(), getFlags(),
659 getElements(), getRuntimeLang(), getVTableHolder(),
660 getTemplateParams(), getIdentifier());
664 DEFINE_MDNODE_GET(MDCompositeType,
665 (unsigned Tag, StringRef Name, Metadata *File,
666 unsigned Line, Metadata *Scope, Metadata *BaseType,
667 uint64_t SizeInBits, uint64_t AlignInBits,
668 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
669 unsigned RuntimeLang, Metadata *VTableHolder,
670 Metadata *TemplateParams = nullptr,
671 StringRef Identifier = ""),
672 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
673 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
674 VTableHolder, TemplateParams, Identifier))
675 DEFINE_MDNODE_GET(MDCompositeType,
676 (unsigned Tag, MDString *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 MDString *Identifier = nullptr),
683 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
684 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
685 VTableHolder, TemplateParams, Identifier))
687 TempMDCompositeType clone() const { return cloneImpl(); }
689 static bool classof(const Metadata *MD) {
690 return MD->getMetadataID() == MDCompositeTypeKind;
694 /// \brief Type array for a subprogram.
696 /// TODO: Detach from CompositeType, and fold the array of types in directly
698 class MDSubroutineType : public MDCompositeTypeBase {
699 friend class LLVMContextImpl;
702 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
703 ArrayRef<Metadata *> Ops)
704 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
705 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
707 ~MDSubroutineType() {}
709 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
710 Metadata *TypeArray, StorageType Storage,
711 bool ShouldCreate = true);
713 TempMDSubroutineType cloneImpl() const {
714 return getTemporary(getContext(), getFlags(), getTypeArray());
718 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
721 TempMDSubroutineType clone() const { return cloneImpl(); }
723 Metadata *getTypeArray() const { return getElements(); }
725 static bool classof(const Metadata *MD) {
726 return MD->getMetadataID() == MDSubroutineTypeKind;
732 /// TODO: Merge with directory/file node (including users).
733 /// TODO: Canonicalize paths on creation.
734 class MDFile : public MDScope {
735 friend class LLVMContextImpl;
738 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
739 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
742 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
743 StringRef Directory, StorageType Storage,
744 bool ShouldCreate = true) {
745 return getImpl(Context, getCanonicalMDString(Context, Filename),
746 getCanonicalMDString(Context, Directory), Storage,
749 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
750 MDString *Directory, StorageType Storage,
751 bool ShouldCreate = true);
753 TempMDFile cloneImpl() const {
754 return getTemporary(getContext(), getFilename(), getDirectory());
758 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
759 (Filename, Directory))
760 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
761 (Filename, Directory))
763 TempMDFile clone() const { return cloneImpl(); }
765 StringRef getFilename() const { return getStringOperand(0); }
766 StringRef getDirectory() const { return getStringOperand(1); }
768 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
769 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
771 static bool classof(const Metadata *MD) {
772 return MD->getMetadataID() == MDFileKind;
776 /// \brief Compile unit.
777 class MDCompileUnit : public MDScope {
778 friend class LLVMContextImpl;
781 unsigned SourceLanguage;
783 unsigned RuntimeVersion;
784 unsigned EmissionKind;
786 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
787 bool IsOptimized, unsigned RuntimeVersion,
788 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
789 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
790 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
791 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
794 static MDCompileUnit *
795 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
796 StringRef Producer, bool IsOptimized, StringRef Flags,
797 unsigned RuntimeVersion, StringRef SplitDebugFilename,
798 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
799 Metadata *Subprograms, Metadata *GlobalVariables,
800 Metadata *ImportedEntities, StorageType Storage,
801 bool ShouldCreate = true) {
802 return getImpl(Context, SourceLanguage, File,
803 getCanonicalMDString(Context, Producer), IsOptimized,
804 getCanonicalMDString(Context, Flags), RuntimeVersion,
805 getCanonicalMDString(Context, SplitDebugFilename),
806 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
807 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
809 static MDCompileUnit *
810 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
811 MDString *Producer, bool IsOptimized, MDString *Flags,
812 unsigned RuntimeVersion, MDString *SplitDebugFilename,
813 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
814 Metadata *Subprograms, Metadata *GlobalVariables,
815 Metadata *ImportedEntities, StorageType Storage,
816 bool ShouldCreate = true);
818 TempMDCompileUnit cloneImpl() const {
820 getContext(), getSourceLanguage(), getFile(), getProducer(),
821 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
822 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
823 getGlobalVariables(), getImportedEntities());
827 DEFINE_MDNODE_GET(MDCompileUnit,
828 (unsigned SourceLanguage, Metadata *File,
829 StringRef Producer, bool IsOptimized, StringRef Flags,
830 unsigned RuntimeVersion, StringRef SplitDebugFilename,
831 unsigned EmissionKind, Metadata *EnumTypes,
832 Metadata *RetainedTypes, Metadata *Subprograms,
833 Metadata *GlobalVariables, Metadata *ImportedEntities),
834 (SourceLanguage, File, Producer, IsOptimized, Flags,
835 RuntimeVersion, SplitDebugFilename, EmissionKind,
836 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
838 DEFINE_MDNODE_GET(MDCompileUnit,
839 (unsigned SourceLanguage, Metadata *File,
840 MDString *Producer, bool IsOptimized, MDString *Flags,
841 unsigned RuntimeVersion, MDString *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,
850 TempMDCompileUnit clone() const { return cloneImpl(); }
852 unsigned getSourceLanguage() const { return SourceLanguage; }
853 bool isOptimized() const { return IsOptimized; }
854 unsigned getRuntimeVersion() const { return RuntimeVersion; }
855 unsigned getEmissionKind() const { return EmissionKind; }
856 StringRef getProducer() const { return getStringOperand(1); }
857 StringRef getFlags() const { return getStringOperand(2); }
858 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
859 Metadata *getEnumTypes() const { return getOperand(4); }
860 Metadata *getRetainedTypes() const { return getOperand(5); }
861 Metadata *getSubprograms() const { return getOperand(6); }
862 Metadata *getGlobalVariables() const { return getOperand(7); }
863 Metadata *getImportedEntities() const { return getOperand(8); }
865 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
866 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
867 MDString *getRawSplitDebugFilename() const {
868 return getOperandAs<MDString>(3);
871 /// \brief Replace arrays.
873 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
874 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
875 /// MDCompileUnit should be fairly rare.
877 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
878 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
881 static bool classof(const Metadata *MD) {
882 return MD->getMetadataID() == MDCompileUnitKind;
886 /// \brief Subprogram description.
888 /// TODO: Remove DisplayName. It's always equal to Name.
889 /// TODO: Split up flags.
890 class MDSubprogram : public MDScope {
891 friend class LLVMContextImpl;
897 unsigned VirtualIndex;
903 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
904 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
905 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
906 bool IsOptimized, ArrayRef<Metadata *> Ops)
907 : MDScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
908 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
909 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
910 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
913 static MDSubprogram *
914 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
915 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
916 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
917 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
918 unsigned Flags, bool IsOptimized, Metadata *Function,
919 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
920 StorageType Storage, bool ShouldCreate = true) {
921 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
922 getCanonicalMDString(Context, LinkageName), File, Line, Type,
923 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
924 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
925 TemplateParams, Declaration, Variables, Storage,
928 static MDSubprogram *
929 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
930 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
931 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
932 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
933 unsigned Flags, bool IsOptimized, Metadata *Function,
934 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
935 StorageType Storage, bool ShouldCreate = true);
937 TempMDSubprogram cloneImpl() const {
938 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
939 getFile(), getLine(), getType(), isLocalToUnit(),
940 isDefinition(), getScopeLine(), getContainingType(),
941 getVirtuality(), getVirtualIndex(), getFlags(),
942 isOptimized(), getFunction(), getTemplateParams(),
943 getDeclaration(), getVariables());
949 (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
950 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
951 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
952 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
953 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
954 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
955 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
956 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
957 Function, TemplateParams, Declaration, Variables))
960 (Metadata * Scope, MDString *Name, MDString *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))
970 TempMDSubprogram clone() const { return cloneImpl(); }
973 unsigned getLine() const { return Line; }
974 unsigned getVirtuality() const { return Virtuality; }
975 unsigned getVirtualIndex() const { return VirtualIndex; }
976 unsigned getScopeLine() const { return ScopeLine; }
977 unsigned getFlags() const { return Flags; }
978 bool isLocalToUnit() const { return IsLocalToUnit; }
979 bool isDefinition() const { return IsDefinition; }
980 bool isOptimized() const { return IsOptimized; }
982 Metadata *getScope() const { return getOperand(1); }
984 StringRef getName() const { return getStringOperand(2); }
985 StringRef getDisplayName() const { return getStringOperand(3); }
986 StringRef getLinkageName() const { return getStringOperand(4); }
988 MDString *getRawName() const { return getOperandAs<MDString>(2); }
989 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
991 Metadata *getType() const { return getOperand(5); }
992 Metadata *getContainingType() const { return getOperand(6); }
994 Metadata *getFunction() const { return getOperand(7); }
995 Metadata *getTemplateParams() const { return getOperand(8); }
996 Metadata *getDeclaration() const { return getOperand(9); }
997 Metadata *getVariables() const { return getOperand(10); }
999 /// \brief Replace the function.
1001 /// If \a isUniqued() and not \a isResolved(), this could node will be
1002 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1003 /// that's a problem.
1005 void replaceFunction(Function *F);
1006 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1007 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1010 static bool classof(const Metadata *MD) {
1011 return MD->getMetadataID() == MDSubprogramKind;
1015 class MDLexicalBlockBase : public MDScope {
1017 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1018 ArrayRef<Metadata *> Ops)
1019 : MDScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1020 ~MDLexicalBlockBase() {}
1023 Metadata *getScope() const { return getOperand(1); }
1025 static bool classof(const Metadata *MD) {
1026 return MD->getMetadataID() == MDLexicalBlockKind ||
1027 MD->getMetadataID() == MDLexicalBlockFileKind;
1031 class MDLexicalBlock : public MDLexicalBlockBase {
1032 friend class LLVMContextImpl;
1033 friend class MDNode;
1038 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1039 unsigned Column, ArrayRef<Metadata *> Ops)
1040 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1042 ~MDLexicalBlock() {}
1044 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1045 Metadata *File, unsigned Line, unsigned Column,
1046 StorageType Storage, bool ShouldCreate = true);
1048 TempMDLexicalBlock cloneImpl() const {
1049 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1054 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1055 unsigned Line, unsigned Column),
1056 (Scope, File, Line, Column))
1058 TempMDLexicalBlock clone() const { return cloneImpl(); }
1060 unsigned getLine() const { return Line; }
1061 unsigned getColumn() const { return Column; }
1063 static bool classof(const Metadata *MD) {
1064 return MD->getMetadataID() == MDLexicalBlockKind;
1068 class MDLexicalBlockFile : public MDLexicalBlockBase {
1069 friend class LLVMContextImpl;
1070 friend class MDNode;
1072 unsigned Discriminator;
1074 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1075 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1076 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1077 Discriminator(Discriminator) {}
1078 ~MDLexicalBlockFile() {}
1080 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1081 Metadata *File, unsigned Discriminator,
1082 StorageType Storage,
1083 bool ShouldCreate = true);
1085 TempMDLexicalBlockFile cloneImpl() const {
1086 return getTemporary(getContext(), getScope(), getFile(),
1087 getDiscriminator());
1091 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1092 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1093 (Scope, File, Discriminator))
1095 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1097 unsigned getDiscriminator() const { return Discriminator; }
1099 static bool classof(const Metadata *MD) {
1100 return MD->getMetadataID() == MDLexicalBlockFileKind;
1104 class MDNamespace : public MDScope {
1105 friend class LLVMContextImpl;
1106 friend class MDNode;
1110 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1111 ArrayRef<Metadata *> Ops)
1112 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1117 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1118 Metadata *File, StringRef Name, unsigned Line,
1119 StorageType Storage, bool ShouldCreate = true) {
1120 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1121 Line, Storage, ShouldCreate);
1123 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1124 Metadata *File, MDString *Name, unsigned Line,
1125 StorageType Storage, bool ShouldCreate = true);
1127 TempMDNamespace cloneImpl() const {
1128 return getTemporary(getContext(), getScope(), getFile(), getName(),
1133 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1134 StringRef Name, unsigned Line),
1135 (Scope, File, Name, Line))
1136 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1137 MDString *Name, unsigned Line),
1138 (Scope, File, Name, Line))
1140 TempMDNamespace clone() const { return cloneImpl(); }
1142 unsigned getLine() const { return Line; }
1143 Metadata *getScope() const { return getOperand(1); }
1144 StringRef getName() const { return getStringOperand(2); }
1146 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1148 static bool classof(const Metadata *MD) {
1149 return MD->getMetadataID() == MDNamespaceKind;
1153 /// \brief Base class for template parameters.
1154 class MDTemplateParameter : public DebugNode {
1156 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1157 unsigned Tag, ArrayRef<Metadata *> Ops)
1158 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1159 ~MDTemplateParameter() {}
1162 StringRef getName() const { return getStringOperand(0); }
1163 Metadata *getType() const { return getOperand(1); }
1165 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1167 static bool classof(const Metadata *MD) {
1168 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1169 MD->getMetadataID() == MDTemplateValueParameterKind;
1173 class MDTemplateTypeParameter : public MDTemplateParameter {
1174 friend class LLVMContextImpl;
1175 friend class MDNode;
1177 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1178 ArrayRef<Metadata *> Ops)
1179 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1180 dwarf::DW_TAG_template_type_parameter, Ops) {}
1181 ~MDTemplateTypeParameter() {}
1183 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1184 Metadata *Type, StorageType Storage,
1185 bool ShouldCreate = true) {
1186 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1189 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1190 Metadata *Type, StorageType Storage,
1191 bool ShouldCreate = true);
1193 TempMDTemplateTypeParameter cloneImpl() const {
1194 return getTemporary(getContext(), getName(), getType());
1198 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1200 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1203 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1205 static bool classof(const Metadata *MD) {
1206 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1210 class MDTemplateValueParameter : public MDTemplateParameter {
1211 friend class LLVMContextImpl;
1212 friend class MDNode;
1214 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1215 unsigned Tag, ArrayRef<Metadata *> Ops)
1216 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1218 ~MDTemplateValueParameter() {}
1220 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1221 StringRef Name, Metadata *Type,
1222 Metadata *Value, StorageType Storage,
1223 bool ShouldCreate = true) {
1224 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1225 Value, Storage, ShouldCreate);
1227 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1228 MDString *Name, Metadata *Type,
1229 Metadata *Value, StorageType Storage,
1230 bool ShouldCreate = true);
1232 TempMDTemplateValueParameter cloneImpl() const {
1233 return getTemporary(getContext(), getTag(), getName(), getType(),
1238 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1239 Metadata *Type, Metadata *Value),
1240 (Tag, Name, Type, Value))
1241 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1242 Metadata *Type, Metadata *Value),
1243 (Tag, Name, Type, Value))
1245 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1247 Metadata *getValue() const { return getOperand(2); }
1249 static bool classof(const Metadata *MD) {
1250 return MD->getMetadataID() == MDTemplateValueParameterKind;
1254 /// \brief Base class for variables.
1256 /// TODO: Hardcode to DW_TAG_variable.
1257 class MDVariable : public DebugNode {
1261 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1262 unsigned Line, ArrayRef<Metadata *> Ops)
1263 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1267 unsigned getLine() const { return Line; }
1268 Metadata *getScope() const { return getOperand(0); }
1269 StringRef getName() const { return getStringOperand(1); }
1270 Metadata *getFile() const { return getOperand(2); }
1271 Metadata *getType() const { return getOperand(3); }
1273 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1275 static bool classof(const Metadata *MD) {
1276 return MD->getMetadataID() == MDLocalVariableKind ||
1277 MD->getMetadataID() == MDGlobalVariableKind;
1281 /// \brief Global variables.
1283 /// TODO: Remove DisplayName. It's always equal to Name.
1284 class MDGlobalVariable : public MDVariable {
1285 friend class LLVMContextImpl;
1286 friend class MDNode;
1291 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1292 bool IsLocalToUnit, bool IsDefinition,
1293 ArrayRef<Metadata *> Ops)
1294 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1296 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1297 ~MDGlobalVariable() {}
1299 static MDGlobalVariable *
1300 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1301 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1302 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1303 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1304 bool ShouldCreate = true) {
1305 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1306 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1307 IsLocalToUnit, IsDefinition, Variable,
1308 StaticDataMemberDeclaration, Storage, ShouldCreate);
1310 static MDGlobalVariable *
1311 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1312 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1313 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1314 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1315 bool ShouldCreate = true);
1317 TempMDGlobalVariable cloneImpl() const {
1318 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1319 getFile(), getLine(), getType(), isLocalToUnit(),
1320 isDefinition(), getVariable(),
1321 getStaticDataMemberDeclaration());
1325 DEFINE_MDNODE_GET(MDGlobalVariable,
1326 (Metadata * Scope, StringRef Name, StringRef LinkageName,
1327 Metadata *File, unsigned Line, Metadata *Type,
1328 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1329 Metadata *StaticDataMemberDeclaration),
1330 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1331 IsDefinition, Variable, StaticDataMemberDeclaration))
1332 DEFINE_MDNODE_GET(MDGlobalVariable,
1333 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1334 Metadata *File, unsigned Line, Metadata *Type,
1335 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1336 Metadata *StaticDataMemberDeclaration),
1337 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1338 IsDefinition, Variable, StaticDataMemberDeclaration))
1340 TempMDGlobalVariable clone() const { return cloneImpl(); }
1342 bool isLocalToUnit() const { return IsLocalToUnit; }
1343 bool isDefinition() const { return IsDefinition; }
1344 StringRef getDisplayName() const { return getStringOperand(4); }
1345 StringRef getLinkageName() const { return getStringOperand(5); }
1346 Metadata *getVariable() const { return getOperand(6); }
1347 Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1349 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1351 static bool classof(const Metadata *MD) {
1352 return MD->getMetadataID() == MDGlobalVariableKind;
1356 /// \brief Local variable.
1358 /// TODO: Split between arguments and otherwise.
1359 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1360 /// TODO: Split up flags.
1361 class MDLocalVariable : public MDVariable {
1362 friend class LLVMContextImpl;
1363 friend class MDNode;
1368 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1369 unsigned Line, unsigned Arg, unsigned Flags,
1370 ArrayRef<Metadata *> Ops)
1371 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1373 ~MDLocalVariable() {}
1375 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1376 Metadata *Scope, StringRef Name,
1377 Metadata *File, unsigned Line, Metadata *Type,
1378 unsigned Arg, unsigned Flags,
1379 Metadata *InlinedAt, StorageType Storage,
1380 bool ShouldCreate = true) {
1381 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1382 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1385 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1386 Metadata *Scope, MDString *Name,
1387 Metadata *File, unsigned Line, Metadata *Type,
1388 unsigned Arg, unsigned Flags,
1389 Metadata *InlinedAt, StorageType Storage,
1390 bool ShouldCreate = true);
1392 TempMDLocalVariable cloneImpl() const {
1393 return getTemporary(getContext(), getTag(), getScope(), getName(),
1394 getFile(), getLine(), getType(), getArg(), getFlags(),
1399 DEFINE_MDNODE_GET(MDLocalVariable,
1400 (unsigned Tag, Metadata *Scope, StringRef Name,
1401 Metadata *File, unsigned Line, Metadata *Type,
1402 unsigned Arg, unsigned Flags,
1403 Metadata *InlinedAt = nullptr),
1404 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1405 DEFINE_MDNODE_GET(MDLocalVariable,
1406 (unsigned Tag, Metadata *Scope, MDString *Name,
1407 Metadata *File, unsigned Line, Metadata *Type,
1408 unsigned Arg, unsigned Flags,
1409 Metadata *InlinedAt = nullptr),
1410 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1412 TempMDLocalVariable clone() const { return cloneImpl(); }
1414 unsigned getArg() const { return Arg; }
1415 unsigned getFlags() const { return Flags; }
1416 Metadata *getInlinedAt() const { return getOperand(4); }
1418 static bool classof(const Metadata *MD) {
1419 return MD->getMetadataID() == MDLocalVariableKind;
1423 /// \brief DWARF expression.
1425 /// TODO: Co-allocate the expression elements.
1426 /// TODO: Drop fake DW_TAG_expression and separate from DebugNode.
1427 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1429 class MDExpression : public DebugNode {
1430 friend class LLVMContextImpl;
1431 friend class MDNode;
1433 std::vector<uint64_t> Elements;
1435 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1436 : DebugNode(C, MDExpressionKind, Storage, dwarf::DW_TAG_expression, None),
1437 Elements(Elements.begin(), Elements.end()) {}
1440 static MDExpression *getImpl(LLVMContext &Context,
1441 ArrayRef<uint64_t> Elements, StorageType Storage,
1442 bool ShouldCreate = true);
1444 TempMDExpression cloneImpl() const {
1445 return getTemporary(getContext(), getElements());
1449 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1451 TempMDExpression clone() const { return cloneImpl(); }
1453 ArrayRef<uint64_t> getElements() const { return Elements; }
1455 unsigned getNumElements() const { return Elements.size(); }
1456 uint64_t getElement(unsigned I) const {
1457 assert(I < Elements.size() && "Index out of range");
1461 typedef ArrayRef<uint64_t>::iterator element_iterator;
1462 element_iterator elements_begin() const { return getElements().begin(); }
1463 element_iterator elements_end() const { return getElements().end(); }
1465 /// \brief A lightweight wrapper around an expression operand.
1467 /// TODO: Store arguments directly and change \a MDExpression to store a
1473 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1475 const uint64_t *get() const { return Op; }
1477 /// \brief Get the operand code.
1478 uint64_t getOp() const { return *Op; }
1480 /// \brief Get an argument to the operand.
1482 /// Never returns the operand itself.
1483 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1485 unsigned getNumArgs() const { return getSize() - 1; }
1487 /// \brief Return the size of the operand.
1489 /// Return the number of elements in the operand (1 + args).
1490 unsigned getSize() const;
1493 /// \brief An iterator for expression operands.
1494 class expr_op_iterator
1495 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1499 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1501 element_iterator getBase() const { return Op.get(); }
1502 const ExprOperand &operator*() const { return Op; }
1503 const ExprOperand *operator->() const { return &Op; }
1505 expr_op_iterator &operator++() {
1509 expr_op_iterator operator++(int) {
1510 expr_op_iterator T(*this);
1515 bool operator==(const expr_op_iterator &X) const {
1516 return getBase() == X.getBase();
1518 bool operator!=(const expr_op_iterator &X) const {
1519 return getBase() != X.getBase();
1523 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1526 /// \brief Visit the elements via ExprOperand wrappers.
1528 /// These range iterators visit elements through \a ExprOperand wrappers.
1529 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1532 /// \pre \a isValid() gives \c true.
1534 expr_op_iterator expr_op_begin() const {
1535 return expr_op_iterator(elements_begin());
1537 expr_op_iterator expr_op_end() const {
1538 return expr_op_iterator(elements_end());
1542 bool isValid() const;
1544 static bool classof(const Metadata *MD) {
1545 return MD->getMetadataID() == MDExpressionKind;
1549 class MDObjCProperty : public DebugNode {
1550 friend class LLVMContextImpl;
1551 friend class MDNode;
1554 unsigned Attributes;
1556 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1557 unsigned Attributes, ArrayRef<Metadata *> Ops)
1558 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1560 Line(Line), Attributes(Attributes) {}
1561 ~MDObjCProperty() {}
1563 static MDObjCProperty *
1564 getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1565 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1566 Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1567 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1568 getCanonicalMDString(Context, GetterName),
1569 getCanonicalMDString(Context, SetterName), Attributes, Type,
1570 Storage, ShouldCreate);
1572 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1573 Metadata *File, unsigned Line,
1574 MDString *GetterName, MDString *SetterName,
1575 unsigned Attributes, Metadata *Type,
1576 StorageType Storage, bool ShouldCreate = true);
1578 TempMDObjCProperty cloneImpl() const {
1579 return getTemporary(getContext(), getName(), getFile(), getLine(),
1580 getGetterName(), getSetterName(), getAttributes(),
1585 DEFINE_MDNODE_GET(MDObjCProperty,
1586 (StringRef Name, Metadata *File, unsigned Line,
1587 StringRef GetterName, StringRef SetterName,
1588 unsigned Attributes, Metadata *Type),
1589 (Name, File, Line, GetterName, SetterName, Attributes,
1591 DEFINE_MDNODE_GET(MDObjCProperty,
1592 (MDString * Name, Metadata *File, unsigned Line,
1593 MDString *GetterName, MDString *SetterName,
1594 unsigned Attributes, Metadata *Type),
1595 (Name, File, Line, GetterName, SetterName, Attributes,
1598 TempMDObjCProperty clone() const { return cloneImpl(); }
1600 unsigned getLine() const { return Line; }
1601 unsigned getAttributes() const { return Attributes; }
1602 StringRef getName() const { return getStringOperand(0); }
1603 Metadata *getFile() const { return getOperand(1); }
1604 StringRef getGetterName() const { return getStringOperand(2); }
1605 StringRef getSetterName() const { return getStringOperand(3); }
1606 Metadata *getType() const { return getOperand(4); }
1608 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1609 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1610 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1612 static bool classof(const Metadata *MD) {
1613 return MD->getMetadataID() == MDObjCPropertyKind;
1617 class MDImportedEntity : public DebugNode {
1618 friend class LLVMContextImpl;
1619 friend class MDNode;
1623 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1624 unsigned Line, ArrayRef<Metadata *> Ops)
1625 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1626 ~MDImportedEntity() {}
1628 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1629 Metadata *Scope, Metadata *Entity,
1630 unsigned Line, StringRef Name,
1631 StorageType Storage,
1632 bool ShouldCreate = true) {
1633 return getImpl(Context, Tag, Scope, Entity, Line,
1634 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1636 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1637 Metadata *Scope, Metadata *Entity,
1638 unsigned Line, MDString *Name,
1639 StorageType Storage,
1640 bool ShouldCreate = true);
1642 TempMDImportedEntity cloneImpl() const {
1643 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1644 getLine(), getName());
1648 DEFINE_MDNODE_GET(MDImportedEntity,
1649 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1650 unsigned Line, StringRef Name = ""),
1651 (Tag, Scope, Entity, Line, Name))
1652 DEFINE_MDNODE_GET(MDImportedEntity,
1653 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1654 unsigned Line, MDString *Name),
1655 (Tag, Scope, Entity, Line, Name))
1657 TempMDImportedEntity clone() const { return cloneImpl(); }
1659 unsigned getLine() const { return Line; }
1660 Metadata *getScope() const { return getOperand(0); }
1661 Metadata *getEntity() const { return getOperand(1); }
1662 StringRef getName() const { return getStringOperand(2); }
1664 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1666 static bool classof(const Metadata *MD) {
1667 return MD->getMetadataID() == MDImportedEntityKind;
1671 } // end namespace llvm
1673 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1674 #undef DEFINE_MDNODE_GET_UNPACK
1675 #undef DEFINE_MDNODE_GET