From 8d05185a26ecbd1079b43651c427508a6156f1ea Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Sat, 19 Mar 2016 00:40:31 +0000 Subject: Rework linkInModule(), making it oblivious to ThinLTO Summary: ThinLTO is relying on linkInModule to import selected function. However a lot of "magic" was hidden in linkInModule and the IRMover, who would rename and promote global variables on the fly. This is moving to an approach where the steps are decoupled and the client is reponsible to specify the list of globals to import. As a consequence some test are changed because they were relying on the previous behavior which was importing the definition of *every* single global without control on the client side. Now the burden is on the client to decide if a global has to be imported or not. Reviewers: tejohnson Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D18122 From: Mehdi Amini llvm-svn: 263863 --- llvm/tools/llvm-link/llvm-link.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'llvm/tools/llvm-link/llvm-link.cpp') diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp index d886bd177c2..b70ec87f889 100644 --- a/llvm/tools/llvm-link/llvm-link.cpp +++ b/llvm/tools/llvm-link/llvm-link.cpp @@ -33,6 +33,8 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/SystemUtils.h" #include "llvm/Support/ToolOutputFile.h" +#include "llvm/Transforms/Utils/FunctionImportUtils.h" + #include using namespace llvm; @@ -191,7 +193,10 @@ static bool importFunctions(const char *argv0, LLVMContext &Context, if (Verbose) errs() << "Importing " << FunctionName << " from " << FileName << "\n"; - std::unique_ptr Index; + // Link in the specified function. + DenseSet GlobalsToImport; + GlobalsToImport.insert(F); + if (!SummaryIndex.empty()) { ErrorOr> IndexOrErr = llvm::getModuleSummaryIndexForFile(SummaryIndex, diagnosticHandler); @@ -200,7 +205,11 @@ static bool importFunctions(const char *argv0, LLVMContext &Context, errs() << EC.message() << '\n'; return false; } - Index = std::move(IndexOrErr.get()); + auto Index = std::move(IndexOrErr.get()); + + // Linkage Promotion and renaming + if (renameModuleForThinLTO(*M, *Index, &GlobalsToImport)) + return true; } // Save the mapping of value ids to temporary metadata created when @@ -210,11 +219,8 @@ static bool importFunctions(const char *argv0, LLVMContext &Context, if (!TempMDVals) TempMDVals = llvm::make_unique>(); - // Link in the specified function. - DenseSet FunctionsToImport; - FunctionsToImport.insert(F); - if (L.linkInModule(std::move(M), Linker::Flags::None, Index.get(), - &FunctionsToImport, TempMDVals.get())) + if (L.linkInModule(std::move(M), Linker::Flags::None, &GlobalsToImport, + TempMDVals.get())) return false; } @@ -260,7 +266,6 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, // If a module summary index is supplied, load it so linkInModule can treat // local functions/variables as exported and promote if necessary. - std::unique_ptr Index; if (!SummaryIndex.empty()) { ErrorOr> IndexOrErr = llvm::getModuleSummaryIndexForFile(SummaryIndex, diagnosticHandler); @@ -269,13 +274,17 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, errs() << EC.message() << '\n'; return false; } - Index = std::move(IndexOrErr.get()); + auto Index = std::move(IndexOrErr.get()); + + // Promotion + if (renameModuleForThinLTO(*M, *Index)) + return true; } if (Verbose) errs() << "Linking in '" << File << "'\n"; - if (L.linkInModule(std::move(M), ApplicableFlags, Index.get())) + if (L.linkInModule(std::move(M), ApplicableFlags)) return false; // All linker flags apply to linking of subsequent files. ApplicableFlags = Flags; -- cgit v1.2.3