diff options
author | Mark Shannon <mark@hotpy.org> | 2025-01-13 10:30:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-13 10:30:28 (GMT) |
commit | ddd959987c557beaf823b681bf5e5e573ad657ac (patch) | |
tree | e59574d3eb62f94e497f7aecd585bf656ebc984e /Python/bytecodes.c | |
parent | 29fe8072cf404b891dde9c1d415095edddbe19de (diff) | |
download | cpython-ddd959987c557beaf823b681bf5e5e573ad657ac.zip cpython-ddd959987c557beaf823b681bf5e5e573ad657ac.tar.gz cpython-ddd959987c557beaf823b681bf5e5e573ad657ac.tar.bz2 |
GH-128685: Specialize (rather than quicken) LOAD_CONST into LOAD_CONST_[IM]MORTAL (GH-128708)
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r-- | Python/bytecodes.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 8bab4ea..657e2fb 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -285,11 +285,25 @@ dummy_func( } family(LOAD_CONST, 0) = { + LOAD_CONST_MORTAL, LOAD_CONST_IMMORTAL, }; - pure inst(LOAD_CONST, (-- value)) { - value = PyStackRef_FromPyObjectNew(GETITEM(FRAME_CO_CONSTS, oparg)); + inst(LOAD_CONST, (-- value)) { + /* We can't do this in the bytecode compiler as + * marshalling can intern strings and make them immortal. */ + PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg); + value = PyStackRef_FromPyObjectNew(obj); +#if ENABLE_SPECIALIZATION + if (this_instr->op.code == LOAD_CONST) { + this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL; + } +#endif + } + + inst(LOAD_CONST_MORTAL, (-- value)) { + PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg); + value = PyStackRef_FromPyObjectNew(obj); } inst(LOAD_CONST_IMMORTAL, (-- value)) { |