diff options
author | Teresa Johnson <tejohnson@google.com> | 2020-01-13 12:23:34 -0800 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2020-01-13 12:26:17 -0800 |
commit | d0aad9f56e1588effa94b15804b098e6307da6b4 (patch) | |
tree | 9581de88c751dcf2ae45fd5b3ab9b4472aeaa35b | |
parent | a0f4600f4f0ece1d4779544513f5a70c6f0d78bf (diff) | |
download | bcm5719-llvm-d0aad9f56e1588effa94b15804b098e6307da6b4.tar.gz bcm5719-llvm-d0aad9f56e1588effa94b15804b098e6307da6b4.zip |
[LTO] Constify lto::Config reference passed to backends (NFC)
The lto::Config object saved on the global LTO object should not be
updated by any of the LTO backends. Otherwise we could run into
interference between threads utilizing it. Motivated by some proposed
changes that would have caused it to get modified in the ThinLTO
backends.
-rw-r--r-- | llvm/include/llvm/LTO/LTO.h | 5 | ||||
-rw-r--r-- | llvm/include/llvm/LTO/LTOBackend.h | 6 | ||||
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 14 | ||||
-rw-r--r-- | llvm/lib/LTO/LTOBackend.cpp | 21 |
4 files changed, 23 insertions, 23 deletions
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h index 42c9d5b78c0..aa21f963d3a 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<std::unique_ptr<ThinBackendProc>( - Config &C, ModuleSummaryIndex &CombinedIndex, + const Config &C, ModuleSummaryIndex &CombinedIndex, StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache)>; @@ -306,7 +306,8 @@ private: 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 4ff8a1993d4..de4fa308fde 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<Module> 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<StringRef, BitcodeModule> &ModuleMap); diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 950315fc2ed..297b11de17a 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<Module>("ld-temp.o", Ctx)), Mover(std::make_unique<IRMover>(*CombinedModule)) {} @@ -1029,12 +1029,12 @@ ArrayRef<const char*> LTO::getRuntimeLibcallSymbols() { /// This class defines the interface to the ThinLTO backend. class lto::ThinBackendProc { protected: - Config &Conf; + const Config &Conf; ModuleSummaryIndex &CombinedIndex; const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries; public: - ThinBackendProc(Config &Conf, ModuleSummaryIndex &CombinedIndex, + ThinBackendProc(const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap<GVSummaryMapTy> &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<GVSummaryMapTy> &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache) @@ -1160,7 +1160,7 @@ public: } // end anonymous namespace ThinBackend lto::createInProcessThinBackend(unsigned ParallelismLevel) { - return [=](Config &Conf, ModuleSummaryIndex &CombinedIndex, + return [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache) { return std::make_unique<InProcessThinBackend>( @@ -1198,7 +1198,7 @@ class WriteIndexesThinBackend : public ThinBackendProc { public: WriteIndexesThinBackend( - Config &Conf, ModuleSummaryIndex &CombinedIndex, + const Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries, std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, lto::IndexWriteCallback OnWrite) @@ -1250,7 +1250,7 @@ public: 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<GVSummaryMapTy> &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache) { return std::make_unique<WriteIndexesThinBackend>( diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index ef40d24b2a9..dcde7277b82 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<TargetMachine> -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<bool> 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<char, 0> 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<Module> Mod) { ThreadPool CodegenThreadPool(ParallelCodeGenParallelismLevel); @@ -420,7 +420,7 @@ void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream, CodegenThreadPool.wait(); } -Expected<const Target *> initAndLookupTarget(Config &C, Module &Mod) { +Expected<const Target *> initAndLookupTarget(const Config &C, Module &Mod) { if (!C.OverrideTriple.empty()) Mod.setTargetTriple(C.OverrideTriple); else if (Mod.getTargetTriple().empty()) @@ -432,7 +432,6 @@ Expected<const Target *> initAndLookupTarget(Config &C, Module &Mod) { return make_error<StringError>(Msg, inconvertibleErrorCode()); return T; } - } static Error @@ -446,7 +445,7 @@ finalizeOptimizationRemarks(std::unique_ptr<ToolOutputFile> DiagOutputFile) { return Error::success(); } -Error lto::backend(Config &C, AddStreamFn AddStream, +Error lto::backend(const Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, std::unique_ptr<Module> 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, |