|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 | ///
|
13 |
| -/// This file contains an optimizer pass that lowers away move only types from |
14 |
| -/// SIL. It can run on all types or just trivial types. It works by Walking all |
15 |
| -/// values in the IR and unsafely converting their type to be without move |
| 13 | +/// Eliminate SIL constructs required by ownership diagnostics. |
| 14 | +/// |
| 15 | +/// 1. Remove ownership operations on nonowned values: move_value, begin_borrow, |
| 16 | +/// extend_lifetime. |
| 17 | +/// |
| 18 | +/// 2. Remove instructions that convert to and from MoveOnlyWrapped types. |
| 19 | +/// |
| 20 | +/// This pass can run on all types or just trivial types. It works by Walking |
| 21 | +/// all values in the IR and unsafely converting their type to be without move |
16 | 22 | /// only. If a change is made, we add the defining instruction to a set list for
|
17 | 23 | /// post-processing. Once we have updated all types in the function, we revisit
|
18 | 24 | /// the instructions that we touched and update/delete them as appropriate.
|
19 | 25 | ///
|
| 26 | +/// TODO: Rename this pass to OwnershipDiagnosticLowering. |
| 27 | +/// |
20 | 28 | //===----------------------------------------------------------------------===//
|
21 | 29 |
|
22 | 30 | #define DEBUG_TYPE "sil-move-only-type-eliminator"
|
@@ -139,6 +147,7 @@ struct SILMoveOnlyWrappedTypeEliminatorVisitor
|
139 | 147 | }
|
140 | 148 | DELETE_IF_TRIVIAL_OP(DestroyValue)
|
141 | 149 | DELETE_IF_TRIVIAL_OP(EndBorrow)
|
| 150 | + DELETE_IF_TRIVIAL_OP(ExtendLifetime) |
142 | 151 | #undef DELETE_IF_TRIVIAL_OP
|
143 | 152 |
|
144 | 153 | #define NEED_TO_CONVERT_FORWARDING_TO_NONE_IF_TRIVIAL_OP(CLS) \
|
@@ -300,6 +309,19 @@ bool SILMoveOnlyWrappedTypeEliminator::process() {
|
300 | 309 | // - record its users for later visitation
|
301 | 310 | auto visitValue = [&touchedInsts, fn = fn,
|
302 | 311 | trivialOnly = trivialOnly](SILValue value) -> bool {
|
| 312 | + // Trivial move_value instructions are relevant. After they are stripped, |
| 313 | + // any extend_lifetime uses are also stripped. |
| 314 | + if (isa<MoveValueInst>(value) |
| 315 | + && value->getOwnershipKind() == OwnershipKind::None) { |
| 316 | + for (auto *use : value->getNonTypeDependentUses()) { |
| 317 | + auto *user = use->getUser(); |
| 318 | + if (isa<ExtendLifetimeInst>(user)) { |
| 319 | + touchedInsts.insert(user); |
| 320 | + } |
| 321 | + } |
| 322 | + return true; |
| 323 | + } |
| 324 | + |
303 | 325 | if (!value->getType().hasAnyMoveOnlyWrapping(fn))
|
304 | 326 | return false;
|
305 | 327 |
|
|
0 commit comments