Skip to content

Commit beb3951

Browse files
committed
Get rid of getOrCreateAwaitAsyncSupendFn
1 parent b49a882 commit beb3951

File tree

4 files changed

+40
-35
lines changed

4 files changed

+40
-35
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4581,3 +4581,17 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout,
45814581
auto call = IGF.Builder.CreateCall(fnPtr, Args);
45824582
call->setTailCall();
45834583
}
4584+
4585+
FunctionPointer
4586+
IRGenFunction::getFunctionPointerForResumeIntrinsic(llvm::Value *resume) {
4587+
auto *fnTy = llvm::FunctionType::get(
4588+
IGM.VoidTy, {IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy},
4589+
false /*vaargs*/);
4590+
auto signature =
4591+
Signature(fnTy, IGM.constructInitialAttributes(), IGM.SwiftCC);
4592+
auto fnPtr = FunctionPointer(
4593+
FunctionPointer::KindTy::Function,
4594+
Builder.CreateBitOrPointerCast(resume, fnTy->getPointerTo()),
4595+
PointerAuthInfo(), signature);
4596+
return fnPtr;
4597+
}

lib/IRGen/GenFunc.cpp

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,21 +2395,31 @@ llvm::Function *IRGenFunction::getOrCreateResumePrjFn() {
23952395
},
23962396
false /*isNoInline*/));
23972397
}
2398-
23992398
llvm::Function *
24002399
IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
24012400
ArrayRef<llvm::Value *> args) {
24022401
SmallVector<llvm::Type*, 8> argTys;
2403-
argTys.push_back(IGM.Int8PtrTy); // Function pointer to be called.
24042402
for (auto arg : args) {
24052403
auto *ty = arg->getType();
24062404
argTys.push_back(ty);
24072405
}
2406+
return createAsyncDispatchFn(fnPtr, argTys);
2407+
}
2408+
2409+
llvm::Function *
2410+
IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
2411+
ArrayRef<llvm::Type *> argTypes) {
2412+
SmallVector<llvm::Type*, 8> argTys;
2413+
argTys.push_back(IGM.Int8PtrTy); // Function pointer to be called.
2414+
for (auto ty : argTypes) {
2415+
argTys.push_back(ty);
2416+
}
24082417
auto calleeFnPtrType = fnPtr.getRawPointer()->getType();
24092418
auto *dispatchFnTy =
24102419
llvm::FunctionType::get(IGM.VoidTy, argTys, false /*vaargs*/);
24112420
llvm::SmallString<40> name;
2412-
llvm::raw_svector_ostream(name) << "__swift_suspend_dispatch_" << args.size();
2421+
llvm::raw_svector_ostream(name)
2422+
<< "__swift_suspend_dispatch_" << argTypes.size();
24132423
llvm::Function *dispatch =
24142424
llvm::Function::Create(dispatchFnTy, llvm::Function::InternalLinkage,
24152425
llvm::StringRef(name), &IGM.Module);
@@ -2433,31 +2443,3 @@ IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
24332443
Builder.CreateRetVoid();
24342444
return dispatch;
24352445
}
2436-
2437-
llvm::Function *IRGenFunction::getOrCreateAwaitAsyncSupendFn() {
2438-
auto name = "__swift_async_await_async_suspend";
2439-
return cast<llvm::Function>(IGM.getOrCreateHelperFunction(
2440-
name, IGM.VoidTy, {IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy},
2441-
[&](IRGenFunction &IGF) {
2442-
auto it = IGF.CurFn->arg_begin();
2443-
auto &Builder = IGF.Builder;
2444-
auto *fnTy = llvm::FunctionType::get(
2445-
IGM.VoidTy, {IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy},
2446-
false /*vaargs*/);
2447-
llvm::Value *fn = &*(it++);
2448-
SmallVector<llvm::Value *, 8> callArgs;
2449-
for (auto end = IGF.CurFn->arg_end(); it != end; ++it)
2450-
callArgs.push_back(&*it);
2451-
auto signature =
2452-
Signature(fnTy, IGM.constructInitialAttributes(), IGM.SwiftCC);
2453-
auto fnPtr = FunctionPointer(
2454-
FunctionPointer::KindTy::Function,
2455-
Builder.CreateBitOrPointerCast(fn, fnTy->getPointerTo()),
2456-
PointerAuthInfo(), signature);
2457-
auto call = Builder.CreateCall(fnPtr, callArgs);
2458-
call->setTailCall();
2459-
call->setCallingConv(IGM.SwiftCC);
2460-
Builder.CreateRetVoid();
2461-
},
2462-
false /*isNoInline*/));
2463-
}

lib/IRGen/IRGenFunction.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/Support/CommandLine.h"
2424
#include "llvm/Support/raw_ostream.h"
2525

26+
#include "Callee.h"
2627
#include "Explosion.h"
2728
#include "IRGenDebugInfo.h"
2829
#include "IRGenFunction.h"
@@ -697,18 +698,22 @@ void IRGenFunction::emitAwaitAsyncContinuation(
697698
auto resumeProjFn = getOrCreateResumePrjFn();
698699
arguments.push_back(
699700
Builder.CreateBitOrPointerCast(resumeProjFn, IGM.Int8PtrTy));
701+
// The dispatch function just calls the resume point.
702+
auto resumeFnPtr =
703+
getFunctionPointerForResumeIntrinsic(AsyncCoroutineCurrentResume);
700704
arguments.push_back(Builder.CreateBitOrPointerCast(
701-
getOrCreateAwaitAsyncSupendFn(), IGM.Int8PtrTy));
705+
createAsyncDispatchFn(resumeFnPtr,
706+
{IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy}),
707+
IGM.Int8PtrTy));
702708
arguments.push_back(AsyncCoroutineCurrentResume);
703709
arguments.push_back(
704710
Builder.CreateBitOrPointerCast(getAsyncTask(), IGM.Int8PtrTy));
705711
arguments.push_back(
706712
Builder.CreateBitOrPointerCast(getAsyncExecutor(), IGM.Int8PtrTy));
707713
arguments.push_back(Builder.CreateBitOrPointerCast(
708714
AsyncCoroutineCurrentContinuationContext, IGM.Int8PtrTy));
709-
auto *id = Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_suspend_async,
715+
Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_suspend_async, arguments);
710716

711-
arguments);
712717
auto results = Builder.CreateAtomicCmpXchg(
713718
contAwaitSyncAddr, null, one,
714719
llvm::AtomicOrdering::Release /*success ordering*/,

lib/IRGen/IRGenFunction.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ class IRGenFunction {
135135
llvm::Function *getOrCreateResumePrjFn();
136136
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,
137137
ArrayRef<llvm::Value *> args);
138-
llvm::Function *getOrCreateAwaitAsyncSupendFn();
138+
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,
139+
ArrayRef<llvm::Type *> argTypes);
139140

140141
void emitGetAsyncContinuation(SILType silTy, StackAddress optionalResultAddr,
141142
Explosion &out);
@@ -147,6 +148,9 @@ class IRGenFunction {
147148
llvm::PHINode *&optionalErrorPhi,
148149
llvm::BasicBlock *&optionalErrorBB);
149150

151+
FunctionPointer
152+
getFunctionPointerForResumeIntrinsic(llvm::Value *resumeIntrinsic);
153+
150154
private:
151155
void emitPrologue();
152156
void emitEpilogue();

0 commit comments

Comments
 (0)