Skip to content

Commit 9f95271

Browse files
committed
[ownership] Allow for OwnershipRAUWHelper to RAUW in non-ossa mode to cleanup code.
This just makes it easier to write code that supports both ownership/non-ownership code.
1 parent 7d5c60b commit 9f95271

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,11 @@ OwnershipRAUWHelper::OwnershipRAUWHelper(OwnershipFixupContext &inputCtx,
929929
if (!isValid())
930930
return;
931931

932+
// If we are not in ownership, we can always RAUW successfully so just bail
933+
// and leave the object valid.
934+
if (!oldValue->getFunction()->hasOwnership())
935+
return;
936+
932937
// Otherwise, lets check if we can perform this RAUW operation. If we can't,
933938
// set ctx to nullptr to invalidate the helper and return.
934939
if (!canFixUpOwnershipForRAUW(oldValue, newValue, inputCtx)) {
@@ -1030,12 +1035,16 @@ SILBasicBlock::iterator
10301035
OwnershipRAUWHelper::perform(SingleValueInstruction *maybeTransformedNewValue) {
10311036
assert(isValid() && "OwnershipRAUWHelper invalid?!");
10321037

1033-
// Make sure to always clear our context after we transform.
1034-
SWIFT_DEFER { ctx->clear(); };
10351038
SILValue actualNewValue = newValue;
10361039
if (maybeTransformedNewValue)
10371040
actualNewValue = maybeTransformedNewValue;
10381041

1042+
if (!oldValue->getFunction()->hasOwnership())
1043+
return replaceAllUsesAndErase(oldValue, actualNewValue, ctx->callbacks);
1044+
1045+
// Make sure to always clear our context after we transform.
1046+
SWIFT_DEFER { ctx->clear(); };
1047+
10391048
if (oldValue->getType().isAddress())
10401049
return replaceAddressUses(oldValue, actualNewValue);
10411050

0 commit comments

Comments
 (0)