Skip to content

Commit 28bbbd5

Browse files
Merge pull request #65114 from nate-chandler/nfc/20230412/2/delete-duplicate-api
[SIL] NFC: Removed visitBorrowIntroducingUserResults.
2 parents 8202acb + 6ad9581 commit 28bbbd5

File tree

3 files changed

+29
-72
lines changed

3 files changed

+29
-72
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ struct BorrowingOperand {
440440
/// values do not themselves introduce a borrow scope. In other words, they
441441
/// cannot be reborrowed.
442442
///
443-
/// If true, the visitBorrowIntroducingUserResults() can be called to acquire
444-
/// each BorrowedValue that introduces a new borrow scopes.
443+
/// If true, getBorrowIntroducingUserResult() can be called to acquire the
444+
/// BorrowedValue that introduces a new borrow scope.
445445
bool hasBorrowIntroducingUser() const {
446446
// TODO: Can we derive this by running a borrow introducer check ourselves?
447447
switch (kind) {
@@ -461,19 +461,9 @@ struct BorrowingOperand {
461461
llvm_unreachable("Covered switch isn't covered?!");
462462
}
463463

464-
/// Visit all of the "results" of the user of this operand that are borrow
465-
/// scope introducers for the specific scope that this borrow scope operand
466-
/// summarizes.
467-
///
468-
/// Precondition: hasBorrowIntroducingUser() is true
469-
///
470-
/// Returns false and early exits if \p visitor returns false.
471-
bool visitBorrowIntroducingUserResults(
472-
function_ref<bool(BorrowedValue)> visitor) const;
473-
474-
/// If this operand's user has a single borrowed value result return a
475-
/// valid BorrowedValue instance.
476-
BorrowedValue getBorrowIntroducingUserResult();
464+
/// If this operand's user has a borrowed value result return a valid
465+
/// BorrowedValue instance.
466+
BorrowedValue getBorrowIntroducingUserResult() const;
477467

478468
/// Return the borrowing operand's value.
479469
SILValue getScopeIntroducingUserResult();

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -693,59 +693,34 @@ bool BorrowingOperand::visitExtendedScopeEndingUses(
693693
function_ref<bool(Operand *)> visitor) const {
694694

695695
if (hasBorrowIntroducingUser()) {
696-
return visitBorrowIntroducingUserResults(
697-
[visitor](BorrowedValue borrowedValue) {
698-
return borrowedValue.visitExtendedScopeEndingUses(visitor);
699-
});
696+
auto borrowedValue = getBorrowIntroducingUserResult();
697+
return borrowedValue.visitExtendedScopeEndingUses(visitor);
700698
}
701699
return visitScopeEndingUses(visitor);
702700
}
703701

704-
bool BorrowingOperand::visitBorrowIntroducingUserResults(
705-
function_ref<bool(BorrowedValue)> visitor) const {
702+
BorrowedValue BorrowingOperand::getBorrowIntroducingUserResult() const {
706703
switch (kind) {
707704
case BorrowingOperandKind::Invalid:
708-
llvm_unreachable("Using invalid case");
709705
case BorrowingOperandKind::Apply:
710706
case BorrowingOperandKind::TryApply:
711707
case BorrowingOperandKind::BeginApply:
712708
case BorrowingOperandKind::Yield:
713709
case BorrowingOperandKind::PartialApplyStack:
714710
case BorrowingOperandKind::BeginAsyncLet:
715-
llvm_unreachable("Never has borrow introducer results!");
711+
return BorrowedValue();
712+
716713
case BorrowingOperandKind::BeginBorrow: {
717714
auto value = BorrowedValue(cast<BeginBorrowInst>(op->getUser()));
718715
assert(value);
719-
return visitor(value);
716+
return value;
720717
}
721718
case BorrowingOperandKind::Branch: {
722719
auto *bi = cast<BranchInst>(op->getUser());
723-
auto value = BorrowedValue(
724-
bi->getDestBB()->getArgument(op->getOperandNumber()));
720+
auto value =
721+
BorrowedValue(bi->getDestBB()->getArgument(op->getOperandNumber()));
725722
assert(value && "guaranteed-to-unowned conversion not allowed on branches");
726-
return visitor(value);
727-
}
728-
}
729-
llvm_unreachable("Covered switch isn't covered?!");
730-
}
731-
732-
BorrowedValue BorrowingOperand::getBorrowIntroducingUserResult() {
733-
switch (kind) {
734-
case BorrowingOperandKind::Invalid:
735-
case BorrowingOperandKind::Apply:
736-
case BorrowingOperandKind::TryApply:
737-
case BorrowingOperandKind::BeginApply:
738-
case BorrowingOperandKind::Yield:
739-
case BorrowingOperandKind::PartialApplyStack:
740-
case BorrowingOperandKind::BeginAsyncLet:
741-
return BorrowedValue();
742-
743-
case BorrowingOperandKind::BeginBorrow:
744-
return BorrowedValue(cast<BeginBorrowInst>(op->getUser()));
745-
746-
case BorrowingOperandKind::Branch: {
747-
auto *bi = cast<BranchInst>(op->getUser());
748-
return BorrowedValue(bi->getDestBB()->getArgument(op->getOperandNumber()));
723+
return value;
749724
}
750725
}
751726
llvm_unreachable("covered switch");
@@ -919,11 +894,9 @@ bool BorrowedValue::visitExtendedScopeEndingUses(
919894

920895
auto visitEnd = [&](Operand *scopeEndingUse) {
921896
if (scopeEndingUse->getOperandOwnership() == OperandOwnership::Reborrow) {
922-
BorrowingOperand(scopeEndingUse).visitBorrowIntroducingUserResults(
923-
[&](BorrowedValue borrowedValue) {
924-
reborrows.insert(borrowedValue.value);
925-
return true;
926-
});
897+
auto borrowedValue =
898+
BorrowingOperand(scopeEndingUse).getBorrowIntroducingUserResult();
899+
reborrows.insert(borrowedValue.value);
927900
return true;
928901
}
929902
return visitor(scopeEndingUse);
@@ -948,11 +921,9 @@ bool BorrowedValue::visitTransitiveLifetimeEndingUses(
948921

949922
auto visitEnd = [&](Operand *scopeEndingUse) {
950923
if (scopeEndingUse->getOperandOwnership() == OperandOwnership::Reborrow) {
951-
BorrowingOperand(scopeEndingUse)
952-
.visitBorrowIntroducingUserResults([&](BorrowedValue borrowedValue) {
953-
reborrows.insert(borrowedValue.value);
954-
return true;
955-
});
924+
auto borrowedValue =
925+
BorrowingOperand(scopeEndingUse).getBorrowIntroducingUserResult();
926+
reborrows.insert(borrowedValue.value);
956927
// visitor on the reborrow
957928
return visitor(scopeEndingUse);
958929
}
@@ -1003,16 +974,14 @@ bool BorrowedValue::visitInteriorPointerOperandHelper(
1003974
break;
1004975
}
1005976

1006-
borrowingOperand.visitBorrowIntroducingUserResults([&](auto bv) {
1007-
for (auto *use : bv->getUses()) {
1008-
if (auto intPtrOperand = InteriorPointerOperand(use)) {
1009-
func(intPtrOperand);
1010-
continue;
1011-
}
1012-
worklist.push_back(use);
977+
auto bv = borrowingOperand.getBorrowIntroducingUserResult();
978+
for (auto *use : bv->getUses()) {
979+
if (auto intPtrOperand = InteriorPointerOperand(use)) {
980+
func(intPtrOperand);
981+
continue;
1013982
}
1014-
return true;
1015-
});
983+
worklist.push_back(use);
984+
}
1016985
continue;
1017986
}
1018987

lib/SILOptimizer/SILCombiner/SILCombinerBuiltinVisitors.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ SILCombiner::optimizeBuiltinCOWBufferForReadingOSSA(BuiltinInst *bi) {
118118
if (auto operand = BorrowingOperand(use)) {
119119
if (operand.isReborrow())
120120
return nullptr;
121-
operand.visitBorrowIntroducingUserResults([&](BorrowedValue bv) {
122-
accumulatedBorrowedValues.push_back(bv);
123-
return true;
124-
});
121+
auto bv = operand.getBorrowIntroducingUserResult();
122+
accumulatedBorrowedValues.push_back(bv);
125123
continue;
126124
}
127125

0 commit comments

Comments
 (0)