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