Skip to content

Commit 99091c9

Browse files
committed
[NFC] OwnershipUtils: Factored out function.
For historical reasons, the existing function (`areUsesWithinExtendedScope`) trafficked in operands rather than instructions. Now that PrunedLiveness has an API that deals with instructions, add a function (`areWithinExtendedScope`) which does as well. Factor the existing function through this new function.
1 parent d49e9ea commit 99091c9

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,21 @@ struct BorrowedValue {
630630
/// necessarilly dominated by the borrow scope.
631631
void computeTransitiveLiveness(MultiDefPrunedLiveness &liveness) const;
632632

633+
/// Whether \p insts are completely within this borrow introducer's local
634+
/// scope.
635+
///
636+
/// Precondition: \p insts are dominated by the local borrow introducer.
637+
///
638+
/// This ignores reborrows. The assumption is that, since \p insts are
639+
/// dominated by this local scope, checking the extended borrow scope should
640+
/// not be necessary to determine they are within the scope.
641+
///
642+
/// \p deadEndBlocks is optional during transition. It will be completely
643+
/// removed in an upcoming commit.
644+
template <typename Instructions>
645+
bool areWithinExtendedScope(Instructions insts,
646+
DeadEndBlocks *deadEndBlocks) const;
647+
633648
/// Returns true if \p uses are completely within this borrow introducer's
634649
/// local scope.
635650
///

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,9 @@ computeTransitiveLiveness(MultiDefPrunedLiveness &liveness) const {
975975
});
976976
}
977977

978-
bool BorrowedValue::areUsesWithinExtendedScope(
979-
ArrayRef<Operand *> uses, DeadEndBlocks *deadEndBlocks) const {
978+
template <typename Instructions>
979+
bool BorrowedValue::areWithinExtendedScope(Instructions insts,
980+
DeadEndBlocks *deadEndBlocks) const {
980981
// First make sure that we actually have a local scope. If we have a non-local
981982
// scope, then we have something (like a SILFunctionArgument) where a larger
982983
// semantic construct (in the case of SILFunctionArgument, the function
@@ -988,7 +989,17 @@ bool BorrowedValue::areUsesWithinExtendedScope(
988989
// Compute the local scope's liveness.
989990
MultiDefPrunedLiveness liveness(value->getFunction());
990991
computeTransitiveLiveness(liveness);
991-
return liveness.areUsesWithinBoundary(uses, deadEndBlocks);
992+
return liveness.areWithinBoundary(insts, deadEndBlocks);
993+
}
994+
995+
template bool
996+
BorrowedValue::areWithinExtendedScope<SILInstruction::OperandUserRange>(
997+
SILInstruction::OperandUserRange insts, DeadEndBlocks *deadEndBlocks) const;
998+
999+
bool BorrowedValue::areUsesWithinExtendedScope(
1000+
ArrayRef<Operand *> uses, DeadEndBlocks *deadEndBlocks) const {
1001+
SILInstruction::OperandUserRange users(uses, SILInstruction::OperandToUser());
1002+
return areWithinExtendedScope(users, deadEndBlocks);
9921003
}
9931004

9941005
// The visitor \p func is only called on final scope-ending uses, not reborrows.

0 commit comments

Comments
 (0)