[llvm] r279550 - Stop always creating and running an LTO compilation if there is not a single LTO object
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 23 11:39:13 PDT 2016
Author: mehdi_amini
Date: Tue Aug 23 13:39:12 2016
New Revision: 279550
URL: http://llvm.org/viewvc/llvm-project?rev=279550&view=rev
Log:
Stop always creating and running an LTO compilation if there is not a single LTO object
Summary:
I assume there was a use case, so maybe this strawman patch will help
clarifying if it is legit.
In any case the current situation is not legit: a ThinLTO compilation
should not trigger an unexpected full LTO compilation.
Right now, adding a --save-temps option triggers this and makes the
number of output differs.
Reviewers: tejohnson
Subscribers: pcc, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D23600
Modified:
llvm/trunk/include/llvm/LTO/LTO.h
llvm/trunk/lib/LTO/LTO.cpp
Modified: llvm/trunk/include/llvm/LTO/LTO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTO.h?rev=279550&r1=279549&r2=279550&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTO.h (original)
+++ llvm/trunk/include/llvm/LTO/LTO.h Tue Aug 23 13:39:12 2016
@@ -316,7 +316,7 @@ private:
LTOLLVMContext Ctx;
bool HasModule = false;
std::unique_ptr<Module> CombinedModule;
- IRMover Mover;
+ std::unique_ptr<IRMover> Mover;
} RegularLTO;
struct ThinLTOState {
Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=279550&r1=279549&r2=279550&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Tue Aug 23 13:39:12 2016
@@ -167,8 +167,7 @@ Expected<std::unique_ptr<InputFile>> Inp
LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
Config &Conf)
: ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel),
- Ctx(Conf), CombinedModule(llvm::make_unique<Module>("ld-temp.o", Ctx)),
- Mover(*CombinedModule) {}
+ Ctx(Conf) {}
LTO::ThinLTOState::ThinLTOState(ThinBackend Backend) : Backend(Backend) {
if (!Backend)
@@ -249,8 +248,11 @@ Error LTO::add(std::unique_ptr<InputFile
// Add a regular LTO object to the link.
Error LTO::addRegularLTO(std::unique_ptr<InputFile> Input,
ArrayRef<SymbolResolution> Res) {
- RegularLTO.HasModule = true;
-
+ if (!RegularLTO.CombinedModule) {
+ RegularLTO.CombinedModule =
+ llvm::make_unique<Module>("ld-temp.o", RegularLTO.Ctx);
+ RegularLTO.Mover = llvm::make_unique<IRMover>(*RegularLTO.CombinedModule);
+ }
ErrorOr<std::unique_ptr<object::IRObjectFile>> ObjOrErr =
IRObjectFile::create(Input->Obj->getMemoryBufferRef(), RegularLTO.Ctx);
if (!ObjOrErr)
@@ -305,8 +307,8 @@ Error LTO::addRegularLTO(std::unique_ptr
}
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 @@ Error LTO::addThinLTO(std::unique_ptr<In
SmallPtrSet<GlobalValue *, 8> 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<std::unique_ptr<object::ModuleSummaryIndexObjectFile>>
SummaryObjOrErr =
@@ -357,12 +351,8 @@ unsigned LTO::getMaxTasks() const {
}
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 @@ Error LTO::runThinLTO(AddOutputFn AddOut
// 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) {
More information about the llvm-commits
mailing list