Skip to content

Commit f659bc7

Browse files
committed
eliminate refcount from _CALL_BUILTION_O
1 parent 0c6c09b commit f659bc7

File tree

6 files changed

+62
-32
lines changed

6 files changed

+62
-32
lines changed

Include/internal/pycore_opcode_metadata.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.

Lib/test/test_capi/test_opt.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,21 @@ class C:
20112011
self.assertNotIn("_COMPARE_OP_INT", uops)
20122012
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
20132013

2014+
def test_call_builtin_o(self):
2015+
def testfunc(n):
2016+
x = 0
2017+
for _ in range(n):
2018+
y = abs(1)
2019+
x += y
2020+
return x
2021+
2022+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2023+
self.assertEqual(res, TIER2_THRESHOLD)
2024+
self.assertIsNotNone(ex)
2025+
uops = get_opnames(ex)
2026+
self.assertIn("_CALL_BUILTIN_O", uops)
2027+
self.assertIn("_POP_TWO", uops)
2028+
20142029
def test_get_len_with_const_tuple(self):
20152030
def testfunc(n):
20162031
x = 0.0

Python/bytecodes.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,7 +4202,7 @@ dummy_func(
42024202
_CALL_BUILTIN_CLASS +
42034203
_CHECK_PERIODIC;
42044204

4205-
op(_CALL_BUILTIN_O, (callable, self_or_null, args[oparg] -- res)) {
4205+
op(_CALL_BUILTIN_O, (callable, self_or_null, args[oparg] -- res, a, c)) {
42064206
/* Builtin METH_O functions */
42074207
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
42084208

@@ -4222,11 +4222,9 @@ dummy_func(
42224222
PyObject *res_o = _PyCFunction_TrampolineCall(cfunc, PyCFunction_GET_SELF(callable_o), PyStackRef_AsPyObjectBorrow(arg));
42234223
_Py_LeaveRecursiveCallTstate(tstate);
42244224
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
4225-
4226-
PyStackRef_CLOSE(arg);
4227-
DEAD(args);
4228-
DEAD(self_or_null);
4229-
PyStackRef_CLOSE(callable);
4225+
INPUTS_DEAD();
4226+
a = arg;
4227+
c = callable;
42304228
ERROR_IF(res_o == NULL);
42314229
res = PyStackRef_FromPyObjectSteal(res_o);
42324230
}
@@ -4235,6 +4233,7 @@ dummy_func(
42354233
unused/1 +
42364234
unused/2 +
42374235
_CALL_BUILTIN_O +
4236+
_POP_TWO +
42384237
_CHECK_PERIODIC;
42394238

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

Python/executor_cases.c.h

Lines changed: 10 additions & 10 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 & 14 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: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)