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 Metadata *getFile() const { return getOperand(0); }
335 static bool classof(const Metadata *MD) {
336 switch (MD->getMetadataID()) {
339 case MDBasicTypeKind:
340 case MDDerivedTypeKind:
341 case MDCompositeTypeKind:
342 case MDSubroutineTypeKind:
344 case MDCompileUnitKind:
345 case MDSubprogramKind:
346 case MDLexicalBlockKind:
347 case MDLexicalBlockFileKind:
348 case MDNamespaceKind:
354 /// \brief Base class for types.
356 /// TODO: Remove the hardcoded name and context, since many types don't use
358 /// TODO: Split up flags.
359 class MDType : public MDScope {
362 unsigned AlignInBits;
363 unsigned OffsetInBits;
367 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
368 unsigned Line, unsigned SizeInBits, unsigned AlignInBits,
369 unsigned OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
370 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), SizeInBits(SizeInBits),
371 AlignInBits(AlignInBits), OffsetInBits(OffsetInBits), Flags(Flags) {}
375 unsigned getLine() const { return Line; }
376 unsigned getSizeInBits() const { return SizeInBits; }
377 unsigned getAlignInBits() const { return AlignInBits; }
378 unsigned getOffsetInBits() const { return OffsetInBits; }
379 unsigned getFlags() const { return Flags; }
381 Metadata *getScope() const { return getOperand(1); }
382 StringRef getName() const { return getStringOperand(2); }
384 MDString *getRawName() const { return getOperandAs<MDString>(2); }
386 static bool classof(const Metadata *MD) {
387 switch (MD->getMetadataID()) {
390 case MDBasicTypeKind:
391 case MDDerivedTypeKind:
392 case MDCompositeTypeKind:
393 case MDSubroutineTypeKind:
399 /// \brief Basic type.
401 /// TODO: Split out DW_TAG_unspecified_type.
402 /// TODO: Drop unused accessors.
403 class MDBasicType : public MDType {
404 friend class LLVMContextImpl;
409 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
410 unsigned SizeInBits, unsigned AlignInBits, unsigned Encoding,
411 ArrayRef<Metadata *> Ops)
412 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
414 Encoding(Encoding) {}
417 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
418 StringRef Name, unsigned SizeInBits,
419 unsigned AlignInBits, unsigned Encoding,
420 StorageType Storage, bool ShouldCreate = true) {
421 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
422 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
424 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
425 MDString *Name, unsigned SizeInBits,
426 unsigned AlignInBits, unsigned Encoding,
427 StorageType Storage, bool ShouldCreate = true);
429 TempMDBasicType cloneImpl() const {
430 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
431 getAlignInBits(), getEncoding());
435 DEFINE_MDNODE_GET(MDBasicType,
436 (unsigned Tag, StringRef Name, unsigned SizeInBits,
437 unsigned AlignInBits, unsigned Encoding),
438 (Tag, Name, SizeInBits, AlignInBits, Encoding))
439 DEFINE_MDNODE_GET(MDBasicType,
440 (unsigned Tag, MDString *Name, unsigned SizeInBits,
441 unsigned AlignInBits, unsigned Encoding),
442 (Tag, Name, SizeInBits, AlignInBits, Encoding))
444 TempMDBasicType clone() const { return cloneImpl(); }
446 unsigned getEncoding() const { return Encoding; }
448 static bool classof(const Metadata *MD) {
449 return MD->getMetadataID() == MDBasicTypeKind;
453 /// \brief Base class for MDDerivedType and MDCompositeType.
455 /// TODO: Delete; they're not really related.
456 class MDDerivedTypeBase : public MDType {
458 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
459 unsigned Tag, unsigned Line, unsigned SizeInBits,
460 unsigned AlignInBits, unsigned OffsetInBits, unsigned Flags,
461 ArrayRef<Metadata *> Ops)
462 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
464 ~MDDerivedTypeBase() {}
467 Metadata *getBaseType() const { return getOperand(3); }
469 static bool classof(const Metadata *MD) {
470 return MD->getMetadataID() == MDDerivedTypeKind ||
471 MD->getMetadataID() == MDCompositeTypeKind ||
472 MD->getMetadataID() == MDSubroutineTypeKind;
476 /// \brief Derived types.
478 /// This includes qualified types, pointers, references, friends, typedefs, and
481 /// TODO: Split out members (inheritance, fields, methods, etc.).
482 class MDDerivedType : public MDDerivedTypeBase {
483 friend class LLVMContextImpl;
486 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
487 unsigned Line, unsigned SizeInBits, unsigned AlignInBits,
488 unsigned OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
489 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
490 AlignInBits, OffsetInBits, Flags, Ops) {}
493 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
494 StringRef Name, Metadata *File, unsigned Line,
495 Metadata *Scope, Metadata *BaseType,
496 unsigned SizeInBits, unsigned AlignInBits,
497 unsigned OffsetInBits, unsigned Flags,
498 Metadata *ExtraData, StorageType Storage,
499 bool ShouldCreate = true) {
500 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
501 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
502 Flags, ExtraData, Storage, ShouldCreate);
504 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
505 MDString *Name, Metadata *File, unsigned Line,
506 Metadata *Scope, Metadata *BaseType,
507 unsigned SizeInBits, unsigned AlignInBits,
508 unsigned OffsetInBits, unsigned Flags,
509 Metadata *ExtraData, StorageType Storage,
510 bool ShouldCreate = true);
512 TempMDDerivedType cloneImpl() const {
513 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
514 getScope(), getBaseType(), getSizeInBits(),
515 getAlignInBits(), getOffsetInBits(), getFlags(),
520 DEFINE_MDNODE_GET(MDDerivedType,
521 (unsigned Tag, MDString *Name, Metadata *File,
522 unsigned Line, Metadata *Scope, Metadata *BaseType,
523 unsigned SizeInBits, unsigned AlignInBits,
524 unsigned OffsetInBits, unsigned Flags,
525 Metadata *ExtraData = nullptr),
526 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
527 AlignInBits, OffsetInBits, Flags, ExtraData))
528 DEFINE_MDNODE_GET(MDDerivedType,
529 (unsigned Tag, StringRef Name, Metadata *File,
530 unsigned Line, Metadata *Scope, Metadata *BaseType,
531 unsigned SizeInBits, unsigned AlignInBits,
532 unsigned OffsetInBits, unsigned Flags,
533 Metadata *ExtraData = nullptr),
534 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
535 AlignInBits, OffsetInBits, Flags, ExtraData))
537 TempMDDerivedType clone() const { return cloneImpl(); }
539 /// \brief Get extra data associated with this derived type.
541 /// Class type for pointer-to-members, objective-c property node for ivars,
542 /// or global constant wrapper for static members.
544 /// TODO: Separate out types that need this extra operand: pointer-to-member
545 /// types and member fields (static members and ivars).
546 Metadata *getExtraData() const { return getOperand(4); }
548 static bool classof(const Metadata *MD) {
549 return MD->getMetadataID() == MDDerivedTypeKind;
553 /// \brief Base class for MDCompositeType and MDSubroutineType.
555 /// TODO: Delete; they're not really related.
556 class MDCompositeTypeBase : public MDDerivedTypeBase {
557 unsigned RuntimeLang;
560 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
561 unsigned Tag, unsigned Line, unsigned RuntimeLang,
562 unsigned SizeInBits, unsigned AlignInBits,
563 unsigned OffsetInBits, unsigned Flags,
564 ArrayRef<Metadata *> Ops)
565 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
566 OffsetInBits, Flags, Ops),
567 RuntimeLang(RuntimeLang) {}
568 ~MDCompositeTypeBase() {}
571 Metadata *getElements() const { return getOperand(4); }
572 Metadata *getVTableHolder() const { return getOperand(5); }
573 Metadata *getTemplateParams() const { return getOperand(6); }
574 StringRef getIdentifier() const { return getStringOperand(7); }
575 unsigned getRuntimeLang() const { return RuntimeLang; }
577 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
579 static bool classof(const Metadata *MD) {
580 return MD->getMetadataID() == MDCompositeTypeKind ||
581 MD->getMetadataID() == MDSubroutineTypeKind;
585 /// \brief Composite types.
587 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
588 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
589 class MDCompositeType : public MDCompositeTypeBase {
590 friend class LLVMContextImpl;
593 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
594 unsigned Line, unsigned RuntimeLang, unsigned SizeInBits,
595 unsigned AlignInBits, unsigned OffsetInBits, unsigned Flags,
596 ArrayRef<Metadata *> Ops)
597 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
598 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
600 ~MDCompositeType() {}
602 static MDCompositeType *
603 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
604 unsigned Line, Metadata *Scope, Metadata *BaseType,
605 unsigned SizeInBits, unsigned AlignInBits, unsigned OffsetInBits,
606 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
607 Metadata *VTableHolder, Metadata *TemplateParams,
608 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
609 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
610 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
611 Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
612 getCanonicalMDString(Context, Identifier), Storage,
615 static MDCompositeType *
616 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
617 unsigned Line, Metadata *Scope, Metadata *BaseType,
618 unsigned SizeInBits, unsigned AlignInBits, unsigned OffsetInBits,
619 unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
620 Metadata *VTableHolder, Metadata *TemplateParams,
621 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
623 TempMDCompositeType cloneImpl() const {
624 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
625 getScope(), getBaseType(), getSizeInBits(),
626 getAlignInBits(), getOffsetInBits(), getFlags(),
627 getElements(), getRuntimeLang(), getVTableHolder(),
628 getTemplateParams(), getIdentifier());
632 DEFINE_MDNODE_GET(MDCompositeType,
633 (unsigned Tag, StringRef Name, Metadata *File,
634 unsigned Line, Metadata *Scope, Metadata *BaseType,
635 unsigned SizeInBits, unsigned AlignInBits,
636 unsigned OffsetInBits, unsigned Flags, Metadata *Elements,
637 unsigned RuntimeLang, Metadata *VTableHolder,
638 Metadata *TemplateParams = nullptr,
639 StringRef Identifier = ""),
640 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
641 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
642 VTableHolder, TemplateParams, Identifier))
643 DEFINE_MDNODE_GET(MDCompositeType,
644 (unsigned Tag, MDString *Name, Metadata *File,
645 unsigned Line, Metadata *Scope, Metadata *BaseType,
646 unsigned SizeInBits, unsigned AlignInBits,
647 unsigned OffsetInBits, unsigned Flags, Metadata *Elements,
648 unsigned RuntimeLang, Metadata *VTableHolder,
649 Metadata *TemplateParams = nullptr,
650 MDString *Identifier = nullptr),
651 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
652 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
653 VTableHolder, TemplateParams, Identifier))
655 TempMDCompositeType clone() const { return cloneImpl(); }
657 static bool classof(const Metadata *MD) {
658 return MD->getMetadataID() == MDCompositeTypeKind;
662 /// \brief Type array for a subprogram.
664 /// TODO: Detach from CompositeType, and fold the array of types in directly
666 class MDSubroutineType : public MDCompositeTypeBase {
667 friend class LLVMContextImpl;
670 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
671 ArrayRef<Metadata *> Ops)
672 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
673 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
675 ~MDSubroutineType() {}
677 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
678 Metadata *TypeArray, StorageType Storage,
679 bool ShouldCreate = true);
681 TempMDSubroutineType cloneImpl() const {
682 return getTemporary(getContext(), getFlags(), getTypeArray());
686 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
689 TempMDSubroutineType clone() const { return cloneImpl(); }
691 Metadata *getTypeArray() const { return getElements(); }
693 static bool classof(const Metadata *MD) {
694 return MD->getMetadataID() == MDSubroutineTypeKind;
700 /// TODO: Merge with directory/file node (including users).
701 /// TODO: Canonicalize paths on creation.
702 class MDFile : public MDScope {
703 friend class LLVMContextImpl;
706 MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
707 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
710 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
711 StringRef Directory, StorageType Storage,
712 bool ShouldCreate = true) {
713 return getImpl(Context, getCanonicalMDString(Context, Filename),
714 getCanonicalMDString(Context, Directory), Storage,
717 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
718 MDString *Directory, StorageType Storage,
719 bool ShouldCreate = true);
721 TempMDFile cloneImpl() const {
722 return getTemporary(getContext(), getFilename(), getDirectory());
726 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
727 (Filename, Directory))
728 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
729 (Filename, Directory))
731 TempMDFile clone() const { return cloneImpl(); }
733 MDTuple *getFileNode() const { return cast<MDTuple>(getOperand(0)); }
735 StringRef getFilename() const {
736 if (auto *S = getRawFilename())
737 return S->getString();
740 StringRef getDirectory() const {
741 if (auto *S = getRawDirectory())
742 return S->getString();
746 MDString *getRawFilename() const {
747 return cast_or_null<MDString>(getFileNode()->getOperand(0));
749 MDString *getRawDirectory() const {
750 return cast_or_null<MDString>(getFileNode()->getOperand(1));
753 static bool classof(const Metadata *MD) {
754 return MD->getMetadataID() == MDFileKind;
758 /// \brief Compile unit.
759 class MDCompileUnit : public MDScope {
760 friend class LLVMContextImpl;
763 unsigned SourceLanguage;
765 unsigned RuntimeVersion;
766 unsigned EmissionKind;
768 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
769 bool IsOptimized, unsigned RuntimeVersion,
770 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
771 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
772 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
773 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
776 static MDCompileUnit *
777 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
778 StringRef Producer, bool IsOptimized, StringRef Flags,
779 unsigned RuntimeVersion, StringRef SplitDebugFilename,
780 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
781 Metadata *Subprograms, Metadata *GlobalVariables,
782 Metadata *ImportedEntities, StorageType Storage,
783 bool ShouldCreate = true) {
784 return getImpl(Context, SourceLanguage, File,
785 getCanonicalMDString(Context, Producer), IsOptimized,
786 getCanonicalMDString(Context, Flags), RuntimeVersion,
787 getCanonicalMDString(Context, SplitDebugFilename),
788 EmissionKind, EnumTypes, RetainedTypes, Subprograms,
789 GlobalVariables, ImportedEntities, Storage, ShouldCreate);
791 static MDCompileUnit *
792 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
793 MDString *Producer, bool IsOptimized, MDString *Flags,
794 unsigned RuntimeVersion, MDString *SplitDebugFilename,
795 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
796 Metadata *Subprograms, Metadata *GlobalVariables,
797 Metadata *ImportedEntities, StorageType Storage,
798 bool ShouldCreate = true);
800 TempMDCompileUnit cloneImpl() const {
802 getContext(), getSourceLanguage(), getFile(), getProducer(),
803 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
804 getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
805 getGlobalVariables(), getImportedEntities());
809 DEFINE_MDNODE_GET(MDCompileUnit,
810 (unsigned SourceLanguage, Metadata *File,
811 StringRef Producer, bool IsOptimized, StringRef Flags,
812 unsigned RuntimeVersion, StringRef SplitDebugFilename,
813 unsigned EmissionKind, Metadata *EnumTypes,
814 Metadata *RetainedTypes, Metadata *Subprograms,
815 Metadata *GlobalVariables, Metadata *ImportedEntities),
816 (SourceLanguage, File, Producer, IsOptimized, Flags,
817 RuntimeVersion, SplitDebugFilename, EmissionKind,
818 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
820 DEFINE_MDNODE_GET(MDCompileUnit,
821 (unsigned SourceLanguage, Metadata *File,
822 MDString *Producer, bool IsOptimized, MDString *Flags,
823 unsigned RuntimeVersion, MDString *SplitDebugFilename,
824 unsigned EmissionKind, Metadata *EnumTypes,
825 Metadata *RetainedTypes, Metadata *Subprograms,
826 Metadata *GlobalVariables, Metadata *ImportedEntities),
827 (SourceLanguage, File, Producer, IsOptimized, Flags,
828 RuntimeVersion, SplitDebugFilename, EmissionKind,
829 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
832 TempMDCompileUnit clone() const { return cloneImpl(); }
834 unsigned getSourceLanguage() const { return SourceLanguage; }
835 bool isOptimized() const { return IsOptimized; }
836 unsigned getRuntimeVersion() const { return RuntimeVersion; }
837 unsigned getEmissionKind() const { return EmissionKind; }
838 StringRef getProducer() const { return getStringOperand(1); }
839 StringRef getFlags() const { return getStringOperand(2); }
840 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
841 Metadata *getEnumTypes() const { return getOperand(4); }
842 Metadata *getRetainedTypes() const { return getOperand(5); }
843 Metadata *getSubprograms() const { return getOperand(6); }
844 Metadata *getGlobalVariables() const { return getOperand(7); }
845 Metadata *getImportedEntities() const { return getOperand(8); }
847 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
848 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
849 MDString *getRawSplitDebugFilename() const {
850 return getOperandAs<MDString>(3);
853 /// \brief Replace arrays.
855 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
856 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
857 /// MDCompileUnit should be fairly rare.
859 void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
860 void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
863 static bool classof(const Metadata *MD) {
864 return MD->getMetadataID() == MDCompileUnitKind;
868 /// \brief Subprogram description.
870 /// TODO: Remove DisplayName. It's always equal to Name.
871 /// TODO: Split up flags.
872 class MDSubprogram : public MDScope {
873 friend class LLVMContextImpl;
879 unsigned VirtualIndex;
885 MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
886 unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
887 unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
888 bool IsOptimized, ArrayRef<Metadata *> Ops)
889 : MDScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
890 Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
891 VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
892 IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
895 static MDSubprogram *
896 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
897 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
898 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
899 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
900 unsigned Flags, bool IsOptimized, Metadata *Function,
901 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
902 StorageType Storage, bool ShouldCreate = true) {
903 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
904 getCanonicalMDString(Context, LinkageName), File, Line, Type,
905 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
906 Virtuality, VirtualIndex, Flags, IsOptimized, Function,
907 TemplateParams, Declaration, Variables, Storage,
910 static MDSubprogram *
911 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
912 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
913 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
914 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
915 unsigned Flags, bool IsOptimized, Metadata *Function,
916 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
917 StorageType Storage, bool ShouldCreate = true);
919 TempMDSubprogram cloneImpl() const {
920 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
921 getFile(), getLine(), getType(), isLocalToUnit(),
922 isDefinition(), getScopeLine(), getContainingType(),
923 getVirtuality(), getVirtualIndex(), getFlags(),
924 isOptimized(), getFunction(), getTemplateParams(),
925 getDeclaration(), getVariables());
931 (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
932 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
933 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
934 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
935 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
936 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
937 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
938 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
939 Function, TemplateParams, Declaration, Variables))
942 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
943 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
944 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
945 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
946 Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
947 Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
948 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
949 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
950 Function, TemplateParams, Declaration, Variables))
952 TempMDSubprogram clone() const { return cloneImpl(); }
955 unsigned getLine() const { return Line; }
956 unsigned getVirtuality() const { return Virtuality; }
957 unsigned getVirtualIndex() const { return VirtualIndex; }
958 unsigned getScopeLine() const { return ScopeLine; }
959 unsigned getFlags() const { return Flags; }
960 bool isLocalToUnit() const { return IsLocalToUnit; }
961 bool isDefinition() const { return IsDefinition; }
962 bool isOptimized() const { return IsOptimized; }
964 Metadata *getScope() const { return getOperand(1); }
966 StringRef getName() const { return getStringOperand(2); }
967 StringRef getDisplayName() const { return getStringOperand(3); }
968 StringRef getLinkageName() const { return getStringOperand(4); }
970 MDString *getRawName() const { return getOperandAs<MDString>(2); }
971 MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
973 Metadata *getType() const { return getOperand(5); }
974 Metadata *getContainingType() const { return getOperand(6); }
976 Metadata *getFunction() const { return getOperand(7); }
977 Metadata *getTemplateParams() const { return getOperand(8); }
978 Metadata *getDeclaration() const { return getOperand(9); }
979 Metadata *getVariables() const { return getOperand(10); }
981 /// \brief Replace the function.
983 /// If \a isUniqued() and not \a isResolved(), this could node will be
984 /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
985 /// that's a problem.
987 void replaceFunction(Function *F);
988 void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
989 void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
992 static bool classof(const Metadata *MD) {
993 return MD->getMetadataID() == MDSubprogramKind;
997 class MDLexicalBlockBase : public MDScope {
999 MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1000 ArrayRef<Metadata *> Ops)
1001 : MDScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1002 ~MDLexicalBlockBase() {}
1005 Metadata *getScope() const { return getOperand(1); }
1007 static bool classof(const Metadata *MD) {
1008 return MD->getMetadataID() == MDLexicalBlockKind ||
1009 MD->getMetadataID() == MDLexicalBlockFileKind;
1013 class MDLexicalBlock : public MDLexicalBlockBase {
1014 friend class LLVMContextImpl;
1015 friend class MDNode;
1020 MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1021 unsigned Column, ArrayRef<Metadata *> Ops)
1022 : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1024 ~MDLexicalBlock() {}
1026 static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1027 Metadata *File, unsigned Line, unsigned Column,
1028 StorageType Storage, bool ShouldCreate = true);
1030 TempMDLexicalBlock cloneImpl() const {
1031 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1036 DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1037 unsigned Line, unsigned Column),
1038 (Scope, File, Line, Column))
1040 TempMDLexicalBlock clone() const { return cloneImpl(); }
1042 unsigned getLine() const { return Line; }
1043 unsigned getColumn() const { return Column; }
1045 static bool classof(const Metadata *MD) {
1046 return MD->getMetadataID() == MDLexicalBlockKind;
1050 class MDLexicalBlockFile : public MDLexicalBlockBase {
1051 friend class LLVMContextImpl;
1052 friend class MDNode;
1054 unsigned Discriminator;
1056 MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1057 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1058 : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1059 Discriminator(Discriminator) {}
1060 ~MDLexicalBlockFile() {}
1062 static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1063 Metadata *File, unsigned Discriminator,
1064 StorageType Storage,
1065 bool ShouldCreate = true);
1067 TempMDLexicalBlockFile cloneImpl() const {
1068 return getTemporary(getContext(), getScope(), getFile(),
1069 getDiscriminator());
1073 DEFINE_MDNODE_GET(MDLexicalBlockFile,
1074 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1075 (Scope, File, Discriminator))
1077 TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1079 unsigned getDiscriminator() const { return Discriminator; }
1081 static bool classof(const Metadata *MD) {
1082 return MD->getMetadataID() == MDLexicalBlockFileKind;
1086 class MDNamespace : public MDScope {
1087 friend class LLVMContextImpl;
1088 friend class MDNode;
1092 MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1093 ArrayRef<Metadata *> Ops)
1094 : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1099 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1100 Metadata *File, StringRef Name, unsigned Line,
1101 StorageType Storage, bool ShouldCreate = true) {
1102 return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1103 Line, Storage, ShouldCreate);
1105 static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1106 Metadata *File, MDString *Name, unsigned Line,
1107 StorageType Storage, bool ShouldCreate = true);
1109 TempMDNamespace cloneImpl() const {
1110 return getTemporary(getContext(), getScope(), getFile(), getName(),
1115 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1116 StringRef Name, unsigned Line),
1117 (Scope, File, Name, Line))
1118 DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1119 MDString *Name, unsigned Line),
1120 (Scope, File, Name, Line))
1122 TempMDNamespace clone() const { return cloneImpl(); }
1124 unsigned getLine() const { return Line; }
1125 Metadata *getScope() const { return getOperand(1); }
1126 StringRef getName() const { return getStringOperand(2); }
1128 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1130 static bool classof(const Metadata *MD) {
1131 return MD->getMetadataID() == MDNamespaceKind;
1135 /// \brief Base class for template parameters.
1137 /// TODO: Remove the scope. It's always the compile unit, and never
1139 /// TODO: Remove File, Line and Column. They're always 0 and never
1141 class MDTemplateParameter : public DebugNode {
1143 MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1144 unsigned Tag, ArrayRef<Metadata *> Ops)
1145 : DebugNode(Context, ID, Storage, Tag, Ops) {}
1146 ~MDTemplateParameter() {}
1149 Metadata *getScope() const { return getOperand(0); }
1150 StringRef getName() const { return getStringOperand(1); }
1151 Metadata *getType() const { return getOperand(2); }
1153 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1155 static bool classof(const Metadata *MD) {
1156 return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1157 MD->getMetadataID() == MDTemplateValueParameterKind;
1161 class MDTemplateTypeParameter : public MDTemplateParameter {
1162 friend class LLVMContextImpl;
1163 friend class MDNode;
1165 MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1166 ArrayRef<Metadata *> Ops)
1167 : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1168 dwarf::DW_TAG_template_type_parameter, Ops) {}
1169 ~MDTemplateTypeParameter() {}
1171 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, Metadata *Scope,
1172 StringRef Name, Metadata *Type,
1173 StorageType Storage,
1174 bool ShouldCreate = true) {
1175 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), Type,
1176 Storage, ShouldCreate);
1178 static MDTemplateTypeParameter *getImpl(LLVMContext &Context, Metadata *Scope,
1179 MDString *Name, Metadata *Type,
1180 StorageType Storage,
1181 bool ShouldCreate = true);
1183 TempMDTemplateTypeParameter cloneImpl() const {
1184 return getTemporary(getContext(), getScope(), getName(), getType());
1188 DEFINE_MDNODE_GET(MDTemplateTypeParameter,
1189 (Metadata * Scope, StringRef Name, Metadata *Type),
1190 (Scope, Name, Type))
1191 DEFINE_MDNODE_GET(MDTemplateTypeParameter,
1192 (Metadata * Scope, MDString *Name, Metadata *Type),
1193 (Scope, Name, Type))
1195 TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1197 static bool classof(const Metadata *MD) {
1198 return MD->getMetadataID() == MDTemplateTypeParameterKind;
1202 class MDTemplateValueParameter : public MDTemplateParameter {
1203 friend class LLVMContextImpl;
1204 friend class MDNode;
1206 MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1207 unsigned Tag, ArrayRef<Metadata *> Ops)
1208 : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1210 ~MDTemplateValueParameter() {}
1212 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1213 Metadata *Scope, StringRef Name,
1214 Metadata *Type, Metadata *Value,
1215 StorageType Storage,
1216 bool ShouldCreate = true) {
1217 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1218 Type, Value, Storage, ShouldCreate);
1220 static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1221 Metadata *Scope, MDString *Name,
1222 Metadata *Type, Metadata *Value,
1223 StorageType Storage,
1224 bool ShouldCreate = true);
1226 TempMDTemplateValueParameter cloneImpl() const {
1227 return getTemporary(getContext(), getTag(), getScope(), getName(),
1228 getType(), getValue());
1232 DEFINE_MDNODE_GET(MDTemplateValueParameter,
1233 (unsigned Tag, Metadata *Scope, StringRef Name,
1234 Metadata *Type, Metadata *Value),
1235 (Tag, Scope, Name, Type, Value))
1236 DEFINE_MDNODE_GET(MDTemplateValueParameter,
1237 (unsigned Tag, Metadata *Scope, MDString *Name,
1238 Metadata *Type, Metadata *Value),
1239 (Tag, Scope, Name, Type, Value))
1241 TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1243 Metadata *getValue() const { return getOperand(3); }
1245 static bool classof(const Metadata *MD) {
1246 return MD->getMetadataID() == MDTemplateValueParameterKind;
1250 /// \brief Base class for variables.
1252 /// TODO: Hardcode to DW_TAG_variable.
1253 class MDVariable : public DebugNode {
1257 MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1258 unsigned Line, ArrayRef<Metadata *> Ops)
1259 : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1263 unsigned getLine() const { return Line; }
1264 Metadata *getScope() const { return getOperand(0); }
1265 StringRef getName() const { return getStringOperand(1); }
1266 Metadata *getFile() const { return getOperand(2); }
1267 Metadata *getType() const { return getOperand(3); }
1269 MDString *getRawName() const { return getOperandAs<MDString>(1); }
1271 static bool classof(const Metadata *MD) {
1272 return MD->getMetadataID() == MDLocalVariableKind ||
1273 MD->getMetadataID() == MDGlobalVariableKind;
1277 /// \brief Global variables.
1279 /// TODO: Remove DisplayName. It's always equal to Name.
1280 class MDGlobalVariable : public MDVariable {
1281 friend class LLVMContextImpl;
1282 friend class MDNode;
1287 MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1288 bool IsLocalToUnit, bool IsDefinition,
1289 ArrayRef<Metadata *> Ops)
1290 : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1292 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1293 ~MDGlobalVariable() {}
1295 static MDGlobalVariable *
1296 getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1297 StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1298 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1299 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1300 bool ShouldCreate = true) {
1301 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1302 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1303 IsLocalToUnit, IsDefinition, Variable,
1304 StaticDataMemberDeclaration, Storage, ShouldCreate);
1306 static MDGlobalVariable *
1307 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1308 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1309 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1310 Metadata *StaticDataMemberDeclaration, StorageType Storage,
1311 bool ShouldCreate = true);
1313 TempMDGlobalVariable cloneImpl() const {
1314 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1315 getFile(), getLine(), getType(), isLocalToUnit(),
1316 isDefinition(), getVariable(),
1317 getStaticDataMemberDeclaration());
1321 DEFINE_MDNODE_GET(MDGlobalVariable,
1322 (Metadata * Scope, StringRef Name, StringRef LinkageName,
1323 Metadata *File, unsigned Line, Metadata *Type,
1324 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1325 Metadata *StaticDataMemberDeclaration),
1326 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1327 IsDefinition, Variable, StaticDataMemberDeclaration))
1328 DEFINE_MDNODE_GET(MDGlobalVariable,
1329 (Metadata * Scope, MDString *Name, MDString *LinkageName,
1330 Metadata *File, unsigned Line, Metadata *Type,
1331 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1332 Metadata *StaticDataMemberDeclaration),
1333 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1334 IsDefinition, Variable, StaticDataMemberDeclaration))
1336 TempMDGlobalVariable clone() const { return cloneImpl(); }
1338 bool isLocalToUnit() const { return IsLocalToUnit; }
1339 bool isDefinition() const { return IsDefinition; }
1340 StringRef getDisplayName() const { return getStringOperand(4); }
1341 StringRef getLinkageName() const { return getStringOperand(5); }
1342 Metadata *getVariable() const { return getOperand(6); }
1343 Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1345 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1347 static bool classof(const Metadata *MD) {
1348 return MD->getMetadataID() == MDGlobalVariableKind;
1352 /// \brief Local variable.
1354 /// TODO: Split between arguments and otherwise.
1355 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1356 /// TODO: Split up flags.
1357 class MDLocalVariable : public MDVariable {
1358 friend class LLVMContextImpl;
1359 friend class MDNode;
1364 MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1365 unsigned Line, unsigned Arg, unsigned Flags,
1366 ArrayRef<Metadata *> Ops)
1367 : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1369 ~MDLocalVariable() {}
1371 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1372 Metadata *Scope, StringRef Name,
1373 Metadata *File, unsigned Line, Metadata *Type,
1374 unsigned Arg, unsigned Flags,
1375 Metadata *InlinedAt, StorageType Storage,
1376 bool ShouldCreate = true) {
1377 return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1378 File, Line, Type, Arg, Flags, InlinedAt, Storage,
1381 static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1382 Metadata *Scope, MDString *Name,
1383 Metadata *File, unsigned Line, Metadata *Type,
1384 unsigned Arg, unsigned Flags,
1385 Metadata *InlinedAt, StorageType Storage,
1386 bool ShouldCreate = true);
1388 TempMDLocalVariable cloneImpl() const {
1389 return getTemporary(getContext(), getTag(), getScope(), getName(),
1390 getFile(), getLine(), getType(), getArg(), getFlags(),
1395 DEFINE_MDNODE_GET(MDLocalVariable,
1396 (unsigned Tag, Metadata *Scope, StringRef Name,
1397 Metadata *File, unsigned Line, Metadata *Type,
1398 unsigned Arg, unsigned Flags,
1399 Metadata *InlinedAt = nullptr),
1400 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1401 DEFINE_MDNODE_GET(MDLocalVariable,
1402 (unsigned Tag, Metadata *Scope, MDString *Name,
1403 Metadata *File, unsigned Line, Metadata *Type,
1404 unsigned Arg, unsigned Flags,
1405 Metadata *InlinedAt = nullptr),
1406 (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1408 TempMDLocalVariable clone() const { return cloneImpl(); }
1410 unsigned getArg() const { return Arg; }
1411 unsigned getFlags() const { return Flags; }
1412 Metadata *getInlinedAt() const { return getOperand(4); }
1414 static bool classof(const Metadata *MD) {
1415 return MD->getMetadataID() == MDLocalVariableKind;
1419 /// \brief DWARF expression.
1421 /// TODO: Co-allocate the expression elements.
1422 /// TODO: Drop fake DW_TAG_expression and separate from DebugNode.
1423 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1425 class MDExpression : public DebugNode {
1426 friend class LLVMContextImpl;
1427 friend class MDNode;
1429 std::vector<uint64_t> Elements;
1431 MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1432 : DebugNode(C, MDExpressionKind, Storage, dwarf::DW_TAG_expression, None),
1433 Elements(Elements.begin(), Elements.end()) {}
1436 static MDExpression *getImpl(LLVMContext &Context,
1437 ArrayRef<uint64_t> Elements, StorageType Storage,
1438 bool ShouldCreate = true);
1440 TempMDExpression cloneImpl() const {
1441 return getTemporary(getContext(), getElements());
1445 DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1447 TempMDExpression clone() const { return cloneImpl(); }
1449 ArrayRef<uint64_t> getElements() const { return Elements; }
1451 unsigned getNumElements() const { return Elements.size(); }
1452 uint64_t getElement(unsigned I) const {
1453 assert(I < Elements.size() && "Index out of range");
1457 typedef ArrayRef<uint64_t>::iterator element_iterator;
1458 element_iterator elements_begin() const { return getElements().begin(); }
1459 element_iterator elements_end() const { return getElements().end(); }
1461 /// \brief A lightweight wrapper around an expression operand.
1463 /// TODO: Store arguments directly and change \a MDExpression to store a
1469 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1471 const uint64_t *get() const { return Op; }
1473 /// \brief Get the operand code.
1474 uint64_t getOp() const { return *Op; }
1476 /// \brief Get an argument to the operand.
1478 /// Never returns the operand itself.
1479 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1481 unsigned getNumArgs() const { return getSize() - 1; }
1483 /// \brief Return the size of the operand.
1485 /// Return the number of elements in the operand (1 + args).
1486 unsigned getSize() const;
1489 /// \brief An iterator for expression operands.
1490 class expr_op_iterator
1491 : public std::iterator<std::input_iterator_tag, ExprOperand> {
1495 explicit expr_op_iterator(element_iterator I) : Op(I) {}
1497 element_iterator getBase() const { return Op.get(); }
1498 const ExprOperand &operator*() const { return Op; }
1499 const ExprOperand *operator->() const { return &Op; }
1501 expr_op_iterator &operator++() {
1505 expr_op_iterator operator++(int) {
1506 expr_op_iterator T(*this);
1511 bool operator==(const expr_op_iterator &X) const {
1512 return getBase() == X.getBase();
1514 bool operator!=(const expr_op_iterator &X) const {
1515 return getBase() != X.getBase();
1519 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1522 /// \brief Visit the elements via ExprOperand wrappers.
1524 /// These range iterators visit elements through \a ExprOperand wrappers.
1525 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1528 /// \pre \a isValid() gives \c true.
1530 expr_op_iterator expr_op_begin() const {
1531 return expr_op_iterator(elements_begin());
1533 expr_op_iterator expr_op_end() const {
1534 return expr_op_iterator(elements_end());
1538 bool isValid() const;
1540 static bool classof(const Metadata *MD) {
1541 return MD->getMetadataID() == MDExpressionKind;
1545 class MDObjCProperty : public DebugNode {
1546 friend class LLVMContextImpl;
1547 friend class MDNode;
1550 unsigned Attributes;
1552 MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1553 unsigned Attributes, ArrayRef<Metadata *> Ops)
1554 : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1556 Line(Line), Attributes(Attributes) {}
1557 ~MDObjCProperty() {}
1559 static MDObjCProperty *
1560 getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1561 StringRef GetterName, StringRef SetterName, unsigned Attributes,
1562 Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1563 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1564 getCanonicalMDString(Context, GetterName),
1565 getCanonicalMDString(Context, SetterName), Attributes, Type,
1566 Storage, ShouldCreate);
1568 static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1569 Metadata *File, unsigned Line,
1570 MDString *GetterName, MDString *SetterName,
1571 unsigned Attributes, Metadata *Type,
1572 StorageType Storage, bool ShouldCreate = true);
1574 TempMDObjCProperty cloneImpl() const {
1575 return getTemporary(getContext(), getName(), getFile(), getLine(),
1576 getGetterName(), getSetterName(), getAttributes(),
1581 DEFINE_MDNODE_GET(MDObjCProperty,
1582 (StringRef Name, Metadata *File, unsigned Line,
1583 StringRef GetterName, StringRef SetterName,
1584 unsigned Attributes, Metadata *Type),
1585 (Name, File, Line, GetterName, SetterName, Attributes,
1587 DEFINE_MDNODE_GET(MDObjCProperty,
1588 (MDString * Name, Metadata *File, unsigned Line,
1589 MDString *GetterName, MDString *SetterName,
1590 unsigned Attributes, Metadata *Type),
1591 (Name, File, Line, GetterName, SetterName, Attributes,
1594 TempMDObjCProperty clone() const { return cloneImpl(); }
1596 unsigned getLine() const { return Line; }
1597 unsigned getAttributes() const { return Attributes; }
1598 StringRef getName() const { return getStringOperand(0); }
1599 Metadata *getFile() const { return getOperand(1); }
1600 StringRef getGetterName() const { return getStringOperand(2); }
1601 StringRef getSetterName() const { return getStringOperand(3); }
1602 Metadata *getType() const { return getOperand(4); }
1604 MDString *getRawName() const { return getOperandAs<MDString>(0); }
1605 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1606 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1608 static bool classof(const Metadata *MD) {
1609 return MD->getMetadataID() == MDObjCPropertyKind;
1613 class MDImportedEntity : public DebugNode {
1614 friend class LLVMContextImpl;
1615 friend class MDNode;
1619 MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1620 unsigned Line, ArrayRef<Metadata *> Ops)
1621 : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1622 ~MDImportedEntity() {}
1624 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1625 Metadata *Scope, Metadata *Entity,
1626 unsigned Line, StringRef Name,
1627 StorageType Storage,
1628 bool ShouldCreate = true) {
1629 return getImpl(Context, Tag, Scope, Entity, Line,
1630 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1632 static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1633 Metadata *Scope, Metadata *Entity,
1634 unsigned Line, MDString *Name,
1635 StorageType Storage,
1636 bool ShouldCreate = true);
1638 TempMDImportedEntity cloneImpl() const {
1639 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1640 getLine(), getName());
1644 DEFINE_MDNODE_GET(MDImportedEntity,
1645 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1646 unsigned Line, StringRef Name = ""),
1647 (Tag, Scope, Entity, Line, Name))
1648 DEFINE_MDNODE_GET(MDImportedEntity,
1649 (unsigned Tag, Metadata *Scope, Metadata *Entity,
1650 unsigned Line, MDString *Name),
1651 (Tag, Scope, Entity, Line, Name))
1653 TempMDImportedEntity clone() const { return cloneImpl(); }
1655 unsigned getLine() const { return Line; }
1656 Metadata *getScope() const { return getOperand(0); }
1657 Metadata *getEntity() const { return getOperand(1); }
1658 StringRef getName() const { return getStringOperand(2); }
1660 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1662 static bool classof(const Metadata *MD) {
1663 return MD->getMetadataID() == MDImportedEntityKind;
1667 } // end namespace llvm
1669 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1670 #undef DEFINE_MDNODE_GET_UNPACK
1671 #undef DEFINE_MDNODE_GET