mirror of https://github.com/python/cpython
GH-108614: Remove non-debug uses of `#if TIER_ONE` and `#if TIER_TWO` from `_POP_FRAME` op. (GH-108685)
This commit is contained in:
parent
194c6fb85e
commit
059bd4d299
|
@ -768,24 +768,25 @@ dummy_func(
|
||||||
// different frame, and it's accounted for by _PUSH_FRAME.
|
// different frame, and it's accounted for by _PUSH_FRAME.
|
||||||
op(_POP_FRAME, (retval --)) {
|
op(_POP_FRAME, (retval --)) {
|
||||||
assert(EMPTY());
|
assert(EMPTY());
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
_Py_LeaveRecursiveCallPy(tstate);
|
|
||||||
// GH-99729: We need to unlink the frame *before* clearing it:
|
|
||||||
_PyInterpreterFrame *dying = frame;
|
|
||||||
#if TIER_ONE
|
#if TIER_ONE
|
||||||
assert(frame != &entry_frame);
|
assert(frame != &entry_frame);
|
||||||
#endif
|
#endif
|
||||||
|
STORE_SP();
|
||||||
|
_Py_LeaveRecursiveCallPy(tstate);
|
||||||
|
// GH-99729: We need to unlink the frame *before* clearing it:
|
||||||
|
_PyInterpreterFrame *dying = frame;
|
||||||
frame = tstate->current_frame = dying->previous;
|
frame = tstate->current_frame = dying->previous;
|
||||||
_PyEval_FrameClearAndPop(tstate, dying);
|
_PyEval_FrameClearAndPop(tstate, dying);
|
||||||
frame->prev_instr += frame->return_offset;
|
frame->prev_instr += frame->return_offset;
|
||||||
_PyFrame_StackPush(frame, retval);
|
_PyFrame_StackPush(frame, retval);
|
||||||
#if TIER_ONE
|
LOAD_SP();
|
||||||
goto resume_frame;
|
LOAD_IP();
|
||||||
#endif
|
#if LLTRACE && TIER_ONE
|
||||||
#if TIER_TWO
|
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
|
||||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
if (lltrace < 0) {
|
||||||
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
|
goto exit_unwind;
|
||||||
#endif
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
macro(RETURN_VALUE) =
|
macro(RETURN_VALUE) =
|
||||||
|
|
|
@ -189,6 +189,34 @@ lltrace_resume_frame(_PyInterpreterFrame *frame)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
PyErr_SetRaisedException(exc);
|
PyErr_SetRaisedException(exc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
maybe_lltrace_resume_frame(_PyInterpreterFrame *frame, _PyInterpreterFrame *skip_frame, PyObject *globals)
|
||||||
|
{
|
||||||
|
if (globals == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (frame == skip_frame) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int r = PyDict_Contains(globals, &_Py_ID(__lltrace__));
|
||||||
|
if (r < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int lltrace = r;
|
||||||
|
if (!lltrace) {
|
||||||
|
// When tracing executed uops, also trace bytecode
|
||||||
|
char *uop_debug = Py_GETENV("PYTHONUOPSDEBUG");
|
||||||
|
if (uop_debug != NULL && *uop_debug >= '0') {
|
||||||
|
lltrace = (*uop_debug - '0') >= 5; // TODO: Parse an int and all that
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lltrace) {
|
||||||
|
lltrace_resume_frame(frame);
|
||||||
|
}
|
||||||
|
return lltrace;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void monitor_raise(PyThreadState *tstate,
|
static void monitor_raise(PyThreadState *tstate,
|
||||||
|
@ -576,6 +604,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
return _PyEval_EvalFrame(tstate, f->f_frame, throwflag);
|
return _PyEval_EvalFrame(tstate, f->f_frame, throwflag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TIER_ONE 1
|
||||||
#include "ceval_macros.h"
|
#include "ceval_macros.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -714,24 +743,9 @@ resume_frame:
|
||||||
SET_LOCALS_FROM_FRAME();
|
SET_LOCALS_FROM_FRAME();
|
||||||
|
|
||||||
#ifdef LLTRACE
|
#ifdef LLTRACE
|
||||||
{
|
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
|
||||||
if (frame != &entry_frame && GLOBALS()) {
|
if (lltrace < 0) {
|
||||||
int r = PyDict_Contains(GLOBALS(), &_Py_ID(__lltrace__));
|
goto exit_unwind;
|
||||||
if (r < 0) {
|
|
||||||
goto exit_unwind;
|
|
||||||
}
|
|
||||||
lltrace = r;
|
|
||||||
if (!lltrace) {
|
|
||||||
// When tracing executed uops, also trace bytecode
|
|
||||||
char *uop_debug = Py_GETENV("PYTHONUOPSDEBUG");
|
|
||||||
if (uop_debug != NULL && *uop_debug >= '0') {
|
|
||||||
lltrace = (*uop_debug - '0') >= 5; // TODO: Parse an int and all that
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lltrace) {
|
|
||||||
lltrace_resume_frame(frame);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -752,7 +766,6 @@ resume_frame:
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|
||||||
#define TIER_ONE 1
|
|
||||||
#include "generated_cases.c.h"
|
#include "generated_cases.c.h"
|
||||||
|
|
||||||
/* INSTRUMENTED_LINE has to be here, rather than in bytecodes.c,
|
/* INSTRUMENTED_LINE has to be here, rather than in bytecodes.c,
|
||||||
|
|
|
@ -373,3 +373,39 @@ static inline int _Py_EnterRecursivePy(PyThreadState *tstate) {
|
||||||
static inline void _Py_LeaveRecursiveCallPy(PyThreadState *tstate) {
|
static inline void _Py_LeaveRecursiveCallPy(PyThreadState *tstate) {
|
||||||
tstate->py_recursion_remaining++;
|
tstate->py_recursion_remaining++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Implementation of "macros" that modify the instruction pointer,
|
||||||
|
* stack pointer, or frame pointer.
|
||||||
|
* These need to treated differently by tier 1 and 2. */
|
||||||
|
|
||||||
|
#if TIER_ONE
|
||||||
|
|
||||||
|
#define LOAD_IP() \
|
||||||
|
do { next_instr = frame->prev_instr+1; } while (0)
|
||||||
|
|
||||||
|
#define STORE_SP() \
|
||||||
|
_PyFrame_SetStackPointer(frame, stack_pointer)
|
||||||
|
|
||||||
|
#define LOAD_SP() \
|
||||||
|
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if TIER_TWO
|
||||||
|
|
||||||
|
#define LOAD_IP() \
|
||||||
|
do { ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive; } while (0)
|
||||||
|
|
||||||
|
#define STORE_SP() \
|
||||||
|
_PyFrame_SetStackPointer(frame, stack_pointer)
|
||||||
|
|
||||||
|
#define LOAD_SP() \
|
||||||
|
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "pycore_sliceobject.h"
|
#include "pycore_sliceobject.h"
|
||||||
#include "pycore_uops.h"
|
#include "pycore_uops.h"
|
||||||
|
|
||||||
|
#define TIER_TWO 2
|
||||||
#include "ceval_macros.h"
|
#include "ceval_macros.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +84,6 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
|
||||||
OBJECT_STAT_INC(optimization_uops_executed);
|
OBJECT_STAT_INC(optimization_uops_executed);
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
|
||||||
#define TIER_TWO 2
|
|
||||||
#include "executor_cases.c.h"
|
#include "executor_cases.c.h"
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -690,24 +690,25 @@
|
||||||
retval = stack_pointer[-1];
|
retval = stack_pointer[-1];
|
||||||
STACK_SHRINK(1);
|
STACK_SHRINK(1);
|
||||||
assert(EMPTY());
|
assert(EMPTY());
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
_Py_LeaveRecursiveCallPy(tstate);
|
|
||||||
// GH-99729: We need to unlink the frame *before* clearing it:
|
|
||||||
_PyInterpreterFrame *dying = frame;
|
|
||||||
#if TIER_ONE
|
#if TIER_ONE
|
||||||
assert(frame != &entry_frame);
|
assert(frame != &entry_frame);
|
||||||
#endif
|
#endif
|
||||||
|
STORE_SP();
|
||||||
|
_Py_LeaveRecursiveCallPy(tstate);
|
||||||
|
// GH-99729: We need to unlink the frame *before* clearing it:
|
||||||
|
_PyInterpreterFrame *dying = frame;
|
||||||
frame = tstate->current_frame = dying->previous;
|
frame = tstate->current_frame = dying->previous;
|
||||||
_PyEval_FrameClearAndPop(tstate, dying);
|
_PyEval_FrameClearAndPop(tstate, dying);
|
||||||
frame->prev_instr += frame->return_offset;
|
frame->prev_instr += frame->return_offset;
|
||||||
_PyFrame_StackPush(frame, retval);
|
_PyFrame_StackPush(frame, retval);
|
||||||
#if TIER_ONE
|
LOAD_SP();
|
||||||
goto resume_frame;
|
LOAD_IP();
|
||||||
#endif
|
#if LLTRACE && TIER_ONE
|
||||||
#if TIER_TWO
|
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
|
||||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
if (lltrace < 0) {
|
||||||
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
|
goto exit_unwind;
|
||||||
#endif
|
}
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -990,25 +990,27 @@
|
||||||
STACK_SHRINK(1);
|
STACK_SHRINK(1);
|
||||||
{
|
{
|
||||||
assert(EMPTY());
|
assert(EMPTY());
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
_Py_LeaveRecursiveCallPy(tstate);
|
|
||||||
// GH-99729: We need to unlink the frame *before* clearing it:
|
|
||||||
_PyInterpreterFrame *dying = frame;
|
|
||||||
#if TIER_ONE
|
#if TIER_ONE
|
||||||
assert(frame != &entry_frame);
|
assert(frame != &entry_frame);
|
||||||
#endif
|
#endif
|
||||||
|
STORE_SP();
|
||||||
|
_Py_LeaveRecursiveCallPy(tstate);
|
||||||
|
// GH-99729: We need to unlink the frame *before* clearing it:
|
||||||
|
_PyInterpreterFrame *dying = frame;
|
||||||
frame = tstate->current_frame = dying->previous;
|
frame = tstate->current_frame = dying->previous;
|
||||||
_PyEval_FrameClearAndPop(tstate, dying);
|
_PyEval_FrameClearAndPop(tstate, dying);
|
||||||
frame->prev_instr += frame->return_offset;
|
frame->prev_instr += frame->return_offset;
|
||||||
_PyFrame_StackPush(frame, retval);
|
_PyFrame_StackPush(frame, retval);
|
||||||
#if TIER_ONE
|
LOAD_SP();
|
||||||
goto resume_frame;
|
LOAD_IP();
|
||||||
#endif
|
#if LLTRACE && TIER_ONE
|
||||||
#if TIER_TWO
|
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
|
||||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
if (lltrace < 0) {
|
||||||
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
|
goto exit_unwind;
|
||||||
#endif
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(INSTRUMENTED_RETURN_VALUE) {
|
TARGET(INSTRUMENTED_RETURN_VALUE) {
|
||||||
|
@ -1055,25 +1057,27 @@
|
||||||
retval = value;
|
retval = value;
|
||||||
{
|
{
|
||||||
assert(EMPTY());
|
assert(EMPTY());
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
_Py_LeaveRecursiveCallPy(tstate);
|
|
||||||
// GH-99729: We need to unlink the frame *before* clearing it:
|
|
||||||
_PyInterpreterFrame *dying = frame;
|
|
||||||
#if TIER_ONE
|
#if TIER_ONE
|
||||||
assert(frame != &entry_frame);
|
assert(frame != &entry_frame);
|
||||||
#endif
|
#endif
|
||||||
|
STORE_SP();
|
||||||
|
_Py_LeaveRecursiveCallPy(tstate);
|
||||||
|
// GH-99729: We need to unlink the frame *before* clearing it:
|
||||||
|
_PyInterpreterFrame *dying = frame;
|
||||||
frame = tstate->current_frame = dying->previous;
|
frame = tstate->current_frame = dying->previous;
|
||||||
_PyEval_FrameClearAndPop(tstate, dying);
|
_PyEval_FrameClearAndPop(tstate, dying);
|
||||||
frame->prev_instr += frame->return_offset;
|
frame->prev_instr += frame->return_offset;
|
||||||
_PyFrame_StackPush(frame, retval);
|
_PyFrame_StackPush(frame, retval);
|
||||||
#if TIER_ONE
|
LOAD_SP();
|
||||||
goto resume_frame;
|
LOAD_IP();
|
||||||
#endif
|
#if LLTRACE && TIER_ONE
|
||||||
#if TIER_TWO
|
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
|
||||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
if (lltrace < 0) {
|
||||||
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
|
goto exit_unwind;
|
||||||
#endif
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(INSTRUMENTED_RETURN_CONST) {
|
TARGET(INSTRUMENTED_RETURN_CONST) {
|
||||||
|
@ -3887,6 +3891,7 @@
|
||||||
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
|
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(CALL_PY_EXACT_ARGS) {
|
TARGET(CALL_PY_EXACT_ARGS) {
|
||||||
|
@ -3963,6 +3968,7 @@
|
||||||
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
|
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(CALL_PY_WITH_DEFAULTS) {
|
TARGET(CALL_PY_WITH_DEFAULTS) {
|
||||||
|
|
|
@ -369,8 +369,8 @@ def write_macro_instr(
|
||||||
next_instr_is_set = write_components(parts, out, TIER_ONE, mac.cache_offset)
|
next_instr_is_set = write_components(parts, out, TIER_ONE, mac.cache_offset)
|
||||||
except AssertionError as err:
|
except AssertionError as err:
|
||||||
raise AssertionError(f"Error writing macro {mac.name}") from err
|
raise AssertionError(f"Error writing macro {mac.name}") from err
|
||||||
if not parts[-1].instr.always_exits and not next_instr_is_set:
|
if not parts[-1].instr.always_exits:
|
||||||
if mac.cache_offset:
|
if not next_instr_is_set and mac.cache_offset:
|
||||||
out.emit(f"next_instr += {mac.cache_offset};")
|
out.emit(f"next_instr += {mac.cache_offset};")
|
||||||
out.emit("DISPATCH();")
|
out.emit("DISPATCH();")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue