Skip to content

Commit 5907d5d

Browse files
committed
[SIL] Add hasPointerEscape(SILValue).
There is a preexisting function with this name that takes a BorrowedValue. The new function calls that preexisting function if a BorrowedValue can be constructed from the SILValue. Otherwise, it looks for direct uses of the value which qualify as "pointer escapes".
1 parent f284e72 commit 5907d5d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ inline bool isForwardingConsume(SILValue value) {
122122

123123
bool hasPointerEscape(BorrowedValue value);
124124

125+
/// Whether the specified OSSA-lifetime introducer has a pointer escape.
126+
///
127+
/// precondition: \p value introduces an OSSA-lifetime, either a BorrowedValue
128+
/// can be constructed from it or it's an owned value
129+
bool hasPointerEscape(SILValue value);
130+
125131
/// Find leaf "use points" of \p guaranteedValue that determine its lifetime
126132
/// requirement. Return true if no PointerEscape use was found.
127133
///

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ bool swift::hasPointerEscape(BorrowedValue value) {
8383
return false;
8484
}
8585

86+
bool swift::hasPointerEscape(SILValue value) {
87+
if (auto borrowedValue = BorrowedValue(value)) {
88+
return hasPointerEscape(borrowedValue);
89+
}
90+
assert(value->getOwnershipKind() == OwnershipKind::Owned);
91+
for (auto use : value->getUses()) {
92+
switch (use->getOperandOwnership()) {
93+
case OperandOwnership::PointerEscape:
94+
case OperandOwnership::ForwardingUnowned:
95+
return true;
96+
default:
97+
break;
98+
}
99+
}
100+
return false;
101+
}
102+
86103
bool swift::canOpcodeForwardInnerGuaranteedValues(SILValue value) {
87104
// If we have an argument from a transforming terminator, we can forward
88105
// guaranteed.

0 commit comments

Comments
 (0)