GH-143732: SEND specialization (GH-148963)

* SEND specialization. Adds 2 new specialized instructions:

* SEND_VIRTUAL: for sends to virtual iterators e.g lists and tuples
* SEND_ASYNC_GEN: for sends to async generators

Tweak FOR_ITER_VIRTUAL so that SEND_VIRTUAL and FOR_ITER_VIRTUAL use equivalent guards
This commit is contained in:
Mark Shannon 2026-05-05 15:19:16 +01:00 committed by GitHub
parent ffb543d32f
commit 70bd1c2dd2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 2662 additions and 1548 deletions

View file

@ -1860,8 +1860,15 @@
}
case _GET_ANEXT: {
JitOptRef aiter;
JitOptRef awaitable;
awaitable = sym_new_not_null(ctx);
aiter = stack_pointer[-1];
if (sym_matches_type(aiter, &PyAsyncGen_Type)) {
awaitable = sym_new_type(ctx, &_PyAsyncGenASend_Type);
}
else {
awaitable = sym_new_not_null(ctx);
}
CHECK_STACK_BOUNDS(1);
stack_pointer[0] = awaitable;
stack_pointer += 1;
@ -1876,8 +1883,6 @@
break;
}
/* _SEND is not a viable micro-op for tier 2 */
case _SEND_GEN_FRAME: {
JitOptRef v;
JitOptRef receiver;
@ -1896,6 +1901,58 @@
break;
}
case _GUARD_TOS_IS_NONE: {
break;
}
case _GUARD_NOS_NOT_NULL: {
JitOptRef nos;
nos = stack_pointer[-2];
if (sym_is_not_null(nos)) {
ADD_OP(_NOP, 0, 0);
}
else {
sym_set_non_null(nos);
}
break;
}
/* _SEND_VIRTUAL is not a viable micro-op for tier 2 */
case _SEND_VIRTUAL_TIER_TWO: {
JitOptRef next;
next = sym_new_not_null(ctx);
stack_pointer[-1] = next;
break;
}
case _GUARD_3OS_ASYNC_GEN_ASEND: {
JitOptRef iter;
iter = stack_pointer[-3];
if (sym_matches_type(iter, &_PyAsyncGenASend_Type)) {
REPLACE_OP(this_instr, _NOP, 0, 0);
}
else {
sym_set_type(iter, &_PyAsyncGenASend_Type);
}
break;
}
/* _SEND_ASYNC_GEN is not a viable micro-op for tier 2 */
case _SEND_ASYNC_GEN_TIER_TWO: {
JitOptRef asend;
JitOptRef null_out;
JitOptRef retval;
asend = sym_new_not_null(ctx);
null_out = sym_new_not_null(ctx);
retval = sym_new_not_null(ctx);
stack_pointer[-3] = asend;
stack_pointer[-2] = null_out;
stack_pointer[-1] = retval;
break;
}
case _YIELD_VALUE: {
JitOptRef retval;
JitOptRef value;
@ -3687,6 +3744,18 @@
break;
}
case _GUARD_TOS_NOT_NULL: {
JitOptRef null_or_index;
null_or_index = stack_pointer[-1];
if (sym_is_not_null(null_or_index)) {
REPLACE_OP(this_instr, _NOP, 0, 0);
}
else {
sym_set_non_null(null_or_index);
}
break;
}
/* _FOR_ITER_VIRTUAL is not a viable micro-op for tier 2 */
case _FOR_ITER_VIRTUAL_TIER_TWO: {
@ -4211,18 +4280,6 @@
break;
}
case _GUARD_NOS_NOT_NULL: {
JitOptRef nos;
nos = stack_pointer[-2];
if (sym_is_not_null(nos)) {
ADD_OP(_NOP, 0, 0);
}
else {
sym_set_non_null(nos);
}
break;
}
case _GUARD_THIRD_NULL: {
JitOptRef null;
null = stack_pointer[-3];