Verifier: Check accessors of MDLocation
[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   static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
886                              unsigned Column, MDLocalScope *Scope,
887                              MDLocation *InlinedAt, StorageType Storage,
888                              bool ShouldCreate = true) {
889     return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
890                    static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
891   }
892
893   TempMDLocation cloneImpl() const {
894     return getTemporary(getContext(), getLine(), getColumn(), getScope(),
895                         getInlinedAt());
896   }
897
898   // Disallow replacing operands.
899   void replaceOperandWith(unsigned I, Metadata *New) = delete;
900
901 public:
902   DEFINE_MDNODE_GET(MDLocation,
903                     (unsigned Line, unsigned Column, Metadata *Scope,
904                      Metadata *InlinedAt = nullptr),
905                     (Line, Column, Scope, InlinedAt))
906   DEFINE_MDNODE_GET(MDLocation,
907                     (unsigned Line, unsigned Column, MDLocalScope *Scope,
908                      MDLocation *InlinedAt = nullptr),
909                     (Line, Column, Scope, InlinedAt))
910
911   /// \brief Return a (temporary) clone of this.
912   TempMDLocation clone() const { return cloneImpl(); }
913
914   unsigned getLine() const { return SubclassData32; }
915   unsigned getColumn() const { return SubclassData16; }
916   MDLocalScope *getScope() const {
917     return cast_or_null<MDLocalScope>(getRawScope());
918   }
919   MDLocation *getInlinedAt() const {
920     return cast_or_null<MDLocation>(getRawInlinedAt());
921   }
922
923   Metadata *getRawScope() const { return getOperand(0); }
924   Metadata *getRawInlinedAt() const {
925     if (getNumOperands() == 2)
926       return getOperand(1);
927     return nullptr;
928   }
929
930   static bool classof(const Metadata *MD) {
931     return MD->getMetadataID() == MDLocationKind;
932   }
933 };
934
935 /// \brief Subprogram description.
936 ///
937 /// TODO: Remove DisplayName.  It's always equal to Name.
938 /// TODO: Split up flags.
939 class MDSubprogram : public MDLocalScope {
940   friend class LLVMContextImpl;
941   friend class MDNode;
942
943   unsigned Line;
944   unsigned ScopeLine;
945   unsigned Virtuality;
946   unsigned VirtualIndex;
947   unsigned Flags;
948   bool IsLocalToUnit;
949   bool IsDefinition;
950   bool IsOptimized;
951
952   MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
953                unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
954                unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
955                bool IsOptimized, ArrayRef<Metadata *> Ops)
956       : MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
957                      Ops),
958         Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
959         VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
960         IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
961   ~MDSubprogram() {}
962
963   static MDSubprogram *
964   getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
965           StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
966           bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
967           Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
968           unsigned Flags, bool IsOptimized, Metadata *Function,
969           Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
970           StorageType Storage, bool ShouldCreate = true) {
971     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
972                    getCanonicalMDString(Context, LinkageName), File, Line, Type,
973                    IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
974                    Virtuality, VirtualIndex, Flags, IsOptimized, Function,
975                    TemplateParams, Declaration, Variables, Storage,
976                    ShouldCreate);
977   }
978   static MDSubprogram *
979   getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
980           MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
981           bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
982           Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
983           unsigned Flags, bool IsOptimized, Metadata *Function,
984           Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
985           StorageType Storage, bool ShouldCreate = true);
986
987   TempMDSubprogram cloneImpl() const {
988     return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
989                         getFile(), getLine(), getType(), isLocalToUnit(),
990                         isDefinition(), getScopeLine(), getContainingType(),
991                         getVirtuality(), getVirtualIndex(), getFlags(),
992                         isOptimized(), getFunction(), getTemplateParams(),
993                         getDeclaration(), getVariables());
994   }
995
996 public:
997   DEFINE_MDNODE_GET(
998       MDSubprogram,
999       (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
1000        unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1001        unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1002        unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1003        Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1004        Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1005       (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1006        ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1007        Function, TemplateParams, Declaration, Variables))
1008   DEFINE_MDNODE_GET(
1009       MDSubprogram,
1010       (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1011        unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1012        unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1013        unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1014        Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
1015        Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1016       (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1017        ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1018        Function, TemplateParams, Declaration, Variables))
1019
1020   TempMDSubprogram clone() const { return cloneImpl(); }
1021
1022 public:
1023   unsigned getLine() const { return Line; }
1024   unsigned getVirtuality() const { return Virtuality; }
1025   unsigned getVirtualIndex() const { return VirtualIndex; }
1026   unsigned getScopeLine() const { return ScopeLine; }
1027   unsigned getFlags() const { return Flags; }
1028   bool isLocalToUnit() const { return IsLocalToUnit; }
1029   bool isDefinition() const { return IsDefinition; }
1030   bool isOptimized() const { return IsOptimized; }
1031
1032   Metadata *getScope() const { return getOperand(1); }
1033
1034   StringRef getName() const { return getStringOperand(2); }
1035   StringRef getDisplayName() const { return getStringOperand(3); }
1036   StringRef getLinkageName() const { return getStringOperand(4); }
1037
1038   MDString *getRawName() const { return getOperandAs<MDString>(2); }
1039   MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
1040
1041   Metadata *getType() const { return getOperand(5); }
1042   Metadata *getContainingType() const { return getOperand(6); }
1043
1044   Metadata *getFunction() const { return getOperand(7); }
1045   Metadata *getTemplateParams() const { return getOperand(8); }
1046   Metadata *getDeclaration() const { return getOperand(9); }
1047   Metadata *getVariables() const { return getOperand(10); }
1048
1049   /// \brief Replace the function.
1050   ///
1051   /// If \a isUniqued() and not \a isResolved(), this could node will be
1052   /// RAUW'ed and deleted out from under the caller.  Use a \a TrackingMDRef if
1053   /// that's a problem.
1054   /// @{
1055   void replaceFunction(Function *F);
1056   void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1057   void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1058   /// @}
1059
1060   static bool classof(const Metadata *MD) {
1061     return MD->getMetadataID() == MDSubprogramKind;
1062   }
1063 };
1064
1065 class MDLexicalBlockBase : public MDLocalScope {
1066 protected:
1067   MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1068                      ArrayRef<Metadata *> Ops)
1069       : MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1070   ~MDLexicalBlockBase() {}
1071
1072 public:
1073   Metadata *getScope() const { return getOperand(1); }
1074
1075   static bool classof(const Metadata *MD) {
1076     return MD->getMetadataID() == MDLexicalBlockKind ||
1077            MD->getMetadataID() == MDLexicalBlockFileKind;
1078   }
1079 };
1080
1081 class MDLexicalBlock : public MDLexicalBlockBase {
1082   friend class LLVMContextImpl;
1083   friend class MDNode;
1084
1085   unsigned Line;
1086   unsigned Column;
1087
1088   MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1089                  unsigned Column, ArrayRef<Metadata *> Ops)
1090       : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1091         Column(Column) {}
1092   ~MDLexicalBlock() {}
1093
1094   static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1095                                  Metadata *File, unsigned Line, unsigned Column,
1096                                  StorageType Storage, bool ShouldCreate = true);
1097
1098   TempMDLexicalBlock cloneImpl() const {
1099     return getTemporary(getContext(), getScope(), getFile(), getLine(),
1100                         getColumn());
1101   }
1102
1103 public:
1104   DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1105                                      unsigned Line, unsigned Column),
1106                     (Scope, File, Line, Column))
1107
1108   TempMDLexicalBlock clone() const { return cloneImpl(); }
1109
1110   unsigned getLine() const { return Line; }
1111   unsigned getColumn() const { return Column; }
1112
1113   static bool classof(const Metadata *MD) {
1114     return MD->getMetadataID() == MDLexicalBlockKind;
1115   }
1116 };
1117
1118 class MDLexicalBlockFile : public MDLexicalBlockBase {
1119   friend class LLVMContextImpl;
1120   friend class MDNode;
1121
1122   unsigned Discriminator;
1123
1124   MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1125                      unsigned Discriminator, ArrayRef<Metadata *> Ops)
1126       : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1127         Discriminator(Discriminator) {}
1128   ~MDLexicalBlockFile() {}
1129
1130   static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1131                                      Metadata *File, unsigned Discriminator,
1132                                      StorageType Storage,
1133                                      bool ShouldCreate = true);
1134
1135   TempMDLexicalBlockFile cloneImpl() const {
1136     return getTemporary(getContext(), getScope(), getFile(),
1137                         getDiscriminator());
1138   }
1139
1140 public:
1141   DEFINE_MDNODE_GET(MDLexicalBlockFile,
1142                     (Metadata * Scope, Metadata *File, unsigned Discriminator),
1143                     (Scope, File, Discriminator))
1144
1145   TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1146
1147   unsigned getDiscriminator() const { return Discriminator; }
1148
1149   static bool classof(const Metadata *MD) {
1150     return MD->getMetadataID() == MDLexicalBlockFileKind;
1151   }
1152 };
1153
1154 class MDNamespace : public MDScope {
1155   friend class LLVMContextImpl;
1156   friend class MDNode;
1157
1158   unsigned Line;
1159
1160   MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1161               ArrayRef<Metadata *> Ops)
1162       : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1163                 Ops),
1164         Line(Line) {}
1165   ~MDNamespace() {}
1166
1167   static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1168                               Metadata *File, StringRef Name, unsigned Line,
1169                               StorageType Storage, bool ShouldCreate = true) {
1170     return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1171                    Line, Storage, ShouldCreate);
1172   }
1173   static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1174                               Metadata *File, MDString *Name, unsigned Line,
1175                               StorageType Storage, bool ShouldCreate = true);
1176
1177   TempMDNamespace cloneImpl() const {
1178     return getTemporary(getContext(), getScope(), getFile(), getName(),
1179                         getLine());
1180   }
1181
1182 public:
1183   DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1184                                   StringRef Name, unsigned Line),
1185                     (Scope, File, Name, Line))
1186   DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1187                                   MDString *Name, unsigned Line),
1188                     (Scope, File, Name, Line))
1189
1190   TempMDNamespace clone() const { return cloneImpl(); }
1191
1192   unsigned getLine() const { return Line; }
1193   Metadata *getScope() const { return getOperand(1); }
1194   StringRef getName() const { return getStringOperand(2); }
1195
1196   MDString *getRawName() const { return getOperandAs<MDString>(2); }
1197
1198   static bool classof(const Metadata *MD) {
1199     return MD->getMetadataID() == MDNamespaceKind;
1200   }
1201 };
1202
1203 /// \brief Base class for template parameters.
1204 class MDTemplateParameter : public DebugNode {
1205 protected:
1206   MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1207                       unsigned Tag, ArrayRef<Metadata *> Ops)
1208       : DebugNode(Context, ID, Storage, Tag, Ops) {}
1209   ~MDTemplateParameter() {}
1210
1211 public:
1212   StringRef getName() const { return getStringOperand(0); }
1213   Metadata *getType() const { return getOperand(1); }
1214
1215   MDString *getRawName() const { return getOperandAs<MDString>(0); }
1216
1217   static bool classof(const Metadata *MD) {
1218     return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1219            MD->getMetadataID() == MDTemplateValueParameterKind;
1220   }
1221 };
1222
1223 class MDTemplateTypeParameter : public MDTemplateParameter {
1224   friend class LLVMContextImpl;
1225   friend class MDNode;
1226
1227   MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1228                           ArrayRef<Metadata *> Ops)
1229       : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1230                             dwarf::DW_TAG_template_type_parameter, Ops) {}
1231   ~MDTemplateTypeParameter() {}
1232
1233   static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1234                                           Metadata *Type, StorageType Storage,
1235                                           bool ShouldCreate = true) {
1236     return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1237                    ShouldCreate);
1238   }
1239   static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1240                                           Metadata *Type, StorageType Storage,
1241                                           bool ShouldCreate = true);
1242
1243   TempMDTemplateTypeParameter cloneImpl() const {
1244     return getTemporary(getContext(), getName(), getType());
1245   }
1246
1247 public:
1248   DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1249                     (Name, Type))
1250   DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1251                     (Name, Type))
1252
1253   TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1254
1255   static bool classof(const Metadata *MD) {
1256     return MD->getMetadataID() == MDTemplateTypeParameterKind;
1257   }
1258 };
1259
1260 class MDTemplateValueParameter : public MDTemplateParameter {
1261   friend class LLVMContextImpl;
1262   friend class MDNode;
1263
1264   MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1265                            unsigned Tag, ArrayRef<Metadata *> Ops)
1266       : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1267                             Ops) {}
1268   ~MDTemplateValueParameter() {}
1269
1270   static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1271                                            StringRef Name, Metadata *Type,
1272                                            Metadata *Value, StorageType Storage,
1273                                            bool ShouldCreate = true) {
1274     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1275                    Value, Storage, ShouldCreate);
1276   }
1277   static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1278                                            MDString *Name, Metadata *Type,
1279                                            Metadata *Value, StorageType Storage,
1280                                            bool ShouldCreate = true);
1281
1282   TempMDTemplateValueParameter cloneImpl() const {
1283     return getTemporary(getContext(), getTag(), getName(), getType(),
1284                         getValue());
1285   }
1286
1287 public:
1288   DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1289                                                Metadata *Type, Metadata *Value),
1290                     (Tag, Name, Type, Value))
1291   DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1292                                                Metadata *Type, Metadata *Value),
1293                     (Tag, Name, Type, Value))
1294
1295   TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1296
1297   Metadata *getValue() const { return getOperand(2); }
1298
1299   static bool classof(const Metadata *MD) {
1300     return MD->getMetadataID() == MDTemplateValueParameterKind;
1301   }
1302 };
1303
1304 /// \brief Base class for variables.
1305 ///
1306 /// TODO: Hardcode to DW_TAG_variable.
1307 class MDVariable : public DebugNode {
1308   unsigned Line;
1309
1310 protected:
1311   MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1312              unsigned Line, ArrayRef<Metadata *> Ops)
1313       : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1314   ~MDVariable() {}
1315
1316 public:
1317   unsigned getLine() const { return Line; }
1318   Metadata *getScope() const { return getOperand(0); }
1319   StringRef getName() const { return getStringOperand(1); }
1320   Metadata *getFile() const { return getOperand(2); }
1321   Metadata *getType() const { return getOperand(3); }
1322
1323   MDString *getRawName() const { return getOperandAs<MDString>(1); }
1324
1325   static bool classof(const Metadata *MD) {
1326     return MD->getMetadataID() == MDLocalVariableKind ||
1327            MD->getMetadataID() == MDGlobalVariableKind;
1328   }
1329 };
1330
1331 /// \brief Global variables.
1332 ///
1333 /// TODO: Remove DisplayName.  It's always equal to Name.
1334 class MDGlobalVariable : public MDVariable {
1335   friend class LLVMContextImpl;
1336   friend class MDNode;
1337
1338   bool IsLocalToUnit;
1339   bool IsDefinition;
1340
1341   MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1342                    bool IsLocalToUnit, bool IsDefinition,
1343                    ArrayRef<Metadata *> Ops)
1344       : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1345                    Line, Ops),
1346         IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1347   ~MDGlobalVariable() {}
1348
1349   static MDGlobalVariable *
1350   getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1351           StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1352           bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1353           Metadata *StaticDataMemberDeclaration, StorageType Storage,
1354           bool ShouldCreate = true) {
1355     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1356                    getCanonicalMDString(Context, LinkageName), File, Line, Type,
1357                    IsLocalToUnit, IsDefinition, Variable,
1358                    StaticDataMemberDeclaration, Storage, ShouldCreate);
1359   }
1360   static MDGlobalVariable *
1361   getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1362           MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1363           bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1364           Metadata *StaticDataMemberDeclaration, StorageType Storage,
1365           bool ShouldCreate = true);
1366
1367   TempMDGlobalVariable cloneImpl() const {
1368     return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1369                         getFile(), getLine(), getType(), isLocalToUnit(),
1370                         isDefinition(), getVariable(),
1371                         getStaticDataMemberDeclaration());
1372   }
1373
1374 public:
1375   DEFINE_MDNODE_GET(MDGlobalVariable,
1376                     (Metadata * Scope, StringRef Name, StringRef LinkageName,
1377                      Metadata *File, unsigned Line, Metadata *Type,
1378                      bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1379                      Metadata *StaticDataMemberDeclaration),
1380                     (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1381                      IsDefinition, Variable, StaticDataMemberDeclaration))
1382   DEFINE_MDNODE_GET(MDGlobalVariable,
1383                     (Metadata * Scope, MDString *Name, MDString *LinkageName,
1384                      Metadata *File, unsigned Line, Metadata *Type,
1385                      bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1386                      Metadata *StaticDataMemberDeclaration),
1387                     (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1388                      IsDefinition, Variable, StaticDataMemberDeclaration))
1389
1390   TempMDGlobalVariable clone() const { return cloneImpl(); }
1391
1392   bool isLocalToUnit() const { return IsLocalToUnit; }
1393   bool isDefinition() const { return IsDefinition; }
1394   StringRef getDisplayName() const { return getStringOperand(4); }
1395   StringRef getLinkageName() const { return getStringOperand(5); }
1396   Metadata *getVariable() const { return getOperand(6); }
1397   Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1398
1399   MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1400
1401   static bool classof(const Metadata *MD) {
1402     return MD->getMetadataID() == MDGlobalVariableKind;
1403   }
1404 };
1405
1406 /// \brief Local variable.
1407 ///
1408 /// TODO: Split between arguments and otherwise.
1409 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1410 /// TODO: Split up flags.
1411 class MDLocalVariable : public MDVariable {
1412   friend class LLVMContextImpl;
1413   friend class MDNode;
1414
1415   unsigned Arg;
1416   unsigned Flags;
1417
1418   MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1419                   unsigned Line, unsigned Arg, unsigned Flags,
1420                   ArrayRef<Metadata *> Ops)
1421       : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1422         Flags(Flags) {}
1423   ~MDLocalVariable() {}
1424
1425   static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1426                                   Metadata *Scope, StringRef Name,
1427                                   Metadata *File, unsigned Line, Metadata *Type,
1428                                   unsigned Arg, unsigned Flags,
1429                                   Metadata *InlinedAt, StorageType Storage,
1430                                   bool ShouldCreate = true) {
1431     return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1432                    File, Line, Type, Arg, Flags, InlinedAt, Storage,
1433                    ShouldCreate);
1434   }
1435   static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1436                                   Metadata *Scope, MDString *Name,
1437                                   Metadata *File, unsigned Line, Metadata *Type,
1438                                   unsigned Arg, unsigned Flags,
1439                                   Metadata *InlinedAt, StorageType Storage,
1440                                   bool ShouldCreate = true);
1441
1442   TempMDLocalVariable cloneImpl() const {
1443     return getTemporary(getContext(), getTag(), getScope(), getName(),
1444                         getFile(), getLine(), getType(), getArg(), getFlags(),
1445                         getInlinedAt());
1446   }
1447
1448 public:
1449   DEFINE_MDNODE_GET(MDLocalVariable,
1450                     (unsigned Tag, Metadata *Scope, StringRef Name,
1451                      Metadata *File, unsigned Line, Metadata *Type,
1452                      unsigned Arg, unsigned Flags,
1453                      Metadata *InlinedAt = nullptr),
1454                     (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1455   DEFINE_MDNODE_GET(MDLocalVariable,
1456                     (unsigned Tag, Metadata *Scope, MDString *Name,
1457                      Metadata *File, unsigned Line, Metadata *Type,
1458                      unsigned Arg, unsigned Flags,
1459                      Metadata *InlinedAt = nullptr),
1460                     (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1461
1462   TempMDLocalVariable clone() const { return cloneImpl(); }
1463
1464   unsigned getArg() const { return Arg; }
1465   unsigned getFlags() const { return Flags; }
1466   Metadata *getInlinedAt() const { return getOperand(4); }
1467
1468   /// \brief Get an inlined version of this variable.
1469   ///
1470   /// Returns a version of this with \a getAlinedAt() set to \c InlinedAt.
1471   MDLocalVariable *withInline(MDLocation *InlinedAt) const {
1472     if (InlinedAt == getInlinedAt())
1473       return const_cast<MDLocalVariable *>(this);
1474     auto Temp = clone();
1475     Temp->replaceOperandWith(4, InlinedAt);
1476     return replaceWithUniqued(std::move(Temp));
1477   }
1478   MDLocalVariable *withoutInline() const { return withInline(nullptr); }
1479
1480   static bool classof(const Metadata *MD) {
1481     return MD->getMetadataID() == MDLocalVariableKind;
1482   }
1483 };
1484
1485 /// \brief DWARF expression.
1486 ///
1487 /// TODO: Co-allocate the expression elements.
1488 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1489 /// storage types.
1490 class MDExpression : public MDNode {
1491   friend class LLVMContextImpl;
1492   friend class MDNode;
1493
1494   std::vector<uint64_t> Elements;
1495
1496   MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1497       : MDNode(C, MDExpressionKind, Storage, None),
1498         Elements(Elements.begin(), Elements.end()) {}
1499   ~MDExpression() {}
1500
1501   static MDExpression *getImpl(LLVMContext &Context,
1502                                ArrayRef<uint64_t> Elements, StorageType Storage,
1503                                bool ShouldCreate = true);
1504
1505   TempMDExpression cloneImpl() const {
1506     return getTemporary(getContext(), getElements());
1507   }
1508
1509 public:
1510   DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1511
1512   TempMDExpression clone() const { return cloneImpl(); }
1513
1514   ArrayRef<uint64_t> getElements() const { return Elements; }
1515
1516   unsigned getNumElements() const { return Elements.size(); }
1517   uint64_t getElement(unsigned I) const {
1518     assert(I < Elements.size() && "Index out of range");
1519     return Elements[I];
1520   }
1521
1522   typedef ArrayRef<uint64_t>::iterator element_iterator;
1523   element_iterator elements_begin() const { return getElements().begin(); }
1524   element_iterator elements_end() const { return getElements().end(); }
1525
1526   /// \brief A lightweight wrapper around an expression operand.
1527   ///
1528   /// TODO: Store arguments directly and change \a MDExpression to store a
1529   /// range of these.
1530   class ExprOperand {
1531     const uint64_t *Op;
1532
1533   public:
1534     explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1535
1536     const uint64_t *get() const { return Op; }
1537
1538     /// \brief Get the operand code.
1539     uint64_t getOp() const { return *Op; }
1540
1541     /// \brief Get an argument to the operand.
1542     ///
1543     /// Never returns the operand itself.
1544     uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1545
1546     unsigned getNumArgs() const { return getSize() - 1; }
1547
1548     /// \brief Return the size of the operand.
1549     ///
1550     /// Return the number of elements in the operand (1 + args).
1551     unsigned getSize() const;
1552   };
1553
1554   /// \brief An iterator for expression operands.
1555   class expr_op_iterator
1556       : public std::iterator<std::input_iterator_tag, ExprOperand> {
1557     ExprOperand Op;
1558
1559   public:
1560     explicit expr_op_iterator(element_iterator I) : Op(I) {}
1561
1562     element_iterator getBase() const { return Op.get(); }
1563     const ExprOperand &operator*() const { return Op; }
1564     const ExprOperand *operator->() const { return &Op; }
1565
1566     expr_op_iterator &operator++() {
1567       increment();
1568       return *this;
1569     }
1570     expr_op_iterator operator++(int) {
1571       expr_op_iterator T(*this);
1572       increment();
1573       return T;
1574     }
1575
1576     bool operator==(const expr_op_iterator &X) const {
1577       return getBase() == X.getBase();
1578     }
1579     bool operator!=(const expr_op_iterator &X) const {
1580       return getBase() != X.getBase();
1581     }
1582
1583   private:
1584     void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1585   };
1586
1587   /// \brief Visit the elements via ExprOperand wrappers.
1588   ///
1589   /// These range iterators visit elements through \a ExprOperand wrappers.
1590   /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1591   /// true.
1592   ///
1593   /// \pre \a isValid() gives \c true.
1594   /// @{
1595   expr_op_iterator expr_op_begin() const {
1596     return expr_op_iterator(elements_begin());
1597   }
1598   expr_op_iterator expr_op_end() const {
1599     return expr_op_iterator(elements_end());
1600   }
1601   /// @}
1602
1603   bool isValid() const;
1604
1605   static bool classof(const Metadata *MD) {
1606     return MD->getMetadataID() == MDExpressionKind;
1607   }
1608 };
1609
1610 class MDObjCProperty : public DebugNode {
1611   friend class LLVMContextImpl;
1612   friend class MDNode;
1613
1614   unsigned Line;
1615   unsigned Attributes;
1616
1617   MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1618                  unsigned Attributes, ArrayRef<Metadata *> Ops)
1619       : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1620                   Ops),
1621         Line(Line), Attributes(Attributes) {}
1622   ~MDObjCProperty() {}
1623
1624   static MDObjCProperty *
1625   getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1626           StringRef GetterName, StringRef SetterName, unsigned Attributes,
1627           Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1628     return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1629                    getCanonicalMDString(Context, GetterName),
1630                    getCanonicalMDString(Context, SetterName), Attributes, Type,
1631                    Storage, ShouldCreate);
1632   }
1633   static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1634                                  Metadata *File, unsigned Line,
1635                                  MDString *GetterName, MDString *SetterName,
1636                                  unsigned Attributes, Metadata *Type,
1637                                  StorageType Storage, bool ShouldCreate = true);
1638
1639   TempMDObjCProperty cloneImpl() const {
1640     return getTemporary(getContext(), getName(), getFile(), getLine(),
1641                         getGetterName(), getSetterName(), getAttributes(),
1642                         getType());
1643   }
1644
1645 public:
1646   DEFINE_MDNODE_GET(MDObjCProperty,
1647                     (StringRef Name, Metadata *File, unsigned Line,
1648                      StringRef GetterName, StringRef SetterName,
1649                      unsigned Attributes, Metadata *Type),
1650                     (Name, File, Line, GetterName, SetterName, Attributes,
1651                      Type))
1652   DEFINE_MDNODE_GET(MDObjCProperty,
1653                     (MDString * Name, Metadata *File, unsigned Line,
1654                      MDString *GetterName, MDString *SetterName,
1655                      unsigned Attributes, Metadata *Type),
1656                     (Name, File, Line, GetterName, SetterName, Attributes,
1657                      Type))
1658
1659   TempMDObjCProperty clone() const { return cloneImpl(); }
1660
1661   unsigned getLine() const { return Line; }
1662   unsigned getAttributes() const { return Attributes; }
1663   StringRef getName() const { return getStringOperand(0); }
1664   Metadata *getFile() const { return getOperand(1); }
1665   StringRef getGetterName() const { return getStringOperand(2); }
1666   StringRef getSetterName() const { return getStringOperand(3); }
1667   Metadata *getType() const { return getOperand(4); }
1668
1669   MDString *getRawName() const { return getOperandAs<MDString>(0); }
1670   MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1671   MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1672
1673   static bool classof(const Metadata *MD) {
1674     return MD->getMetadataID() == MDObjCPropertyKind;
1675   }
1676 };
1677
1678 class MDImportedEntity : public DebugNode {
1679   friend class LLVMContextImpl;
1680   friend class MDNode;
1681
1682   unsigned Line;
1683
1684   MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1685                    unsigned Line, ArrayRef<Metadata *> Ops)
1686       : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1687   ~MDImportedEntity() {}
1688
1689   static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1690                                    Metadata *Scope, Metadata *Entity,
1691                                    unsigned Line, StringRef Name,
1692                                    StorageType Storage,
1693                                    bool ShouldCreate = true) {
1694     return getImpl(Context, Tag, Scope, Entity, Line,
1695                    getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1696   }
1697   static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1698                                    Metadata *Scope, Metadata *Entity,
1699                                    unsigned Line, MDString *Name,
1700                                    StorageType Storage,
1701                                    bool ShouldCreate = true);
1702
1703   TempMDImportedEntity cloneImpl() const {
1704     return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1705                         getLine(), getName());
1706   }
1707
1708 public:
1709   DEFINE_MDNODE_GET(MDImportedEntity,
1710                     (unsigned Tag, Metadata *Scope, Metadata *Entity,
1711                      unsigned Line, StringRef Name = ""),
1712                     (Tag, Scope, Entity, Line, Name))
1713   DEFINE_MDNODE_GET(MDImportedEntity,
1714                     (unsigned Tag, Metadata *Scope, Metadata *Entity,
1715                      unsigned Line, MDString *Name),
1716                     (Tag, Scope, Entity, Line, Name))
1717
1718   TempMDImportedEntity clone() const { return cloneImpl(); }
1719
1720   unsigned getLine() const { return Line; }
1721   Metadata *getScope() const { return getOperand(0); }
1722   Metadata *getEntity() const { return getOperand(1); }
1723   StringRef getName() const { return getStringOperand(2); }
1724
1725   MDString *getRawName() const { return getOperandAs<MDString>(2); }
1726
1727   static bool classof(const Metadata *MD) {
1728     return MD->getMetadataID() == MDImportedEntityKind;
1729   }
1730 };
1731
1732 } // end namespace llvm
1733
1734 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1735 #undef DEFINE_MDNODE_GET_UNPACK
1736 #undef DEFINE_MDNODE_GET
1737
1738 #endif