From 268826a287f876a9d842c6bfd5819826399de6c7 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Wed, 6 Apr 2016 18:32:13 +0000 Subject: [gold] Save bitcode for module partitions (save-temps + split codegen). llvm-svn: 265583 --- llvm/lib/CodeGen/ParallelCG.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'llvm/lib/CodeGen/ParallelCG.cpp') diff --git a/llvm/lib/CodeGen/ParallelCG.cpp b/llvm/lib/CodeGen/ParallelCG.cpp index d667ee327e7..1486af14d4b 100644 --- a/llvm/lib/CodeGen/ParallelCG.cpp +++ b/llvm/lib/CodeGen/ParallelCG.cpp @@ -39,22 +39,25 @@ static void codegen(Module *M, llvm::raw_pwrite_stream &OS, CodeGenPasses.run(*M); } -std::unique_ptr -llvm::splitCodeGen(std::unique_ptr M, - ArrayRef OSs, StringRef CPU, - StringRef Features, const TargetOptions &Options, - Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL, - TargetMachine::CodeGenFileType FileType, - bool PreserveLocals) { +std::unique_ptr llvm::splitCodeGen( + std::unique_ptr M, ArrayRef OSs, + ArrayRef BCOSs, StringRef CPU, + StringRef Features, const TargetOptions &Options, Reloc::Model RM, + CodeModel::Model CM, CodeGenOpt::Level OL, + TargetMachine::CodeGenFileType FileType, bool PreserveLocals) { StringRef TripleStr = M->getTargetTriple(); std::string ErrMsg; const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg); if (!TheTarget) report_fatal_error(Twine("Target not found: ") + ErrMsg); + assert(BCOSs.empty() || BCOSs.size() == OSs.size()); + if (OSs.size() == 1) { - codegen(M.get(), *OSs[0], TheTarget, CPU, Features, Options, RM, CM, - OL, FileType); + if (!BCOSs.empty()) + WriteBitcodeToFile(M.get(), *BCOSs[0]); + codegen(M.get(), *OSs[0], TheTarget, CPU, Features, Options, RM, CM, OL, + FileType); return M; } @@ -77,6 +80,11 @@ llvm::splitCodeGen(std::unique_ptr M, raw_svector_ostream BCOS(BC); WriteBitcodeToFile(MPart.get(), BCOS); + if (!BCOSs.empty()) { + BCOSs[ThreadCount]->write(BC.begin(), BC.size()); + BCOSs[ThreadCount]->flush(); + } + llvm::raw_pwrite_stream *ThreadOS = OSs[ThreadCount++]; // Enqueue the task CodegenThreadPool.async( -- cgit v1.2.3