|
21 | 21 | /// destroys. Initializes `liveness`.
|
22 | 22 | ///
|
23 | 23 | /// 2. Find `def`s final destroy points based on its pruned
|
24 |
| -/// liveness. Initializes `consumes` and inserts new destroy_value |
25 |
| -/// instructions. |
| 24 | +/// liveness. Initializes `consumes` and inserts new destroy_value |
| 25 | +/// instructions. |
26 | 26 | ///
|
27 |
| -/// 3. Rewrite `def`s original copies and destroys, inserting new copies |
28 |
| -/// where needed. Deletes original copies and destroys and inserts new copies. |
| 27 | +/// 3. Rewrite `def`s original copies and destroys, inserting new copies where |
| 28 | +/// needed. Deletes original copies and destroys and inserts new copies. |
29 | 29 | ///
|
30 | 30 | /// See CanonicalOSSALifetime.h for examples.
|
31 | 31 | ///
|
@@ -57,6 +57,34 @@ STATISTIC(NumCopiesGenerated, "number of copy_value instructions created");
|
57 | 57 | STATISTIC(NumDestroysGenerated, "number of destroy_value instructions created");
|
58 | 58 | STATISTIC(NumUnknownUsers, "number of functions with unknown users");
|
59 | 59 |
|
| 60 | +/// This use-def walk must be consistent with the def-use walks performed |
| 61 | +/// within the canonicalizeValueLifetime() implementation. |
| 62 | +SILValue CanonicalizeOSSALifetime::getCanonicalCopiedDef(SILValue v) { |
| 63 | + while (auto *copy = dyn_cast<CopyValueInst>(v)) { |
| 64 | + auto def = copy->getOperand(); |
| 65 | + if (def.getOwnershipKind() == OwnershipKind::Owned) { |
| 66 | + v = def; |
| 67 | + continue; |
| 68 | + } |
| 69 | + if (auto borrowedVal = BorrowedValue::get(def)) { |
| 70 | + // Any def's that aren't filtered out here must be handled by |
| 71 | + // computeBorrowLiveness. |
| 72 | + switch (borrowedVal->kind) { |
| 73 | + case BorrowedValueKind::SILFunctionArgument: |
| 74 | + case BorrowedValueKind::BeginBorrow: |
| 75 | + return def; |
| 76 | + case BorrowedValueKind::LoadBorrow: |
| 77 | + case BorrowedValueKind::Phi: |
| 78 | + break; |
| 79 | + } |
| 80 | + } |
| 81 | + // This guaranteed value cannot be handled, treat the copy as an owned |
| 82 | + // live range def instead. |
| 83 | + return copy; |
| 84 | + } |
| 85 | + return v; |
| 86 | +} |
| 87 | + |
60 | 88 | //===----------------------------------------------------------------------===//
|
61 | 89 | // MARK: Rewrite borrow scopes
|
62 | 90 | //===----------------------------------------------------------------------===//
|
@@ -224,7 +252,7 @@ bool CanonicalizeOSSALifetime::computeCanonicalLiveness() {
|
224 | 252 | if (pruneDebug) {
|
225 | 253 | if (auto *dvi = dyn_cast<DebugValueInst>(user)) {
|
226 | 254 | // Only instructions potentially outside current pruned liveness are
|
227 |
| - // insteresting. |
| 255 | + // interesting. |
228 | 256 | if (liveness.getBlockLiveness(dvi->getParent())
|
229 | 257 | != PrunedLiveBlocks::LiveOut) {
|
230 | 258 | recordDebugValue(dvi);
|
|
0 commit comments