aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO/LTOBackend.cpp
diff options
context:
space:
mode:
authorMircea Trofin <mtrofin@google.com>2020-09-14 10:45:00 -0700
committerMircea Trofin <mtrofin@google.com>2020-09-15 15:56:11 -0700
commit61fc10d6a520f267e11009ce8fce88d73615796b (patch)
tree0de41e888ded036b80b693c73f37de094331344d /llvm/lib/LTO/LTOBackend.cpp
parentae726fecae9a1cc9c50de5a9f6e860056f82c556 (diff)
downloadllvm-61fc10d6a520f267e11009ce8fce88d73615796b.zip
llvm-61fc10d6a520f267e11009ce8fce88d73615796b.tar.gz
llvm-61fc10d6a520f267e11009ce8fce88d73615796b.tar.bz2
[ThinLTO] add post-thinlto-merge option to -lto-embed-bitcode
This will embed bitcode after (Thin)LTO merge, but before optimizations. In the case the thinlto backend is called from clang, the .llvmcmd section is also produced. Doing so in the case where the caller is the linker doesn't yet have a motivation, and would require plumbing through command line args. Differential Revision: https://reviews.llvm.org/D87636
Diffstat (limited to 'llvm/lib/LTO/LTOBackend.cpp')
-rw-r--r--llvm/lib/LTO/LTOBackend.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 00309b6..4c5778e 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -50,9 +50,12 @@
using namespace llvm;
using namespace lto;
+#define DEBUG_TYPE "lto-backend"
+
enum class LTOBitcodeEmbedding {
DoNotEmbed = 0,
EmbedOptimized = 1,
+ EmbedPostMergePreOptimized = 2
};
static cl::opt<LTOBitcodeEmbedding> EmbedBitcode(
@@ -60,7 +63,10 @@ static cl::opt<LTOBitcodeEmbedding> EmbedBitcode(
cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none",
"Do not embed"),
clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized",
- "Embed after all optimization passes")),
+ "Embed after all optimization passes"),
+ clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized,
+ "post-merge-pre-opt",
+ "Embed post merge, but before optimizations")),
cl::desc("Embed LLVM bitcode in object files produced by LTO"));
LLVM_ATTRIBUTE_NORETURN static void reportOpenError(StringRef Path, Twine Msg) {
@@ -346,7 +352,25 @@ static void runOldPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
- const ModuleSummaryIndex *ImportSummary) {
+ const ModuleSummaryIndex *ImportSummary,
+ const std::vector<uint8_t> *CmdArgs = nullptr) {
+ if (EmbedBitcode == LTOBitcodeEmbedding::EmbedPostMergePreOptimized) {
+ // FIXME: the motivation for capturing post-merge bitcode and command line
+ // is replicating the compilation environment from bitcode, without needing
+ // to understand the dependencies (the functions to be imported). This
+ // assumes a clang - based invocation, case in which we have the command
+ // line.
+ // It's not very clear how the above motivation would map in the
+ // linker-based case, so we currently don't plumb the command line args in
+ // that case.
+ if (CmdArgs == nullptr)
+ LLVM_DEBUG(
+ dbgs() << "Post-(Thin)LTO merge bitcode embedding was requested, but "
+ "command line arguments are not available");
+ llvm::EmbedBitcodeInModule(Mod, llvm::MemoryBufferRef(),
+ /*EmbedBitcode*/ true,
+ /*EmbedMarker*/ false, CmdArgs);
+ }
// FIXME: Plumb the combined index into the new pass manager.
if (!Conf.OptPipeline.empty())
runNewPMCustomPasses(Conf, Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
@@ -531,7 +555,8 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
Module &Mod, const ModuleSummaryIndex &CombinedIndex,
const FunctionImporter::ImportMapTy &ImportList,
const GVSummaryMapTy &DefinedGlobals,
- MapVector<StringRef, BitcodeModule> &ModuleMap) {
+ MapVector<StringRef, BitcodeModule> &ModuleMap,
+ const std::vector<uint8_t> *CmdArgs) {
Expected<const Target *> TOrErr = initAndLookupTarget(Conf, Mod);
if (!TOrErr)
return TOrErr.takeError();
@@ -599,7 +624,8 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true,
- /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex))
+ /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
+ CmdArgs))
return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
codegen(Conf, TM.get(), AddStream, Task, Mod, CombinedIndex);