aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/optimizer.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2023-11-20 10:08:53 -0800
committerGitHub <noreply@github.com>2023-11-20 10:08:53 -0800
commit1995955173737bcb009dbacaeff7821b4d744148 (patch)
tree96a6c3f5901c4ed2c4cf5fa205231f7216a6e9c1 /Python/optimizer.c
parentd59feb5dbe5395615d06c30a95e6a6a9b7681d4d (diff)
downloadcpython-1995955173737bcb009dbacaeff7821b4d744148.tar.gz
cpython-1995955173737bcb009dbacaeff7821b4d744148.zip
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.
Diffstat (limited to 'Python/optimizer.c')
-rw-r--r--Python/optimizer.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Python/optimizer.c b/Python/optimizer.c
index 64a15e0dd66..261a5ffd1e2 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -392,6 +392,7 @@ _PyUop_Replacements[OPCODE_METADATA_SIZE] = {
[_ITER_JUMP_RANGE] = _GUARD_NOT_EXHAUSTED_RANGE,
[_ITER_JUMP_LIST] = _GUARD_NOT_EXHAUSTED_LIST,
[_ITER_JUMP_TUPLE] = _GUARD_NOT_EXHAUSTED_TUPLE,
+ [_FOR_ITER] = _FOR_ITER_TIER_TWO,
};
static const uint16_t
@@ -620,6 +621,11 @@ top: // Jump here after _PUSH_FRAME or likely branches
}
if (_PyUop_Replacements[uop]) {
uop = _PyUop_Replacements[uop];
+ if (uop == _FOR_ITER_TIER_TWO) {
+ target += 1 + INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1;
+ assert(_PyCode_CODE(code)[target-1].op.code == END_FOR ||
+ _PyCode_CODE(code)[target-1].op.code == INSTRUMENTED_END_FOR);
+ }
}
break;
case OPARG_CACHE_1: