diff --git a/llvm/include/llvm/LTO/LTOBackend.h b/llvm/include/llvm/LTO/LTOBackend.h --- a/llvm/include/llvm/LTO/LTOBackend.h +++ b/llvm/include/llvm/LTO/LTOBackend.h @@ -41,9 +41,11 @@ /// Runs a regular LTO backend. The regular LTO backend can also act as the /// regular LTO phase of ThinLTO, which may need to access the combined index. -Error backend(const Config &C, AddStreamFn AddStream, - unsigned ParallelCodeGenParallelismLevel, - std::unique_ptr M, ModuleSummaryIndex &CombinedIndex); +/// If \p ParallelCodeGenParallelismLevel is 1, return the unmodified \p M. +Expected> +backend(const Config &C, AddStreamFn AddStream, + unsigned ParallelCodeGenParallelismLevel, std::unique_ptr M, + ModuleSummaryIndex &CombinedIndex); /// Runs a ThinLTO backend. Error thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream, diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -1068,10 +1068,11 @@ } if (!RegularLTO.EmptyCombinedModule || Conf.AlwaysEmitRegularLTOObj) { - if (Error Err = backend( - Conf, AddStream, RegularLTO.ParallelCodeGenParallelismLevel, - std::move(RegularLTO.CombinedModule), ThinLTO.CombinedIndex)) - return Err; + auto Result = + backend(Conf, AddStream, RegularLTO.ParallelCodeGenParallelismLevel, + std::move(RegularLTO.CombinedModule), ThinLTO.CombinedIndex); + if (!Result) + return Result.takeError(); } return finalizeOptimizationRemarks(std::move(*DiagFileOrErr)); diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -531,10 +531,10 @@ return Error::success(); } -Error lto::backend(const Config &C, AddStreamFn AddStream, - unsigned ParallelCodeGenParallelismLevel, - std::unique_ptr Mod, - ModuleSummaryIndex &CombinedIndex) { +Expected> +lto::backend(const Config &C, AddStreamFn AddStream, + unsigned ParallelCodeGenParallelismLevel, + std::unique_ptr Mod, ModuleSummaryIndex &CombinedIndex) { Expected TOrErr = initAndLookupTarget(C, *Mod); if (!TOrErr) return TOrErr.takeError(); @@ -545,16 +545,17 @@ if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false, /*ExportSummary=*/&CombinedIndex, /*ImportSummary=*/nullptr, /*CmdArgs*/ std::vector())) - return Error::success(); + return {nullptr}; } if (ParallelCodeGenParallelismLevel == 1) { codegen(C, TM.get(), AddStream, 0, *Mod, CombinedIndex); + return {std::move(Mod)}; } else { splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel, std::move(Mod), CombinedIndex); } - return Error::success(); + return {nullptr}; } static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals,