[CoroutineAccessors] Control ABI via flag.

This commit is contained in:
Nate Chandler
2025-04-09 08:52:16 -07:00
parent b3f592aede
commit 056fbc44c9
19 changed files with 63 additions and 8 deletions

View File

@@ -338,6 +338,10 @@ public:
// Whether to allow merging traps and cond_fails.
bool MergeableTraps = false;
/// Whether the @yield_once_2 convention is used by accessors added with the
/// CoroutineAccessors feature (i.e. read2/modify2).
bool CoroutineAccessorsUseYieldOnce2 = false;
SILOptions() {}
/// Return a hash code of any components from these options that should

View File

@@ -1175,6 +1175,12 @@ def enable_arm64_corocc : Flag<["-"], "enable-arm64-corocc">,
def disable_arm64_corocc : Flag<["-"], "disable-arm64-corocc">,
HelpText<"Don't use swiftcorocc for yield_once_2 routines on arm64 variants.">;
def enable_callee_allocated_coro_abi : Flag<["-"], "enable-callee-allocated-coro-abi">,
HelpText<"Override per-platform settings and use yield_once_2.">;
def disable_callee_allocated_coro_abi : Flag<["-"], "disable-callee-allocated-coro-abi">,
HelpText<"Override per-platform settings and don't use yield_once_2.">;
def enable_cond_fail_message_annotation : Flag<["-"], "enable-cond-fail-message-annotation">,
HelpText<"Enable cond_fail message annotation. Will serialize a .o.yaml file per .o file.">;

View File

@@ -597,6 +597,16 @@ struct SILOptOptions {
"enable-address-dependencies",
llvm::cl::desc("Enable enforcement of lifetime dependencies on addressable values."));
llvm::cl::opt<bool> EnableCalleeAllocatedCoroAbi = llvm::cl::opt<bool>(
"enable-callee-allocated-coro-abi",
llvm::cl::desc("Override per-platform settings and use yield_once_2."),
llvm::cl::init(false));
llvm::cl::opt<bool> DisableCalleeAllocatedCoroAbi = llvm::cl::opt<bool>(
"disable-callee-allocated-coro-abi",
llvm::cl::desc(
"Override per-platform settings and don't use yield_once_2."),
llvm::cl::init(false));
llvm::cl::opt<bool> MergeableTraps = llvm::cl::opt<bool>(
"mergeable-traps",
llvm::cl::desc("Enable cond_fail merging."));
@@ -918,6 +928,10 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
options.EnablePackMetadataStackPromotion;
SILOpts.EnableAddressDependencies = options.EnableAddressDependencies;
if (options.EnableCalleeAllocatedCoroAbi)
SILOpts.CoroutineAccessorsUseYieldOnce2 = true;
if (options.DisableCalleeAllocatedCoroAbi)
SILOpts.CoroutineAccessorsUseYieldOnce2 = false;
SILOpts.MergeableTraps = options.MergeableTraps;
if (options.OptModeFlag == OptimizationMode::NotSet) {

View File

@@ -3130,6 +3130,16 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.EnableAddressDependencies = Args.hasFlag(
OPT_enable_address_dependencies, OPT_disable_address_dependencies,
Opts.EnableAddressDependencies);
if (LangOpts.Target.isOSDarwin() || LangOpts.Target.isOSLinux()) {
// On Darwin and Linux, use yield_once_2 by default.
Opts.CoroutineAccessorsUseYieldOnce2 = true;
}
Opts.CoroutineAccessorsUseYieldOnce2 =
Args.hasFlag(OPT_enable_callee_allocated_coro_abi,
OPT_disable_callee_allocated_coro_abi,
Opts.CoroutineAccessorsUseYieldOnce2);
Opts.MergeableTraps = Args.hasArg(OPT_mergeable_traps);
return false;

View File

@@ -1855,5 +1855,8 @@ bool SILDeclRef::isCalleeAllocatedCoroutine() const {
if (!accessor)
return false;
return requiresFeatureCoroutineAccessors(accessor->getAccessorKind());
if (!requiresFeatureCoroutineAccessors(accessor->getAccessorKind()))
return false;
return getASTContext().SILOpts.CoroutineAccessorsUseYieldOnce2;
}

View File

@@ -2481,8 +2481,10 @@ static CanSILFunctionType getSILFunctionType(
if (auto accessor = getAsCoroutineAccessor(constant)) {
auto origAccessor = cast<AccessorDecl>(origConstant->getDecl());
auto &ctx = origAccessor->getASTContext();
coroutineKind =
requiresFeatureCoroutineAccessors(accessor->getAccessorKind())
(requiresFeatureCoroutineAccessors(accessor->getAccessorKind()) &&
ctx.SILOpts.CoroutineAccessorsUseYieldOnce2)
? SILCoroutineKind::YieldOnce2
: SILCoroutineKind::YieldOnce;

View File

@@ -1,5 +1,6 @@
// RUN: %target-swift-emit-irgen \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: | %IRGenFileCheck %s

View File

@@ -1,5 +1,6 @@
// RUN: %target-swift-emit-irgen \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -module-name backdep \
// RUN: -target %target-swift-5.6-abi-triple \
// RUN: -Onone \

View File

@@ -1,5 +1,6 @@
// RUN: %target-swift-emit-irgen \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -module-name backdep \
// RUN: -target %target-swift-5.7-abi-triple \
// RUN: -Onone \

View File

@@ -1,6 +1,7 @@
// RUN: %target-swift-emit-irgen \
// RUN: %s \
// RUN: -Onone \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: -enable-arm64-corocc \
// RUN: -enable-x86_64-corocc \

View File

@@ -1,5 +1,6 @@
// RUN: %target-swift-frontend \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -module-name Library \
// RUN: -emit-ir \
// RUN: -enable-experimental-feature CoroutineAccessors \

View File

@@ -94,8 +94,6 @@
// UNSUPPORTED: wasm
// UNSUPPORTED: OS=wasi
// UNSUPPORTED: CPU=wasm32
// TODO: CoroutineAccessors: Enable on Windows.
// UNSUPPORTED: OS=windows-msvc
// REQUIRES: swift_feature_CoroutineAccessors

View File

@@ -5,6 +5,7 @@
// RUN: %target-swift-frontend \
// RUN: %t/Library.swift \
// RUN: %t/LibImpl.underscored.swift \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -emit-module \
// RUN: -module-name Library \
// RUN: -parse-as-library \
@@ -13,6 +14,7 @@
// RUN: %target-swift-frontend \
// RUN: %t/Executable.swift \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -c \
// RUN: -parse-as-library \
// RUN: -module-name Executable \
@@ -22,6 +24,7 @@
// RUN: %target-build-swift-dylib(%t/%target-library-name(Library)) \
// RUN: %t/Library.swift \
// RUN: %t/LibImpl.nonunderscored.swift \
// RUN: -Xfrontend -enable-callee-allocated-coro-abi \
// RUN: -emit-module \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature CoroutineAccessors \

View File

@@ -1,11 +1,13 @@
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: | %FileCheck %s --check-prefixes=CHECK,CHECK-NOUNWIND
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: -enable-experimental-feature CoroutineAccessorsUnwindOnCallerError \

View File

@@ -1,5 +1,6 @@
// RUN: %target-swift-emit-silgen \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -experimental-skip-non-inlinable-function-bodies \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature CoroutineAccessors \
@@ -7,6 +8,7 @@
// RUN: %target-swift-emit-silgen \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -experimental-skip-non-inlinable-function-bodies \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature CoroutineAccessors \

View File

@@ -1,5 +1,6 @@
// RUN: %target-swift-emit-silgen \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature BuiltinModule \
// RUN: -enable-experimental-feature CoroutineAccessors \
@@ -7,6 +8,7 @@
// RUN: %target-swift-emit-silgen \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -enable-experimental-feature BuiltinModule \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: | %FileCheck %s --check-prefix=CHECK-FRAGILE

View File

@@ -1,11 +1,13 @@
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: | %FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL,CHECK-%target-abi-stability
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
// RUN: %s \
// RUN: -enable-callee-allocated-coro-abi \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: -enable-experimental-feature CoroutineAccessorsUnwindOnCallerError \

View File

@@ -1,5 +1,6 @@
// RUN: %target-sil-opt \
// RUN: -devirtualizer \
// RUN: -enable-callee-allocated-coro-abi\
// RUN: %s \
// RUN: -enable-sil-verify-all \
// RUN: -enable-experimental-feature CoroutineAccessors \

View File

@@ -1,5 +1,6 @@
// RUN: %target-build-swift-dylib(%t/%target-library-name(thing)) \
// RUN: %s \
// RUN: -Xfrontend -enable-callee-allocated-coro-abi \
// RUN: -emit-tbd \
// RUN: -Xfrontend -validate-tbd-against-ir=all \
// RUN: -enable-library-evolution \