Index: include/llvm/LTO/Config.h =================================================================== --- include/llvm/LTO/Config.h +++ include/llvm/LTO/Config.h @@ -46,6 +46,16 @@ unsigned OptLevel = 2; bool DisableVerify = false; + enum EmitIRType { + EIRT_CodeGen, /// Do CodeGen and emit CGFileType + EIRT_LL, /// Emit human-readable LLVM assembly + EIRT_BC, /// Emit LLVM bitcode files + EIRT_Nothing, /// Don't emit anything (benchmarking mode) + }; + + /// Type of IR file to output, defaults to none (do codegen). + EmitIRType IROutputType = EIRT_CodeGen; + /// Disable entirely the optimizer, including importing for ThinLTO bool CodeGenOnly = false; Index: lib/LTO/LTOBackend.cpp =================================================================== --- lib/LTO/LTOBackend.cpp +++ lib/LTO/LTOBackend.cpp @@ -21,6 +21,8 @@ #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/BitcodeWriter.h" +#include "llvm/Bitcode/BitcodeWriterPass.h" +#include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Verifier.h" @@ -269,11 +271,32 @@ if (Conf.PreCodeGenModuleHook && !Conf.PreCodeGenModuleHook(Task, Mod)) return; - auto Stream = AddStream(Task); - legacy::PassManager CodeGenPasses; - if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS, Conf.CGFileType)) - report_fatal_error("Failed to setup codegen"); - CodeGenPasses.run(Mod); + switch (Conf.IROutputType) { + case Config::EIRT_Nothing: + break; + + case Config::EIRT_BC: { + auto Stream = AddStream(Task); + legacy::PassManager PerModulePasses; + PerModulePasses.add(createBitcodeWriterPass(*Stream->OS)); + PerModulePasses.run(Mod); + } break; + + case Config::EIRT_LL: { + auto Stream = AddStream(Task); + legacy::PassManager PerModulePasses; + PerModulePasses.add(createPrintModulePass(*Stream->OS)); + PerModulePasses.run(Mod); + } break; + + case Config::EIRT_CodeGen: { + auto Stream = AddStream(Task); + legacy::PassManager CodeGenPasses; + if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS, Conf.CGFileType)) + report_fatal_error("Failed to setup codegen"); + CodeGenPasses.run(Mod); + } break; + } } void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream,