[PATCH] D153559: [libLTO] Add support for -save-temps
Qiongsi Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 22 08:15:24 PDT 2023
qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: fhahn, w2yehia, steven_wu, tejohnson.
qiongsiwu1 added a project: LLVM.
Herald added subscribers: ormris, StephenFan, hiraditya, inglorion.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added a subscriber: llvm-commits.
This patch rebases https://reviews.llvm.org/D98183 and consolidates the `-save-temps` across `libLTO`, `llvm-lto` and `llvm-lto2`.
Original summary of https://reviews.llvm.org/D98183:
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/D153559
Files:
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp
llvm/tools/lto/lto.cpp
Index: llvm/tools/lto/lto.cpp
===================================================================
--- llvm/tools/lto/lto.cpp
+++ llvm/tools/lto/lto.cpp
@@ -32,6 +32,10 @@
static codegen::RegisterCodeGenFlags CGF;
+namespace llvm {
+extern cl::opt<bool> SaveTemps;
+}
+
// extra command-line flags needed for LTOCodeGenerator
static cl::opt<char>
OptLevel("O",
Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===================================================================
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -63,8 +63,9 @@
static cl::opt<std::string> AAPipeline("aa-pipeline",
cl::desc("Alias Analysis Pipeline"),
cl::value_desc("aapipeline"));
-
-static cl::opt<bool> SaveTemps("save-temps", cl::desc("Save temporary files"));
+namespace llvm {
+extern cl::opt<bool> SaveTemps;
+}
static cl::list<std::string> SelectSaveTemps(
"select-save-temps",
Index: llvm/lib/LTO/LTOCodeGenerator.cpp
===================================================================
--- llvm/lib/LTO/LTOCodeGenerator.cpp
+++ llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -127,6 +127,10 @@
cl::opt<std::string>
LTOCSIRProfile("cs-profile-path",
cl::desc("Context sensitive profile file path"));
+
+cl::opt<bool> SaveTemps(
+ "save-temps", cl::init(false),
+ cl::desc("Save temporary LTO files in the current working directory."));
} // namespace llvm
LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
@@ -623,6 +627,9 @@
// Add an appropriate DataLayout instance for this module...
MergedModule->setDataLayout(TargetMach->createDataLayout());
+ if (Config.PostImportModuleHook)
+ Config.PostImportModuleHook(0, *MergedModule);
+
if (!SaveIRBeforeOptPath.empty()) {
std::error_code EC;
raw_fd_ostream OS(SaveIRBeforeOptPath, EC, sys::fs::OF_None);
@@ -688,6 +695,12 @@
void LTOCodeGenerator::parseCodeGenDebugOptions() {
if (!CodegenOptions.empty())
llvm::parseCommandLineOptions(CodegenOptions);
+
+ if (SaveTemps) {
+ if (Config.addSaveTemps("ld-temp.",
+ /* UseInputModulePath */ true))
+ errs() << "Warning: failed to set up path to save temporary files\n";
+ }
}
void llvm::parseCommandLineOptions(std::vector<std::string> &Options) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153559.533621.patch
Type: text/x-patch
Size: 2366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230622/0da32cd5/attachment.bin>
More information about the llvm-commits
mailing list