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")); + +cl::opt 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 &Options) { diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp --- a/llvm/tools/llvm-lto2/llvm-lto2.cpp +++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp @@ -63,8 +63,9 @@ static cl::opt AAPipeline("aa-pipeline", cl::desc("Alias Analysis Pipeline"), cl::value_desc("aapipeline")); - -static cl::opt SaveTemps("save-temps", cl::desc("Save temporary files")); +namespace llvm { +extern cl::opt SaveTemps; +} static cl::list SelectSaveTemps( "select-save-temps", diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp --- a/llvm/tools/lto/lto.cpp +++ b/llvm/tools/lto/lto.cpp @@ -32,6 +32,10 @@ static codegen::RegisterCodeGenFlags CGF; +namespace llvm { +extern cl::opt SaveTemps; +} + // extra command-line flags needed for LTOCodeGenerator static cl::opt OptLevel("O",