mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-131798: JIT: Optimize _CALL_LEN when the length is known (#135260)
* Add news entry * Optimize _CALL_LEN * Simplify tests
This commit is contained in:
parent
59963e866a
commit
61532b4bc7
4 changed files with 77 additions and 1 deletions
|
@ -1203,8 +1203,21 @@ dummy_func(void) {
|
|||
sym_set_const(callable, (PyObject *)&PyUnicode_Type);
|
||||
}
|
||||
|
||||
op(_CALL_LEN, (unused, unused, unused -- res)) {
|
||||
op(_CALL_LEN, (callable, null, arg -- res)) {
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
int tuple_length = sym_tuple_length(arg);
|
||||
if (tuple_length >= 0) {
|
||||
PyObject *temp = PyLong_FromLong(tuple_length);
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
if (_Py_IsImmortal(temp)) {
|
||||
REPLACE_OP(this_instr, _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW,
|
||||
0, (uintptr_t)temp);
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
}
|
||||
}
|
||||
|
||||
op(_GET_LEN, (obj -- obj, len)) {
|
||||
|
|
19
Python/optimizer_cases.c.h
generated
19
Python/optimizer_cases.c.h
generated
|
@ -2241,8 +2241,27 @@
|
|||
}
|
||||
|
||||
case _CALL_LEN: {
|
||||
JitOptRef arg;
|
||||
JitOptRef res;
|
||||
arg = stack_pointer[-1];
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
int tuple_length = sym_tuple_length(arg);
|
||||
if (tuple_length >= 0) {
|
||||
PyObject *temp = PyLong_FromLong(tuple_length);
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
if (_Py_IsImmortal(temp)) {
|
||||
REPLACE_OP(this_instr, _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW,
|
||||
0, (uintptr_t)temp);
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
stack_pointer[-3] = res;
|
||||
stack_pointer += -2;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
Py_DECREF(temp);
|
||||
stack_pointer += 2;
|
||||
}
|
||||
stack_pointer[-3] = res;
|
||||
stack_pointer += -2;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue