8000 Eliminate redundant refcounting from _CALL_TYPE_1 · python/cpython@19ed708 · GitHub
[go: up one dir, main page]

Skip to content

Commit 19ed708

Browse files
committed
Eliminate redundant refcounting from _CALL_TYPE_1
1 parent c4121f5 commit 19ed708

File tree

8 files changed

+52
-26
lines changed

8 files changed

+52
-26
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.

Include/internal/pycore_uop_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
@@ -1841,6 +1841,21 @@ def testfunc(n):
18411841
uops = get_opnames(ex)
18421842
self.assertNotIn("_GUARD_IS_NOT_NONE_POP", uops)
18431843

1844+
def test_call_type_1_pop_top(self):
1845+
def testfunc(n):
1846+
x = 0
1847+
for _ in range(n):
1848+
foo = eval('42')
1849+
x += type(foo) is int
1850+
return x
1851+
1852+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1853+
self.assertEqual(res, TIER2_THRESHOLD)
1854+
self.assertIsNotNone(ex)
1855+
uops = get_opnames(ex)
1856+
self.assertIn("_CALL_TYPE_1", uops)
1857+
self.assertIn("_POP_TOP", uops)
1858+
18441859
def test_call_str_1(self):
18451860
def testfunc(n):
18461861
x = 0

Python/bytecodes.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,25 +4031,24 @@ dummy_func(
40314031
DEOPT_IF(callable_o != (PyObject *)&PyType_Type);
40324032
}
40334033

4034-
op(_CALL_TYPE_1, (callable, null, arg -- res)) {
4034+
op(_CALL_TYPE_1, (callable, null, arg -- res, c, a)) {
40354035
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
4036-
40374036
assert(oparg == 1);
4038-
DEAD(null);
4039-
DEAD(callable);
4040-
(void)callable; // Silence compiler warnings about unused variables
4041-
(void)null;
40424037
STAT_INC(CALL, hit);
40434038
res = PyStackRef_FromPyObjectNew(Py_TYPE(arg_o));
4044-
PyStackRef_CLOSE(arg);
4039+
INPUTS_DEAD();
4040+
c = callable;
4041+
a = arg;
40454042
}
40464043

40474044
macro(CALL_TYPE_1) =
40484045
unused/1 +
40494046
unused/2 +
40504047
_GUARD_NOS_NULL +
40514048
_GUARD_CALLABLE_TYPE_1 +
4052-
_CALL_TYPE_1;
4049+
_CALL_TYPE_1 +
4050+
POP_TOP +
4051+
POP_TOP;
40534052

40544053
op(_GUARD_CALLABLE_STR_1, (callable, unused, unused -- callable, unused, unused)) {
40554054
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);

Python/executor_cases.c.h

Lines changed: 6 additions & 9 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: 21 additions & 4 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ dummy_func(void) {
970970
next = sym_new_type(ctx, &PyLong_Type);
971971
}
972972

973-
op(_CALL_TYPE_1, (unused, unused, arg -- res)) {
973+
op(_CALL_TYPE_1, (unused, unused, arg -- res, unused, unused)) {
974974
PyObject* type = (PyObject *)sym_get_type(arg);
975975
if (type) {
976976
res = sym_new_const(ctx, type);

Python/optimizer_cases.c.h

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