mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
GH-90997: Shrink the LOAD_GLOBAL caches (#102569)
This commit is contained in:
parent
767d3a8f6f
commit
08b67fb34f
11 changed files with 187 additions and 172 deletions
|
@ -1078,7 +1078,7 @@ dummy_func(
|
|||
LOAD_GLOBAL_BUILTIN,
|
||||
};
|
||||
|
||||
inst(LOAD_GLOBAL, (unused/1, unused/1, unused/2, unused/1 -- null if (oparg & 1), v)) {
|
||||
inst(LOAD_GLOBAL, (unused/1, unused/1, unused/1, unused/1 -- null if (oparg & 1), v)) {
|
||||
#if ENABLE_SPECIALIZATION
|
||||
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
|
||||
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
||||
|
@ -1133,7 +1133,7 @@ dummy_func(
|
|||
null = NULL;
|
||||
}
|
||||
|
||||
inst(LOAD_GLOBAL_MODULE, (unused/1, index/1, version/2, unused/1 -- null if (oparg & 1), res)) {
|
||||
inst(LOAD_GLOBAL_MODULE, (unused/1, index/1, version/1, unused/1 -- null if (oparg & 1), res)) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
|
||||
PyDictObject *dict = (PyDictObject *)GLOBALS();
|
||||
|
@ -1147,7 +1147,7 @@ dummy_func(
|
|||
null = NULL;
|
||||
}
|
||||
|
||||
inst(LOAD_GLOBAL_BUILTIN, (unused/1, index/1, mod_version/2, bltn_version/1 -- null if (oparg & 1), res)) {
|
||||
inst(LOAD_GLOBAL_BUILTIN, (unused/1, index/1, mod_version/1, bltn_version/1 -- null if (oparg & 1), res)) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
|
||||
DEOPT_IF(!PyDict_CheckExact(BUILTINS()), LOAD_GLOBAL);
|
||||
|
|
14
Python/generated_cases.c.h
generated
14
Python/generated_cases.c.h
generated
|
@ -1349,7 +1349,7 @@
|
|||
|
||||
TARGET(LOAD_GLOBAL) {
|
||||
PREDICTED(LOAD_GLOBAL);
|
||||
static_assert(INLINE_CACHE_ENTRIES_LOAD_GLOBAL == 5, "incorrect cache size");
|
||||
static_assert(INLINE_CACHE_ENTRIES_LOAD_GLOBAL == 4, "incorrect cache size");
|
||||
PyObject *null = NULL;
|
||||
PyObject *v;
|
||||
#if ENABLE_SPECIALIZATION
|
||||
|
@ -1408,7 +1408,7 @@
|
|||
STACK_GROW(((oparg & 1) ? 1 : 0));
|
||||
stack_pointer[-1] = v;
|
||||
if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = null; }
|
||||
next_instr += 5;
|
||||
next_instr += 4;
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -1416,7 +1416,7 @@
|
|||
PyObject *null = NULL;
|
||||
PyObject *res;
|
||||
uint16_t index = read_u16(&next_instr[1].cache);
|
||||
uint32_t version = read_u32(&next_instr[2].cache);
|
||||
uint16_t version = read_u16(&next_instr[2].cache);
|
||||
assert(cframe.use_tracing == 0);
|
||||
DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
|
||||
PyDictObject *dict = (PyDictObject *)GLOBALS();
|
||||
|
@ -1432,7 +1432,7 @@
|
|||
STACK_GROW(((oparg & 1) ? 1 : 0));
|
||||
stack_pointer[-1] = res;
|
||||
if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = null; }
|
||||
next_instr += 5;
|
||||
next_instr += 4;
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -1440,8 +1440,8 @@
|
|||
PyObject *null = NULL;
|
||||
PyObject *res;
|
||||
uint16_t index = read_u16(&next_instr[1].cache);
|
||||
uint32_t mod_version = read_u32(&next_instr[2].cache);
|
||||
uint16_t bltn_version = read_u16(&next_instr[4].cache);
|
||||
uint16_t mod_version = read_u16(&next_instr[2].cache);
|
||||
uint16_t bltn_version = read_u16(&next_instr[3].cache);
|
||||
assert(cframe.use_tracing == 0);
|
||||
DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
|
||||
DEOPT_IF(!PyDict_CheckExact(BUILTINS()), LOAD_GLOBAL);
|
||||
|
@ -1460,7 +1460,7 @@
|
|||
STACK_GROW(((oparg & 1) ? 1 : 0));
|
||||
stack_pointer[-1] = res;
|
||||
if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = null; }
|
||||
next_instr += 5;
|
||||
next_instr += 4;
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
|
|
@ -708,7 +708,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
|||
#endif
|
||||
|
||||
enum Direction { DIR_NONE, DIR_READ, DIR_WRITE };
|
||||
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC0, INSTR_FMT_IBC000, INSTR_FMT_IBC0000, INSTR_FMT_IBC00000000, INSTR_FMT_IBIB, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
|
||||
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC0, INSTR_FMT_IBC000, INSTR_FMT_IBC00000000, INSTR_FMT_IBIB, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
|
||||
struct opcode_metadata {
|
||||
enum Direction dir_op1;
|
||||
enum Direction dir_op2;
|
||||
|
@ -790,9 +790,9 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
|
|||
[STORE_GLOBAL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[DELETE_GLOBAL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[LOAD_NAME] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[LOAD_GLOBAL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC0000 },
|
||||
[LOAD_GLOBAL_MODULE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC0000 },
|
||||
[LOAD_GLOBAL_BUILTIN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC0000 },
|
||||
[LOAD_GLOBAL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
|
||||
[LOAD_GLOBAL_MODULE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
|
||||
[LOAD_GLOBAL_BUILTIN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
|
||||
[DELETE_FAST] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[MAKE_CELL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[DELETE_DEREF] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
|
|
|
@ -1148,8 +1148,12 @@ _Py_Specialize_LoadGlobal(
|
|||
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_VERSIONS);
|
||||
goto fail;
|
||||
}
|
||||
if (keys_version != (uint16_t)keys_version) {
|
||||
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_RANGE);
|
||||
goto fail;
|
||||
}
|
||||
cache->index = (uint16_t)index;
|
||||
write_u32(cache->module_keys_version, keys_version);
|
||||
cache->module_keys_version = (uint16_t)keys_version;
|
||||
instr->op.code = LOAD_GLOBAL_MODULE;
|
||||
goto success;
|
||||
}
|
||||
|
@ -1177,6 +1181,10 @@ _Py_Specialize_LoadGlobal(
|
|||
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_VERSIONS);
|
||||
goto fail;
|
||||
}
|
||||
if (globals_version != (uint16_t)globals_version) {
|
||||
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_RANGE);
|
||||
goto fail;
|
||||
}
|
||||
uint32_t builtins_version = _PyDictKeys_GetVersionForCurrentState(
|
||||
interp, builtin_keys);
|
||||
if (builtins_version == 0) {
|
||||
|
@ -1188,7 +1196,7 @@ _Py_Specialize_LoadGlobal(
|
|||
goto fail;
|
||||
}
|
||||
cache->index = (uint16_t)index;
|
||||
write_u32(cache->module_keys_version, globals_version);
|
||||
cache->module_keys_version = (uint16_t)globals_version;
|
||||
cache->builtin_keys_version = (uint16_t)builtins_version;
|
||||
instr->op.code = LOAD_GLOBAL_BUILTIN;
|
||||
goto success;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue