Skip to content

Commit 4425f6c

Browse files
committed
eliminate refcount from _CALL_BUILTION_O
1 parent f893e8f commit 4425f6c

File tree

5 files changed

+64
-30
lines changed

5 files changed

+64
-30
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,21 @@ class C:
21192119
self.assertNotIn("_COMPARE_OP_INT", uops)
21202120
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
21212121

2122+
def test_call_builtin_o(self):
2123+
def testfunc(n):
2124+
x = 0
2125+
for _ in range(n):
2126+
y = abs(1)
2127+
x += y
2128+
return x
2129+
2130+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2131+
self.assertEqual(res, TIER2_THRESHOLD)
2132+
self.assertIsNotNone(ex)
2133+
uops = get_opnames(ex)
2134+
self.assertIn("_CALL_BUILTIN_O", uops)
2135+
self.assertIn("_POP_TWO", uops)
2136+
21222137
def test_get_len_with_const_tuple(self):
21232138
def testfunc(n):
21242139
x = 0.0

Python/bytecodes.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,7 +4186,7 @@ dummy_func(
41864186
_CALL_BUILTIN_CLASS +
41874187
_CHECK_PERIODIC_AT_END;
41884188

4189-
op(_CALL_BUILTIN_O, (callable, self_or_null, args[oparg] -- res)) {
4189+
op(_CALL_BUILTIN_O, (callable, self_or_null, args[oparg] -- res, a, c)) {
41904190
/* Builtin METH_O functions */
41914191
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
41924192

@@ -4206,11 +4206,9 @@ dummy_func(
42064206
PyObject *res_o = _PyCFunction_TrampolineCall(cfunc, PyCFunction_GET_SELF(callable_o), PyStackRef_AsPyObjectBorrow(arg));
42074207
_Py_LeaveRecursiveCallTstate(tstate);
42084208
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
4209-
4210-
PyStackRef_CLOSE(arg);
4211-
DEAD(args);
4212-
DEAD(self_or_null);
4213-
PyStackRef_CLOSE(callable);
4209+
INPUTS_DEAD();
4210+
a = arg;
4211+
c = callable;
42144212
ERROR_IF(res_o == NULL);
42154213
res = PyStackRef_FromPyObjectSteal(res_o);
42164214
}
@@ -4219,6 +4217,7 @@ dummy_func(
42194217
unused/1 +
42204218
unused/2 +
42214219
_CALL_BUILTIN_O +
4220+
_POP_TWO +
42224221
_CHECK_PERIODIC_AT_END;
42234222

42244223
op(_CALL_BUILTIN_FAST, (callable, self_or_null, args[oparg] -- res)) {

Python/executor_cases.c.h

Lines changed: 12 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_cases.c.h

Lines changed: 8 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)