diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -127,6 +127,10 @@ cl::opt LTOCSIRProfile("cs-profile-path", cl::desc("Context sensitive profile file path")); + +static cl::opt LTOSaveTemps( + "lto-save-temps", cl::init(false), + cl::desc("Save temporary LTO files in the current working directory.")); } // namespace llvm LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context) @@ -143,6 +147,11 @@ Config.RunCSIRInstr = LTORunCSIRInstr; Config.CSIRProfile = LTOCSIRProfile; + + if (LTOSaveTemps) + if (Config.addSaveTemps("ld-temp.", + /* UseInputModulePath */ true)) + errs() << "Warning: failed to set up path to save temporary files\n"; } LTOCodeGenerator::~LTOCodeGenerator() = default; @@ -620,6 +629,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); diff --git a/llvm/test/LTO/X86/lto-save-temps.ll b/llvm/test/LTO/X86/lto-save-temps.ll new file mode 100644 --- /dev/null +++ b/llvm/test/LTO/X86/lto-save-temps.ll @@ -0,0 +1,19 @@ +; Check -lto-save-temps generates all the necessary temp files. +; RUN: rm -rf %t.d +; RUN: mkdir -p %t.d && cd %t.d +; RUN: llvm-as %s -o %t1.bc +; RUN: llvm-lto -lto-save-temps %t1.bc -o %t2.bc +; RUN: llvm-dis ld-temp.0.3.import.bc -o - | FileCheck %s +; RUN: llvm-dis ld-temp.0.4.opt.bc -o - | FileCheck %s +; RUN: llvm-dis ld-temp.0.5.precodegen.bc -o - | FileCheck %s +; RUN: ls ld-temp.resolution.txt + +; CHECK: source_filename = "ld-temp.o" + +define i32 @main() { +entry: + %call = call i32 @foo() + ret i32 %call +} + +declare i32 @foo()