[PATCH] D20582: Don't add repeats of llvm.ident list when linking

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue May 24 10:56:09 PDT 2016


arsenm created this revision.
arsenm added a subscriber: llvm-commits.

Fixes spam in the common case when linking together
many modules produced by the same compiler version.

http://reviews.llvm.org/D20582

Files:
  lib/Linker/IRMover.cpp
  test/Linker/ident.ll

Index: test/Linker/ident.ll
===================================================================
--- test/Linker/ident.ll
+++ test/Linker/ident.ll
@@ -1,6 +1,6 @@
-; RUN: llvm-link %S/Inputs/ident.a.ll %S/Inputs/ident.b.ll -S | FileCheck %s
+; RUN: llvm-link %S/Inputs/ident.a.ll %S/Inputs/ident.b.ll %S/Inputs/ident.c.ll -S | FileCheck %s
 
-; Verify that multiple input llvm.ident metadata are linked together.
+; Verify that multiple input llvm.ident metadata are linked together, but uniqued.
 
 ; CHECK-DAG: !llvm.ident = !{!0, !1, !2}
 ; CHECK-DAG: "Compiler V1"
Index: lib/Linker/IRMover.cpp
===================================================================
--- lib/Linker/IRMover.cpp
+++ lib/Linker/IRMover.cpp
@@ -11,6 +11,7 @@
 #include "LinkDiagnosticInfo.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DebugInfo.h"
@@ -992,6 +993,27 @@
     if (&NMD == SrcModFlags)
       continue;
     NamedMDNode *DestNMD = DstM.getOrInsertNamedMetadata(NMD.getName());
+
+    if (NMD.getName() == "llvm.ident") {
+      StringSet<> UniqueIdents;
+
+      // Unique the compiler IDs linked together.
+      for (const MDNode *DestID : DestNMD->operands()) {
+        if (const MDString *VerStr
+            = cast_or_null<MDString>(DestID->getOperand(0)))
+          UniqueIdents.insert(VerStr->getString());
+      }
+
+      for (const MDNode *Op : NMD.operands()) {
+        if (const MDString *VerStr = cast_or_null<MDString>(Op->getOperand(0))) {
+          if (UniqueIdents.insert(VerStr->getString()).second)
+            DestNMD->addOperand(Mapper.mapMDNode(*Op));
+        }
+      }
+
+      continue;
+    }
+
     // Add Src elements into Dest node.
     for (const MDNode *Op : NMD.operands())
       DestNMD->addOperand(Mapper.mapMDNode(*Op));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20582.58273.patch
Type: text/x-patch
Size: 1896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160524/e3c87f98/attachment.bin>


More information about the llvm-commits mailing list