mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +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
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue