Skip to content

Commit 515f0db

Browse files
Merge pull request #34141 from nate-chandler/concurrency/irgen/signature
[Concurrency] Async CC, part 1.
2 parents 9c9f3f5 + ee88152 commit 515f0db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2976
-324
lines changed

include/swift/AST/ASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,9 @@ class ASTContext final {
694694
/// generic metadata.
695695
AvailabilityContext getIntermodulePrespecializedGenericMetadataAvailability();
696696

697+
/// Get the runtime availability of support for concurrency.
698+
AvailabilityContext getConcurrencyAvailability();
699+
697700
/// Get the runtime availability of features introduced in the Swift 5.2
698701
/// compiler for the target platform.
699702
AvailabilityContext getSwift52Availability();

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,22 @@ FUNCTION(GetTypeByMangledNameInContextInMetadataState,
14611461
Int8PtrPtrTy),
14621462
ATTRS(NoUnwind, ArgMemOnly))
14631463

1464+
// void *swift_taskAlloc(SwiftTask *task, size_t size);
1465+
FUNCTION(TaskAlloc,
1466+
swift_taskAlloc, SwiftCC,
1467+
ConcurrencyAvailability,
1468+
RETURNS(Int8PtrTy),
1469+
ARGS(SwiftTaskPtrTy, SizeTy),
1470+
ATTRS(NoUnwind, ArgMemOnly))
1471+
1472+
// void swift_taskDealloc(SwiftTask *task, void *ptr);
1473+
FUNCTION(TaskDealloc,
1474+
swift_taskDealloc, SwiftCC,
1475+
ConcurrencyAvailability,
1476+
RETURNS(VoidTy),
1477+
ARGS(SwiftTaskPtrTy, Int8PtrTy),
1478+
ATTRS(NoUnwind, ArgMemOnly))
1479+
14641480
#undef RETURNS
14651481
#undef ARGS
14661482
#undef ATTRS

lib/AST/Availability.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ ASTContext::getIntermodulePrespecializedGenericMetadataAvailability() {
323323
return getSwift54Availability();
324324
}
325325

326+
AvailabilityContext ASTContext::getConcurrencyAvailability() {
327+
return getSwiftFutureAvailability();
328+
}
329+
326330
AvailabilityContext ASTContext::getSwift52Availability() {
327331
auto target = LangOpts.Target;
328332

lib/IRGen/CallEmission.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ struct WitnessMetadata;
3333

3434
/// A plan for emitting a series of calls.
3535
class CallEmission {
36+
enum class State { Emitting, Finished };
37+
State state = State::Emitting;
38+
3639
public:
3740
IRGenFunction &IGF;
3841

39-
private:
42+
protected:
43+
llvm::Value *selfValue;
44+
4045
/// The builtin/special arguments to pass to the call.
4146
SmallVector<llvm::Value*, 8> Args;
4247

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

60-
void setFromCallee();
65+
virtual void setFromCallee();
6166
void emitToUnmappedMemory(Address addr);
6267
void emitToUnmappedExplosion(Explosion &out);
68+
virtual void emitCallToUnmappedExplosion(llvm::CallInst *call, Explosion &out) = 0;
6369
void emitYieldsToExplosion(Explosion &out);
6470
llvm::CallInst *emitCallSite();
6571

72+
CallEmission(IRGenFunction &IGF, llvm::Value *selfValue, Callee &&callee)
73+
: IGF(IGF), selfValue(selfValue), CurCallee(std::move(callee)) {}
74+
6675
public:
67-
CallEmission(IRGenFunction &IGF, Callee &&callee)
68-
: IGF(IGF), CurCallee(std::move(callee)) {
69-
setFromCallee();
70-
}
7176
CallEmission(const CallEmission &other) = delete;
7277
CallEmission(CallEmission &&other);
7378
CallEmission &operator=(const CallEmission &other) = delete;
74-
~CallEmission();
79+
virtual ~CallEmission();
7580

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

7883
SubstitutionMap getSubstitutions() const {
7984
return CurCallee.getSubstitutions();
8085
}
8186

87+
virtual void begin();
88+
virtual void end();
89+
virtual SILType getParameterType(unsigned index) = 0;
8290
/// Set the arguments to the function from an explosion.
83-
void setArgs(Explosion &arg, bool isOutlined,
84-
WitnessMetadata *witnessMetadata = nullptr);
91+
virtual void setArgs(Explosion &arg, bool isOutlined,
92+
WitnessMetadata *witnessMetadata);
93+
virtual Address getCalleeErrorSlot(SILType errorType) = 0;
8594

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

@@ -100,6 +109,9 @@ class CallEmission {
100109
}
101110
};
102111

112+
std::unique_ptr<CallEmission>
113+
getCallEmission(IRGenFunction &IGF, llvm::Value *selfValue, Callee &&callee);
114+
103115
} // end namespace irgen
104116
} // end namespace swift
105117

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===-- EntryPointArgumentEmission.h - Emit function entries. -------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#pragma once
14+
15+
namespace llvm {
16+
class Value;
17+
}
18+
19+
namespace swift {
20+
namespace irgen {
21+
22+
class Explosion;
23+
24+
class EntryPointArgumentEmission {
25+
26+
public:
27+
virtual ~EntryPointArgumentEmission() {}
28+
virtual bool requiresIndirectResult(SILType retType) = 0;
29+
virtual llvm::Value *getIndirectResultForFormallyDirectResult() = 0;
30+
virtual llvm::Value *getIndirectResult(unsigned index) = 0;
31+
};
32+
33+
class NativeCCEntryPointArgumentEmission
34+
: public virtual EntryPointArgumentEmission {
35+
36+
public:
37+
virtual llvm::Value *getCallerErrorResultArgument() = 0;
38+
virtual llvm::Value *getContext() = 0;
39+
virtual Explosion getArgumentExplosion(unsigned index, unsigned size) = 0;
40+
virtual llvm::Value *getSelfWitnessTable() = 0;
41+
virtual llvm::Value *getSelfMetadata() = 0;
42+
virtual llvm::Value *getCoroutineBuffer() = 0;
43+
};
44+
45+
} // end namespace irgen
46+
} // end namespace swift

lib/IRGen/Explosion.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ class Explosion {
152152
return Values[NextValue-1];
153153
}
154154

155+
llvm::Value *peek(unsigned n) {
156+
assert(n < Values.size());
157+
return Values[n];
158+
}
159+
155160
/// Claim and remove the last item in the array.
156161
/// Unlike the normal 'claim' methods, the item is gone forever.
157162
llvm::Value *takeLast() {

lib/IRGen/GenBuiltin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,10 @@ if (Builtin.ID == BuiltinValueKind::id) { \
408408

409409
auto *fn = cast<llvm::Function>(IGF.IGM.getWillThrowFn());
410410
auto error = args.claimNext();
411-
auto errorBuffer = IGF.getErrorResultSlot(
412-
SILType::getPrimitiveObjectType(IGF.IGM.Context.getErrorDecl()
413-
->getDeclaredInterfaceType()
414-
->getCanonicalType()));
411+
auto errorBuffer = IGF.getCalleeErrorResultSlot(
412+
SILType::getPrimitiveObjectType(IGF.IGM.Context.getErrorDecl()
413+
->getDeclaredInterfaceType()
414+
->getCanonicalType()));
415415
IGF.Builder.CreateStore(error, errorBuffer);
416416

417417
auto context = llvm::UndefValue::get(IGF.IGM.Int8PtrTy);

0 commit comments

Comments
 (0)