Merge pull request #67237 from nate-chandler/opt_hop_to_executor/20230711/1

[OptimizeHopToExecutor] Don't hop for begin_borrow/end_borrow.
This commit is contained in:
nate-chandler
2023-07-12 07:02:24 -07:00
committed by GitHub
2 changed files with 32 additions and 0 deletions

View File

@@ -331,6 +331,14 @@ bool OptimizeHopToExecutor::needsExecutor(SILInstruction *inst) {
if (auto *copy = dyn_cast<CopyAddrInst>(inst)) {
return isGlobalMemory(copy->getSrc()) || isGlobalMemory(copy->getDest());
}
// BeginBorrowInst and EndBorrowInst currently have
// MemoryBehavior::MayHaveSideEffects. Fixing that is tracked by
// rdar://111875527. These instructions only have effects in the sense of
// memory dependencies, which aren't relevant for hop_to_executor
// elimination.
if (isa<BeginBorrowInst>(inst) || isa<EndBorrowInst>(inst)) {
return false;
}
return inst->mayReadOrWriteMemory();
}

View File

@@ -278,3 +278,27 @@ bb0(%0 : @guaranteed $MyActor):
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: sil [ossa] @handleBeginBorrow : {{.*}} {
// CHECK-NOT: hop_to_executor
// CHECK-LABEL: } // end sil function 'handleBeginBorrow'
sil [ossa] @handleBeginBorrow : $@convention(method) @async (@guaranteed MyActor) -> () {
bb0(%0 : @guaranteed $MyActor):
hop_to_executor %0 : $MyActor
%b = begin_borrow %0 : $MyActor
end_borrow %b : $MyActor
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: sil [ossa] @handleEndBorrow : {{.*}} {
// CHECK-NOT: hop_to_executor
// CHECK-LABEL: } // end sil function 'handleEndBorrow'
sil [ossa] @handleEndBorrow : $@convention(method) @async (@guaranteed MyActor) -> () {
bb0(%0 : @guaranteed $MyActor):
%b = begin_borrow %0 : $MyActor
hop_to_executor %0 : $MyActor
end_borrow %b : $MyActor
%r = tuple ()
return %r : $()
}