Skip to content

Commit a9079bc

Browse files
committed
[SILGen] Used move_value for @noImplicitCopy.
Replace the pattern of begin_borrow [lexical] + copy_value with move_value [lexical] to avoid introducing a spurious copy to begin with.
1 parent 7a1829f commit a9079bc

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,7 @@ class LetValueInitialization : public Initialization {
816816

817817
// If we have a no implicit copy lexical, emit the instruction stream so
818818
// that the move checker knows to check this variable.
819-
value = SGF.B.createBeginBorrow(PrologueLoc, value,
820-
/*isLexical*/ true);
821-
value = SGF.B.createCopyValue(PrologueLoc, value);
819+
value = SGF.B.createMoveValue(PrologueLoc, value, /*IisLexical*/ true);
822820
value = SGF.B.createOwnedCopyableToMoveOnlyWrapperValue(PrologueLoc, value);
823821
return SGF.B.createMarkMustCheckInst(
824822
PrologueLoc, value,
@@ -2155,14 +2153,10 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
21552153

21562154
if (auto *copyToMove = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
21572155
mvi->getOperand())) {
2158-
if (auto *cvi = dyn_cast<CopyValueInst>(copyToMove->getOperand())) {
2159-
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
2160-
if (bbi->isLexical()) {
2161-
B.emitDestroyValueOperation(silLoc, mvi);
2162-
B.createEndBorrow(silLoc, bbi);
2163-
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
2164-
return;
2165-
}
2156+
if (auto *move = dyn_cast<MoveValueInst>(copyToMove->getOperand())) {
2157+
if (move->isLexical()) {
2158+
B.emitDestroyValueOperation(silLoc, mvi);
2159+
return;
21662160
}
21672161
}
21682162
}

lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerUtils.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,10 @@ bool swift::siloptimizer::searchForCandidateObjectMarkMustChecks(
228228
// Or for a move only type, we look for a move_value [lexical].
229229
if (auto *mvi = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
230230
mmci->getOperand())) {
231-
if (auto *cvi = dyn_cast<CopyValueInst>(mvi->getOperand())) {
232-
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
233-
if (bbi->isLexical()) {
234-
moveIntroducersToProcess.insert(mmci);
235-
continue;
236-
}
231+
if (auto *move = dyn_cast<MoveValueInst>(mvi->getOperand())) {
232+
if (move->isLexical()) {
233+
moveIntroducersToProcess.insert(mmci);
234+
continue;
237235
}
238236
}
239237
}

test/SILGen/noimplicitcopy.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,8 @@ func callClosureIntOwned() {
333333
// NOTE: MOW expands to MOVEONLYWRAPPED
334334
//
335335
// CHECK-LABEL: sil hidden [ossa] @$s14noimplicitcopy10printKlassyyF : $@convention(thin) () -> () {
336-
// CHECK: [[X:%.*]] = begin_borrow [lexical] {{%[0-9]+}} : $Klass
337-
// CHECK: [[X_COPY:%.*]] = copy_value [[X]]
338-
// CHECK: [[X_MOVEONLYWRAPPED:%.*]] = copyable_to_moveonlywrapper [owned] [[X_COPY]]
336+
// CHECK: [[X:%.*]] = move_value [lexical] {{%[0-9]+}} : $Klass
337+
// CHECK: [[X_MOVEONLYWRAPPED:%.*]] = copyable_to_moveonlywrapper [owned] [[X]]
339338
// CHECK: [[X_MOVEONLYWRAPPED_MARKED:%.*]] = mark_must_check [consumable_and_assignable] [[X_MOVEONLYWRAPPED]]
340339
// CHECK: [[BORROWED_X_MOVEONLYWRAPPED_MARKED:%.*]] = begin_borrow [[X_MOVEONLYWRAPPED_MARKED]]
341340
// CHECK: [[FUNC:%.*]] = class_method [[BORROWED_X_MOVEONLYWRAPPED_MARKED]]

test/SILOptimizer/noimplicitcopy_borrow_to_destructure_transform_diagnostics.sil

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ sil [ossa] @aggStructConsumeField : $@convention(thin) (@guaranteed AggStruct) -
2323
bb0(%0 : @guaranteed $AggStruct):
2424
debug_value %0 : $AggStruct, let, name "x", argno 1
2525
%2 = copy_value %0 : $AggStruct
26-
%3 = begin_borrow [lexical] %2 : $AggStruct
27-
%4 = copy_value %3 : $AggStruct
28-
%5 = copyable_to_moveonlywrapper [owned] %4 : $AggStruct
26+
%3 = move_value [lexical] %2 : $AggStruct
27+
%5 = copyable_to_moveonlywrapper [owned] %3 : $AggStruct
2928
%6 = mark_must_check [consumable_and_assignable] %5 : $@moveOnly AggStruct
3029
debug_value %6 : $@moveOnly AggStruct, let, name "x2"
3130
%8 = begin_borrow %6 : $@moveOnly AggStruct
@@ -52,8 +51,6 @@ bb2:
5251

5352
bb3:
5453
destroy_value %6 : $@moveOnly AggStruct
55-
end_borrow %3 : $AggStruct
56-
destroy_value %2 : $AggStruct
5754
%64 = tuple ()
5855
return %64 : $()
5956
}

0 commit comments

Comments
 (0)