Skip to content

Commit 487234c

Browse files
authored
Merge pull request #41458 from gottesmm/pr-d179a548962e72bacc7ac8a564a69f32567839be
[sil-opt] Propagate to IRGenOptions whether we have debug info and or optimizations enabled.
2 parents 036d78f + 135ab2b commit 487234c

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

include/swift/IRGen/IRGenPublic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class IRGenModule;
3131
std::pair<IRGenerator *, IRGenModule *>
3232
createIRGenModule(SILModule *SILMod, StringRef OutputFilename,
3333
StringRef MainInputFilenameForDebugInfo,
34-
StringRef PrivateDiscriminator);
34+
StringRef PrivateDiscriminator, IRGenOptions &options);
3535

3636
/// Delete the IRGenModule and IRGenerator obtained by the above call.
3737
void deleteIRGenModule(std::pair<IRGenerator *, IRGenModule *> &Module);

lib/IRGen/IRGen.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,8 @@ static void initLLVMModule(const IRGenModule &IGM, SILModule &SIL) {
937937
std::pair<IRGenerator *, IRGenModule *>
938938
swift::irgen::createIRGenModule(SILModule *SILMod, StringRef OutputFilename,
939939
StringRef MainInputFilenameForDebugInfo,
940-
StringRef PrivateDiscriminator) {
941-
942-
IRGenOptions Opts;
940+
StringRef PrivateDiscriminator,
941+
IRGenOptions &Opts) {
943942
IRGenerator *irgen = new IRGenerator(Opts, *SILMod);
944943
auto targetMachine = irgen->createTargetMachine();
945944
if (!targetMachine)

tools/sil-opt/SILOpt.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
299311
static 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

Comments
 (0)