Skip to content

Commit 4bc29a9

Browse files
committed
Delete OperandOwnership::GuaranteedForwardingPhi
Use OperandOwnership::GuaranteedForwarding instead.
1 parent 4f9e008 commit 4bc29a9

11 files changed

+42
-69
lines changed

include/swift/SIL/SILValue.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,6 @@ struct OperandOwnership {
833833
/// borrow scope.
834834
/// (tuple_extract, struct_extract, cast, switch)
835835
GuaranteedForwarding,
836-
/// A GuaranteedForwarding value passed as a phi operand.
837-
GuaranteedForwardingPhi,
838836
/// End Borrow. End the borrow scope opened directly by the operand.
839837
/// The operand must be a begin_borrow, begin_apply, or function argument.
840838
/// (end_borrow, end_apply)
@@ -927,7 +925,6 @@ inline OwnershipConstraint OperandOwnership::getOwnershipConstraint() {
927925
return {OwnershipKind::Owned, UseLifetimeConstraint::LifetimeEnding};
928926
case OperandOwnership::InteriorPointer:
929927
case OperandOwnership::GuaranteedForwarding:
930-
case OperandOwnership::GuaranteedForwardingPhi:
931928
return {OwnershipKind::Guaranteed,
932929
UseLifetimeConstraint::NonLifetimeEnding};
933930
case OperandOwnership::EndBorrow:
@@ -956,7 +953,6 @@ inline bool canAcceptUnownedValue(OperandOwnership operandOwnership) {
956953
case OperandOwnership::ForwardingConsume:
957954
case OperandOwnership::InteriorPointer:
958955
case OperandOwnership::GuaranteedForwarding:
959-
case OperandOwnership::GuaranteedForwardingPhi:
960956
case OperandOwnership::EndBorrow:
961957
case OperandOwnership::Reborrow:
962958
return false;

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ OperandOwnership OperandOwnershipClassifier::visitBranchInst(BranchInst *bi) {
431431

432432
if (destBlockArgOwnershipKind == OwnershipKind::Guaranteed) {
433433
return isGuaranteedForwarding(getValue())
434-
? OperandOwnership::GuaranteedForwardingPhi
434+
? OperandOwnership::GuaranteedForwarding
435435
: OperandOwnership::Reborrow;
436436
}
437437
return destBlockArgOwnershipKind.getForwardingOperandOwnership(

lib/SIL/IR/SILValue.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,6 @@ StringRef OperandOwnership::asString() const {
432432
return "interior-pointer";
433433
case OperandOwnership::GuaranteedForwarding:
434434
return "guaranteed-forwarding";
435-
case OperandOwnership::GuaranteedForwardingPhi:
436-
return "guaranteed-forwarding-phi";
437435
case OperandOwnership::EndBorrow:
438436
return "end-borrow";
439437
case OperandOwnership::Reborrow:

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ bool swift::hasPointerEscape(BorrowedValue value) {
5353
case OperandOwnership::InteriorPointer:
5454
case OperandOwnership::BitwiseEscape:
5555
break;
56-
57-
case OperandOwnership::GuaranteedForwardingPhi:
5856
case OperandOwnership::Reborrow: {
5957
SILArgument *phi = cast<BranchInst>(op->getUser())
6058
->getDestBB()
@@ -225,6 +223,12 @@ bool swift::findInnerTransitiveGuaranteedUses(
225223
// Do not include transitive uses with 'none' ownership
226224
if (result->getOwnershipKind() == OwnershipKind::None)
227225
return true;
226+
auto *phi = dyn_cast<SILPhiArgument>(result);
227+
if (phi && phi->isPhi()) {
228+
leafUse(use);
229+
foundPointerEscape = true;
230+
return true;
231+
}
228232
for (auto *resultUse : result->getUses()) {
229233
if (resultUse->getOperandOwnership() != OperandOwnership::NonUse) {
230234
nonLeaf = true;
@@ -240,11 +244,6 @@ bool swift::findInnerTransitiveGuaranteedUses(
240244
}
241245
break;
242246
}
243-
case OperandOwnership::GuaranteedForwardingPhi: {
244-
leafUse(use);
245-
foundPointerEscape = true;
246-
break;
247-
}
248247
case OperandOwnership::Borrow:
249248
// FIXME: Use visitExtendedScopeEndingUses and audit all clients to handle
250249
// reborrows.
@@ -342,17 +341,6 @@ bool swift::findExtendedUsesOfSimpleBorrowedValue(
342341
}
343342
recordUse(use);
344343
break;
345-
// \p borrowedValue will dominate this GuaranteedForwardingPhi, because we
346-
// return false in the case of Reborrow.
347-
case OperandOwnership::GuaranteedForwardingPhi: {
348-
SILArgument *phi = PhiOperand(use).getValue();
349-
for (auto *use : phi->getUses()) {
350-
if (use->getOperandOwnership() != OperandOwnership::NonUse)
351-
worklist.insert(use);
352-
}
353-
recordUse(use);
354-
break;
355-
}
356344
case OperandOwnership::GuaranteedForwarding: {
357345
ForwardingOperand(use).visitForwardedValues([&](SILValue result) {
358346
// Do not include transitive uses with 'none' ownership
@@ -425,15 +413,12 @@ bool swift::visitGuaranteedForwardingPhisForSSAValue(
425413
// GuaranteedForwardingPhi uses.
426414
for (auto *use : value->getUses()) {
427415
if (use->getOperandOwnership() == OperandOwnership::GuaranteedForwarding) {
428-
guaranteedForwardingOps.insert(use);
429-
continue;
430-
}
431-
if (use->getOperandOwnership() ==
432-
OperandOwnership::GuaranteedForwardingPhi) {
433-
if (!visitor(use)) {
434-
return false;
416+
if (isa<BranchInst>(use->getUser())) {
417+
if (!visitor(use)) {
418+
return false;
419+
}
435420
}
436-
continue;
421+
guaranteedForwardingOps.insert(use);
437422
}
438423
}
439424

@@ -443,15 +428,12 @@ bool swift::visitGuaranteedForwardingPhisForSSAValue(
443428
for (auto *valUse : val->getUses()) {
444429
if (valUse->getOperandOwnership() ==
445430
OperandOwnership::GuaranteedForwarding) {
446-
guaranteedForwardingOps.insert(valUse);
447-
continue;
448-
}
449-
if (valUse->getOperandOwnership() ==
450-
OperandOwnership::GuaranteedForwardingPhi) {
451-
if (!visitor(valUse)) {
452-
return false;
431+
if (isa<BranchInst>(valUse->getUser())) {
432+
if (!visitor(valUse)) {
433+
return false;
434+
}
453435
}
454-
continue;
436+
guaranteedForwardingOps.insert(valUse);
455437
}
456438
}
457439
}
@@ -1438,10 +1420,6 @@ ForwardingOperand::ForwardingOperand(Operand *use) {
14381420
if (use->isTypeDependent())
14391421
return;
14401422

1441-
if (!OwnershipForwardingMixin::isa(use->getUser())) {
1442-
return;
1443-
}
1444-
#ifndef NDEBUG
14451423
switch (use->getOperandOwnership()) {
14461424
case OperandOwnership::ForwardingUnowned:
14471425
case OperandOwnership::ForwardingConsume:
@@ -1456,12 +1434,12 @@ ForwardingOperand::ForwardingOperand(Operand *use) {
14561434
case OperandOwnership::Borrow:
14571435
case OperandOwnership::DestroyingConsume:
14581436
case OperandOwnership::InteriorPointer:
1459-
case OperandOwnership::GuaranteedForwardingPhi:
14601437
case OperandOwnership::EndBorrow:
14611438
case OperandOwnership::Reborrow:
1462-
llvm_unreachable("this isn't the operand being forwarding!");
1439+
this->use = nullptr;
1440+
return;
14631441
}
1464-
#endif
1442+
14651443
this->use = use;
14661444
}
14671445

@@ -1668,15 +1646,23 @@ bool ForwardingOperand::visitForwardedValues(
16681646
// "transforming terminators"... We know that this means that we should at
16691647
// most have a single phi argument.
16701648
auto *ti = cast<TermInst>(user);
1671-
return llvm::all_of(ti->getSuccessorBlocks(), [&](SILBasicBlock *succBlock) {
1672-
// If we do not have any arguments, then continue.
1673-
if (succBlock->args_empty())
1674-
return true;
1649+
if (ti->isTransformationTerminator()) {
1650+
return llvm::all_of(
1651+
ti->getSuccessorBlocks(), [&](SILBasicBlock *succBlock) {
1652+
// If we do not have any arguments, then continue.
1653+
if (succBlock->args_empty())
1654+
return true;
16751655

1676-
auto args = succBlock->getSILPhiArguments();
1677-
assert(args.size() == 1 && "Transforming terminator with multiple args?!");
1678-
return visitor(args[0]);
1679-
});
1656+
auto args = succBlock->getSILPhiArguments();
1657+
assert(args.size() == 1 &&
1658+
"Transforming terminator with multiple args?!");
1659+
return visitor(args[0]);
1660+
});
1661+
}
1662+
1663+
auto *bi = cast<BranchInst>(ti);
1664+
auto *succArg = bi->getDestBB()->getArgument(use->getOperandNumber());
1665+
return visitor(succArg);
16801666
}
16811667

16821668
void swift::visitExtendedReborrowPhiBaseValuePairs(

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,6 @@ PrunedLiveRange<LivenessWithDefs>::updateForDef(SILValue def) {
318318
updateForUse(use->getUser(), /*lifetimeEnding*/false);
319319
break;
320320
}
321-
case OperandOwnership::GuaranteedForwardingPhi: {
322-
updateForDef(PhiOperand(use).getValue());
323-
break;
324-
}
325321
default:
326322
updateForUse(use->getUser(), use->isLifetimeEnding());
327323
break;

lib/SIL/Verifier/LinearLifetimeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void State::checkForSameBlockUseAfterFree(Operand *consumingUse,
317317
} else if (nonConsumingUse->getOperandOwnership() ==
318318
OperandOwnership::Reborrow ||
319319
nonConsumingUse->getOperandOwnership() ==
320-
OperandOwnership::GuaranteedForwardingPhi) {
320+
OperandOwnership::GuaranteedForwarding) {
321321
continue;
322322
}
323323

lib/SIL/Verifier/SILOwnershipVerifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ bool SILValueOwnershipChecker::gatherUsers(
311311
continue;
312312
}
313313

314-
if (op->getOperandOwnership() ==
315-
OperandOwnership::GuaranteedForwardingPhi) {
314+
if (PhiOperand(op) &&
315+
op->getOperandOwnership() == OperandOwnership::GuaranteedForwarding) {
316316
LLVM_DEBUG(llvm::dbgs() << "Regular User: " << *user);
317317
nonLifetimeEndingUsers.push_back(op);
318318
continue;

lib/SILOptimizer/Mandatory/DiagnoseLifetimeIssues.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ visitUses(SILValue def, bool updateLivenessAndWeakStores, int callDepth) {
215215
liveness.updateForUse(user, /*lifetimeEnding*/ false);
216216
break;
217217
case OperandOwnership::GuaranteedForwarding:
218-
case OperandOwnership::GuaranteedForwardingPhi:
219218
case OperandOwnership::ForwardingConsume:
220219
// TermInst includes ReturnInst, which is generally an escape.
221220
// If this is called as part of getArgumentState, then it is not really

lib/SILOptimizer/Mandatory/MoveKillsCopyableValuesChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ bool CheckerLivenessInfo::compute() {
164164
// A forwarding borrow is validated as part of its parent borrow. So
165165
// just mark it as extending liveness and look through it.
166166
liveness.updateForUse(user, /*lifetimeEnding*/ false);
167-
for (SILValue result : user->getResults()) {
167+
ForwardingOperand(use).visitForwardedValues([&](SILValue result) {
168168
if (result->getOwnershipKind() == OwnershipKind::Guaranteed)
169169
defUseWorklist.insert(result);
170-
}
170+
return true;
171+
});
171172
break;
172173
case OperandOwnership::InteriorPointer: {
173174
// An interior pointer user extends liveness until the end of the
@@ -191,7 +192,6 @@ bool CheckerLivenessInfo::compute() {
191192
case OperandOwnership::EndBorrow:
192193
// Don't care about this use.
193194
break;
194-
case OperandOwnership::GuaranteedForwardingPhi:
195195
case OperandOwnership::Reborrow:
196196
// Reborrows do not occur this early in the pipeline.
197197
llvm_unreachable(

lib/SILOptimizer/Utils/CanonicalizeBorrowScope.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ bool CanonicalizeBorrowScope::visitBorrowScopeUses(SILValue innerValue,
275275
break;
276276

277277
case OperandOwnership::GuaranteedForwarding:
278-
case OperandOwnership::GuaranteedForwardingPhi:
279278
case OperandOwnership::ForwardingConsume:
280279
if (CanonicalizeBorrowScope::isRewritableOSSAForward(user)) {
281280
if (!visitor.visitForwardingUse(use)) {

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ bool CanonicalizeOSSALifetime::computeCanonicalLiveness() {
192192
// reborrow of such.
193193
liveness.updateForUse(user, /*lifetimeEnding*/ false);
194194
break;
195-
case OperandOwnership::GuaranteedForwardingPhi:
196195
case OperandOwnership::Reborrow:
197196
BranchInst *branch;
198197
if (!(branch = dyn_cast<BranchInst>(user))) {

0 commit comments

Comments
 (0)