]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
JIT: Move executor to a register (#143072)
authorDiego Russo <diego.russo@arm.com>
Wed, 24 Dec 2025 09:44:16 +0000 (09:44 +0000)
committerGitHub <noreply@github.com>
Wed, 24 Dec 2025 09:44:16 +0000 (09:44 +0000)
Include/internal/pycore_jit.h
Python/bytecodes.c
Python/executor_cases.c.h
Tools/jit/_stencils.py
Tools/jit/jit.h
Tools/jit/shim.c
Tools/jit/template.c

index b96ac879289673ded68567d6771a0e641e509f91..89d5bb536439302687133f62270c947a5bd4bedf 100644 (file)
@@ -19,7 +19,7 @@ extern "C" {
 #ifdef _Py_JIT
 
 typedef _Py_CODEUNIT *(*jit_func)(
-    _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate,
+    _PyExecutorObject *executor, _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate,
     _PyStackRef _tos_cache0, _PyStackRef _tos_cache1, _PyStackRef _tos_cache2
 );
 
index 950b9f08f2ead1c68e58b939b1e9e14dd7b4a385..9232a16551d8a25329488e0462f3ebbcc98b64a4 100644 (file)
@@ -5296,7 +5296,7 @@ dummy_func(
             assert(current_executor == (_PyExecutorObject*)executor);
 #endif
             assert(tstate->jit_exit == NULL || tstate->jit_exit->executor == current_executor);
-            tstate->current_executor = (PyObject *)executor;
+            tstate->current_executor = (PyObject *)current_executor;
             if (!current_executor->vm_data.valid) {
                 assert(tstate->jit_exit->executor == current_executor);
                 assert(tstate->current_executor == executor);
index dc21a4aa90cf46f8cca48988a5d00bd91aec498f..aa98d4019dbdffac96fe86a904de5a793efa5b87 100644 (file)
             assert(current_executor == (_PyExecutorObject*)executor);
             #endif
             assert(tstate->jit_exit == NULL || tstate->jit_exit->executor == current_executor);
-            tstate->current_executor = (PyObject *)executor;
+            tstate->current_executor = (PyObject *)current_executor;
             if (!current_executor->vm_data.valid) {
                 assert(tstate->jit_exit->executor == current_executor);
                 assert(tstate->current_executor == executor);
index 2b78d8013af5dbc8e599c25ef037b7532c50f7b9..258de8ab3136a4a47294a59014170dae168cf3b8 100644 (file)
@@ -19,8 +19,6 @@ class HoleValue(enum.Enum):
     CODE = enum.auto()
     # The base address of the read-only data for this uop:
     DATA = enum.auto()
-    # The address of the current executor (exposed as _JIT_EXECUTOR):
-    EXECUTOR = enum.auto()
     # The base address of the "global" offset table located in the read-only data.
     # Shouldn't be present in the final stencils, since these are all replaced with
     # equivalent DATA values:
@@ -108,7 +106,6 @@ _PATCH_FUNCS = {
 _HOLE_EXPRS = {
     HoleValue.CODE: "(uintptr_t)code",
     HoleValue.DATA: "(uintptr_t)data",
-    HoleValue.EXECUTOR: "(uintptr_t)executor",
     HoleValue.GOT: "",
     # These should all have been turned into DATA values by process_relocations:
     HoleValue.OPARG: "instruction->oparg",
index d5cf288c660f00b6e906c95de9bc3d62c9878904..05e73ac6b39e8b8c17bcae52a9ef0eb211902e90 100644 (file)
@@ -9,5 +9,5 @@ typedef jit_func __attribute__((preserve_none)) jit_func_preserve_none;
 
 #define DECLARE_TARGET(NAME)                     \
     _Py_CODEUNIT *__attribute__((preserve_none, visibility("hidden"))) \
-    NAME(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate, \
+    NAME(_PyExecutorObject *executor, _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate, \
     _PyStackRef _tos_cache0, _PyStackRef _tos_cache1, _PyStackRef _tos_cache2);
index 698e491aeb349b50a018db4c6175a3a48c7ad754..8ec4885a48354fd6ca10382d797d46aaed4c1e7c 100644 (file)
@@ -12,5 +12,6 @@ _JIT_ENTRY(
 ) {
     // Note that this is *not* a tail call
     jit_func_preserve_none jitted = (jit_func_preserve_none)exec->jit_code;
-    return jitted(frame, stack_pointer, tstate, PyStackRef_ZERO_BITS, PyStackRef_ZERO_BITS, PyStackRef_ZERO_BITS);
+    return jitted(exec, frame, stack_pointer, tstate,
+                  PyStackRef_ZERO_BITS, PyStackRef_ZERO_BITS, PyStackRef_ZERO_BITS);
 }
index 064b401bc3aca4445850dac630fd50612c7b06ba..3537c74a8203650c5d8b5df962bdbcbf3c4d69e8 100644 (file)
@@ -76,7 +76,7 @@ do {                                                                       \
     OPT_STAT_INC(traces_executed);                                         \
     _PyExecutorObject *_executor = (EXECUTOR);                             \
     jit_func_preserve_none jitted = _executor->jit_code;                   \
-    __attribute__((musttail)) return jitted(frame, stack_pointer, tstate,  \
+    __attribute__((musttail)) return jitted(_executor, frame, stack_pointer, tstate,  \
     _tos_cache0, _tos_cache1, _tos_cache2); \
 } while (0)
 
@@ -100,7 +100,7 @@ do {                                                                       \
 #define PATCH_JUMP(ALIAS)                                                 \
 do {                                                                      \
     DECLARE_TARGET(ALIAS);                                                \
-    __attribute__((musttail)) return ALIAS(frame, stack_pointer, tstate,  \
+    __attribute__((musttail)) return ALIAS(current_executor, frame, stack_pointer, tstate,  \
     _tos_cache0, _tos_cache1, _tos_cache2); \
 } while (0)
 
@@ -120,11 +120,11 @@ do {                                                                      \
 
 __attribute__((preserve_none)) _Py_CODEUNIT *
 _JIT_ENTRY(
-    _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate,
-     _PyStackRef _tos_cache0, _PyStackRef _tos_cache1, _PyStackRef _tos_cache2
+    _PyExecutorObject *executor, _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate,
+    _PyStackRef _tos_cache0, _PyStackRef _tos_cache1, _PyStackRef _tos_cache2
 ) {
     // Locals that the instruction implementations expect to exist:
-    PATCH_VALUE(_PyExecutorObject *, current_executor, _JIT_EXECUTOR)
+    _PyExecutorObject *current_executor = executor;
     int oparg;
     int uopcode = _JIT_OPCODE;
     _Py_CODEUNIT *next_instr;