From fdf1a2fc6d628a3a21df4b9be4ffb84cca46185f Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 1 Nov 2023 08:17:58 -0700 Subject: [PATCH] Move `_EXIT_TRACE` logic to a separate label Using `GOTO_TIER_ONE()` macro. This should make things simpler for Justin. --- Python/bytecodes.c | 5 +---- Python/ceval.c | 11 +++++++++++ Python/ceval_macros.h | 2 ++ Python/executor_cases.c.h | 5 +---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 6c668c36166bd7..98af114a72fa60 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -4024,10 +4024,7 @@ dummy_func( op(_EXIT_TRACE, (--)) { TIER_TWO_ONLY - _PyFrame_SetStackPointer(frame, stack_pointer); - Py_DECREF(current_executor); - OPT_HIST(trace_uop_execution_counter, trace_run_length_hist); - goto enter_tier_one; + GOTO_TIER_ONE(); } op(_INSERT, (unused[oparg], top -- top, unused[oparg])) { diff --git a/Python/ceval.c b/Python/ceval.c index e1c9a2e0b03ef0..6e156ab2009468 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1027,6 +1027,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } } +// Jump here from ERROR_IF(..., unbound_local_error) unbound_local_error_tier_two: _PyEval_FormatExcCheckArg(tstate, PyExc_UnboundLocalError, UNBOUNDLOCAL_ERROR_MSG, @@ -1034,6 +1035,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int ); goto error_tier_two; +// JUMP to any of these from ERROR_IF(..., error) pop_4_error_tier_two: STACK_SHRINK(1); pop_3_error_tier_two: @@ -1050,6 +1052,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int Py_DECREF(current_executor); goto resume_with_error; +// Jump here from DEOPT_IF() deoptimize: // On DEOPT_IF we just repeat the last instruction. // This presumes nothing was popped from the stack (nor pushed). @@ -1058,10 +1061,18 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int frame->return_offset = 0; // Dispatch to frame->instr_ptr _PyFrame_SetStackPointer(frame, stack_pointer); Py_DECREF(current_executor); + // Fall through +// Jump here from ENTER_EXECUTOR enter_tier_one: next_instr = frame->instr_ptr; goto resume_frame; +// Jump here from _EXIT_TRACE +exit_trace: + _PyFrame_SetStackPointer(frame, stack_pointer); + Py_DECREF(current_executor); + OPT_HIST(trace_uop_execution_counter, trace_run_length_hist); + goto enter_tier_one; } #if defined(__GNUC__) # pragma GCC diagnostic pop diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index d22075169b8199..546adbe5f438d1 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -395,3 +395,5 @@ stack_pointer = _PyFrame_GetStackPointer(frame); /* Tier-switching macros. */ #define GOTO_TIER_TWO() goto enter_tier_two; + +#define GOTO_TIER_ONE() goto exit_trace; diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 94005285ec7ee8..fdf3e4b01a88b3 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -3261,10 +3261,7 @@ case _EXIT_TRACE: { TIER_TWO_ONLY - _PyFrame_SetStackPointer(frame, stack_pointer); - Py_DECREF(current_executor); - OPT_HIST(trace_uop_execution_counter, trace_run_length_hist); - goto enter_tier_one; + GOTO_TIER_ONE(); break; }