diff options
author | Ken Jin <kenjin@python.org> | 2022-12-23 16:26:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-23 16:26:42 (GMT) |
commit | c3c7848a48b74a321632202e4bdcf2f465fb1cc6 (patch) | |
tree | c880b1a9a096b627e85d643db00704e03f041446 /Python/bytecodes.c | |
parent | 7fc7909677759fd0cb9d30cd7ff839afd3973325 (diff) | |
download | cpython-c3c7848a48b74a321632202e4bdcf2f465fb1cc6.zip cpython-c3c7848a48b74a321632202e4bdcf2f465fb1cc6.tar.gz cpython-c3c7848a48b74a321632202e4bdcf2f465fb1cc6.tar.bz2 |
gh-100288: Specialise LOAD_ATTR_METHOD for managed dictionaries (GH-100289)
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r-- | Python/bytecodes.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index c0b625b..c2f6a7a 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2718,6 +2718,31 @@ dummy_func( } // error: LOAD_ATTR has irregular stack effect + inst(LOAD_ATTR_METHOD_MANAGED_DICT) { + assert(cframe.use_tracing == 0); + PyObject *self = TOP(); + PyTypeObject *self_cls = Py_TYPE(self); + _PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr; + uint32_t type_version = read_u32(cache->type_version); + assert(type_version != 0); + DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR) + assert(self_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT); + PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(self); + DEOPT_IF(_PyDictOrValues_IsValues(dorv), LOAD_ATTR); + PyObject *dict = _PyDictOrValues_GetDict(dorv); + PyDictKeysObject *keys = (dict == NULL) ? NULL : ((PyDictObject *)dict)->ma_keys; + // Note: cache->keys_version can be 0 when dict is NULL. + DEOPT_IF(keys != NULL && keys->dk_version != read_u32(cache->keys_version), LOAD_ATTR); + STAT_INC(LOAD_ATTR, hit); + PyObject *res = read_obj(cache->descr); + assert(res != NULL); + assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)); + SET_TOP(Py_NewRef(res)); + PUSH(self); + JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR); + } + + // error: LOAD_ATTR has irregular stack effect inst(LOAD_ATTR_METHOD_WITH_DICT) { /* Can be either a managed dict, or a tp_dictoffset offset.*/ assert(cframe.use_tracing == 0); |