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 @@ -33,6 +33,12 @@ namespace lto { +/// Runs middle-end LTO optimizations on \p Mod. +bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, + bool IsThinLTO, ModuleSummaryIndex *ExportSummary, + const ModuleSummaryIndex *ImportSummary, + const std::vector &CmdArgs); + /// 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, 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 @@ -360,39 +360,6 @@ passes.run(Mod); } -bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, - bool IsThinLTO, ModuleSummaryIndex *ExportSummary, - const ModuleSummaryIndex *ImportSummary, - const std::vector &CmdArgs) { - if (EmbedBitcode == LTOBitcodeEmbedding::EmbedPostMergePreOptimized) { - // FIXME: the motivation for capturing post-merge bitcode and command line - // is replicating the compilation environment from bitcode, without needing - // to understand the dependencies (the functions to be imported). This - // assumes a clang - based invocation, case in which we have the command - // line. - // It's not very clear how the above motivation would map in the - // linker-based case, so we currently don't plumb the command line args in - // that case. - if (CmdArgs.empty()) - LLVM_DEBUG( - dbgs() << "Post-(Thin)LTO merge bitcode embedding was requested, but " - "command line arguments are not available"); - llvm::EmbedBitcodeInModule(Mod, llvm::MemoryBufferRef(), - /*EmbedBitcode*/ true, /*EmbedCmdline*/ true, - /*Cmdline*/ CmdArgs); - } - // FIXME: Plumb the combined index into the new pass manager. - if (!Conf.OptPipeline.empty()) - runNewPMCustomPasses(Conf, Mod, TM, Conf.OptPipeline, Conf.AAPipeline, - Conf.DisableVerify); - else if (Conf.UseNewPM) - runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO, ExportSummary, - ImportSummary); - else - runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary); - return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod); -} - void codegen(const Config &Conf, TargetMachine *TM, AddStreamFn AddStream, unsigned Task, Module &Mod, const ModuleSummaryIndex &CombinedIndex) { @@ -516,6 +483,39 @@ return Error::success(); } +bool lto::opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, + bool IsThinLTO, ModuleSummaryIndex *ExportSummary, + const ModuleSummaryIndex *ImportSummary, + const std::vector &CmdArgs) { + if (EmbedBitcode == LTOBitcodeEmbedding::EmbedPostMergePreOptimized) { + // FIXME: the motivation for capturing post-merge bitcode and command line + // is replicating the compilation environment from bitcode, without needing + // to understand the dependencies (the functions to be imported). This + // assumes a clang - based invocation, case in which we have the command + // line. + // It's not very clear how the above motivation would map in the + // linker-based case, so we currently don't plumb the command line args in + // that case. + if (CmdArgs.empty()) + LLVM_DEBUG( + dbgs() << "Post-(Thin)LTO merge bitcode embedding was requested, but " + "command line arguments are not available"); + llvm::EmbedBitcodeInModule(Mod, llvm::MemoryBufferRef(), + /*EmbedBitcode*/ true, /*EmbedCmdline*/ true, + /*Cmdline*/ CmdArgs); + } + // FIXME: Plumb the combined index into the new pass manager. + if (!Conf.OptPipeline.empty()) + runNewPMCustomPasses(Conf, Mod, TM, Conf.OptPipeline, Conf.AAPipeline, + Conf.DisableVerify); + else if (Conf.UseNewPM) + runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO, ExportSummary, + ImportSummary); + else + runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary); + return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod); +} + Error lto::backend(const Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, std::unique_ptr Mod,