Skip to content

Commit 4aec4e7

Browse files
committed
Remove dependency of SILFunction in IRGenOptions
SILFunction::shouldBePreservedForDebugger checks if some optimizations are enabled to decide whether a function should be preserved so its accessible form the debugger or not. Some of these settings used to live only in IRGenOptions making SILFunction depend on IRGenOptions.
1 parent 8599292 commit 4aec4e7

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

include/swift/AST/SILOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ class SILOptions {
305305
/// The format used for serializing remarks (default: YAML)
306306
llvm::remarks::Format OptRecordFormat = llvm::remarks::Format::YAML;
307307

308+
/// Are there any options that indicate that functions should not be preserved
309+
/// for the debugger?
310+
bool ShouldFunctionsBePreservedToDebugger = true;
311+
308312
SILOptions() {}
309313

310314
/// Return a hash code of any components from these options that should

lib/Frontend/CompilerInvocation.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,22 @@ void parseExclusivityEnforcementOptions(const llvm::opt::Arg *A,
22032203
}
22042204
}
22052205

2206+
static std::optional<IRGenLLVMLTOKind>
2207+
ParseLLVMLTOKind(const ArgList &Args, DiagnosticEngine &Diags) {
2208+
std::optional<IRGenLLVMLTOKind> LLVMLTOKind;
2209+
if (const Arg *A = Args.getLastArg(options::OPT_lto)) {
2210+
LLVMLTOKind =
2211+
llvm::StringSwitch<std::optional<IRGenLLVMLTOKind>>(A->getValue())
2212+
.Case("llvm-thin", IRGenLLVMLTOKind::Thin)
2213+
.Case("llvm-full", IRGenLLVMLTOKind::Full)
2214+
.Default(std::nullopt);
2215+
if (!LLVMLTOKind)
2216+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
2217+
A->getAsString(Args), A->getValue());
2218+
}
2219+
return LLVMLTOKind;
2220+
}
2221+
22062222
static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
22072223
IRGenOptions &IRGenOpts, const FrontendOptions &FEOpts,
22082224
const TypeCheckerOptions &TCOpts,
@@ -2603,6 +2619,16 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
26032619
Opts.EnableExperimentalSwiftBasedClosureSpecialization =
26042620
Args.hasArg(OPT_enable_experimental_swift_based_closure_specialization);
26052621

2622+
// If these optimizations are enabled never preserve functions for the
2623+
// debugger.
2624+
Opts.ShouldFunctionsBePreservedToDebugger =
2625+
!Args.hasArg(OPT_enable_llvm_wme);
2626+
Opts.ShouldFunctionsBePreservedToDebugger &=
2627+
!Args.hasArg(OPT_enable_llvm_vfe);
2628+
if (auto LTOKind = ParseLLVMLTOKind(Args, Diags))
2629+
Opts.ShouldFunctionsBePreservedToDebugger &=
2630+
LTOKind.value() == IRGenLLVMLTOKind::None;
2631+
26062632
return false;
26072633
}
26082634

@@ -2949,18 +2975,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
29492975
}
29502976
}
29512977

2952-
if (const Arg *A = Args.getLastArg(options::OPT_lto)) {
2953-
auto LLVMLTOKind =
2954-
llvm::StringSwitch<std::optional<IRGenLLVMLTOKind>>(A->getValue())
2955-
.Case("llvm-thin", IRGenLLVMLTOKind::Thin)
2956-
.Case("llvm-full", IRGenLLVMLTOKind::Full)
2957-
.Default(std::nullopt);
2958-
if (LLVMLTOKind)
2959-
Opts.LLVMLTOKind = LLVMLTOKind.value();
2960-
else
2961-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
2962-
A->getAsString(Args), A->getValue());
2963-
}
2978+
if (auto LTOKind = ParseLLVMLTOKind(Args, Diags))
2979+
Opts.LLVMLTOKind = LTOKind.value();
29642980

29652981
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_coverage_EQ)) {
29662982
Opts.SanitizeCoverage =

lib/SIL/IR/SILFunction.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "swift/AST/Availability.h"
1717
#include "swift/AST/Expr.h"
1818
#include "swift/AST/GenericEnvironment.h"
19-
#include "swift/AST/IRGenOptions.h"
2019
#include "swift/AST/LocalArchetypeRequirementCollector.h"
2120
#include "swift/AST/Module.h"
2221
#include "swift/AST/Stmt.h"
@@ -999,16 +998,11 @@ bool SILFunction::shouldBePreservedForDebugger() const {
999998
if (getEffectiveOptimizationMode() != OptimizationMode::NoOptimization)
1000999
return false;
10011000

1002-
if (getModule().getASTContext().LangOpts.hasFeature(Feature::Embedded))
1001+
if (!getModule().getOptions().ShouldFunctionsBePreservedToDebugger)
10031002
return false;
10041003

1005-
if (const IRGenOptions *options = getModule().getIRGenOptionsOrNull()) {
1006-
if (options->WitnessMethodElimination ||
1007-
options->VirtualFunctionElimination ||
1008-
options->LLVMLTOKind != IRGenLLVMLTOKind::None) {
1009-
return false;
1010-
}
1011-
}
1004+
if (getModule().getASTContext().LangOpts.hasFeature(Feature::Embedded))
1005+
return false;
10121006

10131007
if (isAvailableExternally())
10141008
return false;

0 commit comments

Comments
 (0)