[llvm] r294015 - ModuleLinker: Remove importing support. NFCI.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 3 08:58:19 PST 2017
Author: pcc
Date: Fri Feb 3 10:58:19 2017
New Revision: 294015
URL: http://llvm.org/viewvc/llvm-project?rev=294015&view=rev
Log:
ModuleLinker: Remove importing support. NFCI.
Differential Revision: https://reviews.llvm.org/D29470
Modified:
llvm/trunk/include/llvm/Linker/Linker.h
llvm/trunk/lib/Linker/LinkModules.cpp
Modified: llvm/trunk/include/llvm/Linker/Linker.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Linker/Linker.h?rev=294015&r1=294014&r2=294015&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Linker/Linker.h (original)
+++ llvm/trunk/include/llvm/Linker/Linker.h Fri Feb 3 10:58:19 2017
@@ -30,9 +30,6 @@ public:
OverrideFromSrc = (1 << 0),
LinkOnlyNeeded = (1 << 1),
InternalizeLinkedSymbols = (1 << 2),
- /// Don't force link referenced linkonce definitions, import declaration.
- DontForceLinkLinkonceODR = (1 << 3)
-
};
Linker(Module &M);
@@ -41,13 +38,9 @@ public:
///
/// Passing OverrideSymbols as true will have symbols from Src
/// shadow those in the Dest.
- /// For ThinLTO function importing/exporting the \p ModuleSummaryIndex
- /// is passed. If \p GlobalsToImport is provided, only the globals that
- /// are part of the set will be imported from the source module.
///
/// Returns true on error.
- bool linkInModule(std::unique_ptr<Module> Src, unsigned Flags = Flags::None,
- DenseSet<const GlobalValue *> *GlobalsToImport = nullptr);
+ bool linkInModule(std::unique_ptr<Module> Src, unsigned Flags = Flags::None);
static bool linkModules(Module &Dest, std::unique_ptr<Module> Src,
unsigned Flags = Flags::None);
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=294015&r1=294014&r2=294015&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Fri Feb 3 10:58:19 2017
@@ -15,11 +15,13 @@
#include "llvm-c/Linker.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringSet.h"
+#include "llvm/IR/Comdat.h"
#include "llvm/IR/DiagnosticPrinter.h"
+#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
#include "llvm/Linker/Linker.h"
#include "llvm/Support/Error.h"
-#include "llvm/Transforms/Utils/FunctionImportUtils.h"
using namespace llvm;
namespace {
@@ -36,19 +38,12 @@ class ModuleLinker {
/// For symbol clashes, prefer those from Src.
unsigned Flags;
- /// Functions to import from source module, all other functions are
- /// imported as declarations instead of definitions.
- DenseSet<const GlobalValue *> *GlobalsToImport;
-
/// Used as the callback for lazy linking.
/// The mover has just hit GV and we have to decide if it, and other members
/// of the same comdat, should be linked. Every member to be linked is passed
/// to Add.
void addLazyFor(GlobalValue &GV, const IRMover::ValueAdder &Add);
- bool shouldLinkReferencedLinkOnce() {
- return !(Flags & Linker::DontForceLinkLinkonceODR);
- }
bool shouldOverrideFromSrc() { return Flags & Linker::OverrideFromSrc; }
bool shouldLinkOnlyNeeded() { return Flags & Linker::LinkOnlyNeeded; }
bool shouldInternalizeLinkedSymbols() {
@@ -108,30 +103,14 @@ class ModuleLinker {
bool linkIfNeeded(GlobalValue &GV);
- /// Helper method to check if we are importing from the current source
- /// module.
- bool isPerformingImport() const { return GlobalsToImport != nullptr; }
-
- /// If we are importing from the source module, checks if we should
- /// import SGV as a definition, otherwise import as a declaration.
- bool doImportAsDefinition(const GlobalValue *SGV);
-
public:
- ModuleLinker(IRMover &Mover, std::unique_ptr<Module> SrcM, unsigned Flags,
- DenseSet<const GlobalValue *> *GlobalsToImport = nullptr)
- : Mover(Mover), SrcM(std::move(SrcM)), Flags(Flags),
- GlobalsToImport(GlobalsToImport) {}
+ ModuleLinker(IRMover &Mover, std::unique_ptr<Module> SrcM, unsigned Flags)
+ : Mover(Mover), SrcM(std::move(SrcM)), Flags(Flags) {}
bool run();
};
}
-bool ModuleLinker::doImportAsDefinition(const GlobalValue *SGV) {
- if (!isPerformingImport())
- return false;
- report_fatal_error("ModuleLinker does not support importing");
-}
-
static GlobalValue::VisibilityTypes
getMinVisibility(GlobalValue::VisibilityTypes A,
GlobalValue::VisibilityTypes B) {
@@ -265,18 +244,10 @@ bool ModuleLinker::shouldLinkFromSource(
// We always have to add Src if it has appending linkage.
if (Src.hasAppendingLinkage()) {
- // Should have prevented importing for appending linkage in linkIfNeeded.
- assert(!isPerformingImport());
LinkFromSrc = true;
return false;
}
- if (isPerformingImport()) {
- // LinkFromSrc iff this is a global requested for importing.
- LinkFromSrc = GlobalsToImport->count(&Src);
- return false;
- }
-
bool SrcIsDeclaration = Src.isDeclarationForLinker();
bool DestIsDeclaration = Dest.isDeclarationForLinker();
@@ -382,19 +353,9 @@ bool ModuleLinker::linkIfNeeded(GlobalVa
GV.setUnnamedAddr(UnnamedAddr);
}
- // Don't want to append to global_ctors list, for example, when we
- // are importing for ThinLTO, otherwise the global ctors and dtors
- // get executed multiple times for local variables (the latter causing
- // double frees).
- if (GV.hasAppendingLinkage() && isPerformingImport())
- return false;
-
- if (isPerformingImport()) {
- if (!doImportAsDefinition(&GV))
- return false;
- } else if (!DGV && !shouldOverrideFromSrc() &&
- (GV.hasLocalLinkage() || GV.hasLinkOnceLinkage() ||
- GV.hasAvailableExternallyLinkage()))
+ if (!DGV && !shouldOverrideFromSrc() &&
+ (GV.hasLocalLinkage() || GV.hasLinkOnceLinkage() ||
+ GV.hasAvailableExternallyLinkage()))
return false;
if (GV.isDeclaration())
@@ -417,12 +378,6 @@ bool ModuleLinker::linkIfNeeded(GlobalVa
}
void ModuleLinker::addLazyFor(GlobalValue &GV, const IRMover::ValueAdder &Add) {
- if (!shouldLinkReferencedLinkOnce())
- // For ThinLTO we don't import more than what was required.
- // The client has to guarantee that the linkonce will be availabe at link
- // time (by promoting it to weak for instance).
- return;
-
// Add these to the internalize list
if (!GV.hasLinkOnceLinkage() && !GV.hasAvailableExternallyLinkage() &&
!shouldLinkOnlyNeeded())
@@ -583,8 +538,8 @@ bool ModuleLinker::run() {
[this](GlobalValue &GV, IRMover::ValueAdder Add) {
addLazyFor(GV, Add);
},
- /* LinkModuleInlineAsm */ !isPerformingImport(),
- /* IsPerformingImport */ isPerformingImport())) {
+ /* LinkModuleInlineAsm */ true,
+ /* IsPerformingImport */ false)) {
handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
DstM.getContext().diagnose(LinkDiagnosticInfo(DS_Error, EIB.message()));
HasErrors = true;
@@ -603,9 +558,8 @@ bool ModuleLinker::run() {
Linker::Linker(Module &M) : Mover(M) {}
-bool Linker::linkInModule(std::unique_ptr<Module> Src, unsigned Flags,
- DenseSet<const GlobalValue *> *GlobalsToImport) {
- ModuleLinker ModLinker(Mover, std::move(Src), Flags, GlobalsToImport);
+bool Linker::linkInModule(std::unique_ptr<Module> Src, unsigned Flags) {
+ ModuleLinker ModLinker(Mover, std::move(Src), Flags);
return ModLinker.run();
}
More information about the llvm-commits
mailing list