@@ -862,6 +862,40 @@ CanType irgen::getArgumentLoweringType(CanType type, SILParameterInfo paramInfo,
862
862
llvm_unreachable (" unhandled convention" );
863
863
}
864
864
865
+ llvm::Constant *irgen::getCoroFrameAllocStubFn (IRGenModule &IGM) {
866
+ return IGM.getOrCreateHelperFunction (
867
+ " __swift_coroFrameAllocStub" , IGM.Int8PtrTy ,
868
+ {IGM.SizeTy , IGM.Int64Ty },
869
+ [&](IRGenFunction &IGF) {
870
+ auto parameters = IGF.collectParameters ();
871
+ auto *size = parameters.claimNext ();
872
+ auto coroAllocPtr = IGF.IGM .getCoroFrameAllocFn ();
873
+ auto coroAllocFn = dyn_cast<llvm::Function>(coroAllocPtr);
874
+ coroAllocFn->setLinkage (llvm::GlobalValue::ExternalWeakLinkage);
875
+ auto *coroFrameAllocFn = IGF.IGM .getOpaquePtr (coroAllocPtr);
876
+ auto *nullSwiftCoroFrameAlloc = IGF.Builder .CreateCmp (
877
+ llvm::CmpInst::Predicate::ICMP_NE, coroFrameAllocFn,
878
+ llvm::ConstantPointerNull::get (
879
+ cast<llvm::PointerType>(coroFrameAllocFn->getType ())));
880
+ auto *coroFrameAllocReturn = IGF.createBasicBlock (" return-coroFrameAlloc" );
881
+ auto *mallocReturn = IGF.createBasicBlock (" return-malloc" );
882
+ IGF.Builder .CreateCondBr (nullSwiftCoroFrameAlloc, coroFrameAllocReturn, mallocReturn);
883
+
884
+ IGF.Builder .emitBlock (coroFrameAllocReturn);
885
+ auto *mallocTypeId = parameters.claimNext ();
886
+ auto *coroFrameAllocCall = IGF.Builder .CreateCall (IGF.IGM .getCoroFrameAllocFunctionPointer (), {size, mallocTypeId});
887
+ IGF.Builder .CreateRet (coroFrameAllocCall);
888
+
889
+ IGF.Builder .emitBlock (mallocReturn);
890
+ auto *mallocCall = IGF.Builder .CreateCall (IGF.IGM .getMallocFunctionPointer (), {size});
891
+ IGF.Builder .CreateRet (mallocCall);
892
+ },
893
+ /* setIsNoInline=*/ false ,
894
+ /* forPrologue=*/ false ,
895
+ /* isPerformanceConstraint=*/ false ,
896
+ /* optionalLinkageOverride=*/ nullptr , llvm::CallingConv::C);
897
+ }
898
+
865
899
static Size getOffsetOfOpaqueIsolationField (IRGenModule &IGM,
866
900
const LoadableTypeInfo &isolationTI) {
867
901
auto offset = IGM.RefCountedStructSize ;
0 commit comments