diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h index 42c9d5b78c0bc..aa21f963d3a82 100644 --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -222,7 +222,7 @@ using NativeObjectCache = /// The details of this type definition aren't important; clients can only /// create a ThinBackend using one of the create*ThinBackend() functions below. using ThinBackend = std::function( - Config &C, ModuleSummaryIndex &CombinedIndex, + const Config &C, ModuleSummaryIndex &CombinedIndex, StringMap &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache)>; @@ -306,7 +306,8 @@ class LTO { Config Conf; struct RegularLTOState { - RegularLTOState(unsigned ParallelCodeGenParallelismLevel, Config &Conf); + RegularLTOState(unsigned ParallelCodeGenParallelismLevel, + const Config &Conf); struct CommonResolution { uint64_t Size = 0; MaybeAlign Align; diff --git a/llvm/include/llvm/LTO/LTOBackend.h b/llvm/include/llvm/LTO/LTOBackend.h index 4ff8a1993d49f..de4fa308fde7d 100644 --- a/llvm/include/llvm/LTO/LTOBackend.h +++ b/llvm/include/llvm/LTO/LTOBackend.h @@ -35,13 +35,13 @@ namespace lto { /// 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(Config &C, AddStreamFn AddStream, +Error backend(const Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, std::unique_ptr M, ModuleSummaryIndex &CombinedIndex); /// Runs a ThinLTO backend. -Error thinBackend(Config &C, unsigned Task, AddStreamFn AddStream, Module &M, - const ModuleSummaryIndex &CombinedIndex, +Error thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream, + Module &M, const ModuleSummaryIndex &CombinedIndex, const FunctionImporter::ImportMapTy &ImportList, const GVSummaryMapTy &DefinedGlobals, MapVector &ModuleMap); diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 950315fc2ed45..297b11de17a90 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -467,7 +467,7 @@ BitcodeModule &InputFile::getSingleBitcodeModule() { } LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel, - Config &Conf) + const Config &Conf) : ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel), Ctx(Conf), CombinedModule(std::make_unique("ld-temp.o", Ctx)), Mover(std::make_unique(*CombinedModule)) {} @@ -1029,12 +1029,12 @@ ArrayRef LTO::getRuntimeLibcallSymbols() { /// This class defines the interface to the ThinLTO backend. class lto::ThinBackendProc { protected: - Config &Conf; + const Config &Conf; ModuleSummaryIndex &CombinedIndex; const StringMap &ModuleToDefinedGVSummaries; public: - ThinBackendProc(Config &Conf, ModuleSummaryIndex &CombinedIndex, + ThinBackendProc(const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap &ModuleToDefinedGVSummaries) : Conf(Conf), CombinedIndex(CombinedIndex), ModuleToDefinedGVSummaries(ModuleToDefinedGVSummaries) {} @@ -1062,7 +1062,7 @@ class InProcessThinBackend : public ThinBackendProc { public: InProcessThinBackend( - Config &Conf, ModuleSummaryIndex &CombinedIndex, + const Config &Conf, ModuleSummaryIndex &CombinedIndex, unsigned ThinLTOParallelismLevel, const StringMap &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache) @@ -1160,7 +1160,7 @@ class InProcessThinBackend : public ThinBackendProc { } // end anonymous namespace ThinBackend lto::createInProcessThinBackend(unsigned ParallelismLevel) { - return [=](Config &Conf, ModuleSummaryIndex &CombinedIndex, + return [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache) { return std::make_unique( @@ -1198,7 +1198,7 @@ class WriteIndexesThinBackend : public ThinBackendProc { public: WriteIndexesThinBackend( - Config &Conf, ModuleSummaryIndex &CombinedIndex, + const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap &ModuleToDefinedGVSummaries, std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, lto::IndexWriteCallback OnWrite) @@ -1250,7 +1250,7 @@ class WriteIndexesThinBackend : public ThinBackendProc { ThinBackend lto::createWriteIndexesThinBackend( std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite) { - return [=](Config &Conf, ModuleSummaryIndex &CombinedIndex, + return [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache) { return std::make_unique( diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index ef40d24b2a914..dcde7277b8202 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -128,7 +128,7 @@ Error Config::addSaveTemps(std::string OutputFileName, namespace { std::unique_ptr -createTargetMachine(Config &Conf, const Target *TheTarget, Module &M) { +createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) { StringRef TheTriple = M.getTargetTriple(); SubtargetFeatures Features; Features.getDefaultSubtargetFeatures(Triple(TheTriple)); @@ -153,7 +153,7 @@ createTargetMachine(Config &Conf, const Target *TheTarget, Module &M) { CodeModel, Conf.CGOptLevel)); } -static void runNewPMPasses(Config &Conf, Module &Mod, TargetMachine *TM, +static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM, unsigned OptLevel, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary) { @@ -269,7 +269,7 @@ static void runNewPMCustomPasses(Module &Mod, TargetMachine *TM, MPM.run(Mod, MAM); } -static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM, +static void runOldPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary) { legacy::PassManager passes; @@ -300,7 +300,7 @@ static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM, passes.run(Mod); } -bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, +bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary) { // FIXME: Plumb the combined index into the new pass manager. @@ -319,7 +319,7 @@ static cl::opt EmbedBitcode( "lto-embed-bitcode", cl::init(false), cl::desc("Embed LLVM bitcode in object files produced by LTO")); -static void EmitBitcodeSection(Module &M, Config &Conf) { +static void EmitBitcodeSection(Module &M, const Config &Conf) { if (!EmbedBitcode) return; SmallVector Buffer; @@ -332,7 +332,7 @@ static void EmitBitcodeSection(Module &M, Config &Conf) { /*EmbedMarker*/ false, /*CmdArgs*/ nullptr); } -void codegen(Config &Conf, TargetMachine *TM, AddStreamFn AddStream, +void codegen(const Config &Conf, TargetMachine *TM, AddStreamFn AddStream, unsigned Task, Module &Mod) { if (Conf.PreCodeGenModuleHook && !Conf.PreCodeGenModuleHook(Task, Mod)) return; @@ -372,7 +372,7 @@ void codegen(Config &Conf, TargetMachine *TM, AddStreamFn AddStream, DwoOut->keep(); } -void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream, +void splitCodeGen(const Config &C, TargetMachine *TM, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, std::unique_ptr Mod) { ThreadPool CodegenThreadPool(ParallelCodeGenParallelismLevel); @@ -420,7 +420,7 @@ void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream, CodegenThreadPool.wait(); } -Expected initAndLookupTarget(Config &C, Module &Mod) { +Expected initAndLookupTarget(const Config &C, Module &Mod) { if (!C.OverrideTriple.empty()) Mod.setTargetTriple(C.OverrideTriple); else if (Mod.getTargetTriple().empty()) @@ -432,7 +432,6 @@ Expected initAndLookupTarget(Config &C, Module &Mod) { return make_error(Msg, inconvertibleErrorCode()); return T; } - } static Error @@ -446,7 +445,7 @@ finalizeOptimizationRemarks(std::unique_ptr DiagOutputFile) { return Error::success(); } -Error lto::backend(Config &C, AddStreamFn AddStream, +Error lto::backend(const Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, std::unique_ptr Mod, ModuleSummaryIndex &CombinedIndex) { @@ -500,7 +499,7 @@ static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals, } } -Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream, +Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream, Module &Mod, const ModuleSummaryIndex &CombinedIndex, const FunctionImporter::ImportMapTy &ImportList, const GVSummaryMapTy &DefinedGlobals,