012ea80d1d8e6c35e902aec1493939cb9c1922d4
[oota-llvm.git] / include / llvm / IR / DebugInfoMetadata.h
1 //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Declarations for metadata specific to debug info.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_IR_DEBUGINFOMETADATA_H
15 #define LLVM_IR_DEBUGINFOMETADATA_H
16
17 #include "llvm/IR/Metadata.h"
18 #include "llvm/Support/Dwarf.h"
19
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);          \
26   }                                                                            \
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);                                  \
31   }                                                                            \
32   static CLASS *getDistinct(LLVMContext &Context,                              \
33                             DEFINE_MDNODE_GET_UNPACK(FORMAL)) {                \
34     return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct);         \
35   }                                                                            \
36   static Temp##CLASS getTemporary(LLVMContext &Context,                        \
37                                   DEFINE_MDNODE_GET_UNPACK(FORMAL)) {          \
38     return Temp##CLASS(                                                        \
39         getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary));          \
40   }
41
42 namespace llvm {
43
44 /// \brief Debug location.
45 ///
46 /// A debug location in source code, used for debug info and otherwise.
47 class MDLocation : public MDNode {
48   friend class LLVMContextImpl;
49   friend class MDNode;
50
51   MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
52              unsigned Column, ArrayRef<Metadata *> MDs);
53   ~MDLocation() { dropAllReferences(); }
54
55   static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
56                              unsigned Column, Metadata *Scope,
57                              Metadata *InlinedAt, StorageType Storage,
58                              bool ShouldCreate = true);
59
60   TempMDLocation cloneImpl() const {
61     return getTemporary(getContext(), getLine(), getColumn(), getScope(),
62                         getInlinedAt());
63   }
64
65   // Disallow replacing operands.
66   void replaceOperandWith(unsigned I, Metadata *New) = delete;
67
68 public:
69   DEFINE_MDNODE_GET(MDLocation,
70                     (unsigned Line, unsigned Column, Metadata *Scope,
71                      Metadata *InlinedAt = nullptr),
72                     (Line, Column, Scope, InlinedAt))
73
74   /// \brief Return a (temporary) clone of this.
75   TempMDLocation clone() const { return cloneImpl(); }
76
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)
82       return getOperand(1);
83     return nullptr;
84   }
85
86   static bool classof(const Metadata *MD) {
87     return MD->getMetadataID() == MDLocationKind;
88   }
89 };
90
91 /// \brief Tagged DWARF-like metadata node.
92 ///
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;
98   friend class MDNode;
99
100 protected:
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;
106   }
107   ~DebugNode() {}
108
109   template <class Ty> Ty *getOperandAs(unsigned I) const {
110     return cast_or_null<Ty>(getOperand(I));
111   }
112
113   StringRef getStringOperand(unsigned I) const {
114     if (auto *S = getOperandAs<MDString>(I))
115       return S->getString();
116     return StringRef();
117   }
118
119   static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
120     if (S.empty())
121       return nullptr;
122     return MDString::get(Context, S);
123   }
124
125 public:
126   unsigned getTag() const { return SubclassData16; }
127
128   static bool classof(const Metadata *MD) {
129     switch (MD->getMetadataID()) {
130     default:
131       return false;
132     case GenericDebugNodeKind:
133     case MDSubrangeKind:
134     case MDEnumeratorKind:
135     case MDBasicTypeKind:
136     case MDDerivedTypeKind:
137     case MDCompositeTypeKind:
138     case MDSubroutineTypeKind:
139     case MDFileKind:
140     case MDCompileUnitKind:
141     case MDSubprogramKind:
142     case MDLexicalBlockKind:
143     case MDLexicalBlockFileKind:
144     case MDNamespaceKind:
145     case MDTemplateTypeParameterKind:
146     case MDTemplateValueParameterKind:
147     case MDGlobalVariableKind:
148     case MDLocalVariableKind:
149     case MDObjCPropertyKind:
150     case MDImportedEntityKind:
151       return true;
152     }
153   }
154 };
155
156 /// \brief Generic tagged DWARF-like metadata node.
157 ///
158 /// An un-specialized DWARF-like metadata node.  The first operand is a
159 /// (possibly empty) null-separated \a MDString header that contains arbitrary
160 /// fields.  The remaining operands are \a dwarf_operands(), and are pointers
161 /// to other metadata.
162 class GenericDebugNode : public DebugNode {
163   friend class LLVMContextImpl;
164   friend class MDNode;
165
166   GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
167                    unsigned Tag, ArrayRef<Metadata *> Ops1,
168                    ArrayRef<Metadata *> Ops2)
169       : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
170     setHash(Hash);
171   }
172   ~GenericDebugNode() { dropAllReferences(); }
173
174   void setHash(unsigned Hash) { SubclassData32 = Hash; }
175   void recalculateHash();
176
177   static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
178                                    StringRef Header,
179                                    ArrayRef<Metadata *> DwarfOps,
180                                    StorageType Storage,
181                                    bool ShouldCreate = true) {
182     return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
183                    DwarfOps, Storage, ShouldCreate);
184   }
185
186   static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
187                                    MDString *Header,
188                                    ArrayRef<Metadata *> DwarfOps,
189                                    StorageType Storage,
190                                    bool ShouldCreate = true);
191
192   TempGenericDebugNode cloneImpl() const {
193     return getTemporary(
194         getContext(), getTag(), getHeader(),
195         SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
196   }
197
198 public:
199   unsigned getHash() const { return SubclassData32; }
200
201   DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
202                                        ArrayRef<Metadata *> DwarfOps),
203                     (Tag, Header, DwarfOps))
204   DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
205                                        ArrayRef<Metadata *> DwarfOps),
206                     (Tag, Header, DwarfOps))
207
208   /// \brief Return a (temporary) clone of this.
209   TempGenericDebugNode clone() const { return cloneImpl(); }
210
211   unsigned getTag() const { return SubclassData16; }
212   StringRef getHeader() const { return getStringOperand(0); }
213
214   op_iterator dwarf_op_begin() const { return op_begin() + 1; }
215   op_iterator dwarf_op_end() const { return op_end(); }
216   op_range dwarf_operands() const {
217     return op_range(dwarf_op_begin(), dwarf_op_end());
218   }
219
220   unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
221   const MDOperand &getDwarfOperand(unsigned I) const {
222     return getOperand(I + 1);
223   }
224   void replaceDwarfOperandWith(unsigned I, Metadata *New) {
225     replaceOperandWith(I + 1, New);
226   }
227
228   static bool classof(const Metadata *MD) {
229     return MD->getMetadataID() == GenericDebugNodeKind;
230   }
231 };
232
233 /// \brief Array subrange.
234 ///
235 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
236 /// type.
237 class MDSubrange : public DebugNode {
238   friend class LLVMContextImpl;
239   friend class MDNode;
240
241   int64_t Count;
242   int64_t Lo;
243
244   MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count, int64_t Lo)
245       : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
246                   None),
247         Count(Count), Lo(Lo) {}
248   ~MDSubrange() {}
249
250   static MDSubrange *getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
251                              StorageType Storage, bool ShouldCreate = true);
252
253   TempMDSubrange cloneImpl() const {
254     return getTemporary(getContext(), getCount(), getLo());
255   }
256
257 public:
258   DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t Lo = 0), (Count, Lo))
259
260   TempMDSubrange clone() const { return cloneImpl(); }
261
262   int64_t getLo() const { return Lo; }
263   int64_t getCount() const { return Count; }
264
265   static bool classof(const Metadata *MD) {
266     return MD->getMetadataID() == MDSubrangeKind;
267   }
268 };
269
270 /// \brief Enumeration value.
271 ///
272 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
273 /// longer creates a type cycle.
274 class MDEnumerator : public DebugNode {
275   friend class LLVMContextImpl;
276   friend class MDNode;
277
278   int64_t Value;
279
280   MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
281                ArrayRef<Metadata *> Ops)
282       : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
283         Value(Value) {}
284   ~MDEnumerator() {}
285
286   static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
287                                StringRef Name, StorageType Storage,
288                                bool ShouldCreate = true) {
289     return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
290                    ShouldCreate);
291   }
292   static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
293                                MDString *Name, StorageType Storage,
294                                bool ShouldCreate = true);
295
296   TempMDEnumerator cloneImpl() const {
297     return getTemporary(getContext(), getValue(), getName());
298   }
299
300 public:
301   DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
302                     (Value, Name))
303   DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
304                     (Value, Name))
305
306   TempMDEnumerator clone() const { return cloneImpl(); }
307
308   int64_t getValue() const { return Value; }
309   StringRef getName() const { return getStringOperand(0); }
310
311   MDString *getRawName() const { return getOperandAs<MDString>(0); }
312
313   static bool classof(const Metadata *MD) {
314     return MD->getMetadataID() == MDEnumeratorKind;
315   }
316 };
317
318 /// \brief Base class for scope-like contexts.
319 ///
320 /// Base class for lexical scopes and types (which are also declaration
321 /// contexts).
322 ///
323 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
324 class MDScope : public DebugNode {
325 protected:
326   MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
327           ArrayRef<Metadata *> Ops)
328       : DebugNode(C, ID, Storage, Tag, Ops) {}
329   ~MDScope() {}
330
331 public:
332   /// \brief Return the underlying file.
333   ///
334   /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
335   /// (it\em is the file).  If \c this is an \a MDFile, we need to return \c
336   /// this.  Otherwise, return the first operand, which is where all other
337   /// subclasses store their file pointer.
338   Metadata *getFile() const {
339     return isa<MDFile>(this) ? const_cast<MDScope *>(this)
340                              : static_cast<Metadata *>(getOperand(0));
341   }
342
343   static bool classof(const Metadata *MD) {
344     switch (MD->getMetadataID()) {
345     default:
346       return false;
347     case MDBasicTypeKind:
348     case MDDerivedTypeKind:
349     case MDCompositeTypeKind:
350     case MDSubroutineTypeKind:
351     case MDFileKind:
352     case MDCompileUnitKind:
353     case MDSubprogramKind:
354     case MDLexicalBlockKind:
355     case MDLexicalBlockFileKind:
356     case MDNamespaceKind:
357       return true;
358     }
359   }
360 };
361
362 /// \brief Base class for types.
363 ///
364 /// TODO: Remove the hardcoded name and context, since many types don't use
365 /// them.
366 /// TODO: Split up flags.
367 class MDType : public MDScope {
368   unsigned Line;
369   unsigned Flags;
370   uint64_t SizeInBits;
371   uint64_t AlignInBits;
372   uint64_t OffsetInBits;
373
374 protected:
375   MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
376          unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
377          uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
378       : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
379         SizeInBits(SizeInBits), AlignInBits(AlignInBits),
380         OffsetInBits(OffsetInBits) {}
381   ~MDType() {}
382
383 public:
384   TempMDType clone() const {
385     return TempMDType(cast<MDType>(MDNode::clone().release()));
386   }
387
388   unsigned getLine() const { return Line; }
389   uint64_t getSizeInBits() const { return SizeInBits; }
390   uint64_t getAlignInBits() const { return AlignInBits; }
391   uint64_t getOffsetInBits() const { return OffsetInBits; }
392   unsigned getFlags() const { return Flags; }
393
394   Metadata *getScope() const { return getOperand(1); }
395   StringRef getName() const { return getStringOperand(2); }
396
397   MDString *getRawName() const { return getOperandAs<MDString>(2); }
398
399   void setFlags(unsigned NewFlags) {
400     assert(!isUniqued() && "Cannot set flags on uniqued nodes");
401     Flags = NewFlags;
402   }
403
404   static bool classof(const Metadata *MD) {
405     switch (MD->getMetadataID()) {
406     default:
407       return false;
408     case MDBasicTypeKind:
409     case MDDerivedTypeKind:
410     case MDCompositeTypeKind:
411     case MDSubroutineTypeKind:
412       return true;
413     }
414   }
415 };
416
417 /// \brief Basic type.
418 ///
419 /// TODO: Split out DW_TAG_unspecified_type.
420 /// TODO: Drop unused accessors.
421 class MDBasicType : public MDType {
422   friend class LLVMContextImpl;
423   friend class MDNode;
424
425   unsigned Encoding;
426
427   MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
428               uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
429               ArrayRef<Metadata *> Ops)
430       : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
431                0, Ops),
432         Encoding(Encoding) {}
433   ~MDBasicType() {}
434
435   static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
436                               StringRef Name, uint64_t SizeInBits,
437                               uint64_t AlignInBits, unsigned Encoding,
438                               StorageType Storage, bool ShouldCreate = true) {
439     return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
440                    SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
441   }
442   static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
443                               MDString *Name, uint64_t SizeInBits,
444                               uint64_t AlignInBits, unsigned Encoding,
445                               StorageType Storage, bool ShouldCreate = true);
446
447   TempMDBasicType cloneImpl() const {
448     return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
449                         getAlignInBits(), getEncoding());
450   }
451
452 public:
453   DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
454                     (Tag, Name, 0, 0, 0))
455   DEFINE_MDNODE_GET(MDBasicType,
456                     (unsigned Tag, StringRef Name, uint64_t SizeInBits,
457                      uint64_t AlignInBits, unsigned Encoding),
458                     (Tag, Name, SizeInBits, AlignInBits, Encoding))
459   DEFINE_MDNODE_GET(MDBasicType,
460                     (unsigned Tag, MDString *Name, uint64_t SizeInBits,
461                      uint64_t AlignInBits, unsigned Encoding),
462                     (Tag, Name, SizeInBits, AlignInBits, Encoding))
463
464   TempMDBasicType clone() const { return cloneImpl(); }
465
466   unsigned getEncoding() const { return Encoding; }
467
468   static bool classof(const Metadata *MD) {
469     return MD->getMetadataID() == MDBasicTypeKind;
470   }
471 };
472
473 /// \brief Base class for MDDerivedType and MDCompositeType.
474 ///
475 /// TODO: Delete; they're not really related.
476 class MDDerivedTypeBase : public MDType {
477 protected:
478   MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
479                     unsigned Tag, unsigned Line, uint64_t SizeInBits,
480                     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
481                     ArrayRef<Metadata *> Ops)
482       : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
483                Flags, Ops) {}
484   ~MDDerivedTypeBase() {}
485
486 public:
487   Metadata *getBaseType() const { return getOperand(3); }
488
489   static bool classof(const Metadata *MD) {
490     return MD->getMetadataID() == MDDerivedTypeKind ||
491            MD->getMetadataID() == MDCompositeTypeKind ||
492            MD->getMetadataID() == MDSubroutineTypeKind;
493   }
494 };
495
496 /// \brief Derived types.
497 ///
498 /// This includes qualified types, pointers, references, friends, typedefs, and
499 /// class members.
500 ///
501 /// TODO: Split out members (inheritance, fields, methods, etc.).
502 class MDDerivedType : public MDDerivedTypeBase {
503   friend class LLVMContextImpl;
504   friend class MDNode;
505
506   MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
507                 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
508                 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
509       : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
510                           AlignInBits, OffsetInBits, Flags, Ops) {}
511   ~MDDerivedType() {}
512
513   static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
514                                 StringRef Name, Metadata *File, unsigned Line,
515                                 Metadata *Scope, Metadata *BaseType,
516                                 uint64_t SizeInBits, uint64_t AlignInBits,
517                                 uint64_t OffsetInBits, unsigned Flags,
518                                 Metadata *ExtraData, StorageType Storage,
519                                 bool ShouldCreate = true) {
520     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
521                    Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
522                    Flags, ExtraData, Storage, ShouldCreate);
523   }
524   static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
525                                 MDString *Name, Metadata *File, unsigned Line,
526                                 Metadata *Scope, Metadata *BaseType,
527                                 uint64_t SizeInBits, uint64_t AlignInBits,
528                                 uint64_t OffsetInBits, unsigned Flags,
529                                 Metadata *ExtraData, StorageType Storage,
530                                 bool ShouldCreate = true);
531
532   TempMDDerivedType cloneImpl() const {
533     return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
534                         getScope(), getBaseType(), getSizeInBits(),
535                         getAlignInBits(), getOffsetInBits(), getFlags(),
536                         getExtraData());
537   }
538
539 public:
540   DEFINE_MDNODE_GET(MDDerivedType,
541                     (unsigned Tag, MDString *Name, Metadata *File,
542                      unsigned Line, Metadata *Scope, Metadata *BaseType,
543                      uint64_t SizeInBits, uint64_t AlignInBits,
544                      uint64_t OffsetInBits, unsigned Flags,
545                      Metadata *ExtraData = nullptr),
546                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
547                      AlignInBits, OffsetInBits, Flags, ExtraData))
548   DEFINE_MDNODE_GET(MDDerivedType,
549                     (unsigned Tag, StringRef Name, Metadata *File,
550                      unsigned Line, Metadata *Scope, Metadata *BaseType,
551                      uint64_t SizeInBits, uint64_t AlignInBits,
552                      uint64_t OffsetInBits, unsigned Flags,
553                      Metadata *ExtraData = nullptr),
554                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
555                      AlignInBits, OffsetInBits, Flags, ExtraData))
556
557   TempMDDerivedType clone() const { return cloneImpl(); }
558
559   /// \brief Get extra data associated with this derived type.
560   ///
561   /// Class type for pointer-to-members, objective-c property node for ivars,
562   /// or global constant wrapper for static members.
563   ///
564   /// TODO: Separate out types that need this extra operand: pointer-to-member
565   /// types and member fields (static members and ivars).
566   Metadata *getExtraData() const { return getOperand(4); }
567
568   static bool classof(const Metadata *MD) {
569     return MD->getMetadataID() == MDDerivedTypeKind;
570   }
571 };
572
573 /// \brief Base class for MDCompositeType and MDSubroutineType.
574 ///
575 /// TODO: Delete; they're not really related.
576 class MDCompositeTypeBase : public MDDerivedTypeBase {
577   unsigned RuntimeLang;
578
579 protected:
580   MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
581                       unsigned Tag, unsigned Line, unsigned RuntimeLang,
582                       uint64_t SizeInBits, uint64_t AlignInBits,
583                       uint64_t OffsetInBits, unsigned Flags,
584                       ArrayRef<Metadata *> Ops)
585       : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
586                           OffsetInBits, Flags, Ops),
587         RuntimeLang(RuntimeLang) {}
588   ~MDCompositeTypeBase() {}
589
590 public:
591   Metadata *getElements() const { return getOperand(4); }
592   Metadata *getVTableHolder() const { return getOperand(5); }
593   Metadata *getTemplateParams() const { return getOperand(6); }
594   StringRef getIdentifier() const { return getStringOperand(7); }
595   unsigned getRuntimeLang() const { return RuntimeLang; }
596
597   MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
598
599   /// \brief Replace operands.
600   ///
601   /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
602   /// this will be RAUW'ed and deleted.  Use a \a TrackingMDRef to keep track
603   /// of its movement if necessary.
604   /// @{
605   void replaceElements(MDTuple *Elements) {
606 #ifndef NDEBUG
607     if (auto *Old = cast_or_null<MDTuple>(getElements()))
608       for (const auto &Op : Old->operands())
609         assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
610                "Lost a member during member list replacement");
611 #endif
612     replaceOperandWith(4, Elements);
613   }
614   void replaceVTableHolder(Metadata *VTableHolder) {
615     replaceOperandWith(5, VTableHolder);
616   }
617   void replaceTemplateParams(MDTuple *TemplateParams) {
618     replaceOperandWith(6, TemplateParams);
619   }
620   /// @}
621
622   static bool classof(const Metadata *MD) {
623     return MD->getMetadataID() == MDCompositeTypeKind ||
624            MD->getMetadataID() == MDSubroutineTypeKind;
625   }
626 };
627
628 /// \brief Composite types.
629 ///
630 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
631 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
632 class MDCompositeType : public MDCompositeTypeBase {
633   friend class LLVMContextImpl;
634   friend class MDNode;
635
636   MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
637                   unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
638                   uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
639                   ArrayRef<Metadata *> Ops)
640       : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
641                             RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
642                             Flags, Ops) {}
643   ~MDCompositeType() {}
644
645   static MDCompositeType *
646   getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
647           unsigned Line, Metadata *Scope, Metadata *BaseType,
648           uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
649           uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
650           Metadata *VTableHolder, Metadata *TemplateParams,
651           StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
652     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
653                    Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
654                    Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
655                    getCanonicalMDString(Context, Identifier), Storage,
656                    ShouldCreate);
657   }
658   static MDCompositeType *
659   getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
660           unsigned Line, Metadata *Scope, Metadata *BaseType,
661           uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
662           unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
663           Metadata *VTableHolder, Metadata *TemplateParams,
664           MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
665
666   TempMDCompositeType cloneImpl() const {
667     return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
668                         getScope(), getBaseType(), getSizeInBits(),
669                         getAlignInBits(), getOffsetInBits(), getFlags(),
670                         getElements(), getRuntimeLang(), getVTableHolder(),
671                         getTemplateParams(), getIdentifier());
672   }
673
674 public:
675   DEFINE_MDNODE_GET(MDCompositeType,
676                     (unsigned Tag, StringRef Name, Metadata *File,
677                      unsigned Line, Metadata *Scope, Metadata *BaseType,
678                      uint64_t SizeInBits, uint64_t AlignInBits,
679                      uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
680                      unsigned RuntimeLang, Metadata *VTableHolder,
681                      Metadata *TemplateParams = nullptr,
682                      StringRef Identifier = ""),
683                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
684                      AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
685                      VTableHolder, TemplateParams, Identifier))
686   DEFINE_MDNODE_GET(MDCompositeType,
687                     (unsigned Tag, MDString *Name, Metadata *File,
688                      unsigned Line, Metadata *Scope, Metadata *BaseType,
689                      uint64_t SizeInBits, uint64_t AlignInBits,
690                      uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
691                      unsigned RuntimeLang, Metadata *VTableHolder,
692                      Metadata *TemplateParams = nullptr,
693                      MDString *Identifier = nullptr),
694                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
695                      AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
696                      VTableHolder, TemplateParams, Identifier))
697
698   TempMDCompositeType clone() const { return cloneImpl(); }
699
700   static bool classof(const Metadata *MD) {
701     return MD->getMetadataID() == MDCompositeTypeKind;
702   }
703 };
704
705 /// \brief Type array for a subprogram.
706 ///
707 /// TODO: Detach from CompositeType, and fold the array of types in directly
708 /// as operands.
709 class MDSubroutineType : public MDCompositeTypeBase {
710   friend class LLVMContextImpl;
711   friend class MDNode;
712
713   MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
714                    ArrayRef<Metadata *> Ops)
715       : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
716                             dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
717                             Ops) {}
718   ~MDSubroutineType() {}
719
720   static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
721                                    Metadata *TypeArray, StorageType Storage,
722                                    bool ShouldCreate = true);
723
724   TempMDSubroutineType cloneImpl() const {
725     return getTemporary(getContext(), getFlags(), getTypeArray());
726   }
727
728 public:
729   DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
730                     (Flags, TypeArray))
731
732   TempMDSubroutineType clone() const { return cloneImpl(); }
733
734   Metadata *getTypeArray() const { return getElements(); }
735
736   static bool classof(const Metadata *MD) {
737     return MD->getMetadataID() == MDSubroutineTypeKind;
738   }
739 };
740
741 /// \brief File.
742 ///
743 /// TODO: Merge with directory/file node (including users).
744 /// TODO: Canonicalize paths on creation.
745 class MDFile : public MDScope {
746   friend class LLVMContextImpl;
747   friend class MDNode;
748
749   MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
750       : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
751   ~MDFile() {}
752
753   static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
754                          StringRef Directory, StorageType Storage,
755                          bool ShouldCreate = true) {
756     return getImpl(Context, getCanonicalMDString(Context, Filename),
757                    getCanonicalMDString(Context, Directory), Storage,
758                    ShouldCreate);
759   }
760   static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
761                          MDString *Directory, StorageType Storage,
762                          bool ShouldCreate = true);
763
764   TempMDFile cloneImpl() const {
765     return getTemporary(getContext(), getFilename(), getDirectory());
766   }
767
768 public:
769   DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
770                     (Filename, Directory))
771   DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
772                     (Filename, Directory))
773
774   TempMDFile clone() const { return cloneImpl(); }
775
776   StringRef getFilename() const { return getStringOperand(0); }
777   StringRef getDirectory() const { return getStringOperand(1); }
778
779   MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
780   MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
781
782   static bool classof(const Metadata *MD) {
783     return MD->getMetadataID() == MDFileKind;
784   }
785 };
786
787 /// \brief Compile unit.
788 class MDCompileUnit : public MDScope {
789   friend class LLVMContextImpl;
790   friend class MDNode;
791
792   unsigned SourceLanguage;
793   bool IsOptimized;
794   unsigned RuntimeVersion;
795   unsigned EmissionKind;
796
797   MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
798                 bool IsOptimized, unsigned RuntimeVersion,
799                 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
800       : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
801         SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
802         RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
803   ~MDCompileUnit() {}
804
805   static MDCompileUnit *
806   getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
807           StringRef Producer, bool IsOptimized, StringRef Flags,
808           unsigned RuntimeVersion, StringRef SplitDebugFilename,
809           unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
810           Metadata *Subprograms, Metadata *GlobalVariables,
811           Metadata *ImportedEntities, StorageType Storage,
812           bool ShouldCreate = true) {
813     return getImpl(Context, SourceLanguage, File,
814                    getCanonicalMDString(Context, Producer), IsOptimized,
815                    getCanonicalMDString(Context, Flags), RuntimeVersion,
816                    getCanonicalMDString(Context, SplitDebugFilename),
817                    EmissionKind, EnumTypes, RetainedTypes, Subprograms,
818                    GlobalVariables, ImportedEntities, Storage, ShouldCreate);
819   }
820   static MDCompileUnit *
821   getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
822           MDString *Producer, bool IsOptimized, MDString *Flags,
823           unsigned RuntimeVersion, MDString *SplitDebugFilename,
824           unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
825           Metadata *Subprograms, Metadata *GlobalVariables,
826           Metadata *ImportedEntities, StorageType Storage,
827           bool ShouldCreate = true);
828
829   TempMDCompileUnit cloneImpl() const {
830     return getTemporary(
831         getContext(), getSourceLanguage(), getFile(), getProducer(),
832         isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
833         getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
834         getGlobalVariables(), getImportedEntities());
835   }
836
837 public:
838   DEFINE_MDNODE_GET(MDCompileUnit,
839                     (unsigned SourceLanguage, Metadata *File,
840                      StringRef Producer, bool IsOptimized, StringRef Flags,
841                      unsigned RuntimeVersion, StringRef SplitDebugFilename,
842                      unsigned EmissionKind, Metadata *EnumTypes,
843                      Metadata *RetainedTypes, Metadata *Subprograms,
844                      Metadata *GlobalVariables, Metadata *ImportedEntities),
845                     (SourceLanguage, File, Producer, IsOptimized, Flags,
846                      RuntimeVersion, SplitDebugFilename, EmissionKind,
847                      EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
848                      ImportedEntities))
849   DEFINE_MDNODE_GET(MDCompileUnit,
850                     (unsigned SourceLanguage, Metadata *File,
851                      MDString *Producer, bool IsOptimized, MDString *Flags,
852                      unsigned RuntimeVersion, MDString *SplitDebugFilename,
853                      unsigned EmissionKind, Metadata *EnumTypes,
854                      Metadata *RetainedTypes, Metadata *Subprograms,
855                      Metadata *GlobalVariables, Metadata *ImportedEntities),
856                     (SourceLanguage, File, Producer, IsOptimized, Flags,
857                      RuntimeVersion, SplitDebugFilename, EmissionKind,
858                      EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
859                      ImportedEntities))
860
861   TempMDCompileUnit clone() const { return cloneImpl(); }
862
863   unsigned getSourceLanguage() const { return SourceLanguage; }
864   bool isOptimized() const { return IsOptimized; }
865   unsigned getRuntimeVersion() const { return RuntimeVersion; }
866   unsigned getEmissionKind() const { return EmissionKind; }
867   StringRef getProducer() const { return getStringOperand(1); }
868   StringRef getFlags() const { return getStringOperand(2); }
869   StringRef getSplitDebugFilename() const { return getStringOperand(3); }
870   Metadata *getEnumTypes() const { return getOperand(4); }
871   Metadata *getRetainedTypes() const { return getOperand(5); }
872   Metadata *getSubprograms() const { return getOperand(6); }
873   Metadata *getGlobalVariables() const { return getOperand(7); }
874   Metadata *getImportedEntities() const { return getOperand(8); }
875
876   MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
877   MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
878   MDString *getRawSplitDebugFilename() const {
879     return getOperandAs<MDString>(3);
880   }
881
882   /// \brief Replace arrays.
883   ///
884   /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
885   /// deleted on a uniquing collision.  In practice, uniquing collisions on \a
886   /// MDCompileUnit should be fairly rare.
887   /// @{
888   void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
889   void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
890   /// @}
891
892   static bool classof(const Metadata *MD) {
893     return MD->getMetadataID() == MDCompileUnitKind;
894   }
895 };
896
897 /// \brief A scope for locals.
898 ///
899 /// A legal scope for lexical blocks, local variables, and debug info
900 /// locations.  Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
901 /// MDLexicalBlockFile.
902 class MDLocalScope : public MDScope {
903 protected:
904   MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
905                ArrayRef<Metadata *> Ops)
906       : MDScope(C, ID, Storage, Tag, Ops) {}
907   ~MDLocalScope() {}
908
909 public:
910   static bool classof(const Metadata *MD) {
911     return MD->getMetadataID() == MDSubprogramKind ||
912            MD->getMetadataID() == MDLexicalBlockKind ||
913            MD->getMetadataID() == MDLexicalBlockFileKind;
914   }
915 };
916
917 /// \brief Subprogram description.
918 ///
919 /// TODO: Remove DisplayName.  It's always equal to Name.
920 /// TODO: Split up flags.
921 class MDSubprogram : public MDLocalScope {
922   friend class LLVMContextImpl;
923   friend class MDNode;
924
925   unsigned Line;
926   unsigned ScopeLine;
927   unsigned Virtuality;
928   unsigned VirtualIndex;
929   unsigned Flags;
930   bool IsLocalToUnit;
931   bool IsDefinition;
932   bool IsOptimized;
933
934   MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
935                unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
936                unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
937                bool IsOptimized, ArrayRef<Metadata *> Ops)
938       : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
939                      Ops),
940         Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
941         VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
942         IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
943   ~MDSubprogram() {}
944
945   static MDSubprogram *
946   getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
947           StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
948           bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
949           Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
950           unsigned Flags, bool IsOptimized, Metadata *Function,
951           Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
952           StorageType Storage, bool ShouldCreate = true) {
953     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
954                    getCanonicalMDString(Context, LinkageName), File, Line, Type,
955                    IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
956                    Virtuality, VirtualIndex, Flags, IsOptimized, Function,
957                    TemplateParams, Declaration, Variables, Storage,
958                    ShouldCreate);
959   }
960   static MDSubprogram *
961   getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
962           MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
963           bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
964           Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
965           unsigned Flags, bool IsOptimized, Metadata *Function,
966           Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
967           StorageType Storage, bool ShouldCreate = true);
968
969   TempMDSubprogram cloneImpl() const {
970     return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
971                         getFile(), getLine(), getType(), isLocalToUnit(),
972                         isDefinition(), getScopeLine(), getContainingType(),
973                         getVirtuality(), getVirtualIndex(), getFlags(),
974                         isOptimized(), getFunction(), getTemplateParams(),
975                         getDeclaration(), getVariables());
976   }
977
978 public:
979   DEFINE_MDNODE_GET(
980       MDSubprogram,
981       (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
982        unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
983        unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
984        unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
985        Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
986        Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
987       (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
988        ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
989        Function, TemplateParams, Declaration, Variables))
990   DEFINE_MDNODE_GET(
991       MDSubprogram,
992       (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
993        unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
994        unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
995        unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
996        Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
997        Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
998       (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
999        ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1000        Function, TemplateParams, Declaration, Variables))
1001
1002   TempMDSubprogram clone() const { return cloneImpl(); }
1003
1004 public:
1005   unsigned getLine() const { return Line; }
1006   unsigned getVirtuality() const { return Virtuality; }
1007   unsigned getVirtualIndex() const { return VirtualIndex; }
1008   unsigned getScopeLine() const { return ScopeLine; }
1009   unsigned getFlags() const { return Flags; }
1010   bool isLocalToUnit() const { return IsLocalToUnit; }
1011   bool isDefinition() const { return IsDefinition; }
1012   bool isOptimized() const { return IsOptimized; }
1013
1014   Metadata *getScope() const { return getOperand(1); }
1015
1016   StringRef getName() const { return getStringOperand(2); }
1017   StringRef getDisplayName() const { return getStringOperand(3); }
1018   StringRef getLinkageName() const { return getStringOperand(4); }
1019
1020   MDString *getRawName() const { return getOperandAs<MDString>(2); }
1021   MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1022
1023   Metadata *getType() const { return getOperand(5); }
1024   Metadata *getContainingType() const { return getOperand(6); }
1025
1026   Metadata *getFunction() const { return getOperand(7); }
1027   Metadata *getTemplateParams() const { return getOperand(8); }
1028   Metadata *getDeclaration() const { return getOperand(9); }
1029   Metadata *getVariables() const { return getOperand(10); }
1030
1031   /// \brief Replace the function.
1032   ///
1033   /// If \a isUniqued() and not \a isResolved(), this could node will be
1034   /// RAUW'ed and deleted out from under the caller.  Use a \a TrackingMDRef if
1035   /// that's a problem.
1036   /// @{
1037   void replaceFunction(Function *F);
1038   void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1039   void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1040   /// @}
1041
1042   static bool classof(const Metadata *MD) {
1043     return MD->getMetadataID() == MDSubprogramKind;
1044   }
1045 };
1046
1047 class MDLexicalBlockBase : public MDLocalScope {
1048 protected:
1049   MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1050                      ArrayRef<Metadata *> Ops)
1051       : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1052   ~MDLexicalBlockBase() {}
1053
1054 public:
1055   Metadata *getScope() const { return getOperand(1); }
1056
1057   static bool classof(const Metadata *MD) {
1058     return MD->getMetadataID() == MDLexicalBlockKind ||
1059            MD->getMetadataID() == MDLexicalBlockFileKind;
1060   }
1061 };
1062
1063 class MDLexicalBlock : public MDLexicalBlockBase {
1064   friend class LLVMContextImpl;
1065   friend class MDNode;
1066
1067   unsigned Line;
1068   unsigned Column;
1069
1070   MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1071                  unsigned Column, ArrayRef<Metadata *> Ops)
1072       : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1073         Column(Column) {}
1074   ~MDLexicalBlock() {}
1075
1076   static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1077                                  Metadata *File, unsigned Line, unsigned Column,
1078                                  StorageType Storage, bool ShouldCreate = true);
1079
1080   TempMDLexicalBlock cloneImpl() const {
1081     return getTemporary(getContext(), getScope(), getFile(), getLine(),
1082                         getColumn());
1083   }
1084
1085 public:
1086   DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1087                                      unsigned Line, unsigned Column),
1088                     (Scope, File, Line, Column))
1089
1090   TempMDLexicalBlock clone() const { return cloneImpl(); }
1091
1092   unsigned getLine() const { return Line; }
1093   unsigned getColumn() const { return Column; }
1094
1095   static bool classof(const Metadata *MD) {
1096     return MD->getMetadataID() == MDLexicalBlockKind;
1097   }
1098 };
1099
1100 class MDLexicalBlockFile : public MDLexicalBlockBase {
1101   friend class LLVMContextImpl;
1102   friend class MDNode;
1103
1104   unsigned Discriminator;
1105
1106   MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1107                      unsigned Discriminator, ArrayRef<Metadata *> Ops)
1108       : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1109         Discriminator(Discriminator) {}
1110   ~MDLexicalBlockFile() {}
1111
1112   static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1113                                      Metadata *File, unsigned Discriminator,
1114                                      StorageType Storage,
1115                                      bool ShouldCreate = true);
1116
1117   TempMDLexicalBlockFile cloneImpl() const {
1118     return getTemporary(getContext(), getScope(), getFile(),
1119                         getDiscriminator());
1120   }
1121
1122 public:
1123   DEFINE_MDNODE_GET(MDLexicalBlockFile,
1124                     (Metadata * Scope, Metadata *File, unsigned Discriminator),
1125                     (Scope, File, Discriminator))
1126
1127   TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1128
1129   unsigned getDiscriminator() const { return Discriminator; }
1130
1131   static bool classof(const Metadata *MD) {
1132     return MD->getMetadataID() == MDLexicalBlockFileKind;
1133   }
1134 };
1135
1136 class MDNamespace : public MDScope {
1137   friend class LLVMContextImpl;
1138   friend class MDNode;
1139
1140   unsigned Line;
1141
1142   MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1143               ArrayRef<Metadata *> Ops)
1144       : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1145                 Ops),
1146         Line(Line) {}
1147   ~MDNamespace() {}
1148
1149   static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1150                               Metadata *File, StringRef Name, unsigned Line,
1151                               StorageType Storage, bool ShouldCreate = true) {
1152     return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1153                    Line, Storage, ShouldCreate);
1154   }
1155   static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1156                               Metadata *File, MDString *Name, unsigned Line,
1157                               StorageType Storage, bool ShouldCreate = true);
1158
1159   TempMDNamespace cloneImpl() const {
1160     return getTemporary(getContext(), getScope(), getFile(), getName(),
1161                         getLine());
1162   }
1163
1164 public:
1165   DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1166                                   StringRef Name, unsigned Line),
1167                     (Scope, File, Name, Line))
1168   DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1169                                   MDString *Name, unsigned Line),
1170                     (Scope, File, Name, Line))
1171
1172   TempMDNamespace clone() const { return cloneImpl(); }
1173
1174   unsigned getLine() const { return Line; }
1175   Metadata *getScope() const { return getOperand(1); }
1176   StringRef getName() const { return getStringOperand(2); }
1177
1178   MDString *getRawName() const { return getOperandAs<MDString>(2); }
1179
1180   static bool classof(const Metadata *MD) {
1181     return MD->getMetadataID() == MDNamespaceKind;
1182   }
1183 };
1184
1185 /// \brief Base class for template parameters.
1186 class MDTemplateParameter : public DebugNode {
1187 protected:
1188   MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1189                       unsigned Tag, ArrayRef<Metadata *> Ops)
1190       : DebugNode(Context, ID, Storage, Tag, Ops) {}
1191   ~MDTemplateParameter() {}
1192
1193 public:
1194   StringRef getName() const { return getStringOperand(0); }
1195   Metadata *getType() const { return getOperand(1); }
1196
1197   MDString *getRawName() const { return getOperandAs<MDString>(0); }
1198
1199   static bool classof(const Metadata *MD) {
1200     return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1201            MD->getMetadataID() == MDTemplateValueParameterKind;
1202   }
1203 };
1204
1205 class MDTemplateTypeParameter : public MDTemplateParameter {
1206   friend class LLVMContextImpl;
1207   friend class MDNode;
1208
1209   MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1210                           ArrayRef<Metadata *> Ops)
1211       : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1212                             dwarf::DW_TAG_template_type_parameter, Ops) {}
1213   ~MDTemplateTypeParameter() {}
1214
1215   static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1216                                           Metadata *Type, StorageType Storage,
1217                                           bool ShouldCreate = true) {
1218     return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1219                    ShouldCreate);
1220   }
1221   static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1222                                           Metadata *Type, StorageType Storage,
1223                                           bool ShouldCreate = true);
1224
1225   TempMDTemplateTypeParameter cloneImpl() const {
1226     return getTemporary(getContext(), getName(), getType());
1227   }
1228
1229 public:
1230   DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1231                     (Name, Type))
1232   DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1233                     (Name, Type))
1234
1235   TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1236
1237   static bool classof(const Metadata *MD) {
1238     return MD->getMetadataID() == MDTemplateTypeParameterKind;
1239   }
1240 };
1241
1242 class MDTemplateValueParameter : public MDTemplateParameter {
1243   friend class LLVMContextImpl;
1244   friend class MDNode;
1245
1246   MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1247                            unsigned Tag, ArrayRef<Metadata *> Ops)
1248       : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1249                             Ops) {}
1250   ~MDTemplateValueParameter() {}
1251
1252   static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1253                                            StringRef Name, Metadata *Type,
1254                                            Metadata *Value, StorageType Storage,
1255                                            bool ShouldCreate = true) {
1256     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1257                    Value, Storage, ShouldCreate);
1258   }
1259   static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1260                                            MDString *Name, Metadata *Type,
1261                                            Metadata *Value, StorageType Storage,
1262                                            bool ShouldCreate = true);
1263
1264   TempMDTemplateValueParameter cloneImpl() const {
1265     return getTemporary(getContext(), getTag(), getName(), getType(),
1266                         getValue());
1267   }
1268
1269 public:
1270   DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1271                                                Metadata *Type, Metadata *Value),
1272                     (Tag, Name, Type, Value))
1273   DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1274                                                Metadata *Type, Metadata *Value),
1275                     (Tag, Name, Type, Value))
1276
1277   TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1278
1279   Metadata *getValue() const { return getOperand(2); }
1280
1281   static bool classof(const Metadata *MD) {
1282     return MD->getMetadataID() == MDTemplateValueParameterKind;
1283   }
1284 };
1285
1286 /// \brief Base class for variables.
1287 ///
1288 /// TODO: Hardcode to DW_TAG_variable.
1289 class MDVariable : public DebugNode {
1290   unsigned Line;
1291
1292 protected:
1293   MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1294              unsigned Line, ArrayRef<Metadata *> Ops)
1295       : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1296   ~MDVariable() {}
1297
1298 public:
1299   unsigned getLine() const { return Line; }
1300   Metadata *getScope() const { return getOperand(0); }
1301   StringRef getName() const { return getStringOperand(1); }
1302   Metadata *getFile() const { return getOperand(2); }
1303   Metadata *getType() const { return getOperand(3); }
1304
1305   MDString *getRawName() const { return getOperandAs<MDString>(1); }
1306
1307   static bool classof(const Metadata *MD) {
1308     return MD->getMetadataID() == MDLocalVariableKind ||
1309            MD->getMetadataID() == MDGlobalVariableKind;
1310   }
1311 };
1312
1313 /// \brief Global variables.
1314 ///
1315 /// TODO: Remove DisplayName.  It's always equal to Name.
1316 class MDGlobalVariable : public MDVariable {
1317   friend class LLVMContextImpl;
1318   friend class MDNode;
1319
1320   bool IsLocalToUnit;
1321   bool IsDefinition;
1322
1323   MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1324                    bool IsLocalToUnit, bool IsDefinition,
1325                    ArrayRef<Metadata *> Ops)
1326       : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1327                    Line, Ops),
1328         IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1329   ~MDGlobalVariable() {}
1330
1331   static MDGlobalVariable *
1332   getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1333           StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1334           bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1335           Metadata *StaticDataMemberDeclaration, StorageType Storage,
1336           bool ShouldCreate = true) {
1337     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1338                    getCanonicalMDString(Context, LinkageName), File, Line, Type,
1339                    IsLocalToUnit, IsDefinition, Variable,
1340                    StaticDataMemberDeclaration, Storage, ShouldCreate);
1341   }
1342   static MDGlobalVariable *
1343   getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1344           MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1345           bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1346           Metadata *StaticDataMemberDeclaration, StorageType Storage,
1347           bool ShouldCreate = true);
1348
1349   TempMDGlobalVariable cloneImpl() const {
1350     return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1351                         getFile(), getLine(), getType(), isLocalToUnit(),
1352                         isDefinition(), getVariable(),
1353                         getStaticDataMemberDeclaration());
1354   }
1355
1356 public:
1357   DEFINE_MDNODE_GET(MDGlobalVariable,
1358                     (Metadata * Scope, StringRef Name, StringRef LinkageName,
1359                      Metadata *File, unsigned Line, Metadata *Type,
1360                      bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1361                      Metadata *StaticDataMemberDeclaration),
1362                     (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1363                      IsDefinition, Variable, StaticDataMemberDeclaration))
1364   DEFINE_MDNODE_GET(MDGlobalVariable,
1365                     (Metadata * Scope, MDString *Name, MDString *LinkageName,
1366                      Metadata *File, unsigned Line, Metadata *Type,
1367                      bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1368                      Metadata *StaticDataMemberDeclaration),
1369                     (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1370                      IsDefinition, Variable, StaticDataMemberDeclaration))
1371
1372   TempMDGlobalVariable clone() const { return cloneImpl(); }
1373
1374   bool isLocalToUnit() const { return IsLocalToUnit; }
1375   bool isDefinition() const { return IsDefinition; }
1376   StringRef getDisplayName() const { return getStringOperand(4); }
1377   StringRef getLinkageName() const { return getStringOperand(5); }
1378   Metadata *getVariable() const { return getOperand(6); }
1379   Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1380
1381   MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1382
1383   static bool classof(const Metadata *MD) {
1384     return MD->getMetadataID() == MDGlobalVariableKind;
1385   }
1386 };
1387
1388 /// \brief Local variable.
1389 ///
1390 /// TODO: Split between arguments and otherwise.
1391 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1392 /// TODO: Split up flags.
1393 class MDLocalVariable : public MDVariable {
1394   friend class LLVMContextImpl;
1395   friend class MDNode;
1396
1397   unsigned Arg;
1398   unsigned Flags;
1399
1400   MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1401                   unsigned Line, unsigned Arg, unsigned Flags,
1402                   ArrayRef<Metadata *> Ops)
1403       : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1404         Flags(Flags) {}
1405   ~MDLocalVariable() {}
1406
1407   static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1408                                   Metadata *Scope, StringRef Name,
1409                                   Metadata *File, unsigned Line, Metadata *Type,
1410                                   unsigned Arg, unsigned Flags,
1411                                   Metadata *InlinedAt, StorageType Storage,
1412                                   bool ShouldCreate = true) {
1413     return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1414                    File, Line, Type, Arg, Flags, InlinedAt, Storage,
1415                    ShouldCreate);
1416   }
1417   static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1418                                   Metadata *Scope, MDString *Name,
1419                                   Metadata *File, unsigned Line, Metadata *Type,
1420                                   unsigned Arg, unsigned Flags,
1421                                   Metadata *InlinedAt, StorageType Storage,
1422                                   bool ShouldCreate = true);
1423
1424   TempMDLocalVariable cloneImpl() const {
1425     return getTemporary(getContext(), getTag(), getScope(), getName(),
1426                         getFile(), getLine(), getType(), getArg(), getFlags(),
1427                         getInlinedAt());
1428   }
1429
1430 public:
1431   DEFINE_MDNODE_GET(MDLocalVariable,
1432                     (unsigned Tag, Metadata *Scope, StringRef Name,
1433                      Metadata *File, unsigned Line, Metadata *Type,
1434                      unsigned Arg, unsigned Flags,
1435                      Metadata *InlinedAt = nullptr),
1436                     (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1437   DEFINE_MDNODE_GET(MDLocalVariable,
1438                     (unsigned Tag, Metadata *Scope, MDString *Name,
1439                      Metadata *File, unsigned Line, Metadata *Type,
1440                      unsigned Arg, unsigned Flags,
1441                      Metadata *InlinedAt = nullptr),
1442                     (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1443
1444   TempMDLocalVariable clone() const { return cloneImpl(); }
1445
1446   unsigned getArg() const { return Arg; }
1447   unsigned getFlags() const { return Flags; }
1448   Metadata *getInlinedAt() const { return getOperand(4); }
1449
1450   /// \brief Get an inlined version of this variable.
1451   ///
1452   /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1453   MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1454     if (InlinedAt == getInlinedAt())
1455       return const_cast<MDLocalVariable *>(this);
1456     auto Temp = clone();
1457     Temp->replaceOperandWith(4, InlinedAt);
1458     return replaceWithUniqued(std::move(Temp));
1459   }
1460   MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1461
1462   static bool classof(const Metadata *MD) {
1463     return MD->getMetadataID() == MDLocalVariableKind;
1464   }
1465 };
1466
1467 /// \brief DWARF expression.
1468 ///
1469 /// TODO: Co-allocate the expression elements.
1470 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1471 /// storage types.
1472 class MDExpression : public MDNode {
1473   friend class LLVMContextImpl;
1474   friend class MDNode;
1475
1476   std::vector<uint64_t> Elements;
1477
1478   MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1479       : MDNode(C, MDExpressionKind, Storage, None),
1480         Elements(Elements.begin(), Elements.end()) {}
1481   ~MDExpression() {}
1482
1483   static MDExpression *getImpl(LLVMContext &Context,
1484                                ArrayRef<uint64_t> Elements, StorageType Storage,
1485                                bool ShouldCreate = true);
1486
1487   TempMDExpression cloneImpl() const {
1488     return getTemporary(getContext(), getElements());
1489   }
1490
1491 public:
1492   DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1493
1494   TempMDExpression clone() const { return cloneImpl(); }
1495
1496   ArrayRef<uint64_t> getElements() const { return Elements; }
1497
1498   unsigned getNumElements() const { return Elements.size(); }
1499   uint64_t getElement(unsigned I) const {
1500     assert(I < Elements.size() && "Index out of range");
1501     return Elements[I];
1502   }
1503
1504   typedef ArrayRef<uint64_t>::iterator element_iterator;
1505   element_iterator elements_begin() const { return getElements().begin(); }
1506   element_iterator elements_end() const { return getElements().end(); }
1507
1508   /// \brief A lightweight wrapper around an expression operand.
1509   ///
1510   /// TODO: Store arguments directly and change \a MDExpression to store a
1511   /// range of these.
1512   class ExprOperand {
1513     const uint64_t *Op;
1514
1515   public:
1516     explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1517
1518     const uint64_t *get() const { return Op; }
1519
1520     /// \brief Get the operand code.
1521     uint64_t getOp() const { return *Op; }
1522
1523     /// \brief Get an argument to the operand.
1524     ///
1525     /// Never returns the operand itself.
1526     uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1527
1528     unsigned getNumArgs() const { return getSize() - 1; }
1529
1530     /// \brief Return the size of the operand.
1531     ///
1532     /// Return the number of elements in the operand (1 + args).
1533     unsigned getSize() const;
1534   };
1535
1536   /// \brief An iterator for expression operands.
1537   class expr_op_iterator
1538       : public std::iterator<std::input_iterator_tag, ExprOperand> {
1539     ExprOperand Op;
1540
1541   public:
1542     explicit expr_op_iterator(element_iterator I) : Op(I) {}
1543
1544     element_iterator getBase() const { return Op.get(); }
1545     const ExprOperand &operator*() const { return Op; }
1546     const ExprOperand *operator->() const { return &Op; }
1547
1548     expr_op_iterator &operator++() {
1549       increment();
1550       return *this;
1551     }
1552     expr_op_iterator operator++(int) {
1553       expr_op_iterator T(*this);
1554       increment();
1555       return T;
1556     }
1557
1558     bool operator==(const expr_op_iterator &X) const {
1559       return getBase() == X.getBase();
1560     }
1561     bool operator!=(const expr_op_iterator &X) const {
1562       return getBase() != X.getBase();
1563     }
1564
1565   private:
1566     void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1567   };
1568
1569   /// \brief Visit the elements via ExprOperand wrappers.
1570   ///
1571   /// These range iterators visit elements through \a ExprOperand wrappers.
1572   /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1573   /// true.
1574   ///
1575   /// \pre \a isValid() gives \c true.
1576   /// @{
1577   expr_op_iterator expr_op_begin() const {
1578     return expr_op_iterator(elements_begin());
1579   }
1580   expr_op_iterator expr_op_end() const {
1581     return expr_op_iterator(elements_end());
1582   }
1583   /// @}
1584
1585   bool isValid() const;
1586
1587   static bool classof(const Metadata *MD) {
1588     return MD->getMetadataID() == MDExpressionKind;
1589   }
1590 };
1591
1592 class MDObjCProperty : public DebugNode {
1593   friend class LLVMContextImpl;
1594   friend class MDNode;
1595
1596   unsigned Line;
1597   unsigned Attributes;
1598
1599   MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1600                  unsigned Attributes, ArrayRef<Metadata *> Ops)
1601       : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1602                   Ops),
1603         Line(Line), Attributes(Attributes) {}
1604   ~MDObjCProperty() {}
1605
1606   static MDObjCProperty *
1607   getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1608           StringRef GetterName, StringRef SetterName, unsigned Attributes,
1609           Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1610     return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1611                    getCanonicalMDString(Context, GetterName),
1612                    getCanonicalMDString(Context, SetterName), Attributes, Type,
1613                    Storage, ShouldCreate);
1614   }
1615   static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1616                                  Metadata *File, unsigned Line,
1617                                  MDString *GetterName, MDString *SetterName,
1618                                  unsigned Attributes, Metadata *Type,
1619                                  StorageType Storage, bool ShouldCreate = true);
1620
1621   TempMDObjCProperty cloneImpl() const {
1622     return getTemporary(getContext(), getName(), getFile(), getLine(),
1623                         getGetterName(), getSetterName(), getAttributes(),
1624                         getType());
1625   }
1626
1627 public:
1628   DEFINE_MDNODE_GET(MDObjCProperty,
1629                     (StringRef Name, Metadata *File, unsigned Line,
1630                      StringRef GetterName, StringRef SetterName,
1631                      unsigned Attributes, Metadata *Type),
1632                     (Name, File, Line, GetterName, SetterName, Attributes,
1633                      Type))
1634   DEFINE_MDNODE_GET(MDObjCProperty,
1635                     (MDString * Name, Metadata *File, unsigned Line,
1636                      MDString *GetterName, MDString *SetterName,
1637                      unsigned Attributes, Metadata *Type),
1638                     (Name, File, Line, GetterName, SetterName, Attributes,
1639                      Type))
1640
1641   TempMDObjCProperty clone() const { return cloneImpl(); }
1642
1643   unsigned getLine() const { return Line; }
1644   unsigned getAttributes() const { return Attributes; }
1645   StringRef getName() const { return getStringOperand(0); }
1646   Metadata *getFile() const { return getOperand(1); }
1647   StringRef getGetterName() const { return getStringOperand(2); }
1648   StringRef getSetterName() const { return getStringOperand(3); }
1649   Metadata *getType() const { return getOperand(4); }
1650
1651   MDString *getRawName() const { return getOperandAs<MDString>(0); }
1652   MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1653   MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1654
1655   static bool classof(const Metadata *MD) {
1656     return MD->getMetadataID() == MDObjCPropertyKind;
1657   }
1658 };
1659
1660 class MDImportedEntity : public DebugNode {
1661   friend class LLVMContextImpl;
1662   friend class MDNode;
1663
1664   unsigned Line;
1665
1666   MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1667                    unsigned Line, ArrayRef<Metadata *> Ops)
1668       : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1669   ~MDImportedEntity() {}
1670
1671   static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1672                                    Metadata *Scope, Metadata *Entity,
1673                                    unsigned Line, StringRef Name,
1674                                    StorageType Storage,
1675                                    bool ShouldCreate = true) {
1676     return getImpl(Context, Tag, Scope, Entity, Line,
1677                    getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1678   }
1679   static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1680                                    Metadata *Scope, Metadata *Entity,
1681                                    unsigned Line, MDString *Name,
1682                                    StorageType Storage,
1683                                    bool ShouldCreate = true);
1684
1685   TempMDImportedEntity cloneImpl() const {
1686     return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1687                         getLine(), getName());
1688   }
1689
1690 public:
1691   DEFINE_MDNODE_GET(MDImportedEntity,
1692                     (unsigned Tag, Metadata *Scope, Metadata *Entity,
1693                      unsigned Line, StringRef Name = ""),
1694                     (Tag, Scope, Entity, Line, Name))
1695   DEFINE_MDNODE_GET(MDImportedEntity,
1696                     (unsigned Tag, Metadata *Scope, Metadata *Entity,
1697                      unsigned Line, MDString *Name),
1698                     (Tag, Scope, Entity, Line, Name))
1699
1700   TempMDImportedEntity clone() const { return cloneImpl(); }
1701
1702   unsigned getLine() const { return Line; }
1703   Metadata *getScope() const { return getOperand(0); }
1704   Metadata *getEntity() const { return getOperand(1); }
1705   StringRef getName() const { return getStringOperand(2); }
1706
1707   MDString *getRawName() const { return getOperandAs<MDString>(2); }
1708
1709   static bool classof(const Metadata *MD) {
1710     return MD->getMetadataID() == MDImportedEntityKind;
1711   }
1712 };
1713
1714 } // end namespace llvm
1715
1716 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1717 #undef DEFINE_MDNODE_GET_UNPACK
1718 #undef DEFINE_MDNODE_GET
1719
1720 #endif