@@ -671,6 +671,18 @@ struct Allocator {
671671 }
672672 }
673673
674+ llvm::AttributeList getFunctionAttributeList (IRGenModule &IGM) {
675+ switch (kind) {
676+ case Flags:
677+ llvm_unreachable (" not a function" );
678+ case Field::Allocate:
679+ case Field::Deallocate:
680+ auto attrs = llvm::AttributeList ();
681+ IGM.addSwiftCoroAttributes (attrs, 0 );
682+ return attrs;
683+ }
684+ }
685+
674686 const PointerAuthSchema &getSchema (IRGenModule &IGM) {
675687 switch (kind) {
676688 case Flags:
@@ -732,7 +744,8 @@ struct Allocator {
732744 }
733745 return FunctionPointer::createUnsigned (
734746 FunctionPointer::Kind::Function, callee,
735- Signature (field.getFunctionType (IGF.IGM ), {}, IGF.IGM .SwiftCC ));
747+ Signature (field.getFunctionType (IGF.IGM ),
748+ field.getFunctionAttributeList (IGF.IGM ), IGF.IGM .SwiftCC ));
736749 }
737750};
738751} // end anonymous namespace
@@ -743,7 +756,8 @@ llvm::Constant *swift::irgen::getCoroAllocFn(IRGenModule &IGM) {
743756 " _swift_coro_alloc" , IGM.Int8PtrTy , {IGM.CoroAllocatorPtrTy , IGM.SizeTy },
744757 [isSwiftCoroCCAvailable](IRGenFunction &IGF) {
745758 auto parameters = IGF.collectParameters ();
746- auto allocator = Allocator (parameters.claimNext (), IGF);
759+ auto *allocatorValue = parameters.claimNext ();
760+ auto allocator = Allocator (allocatorValue, IGF);
747761 auto *size = parameters.claimNext ();
748762 if (isSwiftCoroCCAvailable) {
749763 // swiftcorocc is available, so if there's no allocator pointer,
@@ -762,7 +776,7 @@ llvm::Constant *swift::irgen::getCoroAllocFn(IRGenModule &IGM) {
762776 });
763777 }
764778 auto fnPtr = allocator.getAllocate ();
765- auto *call = IGF.Builder .CreateCall (fnPtr, {size});
779+ auto *call = IGF.Builder .CreateCall (fnPtr, {allocatorValue, size});
766780 call->setDoesNotThrow ();
767781 call->setCallingConv (IGF.IGM .SwiftCC );
768782 IGF.Builder .CreateRet (call);
@@ -784,7 +798,8 @@ llvm::Constant *swift::irgen::getCoroDeallocFn(IRGenModule &IGM) {
784798 {IGM.CoroAllocatorPtrTy , IGM.Int8PtrTy },
785799 [isSwiftCoroCCAvailable](IRGenFunction &IGF) {
786800 auto parameters = IGF.collectParameters ();
787- auto allocator = Allocator (parameters.claimNext (), IGF);
801+ auto *allocatorValue = parameters.claimNext ();
802+ auto allocator = Allocator (allocatorValue, IGF);
788803 auto *ptr = parameters.claimNext ();
789804 if (isSwiftCoroCCAvailable) {
790805 // swiftcorocc is available, so if there's no allocator pointer,
@@ -816,7 +831,7 @@ llvm::Constant *swift::irgen::getCoroDeallocFn(IRGenModule &IGM) {
816831 // Start emitting the "normal" block.
817832 IGF.Builder .emitBlock (normalBlock);
818833 auto fnPtr = allocator.getDeallocate ();
819- auto *call = IGF.Builder .CreateCall (fnPtr, {ptr});
834+ auto *call = IGF.Builder .CreateCall (fnPtr, {allocatorValue, ptr});
820835 call->setDoesNotThrow ();
821836 call->setCallingConv (IGF.IGM .SwiftCC );
822837 IGF.Builder .CreateRetVoid ();
@@ -854,51 +869,106 @@ static llvm::Constant *getAddrOfGlobalCoroAllocator(
854869 return taskAllocator;
855870}
856871
857- static llvm::Constant *getAddrOfSwiftCCMalloc (IRGenModule &IGM) {
858- auto mallocFnPtr = IGM.getMallocFunctionPointer ();
859- auto sig = mallocFnPtr.getSignature ();
860- if (sig.getCallingConv () == IGM.SwiftCC ) {
861- return IGM.getMallocFn ();
862- }
872+ static llvm::Constant *getAddrOfSwiftCoroMalloc (IRGenModule &IGM) {
873+ auto *ty = IGM.CoroAllocateFnTy ;
863874 return IGM.getOrCreateHelperFunction (
864- " _swift_malloc " , sig. getType () ->getReturnType (), sig. getType () ->params (),
875+ " _swift_coro_malloc " , ty ->getReturnType (), ty ->params (),
865876 [](IRGenFunction &IGF) {
866877 auto parameters = IGF.collectParameters ();
878+ parameters.claimNext (); // allocator
867879 auto *size = parameters.claimNext ();
868- auto malloc = IGF.IGM .getMallocFunctionPointer ();
869- auto *call = IGF.Builder .CreateCall (malloc , {size});
880+ auto alloc = IGF.IGM .getMallocFunctionPointer ();
881+ auto *call = IGF.Builder .CreateCall (alloc , {size});
870882 IGF.Builder .CreateRet (call);
883+ },
884+ /* setIsNoInline=*/ true , /* forPrologue=*/ false ,
885+ /* isPerformanceConstraint=*/ false ,
886+ /* optionalLinkage=*/ nullptr ,
887+ /* specialCallingConv=*/ std::nullopt ,
888+ /* transformAttributes=*/
889+ [&IGM](llvm::AttributeList &attrs) {
890+ IGM.addSwiftCoroAttributes (attrs, 0 );
871891 });
872892}
873893
874- static llvm::Constant *getAddrOfSwiftCCFree (IRGenModule &IGM) {
875- auto freeFnPtr = IGM.getFreeFunctionPointer ();
876- auto sig = freeFnPtr.getSignature ();
877- if (sig.getCallingConv () == IGM.SwiftCC ) {
878- return IGM.getFreeFn ();
879- }
894+ static llvm::Constant *getAddrOfSwiftCoroFree (IRGenModule &IGM) {
895+ auto *ty = IGM.CoroDeallocateFnTy ;
880896 return IGM.getOrCreateHelperFunction (
881- " _swift_free " , sig. getType () ->getReturnType (), sig. getType () ->params (),
897+ " _swift_coro_free " , ty ->getReturnType (), ty ->params (),
882898 [](IRGenFunction &IGF) {
883899 auto parameters = IGF.collectParameters ();
900+ parameters.claimNext (); // allocator
884901 auto *ptr = parameters.claimNext ();
885- auto free = IGF.IGM .getFreeFunctionPointer ();
886- IGF.Builder .CreateCall (free , {ptr});
902+ auto dealloc = IGF.IGM .getFreeFunctionPointer ();
903+ IGF.Builder .CreateCall (dealloc , {ptr});
887904 IGF.Builder .CreateRetVoid ();
905+ },
906+ /* setIsNoInline=*/ true , /* forPrologue=*/ false ,
907+ /* isPerformanceConstraint=*/ false ,
908+ /* optionalLinkage=*/ nullptr ,
909+ /* specialCallingConv=*/ std::nullopt ,
910+ /* transformAttributes=*/
911+ [&IGM](llvm::AttributeList &attrs) {
912+ IGM.addSwiftCoroAttributes (attrs, 0 );
888913 });
889914}
890915
891916llvm::Constant *IRGenModule::getAddrOfGlobalCoroMallocAllocator () {
892917 return getAddrOfGlobalCoroAllocator (*this , CoroAllocatorKind::Malloc,
893918 /* shouldDeallocateImmediately=*/ true ,
894- getAddrOfSwiftCCMalloc (*this ),
895- getAddrOfSwiftCCFree (*this ));
919+ getAddrOfSwiftCoroMalloc (*this ),
920+ getAddrOfSwiftCoroFree (*this ));
921+ }
922+
923+ static llvm::Constant *getAddrOfSwiftCoroTaskAlloc (IRGenModule &IGM) {
924+ auto *ty = IGM.CoroAllocateFnTy ;
925+ return IGM.getOrCreateHelperFunction (
926+ " _swift_coro_task_alloc" , ty->getReturnType (), ty->params (),
927+ [](IRGenFunction &IGF) {
928+ auto parameters = IGF.collectParameters ();
929+ parameters.claimNext (); // allocator
930+ auto *size = parameters.claimNext ();
931+ auto alloc = IGF.IGM .getTaskAllocFunctionPointer ();
932+ auto *call = IGF.Builder .CreateCall (alloc, {size});
933+ IGF.Builder .CreateRet (call);
934+ },
935+ /* setIsNoInline=*/ true , /* forPrologue=*/ false ,
936+ /* isPerformanceConstraint=*/ false ,
937+ /* optionalLinkage=*/ nullptr ,
938+ /* specialCallingConv=*/ std::nullopt ,
939+ /* transformAttributes=*/
940+ [&IGM](llvm::AttributeList &attrs) {
941+ IGM.addSwiftCoroAttributes (attrs, 0 );
942+ });
943+ }
944+
945+ static llvm::Constant *getAddrOfSwiftCoroTaskDealloc (IRGenModule &IGM) {
946+ auto *ty = IGM.CoroDeallocateFnTy ;
947+ return IGM.getOrCreateHelperFunction (
948+ " _swift_coro_task_dealloc" , ty->getReturnType (), ty->params (),
949+ [](IRGenFunction &IGF) {
950+ auto parameters = IGF.collectParameters ();
951+ parameters.claimNext (); // allocator
952+ auto *ptr = parameters.claimNext ();
953+ auto dealloc = IGF.IGM .getTaskDeallocFunctionPointer ();
954+ IGF.Builder .CreateCall (dealloc, {ptr});
955+ IGF.Builder .CreateRetVoid ();
956+ },
957+ /* setIsNoInline=*/ true , /* forPrologue=*/ false ,
958+ /* isPerformanceConstraint=*/ false ,
959+ /* optionalLinkage=*/ nullptr ,
960+ /* specialCallingConv=*/ std::nullopt ,
961+ /* transformAttributes=*/
962+ [&IGM](llvm::AttributeList &attrs) {
963+ IGM.addSwiftCoroAttributes (attrs, 0 );
964+ });
896965}
897966
898967llvm::Constant *IRGenModule::getAddrOfGlobalCoroAsyncTaskAllocator () {
899968 return getAddrOfGlobalCoroAllocator (*this , CoroAllocatorKind::Async,
900969 /* shouldDeallocateImmediately=*/ false ,
901- getTaskAllocFn (), getTaskDeallocFn ());
970+ getAddrOfSwiftCoroTaskAlloc (*this ),
971+ getAddrOfSwiftCoroTaskDealloc (*this ));
902972}
903973
904974llvm::Value *
0 commit comments