@@ -5153,6 +5153,35 @@ static llvm::Constant *getCoroAllocWrapperFn(IRGenModule &IGM) {
5153
5153
/* optionalLinkageOverride=*/ nullptr , llvm::CallingConv::SwiftCoro);
5154
5154
}
5155
5155
5156
+ static llvm::Constant *getCoroDeallocWrapperFn (IRGenModule &IGM) {
5157
+ return IGM.getOrCreateHelperFunction (
5158
+ " __swift_coro_dealloc_" , IGM.VoidTy ,
5159
+ {IGM.CoroAllocatorPtrTy , IGM.Int8PtrTy },
5160
+ [](IRGenFunction &IGF) {
5161
+ auto parameters = IGF.collectParameters ();
5162
+ auto *allocator = parameters.claimNext ();
5163
+ auto *ptr = parameters.claimNext ();
5164
+ auto *nullAllocator = IGF.Builder .CreateCmp (
5165
+ llvm::CmpInst::Predicate::ICMP_EQ, allocator,
5166
+ llvm::ConstantPointerNull::get (
5167
+ cast<llvm::PointerType>(allocator->getType ())));
5168
+ auto *bailBlock = IGF.createBasicBlock (" bail" );
5169
+ auto *forwardBlock = IGF.createBasicBlock (" forward" );
5170
+ IGF.Builder .CreateCondBr (nullAllocator, bailBlock, forwardBlock);
5171
+ IGF.Builder .emitBlock (bailBlock);
5172
+ // Emit the dynamic alloca.
5173
+ IGF.Builder .CreateRetVoid ();
5174
+ IGF.Builder .emitBlock (forwardBlock);
5175
+ IGF.Builder .CreateCall (
5176
+ IGF.IGM .getCoroDeallocFunctionPointer (), {allocator, ptr});
5177
+ IGF.Builder .CreateRetVoid ();
5178
+ },
5179
+ /* setIsNoInline=*/ false ,
5180
+ /* forPrologue=*/ false ,
5181
+ /* isPerformanceConstraint=*/ false ,
5182
+ /* optionalLinkageOverride=*/ nullptr , llvm::CallingConv::SwiftCoro);
5183
+ }
5184
+
5156
5185
void irgen::emitYieldOnce2CoroutineEntry (IRGenFunction &IGF,
5157
5186
CanSILFunctionType fnType,
5158
5187
llvm::Value *buffer,
@@ -5164,7 +5193,9 @@ void irgen::emitYieldOnce2CoroutineEntry(IRGenFunction &IGF,
5164
5193
auto allocFn = IGF.IGM .getOpaquePtr (isSwiftCoroCCAvailable
5165
5194
? getCoroAllocWrapperFn (IGF.IGM )
5166
5195
: IGF.IGM .getCoroAllocFn ());
5167
- auto deallocFn = IGF.IGM .getOpaquePtr (IGF.IGM .getCoroDeallocFn ());
5196
+ auto deallocFn = IGF.IGM .getOpaquePtr (isSwiftCoroCCAvailable
5197
+ ? getCoroDeallocWrapperFn (IGF.IGM )
5198
+ : IGF.IGM .getCoroDeallocFn ());
5168
5199
emitRetconCoroutineEntry (
5169
5200
IGF, fnType, buffer, llvm::Intrinsic::coro_id_retcon_once_dynamic,
5170
5201
Size (-1 ) /* dynamic-to-IRGen size*/ , IGF.IGM .getCoroStaticFrameAlignment (),
0 commit comments