Fix buildbot issues for MDScope::getFile() after r230871
[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)
341                              : static_cast<Metadata *>(getOperand(0));
342   }
343
344   static bool classof(const Metadata *MD) {
345     switch (MD->getMetadataID()) {
346     default:
347       return false;
348     case MDBasicTypeKind:
349     case MDDerivedTypeKind:
350     case MDCompositeTypeKind:
351     case MDSubroutineTypeKind:
352     case MDFileKind:
353     case MDCompileUnitKind:
354     case MDSubprogramKind:
355     case MDLexicalBlockKind:
356     case MDLexicalBlockFileKind:
357     case MDNamespaceKind:
358       return true;
359     }
360   }
361 };
362
363 /// \brief Base class for types.
364 ///
365 /// TODO: Remove the hardcoded name and context, since many types don't use
366 /// them.
367 /// TODO: Split up flags.
368 class MDType : public MDScope {
369   unsigned Line;
370   unsigned Flags;
371   uint64_t SizeInBits;
372   uint64_t AlignInBits;
373   uint64_t OffsetInBits;
374
375 protected:
376   MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
377          unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
378          uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
379       : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
380         SizeInBits(SizeInBits), AlignInBits(AlignInBits),
381         OffsetInBits(OffsetInBits) {}
382   ~MDType() {}
383
384 public:
385   unsigned getLine() const { return Line; }
386   uint64_t getSizeInBits() const { return SizeInBits; }
387   uint64_t getAlignInBits() const { return AlignInBits; }
388   uint64_t getOffsetInBits() const { return OffsetInBits; }
389   unsigned getFlags() const { return Flags; }
390
391   Metadata *getScope() const { return getOperand(1); }
392   StringRef getName() const { return getStringOperand(2); }
393
394   MDString *getRawName() const { return getOperandAs<MDString>(2); }
395
396   static bool classof(const Metadata *MD) {
397     switch (MD->getMetadataID()) {
398     default:
399       return false;
400     case MDBasicTypeKind:
401     case MDDerivedTypeKind:
402     case MDCompositeTypeKind:
403     case MDSubroutineTypeKind:
404       return true;
405     }
406   }
407 };
408
409 /// \brief Basic type.
410 ///
411 /// TODO: Split out DW_TAG_unspecified_type.
412 /// TODO: Drop unused accessors.
413 class MDBasicType : public MDType {
414   friend class LLVMContextImpl;
415   friend class MDNode;
416
417   unsigned Encoding;
418
419   MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
420               uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
421               ArrayRef<Metadata *> Ops)
422       : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
423                0, Ops),
424         Encoding(Encoding) {}
425   ~MDBasicType() {}
426
427   static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
428                               StringRef Name, uint64_t SizeInBits,
429                               uint64_t AlignInBits, unsigned Encoding,
430                               StorageType Storage, bool ShouldCreate = true) {
431     return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
432                    SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
433   }
434   static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
435                               MDString *Name, uint64_t SizeInBits,
436                               uint64_t AlignInBits, unsigned Encoding,
437                               StorageType Storage, bool ShouldCreate = true);
438
439   TempMDBasicType cloneImpl() const {
440     return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
441                         getAlignInBits(), getEncoding());
442   }
443
444 public:
445   DEFINE_MDNODE_GET(MDBasicType,
446                     (unsigned Tag, StringRef Name, uint64_t SizeInBits,
447                      uint64_t AlignInBits, unsigned Encoding),
448                     (Tag, Name, SizeInBits, AlignInBits, Encoding))
449   DEFINE_MDNODE_GET(MDBasicType,
450                     (unsigned Tag, MDString *Name, uint64_t SizeInBits,
451                      uint64_t AlignInBits, unsigned Encoding),
452                     (Tag, Name, SizeInBits, AlignInBits, Encoding))
453
454   TempMDBasicType clone() const { return cloneImpl(); }
455
456   unsigned getEncoding() const { return Encoding; }
457
458   static bool classof(const Metadata *MD) {
459     return MD->getMetadataID() == MDBasicTypeKind;
460   }
461 };
462
463 /// \brief Base class for MDDerivedType and MDCompositeType.
464 ///
465 /// TODO: Delete; they're not really related.
466 class MDDerivedTypeBase : public MDType {
467 protected:
468   MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
469                     unsigned Tag, unsigned Line, uint64_t SizeInBits,
470                     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
471                     ArrayRef<Metadata *> Ops)
472       : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
473                Flags, Ops) {}
474   ~MDDerivedTypeBase() {}
475
476 public:
477   Metadata *getBaseType() const { return getOperand(3); }
478
479   static bool classof(const Metadata *MD) {
480     return MD->getMetadataID() == MDDerivedTypeKind ||
481            MD->getMetadataID() == MDCompositeTypeKind ||
482            MD->getMetadataID() == MDSubroutineTypeKind;
483   }
484 };
485
486 /// \brief Derived types.
487 ///
488 /// This includes qualified types, pointers, references, friends, typedefs, and
489 /// class members.
490 ///
491 /// TODO: Split out members (inheritance, fields, methods, etc.).
492 class MDDerivedType : public MDDerivedTypeBase {
493   friend class LLVMContextImpl;
494   friend class MDNode;
495
496   MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
497                 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
498                 uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
499       : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
500                           AlignInBits, OffsetInBits, Flags, Ops) {}
501   ~MDDerivedType() {}
502
503   static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
504                                 StringRef Name, Metadata *File, unsigned Line,
505                                 Metadata *Scope, Metadata *BaseType,
506                                 uint64_t SizeInBits, uint64_t AlignInBits,
507                                 uint64_t OffsetInBits, unsigned Flags,
508                                 Metadata *ExtraData, StorageType Storage,
509                                 bool ShouldCreate = true) {
510     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
511                    Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
512                    Flags, ExtraData, Storage, ShouldCreate);
513   }
514   static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
515                                 MDString *Name, Metadata *File, unsigned Line,
516                                 Metadata *Scope, Metadata *BaseType,
517                                 uint64_t SizeInBits, uint64_t AlignInBits,
518                                 uint64_t OffsetInBits, unsigned Flags,
519                                 Metadata *ExtraData, StorageType Storage,
520                                 bool ShouldCreate = true);
521
522   TempMDDerivedType cloneImpl() const {
523     return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
524                         getScope(), getBaseType(), getSizeInBits(),
525                         getAlignInBits(), getOffsetInBits(), getFlags(),
526                         getExtraData());
527   }
528
529 public:
530   DEFINE_MDNODE_GET(MDDerivedType,
531                     (unsigned Tag, MDString *Name, Metadata *File,
532                      unsigned Line, Metadata *Scope, Metadata *BaseType,
533                      uint64_t SizeInBits, uint64_t AlignInBits,
534                      uint64_t OffsetInBits, unsigned Flags,
535                      Metadata *ExtraData = nullptr),
536                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
537                      AlignInBits, OffsetInBits, Flags, ExtraData))
538   DEFINE_MDNODE_GET(MDDerivedType,
539                     (unsigned Tag, StringRef Name, Metadata *File,
540                      unsigned Line, Metadata *Scope, Metadata *BaseType,
541                      uint64_t SizeInBits, uint64_t AlignInBits,
542                      uint64_t OffsetInBits, unsigned Flags,
543                      Metadata *ExtraData = nullptr),
544                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
545                      AlignInBits, OffsetInBits, Flags, ExtraData))
546
547   TempMDDerivedType clone() const { return cloneImpl(); }
548
549   /// \brief Get extra data associated with this derived type.
550   ///
551   /// Class type for pointer-to-members, objective-c property node for ivars,
552   /// or global constant wrapper for static members.
553   ///
554   /// TODO: Separate out types that need this extra operand: pointer-to-member
555   /// types and member fields (static members and ivars).
556   Metadata *getExtraData() const { return getOperand(4); }
557
558   static bool classof(const Metadata *MD) {
559     return MD->getMetadataID() == MDDerivedTypeKind;
560   }
561 };
562
563 /// \brief Base class for MDCompositeType and MDSubroutineType.
564 ///
565 /// TODO: Delete; they're not really related.
566 class MDCompositeTypeBase : public MDDerivedTypeBase {
567   unsigned RuntimeLang;
568
569 protected:
570   MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
571                       unsigned Tag, unsigned Line, unsigned RuntimeLang,
572                       uint64_t SizeInBits, uint64_t AlignInBits,
573                       uint64_t OffsetInBits, unsigned Flags,
574                       ArrayRef<Metadata *> Ops)
575       : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
576                           OffsetInBits, Flags, Ops),
577         RuntimeLang(RuntimeLang) {}
578   ~MDCompositeTypeBase() {}
579
580 public:
581   Metadata *getElements() const { return getOperand(4); }
582   Metadata *getVTableHolder() const { return getOperand(5); }
583   Metadata *getTemplateParams() const { return getOperand(6); }
584   StringRef getIdentifier() const { return getStringOperand(7); }
585   unsigned getRuntimeLang() const { return RuntimeLang; }
586
587   MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
588
589   /// \brief Replace operands.
590   ///
591   /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
592   /// this will be RAUW'ed and deleted.  Use a \a TrackingMDRef to keep track
593   /// of its movement if necessary.
594   /// @{
595   void replaceElements(MDTuple *Elements) {
596 #ifndef NDEBUG
597     if (auto *Old = cast_or_null<MDTuple>(getElements()))
598       for (const auto &Op : Old->operands())
599         assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
600                "Lost a member during member list replacement");
601 #endif
602     replaceOperandWith(4, Elements);
603   }
604   void replaceVTableHolder(Metadata *VTableHolder) {
605     replaceOperandWith(5, VTableHolder);
606   }
607   void replaceTemplateParams(MDTuple *TemplateParams) {
608     replaceOperandWith(6, TemplateParams);
609   }
610   /// @}
611
612   static bool classof(const Metadata *MD) {
613     return MD->getMetadataID() == MDCompositeTypeKind ||
614            MD->getMetadataID() == MDSubroutineTypeKind;
615   }
616 };
617
618 /// \brief Composite types.
619 ///
620 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
621 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
622 class MDCompositeType : public MDCompositeTypeBase {
623   friend class LLVMContextImpl;
624   friend class MDNode;
625
626   MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
627                   unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
628                   uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
629                   ArrayRef<Metadata *> Ops)
630       : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
631                             RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
632                             Flags, Ops) {}
633   ~MDCompositeType() {}
634
635   static MDCompositeType *
636   getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
637           unsigned Line, Metadata *Scope, Metadata *BaseType,
638           uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
639           uint64_t Flags, Metadata *Elements, unsigned RuntimeLang,
640           Metadata *VTableHolder, Metadata *TemplateParams,
641           StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
642     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
643                    Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
644                    Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
645                    getCanonicalMDString(Context, Identifier), Storage,
646                    ShouldCreate);
647   }
648   static MDCompositeType *
649   getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
650           unsigned Line, Metadata *Scope, Metadata *BaseType,
651           uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
652           unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
653           Metadata *VTableHolder, Metadata *TemplateParams,
654           MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
655
656   TempMDCompositeType cloneImpl() const {
657     return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
658                         getScope(), getBaseType(), getSizeInBits(),
659                         getAlignInBits(), getOffsetInBits(), getFlags(),
660                         getElements(), getRuntimeLang(), getVTableHolder(),
661                         getTemplateParams(), getIdentifier());
662   }
663
664 public:
665   DEFINE_MDNODE_GET(MDCompositeType,
666                     (unsigned Tag, StringRef Name, Metadata *File,
667                      unsigned Line, Metadata *Scope, Metadata *BaseType,
668                      uint64_t SizeInBits, uint64_t AlignInBits,
669                      uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
670                      unsigned RuntimeLang, Metadata *VTableHolder,
671                      Metadata *TemplateParams = nullptr,
672                      StringRef Identifier = ""),
673                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
674                      AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
675                      VTableHolder, TemplateParams, Identifier))
676   DEFINE_MDNODE_GET(MDCompositeType,
677                     (unsigned Tag, MDString *Name, Metadata *File,
678                      unsigned Line, Metadata *Scope, Metadata *BaseType,
679                      uint64_t SizeInBits, uint64_t AlignInBits,
680                      uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
681                      unsigned RuntimeLang, Metadata *VTableHolder,
682                      Metadata *TemplateParams = nullptr,
683                      MDString *Identifier = nullptr),
684                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
685                      AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
686                      VTableHolder, TemplateParams, Identifier))
687
688   TempMDCompositeType clone() const { return cloneImpl(); }
689
690   static bool classof(const Metadata *MD) {
691     return MD->getMetadataID() == MDCompositeTypeKind;
692   }
693 };
694
695 /// \brief Type array for a subprogram.
696 ///
697 /// TODO: Detach from CompositeType, and fold the array of types in directly
698 /// as operands.
699 class MDSubroutineType : public MDCompositeTypeBase {
700   friend class LLVMContextImpl;
701   friend class MDNode;
702
703   MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
704                    ArrayRef<Metadata *> Ops)
705       : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
706                             dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
707                             Ops) {}
708   ~MDSubroutineType() {}
709
710   static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
711                                    Metadata *TypeArray, StorageType Storage,
712                                    bool ShouldCreate = true);
713
714   TempMDSubroutineType cloneImpl() const {
715     return getTemporary(getContext(), getFlags(), getTypeArray());
716   }
717
718 public:
719   DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
720                     (Flags, TypeArray))
721
722   TempMDSubroutineType clone() const { return cloneImpl(); }
723
724   Metadata *getTypeArray() const { return getElements(); }
725
726   static bool classof(const Metadata *MD) {
727     return MD->getMetadataID() == MDSubroutineTypeKind;
728   }
729 };
730
731 /// \brief File.
732 ///
733 /// TODO: Merge with directory/file node (including users).
734 /// TODO: Canonicalize paths on creation.
735 class MDFile : public MDScope {
736   friend class LLVMContextImpl;
737   friend class MDNode;
738
739   MDFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
740       : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
741   ~MDFile() {}
742
743   static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
744                          StringRef Directory, StorageType Storage,
745                          bool ShouldCreate = true) {
746     return getImpl(Context, getCanonicalMDString(Context, Filename),
747                    getCanonicalMDString(Context, Directory), Storage,
748                    ShouldCreate);
749   }
750   static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
751                          MDString *Directory, StorageType Storage,
752                          bool ShouldCreate = true);
753
754   TempMDFile cloneImpl() const {
755     return getTemporary(getContext(), getFilename(), getDirectory());
756   }
757
758 public:
759   DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
760                     (Filename, Directory))
761   DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
762                     (Filename, Directory))
763
764   TempMDFile clone() const { return cloneImpl(); }
765
766   StringRef getFilename() const { return getStringOperand(0); }
767   StringRef getDirectory() const { return getStringOperand(1); }
768
769   MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
770   MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
771
772   static bool classof(const Metadata *MD) {
773     return MD->getMetadataID() == MDFileKind;
774   }
775 };
776
777 /// \brief Compile unit.
778 class MDCompileUnit : public MDScope {
779   friend class LLVMContextImpl;
780   friend class MDNode;
781
782   unsigned SourceLanguage;
783   bool IsOptimized;
784   unsigned RuntimeVersion;
785   unsigned EmissionKind;
786
787   MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
788                 bool IsOptimized, unsigned RuntimeVersion,
789                 unsigned EmissionKind, ArrayRef<Metadata *> Ops)
790       : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
791         SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
792         RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
793   ~MDCompileUnit() {}
794
795   static MDCompileUnit *
796   getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
797           StringRef Producer, bool IsOptimized, StringRef Flags,
798           unsigned RuntimeVersion, StringRef SplitDebugFilename,
799           unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
800           Metadata *Subprograms, Metadata *GlobalVariables,
801           Metadata *ImportedEntities, StorageType Storage,
802           bool ShouldCreate = true) {
803     return getImpl(Context, SourceLanguage, File,
804                    getCanonicalMDString(Context, Producer), IsOptimized,
805                    getCanonicalMDString(Context, Flags), RuntimeVersion,
806                    getCanonicalMDString(Context, SplitDebugFilename),
807                    EmissionKind, EnumTypes, RetainedTypes, Subprograms,
808                    GlobalVariables, ImportedEntities, Storage, ShouldCreate);
809   }
810   static MDCompileUnit *
811   getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
812           MDString *Producer, bool IsOptimized, MDString *Flags,
813           unsigned RuntimeVersion, MDString *SplitDebugFilename,
814           unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
815           Metadata *Subprograms, Metadata *GlobalVariables,
816           Metadata *ImportedEntities, StorageType Storage,
817           bool ShouldCreate = true);
818
819   TempMDCompileUnit cloneImpl() const {
820     return getTemporary(
821         getContext(), getSourceLanguage(), getFile(), getProducer(),
822         isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
823         getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
824         getGlobalVariables(), getImportedEntities());
825   }
826
827 public:
828   DEFINE_MDNODE_GET(MDCompileUnit,
829                     (unsigned SourceLanguage, Metadata *File,
830                      StringRef Producer, bool IsOptimized, StringRef Flags,
831                      unsigned RuntimeVersion, StringRef SplitDebugFilename,
832                      unsigned EmissionKind, Metadata *EnumTypes,
833                      Metadata *RetainedTypes, Metadata *Subprograms,
834                      Metadata *GlobalVariables, Metadata *ImportedEntities),
835                     (SourceLanguage, File, Producer, IsOptimized, Flags,
836                      RuntimeVersion, SplitDebugFilename, EmissionKind,
837                      EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
838                      ImportedEntities))
839   DEFINE_MDNODE_GET(MDCompileUnit,
840                     (unsigned SourceLanguage, Metadata *File,
841                      MDString *Producer, bool IsOptimized, MDString *Flags,
842                      unsigned RuntimeVersion, MDString *SplitDebugFilename,
843                      unsigned EmissionKind, Metadata *EnumTypes,
844                      Metadata *RetainedTypes, Metadata *Subprograms,
845                      Metadata *GlobalVariables, Metadata *ImportedEntities),
846                     (SourceLanguage, File, Producer, IsOptimized, Flags,
847                      RuntimeVersion, SplitDebugFilename, EmissionKind,
848                      EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
849                      ImportedEntities))
850
851   TempMDCompileUnit clone() const { return cloneImpl(); }
852
853   unsigned getSourceLanguage() const { return SourceLanguage; }
854   bool isOptimized() const { return IsOptimized; }
855   unsigned getRuntimeVersion() const { return RuntimeVersion; }
856   unsigned getEmissionKind() const { return EmissionKind; }
857   StringRef getProducer() const { return getStringOperand(1); }
858   StringRef getFlags() const { return getStringOperand(2); }
859   StringRef getSplitDebugFilename() const { return getStringOperand(3); }
860   Metadata *getEnumTypes() const { return getOperand(4); }
861   Metadata *getRetainedTypes() const { return getOperand(5); }
862   Metadata *getSubprograms() const { return getOperand(6); }
863   Metadata *getGlobalVariables() const { return getOperand(7); }
864   Metadata *getImportedEntities() const { return getOperand(8); }
865
866   MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
867   MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
868   MDString *getRawSplitDebugFilename() const {
869     return getOperandAs<MDString>(3);
870   }
871
872   /// \brief Replace arrays.
873   ///
874   /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
875   /// deleted on a uniquing collision.  In practice, uniquing collisions on \a
876   /// MDCompileUnit should be fairly rare.
877   /// @{
878   void replaceSubprograms(MDTuple *N) { replaceOperandWith(6, N); }
879   void replaceGlobalVariables(MDTuple *N) { replaceOperandWith(7, N); }
880   /// @}
881
882   static bool classof(const Metadata *MD) {
883     return MD->getMetadataID() == MDCompileUnitKind;
884   }
885 };
886
887 /// \brief Subprogram description.
888 ///
889 /// TODO: Remove DisplayName.  It's always equal to Name.
890 /// TODO: Split up flags.
891 class MDSubprogram : public MDScope {
892   friend class LLVMContextImpl;
893   friend class MDNode;
894
895   unsigned Line;
896   unsigned ScopeLine;
897   unsigned Virtuality;
898   unsigned VirtualIndex;
899   unsigned Flags;
900   bool IsLocalToUnit;
901   bool IsDefinition;
902   bool IsOptimized;
903
904   MDSubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
905                unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
906                unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
907                bool IsOptimized, ArrayRef<Metadata *> Ops)
908       : MDScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
909         Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
910         VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
911         IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
912   ~MDSubprogram() {}
913
914   static MDSubprogram *
915   getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
916           StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
917           bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
918           Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
919           unsigned Flags, bool IsOptimized, Metadata *Function,
920           Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
921           StorageType Storage, bool ShouldCreate = true) {
922     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
923                    getCanonicalMDString(Context, LinkageName), File, Line, Type,
924                    IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
925                    Virtuality, VirtualIndex, Flags, IsOptimized, Function,
926                    TemplateParams, Declaration, Variables, Storage,
927                    ShouldCreate);
928   }
929   static MDSubprogram *
930   getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
931           MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
932           bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
933           Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
934           unsigned Flags, bool IsOptimized, Metadata *Function,
935           Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
936           StorageType Storage, bool ShouldCreate = true);
937
938   TempMDSubprogram cloneImpl() const {
939     return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
940                         getFile(), getLine(), getType(), isLocalToUnit(),
941                         isDefinition(), getScopeLine(), getContainingType(),
942                         getVirtuality(), getVirtualIndex(), getFlags(),
943                         isOptimized(), getFunction(), getTemplateParams(),
944                         getDeclaration(), getVariables());
945   }
946
947 public:
948   DEFINE_MDNODE_GET(
949       MDSubprogram,
950       (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
951        unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
952        unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
953        unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
954        Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
955        Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
956       (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
957        ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
958        Function, TemplateParams, Declaration, Variables))
959   DEFINE_MDNODE_GET(
960       MDSubprogram,
961       (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
962        unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
963        unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
964        unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
965        Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
966        Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
967       (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
968        ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
969        Function, TemplateParams, Declaration, Variables))
970
971   TempMDSubprogram clone() const { return cloneImpl(); }
972
973 public:
974   unsigned getLine() const { return Line; }
975   unsigned getVirtuality() const { return Virtuality; }
976   unsigned getVirtualIndex() const { return VirtualIndex; }
977   unsigned getScopeLine() const { return ScopeLine; }
978   unsigned getFlags() const { return Flags; }
979   bool isLocalToUnit() const { return IsLocalToUnit; }
980   bool isDefinition() const { return IsDefinition; }
981   bool isOptimized() const { return IsOptimized; }
982
983   Metadata *getScope() const { return getOperand(1); }
984
985   StringRef getName() const { return getStringOperand(2); }
986   StringRef getDisplayName() const { return getStringOperand(3); }
987   StringRef getLinkageName() const { return getStringOperand(4); }
988
989   MDString *getRawName() const { return getOperandAs<MDString>(2); }
990   MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
991
992   Metadata *getType() const { return getOperand(5); }
993   Metadata *getContainingType() const { return getOperand(6); }
994
995   Metadata *getFunction() const { return getOperand(7); }
996   Metadata *getTemplateParams() const { return getOperand(8); }
997   Metadata *getDeclaration() const { return getOperand(9); }
998   Metadata *getVariables() const { return getOperand(10); }
999
1000   /// \brief Replace the function.
1001   ///
1002   /// If \a isUniqued() and not \a isResolved(), this could node will be
1003   /// RAUW'ed and deleted out from under the caller.  Use a \a TrackingMDRef if
1004   /// that's a problem.
1005   /// @{
1006   void replaceFunction(Function *F);
1007   void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
1008   void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
1009   /// @}
1010
1011   static bool classof(const Metadata *MD) {
1012     return MD->getMetadataID() == MDSubprogramKind;
1013   }
1014 };
1015
1016 class MDLexicalBlockBase : public MDScope {
1017 protected:
1018   MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1019                      ArrayRef<Metadata *> Ops)
1020       : MDScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1021   ~MDLexicalBlockBase() {}
1022
1023 public:
1024   Metadata *getScope() const { return getOperand(1); }
1025
1026   static bool classof(const Metadata *MD) {
1027     return MD->getMetadataID() == MDLexicalBlockKind ||
1028            MD->getMetadataID() == MDLexicalBlockFileKind;
1029   }
1030 };
1031
1032 class MDLexicalBlock : public MDLexicalBlockBase {
1033   friend class LLVMContextImpl;
1034   friend class MDNode;
1035
1036   unsigned Line;
1037   unsigned Column;
1038
1039   MDLexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1040                  unsigned Column, ArrayRef<Metadata *> Ops)
1041       : MDLexicalBlockBase(C, MDLexicalBlockKind, Storage, Ops), Line(Line),
1042         Column(Column) {}
1043   ~MDLexicalBlock() {}
1044
1045   static MDLexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1046                                  Metadata *File, unsigned Line, unsigned Column,
1047                                  StorageType Storage, bool ShouldCreate = true);
1048
1049   TempMDLexicalBlock cloneImpl() const {
1050     return getTemporary(getContext(), getScope(), getFile(), getLine(),
1051                         getColumn());
1052   }
1053
1054 public:
1055   DEFINE_MDNODE_GET(MDLexicalBlock, (Metadata * Scope, Metadata *File,
1056                                      unsigned Line, unsigned Column),
1057                     (Scope, File, Line, Column))
1058
1059   TempMDLexicalBlock clone() const { return cloneImpl(); }
1060
1061   unsigned getLine() const { return Line; }
1062   unsigned getColumn() const { return Column; }
1063
1064   static bool classof(const Metadata *MD) {
1065     return MD->getMetadataID() == MDLexicalBlockKind;
1066   }
1067 };
1068
1069 class MDLexicalBlockFile : public MDLexicalBlockBase {
1070   friend class LLVMContextImpl;
1071   friend class MDNode;
1072
1073   unsigned Discriminator;
1074
1075   MDLexicalBlockFile(LLVMContext &C, StorageType Storage,
1076                      unsigned Discriminator, ArrayRef<Metadata *> Ops)
1077       : MDLexicalBlockBase(C, MDLexicalBlockFileKind, Storage, Ops),
1078         Discriminator(Discriminator) {}
1079   ~MDLexicalBlockFile() {}
1080
1081   static MDLexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1082                                      Metadata *File, unsigned Discriminator,
1083                                      StorageType Storage,
1084                                      bool ShouldCreate = true);
1085
1086   TempMDLexicalBlockFile cloneImpl() const {
1087     return getTemporary(getContext(), getScope(), getFile(),
1088                         getDiscriminator());
1089   }
1090
1091 public:
1092   DEFINE_MDNODE_GET(MDLexicalBlockFile,
1093                     (Metadata * Scope, Metadata *File, unsigned Discriminator),
1094                     (Scope, File, Discriminator))
1095
1096   TempMDLexicalBlockFile clone() const { return cloneImpl(); }
1097
1098   unsigned getDiscriminator() const { return Discriminator; }
1099
1100   static bool classof(const Metadata *MD) {
1101     return MD->getMetadataID() == MDLexicalBlockFileKind;
1102   }
1103 };
1104
1105 class MDNamespace : public MDScope {
1106   friend class LLVMContextImpl;
1107   friend class MDNode;
1108
1109   unsigned Line;
1110
1111   MDNamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
1112               ArrayRef<Metadata *> Ops)
1113       : MDScope(Context, MDNamespaceKind, Storage, dwarf::DW_TAG_namespace,
1114                 Ops),
1115         Line(Line) {}
1116   ~MDNamespace() {}
1117
1118   static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1119                               Metadata *File, StringRef Name, unsigned Line,
1120                               StorageType Storage, bool ShouldCreate = true) {
1121     return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
1122                    Line, Storage, ShouldCreate);
1123   }
1124   static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1125                               Metadata *File, MDString *Name, unsigned Line,
1126                               StorageType Storage, bool ShouldCreate = true);
1127
1128   TempMDNamespace cloneImpl() const {
1129     return getTemporary(getContext(), getScope(), getFile(), getName(),
1130                         getLine());
1131   }
1132
1133 public:
1134   DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1135                                   StringRef Name, unsigned Line),
1136                     (Scope, File, Name, Line))
1137   DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
1138                                   MDString *Name, unsigned Line),
1139                     (Scope, File, Name, Line))
1140
1141   TempMDNamespace clone() const { return cloneImpl(); }
1142
1143   unsigned getLine() const { return Line; }
1144   Metadata *getScope() const { return getOperand(1); }
1145   StringRef getName() const { return getStringOperand(2); }
1146
1147   MDString *getRawName() const { return getOperandAs<MDString>(2); }
1148
1149   static bool classof(const Metadata *MD) {
1150     return MD->getMetadataID() == MDNamespaceKind;
1151   }
1152 };
1153
1154 /// \brief Base class for template parameters.
1155 class MDTemplateParameter : public DebugNode {
1156 protected:
1157   MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1158                       unsigned Tag, ArrayRef<Metadata *> Ops)
1159       : DebugNode(Context, ID, Storage, Tag, Ops) {}
1160   ~MDTemplateParameter() {}
1161
1162 public:
1163   StringRef getName() const { return getStringOperand(0); }
1164   Metadata *getType() const { return getOperand(1); }
1165
1166   MDString *getRawName() const { return getOperandAs<MDString>(0); }
1167
1168   static bool classof(const Metadata *MD) {
1169     return MD->getMetadataID() == MDTemplateTypeParameterKind ||
1170            MD->getMetadataID() == MDTemplateValueParameterKind;
1171   }
1172 };
1173
1174 class MDTemplateTypeParameter : public MDTemplateParameter {
1175   friend class LLVMContextImpl;
1176   friend class MDNode;
1177
1178   MDTemplateTypeParameter(LLVMContext &Context, StorageType Storage,
1179                           ArrayRef<Metadata *> Ops)
1180       : MDTemplateParameter(Context, MDTemplateTypeParameterKind, Storage,
1181                             dwarf::DW_TAG_template_type_parameter, Ops) {}
1182   ~MDTemplateTypeParameter() {}
1183
1184   static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
1185                                           Metadata *Type, StorageType Storage,
1186                                           bool ShouldCreate = true) {
1187     return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
1188                    ShouldCreate);
1189   }
1190   static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
1191                                           Metadata *Type, StorageType Storage,
1192                                           bool ShouldCreate = true);
1193
1194   TempMDTemplateTypeParameter cloneImpl() const {
1195     return getTemporary(getContext(), getName(), getType());
1196   }
1197
1198 public:
1199   DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
1200                     (Name, Type))
1201   DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
1202                     (Name, Type))
1203
1204   TempMDTemplateTypeParameter clone() const { return cloneImpl(); }
1205
1206   static bool classof(const Metadata *MD) {
1207     return MD->getMetadataID() == MDTemplateTypeParameterKind;
1208   }
1209 };
1210
1211 class MDTemplateValueParameter : public MDTemplateParameter {
1212   friend class LLVMContextImpl;
1213   friend class MDNode;
1214
1215   MDTemplateValueParameter(LLVMContext &Context, StorageType Storage,
1216                            unsigned Tag, ArrayRef<Metadata *> Ops)
1217       : MDTemplateParameter(Context, MDTemplateValueParameterKind, Storage, Tag,
1218                             Ops) {}
1219   ~MDTemplateValueParameter() {}
1220
1221   static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1222                                            StringRef Name, Metadata *Type,
1223                                            Metadata *Value, StorageType Storage,
1224                                            bool ShouldCreate = true) {
1225     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
1226                    Value, Storage, ShouldCreate);
1227   }
1228   static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
1229                                            MDString *Name, Metadata *Type,
1230                                            Metadata *Value, StorageType Storage,
1231                                            bool ShouldCreate = true);
1232
1233   TempMDTemplateValueParameter cloneImpl() const {
1234     return getTemporary(getContext(), getTag(), getName(), getType(),
1235                         getValue());
1236   }
1237
1238 public:
1239   DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
1240                                                Metadata *Type, Metadata *Value),
1241                     (Tag, Name, Type, Value))
1242   DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
1243                                                Metadata *Type, Metadata *Value),
1244                     (Tag, Name, Type, Value))
1245
1246   TempMDTemplateValueParameter clone() const { return cloneImpl(); }
1247
1248   Metadata *getValue() const { return getOperand(2); }
1249
1250   static bool classof(const Metadata *MD) {
1251     return MD->getMetadataID() == MDTemplateValueParameterKind;
1252   }
1253 };
1254
1255 /// \brief Base class for variables.
1256 ///
1257 /// TODO: Hardcode to DW_TAG_variable.
1258 class MDVariable : public DebugNode {
1259   unsigned Line;
1260
1261 protected:
1262   MDVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1263              unsigned Line, ArrayRef<Metadata *> Ops)
1264       : DebugNode(C, ID, Storage, Tag, Ops), Line(Line) {}
1265   ~MDVariable() {}
1266
1267 public:
1268   unsigned getLine() const { return Line; }
1269   Metadata *getScope() const { return getOperand(0); }
1270   StringRef getName() const { return getStringOperand(1); }
1271   Metadata *getFile() const { return getOperand(2); }
1272   Metadata *getType() const { return getOperand(3); }
1273
1274   MDString *getRawName() const { return getOperandAs<MDString>(1); }
1275
1276   static bool classof(const Metadata *MD) {
1277     return MD->getMetadataID() == MDLocalVariableKind ||
1278            MD->getMetadataID() == MDGlobalVariableKind;
1279   }
1280 };
1281
1282 /// \brief Global variables.
1283 ///
1284 /// TODO: Remove DisplayName.  It's always equal to Name.
1285 class MDGlobalVariable : public MDVariable {
1286   friend class LLVMContextImpl;
1287   friend class MDNode;
1288
1289   bool IsLocalToUnit;
1290   bool IsDefinition;
1291
1292   MDGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
1293                    bool IsLocalToUnit, bool IsDefinition,
1294                    ArrayRef<Metadata *> Ops)
1295       : MDVariable(C, MDGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
1296                    Line, Ops),
1297         IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
1298   ~MDGlobalVariable() {}
1299
1300   static MDGlobalVariable *
1301   getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
1302           StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1303           bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1304           Metadata *StaticDataMemberDeclaration, StorageType Storage,
1305           bool ShouldCreate = true) {
1306     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1307                    getCanonicalMDString(Context, LinkageName), File, Line, Type,
1308                    IsLocalToUnit, IsDefinition, Variable,
1309                    StaticDataMemberDeclaration, Storage, ShouldCreate);
1310   }
1311   static MDGlobalVariable *
1312   getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1313           MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1314           bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1315           Metadata *StaticDataMemberDeclaration, StorageType Storage,
1316           bool ShouldCreate = true);
1317
1318   TempMDGlobalVariable cloneImpl() const {
1319     return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1320                         getFile(), getLine(), getType(), isLocalToUnit(),
1321                         isDefinition(), getVariable(),
1322                         getStaticDataMemberDeclaration());
1323   }
1324
1325 public:
1326   DEFINE_MDNODE_GET(MDGlobalVariable,
1327                     (Metadata * Scope, StringRef Name, StringRef LinkageName,
1328                      Metadata *File, unsigned Line, Metadata *Type,
1329                      bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1330                      Metadata *StaticDataMemberDeclaration),
1331                     (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1332                      IsDefinition, Variable, StaticDataMemberDeclaration))
1333   DEFINE_MDNODE_GET(MDGlobalVariable,
1334                     (Metadata * Scope, MDString *Name, MDString *LinkageName,
1335                      Metadata *File, unsigned Line, Metadata *Type,
1336                      bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
1337                      Metadata *StaticDataMemberDeclaration),
1338                     (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1339                      IsDefinition, Variable, StaticDataMemberDeclaration))
1340
1341   TempMDGlobalVariable clone() const { return cloneImpl(); }
1342
1343   bool isLocalToUnit() const { return IsLocalToUnit; }
1344   bool isDefinition() const { return IsDefinition; }
1345   StringRef getDisplayName() const { return getStringOperand(4); }
1346   StringRef getLinkageName() const { return getStringOperand(5); }
1347   Metadata *getVariable() const { return getOperand(6); }
1348   Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
1349
1350   MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
1351
1352   static bool classof(const Metadata *MD) {
1353     return MD->getMetadataID() == MDGlobalVariableKind;
1354   }
1355 };
1356
1357 /// \brief Local variable.
1358 ///
1359 /// TODO: Split between arguments and otherwise.
1360 /// TODO: Use \c DW_TAG_variable instead of fake tags.
1361 /// TODO: Split up flags.
1362 class MDLocalVariable : public MDVariable {
1363   friend class LLVMContextImpl;
1364   friend class MDNode;
1365
1366   unsigned Arg;
1367   unsigned Flags;
1368
1369   MDLocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
1370                   unsigned Line, unsigned Arg, unsigned Flags,
1371                   ArrayRef<Metadata *> Ops)
1372       : MDVariable(C, MDLocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
1373         Flags(Flags) {}
1374   ~MDLocalVariable() {}
1375
1376   static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1377                                   Metadata *Scope, StringRef Name,
1378                                   Metadata *File, unsigned Line, Metadata *Type,
1379                                   unsigned Arg, unsigned Flags,
1380                                   Metadata *InlinedAt, StorageType Storage,
1381                                   bool ShouldCreate = true) {
1382     return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
1383                    File, Line, Type, Arg, Flags, InlinedAt, Storage,
1384                    ShouldCreate);
1385   }
1386   static MDLocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
1387                                   Metadata *Scope, MDString *Name,
1388                                   Metadata *File, unsigned Line, Metadata *Type,
1389                                   unsigned Arg, unsigned Flags,
1390                                   Metadata *InlinedAt, StorageType Storage,
1391                                   bool ShouldCreate = true);
1392
1393   TempMDLocalVariable cloneImpl() const {
1394     return getTemporary(getContext(), getTag(), getScope(), getName(),
1395                         getFile(), getLine(), getType(), getArg(), getFlags(),
1396                         getInlinedAt());
1397   }
1398
1399 public:
1400   DEFINE_MDNODE_GET(MDLocalVariable,
1401                     (unsigned Tag, Metadata *Scope, StringRef Name,
1402                      Metadata *File, unsigned Line, Metadata *Type,
1403                      unsigned Arg, unsigned Flags,
1404                      Metadata *InlinedAt = nullptr),
1405                     (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1406   DEFINE_MDNODE_GET(MDLocalVariable,
1407                     (unsigned Tag, Metadata *Scope, MDString *Name,
1408                      Metadata *File, unsigned Line, Metadata *Type,
1409                      unsigned Arg, unsigned Flags,
1410                      Metadata *InlinedAt = nullptr),
1411                     (Tag, Scope, Name, File, Line, Type, Arg, Flags, InlinedAt))
1412
1413   TempMDLocalVariable clone() const { return cloneImpl(); }
1414
1415   unsigned getArg() const { return Arg; }
1416   unsigned getFlags() const { return Flags; }
1417   Metadata *getInlinedAt() const { return getOperand(4); }
1418
1419   static bool classof(const Metadata *MD) {
1420     return MD->getMetadataID() == MDLocalVariableKind;
1421   }
1422 };
1423
1424 /// \brief DWARF expression.
1425 ///
1426 /// TODO: Co-allocate the expression elements.
1427 /// TODO: Drop fake DW_TAG_expression and separate from DebugNode.
1428 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
1429 /// storage types.
1430 class MDExpression : public DebugNode {
1431   friend class LLVMContextImpl;
1432   friend class MDNode;
1433
1434   std::vector<uint64_t> Elements;
1435
1436   MDExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
1437       : DebugNode(C, MDExpressionKind, Storage, dwarf::DW_TAG_expression, None),
1438         Elements(Elements.begin(), Elements.end()) {}
1439   ~MDExpression() {}
1440
1441   static MDExpression *getImpl(LLVMContext &Context,
1442                                ArrayRef<uint64_t> Elements, StorageType Storage,
1443                                bool ShouldCreate = true);
1444
1445   TempMDExpression cloneImpl() const {
1446     return getTemporary(getContext(), getElements());
1447   }
1448
1449 public:
1450   DEFINE_MDNODE_GET(MDExpression, (ArrayRef<uint64_t> Elements), (Elements))
1451
1452   TempMDExpression clone() const { return cloneImpl(); }
1453
1454   ArrayRef<uint64_t> getElements() const { return Elements; }
1455
1456   unsigned getNumElements() const { return Elements.size(); }
1457   uint64_t getElement(unsigned I) const {
1458     assert(I < Elements.size() && "Index out of range");
1459     return Elements[I];
1460   }
1461
1462   typedef ArrayRef<uint64_t>::iterator element_iterator;
1463   element_iterator elements_begin() const { return getElements().begin(); }
1464   element_iterator elements_end() const { return getElements().end(); }
1465
1466   /// \brief A lightweight wrapper around an expression operand.
1467   ///
1468   /// TODO: Store arguments directly and change \a MDExpression to store a
1469   /// range of these.
1470   class ExprOperand {
1471     const uint64_t *Op;
1472
1473   public:
1474     explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
1475
1476     const uint64_t *get() const { return Op; }
1477
1478     /// \brief Get the operand code.
1479     uint64_t getOp() const { return *Op; }
1480
1481     /// \brief Get an argument to the operand.
1482     ///
1483     /// Never returns the operand itself.
1484     uint64_t getArg(unsigned I) const { return Op[I + 1]; }
1485
1486     unsigned getNumArgs() const { return getSize() - 1; }
1487
1488     /// \brief Return the size of the operand.
1489     ///
1490     /// Return the number of elements in the operand (1 + args).
1491     unsigned getSize() const;
1492   };
1493
1494   /// \brief An iterator for expression operands.
1495   class expr_op_iterator
1496       : public std::iterator<std::input_iterator_tag, ExprOperand> {
1497     ExprOperand Op;
1498
1499   public:
1500     explicit expr_op_iterator(element_iterator I) : Op(I) {}
1501
1502     element_iterator getBase() const { return Op.get(); }
1503     const ExprOperand &operator*() const { return Op; }
1504     const ExprOperand *operator->() const { return &Op; }
1505
1506     expr_op_iterator &operator++() {
1507       increment();
1508       return *this;
1509     }
1510     expr_op_iterator operator++(int) {
1511       expr_op_iterator T(*this);
1512       increment();
1513       return T;
1514     }
1515
1516     bool operator==(const expr_op_iterator &X) const {
1517       return getBase() == X.getBase();
1518     }
1519     bool operator!=(const expr_op_iterator &X) const {
1520       return getBase() != X.getBase();
1521     }
1522
1523   private:
1524     void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
1525   };
1526
1527   /// \brief Visit the elements via ExprOperand wrappers.
1528   ///
1529   /// These range iterators visit elements through \a ExprOperand wrappers.
1530   /// This is not guaranteed to be a valid range unless \a isValid() gives \c
1531   /// true.
1532   ///
1533   /// \pre \a isValid() gives \c true.
1534   /// @{
1535   expr_op_iterator expr_op_begin() const {
1536     return expr_op_iterator(elements_begin());
1537   }
1538   expr_op_iterator expr_op_end() const {
1539     return expr_op_iterator(elements_end());
1540   }
1541   /// @}
1542
1543   bool isValid() const;
1544
1545   static bool classof(const Metadata *MD) {
1546     return MD->getMetadataID() == MDExpressionKind;
1547   }
1548 };
1549
1550 class MDObjCProperty : public DebugNode {
1551   friend class LLVMContextImpl;
1552   friend class MDNode;
1553
1554   unsigned Line;
1555   unsigned Attributes;
1556
1557   MDObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
1558                  unsigned Attributes, ArrayRef<Metadata *> Ops)
1559       : DebugNode(C, MDObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
1560                   Ops),
1561         Line(Line), Attributes(Attributes) {}
1562   ~MDObjCProperty() {}
1563
1564   static MDObjCProperty *
1565   getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
1566           StringRef GetterName, StringRef SetterName, unsigned Attributes,
1567           Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
1568     return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1569                    getCanonicalMDString(Context, GetterName),
1570                    getCanonicalMDString(Context, SetterName), Attributes, Type,
1571                    Storage, ShouldCreate);
1572   }
1573   static MDObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
1574                                  Metadata *File, unsigned Line,
1575                                  MDString *GetterName, MDString *SetterName,
1576                                  unsigned Attributes, Metadata *Type,
1577                                  StorageType Storage, bool ShouldCreate = true);
1578
1579   TempMDObjCProperty cloneImpl() const {
1580     return getTemporary(getContext(), getName(), getFile(), getLine(),
1581                         getGetterName(), getSetterName(), getAttributes(),
1582                         getType());
1583   }
1584
1585 public:
1586   DEFINE_MDNODE_GET(MDObjCProperty,
1587                     (StringRef Name, Metadata *File, unsigned Line,
1588                      StringRef GetterName, StringRef SetterName,
1589                      unsigned Attributes, Metadata *Type),
1590                     (Name, File, Line, GetterName, SetterName, Attributes,
1591                      Type))
1592   DEFINE_MDNODE_GET(MDObjCProperty,
1593                     (MDString * Name, Metadata *File, unsigned Line,
1594                      MDString *GetterName, MDString *SetterName,
1595                      unsigned Attributes, Metadata *Type),
1596                     (Name, File, Line, GetterName, SetterName, Attributes,
1597                      Type))
1598
1599   TempMDObjCProperty clone() const { return cloneImpl(); }
1600
1601   unsigned getLine() const { return Line; }
1602   unsigned getAttributes() const { return Attributes; }
1603   StringRef getName() const { return getStringOperand(0); }
1604   Metadata *getFile() const { return getOperand(1); }
1605   StringRef getGetterName() const { return getStringOperand(2); }
1606   StringRef getSetterName() const { return getStringOperand(3); }
1607   Metadata *getType() const { return getOperand(4); }
1608
1609   MDString *getRawName() const { return getOperandAs<MDString>(0); }
1610   MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
1611   MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
1612
1613   static bool classof(const Metadata *MD) {
1614     return MD->getMetadataID() == MDObjCPropertyKind;
1615   }
1616 };
1617
1618 class MDImportedEntity : public DebugNode {
1619   friend class LLVMContextImpl;
1620   friend class MDNode;
1621
1622   unsigned Line;
1623
1624   MDImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
1625                    unsigned Line, ArrayRef<Metadata *> Ops)
1626       : DebugNode(C, MDImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
1627   ~MDImportedEntity() {}
1628
1629   static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1630                                    Metadata *Scope, Metadata *Entity,
1631                                    unsigned Line, StringRef Name,
1632                                    StorageType Storage,
1633                                    bool ShouldCreate = true) {
1634     return getImpl(Context, Tag, Scope, Entity, Line,
1635                    getCanonicalMDString(Context, Name), Storage, ShouldCreate);
1636   }
1637   static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
1638                                    Metadata *Scope, Metadata *Entity,
1639                                    unsigned Line, MDString *Name,
1640                                    StorageType Storage,
1641                                    bool ShouldCreate = true);
1642
1643   TempMDImportedEntity cloneImpl() const {
1644     return getTemporary(getContext(), getTag(), getScope(), getEntity(),
1645                         getLine(), getName());
1646   }
1647
1648 public:
1649   DEFINE_MDNODE_GET(MDImportedEntity,
1650                     (unsigned Tag, Metadata *Scope, Metadata *Entity,
1651                      unsigned Line, StringRef Name = ""),
1652                     (Tag, Scope, Entity, Line, Name))
1653   DEFINE_MDNODE_GET(MDImportedEntity,
1654                     (unsigned Tag, Metadata *Scope, Metadata *Entity,
1655                      unsigned Line, MDString *Name),
1656                     (Tag, Scope, Entity, Line, Name))
1657
1658   TempMDImportedEntity clone() const { return cloneImpl(); }
1659
1660   unsigned getLine() const { return Line; }
1661   Metadata *getScope() const { return getOperand(0); }
1662   Metadata *getEntity() const { return getOperand(1); }
1663   StringRef getName() const { return getStringOperand(2); }
1664
1665   MDString *getRawName() const { return getOperandAs<MDString>(2); }
1666
1667   static bool classof(const Metadata *MD) {
1668     return MD->getMetadataID() == MDImportedEntityKind;
1669   }
1670 };
1671
1672 } // end namespace llvm
1673
1674 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
1675 #undef DEFINE_MDNODE_GET_UNPACK
1676 #undef DEFINE_MDNODE_GET
1677
1678 #endif