mirror of
https://github.com/python/cpython.git
synced 2025-10-15 03:10:29 +00:00
GH-100288: Specialize LOAD_ATTR for simple class attributes. (#105990)
* Add two more specializations of LOAD_ATTR.
This commit is contained in:
parent
34c14147a2
commit
0c90e75610
10 changed files with 405 additions and 290 deletions
|
@ -1809,6 +1809,8 @@ dummy_func(
|
|||
LOAD_ATTR_METHOD_WITH_VALUES,
|
||||
LOAD_ATTR_METHOD_NO_DICT,
|
||||
LOAD_ATTR_METHOD_LAZY_DICT,
|
||||
LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES,
|
||||
LOAD_ATTR_NONDESCRIPTOR_NO_DICT,
|
||||
};
|
||||
|
||||
inst(LOAD_ATTR, (unused/9, owner -- res2 if (oparg & 1), res)) {
|
||||
|
@ -2657,7 +2659,8 @@ dummy_func(
|
|||
exc_info->exc_value = Py_NewRef(new_exc);
|
||||
}
|
||||
|
||||
inst(LOAD_ATTR_METHOD_WITH_VALUES, (unused/1, type_version/2, keys_version/2, descr/4, self -- res2 if (oparg & 1), res)) {
|
||||
inst(LOAD_ATTR_METHOD_WITH_VALUES, (unused/1, type_version/2, keys_version/2, descr/4, self -- res2 if (1), res)) {
|
||||
assert(oparg & 1);
|
||||
/* Cached method object */
|
||||
PyTypeObject *self_cls = Py_TYPE(self);
|
||||
assert(type_version != 0);
|
||||
|
@ -2673,10 +2676,10 @@ dummy_func(
|
|||
res2 = Py_NewRef(descr);
|
||||
assert(_PyType_HasFeature(Py_TYPE(res2), Py_TPFLAGS_METHOD_DESCRIPTOR));
|
||||
res = self;
|
||||
assert(oparg & 1);
|
||||
}
|
||||
|
||||
inst(LOAD_ATTR_METHOD_NO_DICT, (unused/1, type_version/2, unused/2, descr/4, self -- res2 if (oparg & 1), res)) {
|
||||
inst(LOAD_ATTR_METHOD_NO_DICT, (unused/1, type_version/2, unused/2, descr/4, self -- res2 if (1), res)) {
|
||||
assert(oparg & 1);
|
||||
PyTypeObject *self_cls = Py_TYPE(self);
|
||||
DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
|
||||
assert(self_cls->tp_dictoffset == 0);
|
||||
|
@ -2685,10 +2688,39 @@ dummy_func(
|
|||
assert(_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR));
|
||||
res2 = Py_NewRef(descr);
|
||||
res = self;
|
||||
assert(oparg & 1);
|
||||
}
|
||||
|
||||
inst(LOAD_ATTR_METHOD_LAZY_DICT, (unused/1, type_version/2, unused/2, descr/4, self -- res2 if (oparg & 1), res)) {
|
||||
inst(LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES, (unused/1, type_version/2, keys_version/2, descr/4, self -- res2 if (0), res)) {
|
||||
assert((oparg & 1) == 0);
|
||||
PyTypeObject *self_cls = Py_TYPE(self);
|
||||
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);
|
||||
PyHeapTypeObject *self_heap_type = (PyHeapTypeObject *)self_cls;
|
||||
DEOPT_IF(self_heap_type->ht_cached_keys->dk_version !=
|
||||
keys_version, LOAD_ATTR);
|
||||
STAT_INC(LOAD_ATTR, hit);
|
||||
assert(descr != NULL);
|
||||
DECREF_INPUTS();
|
||||
res = Py_NewRef(descr);
|
||||
}
|
||||
|
||||
inst(LOAD_ATTR_NONDESCRIPTOR_NO_DICT, (unused/1, type_version/2, unused/2, descr/4, self -- res2 if (0), res)) {
|
||||
assert((oparg & 1) == 0);
|
||||
PyTypeObject *self_cls = Py_TYPE(self);
|
||||
assert(type_version != 0);
|
||||
DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
|
||||
assert(self_cls->tp_dictoffset == 0);
|
||||
STAT_INC(LOAD_ATTR, hit);
|
||||
assert(descr != NULL);
|
||||
DECREF_INPUTS();
|
||||
res = Py_NewRef(descr);
|
||||
}
|
||||
|
||||
inst(LOAD_ATTR_METHOD_LAZY_DICT, (unused/1, type_version/2, unused/2, descr/4, self -- res2 if (1), res)) {
|
||||
assert(oparg & 1);
|
||||
PyTypeObject *self_cls = Py_TYPE(self);
|
||||
DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
|
||||
Py_ssize_t dictoffset = self_cls->tp_dictoffset;
|
||||
|
@ -2701,7 +2733,6 @@ dummy_func(
|
|||
assert(_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR));
|
||||
res2 = Py_NewRef(descr);
|
||||
res = self;
|
||||
assert(oparg & 1);
|
||||
}
|
||||
|
||||
inst(KW_NAMES, (--)) {
|
||||
|
|
70
Python/executor_cases.c.h
generated
70
Python/executor_cases.c.h
generated
|
@ -1738,7 +1738,7 @@
|
|||
PyObject *right = stack_pointer[-1];
|
||||
PyObject *left = stack_pointer[-2];
|
||||
PyObject *res;
|
||||
#line 2114 "Python/bytecodes.c"
|
||||
#line 2116 "Python/bytecodes.c"
|
||||
DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP);
|
||||
DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_OP);
|
||||
STAT_INC(COMPARE_OP, hit);
|
||||
|
@ -1760,7 +1760,7 @@
|
|||
PyObject *right = stack_pointer[-1];
|
||||
PyObject *left = stack_pointer[-2];
|
||||
PyObject *res;
|
||||
#line 2129 "Python/bytecodes.c"
|
||||
#line 2131 "Python/bytecodes.c"
|
||||
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP);
|
||||
DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP);
|
||||
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_OP);
|
||||
|
@ -1786,7 +1786,7 @@
|
|||
PyObject *right = stack_pointer[-1];
|
||||
PyObject *left = stack_pointer[-2];
|
||||
PyObject *res;
|
||||
#line 2148 "Python/bytecodes.c"
|
||||
#line 2150 "Python/bytecodes.c"
|
||||
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
|
||||
DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP);
|
||||
STAT_INC(COMPARE_OP, hit);
|
||||
|
@ -1809,12 +1809,12 @@
|
|||
PyObject *right = stack_pointer[-1];
|
||||
PyObject *left = stack_pointer[-2];
|
||||
PyObject *b;
|
||||
#line 2163 "Python/bytecodes.c"
|
||||
#line 2165 "Python/bytecodes.c"
|
||||
int res = Py_Is(left, right) ^ oparg;
|
||||
#line 1815 "Python/executor_cases.c.h"
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
#line 2165 "Python/bytecodes.c"
|
||||
#line 2167 "Python/bytecodes.c"
|
||||
b = res ? Py_True : Py_False;
|
||||
#line 1820 "Python/executor_cases.c.h"
|
||||
STACK_SHRINK(1);
|
||||
|
@ -1826,12 +1826,12 @@
|
|||
PyObject *right = stack_pointer[-1];
|
||||
PyObject *left = stack_pointer[-2];
|
||||
PyObject *b;
|
||||
#line 2169 "Python/bytecodes.c"
|
||||
#line 2171 "Python/bytecodes.c"
|
||||
int res = PySequence_Contains(right, left);
|
||||
#line 1832 "Python/executor_cases.c.h"
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
#line 2171 "Python/bytecodes.c"
|
||||
#line 2173 "Python/bytecodes.c"
|
||||
if (res < 0) goto pop_2_error;
|
||||
b = (res ^ oparg) ? Py_True : Py_False;
|
||||
#line 1838 "Python/executor_cases.c.h"
|
||||
|
@ -1845,12 +1845,12 @@
|
|||
PyObject *exc_value = stack_pointer[-2];
|
||||
PyObject *rest;
|
||||
PyObject *match;
|
||||
#line 2176 "Python/bytecodes.c"
|
||||
#line 2178 "Python/bytecodes.c"
|
||||
if (check_except_star_type_valid(tstate, match_type) < 0) {
|
||||
#line 1851 "Python/executor_cases.c.h"
|
||||
Py_DECREF(exc_value);
|
||||
Py_DECREF(match_type);
|
||||
#line 2178 "Python/bytecodes.c"
|
||||
#line 2180 "Python/bytecodes.c"
|
||||
if (true) goto pop_2_error;
|
||||
}
|
||||
|
||||
|
@ -1861,7 +1861,7 @@
|
|||
#line 1862 "Python/executor_cases.c.h"
|
||||
Py_DECREF(exc_value);
|
||||
Py_DECREF(match_type);
|
||||
#line 2186 "Python/bytecodes.c"
|
||||
#line 2188 "Python/bytecodes.c"
|
||||
if (res < 0) goto pop_2_error;
|
||||
|
||||
assert((match == NULL) == (rest == NULL));
|
||||
|
@ -1880,19 +1880,19 @@
|
|||
PyObject *right = stack_pointer[-1];
|
||||
PyObject *left = stack_pointer[-2];
|
||||
PyObject *b;
|
||||
#line 2197 "Python/bytecodes.c"
|
||||
#line 2199 "Python/bytecodes.c"
|
||||
assert(PyExceptionInstance_Check(left));
|
||||
if (check_except_type_valid(tstate, right) < 0) {
|
||||
#line 1887 "Python/executor_cases.c.h"
|
||||
Py_DECREF(right);
|
||||
#line 2200 "Python/bytecodes.c"
|
||||
#line 2202 "Python/bytecodes.c"
|
||||
if (true) goto pop_1_error;
|
||||
}
|
||||
|
||||
int res = PyErr_GivenExceptionMatches(left, right);
|
||||
#line 1894 "Python/executor_cases.c.h"
|
||||
Py_DECREF(right);
|
||||
#line 2205 "Python/bytecodes.c"
|
||||
#line 2207 "Python/bytecodes.c"
|
||||
b = res ? Py_True : Py_False;
|
||||
#line 1898 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = b;
|
||||
|
@ -1902,7 +1902,7 @@
|
|||
case GET_LEN: {
|
||||
PyObject *obj = stack_pointer[-1];
|
||||
PyObject *len_o;
|
||||
#line 2309 "Python/bytecodes.c"
|
||||
#line 2311 "Python/bytecodes.c"
|
||||
// PUSH(len(TOS))
|
||||
Py_ssize_t len_i = PyObject_Length(obj);
|
||||
if (len_i < 0) goto error;
|
||||
|
@ -1919,7 +1919,7 @@
|
|||
PyObject *type = stack_pointer[-2];
|
||||
PyObject *subject = stack_pointer[-3];
|
||||
PyObject *attrs;
|
||||
#line 2317 "Python/bytecodes.c"
|
||||
#line 2319 "Python/bytecodes.c"
|
||||
// Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or
|
||||
// None on failure.
|
||||
assert(PyTuple_CheckExact(names));
|
||||
|
@ -1928,7 +1928,7 @@
|
|||
Py_DECREF(subject);
|
||||
Py_DECREF(type);
|
||||
Py_DECREF(names);
|
||||
#line 2322 "Python/bytecodes.c"
|
||||
#line 2324 "Python/bytecodes.c"
|
||||
if (attrs) {
|
||||
assert(PyTuple_CheckExact(attrs)); // Success!
|
||||
}
|
||||
|
@ -1945,7 +1945,7 @@
|
|||
case MATCH_MAPPING: {
|
||||
PyObject *subject = stack_pointer[-1];
|
||||
PyObject *res;
|
||||
#line 2332 "Python/bytecodes.c"
|
||||
#line 2334 "Python/bytecodes.c"
|
||||
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING;
|
||||
res = match ? Py_True : Py_False;
|
||||
#line 1952 "Python/executor_cases.c.h"
|
||||
|
@ -1957,7 +1957,7 @@
|
|||
case MATCH_SEQUENCE: {
|
||||
PyObject *subject = stack_pointer[-1];
|
||||
PyObject *res;
|
||||
#line 2337 "Python/bytecodes.c"
|
||||
#line 2339 "Python/bytecodes.c"
|
||||
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE;
|
||||
res = match ? Py_True : Py_False;
|
||||
#line 1964 "Python/executor_cases.c.h"
|
||||
|
@ -1970,7 +1970,7 @@
|
|||
PyObject *keys = stack_pointer[-1];
|
||||
PyObject *subject = stack_pointer[-2];
|
||||
PyObject *values_or_none;
|
||||
#line 2342 "Python/bytecodes.c"
|
||||
#line 2344 "Python/bytecodes.c"
|
||||
// On successful match, PUSH(values). Otherwise, PUSH(None).
|
||||
values_or_none = match_keys(tstate, subject, keys);
|
||||
if (values_or_none == NULL) goto error;
|
||||
|
@ -1983,12 +1983,12 @@
|
|||
case GET_ITER: {
|
||||
PyObject *iterable = stack_pointer[-1];
|
||||
PyObject *iter;
|
||||
#line 2348 "Python/bytecodes.c"
|
||||
#line 2350 "Python/bytecodes.c"
|
||||
/* before: [obj]; after [getiter(obj)] */
|
||||
iter = PyObject_GetIter(iterable);
|
||||
#line 1990 "Python/executor_cases.c.h"
|
||||
Py_DECREF(iterable);
|
||||
#line 2351 "Python/bytecodes.c"
|
||||
#line 2353 "Python/bytecodes.c"
|
||||
if (iter == NULL) goto pop_1_error;
|
||||
#line 1994 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = iter;
|
||||
|
@ -1998,7 +1998,7 @@
|
|||
case GET_YIELD_FROM_ITER: {
|
||||
PyObject *iterable = stack_pointer[-1];
|
||||
PyObject *iter;
|
||||
#line 2355 "Python/bytecodes.c"
|
||||
#line 2357 "Python/bytecodes.c"
|
||||
/* before: [obj]; after [getiter(obj)] */
|
||||
if (PyCoro_CheckExact(iterable)) {
|
||||
/* `iterable` is a coroutine */
|
||||
|
@ -2023,7 +2023,7 @@
|
|||
}
|
||||
#line 2025 "Python/executor_cases.c.h"
|
||||
Py_DECREF(iterable);
|
||||
#line 2378 "Python/bytecodes.c"
|
||||
#line 2380 "Python/bytecodes.c"
|
||||
}
|
||||
#line 2029 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = iter;
|
||||
|
@ -2035,7 +2035,7 @@
|
|||
PyObject *lasti = stack_pointer[-3];
|
||||
PyObject *exit_func = stack_pointer[-4];
|
||||
PyObject *res;
|
||||
#line 2610 "Python/bytecodes.c"
|
||||
#line 2612 "Python/bytecodes.c"
|
||||
/* At the top of the stack are 4 values:
|
||||
- val: TOP = exc_info()
|
||||
- unused: SECOND = previous exception
|
||||
|
@ -2065,7 +2065,7 @@
|
|||
case PUSH_EXC_INFO: {
|
||||
PyObject *new_exc = stack_pointer[-1];
|
||||
PyObject *prev_exc;
|
||||
#line 2649 "Python/bytecodes.c"
|
||||
#line 2651 "Python/bytecodes.c"
|
||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
||||
if (exc_info->exc_value != NULL) {
|
||||
prev_exc = exc_info->exc_value;
|
||||
|
@ -2084,7 +2084,7 @@
|
|||
|
||||
case EXIT_INIT_CHECK: {
|
||||
PyObject *should_be_none = stack_pointer[-1];
|
||||
#line 3019 "Python/bytecodes.c"
|
||||
#line 3050 "Python/bytecodes.c"
|
||||
assert(STACK_LEVEL() == 2);
|
||||
if (should_be_none != Py_None) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
@ -2100,7 +2100,7 @@
|
|||
case MAKE_FUNCTION: {
|
||||
PyObject *codeobj = stack_pointer[-1];
|
||||
PyObject *func;
|
||||
#line 3433 "Python/bytecodes.c"
|
||||
#line 3464 "Python/bytecodes.c"
|
||||
|
||||
PyFunctionObject *func_obj = (PyFunctionObject *)
|
||||
PyFunction_New(codeobj, GLOBALS());
|
||||
|
@ -2120,7 +2120,7 @@
|
|||
case SET_FUNCTION_ATTRIBUTE: {
|
||||
PyObject *func = stack_pointer[-1];
|
||||
PyObject *attr = stack_pointer[-2];
|
||||
#line 3447 "Python/bytecodes.c"
|
||||
#line 3478 "Python/bytecodes.c"
|
||||
assert(PyFunction_Check(func));
|
||||
PyFunctionObject *func_obj = (PyFunctionObject *)func;
|
||||
switch(oparg) {
|
||||
|
@ -2156,13 +2156,13 @@
|
|||
PyObject *stop = stack_pointer[-(1 + ((oparg == 3) ? 1 : 0))];
|
||||
PyObject *start = stack_pointer[-(2 + ((oparg == 3) ? 1 : 0))];
|
||||
PyObject *slice;
|
||||
#line 3497 "Python/bytecodes.c"
|
||||
#line 3528 "Python/bytecodes.c"
|
||||
slice = PySlice_New(start, stop, step);
|
||||
#line 2162 "Python/executor_cases.c.h"
|
||||
Py_DECREF(start);
|
||||
Py_DECREF(stop);
|
||||
Py_XDECREF(step);
|
||||
#line 3499 "Python/bytecodes.c"
|
||||
#line 3530 "Python/bytecodes.c"
|
||||
if (slice == NULL) { STACK_SHRINK(((oparg == 3) ? 1 : 0)); goto pop_2_error; }
|
||||
#line 2168 "Python/executor_cases.c.h"
|
||||
STACK_SHRINK(((oparg == 3) ? 1 : 0));
|
||||
|
@ -2174,7 +2174,7 @@
|
|||
case CONVERT_VALUE: {
|
||||
PyObject *value = stack_pointer[-1];
|
||||
PyObject *result;
|
||||
#line 3503 "Python/bytecodes.c"
|
||||
#line 3534 "Python/bytecodes.c"
|
||||
convertion_func_ptr conv_fn;
|
||||
assert(oparg >= FVC_STR && oparg <= FVC_ASCII);
|
||||
conv_fn = CONVERSION_FUNCTIONS[oparg];
|
||||
|
@ -2189,7 +2189,7 @@
|
|||
case FORMAT_SIMPLE: {
|
||||
PyObject *value = stack_pointer[-1];
|
||||
PyObject *res;
|
||||
#line 3512 "Python/bytecodes.c"
|
||||
#line 3543 "Python/bytecodes.c"
|
||||
/* If value is a unicode object, then we know the result
|
||||
* of format(value) is value itself. */
|
||||
if (!PyUnicode_CheckExact(value)) {
|
||||
|
@ -2209,7 +2209,7 @@
|
|||
PyObject *fmt_spec = stack_pointer[-1];
|
||||
PyObject *value = stack_pointer[-2];
|
||||
PyObject *res;
|
||||
#line 3525 "Python/bytecodes.c"
|
||||
#line 3556 "Python/bytecodes.c"
|
||||
res = PyObject_Format(value, fmt_spec);
|
||||
Py_DECREF(value);
|
||||
Py_DECREF(fmt_spec);
|
||||
|
@ -2223,7 +2223,7 @@
|
|||
case COPY: {
|
||||
PyObject *bottom = stack_pointer[-(1 + (oparg-1))];
|
||||
PyObject *top;
|
||||
#line 3532 "Python/bytecodes.c"
|
||||
#line 3563 "Python/bytecodes.c"
|
||||
assert(oparg > 0);
|
||||
top = Py_NewRef(bottom);
|
||||
#line 2230 "Python/executor_cases.c.h"
|
||||
|
@ -2266,7 +2266,7 @@
|
|||
case SWAP: {
|
||||
PyObject *top = stack_pointer[-1];
|
||||
PyObject *bottom = stack_pointer[-(2 + (oparg-2))];
|
||||
#line 3557 "Python/bytecodes.c"
|
||||
#line 3588 "Python/bytecodes.c"
|
||||
assert(oparg >= 2);
|
||||
#line 2272 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = bottom;
|
||||
|
|
398
Python/generated_cases.c.h
generated
398
Python/generated_cases.c.h
generated
File diff suppressed because it is too large
Load diff
16
Python/opcode_metadata.h
generated
16
Python/opcode_metadata.h
generated
|
@ -378,6 +378,10 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
|
|||
return 1;
|
||||
case LOAD_ATTR_METHOD_NO_DICT:
|
||||
return 1;
|
||||
case LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES:
|
||||
return 1;
|
||||
case LOAD_ATTR_NONDESCRIPTOR_NO_DICT:
|
||||
return 1;
|
||||
case LOAD_ATTR_METHOD_LAZY_DICT:
|
||||
return 1;
|
||||
case KW_NAMES:
|
||||
|
@ -815,11 +819,15 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
|||
case PUSH_EXC_INFO:
|
||||
return 2;
|
||||
case LOAD_ATTR_METHOD_WITH_VALUES:
|
||||
return ((oparg & 1) ? 1 : 0) + 1;
|
||||
return (1 ? 1 : 0) + 1;
|
||||
case LOAD_ATTR_METHOD_NO_DICT:
|
||||
return ((oparg & 1) ? 1 : 0) + 1;
|
||||
return (1 ? 1 : 0) + 1;
|
||||
case LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES:
|
||||
return (0 ? 1 : 0) + 1;
|
||||
case LOAD_ATTR_NONDESCRIPTOR_NO_DICT:
|
||||
return (0 ? 1 : 0) + 1;
|
||||
case LOAD_ATTR_METHOD_LAZY_DICT:
|
||||
return ((oparg & 1) ? 1 : 0) + 1;
|
||||
return (1 ? 1 : 0) + 1;
|
||||
case KW_NAMES:
|
||||
return 0;
|
||||
case INSTRUMENTED_CALL:
|
||||
|
@ -1120,6 +1128,8 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[512] = {
|
|||
[PUSH_EXC_INFO] = { true, INSTR_FMT_IX, 0 },
|
||||
[LOAD_ATTR_METHOD_WITH_VALUES] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||
[LOAD_ATTR_METHOD_NO_DICT] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||
[LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||
[LOAD_ATTR_NONDESCRIPTOR_NO_DICT] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||
[LOAD_ATTR_METHOD_LAZY_DICT] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||
[KW_NAMES] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_CONST_FLAG },
|
||||
[INSTRUMENTED_CALL] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||
|
|
36
Python/opcode_targets.h
generated
36
Python/opcode_targets.h
generated
|
@ -80,14 +80,14 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_LOAD_ATTR_METHOD_WITH_VALUES,
|
||||
&&TARGET_LOAD_ATTR_METHOD_NO_DICT,
|
||||
&&TARGET_LOAD_ATTR_METHOD_LAZY_DICT,
|
||||
&&TARGET_COMPARE_OP_FLOAT,
|
||||
&&TARGET_COMPARE_OP_INT,
|
||||
&&TARGET_LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES,
|
||||
&&TARGET_LOAD_ATTR_NONDESCRIPTOR_NO_DICT,
|
||||
&&TARGET_RETURN_VALUE,
|
||||
&&TARGET_COMPARE_OP_STR,
|
||||
&&TARGET_COMPARE_OP_FLOAT,
|
||||
&&TARGET_SETUP_ANNOTATIONS,
|
||||
&&TARGET_FOR_ITER_LIST,
|
||||
&&TARGET_COMPARE_OP_INT,
|
||||
&&TARGET_LOAD_LOCALS,
|
||||
&&TARGET_FOR_ITER_TUPLE,
|
||||
&&TARGET_COMPARE_OP_STR,
|
||||
&&TARGET_POP_EXCEPT,
|
||||
&&TARGET_STORE_NAME,
|
||||
&&TARGET_DELETE_NAME,
|
||||
|
@ -110,9 +110,9 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_IMPORT_NAME,
|
||||
&&TARGET_IMPORT_FROM,
|
||||
&&TARGET_JUMP_FORWARD,
|
||||
&&TARGET_FOR_ITER_LIST,
|
||||
&&TARGET_FOR_ITER_TUPLE,
|
||||
&&TARGET_FOR_ITER_RANGE,
|
||||
&&TARGET_FOR_ITER_GEN,
|
||||
&&TARGET_CALL_BOUND_METHOD_EXACT_ARGS,
|
||||
&&TARGET_POP_JUMP_IF_FALSE,
|
||||
&&TARGET_POP_JUMP_IF_TRUE,
|
||||
&&TARGET_LOAD_GLOBAL,
|
||||
|
@ -131,11 +131,11 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_POP_JUMP_IF_NONE,
|
||||
&&TARGET_RAISE_VARARGS,
|
||||
&&TARGET_GET_AWAITABLE,
|
||||
&&TARGET_CALL_PY_EXACT_ARGS,
|
||||
&&TARGET_FOR_ITER_GEN,
|
||||
&&TARGET_BUILD_SLICE,
|
||||
&&TARGET_JUMP_BACKWARD_NO_INTERRUPT,
|
||||
&&TARGET_MAKE_CELL,
|
||||
&&TARGET_CALL_PY_WITH_DEFAULTS,
|
||||
&&TARGET_CALL_BOUND_METHOD_EXACT_ARGS,
|
||||
&&TARGET_LOAD_DEREF,
|
||||
&&TARGET_STORE_DEREF,
|
||||
&&TARGET_DELETE_DEREF,
|
||||
|
@ -147,26 +147,26 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_LIST_APPEND,
|
||||
&&TARGET_SET_ADD,
|
||||
&&TARGET_MAP_ADD,
|
||||
&&TARGET_CALL_NO_KW_TYPE_1,
|
||||
&&TARGET_CALL_PY_EXACT_ARGS,
|
||||
&&TARGET_COPY_FREE_VARS,
|
||||
&&TARGET_YIELD_VALUE,
|
||||
&&TARGET_RESUME,
|
||||
&&TARGET_MATCH_CLASS,
|
||||
&&TARGET_CALL_PY_WITH_DEFAULTS,
|
||||
&&TARGET_CALL_NO_KW_TYPE_1,
|
||||
&&TARGET_CALL_NO_KW_STR_1,
|
||||
&&TARGET_CALL_NO_KW_TUPLE_1,
|
||||
&&TARGET_CALL_BUILTIN_CLASS,
|
||||
&&TARGET_BUILD_CONST_KEY_MAP,
|
||||
&&TARGET_BUILD_STRING,
|
||||
&&TARGET_CONVERT_VALUE,
|
||||
&&TARGET_CALL_NO_KW_TUPLE_1,
|
||||
&&TARGET_CALL_BUILTIN_CLASS,
|
||||
&&TARGET_CALL_NO_KW_BUILTIN_O,
|
||||
&&TARGET_CALL_NO_KW_BUILTIN_FAST,
|
||||
&&TARGET_CALL_BUILTIN_FAST_WITH_KEYWORDS,
|
||||
&&TARGET_LIST_EXTEND,
|
||||
&&TARGET_SET_UPDATE,
|
||||
&&TARGET_DICT_MERGE,
|
||||
&&TARGET_DICT_UPDATE,
|
||||
&&TARGET_CALL_NO_KW_LEN,
|
||||
&&TARGET_CALL_NO_KW_ISINSTANCE,
|
||||
&&TARGET_CALL_NO_KW_BUILTIN_FAST,
|
||||
&&TARGET_CALL_BUILTIN_FAST_WITH_KEYWORDS,
|
||||
&&TARGET_LOAD_FAST_LOAD_FAST,
|
||||
&&TARGET_STORE_FAST_LOAD_FAST,
|
||||
&&TARGET_STORE_FAST_STORE_FAST,
|
||||
|
@ -177,6 +177,8 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_LOAD_FROM_DICT_OR_GLOBALS,
|
||||
&&TARGET_LOAD_FROM_DICT_OR_DEREF,
|
||||
&&TARGET_SET_FUNCTION_ATTRIBUTE,
|
||||
&&TARGET_CALL_NO_KW_LEN,
|
||||
&&TARGET_CALL_NO_KW_ISINSTANCE,
|
||||
&&TARGET_CALL_NO_KW_LIST_APPEND,
|
||||
&&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_O,
|
||||
&&TARGET_CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS,
|
||||
|
@ -227,8 +229,6 @@ static void *opcode_targets[256] = {
|
|||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&TARGET_ENTER_EXECUTOR,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
|
|
|
@ -711,8 +711,8 @@ specialize_dict_access(
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int specialize_attr_loadmethod(PyObject* owner, _Py_CODEUNIT* instr, PyObject* name,
|
||||
PyObject* descr, DescriptorClassification kind);
|
||||
static int specialize_attr_loadclassattr(PyObject* owner, _Py_CODEUNIT* instr, PyObject* name,
|
||||
PyObject* descr, DescriptorClassification kind, bool is_method);
|
||||
static int specialize_class_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject* name);
|
||||
|
||||
void
|
||||
|
@ -753,7 +753,7 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
|
|||
{
|
||||
int oparg = instr->op.arg;
|
||||
if (oparg & 1) {
|
||||
if (specialize_attr_loadmethod(owner, instr, name, descr, kind)) {
|
||||
if (specialize_attr_loadclassattr(owner, instr, name, descr, kind, true)) {
|
||||
goto success;
|
||||
}
|
||||
}
|
||||
|
@ -872,10 +872,14 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
|
|||
SPEC_FAIL_ATTR_NOT_MANAGED_DICT);
|
||||
goto fail;
|
||||
case NON_DESCRIPTOR:
|
||||
SPECIALIZATION_FAIL(LOAD_ATTR,
|
||||
(type->tp_flags & Py_TPFLAGS_MANAGED_DICT) ?
|
||||
SPEC_FAIL_ATTR_CLASS_ATTR_SIMPLE :
|
||||
SPEC_FAIL_ATTR_NOT_MANAGED_DICT);
|
||||
if ((instr->op.arg & 1) == 0) {
|
||||
if (specialize_attr_loadclassattr(owner, instr, name, descr, kind, false)) {
|
||||
goto success;
|
||||
}
|
||||
}
|
||||
else {
|
||||
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_CLASS_ATTR_SIMPLE);
|
||||
}
|
||||
goto fail;
|
||||
case ABSENT:
|
||||
if (specialize_dict_access(owner, instr, type, kind, name, LOAD_ATTR,
|
||||
|
@ -1064,13 +1068,14 @@ specialize_class_load_attr(PyObject *owner, _Py_CODEUNIT *instr,
|
|||
// can cause a significant drop in cache hits. A possible test is
|
||||
// python.exe -m test_typing test_re test_dis test_zlib.
|
||||
static int
|
||||
specialize_attr_loadmethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name,
|
||||
PyObject *descr, DescriptorClassification kind)
|
||||
specialize_attr_loadclassattr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name,
|
||||
PyObject *descr, DescriptorClassification kind, bool is_method)
|
||||
{
|
||||
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)(instr + 1);
|
||||
PyTypeObject *owner_cls = Py_TYPE(owner);
|
||||
|
||||
assert(kind == METHOD && descr != NULL);
|
||||
assert(descr != NULL);
|
||||
assert((is_method && kind == METHOD) || (!is_method && kind == NON_DESCRIPTOR));
|
||||
if (owner_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
|
||||
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(owner);
|
||||
PyDictKeysObject *keys = ((PyHeapTypeObject *)owner_cls)->ht_cached_keys;
|
||||
|
@ -1090,7 +1095,7 @@ PyObject *descr, DescriptorClassification kind)
|
|||
return 0;
|
||||
}
|
||||
write_u32(cache->keys_version, keys_version);
|
||||
instr->op.code = LOAD_ATTR_METHOD_WITH_VALUES;
|
||||
instr->op.code = is_method ? LOAD_ATTR_METHOD_WITH_VALUES : LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES;
|
||||
}
|
||||
else {
|
||||
Py_ssize_t dictoffset = owner_cls->tp_dictoffset;
|
||||
|
@ -1099,9 +1104,9 @@ PyObject *descr, DescriptorClassification kind)
|
|||
return 0;
|
||||
}
|
||||
if (dictoffset == 0) {
|
||||
instr->op.code = LOAD_ATTR_METHOD_NO_DICT;
|
||||
instr->op.code = is_method ? LOAD_ATTR_METHOD_NO_DICT : LOAD_ATTR_NONDESCRIPTOR_NO_DICT;
|
||||
}
|
||||
else {
|
||||
else if (is_method) {
|
||||
PyObject *dict = *(PyObject **) ((char *)owner + dictoffset);
|
||||
if (dict) {
|
||||
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_NOT_MANAGED_DICT);
|
||||
|
@ -1111,6 +1116,10 @@ PyObject *descr, DescriptorClassification kind)
|
|||
assert(owner_cls->tp_dictoffset <= INT16_MAX);
|
||||
instr->op.code = LOAD_ATTR_METHOD_LAZY_DICT;
|
||||
}
|
||||
else {
|
||||
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_CLASS_ATTR_SIMPLE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* `descr` is borrowed. This is safe for methods (even inherited ones from
|
||||
* super classes!) as long as tp_version_tag is validated for two main reasons:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue