[PATCH] D95222: [LTOBackend] Return module when Parallelism Level == 1.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 22 05:04:48 PST 2021
fhahn created this revision.
fhahn added reviewers: steven_wu, tejohnson, dexonsmith, probinson.
Herald added subscribers: hiraditya, inglorion.
fhahn requested review of this revision.
Herald added a project: LLVM.
This patch updates lto::backend() the return the passed in module
if ParallelCodeGenParallelismLevel == 1. In that case, only a reference
to the module is needed and we can move the module back to the caller.
This is required to use lto::backend() for libLTO, because the merged
module might be accessed after code-gen, if
ParallelCodeGenParallelismLevel == 1.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95222
Files:
llvm/include/llvm/LTO/LTOBackend.h
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/LTOBackend.cpp
Index: llvm/lib/LTO/LTOBackend.cpp
===================================================================
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -531,10 +531,10 @@
return Error::success();
}
-Error lto::backend(const Config &C, AddStreamFn AddStream,
- unsigned ParallelCodeGenParallelismLevel,
- std::unique_ptr<Module> Mod,
- ModuleSummaryIndex &CombinedIndex) {
+Expected<std::unique_ptr<Module>>
+lto::backend(const Config &C, AddStreamFn AddStream,
+ unsigned ParallelCodeGenParallelismLevel,
+ std::unique_ptr<Module> Mod, ModuleSummaryIndex &CombinedIndex) {
Expected<const Target *> TOrErr = initAndLookupTarget(C, *Mod);
if (!TOrErr)
return TOrErr.takeError();
@@ -545,16 +545,17 @@
if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false,
/*ExportSummary=*/&CombinedIndex, /*ImportSummary=*/nullptr,
/*CmdArgs*/ std::vector<uint8_t>()))
- return Error::success();
+ return {nullptr};
}
if (ParallelCodeGenParallelismLevel == 1) {
codegen(C, TM.get(), AddStream, 0, *Mod, CombinedIndex);
+ return {std::move(Mod)};
} else {
splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel,
std::move(Mod), CombinedIndex);
}
- return Error::success();
+ return {nullptr};
}
static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals,
Index: llvm/lib/LTO/LTO.cpp
===================================================================
--- llvm/lib/LTO/LTO.cpp
+++ llvm/lib/LTO/LTO.cpp
@@ -1068,10 +1068,11 @@
}
if (!RegularLTO.EmptyCombinedModule || Conf.AlwaysEmitRegularLTOObj) {
- if (Error Err = backend(
- Conf, AddStream, RegularLTO.ParallelCodeGenParallelismLevel,
- std::move(RegularLTO.CombinedModule), ThinLTO.CombinedIndex))
- return Err;
+ auto Result =
+ backend(Conf, AddStream, RegularLTO.ParallelCodeGenParallelismLevel,
+ std::move(RegularLTO.CombinedModule), ThinLTO.CombinedIndex);
+ if (!Result)
+ return Result.takeError();
}
return finalizeOptimizationRemarks(std::move(*DiagFileOrErr));
Index: llvm/include/llvm/LTO/LTOBackend.h
===================================================================
--- llvm/include/llvm/LTO/LTOBackend.h
+++ llvm/include/llvm/LTO/LTOBackend.h
@@ -41,9 +41,11 @@
/// 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(const Config &C, AddStreamFn AddStream,
- unsigned ParallelCodeGenParallelismLevel,
- std::unique_ptr<Module> M, ModuleSummaryIndex &CombinedIndex);
+/// If \p ParallelCodeGenParallelismLevel is 1, return the unmodified \p M.
+Expected<std::unique_ptr<Module>>
+backend(const Config &C, AddStreamFn AddStream,
+ unsigned ParallelCodeGenParallelismLevel, std::unique_ptr<Module> M,
+ ModuleSummaryIndex &CombinedIndex);
/// Runs a ThinLTO backend.
Error thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95222.318488.patch
Type: text/x-patch
Size: 3169 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210122/c43e8a16/attachment.bin>
More information about the llvm-commits
mailing list