2017-02-03 07:58:14 +08:00
|
|
|
//===- LTO.cpp ------------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-02-03 07:58:14 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "LTO.h"
|
|
|
|
#include "Config.h"
|
|
|
|
#include "InputFiles.h"
|
|
|
|
#include "Symbols.h"
|
2019-01-31 04:46:18 +08:00
|
|
|
#include "lld/Common/Args.h"
|
[lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D39259
llvm-svn: 316624
2017-10-26 06:28:38 +08:00
|
|
|
#include "lld/Common/ErrorHandler.h"
|
2018-05-23 04:20:25 +08:00
|
|
|
#include "lld/Common/Strings.h"
|
2017-10-03 05:00:41 +08:00
|
|
|
#include "lld/Common/TargetOptionsCommandFlags.h"
|
2017-02-03 07:58:14 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
#include "llvm/Bitcode/BitcodeWriter.h"
|
2017-02-03 07:58:14 +08:00
|
|
|
#include "llvm/IR/DiagnosticPrinter.h"
|
2017-09-08 08:50:50 +08:00
|
|
|
#include "llvm/LTO/Caching.h"
|
2017-02-03 07:58:14 +08:00
|
|
|
#include "llvm/LTO/Config.h"
|
|
|
|
#include "llvm/LTO/LTO.h"
|
|
|
|
#include "llvm/Object/SymbolicFile.h"
|
|
|
|
#include "llvm/Support/CodeGen.h"
|
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <system_error>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
2020-02-20 09:05:42 +08:00
|
|
|
using namespace lld;
|
|
|
|
using namespace lld::coff;
|
2017-02-03 07:58:14 +08:00
|
|
|
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
// Creates an empty file to and returns a raw_fd_ostream to write to it.
|
|
|
|
static std::unique_ptr<raw_fd_ostream> openFile(StringRef file) {
|
|
|
|
std::error_code ec;
|
|
|
|
auto ret =
|
2019-08-15 06:28:17 +08:00
|
|
|
std::make_unique<raw_fd_ostream>(file, ec, sys::fs::OpenFlags::OF_None);
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
if (ec) {
|
|
|
|
error("cannot open " + file + ": " + ec.message());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-12 02:48:58 +08:00
|
|
|
static std::string getThinLTOOutputFile(StringRef path) {
|
2020-01-29 03:23:46 +08:00
|
|
|
return lto::getThinLTOOutputFile(
|
|
|
|
std::string(path), std::string(config->thinLTOPrefixReplace.first),
|
|
|
|
std::string(config->thinLTOPrefixReplace.second));
|
2019-07-12 02:48:58 +08:00
|
|
|
}
|
|
|
|
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
static lto::Config createConfig() {
|
2018-05-23 04:20:25 +08:00
|
|
|
lto::Config c;
|
2019-02-01 10:24:50 +08:00
|
|
|
c.Options = initTargetOptionsFromCodeGenFlags();
|
2018-03-15 04:25:41 +08:00
|
|
|
|
|
|
|
// Always emit a section per function/datum with LTO. LLVM LTO should get most
|
|
|
|
// of the benefit of linker GC, but there are still opportunities for ICF.
|
2018-05-23 04:20:25 +08:00
|
|
|
c.Options.FunctionSections = true;
|
|
|
|
c.Options.DataSections = true;
|
2018-03-15 04:25:41 +08:00
|
|
|
|
2017-10-11 08:46:58 +08:00
|
|
|
// Use static reloc model on 32-bit x86 because it usually results in more
|
|
|
|
// compact code, and because there are also known code generation bugs when
|
|
|
|
// using the PIC model (see PR34306).
|
|
|
|
if (config->machine == COFF::IMAGE_FILE_MACHINE_I386)
|
2018-05-23 04:20:25 +08:00
|
|
|
c.RelocModel = Reloc::Static;
|
2017-10-11 08:46:58 +08:00
|
|
|
else
|
2018-05-23 04:20:25 +08:00
|
|
|
c.RelocModel = Reloc::PIC_;
|
|
|
|
c.DisableVerify = true;
|
|
|
|
c.DiagHandler = diagnosticHandler;
|
|
|
|
c.OptLevel = config->ltoo;
|
2019-02-01 10:24:50 +08:00
|
|
|
c.CPU = getCPUStr();
|
|
|
|
c.MAttrs = getMAttrs();
|
2019-01-31 04:46:18 +08:00
|
|
|
c.CGOptLevel = args::getCGOptLevel(config->ltoo);
|
[LTO] Suppress emission of empty combined module by default
Summary:
That unless the user requested an output object (--lto-obj-path), the an
unused empty combined module is not emitted.
This changed is helpful for some target (ex. RISCV-V) which encoded the
ABI info in IR module flags (target-abi). Empty unused module has no ABI
info so the linker would get the linking error during merging
incompatible ABIs.
Reviewers: tejohnson, espindola, MaskRay
Subscribers: emaste, inglorion, arichardson, hiraditya, simoncook, MaskRay, steven_wu, dexonsmith, PkmX, dang, lenary, s.egerton, luismarques, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78988
2020-04-28 11:04:36 +08:00
|
|
|
c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty();
|
2020-11-06 03:41:35 +08:00
|
|
|
c.UseNewPM = config->ltoNewPassManager;
|
|
|
|
c.DebugPassManager = config->ltoDebugPassManager;
|
2019-07-11 13:40:30 +08:00
|
|
|
|
2017-02-09 02:36:41 +08:00
|
|
|
if (config->saveTemps)
|
2018-05-23 04:20:25 +08:00
|
|
|
checkError(c.addSaveTemps(std::string(config->outputFile) + ".",
|
|
|
|
/*UseInputModulePath*/ true));
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
BitcodeCompiler::BitcodeCompiler() {
|
|
|
|
// Initialize indexFile.
|
|
|
|
if (!config->thinLTOIndexOnlyArg.empty())
|
|
|
|
indexFile = openFile(config->thinLTOIndexOnlyArg);
|
|
|
|
|
|
|
|
// Initialize ltoObj.
|
2017-02-03 07:58:14 +08:00
|
|
|
lto::ThinBackend backend;
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
if (config->thinLTOIndexOnly) {
|
|
|
|
auto OnIndexWrite = [&](StringRef S) { thinIndices.erase(S); };
|
|
|
|
backend = lto::createWriteIndexesThinBackend(
|
2020-01-29 03:23:46 +08:00
|
|
|
std::string(config->thinLTOPrefixReplace.first),
|
|
|
|
std::string(config->thinLTOPrefixReplace.second),
|
2019-07-12 02:48:58 +08:00
|
|
|
config->thinLTOEmitImportsFiles, indexFile.get(), OnIndexWrite);
|
2020-03-27 22:20:39 +08:00
|
|
|
} else {
|
|
|
|
backend = lto::createInProcessThinBackend(
|
|
|
|
llvm::heavyweight_hardware_concurrency(config->thinLTOJobs));
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
}
|
2017-02-03 07:58:14 +08:00
|
|
|
|
2019-08-15 06:28:17 +08:00
|
|
|
ltoObj = std::make_unique<lto::LTO>(createConfig(), backend,
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
config->ltoPartitions);
|
|
|
|
}
|
2017-02-03 07:58:14 +08:00
|
|
|
|
|
|
|
BitcodeCompiler::~BitcodeCompiler() = default;
|
|
|
|
|
2017-11-04 06:48:47 +08:00
|
|
|
static void undefine(Symbol *s) { replaceSymbol<Undefined>(s, s->getName()); }
|
2017-02-03 07:58:14 +08:00
|
|
|
|
|
|
|
void BitcodeCompiler::add(BitcodeFile &f) {
|
|
|
|
lto::InputFile &obj = *f.obj;
|
|
|
|
unsigned symNum = 0;
|
2017-11-04 05:21:47 +08:00
|
|
|
std::vector<Symbol *> symBodies = f.getSymbols();
|
2017-02-03 07:58:14 +08:00
|
|
|
std::vector<lto::SymbolResolution> resols(symBodies.size());
|
|
|
|
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
if (config->thinLTOIndexOnly)
|
|
|
|
thinIndices.insert(obj.getName());
|
|
|
|
|
2017-02-03 07:58:14 +08:00
|
|
|
// Provide a resolution to the LTO API for each symbol.
|
|
|
|
for (const lto::InputFile::Symbol &objSym : obj.symbols()) {
|
2017-11-04 05:21:47 +08:00
|
|
|
Symbol *sym = symBodies[symNum];
|
2017-02-03 07:58:14 +08:00
|
|
|
lto::SymbolResolution &r = resols[symNum];
|
|
|
|
++symNum;
|
|
|
|
|
|
|
|
// Ideally we shouldn't check for SF_Undefined but currently IRObjectFile
|
|
|
|
// reports two symbols for module ASM defined. Without this check, lld
|
|
|
|
// flags an undefined in IR with a definition in ASM as prevailing.
|
|
|
|
// Once IRObjectFile is fixed to report only one symbol this hack can
|
|
|
|
// be removed.
|
2017-11-01 00:10:24 +08:00
|
|
|
r.Prevailing = !objSym.isUndefined() && sym->getFile() == &f;
|
2017-02-03 07:58:14 +08:00
|
|
|
r.VisibleToRegularObj = sym->isUsedInRegularObj;
|
|
|
|
if (r.Prevailing)
|
|
|
|
undefine(sym);
|
2020-10-06 18:54:49 +08:00
|
|
|
|
|
|
|
// We tell LTO to not apply interprocedural optimization for wrapped
|
|
|
|
// (with -wrap) symbols because otherwise LTO would inline them while
|
|
|
|
// their values are still not final.
|
|
|
|
r.LinkerRedefined = !sym->canInline;
|
2017-02-03 07:58:14 +08:00
|
|
|
}
|
|
|
|
checkError(ltoObj->add(std::move(f.obj), resols));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge all the bitcode files we have seen, codegen the result
|
2017-02-07 04:47:55 +08:00
|
|
|
// and return the resulting objects.
|
2020-04-16 00:54:22 +08:00
|
|
|
std::vector<InputFile *> BitcodeCompiler::compile() {
|
2017-02-03 07:58:14 +08:00
|
|
|
unsigned maxTasks = ltoObj->getMaxTasks();
|
2018-05-23 04:20:25 +08:00
|
|
|
buf.resize(maxTasks);
|
2017-09-08 08:50:50 +08:00
|
|
|
files.resize(maxTasks);
|
|
|
|
|
|
|
|
// The /lldltocache option specifies the path to a directory in which to cache
|
|
|
|
// native object files for ThinLTO incremental builds. If a path was
|
|
|
|
// specified, configure LTO to use it as the cache directory.
|
|
|
|
lto::NativeObjectCache cache;
|
|
|
|
if (!config->ltoCache.empty())
|
2018-02-21 04:21:59 +08:00
|
|
|
cache = check(lto::localCache(
|
|
|
|
config->ltoCache, [&](size_t task, std::unique_ptr<MemoryBuffer> mb) {
|
|
|
|
files[task] = std::move(mb);
|
|
|
|
}));
|
2017-09-08 08:50:50 +08:00
|
|
|
|
|
|
|
checkError(ltoObj->run(
|
|
|
|
[&](size_t task) {
|
2019-08-15 06:28:17 +08:00
|
|
|
return std::make_unique<lto::NativeObjectStream>(
|
|
|
|
std::make_unique<raw_svector_ostream>(buf[task]));
|
2017-09-08 08:50:50 +08:00
|
|
|
},
|
|
|
|
cache));
|
|
|
|
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
// Emit empty index files for non-indexed files
|
2019-07-12 02:48:58 +08:00
|
|
|
for (StringRef s : thinIndices) {
|
|
|
|
std::string path = getThinLTOOutputFile(s);
|
|
|
|
openFile(path + ".thinlto.bc");
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
if (config->thinLTOEmitImportsFiles)
|
2019-07-12 02:48:58 +08:00
|
|
|
openFile(path + ".imports");
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ThinLTO with index only option is required to generate only the index
|
|
|
|
// files. After that, we exit from linker and ThinLTO backend runs in a
|
|
|
|
// distributed environment.
|
|
|
|
if (config->thinLTOIndexOnly) {
|
2019-08-22 02:24:59 +08:00
|
|
|
if (!config->ltoObjPath.empty())
|
|
|
|
saveBuffer(buf[0], config->ltoObjPath);
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
if (indexFile)
|
|
|
|
indexFile->close();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-09-08 08:50:50 +08:00
|
|
|
if (!config->ltoCache.empty())
|
|
|
|
pruneCache(config->ltoCache, config->ltoCachePolicy);
|
2017-02-03 07:58:14 +08:00
|
|
|
|
2020-04-16 00:54:22 +08:00
|
|
|
std::vector<InputFile *> ret;
|
2017-02-09 02:36:41 +08:00
|
|
|
for (unsigned i = 0; i != maxTasks; ++i) {
|
2020-04-16 00:54:22 +08:00
|
|
|
// Assign unique names to LTO objects. This ensures they have unique names
|
|
|
|
// in the PDB if one is produced. The names should look like:
|
|
|
|
// - foo.exe.lto.obj
|
|
|
|
// - foo.exe.lto.1.obj
|
|
|
|
// - ...
|
|
|
|
StringRef ltoObjName =
|
|
|
|
saver.save(Twine(config->outputFile) + ".lto" +
|
|
|
|
(i == 0 ? Twine("") : Twine('.') + Twine(i)) + ".obj");
|
|
|
|
|
|
|
|
// Get the native object contents either from the cache or from memory. Do
|
|
|
|
// not use the cached MemoryBuffer directly, or the PDB will not be
|
|
|
|
// deterministic.
|
|
|
|
StringRef objBuf;
|
|
|
|
if (files[i])
|
|
|
|
objBuf = files[i]->getBuffer();
|
|
|
|
else
|
|
|
|
objBuf = buf[i];
|
|
|
|
if (objBuf.empty())
|
2017-02-09 02:36:41 +08:00
|
|
|
continue;
|
2017-09-08 08:50:50 +08:00
|
|
|
|
2020-04-16 00:54:22 +08:00
|
|
|
if (config->saveTemps)
|
|
|
|
saveBuffer(buf[i], ltoObjName);
|
|
|
|
ret.push_back(make<ObjFile>(MemoryBufferRef(objBuf, ltoObjName)));
|
|
|
|
}
|
2017-09-08 08:50:50 +08:00
|
|
|
|
2017-02-03 07:58:14 +08:00
|
|
|
return ret;
|
|
|
|
}
|