@@ -1830,7 +1830,7 @@ void irgen::extractScalarResults(IRGenFunction &IGF, llvm::Type *bodyType,
1830
1830
std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize (
1831
1831
IRGenFunction &IGF, SILFunctionTypeRepresentation representation,
1832
1832
FunctionPointer functionPointer, llvm::Value *thickContext,
1833
- std::pair<bool , bool > values) {
1833
+ std::pair<bool , bool > values, Size initialContextSize ) {
1834
1834
assert (values.first || values.second );
1835
1835
bool emitFunction = values.first ;
1836
1836
bool emitSize = values.second ;
@@ -1997,11 +1997,16 @@ std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize(
1997
1997
}
1998
1998
llvm::Value *size = nullptr ;
1999
1999
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
+ }
2005
2010
}
2006
2011
return {fn, size};
2007
2012
}
@@ -2270,7 +2275,8 @@ class AsyncCallEmission final : public CallEmission {
2270
2275
llvm::Value *dynamicContextSize32;
2271
2276
std::tie (calleeFunction, dynamicContextSize32) = getAsyncFunctionAndSize (
2272
2277
IGF, CurCallee.getOrigFunctionType ()->getRepresentation (),
2273
- CurCallee.getFunctionPointer (), thickContext);
2278
+ CurCallee.getFunctionPointer (), thickContext,
2279
+ std::make_pair (true , true ), layout.getSize ());
2274
2280
auto *dynamicContextSize =
2275
2281
IGF.Builder .CreateZExt (dynamicContextSize32, IGF.IGM .SizeTy );
2276
2282
contextBuffer = emitAllocAsyncContext (IGF, dynamicContextSize);
@@ -4494,13 +4500,20 @@ llvm::Value *FunctionPointer::getPointer(IRGenFunction &IGF) const {
4494
4500
switch (Kind.value ) {
4495
4501
case KindTy::Value::Function:
4496
4502
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
+
4504
4517
}
4505
4518
}
4506
4519
0 commit comments