Skip to content

Commit 16755e9

Browse files
authored
Merge pull request swiftlang#73727 from augusto2112/remove-dep-irgen
Remove dependency of SILFunction in IRGenOptions
2 parents dd39730 + 4aec4e7 commit 16755e9

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
@@ -2278,6 +2278,22 @@ void parseExclusivityEnforcementOptions(const llvm::opt::Arg *A,
22782278
}
22792279
}
22802280

2281+
static std::optional<IRGenLLVMLTOKind>
2282+
ParseLLVMLTOKind(const ArgList &Args, DiagnosticEngine &Diags) {
2283+
std::optional<IRGenLLVMLTOKind> LLVMLTOKind;
2284+
if (const Arg *A = Args.getLastArg(options::OPT_lto)) {
2285+
LLVMLTOKind =
2286+
llvm::StringSwitch<std::optional<IRGenLLVMLTOKind>>(A->getValue())
2287+
.Case("llvm-thin", IRGenLLVMLTOKind::Thin)
2288+
.Case("llvm-full", IRGenLLVMLTOKind::Full)
2289+
.Default(std::nullopt);
2290+
if (!LLVMLTOKind)
2291+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
2292+
A->getAsString(Args), A->getValue());
2293+
}
2294+
return LLVMLTOKind;
2295+
}
2296+
22812297
static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
22822298
IRGenOptions &IRGenOpts, const FrontendOptions &FEOpts,
22832299
const TypeCheckerOptions &TCOpts,
@@ -2678,6 +2694,16 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
26782694
Opts.EnableExperimentalSwiftBasedClosureSpecialization =
26792695
Args.hasArg(OPT_enable_experimental_swift_based_closure_specialization);
26802696

2697+
// If these optimizations are enabled never preserve functions for the
2698+
// debugger.
2699+
Opts.ShouldFunctionsBePreservedToDebugger =
2700+
!Args.hasArg(OPT_enable_llvm_wme);
2701+
Opts.ShouldFunctionsBePreservedToDebugger &=
2702+
!Args.hasArg(OPT_enable_llvm_vfe);
2703+
if (auto LTOKind = ParseLLVMLTOKind(Args, Diags))
2704+
Opts.ShouldFunctionsBePreservedToDebugger &=
2705+
LTOKind.value() == IRGenLLVMLTOKind::None;
2706+
26812707
return false;
26822708
}
26832709

@@ -3024,18 +3050,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
30243050
}
30253051
}
30263052

3027-
if (const Arg *A = Args.getLastArg(options::OPT_lto)) {
3028-
auto LLVMLTOKind =
3029-
llvm::StringSwitch<std::optional<IRGenLLVMLTOKind>>(A->getValue())
3030-
.Case("llvm-thin", IRGenLLVMLTOKind::Thin)
3031-
.Case("llvm-full", IRGenLLVMLTOKind::Full)
3032-
.Default(std::nullopt);
3033-
if (LLVMLTOKind)
3034-
Opts.LLVMLTOKind = LLVMLTOKind.value();
3035-
else
3036-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
3037-
A->getAsString(Args), A->getValue());
3038-
}
3053+
if (auto LTOKind = ParseLLVMLTOKind(Args, Diags))
3054+
Opts.LLVMLTOKind = LTOKind.value();
30393055

30403056
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_coverage_EQ)) {
30413057
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"
@@ -988,16 +987,11 @@ bool SILFunction::shouldBePreservedForDebugger() const {
988987
if (getEffectiveOptimizationMode() != OptimizationMode::NoOptimization)
989988
return false;
990989

991-
if (getModule().getASTContext().LangOpts.hasFeature(Feature::Embedded))
990+
if (!getModule().getOptions().ShouldFunctionsBePreservedToDebugger)
992991
return false;
993992

994-
if (const IRGenOptions *options = getModule().getIRGenOptionsOrNull()) {
995-
if (options->WitnessMethodElimination ||
996-
options->VirtualFunctionElimination ||
997-
options->LLVMLTOKind != IRGenLLVMLTOKind::None) {
998-
return false;
999-
}
1000-
}
993+
if (getModule().getASTContext().LangOpts.hasFeature(Feature::Embedded))
994+
return false;
1001995

1002996
if (isAvailableExternally())
1003997
return false;

0 commit comments

Comments
 (0)