Skip to content

Commit f965df2

Browse files
aslaschwaighofer
andcommitted
Bring mangling of coroutine continuations back.
Co-authored-by: Arnold Schwaighofer <[email protected]>
1 parent 85810bf commit f965df2

8 files changed

+30
-31
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,8 +1456,11 @@ class CoroPartialApplicationForwarderEmission
14561456
Self(nullptr), FirstData(nullptr), SecondData(nullptr) {}
14571457

14581458
void begin() override {
1459+
auto unsubstType = substType->getUnsubstitutedType(IGM.getSILModule());
14591460
auto prototype = subIGF.IGM.getOpaquePtr(
1460-
subIGF.IGM.getAddrOfContinuationPrototype(origType));
1461+
subIGF.IGM.getAddrOfContinuationPrototype(
1462+
cast<SILFunctionType>(
1463+
unsubstType->mapTypeOutOfContext()->getCanonicalType())));
14611464

14621465
// Use malloc and free as our allocator.
14631466
auto allocFn = subIGF.IGM.getOpaquePtr(subIGF.IGM.getMallocFn());

lib/IRGen/IRGenMangler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ class IRGenMangler : public Mangle::ASTMangler {
498498
CanType shapeType,
499499
bool isUnique);
500500

501+
std::string mangleCoroutineContinuationPrototype(CanSILFunctionType type) {
502+
return mangleTypeSymbol(type, "TC");
503+
}
504+
501505
std::string mangleReflectionBuiltinDescriptor(Type type) {
502506
const char * const reflectionDescriptorOp = "MB";
503507
if (type->isAnyObject()) {

lib/IRGen/Linking.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,8 @@ std::string LinkEntity::mangleAsString() const {
376376
}
377377

378378
case Kind::CoroutineContinuationPrototype:
379-
// Emit unnamed functions for coroutine continuation
380-
// prototypes. These are supposed to be replaced by the LLVM
381-
// coroutine lowering pass.
382-
return std::string();
379+
return mangler.mangleCoroutineContinuationPrototype(
380+
cast<SILFunctionType>(getType()));
383381

384382
// An Objective-C class reference reference. The symbol is private, so
385383
// the mangling is unimportant; it should just be readable in LLVM IR.

test/IRGen/yield_once.sil

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ sil @marker : $(Builtin.Int32) -> ()
1010
// CHECK-SAME: [[CORO_ATTRIBUTES:#[0-9]+]]
1111
sil @test_simple : $@yield_once () -> () {
1212
entry:
13-
// CHECK-32: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
14-
// CHECK-64: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
13+
// CHECK-32: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @"$sIetA_TC", ptr @malloc, ptr @free)
14+
// CHECK-64: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @"$sIetA_TC", ptr @malloc, ptr @free)
1515
// CHECK-NEXT: [[BEGIN:%.*]] = call ptr @llvm.coro.begin(token [[ID]], ptr null)
1616

1717
// CHECK-NEXT: call swiftcc void @marker(i32 1000)
@@ -43,8 +43,7 @@ unwind:
4343
// CHECK-NEXT: unreachable
4444
}
4545

46-
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}} swiftcc
47-
// CHECK-SAME: void @[[CONT_FN]]
46+
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}} swiftcc void @"$sIetA_TC"
4847
// CHECK-SAME: (ptr noalias dereferenceable([[BUFFER_SIZE]]), i1)
4948

5049
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @test_simple_call(i1 %0)

test/IRGen/yield_once_big.sil

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ entry:
4444
// CHECK-64-SAME: , align 8
4545

4646
// Coroutine setup.
47-
// CHECK-32-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
48-
// CHECK-64-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
47+
// CHECK-32-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @"$s14yield_once_big3BigVyxGAA9SomeClassCRbzlIetAYi_TC", ptr @malloc, ptr @free)
48+
// CHECK-64-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @"$s14yield_once_big3BigVyxGAA9SomeClassCRbzlIetAYi_TC", ptr @malloc, ptr @free)
4949
// CHECK-NEXT: [[BEGIN:%.*]] = call ptr @llvm.coro.begin(token [[ID]], ptr null)
5050
// CHECK-NEXT: store ptr
5151

@@ -89,8 +89,7 @@ unwind:
8989
// CHECK-NEXT: unreachable
9090
}
9191

92-
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}}
93-
// CHECK-SAME: swiftcc void @[[CONT_FN]]
92+
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}} swiftcc void @"$s14yield_once_big3BigVyxGAA9SomeClassCRbzlIetAYi_TC"
9493
// CHECK-SAME: (ptr noalias dereferenceable([[BUFFER_SIZE]]), i1)
9594

9695
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @test_simple_call(i1 %0)
@@ -182,8 +181,8 @@ entry(%arg : $*BigWrapper<C>):
182181
// CHECK-64-SAME: , align 8
183182

184183
// Coroutine setup.
185-
// CHECK-32-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
186-
// CHECK-64-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
184+
// CHECK-32-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @"$s14yield_once_big10BigWrapperVyxGAA0D0VyxGAA9SomeClassCRbzlIetAnYn_TC", ptr @malloc, ptr @free)
185+
// CHECK-64-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @"$s14yield_once_big10BigWrapperVyxGAA0D0VyxGAA9SomeClassCRbzlIetAnYn_TC", ptr @malloc, ptr @free)
187186
// CHECK-NEXT: [[BEGIN:%.*]] = call ptr @llvm.coro.begin(token [[ID]], ptr null)
188187
// CHECK-NEXT: store ptr
189188

@@ -238,6 +237,5 @@ unwind:
238237
// CHECK-NEXT: unreachable
239238
}
240239

241-
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}}
242-
// CHECK-SAME: swiftcc void @[[CONT_FN]]
240+
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}} swiftcc void @"$s14yield_once_big10BigWrapperVyxGAA0D0VyxGAA9SomeClassCRbzlIetAnYn_TC"
243241
// CHECK-SAME: (ptr noalias dereferenceable([[BUFFER_SIZE]]), i1)

test/IRGen/yield_once_biggish.sil

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ entry:
4040
// CHECK-64-SAME: , align 8
4141

4242
// Coroutine setup.
43-
// CHECK-32-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
44-
// CHECK-64-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
43+
// CHECK-32-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @"$s18yield_once_biggish7BiggishVyxGAA9SomeClassCRbzlIetAYx_TC", ptr @malloc, ptr @free)
44+
// CHECK-64-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @"$s18yield_once_biggish7BiggishVyxGAA9SomeClassCRbzlIetAYx_TC", ptr @malloc, ptr @free)
4545
// CHECK-NEXT: [[BEGIN:%.*]] = call ptr @llvm.coro.begin(token [[ID]], ptr null)
4646
// CHECK-NEXT: store ptr
4747
// CHECK-NEXT: call swiftcc void @marker(i32 1000)
@@ -93,8 +93,7 @@ unwind:
9393
// CHECK-NEXT: unreachable
9494
}
9595

96-
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}}
97-
// CHECK-SAME: swiftcc void @[[CONT_FN:[0-9]+]]
96+
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}} swiftcc void @"$s18yield_once_biggish7BiggishVyxGAA9SomeClassCRbzlIetAYx_TC"
9897
// CHECK-SAME: (ptr noalias dereferenceable([[BUFFER_SIZE]]), i1)
9998

10099
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @test_simple_call(i1 %0)

test/IRGen/yield_once_indirect.sil

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ entry:
3030
// CHECK-64-SAME: , align 8
3131

3232
// Coroutine setup.
33-
// CHECK-32-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
34-
// CHECK-64-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
33+
// CHECK-32-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @"$s19yield_once_indirect8IndirectVyxGAA9SomeClassCRbzlIetAYi_TC", ptr @malloc, ptr @free)
34+
// CHECK-64-NEXT: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @"$s19yield_once_indirect8IndirectVyxGAA9SomeClassCRbzlIetAYi_TC", ptr @malloc, ptr @free)
3535
// CHECK-NEXT: [[BEGIN:%.*]] = call ptr @llvm.coro.begin(token [[ID]], ptr null)
3636
// CHECK-NEXT: store ptr
3737
// CHECK-NEXT: call swiftcc void @marker(i32 1000)
@@ -80,8 +80,7 @@ unwind:
8080
// CHECK-NEXT: unreachable
8181
}
8282

83-
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}}
84-
// CHECK-SAME: swiftcc void @[[CONT_FN]]
83+
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}} swiftcc void @"$s19yield_once_indirect8IndirectVyxGAA9SomeClassCRbzlIetAYi_TC"
8584
// CHECK-SAME: (ptr noalias dereferenceable([[BUFFER_SIZE]]), i1)
8685

8786
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @test_simple_call(i1 %0)

test/IRGen/yield_result.sil

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ sil @coro_ret_pair : $@yield_once @convention(thin) () -> (@yields Builtin.Int64
1313
// CHECK-SAME: [[CORO_ATTRIBUTES:#[0-9]+]]
1414
sil @test_simple : $@yield_once () -> (Builtin.Int64) {
1515
entry:
16-
// CHECK-32: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
17-
// CHECK-64: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
16+
// CHECK-32: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @"$sBi64_IetAd_TC{{(.ptrauth)?}}", ptr @malloc, ptr @free)
17+
// CHECK-64: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @"$sBi64_IetAd_TC{{(.ptrauth)?}}", ptr @malloc, ptr @free)
1818
// CHECK-NEXT: [[BEGIN:%.*]] = call ptr @llvm.coro.begin(token [[ID]], ptr null)
1919

2020
// CHECK-NEXT: call swiftcc void @marker(i64 1000)
@@ -47,8 +47,7 @@ unwind:
4747
// CHECK-NEXT: unreachable
4848
}
4949

50-
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}}
51-
// CHECK-SAME: swiftcc i64 @[[CONT_FN]]
50+
// CHECK-LABEL: declare{{( dllimport)?}}{{( protected)?}} swiftcc i64 @"$sBi64_IetAd_TC{{(.ptrauth)?}}"
5251
// CHECK-SAME: (ptr noalias dereferenceable([[BUFFER_SIZE]]), i1)
5352

5453
// CHECK-LABEL: test_coro_ret
@@ -99,8 +98,8 @@ entry:
9998
// CHECK-SAME: ptr{{.*}} [[CTX:%.*]], ptr{{.*}} [[INDIRECT_RET:%.*]], ptr{{.*}} [[ARG:%.*]], ptr{{.*}} [[TYPE:%.*]])
10099
sil @coro_ret_indirect : $@yield_once @convention(thin) <T> (@in T) -> (@yields @in T, @out T) {
101100
bb0(%outt : $*T, %t : $*T):
102-
// CHECK-32: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr [[CTX]], ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
103-
// CHECK-64: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr [[CTX]], ptr @[[CONT_FN:[0-9]+]], ptr @malloc, ptr @free)
101+
// CHECK-32: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr [[CTX]], ptr @"$sxxxlIetAirYi_TC{{(.ptrauth)?}}", ptr @malloc, ptr @free)
102+
// CHECK-64: [[ID:%.*]] = call token @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr [[CTX]], ptr @"$sxxxlIetAirYi_TC{{(.ptrauth)?}}", ptr @malloc, ptr @free)
104103

105104
// CHECK: [[IS_UNWIND:%.*]] = call i1 (...) @llvm.coro.suspend.retcon.i1(ptr [[ARG]])
106105
// CHECK: br i1 [[IS_UNWIND]], label %[[UNWIND_BB:.*]], label %[[RESUME_BB:.*]]

0 commit comments

Comments
 (0)