[PATCH] Expose the NamedOnly flag in IRMover
Ben Karel via llvm-commits
llvm-commits at lists.llvm.org
Thu May 25 09:42:37 PDT 2017
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 originally implemented the patch against the 4.0 codebase. I've compiled
it against trunk but didn't bother running any tests... I'm hoping that
it's small enough that a mainline LLVM dev can fold the patch (with fixes
for any style nits ;-)) into their compile-test cycle if desired.
Cheers!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170525/2d1a71da/attachment.html>
-------------- next part --------------
Index: include/llvm/Linker/IRMover.h
===================================================================
--- include/llvm/Linker/IRMover.h (revision 303835)
+++ include/llvm/Linker/IRMover.h (working copy)
@@ -61,6 +61,7 @@
};
IRMover(Module &M);
+ IRMover(Module &M, bool OnlyNamedTypes);
typedef std::function<void(GlobalValue &)> ValueAdder;
Index: include/llvm/Linker/Linker.h
===================================================================
--- include/llvm/Linker/Linker.h (revision 303835)
+++ include/llvm/Linker/Linker.h (working copy)
@@ -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: lib/Linker/IRMover.cpp
===================================================================
--- lib/Linker/IRMover.cpp (revision 303835)
+++ lib/Linker/IRMover.cpp (working copy)
@@ -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: lib/Linker/LinkModules.cpp
===================================================================
--- lib/Linker/LinkModules.cpp (revision 303835)
+++ lib/Linker/LinkModules.cpp (working copy)
@@ -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));
}
More information about the llvm-commits
mailing list