Index: llvm/trunk/include/llvm/LTO/LTO.h =================================================================== --- llvm/trunk/include/llvm/LTO/LTO.h +++ llvm/trunk/include/llvm/LTO/LTO.h @@ -316,7 +316,7 @@ LTOLLVMContext Ctx; bool HasModule = false; std::unique_ptr CombinedModule; - IRMover Mover; + std::unique_ptr Mover; } RegularLTO; struct ThinLTOState { Index: llvm/trunk/lib/LTO/LTO.cpp =================================================================== --- llvm/trunk/lib/LTO/LTO.cpp +++ llvm/trunk/lib/LTO/LTO.cpp @@ -167,8 +167,7 @@ LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel, Config &Conf) : ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel), - Ctx(Conf), CombinedModule(llvm::make_unique("ld-temp.o", Ctx)), - Mover(*CombinedModule) {} + Ctx(Conf) {} LTO::ThinLTOState::ThinLTOState(ThinBackend Backend) : Backend(Backend) { if (!Backend) @@ -249,8 +248,11 @@ // Add a regular LTO object to the link. Error LTO::addRegularLTO(std::unique_ptr Input, ArrayRef Res) { - RegularLTO.HasModule = true; - + if (!RegularLTO.CombinedModule) { + RegularLTO.CombinedModule = + llvm::make_unique("ld-temp.o", RegularLTO.Ctx); + RegularLTO.Mover = llvm::make_unique(*RegularLTO.CombinedModule); + } ErrorOr> ObjOrErr = IRObjectFile::create(Input->Obj->getMemoryBufferRef(), RegularLTO.Ctx); if (!ObjOrErr) @@ -305,8 +307,8 @@ } assert(ResI == Res.end()); - return RegularLTO.Mover.move(Obj->takeModule(), Keep, - [](GlobalValue &, IRMover::ValueAdder) {}); + return RegularLTO.Mover->move(Obj->takeModule(), Keep, + [](GlobalValue &, IRMover::ValueAdder) {}); } // Add a ThinLTO object to the link. @@ -316,14 +318,6 @@ SmallPtrSet Used; collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false); - // We need to initialize the target info for the combined regular LTO module - // in case we have no regular LTO objects. In that case we still need to build - // it as usual because the client may want to add symbol definitions to it. - if (RegularLTO.CombinedModule->getTargetTriple().empty()) { - RegularLTO.CombinedModule->setTargetTriple(M.getTargetTriple()); - RegularLTO.CombinedModule->setDataLayout(M.getDataLayout()); - } - MemoryBufferRef MBRef = Input->Obj->getMemoryBufferRef(); ErrorOr> SummaryObjOrErr = @@ -357,12 +351,8 @@ } Error LTO::run(AddOutputFn AddOutput) { - // Invoke regular LTO if there was a regular LTO module to start with, - // or if there are any hooks that the linker may have used to add - // its own resolved symbols to the combined module. - if (RegularLTO.HasModule || Conf.PreOptModuleHook || - Conf.PostInternalizeModuleHook || Conf.PostOptModuleHook || - Conf.PreCodeGenModuleHook) + // Invoke regular LTO if there was a regular LTO module to start with. + if (RegularLTO.CombinedModule) if (auto E = runRegularLTO(AddOutput)) return E; return runThinLTO(AddOutput); @@ -660,7 +650,9 @@ // ParallelCodeGenParallelismLevel, as tasks 0 through // ParallelCodeGenParallelismLevel-1 are reserved for parallel code generation // partitions. - unsigned Task = RegularLTO.ParallelCodeGenParallelismLevel; + unsigned Task = RegularLTO.CombinedModule + ? RegularLTO.ParallelCodeGenParallelismLevel + : 0; unsigned Partition = 1; for (auto &Mod : ThinLTO.ModuleMap) {