diff options
author | Vitaly Buka <vitalybuka@google.com> | 2017-12-16 02:10:00 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2017-12-16 02:10:00 +0000 |
commit | ef76fcda6ef0bb520fc1f96a25ee9c317ed32474 (patch) | |
tree | 3af0eea8fa0b7ad99ab1549ebb82917430784927 /lib/LTO/LTO.cpp | |
parent | c82441edf7067c777414b2a7a6901fe322f4bc87 (diff) |
[LTO] Make processing of combined module more consistent
Summary:
1. Use stream 0 only for combined module. Previously if combined module was not
processes ThinLTO used the stream for own output. However small changes in input,
could trigger combined module and shuffle outputs making life of llvm::LTO harder.
2. Always process combined module and write output to stream 0. Processing empty
combined module is cheap and allows llvm::LTO users to avoid implementing processing
which is already done in llvm::LTO.
Subscribers: mehdi_amini, inglorion, eraman, hiraditya
Differential Revision: https://reviews.llvm.org/D41267
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320905 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/LTO/LTO.cpp')
-rw-r--r-- | lib/LTO/LTO.cpp | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/lib/LTO/LTO.cpp b/lib/LTO/LTO.cpp index 69a696793a6..64e5186255b 100644 --- a/lib/LTO/LTO.cpp +++ b/lib/LTO/LTO.cpp @@ -385,7 +385,8 @@ StringRef InputFile::getName() const { LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel, Config &Conf) : ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel), - Ctx(Conf) {} + Ctx(Conf), CombinedModule(llvm::make_unique<Module>("ld-temp.o", Ctx)), + Mover(llvm::make_unique<IRMover>(*CombinedModule)) {} LTO::ThinLTOState::ThinLTOState(ThinBackend Backend) : Backend(Backend) { if (!Backend) @@ -472,6 +473,9 @@ Error LTO::add(std::unique_ptr<InputFile> Input, if (Conf.ResolutionFile) writeToResolutionFile(*Conf.ResolutionFile, Input.get(), Res); + if (RegularLTO.CombinedModule->getTargetTriple().empty()) + RegularLTO.CombinedModule->setTargetTriple(Input->getTargetTriple()); + const SymbolResolution *ResI = Res.begin(); for (unsigned I = 0; I != Input->Mods.size(); ++I) if (Error Err = addModule(*Input, I, ResI, Res.end())) @@ -659,12 +663,6 @@ LTO::addRegularLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms, Error LTO::linkRegularLTO(RegularLTOState::AddedModule Mod, bool LivenessFromIndex) { - if (!RegularLTO.CombinedModule) { - RegularLTO.CombinedModule = - llvm::make_unique<Module>("ld-temp.o", RegularLTO.Ctx); - RegularLTO.Mover = llvm::make_unique<IRMover>(*RegularLTO.CombinedModule); - } - std::vector<GlobalValue *> Keep; for (GlobalValue *GV : Mod.Keep) { if (LivenessFromIndex && !ThinLTO.CombinedIndex.isGUIDLive(GV->getGUID())) @@ -757,16 +755,9 @@ Error LTO::run(AddStreamFn AddStream, NativeObjectCache Cache) { computeDeadSymbols(ThinLTO.CombinedIndex, GUIDPreservedSymbols); - // Save the status of having a regularLTO combined module, as - // this is needed for generating the ThinLTO Task ID, and - // the CombinedModule will be moved at the end of runRegularLTO. - bool HasRegularLTO = RegularLTO.CombinedModule != nullptr || - !RegularLTO.ModsWithSummaries.empty(); - // Invoke regular LTO if there was a regular LTO module to start with. - if (HasRegularLTO) - if (auto E = runRegularLTO(AddStream)) - return E; - return runThinLTO(AddStream, Cache, HasRegularLTO); + if (auto E = runRegularLTO(AddStream)) + return E; + return runThinLTO(AddStream, Cache); } Error LTO::runRegularLTO(AddStreamFn AddStream) { @@ -1081,8 +1072,7 @@ ThinBackend lto::createWriteIndexesThinBackend(std::string OldPrefix, }; } -Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache, - bool HasRegularLTO) { +Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache) { if (ThinLTO.ModuleMap.empty()) return Error::success(); @@ -1167,11 +1157,9 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache, ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries, AddStream, Cache); - // Task numbers start at ParallelCodeGenParallelismLevel if an LTO - // module is present, as tasks 0 through ParallelCodeGenParallelismLevel-1 - // are reserved for parallel code generation partitions. - unsigned Task = - HasRegularLTO ? RegularLTO.ParallelCodeGenParallelismLevel : 0; + // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for combined + // module and parallel code generation partitions. + unsigned Task = RegularLTO.ParallelCodeGenParallelismLevel; for (auto &Mod : ThinLTO.ModuleMap) { if (Error E = BackendProc->start(Task, Mod.second, ImportLists[Mod.first], ExportLists[Mod.first], |