[PATCH] D98183: [libLTO] Add support for -save-temps.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 8 08:14:30 PST 2021
fhahn created this revision.
fhahn added reviewers: tejohnson, steven_wu.
Herald added subscribers: hiraditya, inglorion.
fhahn requested review of this revision.
Herald added a project: LLVM.
This patch updates LTOCodeGenerator to use `addSaveTemps` to support the
-save-temps option when using libLTO. At the moment, the save-temps
hooks are set up in parseCodeGenDebugOptions, because that's the
earliest the options have been parsed. I am not sure if there's a better
place, given the way libLTO's API is structured. At the moment, the
temporary files are created in the current working directory, because I
do not think there's a way to get the path for the final binary
up-front.
It also adds support for running the PostImportModuleHook just before
IR optimiztions are run. At the moment, the following temporary files
are created:
- ld-temp.0.3.import.bc (before IR optimizations)
- ld-temp.0.4.opt.bc (after IR optimizations)
- ld-temp.0.5.precodegen.bc (before codegen)
Other hooks can be supported in the future, but the 3 IR files above
should be the most valuable ones when investigating mis-compiles or
crashes when doing full LTO using libLTO.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98183
Files:
llvm/lib/LTO/LTOCodeGenerator.cpp
Index: llvm/lib/LTO/LTOCodeGenerator.cpp
===================================================================
--- llvm/lib/LTO/LTOCodeGenerator.cpp
+++ llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -119,6 +119,10 @@
cl::Hidden);
}
+static cl::opt<bool> SaveTemps(
+ "save-temps", cl::init(false),
+ cl::desc("Save temporary LTO files in the current working directory."));
+
LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
: Context(Context), MergedModule(new Module("ld-temp.o", Context)),
TheLinker(new Linker(*MergedModule)) {
@@ -545,6 +549,9 @@
// Add an appropriate DataLayout instance for this module...
MergedModule->setDataLayout(TargetMach->createDataLayout());
+ if (Config.PostImportModuleHook)
+ Config.PostImportModuleHook(0, *MergedModule);
+
ModuleSummaryIndex CombinedIndex(false);
TargetMach = createTargetMachine();
if (!opt(Config, TargetMach.get(), 0, *MergedModule, /*IsThinLTO=*/false,
@@ -606,8 +613,13 @@
CodegenArgv.push_back(Arg.c_str());
cl::ParseCommandLineOptions(CodegenArgv.size(), CodegenArgv.data());
}
-}
+ if (SaveTemps) {
+ if (Config.addSaveTemps("ld-temp.",
+ /* UseInputModulePath */ true))
+ errs() << "Warning: failed to set up path to save temporary files\n";
+ }
+}
void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo &DI) {
// Map the LLVM internal diagnostic severity to the LTO diagnostic severity.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98183.329021.patch
Type: text/x-patch
Size: 1462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210308/4aaa2d5c/attachment.bin>
More information about the llvm-commits
mailing list