From faa3272fb8d63d481a136cc0467a0cba6ed7b264 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Tue, 29 Oct 2024 11:15:42 +0000 Subject: GH-125837: Split `LOAD_CONST` into three. (GH-125972) * Add LOAD_CONST_IMMORTAL opcode * Add LOAD_SMALL_INT opcode * Remove RETURN_CONST opcode --- Python/bytecodes.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'Python/bytecodes.c') diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 057ee0a92d9..b7469c2dd8d 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -255,10 +255,26 @@ dummy_func( value2 = PyStackRef_DUP(GETLOCAL(oparg2)); } + family(LOAD_CONST, 0) = { + LOAD_CONST_IMMORTAL, + }; + pure inst(LOAD_CONST, (-- value)) { value = PyStackRef_FromPyObjectNew(GETITEM(FRAME_CO_CONSTS, oparg)); } + inst(LOAD_CONST_IMMORTAL, (-- value)) { + PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg); + assert(_Py_IsImmortal(obj)); + value = PyStackRef_FromPyObjectImmortal(obj); + } + + replicate(4) inst(LOAD_SMALL_INT, (-- value)) { + assert(oparg < _PY_NSMALLPOSINTS); + PyObject *obj = (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + oparg]; + value = PyStackRef_FromPyObjectImmortal(obj); + } + replicate(8) inst(STORE_FAST, (value --)) { SETLOCAL(oparg, value); DEAD(value); @@ -979,10 +995,9 @@ dummy_func( return result; } - // The stack effect here is ambiguous. - // 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. + // The stack effect here is a bit misleading. + // retval is popped from the stack, but res + // is pushed to a different frame, the callers' frame. inst(RETURN_VALUE, (retval -- res)) { #if TIER_ONE assert(frame != &entry_frame); @@ -1013,15 +1028,6 @@ dummy_func( _RETURN_VALUE_EVENT + RETURN_VALUE; - macro(RETURN_CONST) = - LOAD_CONST + - RETURN_VALUE; - - macro(INSTRUMENTED_RETURN_CONST) = - LOAD_CONST + - _RETURN_VALUE_EVENT + - RETURN_VALUE; - inst(GET_AITER, (obj -- iter)) { unaryfunc getter = NULL; PyObject *obj_o = PyStackRef_AsPyObjectBorrow(obj); -- cgit v1.2.3