Skip to content

Commit 511739b

Browse files
committed
Delete OperandOwnership::GuaranteedForwardingPhi
Use OperandOwnership::GuaranteedForwarding instead.
1 parent b105639 commit 511739b

11 files changed

+46
-81
lines changed

include/swift/SIL/SILValue.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,6 @@ struct OperandOwnership {
825825
/// borrow scope.
826826
/// (tuple_extract, struct_extract, cast, switch)
827827
GuaranteedForwarding,
828-
/// A GuaranteedForwarding value passed as a phi operand.
829-
GuaranteedForwardingPhi,
830828
/// End Borrow. End the borrow scope opened directly by the operand.
831829
/// The operand must be a begin_borrow, begin_apply, or function argument.
832830
/// (end_borrow, end_apply)
@@ -919,7 +917,6 @@ inline OwnershipConstraint OperandOwnership::getOwnershipConstraint() {
919917
return {OwnershipKind::Owned, UseLifetimeConstraint::LifetimeEnding};
920918
case OperandOwnership::InteriorPointer:
921919
case OperandOwnership::GuaranteedForwarding:
922-
case OperandOwnership::GuaranteedForwardingPhi:
923920
return {OwnershipKind::Guaranteed,
924921
UseLifetimeConstraint::NonLifetimeEnding};
925922
case OperandOwnership::EndBorrow:
@@ -948,7 +945,6 @@ inline bool canAcceptUnownedValue(OperandOwnership operandOwnership) {
948945
case OperandOwnership::ForwardingConsume:
949946
case OperandOwnership::InteriorPointer:
950947
case OperandOwnership::GuaranteedForwarding:
951-
case OperandOwnership::GuaranteedForwardingPhi:
952948
case OperandOwnership::EndBorrow:
953949
case OperandOwnership::Reborrow:
954950
return false;

lib/SIL/IR/OperandOwnership.cpp

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

429429
if (destBlockArgOwnershipKind == OwnershipKind::Guaranteed) {
430430
return isGuaranteedForwarding(getValue())
431-
? OperandOwnership::GuaranteedForwardingPhi
431+
? OperandOwnership::GuaranteedForwarding
432432
: OperandOwnership::Reborrow;
433433
}
434434
return destBlockArgOwnershipKind.getForwardingOperandOwnership(

lib/SIL/IR/SILValue.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,6 @@ StringRef OperandOwnership::asString() const {
441441
return "interior-pointer";
442442
case OperandOwnership::GuaranteedForwarding:
443443
return "guaranteed-forwarding";
444-
case OperandOwnership::GuaranteedForwardingPhi:
445-
return "guaranteed-forwarding-phi";
446444
case OperandOwnership::EndBorrow:
447445
return "end-borrow";
448446
case OperandOwnership::Reborrow:

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 34 additions & 61 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()
@@ -219,6 +217,11 @@ bool swift::findInnerTransitiveGuaranteedUses(
219217
// Do not include transitive uses with 'none' ownership
220218
if (result->getOwnershipKind() == OwnershipKind::None)
221219
return true;
220+
if (auto *phi = SILArgument::asPhi(result)) {
221+
leafUse(use);
222+
foundPointerEscape = true;
223+
return true;
224+
}
222225
for (auto *resultUse : result->getUses()) {
223226
if (resultUse->getOperandOwnership() != OperandOwnership::NonUse) {
224227
nonLeaf = true;
@@ -234,11 +237,6 @@ bool swift::findInnerTransitiveGuaranteedUses(
234237
}
235238
break;
236239
}
237-
case OperandOwnership::GuaranteedForwardingPhi: {
238-
leafUse(use);
239-
foundPointerEscape = true;
240-
break;
241-
}
242240
case OperandOwnership::Borrow:
243241
// FIXME: Use visitExtendedScopeEndingUses and audit all clients to handle
244242
// reborrows.
@@ -336,17 +334,6 @@ bool swift::findExtendedUsesOfSimpleBorrowedValue(
336334
}
337335
recordUse(use);
338336
break;
339-
// \p borrowedValue will dominate this GuaranteedForwardingPhi, because we
340-
// return false in the case of Reborrow.
341-
case OperandOwnership::GuaranteedForwardingPhi: {
342-
SILArgument *phi = PhiOperand(use).getValue();
343-
for (auto *use : phi->getUses()) {
344-
if (use->getOperandOwnership() != OperandOwnership::NonUse)
345-
worklist.insert(use);
346-
}
347-
recordUse(use);
348-
break;
349-
}
350337
case OperandOwnership::GuaranteedForwarding: {
351338
ForwardingOperand(use).visitForwardedValues([&](SILValue result) {
352339
// Do not include transitive uses with 'none' ownership
@@ -419,15 +406,12 @@ bool swift::visitGuaranteedForwardingPhisForSSAValue(
419406
// GuaranteedForwardingPhi uses.
420407
for (auto *use : value->getUses()) {
421408
if (use->getOperandOwnership() == OperandOwnership::GuaranteedForwarding) {
422-
guaranteedForwardingOps.insert(use);
423-
continue;
424-
}
425-
if (use->getOperandOwnership() ==
426-
OperandOwnership::GuaranteedForwardingPhi) {
427-
if (!visitor(use)) {
428-
return false;
409+
if (PhiOperand(use)) {
410+
if (!visitor(use)) {
411+
return false;
412+
}
429413
}
430-
continue;
414+
guaranteedForwardingOps.insert(use);
431415
}
432416
}
433417

@@ -437,15 +421,12 @@ bool swift::visitGuaranteedForwardingPhisForSSAValue(
437421
for (auto *valUse : val->getUses()) {
438422
if (valUse->getOperandOwnership() ==
439423
OperandOwnership::GuaranteedForwarding) {
440-
guaranteedForwardingOps.insert(valUse);
441-
continue;
442-
}
443-
if (valUse->getOperandOwnership() ==
444-
OperandOwnership::GuaranteedForwardingPhi) {
445-
if (!visitor(valUse)) {
446-
return false;
424+
if (PhiOperand(valUse)) {
425+
if (!visitor(valUse)) {
426+
return false;
427+
}
447428
}
448-
continue;
429+
guaranteedForwardingOps.insert(valUse);
449430
}
450431
}
451432
}
@@ -1395,31 +1376,16 @@ ForwardingOperand::ForwardingOperand(Operand *use) {
13951376
if (use->isTypeDependent())
13961377
return;
13971378

1398-
if (!OwnershipForwardingMixin::isa(use->getUser())) {
1399-
return;
1400-
}
1401-
#ifndef NDEBUG
14021379
switch (use->getOperandOwnership()) {
14031380
case OperandOwnership::ForwardingUnowned:
14041381
case OperandOwnership::ForwardingConsume:
14051382
case OperandOwnership::GuaranteedForwarding:
1383+
this->use = use;
14061384
break;
1407-
case OperandOwnership::NonUse:
1408-
case OperandOwnership::TrivialUse:
1409-
case OperandOwnership::InstantaneousUse:
1410-
case OperandOwnership::UnownedInstantaneousUse:
1411-
case OperandOwnership::PointerEscape:
1412-
case OperandOwnership::BitwiseEscape:
1413-
case OperandOwnership::Borrow:
1414-
case OperandOwnership::DestroyingConsume:
1415-
case OperandOwnership::InteriorPointer:
1416-
case OperandOwnership::GuaranteedForwardingPhi:
1417-
case OperandOwnership::EndBorrow:
1418-
case OperandOwnership::Reborrow:
1419-
llvm_unreachable("this isn't the operand being forwarding!");
1385+
default:
1386+
this->use = nullptr;
1387+
return;
14201388
}
1421-
#endif
1422-
this->use = use;
14231389
}
14241390

14251391
ValueOwnershipKind ForwardingOperand::getForwardingOwnershipKind() const {
@@ -1625,15 +1591,22 @@ bool ForwardingOperand::visitForwardedValues(
16251591
// "transforming terminators"... We know that this means that we should at
16261592
// most have a single phi argument.
16271593
auto *ti = cast<TermInst>(user);
1628-
return llvm::all_of(ti->getSuccessorBlocks(), [&](SILBasicBlock *succBlock) {
1629-
// If we do not have any arguments, then continue.
1630-
if (succBlock->args_empty())
1631-
return true;
1594+
if (ti->mayHaveTerminatorResult()) {
1595+
return llvm::all_of(
1596+
ti->getSuccessorBlocks(), [&](SILBasicBlock *succBlock) {
1597+
// If we do not have any arguments, then continue.
1598+
if (succBlock->args_empty())
1599+
return true;
16321600

1633-
auto args = succBlock->getSILPhiArguments();
1634-
assert(args.size() == 1 && "Transforming terminator with multiple args?!");
1635-
return visitor(args[0]);
1636-
});
1601+
auto args = succBlock->getSILPhiArguments();
1602+
assert(args.size() == 1 &&
1603+
"Transforming terminator with multiple args?!");
1604+
return visitor(args[0]);
1605+
});
1606+
}
1607+
1608+
auto *succArg = PhiOperand(use).getValue();
1609+
return visitor(succArg);
16371610
}
16381611

16391612
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
@@ -308,8 +308,8 @@ bool SILValueOwnershipChecker::gatherUsers(
308308
continue;
309309
}
310310

311-
if (op->getOperandOwnership() ==
312-
OperandOwnership::GuaranteedForwardingPhi) {
311+
if (PhiOperand(op) &&
312+
op->getOperandOwnership() == OperandOwnership::GuaranteedForwarding) {
313313
LLVM_DEBUG(llvm::dbgs() << "Regular User: " << *user);
314314
nonLifetimeEndingUsers.push_back(op);
315315
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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,16 @@ 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) {
168+
if (auto *arg = dyn_cast<SILPhiArgument>(result)) {
169+
if (arg->isTerminatorResult()) {
170+
return true;
171+
}
172+
}
168173
if (result->getOwnershipKind() == OwnershipKind::Guaranteed)
169174
defUseWorklist.insert(result);
170-
}
175+
return true;
176+
});
171177
break;
172178
case OperandOwnership::InteriorPointer: {
173179
// An interior pointer user extends liveness until the end of the
@@ -191,7 +197,6 @@ bool CheckerLivenessInfo::compute() {
191197
case OperandOwnership::EndBorrow:
192198
// Don't care about this use.
193199
break;
194-
case OperandOwnership::GuaranteedForwardingPhi:
195200
case OperandOwnership::Reborrow:
196201
// Reborrows do not occur this early in the pipeline.
197202
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)