mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
GH-90690: Remove PRECALL
instruction (GH-92925)
This commit is contained in:
parent
41638967a0
commit
e48ac9c100
14 changed files with 547 additions and 704 deletions
271
Python/ceval.c
271
Python/ceval.c
|
@ -1439,10 +1439,6 @@ eval_frame_handle_pending(PyThreadState *tstate)
|
|||
#define JUMPTO(x) (next_instr = first_instr + (x))
|
||||
#define JUMPBY(x) (next_instr += (x))
|
||||
|
||||
// Skip from a PRECALL over a CALL to the next instruction:
|
||||
#define SKIP_CALL() \
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL)
|
||||
|
||||
/* Get opcode and oparg from original instructions, not quickened form. */
|
||||
#define TRACING_NEXTOPARG() do { \
|
||||
NEXTOPARG(); \
|
||||
|
@ -1687,7 +1683,7 @@ pop_frame(PyThreadState *tstate, _PyInterpreterFrame *frame)
|
|||
return prev_frame;
|
||||
}
|
||||
|
||||
/* It is only between the PRECALL instruction and the following CALL,
|
||||
/* It is only between the KW_NAMES instruction and the following CALL,
|
||||
* that this has any meaning.
|
||||
*/
|
||||
typedef struct {
|
||||
|
@ -4541,7 +4537,7 @@ handle_eval_breaker:
|
|||
|
||||
TARGET(LOAD_METHOD) {
|
||||
PREDICTED(LOAD_METHOD);
|
||||
/* Designed to work in tandem with PRECALL. */
|
||||
/* Designed to work in tandem with CALL. */
|
||||
PyObject *name = GETITEM(names, oparg);
|
||||
PyObject *obj = TOP();
|
||||
PyObject *meth = NULL;
|
||||
|
@ -4566,7 +4562,7 @@ handle_eval_breaker:
|
|||
/* meth is not an unbound method (but a regular attr, or
|
||||
something was returned by a descriptor protocol). Set
|
||||
the second element of the stack to NULL, to signal
|
||||
PRECALL that it's not a method call.
|
||||
CALL that it's not a method call.
|
||||
|
||||
NULL | meth | arg1 | ... | argN
|
||||
*/
|
||||
|
@ -4710,57 +4706,11 @@ handle_eval_breaker:
|
|||
NOTRACE_DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL) {
|
||||
PREDICTED(PRECALL);
|
||||
/* Designed to work in tamdem with LOAD_METHOD. */
|
||||
/* `meth` is NULL when LOAD_METHOD thinks that it's not
|
||||
a method call.
|
||||
|
||||
Stack layout:
|
||||
|
||||
... | NULL | callable | arg1 | ... | argN
|
||||
^- TOP()
|
||||
^- (-oparg)
|
||||
^- (-oparg-1)
|
||||
^- (-oparg-2)
|
||||
|
||||
`callable` will be POPed by call_function.
|
||||
NULL will will be POPed manually later.
|
||||
If `meth` isn't NULL, it's a method call. Stack layout:
|
||||
|
||||
... | method | self | arg1 | ... | argN
|
||||
^- TOP()
|
||||
^- (-oparg)
|
||||
^- (-oparg-1)
|
||||
^- (-oparg-2)
|
||||
|
||||
`self` and `method` will be POPed by call_function.
|
||||
We'll be passing `oparg + 1` to call_function, to
|
||||
make it accept the `self` as a first argument.
|
||||
*/
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int nargs = oparg + is_meth;
|
||||
/* Move ownership of reference from stack to call_shape
|
||||
* and make sure that NULL is cleared from stack */
|
||||
PyObject *function = PEEK(nargs + 1);
|
||||
if (!is_meth && Py_TYPE(function) == &PyMethod_Type) {
|
||||
PyObject *meth = ((PyMethodObject *)function)->im_func;
|
||||
PyObject *self = ((PyMethodObject *)function)->im_self;
|
||||
Py_INCREF(meth);
|
||||
Py_INCREF(self);
|
||||
PEEK(oparg+1) = self;
|
||||
PEEK(oparg+2) = meth;
|
||||
Py_DECREF(function);
|
||||
}
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_BOUND_METHOD) {
|
||||
DEOPT_IF(is_method(stack_pointer, oparg), PRECALL);
|
||||
TARGET(CALL_BOUND_METHOD_EXACT_ARGS) {
|
||||
DEOPT_IF(is_method(stack_pointer, oparg), CALL);
|
||||
PyObject *function = PEEK(oparg + 1);
|
||||
DEOPT_IF(Py_TYPE(function) != &PyMethod_Type, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
DEOPT_IF(Py_TYPE(function) != &PyMethod_Type, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
PyObject *meth = ((PyMethodObject *)function)->im_func;
|
||||
PyObject *self = ((PyMethodObject *)function)->im_self;
|
||||
Py_INCREF(meth);
|
||||
|
@ -4768,17 +4718,7 @@ handle_eval_breaker:
|
|||
PEEK(oparg + 1) = self;
|
||||
PEEK(oparg + 2) = meth;
|
||||
Py_DECREF(function);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_PYFUNC) {
|
||||
int nargs = oparg + is_method(stack_pointer, oparg);
|
||||
PyObject *function = PEEK(nargs + 1);
|
||||
DEOPT_IF(Py_TYPE(function) != &PyFunction_Type, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL);
|
||||
DISPATCH();
|
||||
goto call_exact_args;
|
||||
}
|
||||
|
||||
TARGET(KW_NAMES) {
|
||||
|
@ -4789,11 +4729,22 @@ handle_eval_breaker:
|
|||
}
|
||||
|
||||
TARGET(CALL) {
|
||||
int is_meth;
|
||||
int total_args, is_meth;
|
||||
call_function:
|
||||
is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
PyObject *function = PEEK(total_args + 1);
|
||||
PyObject *function = PEEK(oparg + 1);
|
||||
if (!is_meth && Py_TYPE(function) == &PyMethod_Type) {
|
||||
PyObject *meth = ((PyMethodObject *)function)->im_func;
|
||||
PyObject *self = ((PyMethodObject *)function)->im_self;
|
||||
Py_INCREF(meth);
|
||||
Py_INCREF(self);
|
||||
PEEK(oparg+1) = self;
|
||||
PEEK(oparg+2) = meth;
|
||||
Py_DECREF(function);
|
||||
is_meth = 1;
|
||||
}
|
||||
total_args = oparg + is_meth;
|
||||
function = PEEK(total_args + 1);
|
||||
int positional_args = total_args - KWNAMES_LEN();
|
||||
// Check if the call can be inlined or not
|
||||
if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
|
||||
|
@ -4850,27 +4801,6 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_ADAPTIVE) {
|
||||
_PyPrecallCache *cache = (_PyPrecallCache *)next_instr;
|
||||
if (cache->counter == 0) {
|
||||
next_instr--;
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int nargs = oparg + is_meth;
|
||||
PyObject *callable = PEEK(nargs + 1);
|
||||
int err = _Py_Specialize_Precall(callable, next_instr, nargs,
|
||||
call_shape.kwnames, oparg);
|
||||
if (err < 0) {
|
||||
goto error;
|
||||
}
|
||||
NOTRACE_DISPATCH_SAME_OPARG();
|
||||
}
|
||||
else {
|
||||
STAT_INC(PRECALL, deferred);
|
||||
cache->counter--;
|
||||
JUMP_TO_INSTRUCTION(PRECALL);
|
||||
}
|
||||
}
|
||||
|
||||
TARGET(CALL_ADAPTIVE) {
|
||||
_PyCallCache *cache = (_PyCallCache *)next_instr;
|
||||
if (cache->counter == 0) {
|
||||
|
@ -4893,6 +4823,7 @@ handle_eval_breaker:
|
|||
}
|
||||
|
||||
TARGET(CALL_PY_EXACT_ARGS) {
|
||||
call_exact_args:
|
||||
assert(call_shape.kwnames == NULL);
|
||||
DEOPT_IF(tstate->interp->eval_frame, CALL);
|
||||
_PyCallCache *cache = (_PyCallCache *)next_instr;
|
||||
|
@ -4968,16 +4899,16 @@ handle_eval_breaker:
|
|||
goto start_frame;
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_TYPE_1) {
|
||||
TARGET(CALL_NO_KW_TYPE_1) {
|
||||
assert(call_shape.kwnames == NULL);
|
||||
assert(cframe.use_tracing == 0);
|
||||
assert(oparg == 1);
|
||||
DEOPT_IF(is_method(stack_pointer, 1), PRECALL);
|
||||
DEOPT_IF(is_method(stack_pointer, 1), CALL);
|
||||
PyObject *obj = TOP();
|
||||
PyObject *callable = SECOND();
|
||||
DEOPT_IF(callable != (PyObject *)&PyType_Type, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(callable != (PyObject *)&PyType_Type, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
PyObject *res = Py_NewRef(Py_TYPE(obj));
|
||||
Py_DECREF(callable);
|
||||
Py_DECREF(obj);
|
||||
|
@ -4986,15 +4917,15 @@ handle_eval_breaker:
|
|||
NOTRACE_DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_STR_1) {
|
||||
TARGET(CALL_NO_KW_STR_1) {
|
||||
assert(call_shape.kwnames == NULL);
|
||||
assert(cframe.use_tracing == 0);
|
||||
assert(oparg == 1);
|
||||
DEOPT_IF(is_method(stack_pointer, 1), PRECALL);
|
||||
DEOPT_IF(is_method(stack_pointer, 1), CALL);
|
||||
PyObject *callable = PEEK(2);
|
||||
DEOPT_IF(callable != (PyObject *)&PyUnicode_Type, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(callable != (PyObject *)&PyUnicode_Type, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
PyObject *arg = TOP();
|
||||
PyObject *res = PyObject_Str(arg);
|
||||
Py_DECREF(arg);
|
||||
|
@ -5008,14 +4939,14 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_TUPLE_1) {
|
||||
TARGET(CALL_NO_KW_TUPLE_1) {
|
||||
assert(call_shape.kwnames == NULL);
|
||||
assert(oparg == 1);
|
||||
DEOPT_IF(is_method(stack_pointer, 1), PRECALL);
|
||||
DEOPT_IF(is_method(stack_pointer, 1), CALL);
|
||||
PyObject *callable = PEEK(2);
|
||||
DEOPT_IF(callable != (PyObject *)&PyTuple_Type, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(callable != (PyObject *)&PyTuple_Type, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
PyObject *arg = TOP();
|
||||
PyObject *res = PySequence_Tuple(arg);
|
||||
Py_DECREF(arg);
|
||||
|
@ -5029,16 +4960,16 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_BUILTIN_CLASS) {
|
||||
TARGET(CALL_BUILTIN_CLASS) {
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
int kwnames_len = KWNAMES_LEN();
|
||||
PyObject *callable = PEEK(total_args + 1);
|
||||
DEOPT_IF(!PyType_Check(callable), PRECALL);
|
||||
DEOPT_IF(!PyType_Check(callable), CALL);
|
||||
PyTypeObject *tp = (PyTypeObject *)callable;
|
||||
DEOPT_IF(tp->tp_vectorcall == NULL, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(tp->tp_vectorcall == NULL, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
STACK_SHRINK(total_args);
|
||||
PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer,
|
||||
total_args-kwnames_len, call_shape.kwnames);
|
||||
|
@ -5057,18 +4988,18 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_BUILTIN_O) {
|
||||
TARGET(CALL_NO_KW_BUILTIN_O) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
/* Builtin METH_O functions */
|
||||
assert(call_shape.kwnames == NULL);
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
DEOPT_IF(total_args != 1, PRECALL);
|
||||
DEOPT_IF(total_args != 1, CALL);
|
||||
PyObject *callable = PEEK(total_args + 1);
|
||||
DEOPT_IF(!PyCFunction_CheckExact(callable), PRECALL);
|
||||
DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_O, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
|
||||
DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_O, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
|
||||
// This is slower but CPython promises to check all non-vectorcall
|
||||
// function calls.
|
||||
|
@ -5091,18 +5022,18 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_BUILTIN_FAST) {
|
||||
TARGET(CALL_NO_KW_BUILTIN_FAST) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
/* Builtin METH_FASTCALL functions, without keywords */
|
||||
assert(call_shape.kwnames == NULL);
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
PyObject *callable = PEEK(total_args + 1);
|
||||
DEOPT_IF(!PyCFunction_CheckExact(callable), PRECALL);
|
||||
DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
|
||||
DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_FASTCALL,
|
||||
PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
|
||||
STACK_SHRINK(total_args);
|
||||
/* res = func(self, args, nargs) */
|
||||
|
@ -5131,17 +5062,17 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_BUILTIN_FAST_WITH_KEYWORDS) {
|
||||
TARGET(CALL_BUILTIN_FAST_WITH_KEYWORDS) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
/* Builtin METH_FASTCALL | METH_KEYWORDS functions */
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
PyObject *callable = PEEK(total_args + 1);
|
||||
DEOPT_IF(!PyCFunction_CheckExact(callable), PRECALL);
|
||||
DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
|
||||
DEOPT_IF(PyCFunction_GET_FLAGS(callable) !=
|
||||
(METH_FASTCALL | METH_KEYWORDS), PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
(METH_FASTCALL | METH_KEYWORDS), CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
STACK_SHRINK(total_args);
|
||||
/* res = func(self, args, nargs, kwnames) */
|
||||
_PyCFunctionFastWithKeywords cfunc =
|
||||
|
@ -5170,18 +5101,18 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_LEN) {
|
||||
TARGET(CALL_NO_KW_LEN) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
assert(call_shape.kwnames == NULL);
|
||||
/* len(o) */
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
DEOPT_IF(total_args != 1, PRECALL);
|
||||
DEOPT_IF(total_args != 1, CALL);
|
||||
PyObject *callable = PEEK(total_args + 1);
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
DEOPT_IF(callable != interp->callable_cache.len, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(callable != interp->callable_cache.len, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
PyObject *arg = TOP();
|
||||
Py_ssize_t len_i = PyObject_Length(arg);
|
||||
if (len_i < 0) {
|
||||
|
@ -5200,18 +5131,18 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_ISINSTANCE) {
|
||||
TARGET(CALL_NO_KW_ISINSTANCE) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
assert(call_shape.kwnames == NULL);
|
||||
/* isinstance(o, o2) */
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
PyObject *callable = PEEK(total_args + 1);
|
||||
DEOPT_IF(total_args != 2, PRECALL);
|
||||
DEOPT_IF(total_args != 2, CALL);
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
DEOPT_IF(callable != interp->callable_cache.isinstance, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(callable != interp->callable_cache.isinstance, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
PyObject *cls = POP();
|
||||
PyObject *inst = TOP();
|
||||
int retval = PyObject_IsInstance(inst, cls);
|
||||
|
@ -5233,18 +5164,18 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_LIST_APPEND) {
|
||||
TARGET(CALL_NO_KW_LIST_APPEND) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
assert(call_shape.kwnames == NULL);
|
||||
assert(oparg == 1);
|
||||
PyObject *callable = PEEK(3);
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
DEOPT_IF(callable != interp->callable_cache.list_append, PRECALL);
|
||||
DEOPT_IF(callable != interp->callable_cache.list_append, CALL);
|
||||
PyObject *list = SECOND();
|
||||
DEOPT_IF(!PyList_Check(list), PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
// PRECALL + CALL + POP_TOP
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1);
|
||||
DEOPT_IF(!PyList_Check(list), CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
// CALL + POP_TOP
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL + 1);
|
||||
assert(_Py_OPCODE(next_instr[-1]) == POP_TOP);
|
||||
PyObject *arg = POP();
|
||||
if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) {
|
||||
|
@ -5256,21 +5187,21 @@ handle_eval_breaker:
|
|||
NOTRACE_DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_METHOD_DESCRIPTOR_O) {
|
||||
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
|
||||
assert(call_shape.kwnames == NULL);
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
PyMethodDescrObject *callable =
|
||||
(PyMethodDescrObject *)PEEK(total_args + 1);
|
||||
DEOPT_IF(total_args != 2, PRECALL);
|
||||
DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), PRECALL);
|
||||
DEOPT_IF(total_args != 2, CALL);
|
||||
DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
|
||||
PyMethodDef *meth = callable->d_method;
|
||||
DEOPT_IF(meth->ml_flags != METH_O, PRECALL);
|
||||
DEOPT_IF(meth->ml_flags != METH_O, CALL);
|
||||
PyObject *arg = TOP();
|
||||
PyObject *self = SECOND();
|
||||
DEOPT_IF(!Py_IS_TYPE(self, callable->d_common.d_type), PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(!Py_IS_TYPE(self, callable->d_common.d_type), CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
PyCFunction cfunc = meth->ml_meth;
|
||||
// This is slower but CPython promises to check all non-vectorcall
|
||||
// function calls.
|
||||
|
@ -5292,19 +5223,19 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS) {
|
||||
TARGET(CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS) {
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
PyMethodDescrObject *callable =
|
||||
(PyMethodDescrObject *)PEEK(total_args + 1);
|
||||
DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), PRECALL);
|
||||
DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
|
||||
PyMethodDef *meth = callable->d_method;
|
||||
DEOPT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS), PRECALL);
|
||||
DEOPT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS), CALL);
|
||||
PyTypeObject *d_type = callable->d_common.d_type;
|
||||
PyObject *self = PEEK(total_args);
|
||||
DEOPT_IF(!Py_IS_TYPE(self, d_type), PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(!Py_IS_TYPE(self, d_type), CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
int nargs = total_args-1;
|
||||
STACK_SHRINK(nargs);
|
||||
_PyCFunctionFastWithKeywords cfunc =
|
||||
|
@ -5329,20 +5260,20 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_METHOD_DESCRIPTOR_NOARGS) {
|
||||
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS) {
|
||||
assert(call_shape.kwnames == NULL);
|
||||
assert(oparg == 0 || oparg == 1);
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
DEOPT_IF(total_args != 1, PRECALL);
|
||||
DEOPT_IF(total_args != 1, CALL);
|
||||
PyMethodDescrObject *callable = (PyMethodDescrObject *)SECOND();
|
||||
DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), PRECALL);
|
||||
DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
|
||||
PyMethodDef *meth = callable->d_method;
|
||||
PyObject *self = TOP();
|
||||
DEOPT_IF(!Py_IS_TYPE(self, callable->d_common.d_type), PRECALL);
|
||||
DEOPT_IF(meth->ml_flags != METH_NOARGS, PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(!Py_IS_TYPE(self, callable->d_common.d_type), CALL);
|
||||
DEOPT_IF(meth->ml_flags != METH_NOARGS, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
PyCFunction cfunc = meth->ml_meth;
|
||||
// This is slower but CPython promises to check all non-vectorcall
|
||||
// function calls.
|
||||
|
@ -5363,20 +5294,20 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRECALL_NO_KW_METHOD_DESCRIPTOR_FAST) {
|
||||
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_FAST) {
|
||||
assert(call_shape.kwnames == NULL);
|
||||
int is_meth = is_method(stack_pointer, oparg);
|
||||
int total_args = oparg + is_meth;
|
||||
PyMethodDescrObject *callable =
|
||||
(PyMethodDescrObject *)PEEK(total_args + 1);
|
||||
/* Builtin METH_FASTCALL methods, without keywords */
|
||||
DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), PRECALL);
|
||||
DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
|
||||
PyMethodDef *meth = callable->d_method;
|
||||
DEOPT_IF(meth->ml_flags != METH_FASTCALL, PRECALL);
|
||||
DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL);
|
||||
PyObject *self = PEEK(total_args);
|
||||
DEOPT_IF(!Py_IS_TYPE(self, callable->d_common.d_type), PRECALL);
|
||||
STAT_INC(PRECALL, hit);
|
||||
SKIP_CALL();
|
||||
DEOPT_IF(!Py_IS_TYPE(self, callable->d_common.d_type), CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
_PyCFunctionFast cfunc =
|
||||
(_PyCFunctionFast)(void(*)(void))meth->ml_meth;
|
||||
int nargs = total_args-1;
|
||||
|
|
|
@ -1116,12 +1116,10 @@ stack_effect(int opcode, int oparg, int jump)
|
|||
return -oparg;
|
||||
|
||||
/* Functions and calls */
|
||||
case PRECALL:
|
||||
return -oparg;
|
||||
case KW_NAMES:
|
||||
return 0;
|
||||
case CALL:
|
||||
return -1;
|
||||
return -1-oparg;
|
||||
|
||||
case CALL_FUNCTION_EX:
|
||||
return -2 - ((oparg & 0x01) != 0);
|
||||
|
@ -1947,7 +1945,6 @@ compiler_call_exit_with_nones(struct compiler *c) {
|
|||
ADDOP_LOAD_CONST(c, Py_None);
|
||||
ADDOP_LOAD_CONST(c, Py_None);
|
||||
ADDOP_LOAD_CONST(c, Py_None);
|
||||
ADDOP_I(c, PRECALL, 2);
|
||||
ADDOP_I(c, CALL, 2);
|
||||
return 1;
|
||||
}
|
||||
|
@ -2325,7 +2322,6 @@ compiler_apply_decorators(struct compiler *c, asdl_expr_seq* decos)
|
|||
int old_end_col_offset = c->u->u_end_col_offset;
|
||||
for (Py_ssize_t i = asdl_seq_LEN(decos) - 1; i > -1; i--) {
|
||||
SET_LOC(c, (expr_ty)asdl_seq_GET(decos, i));
|
||||
ADDOP_I(c, PRECALL, 0);
|
||||
ADDOP_I(c, CALL, 0);
|
||||
}
|
||||
c->u->u_lineno = old_lineno;
|
||||
|
@ -4002,7 +3998,6 @@ compiler_assert(struct compiler *c, stmt_ty s)
|
|||
ADDOP(c, LOAD_ASSERTION_ERROR);
|
||||
if (s->v.Assert.msg) {
|
||||
VISIT(c, expr, s->v.Assert.msg);
|
||||
ADDOP_I(c, PRECALL, 0);
|
||||
ADDOP_I(c, CALL, 0);
|
||||
}
|
||||
ADDOP_I(c, RAISE_VARARGS, 1);
|
||||
|
@ -4831,7 +4826,6 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
|
|||
return 0;
|
||||
};
|
||||
}
|
||||
ADDOP_I(c, PRECALL, argsl + kwdsl);
|
||||
ADDOP_I(c, CALL, argsl + kwdsl);
|
||||
c->u->u_lineno = old_lineno;
|
||||
return 1;
|
||||
|
@ -4897,7 +4891,6 @@ compiler_joined_str(struct compiler *c, expr_ty e)
|
|||
VISIT(c, expr, asdl_seq_GET(e->v.JoinedStr.values, i));
|
||||
ADDOP_I(c, LIST_APPEND, 1);
|
||||
}
|
||||
ADDOP_I(c, PRECALL, 1);
|
||||
ADDOP_I(c, CALL, 1);
|
||||
}
|
||||
else {
|
||||
|
@ -5071,7 +5064,6 @@ compiler_call_helper(struct compiler *c,
|
|||
return 0;
|
||||
};
|
||||
}
|
||||
ADDOP_I(c, PRECALL, n + nelts + nkwelts);
|
||||
ADDOP_I(c, CALL, n + nelts + nkwelts);
|
||||
return 1;
|
||||
|
||||
|
@ -5462,7 +5454,6 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
|
|||
ADDOP(c, GET_ITER);
|
||||
}
|
||||
|
||||
ADDOP_I(c, PRECALL, 0);
|
||||
ADDOP_I(c, CALL, 0);
|
||||
|
||||
if (is_async_generator && type != COMP_GENEXP) {
|
||||
|
|
104
Python/opcode_targets.h
generated
104
Python/opcode_targets.h
generated
|
@ -25,62 +25,62 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_CALL_PY_EXACT_ARGS,
|
||||
&&TARGET_CALL_PY_WITH_DEFAULTS,
|
||||
&&TARGET_BINARY_SUBSCR,
|
||||
&&TARGET_COMPARE_OP_ADAPTIVE,
|
||||
&&TARGET_COMPARE_OP_FLOAT_JUMP,
|
||||
&&TARGET_COMPARE_OP_INT_JUMP,
|
||||
&&TARGET_COMPARE_OP_STR_JUMP,
|
||||
&&TARGET_CALL_BOUND_METHOD_EXACT_ARGS,
|
||||
&&TARGET_CALL_BUILTIN_CLASS,
|
||||
&&TARGET_CALL_BUILTIN_FAST_WITH_KEYWORDS,
|
||||
&&TARGET_CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS,
|
||||
&&TARGET_GET_LEN,
|
||||
&&TARGET_MATCH_MAPPING,
|
||||
&&TARGET_MATCH_SEQUENCE,
|
||||
&&TARGET_MATCH_KEYS,
|
||||
&&TARGET_EXTENDED_ARG_QUICK,
|
||||
&&TARGET_CALL_NO_KW_BUILTIN_FAST,
|
||||
&&TARGET_PUSH_EXC_INFO,
|
||||
&&TARGET_CHECK_EXC_MATCH,
|
||||
&&TARGET_CHECK_EG_MATCH,
|
||||
&&TARGET_JUMP_BACKWARD_QUICK,
|
||||
&&TARGET_LOAD_ATTR_ADAPTIVE,
|
||||
&&TARGET_LOAD_ATTR_INSTANCE_VALUE,
|
||||
&&TARGET_LOAD_ATTR_MODULE,
|
||||
&&TARGET_LOAD_ATTR_SLOT,
|
||||
&&TARGET_LOAD_ATTR_WITH_HINT,
|
||||
&&TARGET_LOAD_CONST__LOAD_FAST,
|
||||
&&TARGET_LOAD_FAST__LOAD_CONST,
|
||||
&&TARGET_LOAD_FAST__LOAD_FAST,
|
||||
&&TARGET_LOAD_GLOBAL_ADAPTIVE,
|
||||
&&TARGET_LOAD_GLOBAL_BUILTIN,
|
||||
&&TARGET_CALL_NO_KW_BUILTIN_O,
|
||||
&&TARGET_CALL_NO_KW_ISINSTANCE,
|
||||
&&TARGET_CALL_NO_KW_LEN,
|
||||
&&TARGET_CALL_NO_KW_LIST_APPEND,
|
||||
&&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_FAST,
|
||||
&&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
|
||||
&&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_O,
|
||||
&&TARGET_CALL_NO_KW_STR_1,
|
||||
&&TARGET_CALL_NO_KW_TUPLE_1,
|
||||
&&TARGET_CALL_NO_KW_TYPE_1,
|
||||
&&TARGET_COMPARE_OP_ADAPTIVE,
|
||||
&&TARGET_WITH_EXCEPT_START,
|
||||
&&TARGET_GET_AITER,
|
||||
&&TARGET_GET_ANEXT,
|
||||
&&TARGET_BEFORE_ASYNC_WITH,
|
||||
&&TARGET_BEFORE_WITH,
|
||||
&&TARGET_END_ASYNC_FOR,
|
||||
&&TARGET_LOAD_GLOBAL_MODULE,
|
||||
&&TARGET_LOAD_METHOD_ADAPTIVE,
|
||||
&&TARGET_LOAD_METHOD_CLASS,
|
||||
&&TARGET_LOAD_METHOD_MODULE,
|
||||
&&TARGET_LOAD_METHOD_NO_DICT,
|
||||
&&TARGET_COMPARE_OP_FLOAT_JUMP,
|
||||
&&TARGET_COMPARE_OP_INT_JUMP,
|
||||
&&TARGET_COMPARE_OP_STR_JUMP,
|
||||
&&TARGET_EXTENDED_ARG_QUICK,
|
||||
&&TARGET_JUMP_BACKWARD_QUICK,
|
||||
&&TARGET_STORE_SUBSCR,
|
||||
&&TARGET_DELETE_SUBSCR,
|
||||
&&TARGET_LOAD_METHOD_WITH_DICT,
|
||||
&&TARGET_LOAD_METHOD_WITH_VALUES,
|
||||
&&TARGET_PRECALL_ADAPTIVE,
|
||||
&&TARGET_PRECALL_BOUND_METHOD,
|
||||
&&TARGET_PRECALL_BUILTIN_CLASS,
|
||||
&&TARGET_PRECALL_BUILTIN_FAST_WITH_KEYWORDS,
|
||||
&&TARGET_LOAD_ATTR_ADAPTIVE,
|
||||
&&TARGET_LOAD_ATTR_INSTANCE_VALUE,
|
||||
&&TARGET_LOAD_ATTR_MODULE,
|
||||
&&TARGET_LOAD_ATTR_SLOT,
|
||||
&&TARGET_LOAD_ATTR_WITH_HINT,
|
||||
&&TARGET_LOAD_CONST__LOAD_FAST,
|
||||
&&TARGET_GET_ITER,
|
||||
&&TARGET_GET_YIELD_FROM_ITER,
|
||||
&&TARGET_PRINT_EXPR,
|
||||
&&TARGET_LOAD_BUILD_CLASS,
|
||||
&&TARGET_PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS,
|
||||
&&TARGET_PRECALL_NO_KW_BUILTIN_FAST,
|
||||
&&TARGET_LOAD_FAST__LOAD_CONST,
|
||||
&&TARGET_LOAD_FAST__LOAD_FAST,
|
||||
&&TARGET_LOAD_ASSERTION_ERROR,
|
||||
&&TARGET_RETURN_GENERATOR,
|
||||
&&TARGET_PRECALL_NO_KW_BUILTIN_O,
|
||||
&&TARGET_PRECALL_NO_KW_ISINSTANCE,
|
||||
&&TARGET_PRECALL_NO_KW_LEN,
|
||||
&&TARGET_PRECALL_NO_KW_LIST_APPEND,
|
||||
&&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_FAST,
|
||||
&&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
|
||||
&&TARGET_LOAD_GLOBAL_ADAPTIVE,
|
||||
&&TARGET_LOAD_GLOBAL_BUILTIN,
|
||||
&&TARGET_LOAD_GLOBAL_MODULE,
|
||||
&&TARGET_LOAD_METHOD_ADAPTIVE,
|
||||
&&TARGET_LOAD_METHOD_CLASS,
|
||||
&&TARGET_LOAD_METHOD_MODULE,
|
||||
&&TARGET_LIST_TO_TUPLE,
|
||||
&&TARGET_RETURN_VALUE,
|
||||
&&TARGET_IMPORT_STAR,
|
||||
|
@ -112,7 +112,7 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_JUMP_FORWARD,
|
||||
&&TARGET_JUMP_IF_FALSE_OR_POP,
|
||||
&&TARGET_JUMP_IF_TRUE_OR_POP,
|
||||
&&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_O,
|
||||
&&TARGET_LOAD_METHOD_NO_DICT,
|
||||
&&TARGET_POP_JUMP_FORWARD_IF_FALSE,
|
||||
&&TARGET_POP_JUMP_FORWARD_IF_TRUE,
|
||||
&&TARGET_LOAD_GLOBAL,
|
||||
|
@ -120,13 +120,13 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_CONTAINS_OP,
|
||||
&&TARGET_RERAISE,
|
||||
&&TARGET_COPY,
|
||||
&&TARGET_PRECALL_NO_KW_STR_1,
|
||||
&&TARGET_LOAD_METHOD_WITH_DICT,
|
||||
&&TARGET_BINARY_OP,
|
||||
&&TARGET_SEND,
|
||||
&&TARGET_LOAD_FAST,
|
||||
&&TARGET_STORE_FAST,
|
||||
&&TARGET_DELETE_FAST,
|
||||
&&TARGET_PRECALL_NO_KW_TUPLE_1,
|
||||
&&TARGET_LOAD_METHOD_WITH_VALUES,
|
||||
&&TARGET_POP_JUMP_FORWARD_IF_NOT_NONE,
|
||||
&&TARGET_POP_JUMP_FORWARD_IF_NONE,
|
||||
&&TARGET_RAISE_VARARGS,
|
||||
|
@ -140,45 +140,42 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_STORE_DEREF,
|
||||
&&TARGET_DELETE_DEREF,
|
||||
&&TARGET_JUMP_BACKWARD,
|
||||
&&TARGET_PRECALL_NO_KW_TYPE_1,
|
||||
&&TARGET_RESUME_QUICK,
|
||||
&&TARGET_CALL_FUNCTION_EX,
|
||||
&&TARGET_PRECALL_PYFUNC,
|
||||
&&TARGET_STORE_ATTR_ADAPTIVE,
|
||||
&&TARGET_EXTENDED_ARG,
|
||||
&&TARGET_LIST_APPEND,
|
||||
&&TARGET_SET_ADD,
|
||||
&&TARGET_MAP_ADD,
|
||||
&&TARGET_LOAD_CLASSDEREF,
|
||||
&&TARGET_COPY_FREE_VARS,
|
||||
&&TARGET_RESUME_QUICK,
|
||||
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
|
||||
&&TARGET_RESUME,
|
||||
&&TARGET_MATCH_CLASS,
|
||||
&&TARGET_STORE_ATTR_ADAPTIVE,
|
||||
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
|
||||
&&TARGET_STORE_ATTR_SLOT,
|
||||
&&TARGET_STORE_ATTR_WITH_HINT,
|
||||
&&TARGET_FORMAT_VALUE,
|
||||
&&TARGET_BUILD_CONST_KEY_MAP,
|
||||
&&TARGET_BUILD_STRING,
|
||||
&&TARGET_STORE_ATTR_SLOT,
|
||||
&&TARGET_STORE_ATTR_WITH_HINT,
|
||||
&&TARGET_LOAD_METHOD,
|
||||
&&TARGET_STORE_FAST__LOAD_FAST,
|
||||
&&TARGET_STORE_FAST__STORE_FAST,
|
||||
&&TARGET_LOAD_METHOD,
|
||||
&&TARGET_STORE_SUBSCR_ADAPTIVE,
|
||||
&&TARGET_LIST_EXTEND,
|
||||
&&TARGET_SET_UPDATE,
|
||||
&&TARGET_DICT_MERGE,
|
||||
&&TARGET_DICT_UPDATE,
|
||||
&&TARGET_PRECALL,
|
||||
&&TARGET_STORE_FAST__STORE_FAST,
|
||||
&&TARGET_STORE_SUBSCR_ADAPTIVE,
|
||||
&&TARGET_STORE_SUBSCR_DICT,
|
||||
&&TARGET_STORE_SUBSCR_LIST_INT,
|
||||
&&TARGET_UNPACK_SEQUENCE_ADAPTIVE,
|
||||
&&TARGET_UNPACK_SEQUENCE_LIST,
|
||||
&&TARGET_UNPACK_SEQUENCE_TUPLE,
|
||||
&&TARGET_CALL,
|
||||
&&TARGET_KW_NAMES,
|
||||
&&TARGET_POP_JUMP_BACKWARD_IF_NOT_NONE,
|
||||
&&TARGET_POP_JUMP_BACKWARD_IF_NONE,
|
||||
&&TARGET_POP_JUMP_BACKWARD_IF_FALSE,
|
||||
&&TARGET_POP_JUMP_BACKWARD_IF_TRUE,
|
||||
&&TARGET_UNPACK_SEQUENCE_ADAPTIVE,
|
||||
&&TARGET_UNPACK_SEQUENCE_LIST,
|
||||
&&TARGET_UNPACK_SEQUENCE_TUPLE,
|
||||
&&TARGET_UNPACK_SEQUENCE_TWO_TUPLE,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
|
@ -254,5 +251,8 @@ static void *opcode_targets[256] = {
|
|||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&TARGET_DO_TRACING
|
||||
};
|
||||
|
|
|
@ -24,7 +24,6 @@ uint8_t _PyOpcode_Adaptive[256] = {
|
|||
[BINARY_SUBSCR] = BINARY_SUBSCR_ADAPTIVE,
|
||||
[STORE_SUBSCR] = STORE_SUBSCR_ADAPTIVE,
|
||||
[CALL] = CALL_ADAPTIVE,
|
||||
[PRECALL] = PRECALL_ADAPTIVE,
|
||||
[STORE_ATTR] = STORE_ATTR_ADAPTIVE,
|
||||
[BINARY_OP] = BINARY_OP_ADAPTIVE,
|
||||
[COMPARE_OP] = COMPARE_OP_ADAPTIVE,
|
||||
|
@ -121,7 +120,6 @@ _Py_GetSpecializationStats(void) {
|
|||
err += add_stat_dict(stats, BINARY_OP, "binary_op");
|
||||
err += add_stat_dict(stats, COMPARE_OP, "compare_op");
|
||||
err += add_stat_dict(stats, UNPACK_SEQUENCE, "unpack_sequence");
|
||||
err += add_stat_dict(stats, PRECALL, "precall");
|
||||
if (err < 0) {
|
||||
Py_DECREF(stats);
|
||||
return NULL;
|
||||
|
@ -1358,38 +1356,39 @@ success:
|
|||
|
||||
static int
|
||||
specialize_class_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
|
||||
PyObject *kwnames, int oparg)
|
||||
PyObject *kwnames)
|
||||
{
|
||||
assert(_Py_OPCODE(*instr) == PRECALL_ADAPTIVE);
|
||||
assert(_Py_OPCODE(*instr) == CALL_ADAPTIVE);
|
||||
PyTypeObject *tp = _PyType_CAST(callable);
|
||||
if (tp->tp_new == PyBaseObject_Type.tp_new) {
|
||||
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_CALL_PYTHON_CLASS);
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_PYTHON_CLASS);
|
||||
return -1;
|
||||
}
|
||||
if (tp->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) {
|
||||
int oparg = _Py_OPARG(*instr);
|
||||
if (nargs == 1 && kwnames == NULL && oparg == 1) {
|
||||
if (tp == &PyUnicode_Type) {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_STR_1);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_STR_1);
|
||||
return 0;
|
||||
}
|
||||
else if (tp == &PyType_Type) {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_TYPE_1);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_TYPE_1);
|
||||
return 0;
|
||||
}
|
||||
else if (tp == &PyTuple_Type) {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_TUPLE_1);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_TUPLE_1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (tp->tp_vectorcall != NULL) {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_BUILTIN_CLASS);
|
||||
_Py_SET_OPCODE(*instr, CALL_BUILTIN_CLASS);
|
||||
return 0;
|
||||
}
|
||||
SPECIALIZATION_FAIL(PRECALL, tp == &PyUnicode_Type ?
|
||||
SPECIALIZATION_FAIL(CALL, tp == &PyUnicode_Type ?
|
||||
SPEC_FAIL_CALL_STR : SPEC_FAIL_CALL_CLASS_NO_VECTORCALL);
|
||||
return -1;
|
||||
}
|
||||
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_CALL_CLASS_MUTABLE);
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_CLASS_MUTABLE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1419,11 +1418,11 @@ builtin_call_fail_kind(int ml_flags)
|
|||
|
||||
static int
|
||||
specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
|
||||
int nargs, PyObject *kwnames, int oparg)
|
||||
int nargs, PyObject *kwnames)
|
||||
{
|
||||
assert(_Py_OPCODE(*instr) == PRECALL_ADAPTIVE);
|
||||
assert(_Py_OPCODE(*instr) == CALL_ADAPTIVE);
|
||||
if (kwnames) {
|
||||
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_CALL_KWNAMES);
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_KWNAMES);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1432,45 +1431,45 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
|
|||
METH_KEYWORDS | METH_METHOD)) {
|
||||
case METH_NOARGS: {
|
||||
if (nargs != 1) {
|
||||
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
|
||||
return -1;
|
||||
}
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_METHOD_DESCRIPTOR_NOARGS);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS);
|
||||
return 0;
|
||||
}
|
||||
case METH_O: {
|
||||
if (nargs != 2) {
|
||||
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
|
||||
return -1;
|
||||
}
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
PyObject *list_append = interp->callable_cache.list_append;
|
||||
_Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_PRECALL + 1
|
||||
+ INLINE_CACHE_ENTRIES_CALL + 1];
|
||||
_Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_CALL + 1];
|
||||
bool pop = (_Py_OPCODE(next) == POP_TOP);
|
||||
int oparg = _Py_OPARG(*instr);
|
||||
if ((PyObject *)descr == list_append && oparg == 1 && pop) {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_LIST_APPEND);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_LIST_APPEND);
|
||||
return 0;
|
||||
}
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_METHOD_DESCRIPTOR_O);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_METHOD_DESCRIPTOR_O);
|
||||
return 0;
|
||||
}
|
||||
case METH_FASTCALL: {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_METHOD_DESCRIPTOR_FAST);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_METHOD_DESCRIPTOR_FAST);
|
||||
return 0;
|
||||
}
|
||||
case METH_FASTCALL|METH_KEYWORDS: {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS);
|
||||
_Py_SET_OPCODE(*instr, CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
SPECIALIZATION_FAIL(PRECALL, builtin_call_fail_kind(descr->d_method->ml_flags));
|
||||
SPECIALIZATION_FAIL(CALL, builtin_call_fail_kind(descr->d_method->ml_flags));
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
specialize_py_call(PyFunctionObject *func, _Py_CODEUNIT *instr, int nargs,
|
||||
PyObject *kwnames)
|
||||
PyObject *kwnames, bool bound_method)
|
||||
{
|
||||
_PyCallCache *cache = (_PyCallCache *)(instr + 1);
|
||||
assert(_Py_OPCODE(*instr) == CALL_ADAPTIVE);
|
||||
|
@ -1512,7 +1511,11 @@ specialize_py_call(PyFunctionObject *func, _Py_CODEUNIT *instr, int nargs,
|
|||
write_u32(cache->func_version, version);
|
||||
cache->min_args = min_args;
|
||||
if (argcount == nargs) {
|
||||
_Py_SET_OPCODE(*instr, CALL_PY_EXACT_ARGS);
|
||||
_Py_SET_OPCODE(*instr, bound_method ? CALL_BOUND_METHOD_EXACT_ARGS : CALL_PY_EXACT_ARGS);
|
||||
}
|
||||
else if (bound_method) {
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_BOUND_METHOD);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
_Py_SET_OPCODE(*instr, CALL_PY_WITH_DEFAULTS);
|
||||
|
@ -1524,7 +1527,7 @@ static int
|
|||
specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
|
||||
PyObject *kwnames)
|
||||
{
|
||||
assert(_Py_OPCODE(*instr) == PRECALL_ADAPTIVE);
|
||||
assert(_Py_OPCODE(*instr) == CALL_ADAPTIVE);
|
||||
if (PyCFunction_GET_FUNCTION(callable) == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -1533,44 +1536,44 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
|
|||
METH_KEYWORDS | METH_METHOD)) {
|
||||
case METH_O: {
|
||||
if (kwnames) {
|
||||
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_CALL_KWNAMES);
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_KWNAMES);
|
||||
return -1;
|
||||
}
|
||||
if (nargs != 1) {
|
||||
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
|
||||
return 1;
|
||||
}
|
||||
/* len(o) */
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (callable == interp->callable_cache.len) {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_LEN);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_LEN);
|
||||
return 0;
|
||||
}
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_BUILTIN_O);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_BUILTIN_O);
|
||||
return 0;
|
||||
}
|
||||
case METH_FASTCALL: {
|
||||
if (kwnames) {
|
||||
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_CALL_KWNAMES);
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_KWNAMES);
|
||||
return -1;
|
||||
}
|
||||
if (nargs == 2) {
|
||||
/* isinstance(o1, o2) */
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (callable == interp->callable_cache.isinstance) {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_ISINSTANCE);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_ISINSTANCE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_BUILTIN_FAST);
|
||||
_Py_SET_OPCODE(*instr, CALL_NO_KW_BUILTIN_FAST);
|
||||
return 0;
|
||||
}
|
||||
case METH_FASTCALL | METH_KEYWORDS: {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_BUILTIN_FAST_WITH_KEYWORDS);
|
||||
_Py_SET_OPCODE(*instr, CALL_BUILTIN_FAST_WITH_KEYWORDS);
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
SPECIALIZATION_FAIL(PRECALL,
|
||||
SPECIALIZATION_FAIL(CALL,
|
||||
builtin_call_fail_kind(PyCFunction_GET_FLAGS(callable)));
|
||||
return 1;
|
||||
}
|
||||
|
@ -1618,49 +1621,6 @@ call_fail_kind(PyObject *callable)
|
|||
#endif
|
||||
|
||||
|
||||
int
|
||||
_Py_Specialize_Precall(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
|
||||
PyObject *kwnames, int oparg)
|
||||
{
|
||||
assert(_PyOpcode_Caches[PRECALL] == INLINE_CACHE_ENTRIES_PRECALL);
|
||||
_PyPrecallCache *cache = (_PyPrecallCache *)(instr + 1);
|
||||
int fail;
|
||||
if (PyCFunction_CheckExact(callable)) {
|
||||
fail = specialize_c_call(callable, instr, nargs, kwnames);
|
||||
}
|
||||
else if (PyFunction_Check(callable)) {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_PYFUNC);
|
||||
fail = 0;
|
||||
}
|
||||
else if (PyType_Check(callable)) {
|
||||
fail = specialize_class_call(callable, instr, nargs, kwnames, oparg);
|
||||
}
|
||||
else if (Py_IS_TYPE(callable, &PyMethodDescr_Type)) {
|
||||
fail = specialize_method_descriptor((PyMethodDescrObject *)callable,
|
||||
instr, nargs, kwnames, oparg);
|
||||
}
|
||||
else if (Py_TYPE(callable) == &PyMethod_Type) {
|
||||
_Py_SET_OPCODE(*instr, PRECALL_BOUND_METHOD);
|
||||
fail = 0;
|
||||
}
|
||||
else {
|
||||
SPECIALIZATION_FAIL(PRECALL, call_fail_kind(callable));
|
||||
fail = -1;
|
||||
}
|
||||
if (fail) {
|
||||
STAT_INC(PRECALL, failure);
|
||||
assert(!PyErr_Occurred());
|
||||
cache->counter = ADAPTIVE_CACHE_BACKOFF;
|
||||
}
|
||||
else {
|
||||
STAT_INC(PRECALL, success);
|
||||
assert(!PyErr_Occurred());
|
||||
cache->counter = initial_counter_value();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* TODO:
|
||||
- Specialize calling classes.
|
||||
*/
|
||||
|
@ -1671,9 +1631,29 @@ _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
|
|||
assert(_PyOpcode_Caches[CALL] == INLINE_CACHE_ENTRIES_CALL);
|
||||
_PyCallCache *cache = (_PyCallCache *)(instr + 1);
|
||||
int fail;
|
||||
if (PyFunction_Check(callable)) {
|
||||
if (PyCFunction_CheckExact(callable)) {
|
||||
fail = specialize_c_call(callable, instr, nargs, kwnames);
|
||||
}
|
||||
else if (PyFunction_Check(callable)) {
|
||||
fail = specialize_py_call((PyFunctionObject *)callable, instr, nargs,
|
||||
kwnames);
|
||||
kwnames, false);
|
||||
}
|
||||
else if (PyType_Check(callable)) {
|
||||
fail = specialize_class_call(callable, instr, nargs, kwnames);
|
||||
}
|
||||
else if (Py_IS_TYPE(callable, &PyMethodDescr_Type)) {
|
||||
fail = specialize_method_descriptor((PyMethodDescrObject *)callable,
|
||||
instr, nargs, kwnames);
|
||||
}
|
||||
else if (Py_TYPE(callable) == &PyMethod_Type) {
|
||||
PyObject *func = ((PyMethodObject *)callable)->im_func;
|
||||
if (PyFunction_Check(func)) {
|
||||
fail = specialize_py_call((PyFunctionObject *)func,
|
||||
instr, nargs+1, kwnames, true);
|
||||
} else {
|
||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_BOUND_METHOD);
|
||||
fail = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
SPECIALIZATION_FAIL(CALL, call_fail_kind(callable));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue