Skip to content

Commit fb39643

Browse files
committed
Optimize _CALL_METHOD_DESCRIPTOR_NOARGS
1 parent e371ce1 commit fb39643

File tree

10 files changed

+107
-48
lines changed

10 files changed

+107
-48
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_capi/test_opt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,9 +2780,11 @@ def testfunc(n):
27802780
self.assertEqual(res, TIER2_THRESHOLD * 5)
27812781
self.assertIsNotNone(ex)
27822782
uops = get_opnames(ex)
2783+
27832784
self.assertIn("_CALL_METHOD_DESCRIPTOR_NOARGS_INLINE", uops)
27842785
self.assertNotIn("_CALL_METHOD_DESCRIPTOR_NOARGS", uops)
27852786
self.assertNotIn("_GUARD_CALLABLE_METHOD_DESCRIPTOR_NOARGS", uops)
2787+
self.assertGreaterEqual(count_ops(ex, "_POP_TOP"), 6)
27862788

27872789
def test_call_method_descriptor_fast(self):
27882790
def testfunc(n):

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 24 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4948,7 +4948,7 @@ dummy_func(
49484948
EXIT_IF(!Py_IS_TYPE(self, method->d_common.d_type));
49494949
}
49504950

4951-
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res)) {
4951+
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res, c, s)) {
49524952
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
49534953
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
49544954

@@ -4963,11 +4963,12 @@ dummy_func(
49634963
PyObject *res_o = _PyCFunction_TrampolineCall(cfunc, self, NULL);
49644964
_Py_LeaveRecursiveCallTstate(tstate);
49654965
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
4966-
PyStackRef_CLOSE(self_stackref);
4967-
DEAD(args);
4968-
DEAD(self_or_null);
4969-
PyStackRef_CLOSE(callable);
4970-
ERROR_IF(res_o == NULL);
4966+
if (res_o == NULL) {
4967+
ERROR_NO_POP();
4968+
}
4969+
c = callable;
4970+
s = args[0];
4971+
INPUTS_DEAD();
49714972
res = PyStackRef_FromPyObjectSteal(res_o);
49724973
}
49734974

@@ -4994,6 +4995,8 @@ dummy_func(
49944995
_GUARD_CALLABLE_METHOD_DESCRIPTOR_NOARGS +
49954996
_CHECK_RECURSION_LIMIT +
49964997
_CALL_METHOD_DESCRIPTOR_NOARGS +
4998+
POP_TOP +
4999+
POP_TOP +
49975000
_CHECK_PERIODIC_AT_END;
49985001

49995002
op(_GUARD_CALLABLE_METHOD_DESCRIPTOR_FAST, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {

Python/executor_cases.c.h

Lines changed: 10 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 24 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_bytecodes.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ dummy_func(void) {
14211421
ctx->frame->is_c_recursion_checked = true;
14221422
}
14231423

1424-
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res)) {
1424+
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res, c, s)) {
14251425
PyObject *callable_o = sym_get_const(ctx, callable);
14261426
if (callable_o && Py_IS_TYPE(callable_o, &PyMethodDescr_Type)
14271427
&& sym_is_not_null(self_or_null)) {
@@ -1430,6 +1430,17 @@ dummy_func(void) {
14301430
ADD_OP(_CALL_METHOD_DESCRIPTOR_NOARGS_INLINE, oparg + 1, (uintptr_t)cfunc);
14311431
}
14321432
res = sym_new_not_null(ctx);
1433+
c = callable;
1434+
if (sym_is_not_null(self_or_null)) {
1435+
args--;
1436+
s = args[0];
1437+
}
1438+
else if (sym_is_null(self_or_null)) {
1439+
s = args[0];
1440+
}
1441+
else {
1442+
s = sym_new_unknown(ctx);
1443+
}
14331444
}
14341445

14351446
op(_CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS, (callable, self_or_null, args[oparg] -- res)) {

Python/optimizer_cases.c.h

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)