Skip to content

Commit 44fdc74

Browse files
committed
[ownership] Allow the user of OwnershipRAUWHelper to insert forwarding transforms of the new value at oldValue in between checking and RAUWing.
1 parent d6ffddc commit 44fdc74

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ class OwnershipRAUWHelper {
121121
/// "forwarding" transformation must be performed upon \p newValue at \p
122122
/// oldValue's insertion point so that we can then here RAUW the transformed
123123
/// \p newValue.
124-
SILBasicBlock::iterator perform();
124+
SILBasicBlock::iterator
125+
perform(SingleValueInstruction *maybeTransformedNewValue = nullptr);
125126

126127
private:
127128
SILBasicBlock::iterator replaceAddressUses(SingleValueInstruction *oldValue,

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,15 +1014,19 @@ OwnershipRAUWHelper::OwnershipRAUWHelper(OwnershipFixupContext &inputCtx,
10141014
}
10151015
}
10161016

1017-
SILBasicBlock::iterator OwnershipRAUWHelper::perform() {
1017+
SILBasicBlock::iterator
1018+
OwnershipRAUWHelper::perform(SingleValueInstruction *maybeTransformedNewValue) {
10181019
assert(isValid() && "OwnershipRAUWHelper invalid?!");
10191020

10201021
// Make sure to always clear our context after we transform.
10211022
SWIFT_DEFER { ctx->clear(); };
1023+
SILValue actualNewValue = newValue;
1024+
if (maybeTransformedNewValue)
1025+
actualNewValue = maybeTransformedNewValue;
10221026

10231027
if (oldValue->getType().isAddress())
1024-
return replaceAddressUses(oldValue, newValue);
1028+
return replaceAddressUses(oldValue, actualNewValue);
10251029

1026-
OwnershipRAUWUtility utility{oldValue, newValue, *ctx};
1030+
OwnershipRAUWUtility utility{oldValue, actualNewValue, *ctx};
10271031
return utility.perform();
10281032
}

0 commit comments

Comments
 (0)