Revert "[DebugInfo] Enforce implicit constraints on `distinct` MDNodes"
authorArthur Eubanks <aeubanks@google.com>
Tue, 9 Nov 2021 22:23:04 +0000 (14:23 -0800)
committerArthur Eubanks <aeubanks@google.com>
Tue, 9 Nov 2021 22:27:55 +0000 (14:27 -0800)
This reverts commit ee7652569854af567ba83e5255d70e80cc8619a1.

Causes crashes, see comments in D104827.

18 files changed:
llvm/docs/LangRef.rst
llvm/docs/SourceLevelDebugging.rst
llvm/include/llvm/AsmParser/LLParser.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/include/llvm/IR/Metadata.def
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/CodeGen/MIRParser/MIParser.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/IR/LLVMContextImpl.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/lib/IR/Metadata.cpp
llvm/test/Assembler/invalid-diarglist-outside-function.ll [deleted file]
llvm/test/Assembler/invalid-diexpression-distinct.ll [deleted file]
llvm/test/Bitcode/DIExpression-is-distinct-upgrade.ll [deleted file]
llvm/test/Bitcode/DIExpression-is-distinct-upgrade.ll.bc [deleted file]

index 92dfd6c..3a5bc9c 100644 (file)
@@ -5200,22 +5200,21 @@ metadata nodes are related to debug info.
 DICompileUnit
 """""""""""""
 
-``DICompileUnit`` nodes represent a compile unit. ``DICompileUnit`` nodes must
-be ``distinct``. The ``enums:``, ``retainedTypes:``, ``globals:``, ``imports:``
-and ``macros:`` fields are tuples containing the debug info to be emitted along
-with the compile unit, regardless of code optimizations (some nodes are only
-emitted if there are references to them from instructions). The
-``debugInfoForProfiling:`` field is a boolean indicating whether or not
-line-table discriminators are updated to provide more-accurate debug info for
-profiling results.
+``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
+``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
+containing the debug info to be emitted along with the compile unit, regardless
+of code optimizations (some nodes are only emitted if there are references to
+them from instructions). The ``debugInfoForProfiling:`` field is a boolean
+indicating whether or not line-table discriminators are updated to provide
+more-accurate debug info for profiling results.
 
 .. code-block:: text
 
-    !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
-                                 isOptimized: true, flags: "-O2", runtimeVersion: 2,
-                                 splitDebugFilename: "abc.debug", emissionKind: FullDebug,
-                                 enums: !2, retainedTypes: !3, globals: !4, imports: !5,
-                                 macros: !6, dwoId: 0x0abcd)
+    !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
+                        isOptimized: true, flags: "-O2", runtimeVersion: 2,
+                        splitDebugFilename: "abc.debug", emissionKind: FullDebug,
+                        enums: !2, retainedTypes: !3, globals: !4, imports: !5,
+                        macros: !6, dwoId: 0x0abcd)
 
 Compile unit descriptors provide the root scope for objects declared in a
 specific compilation unit. File descriptors are defined using this scope.  These
@@ -5626,14 +5625,12 @@ DIExpression
 """"""""""""
 
 ``DIExpression`` nodes represent expressions that are inspired by the DWARF
-expression language. ``DIExpression`` nodes must not be ``distinct``, and are
-canonically printed inline at each use. They are used in :ref:`debug
-intrinsics<dbg_intrinsics>` (such as ``llvm.dbg.declare`` and
-``llvm.dbg.value``) to describe how the referenced LLVM variable relates to the
-source language variable. Debug intrinsics are interpreted left-to-right: start
-by pushing the value/address operand of the intrinsic onto a stack, then
-repeatedly push and evaluate opcodes from the DIExpression until the final
-variable description is produced.
+expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
+(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
+referenced LLVM variable relates to the source language variable. Debug
+intrinsics are interpreted left-to-right: start by pushing the value/address
+operand of the intrinsic onto a stack, then repeatedly push and evaluate
+opcodes from the DIExpression until the final variable description is produced.
 
 The current supported opcode vocabulary is limited:
 
@@ -5711,23 +5708,23 @@ The current supported opcode vocabulary is limited:
 
     IR for "*ptr = 4;"
     --------------
-    call void @llvm.dbg.value(metadata i32 4, metadata !17,
-                              metadata !DIExpression(DW_OP_LLVM_implicit_pointer)))
+    call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !20)
     !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
                            type: !18)
     !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
     !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+    !20 = !DIExpression(DW_OP_LLVM_implicit_pointer))
 
     IR for "**ptr = 4;"
     --------------
-    call void @llvm.dbg.value(metadata i32 4, metadata !17,
-                              metadata !DIExpression(DW_OP_LLVM_implicit_pointer,
-                                                     DW_OP_LLVM_implicit_pointer)))
+    call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !21)
     !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
                            type: !18)
     !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
     !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
     !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+    !21 = !DIExpression(DW_OP_LLVM_implicit_pointer,
+                        DW_OP_LLVM_implicit_pointer))
 
 DWARF specifies three kinds of simple location descriptions: Register, memory,
 and implicit location descriptions.  Note that a location description is
@@ -5768,13 +5765,12 @@ valid debug intrinsic.
 DIArgList
 """"""""""""
 
-``DIArgList`` nodes hold a list of constant or SSA value references.
-``DIArgList`` must not be ``distinct``, must only be used as an argument to a
-function call, and must appear inline at each use. ``DIArgList`` may refer to
-function-local values of the containing function. ``DIArgList`` nodes are used
-in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in
+``DIArgList`` nodes hold a list of constant or SSA value references. These are
+used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in
 ``llvm.dbg.value``) in combination with a ``DIExpression`` that uses the
-``DW_OP_LLVM_arg`` operator.
+``DW_OP_LLVM_arg`` operator. Because a DIArgList may refer to local values
+within a function, it must only be used as a function argument, must always be
+inlined, and cannot appear in named metadata.
 
 .. code-block:: text
 
index 5732e9e..dbadaed 100644 (file)
@@ -291,17 +291,17 @@ Compiled to LLVM, this function would be represented like this:
     %X = alloca i32, align 4
     %Y = alloca i32, align 4
     %Z = alloca i32, align 4
-    call void @llvm.dbg.declare(metadata i32* %X, metadata !11, metadata !DIExpression()), !dbg !13
-    store i32 21, i32* %X, align 4, !dbg !13
-    call void @llvm.dbg.declare(metadata i32* %Y, metadata !14, metadata !DIExpression()), !dbg !15
-    store i32 22, i32* %Y, align 4, !dbg !15
-    call void @llvm.dbg.declare(metadata i32* %Z, metadata !16, metadata !DIExpression()), !dbg !18
-    store i32 23, i32* %Z, align 4, !dbg !18
-    %0 = load i32, i32* %X, align 4, !dbg !19
-    store i32 %0, i32* %Z, align 4, !dbg !20
-    %1 = load i32, i32* %Y, align 4, !dbg !21
-    store i32 %1, i32* %X, align 4, !dbg !22
-    ret void, !dbg !23
+    call void @llvm.dbg.declare(metadata i32* %X, metadata !11, metadata !13), !dbg !14
+    store i32 21, i32* %X, align 4, !dbg !14
+    call void @llvm.dbg.declare(metadata i32* %Y, metadata !15, metadata !13), !dbg !16
+    store i32 22, i32* %Y, align 4, !dbg !16
+    call void @llvm.dbg.declare(metadata i32* %Z, metadata !17, metadata !13), !dbg !19
+    store i32 23, i32* %Z, align 4, !dbg !19
+    %0 = load i32, i32* %X, align 4, !dbg !20
+    store i32 %0, i32* %Z, align 4, !dbg !21
+    %1 = load i32, i32* %Y, align 4, !dbg !22
+    store i32 %1, i32* %X, align 4, !dbg !23
+    ret void, !dbg !24
   }
 
   ; Function Attrs: nounwind readnone
@@ -327,17 +327,18 @@ Compiled to LLVM, this function would be represented like this:
   !10 = !{!"clang version 3.7.0 (trunk 231150) (llvm/trunk 231154)"}
   !11 = !DILocalVariable(name: "X", scope: !4, file: !1, line: 2, type: !12)
   !12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
-  !13 = !DILocation(line: 2, column: 9, scope: !4)
-  !14 = !DILocalVariable(name: "Y", scope: !4, file: !1, line: 3, type: !12)
-  !15 = !DILocation(line: 3, column: 9, scope: !4)
-  !16 = !DILocalVariable(name: "Z", scope: !17, file: !1, line: 5, type: !12)
-  !17 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 5)
-  !18 = !DILocation(line: 5, column: 11, scope: !17)
-  !19 = !DILocation(line: 6, column: 11, scope: !17)
-  !20 = !DILocation(line: 6, column: 9, scope: !17)
-  !21 = !DILocation(line: 8, column: 9, scope: !4)
-  !22 = !DILocation(line: 8, column: 7, scope: !4)
-  !23 = !DILocation(line: 9, column: 3, scope: !4)
+  !13 = !DIExpression()
+  !14 = !DILocation(line: 2, column: 9, scope: !4)
+  !15 = !DILocalVariable(name: "Y", scope: !4, file: !1, line: 3, type: !12)
+  !16 = !DILocation(line: 3, column: 9, scope: !4)
+  !17 = !DILocalVariable(name: "Z", scope: !18, file: !1, line: 5, type: !12)
+  !18 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 5)
+  !19 = !DILocation(line: 5, column: 11, scope: !18)
+  !20 = !DILocation(line: 6, column: 11, scope: !18)
+  !21 = !DILocation(line: 6, column: 9, scope: !18)
+  !22 = !DILocation(line: 8, column: 9, scope: !4)
+  !23 = !DILocation(line: 8, column: 7, scope: !4)
+  !24 = !DILocation(line: 9, column: 3, scope: !4)
 
 
 This example illustrates a few important details about LLVM debugging
@@ -348,21 +349,21 @@ variable definitions, and the code used to implement the function.
 
 .. code-block:: llvm
 
-  call void @llvm.dbg.declare(metadata i32* %X, metadata !11, metadata !DIExpression()), !dbg !13
+  call void @llvm.dbg.declare(metadata i32* %X, metadata !11, metadata !13), !dbg !14
     ; [debug line = 2:7] [debug variable = X]
 
 The first intrinsic ``%llvm.dbg.declare`` encodes debugging information for the
-variable ``X``.  The metadata ``!dbg !13`` attached to the intrinsic provides
+variable ``X``.  The metadata ``!dbg !14`` attached to the intrinsic provides
 scope information for the variable ``X``.
 
 .. code-block:: text
 
-  !13 = !DILocation(line: 2, column: 9, scope: !4)
+  !14 = !DILocation(line: 2, column: 9, scope: !4)
   !4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5,
                               isLocal: false, isDefinition: true, scopeLine: 1,
                               isOptimized: false, retainedNodes: !2)
 
-Here ``!13`` is metadata providing `location information
+Here ``!14`` is metadata providing `location information
 <LangRef.html#dilocation>`_.  In this example, scope is encoded by ``!4``, a
 `subprogram descriptor <LangRef.html#disubprogram>`_.  This way the location
 information attached to the intrinsics indicates that the variable ``X`` is
@@ -372,20 +373,20 @@ Now lets take another example.
 
 .. code-block:: llvm
 
-  call void @llvm.dbg.declare(metadata i32* %Z, metadata !16, metadata !DIExpression()), !dbg !18
+  call void @llvm.dbg.declare(metadata i32* %Z, metadata !17, metadata !13), !dbg !19
     ; [debug line = 5:9] [debug variable = Z]
 
 The third intrinsic ``%llvm.dbg.declare`` encodes debugging information for
-variable ``Z``.  The metadata ``!dbg !18`` attached to the intrinsic provides
+variable ``Z``.  The metadata ``!dbg !19`` attached to the intrinsic provides
 scope information for the variable ``Z``.
 
 .. code-block:: text
 
-  !17 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 5)
-  !18 = !DILocation(line: 5, column: 11, scope: !17)
+  !18 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 5)
+  !19 = !DILocation(line: 5, column: 11, scope: !18)
 
-Here ``!18`` indicates that ``Z`` is declared at line number 5 and column
-number 11 inside of lexical scope ``!17``.  The lexical scope itself resides
+Here ``!19`` indicates that ``Z`` is declared at line number 5 and column
+number 11 inside of lexical scope ``!18``.  The lexical scope itself resides
 inside of subprogram ``!4`` described above.
 
 The scope information attached with each instruction provides a straightforward
@@ -801,14 +802,14 @@ presents several difficulties:
     br label %exit, !dbg !26
 
   truebr:
-    call void @llvm.dbg.value(metadata i32 %input, metadata !30, metadata !DIExpression()), !dbg !23
-    call void @llvm.dbg.value(metadata i32 1, metadata !22, metadata !DIExpression()), !dbg !23
+    call void @llvm.dbg.value(metadata i32 %input, metadata !30, metadata !DIExpression()), !dbg !24
+    call void @llvm.dbg.value(metadata i32 1, metadata !23, metadata !DIExpression()), !dbg !24
     %value1 = add i32 %input, 1
     br label %bb1
 
   falsebr:
-    call void @llvm.dbg.value(metadata i32 %input, metadata !30, metadata !DIExpression()), !dbg !23
-    call void @llvm.dbg.value(metadata i32 2, metadata !22, metadata !DIExpression()), !dbg !23
+    call void @llvm.dbg.value(metadata i32 %input, metadata !30, metadata !DIExpression()), !dbg !24
+    call void @llvm.dbg.value(metadata i32 2, metadata !23, metadata !DIExpression()), !dbg !24
     %value = add i32 %input, 2
     br label %bb1
 
@@ -819,7 +820,7 @@ presents several difficulties:
 Here the difficulties are:
 
 * The control flow is roughly the opposite of basic block order
-* The value of the ``!22`` variable merges into ``%bb1``, but there is no PHI
+* The value of the ``!23`` variable merges into ``%bb1``, but there is no PHI
   node
 
 As mentioned above, the ``llvm.dbg.value`` intrinsics essentially form an
@@ -832,9 +833,9 @@ location, which would lead to a large number of debugging intrinsics being
 generated.
 
 Examining the example above, variable ``!30`` is assigned ``%input`` on both
-conditional paths through the function, while ``!22`` is assigned differing
+conditional paths through the function, while ``!23`` is assigned differing
 constant values on either path. Where control flow merges in ``%bb1`` we would
-want ``!30`` to keep its location (``%input``), but ``!22`` to become undefined
+want ``!30`` to keep its location (``%input``), but ``!23`` to become undefined
 as we cannot determine at runtime what value it should have in %bb1 without
 inserting a PHI node. mem2reg does not insert the PHI node to avoid changing
 codegen when debugging is enabled, and does not insert the other dbg.values
@@ -853,7 +854,7 @@ DbgEntityHistoryCalculator) to build a map of each instruction to every
 valid variable location, without the need to consider control flow. From
 the example above, it is otherwise difficult to determine that the location
 of variable ``!30`` should flow "up" into block ``%bb1``, but that the location
-of variable ``!22`` should not flow "down" into the ``%exit`` block.
+of variable ``!23`` should not flow "down" into the ``%exit`` block.
 
 .. _ccxx_frontend:
 
index 2224c28..d621c23 100644 (file)
@@ -520,8 +520,7 @@ namespace llvm {
     template <class ParserTy> bool parseMDFieldsImplBody(ParserTy ParseField);
     template <class ParserTy>
     bool parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc);
-    bool parseSpecializedMDNode(MDNode *&N, bool IsDistinct = false,
-                                LocTy DistinctLoc = LocTy());
+    bool parseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
 
 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS)                                  \
   bool parse##CLASS(MDNode *&Result, bool IsDistinct);
index 0039610..7a41529 100644 (file)
 // Helper macros for defining get() overrides.
 #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
 #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
-#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS)                                 \
-  static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) {  \
-    return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued);          \
-  }
-#define DEFINE_MDNODE_GET_IF_EXISTS(CLASS, FORMAL, ARGS)                       \
-  static CLASS *getIfExists(LLVMContext &Context,                              \
-                            DEFINE_MDNODE_GET_UNPACK(FORMAL)) {                \
-    return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued,           \
-                   /* ShouldCreate */ false);                                  \
-  }
-#define DEFINE_MDNODE_GET_DISTINCT(CLASS, FORMAL, ARGS)                        \
+#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)              \
   static CLASS *getDistinct(LLVMContext &Context,                              \
                             DEFINE_MDNODE_GET_UNPACK(FORMAL)) {                \
     return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct);         \
-  }
-#define DEFINE_MDNODE_GET_TEMPORARY(CLASS, FORMAL, ARGS)                       \
+  }                                                                            \
   static Temp##CLASS getTemporary(LLVMContext &Context,                        \
                                   DEFINE_MDNODE_GET_UNPACK(FORMAL)) {          \
     return Temp##CLASS(                                                        \
         getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary));          \
   }
-#define DEFINE_ALL_MDNODE_GET_METHODS(CLASS, FORMAL, ARGS)                     \
-  DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS)                                       \
-  DEFINE_MDNODE_GET_IF_EXISTS(CLASS, FORMAL, ARGS)                             \
-  DEFINE_MDNODE_GET_DISTINCT(CLASS, FORMAL, ARGS)                              \
-  DEFINE_MDNODE_GET_TEMPORARY(CLASS, FORMAL, ARGS)
-#define DEFINE_ALWAYS_DISTINCT_MDNODE_GET_METHODS(CLASS, FORMAL, ARGS)         \
-  DEFINE_MDNODE_GET_DISTINCT(CLASS, FORMAL, ARGS)                              \
-  DEFINE_MDNODE_GET_TEMPORARY(CLASS, FORMAL, ARGS)
-#define DEFINE_ALWAYS_UNIQUED_MDNODE_GET_METHODS(CLASS, FORMAL, ARGS)          \
-  DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS)                                       \
-  DEFINE_MDNODE_GET_IF_EXISTS(CLASS, FORMAL, ARGS)                             \
-  DEFINE_MDNODE_GET_TEMPORARY(CLASS, FORMAL, ARGS)
+#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS)                                 \
+  static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) {  \
+    return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued);          \
+  }                                                                            \
+  static CLASS *getIfExists(LLVMContext &Context,                              \
+                            DEFINE_MDNODE_GET_UNPACK(FORMAL)) {                \
+    return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued,           \
+                   /* ShouldCreate */ false);                                  \
+  }                                                                            \
+  DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
 
 namespace llvm {
 
@@ -269,14 +256,12 @@ class GenericDINode : public DINode {
 public:
   unsigned getHash() const { return SubclassData32; }
 
-  DEFINE_ALL_MDNODE_GET_METHODS(GenericDINode,
-                                (unsigned Tag, StringRef Header,
-                                 ArrayRef<Metadata *> DwarfOps),
-                                (Tag, Header, DwarfOps))
-  DEFINE_ALL_MDNODE_GET_METHODS(GenericDINode,
-                                (unsigned Tag, MDString *Header,
-                                 ArrayRef<Metadata *> DwarfOps),
-                                (Tag, Header, DwarfOps))
+  DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, StringRef Header,
+                                    ArrayRef<Metadata *> DwarfOps),
+                    (Tag, Header, DwarfOps))
+  DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, MDString *Header,
+                                    ArrayRef<Metadata *> DwarfOps),
+                    (Tag, Header, DwarfOps))
 
   /// Return a (temporary) clone of this.
   TempGenericDINode clone() const { return cloneImpl(); }
@@ -336,18 +321,16 @@ class DISubrange : public DINode {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DISubrange,
-                                (int64_t Count, int64_t LowerBound = 0),
-                                (Count, LowerBound))
+  DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
+                    (Count, LowerBound))
 
-  DEFINE_ALL_MDNODE_GET_METHODS(DISubrange,
-                                (Metadata * CountNode, int64_t LowerBound = 0),
-                                (CountNode, LowerBound))
+  DEFINE_MDNODE_GET(DISubrange, (Metadata *CountNode, int64_t LowerBound = 0),
+                    (CountNode, LowerBound))
 
-  DEFINE_ALL_MDNODE_GET_METHODS(DISubrange,
-                                (Metadata * CountNode, Metadata *LowerBound,
-                                 Metadata *UpperBound, Metadata *Stride),
-                                (CountNode, LowerBound, UpperBound, Stride))
+  DEFINE_MDNODE_GET(DISubrange,
+                    (Metadata * CountNode, Metadata *LowerBound,
+                     Metadata *UpperBound, Metadata *Stride),
+                    (CountNode, LowerBound, UpperBound, Stride))
 
   TempDISubrange clone() const { return cloneImpl(); }
 
@@ -398,10 +381,10 @@ class DIGenericSubrange : public DINode {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DIGenericSubrange,
-                                (Metadata * CountNode, Metadata *LowerBound,
-                                 Metadata *UpperBound, Metadata *Stride),
-                                (CountNode, LowerBound, UpperBound, Stride))
+  DEFINE_MDNODE_GET(DIGenericSubrange,
+                    (Metadata * CountNode, Metadata *LowerBound,
+                     Metadata *UpperBound, Metadata *Stride),
+                    (CountNode, LowerBound, UpperBound, Stride))
 
   TempDIGenericSubrange clone() const { return cloneImpl(); }
 
@@ -458,18 +441,18 @@ class DIEnumerator : public DINode {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(
-      DIEnumerator, (int64_t Value, bool IsUnsigned, StringRef Name),
-      (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
-  DEFINE_ALL_MDNODE_GET_METHODS(
-      DIEnumerator, (int64_t Value, bool IsUnsigned, MDString *Name),
-      (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIEnumerator,
-                                (APInt Value, bool IsUnsigned, StringRef Name),
-                                (Value, IsUnsigned, Name))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIEnumerator,
-                                (APInt Value, bool IsUnsigned, MDString *Name),
-                                (Value, IsUnsigned, Name))
+  DEFINE_MDNODE_GET(DIEnumerator,
+                    (int64_t Value, bool IsUnsigned, StringRef Name),
+                    (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
+  DEFINE_MDNODE_GET(DIEnumerator,
+                    (int64_t Value, bool IsUnsigned, MDString *Name),
+                    (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
+  DEFINE_MDNODE_GET(DIEnumerator,
+                    (APInt Value, bool IsUnsigned, StringRef Name),
+                    (Value, IsUnsigned, Name))
+  DEFINE_MDNODE_GET(DIEnumerator,
+                    (APInt Value, bool IsUnsigned, MDString *Name),
+                    (Value, IsUnsigned, Name))
 
   TempDIEnumerator clone() const { return cloneImpl(); }
 
@@ -617,16 +600,14 @@ private:
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DIFile,
-                                (StringRef Filename, StringRef Directory,
-                                 Optional<ChecksumInfo<StringRef>> CS = None,
-                                 Optional<StringRef> Source = None),
-                                (Filename, Directory, CS, Source))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIFile,
-                                (MDString * Filename, MDString *Directory,
-                                 Optional<ChecksumInfo<MDString *>> CS = None,
-                                 Optional<MDString *> Source = None),
-                                (Filename, Directory, CS, Source))
+  DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory,
+                             Optional<ChecksumInfo<StringRef>> CS = None,
+                             Optional<StringRef> Source = None),
+                    (Filename, Directory, CS, Source))
+  DEFINE_MDNODE_GET(DIFile, (MDString * Filename, MDString *Directory,
+                             Optional<ChecksumInfo<MDString *>> CS = None,
+                             Optional<MDString *> Source = None),
+                    (Filename, Directory, CS, Source))
 
   TempDIFile clone() const { return cloneImpl(); }
 
@@ -820,28 +801,22 @@ class DIBasicType : public DIType {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DIBasicType, (unsigned Tag, StringRef Name),
-                                (Tag, Name, 0, 0, 0, FlagZero))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIBasicType,
-                                (unsigned Tag, StringRef Name,
-                                 uint64_t SizeInBits),
-                                (Tag, Name, SizeInBits, 0, 0, FlagZero))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIBasicType,
-                                (unsigned Tag, MDString *Name,
-                                 uint64_t SizeInBits),
-                                (Tag, Name, SizeInBits, 0, 0, FlagZero))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIBasicType,
-                                (unsigned Tag, StringRef Name,
-                                 uint64_t SizeInBits, uint32_t AlignInBits,
-                                 unsigned Encoding, DIFlags Flags),
-                                (Tag, Name, SizeInBits, AlignInBits, Encoding,
-                                 Flags))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIBasicType,
-                                (unsigned Tag, MDString *Name,
-                                 uint64_t SizeInBits, uint32_t AlignInBits,
-                                 unsigned Encoding, DIFlags Flags),
-                                (Tag, Name, SizeInBits, AlignInBits, Encoding,
-                                 Flags))
+  DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
+                    (Tag, Name, 0, 0, 0, FlagZero))
+  DEFINE_MDNODE_GET(DIBasicType,
+                    (unsigned Tag, StringRef Name, uint64_t SizeInBits),
+                    (Tag, Name, SizeInBits, 0, 0, FlagZero))
+  DEFINE_MDNODE_GET(DIBasicType,
+                    (unsigned Tag, MDString *Name, uint64_t SizeInBits),
+                    (Tag, Name, SizeInBits, 0, 0, FlagZero))
+  DEFINE_MDNODE_GET(DIBasicType,
+                    (unsigned Tag, StringRef Name, uint64_t SizeInBits,
+                     uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
+                    (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))
+  DEFINE_MDNODE_GET(DIBasicType,
+                    (unsigned Tag, MDString *Name, uint64_t SizeInBits,
+                     uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
+                    (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))
 
   TempDIBasicType clone() const { return cloneImpl(); }
 
@@ -895,25 +870,22 @@ class DIStringType : public DIType {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DIStringType,
-                                (unsigned Tag, StringRef Name,
-                                 uint64_t SizeInBits, uint32_t AlignInBits),
-                                (Tag, Name, nullptr, nullptr, SizeInBits,
-                                 AlignInBits, 0))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIStringType,
-                                (unsigned Tag, MDString *Name,
-                                 Metadata *StringLength,
-                                 Metadata *StringLengthExp, uint64_t SizeInBits,
-                                 uint32_t AlignInBits, unsigned Encoding),
-                                (Tag, Name, StringLength, StringLengthExp,
-                                 SizeInBits, AlignInBits, Encoding))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIStringType,
-                                (unsigned Tag, StringRef Name,
-                                 Metadata *StringLength,
-                                 Metadata *StringLengthExp, uint64_t SizeInBits,
-                                 uint32_t AlignInBits, unsigned Encoding),
-                                (Tag, Name, StringLength, StringLengthExp,
-                                 SizeInBits, AlignInBits, Encoding))
+  DEFINE_MDNODE_GET(DIStringType,
+                    (unsigned Tag, StringRef Name, uint64_t SizeInBits,
+                     uint32_t AlignInBits),
+                    (Tag, Name, nullptr, nullptr, SizeInBits, AlignInBits, 0))
+  DEFINE_MDNODE_GET(DIStringType,
+                    (unsigned Tag, MDString *Name, Metadata *StringLength,
+                     Metadata *StringLengthExp, uint64_t SizeInBits,
+                     uint32_t AlignInBits, unsigned Encoding),
+                    (Tag, Name, StringLength, StringLengthExp, SizeInBits,
+                     AlignInBits, Encoding))
+  DEFINE_MDNODE_GET(DIStringType,
+                    (unsigned Tag, StringRef Name, Metadata *StringLength,
+                     Metadata *StringLengthExp, uint64_t SizeInBits,
+                     uint32_t AlignInBits, unsigned Encoding),
+                    (Tag, Name, StringLength, StringLengthExp, SizeInBits,
+                     AlignInBits, Encoding))
 
   TempDIStringType clone() const { return cloneImpl(); }
 
@@ -987,24 +959,27 @@ class DIDerivedType : public DIType {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(
-      DIDerivedType,
-      (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
-       Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
-       uint32_t AlignInBits, uint64_t OffsetInBits,
-       Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
-       Metadata *ExtraData = nullptr, Metadata *Annotations = nullptr),
-      (Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
-       OffsetInBits, DWARFAddressSpace, Flags, ExtraData, Annotations))
-  DEFINE_ALL_MDNODE_GET_METHODS(
-      DIDerivedType,
-      (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
-       DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
-       uint32_t AlignInBits, uint64_t OffsetInBits,
-       Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
-       Metadata *ExtraData = nullptr, DINodeArray Annotations = nullptr),
-      (Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
-       OffsetInBits, DWARFAddressSpace, Flags, ExtraData, Annotations))
+  DEFINE_MDNODE_GET(DIDerivedType,
+                    (unsigned Tag, MDString *Name, Metadata *File,
+                     unsigned Line, Metadata *Scope, Metadata *BaseType,
+                     uint64_t SizeInBits, uint32_t AlignInBits,
+                     uint64_t OffsetInBits,
+                     Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
+                     Metadata *ExtraData = nullptr,
+                     Metadata *Annotations = nullptr),
+                    (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
+                     AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
+                     ExtraData, Annotations))
+  DEFINE_MDNODE_GET(DIDerivedType,
+                    (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
+                     DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
+                     uint32_t AlignInBits, uint64_t OffsetInBits,
+                     Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
+                     Metadata *ExtraData = nullptr,
+                     DINodeArray Annotations = nullptr),
+                    (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
+                     AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
+                     ExtraData, Annotations))
 
   TempDIDerivedType clone() const { return cloneImpl(); }
 
@@ -1145,7 +1120,7 @@ class DICompositeType : public DIType {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(
+  DEFINE_MDNODE_GET(
       DICompositeType,
       (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
        DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
@@ -1160,7 +1135,7 @@ public:
        OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
        Identifier, Discriminator, DataLocation, Associated, Allocated, Rank,
        Annotations))
-  DEFINE_ALL_MDNODE_GET_METHODS(
+  DEFINE_MDNODE_GET(
       DICompositeType,
       (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
        Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
@@ -1334,14 +1309,12 @@ class DISubroutineType : public DIType {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DISubroutineType,
-                                (DIFlags Flags, uint8_t CC,
-                                 DITypeRefArray TypeArray),
-                                (Flags, CC, TypeArray))
-  DEFINE_ALL_MDNODE_GET_METHODS(DISubroutineType,
-                                (DIFlags Flags, uint8_t CC,
-                                 Metadata *TypeArray),
-                                (Flags, CC, TypeArray))
+  DEFINE_MDNODE_GET(DISubroutineType,
+                    (DIFlags Flags, uint8_t CC, DITypeRefArray TypeArray),
+                    (Flags, CC, TypeArray))
+  DEFINE_MDNODE_GET(DISubroutineType,
+                    (DIFlags Flags, uint8_t CC, Metadata *TypeArray),
+                    (Flags, CC, TypeArray))
 
   TempDISubroutineType clone() const { return cloneImpl(); }
 
@@ -1456,7 +1429,7 @@ public:
   static void get() = delete;
   static void getIfExists() = delete;
 
-  DEFINE_ALWAYS_DISTINCT_MDNODE_GET_METHODS(
+  DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
       DICompileUnit,
       (unsigned SourceLanguage, DIFile *File, StringRef Producer,
        bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
@@ -1472,7 +1445,7 @@ public:
        GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
        DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
        SysRoot, SDK))
-  DEFINE_ALWAYS_DISTINCT_MDNODE_GET_METHODS(
+  DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
       DICompileUnit,
       (unsigned SourceLanguage, Metadata *File, MDString *Producer,
        bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
@@ -1636,17 +1609,15 @@ public:
   // Disallow replacing operands.
   void replaceOperandWith(unsigned I, Metadata *New) = delete;
 
-  DEFINE_ALL_MDNODE_GET_METHODS(DILocation,
-                                (unsigned Line, unsigned Column,
-                                 Metadata *Scope, Metadata *InlinedAt = nullptr,
-                                 bool ImplicitCode = false),
-                                (Line, Column, Scope, InlinedAt, ImplicitCode))
-  DEFINE_ALL_MDNODE_GET_METHODS(DILocation,
-                                (unsigned Line, unsigned Column,
-                                 DILocalScope *Scope,
-                                 DILocation *InlinedAt = nullptr,
-                                 bool ImplicitCode = false),
-                                (Line, Column, Scope, InlinedAt, ImplicitCode))
+  DEFINE_MDNODE_GET(DILocation,
+                    (unsigned Line, unsigned Column, Metadata *Scope,
+                     Metadata *InlinedAt = nullptr, bool ImplicitCode = false),
+                    (Line, Column, Scope, InlinedAt, ImplicitCode))
+  DEFINE_MDNODE_GET(DILocation,
+                    (unsigned Line, unsigned Column, DILocalScope *Scope,
+                     DILocation *InlinedAt = nullptr,
+                     bool ImplicitCode = false),
+                    (Line, Column, Scope, InlinedAt, ImplicitCode))
 
   /// Return a (temporary) clone of this.
   TempDILocation clone() const { return cloneImpl(); }
@@ -1951,7 +1922,7 @@ private:
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(
+  DEFINE_MDNODE_GET(
       DISubprogram,
       (DIScope * Scope, StringRef Name, StringRef LinkageName, DIFile *File,
        unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
@@ -1964,7 +1935,7 @@ public:
        VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
        Declaration, RetainedNodes, ThrownTypes, Annotations))
 
-  DEFINE_ALL_MDNODE_GET_METHODS(
+  DEFINE_MDNODE_GET(
       DISubprogram,
       (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
        unsigned Line, Metadata *Type, unsigned ScopeLine,
@@ -2168,14 +2139,12 @@ class DILexicalBlock : public DILexicalBlockBase {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DILexicalBlock,
-                                (DILocalScope * Scope, DIFile *File,
-                                 unsigned Line, unsigned Column),
-                                (Scope, File, Line, Column))
-  DEFINE_ALL_MDNODE_GET_METHODS(DILexicalBlock,
-                                (Metadata * Scope, Metadata *File,
-                                 unsigned Line, unsigned Column),
-                                (Scope, File, Line, Column))
+  DEFINE_MDNODE_GET(DILexicalBlock, (DILocalScope * Scope, DIFile *File,
+                                     unsigned Line, unsigned Column),
+                    (Scope, File, Line, Column))
+  DEFINE_MDNODE_GET(DILexicalBlock, (Metadata * Scope, Metadata *File,
+                                     unsigned Line, unsigned Column),
+                    (Scope, File, Line, Column))
 
   TempDILexicalBlock clone() const { return cloneImpl(); }
 
@@ -2219,14 +2188,12 @@ class DILexicalBlockFile : public DILexicalBlockBase {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DILexicalBlockFile,
-                                (DILocalScope * Scope, DIFile *File,
-                                 unsigned Discriminator),
-                                (Scope, File, Discriminator))
-  DEFINE_ALL_MDNODE_GET_METHODS(DILexicalBlockFile,
-                                (Metadata * Scope, Metadata *File,
-                                 unsigned Discriminator),
-                                (Scope, File, Discriminator))
+  DEFINE_MDNODE_GET(DILexicalBlockFile, (DILocalScope * Scope, DIFile *File,
+                                         unsigned Discriminator),
+                    (Scope, File, Discriminator))
+  DEFINE_MDNODE_GET(DILexicalBlockFile,
+                    (Metadata * Scope, Metadata *File, unsigned Discriminator),
+                    (Scope, File, Discriminator))
 
   TempDILexicalBlockFile clone() const { return cloneImpl(); }
   unsigned getDiscriminator() const { return Discriminator; }
@@ -2335,14 +2302,12 @@ class DINamespace : public DIScope {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DINamespace,
-                                (DIScope * Scope, StringRef Name,
-                                 bool ExportSymbols),
-                                (Scope, Name, ExportSymbols))
-  DEFINE_ALL_MDNODE_GET_METHODS(DINamespace,
-                                (Metadata * Scope, MDString *Name,
-                                 bool ExportSymbols),
-                                (Scope, Name, ExportSymbols))
+  DEFINE_MDNODE_GET(DINamespace,
+                    (DIScope *Scope, StringRef Name, bool ExportSymbols),
+                    (Scope, Name, ExportSymbols))
+  DEFINE_MDNODE_GET(DINamespace,
+                    (Metadata *Scope, MDString *Name, bool ExportSymbols),
+                    (Scope, Name, ExportSymbols))
 
   TempDINamespace clone() const { return cloneImpl(); }
 
@@ -2396,20 +2361,20 @@ class DIModule : public DIScope {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DIModule,
-                                (DIFile * File, DIScope *Scope, StringRef Name,
-                                 StringRef ConfigurationMacros,
-                                 StringRef IncludePath, StringRef APINotesFile,
-                                 unsigned LineNo, bool IsDecl = false),
-                                (File, Scope, Name, ConfigurationMacros,
-                                 IncludePath, APINotesFile, LineNo, IsDecl))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIModule,
-                                (Metadata * File, Metadata *Scope,
-                                 MDString *Name, MDString *ConfigurationMacros,
-                                 MDString *IncludePath, MDString *APINotesFile,
-                                 unsigned LineNo, bool IsDecl = false),
-                                (File, Scope, Name, ConfigurationMacros,
-                                 IncludePath, APINotesFile, LineNo, IsDecl))
+  DEFINE_MDNODE_GET(DIModule,
+                    (DIFile * File, DIScope *Scope, StringRef Name,
+                     StringRef ConfigurationMacros, StringRef IncludePath,
+                     StringRef APINotesFile, unsigned LineNo,
+                     bool IsDecl = false),
+                    (File, Scope, Name, ConfigurationMacros, IncludePath,
+                     APINotesFile, LineNo, IsDecl))
+  DEFINE_MDNODE_GET(DIModule,
+                    (Metadata * File, Metadata *Scope, MDString *Name,
+                     MDString *ConfigurationMacros, MDString *IncludePath,
+                     MDString *APINotesFile, unsigned LineNo,
+                     bool IsDecl = false),
+                    (File, Scope, Name, ConfigurationMacros, IncludePath,
+                     APINotesFile, LineNo, IsDecl))
 
   TempDIModule clone() const { return cloneImpl(); }
 
@@ -2486,13 +2451,12 @@ class DITemplateTypeParameter : public DITemplateParameter {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DITemplateTypeParameter,
-                                (StringRef Name, DIType *Type, bool IsDefault),
-                                (Name, Type, IsDefault))
-  DEFINE_ALL_MDNODE_GET_METHODS(DITemplateTypeParameter,
-                                (MDString * Name, Metadata *Type,
-                                 bool IsDefault),
-                                (Name, Type, IsDefault))
+  DEFINE_MDNODE_GET(DITemplateTypeParameter,
+                    (StringRef Name, DIType *Type, bool IsDefault),
+                    (Name, Type, IsDefault))
+  DEFINE_MDNODE_GET(DITemplateTypeParameter,
+                    (MDString *Name, Metadata *Type, bool IsDefault),
+                    (Name, Type, IsDefault))
 
   TempDITemplateTypeParameter clone() const { return cloneImpl(); }
 
@@ -2532,14 +2496,14 @@ class DITemplateValueParameter : public DITemplateParameter {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DITemplateValueParameter,
-                                (unsigned Tag, StringRef Name, DIType *Type,
-                                 bool IsDefault, Metadata *Value),
-                                (Tag, Name, Type, IsDefault, Value))
-  DEFINE_ALL_MDNODE_GET_METHODS(DITemplateValueParameter,
-                                (unsigned Tag, MDString *Name, Metadata *Type,
-                                 bool IsDefault, Metadata *Value),
-                                (Tag, Name, Type, IsDefault, Value))
+  DEFINE_MDNODE_GET(DITemplateValueParameter,
+                    (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
+                     Metadata *Value),
+                    (Tag, Name, Type, IsDefault, Value))
+  DEFINE_MDNODE_GET(DITemplateValueParameter,
+                    (unsigned Tag, MDString *Name, Metadata *Type,
+                     bool IsDefault, Metadata *Value),
+                    (Tag, Name, Type, IsDefault, Value))
 
   TempDITemplateValueParameter clone() const { return cloneImpl(); }
 
@@ -2639,9 +2603,7 @@ class DIExpression : public MDNode {
   }
 
 public:
-  DEFINE_ALWAYS_UNIQUED_MDNODE_GET_METHODS(DIExpression,
-                                           (ArrayRef<uint64_t> Elements),
-                                           (Elements))
+  DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
 
   TempDIExpression clone() const { return cloneImpl(); }
 
@@ -3025,22 +2987,26 @@ class DIGlobalVariable : public DIVariable {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(
-      DIGlobalVariable,
-      (DIScope * Scope, StringRef Name, StringRef LinkageName, DIFile *File,
-       unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition,
-       DIDerivedType *StaticDataMemberDeclaration, MDTuple *TemplateParams,
-       uint32_t AlignInBits, DINodeArray Annotations),
-      (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
-       StaticDataMemberDeclaration, TemplateParams, AlignInBits, Annotations))
-  DEFINE_ALL_MDNODE_GET_METHODS(
-      DIGlobalVariable,
-      (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
-       unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
-       Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams,
-       uint32_t AlignInBits, Metadata *Annotations),
-      (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
-       StaticDataMemberDeclaration, TemplateParams, AlignInBits, Annotations))
+  DEFINE_MDNODE_GET(DIGlobalVariable,
+                    (DIScope * Scope, StringRef Name, StringRef LinkageName,
+                     DIFile *File, unsigned Line, DIType *Type,
+                     bool IsLocalToUnit, bool IsDefinition,
+                     DIDerivedType *StaticDataMemberDeclaration,
+                     MDTuple *TemplateParams, uint32_t AlignInBits,
+                     DINodeArray Annotations),
+                    (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
+                     IsDefinition, StaticDataMemberDeclaration, TemplateParams,
+                     AlignInBits, Annotations))
+  DEFINE_MDNODE_GET(DIGlobalVariable,
+                    (Metadata * Scope, MDString *Name, MDString *LinkageName,
+                     Metadata *File, unsigned Line, Metadata *Type,
+                     bool IsLocalToUnit, bool IsDefinition,
+                     Metadata *StaticDataMemberDeclaration,
+                     Metadata *TemplateParams, uint32_t AlignInBits,
+                     Metadata *Annotations),
+                    (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
+                     IsDefinition, StaticDataMemberDeclaration, TemplateParams,
+                     AlignInBits, Annotations))
 
   TempDIGlobalVariable clone() const { return cloneImpl(); }
 
@@ -3096,15 +3062,14 @@ class DICommonBlock : public DIScope {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DICommonBlock,
-                                (DIScope * Scope, DIGlobalVariable *Decl,
-                                 StringRef Name, DIFile *File, unsigned LineNo),
-                                (Scope, Decl, Name, File, LineNo))
-  DEFINE_ALL_MDNODE_GET_METHODS(DICommonBlock,
-                                (Metadata * Scope, Metadata *Decl,
-                                 MDString *Name, Metadata *File,
-                                 unsigned LineNo),
-                                (Scope, Decl, Name, File, LineNo))
+  DEFINE_MDNODE_GET(DICommonBlock,
+                    (DIScope *Scope, DIGlobalVariable *Decl, StringRef Name,
+                     DIFile *File, unsigned LineNo),
+                    (Scope, Decl, Name, File, LineNo))
+  DEFINE_MDNODE_GET(DICommonBlock,
+                    (Metadata *Scope, Metadata *Decl, MDString *Name,
+                     Metadata *File, unsigned LineNo),
+                    (Scope, Decl, Name, File, LineNo))
 
   TempDICommonBlock clone() const { return cloneImpl(); }
 
@@ -3167,20 +3132,18 @@ class DILocalVariable : public DIVariable {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DILocalVariable,
-                                (DILocalScope * Scope, StringRef Name,
-                                 DIFile *File, unsigned Line, DIType *Type,
-                                 unsigned Arg, DIFlags Flags,
-                                 uint32_t AlignInBits, DINodeArray Annotations),
-                                (Scope, Name, File, Line, Type, Arg, Flags,
-                                 AlignInBits, Annotations))
-  DEFINE_ALL_MDNODE_GET_METHODS(DILocalVariable,
-                                (Metadata * Scope, MDString *Name,
-                                 Metadata *File, unsigned Line, Metadata *Type,
-                                 unsigned Arg, DIFlags Flags,
-                                 uint32_t AlignInBits, Metadata *Annotations),
-                                (Scope, Name, File, Line, Type, Arg, Flags,
-                                 AlignInBits, Annotations))
+  DEFINE_MDNODE_GET(DILocalVariable,
+                    (DILocalScope * Scope, StringRef Name, DIFile *File,
+                     unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
+                     uint32_t AlignInBits, DINodeArray Annotations),
+                    (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
+                     Annotations))
+  DEFINE_MDNODE_GET(DILocalVariable,
+                    (Metadata * Scope, MDString *Name, Metadata *File,
+                     unsigned Line, Metadata *Type, unsigned Arg,
+                     DIFlags Flags, uint32_t AlignInBits, Metadata *Annotations),
+                    (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
+                     Annotations))
 
   TempDILocalVariable clone() const { return cloneImpl(); }
 
@@ -3248,14 +3211,14 @@ class DILabel : public DINode {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DILabel,
-                                (DILocalScope * Scope, StringRef Name,
-                                 DIFile *File, unsigned Line),
-                                (Scope, Name, File, Line))
-  DEFINE_ALL_MDNODE_GET_METHODS(DILabel,
-                                (Metadata * Scope, MDString *Name,
-                                 Metadata *File, unsigned Line),
-                                (Scope, Name, File, Line))
+  DEFINE_MDNODE_GET(DILabel,
+                    (DILocalScope * Scope, StringRef Name, DIFile *File,
+                     unsigned Line),
+                    (Scope, Name, File, Line))
+  DEFINE_MDNODE_GET(DILabel,
+                    (Metadata * Scope, MDString *Name, Metadata *File,
+                     unsigned Line),
+                    (Scope, Name, File, Line))
 
   TempDILabel clone() const { return cloneImpl(); }
 
@@ -3323,18 +3286,18 @@ class DIObjCProperty : public DINode {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DIObjCProperty,
-                                (StringRef Name, DIFile *File, unsigned Line,
-                                 StringRef GetterName, StringRef SetterName,
-                                 unsigned Attributes, DIType *Type),
-                                (Name, File, Line, GetterName, SetterName,
-                                 Attributes, Type))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIObjCProperty,
-                                (MDString * Name, Metadata *File, unsigned Line,
-                                 MDString *GetterName, MDString *SetterName,
-                                 unsigned Attributes, Metadata *Type),
-                                (Name, File, Line, GetterName, SetterName,
-                                 Attributes, Type))
+  DEFINE_MDNODE_GET(DIObjCProperty,
+                    (StringRef Name, DIFile *File, unsigned Line,
+                     StringRef GetterName, StringRef SetterName,
+                     unsigned Attributes, DIType *Type),
+                    (Name, File, Line, GetterName, SetterName, Attributes,
+                     Type))
+  DEFINE_MDNODE_GET(DIObjCProperty,
+                    (MDString * Name, Metadata *File, unsigned Line,
+                     MDString *GetterName, MDString *SetterName,
+                     unsigned Attributes, Metadata *Type),
+                    (Name, File, Line, GetterName, SetterName, Attributes,
+                     Type))
 
   TempDIObjCProperty clone() const { return cloneImpl(); }
 
@@ -3401,16 +3364,16 @@ class DIImportedEntity : public DINode {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(
-      DIImportedEntity,
-      (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
-       unsigned Line, StringRef Name = "", DINodeArray Elements = nullptr),
-      (Tag, Scope, Entity, File, Line, Name, Elements))
-  DEFINE_ALL_MDNODE_GET_METHODS(
-      DIImportedEntity,
-      (unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File,
-       unsigned Line, MDString *Name, Metadata *Elements = nullptr),
-      (Tag, Scope, Entity, File, Line, Name, Elements))
+  DEFINE_MDNODE_GET(DIImportedEntity,
+                    (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
+                     unsigned Line, StringRef Name = "",
+                     DINodeArray Elements = nullptr),
+                    (Tag, Scope, Entity, File, Line, Name, Elements))
+  DEFINE_MDNODE_GET(DIImportedEntity,
+                    (unsigned Tag, Metadata *Scope, Metadata *Entity,
+                     Metadata *File, unsigned Line, MDString *Name,
+                     Metadata *Elements = nullptr),
+                    (Tag, Scope, Entity, File, Line, Name, Elements))
 
   TempDIImportedEntity clone() const { return cloneImpl(); }
 
@@ -3453,9 +3416,9 @@ class DIGlobalVariableExpression : public MDNode {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DIGlobalVariableExpression,
-                                (Metadata * Variable, Metadata *Expression),
-                                (Variable, Expression))
+  DEFINE_MDNODE_GET(DIGlobalVariableExpression,
+                    (Metadata * Variable, Metadata *Expression),
+                    (Variable, Expression))
 
   TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
 
@@ -3552,14 +3515,12 @@ class DIMacro : public DIMacroNode {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DIMacro,
-                                (unsigned MIType, unsigned Line, StringRef Name,
-                                 StringRef Value = ""),
-                                (MIType, Line, Name, Value))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIMacro,
-                                (unsigned MIType, unsigned Line, MDString *Name,
-                                 MDString *Value),
-                                (MIType, Line, Name, Value))
+  DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, StringRef Name,
+                              StringRef Value = ""),
+                    (MIType, Line, Name, Value))
+  DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, MDString *Name,
+                              MDString *Value),
+                    (MIType, Line, Name, Value))
 
   TempDIMacro clone() const { return cloneImpl(); }
 
@@ -3605,14 +3566,12 @@ class DIMacroFile : public DIMacroNode {
   }
 
 public:
-  DEFINE_ALL_MDNODE_GET_METHODS(DIMacroFile,
-                                (unsigned MIType, unsigned Line, DIFile *File,
-                                 DIMacroNodeArray Elements),
-                                (MIType, Line, File, Elements))
-  DEFINE_ALL_MDNODE_GET_METHODS(DIMacroFile,
-                                (unsigned MIType, unsigned Line, Metadata *File,
-                                 Metadata *Elements),
-                                (MIType, Line, File, Elements))
+  DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line, DIFile *File,
+                                  DIMacroNodeArray Elements),
+                    (MIType, Line, File, Elements))
+  DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line,
+                                  Metadata *File, Metadata *Elements),
+                    (MIType, Line, File, Elements))
 
   TempDIMacroFile clone() const { return cloneImpl(); }
 
@@ -3670,9 +3629,7 @@ class DIArgList : public MDNode {
   void dropAllReferences();
 
 public:
-  DEFINE_ALWAYS_UNIQUED_MDNODE_GET_METHODS(DIArgList,
-                                           (ArrayRef<ValueAsMetadata *> Args),
-                                           (Args))
+  DEFINE_MDNODE_GET(DIArgList, (ArrayRef<ValueAsMetadata *> Args), (Args))
 
   TempDIArgList clone() const { return cloneImpl(); }
 
@@ -3776,11 +3733,5 @@ template <> struct DenseMapInfo<DebugVariable> {
 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
 #undef DEFINE_MDNODE_GET_UNPACK
 #undef DEFINE_MDNODE_GET
-#undef DEFINE_MDNODE_GET_IF_EXISTS
-#undef DEFINE_MDNODE_GET_DISTINCT
-#undef DEFINE_MDNODE_GET_TEMPORARY
-#undef DEFINE_ALL_MDNODE_GET_METHODS
-#undef DEFINE_ALWAYS_DISTINCT_MDNODE_GET_METHODS
-#undef DEFINE_ALWAYS_UNIQUED_MDNODE_GET_METHODS
 
 #endif // LLVM_IR_DEBUGINFOMETADATA_H
index fdef807..bbf349e 100644 (file)
@@ -8,39 +8,12 @@
 //
 // Macros for running through all types of metadata.
 //
-// Definitions for terms used to describe metadata include:
-//
-// * BRANCH: refers to an "abstract" metadata kind, which exists only in the
-//   C++ class hierarchy. These cannot appear directly in IR/bitcode.
-// * LEAF: refers to a "concrete" metadata kind. These can appear directly in
-//   IR/bitcode.
-// * SPECIALIZED: refers to non-MDTuple MDNodes, i.e. those that use the
-//   syntax "!CLASS(...)" in IR.
-// * UNIQUABLE: refers to nodes which can use uniqued, distinct, or temporary
-//   storage without any restrictions.
-// * UNIQUED: refers to nodes which must use uniqued or temporary storage.
-// * DISTINCT: refers to nodes which must use distinct or temporary storage.
-//
-// In LLVM IR, UNIQUABLE and DISTINCT nodes must be referred to by MDNode ID,
-// as in `!0`, whereas UNIQUED nodes canonically appear inline at each use, as
-// in `DIExpression(...)`. This is because `distinct` nodes maintain their
-// identity irrespective of contents, making the inline syntax ambiguous in
-// some cases.
-//
-// Note: UNIQUABLE, UNIQUED, and DISTINCT are mutually exclusive. For example,
-// code which intends to consider all nodes which can use uniqued storage must
-// consider both UNIQUABLE and UNIQUED nodes.
-//
 //===----------------------------------------------------------------------===//
 
 #if !(defined HANDLE_METADATA || defined HANDLE_METADATA_LEAF ||               \
       defined HANDLE_METADATA_BRANCH || defined HANDLE_MDNODE_LEAF ||          \
-      defined HANDLE_MDNODE_LEAF_UNIQUABLE ||                                  \
-      defined HANDLE_MDNODE_LEAF_UNIQUED ||                                    \
-      defined HANDLE_MDNODE_LEAF_DISTINCT || defined HANDLE_MDNODE_BRANCH ||   \
+      defined HANDLE_MDNODE_LEAF_UNIQUABLE || defined HANDLE_MDNODE_BRANCH ||  \
       defined HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE ||                      \
-      defined HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUED ||                        \
-      defined HANDLE_SPECIALIZED_MDNODE_LEAF_DISTINCT ||                       \
       defined HANDLE_SPECIALIZED_MDNODE_LEAF ||                                \
       defined HANDLE_SPECIALIZED_MDNODE_BRANCH)
 #error "Missing macro definition of HANDLE_METADATA*"
@@ -61,7 +34,7 @@
 #define HANDLE_METADATA_BRANCH(CLASS) HANDLE_METADATA(CLASS)
 #endif
 
-// Handler for specialized and uniquable leaf nodes under MDNode. Defers to
+// Handler for specialized and uniquable leaf nodes under MDNode.  Defers to
 // HANDLE_MDNODE_LEAF_UNIQUABLE if it's defined, otherwise to
 // HANDLE_SPECIALIZED_MDNODE_LEAF.
 #ifndef HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE
 #endif
 #endif
 
-// Handler for specialized and always-uniqued leaf nodes under MDNode. Defers to
-// HANDLE_MDNODE_LEAF_UNIQUED if it's defined, otherwise to
-// HANDLE_SPECIALIZED_MDNODE_LEAF.
-#ifndef HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUED
-#ifdef HANDLE_MDNODE_LEAF_UNIQUED
-#define HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUED(CLASS)                        \
-  HANDLE_MDNODE_LEAF_UNIQUED(CLASS)
-#else
-#define HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUED(CLASS)                        \
-  HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS)
-#endif
-#endif
-
-// Handler for specialized and always-distinct leaf nodes under MDNode. Defers
-// to HANDLE_MDNODE_LEAF_DISTINCT if it's defined, otherwise to
-// HANDLE_SPECIALIZED_MDNODE_LEAF.
-#ifndef HANDLE_SPECIALIZED_MDNODE_LEAF_DISTINCT
-#ifdef HANDLE_MDNODE_LEAF_DISTINCT
-#define HANDLE_SPECIALIZED_MDNODE_LEAF_DISTINCT(CLASS)                        \
-  HANDLE_MDNODE_LEAF_DISTINCT(CLASS)
-#else
-#define HANDLE_SPECIALIZED_MDNODE_LEAF_DISTINCT(CLASS)                        \
-  HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS)
-#endif
-#endif
-
-// Handler for uniquable leaf nodes under MDNode.
+// Handler for leaf nodes under MDNode.
 #ifndef HANDLE_MDNODE_LEAF_UNIQUABLE
 #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) HANDLE_MDNODE_LEAF(CLASS)
 #endif
 
-// Handler for uniqued leaf nodes under MDNode.
-#ifndef HANDLE_MDNODE_LEAF_UNIQUED
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS) HANDLE_MDNODE_LEAF(CLASS)
-#endif
-
-// Handler for distinct leaf nodes under MDNode.
-#ifndef HANDLE_MDNODE_LEAF_DISTINCT
-#define HANDLE_MDNODE_LEAF_DISTINCT(CLASS) HANDLE_MDNODE_LEAF(CLASS)
-#endif
-
 // Handler for leaf nodes under MDNode.
 #ifndef HANDLE_MDNODE_LEAF
 #define HANDLE_MDNODE_LEAF(CLASS) HANDLE_METADATA_LEAF(CLASS)
@@ -143,7 +80,7 @@ HANDLE_METADATA_LEAF(DistinctMDOperandPlaceholder)
 HANDLE_MDNODE_BRANCH(MDNode)
 HANDLE_MDNODE_LEAF_UNIQUABLE(MDTuple)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DILocation)
-HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUED(DIExpression)
+HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIExpression)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIGlobalVariableExpression)
 HANDLE_SPECIALIZED_MDNODE_BRANCH(DINode)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(GenericDINode)
@@ -156,7 +93,7 @@ HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIDerivedType)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DICompositeType)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DISubroutineType)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIFile)
-HANDLE_SPECIALIZED_MDNODE_LEAF_DISTINCT(DICompileUnit)
+HANDLE_SPECIALIZED_MDNODE_LEAF(DICompileUnit)
 HANDLE_SPECIALIZED_MDNODE_BRANCH(DILocalScope)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DISubprogram)
 HANDLE_SPECIALIZED_MDNODE_BRANCH(DILexicalBlockBase)
@@ -177,7 +114,7 @@ HANDLE_SPECIALIZED_MDNODE_BRANCH(DIMacroNode)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIMacro)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIMacroFile)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DICommonBlock)
-HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUED(DIArgList)
+HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIArgList)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIStringType)
 HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIGenericSubrange)
 
@@ -186,11 +123,7 @@ HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIGenericSubrange)
 #undef HANDLE_METADATA_BRANCH
 #undef HANDLE_MDNODE_LEAF
 #undef HANDLE_MDNODE_LEAF_UNIQUABLE
-#undef HANDLE_MDNODE_LEAF_UNIQUED
-#undef HANDLE_MDNODE_LEAF_DISTINCT
 #undef HANDLE_MDNODE_BRANCH
 #undef HANDLE_SPECIALIZED_MDNODE_LEAF
 #undef HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE
-#undef HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUED
-#undef HANDLE_SPECIALIZED_MDNODE_LEAF_DISTINCT
 #undef HANDLE_SPECIALIZED_MDNODE_BRANCH
index 62c1c24..5bce1ea 100644 (file)
@@ -742,29 +742,27 @@ bool LLParser::parseNamedMetadata() {
     return true;
 
   NamedMDNode *NMD = M->getOrInsertNamedMetadata(Name);
-
-  if (Lex.getKind() == lltok::rbrace) {
-    Lex.Lex();
-    return false;
-  }
-
-  do {
-    MDNode *N = nullptr;
-    // Parse uniqued MDNodes inline as a special case.
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS)                                      \
-  if (Lex.getKind() == lltok::MetadataVar && Lex.getStrVal() == #CLASS) {      \
-    if (parse##CLASS(N, /*IsDistinct=*/false))                                 \
-      return true;                                                             \
-    NMD->addOperand(N);                                                        \
-    continue;                                                                  \
-  }
-#include "llvm/IR/Metadata.def"
-    // Parse all other MDNodes as an MDNodeID.
-    if (parseToken(lltok::exclaim, "Expected '!' here") || parseMDNodeID(N)) {
-      return true;
-    }
-    NMD->addOperand(N);
-  } while (EatIfPresent(lltok::comma));
+  if (Lex.getKind() != lltok::rbrace)
+    do {
+      MDNode *N = nullptr;
+      // parse DIExpressions inline as a special case. They are still MDNodes,
+      // so they can still appear in named metadata. Remove this logic if they
+      // become plain Metadata.
+      if (Lex.getKind() == lltok::MetadataVar &&
+          Lex.getStrVal() == "DIExpression") {
+        if (parseDIExpression(N, /*IsDistinct=*/false))
+          return true;
+        // DIArgLists should only appear inline in a function, as they may
+        // contain LocalAsMetadata arguments which require a function context.
+      } else if (Lex.getKind() == lltok::MetadataVar &&
+                 Lex.getStrVal() == "DIArgList") {
+        return tokError("found DIArgList outside of function");
+      } else if (parseToken(lltok::exclaim, "Expected '!' here") ||
+                 parseMDNodeID(N)) {
+        return true;
+      }
+      NMD->addOperand(N);
+    } while (EatIfPresent(lltok::comma));
 
   return parseToken(lltok::rbrace, "expected end of metadata node");
 }
@@ -784,10 +782,9 @@ bool LLParser::parseStandaloneMetadata() {
   if (Lex.getKind() == lltok::Type)
     return tokError("unexpected type in metadata definition");
 
-  auto DistinctLoc = Lex.getLoc();
   bool IsDistinct = EatIfPresent(lltok::kw_distinct);
   if (Lex.getKind() == lltok::MetadataVar) {
-    if (parseSpecializedMDNode(Init, IsDistinct, DistinctLoc))
+    if (parseSpecializedMDNode(Init, IsDistinct))
       return true;
   } else if (parseToken(lltok::exclaim, "Expected '!' here") ||
              parseMDTuple(Init, IsDistinct))
@@ -4335,25 +4332,12 @@ bool LLParser::parseMDField(StringRef Name, FieldTy &Result) {
   return parseMDField(Loc, Name, Result);
 }
 
-bool LLParser::parseSpecializedMDNode(MDNode *&N, bool IsDistinct,
-                                      LocTy DistinctLoc) {
+bool LLParser::parseSpecializedMDNode(MDNode *&N, bool IsDistinct) {
   assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
 
-#define HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(CLASS)                        \
+#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS)                                  \
   if (Lex.getStrVal() == #CLASS)                                               \
     return parse##CLASS(N, IsDistinct);
-#define HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUED(CLASS)                          \
-  if (Lex.getStrVal() == #CLASS) {                                             \
-    if (IsDistinct)                                                            \
-      return error(DistinctLoc, "'distinct' not allowed for !" #CLASS);        \
-    return parse##CLASS(N, IsDistinct);                                        \
-  }
-#define HANDLE_SPECIALIZED_MDNODE_LEAF_DISTINCT(CLASS)                         \
-  if (Lex.getStrVal() == #CLASS) {                                             \
-    if (!IsDistinct)                                                           \
-      return error(DistinctLoc, "missing 'distinct', required for !" #CLASS);  \
-    return parse##CLASS(N, IsDistinct);                                        \
-  }
 #include "llvm/IR/Metadata.def"
 
   return tokError("expected metadata type");
@@ -4699,6 +4683,9 @@ bool LLParser::parseDIFile(MDNode *&Result, bool IsDistinct) {
 ///                      globals: !4, imports: !5, macros: !6, dwoId: 0x0abcd,
 ///                      sysroot: "/", sdk: "MacOSX.sdk")
 bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
+  if (!IsDistinct)
+    return Lex.Error("missing 'distinct', required for !DICompileUnit");
+
 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)                                    \
   REQUIRED(language, DwarfLangField, );                                        \
   REQUIRED(file, MDField, (/* AllowNull */ false));                            \
@@ -5022,7 +5009,6 @@ bool LLParser::parseDILabel(MDNode *&Result, bool IsDistinct) {
 /// parseDIExpression:
 ///   ::= !DIExpression(0, 7, -1)
 bool LLParser::parseDIExpression(MDNode *&Result, bool IsDistinct) {
-  assert(!IsDistinct && "DIExpression must not be distinct");
   assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
   Lex.Lex();
 
@@ -5064,18 +5050,17 @@ bool LLParser::parseDIExpression(MDNode *&Result, bool IsDistinct) {
   if (parseToken(lltok::rparen, "expected ')' here"))
     return true;
 
-  Result = DIExpression::get(Context, Elements);
+  Result = GET_OR_DISTINCT(DIExpression, (Context, Elements));
   return false;
 }
 
 bool LLParser::parseDIArgList(MDNode *&Result, bool IsDistinct) {
-  return tokError("!DIArgList cannot appear outside of a function");
+  return parseDIArgList(Result, IsDistinct, nullptr);
 }
 /// ParseDIArgList:
 ///   ::= !DIArgList(i32 7, i64 %0)
 bool LLParser::parseDIArgList(MDNode *&Result, bool IsDistinct,
                               PerFunctionState *PFS) {
-  assert(!IsDistinct && "DIArgList must not be distinct");
   assert(PFS && "Expected valid function state");
   assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
   Lex.Lex();
@@ -5095,7 +5080,7 @@ bool LLParser::parseDIArgList(MDNode *&Result, bool IsDistinct,
   if (parseToken(lltok::rparen, "expected ')' here"))
     return true;
 
-  Result = DIArgList::get(Context, Args);
+  Result = GET_OR_DISTINCT(DIArgList, (Context, Args));
   return false;
 }
 
index 4151e02..15e2386 100644 (file)
@@ -554,7 +554,7 @@ class MetadataLoader::MetadataLoaderImpl {
   }
 
   /// Upgrade the expression from previous versions.
-  Error upgradeDIExpression(uint64_t FromVersion, bool &IsDistinct,
+  Error upgradeDIExpression(uint64_t FromVersion,
                             MutableArrayRef<uint64_t> &Expr,
                             SmallVectorImpl<uint64_t> &Buffer) {
     auto N = Expr.size();
@@ -628,9 +628,6 @@ class MetadataLoader::MetadataLoaderImpl {
       LLVM_FALLTHROUGH;
     }
     case 3:
-      IsDistinct = false;
-      LLVM_FALLTHROUGH;
-    case 4:
       // Up-to-date!
       break;
     }
@@ -2005,13 +2002,11 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
     auto Elts = MutableArrayRef<uint64_t>(Record).slice(1);
 
     SmallVector<uint64_t, 6> Buffer;
-    if (Error Err = upgradeDIExpression(Version, IsDistinct, Elts, Buffer))
+    if (Error Err = upgradeDIExpression(Version, Elts, Buffer))
       return Err;
 
-    if (IsDistinct)
-      return error("Invalid record");
-
-    MetadataList.assignValue(DIExpression::get(Context, Elts), NextMetadataNo);
+    MetadataList.assignValue(
+        GET_OR_DISTINCT(DIExpression, (Context, Elts)), NextMetadataNo);
     NextMetadataNo++;
     break;
   }
index a92c11e..fd77a8c 100644 (file)
@@ -1766,6 +1766,7 @@ void ModuleBitcodeWriter::writeDIFile(const DIFile *N,
 void ModuleBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
                                              SmallVectorImpl<uint64_t> &Record,
                                              unsigned Abbrev) {
+  assert(N->isDistinct() && "Expected distinct compile units");
   Record.push_back(/* IsDistinct */ true);
   Record.push_back(N->getSourceLanguage());
   Record.push_back(VE.getMetadataOrNullID(N->getFile()));
@@ -2019,7 +2020,7 @@ void ModuleBitcodeWriter::writeDIExpression(const DIExpression *N,
                                             SmallVectorImpl<uint64_t> &Record,
                                             unsigned Abbrev) {
   Record.reserve(N->getElements().size() + 1);
-  const uint64_t Version = 4 << 1;
+  const uint64_t Version = 3 << 1;
   Record.push_back((uint64_t)N->isDistinct() | Version);
   Record.append(N->elements_begin(), N->elements_end());
 
@@ -2165,20 +2166,6 @@ void ModuleBitcodeWriter::writeMetadataRecords(
     if (const MDNode *N = dyn_cast<MDNode>(MD)) {
       assert(N->isResolved() && "Expected forward references to be resolved");
 
-#ifndef NDEBUG
-      switch (N->getMetadataID()) {
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS)                                      \
-  case Metadata::CLASS##Kind:                                                  \
-    assert(!N->isDistinct() && "Expected non-distinct " #CLASS);               \
-    break;
-#define HANDLE_MDNODE_LEAF_DISTINCT(CLASS)                                     \
-  case Metadata::CLASS##Kind:                                                  \
-    assert(N->isDistinct() && "Expected distinct " #CLASS);                    \
-    break;
-#include "llvm/IR/Metadata.def"
-      }
-#endif
-
       switch (N->getMetadataID()) {
       default:
         llvm_unreachable("Invalid MDNode subclass");
index 11cb1e1..1a04e1c 100644 (file)
@@ -1184,7 +1184,6 @@ bool MIParser::parseStandaloneMDNode(MDNode *&Node) {
     if (parseMDNode(Node))
       return true;
   } else if (Token.is(MIToken::md_diexpr)) {
-    // FIXME: This should be driven off of the UNIQUED property in Metadata.def
     if (parseDIExpression(Node))
       return true;
   } else if (Token.is(MIToken::md_dilocation)) {
@@ -2328,7 +2327,6 @@ bool MIParser::parseMetadataOperand(MachineOperand &Dest) {
     if (parseMDNode(Node))
       return true;
   } else if (Token.is(MIToken::md_diexpr)) {
-    // FIXME: This should be driven off of the UNIQUED property in Metadata.def
     if (parseDIExpression(Node))
       return true;
   }
index 78bc024..c7a46bd 100644 (file)
@@ -1236,11 +1236,10 @@ void SlotTracker::CreateFunctionSlot(const Value *V) {
 void SlotTracker::CreateMetadataSlot(const MDNode *N) {
   assert(N && "Can't insert a null Value into SlotTracker!");
 
-  // Don't make slots for uniqued nodes. We just print them inline everywhere.
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS)                                      \
-  if (isa<CLASS>(N))                                                           \
+  // Don't make slots for DIExpressions or DIArgLists. We just print them inline
+  // everywhere.
+  if (isa<DIExpression>(N) || isa<DIArgList>(N))
     return;
-#include "llvm/IR/Metadata.def"
 
   unsigned DestSlot = mdnNext;
   if (!mdnMap.insert(std::make_pair(N, DestSlot)).second)
@@ -2333,7 +2332,10 @@ static void writeDIExpression(raw_ostream &Out, const DIExpression *N,
 }
 
 static void writeDIArgList(raw_ostream &Out, const DIArgList *N,
-                           AsmWriterContext &WriterCtx) {
+                           AsmWriterContext &WriterCtx,
+                           bool FromValue = false) {
+  assert(FromValue &&
+         "Unexpected DIArgList metadata outside of value argument");
   Out << "!DIArgList(";
   FieldSeparator FS;
   MDFieldPrinter Printer(Out, WriterCtx);
@@ -2484,16 +2486,16 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
 static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD,
                                    AsmWriterContext &WriterCtx,
                                    bool FromValue) {
-  assert((FromValue || !(isa<LocalAsMetadata>(MD) || isa<DIArgList>(MD))) &&
-         "Unexpected function-local metadata outside of value argument");
-
-  // Write uniqued MDNodes inline when used as a value.
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS)                                      \
-  if (const CLASS *N = dyn_cast<CLASS>(MD)) {                                  \
-    write##CLASS(Out, N, WriterCtx);                                           \
-    return;                                                                    \
+  // Write DIExpressions and DIArgLists inline when used as a value. Improves
+  // readability of debug info intrinsics.
+  if (const DIExpression *Expr = dyn_cast<DIExpression>(MD)) {
+    writeDIExpression(Out, Expr, WriterCtx);
+    return;
+  }
+  if (const DIArgList *ArgList = dyn_cast<DIArgList>(MD)) {
+    writeDIArgList(Out, ArgList, WriterCtx, FromValue);
+    return;
   }
-#include "llvm/IR/Metadata.def"
 
   if (const MDNode *N = dyn_cast<MDNode>(MD)) {
     std::unique_ptr<SlotTracker> MachineStorage;
@@ -2525,6 +2527,9 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD,
 
   auto *V = cast<ValueAsMetadata>(MD);
   assert(WriterCtx.TypePrinter && "TypePrinter required for metadata values");
+  assert((FromValue || !isa<LocalAsMetadata>(V)) &&
+         "Unexpected function-local metadata outside of value argument");
+
   WriterCtx.TypePrinter->print(V->getValue()->getType(), Out);
   Out << ' ';
   WriteAsOperandInternal(Out, V->getValue(), WriterCtx);
@@ -3411,17 +3416,15 @@ void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {
     if (i)
       Out << ", ";
 
-    // Write UNIQUED nodes inline.
+    // Write DIExpressions inline.
     // FIXME: Ban DIExpressions in NamedMDNodes, they will serve no purpose.
     MDNode *Op = NMD->getOperand(i);
     assert(!isa<DIArgList>(Op) &&
            "DIArgLists should not appear in NamedMDNodes");
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS)                                      \
-  if (auto *N = dyn_cast<CLASS>(Op)) {                                         \
-    write##CLASS(Out, N, AsmWriterContext::getEmpty());                        \
-    continue;                                                                  \
-  }
-#include "llvm/IR/Metadata.def"
+    if (auto *Expr = dyn_cast<DIExpression>(Op)) {
+      writeDIExpression(Out, Expr, AsmWriterContext::getEmpty());
+      continue;
+    }
 
     int Slot = Machine.getMetadataSlot(Op);
     if (Slot == -1)
@@ -4770,15 +4773,8 @@ static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD,
   WriteAsOperandInternal(OS, &MD, *WriterCtx, /* FromValue */ true);
 
   auto *N = dyn_cast<MDNode>(&MD);
-  if (OnlyAsOperand || !N) {
-    return;
-  }
-  // Uniqued MDNodes are always treated as if OnlyAsOperand, as they are
-  // printed inline.
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS)                                      \
-  if (isa<CLASS>(MD))                                                          \
+  if (OnlyAsOperand || !N || isa<DIExpression>(MD) || isa<DIArgList>(MD))
     return;
-#include "llvm/IR/Metadata.def"
 
   OS << " = ";
   WriteMDNodeBodyInternal(OS, N, *WriterCtx);
index 0b4db90..66d4365 100644 (file)
@@ -1071,7 +1071,6 @@ DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope,
 DIExpression *DIExpression::getImpl(LLVMContext &Context,
                                     ArrayRef<uint64_t> Elements,
                                     StorageType Storage, bool ShouldCreate) {
-  assert(Storage != Distinct && "DIExpression cannot be distinct");
   DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
   DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
 }
@@ -1642,7 +1641,6 @@ DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
 DIArgList *DIArgList::getImpl(LLVMContext &Context,
                               ArrayRef<ValueAsMetadata *> Args,
                               StorageType Storage, bool ShouldCreate) {
-  assert(Storage != Distinct && "DIArgList cannot be distinct");
   DEFINE_GETIMPL_LOOKUP(DIArgList, (Args));
   DEFINE_GETIMPL_STORE_NO_OPS(DIArgList, (Args));
 }
index f60fbcf..ebbf382 100644 (file)
@@ -65,7 +65,6 @@ LLVMContextImpl::~LLVMContextImpl() {
 #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)                                    \
   for (auto *I : CLASS##s)                                                     \
     I->dropAllReferences();
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS) HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)
 #include "llvm/IR/Metadata.def"
 
   // Also drop references that come from the Value bridges.
@@ -80,7 +79,6 @@ LLVMContextImpl::~LLVMContextImpl() {
 #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)                                    \
   for (CLASS * I : CLASS##s)                                                   \
     delete I;
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS) HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)
 #include "llvm/IR/Metadata.def"
 
   // Free the constants.
index d39d3dc..d84714d 100644 (file)
@@ -1398,7 +1398,6 @@ public:
 
 #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)                                    \
   DenseSet<CLASS *, CLASS##Info> CLASS##s;
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS) HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)
 #include "llvm/IR/Metadata.def"
 
   // Optional map for looking up composite types by identifier.
index b817129..01bfff8 100644 (file)
@@ -672,7 +672,6 @@ MDNode *MDNode::replaceWithPermanentImpl() {
 #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)                                    \
   case CLASS##Kind:                                                            \
     break;
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS) HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)
 #include "llvm/IR/Metadata.def"
   }
 
@@ -813,7 +812,6 @@ MDNode *MDNode::uniquify() {
     dispatchRecalculateHash(SubclassThis, ShouldRecalculateHash);              \
     return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s);           \
   }
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS) HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)
 #include "llvm/IR/Metadata.def"
   }
 }
@@ -826,7 +824,6 @@ void MDNode::eraseFromStore() {
   case CLASS##Kind:                                                            \
     getContext().pImpl->CLASS##s.erase(cast<CLASS>(this));                     \
     break;
-#define HANDLE_MDNODE_LEAF_UNIQUED(CLASS) HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)
 #include "llvm/IR/Metadata.def"
   }
 }
diff --git a/llvm/test/Assembler/invalid-diarglist-outside-function.ll b/llvm/test/Assembler/invalid-diarglist-outside-function.ll
deleted file mode 100644 (file)
index 351cd0b..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
-
-; CHECK: <stdin>:[[@LINE+1]]:6: error: !DIArgList cannot appear outside of a function
-!0 = !DIArgList()
diff --git a/llvm/test/Assembler/invalid-diexpression-distinct.ll b/llvm/test/Assembler/invalid-diexpression-distinct.ll
deleted file mode 100644 (file)
index 96628e3..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
-
-; CHECK: <stdin>:[[@LINE+1]]:6: error: 'distinct' not allowed for !DIExpression
-!0 = distinct !DIExpression()
diff --git a/llvm/test/Bitcode/DIExpression-is-distinct-upgrade.ll b/llvm/test/Bitcode/DIExpression-is-distinct-upgrade.ll
deleted file mode 100644 (file)
index d888e9a..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-; RUN: llvm-dis -o - %s.bc | FileCheck %s
-
-!llvm.dbg.cu = !{!1}
-!llvm.module.flags = !{!8, !9}
-
-!0 = distinct !DIGlobalVariable(name: "g", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true)
-!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
-!2 = !DIFile(filename: "a.c", directory: "/")
-!3 = !{}
-!4 = !{!7}
-!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-; CHECK: expr: !DIExpression()
-!6 = distinct !DIExpression()
-!7 = !DIGlobalVariableExpression(var: !0, expr: !6)
-!8 = !{i32 2, !"Dwarf Version", i32 4}
-!9 = !{i32 2, !"Debug Info Version", i32 3}
diff --git a/llvm/test/Bitcode/DIExpression-is-distinct-upgrade.ll.bc b/llvm/test/Bitcode/DIExpression-is-distinct-upgrade.ll.bc
deleted file mode 100644 (file)
index 4be649d..0000000
Binary files a/llvm/test/Bitcode/DIExpression-is-distinct-upgrade.ll.bc and /dev/null differ