Skip to content

Commit deb1ded

Browse files
Merge pull request #36815 from aschwaighofer/remove_hop_to_executor_in_no_async
hop_to_executor should have no affect if we inline a [noasync] applyinto a non async function.
2 parents 322fc2c + d4246b9 commit deb1ded

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6138,6 +6138,11 @@ void IRGenSILFunction::visitCheckedCastAddrBranchInst(
61386138
}
61396139

61406140
void IRGenSILFunction::visitHopToExecutorInst(HopToExecutorInst *i) {
6141+
if (!i->getFunction()->isAsync()) {
6142+
// This should never occur.
6143+
assert(false && "The hop_to_executor should have been eliminated");
6144+
return;
6145+
}
61416146
assert(i->getTargetExecutor()->getType().is<BuiltinExecutorType>());
61426147
llvm::Value *resumeFn = Builder.CreateIntrinsicCall(
61436148
llvm::Intrinsic::coro_async_resume, {});

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class SILInlineCloner
288288

289289
void visitDebugValueInst(DebugValueInst *Inst);
290290
void visitDebugValueAddrInst(DebugValueAddrInst *Inst);
291+
void visitHopToExecutorInst(HopToExecutorInst *Inst);
291292

292293
void visitTerminator(SILBasicBlock *BB);
293294

@@ -620,7 +621,15 @@ void SILInlineCloner::visitDebugValueAddrInst(DebugValueAddrInst *Inst) {
620621

621622
return SILCloner<SILInlineCloner>::visitDebugValueAddrInst(Inst);
622623
}
624+
void SILInlineCloner::visitHopToExecutorInst(HopToExecutorInst *Inst) {
625+
// Drop hop_to_executor in non async functions.
626+
if (!Apply.getFunction()->isAsync()) {
627+
assert(Apply.isNonAsync());
628+
return;
629+
}
623630

631+
return SILCloner<SILInlineCloner>::visitHopToExecutorInst(Inst);
632+
}
624633
const SILDebugScope *
625634
SILInlineCloner::getOrCreateInlineScope(const SILDebugScope *CalleeScope) {
626635
if (!CalleeScope)

test/SILOptimizer/mandatory_inlining.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,3 +1481,22 @@ bb0:
14811481
return %r : $()
14821482
}
14831483

1484+
sil [transparent] @hop_to_executor : $@convention(thin) @async (@guaranteed Builtin.Executor) -> () {
1485+
entry(%executor: $Builtin.Executor):
1486+
hop_to_executor %executor : $Builtin.Executor
1487+
%r = tuple ()
1488+
return %r : $()
1489+
}
1490+
1491+
// CHECK-LABEL: sil @test_inline_nonasync
1492+
// CHECK-NOT: hop_to_executor
1493+
// CHECK-NOT: apply
1494+
// CHECK: } // end sil function 'test_inline_nonasync'
1495+
1496+
sil @test_inline_nonasync : $@convention(thin) (@guaranteed Builtin.Executor) -> () {
1497+
entry(%executor: $Builtin.Executor):
1498+
%f = function_ref @hop_to_executor : $@convention(thin) @async (@guaranteed Builtin.Executor) -> ()
1499+
%c = apply [noasync] %f(%executor) : $@convention(thin) @async (@guaranteed Builtin.Executor) -> ()
1500+
%r = tuple ()
1501+
return %r : $()
1502+
}

test/SILOptimizer/performance_inliner.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,3 +994,22 @@ bb0(%1 : $@thick X.Type):
994994
return %30 : $X
995995
}
996996

997+
sil @hop_to_executor : $@convention(thin) @async (@guaranteed Builtin.Executor) -> () {
998+
entry(%executor: $Builtin.Executor):
999+
hop_to_executor %executor : $Builtin.Executor
1000+
%r = tuple ()
1001+
return %r : $()
1002+
}
1003+
1004+
// CHECK-LABEL: sil @test_inline_nonasync
1005+
// CHECK-NOT: hop_to_executor
1006+
// CHECK-NOT: apply
1007+
// CHECK: } // end sil function 'test_inline_nonasync'
1008+
1009+
sil @test_inline_nonasync : $@convention(thin) (@guaranteed Builtin.Executor) -> () {
1010+
entry(%executor: $Builtin.Executor):
1011+
%f = function_ref @hop_to_executor : $@convention(thin) @async (@guaranteed Builtin.Executor) -> ()
1012+
%c = apply [noasync] %f(%executor) : $@convention(thin) @async (@guaranteed Builtin.Executor) -> ()
1013+
%r = tuple ()
1014+
return %r : $()
1015+
}

0 commit comments

Comments
 (0)