gh-148171: Convert CALL_BUILTIN_CLASS to leave arguments on the stack (gh-148381)

This commit is contained in:
Donghee Na 2026-04-11 23:01:25 +09:00 committed by GitHub
parent 9831dea3bf
commit a71b043356
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 87 additions and 60 deletions

View file

@ -4572,7 +4572,7 @@ dummy_func(
EXIT_IF(tp->tp_vectorcall == NULL);
}
op(_CALL_BUILTIN_CLASS, (callable, self_or_null, args[oparg] -- res)) {
op(_CALL_BUILTIN_CLASS, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null)) {
@ -4580,15 +4580,16 @@ dummy_func(
total_args++;
}
STAT_INC(CALL, hit);
PyObject *res_o = _Py_CallBuiltinClass_StackRefSteal(
PyObject *res_o = _Py_CallBuiltinClass_StackRef(
callable,
arguments,
total_args);
DEAD(args);
DEAD(self_or_null);
DEAD(callable);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
if (res_o == NULL) {
ERROR_NO_POP();
}
_PyStackRef temp = callable;
callable = PyStackRef_FromPyObjectSteal(res_o);
PyStackRef_CLOSE(temp);
}
macro(CALL_BUILTIN_CLASS) =
@ -4597,6 +4598,8 @@ dummy_func(
unused/2 +
_GUARD_CALLABLE_BUILTIN_CLASS +
_CALL_BUILTIN_CLASS +
_POP_TOP_OPARG +
POP_TOP +
_CHECK_PERIODIC_AT_END;
op(_GUARD_CALLABLE_BUILTIN_O, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {

View file

@ -894,7 +894,7 @@ _PyCallMethodDescriptorFastWithKeywords_StackRef(
}
PyObject *
_Py_CallBuiltinClass_StackRefSteal(
_Py_CallBuiltinClass_StackRef(
_PyStackRef callable,
_PyStackRef *arguments,
int total_args)
@ -902,22 +902,12 @@ _Py_CallBuiltinClass_StackRefSteal(
PyObject *res;
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
res = NULL;
goto cleanup;
return NULL;
}
PyTypeObject *tp = (PyTypeObject *)PyStackRef_AsPyObjectBorrow(callable);
res = tp->tp_vectorcall((PyObject *)tp, args_o, total_args | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res != NULL) ^ (PyErr_Occurred() != NULL));
cleanup:
// arguments is a pointer into the GC visible stack,
// so we must NULL out values as we clear them.
for (int i = total_args-1; i >= 0; i--) {
_PyStackRef tmp = arguments[i];
arguments[i] = PyStackRef_NULL;
PyStackRef_CLOSE(tmp);
}
PyStackRef_CLOSE(callable);
return res;
}

View file

@ -16450,13 +16450,12 @@
break;
}
case _CALL_BUILTIN_CLASS_r01: {
case _CALL_BUILTIN_CLASS_r00: {
CHECK_CURRENT_CACHED_VALUES(0);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef *args;
_PyStackRef self_or_null;
_PyStackRef callable;
_PyStackRef res;
oparg = CURRENT_OPARG();
args = &stack_pointer[-oparg];
self_or_null = stack_pointer[-1 - oparg];
@ -16469,24 +16468,25 @@
}
STAT_INC(CALL, hit);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyObject *res_o = _Py_CallBuiltinClass_StackRefSteal(
PyObject *res_o = _Py_CallBuiltinClass_StackRef(
callable,
arguments,
total_args);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (res_o == NULL) {
stack_pointer += -2 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
res = PyStackRef_FromPyObjectSteal(res_o);
_tos_cache0 = res;
_PyStackRef temp = callable;
callable = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[-2 - oparg] = callable;
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(temp);
stack_pointer = _PyFrame_GetStackPointer(frame);
_tos_cache0 = PyStackRef_ZERO_BITS;
_tos_cache1 = PyStackRef_ZERO_BITS;
_tos_cache2 = PyStackRef_ZERO_BITS;
SET_CURRENT_CACHED_VALUES(1);
stack_pointer += -2 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
SET_CURRENT_CACHED_VALUES(0);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}

View file

@ -2276,7 +2276,7 @@
_PyStackRef callable;
_PyStackRef self_or_null;
_PyStackRef *args;
_PyStackRef res;
_PyStackRef value;
/* Skip 1 cache entry */
/* Skip 2 cache entries */
// _GUARD_CALLABLE_BUILTIN_CLASS
@ -2307,23 +2307,39 @@
}
STAT_INC(CALL, hit);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyObject *res_o = _Py_CallBuiltinClass_StackRefSteal(
PyObject *res_o = _Py_CallBuiltinClass_StackRef(
callable,
arguments,
total_args);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (res_o == NULL) {
stack_pointer += -2 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
JUMP_TO_LABEL(error);
}
res = PyStackRef_FromPyObjectSteal(res_o);
_PyStackRef temp = callable;
callable = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[-2 - oparg] = callable;
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(temp);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
// _POP_TOP_OPARG
{
args = &stack_pointer[-oparg];
_PyFrame_SetStackPointer(frame, stack_pointer);
_PyStackRef_CloseStack(args, oparg);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
// _POP_TOP
{
value = self_or_null;
stack_pointer += -1 - oparg;
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[-2 - oparg] = res;
stack_pointer += -1 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = check_periodics(tstate);
stack_pointer = _PyFrame_GetStackPointer(frame);

View file

@ -1364,6 +1364,10 @@ dummy_func(void) {
callable = sym_new_not_null(ctx);
}
op(_CALL_BUILTIN_CLASS, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
callable = sym_new_not_null(ctx);
}
op(_GUARD_CALLABLE_METHOD_DESCRIPTOR_O, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
PyObject *callable_o = sym_get_const(ctx, callable);
if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type) &&

View file

@ -3950,12 +3950,10 @@
}
case _CALL_BUILTIN_CLASS: {
JitOptRef res;
res = sym_new_not_null(ctx);
CHECK_STACK_BOUNDS(-1 - oparg);
stack_pointer[-2 - oparg] = res;
stack_pointer += -1 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
JitOptRef callable;
callable = stack_pointer[-2 - oparg];
callable = sym_new_not_null(ctx);
stack_pointer[-2 - oparg] = callable;
break;
}