Skip to content

Small SILValue::getOwnershipValue() fixes #6831

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 3 commits into from
Jan 16, 2017
Merged
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
45 changes: 40 additions & 5 deletions lib/SIL/SILValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ CONSTANT_OWNERSHIP_INST(Owned, LoadUnowned)
CONSTANT_OWNERSHIP_INST(Owned, LoadWeak)
CONSTANT_OWNERSHIP_INST(Owned, PartialApply)
CONSTANT_OWNERSHIP_INST(Owned, StrongPin)
CONSTANT_OWNERSHIP_INST(Owned, ThinToThickFunction)

// One would think that these /should/ be unowned. In truth they are owned since
// objc metatypes do not go through the retain/release fast path. In their
// implementations of retain/release nothing happens, so this is safe.
//
// You could even have an optimization that just always removed retain/release
// operations on these objects.
CONSTANT_OWNERSHIP_INST(Owned, ObjCExistentialMetatypeToObject)
CONSTANT_OWNERSHIP_INST(Owned, ObjCMetatypeToObject)

// All addresses have trivial ownership. The values stored at the address may
// not though.
CONSTANT_OWNERSHIP_INST(Trivial, AddressToPointer)
Expand All @@ -213,9 +224,6 @@ CONSTANT_OWNERSHIP_INST(Trivial, MarkFunctionEscape)
CONSTANT_OWNERSHIP_INST(Trivial, MarkUninitialized)
CONSTANT_OWNERSHIP_INST(Trivial, MarkUninitializedBehavior)
CONSTANT_OWNERSHIP_INST(Trivial, Metatype)
CONSTANT_OWNERSHIP_INST(Trivial,
ObjCExistentialMetatypeToObject) // Is this right?
CONSTANT_OWNERSHIP_INST(Trivial, ObjCMetatypeToObject) // Is this right?
CONSTANT_OWNERSHIP_INST(Trivial, ObjCProtocol) // Is this right?
CONSTANT_OWNERSHIP_INST(Trivial, ObjCToThickMetatype)
CONSTANT_OWNERSHIP_INST(Trivial, OpenExistentialAddr)
Expand All @@ -238,10 +246,8 @@ CONSTANT_OWNERSHIP_INST(Trivial, SuperMethod)
CONSTANT_OWNERSHIP_INST(Trivial, TailAddr)
CONSTANT_OWNERSHIP_INST(Trivial, ThickToObjCMetatype)
CONSTANT_OWNERSHIP_INST(Trivial, ThinFunctionToPointer)
CONSTANT_OWNERSHIP_INST(Trivial, ThinToThickFunction)
CONSTANT_OWNERSHIP_INST(Trivial, TupleElementAddr)
CONSTANT_OWNERSHIP_INST(Trivial, UncheckedAddrCast)
CONSTANT_OWNERSHIP_INST(Trivial, UncheckedBitwiseCast)
CONSTANT_OWNERSHIP_INST(Trivial, UncheckedRefCastAddr)
CONSTANT_OWNERSHIP_INST(Trivial, UncheckedTakeEnumDataAddr)
CONSTANT_OWNERSHIP_INST(Trivial, UncheckedTrivialBitCast)
Expand Down Expand Up @@ -392,6 +398,35 @@ FORWARDING_OWNERSHIP_INST(UnconditionalCheckedCast)
FORWARDING_OWNERSHIP_INST(Upcast)
#undef FORWARDING_OWNERSHIP_INST

ValueOwnershipKind
ValueOwnershipKindVisitor::
visitUncheckedBitwiseCastInst(UncheckedBitwiseCastInst *UBCI) {
ValueOwnershipKind OpOwnership = UBCI->getOperand().getOwnershipKind();
bool ResultTypeIsTrivial = UBCI->getType().isTrivial(UBCI->getModule());

// First check if our operand has a trivial value ownership kind...
if (OpOwnership == ValueOwnershipKind::Trivial) {
// If we do have a trivial value ownership kind, see if our result type is
// trivial or non-trivial. If it is trivial, then we have trivial
// ownership. Otherwise, we have unowned ownership since from an ownership
// perspective, the value has instantaneously come into existance and
// nothing has taken ownership of it.
if (ResultTypeIsTrivial) {
return ValueOwnershipKind::Trivial;
}
return ValueOwnershipKind::Unowned;
}

// If our operand has non-trivial ownership, but our result does, then of
// course the result has trivial ownership.
if (ResultTypeIsTrivial) {
return ValueOwnershipKind::Trivial;
}

// Otherwise, we forward our ownership.
return visitForwardingInst(UBCI);
}

// An enum without payload is trivial. One with non-trivial payload is
// forwarding.
ValueOwnershipKind
Expand Down