diff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h index cf01c620476ff7..42da190d4e2a5d 100644 --- a/Include/internal/pycore_optimizer.h +++ b/Include/internal/pycore_optimizer.h @@ -87,7 +87,6 @@ typedef struct _PyJitTracerInitialState { PyFunctionObject *func; // Strong struct _PyExecutorObject *executor; // Strong _Py_CODEUNIT *start_instr; - _Py_CODEUNIT *close_loop_instr; _Py_CODEUNIT *jump_backward_instr; } _PyJitTracerInitialState; @@ -470,8 +469,8 @@ PyAPI_FUNC(int) _PyJit_translate_single_bytecode_to_trace(PyThreadState *tstate, PyAPI_FUNC(int) _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, - _Py_CODEUNIT *curr_instr, _Py_CODEUNIT *start_instr, - _Py_CODEUNIT *close_loop_instr, _PyStackRef *stack_pointer, int chain_depth, _PyExitData *exit, + _Py_CODEUNIT *curr_instr, _PyStackRef *stack_pointer, + int chain_depth, _PyExitData *exit, int oparg, _PyExecutorObject *current_executor); PyAPI_FUNC(void) _PyJit_FinalizeTracing(PyThreadState *tstate, int err); diff --git a/Modules/_testinternalcapi/test_cases.c.h b/Modules/_testinternalcapi/test_cases.c.h index 45cbc58b085851..572f5f2b8b76e3 100644 --- a/Modules/_testinternalcapi/test_cases.c.h +++ b/Modules/_testinternalcapi/test_cases.c.h @@ -7850,13 +7850,8 @@ !IS_JIT_TRACING() && (this_instr->op.code == JUMP_BACKWARD_JIT || is_resume)) && next_instr->op.code != ENTER_EXECUTOR) { - _Py_CODEUNIT *insert_exec_at = this_instr; - while (oparg > 255) { - oparg >>= 8; - insert_exec_at--; - } - int succ = _PyJit_TryInitializeTracing(tstate, frame, this_instr, insert_exec_at, - is_resume ? insert_exec_at : next_instr, stack_pointer, 0, NULL, oparg, NULL); + int succ = _PyJit_TryInitializeTracing( + tstate, frame, this_instr, stack_pointer, 0, NULL, oparg, NULL); if (succ) { ENTER_TRACING(); } @@ -10672,13 +10667,8 @@ !IS_JIT_TRACING() && (this_instr->op.code == JUMP_BACKWARD_JIT || is_resume)) && next_instr->op.code != ENTER_EXECUTOR) { - _Py_CODEUNIT *insert_exec_at = this_instr; - while (oparg > 255) { - oparg >>= 8; - insert_exec_at--; - } - int succ = _PyJit_TryInitializeTracing(tstate, frame, this_instr, insert_exec_at, - is_resume ? insert_exec_at : next_instr, stack_pointer, 0, NULL, oparg, NULL); + int succ = _PyJit_TryInitializeTracing( + tstate, frame, this_instr, stack_pointer, 0, NULL, oparg, NULL); if (succ) { ENTER_TRACING(); } diff --git a/Python/bytecodes.c b/Python/bytecodes.c index edba5a89cc0f29..7b150a34406a6a 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -3373,13 +3373,8 @@ dummy_func( (this_instr->op.code == JUMP_BACKWARD_JIT || is_resume)) && next_instr->op.code != ENTER_EXECUTOR) { /* Back up over EXTENDED_ARGs so executor is inserted at the correct place */ - _Py_CODEUNIT *insert_exec_at = this_instr; - while (oparg > 255) { - oparg >>= 8; - insert_exec_at--; - } - int succ = _PyJit_TryInitializeTracing(tstate, frame, this_instr, insert_exec_at, - is_resume ? insert_exec_at : next_instr, stack_pointer, 0, NULL, oparg, NULL); + int succ = _PyJit_TryInitializeTracing( + tstate, frame, this_instr, stack_pointer, 0, NULL, oparg, NULL); if (succ) { ENTER_TRACING(); } @@ -6066,7 +6061,7 @@ dummy_func( // Note: it's safe to use target->op.arg here instead of the oparg given by EXTENDED_ARG. // The invariant in the optimizer is the deopt target always points back to the first EXTENDED_ARG. // So setting it to anything else is wrong. - int succ = _PyJit_TryInitializeTracing(tstate, frame, target, target, target, stack_pointer, chain_depth, exit, target->op.arg, previous_executor); + int succ = _PyJit_TryInitializeTracing(tstate, frame, target, stack_pointer, chain_depth, exit, target->op.arg, previous_executor); exit->temperature = restart_backoff_counter(exit->temperature); if (succ) { GOTO_TIER_ONE_CONTINUE_TRACING(target); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 6600accb37e3f2..36b6c8d1ca4497 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -22311,7 +22311,7 @@ _PyExecutorObject *previous_executor = _PyExecutor_FromExit(exit); assert(tstate->current_executor == (PyObject *)previous_executor); int chain_depth = previous_executor->vm_data.chain_depth + !exit->is_control_flow; - int succ = _PyJit_TryInitializeTracing(tstate, frame, target, target, target, stack_pointer, chain_depth, exit, target->op.arg, previous_executor); + int succ = _PyJit_TryInitializeTracing(tstate, frame, target, stack_pointer, chain_depth, exit, target->op.arg, previous_executor); exit->temperature = restart_backoff_counter(exit->temperature); if (succ) { GOTO_TIER_ONE_CONTINUE_TRACING(target); diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 127a45ef591053..0d7bbf5e99cf20 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7849,13 +7849,8 @@ !IS_JIT_TRACING() && (this_instr->op.code == JUMP_BACKWARD_JIT || is_resume)) && next_instr->op.code != ENTER_EXECUTOR) { - _Py_CODEUNIT *insert_exec_at = this_instr; - while (oparg > 255) { - oparg >>= 8; - insert_exec_at--; - } - int succ = _PyJit_TryInitializeTracing(tstate, frame, this_instr, insert_exec_at, - is_resume ? insert_exec_at : next_instr, stack_pointer, 0, NULL, oparg, NULL); + int succ = _PyJit_TryInitializeTracing( + tstate, frame, this_instr, stack_pointer, 0, NULL, oparg, NULL); if (succ) { ENTER_TRACING(); } @@ -10669,13 +10664,8 @@ !IS_JIT_TRACING() && (this_instr->op.code == JUMP_BACKWARD_JIT || is_resume)) && next_instr->op.code != ENTER_EXECUTOR) { - _Py_CODEUNIT *insert_exec_at = this_instr; - while (oparg > 255) { - oparg >>= 8; - insert_exec_at--; - } - int succ = _PyJit_TryInitializeTracing(tstate, frame, this_instr, insert_exec_at, - is_resume ? insert_exec_at : next_instr, stack_pointer, 0, NULL, oparg, NULL); + int succ = _PyJit_TryInitializeTracing( + tstate, frame, this_instr, stack_pointer, 0, NULL, oparg, NULL); if (succ) { ENTER_TRACING(); } diff --git a/Python/optimizer.c b/Python/optimizer.c index f09bf778587b12..f75bae35445324 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -826,8 +826,7 @@ _PyJit_translate_single_bytecode_to_trace( _Py_FALLTHROUGH; case JUMP_BACKWARD_NO_INTERRUPT: { - if ((next_instr != tracer->initial_state.close_loop_instr) && - (next_instr != tracer->initial_state.start_instr) && + if ((next_instr != tracer->initial_state.start_instr) && uop_buffer_length(&tracer->code_buffer) > CODE_SIZE_NO_PROGRESS && // For side exits, we don't want to terminate them early. tracer->initial_state.exit == NULL && @@ -840,8 +839,8 @@ _PyJit_translate_single_bytecode_to_trace( OPT_STAT_INC(inner_loop); ADD_TO_TRACE(_EXIT_TRACE, 0, 0, target); uop_buffer_last(trace)->operand1 = true; // is_control_flow - DPRINTF(2, "JUMP_BACKWARD not to top ends trace %p %p %p\n", next_instr, - tracer->initial_state.close_loop_instr, tracer->initial_state.start_instr); + DPRINTF(2, "JUMP_BACKWARD not to top ends trace %p %p\n", next_instr, + tracer->initial_state.start_instr); goto done; } break; @@ -977,8 +976,7 @@ _PyJit_translate_single_bytecode_to_trace( } } // Loop back to the start - int is_first_instr = tracer->initial_state.close_loop_instr == next_instr || - tracer->initial_state.start_instr == next_instr; + int is_first_instr = tracer->initial_state.start_instr == next_instr; if (is_first_instr && uop_buffer_length(trace) > CODE_SIZE_NO_PROGRESS) { if (needs_guard_ip) { ADD_TO_TRACE(_SET_IP, 0, (uintptr_t)next_instr, 0); @@ -1002,7 +1000,7 @@ _PyJit_translate_single_bytecode_to_trace( Py_NO_INLINE int _PyJit_TryInitializeTracing( PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *curr_instr, - _Py_CODEUNIT *start_instr, _Py_CODEUNIT *close_loop_instr, _PyStackRef *stack_pointer, int chain_depth, + _PyStackRef *stack_pointer, int chain_depth, _PyExitData *exit, int oparg, _PyExecutorObject *current_executor) { _PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate; @@ -1022,6 +1020,7 @@ _PyJit_TryInitializeTracing( if (oparg > 0xFFFF) { return 0; } + _Py_CODEUNIT *start_instr = curr_instr - (oparg > 0xFF); PyObject *func = PyStackRef_AsPyObjectBorrow(frame->f_funcobj); if (func == NULL || !PyFunction_Check(func)) { return 0; @@ -1038,7 +1037,7 @@ _PyJit_TryInitializeTracing( PyUnicode_AsUTF8(code->co_qualname), PyUnicode_AsUTF8(code->co_filename), code->co_firstlineno, - 2 * INSTR_IP(close_loop_instr, code), + 2 * INSTR_IP(curr_instr, code), chain_depth); #endif /* Set up tracing buffer*/ @@ -1048,7 +1047,6 @@ _PyJit_TryInitializeTracing( ADD_TO_TRACE(_MAKE_WARM, 0, 0, 0); tracer->initial_state.start_instr = start_instr; - tracer->initial_state.close_loop_instr = close_loop_instr; tracer->initial_state.code = (PyCodeObject *)Py_NewRef(code); tracer->initial_state.func = (PyFunctionObject *)Py_NewRef(func); tracer->initial_state.executor = (_PyExecutorObject *)Py_XNewRef(current_executor);