@@ -5094,26 +5094,72 @@ void irgen::emitAsyncFunctionEntry(IRGenFunction &IGF,
5094
5094
IGF.setupAsync (asyncContextIndex);
5095
5095
}
5096
5096
5097
+ static llvm::Constant *getCoroFrameAllocStubFn (IRGenModule &IGM) {
5098
+ return IGM.getOrCreateHelperFunction (
5099
+ " __swift_coroFrameAllocStub" , IGM.Int8PtrTy ,
5100
+ {IGM.SizeTy },
5101
+ [&](IRGenFunction &IGF) {
5102
+ if (IGM.DebugInfo )
5103
+ IGM.DebugInfo ->emitArtificialFunction (IGF, IGF.CurFn );
5104
+
5105
+ auto parameters = IGF.collectParameters ();
5106
+ auto *size = parameters.claimNext ();
5107
+ auto *coroFrameAllocFn = IGF.IGM .getOpaquePtr (IGF.IGM .getCoroFrameAllocFn ());
5108
+ auto *nullSwiftCoroFrameAlloc = IGF.Builder .CreateCmp (
5109
+ llvm::CmpInst::Predicate::ICMP_NE, coroFrameAllocFn,
5110
+ llvm::ConstantPointerNull::get (
5111
+ cast<llvm::PointerType>(coroFrameAllocFn->getType ())));
5112
+ auto *coroFrameAllocReturn = IGF.createBasicBlock (" return-coroFrameAlloc" );
5113
+ auto *mallocReturn = IGF.createBasicBlock (" return-malloc" );
5114
+ IGF.Builder .CreateCondBr (nullSwiftCoroFrameAlloc, coroFrameAllocReturn, coroFrameAllocReturn);
5115
+
5116
+ IGF.Builder .emitBlock (coroFrameAllocReturn);
5117
+ auto mallocTypeId = IGF.getMallocTypeId ();
5118
+ auto *coroFrameAllocCall = IGF.Builder .CreateCall (IGF.IGM .getCoroFrameAllocFunctionPointer (), {size, mallocTypeId});
5119
+ IGF.Builder .CreateRet (coroFrameAllocCall);
5120
+
5121
+ // llvm::Constant *allocFn = IGF.IGM.getOpaquePtr(IGF.IGM.getCoroFrameAllocFn());
5122
+ // auto fun = cast<llvm::Function>(allocFn);
5123
+ // auto fnType = cast<llvm::FunctionType>(fun->getValueType());
5124
+ // llvm::CallInst *Call = IGF.Builder.CreateCallWithoutDbgLoc(fnType, allocFn, {size, mallocTypeId});
5125
+ // IGF.Builder.CreateRet(Call);
5126
+
5127
+ IGF.Builder .emitBlock (mallocReturn);
5128
+ auto *mallocCall = IGF.Builder .CreateCall (IGF.IGM .getMallocFunctionPointer (), {size});
5129
+ IGF.Builder .CreateRet (mallocCall);
5130
+ // llvm::Constant *mallocFn = IGF.IGM.getOpaquePtr(IGF.IGM.getMallocFn());
5131
+ // auto mallocFun = cast<llvm::Function>(mallocFn);
5132
+ // auto mallocFnType = cast<llvm::FunctionType>(mallocFun->getValueType());
5133
+ // llvm::CallInst *mallocCall = IGF.Builder.CreateCallWithoutDbgLoc(mallocFnType, mallocFn, {size});
5134
+ // IGF.Builder.CreateRet(mallocCall);
5135
+ },
5136
+ /* setIsNoInline=*/ false ,
5137
+ /* forPrologue=*/ false ,
5138
+ /* isPerformanceConstraint=*/ false ,
5139
+ /* optionalLinkageOverride=*/ nullptr , llvm::CallingConv::C);
5140
+ }
5141
+
5097
5142
void irgen::emitYieldOnceCoroutineEntry (
5098
5143
IRGenFunction &IGF, CanSILFunctionType fnType,
5099
5144
NativeCCEntryPointArgumentEmission &emission) {
5100
5145
// Use malloc and free as our allocator.
5101
5146
auto deallocFn = IGF.IGM .getOpaquePtr (IGF.IGM .getFreeFn ());
5102
5147
auto *buffer = emission.getCoroutineBuffer ();
5103
- llvm::SmallVector<llvm::Value *, 2 > finalArgs;
5104
- llvm::Constant *allocFn = nullptr ;
5105
- if (IGF.getOptions ().EmitTypeMallocForCoroFrame ) {
5106
- auto mallocTypeId = IGF.getMallocTypeId ();
5107
- finalArgs.push_back (mallocTypeId);
5108
- allocFn = IGF.IGM .getOpaquePtr (IGF.IGM .getCoroFrameAllocFn ());
5109
- } else {
5110
- allocFn = IGF.IGM .getOpaquePtr (IGF.IGM .getMallocFn ());
5111
- }
5148
+ auto allocFn = IGF.IGM .getOpaquePtr (getCoroFrameAllocStubFn (IGF.IGM ));
5149
+ // llvm::SmallVector<llvm::Value *, 2> finalArgs;
5150
+ // llvm::Constant *allocFn = nullptr;
5151
+ // if (IGF.getOptions().EmitTypeMallocForCoroFrame) {
5152
+ // auto mallocTypeId = IGF.getMallocTypeId();
5153
+ // finalArgs.push_back(mallocTypeId);
5154
+ // allocFn = IGF.IGM.getOpaquePtr(IGF.IGM.getCoroFrameAllocFn());
5155
+ // } else {
5156
+ // allocFn = IGF.IGM.getOpaquePtr(IGF.IGM.getMallocFn());
5157
+ // }
5112
5158
emitRetconCoroutineEntry (IGF, fnType, buffer,
5113
5159
llvm::Intrinsic::coro_id_retcon_once,
5114
5160
getYieldOnceCoroutineBufferSize (IGF.IGM ),
5115
5161
getYieldOnceCoroutineBufferAlignment (IGF.IGM ), {},
5116
- allocFn, deallocFn, finalArgs );
5162
+ allocFn, deallocFn, {} );
5117
5163
}
5118
5164
5119
5165
void irgen::emitYieldManyCoroutineEntry (
0 commit comments