@@ -1002,51 +1002,28 @@ llvm::Constant *swift::irgen::getCoroDeallocFrameFn(IRGenModule &IGM) {
10021002 return getCoroDeallocFn (AllocationKind::Frame, IGM);
10031003}
10041004
1005- using GetAllocFunctionPointer = FunctionPointer (IRGenModule::*)();
1005+ using GetAllocatorFunctionPointer = FunctionPointer (IRGenModule::*)();
10061006
10071007static llvm::Constant *
1008- getAddrOfSwiftCoroAllocThunk (StringRef name,
1009- GetAllocFunctionPointer getAlloc ,
1010- IRGenModule &IGM) {
1011- auto *ty = IGM. CoroAllocateFnTy ;
1008+ getAddrOfSwiftCoroAllocatorThunk (StringRef name, Allocator::Field field ,
1009+ GetAllocatorFunctionPointer getCator ,
1010+ IRGenModule &IGM) {
1011+ auto *ty = field. getFunctionType (IGM) ;
10121012 return IGM.getOrCreateHelperFunction (
10131013 name, ty->getReturnType (), ty->params (),
1014- [getAlloc ](IRGenFunction &IGF) {
1014+ [getCator, ty ](IRGenFunction &IGF) {
10151015 auto parameters = IGF.collectParameters ();
10161016 parameters.claimNext (); // frame
10171017 parameters.claimNext (); // allocator
1018- auto *size = parameters.claimNext ();
1019- auto alloc = (IGF.IGM .*getAlloc)();
1020- auto *call = IGF.Builder .CreateCall (alloc, {size});
1021- IGF.Builder .CreateRet (call);
1022- },
1023- /* setIsNoInline=*/ true , /* forPrologue=*/ false ,
1024- /* isPerformanceConstraint=*/ false ,
1025- /* optionalLinkage=*/ nullptr ,
1026- /* specialCallingConv=*/ std::nullopt ,
1027- /* transformAttributes=*/
1028- [&IGM](llvm::AttributeList &attrs) {
1029- IGM.addSwiftCoroAttributes (attrs, 1 );
1030- });
1031- }
1032-
1033- using GetDeallocFunctionPointer = FunctionPointer (IRGenModule::*)();
1034-
1035- static llvm::Constant *
1036- getAddrOfSwiftCoroDeallocThunk (StringRef name,
1037- GetDeallocFunctionPointer getDealloc,
1038- IRGenModule &IGM) {
1039- auto *ty = IGM.CoroDeallocateFnTy ;
1040- return IGM.getOrCreateHelperFunction (
1041- name, ty->getReturnType (), ty->params (),
1042- [getDealloc](IRGenFunction &IGF) {
1043- auto parameters = IGF.collectParameters ();
1044- parameters.claimNext (); // frame
1045- parameters.claimNext (); // allocator
1046- auto *ptr = parameters.claimNext ();
1047- auto dealloc = (IGF.IGM .*getDealloc)();
1048- IGF.Builder .CreateCall (dealloc, {ptr});
1049- IGF.Builder .CreateRetVoid ();
1018+ // allocator - size; deallocator - address
1019+ auto *value = parameters.claimNext ();
1020+ auto alloc = (IGF.IGM .*getCator)();
1021+ auto *result = IGF.Builder .CreateCall (alloc, {value});
1022+ if (!ty->getReturnType ()->isVoidTy ()) {
1023+ IGF.Builder .CreateRet (result);
1024+ } else {
1025+ IGF.Builder .CreateRetVoid ();
1026+ }
10501027 },
10511028 /* setIsNoInline=*/ true , /* forPrologue=*/ false ,
10521029 /* isPerformanceConstraint=*/ false ,
@@ -1099,15 +1076,15 @@ static llvm::Constant *getAddrOfGlobalCoroAllocator(
10991076}
11001077
11011078static llvm::Constant *getAddrOfSwiftCoroMalloc (IRGenModule &IGM) {
1102- return getAddrOfSwiftCoroAllocThunk ( " _swift_coro_malloc " ,
1103- &IRGenModule::getMallocFunctionPointer ,
1104- IGM);
1079+ return getAddrOfSwiftCoroAllocatorThunk (
1080+ " _swift_coro_malloc " , Allocator::Field::Allocate ,
1081+ &IRGenModule::getMallocFunctionPointer, IGM);
11051082}
11061083
11071084static llvm::Constant *getAddrOfSwiftCoroFree (IRGenModule &IGM) {
1108- return getAddrOfSwiftCoroDeallocThunk ( " _swift_coro_free " ,
1109- &IRGenModule::getFreeFunctionPointer ,
1110- IGM);
1085+ return getAddrOfSwiftCoroAllocatorThunk (
1086+ " _swift_coro_free " , Allocator::Field::Deallocate ,
1087+ &IRGenModule::getFreeFunctionPointer, IGM);
11111088}
11121089
11131090llvm::Constant *IRGenModule::getAddrOfGlobalCoroMallocAllocator () {
@@ -1119,15 +1096,15 @@ llvm::Constant *IRGenModule::getAddrOfGlobalCoroMallocAllocator() {
11191096
11201097static llvm::Constant *
11211098getAddrOfSwiftCoroTaskAlloc (IRGenModule &IGM) {
1122- return getAddrOfSwiftCoroAllocThunk ( " _swift_coro_task_alloc " ,
1123- &IRGenModule::getTaskAllocFunctionPointer ,
1124- IGM);
1099+ return getAddrOfSwiftCoroAllocatorThunk (
1100+ " _swift_coro_task_alloc " , Allocator::Field::Allocate ,
1101+ &IRGenModule::getTaskAllocFunctionPointer, IGM);
11251102}
11261103
11271104static llvm::Constant *
11281105getAddrOfSwiftCoroTaskDealloc (IRGenModule &IGM) {
1129- return getAddrOfSwiftCoroDeallocThunk (
1130- " _swift_coro_task_dealloc" ,
1106+ return getAddrOfSwiftCoroAllocatorThunk (
1107+ " _swift_coro_task_dealloc" , Allocator::Field::Deallocate,
11311108 &IRGenModule::getTaskDeallocFunctionPointer, IGM);
11321109}
11331110
0 commit comments