diff --git a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h --- a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h +++ b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h @@ -193,6 +193,8 @@ void resetMergedModule() { MergedModule.reset(); } void DiagnosticHandler(const DiagnosticInfo &DI); + Module &getMergedModule() { return *MergedModule; } + private: /// Verify the merged module on first call. /// diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -197,6 +197,11 @@ cl::desc("Write merged LTO module to file before CodeGen"), cl::cat(LTOCategory)); +static cl::opt + DumpLinkedModule("dump-linked-module", cl::init(false), + cl::desc("Dump linked LTO module before optimize"), + cl::cat(LTOCategory)); + static cl::list InputFilenames(cl::Positional, cl::OneOrMore, cl::desc(""), cl::cat(LTOCategory)); @@ -316,11 +321,11 @@ if (!CurrentActivity.empty()) OS << ' ' << CurrentActivity; OS << ": "; - + DiagnosticPrinterRawOStream DP(OS); DI.print(DP); OS << '\n'; - + if (DI.getSeverity() == DS_Error) exit(1); return true; @@ -1115,6 +1120,14 @@ error("error compiling the code"); } else { + if (DumpLinkedModule) { + if (SaveLinkedModuleFile) + error(": -dump-linked-module must be used without -dump-linked-module"); + + Module &M = CodeGen.getMergedModule(); + M.dump(); + } + if (Parallelism != 1) error("-j must be specified together with -o");