Skip to content

[Async CC] Add task and executor arguments. #34444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,12 @@ void SignatureExpansion::expandCoroutineContinuationParameters() {
}

void SignatureExpansion::addAsyncParameters() {
// using TaskContinuationFunction =
// SWIFT_CC(swift)
// void (AsyncTask *, ExecutorRef, AsyncContext *);
ParamIRTypes.push_back(IGM.SwiftTaskPtrTy);
ParamIRTypes.push_back(IGM.SwiftExecutorPtrTy);
ParamIRTypes.push_back(IGM.SwiftContextPtrTy);
// TODO: Add actor.
// TODO: Add task.
if (FnType->getRepresentation() == SILFunctionTypeRepresentation::Thick) {
IGM.addSwiftSelfAttributes(Attrs, ParamIRTypes.size());
ParamIRTypes.push_back(IGM.RefCountedPtrTy);
Expand Down Expand Up @@ -2141,6 +2144,9 @@ class AsyncCallEmission final : public CallEmission {
void setArgs(Explosion &llArgs, bool isOutlined,
WitnessMetadata *witnessMetadata) override {
Explosion asyncExplosion;
asyncExplosion.add(llvm::Constant::getNullValue(IGF.IGM.SwiftTaskPtrTy));
asyncExplosion.add(
llvm::Constant::getNullValue(IGF.IGM.SwiftExecutorPtrTy));
asyncExplosion.add(contextBuffer.getAddress());
if (getCallee().getRepresentation() ==
SILFunctionTypeRepresentation::Thick) {
Expand Down
7 changes: 7 additions & 0 deletions lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,8 @@ class AsyncPartialApplicationForwarderEmission
: public PartialApplicationForwarderEmission {
using super = PartialApplicationForwarderEmission;
AsyncContextLayout layout;
llvm::Value *task;
llvm::Value *executor;
llvm::Value *contextBuffer;
Size contextSize;
Address context;
Expand Down Expand Up @@ -1067,6 +1069,8 @@ class AsyncPartialApplicationForwarderEmission
substType, outType, subs, layout, conventions),
layout(getAsyncContextLayout(subIGF, origType, substType, subs)),
currentArgumentIndex(outType->getNumParameters()) {
task = origParams.claimNext();
executor = origParams.claimNext();
contextBuffer = origParams.claimNext();
heapContextBuffer = origParams.claimNext();
}
Expand Down Expand Up @@ -1223,6 +1227,9 @@ class AsyncPartialApplicationForwarderEmission
}
llvm::CallInst *createCall(FunctionPointer &fnPtr) override {
Explosion asyncExplosion;
asyncExplosion.add(llvm::Constant::getNullValue(subIGF.IGM.SwiftTaskPtrTy));
asyncExplosion.add(
llvm::Constant::getNullValue(subIGF.IGM.SwiftExecutorPtrTy));
asyncExplosion.add(contextBuffer);
if (dynamicFunction &&
dynamicFunction->kind == DynamicFunction::Kind::PartialApply) {
Expand Down
2 changes: 2 additions & 0 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,10 @@ IRGenModule::IRGenModule(IRGenerator &irgen,

SwiftContextTy = createStructType(*this, "swift.context", {});
SwiftTaskTy = createStructType(*this, "swift.task", {});
SwiftExecutorTy = createStructType(*this, "swift.executor", {});
SwiftContextPtrTy = SwiftContextTy->getPointerTo(DefaultAS);
SwiftTaskPtrTy = SwiftTaskTy->getPointerTo(DefaultAS);
SwiftExecutorPtrTy = SwiftExecutorTy->getPointerTo(DefaultAS);

DifferentiabilityWitnessTy = createStructType(
*this, "swift.differentiability_witness", {Int8PtrTy, Int8PtrTy});
Expand Down
2 changes: 2 additions & 0 deletions lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,10 @@ class IRGenModule {

llvm::StructType *SwiftContextTy;
llvm::StructType *SwiftTaskTy;
llvm::StructType *SwiftExecutorTy;
llvm::PointerType *SwiftContextPtrTy;
llvm::PointerType *SwiftTaskPtrTy;
llvm::PointerType *SwiftExecutorPtrTy;

llvm::StructType *DifferentiabilityWitnessTy; // { i8*, i8* }

Expand Down
6 changes: 4 additions & 2 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,8 @@ class SyncNativeCCEntryPointArgumentEmission final
class AsyncNativeCCEntryPointArgumentEmission final
: public NativeCCEntryPointArgumentEmission,
public AsyncEntryPointArgumentEmission {
llvm::Value *task;
llvm::Value *executor;
llvm::Value *context;
/*const*/ AsyncContextLayout layout;
const Address dataAddr;
Expand All @@ -1253,6 +1255,7 @@ class AsyncNativeCCEntryPointArgumentEmission final
SILBasicBlock &entry,
Explosion &allParamValues)
: AsyncEntryPointArgumentEmission(IGF, entry, allParamValues),
task(allParamValues.claimNext()), executor(allParamValues.claimNext()),
context(allParamValues.claimNext()), layout(getAsyncContextLayout(IGF)),
dataAddr(layout.emitCastTo(IGF, context)){};

Expand Down Expand Up @@ -3176,8 +3179,7 @@ static void emitReturnInst(IRGenSILFunction &IGF,
assert(!IGF.IndirectReturn.isValid() &&
"Formally direct results should stay direct results for async "
"functions");
Explosion parameters = IGF.collectParameters();
llvm::Value *context = parameters.claimNext();
llvm::Value *context = IGF.CurFn->getArg(2);
auto layout = getAsyncContextLayout(IGF);

Address dataAddr = layout.emitCastTo(IGF, context);
Expand Down
Loading