@@ -377,6 +377,75 @@ is_not_equal:
377
377
; CHECK: musttail call swiftcc void @asyncReturn(
378
378
; CHECK: ret void
379
379
380
+ @polymorphic_suspend_return_fp = constant <{ i32 , i32 }>
381
+ <{ i32 trunc ( ; Relative pointer to async function
382
+ i64 sub (
383
+ i64 ptrtoint (void (i8* , %async.task* , %async.actor* )* @polymorphic_suspend_return to i64 ),
384
+ i64 ptrtoint (i32* getelementptr inbounds (<{ i32 , i32 }>, <{ i32 , i32 }>* @polymorphic_suspend_return_fp , i32 0 , i32 1 ) to i64 )
385
+ )
386
+ to i32 ),
387
+ i32 64 ; Initial async context size without space for frame
388
+ }>
389
+
390
+ define swiftcc void @polymorphic_suspend_return (i8* %async.ctxt , %async.task* %task , %async.actor* %actor ) {
391
+ entry:
392
+ %tmp = alloca { i64 , i64 }, align 8
393
+ %proj.1 = getelementptr inbounds { i64 , i64 }, { i64 , i64 }* %tmp , i64 0 , i32 0
394
+ %proj.2 = getelementptr inbounds { i64 , i64 }, { i64 , i64 }* %tmp , i64 0 , i32 1
395
+
396
+ %id = call token @llvm.coro.id.async (i32 128 , i32 16 , i32 0 ,
397
+ i8* bitcast (<{i32 , i32 }>* @polymorphic_suspend_return_fp to i8* ))
398
+ %hdl = call i8* @llvm.coro.begin (token %id , i8* null )
399
+ store i64 0 , i64* %proj.1 , align 8
400
+ store i64 1 , i64* %proj.2 , align 8
401
+ call void @some_may_write (i64* %proj.1 )
402
+
403
+ ; Begin lowering: apply %my_other_async_function(%args...)
404
+
405
+ ; setup callee context
406
+ %arg0 = bitcast %async.task* %task to i8*
407
+ %arg1 = bitcast <{ i32 , i32 }>* @my_other_async_function_fp to i8*
408
+ %callee_context = call i8* @llvm.coro.async.context.alloc (i8* %arg0 , i8* %arg1 )
409
+ %callee_context.0 = bitcast i8* %callee_context to %async.ctxt*
410
+ ; store arguments ...
411
+ ; ... (omitted)
412
+
413
+ ; store the return continuation
414
+ %callee_context.return_to_caller.addr = getelementptr inbounds %async.ctxt , %async.ctxt* %callee_context.0 , i32 0 , i32 1
415
+ %return_to_caller.addr = bitcast void (i8* , %async.task* , %async.actor* )** %callee_context.return_to_caller.addr to i8**
416
+ %resume.func_ptr = call i8* @llvm.coro.async.resume ()
417
+ store i8* %resume.func_ptr , i8** %return_to_caller.addr
418
+
419
+ ; store caller context into callee context
420
+ %callee_context.caller_context.addr = getelementptr inbounds %async.ctxt , %async.ctxt* %callee_context.0 , i32 0 , i32 0
421
+ store i8* %async.ctxt , i8** %callee_context.caller_context.addr
422
+ %resume_proj_fun = bitcast i8* (i8* )* @resume_context_projection to i8*
423
+ %callee = bitcast void (i8* , %async.task* , %async.actor* )* @asyncSuspend to i8*
424
+ %res = call {i8* , i8* , i8* , i8* } (i8* , i8* , ...) @llvm.coro.suspend.async.sl_p0i8p0i8p0i8p0i8s (
425
+ i8* %resume.func_ptr ,
426
+ i8* %resume_proj_fun ,
427
+ void (i8* , i8* , %async.task* , %async.actor* )* @my_async_function.my_other_async_function_fp.apply ,
428
+ i8* %callee , i8* %callee_context , %async.task* %task , %async.actor * %actor )
429
+
430
+ call void @llvm.coro.async.context.dealloc (i8* %callee_context )
431
+ %continuation_task_arg = extractvalue {i8* , i8* , i8* , i8* } %res , 3
432
+ %task.2 = bitcast i8* %continuation_task_arg to %async.task*
433
+ %val = load i64 , i64* %proj.1
434
+ call void @some_user (i64 %val )
435
+ %val.2 = load i64 , i64* %proj.2
436
+ call void @some_user (i64 %val.2 )
437
+
438
+ tail call swiftcc void @asyncReturn (i8* %async.ctxt , %async.task* %task.2 , %async.actor* %actor )
439
+ call i1 (i8* , i1 , ...) @llvm.coro.end.async (i8* %hdl , i1 0 )
440
+ unreachable
441
+ }
442
+
443
+ ; CHECK-LABEL: define swiftcc void @polymorphic_suspend_return(i8* %async.ctxt, %async.task* %task, %async.actor* %actor)
444
+ ; CHECK-LABEL: define internal swiftcc void @polymorphic_suspend_return.resume.0(i8* {{.*}}%0, i8* {{.*}}%1, i8* {{.*}}%2, i8* {{.*}}%3)
445
+ ; CHECK: bitcast i8* %3 to %async.task*
446
+ ; CHECK: }
447
+
448
+ declare { i8* , i8* , i8* , i8* } @llvm.coro.suspend.async.sl_p0i8p0i8p0i8p0i8s (i8* , i8* , ...)
380
449
declare i8* @llvm.coro.prepare.async (i8* )
381
450
declare token @llvm.coro.id.async (i32 , i32 , i32 , i8* )
382
451
declare i8* @llvm.coro.begin (token, i8* )
0 commit comments