Skip to content

Commit 81f5528

Browse files
committed
[Concurrency] More cleanups for getCurrentAsyncTask builtin.
Michael has ghostwritten all of this to address his own comments. Thank you!
1 parent ed9a548 commit 81f5528

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,16 @@ ANY_OWNERSHIP_BUILTIN(IntInstrprofIncrement)
10331033
}
10341034
CONSTANT_OWNERSHIP_BUILTIN(Owned, MustBeInvalidated, COWBufferForReading)
10351035
CONSTANT_OWNERSHIP_BUILTIN(Owned, MustBeInvalidated, UnsafeGuaranteed)
1036-
CONSTANT_OWNERSHIP_BUILTIN(Owned, MustBeInvalidated, GetCurrentAsyncTask)
10371036
#undef CONSTANT_OWNERSHIP_BUILTIN
10381037

1038+
#define SHOULD_NEVER_VISIT_BUILTIN(ID) \
1039+
OperandOwnershipKindMap OperandOwnershipKindBuiltinClassifier::visit##ID( \
1040+
BuiltinInst *, StringRef) { \
1041+
llvm_unreachable("Builtin should never be visited! E.x.: It may not have arguments"); \
1042+
}
1043+
SHOULD_NEVER_VISIT_BUILTIN(GetCurrentAsyncTask)
1044+
#undef SHOULD_NEVER_VISIT_BUILTIN
1045+
10391046
// Builtins that should be lowered to SIL instructions so we should never see
10401047
// them.
10411048
#define BUILTIN_SIL_OPERATION(ID, NAME, CATEGORY) \

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,7 @@ static ManagedValue emitBuiltinGetCurrentAsyncTask(
14021402
loc,
14031403
ctx.getIdentifier(getBuiltinName(BuiltinValueKind::GetCurrentAsyncTask)),
14041404
SGF.getLoweredType(ctx.TheNativeObjectType), SubstitutionMap(), { });
1405-
SGF.enterEndLifetimeCleanup(apply);
1406-
return ManagedValue::forUnmanaged(apply);
1405+
return SGF.emitManagedRValueWithEndLifetimeCleanup(apply);
14071406
}
14081407

14091408
Optional<SpecializedEmitter>

lib/SILGen/SILGenDecl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,9 +1347,10 @@ class EndLifetimeCleanup : public Cleanup {
13471347
};
13481348
} // end anonymous namespace
13491349

1350-
CleanupHandle SILGenFunction::enterEndLifetimeCleanup(SILValue value) {
1350+
ManagedValue SILGenFunction::emitManagedRValueWithEndLifetimeCleanup(
1351+
SILValue value) {
13511352
Cleanups.pushCleanup<EndLifetimeCleanup>(value);
1352-
return Cleanups.getTopCleanup();
1353+
return ManagedValue::forUnmanaged(value);
13531354
}
13541355

13551356
namespace {

lib/SILGen/SILGenFunction.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,8 +2001,19 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
20012001
/// Enter a cleanup to emit a ReleaseValue/DestroyAddr of the specified value.
20022002
CleanupHandle enterDestroyCleanup(SILValue valueOrAddr);
20032003

2004-
/// Enter cleanup to emit an EndLifetime operation for the given value.
2005-
CleanupHandle enterEndLifetimeCleanup(SILValue value);
2004+
/// Return an owned managed value for \p value that is cleaned up using an end_lifetime instruction.
2005+
///
2006+
/// The end_lifetime cleanup is not placed into the ManagedValue itself and
2007+
/// thus can not be forwarded. This means that the ManagedValue is treated
2008+
/// as a +0 value. This means that the owned value will be copied by SILGen
2009+
/// if it is ever needed as a +1 value (meaning any time that the value
2010+
/// escapes).
2011+
///
2012+
/// DISCUSSION: end_lifetime ends the lifetime of an owned value in OSSA
2013+
/// without resulting in a destroy being emitted. This cleanup should only
2014+
/// be used for owned values that do not need to be destroyed if they do not
2015+
/// escape the current call frame but need to be copied if they escape.
2016+
ManagedValue emitManagedRValueWithEndLifetimeCleanup(SILValue value);
20062017

20072018
/// Enter a cleanup to emit a DeinitExistentialAddr or DeinitExistentialBox
20082019
/// of the specified value.

0 commit comments

Comments
 (0)