[llvm] r225914 - Utils: Add mapping for uniqued MDLocations

Duncan P. N. Exon Smith dexonsmith at apple.com
Tue Jan 13 17:20:27 PST 2015


Author: dexonsmith
Date: Tue Jan 13 19:20:27 2015
New Revision: 225914

URL: http://llvm.org/viewvc/llvm-project?rev=225914&view=rev
Log:
Utils: Add mapping for uniqued MDLocations

Still doesn't handle distinct ones.  Part of PR21433.

Added:
    llvm/trunk/test/Linker/Inputs/mdlocation.ll
    llvm/trunk/test/Linker/mdlocation.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp

Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=225914&r1=225913&r2=225914&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Tue Jan 13 19:20:27 2015
@@ -219,8 +219,8 @@ static bool shouldRemapUniquedNode(const
   return false;
 }
 
-static Metadata *cloneMDTuple(const UniquableMDNode *Node,
-                              ValueToValueMapTy &VM, RemapFlags Flags,
+static Metadata *cloneMDTuple(const MDTuple *Node, ValueToValueMapTy &VM,
+                              RemapFlags Flags,
                               ValueMapTypeRemapper *TypeMapper,
                               ValueMaterializer *Materializer) {
   SmallVector<Metadata *, 4> Elts;
@@ -232,6 +232,16 @@ static Metadata *cloneMDTuple(const Uniq
   return MDTuple::get(Node->getContext(), Elts);
 }
 
+static Metadata *cloneMDLocation(const MDLocation *Node, ValueToValueMapTy &VM,
+                                 RemapFlags Flags,
+                                 ValueMapTypeRemapper *TypeMapper,
+                                 ValueMaterializer *Materializer) {
+  return MDLocation::get(
+      Node->getContext(), Node->getLine(), Node->getColumn(),
+      mapMetadataOp(Node->getScope(), VM, Flags, TypeMapper, Materializer),
+      mapMetadataOp(Node->getInlinedAt(), VM, Flags, TypeMapper, Materializer));
+}
+
 /// \brief Map a uniqued MDNode.
 ///
 /// Uniqued nodes may not need to be recreated (they may map to themselves).
@@ -254,7 +264,17 @@ static Metadata *mapUniquedNode(const Un
   }
 
   // At least one operand needs remapping.
-  Metadata *NewMD = cloneMDTuple(Node, VM, Flags, TypeMapper, Materializer);
+  Metadata *NewMD;
+  switch (Node->getMetadataID()) {
+  default:
+    llvm_unreachable("Invalid UniquableMDNode subclass");
+#define HANDLE_UNIQUABLE_LEAF(CLASS)                                           \
+  case Metadata::CLASS##Kind:                                                  \
+    NewMD =                                                                    \
+        clone##CLASS(cast<CLASS>(Node), VM, Flags, TypeMapper, Materializer);  \
+    break;
+#include "llvm/IR/Metadata.def"
+  }
   Dummy->replaceAllUsesWith(NewMD);
   MDNode::deleteTemporary(Dummy);
   return mapToMetadata(VM, Node, NewMD);

Added: llvm/trunk/test/Linker/Inputs/mdlocation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/mdlocation.ll?rev=225914&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/mdlocation.ll (added)
+++ llvm/trunk/test/Linker/Inputs/mdlocation.ll Tue Jan 13 19:20:27 2015
@@ -0,0 +1,10 @@
+!named = !{!0, !1, !2, !3, !4, !5, !6, !7}
+
+!0 = !{} ; Use this as a scope.
+!1 = !MDLocation(line: 3, column: 7, scope: !0)
+!2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
+!3 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !2)
+!4 = distinct !{} ; Test actual remapping.
+!5 = !MDLocation(line: 3, column: 7, scope: !4)
+!6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
+!7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)

Added: llvm/trunk/test/Linker/mdlocation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/mdlocation.ll?rev=225914&view=auto
==============================================================================
--- llvm/trunk/test/Linker/mdlocation.ll (added)
+++ llvm/trunk/test/Linker/mdlocation.ll Tue Jan 13 19:20:27 2015
@@ -0,0 +1,27 @@
+; RUN: llvm-link %s %S/Inputs/mdlocation.ll -o - -S | FileCheck %s
+
+; Test that MDLocations are remapped properly.
+
+; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !0, !1, !2, !3, !8, !9, !10, !11}
+!named = !{!0, !1, !2, !3, !4, !5, !6, !7}
+
+; CHECK:      !0 = !{}
+; CHECK-NEXT: !1 = !MDLocation(line: 3, column: 7, scope: !0)
+; CHECK-NEXT: !2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
+; CHECK-NEXT: !3 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !2)
+; CHECK-NEXT: !4 = distinct !{}
+; CHECK-NEXT: !5 = !MDLocation(line: 3, column: 7, scope: !4)
+; CHECK-NEXT: !6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
+; CHECK-NEXT: !7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)
+; CHECK-NEXT: !8 = distinct !{}
+; CHECK-NEXT: !9 = !MDLocation(line: 3, column: 7, scope: !8)
+; CHECK-NEXT: !10 = !MDLocation(line: 3, column: 7, scope: !8, inlinedAt: !9)
+; CHECK-NEXT: !11 = !MDLocation(line: 3, column: 7, scope: !8, inlinedAt: !10)
+!0 = !{} ; Use this as a scope.
+!1 = !MDLocation(line: 3, column: 7, scope: !0)
+!2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
+!3 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !2)
+!4 = distinct !{} ; Test actual remapping.
+!5 = !MDLocation(line: 3, column: 7, scope: !4)
+!6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
+!7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)





More information about the llvm-commits mailing list