Skip to content

[Concurrency] Async CC, part 1. #34141

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
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
3 changes: 3 additions & 0 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,9 @@ class ASTContext final {
/// generic metadata.
AvailabilityContext getIntermodulePrespecializedGenericMetadataAvailability();

/// Get the runtime availability of support for concurrency.
AvailabilityContext getConcurrencyAvailability();

/// Get the runtime availability of features introduced in the Swift 5.2
/// compiler for the target platform.
AvailabilityContext getSwift52Availability();
Expand Down
16 changes: 16 additions & 0 deletions include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,22 @@ FUNCTION(GetTypeByMangledNameInContextInMetadataState,
Int8PtrPtrTy),
ATTRS(NoUnwind, ArgMemOnly))

// void *swift_taskAlloc(SwiftTask *task, size_t size);
FUNCTION(TaskAlloc,
swift_taskAlloc, SwiftCC,
ConcurrencyAvailability,
RETURNS(Int8PtrTy),
ARGS(SwiftTaskPtrTy, SizeTy),
ATTRS(NoUnwind, ArgMemOnly))

// void swift_taskDealloc(SwiftTask *task, void *ptr);
FUNCTION(TaskDealloc,
swift_taskDealloc, SwiftCC,
ConcurrencyAvailability,
RETURNS(VoidTy),
ARGS(SwiftTaskPtrTy, Int8PtrTy),
ATTRS(NoUnwind, ArgMemOnly))

#undef RETURNS
#undef ARGS
#undef ATTRS
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/Availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ ASTContext::getIntermodulePrespecializedGenericMetadataAvailability() {
return getSwift54Availability();
}

AvailabilityContext ASTContext::getConcurrencyAvailability() {
return getSwiftFutureAvailability();
}

AvailabilityContext ASTContext::getSwift52Availability() {
auto target = LangOpts.Target;

Expand Down
30 changes: 21 additions & 9 deletions lib/IRGen/CallEmission.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ struct WitnessMetadata;

/// A plan for emitting a series of calls.
class CallEmission {
enum class State { Emitting, Finished };
State state = State::Emitting;

public:
IRGenFunction &IGF;

private:
protected:
llvm::Value *selfValue;

/// The builtin/special arguments to pass to the call.
SmallVector<llvm::Value*, 8> Args;

Expand All @@ -57,31 +62,35 @@ class CallEmission {
/// RemainingArgsForCallee, at least between calls.
bool EmittedCall;

void setFromCallee();
virtual void setFromCallee();
void emitToUnmappedMemory(Address addr);
void emitToUnmappedExplosion(Explosion &out);
virtual void emitCallToUnmappedExplosion(llvm::CallInst *call, Explosion &out) = 0;
void emitYieldsToExplosion(Explosion &out);
llvm::CallInst *emitCallSite();

CallEmission(IRGenFunction &IGF, llvm::Value *selfValue, Callee &&callee)
: IGF(IGF), selfValue(selfValue), CurCallee(std::move(callee)) {}

public:
CallEmission(IRGenFunction &IGF, Callee &&callee)
: IGF(IGF), CurCallee(std::move(callee)) {
setFromCallee();
}
CallEmission(const CallEmission &other) = delete;
CallEmission(CallEmission &&other);
CallEmission &operator=(const CallEmission &other) = delete;
~CallEmission();
virtual ~CallEmission();

const Callee &getCallee() const { return CurCallee; }

SubstitutionMap getSubstitutions() const {
return CurCallee.getSubstitutions();
}

virtual void begin();
virtual void end();
virtual SILType getParameterType(unsigned index) = 0;
/// Set the arguments to the function from an explosion.
void setArgs(Explosion &arg, bool isOutlined,
WitnessMetadata *witnessMetadata = nullptr);
virtual void setArgs(Explosion &arg, bool isOutlined,
WitnessMetadata *witnessMetadata);
virtual Address getCalleeErrorSlot(SILType errorType) = 0;

void addAttribute(unsigned Index, llvm::Attribute::AttrKind Attr);

Expand All @@ -100,6 +109,9 @@ class CallEmission {
}
};

std::unique_ptr<CallEmission>
getCallEmission(IRGenFunction &IGF, llvm::Value *selfValue, Callee &&callee);

} // end namespace irgen
} // end namespace swift

Expand Down
46 changes: 46 additions & 0 deletions lib/IRGen/EntryPointArgumentEmission.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===-- EntryPointArgumentEmission.h - Emit function entries. -------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#pragma once

namespace llvm {
class Value;
}

namespace swift {
namespace irgen {

class Explosion;

class EntryPointArgumentEmission {

public:
virtual ~EntryPointArgumentEmission() {}
virtual bool requiresIndirectResult(SILType retType) = 0;
virtual llvm::Value *getIndirectResultForFormallyDirectResult() = 0;
virtual llvm::Value *getIndirectResult(unsigned index) = 0;
};

class NativeCCEntryPointArgumentEmission
: public virtual EntryPointArgumentEmission {

public:
virtual llvm::Value *getCallerErrorResultArgument() = 0;
virtual llvm::Value *getContext() = 0;
virtual Explosion getArgumentExplosion(unsigned index, unsigned size) = 0;
virtual llvm::Value *getSelfWitnessTable() = 0;
virtual llvm::Value *getSelfMetadata() = 0;
virtual llvm::Value *getCoroutineBuffer() = 0;
};

} // end namespace irgen
} // end namespace swift
5 changes: 5 additions & 0 deletions lib/IRGen/Explosion.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ class Explosion {
return Values[NextValue-1];
}

llvm::Value *peek(unsigned n) {
assert(n < Values.size());
return Values[n];
}

/// Claim and remove the last item in the array.
/// Unlike the normal 'claim' methods, the item is gone forever.
llvm::Value *takeLast() {
Expand Down
8 changes: 4 additions & 4 deletions lib/IRGen/GenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ if (Builtin.ID == BuiltinValueKind::id) { \

auto *fn = cast<llvm::Function>(IGF.IGM.getWillThrowFn());
auto error = args.claimNext();
auto errorBuffer = IGF.getErrorResultSlot(
SILType::getPrimitiveObjectType(IGF.IGM.Context.getErrorDecl()
->getDeclaredInterfaceType()
->getCanonicalType()));
auto errorBuffer = IGF.getCalleeErrorResultSlot(
SILType::getPrimitiveObjectType(IGF.IGM.Context.getErrorDecl()
->getDeclaredInterfaceType()
->getCanonicalType()));
IGF.Builder.CreateStore(error, errorBuffer);

auto context = llvm::UndefValue::get(IGF.IGM.Int8PtrTy);
Expand Down
Loading