Skip to content

Commit c5ea0c3

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. (cherry picked from commit 4aec4e7)
1 parent 26651f9 commit c5ea0c3

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
@@ -298,6 +298,10 @@ class SILOptions {
298298
/// The format used for serializing remarks (default: YAML)
299299
llvm::remarks::Format OptRecordFormat = llvm::remarks::Format::YAML;
300300

301+
/// Are there any options that indicate that functions should not be preserved
302+
/// for the debugger?
303+
bool ShouldFunctionsBePreservedToDebugger = true;
304+
301305
SILOptions() {}
302306

303307
/// 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
@@ -2242,6 +2242,22 @@ void parseExclusivityEnforcementOptions(const llvm::opt::Arg *A,
22422242
}
22432243
}
22442244

2245+
static std::optional<IRGenLLVMLTOKind>
2246+
ParseLLVMLTOKind(const ArgList &Args, DiagnosticEngine &Diags) {
2247+
std::optional<IRGenLLVMLTOKind> LLVMLTOKind;
2248+
if (const Arg *A = Args.getLastArg(options::OPT_lto)) {
2249+
LLVMLTOKind =
2250+
llvm::StringSwitch<std::optional<IRGenLLVMLTOKind>>(A->getValue())
2251+
.Case("llvm-thin", IRGenLLVMLTOKind::Thin)
2252+
.Case("llvm-full", IRGenLLVMLTOKind::Full)
2253+
.Default(std::nullopt);
2254+
if (!LLVMLTOKind)
2255+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
2256+
A->getAsString(Args), A->getValue());
2257+
}
2258+
return LLVMLTOKind;
2259+
}
2260+
22452261
static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
22462262
IRGenOptions &IRGenOpts, const FrontendOptions &FEOpts,
22472263
const TypeCheckerOptions &TCOpts,
@@ -2629,6 +2645,16 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
26292645

26302646
Opts.NoAllocations = Args.hasArg(OPT_no_allocations);
26312647

2648+
// If these optimizations are enabled never preserve functions for the
2649+
// debugger.
2650+
Opts.ShouldFunctionsBePreservedToDebugger =
2651+
!Args.hasArg(OPT_enable_llvm_wme);
2652+
Opts.ShouldFunctionsBePreservedToDebugger &=
2653+
!Args.hasArg(OPT_enable_llvm_vfe);
2654+
if (auto LTOKind = ParseLLVMLTOKind(Args, Diags))
2655+
Opts.ShouldFunctionsBePreservedToDebugger &=
2656+
LTOKind.value() == IRGenLLVMLTOKind::None;
2657+
26322658
return false;
26332659
}
26342660

@@ -2975,18 +3001,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
29753001
}
29763002
}
29773003

2978-
if (const Arg *A = Args.getLastArg(options::OPT_lto)) {
2979-
auto LLVMLTOKind =
2980-
llvm::StringSwitch<std::optional<IRGenLLVMLTOKind>>(A->getValue())
2981-
.Case("llvm-thin", IRGenLLVMLTOKind::Thin)
2982-
.Case("llvm-full", IRGenLLVMLTOKind::Full)
2983-
.Default(std::nullopt);
2984-
if (LLVMLTOKind)
2985-
Opts.LLVMLTOKind = LLVMLTOKind.value();
2986-
else
2987-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
2988-
A->getAsString(Args), A->getValue());
2989-
}
3004+
if (auto LTOKind = ParseLLVMLTOKind(Args, Diags))
3005+
Opts.LLVMLTOKind = LTOKind.value();
29903006

29913007
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_coverage_EQ)) {
29923008
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/Module.h"
2120
#include "swift/AST/Stmt.h"
2221
#include "swift/Basic/OptimizationMode.h"
@@ -943,16 +942,11 @@ bool SILFunction::shouldBePreservedForDebugger() const {
943942
if (getEffectiveOptimizationMode() != OptimizationMode::NoOptimization)
944943
return false;
945944

946-
if (getModule().getASTContext().LangOpts.hasFeature(Feature::Embedded))
945+
if (!getModule().getOptions().ShouldFunctionsBePreservedToDebugger)
947946
return false;
948947

949-
if (const IRGenOptions *options = getModule().getIRGenOptionsOrNull()) {
950-
if (options->WitnessMethodElimination ||
951-
options->VirtualFunctionElimination ||
952-
options->LLVMLTOKind != IRGenLLVMLTOKind::None) {
953-
return false;
954-
}
955-
}
948+
if (getModule().getASTContext().LangOpts.hasFeature(Feature::Embedded))
949+
return false;
956950

957951
if (isAvailableExternally())
958952
return false;

0 commit comments

Comments
 (0)