@@ -181,6 +181,25 @@ static llvm::cl::opt<std::string>
181
181
Target (" target" , llvm::cl::desc(" target triple" ),
182
182
llvm::cl::init(llvm::sys::getDefaultTargetTriple()));
183
183
184
+ // This primarily determines semantics of debug information. The compiler does
185
+ // not directly expose a "preserve debug info mode". It is derived from the
186
+ // optimization level. At -Onone, all debug info must be preserved. At higher
187
+ // levels, debug info cannot change the compiler output.
188
+ //
189
+ // Diagnostics should be "equivalent" at all levels. For example, programs that
190
+ // compile at -Onone should compile at -O. However, it is difficult to guarantee
191
+ // identical diagnostic output given the changes in SIL caused by debug info
192
+ // preservation.
193
+ static llvm::cl::opt<OptimizationMode> OptModeFlag (
194
+ " opt-mode" , llvm::cl::desc(" optimization mode" ),
195
+ llvm::cl::values(clEnumValN(OptimizationMode::NoOptimization, " none" ,
196
+ " preserve debug info" ),
197
+ clEnumValN(OptimizationMode::ForSize, " size" ,
198
+ " ignore debug info, reduce size" ),
199
+ clEnumValN(OptimizationMode::ForSpeed, " speed" ,
200
+ " ignore debug info, reduce runtime" )),
201
+ llvm::cl::init(OptimizationMode::NotSet));
202
+
184
203
static llvm::cl::opt<OptGroup> OptimizationGroup (
185
204
llvm::cl::desc (" Predefined optimization groups:" ),
186
205
llvm::cl::values(
@@ -485,8 +504,6 @@ int main(int argc, char **argv) {
485
504
SILOpts.VerifyNone = SILVerifyNone;
486
505
SILOpts.RemoveRuntimeAsserts = RemoveRuntimeAsserts;
487
506
SILOpts.AssertConfig = AssertConfId;
488
- if (OptimizationGroup != OptGroup::Diagnostics)
489
- SILOpts.OptMode = OptimizationMode::ForSpeed;
490
507
SILOpts.VerifySILOwnership = !DisableSILOwnershipVerifier;
491
508
SILOpts.OptRecordFile = RemarksFilename;
492
509
SILOpts.OptRecordPasses = RemarksPasses;
@@ -547,6 +564,18 @@ int main(int argc, char **argv) {
547
564
if (!EnableLexicalBorrowScopes)
548
565
SILOpts.LexicalLifetimes = LexicalLifetimesOption::Off;
549
566
567
+ if (OptModeFlag == OptimizationMode::NotSet) {
568
+ if (OptimizationGroup == OptGroup::Diagnostics)
569
+ SILOpts.OptMode = OptimizationMode::NoOptimization;
570
+ else
571
+ SILOpts.OptMode = OptimizationMode::ForSpeed;
572
+ } else {
573
+ SILOpts.OptMode = OptModeFlag;
574
+ }
575
+
576
+ // Note: SILOpts must be set before the CompilerInstance is initializer below
577
+ // based on Invocation.
578
+
550
579
serialization::ExtendedValidationInfo extendedInfo;
551
580
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
552
581
Invocation.setUpInputForSILTool (InputFilename, ModuleName,
0 commit comments