@@ -1830,7 +1830,7 @@ void irgen::extractScalarResults(IRGenFunction &IGF, llvm::Type *bodyType,
18301830std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize (
18311831 IRGenFunction &IGF, SILFunctionTypeRepresentation representation,
18321832 FunctionPointer functionPointer, llvm::Value *thickContext,
1833- std::pair<bool , bool > values) {
1833+ std::pair<bool , bool > values, Size initialContextSize ) {
18341834 assert (values.first || values.second );
18351835 bool emitFunction = values.first ;
18361836 bool emitSize = values.second ;
@@ -1997,11 +1997,16 @@ std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize(
19971997 }
19981998 llvm::Value *size = nullptr ;
19991999 if (emitSize) {
2000- auto *ptr = functionPointer.getRawPointer ();
2001- auto *descriptorPtr =
2002- IGF.Builder .CreateBitCast (ptr, IGF.IGM .AsyncFunctionPointerPtrTy );
2003- auto *sizePtr = IGF.Builder .CreateStructGEP (descriptorPtr, 1 );
2004- size = IGF.Builder .CreateLoad (sizePtr, IGF.IGM .getPointerAlignment ());
2000+ if (functionPointer.useStaticContextSize ()) {
2001+ size = llvm::ConstantInt::get (IGF.IGM .Int32Ty ,
2002+ initialContextSize.getValue ());
2003+ } else {
2004+ auto *ptr = functionPointer.getRawPointer ();
2005+ auto *descriptorPtr =
2006+ IGF.Builder .CreateBitCast (ptr, IGF.IGM .AsyncFunctionPointerPtrTy );
2007+ auto *sizePtr = IGF.Builder .CreateStructGEP (descriptorPtr, 1 );
2008+ size = IGF.Builder .CreateLoad (sizePtr, IGF.IGM .getPointerAlignment ());
2009+ }
20052010 }
20062011 return {fn, size};
20072012 }
@@ -2270,7 +2275,8 @@ class AsyncCallEmission final : public CallEmission {
22702275 llvm::Value *dynamicContextSize32;
22712276 std::tie (calleeFunction, dynamicContextSize32) = getAsyncFunctionAndSize (
22722277 IGF, CurCallee.getOrigFunctionType ()->getRepresentation (),
2273- CurCallee.getFunctionPointer (), thickContext);
2278+ CurCallee.getFunctionPointer (), thickContext,
2279+ std::make_pair (true , true ), layout.getSize ());
22742280 auto *dynamicContextSize =
22752281 IGF.Builder .CreateZExt (dynamicContextSize32, IGF.IGM .SizeTy );
22762282 contextBuffer = emitAllocAsyncContext (IGF, dynamicContextSize);
@@ -4494,13 +4500,20 @@ llvm::Value *FunctionPointer::getPointer(IRGenFunction &IGF) const {
44944500 switch (Kind.value ) {
44954501 case KindTy::Value::Function:
44964502 return Value;
4497- case KindTy::Value::AsyncFunctionPointer:
4498- auto *descriptorPtr =
4499- IGF.Builder .CreateBitCast (Value, IGF.IGM .AsyncFunctionPointerPtrTy );
4500- auto *addrPtr = IGF.Builder .CreateStructGEP (descriptorPtr, 0 );
4501- return IGF.emitLoadOfRelativePointer (
4502- Address (addrPtr, IGF.IGM .getPointerAlignment ()), /* isFar*/ false ,
4503- /* expectedType*/ getFunctionType ()->getPointerTo ());
4503+ case KindTy::Value::AsyncFunctionPointer: {
4504+ if (!isFunctionPointerWithoutContext) {
4505+ auto *descriptorPtr =
4506+ IGF.Builder .CreateBitCast (Value, IGF.IGM .AsyncFunctionPointerPtrTy );
4507+ auto *addrPtr = IGF.Builder .CreateStructGEP (descriptorPtr, 0 );
4508+ return IGF.emitLoadOfRelativePointer (
4509+ Address (addrPtr, IGF.IGM .getPointerAlignment ()), /* isFar*/ false ,
4510+ /* expectedType*/ getFunctionType ()->getPointerTo ());
4511+ } else {
4512+ return IGF.Builder .CreateBitOrPointerCast (
4513+ Value, getFunctionType ()->getPointerTo ());
4514+ }
4515+ }
4516+
45044517 }
45054518}
45064519
0 commit comments