@@ -296,6 +296,18 @@ static llvm::cl::opt<OptimizationMode> OptModeFlag(
296296 " ignore debug info, reduce runtime" )),
297297 llvm::cl::init(OptimizationMode::NotSet));
298298
299+ static llvm::cl::opt<IRGenDebugInfoLevel> IRGenDebugInfoLevelArg (
300+ " irgen-debuginfo-level" , llvm::cl::desc(" IRGen debug info level" ),
301+ llvm::cl::values(clEnumValN(IRGenDebugInfoLevel::None, " none" ,
302+ " No debug info" ),
303+ clEnumValN(IRGenDebugInfoLevel::LineTables, " line-tables" ,
304+ " Line tables only" ),
305+ clEnumValN(IRGenDebugInfoLevel::ASTTypes, " ast-types" ,
306+ " Line tables + AST type references" ),
307+ clEnumValN(IRGenDebugInfoLevel::DwarfTypes, " dwarf-types" ,
308+ " Line tables + AST type refs + Dwarf types" )),
309+ llvm::cl::init(IRGenDebugInfoLevel::ASTTypes));
310+
299311static llvm::cl::opt<OptGroup> OptimizationGroup (
300312 llvm::cl::desc (" Predefined optimization groups:" ),
301313 llvm::cl::values(
@@ -675,8 +687,19 @@ int main(int argc, char **argv) {
675687 SILOpts.OptMode = OptModeFlag;
676688 }
677689
678- // Note: SILOpts must be set before the CompilerInstance is initializer below
679- // based on Invocation.
690+ auto &IRGenOpts = Invocation.getIRGenOptions ();
691+ if (OptModeFlag == OptimizationMode::NotSet) {
692+ if (OptimizationGroup == OptGroup::Diagnostics)
693+ IRGenOpts.OptMode = OptimizationMode::NoOptimization;
694+ else
695+ IRGenOpts.OptMode = OptimizationMode::ForSpeed;
696+ } else {
697+ IRGenOpts.OptMode = OptModeFlag;
698+ }
699+ IRGenOpts.DebugInfoLevel = IRGenDebugInfoLevelArg;
700+
701+ // Note: SILOpts, LangOpts, and IRGenOpts must be set before the
702+ // CompilerInstance is initializer below based on Invocation.
680703
681704 serialization::ExtendedValidationInfo extendedInfo;
682705 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
@@ -774,7 +797,8 @@ int main(int argc, char **argv) {
774797 case OptGroup::Unknown: {
775798 auto T = irgen::createIRGenModule (
776799 SILMod.get (), Invocation.getOutputFilenameForAtMostOnePrimary (),
777- Invocation.getMainInputFilenameForDebugInfoForAtMostOnePrimary (), " " );
800+ Invocation.getMainInputFilenameForDebugInfoForAtMostOnePrimary (), " " ,
801+ IRGenOpts);
778802 runCommandLineSelectedPasses (SILMod.get (), T.second );
779803 irgen::deleteIRGenModule (T);
780804 break ;
0 commit comments