Skip to content

Commit 64ec981

Browse files
committed
Rename isDirectlyForwarding to preservesOwnership.
1 parent 16e5fe9 commit 64ec981

File tree

7 files changed

+25
-23
lines changed

7 files changed

+25
-23
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ class ForwardingOperand {
189189
return use->getOwnershipConstraint();
190190
}
191191

192-
bool isDirectlyForwarding() const {
192+
bool preservesOwnership() const {
193193
auto &mixin = *OwnershipForwardingMixin::get(use->getUser());
194-
return mixin.isDirectlyForwarding();
194+
return mixin.preservesOwnership();
195195
}
196196

197197
ValueOwnershipKind getForwardingOwnershipKind() const;

include/swift/SIL/SILInstruction.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,16 +1112,18 @@ class CopyLikeInstruction {
11121112
/// initializes the kind field on our object is run before our constructor runs.
11131113
class OwnershipForwardingMixin {
11141114
ValueOwnershipKind ownershipKind;
1115-
bool directlyForwards;
1115+
bool preservesOwnershipFlag;
11161116

11171117
protected:
11181118
OwnershipForwardingMixin(SILInstructionKind kind,
11191119
ValueOwnershipKind ownershipKind,
1120-
bool isDirectlyForwarding = true)
1121-
: ownershipKind(ownershipKind), directlyForwards(isDirectlyForwarding) {
1120+
bool preservesOwnership = true)
1121+
: ownershipKind(ownershipKind),
1122+
preservesOwnershipFlag(preservesOwnership) {
11221123
assert(isa(kind) && "Invalid subclass?!");
11231124
assert(ownershipKind && "invalid forwarding ownership");
1124-
assert((directlyForwards || ownershipKind != OwnershipKind::Guaranteed) &&
1125+
assert((preservesOwnershipFlag
1126+
|| ownershipKind != OwnershipKind::Guaranteed) &&
11251127
"Non directly forwarding instructions can not forward guaranteed "
11261128
"ownership");
11271129
}
@@ -1160,7 +1162,7 @@ class OwnershipForwardingMixin {
11601162
return ownershipKind;
11611163
}
11621164
void setForwardingOwnershipKind(ValueOwnershipKind newKind) {
1163-
assert((isDirectlyForwarding() || newKind != OwnershipKind::Guaranteed) &&
1165+
assert((preservesOwnership() || newKind != OwnershipKind::Guaranteed) &&
11641166
"Non directly forwarding instructions can not forward guaranteed "
11651167
"ownership");
11661168
ownershipKind = newKind;
@@ -8083,9 +8085,9 @@ class OwnershipForwardingTermInst : public TermInst,
80838085
OwnershipForwardingTermInst(SILInstructionKind kind,
80848086
SILDebugLocation debugLoc,
80858087
ValueOwnershipKind ownershipKind,
8086-
bool isDirectlyForwarding = true)
8088+
bool preservesOwnership = true)
80878089
: TermInst(kind, debugLoc),
8088-
OwnershipForwardingMixin(kind, ownershipKind, isDirectlyForwarding) {
8090+
OwnershipForwardingMixin(kind, ownershipKind, preservesOwnership) {
80898091
assert(classof(kind));
80908092
}
80918093

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ SILValue swift::findOwnershipReferenceAggregate(SILValue ref) {
925925
if (auto *term = arg->getSingleTerminator()) {
926926
if (term->isTransformationTerminator()) {
927927
auto *ti = cast<OwnershipForwardingTermInst>(term);
928-
if (ti->isDirectlyForwarding()) {
928+
if (ti->preservesOwnership()) {
929929
root = term->getOperand(0);
930930
continue;
931931
}

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ bool swift::canOpcodeForwardGuaranteedValues(SILValue value) {
3535
if (auto *arg = dyn_cast<SILArgument>(value))
3636
if (auto *ti = arg->getSingleTerminator())
3737
if (ti->isTransformationTerminator())
38-
return OwnershipForwardingMixin::get(ti)->isDirectlyForwarding();
38+
return OwnershipForwardingMixin::get(ti)->preservesOwnership();
3939

4040
if (auto *inst = value->getDefiningInstruction())
4141
if (auto *mixin = OwnershipForwardingMixin::get(inst))
42-
return mixin->isDirectlyForwarding() &&
42+
return mixin->preservesOwnership() &&
4343
!isa<OwnedFirstArgForwardingSingleValueInst>(inst);
4444

4545
return false;
4646
}
4747

4848
bool swift::canOpcodeForwardGuaranteedValues(Operand *use) {
4949
if (auto *mixin = OwnershipForwardingMixin::get(use->getUser()))
50-
return mixin->isDirectlyForwarding() &&
50+
return mixin->preservesOwnership() &&
5151
!isa<OwnedFirstArgForwardingSingleValueInst>(use->getUser());
5252
return false;
5353
}
@@ -58,11 +58,11 @@ bool swift::canOpcodeForwardOwnedValues(SILValue value) {
5858
if (auto *arg = dyn_cast<SILPhiArgument>(value))
5959
if (auto *predTerm = arg->getSingleTerminator())
6060
if (predTerm->isTransformationTerminator())
61-
return OwnershipForwardingMixin::get(predTerm)->isDirectlyForwarding();
61+
return OwnershipForwardingMixin::get(predTerm)->preservesOwnership();
6262

6363
if (auto *inst = value->getDefiningInstruction())
6464
if (auto *mixin = OwnershipForwardingMixin::get(inst))
65-
return mixin->isDirectlyForwarding() &&
65+
return mixin->preservesOwnership() &&
6666
!isa<GuaranteedFirstArgForwardingSingleValueInst>(inst);
6767

6868
return false;
@@ -71,7 +71,7 @@ bool swift::canOpcodeForwardOwnedValues(SILValue value) {
7171
bool swift::canOpcodeForwardOwnedValues(Operand *use) {
7272
auto *user = use->getUser();
7373
if (auto *mixin = OwnershipForwardingMixin::get(user))
74-
return mixin->isDirectlyForwarding() &&
74+
return mixin->preservesOwnership() &&
7575
!isa<GuaranteedFirstArgForwardingSingleValueInst>(user);
7676
return false;
7777
}
@@ -1078,7 +1078,7 @@ bool swift::getAllBorrowIntroducingValues(SILValue inputValue,
10781078
auto *arg = cast<SILPhiArgument>(value);
10791079
auto *termInst = arg->getSingleTerminator();
10801080
assert(termInst && termInst->isTransformationTerminator() &&
1081-
OwnershipForwardingMixin::get(termInst)->isDirectlyForwarding());
1081+
OwnershipForwardingMixin::get(termInst)->preservesOwnership());
10821082
assert(termInst->getNumOperands() == 1 &&
10831083
"Transforming terminators should always have a single operand");
10841084
worklist.push_back(termInst->getAllOperands()[0].get());
@@ -1130,7 +1130,7 @@ BorrowedValue swift::getSingleBorrowIntroducingValue(SILValue inputValue) {
11301130
auto *arg = cast<SILPhiArgument>(currentValue);
11311131
auto *termInst = arg->getSingleTerminator();
11321132
assert(termInst && termInst->isTransformationTerminator() &&
1133-
OwnershipForwardingMixin::get(termInst)->isDirectlyForwarding());
1133+
OwnershipForwardingMixin::get(termInst)->preservesOwnership());
11341134
assert(termInst->getNumOperands() == 1 &&
11351135
"Transformation terminators should only have single operands");
11361136
currentValue = termInst->getAllOperands()[0].get();
@@ -1183,7 +1183,7 @@ bool swift::getAllOwnedValueIntroducers(
11831183
auto *arg = cast<SILPhiArgument>(value);
11841184
auto *termInst = arg->getSingleTerminator();
11851185
assert(termInst && termInst->isTransformationTerminator() &&
1186-
OwnershipForwardingMixin::get(termInst)->isDirectlyForwarding());
1186+
OwnershipForwardingMixin::get(termInst)->preservesOwnership());
11871187
assert(termInst->getNumOperands() == 1 &&
11881188
"Transforming terminators should always have a single operand");
11891189
worklist.push_back(termInst->getAllOperands()[0].get());
@@ -1231,7 +1231,7 @@ OwnedValueIntroducer swift::getSingleOwnedValueIntroducer(SILValue inputValue) {
12311231
auto *arg = cast<SILPhiArgument>(currentValue);
12321232
auto *termInst = arg->getSingleTerminator();
12331233
assert(termInst && termInst->isTransformationTerminator() &&
1234-
OwnershipForwardingMixin::get(termInst)->isDirectlyForwarding());
1234+
OwnershipForwardingMixin::get(termInst)->preservesOwnership());
12351235
assert(termInst->getNumOperands()
12361236
- termInst->getNumTypeDependentOperands() == 1 &&
12371237
"Transformation terminators should only have single operands");

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4139,7 +4139,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
41394139
OwnershipKind::Guaranteed,
41404140
"checked_cast_br with an AnyObject typed source cannot forward "
41414141
"guaranteed ownership");
4142-
require(CBI->isDirectlyForwarding() ||
4142+
require(CBI->preservesOwnership() ||
41434143
CBI->getOperand().getOwnershipKind() !=
41444144
OwnershipKind::Guaranteed,
41454145
"If checked_cast_br is not directly forwarding, it can not have "

lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ bool CopyOfBorrowedProjectionChecker::check(SILValue markedValue) {
257257
if (auto op = ForwardingOperand(use)) {
258258
// If our user is not directly forwarding, we cannot convert its
259259
// ownership to be guaranteed, so we treat it as a true consuming use.
260-
if (!op.isDirectlyForwarding()) {
260+
if (!op.preservesOwnership()) {
261261
foundConsumesOfBorrowedSubValues.push_back(user);
262262
liveness.updateForUse(user, /*lifetimeEnding*/ true);
263263
break;

lib/SILOptimizer/SemanticARC/OwnershipLiveRange.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ OwnershipLiveRange::OwnershipLiveRange(SILValue value)
9191
// here), we could get back a different value. Thus we can not transform
9292
// such a thing from owned to guaranteed.
9393
if (auto *i = OwnershipForwardingMixin::get(op->getUser())) {
94-
if (!i->isDirectlyForwarding()) {
94+
if (!i->preservesOwnership()) {
9595
tmpUnknownConsumingUses.push_back(op);
9696
continue;
9797
}

0 commit comments

Comments
 (0)