DebugInfo: Reorder definitions of MDLocation and MDFile, NFC
[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 Tagged DWARF-like metadata node.
45 ///
46 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
47 /// defined in llvm/Support/Dwarf.h).  Called \a DebugNode because it's
48 /// potentially used for non-DWARF output.
49 class DebugNode : public MDNode {
50   friend class LLVMContextImpl;
51   friend class MDNode;
52
53 protected:
54   DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
55             ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
56       : MDNode(C, ID, Storage, Ops1, Ops2) {
57     assert(Tag < 1u << 16);
58     SubclassData16 = Tag;
59   }
60   ~DebugNode() {}
61
62   template <class Ty> Ty *getOperandAs(unsigned I) const {
63     return cast_or_null<Ty>(getOperand(I));
64   }
65
66   StringRef getStringOperand(unsigned I) const {
67     if (auto *S = getOperandAs<MDString>(I))
68       return S->getString();
69     return StringRef();
70   }
71
72   static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
73     if (S.empty())
74       return nullptr;
75     return MDString::get(Context, S);
76   }
77
78 public:
79   unsigned getTag() const { return SubclassData16; }
80
81   static bool classof(const Metadata *MD) {
82     switch (MD->getMetadataID()) {
83     default:
84       return false;
85     case GenericDebugNodeKind:
86     case MDSubrangeKind:
87     case MDEnumeratorKind:
88     case MDBasicTypeKind:
89     case MDDerivedTypeKind:
90     case MDCompositeTypeKind:
91     case MDSubroutineTypeKind:
92     case MDFileKind:
93     case MDCompileUnitKind:
94     case MDSubprogramKind:
95     case MDLexicalBlockKind:
96     case MDLexicalBlockFileKind:
97     case MDNamespaceKind:
98     case MDTemplateTypeParameterKind:
99     case MDTemplateValueParameterKind:
100     case MDGlobalVariableKind:
101     case MDLocalVariableKind:
102     case MDObjCPropertyKind:
103     case MDImportedEntityKind:
104       return true;
105     }
106   }
107 };
108
109 /// \brief Generic tagged DWARF-like metadata node.
110 ///
111 /// An un-specialized DWARF-like metadata node.  The first operand is a
112 /// (possibly empty) null-separated \a MDString header that contains arbitrary
113 /// fields.  The remaining operands are \a dwarf_operands(), and are pointers
114 /// to other metadata.
115 class GenericDebugNode : public DebugNode {
116   friend class LLVMContextImpl;
117   friend class MDNode;
118
119   GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
120                    unsigned Tag, ArrayRef<Metadata *> Ops1,
121                    ArrayRef<Metadata *> Ops2)
122       : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
123     setHash(Hash);
124   }
125   ~GenericDebugNode() { dropAllReferences(); }
126
127   void setHash(unsigned Hash) { SubclassData32 = Hash; }
128   void recalculateHash();
129
130   static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
131                                    StringRef Header,
132                                    ArrayRef<Metadata *> DwarfOps,
133                                    StorageType Storage,
134                                    bool ShouldCreate = true) {
135     return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
136                    DwarfOps, Storage, ShouldCreate);
137   }
138
139   static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
140                                    MDString *Header,
141                                    ArrayRef<Metadata *> DwarfOps,
142                                    StorageType Storage,
143                                    bool ShouldCreate = true);
144
145   TempGenericDebugNode cloneImpl() const {
146     return getTemporary(
147         getContext(), getTag(), getHeader(),
148         SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
149   }
150
151 public:
152   unsigned getHash() const { return SubclassData32; }
153
154   DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
155                                        ArrayRef<Metadata *> DwarfOps),
156                     (Tag, Header, DwarfOps))
157   DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
158                                        ArrayRef<Metadata *> DwarfOps),
159                     (Tag, Header, DwarfOps))
160
161   /// \brief Return a (temporary) clone of this.
162   TempGenericDebugNode clone() const { return cloneImpl(); }
163
164   unsigned getTag() const { return SubclassData16; }
165   StringRef getHeader() const { return getStringOperand(0); }
166
167   op_iterator dwarf_op_begin() const { return op_begin() + 1; }
168   op_iterator dwarf_op_end() const { return op_end(); }
169   op_range dwarf_operands() const {
170     return op_range(dwarf_op_begin(), dwarf_op_end());
171   }
172
173   unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
174   const MDOperand &getDwarfOperand(unsigned I) const {
175     return getOperand(I + 1);
176   }
177   void replaceDwarfOperandWith(unsigned I, Metadata *New) {
178     replaceOperandWith(I + 1, New);
179   }
180
181   static bool classof(const Metadata *MD) {
182     return MD->getMetadataID() == GenericDebugNodeKind;
183   }
184 };
185
186 /// \brief Array subrange.
187 ///
188 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
189 /// type.
190 class MDSubrange : public DebugNode {
191   friend class LLVMContextImpl;
192   friend class MDNode;
193
194   int64_t Count;
195   int64_t Lo;
196
197   MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count, int64_t Lo)
198       : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
199                   None),
200         Count(Count), Lo(Lo) {}
201   ~MDSubrange() {}
202
203   static MDSubrange *getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
204                              StorageType Storage, bool ShouldCreate = true);
205
206   TempMDSubrange cloneImpl() const {
207     return getTemporary(getContext(), getCount(), getLo());
208   }
209
210 public:
211   DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t Lo = 0), (Count, Lo))
212
213   TempMDSubrange clone() const { return cloneImpl(); }
214
215   int64_t getLo() const { return Lo; }
216   int64_t getCount() const { return Count; }
217
218   static bool classof(const Metadata *MD) {
219     return MD->getMetadataID() == MDSubrangeKind;
220   }
221 };
222
223 /// \brief Enumeration value.
224 ///
225 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
226 /// longer creates a type cycle.
227 class MDEnumerator : public DebugNode {
228   friend class LLVMContextImpl;
229   friend class MDNode;
230
231   int64_t Value;
232
233   MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
234                ArrayRef<Metadata *> Ops)
235       : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
236         Value(Value) {}
237   ~MDEnumerator() {}
238
239   static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
240                                StringRef Name, StorageType Storage,
241                                bool ShouldCreate = true) {
242     return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
243                    ShouldCreate);
244   }
245   static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
246                                MDString *Name, StorageType Storage,
247                                bool ShouldCreate = true);
248
249   TempMDEnumerator cloneImpl() const {
250     return getTemporary(getContext(), getValue(), getName());
251   }
252
253 public:
254   DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
255                     (Value, Name))
256   DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
257                     (Value, Name))
258
259   TempMDEnumerator clone() const { return cloneImpl(); }
260
261   int64_t getValue() const { return Value; }
262   StringRef getName() const { return getStringOperand(0); }
263
264   MDString *getRawName() const { return getOperandAs<MDString>(0); }
265
266   static bool classof(const Metadata *MD) {
267     return MD->getMetadataID() == MDEnumeratorKind;
268   }
269 };
270
271 /// \brief Base class for scope-like contexts.
272 ///
273 /// Base class for lexical scopes and types (which are also declaration
274 /// contexts).
275 ///
276 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
277 class MDScope : public DebugNode {
278 protected:
279   MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
280           ArrayRef<Metadata *> Ops)
281       : DebugNode(C, ID, Storage, Tag, Ops) {}
282   ~MDScope() {}
283
284 public:
285   /// \brief Return the underlying file.
286   ///
287   /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
288   /// (it\em is the file).  If \c this is an \a MDFile, we need to return \c
289   /// this.  Otherwise, return the first operand, which is where all other
290   /// subclasses store their file pointer.
291   Metadata *getFile() const {
292     return isa<MDFile>(this) ? const_cast<MDScope *>(this)
293                              : static_cast<Metadata *>(getOperand(0));
294   }
295
296   static bool classof(const Metadata *MD) {
297     switch (MD->getMetadataID()) {
298     default:
299       return false;
300     case MDBasicTypeKind:
301     case MDDerivedTypeKind:
302     case MDCompositeTypeKind:
303     case MDSubroutineTypeKind:
304     case MDFileKind:
305     case MDCompileUnitKind:
306     case MDSubprogramKind:
307     case MDLexicalBlockKind:
308     case MDLexicalBlockFileKind:
309     case MDNamespaceKind:
310       return true;
311     }
312   }
313 };
314
315 /// \brief File.
316 ///
317 /// TODO: Merge with directory/file node (including users).
318 /// TODO: Canonicalize paths on creation.
319 class MDFile : public MDScope {
320   friend class LLVMContextImpl;
321   friend class MDNode;
322
323   MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
324       : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
325   ~MDFile() {}
326
327   static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
328                          StringRef Directory, StorageType Storage,
329                          bool ShouldCreate = true) {
330     return getImpl(Context, getCanonicalMDString(Context, Filename),
331                    getCanonicalMDString(Context, Directory), Storage,
332                    ShouldCreate);
333   }
334   static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
335                          MDString *Directory, StorageType Storage,
336                          bool ShouldCreate = true);
337
338   TempMDFile cloneImpl() const {
339     return getTemporary(getContext(), getFilename(), getDirectory());
340   }
341
342 public:
343   DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
344                     (Filename, Directory))
345   DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
346                     (Filename, Directory))
347
348   TempMDFile clone() const { return cloneImpl(); }
349
350   StringRef getFilename() const { return getStringOperand(0); }
351   StringRef getDirectory() const { return getStringOperand(1); }
352
353   MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
354   MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
355
356   static bool classof(const Metadata *MD) {
357     return MD->getMetadataID() == MDFileKind;
358   }
359 };
360
361 /// \brief Base class for types.
362 ///
363 /// TODO: Remove the hardcoded name and context, since many types don't use
364 /// them.
365 /// TODO: Split up flags.
366 class MDType : public MDScope {
367   unsigned Line;
368   unsigned Flags;
369   uint64_t SizeInBits;
370   uint64_t AlignInBits;
371   uint64_t OffsetInBits;
372
373 protected:
374   MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
375          unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
376          uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
377       : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
378         SizeInBits(SizeInBits), AlignInBits(AlignInBits),
379         OffsetInBits(OffsetInBits) {}
380   ~MDType() {}
381
382 public:
383   TempMDType clone() const {
384     return TempMDType(cast<MDType>(MDNode::clone().release()));
385   }
386
387   unsigned getLine() const { return Line; }
388   uint64_t getSizeInBits() const { return SizeInBits; }
389   uint64_t getAlignInBits() const { return AlignInBits; }
390   uint64_t getOffsetInBits() const { return OffsetInBits; }
391   unsigned getFlags() const { return Flags; }
392
393   Metadata *getScope() const { return getOperand(1); }
394   StringRef getName() const { return getStringOperand(2); }
395
396   MDString *getRawName() const { return getOperandAs<MDString>(2); }
397
398   void setFlags(unsigned NewFlags) {
399     assert(!isUniqued() && "Cannot set flags on uniqued nodes");
400     Flags = NewFlags;
401   }
402
403   static bool classof(const Metadata *MD) {
404     switch (MD->getMetadataID()) {
405     default:
406       return false;
407     case MDBasicTypeKind:
408     case MDDerivedTypeKind:
409     case MDCompositeTypeKind:
410     case MDSubroutineTypeKind:
411       return true;
412     }
413   }
414 };
415
416 /// \brief Basic type.
417 ///
418 /// TODO: Split out DW_TAG_unspecified_type.
419 /// TODO: Drop unused accessors.
420 class MDBasicType : public MDType {
421   friend class LLVMContextImpl;
422   friend class MDNode;
423
424   unsigned Encoding;
425
426   MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
427               uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
428               ArrayRef<Metadata *> Ops)
429       : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
430                0, Ops),
431         Encoding(Encoding) {}
432   ~MDBasicType() {}
433
434   static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
435                               StringRef Name, uint64_t SizeInBits,
436                               uint64_t AlignInBits, unsigned Encoding,
437                               StorageType Storage, bool ShouldCreate = true) {
438     return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
439                    SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
440   }
441   static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
442                               MDString *Name, uint64_t SizeInBits,
443                               uint64_t AlignInBits, unsigned Encoding,
444                               StorageType Storage, bool ShouldCreate = true);
445
446   TempMDBasicType cloneImpl() const {
447     return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
448                         getAlignInBits(), getEncoding());
449   }
450
451 public:
452   DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
453                     (Tag, Name, 0, 0, 0))
454   DEFINE_MDNODE_GET(MDBasicType,
455                     (unsigned Tag, StringRef Name, uint64_t SizeInBits,
456                      uint64_t AlignInBits, unsigned Encoding),
457                     (Tag, Name, SizeInBits, AlignInBits, Encoding))
458   DEFINE_MDNODE_GET(MDBasicType,
459                     (unsigned Tag, MDString *Name, uint64_t SizeInBits,
460                      uint64_t AlignInBits, unsigned Encoding),
461                     (Tag, Name, SizeInBits, AlignInBits, Encoding))
462
463   TempMDBasicType clone() const { return cloneImpl(); }
464
465   unsigned getEncoding() const { return Encoding; }
466
467   static bool classof(const Metadata *MD) {
468     return MD->getMetadataID() == MDBasicTypeKind;
469   }
470 };
471
472 /// \brief Base class for MDDerivedType and MDCompositeType.
473 ///
474 /// TODO: Delete; they're not really related.
475 class MDDerivedTypeBase : public MDType {
476 protected:
477   MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
478                     unsigned Tag, unsigned Line, uint64_t SizeInBits,
479                     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
480                     ArrayRef<Metadata *> Ops)
481       : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
482                Flags, Ops) {}
483   ~MDDerivedTypeBase() {}
484
485 public:
486   Metadata *getBaseType() const { return getOperand(3); }
487
488   static bool classof(const Metadata *MD) {
489     return MD->getMetadataID() == MDDerivedTypeKind ||
490            MD->getMetadataID() == MDCompositeTypeKind ||
491            MD->getMetadataID() == MDSubroutineTypeKind;
492   }
493 };
494
495 /// \brief Derived types.
496 ///
497 /// This includes qualified types, pointers, references, friends, typedefs, and
498 /// class members.
499 ///
500 /// TODO: Split out members (inheritance, fields, methods, etc.).
501 class MDDerivedType : public MDDerivedTypeBase {
502   friend class LLVMContextImpl;
503   friend class MDNode;
504
505   MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
506                 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
507                 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
508       : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
509                           AlignInBits, OffsetInBits, Flags, Ops) {}
510   ~MDDerivedType() {}
511
512   static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
513                                 StringRef Name, Metadata *File, unsigned Line,
514                                 Metadata *Scope, Metadata *BaseType,
515                                 uint64_t SizeInBits, uint64_t AlignInBits,
516                                 uint64_t OffsetInBits, unsigned Flags,
517                                 Metadata *ExtraData, StorageType Storage,
518                                 bool ShouldCreate = true) {
519     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
520                    Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
521                    Flags, ExtraData, Storage, ShouldCreate);
522   }
523   static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
524                                 MDString *Name, Metadata *File, unsigned Line,
525                                 Metadata *Scope, Metadata *BaseType,
526                                 uint64_t SizeInBits, uint64_t AlignInBits,
527                                 uint64_t OffsetInBits, unsigned Flags,
528                                 Metadata *ExtraData, StorageType Storage,
529                                 bool ShouldCreate = true);
530
531   TempMDDerivedType cloneImpl() const {
532     return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
533                         getScope(), getBaseType(), getSizeInBits(),
534                         getAlignInBits(), getOffsetInBits(), getFlags(),
535                         getExtraData());
536   }
537
538 public:
539   DEFINE_MDNODE_GET(MDDerivedType,
540                     (unsigned Tag, MDString *Name, Metadata *File,
541                      unsigned Line, Metadata *Scope, Metadata *BaseType,
542                      uint64_t SizeInBits, uint64_t AlignInBits,
543                      uint64_t OffsetInBits, unsigned Flags,
544                      Metadata *ExtraData = nullptr),
545                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
546                      AlignInBits, OffsetInBits, Flags, ExtraData))
547   DEFINE_MDNODE_GET(MDDerivedType,
548                     (unsigned Tag, StringRef Name, Metadata *File,
549                      unsigned Line, Metadata *Scope, Metadata *BaseType,
550                      uint64_t SizeInBits, uint64_t AlignInBits,
551                      uint64_t OffsetInBits, unsigned Flags,
552                      Metadata *ExtraData = nullptr),
553                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
554                      AlignInBits, OffsetInBits, Flags, ExtraData))
555
556   TempMDDerivedType clone() const { return cloneImpl(); }
557
558   /// \brief Get extra data associated with this derived type.
559   ///
560   /// Class type for pointer-to-members, objective-c property node for ivars,
561   /// or global constant wrapper for static members.
562   ///
563   /// TODO: Separate out types that need this extra operand: pointer-to-member
564   /// types and member fields (static members and ivars).
565   Metadata *getExtraData() const { return getOperand(4); }
566
567   static bool classof(const Metadata *MD) {
568     return MD->getMetadataID() == MDDerivedTypeKind;
569   }
570 };
571
572 /// \brief Base class for MDCompositeType and MDSubroutineType.
573 ///
574 /// TODO: Delete; they're not really related.
575 class MDCompositeTypeBase : public MDDerivedTypeBase {
576   unsigned RuntimeLang;
577
578 protected:
579   MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
580                       unsigned Tag, unsigned Line, unsigned RuntimeLang,
581                       uint64_t SizeInBits, uint64_t AlignInBits,
582                       uint64_t OffsetInBits, unsigned Flags,
583                       ArrayRef<Metadata *> Ops)
584       : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
585                           OffsetInBits, Flags, Ops),
586         RuntimeLang(RuntimeLang) {}
587   ~MDCompositeTypeBase() {}
588
589 public:
590   Metadata *getElements() const { return getOperand(4); }
591   Metadata *getVTableHolder() const { return getOperand(5); }
592   Metadata *getTemplateParams() const { return getOperand(6); }
593   StringRef getIdentifier() const { return getStringOperand(7); }
594   unsigned getRuntimeLang() const { return RuntimeLang; }
595
596   MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
597
598   /// \brief Replace operands.
599   ///
600   /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
601   /// this will be RAUW'ed and deleted.  Use a \a TrackingMDRef to keep track
602   /// of its movement if necessary.
603   /// @{
604   void replaceElements(MDTuple *Elements) {
605 #ifndef NDEBUG
606     if (auto *Old = cast_or_null<MDTuple>(getElements()))
607       for (const auto &Op : Old->operands())
608         assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
609                "Lost a member during member list replacement");
610 #endif
611     replaceOperandWith(4, Elements);
612   }
613   void replaceVTableHolder(Metadata *VTableHolder) {
614     replaceOperandWith(5, VTableHolder);
615   }
616   void replaceTemplateParams(MDTuple *TemplateParams) {
617     replaceOperandWith(6, TemplateParams);
618   }
619   /// @}
620
621   static bool classof(const Metadata *MD) {
622     return MD->getMetadataID() == MDCompositeTypeKind ||
623            MD->getMetadataID() == MDSubroutineTypeKind;
624   }
625 };
626
627 /// \brief Composite types.
628 ///
629 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
630 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
631 class MDCompositeType : public MDCompositeTypeBase {
632   friend class LLVMContextImpl;
633   friend class MDNode;
634
635   MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
636                   unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
637                   uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
638                   ArrayRef<Metadata *> Ops)
639       : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
640                             RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
641                             Flags, Ops) {}
642   ~MDCompositeType() {}
643
644   static MDCompositeType *
645   getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
646           unsigned Line, Metadata *Scope, Metadata *BaseType,
647           uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
648           uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
649           Metadata *VTableHolder, Metadata *TemplateParams,
650           StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
651     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
652                    Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
653                    Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
654                    getCanonicalMDString(Context, Identifier), Storage,
655                    ShouldCreate);
656   }
657   static MDCompositeType *
658   getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
659           unsigned Line, Metadata *Scope, Metadata *BaseType,
660           uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
661           unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
662           Metadata *VTableHolder, Metadata *TemplateParams,
663           MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
664
665   TempMDCompositeType cloneImpl() const {
666     return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
667                         getScope(), getBaseType(), getSizeInBits(),
668                         getAlignInBits(), getOffsetInBits(), getFlags(),
669                         getElements(), getRuntimeLang(), getVTableHolder(),
670                         getTemplateParams(), getIdentifier());
671   }
672
673 public:
674   DEFINE_MDNODE_GET(MDCompositeType,
675                     (unsigned Tag, StringRef Name, Metadata *File,
676                      unsigned Line, Metadata *Scope, Metadata *BaseType,
677                      uint64_t SizeInBits, uint64_t AlignInBits,
678                      uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
679                      unsigned RuntimeLang, Metadata *VTableHolder,
680                      Metadata *TemplateParams = nullptr,
681                      StringRef Identifier = ""),
682                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
683                      AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
684                      VTableHolder, TemplateParams, Identifier))
685   DEFINE_MDNODE_GET(MDCompositeType,
686                     (unsigned Tag, MDString *Name, Metadata *File,
687                      unsigned Line, Metadata *Scope, Metadata *BaseType,
688                      uint64_t SizeInBits, uint64_t AlignInBits,
689                      uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
690                      unsigned RuntimeLang, Metadata *VTableHolder,
691                      Metadata *TemplateParams = nullptr,
692                      MDString *Identifier = nullptr),
693                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
694                      AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
695                      VTableHolder, TemplateParams, Identifier))
696
697   TempMDCompositeType clone() const { return cloneImpl(); }
698
699   static bool classof(const Metadata *MD) {
700     return MD->getMetadataID() == MDCompositeTypeKind;
701   }
702 };
703
704 /// \brief Type array for a subprogram.
705 ///
706 /// TODO: Detach from CompositeType, and fold the array of types in directly
707 /// as operands.
708 class MDSubroutineType : public MDCompositeTypeBase {
709   friend class LLVMContextImpl;
710   friend class MDNode;
711
712   MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
713                    ArrayRef<Metadata *> Ops)
714       : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
715                             dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
716                             Ops) {}
717   ~MDSubroutineType() {}
718
719   static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
720                                    Metadata *TypeArray, StorageType Storage,
721                                    bool ShouldCreate = true);
722
723   TempMDSubroutineType cloneImpl() const {
724     return getTemporary(getContext(), getFlags(), getTypeArray());
725   }
726
727 public:
728   DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
729                     (Flags, TypeArray))
730
731   TempMDSubroutineType clone() const { return cloneImpl(); }
732
733   Metadata *getTypeArray() const { return getElements(); }
734
735   static bool classof(const Metadata *MD) {
736     return MD->getMetadataID() == MDSubroutineTypeKind;
737   }
738 };
739
740 /// \brief Compile unit.
741 class MDCompileUnit : public MDScope {
742   friend class LLVMContextImpl;
743   friend class MDNode;
744
745   unsigned SourceLanguage;
746   bool IsOptimized;
747   unsigned RuntimeVersion;
748   unsigned EmissionKind;
749
750   MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
751                 bool IsOptimized, unsigned RuntimeVersion,
752                 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
753       : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
754         SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
755         RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
756   ~MDCompileUnit() {}
757
758   static MDCompileUnit *
759   getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
760           StringRef Producer, bool IsOptimized, StringRef Flags,
761           unsigned RuntimeVersion, StringRef SplitDebugFilename,
762           unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
763           Metadata *Subprograms, Metadata *GlobalVariables,
764           Metadata *ImportedEntities, StorageType Storage,
765           bool ShouldCreate = true) {
766     return getImpl(Context, SourceLanguage, File,
767                    getCanonicalMDString(Context, Producer), IsOptimized,
768                    getCanonicalMDString(Context, Flags), RuntimeVersion,
769                    getCanonicalMDString(Context, SplitDebugFilename),
770                    EmissionKind, EnumTypes, RetainedTypes, Subprograms,
771                    GlobalVariables, ImportedEntities, Storage, ShouldCreate);
772   }
773   static MDCompileUnit *
774   getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
775           MDString *Producer, bool IsOptimized, MDString *Flags,
776           unsigned RuntimeVersion, MDString *SplitDebugFilename,
777           unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
778           Metadata *Subprograms, Metadata *GlobalVariables,
779           Metadata *ImportedEntities, StorageType Storage,
780           bool ShouldCreate = true);
781
782   TempMDCompileUnit cloneImpl() const {
783     return getTemporary(
784         getContext(), getSourceLanguage(), getFile(), getProducer(),
785         isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
786         getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
787         getGlobalVariables(), getImportedEntities());
788   }
789
790 public:
791   DEFINE_MDNODE_GET(MDCompileUnit,
792                     (unsigned SourceLanguage, Metadata *File,
793                      StringRef Producer, bool IsOptimized, StringRef Flags,
794                      unsigned RuntimeVersion, StringRef SplitDebugFilename,
795                      unsigned EmissionKind, Metadata *EnumTypes,
796                      Metadata *RetainedTypes, Metadata *Subprograms,
797                      Metadata *GlobalVariables, Metadata *ImportedEntities),
798                     (SourceLanguage, File, Producer, IsOptimized, Flags,
799                      RuntimeVersion, SplitDebugFilename, EmissionKind,
800                      EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
801                      ImportedEntities))
802   DEFINE_MDNODE_GET(MDCompileUnit,
803                     (unsigned SourceLanguage, Metadata *File,
804                      MDString *Producer, bool IsOptimized, MDString *Flags,
805                      unsigned RuntimeVersion, MDString *SplitDebugFilename,
806                      unsigned EmissionKind, Metadata *EnumTypes,
807                      Metadata *RetainedTypes, Metadata *Subprograms,
808                      Metadata *GlobalVariables, Metadata *ImportedEntities),
809                     (SourceLanguage, File, Producer, IsOptimized, Flags,
810                      RuntimeVersion, SplitDebugFilename, EmissionKind,
811                      EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
812                      ImportedEntities))
813
814   TempMDCompileUnit clone() const { return cloneImpl(); }
815
816   unsigned getSourceLanguage() const { return SourceLanguage; }
817   bool isOptimized() const { return IsOptimized; }
818   unsigned getRuntimeVersion() const { return RuntimeVersion; }
819   unsigned getEmissionKind() const { return EmissionKind; }
820   StringRef getProducer() const { return getStringOperand(1); }
821   StringRef getFlags() const { return getStringOperand(2); }
822   StringRef getSplitDebugFilename() const { return getStringOperand(3); }
823   Metadata *getEnumTypes() const { return getOperand(4); }
824   Metadata *getRetainedTypes() const { return getOperand(5); }
825   Metadata *getSubprograms() const { return getOperand(6); }
826   Metadata *getGlobalVariables() const { return getOperand(7); }
827   Metadata *getImportedEntities() const { return getOperand(8); }
828
829   MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
830   MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
831   MDString *getRawSplitDebugFilename() const {
832     return getOperandAs<MDString>(3);
833   }
834
835   /// \brief Replace arrays.
836   ///
837   /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
838   /// deleted on a uniquing collision.  In practice, uniquing collisions on \a
839   /// MDCompileUnit should be fairly rare.
840   /// @{
841   void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
842   void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
843   /// @}
844
845   static bool classof(const Metadata *MD) {
846     return MD->getMetadataID() == MDCompileUnitKind;
847   }
848 };
849
850 /// \brief A scope for locals.
851 ///
852 /// A legal scope for lexical blocks, local variables, and debug info
853 /// locations.  Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
854 /// MDLexicalBlockFile.
855 class MDLocalScope : public MDScope {
856 protected:
857   MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
858                ArrayRef<Metadata *> Ops)
859       : MDScope(C, ID, Storage, Tag, Ops) {}
860   ~MDLocalScope() {}
861
862 public:
863   static bool classof(const Metadata *MD) {
864     return MD->getMetadataID() == MDSubprogramKind ||
865            MD->getMetadataID() == MDLexicalBlockKind ||
866            MD->getMetadataID() == MDLexicalBlockFileKind;
867   }
868 };
869
870 /// \brief Debug location.
871 ///
872 /// A debug location in source code, used for debug info and otherwise.
873 class MDLocation : public MDNode {
874   friend class LLVMContextImpl;
875   friend class MDNode;
876
877   MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
878              unsigned Column, ArrayRef<Metadata *> MDs);
879   ~MDLocation() { dropAllReferences(); }
880
881   static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
882                              unsigned Column, Metadata *Scope,
883                              Metadata *InlinedAt, StorageType Storage,
884                              bool ShouldCreate = true);
885
886   TempMDLocation cloneImpl() const {
887     return getTemporary(getContext(), getLine(), getColumn(), getScope(),
888                         getInlinedAt());
889   }
890
891   // Disallow replacing operands.
892   void replaceOperandWith(unsigned I, Metadata *New) = delete;
893
894 public:
895   DEFINE_MDNODE_GET(MDLocation,
896                     (unsigned Line, unsigned Column, Metadata *Scope,
897                      Metadata *InlinedAt = nullptr),
898                     (Line, Column, Scope, InlinedAt))
899
900   /// \brief Return a (temporary) clone of this.
901   TempMDLocation clone() const { return cloneImpl(); }
902
903   unsigned getLine() const { return SubclassData32; }
904   unsigned getColumn() const { return SubclassData16; }
905   Metadata *getScope() const { return getOperand(0); }
906   Metadata *getInlinedAt() const {
907     if (getNumOperands() == 2)
908       return getOperand(1);
909     return nullptr;
910   }
911
912   static bool classof(const Metadata *MD) {
913     return MD->getMetadataID() == MDLocationKind;
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