Skip to content

Commit b1ccb59

Browse files
committed
[SIL] NFC: Removed visitBorrowIntroUserResults.
It's equivalent to getBorrowIntroducingUserResult except that it's less convenient to use. There's only ever one result, so there's no need for a visitor. Updated all users to call getBorrowIntroducingUserResult instead.
1 parent 6a5330b commit b1ccb59

File tree

3 files changed

+19
-67
lines changed

3 files changed

+19
-67
lines changed

Diff for: include/swift/SIL/OwnershipUtils.h

+2-12
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,16 +461,6 @@ 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-
474464
/// If this operand's user has a single borrowed value result return a
475465
/// valid BorrowedValue instance.
476466
BorrowedValue getBorrowIntroducingUserResult() const;

Diff for: lib/SIL/Utils/OwnershipUtils.cpp

+15-51
Original file line numberDiff line numberDiff line change
@@ -693,42 +693,12 @@ 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 {
706-
switch (kind) {
707-
case BorrowingOperandKind::Invalid:
708-
llvm_unreachable("Using invalid case");
709-
case BorrowingOperandKind::Apply:
710-
case BorrowingOperandKind::TryApply:
711-
case BorrowingOperandKind::BeginApply:
712-
case BorrowingOperandKind::Yield:
713-
case BorrowingOperandKind::PartialApplyStack:
714-
case BorrowingOperandKind::BeginAsyncLet:
715-
llvm_unreachable("Never has borrow introducer results!");
716-
case BorrowingOperandKind::BeginBorrow: {
717-
auto value = BorrowedValue(cast<BeginBorrowInst>(op->getUser()));
718-
assert(value);
719-
return visitor(value);
720-
}
721-
case BorrowingOperandKind::Branch: {
722-
auto *bi = cast<BranchInst>(op->getUser());
723-
auto value = BorrowedValue(
724-
bi->getDestBB()->getArgument(op->getOperandNumber()));
725-
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-
732702
BorrowedValue BorrowingOperand::getBorrowIntroducingUserResult() const {
733703
switch (kind) {
734704
case BorrowingOperandKind::Invalid:
@@ -900,11 +870,9 @@ bool BorrowedValue::visitExtendedScopeEndingUses(
900870

901871
auto visitEnd = [&](Operand *scopeEndingUse) {
902872
if (scopeEndingUse->getOperandOwnership() == OperandOwnership::Reborrow) {
903-
BorrowingOperand(scopeEndingUse).visitBorrowIntroducingUserResults(
904-
[&](BorrowedValue borrowedValue) {
905-
reborrows.insert(borrowedValue.value);
906-
return true;
907-
});
873+
auto borrowedValue =
874+
BorrowingOperand(scopeEndingUse).getBorrowIntroducingUserResult();
875+
reborrows.insert(borrowedValue.value);
908876
return true;
909877
}
910878
return visitor(scopeEndingUse);
@@ -929,11 +897,9 @@ bool BorrowedValue::visitTransitiveLifetimeEndingUses(
929897

930898
auto visitEnd = [&](Operand *scopeEndingUse) {
931899
if (scopeEndingUse->getOperandOwnership() == OperandOwnership::Reborrow) {
932-
BorrowingOperand(scopeEndingUse)
933-
.visitBorrowIntroducingUserResults([&](BorrowedValue borrowedValue) {
934-
reborrows.insert(borrowedValue.value);
935-
return true;
936-
});
900+
auto borrowedValue =
901+
BorrowingOperand(scopeEndingUse).getBorrowIntroducingUserResult();
902+
reborrows.insert(borrowedValue.value);
937903
// visitor on the reborrow
938904
return visitor(scopeEndingUse);
939905
}
@@ -984,16 +950,14 @@ bool BorrowedValue::visitInteriorPointerOperandHelper(
984950
break;
985951
}
986952

987-
borrowingOperand.visitBorrowIntroducingUserResults([&](auto bv) {
988-
for (auto *use : bv->getUses()) {
989-
if (auto intPtrOperand = InteriorPointerOperand(use)) {
990-
func(intPtrOperand);
991-
continue;
992-
}
993-
worklist.push_back(use);
953+
auto bv = borrowingOperand.getBorrowIntroducingUserResult();
954+
for (auto *use : bv->getUses()) {
955+
if (auto intPtrOperand = InteriorPointerOperand(use)) {
956+
func(intPtrOperand);
957+
continue;
994958
}
995-
return true;
996-
});
959+
worklist.push_back(use);
960+
}
997961
continue;
998962
}
999963

Diff for: lib/SILOptimizer/SILCombiner/SILCombinerBuiltinVisitors.cpp

+2-4
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)