|
25 | 25 |
|
26 | 26 | using namespace swift;
|
27 | 27 |
|
28 |
| -bool swift::hasPointerEscape(BorrowedValue value) { |
29 |
| - assert(value.kind == BorrowedValueKind::BeginBorrow || |
30 |
| - value.kind == BorrowedValueKind::LoadBorrow); |
31 |
| - GraphNodeWorklist<Operand *, 8> worklist; |
32 |
| - for (Operand *use : value->getUses()) { |
33 |
| - if (use->getOperandOwnership() != OperandOwnership::NonUse) |
34 |
| - worklist.insert(use); |
35 |
| - } |
36 |
| - |
37 |
| - while (Operand *op = worklist.pop()) { |
38 |
| - switch (op->getOperandOwnership()) { |
39 |
| - case OperandOwnership::NonUse: |
40 |
| - case OperandOwnership::TrivialUse: |
41 |
| - case OperandOwnership::ForwardingConsume: |
42 |
| - case OperandOwnership::DestroyingConsume: |
43 |
| - llvm_unreachable("this operand cannot handle an inner guaranteed use"); |
| 28 | +bool swift::hasPointerEscape(BorrowedValue original) { |
| 29 | + ValueWorklist worklist(original->getFunction()); |
| 30 | + worklist.push(*original); |
44 | 31 |
|
45 |
| - case OperandOwnership::ForwardingUnowned: |
46 |
| - case OperandOwnership::PointerEscape: |
| 32 | + if (auto *phi = SILArgument::asPhi(*original)) { |
| 33 | + phi->visitTransitiveIncomingPhiOperands([&](auto *phi, auto *operand) { |
| 34 | + worklist.pushIfNotVisited(operand->get()); |
47 | 35 | return true;
|
| 36 | + }); |
| 37 | + } |
48 | 38 |
|
49 |
| - case OperandOwnership::Borrow: |
50 |
| - case OperandOwnership::EndBorrow: |
51 |
| - case OperandOwnership::InstantaneousUse: |
52 |
| - case OperandOwnership::UnownedInstantaneousUse: |
53 |
| - case OperandOwnership::InteriorPointer: |
54 |
| - case OperandOwnership::BitwiseEscape: |
55 |
| - break; |
56 |
| - case OperandOwnership::Reborrow: { |
57 |
| - SILArgument *phi = cast<BranchInst>(op->getUser()) |
58 |
| - ->getDestBB() |
59 |
| - ->getArgument(op->getOperandNumber()); |
60 |
| - for (auto *use : phi->getUses()) { |
61 |
| - if (use->getOperandOwnership() != OperandOwnership::NonUse) |
62 |
| - worklist.insert(use); |
| 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; |
63 | 50 | }
|
64 |
| - break; |
65 |
| - } |
66 |
| - case OperandOwnership::GuaranteedForwarding: { |
67 |
| - // This may follow a guaranteed phis. |
68 |
| - ForwardingOperand(op).visitForwardedValues([&](SILValue result) { |
69 |
| - // Do not include transitive uses with 'none' ownership |
70 |
| - if (result->getOwnershipKind() == OwnershipKind::None) |
| 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); |
71 | 59 | return true;
|
72 |
| - for (auto *resultUse : result->getUses()) { |
73 |
| - if (resultUse->getOperandOwnership() != OperandOwnership::NonUse) { |
74 |
| - worklist.insert(resultUse); |
75 |
| - } |
76 |
| - } |
77 |
| - return true; |
78 |
| - }); |
79 |
| - break; |
80 |
| - } |
| 60 | + }); |
| 61 | + break; |
| 62 | + } |
| 63 | + default: |
| 64 | + break; |
| 65 | + } |
81 | 66 | }
|
82 | 67 | }
|
83 | 68 | return false;
|
|
0 commit comments