diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2015-08-27 23:37:36 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2015-08-27 23:37:36 +0000 |
commit | c269ed511584d9044a4e28a25fa6a0d24df68a9f (patch) | |
tree | eb8ec1c70b5fc9d78ab61aacaffab6d9ab1bb16d /llvm/tools/llvm-lto/llvm-lto.cpp | |
parent | 0e2882345daead6cd9368eda4107e860d9141e35 (diff) | |
download | bcm5719-llvm-c269ed511584d9044a4e28a25fa6a0d24df68a9f.tar.gz bcm5719-llvm-c269ed511584d9044a4e28a25fa6a0d24df68a9f.zip |
CodeGen: Introduce splitCodeGen and teach LTOCodeGenerator to use it.
llvm::splitCodeGen is a function that implements the core of parallel LTO
code generation. It uses llvm::SplitModule to split the module into linkable
partitions and spawning one code generation thread per partition. The function
produces multiple object files which can be linked in the usual way.
This has been threaded through to LTOCodeGenerator (and llvm-lto for testing
purposes). Separate patches will add parallel LTO support to the gold plugin
and lld.
Differential Revision: http://reviews.llvm.org/D12260
llvm-svn: 246236
Diffstat (limited to 'llvm/tools/llvm-lto/llvm-lto.cpp')
-rw-r--r-- | llvm/tools/llvm-lto/llvm-lto.cpp | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index 52e45296126..ddde23175a3 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -22,7 +22,9 @@ #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/raw_ostream.h" +#include <list> using namespace llvm; @@ -77,6 +79,9 @@ static cl::opt<bool> SetMergedModule( "set-merged-module", cl::init(false), cl::desc("Use the first input module as the merged module")); +static cl::opt<unsigned> Parallelism("j", cl::Prefix, cl::init(1), + cl::desc("Number of backend threads")); + namespace { struct ModuleInfo { std::vector<bool> CanBeHidden; @@ -240,24 +245,41 @@ int main(int argc, char **argv) { if (!OutputFilename.empty()) { std::string ErrorInfo; - std::unique_ptr<MemoryBuffer> Code = CodeGen.compile( - DisableInline, DisableGVNLoadPRE, DisableLTOVectorization, ErrorInfo); - if (!Code) { - errs() << argv[0] - << ": error compiling the code: " << ErrorInfo << "\n"; + if (!CodeGen.optimize(DisableInline, DisableGVNLoadPRE, + DisableLTOVectorization, ErrorInfo)) { + errs() << argv[0] << ": error optimizing the code: " << ErrorInfo << "\n"; return 1; } - std::error_code EC; - raw_fd_ostream FileStream(OutputFilename, EC, sys::fs::F_None); - if (EC) { - errs() << argv[0] << ": error opening the file '" << OutputFilename - << "': " << EC.message() << "\n"; + std::list<tool_output_file> OSs; + std::vector<raw_pwrite_stream *> OSPtrs; + for (unsigned I = 0; I != Parallelism; ++I) { + std::string PartFilename = OutputFilename; + if (Parallelism != 1) + PartFilename += "." + utostr(I); + std::error_code EC; + OSs.emplace_back(PartFilename, EC, sys::fs::F_None); + if (EC) { + errs() << argv[0] << ": error opening the file '" << PartFilename + << "': " << EC.message() << "\n"; + return 1; + } + OSPtrs.push_back(&OSs.back().os()); + } + + if (!CodeGen.compileOptimized(OSPtrs, ErrorInfo)) { + errs() << argv[0] << ": error compiling the code: " << ErrorInfo << "\n"; return 1; } - FileStream.write(Code->getBufferStart(), Code->getBufferSize()); + for (tool_output_file &OS : OSs) + OS.keep(); } else { + if (Parallelism != 1) { + errs() << argv[0] << ": -j must be specified together with -o\n"; + return 1; + } + std::string ErrorInfo; const char *OutputName = nullptr; if (!CodeGen.compile_to_file(&OutputName, DisableInline, |