Skip to content

Commit 4862ecc

Browse files
committed
Consolidate swift::findPointerEscape(SILValue) and swift::findPointerEscape(BorrowedValue)
1 parent 031255c commit 4862ecc

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

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

+20-46
Original file line numberDiff line numberDiff line change
@@ -25,54 +25,11 @@
2525

2626
using namespace swift;
2727

28-
bool swift::findPointerEscape(BorrowedValue original) {
29-
ValueWorklist worklist(original->getFunction());
30-
worklist.push(*original);
31-
32-
if (auto *phi = SILArgument::asPhi(*original)) {
33-
phi->visitTransitiveIncomingPhiOperands([&](auto *phi, auto *operand) {
34-
worklist.pushIfNotVisited(operand->get());
35-
return true;
36-
});
37-
}
38-
39-
while (auto value = worklist.pop()) {
40-
for (auto *op : value->getUses()) {
41-
switch (op->getOperandOwnership()) {
42-
case OperandOwnership::ForwardingUnowned:
43-
case OperandOwnership::PointerEscape:
44-
return true;
45-
46-
case OperandOwnership::Reborrow: {
47-
SILArgument *phi = PhiOperand(op).getValue();
48-
worklist.pushIfNotVisited(phi);
49-
break;
50-
}
51-
52-
case OperandOwnership::GuaranteedForwarding: {
53-
// This may follow guaranteed phis.
54-
ForwardingOperand(op).visitForwardedValues([&](SILValue result) {
55-
// Do not include transitive uses with 'none' ownership
56-
if (result->getOwnershipKind() == OwnershipKind::None)
57-
return true;
58-
worklist.pushIfNotVisited(result);
59-
return true;
60-
});
61-
break;
62-
}
63-
default:
64-
break;
65-
}
66-
}
67-
}
68-
return false;
69-
}
70-
7128
bool swift::findPointerEscape(SILValue original) {
72-
if (auto borrowedValue = BorrowedValue(original)) {
73-
return findPointerEscape(borrowedValue);
29+
if (original->getOwnershipKind() != OwnershipKind::Owned &&
30+
original->getOwnershipKind() != OwnershipKind::Guaranteed) {
31+
return false;
7432
}
75-
assert(original->getOwnershipKind() == OwnershipKind::Owned);
7633

7734
ValueWorklist worklist(original->getFunction());
7835
worklist.push(original);
@@ -82,6 +39,7 @@ bool swift::findPointerEscape(SILValue original) {
8239
return true;
8340
});
8441
}
42+
8543
while (auto value = worklist.pop()) {
8644
for (auto use : value->getUses()) {
8745
switch (use->getOperandOwnership()) {
@@ -98,6 +56,22 @@ bool swift::findPointerEscape(SILValue original) {
9856
worklist.pushIfNotVisited(phi);
9957
break;
10058
}
59+
case OperandOwnership::Reborrow: {
60+
SILArgument *phi = PhiOperand(use).getValue();
61+
worklist.pushIfNotVisited(phi);
62+
break;
63+
}
64+
case OperandOwnership::GuaranteedForwarding: {
65+
// This may follow guaranteed phis.
66+
ForwardingOperand(use).visitForwardedValues([&](SILValue result) {
67+
// Do not include transitive uses with 'none' ownership
68+
if (result->getOwnershipKind() == OwnershipKind::None)
69+
return true;
70+
worklist.pushIfNotVisited(result);
71+
return true;
72+
});
73+
break;
74+
}
10175
default:
10276
break;
10377
}

0 commit comments

Comments
 (0)