[PATCH] D33870: Expose IRMover flag

Ben Karel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 12:08:23 PDT 2017


eschew updated this revision to Diff 101593.
eschew edited the summary of this revision.
eschew added a comment.

This adds a defaulted parameter instead of multiple constructors. I also added a hidden flag to llvm-link.

So far I haven't managed to construct inputs which get llvm-link'ed differently when the flag is toggled (I verified that the OnlyNamed flag in TypeFinder.cpp does indeed change). I tried using the testcase from the bug which changed the flag, https://reviews.llvm.org/D26840 , but the linking behavior is essentially unchanged between ThinLTO mode, plain llvm-link, and llvm-link -no-unnamed-types. I also tried reducing a testcase from my frontend, but haven't managed to reproduce the difference in behavior via llvm-link.

FWIW I changed my frontend, so I'm not blocked by this patch, but I am curious whether there is any LLVM IR that links different via llvm-link under the NamedOnly flag.


Repository:
  rL LLVM

https://reviews.llvm.org/D33870

Files:
  include/llvm/Linker/IRMover.h
  include/llvm/Linker/Linker.h
  lib/Linker/IRMover.cpp
  lib/Linker/LinkModules.cpp
  tools/llvm-link/llvm-link.cpp


Index: tools/llvm-link/llvm-link.cpp
===================================================================
--- tools/llvm-link/llvm-link.cpp
+++ tools/llvm-link/llvm-link.cpp
@@ -97,6 +97,10 @@
 DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);
 
 static cl::opt<bool>
+NoLinkUnnamedTypes("no-link-unnamed", cl::desc("Don't link unnamed types"),
+                   cl::Hidden);
+
+static cl::opt<bool>
 SuppressWarnings("suppress-warnings", cl::desc("Suppress all linking warnings"),
                  cl::init(false));
 
@@ -361,6 +365,8 @@
   unsigned Flags = Linker::Flags::None;
   if (OnlyNeeded)
     Flags |= Linker::Flags::LinkOnlyNeeded;
+  if (NoLinkUnnamedTypes)
+    Flags |= Linker::Flags::DontLinkUnnamedTypes;
 
   // First add all the regular input files
   if (!linkFiles(argv[0], Context, L, InputFilenames, Flags))
Index: lib/Linker/LinkModules.cpp
===================================================================
--- lib/Linker/LinkModules.cpp
+++ lib/Linker/LinkModules.cpp
@@ -559,7 +559,8 @@
   return false;
 }
 
-Linker::Linker(Module &M) : Mover(M) {}
+Linker::Linker(Module &M, bool OnlyNamedTypes) :
+  Mover(M, OnlyNamedTypes) {}
 
 bool Linker::linkInModule(
     std::unique_ptr<Module> Src, unsigned Flags,
@@ -581,7 +582,8 @@
 bool Linker::linkModules(
     Module &Dest, std::unique_ptr<Module> Src, unsigned Flags,
     std::function<void(Module &, const StringSet<> &)> InternalizeCallback) {
-  Linker L(Dest);
+  bool OnlyNamedTypes = (Flags & DontLinkUnnamedTypes) != 0;
+  Linker L(Dest, OnlyNamedTypes);
   return L.linkInModule(std::move(Src), Flags, std::move(InternalizeCallback));
 }
 
Index: lib/Linker/IRMover.cpp
===================================================================
--- lib/Linker/IRMover.cpp
+++ lib/Linker/IRMover.cpp
@@ -1411,9 +1411,9 @@
   return I == NonOpaqueStructTypes.end() ? false : *I == Ty;
 }
 
-IRMover::IRMover(Module &M) : Composite(M) {
+IRMover::IRMover(Module &M, bool OnlyNamedTypes) : Composite(M) {
   TypeFinder StructTypes;
-  StructTypes.run(M, /* OnlyNamed */ false);
+  StructTypes.run(M, OnlyNamedTypes);
   for (StructType *Ty : StructTypes) {
     if (Ty->isOpaque())
       IdentifiedStructTypes.addOpaque(Ty);
Index: include/llvm/Linker/Linker.h
===================================================================
--- include/llvm/Linker/Linker.h
+++ include/llvm/Linker/Linker.h
@@ -30,9 +30,10 @@
     None = 0,
     OverrideFromSrc = (1 << 0),
     LinkOnlyNeeded = (1 << 1),
+    DontLinkUnnamedTypes = (1 << 2),
   };
 
-  Linker(Module &M);
+  Linker(Module &M, bool OnlyNamedTypes = false);
 
   /// \brief Link \p Src into the composite.
   ///
Index: include/llvm/Linker/IRMover.h
===================================================================
--- include/llvm/Linker/IRMover.h
+++ include/llvm/Linker/IRMover.h
@@ -60,7 +60,7 @@
     bool hasType(StructType *Ty);
   };
 
-  IRMover(Module &M);
+  IRMover(Module &M, bool OnlyNamedTypes = false);
 
   typedef std::function<void(GlobalValue &)> ValueAdder;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33870.101593.patch
Type: text/x-patch
Size: 3036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170606/14305005/attachment.bin>


More information about the llvm-commits mailing list