]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Point to previous executor when side-exiting
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Tue, 23 Sep 2025 22:27:01 +0000 (23:27 +0100)
committerKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Tue, 23 Sep 2025 22:27:01 +0000 (23:27 +0100)
Include/internal/pycore_interp_structs.h
Include/internal/pycore_optimizer.h
Python/bytecodes.c
Python/executor_cases.c.h
Python/generated_cases.c.h
Python/optimizer.c

index 5834a6f8edda3ae3948eb4a3d7064e8177c10d75..9671325362d5c35171ad6efde2a3da101c8b27a3 100644 (file)
@@ -953,7 +953,7 @@ struct _is {
     int jit_tracer_initial_chain_depth;
     PyCodeObject *jit_tracer_initial_code; // Borrowed
     PyFunctionObject *jit_tracer_initial_func; // Borrowed
-    int jit_tracer_seen_initial_before;
+    struct _PyExitData *jit_tracer_previous_exit;
     bool jit_completed_loop;
     bool jit;
     bool compiling;
index 5dc0a34268696e52d8323e3101fc3b8fa292471b..79b1931d070467021206f239335c67ab7afc042a 100644 (file)
@@ -371,7 +371,7 @@ _PyJIT_translate_single_bytecode_to_trace(
     int jump_taken);
 
 void
-_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr, int curr_stackdepth, int chain_depth);
+_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit);
 #ifdef __cplusplus
 }
 #endif
index e0150aafaf52e87a7d99bf99871b582eaa422e3a..d033900c30839d546c34ebc4c4fdc7d4102851a6 100644 (file)
@@ -2978,7 +2978,7 @@ dummy_func(
                         DISPATCH();
                     }
                 }
-                _PyJIT_InitializeTracing(tstate, frame, next_instr, STACK_LEVEL(), 0);
+                _PyJIT_InitializeTracing(tstate, frame, next_instr, STACK_LEVEL(), 0, NULL);
                 ENTER_TRACING();
                 // Don't add the JUMP_BACKWARD_JIT instruction to the trace.
                 DISPATCH();
@@ -5456,7 +5456,7 @@ dummy_func(
                 _PyExecutorObject *previous_executor = _PyExecutor_FromExit(exit);
                 assert(tstate->current_executor == (PyObject *)previous_executor);
                 int chain_depth = is_dynamic ? 0 : current_executor->vm_data.chain_depth + 1;
-                _PyJIT_InitializeTracing(tstate, frame, target, STACK_LEVEL(), chain_depth);
+                _PyJIT_InitializeTracing(tstate, frame, target, STACK_LEVEL(), chain_depth, exit);
                 GOTO_TIER_ONE(target, 1);
             }
         }
index 56a1c9b7a52e68d427f98abee8a4458ac5e529f8..d4c7c6ad5687a3f35375e1ba4daa710d356bd338 100644 (file)
                 _PyExecutorObject *previous_executor = _PyExecutor_FromExit(exit);
                 assert(tstate->current_executor == (PyObject *)previous_executor);
                 int chain_depth = is_dynamic ? 0 : current_executor->vm_data.chain_depth + 1;
-                _PyJIT_InitializeTracing(tstate, frame, target, STACK_LEVEL(), chain_depth);
+                _PyJIT_InitializeTracing(tstate, frame, target, STACK_LEVEL(), chain_depth, exit);
                 GOTO_TIER_ONE(target, 1);
             }
             break;
index 92ddfeb3a982f9d203fde611db27e95e129eac91..229d75a8dc0dc7e96ec37631a333eed22381442d 100644 (file)
                 next_instr = this_instr;
                 DISPATCH_GOTO();
             }
-            OPT_STAT_INC(traces_executed);                     \
-            next_instr = _Py_jit_entry((executor), frame, stack_pointer, tstate); \
-            frame = tstate->current_frame;                     \
-            stack_pointer = _PyFrame_GetStackPointer(frame);   \
-            int keep_tracing_bit = (uintptr_t)next_instr & 1;   \
-            next_instr = (_Py_CODEUNIT *)(((uintptr_t)next_instr) >> 1 << 1); \
-            if (next_instr == NULL) {                          \
-                next_instr = frame->instr_ptr;                 \
-                JUMP_TO_LABEL(error);                          \
-            }                                                  \
-            if (keep_tracing_bit) { \
-                assert(next_instr->op.code != ENTER_EXECUTOR); \
-                assert(tstate->interp->jit_tracer_code_curr_size == 2); \
-                ENTER_TRACING(); \
-            } \
-            else { \
-                LEAVE_TRACING(); \
-            } \
-            DISPATCH();
+            TIER1_TO_TIER2(executor);
             #else
             Py_FatalError("ENTER_EXECUTOR is not supported in this build");
             #endif /* _Py_TIER2 */
                             DISPATCH();
                         }
                     }
-                    _PyJIT_InitializeTracing(tstate, frame, next_instr, STACK_LEVEL(), 0);
+                    _PyJIT_InitializeTracing(tstate, frame, next_instr, STACK_LEVEL(), 0, NULL);
                     ENTER_TRACING();
                     DISPATCH();
                 }
                             TRACING_DISPATCH();
                         }
                     }
-                    _PyJIT_InitializeTracing(tstate, frame, next_instr, STACK_LEVEL(), 0);
+                    _PyJIT_InitializeTracing(tstate, frame, next_instr, STACK_LEVEL(), 0, NULL);
                     ENTER_TRACING();
                     TRACING_DISPATCH();
                 }
index 7789558a29b9e483624652a1fab13c90ca6cf9d5..8c7028b2a5a399aa4364e40eb4ad76b47d5a0e7d 100644 (file)
@@ -161,6 +161,11 @@ _PyOptimizer_Optimize(
     else {
         executor->vm_data.code = NULL;
     }
+    if (chain_depth > 0) {
+        _PyExitData *prev_exit = tstate->interp->jit_tracer_previous_exit;
+        assert(prev_exit != NULL);
+        prev_exit->executor = executor;;
+    }
     executor->vm_data.chain_depth = chain_depth;
     assert(executor->vm_data.valid);
     interp->compiling = false;
@@ -808,7 +813,7 @@ full:
 }
 
 void
-_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr, int curr_stackdepth, int chain_depth)
+_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit)
 {
     PyCodeObject *code = _PyFrame_GetCode(frame);
 #ifdef Py_DEBUG
@@ -831,7 +836,7 @@ _PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_
     tstate->interp->jit_tracer_initial_instr = next_instr;
     tstate->interp->jit_tracer_initial_code = code;
     tstate->interp->jit_tracer_initial_func = _PyFrame_GetFunction(frame);
-    tstate->interp->jit_tracer_seen_initial_before = 0;
+    tstate->interp->jit_tracer_previous_exit = exit;
     memset(&tstate->interp->jit_tracer_dependencies.bits, 0, sizeof(tstate->interp->jit_tracer_dependencies.bits));
     tstate->interp->jit_completed_loop = false;
     tstate->interp->jit_tracer_initial_stack_depth = curr_stackdepth;