Skip to content

Commit adb842b

Browse files
Merge pull request #67237 from nate-chandler/opt_hop_to_executor/20230711/1
[OptimizeHopToExecutor] Don't hop for begin_borrow/end_borrow.
2 parents 9711ddd + 252b563 commit adb842b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/SILOptimizer/Mandatory/OptimizeHopToExecutor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,14 @@ bool OptimizeHopToExecutor::needsExecutor(SILInstruction *inst) {
331331
if (auto *copy = dyn_cast<CopyAddrInst>(inst)) {
332332
return isGlobalMemory(copy->getSrc()) || isGlobalMemory(copy->getDest());
333333
}
334+
// BeginBorrowInst and EndBorrowInst currently have
335+
// MemoryBehavior::MayHaveSideEffects. Fixing that is tracked by
336+
// rdar://111875527. These instructions only have effects in the sense of
337+
// memory dependencies, which aren't relevant for hop_to_executor
338+
// elimination.
339+
if (isa<BeginBorrowInst>(inst) || isa<EndBorrowInst>(inst)) {
340+
return false;
341+
}
334342
return inst->mayReadOrWriteMemory();
335343
}
336344

test/SILOptimizer/optimize_hop_to_executor.sil

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,27 @@ bb0(%0 : @guaranteed $MyActor):
278278
%r = tuple ()
279279
return %r : $()
280280
}
281+
282+
// CHECK-LABEL: sil [ossa] @handleBeginBorrow : {{.*}} {
283+
// CHECK-NOT: hop_to_executor
284+
// CHECK-LABEL: } // end sil function 'handleBeginBorrow'
285+
sil [ossa] @handleBeginBorrow : $@convention(method) @async (@guaranteed MyActor) -> () {
286+
bb0(%0 : @guaranteed $MyActor):
287+
hop_to_executor %0 : $MyActor
288+
%b = begin_borrow %0 : $MyActor
289+
end_borrow %b : $MyActor
290+
%r = tuple ()
291+
return %r : $()
292+
}
293+
294+
// CHECK-LABEL: sil [ossa] @handleEndBorrow : {{.*}} {
295+
// CHECK-NOT: hop_to_executor
296+
// CHECK-LABEL: } // end sil function 'handleEndBorrow'
297+
sil [ossa] @handleEndBorrow : $@convention(method) @async (@guaranteed MyActor) -> () {
298+
bb0(%0 : @guaranteed $MyActor):
299+
%b = begin_borrow %0 : $MyActor
300+
hop_to_executor %0 : $MyActor
301+
end_borrow %b : $MyActor
302+
%r = tuple ()
303+
return %r : $()
304+
}

0 commit comments

Comments
 (0)