Skip to content

Commit 84eac93

Browse files
committed
[IRGen] Use the result polymorphic coro.suspend.async intrinsic
This needs llvm-project PR 2481.
1 parent e3c1c42 commit 84eac93

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,19 @@ llvm::Value *IRGenFunction::getAsyncContext() {
362362
}
363363

364364
llvm::CallInst *IRGenFunction::emitSuspendAsyncCall(ArrayRef<llvm::Value *> args) {
365-
auto *id =
366-
Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_suspend_async, args);
365+
auto resultTy = llvm::StructType::get(
366+
IGM.getLLVMContext(), {IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy});
367367

368+
auto *id = Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_suspend_async,
369+
{resultTy}, args);
368370
// Update the current values of task, executor and context.
369371

370372
auto *rawTask = Builder.CreateExtractValue(id,
371373
(unsigned)AsyncFunctionArgumentIndex::Task);
372374
auto *task = Builder.CreateBitCast(rawTask, IGM.SwiftTaskPtrTy);
373375
Builder.CreateStore(task, asyncTaskLocation);
374376

377+
// Update the current values of task, executor and context.
375378
auto *rawExecutor = Builder.CreateExtractValue(id,
376379
(unsigned)AsyncFunctionArgumentIndex::Executor);
377380
auto *executor = Builder.CreateBitCast(rawExecutor, IGM.SwiftExecutorPtrTy);

test/IRGen/async/get_async_continuation.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bb0:
8888
// CHECK: unreachable
8989

9090
// CHECK: await.async.maybe.resume:
91-
// CHECK: call { i8*, i8*, i8* } (i8*, i8*, ...) @llvm.coro.suspend.async({{.*}} @__swift_async_resume_project_context
91+
// CHECK: call { i8*, i8*, i8* } (i8*, i8*, ...) @llvm.coro.suspend.async{{.*}}({{.*}} @__swift_async_resume_project_context
9292
// Abort if we are the first to arrive at the continuation point we must wait
9393
// on the await to arrive.
9494
// CHECK: [[first_at_sync_pt:%.*]] = cmpxchg {{(i64|i32)}}* [[synchronization_addr_before_await]], {{(i64|i32)}} 0, {{(i64|i32)}} 1 release acquire

test/IRGen/async/hop_to_executor.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ final actor MyActor {
2626
// CHECK-arm64e: [[SIGNED_INT:%[0-9]+]] = call i64 @llvm.ptrauth.sign.i64(i64 [[RESUME_INT]], i32 0, i64 [[PTRAUTH_BLEND]])
2727
// CHECK-arm64e: [[SIGNED_RESUME:%[0-9]+]] = inttoptr i64 [[SIGNED_INT]] to i8*
2828
// CHECK: [[CAST_ACTOR:%[0-9]+]] = bitcast %T4test7MyActorC* [[ACTOR]] to %swift.executor*
29-
// CHECK-x86_64: call {{.*}} @llvm.coro.suspend.async(i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.task*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.task* [[TASK]], %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}})
30-
// CHECK-arm64e: call {{.*}} @llvm.coro.suspend.async(i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.task*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[SIGNED_RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.task* [[TASK]], %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}})
29+
// CHECK-x86_64: call {{.*}} @llvm.coro.suspend.async{{.*}}(i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.task*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.task* [[TASK]], %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}})
30+
// CHECK-arm64e: call {{.*}} @llvm.coro.suspend.async{{.*}}(i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.task*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[SIGNED_RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.task* [[TASK]], %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}})
3131
sil @test_simple : $@convention(method) @async (@guaranteed MyActor) -> () {
3232
bb0(%0 : $MyActor):
3333
hop_to_executor %0 : $MyActor

0 commit comments

Comments
 (0)