Skip to content

Commit 056fbc4

Browse files
committed
[CoroutineAccessors] Control ABI via flag.
1 parent b3f592a commit 056fbc4

19 files changed

+63
-8
lines changed

include/swift/AST/SILOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ class SILOptions {
338338
// Whether to allow merging traps and cond_fails.
339339
bool MergeableTraps = false;
340340

341+
/// Whether the @yield_once_2 convention is used by accessors added with the
342+
/// CoroutineAccessors feature (i.e. read2/modify2).
343+
bool CoroutineAccessorsUseYieldOnce2 = false;
344+
341345
SILOptions() {}
342346

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

include/swift/Option/FrontendOptions.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,12 @@ def enable_arm64_corocc : Flag<["-"], "enable-arm64-corocc">,
11751175
def disable_arm64_corocc : Flag<["-"], "disable-arm64-corocc">,
11761176
HelpText<"Don't use swiftcorocc for yield_once_2 routines on arm64 variants.">;
11771177

1178+
def enable_callee_allocated_coro_abi : Flag<["-"], "enable-callee-allocated-coro-abi">,
1179+
HelpText<"Override per-platform settings and use yield_once_2.">;
1180+
1181+
def disable_callee_allocated_coro_abi : Flag<["-"], "disable-callee-allocated-coro-abi">,
1182+
HelpText<"Override per-platform settings and don't use yield_once_2.">;
1183+
11781184
def enable_cond_fail_message_annotation : Flag<["-"], "enable-cond-fail-message-annotation">,
11791185
HelpText<"Enable cond_fail message annotation. Will serialize a .o.yaml file per .o file.">;
11801186

lib/DriverTool/sil_opt_main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,16 @@ struct SILOptOptions {
597597
"enable-address-dependencies",
598598
llvm::cl::desc("Enable enforcement of lifetime dependencies on addressable values."));
599599

600+
llvm::cl::opt<bool> EnableCalleeAllocatedCoroAbi = llvm::cl::opt<bool>(
601+
"enable-callee-allocated-coro-abi",
602+
llvm::cl::desc("Override per-platform settings and use yield_once_2."),
603+
llvm::cl::init(false));
604+
llvm::cl::opt<bool> DisableCalleeAllocatedCoroAbi = llvm::cl::opt<bool>(
605+
"disable-callee-allocated-coro-abi",
606+
llvm::cl::desc(
607+
"Override per-platform settings and don't use yield_once_2."),
608+
llvm::cl::init(false));
609+
600610
llvm::cl::opt<bool> MergeableTraps = llvm::cl::opt<bool>(
601611
"mergeable-traps",
602612
llvm::cl::desc("Enable cond_fail merging."));
@@ -918,6 +928,10 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
918928
options.EnablePackMetadataStackPromotion;
919929

920930
SILOpts.EnableAddressDependencies = options.EnableAddressDependencies;
931+
if (options.EnableCalleeAllocatedCoroAbi)
932+
SILOpts.CoroutineAccessorsUseYieldOnce2 = true;
933+
if (options.DisableCalleeAllocatedCoroAbi)
934+
SILOpts.CoroutineAccessorsUseYieldOnce2 = false;
921935
SILOpts.MergeableTraps = options.MergeableTraps;
922936

923937
if (options.OptModeFlag == OptimizationMode::NotSet) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,6 +3130,16 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
31303130
Opts.EnableAddressDependencies = Args.hasFlag(
31313131
OPT_enable_address_dependencies, OPT_disable_address_dependencies,
31323132
Opts.EnableAddressDependencies);
3133+
3134+
if (LangOpts.Target.isOSDarwin() || LangOpts.Target.isOSLinux()) {
3135+
// On Darwin and Linux, use yield_once_2 by default.
3136+
Opts.CoroutineAccessorsUseYieldOnce2 = true;
3137+
}
3138+
Opts.CoroutineAccessorsUseYieldOnce2 =
3139+
Args.hasFlag(OPT_enable_callee_allocated_coro_abi,
3140+
OPT_disable_callee_allocated_coro_abi,
3141+
Opts.CoroutineAccessorsUseYieldOnce2);
3142+
31333143
Opts.MergeableTraps = Args.hasArg(OPT_mergeable_traps);
31343144

31353145
return false;

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1855,5 +1855,8 @@ bool SILDeclRef::isCalleeAllocatedCoroutine() const {
18551855
if (!accessor)
18561856
return false;
18571857

1858-
return requiresFeatureCoroutineAccessors(accessor->getAccessorKind());
1858+
if (!requiresFeatureCoroutineAccessors(accessor->getAccessorKind()))
1859+
return false;
1860+
1861+
return getASTContext().SILOpts.CoroutineAccessorsUseYieldOnce2;
18591862
}

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2481,8 +2481,10 @@ static CanSILFunctionType getSILFunctionType(
24812481

24822482
if (auto accessor = getAsCoroutineAccessor(constant)) {
24832483
auto origAccessor = cast<AccessorDecl>(origConstant->getDecl());
2484+
auto &ctx = origAccessor->getASTContext();
24842485
coroutineKind =
2485-
requiresFeatureCoroutineAccessors(accessor->getAccessorKind())
2486+
(requiresFeatureCoroutineAccessors(accessor->getAccessorKind()) &&
2487+
ctx.SILOpts.CoroutineAccessorsUseYieldOnce2)
24862488
? SILCoroutineKind::YieldOnce2
24872489
: SILCoroutineKind::YieldOnce;
24882490

test/IRGen/coroutine_accessors.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-emit-irgen \
22
// RUN: %s \
3+
// RUN: -enable-callee-allocated-coro-abi \
34
// RUN: -enable-experimental-feature CoroutineAccessors \
45
// RUN: | %IRGenFileCheck %s
56

test/IRGen/coroutine_accessors_backdeploy_async_56.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-emit-irgen \
22
// RUN: %s \
3+
// RUN: -enable-callee-allocated-coro-abi \
34
// RUN: -module-name backdep \
45
// RUN: -target %target-swift-5.6-abi-triple \
56
// RUN: -Onone \

test/IRGen/coroutine_accessors_backdeploy_async_57.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-emit-irgen \
22
// RUN: %s \
3+
// RUN: -enable-callee-allocated-coro-abi \
34
// RUN: -module-name backdep \
45
// RUN: -target %target-swift-5.7-abi-triple \
56
// RUN: -Onone \

test/IRGen/coroutine_accessors_popless.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-swift-emit-irgen \
22
// RUN: %s \
33
// RUN: -Onone \
4+
// RUN: -enable-callee-allocated-coro-abi \
45
// RUN: -enable-experimental-feature CoroutineAccessors \
56
// RUN: -enable-arm64-corocc \
67
// RUN: -enable-x86_64-corocc \

test/IRGen/default_override.sil

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-frontend \
22
// RUN: %s \
3+
// RUN: -enable-callee-allocated-coro-abi \
34
// RUN: -module-name Library \
45
// RUN: -emit-ir \
56
// RUN: -enable-experimental-feature CoroutineAccessors \

test/IRGen/run-coroutine_accessors.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@
9494
// UNSUPPORTED: wasm
9595
// UNSUPPORTED: OS=wasi
9696
// UNSUPPORTED: CPU=wasm32
97-
// TODO: CoroutineAccessors: Enable on Windows.
98-
// UNSUPPORTED: OS=windows-msvc
9997

10098
// REQUIRES: swift_feature_CoroutineAccessors
10199

test/Interpreter/coroutine_accessors_default_implementations.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// RUN: %target-swift-frontend \
66
// RUN: %t/Library.swift \
77
// RUN: %t/LibImpl.underscored.swift \
8+
// RUN: -enable-callee-allocated-coro-abi \
89
// RUN: -emit-module \
910
// RUN: -module-name Library \
1011
// RUN: -parse-as-library \
@@ -13,6 +14,7 @@
1314

1415
// RUN: %target-swift-frontend \
1516
// RUN: %t/Executable.swift \
17+
// RUN: -enable-callee-allocated-coro-abi \
1618
// RUN: -c \
1719
// RUN: -parse-as-library \
1820
// RUN: -module-name Executable \
@@ -22,6 +24,7 @@
2224
// RUN: %target-build-swift-dylib(%t/%target-library-name(Library)) \
2325
// RUN: %t/Library.swift \
2426
// RUN: %t/LibImpl.nonunderscored.swift \
27+
// RUN: -Xfrontend -enable-callee-allocated-coro-abi \
2528
// RUN: -emit-module \
2629
// RUN: -enable-library-evolution \
2730
// RUN: -enable-experimental-feature CoroutineAccessors \

test/SILGen/coroutine_accessors.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
1+
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
22
// RUN: %s \
3+
// RUN: -enable-callee-allocated-coro-abi \
34
// RUN: -enable-library-evolution \
45
// RUN: -enable-experimental-feature CoroutineAccessors \
56
// RUN: | %FileCheck %s --check-prefixes=CHECK,CHECK-NOUNWIND
67

7-
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
8+
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
89
// RUN: %s \
10+
// RUN: -enable-callee-allocated-coro-abi \
911
// RUN: -enable-library-evolution \
1012
// RUN: -enable-experimental-feature CoroutineAccessors \
1113
// RUN: -enable-experimental-feature CoroutineAccessorsUnwindOnCallerError \

test/SILGen/coroutine_accessors_skip.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// RUN: %target-swift-emit-silgen \
22
// RUN: %s \
3+
// RUN: -enable-callee-allocated-coro-abi \
34
// RUN: -experimental-skip-non-inlinable-function-bodies \
45
// RUN: -enable-library-evolution \
56
// RUN: -enable-experimental-feature CoroutineAccessors \
67
// RUN: | %FileCheck %s --check-prefixes=CHECK,CHECK-NOUNWIND
78

89
// RUN: %target-swift-emit-silgen \
910
// RUN: %s \
11+
// RUN: -enable-callee-allocated-coro-abi \
1012
// RUN: -experimental-skip-non-inlinable-function-bodies \
1113
// RUN: -enable-library-evolution \
1214
// RUN: -enable-experimental-feature CoroutineAccessors \

test/SILGen/default_override.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// RUN: %target-swift-emit-silgen \
22
// RUN: %s \
3+
// RUN: -enable-callee-allocated-coro-abi \
34
// RUN: -enable-library-evolution \
45
// RUN: -enable-experimental-feature BuiltinModule \
56
// RUN: -enable-experimental-feature CoroutineAccessors \
67
// RUN: | %FileCheck %s
78

89
// RUN: %target-swift-emit-silgen \
910
// RUN: %s \
11+
// RUN: -enable-callee-allocated-coro-abi \
1012
// RUN: -enable-experimental-feature BuiltinModule \
1113
// RUN: -enable-experimental-feature CoroutineAccessors \
1214
// RUN: | %FileCheck %s --check-prefix=CHECK-FRAGILE

test/SILGen/read_requirements.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
1+
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
22
// RUN: %s \
3+
// RUN: -enable-callee-allocated-coro-abi \
34
// RUN: -enable-library-evolution \
45
// RUN: -enable-experimental-feature CoroutineAccessors \
56
// RUN: | %FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL,CHECK-%target-abi-stability
67

7-
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
8+
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types \
89
// RUN: %s \
10+
// RUN: -enable-callee-allocated-coro-abi \
911
// RUN: -enable-library-evolution \
1012
// RUN: -enable-experimental-feature CoroutineAccessors \
1113
// RUN: -enable-experimental-feature CoroutineAccessorsUnwindOnCallerError \

test/SILOptimizer/devirtualize_coroutine_accessors.sil

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-sil-opt \
22
// RUN: -devirtualizer \
3+
// RUN: -enable-callee-allocated-coro-abi\
34
// RUN: %s \
45
// RUN: -enable-sil-verify-all \
56
// RUN: -enable-experimental-feature CoroutineAccessors \

test/TBD/coroutine_accessors.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-build-swift-dylib(%t/%target-library-name(thing)) \
22
// RUN: %s \
3+
// RUN: -Xfrontend -enable-callee-allocated-coro-abi \
34
// RUN: -emit-tbd \
45
// RUN: -Xfrontend -validate-tbd-against-ir=all \
56
// RUN: -enable-library-evolution \

0 commit comments

Comments
 (0)