aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-06-02 11:46:18 +0100
committerGitHub <noreply@github.com>2023-06-02 11:46:18 +0100
commit4bfa01b9d911ce9358cf1a453bee15554f8e4c07 (patch)
treebd61d8459bf30d42abf0be7258de91360bea434b /Python/bytecodes.c
parent601ae09f0c8eda213b9050892f5ce9b91f0aa522 (diff)
downloadcpython-4bfa01b9d911ce9358cf1a453bee15554f8e4c07.tar.gz
cpython-4bfa01b9d911ce9358cf1a453bee15554f8e4c07.zip
GH-104584: Plugin optimizer API (GH-105100)
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 43e38772688..e86b11f507c 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -31,6 +31,7 @@
#include "dictobject.h"
#include "pycore_frame.h"
#include "opcode.h"
+#include "optimizer.h"
#include "pydtrace.h"
#include "setobject.h"
#include "structmember.h" // struct PyMemberDef, T_OFFSET_EX
@@ -2113,11 +2114,36 @@ dummy_func(
}
inst(JUMP_BACKWARD, (--)) {
- assert(oparg < INSTR_OFFSET());
- JUMPBY(-oparg);
+ _Py_CODEUNIT *here = next_instr - 1;
+ assert(oparg <= INSTR_OFFSET());
+ JUMPBY(1-oparg);
+ #if ENABLE_SPECIALIZATION
+ here[1].cache += (1 << OPTIMIZER_BITS_IN_COUNTER);
+ if (here[1].cache > tstate->interp->optimizer_backedge_threshold) {
+ OBJECT_STAT_INC(optimization_attempts);
+ frame = _PyOptimizer_BackEdge(frame, here, next_instr, stack_pointer);
+ if (frame == NULL) {
+ frame = cframe.current_frame;
+ goto error;
+ }
+ here[1].cache &= ((1 << OPTIMIZER_BITS_IN_COUNTER) -1);
+ goto resume_frame;
+ }
+ #endif /* ENABLE_SPECIALIZATION */
CHECK_EVAL_BREAKER();
}
+ inst(ENTER_EXECUTOR, (--)) {
+ _PyExecutorObject *executor = (_PyExecutorObject *)frame->f_code->co_executors->executors[oparg];
+ Py_INCREF(executor);
+ frame = executor->execute(executor, frame, stack_pointer);
+ if (frame == NULL) {
+ frame = cframe.current_frame;
+ goto error;
+ }
+ goto resume_frame;
+ }
+
inst(POP_JUMP_IF_FALSE, (cond -- )) {
if (Py_IsFalse(cond)) {
JUMPBY(oparg);
@@ -3368,7 +3394,7 @@ dummy_func(
}
inst(INSTRUMENTED_JUMP_BACKWARD, ( -- )) {
- INSTRUMENTED_JUMP(next_instr-1, next_instr-oparg, PY_MONITORING_EVENT_JUMP);
+ INSTRUMENTED_JUMP(next_instr-1, next_instr+1-oparg, PY_MONITORING_EVENT_JUMP);
CHECK_EVAL_BREAKER();
}