Skip to content

Commit

Permalink
Move _EXIT_TRACE logic to a separate label
Browse files Browse the repository at this point in the history
Using `GOTO_TIER_ONE()` macro. This should make things simpler
for Justin.
  • Loading branch information
gvanrossum committed Nov 1, 2023
1 parent e02409d commit fdf1a2f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
5 changes: 1 addition & 4 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down
11 changes: 11 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,13 +1027,15 @@ _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,
PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, oparg)
);
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:
Expand All @@ -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).
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 1 addition & 4 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdf1a2f

Please sign in to comment.