Skip to content

Commit a286004

Browse files
committed
eliminate refcount from _CALL_ISINSTANCE
1 parent bda1218 commit a286004

File tree

9 files changed

+132
-57
lines changed

9 files changed

+132
-57
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_ids.h

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

Python/bytecodes.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,7 +4349,7 @@ dummy_func(
43494349
DEOPT_IF(callable_o != interp->callable_cache.isinstance);
43504350
}
43514351

4352-
op(_CALL_ISINSTANCE, (callable, null, instance, cls -- res)) {
4352+
op(_CALL_ISINSTANCE, (callable, null, instance, cls -- res, i, c)) {
43534353
/* isinstance(o, o2) */
43544354
STAT_INC(CALL, hit);
43554355
PyObject *inst_o = PyStackRef_AsPyObjectBorrow(instance);
@@ -4358,11 +4358,9 @@ dummy_func(
43584358
if (retval < 0) {
43594359
ERROR_NO_POP();
43604360
}
4361-
(void)null; // Silence compiler warnings about unused variables
4362-
PyStackRef_CLOSE(cls);
4363-
PyStackRef_CLOSE(instance);
4364-
DEAD(null);
4365-
PyStackRef_CLOSE(callable);
4361+
INPUTS_DEAD();
4362+
i = instance;
4363+
c = cls;
43664364
res = retval ? PyStackRef_True : PyStackRef_False;
43674365
assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL));
43684366
}
@@ -4372,7 +4370,9 @@ dummy_func(
43724370
unused/2 +
43734371
_GUARD_THIRD_NULL +
43744372
_GUARD_CALLABLE_ISINSTANCE +
4375-
_CALL_ISINSTANCE;
4373+
_CALL_ISINSTANCE +
4374+
POP_TOP +
4375+
POP_TOP;
43764376

43774377
macro(CALL_LIST_APPEND) =
43784378
unused/1 +
@@ -5360,6 +5360,19 @@ dummy_func(
53605360
value = PyStackRef_FromPyObjectBorrow(ptr);
53615361
}
53625362

5363+
tier2 op(_SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, instance, cls -- value, i, c)) {
5364+
PyStackRef_CLOSE(cls);
5365+
PyStackRef_CLOSE(instance);
5366+
(void)null; // Silence compiler warnings about unused variables
5367+
(void)callable;
5368+
DEAD(null);
5369+
DEAD(callable);
5370+
assert(_Py_IsImmortal(PyStackRef_AsPyObjectBorrow(callable)));
5371+
value = PyStackRef_FromPyObjectBorrow(ptr);
5372+
i = instance;
5373+
c = cls;
5374+
}
5375+
53635376
tier2 op(_LOAD_CONST_UNDER_INLINE, (ptr/4, old -- value, new)) {
53645377
new = old;
53655378
DEAD(old);

Python/executor_cases.c.h

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

Python/optimizer_analysis.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ const uint16_t op_without_push[MAX_UOP_ID + 1] = {
567567
[_POP_TOP_LOAD_CONST_INLINE_BORROW] = _POP_TOP,
568568
[_POP_TWO_LOAD_CONST_INLINE_BORROW] = _POP_TWO,
569569
[_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW] = _POP_CALL_TWO,
570+
[_SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW] = _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW,
570571
};
571572

572573
const bool op_skip[MAX_UOP_ID + 1] = {

Python/optimizer_bytecodes.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,12 @@ dummy_func(void) {
567567
value = PyJitRef_Borrow(sym_new_const(ctx, ptr));
568568
}
569569

570+
op(_SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, unused, unused, instance, cls -- value, i, c)) {
571+
value = PyJitRef_Borrow(sym_new_const(ctx, ptr));
572+
i = instance;
573+
c = cls;
574+
}
575+
570576
op(_POP_TOP, (value -- )) {
571577
PyTypeObject *typ = sym_get_type(value);
572578
if (PyJitRef_IsBorrowed(value) ||
@@ -997,7 +1003,7 @@ dummy_func(void) {
9971003
}
9981004
}
9991005

1000-
op(_CALL_ISINSTANCE, (unused, unused, instance, cls -- res)) {
1006+
op(_CALL_ISINSTANCE, (unused, unused, instance, cls -- res, unused, unused)) {
10011007
// the result is always a bool, but sometimes we can
10021008
// narrow it down to True or False
10031009
res = sym_new_type(ctx, &PyBool_Type);
@@ -1013,7 +1019,8 @@ dummy_func(void) {
10131019
out = Py_True;
10141020
}
10151021
sym_set_const(res, out);
1016-
REPLACE_OP(this_instr, _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)out);
1022+
1023+
REPLACE_OP(this_instr, _SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)out);
10171024
}
10181025
}
10191026

Python/optimizer_cases.c.h

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