GH-88691: Shrink the CALL caches (GH-103230)

This commit is contained in:
Brandt Bucher 2023-04-05 14:15:49 -07:00 committed by GitHub
parent aa5a9b5eb7
commit b4978ff872
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 285 additions and 281 deletions

View file

@ -3301,7 +3301,7 @@
TARGET(CALL) {
PREDICTED(CALL);
static_assert(INLINE_CACHE_ENTRIES_CALL == 4, "incorrect cache size");
static_assert(INLINE_CACHE_ENTRIES_CALL == 3, "incorrect cache size");
PyObject **args = (stack_pointer - oparg);
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
@ -3382,7 +3382,7 @@
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3442,7 +3442,6 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
uint32_t func_version = read_u32(&next_instr[1].cache);
uint16_t min_args = read_u16(&next_instr[3].cache);
#line 2469 "Python/bytecodes.c"
assert(kwnames == NULL);
DEOPT_IF(tstate->interp->eval_frame, CALL);
@ -3457,6 +3456,11 @@
PyFunctionObject *func = (PyFunctionObject *)callable;
DEOPT_IF(func->func_version != func_version, CALL);
PyCodeObject *code = (PyCodeObject *)func->func_code;
assert(func->func_defaults);
assert(PyTuple_CheckExact(func->func_defaults));
int defcount = (int)PyTuple_GET_SIZE(func->func_defaults);
assert(defcount <= code->co_argcount);
int min_args = code->co_argcount - defcount;
DEOPT_IF(argcount > code->co_argcount, CALL);
DEOPT_IF(argcount < min_args, CALL);
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
@ -3473,7 +3477,7 @@
STACK_SHRINK(oparg + 2);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
DISPATCH_INLINED(new_frame);
#line 3477 "Python/generated_cases.c.h"
#line 3481 "Python/generated_cases.c.h"
}
TARGET(CALL_NO_KW_TYPE_1) {
@ -3481,7 +3485,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *null = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2501 "Python/bytecodes.c"
#line 2506 "Python/bytecodes.c"
assert(kwnames == NULL);
assert(cframe.use_tracing == 0);
assert(oparg == 1);
@ -3492,11 +3496,11 @@
res = Py_NewRef(Py_TYPE(obj));
Py_DECREF(obj);
Py_DECREF(&PyType_Type); // I.e., callable
#line 3496 "Python/generated_cases.c.h"
#line 3500 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
DISPATCH();
}
@ -3505,7 +3509,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *null = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2514 "Python/bytecodes.c"
#line 2519 "Python/bytecodes.c"
assert(kwnames == NULL);
assert(cframe.use_tracing == 0);
assert(oparg == 1);
@ -3517,11 +3521,11 @@
Py_DECREF(arg);
Py_DECREF(&PyUnicode_Type); // I.e., callable
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3521 "Python/generated_cases.c.h"
#line 3525 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3531,7 +3535,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *null = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2529 "Python/bytecodes.c"
#line 2534 "Python/bytecodes.c"
assert(kwnames == NULL);
assert(oparg == 1);
DEOPT_IF(null != NULL, CALL);
@ -3542,11 +3546,11 @@
Py_DECREF(arg);
Py_DECREF(&PyTuple_Type); // I.e., tuple
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3546 "Python/generated_cases.c.h"
#line 3550 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3556,7 +3560,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2543 "Python/bytecodes.c"
#line 2548 "Python/bytecodes.c"
int is_meth = method != NULL;
int total_args = oparg;
if (is_meth) {
@ -3578,11 +3582,11 @@
}
Py_DECREF(tp);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3582 "Python/generated_cases.c.h"
#line 3586 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3592,7 +3596,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2568 "Python/bytecodes.c"
#line 2573 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
/* Builtin METH_O functions */
assert(kwnames == NULL);
@ -3621,11 +3625,11 @@
Py_DECREF(arg);
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3625 "Python/generated_cases.c.h"
#line 3629 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3635,7 +3639,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2600 "Python/bytecodes.c"
#line 2605 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
/* Builtin METH_FASTCALL functions, without keywords */
assert(kwnames == NULL);
@ -3668,11 +3672,11 @@
'invalid'). In those cases an exception is set, so we must
handle it.
*/
#line 3672 "Python/generated_cases.c.h"
#line 3676 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3682,7 +3686,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2636 "Python/bytecodes.c"
#line 2641 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
/* Builtin METH_FASTCALL | METH_KEYWORDS functions */
int is_meth = method != NULL;
@ -3715,11 +3719,11 @@
}
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3719 "Python/generated_cases.c.h"
#line 3723 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3729,7 +3733,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2672 "Python/bytecodes.c"
#line 2677 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
assert(kwnames == NULL);
/* len(o) */
@ -3755,11 +3759,11 @@
Py_DECREF(callable);
Py_DECREF(arg);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3759 "Python/generated_cases.c.h"
#line 3763 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
DISPATCH();
}
@ -3768,7 +3772,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2700 "Python/bytecodes.c"
#line 2705 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
assert(kwnames == NULL);
/* isinstance(o, o2) */
@ -3796,11 +3800,11 @@
Py_DECREF(cls);
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3800 "Python/generated_cases.c.h"
#line 3804 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
DISPATCH();
}
@ -3808,7 +3812,7 @@
PyObject **args = (stack_pointer - oparg);
PyObject *self = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
#line 2731 "Python/bytecodes.c"
#line 2736 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
assert(kwnames == NULL);
assert(oparg == 1);
@ -3827,14 +3831,14 @@
JUMPBY(INLINE_CACHE_ENTRIES_CALL + 1);
assert(next_instr[-1].op.code == POP_TOP);
DISPATCH();
#line 3831 "Python/generated_cases.c.h"
#line 3835 "Python/generated_cases.c.h"
}
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
PyObject **args = (stack_pointer - oparg);
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2752 "Python/bytecodes.c"
#line 2757 "Python/bytecodes.c"
assert(kwnames == NULL);
int is_meth = method != NULL;
int total_args = oparg;
@ -3865,11 +3869,11 @@
Py_DECREF(arg);
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3869 "Python/generated_cases.c.h"
#line 3873 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3878,7 +3882,7 @@
PyObject **args = (stack_pointer - oparg);
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2786 "Python/bytecodes.c"
#line 2791 "Python/bytecodes.c"
int is_meth = method != NULL;
int total_args = oparg;
if (is_meth) {
@ -3907,11 +3911,11 @@
}
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3911 "Python/generated_cases.c.h"
#line 3915 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3920,7 +3924,7 @@
PyObject **args = (stack_pointer - oparg);
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2818 "Python/bytecodes.c"
#line 2823 "Python/bytecodes.c"
assert(kwnames == NULL);
assert(oparg == 0 || oparg == 1);
int is_meth = method != NULL;
@ -3949,11 +3953,11 @@
Py_DECREF(self);
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3953 "Python/generated_cases.c.h"
#line 3957 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -3962,7 +3966,7 @@
PyObject **args = (stack_pointer - oparg);
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
#line 2850 "Python/bytecodes.c"
#line 2855 "Python/bytecodes.c"
assert(kwnames == NULL);
int is_meth = method != NULL;
int total_args = oparg;
@ -3990,11 +3994,11 @@
}
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
#line 3994 "Python/generated_cases.c.h"
#line 3998 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
next_instr += 3;
CHECK_EVAL_BREAKER();
DISPATCH();
}
@ -4005,7 +4009,7 @@
PyObject *callargs = stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))];
PyObject *func = stack_pointer[-(2 + ((oparg & 1) ? 1 : 0))];
PyObject *result;
#line 2881 "Python/bytecodes.c"
#line 2886 "Python/bytecodes.c"
if (oparg & 1) {
// DICT_MERGE is called before this opcode if there are kwargs.
// It converts all dict subtypes in kwargs into regular dicts.
@ -4024,15 +4028,15 @@
assert(PyTuple_CheckExact(callargs));
result = do_call_core(tstate, func, callargs, kwargs, cframe.use_tracing);
#line 4028 "Python/generated_cases.c.h"
#line 4032 "Python/generated_cases.c.h"
Py_DECREF(func);
Py_DECREF(callargs);
Py_XDECREF(kwargs);
#line 2900 "Python/bytecodes.c"
#line 2905 "Python/bytecodes.c"
assert(PEEK(3 + (oparg & 1)) == NULL);
if (result == NULL) { STACK_SHRINK(((oparg & 1) ? 1 : 0)); goto pop_3_error; }
#line 4036 "Python/generated_cases.c.h"
#line 4040 "Python/generated_cases.c.h"
STACK_SHRINK(((oparg & 1) ? 1 : 0));
STACK_SHRINK(2);
stack_pointer[-1] = result;
@ -4047,7 +4051,7 @@
PyObject *kwdefaults = (oparg & 0x02) ? stack_pointer[-(1 + ((oparg & 0x08) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0))] : NULL;
PyObject *defaults = (oparg & 0x01) ? stack_pointer[-(1 + ((oparg & 0x08) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x01) ? 1 : 0))] : NULL;
PyObject *func;
#line 2911 "Python/bytecodes.c"
#line 2916 "Python/bytecodes.c"
PyFunctionObject *func_obj = (PyFunctionObject *)
PyFunction_New(codeobj, GLOBALS());
@ -4076,14 +4080,14 @@
func_obj->func_version = ((PyCodeObject *)codeobj)->co_version;
func = (PyObject *)func_obj;
#line 4080 "Python/generated_cases.c.h"
#line 4084 "Python/generated_cases.c.h"
STACK_SHRINK(((oparg & 0x01) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x08) ? 1 : 0));
stack_pointer[-1] = func;
DISPATCH();
}
TARGET(RETURN_GENERATOR) {
#line 2942 "Python/bytecodes.c"
#line 2947 "Python/bytecodes.c"
assert(PyFunction_Check(frame->f_funcobj));
PyFunctionObject *func = (PyFunctionObject *)frame->f_funcobj;
PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(func);
@ -4104,7 +4108,7 @@
frame = cframe.current_frame = prev;
_PyFrame_StackPush(frame, (PyObject *)gen);
goto resume_frame;
#line 4108 "Python/generated_cases.c.h"
#line 4112 "Python/generated_cases.c.h"
}
TARGET(BUILD_SLICE) {
@ -4112,15 +4116,15 @@
PyObject *stop = stack_pointer[-(1 + ((oparg == 3) ? 1 : 0))];
PyObject *start = stack_pointer[-(2 + ((oparg == 3) ? 1 : 0))];
PyObject *slice;
#line 2965 "Python/bytecodes.c"
#line 2970 "Python/bytecodes.c"
slice = PySlice_New(start, stop, step);
#line 4118 "Python/generated_cases.c.h"
#line 4122 "Python/generated_cases.c.h"
Py_DECREF(start);
Py_DECREF(stop);
Py_XDECREF(step);
#line 2967 "Python/bytecodes.c"
#line 2972 "Python/bytecodes.c"
if (slice == NULL) { STACK_SHRINK(((oparg == 3) ? 1 : 0)); goto pop_2_error; }
#line 4124 "Python/generated_cases.c.h"
#line 4128 "Python/generated_cases.c.h"
STACK_SHRINK(((oparg == 3) ? 1 : 0));
STACK_SHRINK(1);
stack_pointer[-1] = slice;
@ -4131,7 +4135,7 @@
PyObject *fmt_spec = ((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? stack_pointer[-((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0))] : NULL;
PyObject *value = stack_pointer[-(1 + (((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0))];
PyObject *result;
#line 2971 "Python/bytecodes.c"
#line 2976 "Python/bytecodes.c"
/* Handles f-string value formatting. */
PyObject *(*conv_fn)(PyObject *);
int which_conversion = oparg & FVC_MASK;
@ -4166,7 +4170,7 @@
Py_DECREF(value);
Py_XDECREF(fmt_spec);
if (result == NULL) { STACK_SHRINK((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0)); goto pop_1_error; }
#line 4170 "Python/generated_cases.c.h"
#line 4174 "Python/generated_cases.c.h"
STACK_SHRINK((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0));
stack_pointer[-1] = result;
DISPATCH();
@ -4175,10 +4179,10 @@
TARGET(COPY) {
PyObject *bottom = stack_pointer[-(1 + (oparg-1))];
PyObject *top;
#line 3008 "Python/bytecodes.c"
#line 3013 "Python/bytecodes.c"
assert(oparg > 0);
top = Py_NewRef(bottom);
#line 4182 "Python/generated_cases.c.h"
#line 4186 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = top;
DISPATCH();
@ -4190,7 +4194,7 @@
PyObject *rhs = stack_pointer[-1];
PyObject *lhs = stack_pointer[-2];
PyObject *res;
#line 3013 "Python/bytecodes.c"
#line 3018 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@ -4206,12 +4210,12 @@
assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
assert(binary_ops[oparg]);
res = binary_ops[oparg](lhs, rhs);
#line 4210 "Python/generated_cases.c.h"
#line 4214 "Python/generated_cases.c.h"
Py_DECREF(lhs);
Py_DECREF(rhs);
#line 3029 "Python/bytecodes.c"
#line 3034 "Python/bytecodes.c"
if (res == NULL) goto pop_2_error;
#line 4215 "Python/generated_cases.c.h"
#line 4219 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 1;
@ -4221,27 +4225,27 @@
TARGET(SWAP) {
PyObject *top = stack_pointer[-1];
PyObject *bottom = stack_pointer[-(2 + (oparg-2))];
#line 3034 "Python/bytecodes.c"
#line 3039 "Python/bytecodes.c"
assert(oparg >= 2);
#line 4227 "Python/generated_cases.c.h"
#line 4231 "Python/generated_cases.c.h"
stack_pointer[-1] = bottom;
stack_pointer[-(2 + (oparg-2))] = top;
DISPATCH();
}
TARGET(EXTENDED_ARG) {
#line 3038 "Python/bytecodes.c"
#line 3043 "Python/bytecodes.c"
assert(oparg);
assert(cframe.use_tracing == 0);
opcode = next_instr->op.code;
oparg = oparg << 8 | next_instr->op.arg;
PRE_DISPATCH_GOTO();
DISPATCH_GOTO();
#line 4241 "Python/generated_cases.c.h"
#line 4245 "Python/generated_cases.c.h"
}
TARGET(CACHE) {
#line 3047 "Python/bytecodes.c"
#line 3052 "Python/bytecodes.c"
Py_UNREACHABLE();
#line 4247 "Python/generated_cases.c.h"
#line 4251 "Python/generated_cases.c.h"
}