mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-106529: Make FOR_ITER a viable uop (#112134)
This uses the new mechanism whereby certain uops are replaced by others during translation, using the `_PyUop_Replacements` table. We further special-case the `_FOR_ITER_TIER_TWO` uop to update the deoptimization target to point just past the corresponding `END_FOR` opcode. Two tiny code cleanups are also part of this PR.
This commit is contained in:
parent
d59feb5dbe
commit
1995955173
8 changed files with 138 additions and 43 deletions
25
Python/executor_cases.c.h
generated
25
Python/executor_cases.c.h
generated
|
@ -2101,6 +2101,31 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _FOR_ITER_TIER_TWO: {
|
||||
PyObject *iter;
|
||||
PyObject *next;
|
||||
iter = stack_pointer[-1];
|
||||
/* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */
|
||||
next = (*Py_TYPE(iter)->tp_iternext)(iter);
|
||||
if (next == NULL) {
|
||||
if (_PyErr_Occurred(tstate)) {
|
||||
if (!_PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) {
|
||||
GOTO_ERROR(error);
|
||||
}
|
||||
_PyErr_Clear(tstate);
|
||||
}
|
||||
/* iterator ended normally */
|
||||
Py_DECREF(iter);
|
||||
STACK_SHRINK(1);
|
||||
/* The translator sets the deopt target just past END_FOR */
|
||||
DEOPT_IF(true, _FOR_ITER_TIER_TWO);
|
||||
}
|
||||
// Common case: no jump, leave it to the code generator
|
||||
STACK_GROW(1);
|
||||
stack_pointer[-1] = next;
|
||||
break;
|
||||
}
|
||||
|
||||
case _ITER_CHECK_LIST: {
|
||||
PyObject *iter;
|
||||
iter = stack_pointer[-1];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue