summaryrefslogtreecommitdiffstats
path: root/Python/generated_cases.c.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2025-01-13 10:30:28 (GMT)
committerGitHub <noreply@github.com>2025-01-13 10:30:28 (GMT)
commitddd959987c557beaf823b681bf5e5e573ad657ac (patch)
treee59574d3eb62f94e497f7aecd585bf656ebc984e /Python/generated_cases.c.h
parent29fe8072cf404b891dde9c1d415095edddbe19de (diff)
downloadcpython-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/generated_cases.c.h')
-rw-r--r--Python/generated_cases.c.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 7028ba5..70d0814 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -5913,8 +5913,18 @@
next_instr += 1;
INSTRUCTION_STATS(LOAD_CONST);
PREDICTED(LOAD_CONST);
+ _Py_CODEUNIT* const this_instr = next_instr - 1;
+ (void)this_instr;
_PyStackRef value;
- value = PyStackRef_FromPyObjectNew(GETITEM(FRAME_CO_CONSTS, oparg));
+ /* 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
stack_pointer[0] = value;
stack_pointer += 1;
assert(WITHIN_STACK_BOUNDS());
@@ -5936,6 +5946,20 @@
DISPATCH();
}
+ TARGET(LOAD_CONST_MORTAL) {
+ frame->instr_ptr = next_instr;
+ next_instr += 1;
+ INSTRUCTION_STATS(LOAD_CONST_MORTAL);
+ static_assert(0 == 0, "incorrect cache size");
+ _PyStackRef value;
+ PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg);
+ value = PyStackRef_FromPyObjectNew(obj);
+ stack_pointer[0] = value;
+ stack_pointer += 1;
+ assert(WITHIN_STACK_BOUNDS());
+ DISPATCH();
+ }
+
TARGET(LOAD_DEREF) {
frame->instr_ptr = next_instr;
next_instr += 1;