25
25
26
26
using namespace swift ;
27
27
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
-
71
28
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 ;
74
32
}
75
- assert (original->getOwnershipKind () == OwnershipKind::Owned);
76
33
77
34
ValueWorklist worklist (original->getFunction ());
78
35
worklist.push (original);
@@ -82,6 +39,7 @@ bool swift::findPointerEscape(SILValue original) {
82
39
return true ;
83
40
});
84
41
}
42
+
85
43
while (auto value = worklist.pop ()) {
86
44
for (auto use : value->getUses ()) {
87
45
switch (use->getOperandOwnership ()) {
@@ -98,6 +56,22 @@ bool swift::findPointerEscape(SILValue original) {
98
56
worklist.pushIfNotVisited (phi);
99
57
break ;
100
58
}
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
+ }
101
75
default :
102
76
break ;
103
77
}
0 commit comments