Skip to content

Commit d23139f

Browse files
committed
[OwnershipUtils] Added find for simple value.
1 parent 49044d0 commit d23139f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ bool findExtendedTransitiveGuaranteedUses(
169169
SILValue guaranteedValue,
170170
SmallVectorImpl<Operand *> &usePoints);
171171

172+
/// Find non-transitive uses of a simple (i.e. without looking through
173+
/// reborrows) value.
174+
///
175+
/// The scope-ending use of borrows of the value are included. If a borrow of
176+
/// the value is reborrowed, returns false.
177+
bool findUsesOfSimpleValue(SILValue value,
178+
SmallVectorImpl<Operand *> *usePoints = nullptr);
179+
172180
/// An operand that forwards ownership to one or more results.
173181
class ForwardingOperand {
174182
Operand *use = nullptr;

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,25 @@ bool swift::findExtendedUsesOfSimpleBorrowedValue(
305305
return true;
306306
}
307307

308+
bool swift::findUsesOfSimpleValue(SILValue value,
309+
SmallVectorImpl<Operand *> *usePoints) {
310+
for (auto *use : value->getUses()) {
311+
if (use->getOperandOwnership() == OperandOwnership::Borrow) {
312+
if (!BorrowingOperand(use).visitScopeEndingUses([&](Operand *end) {
313+
if (end->getOperandOwnership() == OperandOwnership::Reborrow) {
314+
return false;
315+
}
316+
usePoints->push_back(use);
317+
return true;
318+
})) {
319+
return false;
320+
}
321+
}
322+
usePoints->push_back(use);
323+
}
324+
return true;
325+
}
326+
308327
// Find all use points of \p guaranteedValue within its borrow scope. All use
309328
// points will be dominated by \p guaranteedValue.
310329
//

0 commit comments

Comments
 (0)