Skip to content

Commit 027684a

Browse files
committed
Teach MoveOnlyTypeWrapperEliminator to lower trivial moves/borrows.
1 parent 9478d34 commit 027684a

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
///
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
1622
/// only. If a change is made, we add the defining instruction to a set list for
1723
/// post-processing. Once we have updated all types in the function, we revisit
1824
/// the instructions that we touched and update/delete them as appropriate.
1925
///
26+
/// TODO: Rename this pass to OwnershipDiagnosticLowering.
27+
///
2028
//===----------------------------------------------------------------------===//
2129

2230
#define DEBUG_TYPE "sil-move-only-type-eliminator"
@@ -139,6 +147,7 @@ struct SILMoveOnlyWrappedTypeEliminatorVisitor
139147
}
140148
DELETE_IF_TRIVIAL_OP(DestroyValue)
141149
DELETE_IF_TRIVIAL_OP(EndBorrow)
150+
DELETE_IF_TRIVIAL_OP(ExtendLifetime)
142151
#undef DELETE_IF_TRIVIAL_OP
143152

144153
#define NEED_TO_CONVERT_FORWARDING_TO_NONE_IF_TRIVIAL_OP(CLS) \
@@ -300,6 +309,19 @@ bool SILMoveOnlyWrappedTypeEliminator::process() {
300309
// - record its users for later visitation
301310
auto visitValue = [&touchedInsts, fn = fn,
302311
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+
303325
if (!value->getType().hasAnyMoveOnlyWrapping(fn))
304326
return false;
305327

0 commit comments

Comments
 (0)