summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-06-17 13:40:11 (GMT)
committerGitHub <noreply@github.com>2024-06-17 13:40:11 (GMT)
commit274f844830898355f14d6edb6e71894a2f37e53c (patch)
tree0f6ef2d7e7fd30f42fe83bbc05859314ac1c230a /Python
parent79e09e60d865b7b3fcde9ccee86a502da82bb2b3 (diff)
downloadcpython-274f844830898355f14d6edb6e71894a2f37e53c.zip
cpython-274f844830898355f14d6edb6e71894a2f37e53c.tar.gz
cpython-274f844830898355f14d6edb6e71894a2f37e53c.tar.bz2
GH-120619: Clean up `RETURN_VALUE` instruction (GH-120624)
* Rename _POP_FRAME to _RETURN_VALUE as it returns a value as well as popping a frame. * Remove remaining _POP_FRAMEs
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c9
-rw-r--r--Python/executor_cases.c.h7
-rw-r--r--Python/generated_cases.c.h12
-rw-r--r--Python/optimizer.c8
-rw-r--r--Python/optimizer_analysis.c6
-rw-r--r--Python/optimizer_bytecodes.c2
-rw-r--r--Python/optimizer_cases.c.h2
7 files changed, 26 insertions, 20 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 05c17ac..31db284 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -827,7 +827,7 @@ dummy_func(
// We definitely pop the return value off the stack on entry.
// We also push it onto the stack on exit, but that's a
// different frame, and it's accounted for by _PUSH_FRAME.
- op(_POP_FRAME, (retval --)) {
+ inst(RETURN_VALUE, (retval -- res)) {
#if TIER_ONE
assert(frame != &entry_frame);
#endif
@@ -839,15 +839,12 @@ dummy_func(
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
- _PyFrame_StackPush(frame, retval);
LOAD_SP();
LOAD_IP(frame->return_offset);
+ res = retval;
LLTRACE_RESUME_FRAME();
}
- macro(RETURN_VALUE) =
- _POP_FRAME;
-
inst(INSTRUMENTED_RETURN_VALUE, (retval --)) {
int err = _Py_call_instrumentation_arg(
tstate, PY_MONITORING_EVENT_PY_RETURN,
@@ -869,7 +866,7 @@ dummy_func(
macro(RETURN_CONST) =
LOAD_CONST +
- _POP_FRAME;
+ RETURN_VALUE;
inst(INSTRUMENTED_RETURN_CONST, (--)) {
PyObject *retval = GETITEM(FRAME_CO_CONSTS, oparg);
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index 470c82d..d390c9f 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -971,8 +971,9 @@
break;
}
- case _POP_FRAME: {
+ case _RETURN_VALUE: {
PyObject *retval;
+ PyObject *res;
retval = stack_pointer[-1];
#if TIER_ONE
assert(frame != &entry_frame);
@@ -985,10 +986,12 @@
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
- _PyFrame_StackPush(frame, retval);
LOAD_SP();
LOAD_IP(frame->return_offset);
+ res = retval;
LLTRACE_RESUME_FRAME();
+ stack_pointer[0] = res;
+ stack_pointer += 1;
break;
}
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 0274f8b..8a6f5ff 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -5202,12 +5202,13 @@
INSTRUCTION_STATS(RETURN_CONST);
PyObject *value;
PyObject *retval;
+ PyObject *res;
// _LOAD_CONST
{
value = GETITEM(FRAME_CO_CONSTS, oparg);
Py_INCREF(value);
}
- // _POP_FRAME
+ // _RETURN_VALUE
retval = value;
{
#if TIER_ONE
@@ -5220,11 +5221,13 @@
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
- _PyFrame_StackPush(frame, retval);
LOAD_SP();
LOAD_IP(frame->return_offset);
+ res = retval;
LLTRACE_RESUME_FRAME();
}
+ stack_pointer[0] = res;
+ stack_pointer += 1;
DISPATCH();
}
@@ -5265,6 +5268,7 @@
next_instr += 1;
INSTRUCTION_STATS(RETURN_VALUE);
PyObject *retval;
+ PyObject *res;
retval = stack_pointer[-1];
#if TIER_ONE
assert(frame != &entry_frame);
@@ -5277,10 +5281,12 @@
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
- _PyFrame_StackPush(frame, retval);
LOAD_SP();
LOAD_IP(frame->return_offset);
+ res = retval;
LLTRACE_RESUME_FRAME();
+ stack_pointer[0] = res;
+ stack_pointer += 1;
DISPATCH();
}
diff --git a/Python/optimizer.c b/Python/optimizer.c
index 4dc3438..c9b187d 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -537,7 +537,7 @@ add_to_trace(
// Reserve space for N uops, plus 3 for _SET_IP, _CHECK_VALIDITY and _EXIT_TRACE
#define RESERVE(needed) RESERVE_RAW((needed) + 3, _PyUOpName(opcode))
-// Trace stack operations (used by _PUSH_FRAME, _POP_FRAME)
+// Trace stack operations (used by _PUSH_FRAME, _RETURN_VALUE)
#define TRACE_STACK_PUSH() \
if (trace_stack_depth >= TRACE_STACK_SIZE) { \
DPRINTF(2, "Trace stack overflow\n"); \
@@ -748,10 +748,10 @@ top: // Jump here after _PUSH_FRAME or likely branches
int nuops = expansion->nuops;
RESERVE(nuops + 1); /* One extra for exit */
int16_t last_op = expansion->uops[nuops-1].uop;
- if (last_op == _POP_FRAME || last_op == _RETURN_GENERATOR || last_op == _YIELD_VALUE) {
+ if (last_op == _RETURN_VALUE || last_op == _RETURN_GENERATOR || last_op == _YIELD_VALUE) {
// Check for trace stack underflow now:
// We can't bail e.g. in the middle of
- // LOAD_CONST + _POP_FRAME.
+ // LOAD_CONST + _RETURN_VALUE.
if (trace_stack_depth == 0) {
DPRINTF(2, "Trace stack underflow\n");
OPT_STAT_INC(trace_stack_underflow);
@@ -810,7 +810,7 @@ top: // Jump here after _PUSH_FRAME or likely branches
Py_FatalError("garbled expansion");
}
- if (uop == _POP_FRAME || uop == _RETURN_GENERATOR || uop == _YIELD_VALUE) {
+ if (uop == _RETURN_VALUE || uop == _RETURN_GENERATOR || uop == _YIELD_VALUE) {
TRACE_STACK_POP();
/* Set the operand to the function or code object returned to,
* to assist optimization passes. (See _PUSH_FRAME below.)
diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index 75d1d9f..0e45bd8 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -265,7 +265,7 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
}
break;
}
- case _POP_FRAME:
+ case _RETURN_VALUE:
{
builtins_watched >>= 1;
globals_watched >>= 1;
@@ -365,13 +365,13 @@ eliminate_pop_guard(_PyUOpInstruction *this_instr, bool exit)
}
}
-/* _PUSH_FRAME/_POP_FRAME's operand can be 0, a PyFunctionObject *, or a
+/* _PUSH_FRAME/_RETURN_VALUE's operand can be 0, a PyFunctionObject *, or a
* PyCodeObject *. Retrieve the code object if possible.
*/
static PyCodeObject *
get_code(_PyUOpInstruction *op)
{
- assert(op->opcode == _PUSH_FRAME || op->opcode == _POP_FRAME || op->opcode == _RETURN_GENERATOR);
+ assert(op->opcode == _PUSH_FRAME || op->opcode == _RETURN_VALUE || op->opcode == _RETURN_GENERATOR);
PyCodeObject *co = NULL;
uint64_t operand = op->operand;
if (operand == 0) {
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index e6fb85a..121ca92 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -606,7 +606,7 @@ dummy_func(void) {
ctx->done = true;
}
- op(_POP_FRAME, (retval -- res)) {
+ op(_RETURN_VALUE, (retval -- res)) {
SYNC_SP();
ctx->frame->stack_pointer = stack_pointer;
frame_pop(ctx);
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index 18f3ca4..53959a3 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -558,7 +558,7 @@
break;
}
- case _POP_FRAME: {
+ case _RETURN_VALUE: {
_Py_UopsSymbol *retval;
_Py_UopsSymbol *res;
retval = stack_pointer[-1];