Skip to content

Commit 194904f

Browse files
committed
[OwnershipUtils] NFC: Deduplicated implementation.
The only difference between visitLocalScopeEndingUses and getLocalScopeEndingInstructions is that the former evaluates a lambda with each `Operand *` and the latter adds `->getUser()` to a SmallVectorImpl for each. So factor the latter through the former and add the users to the SmallVectorImpl in the lambda.
1 parent 003b335 commit 194904f

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

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

+4-18
Original file line numberDiff line numberDiff line change
@@ -850,24 +850,10 @@ void BorrowedValue::print(llvm::raw_ostream &os) const {
850850

851851
void BorrowedValue::getLocalScopeEndingInstructions(
852852
SmallVectorImpl<SILInstruction *> &scopeEndingInsts) const {
853-
assert(isLocalScope() && "Should only call this given a local scope");
854-
855-
switch (kind) {
856-
case BorrowedValueKind::Invalid:
857-
llvm_unreachable("Using invalid case?!");
858-
case BorrowedValueKind::SILFunctionArgument:
859-
llvm_unreachable("Should only call this with a local scope");
860-
case BorrowedValueKind::BeginBorrow:
861-
case BorrowedValueKind::LoadBorrow:
862-
case BorrowedValueKind::Phi:
863-
for (auto *use : value->getUses()) {
864-
if (use->isLifetimeEnding()) {
865-
scopeEndingInsts.push_back(use->getUser());
866-
}
867-
}
868-
return;
869-
}
870-
llvm_unreachable("Covered switch isn't covered?!");
853+
visitLocalScopeEndingUses([&](auto *use) {
854+
scopeEndingInsts.push_back(use->getUser());
855+
return true;
856+
});
871857
}
872858

873859
// Note: BorrowedLifetimeExtender assumes no intermediate values between a

0 commit comments

Comments
 (0)