-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-134584: Eliminate redundant refcounting from _CALL_ISINSTANCE
#136077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a286004
3d0f5d3
6c04f67
f2b4400
cf6e8ef
f081274
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Eliminate redundant refcounting from ``_CALL_ISINSTANCE``. Patch by Noam | ||
| Cohen |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4349,7 +4349,7 @@ dummy_func( | |||||||||||||||||
| DEOPT_IF(callable_o != interp->callable_cache.isinstance); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| op(_CALL_ISINSTANCE, (callable, null, instance, cls -- res)) { | ||||||||||||||||||
| op(_CALL_ISINSTANCE, (callable, null, instance, cls -- res, c1, i, c2)) { | ||||||||||||||||||
| /* isinstance(o, o2) */ | ||||||||||||||||||
| STAT_INC(CALL, hit); | ||||||||||||||||||
| PyObject *inst_o = PyStackRef_AsPyObjectBorrow(instance); | ||||||||||||||||||
|
|
@@ -4358,11 +4358,10 @@ dummy_func( | |||||||||||||||||
| if (retval < 0) { | ||||||||||||||||||
| ERROR_NO_POP(); | ||||||||||||||||||
| } | ||||||||||||||||||
| (void)null; // Silence compiler warnings about unused variables | ||||||||||||||||||
| PyStackRef_CLOSE(cls); | ||||||||||||||||||
| PyStackRef_CLOSE(instance); | ||||||||||||||||||
| DEAD(null); | ||||||||||||||||||
| PyStackRef_CLOSE(callable); | ||||||||||||||||||
| INPUTS_DEAD(); | ||||||||||||||||||
| c1 = callable; | ||||||||||||||||||
| i = instance; | ||||||||||||||||||
| c2 = cls; | ||||||||||||||||||
|
Comment on lines
+4361
to
+4364
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| res = retval ? PyStackRef_True : PyStackRef_False; | ||||||||||||||||||
| assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -4372,7 +4371,10 @@ dummy_func( | |||||||||||||||||
| unused/2 + | ||||||||||||||||||
| _GUARD_THIRD_NULL + | ||||||||||||||||||
| _GUARD_CALLABLE_ISINSTANCE + | ||||||||||||||||||
| _CALL_ISINSTANCE; | ||||||||||||||||||
| _CALL_ISINSTANCE + | ||||||||||||||||||
| POP_TOP + | ||||||||||||||||||
| POP_TOP + | ||||||||||||||||||
| POP_TOP; | ||||||||||||||||||
|
|
||||||||||||||||||
| macro(CALL_LIST_APPEND) = | ||||||||||||||||||
| unused/1 + | ||||||||||||||||||
|
|
@@ -5360,6 +5362,18 @@ dummy_func( | |||||||||||||||||
| value = PyStackRef_FromPyObjectBorrow(ptr); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| tier2 op(_SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, instance, cls -- value, c1, i, c2)) { | ||||||||||||||||||
| PyStackRef_CLOSE(cls); | ||||||||||||||||||
| PyStackRef_CLOSE(instance); | ||||||||||||||||||
| (void)null; // Silence compiler warnings about unused variables | ||||||||||||||||||
| DEAD(null); | ||||||||||||||||||
| PyStackRef_CLOSE(callable); | ||||||||||||||||||
| value = PyStackRef_FromPyObjectBorrow(ptr); | ||||||||||||||||||
| c1 = callable; | ||||||||||||||||||
| i = instance; | ||||||||||||||||||
| c2 = cls; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| tier2 op(_LOAD_CONST_UNDER_INLINE, (ptr/4, old -- value, new)) { | ||||||||||||||||||
| new = old; | ||||||||||||||||||
| DEAD(old); | ||||||||||||||||||
|
|
||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -567,6 +567,13 @@ dummy_func(void) { | |
| value = PyJitRef_Borrow(sym_new_const(ctx, ptr)); | ||
| } | ||
|
|
||
| op(_SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, instance, cls -- value, c1, i, c2)) { | ||
| value = PyJitRef_Borrow(sym_new_const(ctx, ptr)); | ||
| c1 = callable; | ||
| i = instance; | ||
| c2 = cls; | ||
| } | ||
|
Comment on lines
+570
to
+575
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this, as the instruction is emitted by the optimizer, and never seen by itself. |
||
|
|
||
| op(_POP_TOP, (value -- )) { | ||
| PyTypeObject *typ = sym_get_type(value); | ||
| if (PyJitRef_IsBorrowed(value) || | ||
|
|
@@ -997,7 +1004,7 @@ dummy_func(void) { | |
| } | ||
| } | ||
|
|
||
| op(_CALL_ISINSTANCE, (unused, unused, instance, cls -- res)) { | ||
| op(_CALL_ISINSTANCE, (unused, unused, instance, cls -- res, unused, unused, unused)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please name the variables, then assign to them below, e.g. |
||
| // the result is always a bool, but sometimes we can | ||
| // narrow it down to True or False | ||
| res = sym_new_type(ctx, &PyBool_Type); | ||
|
|
@@ -1013,7 +1020,7 @@ dummy_func(void) { | |
| out = Py_True; | ||
| } | ||
| sym_set_const(res, out); | ||
| REPLACE_OP(this_instr, _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)out); | ||
| REPLACE_OP(this_instr, _SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)out); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't leave a comment on that line, but inside
test_call_isinstance_guards_removedwe should include the new opcode_SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROWto ensureremove_unneeded_uopsis still working as expected (I think it should be since you also updatedop_without_push, but just to be sure :))