[PATCH] D33870: Expose IRMover flag

Ben Karel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 3 15:20:38 PDT 2017


eschew created this revision.

In the 4.0 cycle, the NamedOnly flag in IRMover.cpp was changed from true to false. This wound up breaking my out-of-tree compiler frontend.

The attached patch threads through the NamedOnly flag from IRMover to Linker and adds a new flag enum value. Thus, the behavior of existing code remains the same, but linker clients can override the NamedOnly behavior as needed.

I added new constructors to IRMover and Linker, rather than changing the signature of the existing constructors, to minimize changes in the rest of the codebase.

I'm looking into adding a test for the new flag but wanted to throw the current diff up for review first.


https://reviews.llvm.org/D33870

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


Index: lib/Linker/LinkModules.cpp
===================================================================
--- lib/Linker/LinkModules.cpp
+++ lib/Linker/LinkModules.cpp
@@ -561,6 +561,9 @@
 
 Linker::Linker(Module &M) : Mover(M) {}
 
+Linker::Linker(Module &M, unsigned Flags) :
+  Mover(M, (Flags & DontLinkUnnamedTypes) != 0) {}
+
 bool Linker::linkInModule(
     std::unique_ptr<Module> Src, unsigned Flags,
     std::function<void(Module &, const StringSet<> &)> InternalizeCallback) {
@@ -581,7 +584,7 @@
 bool Linker::linkModules(
     Module &Dest, std::unique_ptr<Module> Src, unsigned Flags,
     std::function<void(Module &, const StringSet<> &)> InternalizeCallback) {
-  Linker L(Dest);
+  Linker L(Dest, Flags);
   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,10 @@
   return I == NonOpaqueStructTypes.end() ? false : *I == Ty;
 }
 
-IRMover::IRMover(Module &M) : Composite(M) {
+IRMover::IRMover(Module &M) : IRMover::IRMover(M, false) {}
+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,11 @@
     None = 0,
     OverrideFromSrc = (1 << 0),
     LinkOnlyNeeded = (1 << 1),
+    DontLinkUnnamedTypes = (1 << 2),
   };
 
   Linker(Module &M);
+  Linker(Module &M, unsigned Flags);
 
   /// \brief Link \p Src into the composite.
   ///
Index: include/llvm/Linker/IRMover.h
===================================================================
--- include/llvm/Linker/IRMover.h
+++ include/llvm/Linker/IRMover.h
@@ -61,6 +61,7 @@
   };
 
   IRMover(Module &M);
+  IRMover(Module &M, bool OnlyNamedTypes);
 
   typedef std::function<void(GlobalValue &)> ValueAdder;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33870.101332.patch
Type: text/x-patch
Size: 2201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170603/16042ae3/attachment.bin>


More information about the llvm-commits mailing list