Skip to content

Commit d49e9ea

Browse files
committed
[NFC] PrunedLiveness: Factor out areWithinBoundary
For historical reasons, there was an API to check whether operands were within the boundary which just checked whether those operands' users were within the buondary. Make a copy of the method deal in instructions and factor the original API through it.
1 parent 540882f commit d49e9ea

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

include/swift/SIL/PrunedLiveness.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,20 @@ class PrunedLiveRange : public PrunedLiveness {
729729
bool isWithinBoundary(SILInstruction *inst,
730730
DeadEndBlocks *deadEndBlocks) const;
731731

732+
/// Whether all \p insts are between this def and the liveness boundary;
733+
/// \p deadEndBlocks is optional.
734+
template <typename Instructions>
735+
bool areWithinBoundary(Instructions insts,
736+
DeadEndBlocks *deadEndBlocks) const {
737+
assert(asImpl().isInitialized());
738+
739+
for (auto *inst : insts) {
740+
if (!isWithinBoundary(inst, deadEndBlocks))
741+
return false;
742+
}
743+
return true;
744+
};
745+
732746
/// Returns true when all \p uses are between this def and the liveness
733747
/// boundary \p deadEndBlocks is optional.
734748
bool areUsesWithinBoundary(ArrayRef<Operand *> uses,

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,8 @@ static FunctionTest SSAPrunedLiveness__areUsesWithinBoundary(
796796
template <typename LivenessWithDefs>
797797
bool PrunedLiveRange<LivenessWithDefs>::areUsesWithinBoundary(
798798
ArrayRef<Operand *> uses, DeadEndBlocks *deadEndBlocks) const {
799-
assert(asImpl().isInitialized());
800-
801-
for (auto *use : uses) {
802-
auto *user = use->getUser();
803-
if (!isWithinBoundary(user, deadEndBlocks))
804-
return false;
805-
}
806-
return true;
799+
SILInstruction::OperandUserRange users(uses, SILInstruction::OperandToUser());
800+
return areWithinBoundary(users, deadEndBlocks);
807801
}
808802

809803
template <typename LivenessWithDefs>

0 commit comments

Comments
 (0)