Skip to content

Commit 0d66f84

Browse files
Merge pull request swiftlang#79811 from nate-chandler/general-coro/20250305/1
[CoroutineAccessors] Adopt ret.popless intrinsic.
2 parents 537be30 + 3277971 commit 0d66f84

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

Diff for: lib/IRGen/GenCall.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -5137,9 +5137,10 @@ static llvm::Constant *getCoroAllocWrapperFn(IRGenModule &IGM) {
51375137
auto *alloca =
51385138
IGF.Builder.IRBuilderBase::CreateAlloca(IGF.IGM.Int8Ty, size);
51395139
alloca->setAlignment(llvm::Align(MaximumAlignment));
5140-
auto *ret = IGF.Builder.CreateIntrinsic(
5141-
alloca->getType(), llvm::Intrinsic::coro_return, {alloca});
5142-
IGF.Builder.CreateRet(ret);
5140+
auto *retPopless = IGF.Builder.CreateIntrinsic(
5141+
IGF.IGM.VoidTy, llvm::Intrinsic::ret_popless, {});
5142+
retPopless->setTailCallKind(llvm::CallInst::TailCallKind::TCK_MustTail);
5143+
IGF.Builder.CreateRet(alloca);
51435144
IGF.Builder.emitBlock(normalReturn);
51445145
auto *call = IGF.Builder.CreateCall(
51455146
IGF.IGM.getCoroAllocFunctionPointer(), {allocator, size});

Diff for: test/IRGen/coroutine_accessors_popless.swift

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %target-swift-emit-irgen \
2+
// RUN: %s \
3+
// RUN: -enable-experimental-feature CoroutineAccessors \
4+
// RUN: -enable-arm64-corocc \
5+
// RUN: -enable-x86_64-corocc \
6+
// RUN: | %IRGenFileCheck %s
7+
8+
// REQUIRES: CPU=arm64 || CPU=arm64e || CPU=x86_64
9+
// REQUIRES: swift_feature_CoroutineAccessors
10+
11+
// CHECK-LABEL: @__swift_coro_alloc_(
12+
// CHECK-SAME: ptr [[ALLOCATOR:%[^,]+]]
13+
// CHECK-SAME: i64 [[SIZE:%[^)]+]]
14+
// CHECK-SAME: )
15+
// CHECK-SAME: {
16+
// CHECK: entry:
17+
// CHECK: [[USE_POPLESS:%[^,]+]] = icmp eq ptr [[ALLOCATOR]], null
18+
// CHECK: br i1 [[USE_POPLESS]],
19+
// CHECK-SAME: label %coro.return.popless
20+
// CHECK-SAME: label %coro.return.normal
21+
// CHECK: coro.return.popless:
22+
// CHECK: [[STACK_ALLOCATION:%[^,]+]] = alloca i8, i64 [[SIZE]], align 16
23+
// CHECK: musttail call void @llvm.ret.popless()
24+
// CHECK: ret ptr [[STACK_ALLOCATION]]
25+
// CHECK: coro.return.normal:
26+
// CHECK: [[OTHER_ALLOCATION:%[^,]+]] = call swiftcc ptr @swift_coro_alloc(
27+
// CHECK-SAME: ptr [[ALLOCATOR]]
28+
// CHECK-SAME: i64 [[SIZE]]
29+
// CHECK-SAME: )
30+
// CHECK: ret ptr [[OTHER_ALLOCATION]]
31+
// CHECK: }
32+
33+
public var _i: Int = 0
34+
35+
public var i: Int {
36+
read {
37+
yield _i
38+
}
39+
}
40+

0 commit comments

Comments
 (0)