diff options
author | dim <dim@FreeBSD.org> | 2016-12-26 20:36:37 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2016-12-26 20:36:37 +0000 |
commit | 06210ae42d418d50d8d9365d5c9419308ae9e7ee (patch) | |
tree | ab60b4cdd6e430dda1f292a46a77ddb744723f31 /contrib/llvm/tools/llvm-link/llvm-link.cpp | |
parent | 2dd166267f53df1c3748b4325d294b9b839de74b (diff) | |
download | FreeBSD-src-06210ae42d418d50d8d9365d5c9419308ae9e7ee.zip FreeBSD-src-06210ae42d418d50d8d9365d5c9419308ae9e7ee.tar.gz |
MFC r309124:
Upgrade our copies of clang, llvm, lldb, compiler-rt and libc++ to 3.9.0
release, and add lld 3.9.0. Also completely revamp the build system for
clang, llvm, lldb and their related tools.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Release notes for llvm, clang and lld are available here:
<http://llvm.org/releases/3.9.0/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/clang/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/lld/docs/ReleaseNotes.html>
Thanks to Ed Maste, Bryan Drewery, Andrew Turner, Antoine Brodin and Jan
Beich for their help.
Relnotes: yes
MFC r309147:
Pull in r282174 from upstream llvm trunk (by Krzysztof Parzyszek):
[PPC] Set SP after loading data from stack frame, if no red zone is
present
Follow-up to r280705: Make sure that the SP is only restored after
all data is loaded from the stack frame, if there is no red zone.
This completes the fix for
https://llvm.org/bugs/show_bug.cgi?id=26519.
Differential Revision: https://reviews.llvm.org/D24466
Reported by: Mark Millard
PR: 214433
MFC r309149:
Pull in r283060 from upstream llvm trunk (by Hal Finkel):
[PowerPC] Refactor soft-float support, and enable PPC64 soft float
This change enables soft-float for PowerPC64, and also makes
soft-float disable all vector instruction sets for both 32-bit and
64-bit modes. This latter part is necessary because the PPC backend
canonicalizes many Altivec vector types to floating-point types, and
so soft-float breaks scalarization support for many operations. Both
for embedded targets and for operating-system kernels desiring
soft-float support, it seems reasonable that disabling hardware
floating-point also disables vector instructions (embedded targets
without hardware floating point support are unlikely to have Altivec,
etc. and operating system kernels desiring not to use floating-point
registers to lower syscall cost are unlikely to want to use vector
registers either). If someone needs this to work, we'll need to
change the fact that we promote many Altivec operations to act on
v4f32. To make it possible to disable Altivec when soft-float is
enabled, hardware floating-point support needs to be expressed as a
positive feature, like the others, and not a negative feature,
because target features cannot have dependencies on the disabling of
some other feature. So +soft-float has now become -hard-float.
Fixes PR26970.
Pull in r283061 from upstream clang trunk (by Hal Finkel):
[PowerPC] Enable soft-float for PPC64, and +soft-float -> -hard-float
Enable soft-float support on PPC64, as the backend now supports it.
Also, the backend now uses -hard-float instead of +soft-float, so set
the target features accordingly.
Fixes PR26970.
Reported by: Mark Millard
PR: 214433
MFC r309212:
Add a few missed clang 3.9.0 files to OptionalObsoleteFiles.
MFC r309262:
Fix packaging for clang, lldb and lld 3.9.0
During the upgrade of clang/llvm etc to 3.9.0 in r309124, the PACKAGE
directive in the usr.bin/clang/*.mk files got dropped accidentally.
Restore it, with a few minor changes and additions:
* Correct license in clang.ucl to NCSA
* Add PACKAGE=clang for clang and most of the "ll" tools
* Put lldb in its own package
* Put lld in its own package
Reviewed by: gjb, jmallett
Differential Revision: https://reviews.freebsd.org/D8666
MFC r309656:
During the bootstrap phase, when building the minimal llvm library on
PowerPC, add lib/Support/Atomic.cpp. This is needed because upstream
llvm revision r271821 disabled the use of std::call_once, which causes
some fallback functions from Atomic.cpp to be used instead.
Reported by: Mark Millard
PR: 214902
MFC r309835:
Tentatively apply https://reviews.llvm.org/D18730 to work around gcc PR
70528 (bogus error: constructor required before non-static data member).
This should fix buildworld with the external gcc package.
Reported by: https://jenkins.freebsd.org/job/FreeBSD_HEAD_amd64_gcc/
MFC r310194:
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
3.9.1 release.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Release notes for llvm, clang and lld will be available here:
<http://releases.llvm.org/3.9.1/docs/ReleaseNotes.html>
<http://releases.llvm.org/3.9.1/tools/clang/docs/ReleaseNotes.html>
<http://releases.llvm.org/3.9.1/tools/lld/docs/ReleaseNotes.html>
Relnotes: yes
Diffstat (limited to 'contrib/llvm/tools/llvm-link/llvm-link.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-link/llvm-link.cpp | 203 |
1 files changed, 122 insertions, 81 deletions
diff --git a/contrib/llvm/tools/llvm-link/llvm-link.cpp b/contrib/llvm/tools/llvm-link/llvm-link.cpp index a3238302..185ae2a 100644 --- a/contrib/llvm/tools/llvm-link/llvm-link.cpp +++ b/contrib/llvm/tools/llvm-link/llvm-link.cpp @@ -12,18 +12,18 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Linker/Linker.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" -#include "llvm/IR/FunctionInfo.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" +#include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" -#include "llvm/Object/FunctionIndexObjectFile.h" +#include "llvm/Linker/Linker.h" +#include "llvm/Object/ModuleSummaryIndexObjectFile.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" @@ -33,7 +33,10 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/SystemUtils.h" #include "llvm/Support/ToolOutputFile.h" +#include "llvm/Transforms/Utils/FunctionImportUtils.h" + #include <memory> +#include <utility> using namespace llvm; static cl::list<std::string> @@ -52,15 +55,14 @@ static cl::list<std::string> Imports( cl::desc("Pair of function name and filename, where function should be " "imported from bitcode in filename")); -// Option to support testing of function importing. The function index +// Option to support testing of function importing. The module summary // must be specified in the case were we request imports via the -import // option, as well as when compiling any module with functions that may be // exported (imported by a different llvm-link -import invocation), to ensure // consistent promotion and renaming of locals. -static cl::opt<std::string> FunctionIndex("functionindex", - cl::desc("Function index filename"), - cl::init(""), - cl::value_desc("filename")); +static cl::opt<std::string> + SummaryIndex("summary-index", cl::desc("Module summary index filename"), + cl::init(""), cl::value_desc("filename")); static cl::opt<std::string> OutputFilename("o", cl::desc("Override output filename"), cl::init("-"), @@ -70,6 +72,10 @@ static cl::opt<bool> Internalize("internalize", cl::desc("Internalize linked symbols")); static cl::opt<bool> + DisableDITypeMap("disable-debug-info-type-map", + cl::desc("Don't use a uniquing type map for debug info")); + +static cl::opt<bool> OnlyNeeded("only-needed", cl::desc("Link only needed symbols")); static cl::opt<bool> @@ -89,10 +95,6 @@ static cl::opt<bool> SuppressWarnings("suppress-warnings", cl::desc("Suppress all linking warnings"), cl::init(false)); -static cl::opt<bool> - PreserveModules("preserve-modules", - cl::desc("Preserve linked modules for testing")); - static cl::opt<bool> PreserveBitcodeUseListOrder( "preserve-bc-uselistorder", cl::desc("Preserve use-list order when writing LLVM bitcode."), @@ -114,8 +116,10 @@ static std::unique_ptr<Module> loadFile(const char *argv0, if (Verbose) errs() << "Loading '" << FN << "'\n"; std::unique_ptr<Module> Result = getLazyIRFileModule(FN, Err, Context, !MaterializeMetadata); - if (!Result) + if (!Result) { Err.print(argv0, errs()); + return nullptr; + } if (MaterializeMetadata) { Result->materializeMetadata(); @@ -125,6 +129,48 @@ static std::unique_ptr<Module> loadFile(const char *argv0, return Result; } +namespace { + +/// Helper to load on demand a Module from file and cache it for subsequent +/// queries during function importing. +class ModuleLazyLoaderCache { + /// Cache of lazily loaded module for import. + StringMap<std::unique_ptr<Module>> ModuleMap; + + /// Retrieve a Module from the cache or lazily load it on demand. + std::function<std::unique_ptr<Module>(const char *argv0, + const std::string &FileName)> + createLazyModule; + +public: + /// Create the loader, Module will be initialized in \p Context. + ModuleLazyLoaderCache(std::function<std::unique_ptr<Module>( + const char *argv0, const std::string &FileName)> + createLazyModule) + : createLazyModule(std::move(createLazyModule)) {} + + /// Retrieve a Module from the cache or lazily load it on demand. + Module &operator()(const char *argv0, const std::string &FileName); + + std::unique_ptr<Module> takeModule(const std::string &FileName) { + auto I = ModuleMap.find(FileName); + assert(I != ModuleMap.end()); + std::unique_ptr<Module> Ret = std::move(I->second); + ModuleMap.erase(I); + return Ret; + } +}; + +// Get a Module for \p FileName from the cache, or load it lazily. +Module &ModuleLazyLoaderCache::operator()(const char *argv0, + const std::string &Identifier) { + auto &Module = ModuleMap[Identifier]; + if (!Module) + Module = createLazyModule(argv0, Identifier); + return *Module; +} +} // anonymous namespace + static void diagnosticHandler(const DiagnosticInfo &DI) { unsigned Severity = DI.getSeverity(); switch (Severity) { @@ -153,8 +199,24 @@ static void diagnosticHandlerWithContext(const DiagnosticInfo &DI, void *C) { /// Import any functions requested via the -import option. static bool importFunctions(const char *argv0, LLVMContext &Context, Linker &L) { - StringMap<std::unique_ptr<DenseMap<unsigned, MDNode *>>> - ModuleToTempMDValsMap; + if (SummaryIndex.empty()) + return true; + ErrorOr<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr = + llvm::getModuleSummaryIndexForFile(SummaryIndex, diagnosticHandler); + std::error_code EC = IndexOrErr.getError(); + if (EC) { + errs() << EC.message() << '\n'; + return false; + } + auto Index = std::move(IndexOrErr.get()); + + // Map of Module -> List of globals to import from the Module + std::map<StringRef, DenseSet<const GlobalValue *>> ModuleToGlobalsToImportMap; + auto ModuleLoader = [&Context](const char *argv0, + const std::string &Identifier) { + return loadFile(argv0, Identifier, Context, false); + }; + ModuleLazyLoaderCache ModuleLoaderCache(ModuleLoader); for (const auto &Import : Imports) { // Identify the requested function and its bitcode source file. size_t Idx = Import.find(':'); @@ -166,19 +228,15 @@ static bool importFunctions(const char *argv0, LLVMContext &Context, std::string FileName = Import.substr(Idx + 1, std::string::npos); // Load the specified source module. - std::unique_ptr<Module> M = loadFile(argv0, FileName, Context, false); - if (!M.get()) { - errs() << argv0 << ": error loading file '" << FileName << "'\n"; - return false; - } + auto &SrcModule = ModuleLoaderCache(argv0, FileName); - if (verifyModule(*M, &errs())) { + if (verifyModule(SrcModule, &errs())) { errs() << argv0 << ": " << FileName << ": error: input module is broken!\n"; return false; } - Function *F = M->getFunction(FunctionName); + Function *F = SrcModule.getFunction(FunctionName); if (!F) { errs() << "Ignoring import request for non-existent function " << FunctionName << " from " << FileName << "\n"; @@ -196,53 +254,36 @@ static bool importFunctions(const char *argv0, LLVMContext &Context, if (Verbose) errs() << "Importing " << FunctionName << " from " << FileName << "\n"; - std::unique_ptr<FunctionInfoIndex> Index; - if (!FunctionIndex.empty()) { - ErrorOr<std::unique_ptr<FunctionInfoIndex>> IndexOrErr = - llvm::getFunctionIndexForFile(FunctionIndex, diagnosticHandler); - std::error_code EC = IndexOrErr.getError(); - if (EC) { - errs() << EC.message() << '\n'; - return false; - } - Index = std::move(IndexOrErr.get()); - } + auto &Entry = ModuleToGlobalsToImportMap[SrcModule.getModuleIdentifier()]; + Entry.insert(F); - // Save the mapping of value ids to temporary metadata created when - // importing this function. If we have already imported from this module, - // add new temporary metadata to the existing mapping. - auto &TempMDVals = ModuleToTempMDValsMap[FileName]; - if (!TempMDVals) - TempMDVals = llvm::make_unique<DenseMap<unsigned, MDNode *>>(); - - // Link in the specified function. - DenseSet<const GlobalValue *> FunctionsToImport; - FunctionsToImport.insert(F); - if (L.linkInModule(std::move(M), Linker::Flags::None, Index.get(), - &FunctionsToImport, TempMDVals.get())) - return false; + F->materialize(); } - // Now link in metadata for all modules from which we imported functions. - for (StringMapEntry<std::unique_ptr<DenseMap<unsigned, MDNode *>>> &SME : - ModuleToTempMDValsMap) { - // Load the specified source module. - std::unique_ptr<Module> M = loadFile(argv0, SME.getKey(), Context, true); - if (!M.get()) { - errs() << argv0 << ": error loading file '" << SME.getKey() << "'\n"; - return false; - } + // Do the actual import of globals now, one Module at a time + for (auto &GlobalsToImportPerModule : ModuleToGlobalsToImportMap) { + // Get the module for the import + auto &GlobalsToImport = GlobalsToImportPerModule.second; + std::unique_ptr<Module> SrcModule = + ModuleLoaderCache.takeModule(GlobalsToImportPerModule.first); + assert(&Context == &SrcModule->getContext() && "Context mismatch"); - if (verifyModule(*M, &errs())) { - errs() << argv0 << ": " << SME.getKey() - << ": error: input module is broken!\n"; - return false; - } + // If modules were created with lazy metadata loading, materialize it + // now, before linking it (otherwise this will be a noop). + SrcModule->materializeMetadata(); + UpgradeDebugInfo(*SrcModule); + + // Linkage Promotion and renaming + if (renameModuleForThinLTO(*SrcModule, *Index, &GlobalsToImport)) + return true; + + // Instruct the linker to not automatically import linkonce defintion. + unsigned Flags = Linker::Flags::DontForceLinkLinkonceODR; - // Link in all necessary metadata from this module. - if (L.linkInMetadata(*M, SME.getValue().get())) + if (L.linkInModule(std::move(SrcModule), Flags, &GlobalsToImport)) return false; } + return true; } @@ -258,41 +299,38 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, return false; } - if (verifyModule(*M, &errs())) { + // Note that when ODR merging types cannot verify input files in here When + // doing that debug metadata in the src module might already be pointing to + // the destination. + if (DisableDITypeMap && verifyModule(*M, &errs())) { errs() << argv0 << ": " << File << ": error: input module is broken!\n"; return false; } - // If a function index is supplied, load it so linkInModule can treat + // 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<FunctionInfoIndex> Index; - if (!FunctionIndex.empty()) { - ErrorOr<std::unique_ptr<FunctionInfoIndex>> IndexOrErr = - llvm::getFunctionIndexForFile(FunctionIndex, diagnosticHandler); + if (!SummaryIndex.empty()) { + ErrorOr<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr = + llvm::getModuleSummaryIndexForFile(SummaryIndex, diagnosticHandler); std::error_code EC = IndexOrErr.getError(); if (EC) { 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; - - // If requested for testing, preserve modules by releasing them from - // the unique_ptr before the are freed. This can help catch any - // cross-module references from e.g. unneeded metadata references - // that aren't properly set to null but instead mapped to the source - // module version. The bitcode writer will assert if it finds any such - // cross-module references. - if (PreserveModules) - M.release(); } return true; @@ -300,15 +338,18 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, int main(int argc, char **argv) { // Print a stack trace if we signal out. - sys::PrintStackTraceOnErrorSignal(); + sys::PrintStackTraceOnErrorSignal(argv[0]); PrettyStackTraceProgram X(argc, argv); - LLVMContext &Context = getGlobalContext(); + LLVMContext Context; Context.setDiagnosticHandler(diagnosticHandlerWithContext, nullptr, true); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); + if (!DisableDITypeMap) + Context.enableDebugTypeODRUniquing(); + auto Composite = make_unique<Module>("llvm-link", Context); Linker L(*Composite); |