LCOV - code coverage report
Current view: top level - include/llvm/IR - DebugInfoMetadata.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 645 652 98.9 %
Date: 2017-09-14 15:23:50 Functions: 63 65 96.9 %
Legend: Lines: hit not hit

          Line data    Source code
       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/ADT/ArrayRef.h"
      18             : #include "llvm/ADT/BitmaskEnum.h"
      19             : #include "llvm/ADT/None.h"
      20             : #include "llvm/ADT/Optional.h"
      21             : #include "llvm/ADT/STLExtras.h"
      22             : #include "llvm/ADT/SmallVector.h"
      23             : #include "llvm/ADT/StringRef.h"
      24             : #include "llvm/ADT/iterator_range.h"
      25             : #include "llvm/BinaryFormat/Dwarf.h"
      26             : #include "llvm/IR/Metadata.h"
      27             : #include "llvm/Support/Casting.h"
      28             : #include <cassert>
      29             : #include <climits>
      30             : #include <cstddef>
      31             : #include <cstdint>
      32             : #include <iterator>
      33             : #include <type_traits>
      34             : #include <vector>
      35             : 
      36             : // Helper macros for defining get() overrides.
      37             : #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
      38             : #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
      39             : #define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)              \
      40             :   static CLASS *getDistinct(LLVMContext &Context,                              \
      41             :                             DEFINE_MDNODE_GET_UNPACK(FORMAL)) {                \
      42             :     return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct);         \
      43             :   }                                                                            \
      44             :   static Temp##CLASS getTemporary(LLVMContext &Context,                        \
      45             :                                   DEFINE_MDNODE_GET_UNPACK(FORMAL)) {          \
      46             :     return Temp##CLASS(                                                        \
      47             :         getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary));          \
      48             :   }
      49             : #define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS)                                 \
      50             :   static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) {  \
      51             :     return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued);          \
      52             :   }                                                                            \
      53             :   static CLASS *getIfExists(LLVMContext &Context,                              \
      54             :                             DEFINE_MDNODE_GET_UNPACK(FORMAL)) {                \
      55             :     return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued,           \
      56             :                    /* ShouldCreate */ false);                                  \
      57             :   }                                                                            \
      58             :   DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
      59             : 
      60             : namespace llvm {
      61             : 
      62             : /// Holds a subclass of DINode.
      63             : ///
      64             : /// FIXME: This class doesn't currently make much sense.  Previously it was a
      65             : /// union beteen MDString (for ODR-uniqued types) and things like DIType.  To
      66             : /// support CodeView work, it wasn't deleted outright when MDString-based type
      67             : /// references were deleted; we'll soon need a similar concept for CodeView
      68             : /// DITypeIndex.
      69             : template <class T> class TypedDINodeRef {
      70             :   const Metadata *MD = nullptr;
      71             : 
      72             : public:
      73             :   TypedDINodeRef() = default;
      74             :   TypedDINodeRef(std::nullptr_t) {}
      75        7602 :   TypedDINodeRef(const T *MD) : MD(MD) {}
      76             : 
      77           8 :   explicit TypedDINodeRef(const Metadata *MD) : MD(MD) {
      78             :     assert((!MD || isa<T>(MD)) && "Expected valid type ref");
      79             :   }
      80             : 
      81             :   template <class U>
      82             :   TypedDINodeRef(
      83             :       const TypedDINodeRef<U> &X,
      84             :       typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
      85             :           nullptr)
      86             :       : MD(X) {}
      87             : 
      88      226315 :   operator Metadata *() const { return const_cast<Metadata *>(MD); }
      89             : 
      90      500931 :   T *resolve() const { return const_cast<T *>(cast_or_null<T>(MD)); }
      91             : 
      92             :   bool operator==(const TypedDINodeRef<T> &X) const { return MD == X.MD; }
      93             :   bool operator!=(const TypedDINodeRef<T> &X) const { return MD != X.MD; }
      94             : };
      95             : 
      96             : using DINodeRef = TypedDINodeRef<DINode>;
      97             : using DIScopeRef = TypedDINodeRef<DIScope>;
      98             : using DITypeRef = TypedDINodeRef<DIType>;
      99             : 
     100             : class DITypeRefArray {
     101             :   const MDTuple *N = nullptr;
     102             : 
     103             : public:
     104             :   DITypeRefArray() = default;
     105             :   DITypeRefArray(const MDTuple *N) : N(N) {}
     106             : 
     107             :   explicit operator bool() const { return get(); }
     108             :   explicit operator MDTuple *() const { return get(); }
     109             : 
     110             :   MDTuple *get() const { return const_cast<MDTuple *>(N); }
     111        5132 :   MDTuple *operator->() const { return get(); }
     112             :   MDTuple &operator*() const { return *get(); }
     113             : 
     114             :   // FIXME: Fix callers and remove condition on N.
     115       52520 :   unsigned size() const { return N ? N->getNumOperands() : 0u; }
     116      215721 :   DITypeRef operator[](unsigned I) const { return DITypeRef(N->getOperand(I)); }
     117             : 
     118             :   class iterator : std::iterator<std::input_iterator_tag, DITypeRef,
     119             :                                  std::ptrdiff_t, void, DITypeRef> {
     120             :     MDNode::op_iterator I = nullptr;
     121             : 
     122             :   public:
     123             :     iterator() = default;
     124             :     explicit iterator(MDNode::op_iterator I) : I(I) {}
     125             : 
     126         546 :     DITypeRef operator*() const { return DITypeRef(*I); }
     127             : 
     128             :     iterator &operator++() {
     129         273 :       ++I;
     130             :       return *this;
     131             :     }
     132             : 
     133             :     iterator operator++(int) {
     134             :       iterator Temp(*this);
     135             :       ++I;
     136             :       return Temp;
     137             :     }
     138             : 
     139             :     bool operator==(const iterator &X) const { return I == X.I; }
     140             :     bool operator!=(const iterator &X) const { return I != X.I; }
     141             :   };
     142             : 
     143             :   // FIXME: Fix callers and remove condition on N.
     144         392 :   iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
     145         392 :   iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
     146             : };
     147             : 
     148             : /// Tagged DWARF-like metadata node.
     149             : ///
     150             : /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
     151             : /// defined in llvm/BinaryFormat/Dwarf.h).  Called \a DINode because it's
     152             : /// potentially used for non-DWARF output.
     153             : class DINode : public MDNode {
     154             :   friend class LLVMContextImpl;
     155             :   friend class MDNode;
     156             : 
     157             : protected:
     158             :   DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
     159             :          ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
     160      152841 :       : MDNode(C, ID, Storage, Ops1, Ops2) {
     161             :     assert(Tag < 1u << 16);
     162      152841 :     SubclassData16 = Tag;
     163             :   }
     164      101108 :   ~DINode() = default;
     165             : 
     166             :   template <class Ty> Ty *getOperandAs(unsigned I) const {
     167    14624722 :     return cast_or_null<Ty>(getOperand(I));
     168             :   }
     169             : 
     170     4380056 :   StringRef getStringOperand(unsigned I) const {
     171     4380056 :     if (auto *S = getOperandAs<MDString>(I))
     172     4310811 :       return S->getString();
     173       69245 :     return StringRef();
     174             :   }
     175             : 
     176             :   static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
     177      197255 :     if (S.empty())
     178             :       return nullptr;
     179      132576 :     return MDString::get(Context, S);
     180             :   }
     181             : 
     182             :   /// Allow subclasses to mutate the tag.
     183           4 :   void setTag(unsigned Tag) { SubclassData16 = Tag; }
     184             : 
     185             : public:
     186      285098 :   unsigned getTag() const { return SubclassData16; }
     187             : 
     188             :   /// Debug info flags.
     189             :   ///
     190             :   /// The three accessibility flags are mutually exclusive and rolled together
     191             :   /// in the first two bits.
     192             :   enum DIFlags : uint32_t {
     193             : #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
     194             : #define DI_FLAG_LARGEST_NEEDED
     195             : #include "llvm/IR/DebugInfoFlags.def"
     196             :     FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
     197             :     FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
     198             :                          FlagVirtualInheritance,
     199             :     LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)
     200             :   };
     201             : 
     202             :   static DIFlags getFlag(StringRef Flag);
     203             :   static StringRef getFlagString(DIFlags Flag);
     204             : 
     205             :   /// Split up a flags bitfield.
     206             :   ///
     207             :   /// Split \c Flags into \c SplitFlags, a vector of its components.  Returns
     208             :   /// any remaining (unrecognized) bits.
     209             :   static DIFlags splitFlags(DIFlags Flags,
     210             :                             SmallVectorImpl<DIFlags> &SplitFlags);
     211             : 
     212             :   static bool classof(const Metadata *MD) {
     213         247 :     switch (MD->getMetadataID()) {
     214             :     default:
     215             :       return false;
     216             :     case GenericDINodeKind:
     217             :     case DISubrangeKind:
     218             :     case DIEnumeratorKind:
     219             :     case DIBasicTypeKind:
     220             :     case DIDerivedTypeKind:
     221             :     case DICompositeTypeKind:
     222             :     case DISubroutineTypeKind:
     223             :     case DIFileKind:
     224             :     case DICompileUnitKind:
     225             :     case DISubprogramKind:
     226             :     case DILexicalBlockKind:
     227             :     case DILexicalBlockFileKind:
     228             :     case DINamespaceKind:
     229             :     case DITemplateTypeParameterKind:
     230             :     case DITemplateValueParameterKind:
     231             :     case DIGlobalVariableKind:
     232             :     case DILocalVariableKind:
     233             :     case DIObjCPropertyKind:
     234             :     case DIImportedEntityKind:
     235             :     case DIModuleKind:
     236             :       return true;
     237             :     }
     238             :   }
     239             : };
     240             : 
     241             : template <class T> struct simplify_type<const TypedDINodeRef<T>> {
     242             :   using SimpleType = Metadata *;
     243             : 
     244             :   static SimpleType getSimplifiedValue(const TypedDINodeRef<T> &MD) {
     245          12 :     return MD;
     246             :   }
     247             : };
     248             : 
     249             : template <class T>
     250             : struct simplify_type<TypedDINodeRef<T>>
     251             :     : simplify_type<const TypedDINodeRef<T>> {};
     252             : 
     253             : /// Generic tagged DWARF-like metadata node.
     254             : ///
     255             : /// An un-specialized DWARF-like metadata node.  The first operand is a
     256             : /// (possibly empty) null-separated \a MDString header that contains arbitrary
     257             : /// fields.  The remaining operands are \a dwarf_operands(), and are pointers
     258             : /// to other metadata.
     259             : class GenericDINode : public DINode {
     260             :   friend class LLVMContextImpl;
     261             :   friend class MDNode;
     262             : 
     263             :   GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
     264             :                 unsigned Tag, ArrayRef<Metadata *> Ops1,
     265             :                 ArrayRef<Metadata *> Ops2)
     266          96 :       : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
     267          96 :     setHash(Hash);
     268             :   }
     269          96 :   ~GenericDINode() { dropAllReferences(); }
     270             : 
     271          74 :   void setHash(unsigned Hash) { SubclassData32 = Hash; }
     272             :   void recalculateHash();
     273             : 
     274           6 :   static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
     275             :                                 StringRef Header, ArrayRef<Metadata *> DwarfOps,
     276             :                                 StorageType Storage, bool ShouldCreate = true) {
     277          12 :     return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
     278           6 :                    DwarfOps, Storage, ShouldCreate);
     279             :   }
     280             : 
     281             :   static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
     282             :                                 MDString *Header, ArrayRef<Metadata *> DwarfOps,
     283             :                                 StorageType Storage, bool ShouldCreate = true);
     284             : 
     285           1 :   TempGenericDINode cloneImpl() const {
     286             :     return getTemporary(
     287             :         getContext(), getTag(), getHeader(),
     288           9 :         SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
     289             :   }
     290             : 
     291             : public:
     292             :   unsigned getHash() const { return SubclassData32; }
     293             : 
     294           7 :   DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, StringRef Header,
     295             :                                     ArrayRef<Metadata *> DwarfOps),
     296             :                     (Tag, Header, DwarfOps))
     297          55 :   DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, MDString *Header,
     298             :                                     ArrayRef<Metadata *> DwarfOps),
     299             :                     (Tag, Header, DwarfOps))
     300             : 
     301             :   /// Return a (temporary) clone of this.
     302           1 :   TempGenericDINode clone() const { return cloneImpl(); }
     303             : 
     304         101 :   unsigned getTag() const { return SubclassData16; }
     305          25 :   StringRef getHeader() const { return getStringOperand(0); }
     306         194 :   MDString *getRawHeader() const { return getOperandAs<MDString>(0); }
     307             : 
     308          12 :   op_iterator dwarf_op_begin() const { return op_begin() + 1; }
     309          12 :   op_iterator dwarf_op_end() const { return op_end(); }
     310             :   op_range dwarf_operands() const {
     311          15 :     return op_range(dwarf_op_begin(), dwarf_op_end());
     312             :   }
     313             : 
     314          21 :   unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
     315             :   const MDOperand &getDwarfOperand(unsigned I) const {
     316           6 :     return getOperand(I + 1);
     317             :   }
     318             :   void replaceDwarfOperandWith(unsigned I, Metadata *New) {
     319           1 :     replaceOperandWith(I + 1, New);
     320             :   }
     321             : 
     322             :   static bool classof(const Metadata *MD) {
     323             :     return MD->getMetadataID() == GenericDINodeKind;
     324             :   }
     325             : };
     326             : 
     327             : /// Array subrange.
     328             : ///
     329             : /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
     330             : /// type.
     331             : class DISubrange : public DINode {
     332             :   friend class LLVMContextImpl;
     333             :   friend class MDNode;
     334             : 
     335             :   int64_t Count;
     336             :   int64_t LowerBound;
     337             : 
     338             :   DISubrange(LLVMContext &C, StorageType Storage, int64_t Count,
     339             :              int64_t LowerBound)
     340         497 :       : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, None),
     341         994 :         Count(Count), LowerBound(LowerBound) {}
     342         722 :   ~DISubrange() = default;
     343             : 
     344             :   static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
     345             :                              int64_t LowerBound, StorageType Storage,
     346             :                              bool ShouldCreate = true);
     347             : 
     348           1 :   TempDISubrange cloneImpl() const {
     349           3 :     return getTemporary(getContext(), getCount(), getLowerBound());
     350             :   }
     351             : 
     352             : public:
     353         562 :   DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
     354             :                     (Count, LowerBound))
     355             : 
     356           1 :   TempDISubrange clone() const { return cloneImpl(); }
     357             : 
     358             :   int64_t getLowerBound() const { return LowerBound; }
     359             :   int64_t getCount() const { return Count; }
     360             : 
     361             :   static bool classof(const Metadata *MD) {
     362             :     return MD->getMetadataID() == DISubrangeKind;
     363             :   }
     364             : };
     365             : 
     366             : /// Enumeration value.
     367             : ///
     368             : /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
     369             : /// longer creates a type cycle.
     370             : class DIEnumerator : public DINode {
     371             :   friend class LLVMContextImpl;
     372             :   friend class MDNode;
     373             : 
     374             :   int64_t Value;
     375             : 
     376             :   DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
     377             :                ArrayRef<Metadata *> Ops)
     378        6065 :       : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
     379       12130 :         Value(Value) {}
     380       11716 :   ~DIEnumerator() = default;
     381             : 
     382         282 :   static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
     383             :                                StringRef Name, StorageType Storage,
     384             :                                bool ShouldCreate = true) {
     385         564 :     return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
     386         282 :                    ShouldCreate);
     387             :   }
     388             :   static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
     389             :                                MDString *Name, StorageType Storage,
     390             :                                bool ShouldCreate = true);
     391             : 
     392           1 :   TempDIEnumerator cloneImpl() const {
     393           3 :     return getTemporary(getContext(), getValue(), getName());
     394             :   }
     395             : 
     396             : public:
     397         283 :   DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, StringRef Name),
     398             :                     (Value, Name))
     399        5796 :   DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, MDString *Name),
     400             :                     (Value, Name))
     401             : 
     402           1 :   TempDIEnumerator clone() const { return cloneImpl(); }
     403             : 
     404             :   int64_t getValue() const { return Value; }
     405        6049 :   StringRef getName() const { return getStringOperand(0); }
     406             : 
     407       24496 :   MDString *getRawName() const { return getOperandAs<MDString>(0); }
     408             : 
     409             :   static bool classof(const Metadata *MD) {
     410        5987 :     return MD->getMetadataID() == DIEnumeratorKind;
     411             :   }
     412             : };
     413             : 
     414             : /// Base class for scope-like contexts.
     415             : ///
     416             : /// Base class for lexical scopes and types (which are also declaration
     417             : /// contexts).
     418             : ///
     419             : /// TODO: Separate the concepts of declaration contexts and lexical scopes.
     420             : class DIScope : public DINode {
     421             : protected:
     422             :   DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
     423             :           ArrayRef<Metadata *> Ops)
     424      241864 :       : DINode(C, ID, Storage, Tag, Ops) {}
     425       75150 :   ~DIScope() = default;
     426             : 
     427             : public:
     428     6866424 :   DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
     429             : 
     430             :   inline StringRef getFilename() const;
     431             :   inline StringRef getDirectory() const;
     432             : 
     433             :   StringRef getName() const;
     434             :   DIScopeRef getScope() const;
     435             : 
     436             :   /// Return the raw underlying file.
     437             :   ///
     438             :   /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
     439             :   /// \em is the file).  If \c this is an \a DIFile, we need to return \c this.
     440             :   /// Otherwise, return the first operand, which is where all other subclasses
     441             :   /// store their file pointer.
     442             :   Metadata *getRawFile() const {
     443     7230214 :     return isa<DIFile>(this) ? const_cast<DIScope *>(this)
     444     7239686 :                              : static_cast<Metadata *>(getOperand(0));
     445             :   }
     446             : 
     447             :   static bool classof(const Metadata *MD) {
     448       29178 :     switch (MD->getMetadataID()) {
     449             :     default:
     450             :       return false;
     451             :     case DIBasicTypeKind:
     452             :     case DIDerivedTypeKind:
     453             :     case DICompositeTypeKind:
     454             :     case DISubroutineTypeKind:
     455             :     case DIFileKind:
     456             :     case DICompileUnitKind:
     457             :     case DISubprogramKind:
     458             :     case DILexicalBlockKind:
     459             :     case DILexicalBlockFileKind:
     460             :     case DINamespaceKind:
     461             :     case DIModuleKind:
     462             :       return true;
     463             :     }
     464             :   }
     465             : };
     466             : 
     467             : /// File.
     468             : ///
     469             : /// TODO: Merge with directory/file node (including users).
     470             : /// TODO: Canonicalize paths on creation.
     471             : class DIFile : public DIScope {
     472             :   friend class LLVMContextImpl;
     473             :   friend class MDNode;
     474             : 
     475             : public:
     476             :   enum ChecksumKind {
     477             :     CSK_None,
     478             :     CSK_MD5,
     479             :     CSK_SHA1,
     480             :     CSK_Last = CSK_SHA1 // Should be last enumeration.
     481             :   };
     482             : 
     483             : private:
     484             :   ChecksumKind CSKind;
     485             : 
     486             :   DIFile(LLVMContext &C, StorageType Storage, ChecksumKind CSK,
     487             :          ArrayRef<Metadata *> Ops)
     488        6048 :       : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
     489       12096 :         CSKind(CSK) {}
     490        5962 :   ~DIFile() = default;
     491             : 
     492        8243 :   static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
     493             :                          StringRef Directory, ChecksumKind CSK, StringRef CS,
     494             :                          StorageType Storage, bool ShouldCreate = true) {
     495       32972 :     return getImpl(Context, getCanonicalMDString(Context, Filename),
     496             :                    getCanonicalMDString(Context, Directory), CSK,
     497        8243 :                    getCanonicalMDString(Context, CS), Storage, ShouldCreate);
     498             :   }
     499             :   static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
     500             :                          MDString *Directory, ChecksumKind CSK, MDString *CS,
     501             :                          StorageType Storage, bool ShouldCreate = true);
     502             : 
     503           1 :   TempDIFile cloneImpl() const {
     504             :     return getTemporary(getContext(), getFilename(), getDirectory(),
     505           5 :                         getChecksumKind(), getChecksum());
     506             :   }
     507             : 
     508             : public:
     509        8244 :   DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory,
     510             :                              ChecksumKind CSK = CSK_None,
     511             :                              StringRef CS = StringRef()),
     512             :                     (Filename, Directory, CSK, CS))
     513        2542 :   DEFINE_MDNODE_GET(DIFile, (MDString *Filename, MDString *Directory,
     514             :                              ChecksumKind CSK = CSK_None,
     515             :                              MDString *CS = nullptr),
     516             :                     (Filename, Directory, CSK, CS))
     517             : 
     518           1 :   TempDIFile clone() const { return cloneImpl(); }
     519             : 
     520     2761675 :   StringRef getFilename() const { return getStringOperand(0); }
     521      648402 :   StringRef getDirectory() const { return getStringOperand(1); }
     522       10777 :   StringRef getChecksum() const { return getStringOperand(2); }
     523             :   ChecksumKind getChecksumKind() const { return CSKind; }
     524             :   StringRef getChecksumKindAsString() const;
     525             : 
     526       28534 :   MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
     527       24652 :   MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
     528       24650 :   MDString *getRawChecksum() const { return getOperandAs<MDString>(2); }
     529             : 
     530             :   static ChecksumKind getChecksumKind(StringRef CSKindStr);
     531             : 
     532             :   static bool classof(const Metadata *MD) {
     533     3692332 :     return MD->getMetadataID() == DIFileKind;
     534             :   }
     535             : };
     536             : 
     537     2755347 : StringRef DIScope::getFilename() const {
     538     2755347 :   if (auto *F = getFile())
     539             :     return F->getFilename();
     540        7526 :   return "";
     541             : }
     542             : 
     543      647142 : StringRef DIScope::getDirectory() const {
     544      647142 :   if (auto *F = getFile())
     545             :     return F->getDirectory();
     546        7483 :   return "";
     547             : }
     548             : 
     549             : /// Base class for types.
     550             : ///
     551             : /// TODO: Remove the hardcoded name and context, since many types don't use
     552             : /// them.
     553             : /// TODO: Split up flags.
     554             : class DIType : public DIScope {
     555             :   unsigned Line;
     556             :   DIFlags Flags;
     557             :   uint64_t SizeInBits;
     558             :   uint64_t OffsetInBits;
     559             :   uint32_t AlignInBits;
     560             : 
     561             : protected:
     562             :   DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
     563             :          unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
     564             :          uint64_t OffsetInBits, DIFlags Flags, ArrayRef<Metadata *> Ops)
     565      119942 :       : DIScope(C, ID, Storage, Tag, Ops) {
     566       59971 :     init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
     567             :   }
     568       48392 :   ~DIType() = default;
     569             : 
     570             :   void init(unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
     571             :             uint64_t OffsetInBits, DIFlags Flags) {
     572       59975 :     this->Line = Line;
     573       59975 :     this->Flags = Flags;
     574       59975 :     this->SizeInBits = SizeInBits;
     575       59975 :     this->AlignInBits = AlignInBits;
     576       59975 :     this->OffsetInBits = OffsetInBits;
     577             :   }
     578             : 
     579             :   /// Change fields in place.
     580             :   void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits,
     581             :               uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags) {
     582             :     assert(isDistinct() && "Only distinct nodes can mutate");
     583           8 :     setTag(Tag);
     584           4 :     init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
     585             :   }
     586             : 
     587             : public:
     588             :   TempDIType clone() const {
     589       66865 :     return TempDIType(cast<DIType>(MDNode::clone().release()));
     590             :   }
     591             : 
     592             :   unsigned getLine() const { return Line; }
     593             :   uint64_t getSizeInBits() const { return SizeInBits; }
     594             :   uint32_t getAlignInBits() const { return AlignInBits; }
     595        6011 :   uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
     596             :   uint64_t getOffsetInBits() const { return OffsetInBits; }
     597             :   DIFlags getFlags() const { return Flags; }
     598             : 
     599      110815 :   DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
     600       64864 :   StringRef getName() const { return getStringOperand(2); }
     601             : 
     602             : 
     603      766368 :   Metadata *getRawScope() const { return getOperand(1); }
     604      273732 :   MDString *getRawName() const { return getOperandAs<MDString>(2); }
     605             : 
     606             :   void setFlags(DIFlags NewFlags) {
     607             :     assert(!isUniqued() && "Cannot set flags on uniqued nodes");
     608       13376 :     Flags = NewFlags;
     609             :   }
     610             : 
     611             :   bool isPrivate() const {
     612        6746 :     return (getFlags() & FlagAccessibility) == FlagPrivate;
     613             :   }
     614             :   bool isProtected() const {
     615        7036 :     return (getFlags() & FlagAccessibility) == FlagProtected;
     616             :   }
     617             :   bool isPublic() const {
     618        6510 :     return (getFlags() & FlagAccessibility) == FlagPublic;
     619             :   }
     620       49698 :   bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
     621        4784 :   bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
     622       55650 :   bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; }
     623        7336 :   bool isVirtual() const { return getFlags() & FlagVirtual; }
     624       78376 :   bool isArtificial() const { return getFlags() & FlagArtificial; }
     625       51700 :   bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
     626             :   bool isObjcClassComplete() const {
     627        4876 :     return getFlags() & FlagObjcClassComplete;
     628             :   }
     629         442 :   bool isVector() const { return getFlags() & FlagVector; }
     630         164 :   bool isBitField() const { return getFlags() & FlagBitField; }
     631        7220 :   bool isStaticMember() const { return getFlags() & FlagStaticMember; }
     632         238 :   bool isLValueReference() const { return getFlags() & FlagLValueReference; }
     633         238 :   bool isRValueReference() const { return getFlags() & FlagRValueReference; }
     634             : 
     635             :   static bool classof(const Metadata *MD) {
     636      323710 :     switch (MD->getMetadataID()) {
     637             :     default:
     638             :       return false;
     639             :     case DIBasicTypeKind:
     640             :     case DIDerivedTypeKind:
     641             :     case DICompositeTypeKind:
     642             :     case DISubroutineTypeKind:
     643             :       return true;
     644             :     }
     645             :   }
     646             : };
     647             : 
     648             : /// Basic type, like 'int' or 'float'.
     649             : ///
     650             : /// TODO: Split out DW_TAG_unspecified_type.
     651             : /// TODO: Drop unused accessors.
     652             : class DIBasicType : public DIType {
     653             :   friend class LLVMContextImpl;
     654             :   friend class MDNode;
     655             : 
     656             :   unsigned Encoding;
     657             : 
     658             :   DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
     659             :               uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
     660             :               ArrayRef<Metadata *> Ops)
     661        2215 :       : DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
     662             :                FlagZero, Ops),
     663        4430 :         Encoding(Encoding) {}
     664        3492 :   ~DIBasicType() = default;
     665             : 
     666         997 :   static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
     667             :                               StringRef Name, uint64_t SizeInBits,
     668             :                               uint32_t AlignInBits, unsigned Encoding,
     669             :                               StorageType Storage, bool ShouldCreate = true) {
     670        1994 :     return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
     671         997 :                    SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
     672             :   }
     673             :   static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
     674             :                               MDString *Name, uint64_t SizeInBits,
     675             :                               uint32_t AlignInBits, unsigned Encoding,
     676             :                               StorageType Storage, bool ShouldCreate = true);
     677             : 
     678           2 :   TempDIBasicType cloneImpl() const {
     679             :     return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
     680          10 :                         getAlignInBits(), getEncoding());
     681             :   }
     682             : 
     683             : public:
     684          58 :   DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
     685             :                     (Tag, Name, 0, 0, 0))
     686         941 :   DEFINE_MDNODE_GET(DIBasicType,
     687             :                     (unsigned Tag, StringRef Name, uint64_t SizeInBits,
     688             :                      uint32_t AlignInBits, unsigned Encoding),
     689             :                     (Tag, Name, SizeInBits, AlignInBits, Encoding))
     690        1258 :   DEFINE_MDNODE_GET(DIBasicType,
     691             :                     (unsigned Tag, MDString *Name, uint64_t SizeInBits,
     692             :                      uint32_t AlignInBits, unsigned Encoding),
     693             :                     (Tag, Name, SizeInBits, AlignInBits, Encoding))
     694             : 
     695           1 :   TempDIBasicType clone() const { return cloneImpl(); }
     696             : 
     697             :   unsigned getEncoding() const { return Encoding; }
     698             : 
     699             :   static bool classof(const Metadata *MD) {
     700       14866 :     return MD->getMetadataID() == DIBasicTypeKind;
     701             :   }
     702             : };
     703             : 
     704             : /// Derived types.
     705             : ///
     706             : /// This includes qualified types, pointers, references, friends, typedefs, and
     707             : /// class members.
     708             : ///
     709             : /// TODO: Split out members (inheritance, fields, methods, etc.).
     710             : class DIDerivedType : public DIType {
     711             :   friend class LLVMContextImpl;
     712             :   friend class MDNode;
     713             : 
     714             :   /// \brief The DWARF address space of the memory pointed to or referenced by a
     715             :   /// pointer or reference type respectively.
     716             :   Optional<unsigned> DWARFAddressSpace;
     717             : 
     718             :   DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
     719             :                 unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
     720             :                 uint64_t OffsetInBits, Optional<unsigned> DWARFAddressSpace,
     721             :                 DIFlags Flags, ArrayRef<Metadata *> Ops)
     722       31604 :       : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits,
     723             :                AlignInBits, OffsetInBits, Flags, Ops),
     724       94812 :         DWARFAddressSpace(DWARFAddressSpace) {}
     725       49920 :   ~DIDerivedType() = default;
     726             : 
     727       41826 :   static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
     728             :                                 StringRef Name, DIFile *File, unsigned Line,
     729             :                                 DIScopeRef Scope, DITypeRef BaseType,
     730             :                                 uint64_t SizeInBits, uint32_t AlignInBits,
     731             :                                 uint64_t OffsetInBits,
     732             :                                 Optional<unsigned> DWARFAddressSpace,
     733             :                                 DIFlags Flags, Metadata *ExtraData,
     734             :                                 StorageType Storage, bool ShouldCreate = true) {
     735      250956 :     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
     736             :                    Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
     737       83652 :                    DWARFAddressSpace, Flags, ExtraData, Storage, ShouldCreate);
     738             :   }
     739             :   static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
     740             :                                 MDString *Name, Metadata *File, unsigned Line,
     741             :                                 Metadata *Scope, Metadata *BaseType,
     742             :                                 uint64_t SizeInBits, uint32_t AlignInBits,
     743             :                                 uint64_t OffsetInBits,
     744             :                                 Optional<unsigned> DWARFAddressSpace,
     745             :                                 DIFlags Flags, Metadata *ExtraData,
     746             :                                 StorageType Storage, bool ShouldCreate = true);
     747             : 
     748       13375 :   TempDIDerivedType cloneImpl() const {
     749             :     return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
     750             :                         getScope(), getBaseType(), getSizeInBits(),
     751             :                         getAlignInBits(), getOffsetInBits(),
     752      120375 :                         getDWARFAddressSpace(), getFlags(), getExtraData());
     753             :   }
     754             : 
     755             : public:
     756        3524 :   DEFINE_MDNODE_GET(DIDerivedType,
     757             :                     (unsigned Tag, MDString *Name, Metadata *File,
     758             :                      unsigned Line, Metadata *Scope, Metadata *BaseType,
     759             :                      uint64_t SizeInBits, uint32_t AlignInBits,
     760             :                      uint64_t OffsetInBits,
     761             :                      Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
     762             :                      Metadata *ExtraData = nullptr),
     763             :                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
     764             :                      AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
     765             :                      ExtraData))
     766      110402 :   DEFINE_MDNODE_GET(DIDerivedType,
     767             :                     (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
     768             :                      DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
     769             :                      uint32_t AlignInBits, uint64_t OffsetInBits,
     770             :                      Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
     771             :                      Metadata *ExtraData = nullptr),
     772             :                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
     773             :                      AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
     774             :                      ExtraData))
     775             : 
     776           1 :   TempDIDerivedType clone() const { return cloneImpl(); }
     777             : 
     778             :   /// Get the base type this is derived from.
     779       33771 :   DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
     780      411864 :   Metadata *getRawBaseType() const { return getOperand(3); }
     781             : 
     782             :   /// \returns The DWARF address space of the memory pointed to or referenced by
     783             :   /// a pointer or reference type respectively.
     784      237936 :   Optional<unsigned> getDWARFAddressSpace() const { return DWARFAddressSpace; }
     785             : 
     786             :   /// Get extra data associated with this derived type.
     787             :   ///
     788             :   /// Class type for pointer-to-members, objective-c property node for ivars,
     789             :   /// or global constant wrapper for static members.
     790             :   ///
     791             :   /// TODO: Separate out types that need this extra operand: pointer-to-member
     792             :   /// types and member fields (static members and ivars).
     793       17315 :   Metadata *getExtraData() const { return getRawExtraData(); }
     794      311568 :   Metadata *getRawExtraData() const { return getOperand(4); }
     795             : 
     796             :   /// Get casted version of extra data.
     797             :   /// @{
     798             :   DITypeRef getClassType() const {
     799             :     assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
     800          34 :     return DITypeRef(getExtraData());
     801             :   }
     802             : 
     803             :   DIObjCProperty *getObjCProperty() const {
     804        3293 :     return dyn_cast_or_null<DIObjCProperty>(getExtraData());
     805             :   }
     806             : 
     807             :   Constant *getStorageOffsetInBits() const {
     808             :     assert(getTag() == dwarf::DW_TAG_member && isBitField());
     809          12 :     if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
     810           6 :       return C->getValue();
     811             :     return nullptr;
     812             :   }
     813             : 
     814             :   Constant *getConstant() const {
     815             :     assert(getTag() == dwarf::DW_TAG_member && isStaticMember());
     816         868 :     if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
     817         408 :       return C->getValue();
     818             :     return nullptr;
     819             :   }
     820             :   /// @}
     821             : 
     822             :   static bool classof(const Metadata *MD) {
     823       13891 :     return MD->getMetadataID() == DIDerivedTypeKind;
     824             :   }
     825             : };
     826             : 
     827             : /// Composite types.
     828             : ///
     829             : /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
     830             : /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
     831             : class DICompositeType : public DIType {
     832             :   friend class LLVMContextImpl;
     833             :   friend class MDNode;
     834             : 
     835             :   unsigned RuntimeLang;
     836             : 
     837             :   DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
     838             :                   unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
     839             :                   uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
     840             :                   ArrayRef<Metadata *> Ops)
     841        5197 :       : DIType(C, DICompositeTypeKind, Storage, Tag, Line, SizeInBits,
     842             :                AlignInBits, OffsetInBits, Flags, Ops),
     843       10394 :         RuntimeLang(RuntimeLang) {}
     844        5414 :   ~DICompositeType() = default;
     845             : 
     846             :   /// Change fields in place.
     847             :   void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
     848             :               uint64_t SizeInBits, uint32_t AlignInBits,
     849             :               uint64_t OffsetInBits, DIFlags Flags) {
     850             :     assert(isDistinct() && "Only distinct nodes can mutate");
     851             :     assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
     852           4 :     this->RuntimeLang = RuntimeLang;
     853           8 :     DIType::mutate(Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
     854             :   }
     855             : 
     856             :   static DICompositeType *
     857        4299 :   getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
     858             :           unsigned Line, DIScopeRef Scope, DITypeRef BaseType,
     859             :           uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
     860             :           DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang,
     861             :           DITypeRef VTableHolder, DITemplateParameterArray TemplateParams,
     862             :           StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
     863       25794 :     return getImpl(
     864             :         Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
     865        4299 :         BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
     866        4299 :         RuntimeLang, VTableHolder, TemplateParams.get(),
     867        4299 :         getCanonicalMDString(Context, Identifier), Storage, ShouldCreate);
     868             :   }
     869             :   static DICompositeType *
     870             :   getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
     871             :           unsigned Line, Metadata *Scope, Metadata *BaseType,
     872             :           uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
     873             :           DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
     874             :           Metadata *VTableHolder, Metadata *TemplateParams,
     875             :           MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
     876             : 
     877           2 :   TempDICompositeType cloneImpl() const {
     878             :     return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
     879             :                         getScope(), getBaseType(), getSizeInBits(),
     880             :                         getAlignInBits(), getOffsetInBits(), getFlags(),
     881             :                         getElements(), getRuntimeLang(), getVTableHolder(),
     882          22 :                         getTemplateParams(), getIdentifier());
     883             :   }
     884             : 
     885             : public:
     886        7789 :   DEFINE_MDNODE_GET(DICompositeType,
     887             :                     (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
     888             :                      DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
     889             :                      uint32_t AlignInBits, uint64_t OffsetInBits,
     890             :                      DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang,
     891             :                      DITypeRef VTableHolder,
     892             :                      DITemplateParameterArray TemplateParams = nullptr,
     893             :                      StringRef Identifier = ""),
     894             :                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
     895             :                      AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
     896             :                      VTableHolder, TemplateParams, Identifier))
     897         919 :   DEFINE_MDNODE_GET(DICompositeType,
     898             :                     (unsigned Tag, MDString *Name, Metadata *File,
     899             :                      unsigned Line, Metadata *Scope, Metadata *BaseType,
     900             :                      uint64_t SizeInBits, uint32_t AlignInBits,
     901             :                      uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
     902             :                      unsigned RuntimeLang, Metadata *VTableHolder,
     903             :                      Metadata *TemplateParams = nullptr,
     904             :                      MDString *Identifier = nullptr),
     905             :                     (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
     906             :                      AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
     907             :                      VTableHolder, TemplateParams, Identifier))
     908             : 
     909           1 :   TempDICompositeType clone() const { return cloneImpl(); }
     910             : 
     911             :   /// Get a DICompositeType with the given ODR identifier.
     912             :   ///
     913             :   /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
     914             :   /// DICompositeType for the given ODR \c Identifier.  If none exists, creates
     915             :   /// a new node.
     916             :   ///
     917             :   /// Else, returns \c nullptr.
     918             :   static DICompositeType *
     919             :   getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
     920             :              MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
     921             :              Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
     922             :              uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
     923             :              unsigned RuntimeLang, Metadata *VTableHolder,
     924             :              Metadata *TemplateParams);
     925             :   static DICompositeType *getODRTypeIfExists(LLVMContext &Context,
     926             :                                              MDString &Identifier);
     927             : 
     928             :   /// Build a DICompositeType with the given ODR identifier.
     929             :   ///
     930             :   /// Looks up the mapped DICompositeType for the given ODR \c Identifier.  If
     931             :   /// it doesn't exist, creates a new one.  If it does exist and \a
     932             :   /// isForwardDecl(), and the new arguments would be a definition, mutates the
     933             :   /// the type in place.  In either case, returns the type.
     934             :   ///
     935             :   /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
     936             :   /// nullptr.
     937             :   static DICompositeType *
     938             :   buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
     939             :                MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
     940             :                Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
     941             :                uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
     942             :                unsigned RuntimeLang, Metadata *VTableHolder,
     943             :                Metadata *TemplateParams);
     944             : 
     945         596 :   DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
     946             :   DINodeArray getElements() const {
     947        6462 :     return cast_or_null<MDTuple>(getRawElements());
     948             :   }
     949        2649 :   DITypeRef getVTableHolder() const { return DITypeRef(getRawVTableHolder()); }
     950             :   DITemplateParameterArray getTemplateParams() const {
     951        5298 :     return cast_or_null<MDTuple>(getRawTemplateParams());
     952             :   }
     953        1646 :   StringRef getIdentifier() const { return getStringOperand(7); }
     954             :   unsigned getRuntimeLang() const { return RuntimeLang; }
     955             : 
     956       33888 :   Metadata *getRawBaseType() const { return getOperand(3); }
     957       50352 :   Metadata *getRawElements() const { return getOperand(4); }
     958       39507 :   Metadata *getRawVTableHolder() const { return getOperand(5); }
     959       39495 :   Metadata *getRawTemplateParams() const { return getOperand(6); }
     960      179917 :   MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
     961             : 
     962             :   /// Replace operands.
     963             :   ///
     964             :   /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
     965             :   /// this will be RAUW'ed and deleted.  Use a \a TrackingMDRef to keep track
     966             :   /// of its movement if necessary.
     967             :   /// @{
     968             :   void replaceElements(DINodeArray Elements) {
     969             : #ifndef NDEBUG
     970             :     for (DINode *Op : getElements())
     971             :       assert(is_contained(Elements->operands(), Op) &&
     972             :              "Lost a member during member list replacement");
     973             : #endif
     974        2662 :     replaceOperandWith(4, Elements.get());
     975             :   }
     976             : 
     977             :   void replaceVTableHolder(DITypeRef VTableHolder) {
     978        2406 :     replaceOperandWith(5, VTableHolder);
     979             :   }
     980             : 
     981             :   void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
     982        1558 :     replaceOperandWith(6, TemplateParams.get());
     983             :   }
     984             :   /// @}
     985             : 
     986             :   static bool classof(const Metadata *MD) {
     987       23997 :     return MD->getMetadataID() == DICompositeTypeKind;
     988             :   }
     989             : };
     990             : 
     991             : /// Type array for a subprogram.
     992             : ///
     993             : /// TODO: Fold the array of types in directly as operands.
     994             : class DISubroutineType : public DIType {
     995             :   friend class LLVMContextImpl;
     996             :   friend class MDNode;
     997             : 
     998             :   /// The calling convention used with DW_AT_calling_convention. Actually of
     999             :   /// type dwarf::CallingConvention.
    1000             :   uint8_t CC;
    1001             : 
    1002       20955 :   DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags,
    1003             :                    uint8_t CC, ArrayRef<Metadata *> Ops)
    1004       20955 :       : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type,
    1005             :                0, 0, 0, 0, Flags, Ops),
    1006       41910 :         CC(CC) {}
    1007        6206 :   ~DISubroutineType() = default;
    1008             : 
    1009             :   static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
    1010             :                                    uint8_t CC, DITypeRefArray TypeArray,
    1011             :                                    StorageType Storage,
    1012             :                                    bool ShouldCreate = true) {
    1013       47266 :     return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
    1014             :   }
    1015             :   static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
    1016             :                                    uint8_t CC, Metadata *TypeArray,
    1017             :                                    StorageType Storage,
    1018             :                                    bool ShouldCreate = true);
    1019             : 
    1020           3 :   TempDISubroutineType cloneImpl() const {
    1021           9 :     return getTemporary(getContext(), getFlags(), getCC(), getTypeArray());
    1022             :   }
    1023             : 
    1024             : public:
    1025       94535 :   DEFINE_MDNODE_GET(DISubroutineType,
    1026             :                     (DIFlags Flags, uint8_t CC, DITypeRefArray TypeArray),
    1027             :                     (Flags, CC, TypeArray))
    1028        1727 :   DEFINE_MDNODE_GET(DISubroutineType,
    1029             :                     (DIFlags Flags, uint8_t CC, Metadata *TypeArray),
    1030             :                     (Flags, CC, TypeArray))
    1031             : 
    1032           1 :   TempDISubroutineType clone() const { return cloneImpl(); }
    1033             : 
    1034             :   uint8_t getCC() const { return CC; }
    1035             : 
    1036             :   DITypeRefArray getTypeArray() const {
    1037       82614 :     return cast_or_null<MDTuple>(getRawTypeArray());
    1038             :   }
    1039             : 
    1040      475362 :   Metadata *getRawTypeArray() const { return getOperand(3); }
    1041             : 
    1042             :   static bool classof(const Metadata *MD) {
    1043       13986 :     return MD->getMetadataID() == DISubroutineTypeKind;
    1044             :   }
    1045             : };
    1046             : 
    1047             : /// Compile unit.
    1048             : class DICompileUnit : public DIScope {
    1049             :   friend class LLVMContextImpl;
    1050             :   friend class MDNode;
    1051             : 
    1052             : public:
    1053             :   enum DebugEmissionKind : unsigned {
    1054             :     NoDebug = 0,
    1055             :     FullDebug,
    1056             :     LineTablesOnly,
    1057             :     LastEmissionKind = LineTablesOnly
    1058             :   };
    1059             : 
    1060             :   static Optional<DebugEmissionKind> getEmissionKind(StringRef Str);
    1061             :   static const char *EmissionKindString(DebugEmissionKind EK);
    1062             : 
    1063             : private:
    1064             :   unsigned SourceLanguage;
    1065             :   bool IsOptimized;
    1066             :   unsigned RuntimeVersion;
    1067             :   unsigned EmissionKind;
    1068             :   uint64_t DWOId;
    1069             :   bool SplitDebugInlining;
    1070             :   bool DebugInfoForProfiling;
    1071             :   bool GnuPubnames;
    1072             : 
    1073             :   DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
    1074             :                 bool IsOptimized, unsigned RuntimeVersion,
    1075             :                 unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
    1076             :                 bool DebugInfoForProfiling, bool GnuPubnames, ArrayRef<Metadata *> Ops)
    1077        2545 :       : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
    1078             :         SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
    1079             :         RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
    1080             :         DWOId(DWOId), SplitDebugInlining(SplitDebugInlining),
    1081        5090 :         DebugInfoForProfiling(DebugInfoForProfiling), GnuPubnames(GnuPubnames) {
    1082             :     assert(Storage != Uniqued);
    1083             :   }
    1084        4816 :   ~DICompileUnit() = default;
    1085             : 
    1086             :   static DICompileUnit *
    1087         842 :   getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
    1088             :           StringRef Producer, bool IsOptimized, StringRef Flags,
    1089             :           unsigned RuntimeVersion, StringRef SplitDebugFilename,
    1090             :           unsigned EmissionKind, DICompositeTypeArray EnumTypes,
    1091             :           DIScopeArray RetainedTypes,
    1092             :           DIGlobalVariableExpressionArray GlobalVariables,
    1093             :           DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
    1094             :           uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
    1095             :           bool GnuPubnames, StorageType Storage, bool ShouldCreate = true) {
    1096        3368 :     return getImpl(
    1097             :         Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
    1098             :         IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
    1099             :         getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
    1100        2526 :         EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
    1101        1684 :         ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
    1102         842 :         DebugInfoForProfiling, GnuPubnames, Storage, ShouldCreate);
    1103             :   }
    1104             :   static DICompileUnit *
    1105             :   getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
    1106             :           MDString *Producer, bool IsOptimized, MDString *Flags,
    1107             :           unsigned RuntimeVersion, MDString *SplitDebugFilename,
    1108             :           unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
    1109             :           Metadata *GlobalVariables, Metadata *ImportedEntities,
    1110             :           Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
    1111             :           bool DebugInfoForProfiling, bool GnuPubnames, StorageType Storage,
    1112             :           bool ShouldCreate = true);
    1113             : 
    1114         206 :   TempDICompileUnit cloneImpl() const {
    1115             :     return getTemporary(getContext(), getSourceLanguage(), getFile(),
    1116         206 :                         getProducer(), isOptimized(), getFlags(),
    1117             :                         getRuntimeVersion(), getSplitDebugFilename(),
    1118             :                         getEmissionKind(), getEnumTypes(), getRetainedTypes(),
    1119             :                         getGlobalVariables(), getImportedEntities(),
    1120         412 :                         getMacros(), DWOId, getSplitDebugInlining(),
    1121        2884 :                         getDebugInfoForProfiling(), getGnuPubnames());
    1122             :   }
    1123             : 
    1124             : public:
    1125             :   static void get() = delete;
    1126             :   static void getIfExists() = delete;
    1127             : 
    1128        1048 :   DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
    1129             :       DICompileUnit,
    1130             :       (unsigned SourceLanguage, DIFile *File, StringRef Producer,
    1131             :        bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
    1132             :        StringRef SplitDebugFilename, DebugEmissionKind EmissionKind,
    1133             :        DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
    1134             :        DIGlobalVariableExpressionArray GlobalVariables,
    1135             :        DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
    1136             :        uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
    1137             :        bool GnuPubnames),
    1138             :       (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
    1139             :        SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
    1140             :        GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
    1141             :        DebugInfoForProfiling, GnuPubnames))
    1142        1703 :   DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
    1143             :       DICompileUnit,
    1144             :       (unsigned SourceLanguage, Metadata *File, MDString *Producer,
    1145             :        bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
    1146             :        MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
    1147             :        Metadata *RetainedTypes, Metadata *GlobalVariables,
    1148             :        Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
    1149             :        bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames),
    1150             :       (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
    1151             :        SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
    1152             :        GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
    1153             :        DebugInfoForProfiling, GnuPubnames))
    1154             : 
    1155           1 :   TempDICompileUnit clone() const { return cloneImpl(); }
    1156             : 
    1157             :   unsigned getSourceLanguage() const { return SourceLanguage; }
    1158             :   bool isOptimized() const { return IsOptimized; }
    1159             :   unsigned getRuntimeVersion() const { return RuntimeVersion; }
    1160             :   DebugEmissionKind getEmissionKind() const {
    1161             :     return (DebugEmissionKind)EmissionKind;
    1162             :   }
    1163             :   bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
    1164             :   bool getGnuPubnames() const { return GnuPubnames; }
    1165        1949 :   StringRef getProducer() const { return getStringOperand(1); }
    1166        2034 :   StringRef getFlags() const { return getStringOperand(2); }
    1167        1131 :   StringRef getSplitDebugFilename() const { return getStringOperand(3); }
    1168             :   DICompositeTypeArray getEnumTypes() const {
    1169       10644 :     return cast_or_null<MDTuple>(getRawEnumTypes());
    1170             :   }
    1171             :   DIScopeArray getRetainedTypes() const {
    1172        7822 :     return cast_or_null<MDTuple>(getRawRetainedTypes());
    1173             :   }
    1174             :   DIGlobalVariableExpressionArray getGlobalVariables() const {
    1175        8308 :     return cast_or_null<MDTuple>(getRawGlobalVariables());
    1176             :   }
    1177             :   DIImportedEntityArray getImportedEntities() const {
    1178        8218 :     return cast_or_null<MDTuple>(getRawImportedEntities());
    1179             :   }
    1180             :   DIMacroNodeArray getMacros() const {
    1181        5590 :     return cast_or_null<MDTuple>(getRawMacros());
    1182             :   }
    1183             :   uint64_t getDWOId() const { return DWOId; }
    1184          22 :   void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
    1185             :   bool getSplitDebugInlining() const { return SplitDebugInlining; }
    1186             :   void setSplitDebugInlining(bool SplitDebugInlining) {
    1187             :     this->SplitDebugInlining = SplitDebugInlining;
    1188             :   }
    1189             : 
    1190        1186 :   MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
    1191        1186 :   MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
    1192             :   MDString *getRawSplitDebugFilename() const {
    1193        1186 :     return getOperandAs<MDString>(3);
    1194             :   }
    1195       31710 :   Metadata *getRawEnumTypes() const { return getOperand(4); }
    1196       27477 :   Metadata *getRawRetainedTypes() const { return getOperand(5); }
    1197       28227 :   Metadata *getRawGlobalVariables() const { return getOperand(6); }
    1198       28029 :   Metadata *getRawImportedEntities() const { return getOperand(7); }
    1199       24126 :   Metadata *getRawMacros() const { return getOperand(8); }
    1200             : 
    1201             :   /// Replace arrays.
    1202             :   ///
    1203             :   /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
    1204             :   /// deleted on a uniquing collision.  In practice, uniquing collisions on \a
    1205             :   /// DICompileUnit should be fairly rare.
    1206             :   /// @{
    1207             :   void replaceEnumTypes(DICompositeTypeArray N) {
    1208         611 :     replaceOperandWith(4, N.get());
    1209             :   }
    1210             :   void replaceRetainedTypes(DITypeArray N) {
    1211         116 :     replaceOperandWith(5, N.get());
    1212             :   }
    1213             :   void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
    1214         165 :     replaceOperandWith(6, N.get());
    1215             :   }
    1216             :   void replaceImportedEntities(DIImportedEntityArray N) {
    1217          38 :     replaceOperandWith(7, N.get());
    1218             :   }
    1219           7 :   void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
    1220             :   /// @}
    1221             : 
    1222             :   static bool classof(const Metadata *MD) {
    1223       78573 :     return MD->getMetadataID() == DICompileUnitKind;
    1224             :   }
    1225             : };
    1226             : 
    1227             : /// A scope for locals.
    1228             : ///
    1229             : /// A legal scope for lexical blocks, local variables, and debug info
    1230             : /// locations.  Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
    1231             : /// DILexicalBlockFile.
    1232             : class DILocalScope : public DIScope {
    1233             : protected:
    1234             :   DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
    1235             :                ArrayRef<Metadata *> Ops)
    1236      103790 :       : DIScope(C, ID, Storage, Tag, Ops) {}
    1237       15380 :   ~DILocalScope() = default;
    1238             : 
    1239             : public:
    1240             :   /// Get the subprogram for this scope.
    1241             :   ///
    1242             :   /// Return this if it's an \a DISubprogram; otherwise, look up the scope
    1243             :   /// chain.
    1244             :   DISubprogram *getSubprogram() const;
    1245             : 
    1246             :   /// Get the first non DILexicalBlockFile scope of this scope.
    1247             :   ///
    1248             :   /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
    1249             :   /// scope chain.
    1250             :   DILocalScope *getNonLexicalBlockFileScope() const;
    1251             : 
    1252             :   static bool classof(const Metadata *MD) {
    1253      329419 :     return MD->getMetadataID() == DISubprogramKind ||
    1254      320693 :            MD->getMetadataID() == DILexicalBlockKind ||
    1255       14793 :            MD->getMetadataID() == DILexicalBlockFileKind;
    1256             :   }
    1257             : };
    1258             : 
    1259             : /// Debug location.
    1260             : ///
    1261             : /// A debug location in source code, used for debug info and otherwise.
    1262             : class DILocation : public MDNode {
    1263             :   friend class LLVMContextImpl;
    1264             :   friend class MDNode;
    1265             : 
    1266             :   DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
    1267             :              unsigned Column, ArrayRef<Metadata *> MDs);
    1268       35302 :   ~DILocation() { dropAllReferences(); }
    1269             : 
    1270             :   static DILocation *getImpl(LLVMContext &Context, unsigned Line,
    1271             :                              unsigned Column, Metadata *Scope,
    1272             :                              Metadata *InlinedAt, StorageType Storage,
    1273             :                              bool ShouldCreate = true);
    1274             :   static DILocation *getImpl(LLVMContext &Context, unsigned Line,
    1275             :                              unsigned Column, DILocalScope *Scope,
    1276             :                              DILocation *InlinedAt, StorageType Storage,
    1277             :                              bool ShouldCreate = true) {
    1278             :     return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
    1279      143162 :                    static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
    1280             :   }
    1281             : 
    1282             :   /// With a given unsigned int \p U, use up to 13 bits to represent it.
    1283             :   /// old_bit 1~5  --> new_bit 1~5
    1284             :   /// old_bit 6~12 --> new_bit 7~13
    1285             :   /// new_bit_6 is 0 if higher bits (7~13) are all 0
    1286             :   static unsigned getPrefixEncodingFromUnsigned(unsigned U) {
    1287         298 :     U &= 0xfff;
    1288         298 :     return U > 0x1f ? (((U & 0xfe0) << 1) | (U & 0x1f) | 0x20) : U;
    1289             :   }
    1290             : 
    1291             :   /// Reverse transformation as getPrefixEncodingFromUnsigned.
    1292             :   static unsigned getUnsignedFromPrefixEncoding(unsigned U) {
    1293        1246 :     return (U & 0x20) ? (((U >> 1) & 0xfe0) | (U & 0x1f)) : (U & 0x1f);
    1294             :   }
    1295             : 
    1296             :   /// Returns the next component stored in discriminator.
    1297             :   static unsigned getNextComponentInDiscriminator(unsigned D) {
    1298         330 :     if ((D & 1) == 0)
    1299         214 :       return D >> ((D & 0x40) ? 14 : 7);
    1300             :     else
    1301         116 :       return D >> 1;
    1302             :   }
    1303             : 
    1304         293 :   TempDILocation cloneImpl() const {
    1305             :     // Get the raw scope/inlinedAt since it is possible to invoke this on
    1306             :     // a DILocation containing temporary metadata.
    1307             :     return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
    1308        1465 :                         getRawInlinedAt());
    1309             :   }
    1310             : 
    1311             : public:
    1312             :   // Disallow replacing operands.
    1313             :   void replaceOperandWith(unsigned I, Metadata *New) = delete;
    1314             : 
    1315     2208690 :   DEFINE_MDNODE_GET(DILocation,
    1316             :                     (unsigned Line, unsigned Column, Metadata *Scope,
    1317             :                      Metadata *InlinedAt = nullptr),
    1318             :                     (Line, Column, Scope, InlinedAt))
    1319      143162 :   DEFINE_MDNODE_GET(DILocation,
    1320             :                     (unsigned Line, unsigned Column, DILocalScope *Scope,
    1321             :                      DILocation *InlinedAt = nullptr),
    1322             :                     (Line, Column, Scope, InlinedAt))
    1323             : 
    1324             :   /// Return a (temporary) clone of this.
    1325           1 :   TempDILocation clone() const { return cloneImpl(); }
    1326             : 
    1327             :   unsigned getLine() const { return SubclassData32; }
    1328     5608454 :   unsigned getColumn() const { return SubclassData16; }
    1329    10487468 :   DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
    1330             : 
    1331             :   DILocation *getInlinedAt() const {
    1332     5357814 :     return cast_or_null<DILocation>(getRawInlinedAt());
    1333             :   }
    1334             : 
    1335        2380 :   DIFile *getFile() const { return getScope()->getFile(); }
    1336      737415 :   StringRef getFilename() const { return getScope()->getFilename(); }
    1337      174804 :   StringRef getDirectory() const { return getScope()->getDirectory(); }
    1338             : 
    1339             :   /// Get the scope where this is inlined.
    1340             :   ///
    1341             :   /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
    1342             :   /// location.
    1343             :   DILocalScope *getInlinedAtScope() const {
    1344             :     if (auto *IA = getInlinedAt())
    1345             :       return IA->getInlinedAtScope();
    1346       28388 :     return getScope();
    1347             :   }
    1348             : 
    1349             :   /// Check whether this can be discriminated from another location.
    1350             :   ///
    1351             :   /// Check \c this can be discriminated from \c RHS in a linetable entry.
    1352             :   /// Scope and inlined-at chains are not recorded in the linetable, so they
    1353             :   /// cannot be used to distinguish basic blocks.
    1354       47148 :   bool canDiscriminate(const DILocation &RHS) const {
    1355       91077 :     return getLine() != RHS.getLine() ||
    1356       87567 :            getColumn() != RHS.getColumn() ||
    1357       87276 :            getDiscriminator() != RHS.getDiscriminator() ||
    1358      134420 :            getFilename() != RHS.getFilename() ||
    1359      134420 :            getDirectory() != RHS.getDirectory();
    1360             :   }
    1361             : 
    1362             :   /// Get the DWARF discriminator.
    1363             :   ///
    1364             :   /// DWARF discriminators distinguish identical file locations between
    1365             :   /// instructions that are on different basic blocks.
    1366             :   ///
    1367             :   /// There are 3 components stored in discriminator, from lower bits:
    1368             :   ///
    1369             :   /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
    1370             :   ///                     that are defined by the same source line, but
    1371             :   ///                     different basic blocks.
    1372             :   /// Duplication factor: assigned by optimizations that will scale down
    1373             :   ///                     the execution frequency of the original IR.
    1374             :   /// Copy Identifier: assigned by optimizations that clones the IR.
    1375             :   ///                  Each copy of the IR will be assigned an identifier.
    1376             :   ///
    1377             :   /// Encoding:
    1378             :   ///
    1379             :   /// The above 3 components are encoded into a 32bit unsigned integer in
    1380             :   /// order. If the lowest bit is 1, the current component is empty, and the
    1381             :   /// next component will start in the next bit. Otherwise, the the current
    1382             :   /// component is non-empty, and its content starts in the next bit. The
    1383             :   /// length of each components is either 5 bit or 12 bit: if the 7th bit
    1384             :   /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
    1385             :   /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
    1386             :   /// represent the component.
    1387             : 
    1388             :   inline unsigned getDiscriminator() const;
    1389             : 
    1390             :   /// Returns a new DILocation with updated \p Discriminator.
    1391             :   inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
    1392             : 
    1393             :   /// Returns a new DILocation with updated base discriminator \p BD.
    1394             :   inline const DILocation *setBaseDiscriminator(unsigned BD) const;
    1395             : 
    1396             :   /// Returns the duplication factor stored in the discriminator.
    1397             :   inline unsigned getDuplicationFactor() const;
    1398             : 
    1399             :   /// Returns the copy identifier stored in the discriminator.
    1400             :   inline unsigned getCopyIdentifier() const;
    1401             : 
    1402             :   /// Returns the base discriminator stored in the discriminator.
    1403             :   inline unsigned getBaseDiscriminator() const;
    1404             : 
    1405             :   /// Returns a new DILocation with duplication factor \p DF encoded in the
    1406             :   /// discriminator.
    1407             :   inline const DILocation *cloneWithDuplicationFactor(unsigned DF) const;
    1408             : 
    1409             :   /// When two instructions are combined into a single instruction we also
    1410             :   /// need to combine the original locations into a single location.
    1411             :   ///
    1412             :   /// When the locations are the same we can use either location. When they
    1413             :   /// differ, we need a third location which is distinct from either. If
    1414             :   /// they have the same file/line but have a different discriminator we
    1415             :   /// could create a location with a new discriminator. If they are from
    1416             :   /// different files/lines the location is ambiguous and can't be
    1417             :   /// represented in a single line entry.  In this case, no location
    1418             :   /// should be set.
    1419             :   ///
    1420             :   /// Currently the function does not create a new location. If the locations
    1421             :   /// are the same, or cannot be discriminated, the first location is returned.
    1422             :   /// Otherwise an empty location will be used.
    1423       73751 :   static const DILocation *getMergedLocation(const DILocation *LocA,
    1424             :                                              const DILocation *LocB) {
    1425       73751 :     if (LocA && LocB && (LocA == LocB || !LocA->canDiscriminate(*LocB)))
    1426             :       return LocA;
    1427             :     return nullptr;
    1428             :   }
    1429             : 
    1430             :   /// Returns the base discriminator for a given encoded discriminator \p D.
    1431             :   static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D) {
    1432        1144 :     if ((D & 1) == 0)
    1433        1078 :       return getUnsignedFromPrefixEncoding(D >> 1);
    1434             :     else
    1435             :       return 0;
    1436             :   }
    1437             : 
    1438             :   /// Returns the duplication factor for a given encoded discriminator \p D.
    1439         110 :   static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
    1440         110 :     D = getNextComponentInDiscriminator(D);
    1441         110 :     if (D == 0 || (D & 1))
    1442             :       return 1;
    1443             :     else
    1444          58 :       return getUnsignedFromPrefixEncoding(D >> 1);
    1445             :   }
    1446             : 
    1447             :   /// Returns the copy identifier for a given encoded discriminator \p D.
    1448         110 :   static unsigned getCopyIdentifierFromDiscriminator(unsigned D) {
    1449         220 :     return getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator(
    1450         110 :         getNextComponentInDiscriminator(D)));
    1451             :   }
    1452             : 
    1453             : 
    1454    25607451 :   Metadata *getRawScope() const { return getOperand(0); }
    1455             :   Metadata *getRawInlinedAt() const {
    1456     6936647 :     if (getNumOperands() == 2)
    1457    10905612 :       return getOperand(1);
    1458             :     return nullptr;
    1459             :   }
    1460             : 
    1461             :   static bool classof(const Metadata *MD) {
    1462      121217 :     return MD->getMetadataID() == DILocationKind;
    1463             :   }
    1464             : };
    1465             : 
    1466             : /// Subprogram description.
    1467             : ///
    1468             : /// TODO: Remove DisplayName.  It's always equal to Name.
    1469             : /// TODO: Split up flags.
    1470             : class DISubprogram : public DILocalScope {
    1471             :   friend class LLVMContextImpl;
    1472             :   friend class MDNode;
    1473             : 
    1474             :   unsigned Line;
    1475             :   unsigned ScopeLine;
    1476             :   unsigned VirtualIndex;
    1477             : 
    1478             :   /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
    1479             :   /// of method overrides from secondary bases by this amount. It may be
    1480             :   /// negative.
    1481             :   int ThisAdjustment;
    1482             : 
    1483             :   // Virtuality can only assume three values, so we can pack
    1484             :   // in 2 bits (none/pure/pure_virtual).
    1485             :   unsigned Virtuality : 2;
    1486             : 
    1487             :   // These are boolean flags so one bit is enough.
    1488             :   // MSVC starts a new container field every time the base
    1489             :   // type changes so we can't use 'bool' to ensure these bits
    1490             :   // are packed.
    1491             :   unsigned IsLocalToUnit : 1;
    1492             :   unsigned IsDefinition : 1;
    1493             :   unsigned IsOptimized : 1;
    1494             : 
    1495             :   unsigned Padding : 3;
    1496             : 
    1497             :   DIFlags Flags;
    1498             : 
    1499             :   DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
    1500             :                unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
    1501             :                int ThisAdjustment, DIFlags Flags, bool IsLocalToUnit,
    1502             :                bool IsDefinition, bool IsOptimized, ArrayRef<Metadata *> Ops)
    1503       46964 :       : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram,
    1504             :                      Ops),
    1505             :         Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
    1506             :         ThisAdjustment(ThisAdjustment), Virtuality(Virtuality),
    1507             :         IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition),
    1508       93928 :         IsOptimized(IsOptimized), Flags(Flags) {
    1509             :     static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
    1510             :     assert(Virtuality < 4 && "Virtuality out of range");
    1511             :   }
    1512       11276 :   ~DISubprogram() = default;
    1513             : 
    1514             :   static DISubprogram *
    1515       44457 :   getImpl(LLVMContext &Context, DIScopeRef Scope, StringRef Name,
    1516             :           StringRef LinkageName, DIFile *File, unsigned Line,
    1517             :           DISubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
    1518             :           unsigned ScopeLine, DITypeRef ContainingType, unsigned Virtuality,
    1519             :           unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
    1520             :           bool IsOptimized, DICompileUnit *Unit,
    1521             :           DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
    1522             :           DILocalVariableArray Variables, DITypeArray ThrownTypes,
    1523             :           StorageType Storage, bool ShouldCreate = true) {
    1524      266742 :     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
    1525             :                    getCanonicalMDString(Context, LinkageName), File, Line, Type,
    1526             :                    IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
    1527             :                    Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized,
    1528       88914 :                    Unit, TemplateParams.get(), Declaration, Variables.get(),
    1529       88914 :                    ThrownTypes.get(), Storage, ShouldCreate);
    1530             :   }
    1531             :   static DISubprogram *
    1532             :   getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
    1533             :           MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
    1534             :           bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
    1535             :           Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
    1536             :           int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit,
    1537             :           Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
    1538             :           Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate = true);
    1539             : 
    1540          59 :   TempDISubprogram cloneImpl() const {
    1541             :     return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
    1542          59 :                         getFile(), getLine(), getType(), isLocalToUnit(),
    1543          59 :                         isDefinition(), getScopeLine(), getContainingType(),
    1544             :                         getVirtuality(), getVirtualIndex(), getThisAdjustment(),
    1545          59 :                         getFlags(), isOptimized(), getUnit(),
    1546             :                         getTemplateParams(), getDeclaration(), getVariables(),
    1547        1003 :                         getThrownTypes());
    1548             :   }
    1549             : 
    1550             : public:
    1551       50321 :   DEFINE_MDNODE_GET(DISubprogram,
    1552             :                     (DIScopeRef Scope, StringRef Name, StringRef LinkageName,
    1553             :                      DIFile *File, unsigned Line, DISubroutineType *Type,
    1554             :                      bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
    1555             :                      DITypeRef ContainingType, unsigned Virtuality,
    1556             :                      unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
    1557             :                      bool IsOptimized, DICompileUnit *Unit,
    1558             :                      DITemplateParameterArray TemplateParams = nullptr,
    1559             :                      DISubprogram *Declaration = nullptr,
    1560             :                      DILocalVariableArray Variables = nullptr,
    1561             :                      DITypeArray ThrownTypes = nullptr),
    1562             :                     (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
    1563             :                      IsDefinition, ScopeLine, ContainingType, Virtuality,
    1564             :                      VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
    1565             :                      TemplateParams, Declaration, Variables, ThrownTypes))
    1566        2515 :   DEFINE_MDNODE_GET(
    1567             :       DISubprogram,
    1568             :       (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
    1569             :        unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
    1570             :        unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
    1571             :        unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
    1572             :        bool IsOptimized, Metadata *Unit, Metadata *TemplateParams = nullptr,
    1573             :        Metadata *Declaration = nullptr, Metadata *Variables = nullptr,
    1574             :        Metadata *ThrownTypes = nullptr),
    1575             :       (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
    1576             :        ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment,
    1577             :        Flags, IsOptimized, Unit, TemplateParams, Declaration, Variables,
    1578             :        ThrownTypes))
    1579             : 
    1580           1 :   TempDISubprogram clone() const { return cloneImpl(); }
    1581             : 
    1582             : public:
    1583             :   unsigned getLine() const { return Line; }
    1584       73309 :   unsigned getVirtuality() const { return Virtuality; }
    1585             :   unsigned getVirtualIndex() const { return VirtualIndex; }
    1586             :   int getThisAdjustment() const { return ThisAdjustment; }
    1587             :   unsigned getScopeLine() const { return ScopeLine; }
    1588             :   DIFlags getFlags() const { return Flags; }
    1589       70425 :   bool isLocalToUnit() const { return IsLocalToUnit; }
    1590      328747 :   bool isDefinition() const { return IsDefinition; }
    1591       53289 :   bool isOptimized() const { return IsOptimized; }
    1592             : 
    1593       34806 :   bool isArtificial() const { return getFlags() & FlagArtificial; }
    1594             :   bool isPrivate() const {
    1595       33092 :     return (getFlags() & FlagAccessibility) == FlagPrivate;
    1596             :   }
    1597             :   bool isProtected() const {
    1598       34732 :     return (getFlags() & FlagAccessibility) == FlagProtected;
    1599             :   }
    1600             :   bool isPublic() const {
    1601       32998 :     return (getFlags() & FlagAccessibility) == FlagPublic;
    1602             :   }
    1603       34732 :   bool isExplicit() const { return getFlags() & FlagExplicit; }
    1604       34732 :   bool isPrototyped() const { return getFlags() & FlagPrototyped; }
    1605       34732 :   bool isMainSubprogram() const { return getFlags() & FlagMainSubprogram; }
    1606             : 
    1607             :   /// Check if this is reference-qualified.
    1608             :   ///
    1609             :   /// Return true if this subprogram is a C++11 reference-qualified non-static
    1610             :   /// member function (void foo() &).
    1611       34732 :   bool isLValueReference() const { return getFlags() & FlagLValueReference; }
    1612             : 
    1613             :   /// Check if this is rvalue-reference-qualified.
    1614             :   ///
    1615             :   /// Return true if this subprogram is a C++11 rvalue-reference-qualified
    1616             :   /// non-static member function (void foo() &&).
    1617       34732 :   bool isRValueReference() const { return getFlags() & FlagRValueReference; }
    1618             : 
    1619             :   /// Check if this is marked as noreturn.
    1620             :   ///
    1621             :   /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
    1622       34732 :   bool isNoReturn() const { return getFlags() & FlagNoReturn; }
    1623             : 
    1624       39726 :   DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
    1625             : 
    1626      367766 :   StringRef getName() const { return getStringOperand(2); }
    1627      474186 :   StringRef getLinkageName() const { return getStringOperand(3); }
    1628             : 
    1629             :   DISubroutineType *getType() const {
    1630       46608 :     return cast_or_null<DISubroutineType>(getRawType());
    1631             :   }
    1632             :   DITypeRef getContainingType() const {
    1633         543 :     return DITypeRef(getRawContainingType());
    1634             :   }
    1635             : 
    1636             :   DICompileUnit *getUnit() const {
    1637     4932427 :     return cast_or_null<DICompileUnit>(getRawUnit());
    1638             :   }
    1639           4 :   void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
    1640             :   DITemplateParameterArray getTemplateParams() const {
    1641       21232 :     return cast_or_null<MDTuple>(getRawTemplateParams());
    1642             :   }
    1643             :   DISubprogram *getDeclaration() const {
    1644       86548 :     return cast_or_null<DISubprogram>(getRawDeclaration());
    1645             :   }
    1646             :   DILocalVariableArray getVariables() const {
    1647      193930 :     return cast_or_null<MDTuple>(getRawVariables());
    1648             :   }
    1649             :   DITypeArray getThrownTypes() const {
    1650       17867 :     return cast_or_null<MDTuple>(getRawThrownTypes());
    1651             :   }
    1652             : 
    1653      560535 :   Metadata *getRawScope() const { return getOperand(1); }
    1654      104146 :   MDString *getRawName() const { return getOperandAs<MDString>(2); }
    1655      166854 :   MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
    1656      251862 :   Metadata *getRawType() const { return getOperand(4); }
    1657     7588950 :   Metadata *getRawUnit() const { return getOperand(5); }
    1658      368850 :   Metadata *getRawDeclaration() const { return getOperand(6); }
    1659      472617 :   Metadata *getRawVariables() const { return getOperand(7); }
    1660             :   Metadata *getRawContainingType() const {
    1661       61160 :     return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
    1662             :   }
    1663             :   Metadata *getRawTemplateParams() const {
    1664      111598 :     return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
    1665             :   }
    1666             :   Metadata *getRawThrownTypes() const {
    1667       78419 :     return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
    1668             :   }
    1669             : 
    1670             :   /// Check if this subprogram describes the given function.
    1671             :   ///
    1672             :   /// FIXME: Should this be looking through bitcasts?
    1673             :   bool describes(const Function *F) const;
    1674             : 
    1675             :   static bool classof(const Metadata *MD) {
    1676      460884 :     return MD->getMetadataID() == DISubprogramKind;
    1677             :   }
    1678             : };
    1679             : 
    1680             : class DILexicalBlockBase : public DILocalScope {
    1681             : protected:
    1682             :   DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
    1683             :                      ArrayRef<Metadata *> Ops)
    1684        9862 :       : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
    1685        4104 :   ~DILexicalBlockBase() = default;
    1686             : 
    1687             : public:
    1688      186434 :   DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
    1689             : 
    1690      325020 :   Metadata *getRawScope() const { return getOperand(1); }
    1691             : 
    1692             :   static bool classof(const Metadata *MD) {
    1693     5366909 :     return MD->getMetadataID() == DILexicalBlockKind ||
    1694     1726021 :            MD->getMetadataID() == DILexicalBlockFileKind;
    1695             :   }
    1696             : };
    1697             : 
    1698             : class DILexicalBlock : public DILexicalBlockBase {
    1699             :   friend class LLVMContextImpl;
    1700             :   friend class MDNode;
    1701             : 
    1702             :   unsigned Line;
    1703             :   uint16_t Column;
    1704             : 
    1705             :   DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
    1706             :                  unsigned Column, ArrayRef<Metadata *> Ops)
    1707        4475 :       : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
    1708        8950 :         Column(Column) {
    1709             :     assert(Column < (1u << 16) && "Expected 16-bit column");
    1710             :   }
    1711        3212 :   ~DILexicalBlock() = default;
    1712             : 
    1713             :   static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
    1714             :                                  DIFile *File, unsigned Line, unsigned Column,
    1715             :                                  StorageType Storage,
    1716             :                                  bool ShouldCreate = true) {
    1717             :     return getImpl(Context, static_cast<Metadata *>(Scope),
    1718             :                    static_cast<Metadata *>(File), Line, Column, Storage,
    1719          33 :                    ShouldCreate);
    1720             :   }
    1721             : 
    1722             :   static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
    1723             :                                  Metadata *File, unsigned Line, unsigned Column,
    1724             :                                  StorageType Storage, bool ShouldCreate = true);
    1725             : 
    1726          23 :   TempDILexicalBlock cloneImpl() const {
    1727             :     return getTemporary(getContext(), getScope(), getFile(), getLine(),
    1728         138 :                         getColumn());
    1729             :   }
    1730             : 
    1731             : public:
    1732          56 :   DEFINE_MDNODE_GET(DILexicalBlock, (DILocalScope * Scope, DIFile *File,
    1733             :                                      unsigned Line, unsigned Column),
    1734             :                     (Scope, File, Line, Column))
    1735        4446 :   DEFINE_MDNODE_GET(DILexicalBlock, (Metadata * Scope, Metadata *File,
    1736             :                                      unsigned Line, unsigned Column),
    1737             :                     (Scope, File, Line, Column))
    1738             : 
    1739           1 :   TempDILexicalBlock clone() const { return cloneImpl(); }
    1740             : 
    1741             :   unsigned getLine() const { return Line; }
    1742         663 :   unsigned getColumn() const { return Column; }
    1743             : 
    1744             :   static bool classof(const Metadata *MD) {
    1745          95 :     return MD->getMetadataID() == DILexicalBlockKind;
    1746             :   }
    1747             : };
    1748             : 
    1749             : class DILexicalBlockFile : public DILexicalBlockBase {
    1750             :   friend class LLVMContextImpl;
    1751             :   friend class MDNode;
    1752             : 
    1753             :   unsigned Discriminator;
    1754             : 
    1755             :   DILexicalBlockFile(LLVMContext &C, StorageType Storage,
    1756             :                      unsigned Discriminator, ArrayRef<Metadata *> Ops)
    1757         456 :       : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops),
    1758         912 :         Discriminator(Discriminator) {}
    1759         892 :   ~DILexicalBlockFile() = default;
    1760             : 
    1761             :   static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
    1762             :                                      DIFile *File, unsigned Discriminator,
    1763             :                                      StorageType Storage,
    1764             :                                      bool ShouldCreate = true) {
    1765             :     return getImpl(Context, static_cast<Metadata *>(Scope),
    1766             :                    static_cast<Metadata *>(File), Discriminator, Storage,
    1767           6 :                    ShouldCreate);
    1768             :   }
    1769             : 
    1770             :   static DILexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
    1771             :                                      Metadata *File, unsigned Discriminator,
    1772             :                                      StorageType Storage,
    1773             :                                      bool ShouldCreate = true);
    1774             : 
    1775           1 :   TempDILexicalBlockFile cloneImpl() const {
    1776             :     return getTemporary(getContext(), getScope(), getFile(),
    1777           5 :                         getDiscriminator());
    1778             :   }
    1779             : 
    1780             : public:
    1781           7 :   DEFINE_MDNODE_GET(DILexicalBlockFile, (DILocalScope * Scope, DIFile *File,
    1782             :                                          unsigned Discriminator),
    1783             :                     (Scope, File, Discriminator))
    1784         900 :   DEFINE_MDNODE_GET(DILexicalBlockFile,
    1785             :                     (Metadata * Scope, Metadata *File, unsigned Discriminator),
    1786             :                     (Scope, File, Discriminator))
    1787             : 
    1788           1 :   TempDILexicalBlockFile clone() const { return cloneImpl(); }
    1789             : 
    1790             :   // TODO: Remove these once they're gone from DILexicalBlockBase.
    1791             :   unsigned getLine() const = delete;
    1792             :   unsigned getColumn() const = delete;
    1793             : 
    1794             :   unsigned getDiscriminator() const { return Discriminator; }
    1795             : 
    1796             :   static bool classof(const Metadata *MD) {
    1797     3248549 :     return MD->getMetadataID() == DILexicalBlockFileKind;
    1798             :   }
    1799             : };
    1800             : 
    1801             : unsigned DILocation::getDiscriminator() const {
    1802      176514 :   if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
    1803             :     return F->getDiscriminator();
    1804             :   return 0;
    1805             : }
    1806             : 
    1807             : const DILocation *
    1808         298 : DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
    1809         298 :   DIScope *Scope = getScope();
    1810             :   // Skip all parent DILexicalBlockFile that already have a discriminator
    1811             :   // assigned. We do not want to have nested DILexicalBlockFiles that have
    1812             :   // mutliple discriminators because only the leaf DILexicalBlockFile's
    1813             :   // dominator will be used.
    1814             :   for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
    1815         357 :        LBF && LBF->getDiscriminator() != 0;
    1816             :        LBF = dyn_cast<DILexicalBlockFile>(Scope))
    1817         118 :     Scope = LBF->getScope();
    1818             :   DILexicalBlockFile *NewScope =
    1819         894 :       DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
    1820         894 :   return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
    1821         298 :                          getInlinedAt());
    1822             : }
    1823             : 
    1824        1144 : unsigned DILocation::getBaseDiscriminator() const {
    1825        2288 :   return getBaseDiscriminatorFromDiscriminator(getDiscriminator());
    1826             : }
    1827             : 
    1828         110 : unsigned DILocation::getDuplicationFactor() const {
    1829         110 :   return getDuplicationFactorFromDiscriminator(getDiscriminator());
    1830             : }
    1831             : 
    1832         110 : unsigned DILocation::getCopyIdentifier() const {
    1833         110 :   return getCopyIdentifierFromDiscriminator(getDiscriminator());
    1834             : }
    1835             : 
    1836         188 : const DILocation *DILocation::setBaseDiscriminator(unsigned D) const {
    1837         188 :   if (D == 0)
    1838             :     return this;
    1839             :   else
    1840         188 :     return cloneWithDiscriminator(getPrefixEncodingFromUnsigned(D) << 1);
    1841             : }
    1842             : 
    1843         110 : const DILocation *DILocation::cloneWithDuplicationFactor(unsigned DF) const {
    1844         110 :   DF *= getDuplicationFactor();
    1845         110 :   if (DF <= 1)
    1846             :     return this;
    1847             : 
    1848         110 :   unsigned BD = getBaseDiscriminator();
    1849         110 :   unsigned CI = getCopyIdentifier() << (DF > 0x1f ? 14 : 7);
    1850         110 :   unsigned D = CI | (getPrefixEncodingFromUnsigned(DF) << 1);
    1851             : 
    1852         110 :   if (BD == 0)
    1853         110 :     D = (D << 1) | 1;
    1854             :   else
    1855           0 :     D = (D << (BD > 0x1f ? 14 : 7)) | (getPrefixEncodingFromUnsigned(BD) << 1);
    1856             : 
    1857         110 :   return cloneWithDiscriminator(D);
    1858             : }
    1859             : 
    1860             : class DINamespace : public DIScope {
    1861             :   friend class LLVMContextImpl;
    1862             :   friend class MDNode;
    1863             : 
    1864             :   unsigned ExportSymbols : 1;
    1865             : 
    1866             :   DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
    1867             :               ArrayRef<Metadata *> Ops)
    1868         388 :       : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace,
    1869             :                 Ops),
    1870         776 :         ExportSymbols(ExportSymbols) {}
    1871         430 :   ~DINamespace() = default;
    1872             : 
    1873        1262 :   static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
    1874             :                               StringRef Name, bool ExportSymbols,
    1875             :                               StorageType Storage, bool ShouldCreate = true) {
    1876        2524 :     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
    1877        1262 :                    ExportSymbols, Storage, ShouldCreate);
    1878             :   }
    1879             :   static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
    1880             :                               MDString *Name, bool ExportSymbols,
    1881             :                               StorageType Storage, bool ShouldCreate = true);
    1882             : 
    1883           1 :   TempDINamespace cloneImpl() const {
    1884             :     return getTemporary(getContext(), getScope(), getName(),
    1885           5 :                         getExportSymbols());
    1886             :   }
    1887             : 
    1888             : public:
    1889        1263 :   DEFINE_MDNODE_GET(DINamespace,
    1890             :                     (DIScope *Scope, StringRef Name, bool ExportSymbols),
    1891             :                     (Scope, Name, ExportSymbols))
    1892         118 :   DEFINE_MDNODE_GET(DINamespace,
    1893             :                     (Metadata *Scope, MDString *Name, bool ExportSymbols),
    1894             :                     (Scope, Name, ExportSymbols))
    1895             : 
    1896           1 :   TempDINamespace clone() const { return cloneImpl(); }
    1897             : 
    1898        1783 :   bool getExportSymbols() const { return ExportSymbols; }
    1899       90316 :   DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
    1900        5212 :   StringRef getName() const { return getStringOperand(2); }
    1901             : 
    1902      141072 :   Metadata *getRawScope() const { return getOperand(1); }
    1903        2938 :   MDString *getRawName() const { return getOperandAs<MDString>(2); }
    1904             : 
    1905             :   static bool classof(const Metadata *MD) {
    1906       62296 :     return MD->getMetadataID() == DINamespaceKind;
    1907             :   }
    1908             : };
    1909             : 
    1910             : /// A (clang) module that has been imported by the compile unit.
    1911             : ///
    1912             : class DIModule : public DIScope {
    1913             :   friend class LLVMContextImpl;
    1914             :   friend class MDNode;
    1915             : 
    1916             :   DIModule(LLVMContext &Context, StorageType Storage, ArrayRef<Metadata *> Ops)
    1917         170 :       : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
    1918         170 :   ~DIModule() = default;
    1919             : 
    1920          61 :   static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
    1921             :                            StringRef Name, StringRef ConfigurationMacros,
    1922             :                            StringRef IncludePath, StringRef ISysRoot,
    1923             :                            StorageType Storage, bool ShouldCreate = true) {
    1924         305 :     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
    1925             :                    getCanonicalMDString(Context, ConfigurationMacros),
    1926             :                    getCanonicalMDString(Context, IncludePath),
    1927             :                    getCanonicalMDString(Context, ISysRoot),
    1928          61 :                    Storage, ShouldCreate);
    1929             :   }
    1930             :   static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
    1931             :                            MDString *Name, MDString *ConfigurationMacros,
    1932             :                            MDString *IncludePath, MDString *ISysRoot,
    1933             :                            StorageType Storage, bool ShouldCreate = true);
    1934             : 
    1935           1 :   TempDIModule cloneImpl() const {
    1936             :     return getTemporary(getContext(), getScope(), getName(),
    1937             :                         getConfigurationMacros(), getIncludePath(),
    1938           7 :                         getISysRoot());
    1939             :   }
    1940             : 
    1941             : public:
    1942          62 :   DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name,
    1943             :                                StringRef ConfigurationMacros, StringRef IncludePath,
    1944             :                                StringRef ISysRoot),
    1945             :                     (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
    1946          31 :   DEFINE_MDNODE_GET(DIModule,
    1947             :                     (Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
    1948             :                      MDString *IncludePath, MDString *ISysRoot),
    1949             :                     (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
    1950             : 
    1951           1 :   TempDIModule clone() const { return cloneImpl(); }
    1952             : 
    1953         540 :   DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
    1954         276 :   StringRef getName() const { return getStringOperand(1); }
    1955          71 :   StringRef getConfigurationMacros() const { return getStringOperand(2); }
    1956          85 :   StringRef getIncludePath() const { return getStringOperand(3); }
    1957          90 :   StringRef getISysRoot() const { return getStringOperand(4); }
    1958             : 
    1959        1203 :   Metadata *getRawScope() const { return getOperand(0); }
    1960         186 :   MDString *getRawName() const { return getOperandAs<MDString>(1); }
    1961         186 :   MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
    1962         186 :   MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
    1963         186 :   MDString *getRawISysRoot() const { return getOperandAs<MDString>(4); }
    1964             : 
    1965             :   static bool classof(const Metadata *MD) {
    1966        8112 :     return MD->getMetadataID() == DIModuleKind;
    1967             :   }
    1968             : };
    1969             : 
    1970             : /// Base class for template parameters.
    1971             : class DITemplateParameter : public DINode {
    1972             : protected:
    1973             :   DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
    1974             :                       unsigned Tag, ArrayRef<Metadata *> Ops)
    1975        5092 :       : DINode(Context, ID, Storage, Tag, Ops) {}
    1976        1230 :   ~DITemplateParameter() = default;
    1977             : 
    1978             : public:
    1979        9397 :   StringRef getName() const { return getStringOperand(0); }
    1980        8994 :   DITypeRef getType() const { return DITypeRef(getRawType()); }
    1981             : 
    1982       31782 :   MDString *getRawName() const { return getOperandAs<MDString>(0); }
    1983       60852 :   Metadata *getRawType() const { return getOperand(1); }
    1984             : 
    1985             :   static bool classof(const Metadata *MD) {
    1986        2339 :     return MD->getMetadataID() == DITemplateTypeParameterKind ||
    1987         481 :            MD->getMetadataID() == DITemplateValueParameterKind;
    1988             :   }
    1989             : };
    1990             : 
    1991             : class DITemplateTypeParameter : public DITemplateParameter {
    1992             :   friend class LLVMContextImpl;
    1993             :   friend class MDNode;
    1994             : 
    1995             :   DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
    1996             :                           ArrayRef<Metadata *> Ops)
    1997             :       : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
    1998        3786 :                             dwarf::DW_TAG_template_type_parameter, Ops) {}
    1999         570 :   ~DITemplateTypeParameter() = default;
    2000             : 
    2001        5525 :   static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
    2002             :                                           DITypeRef Type, StorageType Storage,
    2003             :                                           bool ShouldCreate = true) {
    2004       16575 :     return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
    2005        5525 :                    ShouldCreate);
    2006             :   }
    2007             :   static DITemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
    2008             :                                           Metadata *Type, StorageType Storage,
    2009             :                                           bool ShouldCreate = true);
    2010             : 
    2011           2 :   TempDITemplateTypeParameter cloneImpl() const {
    2012          10 :     return getTemporary(getContext(), getName(), getType());
    2013             :   }
    2014             : 
    2015             : public:
    2016        5527 :   DEFINE_MDNODE_GET(DITemplateTypeParameter, (StringRef Name, DITypeRef Type),
    2017             :                     (Name, Type))
    2018          74 :   DEFINE_MDNODE_GET(DITemplateTypeParameter, (MDString * Name, Metadata *Type),
    2019             :                     (Name, Type))
    2020             : 
    2021           1 :   TempDITemplateTypeParameter clone() const { return cloneImpl(); }
    2022             : 
    2023             :   static bool classof(const Metadata *MD) {
    2024        4772 :     return MD->getMetadataID() == DITemplateTypeParameterKind;
    2025             :   }
    2026             : };
    2027             : 
    2028             : class DITemplateValueParameter : public DITemplateParameter {
    2029             :   friend class LLVMContextImpl;
    2030             :   friend class MDNode;
    2031             : 
    2032             :   DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
    2033             :                            unsigned Tag, ArrayRef<Metadata *> Ops)
    2034             :       : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
    2035        1306 :                             Ops) {}
    2036         660 :   ~DITemplateValueParameter() = default;
    2037             : 
    2038        1402 :   static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
    2039             :                                            StringRef Name, DITypeRef Type,
    2040             :                                            Metadata *Value, StorageType Storage,
    2041             :                                            bool ShouldCreate = true) {
    2042        4206 :     return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
    2043        1402 :                    Value, Storage, ShouldCreate);
    2044             :   }
    2045             :   static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
    2046             :                                            MDString *Name, Metadata *Type,
    2047             :                                            Metadata *Value, StorageType Storage,
    2048             :                                            bool ShouldCreate = true);
    2049             : 
    2050           2 :   TempDITemplateValueParameter cloneImpl() const {
    2051             :     return getTemporary(getContext(), getTag(), getName(), getType(),
    2052          12 :                         getValue());
    2053             :   }
    2054             : 
    2055             : public:
    2056        1404 :   DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, StringRef Name,
    2057             :                                                DITypeRef Type, Metadata *Value),
    2058             :                     (Tag, Name, Type, Value))
    2059          78 :   DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, MDString *Name,
    2060             :                                                Metadata *Type, Metadata *Value),
    2061             :                     (Tag, Name, Type, Value))
    2062             : 
    2063           1 :   TempDITemplateValueParameter clone() const { return cloneImpl(); }
    2064             : 
    2065       10365 :   Metadata *getValue() const { return getOperand(2); }
    2066             : 
    2067             :   static bool classof(const Metadata *MD) {
    2068         838 :     return MD->getMetadataID() == DITemplateValueParameterKind;
    2069             :   }
    2070             : };
    2071             : 
    2072             : /// Base class for variables.
    2073             : class DIVariable : public DINode {
    2074             :   unsigned Line;
    2075             :   uint32_t AlignInBits;
    2076             : 
    2077             : protected:
    2078             :   DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line,
    2079             :              ArrayRef<Metadata *> Ops, uint32_t AlignInBits = 0)
    2080       15636 :       : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
    2081       31272 :         AlignInBits(AlignInBits) {}
    2082       11712 :   ~DIVariable() = default;
    2083             : 
    2084             : public:
    2085             :   unsigned getLine() const { return Line; }
    2086      102576 :   DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
    2087       15431 :   StringRef getName() const { return getStringOperand(1); }
    2088        2302 :   DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
    2089       39454 :   DITypeRef getType() const { return DITypeRef(getRawType()); }
    2090             :   uint32_t getAlignInBits() const { return AlignInBits; }
    2091        8484 :   uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
    2092             : 
    2093         418 :   StringRef getFilename() const {
    2094         418 :     if (auto *F = getFile())
    2095             :       return F->getFilename();
    2096           3 :     return "";
    2097             :   }
    2098             : 
    2099         418 :   StringRef getDirectory() const {
    2100         418 :     if (auto *F = getFile())
    2101             :       return F->getDirectory();
    2102           3 :     return "";
    2103             :   }
    2104             : 
    2105      410673 :   Metadata *getRawScope() const { return getOperand(0); }
    2106       71152 :   MDString *getRawName() const { return getOperandAs<MDString>(1); }
    2107      146307 :   Metadata *getRawFile() const { return getOperand(2); }
    2108      266730 :   Metadata *getRawType() const { return getOperand(3); }
    2109             : 
    2110             :   static bool classof(const Metadata *MD) {
    2111             :     return MD->getMetadataID() == DILocalVariableKind ||
    2112             :            MD->getMetadataID() == DIGlobalVariableKind;
    2113             :   }
    2114             : };
    2115             : 
    2116             : /// DWARF expression.
    2117             : ///
    2118             : /// This is (almost) a DWARF expression that modifies the location of a
    2119             : /// variable, or the location of a single piece of a variable, or (when using
    2120             : /// DW_OP_stack_value) is the constant variable value.
    2121             : ///
    2122             : /// TODO: Co-allocate the expression elements.
    2123             : /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
    2124             : /// storage types.
    2125             : class DIExpression : public MDNode {
    2126             :   friend class LLVMContextImpl;
    2127             :   friend class MDNode;
    2128             : 
    2129             :   std::vector<uint64_t> Elements;
    2130             : 
    2131        1849 :   DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
    2132        1849 :       : MDNode(C, DIExpressionKind, Storage, None),
    2133       12943 :         Elements(Elements.begin(), Elements.end()) {}
    2134        4539 :   ~DIExpression() = default;
    2135             : 
    2136             :   static DIExpression *getImpl(LLVMContext &Context,
    2137             :                                ArrayRef<uint64_t> Elements, StorageType Storage,
    2138             :                                bool ShouldCreate = true);
    2139             : 
    2140           1 :   TempDIExpression cloneImpl() const {
    2141           3 :     return getTemporary(getContext(), getElements());
    2142             :   }
    2143             : 
    2144             : public:
    2145       18594 :   DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
    2146             : 
    2147           1 :   TempDIExpression clone() const { return cloneImpl(); }
    2148             : 
    2149      550120 :   ArrayRef<uint64_t> getElements() const { return Elements; }
    2150             : 
    2151       24012 :   unsigned getNumElements() const { return Elements.size(); }
    2152             : 
    2153             :   uint64_t getElement(unsigned I) const {
    2154             :     assert(I < Elements.size() && "Index out of range");
    2155          62 :     return Elements[I];
    2156             :   }
    2157             : 
    2158             :   /// Determine whether this represents a standalone constant value.
    2159             :   bool isConstant() const;
    2160             : 
    2161             :   using element_iterator = ArrayRef<uint64_t>::iterator;
    2162             : 
    2163      127829 :   element_iterator elements_begin() const { return getElements().begin(); }
    2164      127866 :   element_iterator elements_end() const { return getElements().end(); }
    2165             : 
    2166             :   /// A lightweight wrapper around an expression operand.
    2167             :   ///
    2168             :   /// TODO: Store arguments directly and change \a DIExpression to store a
    2169             :   /// range of these.
    2170             :   class ExprOperand {
    2171             :     const uint64_t *Op = nullptr;
    2172             : 
    2173             :   public:
    2174       52636 :     ExprOperand() = default;
    2175         890 :     explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
    2176             : 
    2177      337818 :     const uint64_t *get() const { return Op; }
    2178             : 
    2179             :     /// Get the operand code.
    2180       59487 :     uint64_t getOp() const { return *Op; }
    2181             : 
    2182             :     /// Get an argument to the operand.
    2183             :     ///
    2184             :     /// Never returns the operand itself.
    2185        7299 :     uint64_t getArg(unsigned I) const { return Op[I + 1]; }
    2186             : 
    2187        2415 :     unsigned getNumArgs() const { return getSize() - 1; }
    2188             : 
    2189             :     /// Return the size of the operand.
    2190             :     ///
    2191             :     /// Return the number of elements in the operand (1 + args).
    2192             :     unsigned getSize() const;
    2193             :   };
    2194             : 
    2195             :   /// An iterator for expression operands.
    2196             :   class expr_op_iterator
    2197             :       : public std::iterator<std::input_iterator_tag, ExprOperand> {
    2198             :     ExprOperand Op;
    2199             : 
    2200             :   public:
    2201      105876 :     expr_op_iterator() = default;
    2202      256401 :     explicit expr_op_iterator(element_iterator I) : Op(I) {}
    2203             : 
    2204      726485 :     element_iterator getBase() const { return Op.get(); }
    2205             :     const ExprOperand &operator*() const { return Op; }
    2206             :     const ExprOperand *operator->() const { return &Op; }
    2207             : 
    2208             :     expr_op_iterator &operator++() {
    2209       19998 :       increment();
    2210             :       return *this;
    2211             :     }
    2212             :     expr_op_iterator operator++(int) {
    2213        2601 :       expr_op_iterator T(*this);
    2214        2601 :       increment();
    2215             :       return T;
    2216             :     }
    2217             : 
    2218             :     /// Get the next iterator.
    2219             :     ///
    2220             :     /// \a std::next() doesn't work because this is technically an
    2221             :     /// input_iterator, but it's a perfectly valid operation.  This is an
    2222             :     /// accessor to provide the same functionality.
    2223          44 :     expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
    2224             : 
    2225             :     bool operator==(const expr_op_iterator &X) const {
    2226       62902 :       return getBase() == X.getBase();
    2227             :     }
    2228             :     bool operator!=(const expr_op_iterator &X) const {
    2229      303166 :       return getBase() != X.getBase();
    2230             :     }
    2231             : 
    2232             :   private:
    2233       22599 :     void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
    2234             :   };
    2235             : 
    2236             :   /// Visit the elements via ExprOperand wrappers.
    2237             :   ///
    2238             :   /// These range iterators visit elements through \a ExprOperand wrappers.
    2239             :   /// This is not guaranteed to be a valid range unless \a isValid() gives \c
    2240             :   /// true.
    2241             :   ///
    2242             :   /// \pre \a isValid() gives \c true.
    2243             :   /// @{
    2244             :   expr_op_iterator expr_op_begin() const {
    2245      254584 :     return expr_op_iterator(elements_begin());
    2246             :   }
    2247             :   expr_op_iterator expr_op_end() const {
    2248      254658 :     return expr_op_iterator(elements_end());
    2249             :   }
    2250             :   iterator_range<expr_op_iterator> expr_ops() const {
    2251       10773 :     return {expr_op_begin(), expr_op_end()};
    2252             :   }
    2253             :   /// @}
    2254             : 
    2255             :   bool isValid() const;
    2256             : 
    2257             :   static bool classof(const Metadata *MD) {
    2258      266506 :     return MD->getMetadataID() == DIExpressionKind;
    2259             :   }
    2260             : 
    2261             :   /// Return whether the first element a DW_OP_deref.
    2262             :   bool startsWithDeref() const {
    2263           8 :     return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
    2264             :   }
    2265             : 
    2266             :   /// Holds the characteristics of one fragment of a larger variable.
    2267             :   struct FragmentInfo {
    2268             :     uint64_t SizeInBits;
    2269             :     uint64_t OffsetInBits;
    2270             :   };
    2271             : 
    2272             :   /// Retrieve the details of this fragment expression.
    2273             :   static Optional<FragmentInfo> getFragmentInfo(expr_op_iterator Start,
    2274             :                                                 expr_op_iterator End);
    2275             : 
    2276             :   /// Retrieve the details of this fragment expression.
    2277             :   Optional<FragmentInfo> getFragmentInfo() const {
    2278      151794 :     return getFragmentInfo(expr_op_begin(), expr_op_end());
    2279             :   }
    2280             : 
    2281             :   /// Return whether this is a piece of an aggregate variable.
    2282      127002 :   bool isFragment() const { return getFragmentInfo().hasValue(); }
    2283             : 
    2284             :   /// Append \p Ops with operations to apply the \p Offset.
    2285             :   static void appendOffset(SmallVectorImpl<uint64_t> &Ops, int64_t Offset);
    2286             : 
    2287             :   /// If this is a constant offset, extract it. If there is no expression,
    2288             :   /// return true with an offset of zero.
    2289             :   bool extractIfOffset(int64_t &Offset) const;
    2290             : 
    2291             :   /// Constants for DIExpression::prepend.
    2292             :   enum { NoDeref = false, WithDeref = true, WithStackValue = true };
    2293             : 
    2294             :   /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
    2295             :   /// into a stack value.
    2296             :   static DIExpression *prepend(const DIExpression *DIExpr, bool Deref,
    2297             :                                int64_t Offset = 0, bool StackValue = false);
    2298             : 
    2299             :   /// Create a DIExpression to describe one part of an aggregate variable that
    2300             :   /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
    2301             :   /// will be appended to the elements of \c Expr. If \c Expr already contains
    2302             :   /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
    2303             :   /// into the existing fragment.
    2304             :   ///
    2305             :   /// \param OffsetInBits Offset of the piece in bits.
    2306             :   /// \param SizeInBits   Size of the piece in bits.
    2307             :   static DIExpression *createFragmentExpression(const DIExpression *Exp,
    2308             :                                                 unsigned OffsetInBits,
    2309             :                                                 unsigned SizeInBits);
    2310             : };
    2311             : 
    2312             : /// Global variables.
    2313             : ///
    2314             : /// TODO: Remove DisplayName.  It's always equal to Name.
    2315             : class DIGlobalVariable : public DIVariable {
    2316             :   friend class LLVMContextImpl;
    2317             :   friend class MDNode;
    2318             : 
    2319             :   bool IsLocalToUnit;
    2320             :   bool IsDefinition;
    2321             : 
    2322             :   DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
    2323             :                    bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
    2324             :                    ArrayRef<Metadata *> Ops)
    2325        1148 :       : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
    2326        2296 :         IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
    2327        1942 :   ~DIGlobalVariable() = default;
    2328             : 
    2329         541 :   static DIGlobalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
    2330             :                                    StringRef Name, StringRef LinkageName,
    2331             :                                    DIFile *File, unsigned Line, DITypeRef Type,
    2332             :                                    bool IsLocalToUnit, bool IsDefinition,
    2333             :                                    DIDerivedType *StaticDataMemberDeclaration,
    2334             :                                    uint32_t AlignInBits, StorageType Storage,
    2335             :                                    bool ShouldCreate = true) {
    2336        2164 :     return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
    2337             :                    getCanonicalMDString(Context, LinkageName), File, Line, Type,
    2338             :                    IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration,
    2339         541 :                    AlignInBits, Storage, ShouldCreate);
    2340             :   }
    2341             :   static DIGlobalVariable *
    2342             :   getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
    2343             :           MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
    2344             :           bool IsLocalToUnit, bool IsDefinition,
    2345             :           Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits,
    2346             :           StorageType Storage, bool ShouldCreate = true);
    2347             : 
    2348           2 :   TempDIGlobalVariable cloneImpl() const {
    2349             :     return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
    2350           2 :                         getFile(), getLine(), getType(), isLocalToUnit(),
    2351           2 :                         isDefinition(), getStaticDataMemberDeclaration(),
    2352          22 :                         getAlignInBits());
    2353             :   }
    2354             : 
    2355             : public:
    2356         551 :   DEFINE_MDNODE_GET(DIGlobalVariable,
    2357             :                     (DIScope * Scope, StringRef Name, StringRef LinkageName,
    2358             :                      DIFile *File, unsigned Line, DITypeRef Type,
    2359             :                      bool IsLocalToUnit, bool IsDefinition,
    2360             :                      DIDerivedType *StaticDataMemberDeclaration,
    2361             :                      uint32_t AlignInBits),
    2362             :                     (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
    2363             :                      IsDefinition, StaticDataMemberDeclaration, AlignInBits))
    2364         608 :   DEFINE_MDNODE_GET(DIGlobalVariable,
    2365             :                     (Metadata * Scope, MDString *Name, MDString *LinkageName,
    2366             :                      Metadata *File, unsigned Line, Metadata *Type,
    2367             :                      bool IsLocalToUnit, bool IsDefinition,
    2368             :                      Metadata *StaticDataMemberDeclaration,
    2369             :                      uint32_t AlignInBits),
    2370             :                     (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
    2371             :                      IsDefinition, StaticDataMemberDeclaration, AlignInBits))
    2372             : 
    2373           1 :   TempDIGlobalVariable clone() const { return cloneImpl(); }
    2374             : 
    2375             :   bool isLocalToUnit() const { return IsLocalToUnit; }
    2376             :   bool isDefinition() const { return IsDefinition; }
    2377         417 :   StringRef getDisplayName() const { return getStringOperand(4); }
    2378        1387 :   StringRef getLinkageName() const { return getStringOperand(5); }
    2379             :   DIDerivedType *getStaticDataMemberDeclaration() const {
    2380         976 :     return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration());
    2381             :   }
    2382             : 
    2383        5248 :   MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
    2384       16449 :   Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(6); }
    2385             : 
    2386             :   static bool classof(const Metadata *MD) {
    2387          28 :     return MD->getMetadataID() == DIGlobalVariableKind;
    2388             :   }
    2389             : };
    2390             : 
    2391             : /// Local variable.
    2392             : ///
    2393             : /// TODO: Split up flags.
    2394             : class DILocalVariable : public DIVariable {
    2395             :   friend class LLVMContextImpl;
    2396             :   friend class MDNode;
    2397             : 
    2398             :   unsigned Arg : 16;
    2399             :   DIFlags Flags;
    2400             : 
    2401             :   DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
    2402             :                   unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
    2403             :                   ArrayRef<Metadata *> Ops)
    2404       14488 :       : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
    2405       28976 :         Arg(Arg), Flags(Flags) {
    2406             :     assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
    2407             :   }
    2408        9770 :   ~DILocalVariable() = default;
    2409             : 
    2410       12667 :   static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
    2411             :                                   StringRef Name, DIFile *File, unsigned Line,
    2412             :                                   DITypeRef Type, unsigned Arg, DIFlags Flags,
    2413             :                                   uint32_t AlignInBits, StorageType Storage,
    2414             :                                   bool ShouldCreate = true) {
    2415       38001 :     return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
    2416       12667 :                    Line, Type, Arg, Flags, AlignInBits, Storage, ShouldCreate);
    2417             :   }
    2418             :   static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope,
    2419             :                                   MDString *Name, Metadata *File, unsigned Line,
    2420             :                                   Metadata *Type, unsigned Arg, DIFlags Flags,
    2421             :                                   uint32_t AlignInBits, StorageType Storage,
    2422             :                                   bool ShouldCreate = true);
    2423             : 
    2424          21 :   TempDILocalVariable cloneImpl() const {
    2425             :     return getTemporary(getContext(), getScope(), getName(), getFile(),
    2426             :                         getLine(), getType(), getArg(), getFlags(),
    2427         168 :                         getAlignInBits());
    2428             :   }
    2429             : 
    2430             : public:
    2431       12688 :   DEFINE_MDNODE_GET(DILocalVariable,
    2432             :                     (DILocalScope * Scope, StringRef Name, DIFile *File,
    2433             :                      unsigned Line, DITypeRef Type, unsigned Arg,
    2434             :                      DIFlags Flags, uint32_t AlignInBits),
    2435             :                     (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
    2436        1908 :   DEFINE_MDNODE_GET(DILocalVariable,
    2437             :                     (Metadata * Scope, MDString *Name, Metadata *File,
    2438             :                      unsigned Line, Metadata *Type, unsigned Arg,
    2439             :                      DIFlags Flags, uint32_t AlignInBits),
    2440             :                     (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
    2441             : 
    2442           1 :   TempDILocalVariable clone() const { return cloneImpl(); }
    2443             : 
    2444             :   /// Get the local scope for this variable.
    2445             :   ///
    2446             :   /// Variables must be defined in a local scope.
    2447             :   DILocalScope *getScope() const {
    2448      151119 :     return cast<DILocalScope>(DIVariable::getScope());
    2449             :   }
    2450             : 
    2451       27340 :   bool isParameter() const { return Arg; }
    2452       66553 :   unsigned getArg() const { return Arg; }
    2453             :   DIFlags getFlags() const { return Flags; }
    2454             : 
    2455       16658 :   bool isArtificial() const { return getFlags() & FlagArtificial; }
    2456       32668 :   bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
    2457             : 
    2458             :   /// Check that a location is valid for this variable.
    2459             :   ///
    2460             :   /// Check that \c DL exists, is in the same subprogram, and has the same
    2461             :   /// inlined-at location as \c this.  (Otherwise, it's not a valid attachment
    2462             :   /// to a \a DbgInfoIntrinsic.)
    2463             :   bool isValidLocationForIntrinsic(const DILocation *DL) const {
    2464             :     return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
    2465             :   }
    2466             : 
    2467             :   static bool classof(const Metadata *MD) {
    2468          81 :     return MD->getMetadataID() == DILocalVariableKind;
    2469             :   }
    2470             : };
    2471             : 
    2472             : class DIObjCProperty : public DINode {
    2473             :   friend class LLVMContextImpl;
    2474             :   friend class MDNode;
    2475             : 
    2476             :   unsigned Line;
    2477             :   unsigned Attributes;
    2478             : 
    2479             :   DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
    2480             :                  unsigned Attributes, ArrayRef<Metadata *> Ops)
    2481          92 :       : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
    2482             :                Ops),
    2483         184 :         Line(Line), Attributes(Attributes) {}
    2484         184 :   ~DIObjCProperty() = default;
    2485             : 
    2486             :   static DIObjCProperty *
    2487          86 :   getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
    2488             :           StringRef GetterName, StringRef SetterName, unsigned Attributes,
    2489             :           DITypeRef Type, StorageType Storage, bool ShouldCreate = true) {
    2490         430 :     return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
    2491             :                    getCanonicalMDString(Context, GetterName),
    2492             :                    getCanonicalMDString(Context, SetterName), Attributes, Type,
    2493          86 :                    Storage, ShouldCreate);
    2494             :   }
    2495             :   static DIObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
    2496             :                                  Metadata *File, unsigned Line,
    2497             :                                  MDString *GetterName, MDString *SetterName,
    2498             :                                  unsigned Attributes, Metadata *Type,
    2499             :                                  StorageType Storage, bool ShouldCreate = true);
    2500             : 
    2501           1 :   TempDIObjCProperty cloneImpl() const {
    2502             :     return getTemporary(getContext(), getName(), getFile(), getLine(),
    2503             :                         getGetterName(), getSetterName(), getAttributes(),
    2504           7 :                         getType());
    2505             :   }
    2506             : 
    2507             : public:
    2508          87 :   DEFINE_MDNODE_GET(DIObjCProperty,
    2509             :                     (StringRef Name, DIFile *File, unsigned Line,
    2510             :                      StringRef GetterName, StringRef SetterName,
    2511             :                      unsigned Attributes, DITypeRef Type),
    2512             :                     (Name, File, Line, GetterName, SetterName, Attributes,
    2513             :                      Type))
    2514          39 :   DEFINE_MDNODE_GET(DIObjCProperty,
    2515             :                     (MDString * Name, Metadata *File, unsigned Line,
    2516             :                      MDString *GetterName, MDString *SetterName,
    2517             :                      unsigned Attributes, Metadata *Type),
    2518             :                     (Name, File, Line, GetterName, SetterName, Attributes,
    2519             :                      Type))
    2520             : 
    2521           1 :   TempDIObjCProperty clone() const { return cloneImpl(); }
    2522             : 
    2523             :   unsigned getLine() const { return Line; }
    2524             :   unsigned getAttributes() const { return Attributes; }
    2525          66 :   StringRef getName() const { return getStringOperand(0); }
    2526          76 :   DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
    2527          66 :   StringRef getGetterName() const { return getStringOperand(2); }
    2528          66 :   StringRef getSetterName() const { return getStringOperand(3); }
    2529          37 :   DITypeRef getType() const { return DITypeRef(getRawType()); }
    2530             : 
    2531          10 :   StringRef getFilename() const {
    2532          10 :     if (auto *F = getFile())
    2533             :       return F->getFilename();
    2534           0 :     return "";
    2535             :   }
    2536             : 
    2537          10 :   StringRef getDirectory() const {
    2538          10 :     if (auto *F = getFile())
    2539             :       return F->getDirectory();
    2540           0 :     return "";
    2541             :   }
    2542             : 
    2543         284 :   MDString *getRawName() const { return getOperandAs<MDString>(0); }
    2544         975 :   Metadata *getRawFile() const { return getOperand(1); }
    2545         284 :   MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
    2546         284 :   MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
    2547         972 :   Metadata *getRawType() const { return getOperand(4); }
    2548             : 
    2549             :   static bool classof(const Metadata *MD) {
    2550          10 :     return MD->getMetadataID() == DIObjCPropertyKind;
    2551             :   }
    2552             : };
    2553             : 
    2554             : /// An imported module (C++ using directive or similar).
    2555             : class DIImportedEntity : public DINode {
    2556             :   friend class LLVMContextImpl;
    2557             :   friend class MDNode;
    2558             : 
    2559             :   unsigned Line;
    2560             : 
    2561             :   DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
    2562             :                    unsigned Line, ArrayRef<Metadata *> Ops)
    2563       14050 :       : DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
    2564         298 :   ~DIImportedEntity() = default;
    2565             : 
    2566        6937 :   static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
    2567             :                                    DIScope *Scope, DINodeRef Entity,
    2568             :                                    DIFile *File, unsigned Line, StringRef Name,
    2569             :                                    StorageType Storage,
    2570             :                                    bool ShouldCreate = true) {
    2571       20811 :     return getImpl(Context, Tag, Scope, Entity, File, Line,
    2572        6937 :                    getCanonicalMDString(Context, Name), Storage, ShouldCreate);
    2573             :   }
    2574             :   static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
    2575             :                                    Metadata *Scope, Metadata *Entity,
    2576             :                                    Metadata *File, unsigned Line,
    2577             :                                    MDString *Name, StorageType Storage,
    2578             :                                    bool ShouldCreate = true);
    2579             : 
    2580           1 :   TempDIImportedEntity cloneImpl() const {
    2581             :     return getTemporary(getContext(), getTag(), getScope(), getEntity(),
    2582           7 :                         getFile(), getLine(), getName());
    2583             :   }
    2584             : 
    2585             : public:
    2586        6938 :   DEFINE_MDNODE_GET(DIImportedEntity,
    2587             :                     (unsigned Tag, DIScope *Scope, DINodeRef Entity,
    2588             :                      DIFile *File, unsigned Line, StringRef Name = ""),
    2589             :                     (Tag, Scope, Entity, File, Line, Name))
    2590          94 :   DEFINE_MDNODE_GET(DIImportedEntity,
    2591             :                     (unsigned Tag, Metadata *Scope, Metadata *Entity,
    2592             :                      Metadata *File, unsigned Line, MDString *Name),
    2593             :                     (Tag, Scope, Entity, File, Line, Name))
    2594             : 
    2595           1 :   TempDIImportedEntity clone() const { return cloneImpl(); }
    2596             : 
    2597             :   unsigned getLine() const { return Line; }
    2598       34654 :   DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
    2599        6940 :   DINodeRef getEntity() const { return DINodeRef(getRawEntity()); }
    2600        6988 :   StringRef getName() const { return getStringOperand(2); }
    2601       13842 :   DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
    2602             : 
    2603      147693 :   Metadata *getRawScope() const { return getOperand(0); }
    2604      102078 :   Metadata *getRawEntity() const { return getOperand(1); }
    2605       35710 :   MDString *getRawName() const { return getOperandAs<MDString>(2); }
    2606       74529 :   Metadata *getRawFile() const { return getOperand(3); }
    2607             : 
    2608             :   static bool classof(const Metadata *MD) {
    2609             :     return MD->getMetadataID() == DIImportedEntityKind;
    2610             :   }
    2611             : };
    2612             : 
    2613             : /// A pair of DIGlobalVariable and DIExpression.
    2614             : class DIGlobalVariableExpression : public MDNode {
    2615             :   friend class LLVMContextImpl;
    2616             :   friend class MDNode;
    2617             : 
    2618             :   DIGlobalVariableExpression(LLVMContext &C, StorageType Storage,
    2619             :                              ArrayRef<Metadata *> Ops)
    2620        2238 :       : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
    2621        1892 :   ~DIGlobalVariableExpression() = default;
    2622             : 
    2623             :   static DIGlobalVariableExpression *
    2624             :   getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
    2625             :           StorageType Storage, bool ShouldCreate = true);
    2626             : 
    2627           2 :   TempDIGlobalVariableExpression cloneImpl() const {
    2628           8 :     return getTemporary(getContext(), getVariable(), getExpression());
    2629             :   }
    2630             : 
    2631             : public:
    2632        1123 :   DEFINE_MDNODE_GET(DIGlobalVariableExpression,
    2633             :                     (Metadata * Variable, Metadata *Expression),
    2634             :                     (Variable, Expression))
    2635             : 
    2636           1 :   TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
    2637             : 
    2638       24558 :   Metadata *getRawVariable() const { return getOperand(0); }
    2639             : 
    2640             :   DIGlobalVariable *getVariable() const {
    2641       10182 :     return cast_or_null<DIGlobalVariable>(getRawVariable());
    2642             :   }
    2643             : 
    2644       21246 :   Metadata *getRawExpression() const { return getOperand(1); }
    2645             : 
    2646             :   DIExpression *getExpression() const {
    2647        9108 :     return cast<DIExpression>(getRawExpression());
    2648             :   }
    2649             : 
    2650             :   static bool classof(const Metadata *MD) {
    2651        1385 :     return MD->getMetadataID() == DIGlobalVariableExpressionKind;
    2652             :   }
    2653             : };
    2654             : 
    2655             : /// Macro Info DWARF-like metadata node.
    2656             : ///
    2657             : /// A metadata node with a DWARF macro info (i.e., a constant named
    2658             : /// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h).  Called \a
    2659             : /// DIMacroNode
    2660             : /// because it's potentially used for non-DWARF output.
    2661             : class DIMacroNode : public MDNode {
    2662             :   friend class LLVMContextImpl;
    2663             :   friend class MDNode;
    2664             : 
    2665             : protected:
    2666             :   DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
    2667             :               ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
    2668        1176 :       : MDNode(C, ID, Storage, Ops1, Ops2) {
    2669             :     assert(MIType < 1u << 16);
    2670        1176 :     SubclassData16 = MIType;
    2671             :   }
    2672        2352 :   ~DIMacroNode() = default;
    2673             : 
    2674             :   template <class Ty> Ty *getOperandAs(unsigned I) const {
    2675       30069 :     return cast_or_null<Ty>(getOperand(I));
    2676             :   }
    2677             : 
    2678        4360 :   StringRef getStringOperand(unsigned I) const {
    2679        4360 :     if (auto *S = getOperandAs<MDString>(I))
    2680        4275 :       return S->getString();
    2681          85 :     return StringRef();
    2682             :   }
    2683             : 
    2684             :   static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
    2685        2138 :     if (S.empty())
    2686             :       return nullptr;
    2687        2091 :     return MDString::get(Context, S);
    2688             :   }
    2689             : 
    2690             : public:
    2691        5884 :   unsigned getMacinfoType() const { return SubclassData16; }
    2692             : 
    2693             :   static bool classof(const Metadata *MD) {
    2694        1157 :     switch (MD->getMetadataID()) {
    2695             :     default:
    2696             :       return false;
    2697             :     case DIMacroKind:
    2698             :     case DIMacroFileKind:
    2699             :       return true;
    2700             :     }
    2701             :   }
    2702             : };
    2703             : 
    2704             : class DIMacro : public DIMacroNode {
    2705             :   friend class LLVMContextImpl;
    2706             :   friend class MDNode;
    2707             : 
    2708             :   unsigned Line;
    2709             : 
    2710             :   DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
    2711             :           ArrayRef<Metadata *> Ops)
    2712        2188 :       : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops), Line(Line) {}
    2713        2188 :   ~DIMacro() = default;
    2714             : 
    2715        1069 :   static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
    2716             :                           StringRef Name, StringRef Value, StorageType Storage,
    2717             :                           bool ShouldCreate = true) {
    2718        3207 :     return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
    2719        1069 :                    getCanonicalMDString(Context, Value), Storage, ShouldCreate);
    2720             :   }
    2721             :   static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
    2722             :                           MDString *Name, MDString *Value, StorageType Storage,
    2723             :                           bool ShouldCreate = true);
    2724             : 
    2725           0 :   TempDIMacro cloneImpl() const {
    2726             :     return getTemporary(getContext(), getMacinfoType(), getLine(), getName(),
    2727           0 :                         getValue());
    2728             :   }
    2729             : 
    2730             : public:
    2731        1069 :   DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, StringRef Name,
    2732             :                               StringRef Value = ""),
    2733             :                     (MIType, Line, Name, Value))
    2734          34 :   DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, MDString *Name,
    2735             :                               MDString *Value),
    2736             :                     (MIType, Line, Name, Value))
    2737             : 
    2738             :   TempDIMacro clone() const { return cloneImpl(); }
    2739             : 
    2740             :   unsigned getLine() const { return Line; }
    2741             : 
    2742        2180 :   StringRef getName() const { return getStringOperand(0); }
    2743        2180 :   StringRef getValue() const { return getStringOperand(1); }
    2744             : 
    2745        7078 :   MDString *getRawName() const { return getOperandAs<MDString>(0); }
    2746        4248 :   MDString *getRawValue() const { return getOperandAs<MDString>(1); }
    2747             : 
    2748             :   static bool classof(const Metadata *MD) {
    2749           7 :     return MD->getMetadataID() == DIMacroKind;
    2750             :   }
    2751             : };
    2752             : 
    2753             : class DIMacroFile : public DIMacroNode {
    2754             :   friend class LLVMContextImpl;
    2755             :   friend class MDNode;
    2756             : 
    2757             :   unsigned Line;
    2758             : 
    2759             :   DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
    2760             :               unsigned Line, ArrayRef<Metadata *> Ops)
    2761         164 :       : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops), Line(Line) {}
    2762         164 :   ~DIMacroFile() = default;
    2763             : 
    2764             :   static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
    2765             :                               unsigned Line, DIFile *File,
    2766             :                               DIMacroNodeArray Elements, StorageType Storage,
    2767             :                               bool ShouldCreate = true) {
    2768          38 :     return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
    2769          38 :                    Elements.get(), Storage, ShouldCreate);
    2770             :   }
    2771             : 
    2772             :   static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
    2773             :                               unsigned Line, Metadata *File, Metadata *Elements,
    2774             :                               StorageType Storage, bool ShouldCreate = true);
    2775             : 
    2776           0 :   TempDIMacroFile cloneImpl() const {
    2777             :     return getTemporary(getContext(), getMacinfoType(), getLine(), getFile(),
    2778           0 :                         getElements());
    2779             :   }
    2780             : 
    2781             : public:
    2782          56 :   DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line, DIFile *File,
    2783             :                                   DIMacroNodeArray Elements),
    2784             :                     (MIType, Line, File, Elements))
    2785          46 :   DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line,
    2786             :                                   Metadata *File, Metadata *Elements),
    2787             :                     (MIType, Line, File, Elements))
    2788             : 
    2789             :   TempDIMacroFile clone() const { return cloneImpl(); }
    2790             : 
    2791             :   void replaceElements(DIMacroNodeArray Elements) {
    2792             : #ifndef NDEBUG
    2793             :     for (DIMacroNode *Op : getElements())
    2794             :       assert(is_contained(Elements->operands(), Op) &&
    2795             :              "Lost a macro node during macro node list replacement");
    2796             : #endif
    2797             :     replaceOperandWith(1, Elements.get());
    2798             :   }
    2799             : 
    2800             :   unsigned getLine() const { return Line; }
    2801          82 :   DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
    2802             : 
    2803             :   DIMacroNodeArray getElements() const {
    2804         160 :     return cast_or_null<MDTuple>(getRawElements());
    2805             :   }
    2806             : 
    2807         768 :   Metadata *getRawFile() const { return getOperand(0); }
    2808         891 :   Metadata *getRawElements() const { return getOperand(1); }
    2809             : 
    2810             :   static bool classof(const Metadata *MD) {
    2811           3 :     return MD->getMetadataID() == DIMacroFileKind;
    2812             :   }
    2813             : };
    2814             : 
    2815             : } // end namespace llvm
    2816             : 
    2817             : #undef DEFINE_MDNODE_GET_UNPACK_IMPL
    2818             : #undef DEFINE_MDNODE_GET_UNPACK
    2819             : #undef DEFINE_MDNODE_GET
    2820             : 
    2821             : #endif // LLVM_IR_DEBUGINFOMETADATA_H

Generated by: LCOV version 1.13