mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-87729: improve hit rate of LOAD_SUPER_ATTR specialization (#104270)
This commit is contained in:
parent
ddc0e70a32
commit
77262458fe
13 changed files with 374 additions and 352 deletions
|
@ -53,9 +53,6 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t counter;
|
uint16_t counter;
|
||||||
uint16_t class_version[2];
|
|
||||||
uint16_t self_type_version[2];
|
|
||||||
uint16_t method[4];
|
|
||||||
} _PySuperAttrCache;
|
} _PySuperAttrCache;
|
||||||
|
|
||||||
#define INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR CACHE_ENTRIES(_PySuperAttrCache)
|
#define INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR CACHE_ENTRIES(_PySuperAttrCache)
|
||||||
|
@ -227,8 +224,8 @@ extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
|
||||||
|
|
||||||
/* Specialization functions */
|
/* Specialization functions */
|
||||||
|
|
||||||
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self,
|
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls,
|
||||||
_Py_CODEUNIT *instr, PyObject *name, int load_method);
|
_Py_CODEUNIT *instr, int load_method);
|
||||||
extern void _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr,
|
extern void _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr,
|
||||||
PyObject *name);
|
PyObject *name);
|
||||||
extern void _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr,
|
extern void _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr,
|
||||||
|
|
24
Include/internal/pycore_opcode.h
generated
24
Include/internal/pycore_opcode.h
generated
|
@ -42,7 +42,7 @@ const uint8_t _PyOpcode_Caches[256] = {
|
||||||
[LOAD_GLOBAL] = 4,
|
[LOAD_GLOBAL] = 4,
|
||||||
[BINARY_OP] = 1,
|
[BINARY_OP] = 1,
|
||||||
[SEND] = 1,
|
[SEND] = 1,
|
||||||
[LOAD_SUPER_ATTR] = 9,
|
[LOAD_SUPER_ATTR] = 1,
|
||||||
[CALL] = 3,
|
[CALL] = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,6 +182,7 @@ const uint8_t _PyOpcode_Deopt[256] = {
|
||||||
[LOAD_GLOBAL_MODULE] = LOAD_GLOBAL,
|
[LOAD_GLOBAL_MODULE] = LOAD_GLOBAL,
|
||||||
[LOAD_NAME] = LOAD_NAME,
|
[LOAD_NAME] = LOAD_NAME,
|
||||||
[LOAD_SUPER_ATTR] = LOAD_SUPER_ATTR,
|
[LOAD_SUPER_ATTR] = LOAD_SUPER_ATTR,
|
||||||
|
[LOAD_SUPER_ATTR_ATTR] = LOAD_SUPER_ATTR,
|
||||||
[LOAD_SUPER_ATTR_METHOD] = LOAD_SUPER_ATTR,
|
[LOAD_SUPER_ATTR_METHOD] = LOAD_SUPER_ATTR,
|
||||||
[MAKE_CELL] = MAKE_CELL,
|
[MAKE_CELL] = MAKE_CELL,
|
||||||
[MAKE_FUNCTION] = MAKE_FUNCTION,
|
[MAKE_FUNCTION] = MAKE_FUNCTION,
|
||||||
|
@ -307,29 +308,29 @@ static const char *const _PyOpcode_OpName[267] = {
|
||||||
[FOR_ITER_TUPLE] = "FOR_ITER_TUPLE",
|
[FOR_ITER_TUPLE] = "FOR_ITER_TUPLE",
|
||||||
[FOR_ITER_RANGE] = "FOR_ITER_RANGE",
|
[FOR_ITER_RANGE] = "FOR_ITER_RANGE",
|
||||||
[FOR_ITER_GEN] = "FOR_ITER_GEN",
|
[FOR_ITER_GEN] = "FOR_ITER_GEN",
|
||||||
|
[LOAD_SUPER_ATTR_ATTR] = "LOAD_SUPER_ATTR_ATTR",
|
||||||
[LOAD_SUPER_ATTR_METHOD] = "LOAD_SUPER_ATTR_METHOD",
|
[LOAD_SUPER_ATTR_METHOD] = "LOAD_SUPER_ATTR_METHOD",
|
||||||
[LOAD_ATTR_CLASS] = "LOAD_ATTR_CLASS",
|
|
||||||
[GET_ITER] = "GET_ITER",
|
[GET_ITER] = "GET_ITER",
|
||||||
[GET_YIELD_FROM_ITER] = "GET_YIELD_FROM_ITER",
|
[GET_YIELD_FROM_ITER] = "GET_YIELD_FROM_ITER",
|
||||||
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = "LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN",
|
[LOAD_ATTR_CLASS] = "LOAD_ATTR_CLASS",
|
||||||
[LOAD_BUILD_CLASS] = "LOAD_BUILD_CLASS",
|
[LOAD_BUILD_CLASS] = "LOAD_BUILD_CLASS",
|
||||||
|
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = "LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN",
|
||||||
[LOAD_ATTR_INSTANCE_VALUE] = "LOAD_ATTR_INSTANCE_VALUE",
|
[LOAD_ATTR_INSTANCE_VALUE] = "LOAD_ATTR_INSTANCE_VALUE",
|
||||||
[LOAD_ATTR_MODULE] = "LOAD_ATTR_MODULE",
|
|
||||||
[LOAD_ASSERTION_ERROR] = "LOAD_ASSERTION_ERROR",
|
[LOAD_ASSERTION_ERROR] = "LOAD_ASSERTION_ERROR",
|
||||||
[RETURN_GENERATOR] = "RETURN_GENERATOR",
|
[RETURN_GENERATOR] = "RETURN_GENERATOR",
|
||||||
|
[LOAD_ATTR_MODULE] = "LOAD_ATTR_MODULE",
|
||||||
[LOAD_ATTR_PROPERTY] = "LOAD_ATTR_PROPERTY",
|
[LOAD_ATTR_PROPERTY] = "LOAD_ATTR_PROPERTY",
|
||||||
[LOAD_ATTR_SLOT] = "LOAD_ATTR_SLOT",
|
[LOAD_ATTR_SLOT] = "LOAD_ATTR_SLOT",
|
||||||
[LOAD_ATTR_WITH_HINT] = "LOAD_ATTR_WITH_HINT",
|
[LOAD_ATTR_WITH_HINT] = "LOAD_ATTR_WITH_HINT",
|
||||||
[LOAD_ATTR_METHOD_LAZY_DICT] = "LOAD_ATTR_METHOD_LAZY_DICT",
|
[LOAD_ATTR_METHOD_LAZY_DICT] = "LOAD_ATTR_METHOD_LAZY_DICT",
|
||||||
[LOAD_ATTR_METHOD_NO_DICT] = "LOAD_ATTR_METHOD_NO_DICT",
|
[LOAD_ATTR_METHOD_NO_DICT] = "LOAD_ATTR_METHOD_NO_DICT",
|
||||||
[LOAD_ATTR_METHOD_WITH_VALUES] = "LOAD_ATTR_METHOD_WITH_VALUES",
|
[LOAD_ATTR_METHOD_WITH_VALUES] = "LOAD_ATTR_METHOD_WITH_VALUES",
|
||||||
[LOAD_CONST__LOAD_FAST] = "LOAD_CONST__LOAD_FAST",
|
|
||||||
[RETURN_VALUE] = "RETURN_VALUE",
|
[RETURN_VALUE] = "RETURN_VALUE",
|
||||||
[LOAD_FAST__LOAD_CONST] = "LOAD_FAST__LOAD_CONST",
|
[LOAD_CONST__LOAD_FAST] = "LOAD_CONST__LOAD_FAST",
|
||||||
[SETUP_ANNOTATIONS] = "SETUP_ANNOTATIONS",
|
[SETUP_ANNOTATIONS] = "SETUP_ANNOTATIONS",
|
||||||
|
[LOAD_FAST__LOAD_CONST] = "LOAD_FAST__LOAD_CONST",
|
||||||
[LOAD_FAST__LOAD_FAST] = "LOAD_FAST__LOAD_FAST",
|
[LOAD_FAST__LOAD_FAST] = "LOAD_FAST__LOAD_FAST",
|
||||||
[LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN",
|
[LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN",
|
||||||
[LOAD_GLOBAL_MODULE] = "LOAD_GLOBAL_MODULE",
|
|
||||||
[POP_EXCEPT] = "POP_EXCEPT",
|
[POP_EXCEPT] = "POP_EXCEPT",
|
||||||
[STORE_NAME] = "STORE_NAME",
|
[STORE_NAME] = "STORE_NAME",
|
||||||
[DELETE_NAME] = "DELETE_NAME",
|
[DELETE_NAME] = "DELETE_NAME",
|
||||||
|
@ -352,9 +353,9 @@ static const char *const _PyOpcode_OpName[267] = {
|
||||||
[IMPORT_NAME] = "IMPORT_NAME",
|
[IMPORT_NAME] = "IMPORT_NAME",
|
||||||
[IMPORT_FROM] = "IMPORT_FROM",
|
[IMPORT_FROM] = "IMPORT_FROM",
|
||||||
[JUMP_FORWARD] = "JUMP_FORWARD",
|
[JUMP_FORWARD] = "JUMP_FORWARD",
|
||||||
|
[LOAD_GLOBAL_MODULE] = "LOAD_GLOBAL_MODULE",
|
||||||
[STORE_ATTR_INSTANCE_VALUE] = "STORE_ATTR_INSTANCE_VALUE",
|
[STORE_ATTR_INSTANCE_VALUE] = "STORE_ATTR_INSTANCE_VALUE",
|
||||||
[STORE_ATTR_SLOT] = "STORE_ATTR_SLOT",
|
[STORE_ATTR_SLOT] = "STORE_ATTR_SLOT",
|
||||||
[STORE_ATTR_WITH_HINT] = "STORE_ATTR_WITH_HINT",
|
|
||||||
[POP_JUMP_IF_FALSE] = "POP_JUMP_IF_FALSE",
|
[POP_JUMP_IF_FALSE] = "POP_JUMP_IF_FALSE",
|
||||||
[POP_JUMP_IF_TRUE] = "POP_JUMP_IF_TRUE",
|
[POP_JUMP_IF_TRUE] = "POP_JUMP_IF_TRUE",
|
||||||
[LOAD_GLOBAL] = "LOAD_GLOBAL",
|
[LOAD_GLOBAL] = "LOAD_GLOBAL",
|
||||||
|
@ -394,22 +395,22 @@ static const char *const _PyOpcode_OpName[267] = {
|
||||||
[YIELD_VALUE] = "YIELD_VALUE",
|
[YIELD_VALUE] = "YIELD_VALUE",
|
||||||
[RESUME] = "RESUME",
|
[RESUME] = "RESUME",
|
||||||
[MATCH_CLASS] = "MATCH_CLASS",
|
[MATCH_CLASS] = "MATCH_CLASS",
|
||||||
|
[STORE_ATTR_WITH_HINT] = "STORE_ATTR_WITH_HINT",
|
||||||
[STORE_FAST__LOAD_FAST] = "STORE_FAST__LOAD_FAST",
|
[STORE_FAST__LOAD_FAST] = "STORE_FAST__LOAD_FAST",
|
||||||
[STORE_FAST__STORE_FAST] = "STORE_FAST__STORE_FAST",
|
|
||||||
[FORMAT_VALUE] = "FORMAT_VALUE",
|
[FORMAT_VALUE] = "FORMAT_VALUE",
|
||||||
[BUILD_CONST_KEY_MAP] = "BUILD_CONST_KEY_MAP",
|
[BUILD_CONST_KEY_MAP] = "BUILD_CONST_KEY_MAP",
|
||||||
[BUILD_STRING] = "BUILD_STRING",
|
[BUILD_STRING] = "BUILD_STRING",
|
||||||
|
[STORE_FAST__STORE_FAST] = "STORE_FAST__STORE_FAST",
|
||||||
[STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT",
|
[STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT",
|
||||||
[STORE_SUBSCR_LIST_INT] = "STORE_SUBSCR_LIST_INT",
|
[STORE_SUBSCR_LIST_INT] = "STORE_SUBSCR_LIST_INT",
|
||||||
[UNPACK_SEQUENCE_LIST] = "UNPACK_SEQUENCE_LIST",
|
[UNPACK_SEQUENCE_LIST] = "UNPACK_SEQUENCE_LIST",
|
||||||
[UNPACK_SEQUENCE_TUPLE] = "UNPACK_SEQUENCE_TUPLE",
|
|
||||||
[LIST_EXTEND] = "LIST_EXTEND",
|
[LIST_EXTEND] = "LIST_EXTEND",
|
||||||
[SET_UPDATE] = "SET_UPDATE",
|
[SET_UPDATE] = "SET_UPDATE",
|
||||||
[DICT_MERGE] = "DICT_MERGE",
|
[DICT_MERGE] = "DICT_MERGE",
|
||||||
[DICT_UPDATE] = "DICT_UPDATE",
|
[DICT_UPDATE] = "DICT_UPDATE",
|
||||||
|
[UNPACK_SEQUENCE_TUPLE] = "UNPACK_SEQUENCE_TUPLE",
|
||||||
[UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE",
|
[UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE",
|
||||||
[SEND_GEN] = "SEND_GEN",
|
[SEND_GEN] = "SEND_GEN",
|
||||||
[168] = "<168>",
|
|
||||||
[169] = "<169>",
|
[169] = "<169>",
|
||||||
[170] = "<170>",
|
[170] = "<170>",
|
||||||
[CALL] = "CALL",
|
[CALL] = "CALL",
|
||||||
|
@ -512,7 +513,6 @@ static const char *const _PyOpcode_OpName[267] = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define EXTRA_CASES \
|
#define EXTRA_CASES \
|
||||||
case 168: \
|
|
||||||
case 169: \
|
case 169: \
|
||||||
case 170: \
|
case 170: \
|
||||||
case 175: \
|
case 175: \
|
||||||
|
|
|
@ -142,8 +142,6 @@ PyAPI_DATA(PyTypeObject) _PyBufferWrapper_Type;
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *meth_found);
|
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *meth_found);
|
||||||
PyObject *
|
|
||||||
_PySuper_LookupDescr(PyTypeObject *su_type, PyObject *su_obj, PyObject *name);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
55
Include/opcode.h
generated
55
Include/opcode.h
generated
|
@ -185,33 +185,34 @@ extern "C" {
|
||||||
#define FOR_ITER_TUPLE 63
|
#define FOR_ITER_TUPLE 63
|
||||||
#define FOR_ITER_RANGE 64
|
#define FOR_ITER_RANGE 64
|
||||||
#define FOR_ITER_GEN 65
|
#define FOR_ITER_GEN 65
|
||||||
#define LOAD_SUPER_ATTR_METHOD 66
|
#define LOAD_SUPER_ATTR_ATTR 66
|
||||||
#define LOAD_ATTR_CLASS 67
|
#define LOAD_SUPER_ATTR_METHOD 67
|
||||||
#define LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 70
|
#define LOAD_ATTR_CLASS 70
|
||||||
#define LOAD_ATTR_INSTANCE_VALUE 72
|
#define LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 72
|
||||||
#define LOAD_ATTR_MODULE 73
|
#define LOAD_ATTR_INSTANCE_VALUE 73
|
||||||
#define LOAD_ATTR_PROPERTY 76
|
#define LOAD_ATTR_MODULE 76
|
||||||
#define LOAD_ATTR_SLOT 77
|
#define LOAD_ATTR_PROPERTY 77
|
||||||
#define LOAD_ATTR_WITH_HINT 78
|
#define LOAD_ATTR_SLOT 78
|
||||||
#define LOAD_ATTR_METHOD_LAZY_DICT 79
|
#define LOAD_ATTR_WITH_HINT 79
|
||||||
#define LOAD_ATTR_METHOD_NO_DICT 80
|
#define LOAD_ATTR_METHOD_LAZY_DICT 80
|
||||||
#define LOAD_ATTR_METHOD_WITH_VALUES 81
|
#define LOAD_ATTR_METHOD_NO_DICT 81
|
||||||
#define LOAD_CONST__LOAD_FAST 82
|
#define LOAD_ATTR_METHOD_WITH_VALUES 82
|
||||||
#define LOAD_FAST__LOAD_CONST 84
|
#define LOAD_CONST__LOAD_FAST 84
|
||||||
#define LOAD_FAST__LOAD_FAST 86
|
#define LOAD_FAST__LOAD_CONST 86
|
||||||
#define LOAD_GLOBAL_BUILTIN 87
|
#define LOAD_FAST__LOAD_FAST 87
|
||||||
#define LOAD_GLOBAL_MODULE 88
|
#define LOAD_GLOBAL_BUILTIN 88
|
||||||
#define STORE_ATTR_INSTANCE_VALUE 111
|
#define LOAD_GLOBAL_MODULE 111
|
||||||
#define STORE_ATTR_SLOT 112
|
#define STORE_ATTR_INSTANCE_VALUE 112
|
||||||
#define STORE_ATTR_WITH_HINT 113
|
#define STORE_ATTR_SLOT 113
|
||||||
#define STORE_FAST__LOAD_FAST 153
|
#define STORE_ATTR_WITH_HINT 153
|
||||||
#define STORE_FAST__STORE_FAST 154
|
#define STORE_FAST__LOAD_FAST 154
|
||||||
#define STORE_SUBSCR_DICT 158
|
#define STORE_FAST__STORE_FAST 158
|
||||||
#define STORE_SUBSCR_LIST_INT 159
|
#define STORE_SUBSCR_DICT 159
|
||||||
#define UNPACK_SEQUENCE_LIST 160
|
#define STORE_SUBSCR_LIST_INT 160
|
||||||
#define UNPACK_SEQUENCE_TUPLE 161
|
#define UNPACK_SEQUENCE_LIST 161
|
||||||
#define UNPACK_SEQUENCE_TWO_TUPLE 166
|
#define UNPACK_SEQUENCE_TUPLE 166
|
||||||
#define SEND_GEN 167
|
#define UNPACK_SEQUENCE_TWO_TUPLE 167
|
||||||
|
#define SEND_GEN 168
|
||||||
|
|
||||||
#define HAS_ARG(op) ((((op) >= HAVE_ARGUMENT) && (!IS_PSEUDO_OPCODE(op)))\
|
#define HAS_ARG(op) ((((op) >= HAVE_ARGUMENT) && (!IS_PSEUDO_OPCODE(op)))\
|
||||||
|| ((op) == JUMP) \
|
|| ((op) == JUMP) \
|
||||||
|
|
|
@ -443,6 +443,7 @@ _code_type = type(_write_atomic.__code__)
|
||||||
# Python 3.12b1 3527 (Add LOAD_SUPER_ATTR)
|
# Python 3.12b1 3527 (Add LOAD_SUPER_ATTR)
|
||||||
# Python 3.12b1 3528 (Add LOAD_SUPER_ATTR_METHOD specialization)
|
# Python 3.12b1 3528 (Add LOAD_SUPER_ATTR_METHOD specialization)
|
||||||
# Python 3.12b1 3529 (Inline list/dict/set comprehensions)
|
# Python 3.12b1 3529 (Inline list/dict/set comprehensions)
|
||||||
|
# Python 3.12b1 3530 (Shrink the LOAD_SUPER_ATTR caches)
|
||||||
|
|
||||||
# Python 3.13 will start with 3550
|
# Python 3.13 will start with 3550
|
||||||
|
|
||||||
|
@ -459,7 +460,7 @@ _code_type = type(_write_atomic.__code__)
|
||||||
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
|
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
|
||||||
# in PC/launcher.c must also be updated.
|
# in PC/launcher.c must also be updated.
|
||||||
|
|
||||||
MAGIC_NUMBER = (3529).to_bytes(2, 'little') + b'\r\n'
|
MAGIC_NUMBER = (3530).to_bytes(2, 'little') + b'\r\n'
|
||||||
|
|
||||||
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
|
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
|
||||||
|
|
||||||
|
|
|
@ -373,6 +373,7 @@ _specializations = {
|
||||||
"FOR_ITER_GEN",
|
"FOR_ITER_GEN",
|
||||||
],
|
],
|
||||||
"LOAD_SUPER_ATTR": [
|
"LOAD_SUPER_ATTR": [
|
||||||
|
"LOAD_SUPER_ATTR_ATTR",
|
||||||
"LOAD_SUPER_ATTR_METHOD",
|
"LOAD_SUPER_ATTR_METHOD",
|
||||||
],
|
],
|
||||||
"LOAD_ATTR": [
|
"LOAD_ATTR": [
|
||||||
|
@ -450,9 +451,6 @@ _cache_format = {
|
||||||
},
|
},
|
||||||
"LOAD_SUPER_ATTR": {
|
"LOAD_SUPER_ATTR": {
|
||||||
"counter": 1,
|
"counter": 1,
|
||||||
"class_version": 2,
|
|
||||||
"self_type_version": 2,
|
|
||||||
"method": 4,
|
|
||||||
},
|
},
|
||||||
"LOAD_ATTR": {
|
"LOAD_ATTR": {
|
||||||
"counter": 1,
|
"counter": 1,
|
||||||
|
|
|
@ -10245,18 +10245,6 @@ _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *me
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
|
||||||
_PySuper_LookupDescr(PyTypeObject *su_type, PyObject *su_obj, PyObject *name)
|
|
||||||
{
|
|
||||||
PyTypeObject *su_obj_type = supercheck(su_type, su_obj);
|
|
||||||
if (su_obj_type == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
PyObject *res = _super_lookup_descr(su_type, su_obj_type, name);
|
|
||||||
Py_DECREF(su_obj_type);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
|
super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1562,17 +1562,18 @@ dummy_func(
|
||||||
|
|
||||||
family(load_super_attr, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR) = {
|
family(load_super_attr, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR) = {
|
||||||
LOAD_SUPER_ATTR,
|
LOAD_SUPER_ATTR,
|
||||||
|
LOAD_SUPER_ATTR_ATTR,
|
||||||
LOAD_SUPER_ATTR_METHOD,
|
LOAD_SUPER_ATTR_METHOD,
|
||||||
};
|
};
|
||||||
|
|
||||||
inst(LOAD_SUPER_ATTR, (unused/9, global_super, class, self -- res2 if (oparg & 1), res)) {
|
inst(LOAD_SUPER_ATTR, (unused/1, global_super, class, self -- res2 if (oparg & 1), res)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
|
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
|
||||||
int load_method = oparg & 1;
|
int load_method = oparg & 1;
|
||||||
#if ENABLE_SPECIALIZATION
|
#if ENABLE_SPECIALIZATION
|
||||||
_PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr;
|
_PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr;
|
||||||
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
||||||
next_instr--;
|
next_instr--;
|
||||||
_Py_Specialize_LoadSuperAttr(global_super, class, self, next_instr, name, load_method);
|
_Py_Specialize_LoadSuperAttr(global_super, class, next_instr, load_method);
|
||||||
DISPATCH_SAME_OPARG();
|
DISPATCH_SAME_OPARG();
|
||||||
}
|
}
|
||||||
STAT_INC(LOAD_SUPER_ATTR, deferred);
|
STAT_INC(LOAD_SUPER_ATTR, deferred);
|
||||||
|
@ -1590,17 +1591,38 @@ dummy_func(
|
||||||
ERROR_IF(res == NULL, error);
|
ERROR_IF(res == NULL, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(LOAD_SUPER_ATTR_METHOD, (unused/1, class_version/2, self_type_version/2, method/4, global_super, class, self -- res2, res)) {
|
inst(LOAD_SUPER_ATTR_ATTR, (unused/1, global_super, class, self -- res2 if (oparg & 1), res)) {
|
||||||
|
assert(!(oparg & 1));
|
||||||
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
|
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
|
||||||
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
|
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
|
||||||
DEOPT_IF(((PyTypeObject *)class)->tp_version_tag != class_version, LOAD_SUPER_ATTR);
|
STAT_INC(LOAD_SUPER_ATTR, hit);
|
||||||
PyTypeObject *self_type = Py_TYPE(self);
|
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
|
||||||
DEOPT_IF(self_type->tp_version_tag != self_type_version, LOAD_SUPER_ATTR);
|
res = _PySuper_Lookup((PyTypeObject *)class, self, name, NULL);
|
||||||
res2 = method;
|
ERROR_IF(res == NULL, error);
|
||||||
res = self; // transfer ownership
|
DECREF_INPUTS();
|
||||||
Py_INCREF(res2);
|
}
|
||||||
|
|
||||||
|
inst(LOAD_SUPER_ATTR_METHOD, (unused/1, global_super, class, self -- res2, res)) {
|
||||||
|
assert(oparg & 1);
|
||||||
|
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
|
||||||
|
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
|
||||||
|
STAT_INC(LOAD_SUPER_ATTR, hit);
|
||||||
|
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
|
||||||
|
int method_found = 0;
|
||||||
|
res2 = _PySuper_Lookup((PyTypeObject *)class, self, name, &method_found);
|
||||||
Py_DECREF(global_super);
|
Py_DECREF(global_super);
|
||||||
Py_DECREF(class);
|
Py_DECREF(class);
|
||||||
|
if (res2 == NULL) {
|
||||||
|
Py_DECREF(self);
|
||||||
|
ERROR_IF(true, error);
|
||||||
|
}
|
||||||
|
if (method_found) {
|
||||||
|
res = self; // transfer ownership
|
||||||
|
} else {
|
||||||
|
Py_DECREF(self);
|
||||||
|
res = res2;
|
||||||
|
res2 = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
family(load_attr, INLINE_CACHE_ENTRIES_LOAD_ATTR) = {
|
family(load_attr, INLINE_CACHE_ENTRIES_LOAD_ATTR) = {
|
||||||
|
|
507
Python/generated_cases.c.h
generated
507
Python/generated_cases.c.h
generated
File diff suppressed because it is too large
Load diff
|
@ -209,6 +209,8 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
|
||||||
return 2;
|
return 2;
|
||||||
case LOAD_SUPER_ATTR:
|
case LOAD_SUPER_ATTR:
|
||||||
return 3;
|
return 3;
|
||||||
|
case LOAD_SUPER_ATTR_ATTR:
|
||||||
|
return 3;
|
||||||
case LOAD_SUPER_ATTR_METHOD:
|
case LOAD_SUPER_ATTR_METHOD:
|
||||||
return 3;
|
return 3;
|
||||||
case LOAD_ATTR:
|
case LOAD_ATTR:
|
||||||
|
@ -599,6 +601,8 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
||||||
return 0;
|
return 0;
|
||||||
case LOAD_SUPER_ATTR:
|
case LOAD_SUPER_ATTR:
|
||||||
return ((oparg & 1) ? 1 : 0) + 1;
|
return ((oparg & 1) ? 1 : 0) + 1;
|
||||||
|
case LOAD_SUPER_ATTR_ATTR:
|
||||||
|
return ((oparg & 1) ? 1 : 0) + 1;
|
||||||
case LOAD_SUPER_ATTR_METHOD:
|
case LOAD_SUPER_ATTR_METHOD:
|
||||||
return 2;
|
return 2;
|
||||||
case LOAD_ATTR:
|
case LOAD_ATTR:
|
||||||
|
@ -783,7 +787,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC00, INSTR_FMT_IBC000, INSTR_FMT_IBC00000000, INSTR_FMT_IBIB, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000, INSTR_FMT_IXC00000000 };
|
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC00, INSTR_FMT_IBC000, INSTR_FMT_IBC00000000, INSTR_FMT_IBIB, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
|
||||||
struct opcode_metadata {
|
struct opcode_metadata {
|
||||||
bool valid_entry;
|
bool valid_entry;
|
||||||
enum InstructionFormat instr_format;
|
enum InstructionFormat instr_format;
|
||||||
|
@ -892,8 +896,9 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
|
||||||
[DICT_UPDATE] = { true, INSTR_FMT_IB },
|
[DICT_UPDATE] = { true, INSTR_FMT_IB },
|
||||||
[DICT_MERGE] = { true, INSTR_FMT_IB },
|
[DICT_MERGE] = { true, INSTR_FMT_IB },
|
||||||
[MAP_ADD] = { true, INSTR_FMT_IB },
|
[MAP_ADD] = { true, INSTR_FMT_IB },
|
||||||
[LOAD_SUPER_ATTR] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_SUPER_ATTR] = { true, INSTR_FMT_IBC },
|
||||||
[LOAD_SUPER_ATTR_METHOD] = { true, INSTR_FMT_IXC00000000 },
|
[LOAD_SUPER_ATTR_ATTR] = { true, INSTR_FMT_IBC },
|
||||||
|
[LOAD_SUPER_ATTR_METHOD] = { true, INSTR_FMT_IBC },
|
||||||
[LOAD_ATTR] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR] = { true, INSTR_FMT_IBC00000000 },
|
||||||
[LOAD_ATTR_INSTANCE_VALUE] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_INSTANCE_VALUE] = { true, INSTR_FMT_IBC00000000 },
|
||||||
[LOAD_ATTR_MODULE] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_MODULE] = { true, INSTR_FMT_IBC00000000 },
|
||||||
|
|
20
Python/opcode_targets.h
generated
20
Python/opcode_targets.h
generated
|
@ -65,29 +65,29 @@ static void *opcode_targets[256] = {
|
||||||
&&TARGET_FOR_ITER_TUPLE,
|
&&TARGET_FOR_ITER_TUPLE,
|
||||||
&&TARGET_FOR_ITER_RANGE,
|
&&TARGET_FOR_ITER_RANGE,
|
||||||
&&TARGET_FOR_ITER_GEN,
|
&&TARGET_FOR_ITER_GEN,
|
||||||
|
&&TARGET_LOAD_SUPER_ATTR_ATTR,
|
||||||
&&TARGET_LOAD_SUPER_ATTR_METHOD,
|
&&TARGET_LOAD_SUPER_ATTR_METHOD,
|
||||||
&&TARGET_LOAD_ATTR_CLASS,
|
|
||||||
&&TARGET_GET_ITER,
|
&&TARGET_GET_ITER,
|
||||||
&&TARGET_GET_YIELD_FROM_ITER,
|
&&TARGET_GET_YIELD_FROM_ITER,
|
||||||
&&TARGET_LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
|
&&TARGET_LOAD_ATTR_CLASS,
|
||||||
&&TARGET_LOAD_BUILD_CLASS,
|
&&TARGET_LOAD_BUILD_CLASS,
|
||||||
|
&&TARGET_LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
|
||||||
&&TARGET_LOAD_ATTR_INSTANCE_VALUE,
|
&&TARGET_LOAD_ATTR_INSTANCE_VALUE,
|
||||||
&&TARGET_LOAD_ATTR_MODULE,
|
|
||||||
&&TARGET_LOAD_ASSERTION_ERROR,
|
&&TARGET_LOAD_ASSERTION_ERROR,
|
||||||
&&TARGET_RETURN_GENERATOR,
|
&&TARGET_RETURN_GENERATOR,
|
||||||
|
&&TARGET_LOAD_ATTR_MODULE,
|
||||||
&&TARGET_LOAD_ATTR_PROPERTY,
|
&&TARGET_LOAD_ATTR_PROPERTY,
|
||||||
&&TARGET_LOAD_ATTR_SLOT,
|
&&TARGET_LOAD_ATTR_SLOT,
|
||||||
&&TARGET_LOAD_ATTR_WITH_HINT,
|
&&TARGET_LOAD_ATTR_WITH_HINT,
|
||||||
&&TARGET_LOAD_ATTR_METHOD_LAZY_DICT,
|
&&TARGET_LOAD_ATTR_METHOD_LAZY_DICT,
|
||||||
&&TARGET_LOAD_ATTR_METHOD_NO_DICT,
|
&&TARGET_LOAD_ATTR_METHOD_NO_DICT,
|
||||||
&&TARGET_LOAD_ATTR_METHOD_WITH_VALUES,
|
&&TARGET_LOAD_ATTR_METHOD_WITH_VALUES,
|
||||||
&&TARGET_LOAD_CONST__LOAD_FAST,
|
|
||||||
&&TARGET_RETURN_VALUE,
|
&&TARGET_RETURN_VALUE,
|
||||||
&&TARGET_LOAD_FAST__LOAD_CONST,
|
&&TARGET_LOAD_CONST__LOAD_FAST,
|
||||||
&&TARGET_SETUP_ANNOTATIONS,
|
&&TARGET_SETUP_ANNOTATIONS,
|
||||||
|
&&TARGET_LOAD_FAST__LOAD_CONST,
|
||||||
&&TARGET_LOAD_FAST__LOAD_FAST,
|
&&TARGET_LOAD_FAST__LOAD_FAST,
|
||||||
&&TARGET_LOAD_GLOBAL_BUILTIN,
|
&&TARGET_LOAD_GLOBAL_BUILTIN,
|
||||||
&&TARGET_LOAD_GLOBAL_MODULE,
|
|
||||||
&&TARGET_POP_EXCEPT,
|
&&TARGET_POP_EXCEPT,
|
||||||
&&TARGET_STORE_NAME,
|
&&TARGET_STORE_NAME,
|
||||||
&&TARGET_DELETE_NAME,
|
&&TARGET_DELETE_NAME,
|
||||||
|
@ -110,9 +110,9 @@ static void *opcode_targets[256] = {
|
||||||
&&TARGET_IMPORT_NAME,
|
&&TARGET_IMPORT_NAME,
|
||||||
&&TARGET_IMPORT_FROM,
|
&&TARGET_IMPORT_FROM,
|
||||||
&&TARGET_JUMP_FORWARD,
|
&&TARGET_JUMP_FORWARD,
|
||||||
|
&&TARGET_LOAD_GLOBAL_MODULE,
|
||||||
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
|
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
|
||||||
&&TARGET_STORE_ATTR_SLOT,
|
&&TARGET_STORE_ATTR_SLOT,
|
||||||
&&TARGET_STORE_ATTR_WITH_HINT,
|
|
||||||
&&TARGET_POP_JUMP_IF_FALSE,
|
&&TARGET_POP_JUMP_IF_FALSE,
|
||||||
&&TARGET_POP_JUMP_IF_TRUE,
|
&&TARGET_POP_JUMP_IF_TRUE,
|
||||||
&&TARGET_LOAD_GLOBAL,
|
&&TARGET_LOAD_GLOBAL,
|
||||||
|
@ -152,24 +152,24 @@ static void *opcode_targets[256] = {
|
||||||
&&TARGET_YIELD_VALUE,
|
&&TARGET_YIELD_VALUE,
|
||||||
&&TARGET_RESUME,
|
&&TARGET_RESUME,
|
||||||
&&TARGET_MATCH_CLASS,
|
&&TARGET_MATCH_CLASS,
|
||||||
|
&&TARGET_STORE_ATTR_WITH_HINT,
|
||||||
&&TARGET_STORE_FAST__LOAD_FAST,
|
&&TARGET_STORE_FAST__LOAD_FAST,
|
||||||
&&TARGET_STORE_FAST__STORE_FAST,
|
|
||||||
&&TARGET_FORMAT_VALUE,
|
&&TARGET_FORMAT_VALUE,
|
||||||
&&TARGET_BUILD_CONST_KEY_MAP,
|
&&TARGET_BUILD_CONST_KEY_MAP,
|
||||||
&&TARGET_BUILD_STRING,
|
&&TARGET_BUILD_STRING,
|
||||||
|
&&TARGET_STORE_FAST__STORE_FAST,
|
||||||
&&TARGET_STORE_SUBSCR_DICT,
|
&&TARGET_STORE_SUBSCR_DICT,
|
||||||
&&TARGET_STORE_SUBSCR_LIST_INT,
|
&&TARGET_STORE_SUBSCR_LIST_INT,
|
||||||
&&TARGET_UNPACK_SEQUENCE_LIST,
|
&&TARGET_UNPACK_SEQUENCE_LIST,
|
||||||
&&TARGET_UNPACK_SEQUENCE_TUPLE,
|
|
||||||
&&TARGET_LIST_EXTEND,
|
&&TARGET_LIST_EXTEND,
|
||||||
&&TARGET_SET_UPDATE,
|
&&TARGET_SET_UPDATE,
|
||||||
&&TARGET_DICT_MERGE,
|
&&TARGET_DICT_MERGE,
|
||||||
&&TARGET_DICT_UPDATE,
|
&&TARGET_DICT_UPDATE,
|
||||||
|
&&TARGET_UNPACK_SEQUENCE_TUPLE,
|
||||||
&&TARGET_UNPACK_SEQUENCE_TWO_TUPLE,
|
&&TARGET_UNPACK_SEQUENCE_TWO_TUPLE,
|
||||||
&&TARGET_SEND_GEN,
|
&&TARGET_SEND_GEN,
|
||||||
&&_unknown_opcode,
|
&&_unknown_opcode,
|
||||||
&&_unknown_opcode,
|
&&_unknown_opcode,
|
||||||
&&_unknown_opcode,
|
|
||||||
&&TARGET_CALL,
|
&&TARGET_CALL,
|
||||||
&&TARGET_KW_NAMES,
|
&&TARGET_KW_NAMES,
|
||||||
&&TARGET_CALL_INTRINSIC_1,
|
&&TARGET_CALL_INTRINSIC_1,
|
||||||
|
|
|
@ -323,11 +323,8 @@ _PyCode_Quicken(PyCodeObject *code)
|
||||||
|
|
||||||
/* Super */
|
/* Super */
|
||||||
|
|
||||||
#define SPEC_FAIL_SUPER_NOT_LOAD_METHOD 9
|
#define SPEC_FAIL_SUPER_BAD_CLASS 9
|
||||||
#define SPEC_FAIL_SUPER_BAD_CLASS 10
|
#define SPEC_FAIL_SUPER_SHADOWED 10
|
||||||
#define SPEC_FAIL_SUPER_SHADOWED 11
|
|
||||||
#define SPEC_FAIL_SUPER_NOT_METHOD 12
|
|
||||||
#define SPEC_FAIL_SUPER_ERROR_OR_NOT_FOUND 13
|
|
||||||
|
|
||||||
/* Attributes */
|
/* Attributes */
|
||||||
|
|
||||||
|
@ -516,15 +513,10 @@ specialize_module_load_attr(
|
||||||
/* Attribute specialization */
|
/* Attribute specialization */
|
||||||
|
|
||||||
void
|
void
|
||||||
_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self,
|
_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, _Py_CODEUNIT *instr, int load_method) {
|
||||||
_Py_CODEUNIT *instr, PyObject *name, int load_method) {
|
|
||||||
assert(ENABLE_SPECIALIZATION);
|
assert(ENABLE_SPECIALIZATION);
|
||||||
assert(_PyOpcode_Caches[LOAD_SUPER_ATTR] == INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR);
|
assert(_PyOpcode_Caches[LOAD_SUPER_ATTR] == INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR);
|
||||||
_PySuperAttrCache *cache = (_PySuperAttrCache *)(instr + 1);
|
_PySuperAttrCache *cache = (_PySuperAttrCache *)(instr + 1);
|
||||||
if (!load_method) {
|
|
||||||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_NOT_LOAD_METHOD);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
if (global_super != (PyObject *)&PySuper_Type) {
|
if (global_super != (PyObject *)&PySuper_Type) {
|
||||||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_SHADOWED);
|
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_SHADOWED);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -533,23 +525,8 @@ _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *se
|
||||||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_BAD_CLASS);
|
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_BAD_CLASS);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
PyTypeObject *tp = (PyTypeObject *)cls;
|
instr->op.code = load_method ? LOAD_SUPER_ATTR_METHOD : LOAD_SUPER_ATTR_ATTR;
|
||||||
PyObject *res = _PySuper_LookupDescr(tp, self, name);
|
goto success;
|
||||||
if (res == NULL) {
|
|
||||||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_ERROR_OR_NOT_FOUND);
|
|
||||||
PyErr_Clear();
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
if (_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
|
|
||||||
write_u32(cache->class_version, tp->tp_version_tag);
|
|
||||||
write_u32(cache->self_type_version, Py_TYPE(self)->tp_version_tag);
|
|
||||||
write_obj(cache->method, res); // borrowed
|
|
||||||
instr->op.code = LOAD_SUPER_ATTR_METHOD;
|
|
||||||
Py_DECREF(res);
|
|
||||||
goto success;
|
|
||||||
}
|
|
||||||
Py_DECREF(res);
|
|
||||||
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_NOT_METHOD);
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
STAT_INC(LOAD_SUPER_ATTR, failure);
|
STAT_INC(LOAD_SUPER_ATTR, failure);
|
||||||
|
|
|
@ -226,11 +226,13 @@ def pretty(defname):
|
||||||
def kind_to_text(kind, defines, opname):
|
def kind_to_text(kind, defines, opname):
|
||||||
if kind <= 8:
|
if kind <= 8:
|
||||||
return pretty(defines[kind][0])
|
return pretty(defines[kind][0])
|
||||||
if opname.endswith("ATTR"):
|
if opname == "LOAD_SUPER_ATTR":
|
||||||
|
opname = "SUPER"
|
||||||
|
elif opname.endswith("ATTR"):
|
||||||
opname = "ATTR"
|
opname = "ATTR"
|
||||||
if opname in ("FOR_ITER", "SEND"):
|
elif opname in ("FOR_ITER", "SEND"):
|
||||||
opname = "ITER"
|
opname = "ITER"
|
||||||
if opname.endswith("SUBSCR"):
|
elif opname.endswith("SUBSCR"):
|
||||||
opname = "SUBSCR"
|
opname = "SUBSCR"
|
||||||
for name in defines[kind]:
|
for name in defines[kind]:
|
||||||
if name.startswith(opname):
|
if name.startswith(opname):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue