GH-128685: Specialize (rather than quicken) LOAD_CONST into LOAD_CONST_[IM]MORTAL (GH-128708)

This commit is contained in:
Mark Shannon 2025-01-13 10:30:28 +00:00 committed by GitHub
parent 29fe8072cf
commit ddd959987c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 121 additions and 65 deletions

View file

@ -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)) {