Skip to content

Commit 3f60d3e

Browse files
committed
[CoroutineAccessors] Adopt ret.popless intrinsic.
And annotate it musttail.
1 parent 375bc35 commit 3f60d3e

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5149,9 +5149,10 @@ static llvm::Constant *getCoroAllocWrapperFn(IRGenModule &IGM) {
51495149
auto *alloca =
51505150
IGF.Builder.IRBuilderBase::CreateAlloca(IGF.IGM.Int8Ty, size);
51515151
alloca->setAlignment(llvm::Align(MaximumAlignment));
5152-
auto *ret = IGF.Builder.CreateIntrinsic(
5153-
alloca->getType(), llvm::Intrinsic::coro_return, {alloca});
5154-
IGF.Builder.CreateRet(ret);
5152+
auto *retPopless = IGF.Builder.CreateIntrinsic(
5153+
IGF.IGM.VoidTy, llvm::Intrinsic::ret_popless, {});
5154+
retPopless->setTailCallKind(llvm::CallInst::TailCallKind::TCK_MustTail);
5155+
IGF.Builder.CreateRet(alloca);
51555156
IGF.Builder.emitBlock(normalReturn);
51565157
auto *call = IGF.Builder.CreateCall(
51575158
IGF.IGM.getCoroAllocFunctionPointer(), {allocator, size});
Lines changed: 40 additions & 0 deletions
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)