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 unsigned getLine() const { return Line; }
386 uint64_t getSizeInBits() const { return SizeInBits; }
387 uint64_t getAlignInBits() const { return AlignInBits; }
388 uint64_t getOffsetInBits() const { return OffsetInBits; }
389 unsigned getFlags() const { return Flags; }
391 Metadata *getScope() const { return getOperand(1); }
392 StringRef getName() const { return getStringOperand(2); }
394 MDString *getRawName() const { return getOperandAs<MDString>(2); }
396 static bool classof(const Metadata *MD) {
397 switch (MD->getMetadataID()) {
400 case MDBasicTypeKind:
401 case MDDerivedTypeKind:
402 case MDCompositeTypeKind:
403 case MDSubroutineTypeKind:
409 /// \brief Basic type.
411 /// TODO: Split out DW_TAG_unspecified_type.
412 /// TODO: Drop unused accessors.
413 class MDBasicType : public MDType {
414 friend class LLVMContextImpl;
419 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
420 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
421 ArrayRef<Metadata *> Ops)
422 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
424 Encoding(Encoding) {}
427 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
428 StringRef Name, uint64_t SizeInBits,
429 uint64_t AlignInBits, unsigned Encoding,
430 StorageType Storage, bool ShouldCreate = true) {
431 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
432 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
434 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
435 MDString *Name, uint64_t SizeInBits,
436 uint64_t AlignInBits, unsigned Encoding,
437 StorageType Storage, bool ShouldCreate = true);
439 TempMDBasicType cloneImpl() const {
440 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
441 getAlignInBits(), getEncoding());
445 DEFINE_MDNODE_GET(MDBasicType,
446 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
447 uint64_t AlignInBits, unsigned Encoding),
448 (Tag, Name, SizeInBits, AlignInBits, Encoding))
449 DEFINE_MDNODE_GET(MDBasicType,
450 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
451 uint64_t AlignInBits, unsigned Encoding),
452 (Tag, Name, SizeInBits, AlignInBits, Encoding))
454 TempMDBasicType clone() const { return cloneImpl(); }
456 unsigned getEncoding() const { return Encoding; }
458 static bool classof(const Metadata *MD) {
459 return MD->getMetadataID() == MDBasicTypeKind;
463 /// \brief Base class for MDDerivedType and MDCompositeType.
465 /// TODO: Delete; they're not really related.
466 class MDDerivedTypeBase : public MDType {
468 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
469 unsigned Tag, unsigned Line, uint64_t SizeInBits,
470 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
471 ArrayRef<Metadata *> Ops)
472 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
474 ~MDDerivedTypeBase() {}
477 Metadata *getBaseType() const { return getOperand(3); }
479 static bool classof(const Metadata *MD) {
480 return MD->getMetadataID() == MDDerivedTypeKind ||
481 MD->getMetadataID() == MDCompositeTypeKind ||
482 MD->getMetadataID() == MDSubroutineTypeKind;
486 /// \brief Derived types.
488 /// This includes qualified types, pointers, references, friends, typedefs, and
491 /// TODO: Split out members (inheritance, fields, methods, etc.).
492 class MDDerivedType : public MDDerivedTypeBase {
493 friend class LLVMContextImpl;
496 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
497 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
498 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
499 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
500 AlignInBits, OffsetInBits, Flags, Ops) {}
503 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
504 StringRef Name, Metadata *File, unsigned Line,
505 Metadata *Scope, Metadata *BaseType,
506 uint64_t SizeInBits, uint64_t AlignInBits,
507 uint64_t OffsetInBits, unsigned Flags,
508 Metadata *ExtraData, StorageType Storage,
509 bool ShouldCreate = true) {
510 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
511 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
512 Flags, ExtraData, Storage, ShouldCreate);
514 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
515 MDString *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);
522 TempMDDerivedType cloneImpl() const {
523 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
524 getScope(), getBaseType(), getSizeInBits(),
525 getAlignInBits(), getOffsetInBits(), getFlags(),
530 DEFINE_MDNODE_GET(MDDerivedType,
531 (unsigned Tag, MDString *Name, Metadata *File,
532 unsigned Line, Metadata *Scope, Metadata *BaseType,
533 uint64_t SizeInBits, uint64_t AlignInBits,
534 uint64_t OffsetInBits, unsigned Flags,
535 Metadata *ExtraData = nullptr),
536 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
537 AlignInBits, OffsetInBits, Flags, ExtraData))
538 DEFINE_MDNODE_GET(MDDerivedType,
539 (unsigned Tag, StringRef Name, Metadata *File,
540 unsigned Line, Metadata *Scope, Metadata *BaseType,
541 uint64_t SizeInBits, uint64_t AlignInBits,
542 uint64_t OffsetInBits, unsigned Flags,
543 Metadata *ExtraData = nullptr),
544 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
545 AlignInBits, OffsetInBits, Flags, ExtraData))
547 TempMDDerivedType clone() const { return cloneImpl(); }
549 /// \brief Get extra data associated with this derived type.
551 /// Class type for pointer-to-members, objective-c property node for ivars,
552 /// or global constant wrapper for static members.
554 /// TODO: Separate out types that need this extra operand: pointer-to-member
555 /// types and member fields (static members and ivars).
556 Metadata *getExtraData() const { return getOperand(4); }
558 static bool classof(const Metadata *MD) {
559 return MD->getMetadataID() == MDDerivedTypeKind;
563 /// \brief Base class for MDCompositeType and MDSubroutineType.
565 /// TODO: Delete; they're not really related.
566 class MDCompositeTypeBase : public MDDerivedTypeBase {
567 unsigned RuntimeLang;
570 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
571 unsigned Tag, unsigned Line, unsigned RuntimeLang,
572 uint64_t SizeInBits, uint64_t AlignInBits,
573 uint64_t OffsetInBits, unsigned Flags,
574 ArrayRef<Metadata *> Ops)
575 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
576 OffsetInBits, Flags, Ops),
577 RuntimeLang(RuntimeLang) {}
578 ~MDCompositeTypeBase() {}
581 Metadata *getElements() const { return getOperand(4); }
582 Metadata *getVTableHolder() const { return getOperand(5); }
583 Metadata *getTemplateParams() const { return getOperand(6); }
584 StringRef getIdentifier() const { return getStringOperand(7); }
585 unsigned getRuntimeLang() const { return RuntimeLang; }
587 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
589 /// \brief Replace operands.
591 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
592 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
593 /// of its movement if necessary.
595 void replaceElements(MDTuple *Elements) {
597 if (auto *Old = cast_or_null<MDTuple>(getElements()))
598 for (const auto &Op : Old->operands())
599 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
600 "Lost a member during member list replacement");
602 replaceOperandWith(4, Elements);
604 void replaceVTableHolder(Metadata *VTableHolder) {
605 replaceOperandWith(5, VTableHolder);
607 void replaceTemplateParams(MDTuple *TemplateParams) {
608 replaceOperandWith(6, TemplateParams);
612 static bool classof(const Metadata *MD) {
613 return MD->getMetadataID() == MDCompositeTypeKind ||
614 MD->getMetadataID() == MDSubroutineTypeKind;
618 /// \brief Composite types.
620 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
621 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
622 class MDCompositeType : public MDCompositeTypeBase {
623 friend class LLVMContextImpl;
626 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
627 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
628 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
629 ArrayRef<Metadata *> Ops)
630 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
631 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
633 ~MDCompositeType() {}
635 static MDCompositeType *
636 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
637 unsigned Line, Metadata *Scope, Metadata *BaseType,
638 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
639 uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
640 Metadata *VTableHolder, Metadata *TemplateParams,
641 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
642 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
643 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
644 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
645 getCanonicalMDString(Context, Identifier), Storage,
648 static MDCompositeType *
649 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
650 unsigned Line, Metadata *Scope, Metadata *BaseType,
651 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
652 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
653 Metadata *VTableHolder, Metadata *TemplateParams,
654 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
656 TempMDCompositeType cloneImpl() const {
657 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
658 getScope(), getBaseType(), getSizeInBits(),
659 getAlignInBits(), getOffsetInBits(), getFlags(),
660 getElements(), getRuntimeLang(), getVTableHolder(),
661 getTemplateParams(), getIdentifier());
665 DEFINE_MDNODE_GET(MDCompositeType,
666 (unsigned Tag, StringRef Name, Metadata *File,
667 unsigned Line, Metadata *Scope, Metadata *BaseType,
668 uint64_t SizeInBits, uint64_t AlignInBits,
669 uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
670 unsigned RuntimeLang, Metadata *VTableHolder,
671 Metadata *TemplateParams = nullptr,
672 StringRef Identifier = ""),
673 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
674 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
675 VTableHolder, TemplateParams, Identifier))
676 DEFINE_MDNODE_GET(MDCompositeType,
677 (unsigned Tag, MDString *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 MDString *Identifier = nullptr),
684 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
685 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
686 VTableHolder, TemplateParams, Identifier))
688 TempMDCompositeType clone() const { return cloneImpl(); }
690 static bool classof(const Metadata *MD) {
691 return MD->getMetadataID() == MDCompositeTypeKind;
695 /// \brief Type array for a subprogram.
697 /// TODO: Detach from CompositeType, and fold the array of types in directly
699 class MDSubroutineType : public MDCompositeTypeBase {
700 friend class LLVMContextImpl;
703 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
704 ArrayRef<Metadata *> Ops)
705 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
706 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
708 ~MDSubroutineType() {}
710 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
711 Metadata *TypeArray, StorageType Storage,
712 bool ShouldCreate = true);
714 TempMDSubroutineType cloneImpl() const {
715 return getTemporary(getContext(), getFlags(), getTypeArray());
719 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
722 TempMDSubroutineType clone() const { return cloneImpl(); }
724 Metadata *getTypeArray() const { return getElements(); }
726 static bool classof(const Metadata *MD) {
727 return MD->getMetadataID() == MDSubroutineTypeKind;
733 /// TODO: Merge with directory/file node (including users).
734 /// TODO: Canonicalize paths on creation.
735 class MDFile : public MDScope {
736 friend class LLVMContextImpl;
739 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
740 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
743 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
744 StringRef Directory, StorageType Storage,
745 bool ShouldCreate = true) {
746 return getImpl(Context, getCanonicalMDString(Context, Filename),
747 getCanonicalMDString(Context, Directory), Storage,
750 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
751 MDString *Directory, StorageType Storage,
752 bool ShouldCreate = true);
754 TempMDFile cloneImpl() const {
755 return getTemporary(getContext(), getFilename(), getDirectory());
759 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
760 (Filename, Directory))
761 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
762 (Filename, Directory))
764 TempMDFile clone() const { return cloneImpl(); }
766 StringRef getFilename() const { return getStringOperand(0); }
767 StringRef getDirectory() const { return getStringOperand(1); }
769 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
770 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
772 static bool classof(const Metadata *MD) {
773 return MD->getMetadataID() == MDFileKind;
777 /// \brief Compile unit.
778 class MDCompileUnit : public MDScope {
779 friend class LLVMContextImpl;
782 unsigned SourceLanguage;
784 unsigned RuntimeVersion;
785 unsigned EmissionKind;
787 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
788 bool IsOptimized, unsigned RuntimeVersion,
789 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
790 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
791 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
792 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
795 static MDCompileUnit *
796 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
797 StringRef Producer, bool IsOptimized, StringRef Flags,
798 unsigned RuntimeVersion, StringRef SplitDebugFilename,
799 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
800 Metadata *Subprograms, Metadata *GlobalVariables,
801 Metadata *ImportedEntities, StorageType Storage,
802 bool ShouldCreate = true) {
803 return getImpl(Context, SourceLanguage, File,
804 getCanonicalMDString(Context, Producer), IsOptimized,
805 getCanonicalMDString(Context, Flags), RuntimeVersion,
806 getCanonicalMDString(Context, SplitDebugFilename),
807 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
808 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
810 static MDCompileUnit *
811 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
812 MDString *Producer, bool IsOptimized, MDString *Flags,
813 unsigned RuntimeVersion, MDString *SplitDebugFilename,
814 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
815 Metadata *Subprograms, Metadata *GlobalVariables,
816 Metadata *ImportedEntities, StorageType Storage,
817 bool ShouldCreate = true);
819 TempMDCompileUnit cloneImpl() const {
821 getContext(), getSourceLanguage(), getFile(), getProducer(),
822 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
823 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
824 getGlobalVariables(), getImportedEntities());
828 DEFINE_MDNODE_GET(MDCompileUnit,
829 (unsigned SourceLanguage, Metadata *File,
830 StringRef Producer, bool IsOptimized, StringRef Flags,
831 unsigned RuntimeVersion, StringRef SplitDebugFilename,
832 unsigned EmissionKind, Metadata *EnumTypes,
833 Metadata *RetainedTypes, Metadata *Subprograms,
834 Metadata *GlobalVariables, Metadata *ImportedEntities),
835 (SourceLanguage, File, Producer, IsOptimized, Flags,
836 RuntimeVersion, SplitDebugFilename, EmissionKind,
837 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
839 DEFINE_MDNODE_GET(MDCompileUnit,
840 (unsigned SourceLanguage, Metadata *File,
841 MDString *Producer, bool IsOptimized, MDString *Flags,
842 unsigned RuntimeVersion, MDString *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,
851 TempMDCompileUnit clone() const { return cloneImpl(); }
853 unsigned getSourceLanguage() const { return SourceLanguage; }
854 bool isOptimized() const { return IsOptimized; }
855 unsigned getRuntimeVersion() const { return RuntimeVersion; }
856 unsigned getEmissionKind() const { return EmissionKind; }
857 StringRef getProducer() const { return getStringOperand(1); }
858 StringRef getFlags() const { return getStringOperand(2); }
859 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
860 Metadata *getEnumTypes() const { return getOperand(4); }
861 Metadata *getRetainedTypes() const { return getOperand(5); }
862 Metadata *getSubprograms() const { return getOperand(6); }
863 Metadata *getGlobalVariables() const { return getOperand(7); }
864 Metadata *getImportedEntities() const { return getOperand(8); }
866 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
867 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
868 MDString *getRawSplitDebugFilename() const {
869 return getOperandAs<MDString>(3);
872 /// \brief Replace arrays.
874 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
875 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
876 /// MDCompileUnit should be fairly rare.
878 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
879 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
882 static bool classof(const Metadata *MD) {
883 return MD->getMetadataID() == MDCompileUnitKind;
887 /// \brief Subprogram description.
889 /// TODO: Remove DisplayName. It's always equal to Name.
890 /// TODO: Split up flags.
891 class MDSubprogram : public MDScope {
892 friend class LLVMContextImpl;
898 unsigned VirtualIndex;
904 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
905 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
906 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
907 bool IsOptimized, ArrayRef<Metadata *> Ops)
908 : MDScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
909 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
910 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
911 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
914 static MDSubprogram *
915 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
916 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
917 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
918 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
919 unsigned Flags, bool IsOptimized, Metadata *Function,
920 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
921 StorageType Storage, bool ShouldCreate = true) {
922 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
923 getCanonicalMDString(Context, LinkageName), File, Line, Type,
924 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
925 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
926 TemplateParams, Declaration, Variables, Storage,
929 static MDSubprogram *
930 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
931 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
932 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
933 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
934 unsigned Flags, bool IsOptimized, Metadata *Function,
935 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
936 StorageType Storage, bool ShouldCreate = true);
938 TempMDSubprogram cloneImpl() const {
939 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
940 getFile(), getLine(), getType(), isLocalToUnit(),
941 isDefinition(), getScopeLine(), getContainingType(),
942 getVirtuality(), getVirtualIndex(), getFlags(),
943 isOptimized(), getFunction(), getTemplateParams(),
944 getDeclaration(), getVariables());
950 (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
951 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
952 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
953 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
954 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
955 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
956 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
957 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
958 Function, TemplateParams, Declaration, Variables))
961 (Metadata * Scope, MDString *Name, MDString *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))
971 TempMDSubprogram clone() const { return cloneImpl(); }
974 unsigned getLine() const { return Line; }
975 unsigned getVirtuality() const { return Virtuality; }
976 unsigned getVirtualIndex() const { return VirtualIndex; }
977 unsigned getScopeLine() const { return ScopeLine; }
978 unsigned getFlags() const { return Flags; }
979 bool isLocalToUnit() const { return IsLocalToUnit; }
980 bool isDefinition() const { return IsDefinition; }
981 bool isOptimized() const { return IsOptimized; }
983 Metadata *getScope() const { return getOperand(1); }
985 StringRef getName() const { return getStringOperand(2); }
986 StringRef getDisplayName() const { return getStringOperand(3); }
987 StringRef getLinkageName() const { return getStringOperand(4); }
989 MDString *getRawName() const { return getOperandAs<MDString>(2); }
990 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
992 Metadata *getType() const { return getOperand(5); }
993 Metadata *getContainingType() const { return getOperand(6); }
995 Metadata *getFunction() const { return getOperand(7); }
996 Metadata *getTemplateParams() const { return getOperand(8); }
997 Metadata *getDeclaration() const { return getOperand(9); }
998 Metadata *getVariables() const { return getOperand(10); }
1000 /// \brief Replace the function.
1002 /// If \a isUniqued() and not \a isResolved(), this could node will be
1003 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
1004 /// that's a problem.
1006 void replaceFunction(Function *F);
1007 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1008 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1011 static bool classof(const Metadata *MD) {
1012 return MD->getMetadataID() == MDSubprogramKind;
1016 class MDLexicalBlockBase : public MDScope {
1018 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1019 ArrayRef<Metadata *> Ops)
1020 : MDScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1021 ~MDLexicalBlockBase() {}
1024 Metadata *getScope() const { return getOperand(1); }
1026 static bool classof(const Metadata *MD) {
1027 return MD->getMetadataID() == MDLexicalBlockKind ||
1028 MD->getMetadataID() == MDLexicalBlockFileKind;
1032 class MDLexicalBlock : public MDLexicalBlockBase {
1033 friend class LLVMContextImpl;
1034 friend class MDNode;
1039 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1040 unsigned Column, ArrayRef<Metadata *> Ops)
1041 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1043 ~MDLexicalBlock() {}
1045 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1046 Metadata *File, unsigned Line, unsigned Column,
1047 StorageType Storage, bool ShouldCreate = true);
1049 TempMDLexicalBlock cloneImpl() const {
1050 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1055 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1056 unsigned Line, unsigned Column),
1057 (Scope, File, Line, Column))
1059 TempMDLexicalBlock clone() const { return cloneImpl(); }
1061 unsigned getLine() const { return Line; }
1062 unsigned getColumn() const { return Column; }
1064 static bool classof(const Metadata *MD) {
1065 return MD->getMetadataID() == MDLexicalBlockKind;
1069 class MDLexicalBlockFile : public MDLexicalBlockBase {
1070 friend class LLVMContextImpl;
1071 friend class MDNode;
1073 unsigned Discriminator;
1075 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1076 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1077 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1078 Discriminator(Discriminator) {}
1079 ~MDLexicalBlockFile() {}
1081 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1082 Metadata *File, unsigned Discriminator,
1083 StorageType Storage,
1084 bool ShouldCreate = true);
1086 TempMDLexicalBlockFile cloneImpl() const {
1087 return getTemporary(getContext(), getScope(), getFile(),
1088 getDiscriminator());
1092 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1093 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1094 (Scope, File, Discriminator))
1096 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1098 unsigned getDiscriminator() const { return Discriminator; }
1100 static bool classof(const Metadata *MD) {
1101 return MD->getMetadataID() == MDLexicalBlockFileKind;
1105 class MDNamespace : public MDScope {
1106 friend class LLVMContextImpl;
1107 friend class MDNode;
1111 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1112 ArrayRef<Metadata *> Ops)
1113 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1118 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1119 Metadata *File, StringRef Name, unsigned Line,
1120 StorageType Storage, bool ShouldCreate = true) {
1121 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1122 Line, Storage, ShouldCreate);
1124 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1125 Metadata *File, MDString *Name, unsigned Line,
1126 StorageType Storage, bool ShouldCreate = true);
1128 TempMDNamespace cloneImpl() const {
1129 return getTemporary(getContext(), getScope(), getFile(), getName(),
1134 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1135 StringRef Name, unsigned Line),
1136 (Scope, File, Name, Line))
1137 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1138 MDString *Name, unsigned Line),
1139 (Scope, File, Name, Line))
1141 TempMDNamespace clone() const { return cloneImpl(); }
1143 unsigned getLine() const { return Line; }
1144 Metadata *getScope() const { return getOperand(1); }
1145 StringRef getName() const { return getStringOperand(2); }
1147 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1149 static bool classof(const Metadata *MD) {
1150 return MD->getMetadataID() == MDNamespaceKind;
1154 /// \brief Base class for template parameters.
1155 class MDTemplateParameter : public DebugNode {
1157 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1158 unsigned Tag, ArrayRef<Metadata *> Ops)
1159 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1160 ~MDTemplateParameter() {}
1163 StringRef getName() const { return getStringOperand(0); }
1164 Metadata *getType() const { return getOperand(1); }
1166 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1168 static bool classof(const Metadata *MD) {
1169 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1170 MD->getMetadataID() == MDTemplateValueParameterKind;
1174 class MDTemplateTypeParameter : public MDTemplateParameter {
1175 friend class LLVMContextImpl;
1176 friend class MDNode;
1178 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1179 ArrayRef<Metadata *> Ops)
1180 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1181 dwarf::DW_TAG_template_type_parameter, Ops) {}
1182 ~MDTemplateTypeParameter() {}
1184 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1185 Metadata *Type, StorageType Storage,
1186 bool ShouldCreate = true) {
1187 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1190 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1191 Metadata *Type, StorageType Storage,
1192 bool ShouldCreate = true);
1194 TempMDTemplateTypeParameter cloneImpl() const {
1195 return getTemporary(getContext(), getName(), getType());
1199 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1201 DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1204 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1206 static bool classof(const Metadata *MD) {
1207 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1211 class MDTemplateValueParameter : public MDTemplateParameter {
1212 friend class LLVMContextImpl;
1213 friend class MDNode;
1215 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1216 unsigned Tag, ArrayRef<Metadata *> Ops)
1217 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1219 ~MDTemplateValueParameter() {}
1221 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1222 StringRef Name, Metadata *Type,
1223 Metadata *Value, StorageType Storage,
1224 bool ShouldCreate = true) {
1225 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1226 Value, Storage, ShouldCreate);
1228 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1229 MDString *Name, Metadata *Type,
1230 Metadata *Value, StorageType Storage,
1231 bool ShouldCreate = true);
1233 TempMDTemplateValueParameter cloneImpl() const {
1234 return getTemporary(getContext(), getTag(), getName(), getType(),
1239 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1240 Metadata *Type, Metadata *Value),
1241 (Tag, Name, Type, Value))
1242 DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1243 Metadata *Type, Metadata *Value),
1244 (Tag, Name, Type, Value))
1246 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1248 Metadata *getValue() const { return getOperand(2); }
1250 static bool classof(const Metadata *MD) {
1251 return MD->getMetadataID() == MDTemplateValueParameterKind;
1255 /// \brief Base class for variables.
1257 /// TODO: Hardcode to DW_TAG_variable.
1258 class MDVariable : public DebugNode {
1262 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1263 unsigned Line, ArrayRef<Metadata *> Ops)
1264 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1268 unsigned getLine() const { return Line; }
1269 Metadata *getScope() const { return getOperand(0); }
1270 StringRef getName() const { return getStringOperand(1); }
1271 Metadata *getFile() const { return getOperand(2); }
1272 Metadata *getType() const { return getOperand(3); }
1274 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1276 static bool classof(const Metadata *MD) {
1277 return MD->getMetadataID() == MDLocalVariableKind ||
1278 MD->getMetadataID() == MDGlobalVariableKind;
1282 /// \brief Global variables.
1284 /// TODO: Remove DisplayName. It's always equal to Name.
1285 class MDGlobalVariable : public MDVariable {
1286 friend class LLVMContextImpl;
1287 friend class MDNode;
1292 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1293 bool IsLocalToUnit, bool IsDefinition,
1294 ArrayRef<Metadata *> Ops)
1295 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1297 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1298 ~MDGlobalVariable() {}
1300 static MDGlobalVariable *
1301 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1302 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1303 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1304 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1305 bool ShouldCreate = true) {
1306 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1307 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1308 IsLocalToUnit, IsDefinition, Variable,
1309 StaticDataMemberDeclaration, Storage, ShouldCreate);
1311 static MDGlobalVariable *
1312 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1313 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1314 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1315 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1316 bool ShouldCreate = true);
1318 TempMDGlobalVariable cloneImpl() const {
1319 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1320 getFile(), getLine(), getType(), isLocalToUnit(),
1321 isDefinition(), getVariable(),
1322 getStaticDataMemberDeclaration());
1326 DEFINE_MDNODE_GET(MDGlobalVariable,
1327 (Metadata * Scope, StringRef Name, StringRef LinkageName,
1328 Metadata *File, unsigned Line, Metadata *Type,
1329 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1330 Metadata *StaticDataMemberDeclaration),
1331 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1332 IsDefinition, Variable, StaticDataMemberDeclaration))
1333 DEFINE_MDNODE_GET(MDGlobalVariable,
1334 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1335 Metadata *File, unsigned Line, Metadata *Type,
1336 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1337 Metadata *StaticDataMemberDeclaration),
1338 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1339 IsDefinition, Variable, StaticDataMemberDeclaration))
1341 TempMDGlobalVariable clone() const { return cloneImpl(); }
1343 bool isLocalToUnit() const { return IsLocalToUnit; }
1344 bool isDefinition() const { return IsDefinition; }
1345 StringRef getDisplayName() const { return getStringOperand(4); }
1346 StringRef getLinkageName() const { return getStringOperand(5); }
1347 Metadata *getVariable() const { return getOperand(6); }
1348 Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1350 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1352 static bool classof(const Metadata *MD) {
1353 return MD->getMetadataID() == MDGlobalVariableKind;
1357 /// \brief Local variable.
1359 /// TODO: Split between arguments and otherwise.
1360 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1361 /// TODO: Split up flags.
1362 class MDLocalVariable : public MDVariable {
1363 friend class LLVMContextImpl;
1364 friend class MDNode;
1369 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1370 unsigned Line, unsigned Arg, unsigned Flags,
1371 ArrayRef<Metadata *> Ops)
1372 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1374 ~MDLocalVariable() {}
1376 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1377 Metadata *Scope, StringRef Name,
1378 Metadata *File, unsigned Line, Metadata *Type,
1379 unsigned Arg, unsigned Flags,
1380 Metadata *InlinedAt, StorageType Storage,
1381 bool ShouldCreate = true) {
1382 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1383 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1386 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1387 Metadata *Scope, MDString *Name,
1388 Metadata *File, unsigned Line, Metadata *Type,
1389 unsigned Arg, unsigned Flags,
1390 Metadata *InlinedAt, StorageType Storage,
1391 bool ShouldCreate = true);
1393 TempMDLocalVariable cloneImpl() const {
1394 return getTemporary(getContext(), getTag(), getScope(), getName(),
1395 getFile(), getLine(), getType(), getArg(), getFlags(),
1400 DEFINE_MDNODE_GET(MDLocalVariable,
1401 (unsigned Tag, Metadata *Scope, StringRef Name,
1402 Metadata *File, unsigned Line, Metadata *Type,
1403 unsigned Arg, unsigned Flags,
1404 Metadata *InlinedAt = nullptr),
1405 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1406 DEFINE_MDNODE_GET(MDLocalVariable,
1407 (unsigned Tag, Metadata *Scope, MDString *Name,
1408 Metadata *File, unsigned Line, Metadata *Type,
1409 unsigned Arg, unsigned Flags,
1410 Metadata *InlinedAt = nullptr),
1411 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1413 TempMDLocalVariable clone() const { return cloneImpl(); }
1415 unsigned getArg() const { return Arg; }
1416 unsigned getFlags() const { return Flags; }
1417 Metadata *getInlinedAt() const { return getOperand(4); }
1419 static bool classof(const Metadata *MD) {
1420 return MD->getMetadataID() == MDLocalVariableKind;
1424 /// \brief DWARF expression.
1426 /// TODO: Co-allocate the expression elements.
1427 /// TODO: Drop fake DW_TAG_expression and separate from DebugNode.
1428 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1430 class MDExpression : public DebugNode {
1431 friend class LLVMContextImpl;
1432 friend class MDNode;
1434 std::vector<uint64_t> Elements;
1436 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1437 : DebugNode(C, MDExpressionKind, Storage, dwarf::DW_TAG_expression, None),
1438 Elements(Elements.begin(), Elements.end()) {}
1441 static MDExpression *getImpl(LLVMContext &Context,
1442 ArrayRef<uint64_t> Elements, StorageType Storage,
1443 bool ShouldCreate = true);
1445 TempMDExpression cloneImpl() const {
1446 return getTemporary(getContext(), getElements());
1450 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1452 TempMDExpression clone() const { return cloneImpl(); }
1454 ArrayRef<uint64_t> getElements() const { return Elements; }
1456 unsigned getNumElements() const { return Elements.size(); }
1457 uint64_t getElement(unsigned I) const {
1458 assert(I < Elements.size() && "Index out of range");
1462 typedef ArrayRef<uint64_t>::iterator element_iterator;
1463 element_iterator elements_begin() const { return getElements().begin(); }
1464 element_iterator elements_end() const { return getElements().end(); }
1466 /// \brief A lightweight wrapper around an expression operand.
1468 /// TODO: Store arguments directly and change \a MDExpression to store a
1474 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1476 const uint64_t *get() const { return Op; }
1478 /// \brief Get the operand code.
1479 uint64_t getOp() const { return *Op; }
1481 /// \brief Get an argument to the operand.
1483 /// Never returns the operand itself.
1484 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1486 unsigned getNumArgs() const { return getSize() - 1; }
1488 /// \brief Return the size of the operand.
1490 /// Return the number of elements in the operand (1 + args).
1491 unsigned getSize() const;
1494 /// \brief An iterator for expression operands.
1495 class expr_op_iterator
1496 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1500 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1502 element_iterator getBase() const { return Op.get(); }
1503 const ExprOperand &operator*() const { return Op; }
1504 const ExprOperand *operator->() const { return &Op; }
1506 expr_op_iterator &operator++() {
1510 expr_op_iterator operator++(int) {
1511 expr_op_iterator T(*this);
1516 bool operator==(const expr_op_iterator &X) const {
1517 return getBase() == X.getBase();
1519 bool operator!=(const expr_op_iterator &X) const {
1520 return getBase() != X.getBase();
1524 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1527 /// \brief Visit the elements via ExprOperand wrappers.
1529 /// These range iterators visit elements through \a ExprOperand wrappers.
1530 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1533 /// \pre \a isValid() gives \c true.
1535 expr_op_iterator expr_op_begin() const {
1536 return expr_op_iterator(elements_begin());
1538 expr_op_iterator expr_op_end() const {
1539 return expr_op_iterator(elements_end());
1543 bool isValid() const;
1545 static bool classof(const Metadata *MD) {
1546 return MD->getMetadataID() == MDExpressionKind;
1550 class MDObjCProperty : public DebugNode {
1551 friend class LLVMContextImpl;
1552 friend class MDNode;
1555 unsigned Attributes;
1557 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1558 unsigned Attributes, ArrayRef<Metadata *> Ops)
1559 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1561 Line(Line), Attributes(Attributes) {}
1562 ~MDObjCProperty() {}
1564 static MDObjCProperty *
1565 getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1566 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1567 Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1568 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1569 getCanonicalMDString(Context, GetterName),
1570 getCanonicalMDString(Context, SetterName), Attributes, Type,
1571 Storage, ShouldCreate);
1573 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1574 Metadata *File, unsigned Line,
1575 MDString *GetterName, MDString *SetterName,
1576 unsigned Attributes, Metadata *Type,
1577 StorageType Storage, bool ShouldCreate = true);
1579 TempMDObjCProperty cloneImpl() const {
1580 return getTemporary(getContext(), getName(), getFile(), getLine(),
1581 getGetterName(), getSetterName(), getAttributes(),
1586 DEFINE_MDNODE_GET(MDObjCProperty,
1587 (StringRef Name, Metadata *File, unsigned Line,
1588 StringRef GetterName, StringRef SetterName,
1589 unsigned Attributes, Metadata *Type),
1590 (Name, File, Line, GetterName, SetterName, Attributes,
1592 DEFINE_MDNODE_GET(MDObjCProperty,
1593 (MDString * Name, Metadata *File, unsigned Line,
1594 MDString *GetterName, MDString *SetterName,
1595 unsigned Attributes, Metadata *Type),
1596 (Name, File, Line, GetterName, SetterName, Attributes,
1599 TempMDObjCProperty clone() const { return cloneImpl(); }
1601 unsigned getLine() const { return Line; }
1602 unsigned getAttributes() const { return Attributes; }
1603 StringRef getName() const { return getStringOperand(0); }
1604 Metadata *getFile() const { return getOperand(1); }
1605 StringRef getGetterName() const { return getStringOperand(2); }
1606 StringRef getSetterName() const { return getStringOperand(3); }
1607 Metadata *getType() const { return getOperand(4); }
1609 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1610 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1611 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1613 static bool classof(const Metadata *MD) {
1614 return MD->getMetadataID() == MDObjCPropertyKind;
1618 class MDImportedEntity : public DebugNode {
1619 friend class LLVMContextImpl;
1620 friend class MDNode;
1624 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1625 unsigned Line, ArrayRef<Metadata *> Ops)
1626 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1627 ~MDImportedEntity() {}
1629 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1630 Metadata *Scope, Metadata *Entity,
1631 unsigned Line, StringRef Name,
1632 StorageType Storage,
1633 bool ShouldCreate = true) {
1634 return getImpl(Context, Tag, Scope, Entity, Line,
1635 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1637 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1638 Metadata *Scope, Metadata *Entity,
1639 unsigned Line, MDString *Name,
1640 StorageType Storage,
1641 bool ShouldCreate = true);
1643 TempMDImportedEntity cloneImpl() const {
1644 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1645 getLine(), getName());
1649 DEFINE_MDNODE_GET(MDImportedEntity,
1650 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1651 unsigned Line, StringRef Name = ""),
1652 (Tag, Scope, Entity, Line, Name))
1653 DEFINE_MDNODE_GET(MDImportedEntity,
1654 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1655 unsigned Line, MDString *Name),
1656 (Tag, Scope, Entity, Line, Name))
1658 TempMDImportedEntity clone() const { return cloneImpl(); }
1660 unsigned getLine() const { return Line; }
1661 Metadata *getScope() const { return getOperand(0); }
1662 Metadata *getEntity() const { return getOperand(1); }
1663 StringRef getName() const { return getStringOperand(2); }
1665 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1667 static bool classof(const Metadata *MD) {
1668 return MD->getMetadataID() == MDImportedEntityKind;
1672 } // end namespace llvm
1674 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1675 #undef DEFINE_MDNODE_GET_UNPACK
1676 #undef DEFINE_MDNODE_GET