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)
341 : static_cast<Metadata *>(getOperand(0));
344 static bool classof(const Metadata *MD) {
345 switch (MD->getMetadataID()) {
348 case MDBasicTypeKind:
349 case MDDerivedTypeKind:
350 case MDCompositeTypeKind:
351 case MDSubroutineTypeKind:
353 case MDCompileUnitKind:
354 case MDSubprogramKind:
355 case MDLexicalBlockKind:
356 case MDLexicalBlockFileKind:
357 case MDNamespaceKind:
363 /// \brief Base class for types.
365 /// TODO: Remove the hardcoded name and context, since many types don't use
367 /// TODO: Split up flags.
368 class MDType : public MDScope {
372 uint64_t AlignInBits;
373 uint64_t OffsetInBits;
376 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
377 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
378 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
379 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
380 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
381 OffsetInBits(OffsetInBits) {}
385 TempMDType clone() const {
386 return TempMDType(cast<MDType>(MDNode::clone().release()));
389 unsigned getLine() const { return Line; }
390 uint64_t getSizeInBits() const { return SizeInBits; }
391 uint64_t getAlignInBits() const { return AlignInBits; }
392 uint64_t getOffsetInBits() const { return OffsetInBits; }
393 unsigned getFlags() const { return Flags; }
395 Metadata *getScope() const { return getOperand(1); }
396 StringRef getName() const { return getStringOperand(2); }
398 MDString *getRawName() const { return getOperandAs<MDString>(2); }
400 void setFlags(unsigned NewFlags) {
401 assert(!isUniqued() && "Cannot set flags on uniqued nodes");
405 static bool classof(const Metadata *MD) {
406 switch (MD->getMetadataID()) {
409 case MDBasicTypeKind:
410 case MDDerivedTypeKind:
411 case MDCompositeTypeKind:
412 case MDSubroutineTypeKind:
418 /// \brief Basic type.
420 /// TODO: Split out DW_TAG_unspecified_type.
421 /// TODO: Drop unused accessors.
422 class MDBasicType : public MDType {
423 friend class LLVMContextImpl;
428 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
429 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
430 ArrayRef<Metadata *> Ops)
431 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
433 Encoding(Encoding) {}
436 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
437 StringRef Name, uint64_t SizeInBits,
438 uint64_t AlignInBits, unsigned Encoding,
439 StorageType Storage, bool ShouldCreate = true) {
440 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
441 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
443 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
444 MDString *Name, uint64_t SizeInBits,
445 uint64_t AlignInBits, unsigned Encoding,
446 StorageType Storage, bool ShouldCreate = true);
448 TempMDBasicType cloneImpl() const {
449 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
450 getAlignInBits(), getEncoding());
454 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
455 (Tag, Name, 0, 0, 0))
456 DEFINE_MDNODE_GET(MDBasicType,
457 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
458 uint64_t AlignInBits, unsigned Encoding),
459 (Tag, Name, SizeInBits, AlignInBits, Encoding))
460 DEFINE_MDNODE_GET(MDBasicType,
461 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
462 uint64_t AlignInBits, unsigned Encoding),
463 (Tag, Name, SizeInBits, AlignInBits, Encoding))
465 TempMDBasicType clone() const { return cloneImpl(); }
467 unsigned getEncoding() const { return Encoding; }
469 static bool classof(const Metadata *MD) {
470 return MD->getMetadataID() == MDBasicTypeKind;
474 /// \brief Base class for MDDerivedType and MDCompositeType.
476 /// TODO: Delete; they're not really related.
477 class MDDerivedTypeBase : public MDType {
479 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
480 unsigned Tag, unsigned Line, uint64_t SizeInBits,
481 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
482 ArrayRef<Metadata *> Ops)
483 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
485 ~MDDerivedTypeBase() {}
488 Metadata *getBaseType() const { return getOperand(3); }
490 static bool classof(const Metadata *MD) {
491 return MD->getMetadataID() == MDDerivedTypeKind ||
492 MD->getMetadataID() == MDCompositeTypeKind ||
493 MD->getMetadataID() == MDSubroutineTypeKind;
497 /// \brief Derived types.
499 /// This includes qualified types, pointers, references, friends, typedefs, and
502 /// TODO: Split out members (inheritance, fields, methods, etc.).
503 class MDDerivedType : public MDDerivedTypeBase {
504 friend class LLVMContextImpl;
507 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
508 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
509 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
510 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
511 AlignInBits, OffsetInBits, Flags, Ops) {}
514 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
515 StringRef Name, Metadata *File, unsigned Line,
516 Metadata *Scope, Metadata *BaseType,
517 uint64_t SizeInBits, uint64_t AlignInBits,
518 uint64_t OffsetInBits, unsigned Flags,
519 Metadata *ExtraData, StorageType Storage,
520 bool ShouldCreate = true) {
521 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
522 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
523 Flags, ExtraData, Storage, ShouldCreate);
525 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
526 MDString *Name, Metadata *File, unsigned Line,
527 Metadata *Scope, Metadata *BaseType,
528 uint64_t SizeInBits, uint64_t AlignInBits,
529 uint64_t OffsetInBits, unsigned Flags,
530 Metadata *ExtraData, StorageType Storage,
531 bool ShouldCreate = true);
533 TempMDDerivedType cloneImpl() const {
534 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
535 getScope(), getBaseType(), getSizeInBits(),
536 getAlignInBits(), getOffsetInBits(), getFlags(),
541 DEFINE_MDNODE_GET(MDDerivedType,
542 (unsigned Tag, MDString *Name, Metadata *File,
543 unsigned Line, Metadata *Scope, Metadata *BaseType,
544 uint64_t SizeInBits, uint64_t AlignInBits,
545 uint64_t OffsetInBits, unsigned Flags,
546 Metadata *ExtraData = nullptr),
547 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
548 AlignInBits, OffsetInBits, Flags, ExtraData))
549 DEFINE_MDNODE_GET(MDDerivedType,
550 (unsigned Tag, StringRef Name, Metadata *File,
551 unsigned Line, Metadata *Scope, Metadata *BaseType,
552 uint64_t SizeInBits, uint64_t AlignInBits,
553 uint64_t OffsetInBits, unsigned Flags,
554 Metadata *ExtraData = nullptr),
555 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
556 AlignInBits, OffsetInBits, Flags, ExtraData))
558 TempMDDerivedType clone() const { return cloneImpl(); }
560 /// \brief Get extra data associated with this derived type.
562 /// Class type for pointer-to-members, objective-c property node for ivars,
563 /// or global constant wrapper for static members.
565 /// TODO: Separate out types that need this extra operand: pointer-to-member
566 /// types and member fields (static members and ivars).
567 Metadata *getExtraData() const { return getOperand(4); }
569 static bool classof(const Metadata *MD) {
570 return MD->getMetadataID() == MDDerivedTypeKind;
574 /// \brief Base class for MDCompositeType and MDSubroutineType.
576 /// TODO: Delete; they're not really related.
577 class MDCompositeTypeBase : public MDDerivedTypeBase {
578 unsigned RuntimeLang;
581 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
582 unsigned Tag, unsigned Line, unsigned RuntimeLang,
583 uint64_t SizeInBits, uint64_t AlignInBits,
584 uint64_t OffsetInBits, unsigned Flags,
585 ArrayRef<Metadata *> Ops)
586 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
587 OffsetInBits, Flags, Ops),
588 RuntimeLang(RuntimeLang) {}
589 ~MDCompositeTypeBase() {}
592 Metadata *getElements() const { return getOperand(4); }
593 Metadata *getVTableHolder() const { return getOperand(5); }
594 Metadata *getTemplateParams() const { return getOperand(6); }
595 StringRef getIdentifier() const { return getStringOperand(7); }
596 unsigned getRuntimeLang() const { return RuntimeLang; }
598 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
600 /// \brief Replace operands.
602 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
603 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
604 /// of its movement if necessary.
606 void replaceElements(MDTuple *Elements) {
608 if (auto *Old = cast_or_null<MDTuple>(getElements()))
609 for (const auto &Op : Old->operands())
610 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
611 "Lost a member during member list replacement");
613 replaceOperandWith(4, Elements);
615 void replaceVTableHolder(Metadata *VTableHolder) {
616 replaceOperandWith(5, VTableHolder);
618 void replaceTemplateParams(MDTuple *TemplateParams) {
619 replaceOperandWith(6, TemplateParams);
623 static bool classof(const Metadata *MD) {
624 return MD->getMetadataID() == MDCompositeTypeKind ||
625 MD->getMetadataID() == MDSubroutineTypeKind;
629 /// \brief Composite types.
631 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
632 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
633 class MDCompositeType : public MDCompositeTypeBase {
634 friend class LLVMContextImpl;
637 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
638 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
639 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
640 ArrayRef<Metadata *> Ops)
641 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
642 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
644 ~MDCompositeType() {}
646 static MDCompositeType *
647 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
648 unsigned Line, Metadata *Scope, Metadata *BaseType,
649 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
650 uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
651 Metadata *VTableHolder, Metadata *TemplateParams,
652 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
653 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
654 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
655 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
656 getCanonicalMDString(Context, Identifier), Storage,
659 static MDCompositeType *
660 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
661 unsigned Line, Metadata *Scope, Metadata *BaseType,
662 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
663 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
664 Metadata *VTableHolder, Metadata *TemplateParams,
665 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
667 TempMDCompositeType cloneImpl() const {
668 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
669 getScope(), getBaseType(), getSizeInBits(),
670 getAlignInBits(), getOffsetInBits(), getFlags(),
671 getElements(), getRuntimeLang(), getVTableHolder(),
672 getTemplateParams(), getIdentifier());
676 DEFINE_MDNODE_GET(MDCompositeType,
677 (unsigned Tag, StringRef Name, Metadata *File,
678 unsigned Line, Metadata *Scope, Metadata *BaseType,
679 uint64_t SizeInBits, uint64_t AlignInBits,
680 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
681 unsigned RuntimeLang, Metadata *VTableHolder,
682 Metadata *TemplateParams = nullptr,
683 StringRef Identifier = ""),
684 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
685 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
686 VTableHolder, TemplateParams, Identifier))
687 DEFINE_MDNODE_GET(MDCompositeType,
688 (unsigned Tag, MDString *Name, Metadata *File,
689 unsigned Line, Metadata *Scope, Metadata *BaseType,
690 uint64_t SizeInBits, uint64_t AlignInBits,
691 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
692 unsigned RuntimeLang, Metadata *VTableHolder,
693 Metadata *TemplateParams = nullptr,
694 MDString *Identifier = nullptr),
695 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
696 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
697 VTableHolder, TemplateParams, Identifier))
699 TempMDCompositeType clone() const { return cloneImpl(); }
701 static bool classof(const Metadata *MD) {
702 return MD->getMetadataID() == MDCompositeTypeKind;
706 /// \brief Type array for a subprogram.
708 /// TODO: Detach from CompositeType, and fold the array of types in directly
710 class MDSubroutineType : public MDCompositeTypeBase {
711 friend class LLVMContextImpl;
714 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
715 ArrayRef<Metadata *> Ops)
716 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
717 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
719 ~MDSubroutineType() {}
721 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
722 Metadata *TypeArray, StorageType Storage,
723 bool ShouldCreate = true);
725 TempMDSubroutineType cloneImpl() const {
726 return getTemporary(getContext(), getFlags(), getTypeArray());
730 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
733 TempMDSubroutineType clone() const { return cloneImpl(); }
735 Metadata *getTypeArray() const { return getElements(); }
737 static bool classof(const Metadata *MD) {
738 return MD->getMetadataID() == MDSubroutineTypeKind;
744 /// TODO: Merge with directory/file node (including users).
745 /// TODO: Canonicalize paths on creation.
746 class MDFile : public MDScope {
747 friend class LLVMContextImpl;
750 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
751 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
754 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
755 StringRef Directory, StorageType Storage,
756 bool ShouldCreate = true) {
757 return getImpl(Context, getCanonicalMDString(Context, Filename),
758 getCanonicalMDString(Context, Directory), Storage,
761 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
762 MDString *Directory, StorageType Storage,
763 bool ShouldCreate = true);
765 TempMDFile cloneImpl() const {
766 return getTemporary(getContext(), getFilename(), getDirectory());
770 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
771 (Filename, Directory))
772 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
773 (Filename, Directory))
775 TempMDFile clone() const { return cloneImpl(); }
777 StringRef getFilename() const { return getStringOperand(0); }
778 StringRef getDirectory() const { return getStringOperand(1); }
780 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
781 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
783 static bool classof(const Metadata *MD) {
784 return MD->getMetadataID() == MDFileKind;
788 /// \brief Compile unit.
789 class MDCompileUnit : public MDScope {
790 friend class LLVMContextImpl;
793 unsigned SourceLanguage;
795 unsigned RuntimeVersion;
796 unsigned EmissionKind;
798 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
799 bool IsOptimized, unsigned RuntimeVersion,
800 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
801 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
802 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
803 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
806 static MDCompileUnit *
807 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
808 StringRef Producer, bool IsOptimized, StringRef Flags,
809 unsigned RuntimeVersion, StringRef SplitDebugFilename,
810 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
811 Metadata *Subprograms, Metadata *GlobalVariables,
812 Metadata *ImportedEntities, StorageType Storage,
813 bool ShouldCreate = true) {
814 return getImpl(Context, SourceLanguage, File,
815 getCanonicalMDString(Context, Producer), IsOptimized,
816 getCanonicalMDString(Context, Flags), RuntimeVersion,
817 getCanonicalMDString(Context, SplitDebugFilename),
818 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
819 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
821 static MDCompileUnit *
822 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
823 MDString *Producer, bool IsOptimized, MDString *Flags,
824 unsigned RuntimeVersion, MDString *SplitDebugFilename,
825 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
826 Metadata *Subprograms, Metadata *GlobalVariables,
827 Metadata *ImportedEntities, StorageType Storage,
828 bool ShouldCreate = true);
830 TempMDCompileUnit cloneImpl() const {
832 getContext(), getSourceLanguage(), getFile(), getProducer(),
833 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
834 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
835 getGlobalVariables(), getImportedEntities());
839 DEFINE_MDNODE_GET(MDCompileUnit,
840 (unsigned SourceLanguage, Metadata *File,
841 StringRef Producer, bool IsOptimized, StringRef Flags,
842 unsigned RuntimeVersion, StringRef SplitDebugFilename,
843 unsigned EmissionKind, Metadata *EnumTypes,
844 Metadata *RetainedTypes, Metadata *Subprograms,
845 Metadata *GlobalVariables, Metadata *ImportedEntities),
846 (SourceLanguage, File, Producer, IsOptimized, Flags,
847 RuntimeVersion, SplitDebugFilename, EmissionKind,
848 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
850 DEFINE_MDNODE_GET(MDCompileUnit,
851 (unsigned SourceLanguage, Metadata *File,
852 MDString *Producer, bool IsOptimized, MDString *Flags,
853 unsigned RuntimeVersion, MDString *SplitDebugFilename,
854 unsigned EmissionKind, Metadata *EnumTypes,
855 Metadata *RetainedTypes, Metadata *Subprograms,
856 Metadata *GlobalVariables, Metadata *ImportedEntities),
857 (SourceLanguage, File, Producer, IsOptimized, Flags,
858 RuntimeVersion, SplitDebugFilename, EmissionKind,
859 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
862 TempMDCompileUnit clone() const { return cloneImpl(); }
864 unsigned getSourceLanguage() const { return SourceLanguage; }
865 bool isOptimized() const { return IsOptimized; }
866 unsigned getRuntimeVersion() const { return RuntimeVersion; }
867 unsigned getEmissionKind() const { return EmissionKind; }
868 StringRef getProducer() const { return getStringOperand(1); }
869 StringRef getFlags() const { return getStringOperand(2); }
870 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
871 Metadata *getEnumTypes() const { return getOperand(4); }
872 Metadata *getRetainedTypes() const { return getOperand(5); }
873 Metadata *getSubprograms() const { return getOperand(6); }
874 Metadata *getGlobalVariables() const { return getOperand(7); }
875 Metadata *getImportedEntities() const { return getOperand(8); }
877 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
878 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
879 MDString *getRawSplitDebugFilename() const {
880 return getOperandAs<MDString>(3);
883 /// \brief Replace arrays.
885 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
886 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
887 /// MDCompileUnit should be fairly rare.
889 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
890 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
893 static bool classof(const Metadata *MD) {
894 return MD->getMetadataID() == MDCompileUnitKind;
898 /// \brief Subprogram description.
900 /// TODO: Remove DisplayName. It's always equal to Name.
901 /// TODO: Split up flags.
902 class MDSubprogram : public MDScope {
903 friend class LLVMContextImpl;
909 unsigned VirtualIndex;
915 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
916 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
917 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
918 bool IsOptimized, ArrayRef<Metadata *> Ops)
919 : MDScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
920 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
921 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
922 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
925 static MDSubprogram *
926 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
927 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
928 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
929 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
930 unsigned Flags, bool IsOptimized, Metadata *Function,
931 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
932 StorageType Storage, bool ShouldCreate = true) {
933 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
934 getCanonicalMDString(Context, LinkageName), File, Line, Type,
935 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
936 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
937 TemplateParams, Declaration, Variables, Storage,
940 static MDSubprogram *
941 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
942 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
943 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
944 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
945 unsigned Flags, bool IsOptimized, Metadata *Function,
946 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
947 StorageType Storage, bool ShouldCreate = true);
949 TempMDSubprogram cloneImpl() const {
950 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
951 getFile(), getLine(), getType(), isLocalToUnit(),
952 isDefinition(), getScopeLine(), getContainingType(),
953 getVirtuality(), getVirtualIndex(), getFlags(),
954 isOptimized(), getFunction(), getTemplateParams(),
955 getDeclaration(), getVariables());
961 (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
962 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
963 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
964 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
965 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
966 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
967 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
968 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
969 Function, TemplateParams, Declaration, Variables))
972 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
973 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
974 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
975 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
976 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
977 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
978 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
979 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
980 Function, TemplateParams, Declaration, Variables))
982 TempMDSubprogram clone() const { return cloneImpl(); }
985 unsigned getLine() const { return Line; }
986 unsigned getVirtuality() const { return Virtuality; }
987 unsigned getVirtualIndex() const { return VirtualIndex; }
988 unsigned getScopeLine() const { return ScopeLine; }
989 unsigned getFlags() const { return Flags; }
990 bool isLocalToUnit() const { return IsLocalToUnit; }
991 bool isDefinition() const { return IsDefinition; }
992 bool isOptimized() const { return IsOptimized; }
994 Metadata *getScope() const { return getOperand(1); }
996 StringRef getName() const { return getStringOperand(2); }
997 StringRef getDisplayName() const { return getStringOperand(3); }
998 StringRef getLinkageName() const { return getStringOperand(4); }
1000 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1001 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1003 Metadata *getType() const { return getOperand(5); }
1004 Metadata *getContainingType() const { return getOperand(6); }
1006 Metadata *getFunction() const { return getOperand(7); }
1007 Metadata *getTemplateParams() const { return getOperand(8); }
1008 Metadata *getDeclaration() const { return getOperand(9); }
1009 Metadata *getVariables() const { return getOperand(10); }
1011 /// \brief Replace the function.
1013 /// If \a isUniqued() and not \a isResolved(), this could node will be
1014 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1015 /// that's a problem.
1017 void replaceFunction(Function *F);
1018 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1019 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1022 static bool classof(const Metadata *MD) {
1023 return MD->getMetadataID() == MDSubprogramKind;
1027 class MDLexicalBlockBase : public MDScope {
1029 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1030 ArrayRef<Metadata *> Ops)
1031 : MDScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1032 ~MDLexicalBlockBase() {}
1035 Metadata *getScope() const { return getOperand(1); }
1037 static bool classof(const Metadata *MD) {
1038 return MD->getMetadataID() == MDLexicalBlockKind ||
1039 MD->getMetadataID() == MDLexicalBlockFileKind;
1043 class MDLexicalBlock : public MDLexicalBlockBase {
1044 friend class LLVMContextImpl;
1045 friend class MDNode;
1050 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1051 unsigned Column, ArrayRef<Metadata *> Ops)
1052 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1054 ~MDLexicalBlock() {}
1056 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1057 Metadata *File, unsigned Line, unsigned Column,
1058 StorageType Storage, bool ShouldCreate = true);
1060 TempMDLexicalBlock cloneImpl() const {
1061 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1066 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1067 unsigned Line, unsigned Column),
1068 (Scope, File, Line, Column))
1070 TempMDLexicalBlock clone() const { return cloneImpl(); }
1072 unsigned getLine() const { return Line; }
1073 unsigned getColumn() const { return Column; }
1075 static bool classof(const Metadata *MD) {
1076 return MD->getMetadataID() == MDLexicalBlockKind;
1080 class MDLexicalBlockFile : public MDLexicalBlockBase {
1081 friend class LLVMContextImpl;
1082 friend class MDNode;
1084 unsigned Discriminator;
1086 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1087 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1088 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1089 Discriminator(Discriminator) {}
1090 ~MDLexicalBlockFile() {}
1092 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1093 Metadata *File, unsigned Discriminator,
1094 StorageType Storage,
1095 bool ShouldCreate = true);
1097 TempMDLexicalBlockFile cloneImpl() const {
1098 return getTemporary(getContext(), getScope(), getFile(),
1099 getDiscriminator());
1103 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1104 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1105 (Scope, File, Discriminator))
1107 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1109 unsigned getDiscriminator() const { return Discriminator; }
1111 static bool classof(const Metadata *MD) {
1112 return MD->getMetadataID() == MDLexicalBlockFileKind;
1116 class MDNamespace : public MDScope {
1117 friend class LLVMContextImpl;
1118 friend class MDNode;
1122 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1123 ArrayRef<Metadata *> Ops)
1124 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1129 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1130 Metadata *File, StringRef Name, unsigned Line,
1131 StorageType Storage, bool ShouldCreate = true) {
1132 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1133 Line, Storage, ShouldCreate);
1135 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1136 Metadata *File, MDString *Name, unsigned Line,
1137 StorageType Storage, bool ShouldCreate = true);
1139 TempMDNamespace cloneImpl() const {
1140 return getTemporary(getContext(), getScope(), getFile(), getName(),
1145 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1146 StringRef Name, unsigned Line),
1147 (Scope, File, Name, Line))
1148 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1149 MDString *Name, unsigned Line),
1150 (Scope, File, Name, Line))
1152 TempMDNamespace clone() const { return cloneImpl(); }
1154 unsigned getLine() const { return Line; }
1155 Metadata *getScope() const { return getOperand(1); }
1156 StringRef getName() const { return getStringOperand(2); }
1158 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1160 static bool classof(const Metadata *MD) {
1161 return MD->getMetadataID() == MDNamespaceKind;
1165 /// \brief Base class for template parameters.
1166 class MDTemplateParameter : public DebugNode {
1168 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1169 unsigned Tag, ArrayRef<Metadata *> Ops)
1170 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1171 ~MDTemplateParameter() {}
1174 StringRef getName() const { return getStringOperand(0); }
1175 Metadata *getType() const { return getOperand(1); }
1177 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1179 static bool classof(const Metadata *MD) {
1180 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1181 MD->getMetadataID() == MDTemplateValueParameterKind;
1185 class MDTemplateTypeParameter : public MDTemplateParameter {
1186 friend class LLVMContextImpl;
1187 friend class MDNode;
1189 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1190 ArrayRef<Metadata *> Ops)
1191 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1192 dwarf::DW_TAG_template_type_parameter, Ops) {}
1193 ~MDTemplateTypeParameter() {}
1195 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1196 Metadata *Type, StorageType Storage,
1197 bool ShouldCreate = true) {
1198 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1201 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1202 Metadata *Type, StorageType Storage,
1203 bool ShouldCreate = true);
1205 TempMDTemplateTypeParameter cloneImpl() const {
1206 return getTemporary(getContext(), getName(), getType());
1210 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1212 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1215 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1217 static bool classof(const Metadata *MD) {
1218 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1222 class MDTemplateValueParameter : public MDTemplateParameter {
1223 friend class LLVMContextImpl;
1224 friend class MDNode;
1226 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1227 unsigned Tag, ArrayRef<Metadata *> Ops)
1228 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1230 ~MDTemplateValueParameter() {}
1232 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1233 StringRef Name, Metadata *Type,
1234 Metadata *Value, StorageType Storage,
1235 bool ShouldCreate = true) {
1236 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1237 Value, Storage, ShouldCreate);
1239 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1240 MDString *Name, Metadata *Type,
1241 Metadata *Value, StorageType Storage,
1242 bool ShouldCreate = true);
1244 TempMDTemplateValueParameter cloneImpl() const {
1245 return getTemporary(getContext(), getTag(), getName(), getType(),
1250 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1251 Metadata *Type, Metadata *Value),
1252 (Tag, Name, Type, Value))
1253 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1254 Metadata *Type, Metadata *Value),
1255 (Tag, Name, Type, Value))
1257 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1259 Metadata *getValue() const { return getOperand(2); }
1261 static bool classof(const Metadata *MD) {
1262 return MD->getMetadataID() == MDTemplateValueParameterKind;
1266 /// \brief Base class for variables.
1268 /// TODO: Hardcode to DW_TAG_variable.
1269 class MDVariable : public DebugNode {
1273 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1274 unsigned Line, ArrayRef<Metadata *> Ops)
1275 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1279 unsigned getLine() const { return Line; }
1280 Metadata *getScope() const { return getOperand(0); }
1281 StringRef getName() const { return getStringOperand(1); }
1282 Metadata *getFile() const { return getOperand(2); }
1283 Metadata *getType() const { return getOperand(3); }
1285 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1287 static bool classof(const Metadata *MD) {
1288 return MD->getMetadataID() == MDLocalVariableKind ||
1289 MD->getMetadataID() == MDGlobalVariableKind;
1293 /// \brief Global variables.
1295 /// TODO: Remove DisplayName. It's always equal to Name.
1296 class MDGlobalVariable : public MDVariable {
1297 friend class LLVMContextImpl;
1298 friend class MDNode;
1303 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1304 bool IsLocalToUnit, bool IsDefinition,
1305 ArrayRef<Metadata *> Ops)
1306 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1308 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1309 ~MDGlobalVariable() {}
1311 static MDGlobalVariable *
1312 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1313 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1314 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1315 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1316 bool ShouldCreate = true) {
1317 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1318 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1319 IsLocalToUnit, IsDefinition, Variable,
1320 StaticDataMemberDeclaration, Storage, ShouldCreate);
1322 static MDGlobalVariable *
1323 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1324 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1325 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1326 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1327 bool ShouldCreate = true);
1329 TempMDGlobalVariable cloneImpl() const {
1330 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1331 getFile(), getLine(), getType(), isLocalToUnit(),
1332 isDefinition(), getVariable(),
1333 getStaticDataMemberDeclaration());
1337 DEFINE_MDNODE_GET(MDGlobalVariable,
1338 (Metadata * Scope, StringRef Name, StringRef LinkageName,
1339 Metadata *File, unsigned Line, Metadata *Type,
1340 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1341 Metadata *StaticDataMemberDeclaration),
1342 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1343 IsDefinition, Variable, StaticDataMemberDeclaration))
1344 DEFINE_MDNODE_GET(MDGlobalVariable,
1345 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1346 Metadata *File, unsigned Line, Metadata *Type,
1347 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1348 Metadata *StaticDataMemberDeclaration),
1349 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1350 IsDefinition, Variable, StaticDataMemberDeclaration))
1352 TempMDGlobalVariable clone() const { return cloneImpl(); }
1354 bool isLocalToUnit() const { return IsLocalToUnit; }
1355 bool isDefinition() const { return IsDefinition; }
1356 StringRef getDisplayName() const { return getStringOperand(4); }
1357 StringRef getLinkageName() const { return getStringOperand(5); }
1358 Metadata *getVariable() const { return getOperand(6); }
1359 Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1361 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1363 static bool classof(const Metadata *MD) {
1364 return MD->getMetadataID() == MDGlobalVariableKind;
1368 /// \brief Local variable.
1370 /// TODO: Split between arguments and otherwise.
1371 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1372 /// TODO: Split up flags.
1373 class MDLocalVariable : public MDVariable {
1374 friend class LLVMContextImpl;
1375 friend class MDNode;
1380 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1381 unsigned Line, unsigned Arg, unsigned Flags,
1382 ArrayRef<Metadata *> Ops)
1383 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1385 ~MDLocalVariable() {}
1387 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1388 Metadata *Scope, StringRef Name,
1389 Metadata *File, unsigned Line, Metadata *Type,
1390 unsigned Arg, unsigned Flags,
1391 Metadata *InlinedAt, StorageType Storage,
1392 bool ShouldCreate = true) {
1393 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1394 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1397 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1398 Metadata *Scope, MDString *Name,
1399 Metadata *File, unsigned Line, Metadata *Type,
1400 unsigned Arg, unsigned Flags,
1401 Metadata *InlinedAt, StorageType Storage,
1402 bool ShouldCreate = true);
1404 TempMDLocalVariable cloneImpl() const {
1405 return getTemporary(getContext(), getTag(), getScope(), getName(),
1406 getFile(), getLine(), getType(), getArg(), getFlags(),
1411 DEFINE_MDNODE_GET(MDLocalVariable,
1412 (unsigned Tag, Metadata *Scope, StringRef Name,
1413 Metadata *File, unsigned Line, Metadata *Type,
1414 unsigned Arg, unsigned Flags,
1415 Metadata *InlinedAt = nullptr),
1416 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1417 DEFINE_MDNODE_GET(MDLocalVariable,
1418 (unsigned Tag, Metadata *Scope, MDString *Name,
1419 Metadata *File, unsigned Line, Metadata *Type,
1420 unsigned Arg, unsigned Flags,
1421 Metadata *InlinedAt = nullptr),
1422 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1424 TempMDLocalVariable clone() const { return cloneImpl(); }
1426 unsigned getArg() const { return Arg; }
1427 unsigned getFlags() const { return Flags; }
1428 Metadata *getInlinedAt() const { return getOperand(4); }
1430 /// \brief Get an inlined version of this variable.
1432 /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1433 MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1434 if (InlinedAt == getInlinedAt())
1435 return const_cast<MDLocalVariable *>(this);
1436 auto Temp = clone();
1437 Temp->replaceOperandWith(4, InlinedAt);
1438 return replaceWithUniqued(std::move(Temp));
1440 MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1442 static bool classof(const Metadata *MD) {
1443 return MD->getMetadataID() == MDLocalVariableKind;
1447 /// \brief DWARF expression.
1449 /// TODO: Co-allocate the expression elements.
1450 /// TODO: Drop fake DW_TAG_expression and separate from DebugNode.
1451 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1453 class MDExpression : public DebugNode {
1454 friend class LLVMContextImpl;
1455 friend class MDNode;
1457 std::vector<uint64_t> Elements;
1459 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1460 : DebugNode(C, MDExpressionKind, Storage, dwarf::DW_TAG_expression, None),
1461 Elements(Elements.begin(), Elements.end()) {}
1464 static MDExpression *getImpl(LLVMContext &Context,
1465 ArrayRef<uint64_t> Elements, StorageType Storage,
1466 bool ShouldCreate = true);
1468 TempMDExpression cloneImpl() const {
1469 return getTemporary(getContext(), getElements());
1473 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1475 TempMDExpression clone() const { return cloneImpl(); }
1477 ArrayRef<uint64_t> getElements() const { return Elements; }
1479 unsigned getNumElements() const { return Elements.size(); }
1480 uint64_t getElement(unsigned I) const {
1481 assert(I < Elements.size() && "Index out of range");
1485 typedef ArrayRef<uint64_t>::iterator element_iterator;
1486 element_iterator elements_begin() const { return getElements().begin(); }
1487 element_iterator elements_end() const { return getElements().end(); }
1489 /// \brief A lightweight wrapper around an expression operand.
1491 /// TODO: Store arguments directly and change \a MDExpression to store a
1497 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1499 const uint64_t *get() const { return Op; }
1501 /// \brief Get the operand code.
1502 uint64_t getOp() const { return *Op; }
1504 /// \brief Get an argument to the operand.
1506 /// Never returns the operand itself.
1507 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1509 unsigned getNumArgs() const { return getSize() - 1; }
1511 /// \brief Return the size of the operand.
1513 /// Return the number of elements in the operand (1 + args).
1514 unsigned getSize() const;
1517 /// \brief An iterator for expression operands.
1518 class expr_op_iterator
1519 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1523 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1525 element_iterator getBase() const { return Op.get(); }
1526 const ExprOperand &operator*() const { return Op; }
1527 const ExprOperand *operator->() const { return &Op; }
1529 expr_op_iterator &operator++() {
1533 expr_op_iterator operator++(int) {
1534 expr_op_iterator T(*this);
1539 bool operator==(const expr_op_iterator &X) const {
1540 return getBase() == X.getBase();
1542 bool operator!=(const expr_op_iterator &X) const {
1543 return getBase() != X.getBase();
1547 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1550 /// \brief Visit the elements via ExprOperand wrappers.
1552 /// These range iterators visit elements through \a ExprOperand wrappers.
1553 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1556 /// \pre \a isValid() gives \c true.
1558 expr_op_iterator expr_op_begin() const {
1559 return expr_op_iterator(elements_begin());
1561 expr_op_iterator expr_op_end() const {
1562 return expr_op_iterator(elements_end());
1566 bool isValid() const;
1568 static bool classof(const Metadata *MD) {
1569 return MD->getMetadataID() == MDExpressionKind;
1573 class MDObjCProperty : public DebugNode {
1574 friend class LLVMContextImpl;
1575 friend class MDNode;
1578 unsigned Attributes;
1580 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1581 unsigned Attributes, ArrayRef<Metadata *> Ops)
1582 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1584 Line(Line), Attributes(Attributes) {}
1585 ~MDObjCProperty() {}
1587 static MDObjCProperty *
1588 getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1589 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1590 Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1591 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1592 getCanonicalMDString(Context, GetterName),
1593 getCanonicalMDString(Context, SetterName), Attributes, Type,
1594 Storage, ShouldCreate);
1596 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1597 Metadata *File, unsigned Line,
1598 MDString *GetterName, MDString *SetterName,
1599 unsigned Attributes, Metadata *Type,
1600 StorageType Storage, bool ShouldCreate = true);
1602 TempMDObjCProperty cloneImpl() const {
1603 return getTemporary(getContext(), getName(), getFile(), getLine(),
1604 getGetterName(), getSetterName(), getAttributes(),
1609 DEFINE_MDNODE_GET(MDObjCProperty,
1610 (StringRef Name, Metadata *File, unsigned Line,
1611 StringRef GetterName, StringRef SetterName,
1612 unsigned Attributes, Metadata *Type),
1613 (Name, File, Line, GetterName, SetterName, Attributes,
1615 DEFINE_MDNODE_GET(MDObjCProperty,
1616 (MDString * Name, Metadata *File, unsigned Line,
1617 MDString *GetterName, MDString *SetterName,
1618 unsigned Attributes, Metadata *Type),
1619 (Name, File, Line, GetterName, SetterName, Attributes,
1622 TempMDObjCProperty clone() const { return cloneImpl(); }
1624 unsigned getLine() const { return Line; }
1625 unsigned getAttributes() const { return Attributes; }
1626 StringRef getName() const { return getStringOperand(0); }
1627 Metadata *getFile() const { return getOperand(1); }
1628 StringRef getGetterName() const { return getStringOperand(2); }
1629 StringRef getSetterName() const { return getStringOperand(3); }
1630 Metadata *getType() const { return getOperand(4); }
1632 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1633 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1634 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1636 static bool classof(const Metadata *MD) {
1637 return MD->getMetadataID() == MDObjCPropertyKind;
1641 class MDImportedEntity : public DebugNode {
1642 friend class LLVMContextImpl;
1643 friend class MDNode;
1647 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1648 unsigned Line, ArrayRef<Metadata *> Ops)
1649 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1650 ~MDImportedEntity() {}
1652 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1653 Metadata *Scope, Metadata *Entity,
1654 unsigned Line, StringRef Name,
1655 StorageType Storage,
1656 bool ShouldCreate = true) {
1657 return getImpl(Context, Tag, Scope, Entity, Line,
1658 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1660 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1661 Metadata *Scope, Metadata *Entity,
1662 unsigned Line, MDString *Name,
1663 StorageType Storage,
1664 bool ShouldCreate = true);
1666 TempMDImportedEntity cloneImpl() const {
1667 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1668 getLine(), getName());
1672 DEFINE_MDNODE_GET(MDImportedEntity,
1673 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1674 unsigned Line, StringRef Name = ""),
1675 (Tag, Scope, Entity, Line, Name))
1676 DEFINE_MDNODE_GET(MDImportedEntity,
1677 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1678 unsigned Line, MDString *Name),
1679 (Tag, Scope, Entity, Line, Name))
1681 TempMDImportedEntity clone() const { return cloneImpl(); }
1683 unsigned getLine() const { return Line; }
1684 Metadata *getScope() const { return getOperand(0); }
1685 Metadata *getEntity() const { return getOperand(1); }
1686 StringRef getName() const { return getStringOperand(2); }
1688 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1690 static bool classof(const Metadata *MD) {
1691 return MD->getMetadataID() == MDImportedEntityKind;
1695 } // end namespace llvm
1697 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1698 #undef DEFINE_MDNODE_GET_UNPACK
1699 #undef DEFINE_MDNODE_GET