diff options
author | Mark Shannon <mark@hotpy.org> | 2024-10-29 11:15:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-29 11:15:42 +0000 |
commit | faa3272fb8d63d481a136cc0467a0cba6ed7b264 (patch) | |
tree | 474ac9edbff637a8edb280846a1d3d9b113915c4 /Python/specialize.c | |
parent | 67f5c5bd6fcc956a785edef3be67e8cbe470cd31 (diff) | |
download | cpython-faa3272fb8d63d481a136cc0467a0cba6ed7b264.tar.gz cpython-faa3272fb8d63d481a136cc0467a0cba6ed7b264.zip |
GH-125837: Split `LOAD_CONST` into three. (GH-125972)
* Add LOAD_CONST_IMMORTAL opcode
* Add LOAD_SMALL_INT opcode
* Remove RETURN_CONST opcode
Diffstat (limited to 'Python/specialize.c')
-rw-r--r-- | Python/specialize.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/specialize.c b/Python/specialize.c index 4b33a468733..ae47809305a 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -442,11 +442,13 @@ _PyCode_Quicken(PyCodeObject *code) { #if ENABLE_SPECIALIZATION int opcode = 0; + int oparg = 0; _Py_CODEUNIT *instructions = _PyCode_CODE(code); /* The last code unit cannot have a cache, so we don't need to check it */ for (int i = 0; i < Py_SIZE(code)-1; i++) { opcode = instructions[i].op.code; int caches = _PyOpcode_Caches[opcode]; + oparg = (oparg << 8) | instructions[i].op.arg; if (caches) { // The initial value depends on the opcode switch (opcode) { @@ -465,6 +467,18 @@ _PyCode_Quicken(PyCodeObject *code) } i += caches; } + else if (opcode == LOAD_CONST) { + /* We can't do this in the bytecode compiler as + * marshalling can intern strings and make them immortal. */ + + PyObject *obj = PyTuple_GET_ITEM(code->co_consts, oparg); + if (_Py_IsImmortal(obj)) { + instructions[i].op.code = LOAD_CONST_IMMORTAL; + } + } + if (opcode != EXTENDED_ARG) { + oparg = 0; + } } #endif /* ENABLE_SPECIALIZATION */ } |