Skip to content

Commit 29806a3

Browse files
committed
[ownership] Change canFixUpOwnershipForRAUW so that 'oldValue' is a SILValue not a SingleValueInstruction
The only operational change here is that I needed to be able to grab the module from the SILValue so I could see if we were in Raw SIL or not. I realized the only case where we could not get the module is from SILUndef and at this point in the code we know we are going to bail already for SILUndef. This is because we already know our new value doesn't have OwnershipKind::None and we don't replace OwnershipKind::None things with non-OwnershipKind::None things since I haven't implemented support for that corner case yet (but will with time). Once I realized the previous paragraph, I was able to add support without issue.
1 parent 1e4d3d2 commit 29806a3

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ struct OwnershipFixupContext {
5252
/// Namely, we do not support RAUWing values with ValueOwnershipKind::None
5353
/// that have uses that do not require ValueOwnershipKind::None or
5454
/// ValueOwnershipKind::Any.
55-
static bool canFixUpOwnershipForRAUW(const SingleValueInstruction *oldValue,
56-
SILValue newValue);
55+
static bool canFixUpOwnershipForRAUW(SILValue oldValue, SILValue newValue);
5756
};
5857

5958
} // namespace swift

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,11 @@ SILBasicBlock::iterator OwnershipRAUWUtility::perform() {
721721
//===----------------------------------------------------------------------===//
722722
// Ownership Fixup Context
723723
//===----------------------------------------------------------------------===//
724-
//
725-
// Top level entry points to RAUW code.
726-
//
727-
bool OwnershipFixupContext::canFixUpOwnershipForRAUW(
728-
const SingleValueInstruction *oldValue, SILValue newValue) {
724+
725+
// All callers of our RAUW routines must ensure that their values return true
726+
// from this.
727+
bool OwnershipFixupContext::canFixUpOwnershipForRAUW(SILValue oldValue,
728+
SILValue newValue) {
729729
auto newOwnershipKind = newValue.getOwnershipKind();
730730

731731
// If our new kind is ValueOwnershipKind::None, then we are fine. We
@@ -734,9 +734,26 @@ bool OwnershipFixupContext::canFixUpOwnershipForRAUW(
734734
if (newOwnershipKind == OwnershipKind::None)
735735
return true;
736736

737+
// First check if oldValue is SILUndef. If it is, then we know that:
738+
//
739+
// 1. SILUndef (and thus oldValue) must have OwnershipKind::None.
740+
// 2. newValue is not OwnershipKind::None due to our check above.
741+
//
742+
// Thus we know that we would be replacing a value with OwnershipKind::None
743+
// with a value with non-None ownership. This is a case we don't support, so
744+
// we can bail now.
745+
if (isa<SILUndef>(oldValue))
746+
return false;
747+
748+
// Ok, we now know that we do not have SILUndef implying that we must be able
749+
// to get a module from our value since we must have an argument or an
750+
// instruction.
751+
auto *m = oldValue->getModule();
752+
assert(m);
753+
737754
// If we are in Raw SIL, just bail at this point. We do not support
738755
// ownership fixups.
739-
if (oldValue->getModule().getStage() == SILStage::Raw)
756+
if (m->getStage() == SILStage::Raw)
740757
return false;
741758

742759
// If our old ownership kind is ValueOwnershipKind::None and our new kind is

0 commit comments

Comments
 (0)