mirror of
https://github.com/python/cpython.git
synced 2026-01-05 06:52:26 +00:00
gh-134584: Eliminate redundant refcounting from _CALL_STR_1 (GH-136070)
Signed-off-by: Manjusaka <me@manjusaka.me>
This commit is contained in:
parent
d3ef5ba34d
commit
a154c9ed4e
10 changed files with 58 additions and 43 deletions
|
|
@ -4040,18 +4040,17 @@ dummy_func(
|
|||
DEOPT_IF(callable_o != (PyObject *)&PyUnicode_Type);
|
||||
}
|
||||
|
||||
op(_CALL_STR_1, (callable, null, arg -- res)) {
|
||||
op(_CALL_STR_1, (callable, null, arg -- res, a)) {
|
||||
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
|
||||
|
||||
assert(oparg == 1);
|
||||
STAT_INC(CALL, hit);
|
||||
PyObject *res_o = PyObject_Str(arg_o);
|
||||
DEAD(null);
|
||||
DEAD(callable);
|
||||
(void)callable; // Silence compiler warnings about unused variables
|
||||
(void)null;
|
||||
PyStackRef_CLOSE(arg);
|
||||
ERROR_IF(res_o == NULL);
|
||||
if (res_o == NULL) {
|
||||
ERROR_NO_POP();
|
||||
}
|
||||
a = arg;
|
||||
INPUTS_DEAD();
|
||||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
|
||||
|
|
@ -4061,6 +4060,7 @@ dummy_func(
|
|||
_GUARD_NOS_NULL +
|
||||
_GUARD_CALLABLE_STR_1 +
|
||||
_CALL_STR_1 +
|
||||
POP_TOP +
|
||||
_CHECK_PERIODIC_AT_END;
|
||||
|
||||
op(_GUARD_CALLABLE_TUPLE_1, (callable, unused, unused -- callable, unused, unused)) {
|
||||
|
|
|
|||
25
Python/executor_cases.c.h
generated
25
Python/executor_cases.c.h
generated
|
|
@ -12755,47 +12755,40 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _CALL_STR_1_r31: {
|
||||
case _CALL_STR_1_r32: {
|
||||
CHECK_CURRENT_CACHED_VALUES(3);
|
||||
assert(WITHIN_STACK_BOUNDS_WITH_CACHE());
|
||||
_PyStackRef arg;
|
||||
_PyStackRef null;
|
||||
_PyStackRef callable;
|
||||
_PyStackRef res;
|
||||
_PyStackRef a;
|
||||
_PyStackRef _stack_item_0 = _tos_cache0;
|
||||
_PyStackRef _stack_item_1 = _tos_cache1;
|
||||
_PyStackRef _stack_item_2 = _tos_cache2;
|
||||
oparg = CURRENT_OPARG();
|
||||
arg = _stack_item_2;
|
||||
null = _stack_item_1;
|
||||
callable = _stack_item_0;
|
||||
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
|
||||
assert(oparg == 1);
|
||||
STAT_INC(CALL, hit);
|
||||
stack_pointer[0] = callable;
|
||||
stack_pointer[1] = null;
|
||||
stack_pointer[0] = _stack_item_0;
|
||||
stack_pointer[1] = _stack_item_1;
|
||||
stack_pointer[2] = arg;
|
||||
stack_pointer += 3;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyObject *res_o = PyObject_Str(arg_o);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
(void)callable;
|
||||
(void)null;
|
||||
stack_pointer += -3;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_CLOSE(arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (res_o == NULL) {
|
||||
SET_CURRENT_CACHED_VALUES(0);
|
||||
JUMP_TO_ERROR();
|
||||
}
|
||||
a = arg;
|
||||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
_tos_cache1 = a;
|
||||
_tos_cache0 = res;
|
||||
_tos_cache1 = PyStackRef_ZERO_BITS;
|
||||
_tos_cache2 = PyStackRef_ZERO_BITS;
|
||||
SET_CURRENT_CACHED_VALUES(1);
|
||||
SET_CURRENT_CACHED_VALUES(2);
|
||||
stack_pointer += -3;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
assert(WITHIN_STACK_BOUNDS_WITH_CACHE());
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
23
Python/generated_cases.c.h
generated
23
Python/generated_cases.c.h
generated
|
|
@ -3968,6 +3968,8 @@
|
|||
_PyStackRef callable;
|
||||
_PyStackRef arg;
|
||||
_PyStackRef res;
|
||||
_PyStackRef a;
|
||||
_PyStackRef value;
|
||||
/* Skip 1 cache entry */
|
||||
/* Skip 2 cache entries */
|
||||
// _GUARD_NOS_NULL
|
||||
|
|
@ -3998,23 +4000,24 @@
|
|||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyObject *res_o = PyObject_Str(arg_o);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
(void)callable;
|
||||
(void)null;
|
||||
stack_pointer += -3;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_CLOSE(arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (res_o == NULL) {
|
||||
JUMP_TO_LABEL(error);
|
||||
}
|
||||
a = arg;
|
||||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
// _POP_TOP
|
||||
{
|
||||
value = a;
|
||||
stack_pointer[-3] = res;
|
||||
stack_pointer += -2;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(value);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
// _CHECK_PERIODIC_AT_END
|
||||
{
|
||||
stack_pointer[0] = res;
|
||||
stack_pointer += 1;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
int err = check_periodics(tstate);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
|
|
|
|||
|
|
@ -951,7 +951,7 @@ dummy_func(void) {
|
|||
}
|
||||
}
|
||||
|
||||
op(_CALL_STR_1, (unused, unused, arg -- res)) {
|
||||
op(_CALL_STR_1, (unused, unused, arg -- res, a)) {
|
||||
if (sym_matches_type(arg, &PyUnicode_Type)) {
|
||||
// e.g. str('foo') or str(foo) where foo is known to be a string
|
||||
// Note: we must strip the reference information because it goes
|
||||
|
|
@ -961,6 +961,7 @@ dummy_func(void) {
|
|||
else {
|
||||
res = sym_new_type(ctx, &PyUnicode_Type);
|
||||
}
|
||||
a = arg;
|
||||
}
|
||||
|
||||
op(_CALL_ISINSTANCE, (unused, unused, instance, cls -- res)) {
|
||||
|
|
|
|||
7
Python/optimizer_cases.c.h
generated
7
Python/optimizer_cases.c.h
generated
|
|
@ -2855,6 +2855,7 @@
|
|||
case _CALL_STR_1: {
|
||||
JitOptRef arg;
|
||||
JitOptRef res;
|
||||
JitOptRef a;
|
||||
arg = stack_pointer[-1];
|
||||
if (sym_matches_type(arg, &PyUnicode_Type)) {
|
||||
res = PyJitRef_StripReferenceInfo(arg);
|
||||
|
|
@ -2862,9 +2863,11 @@
|
|||
else {
|
||||
res = sym_new_type(ctx, &PyUnicode_Type);
|
||||
}
|
||||
CHECK_STACK_BOUNDS(-2);
|
||||
a = arg;
|
||||
CHECK_STACK_BOUNDS(-1);
|
||||
stack_pointer[-3] = res;
|
||||
stack_pointer += -2;
|
||||
stack_pointer[-2] = a;
|
||||
stack_pointer += -1;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue