Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
noamcohen97 wants to merge6 commits intopython:main
base:main
Choose a base branch
Loading
fromnoamcohen97:refcount-isinstance
Draft
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
eliminate refcount from_CALL_ISINSTANCE
  • Loading branch information
@noamcohen97
noamcohen97 committedJun 28, 2025
commita2860043854fe10ce941b7aab18da66f1324a429
2 changes: 1 addition & 1 deletionInclude/internal/pycore_opcode_metadata.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

19 changes: 10 additions & 9 deletionsInclude/internal/pycore_uop_ids.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

4 changes: 4 additions & 0 deletionsInclude/internal/pycore_uop_metadata.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

27 changes: 20 additions & 7 deletionsPython/bytecodes.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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, i, c)) {
/* isinstance(o, o2) */
STAT_INC(CALL, hit);
PyObject *inst_o = PyStackRef_AsPyObjectBorrow(instance);
Expand All@@ -4358,11 +4358,9 @@ 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();
i = instance;
c = cls;
res = retval ? PyStackRef_True : PyStackRef_False;
assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL));
}
Expand All@@ -4372,7 +4370,9 @@ dummy_func(
unused/2 +
_GUARD_THIRD_NULL +
_GUARD_CALLABLE_ISINSTANCE +
_CALL_ISINSTANCE;
_CALL_ISINSTANCE +
POP_TOP +
POP_TOP;

macro(CALL_LIST_APPEND) =
unused/1 +
Expand DownExpand Up@@ -5360,6 +5360,19 @@ dummy_func(
value = PyStackRef_FromPyObjectBorrow(ptr);
}

tier2 op(_SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, instance, cls -- value, i, c)) {
PyStackRef_CLOSE(cls);
PyStackRef_CLOSE(instance);
(void)null; // Silence compiler warnings about unused variables
(void)callable;
DEAD(null);
DEAD(callable);
assert(_Py_IsImmortal(PyStackRef_AsPyObjectBorrow(callable)));
value = PyStackRef_FromPyObjectBorrow(ptr);
i = instance;
c = cls;
}

tier2 op(_LOAD_CONST_UNDER_INLINE, (ptr/4, old -- value, new)) {
new = old;
DEAD(old);
Expand Down
67 changes: 45 additions & 22 deletionsPython/executor_cases.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

34 changes: 20 additions & 14 deletionsPython/generated_cases.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionsPython/optimizer_analysis.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -567,6 +567,7 @@ const uint16_t op_without_push[MAX_UOP_ID + 1] = {
[_POP_TOP_LOAD_CONST_INLINE_BORROW] = _POP_TOP,
[_POP_TWO_LOAD_CONST_INLINE_BORROW] = _POP_TWO,
[_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW] = _POP_CALL_TWO,
[_SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW] = _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW,
};

const bool op_skip[MAX_UOP_ID + 1] = {
Expand Down
11 changes: 9 additions & 2 deletionsPython/optimizer_bytecodes.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -567,6 +567,12 @@ dummy_func(void) {
value = PyJitRef_Borrow(sym_new_const(ctx, ptr));
}

op(_SWAP_CALL_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, unused, unused, instance, cls -- value, i, c)) {
value = PyJitRef_Borrow(sym_new_const(ctx, ptr));
i = instance;
c = cls;
}

op(_POP_TOP, (value -- )) {
PyTypeObject *typ = sym_get_type(value);
if (PyJitRef_IsBorrowed(value) ||
Expand DownExpand Up@@ -997,7 +1003,7 @@ dummy_func(void) {
}
}

op(_CALL_ISINSTANCE, (unused, unused, instance, cls -- res)) {
op(_CALL_ISINSTANCE, (unused, unused, instance, cls -- res, unused, unused)) {
// the result is always a bool, but sometimes we can
// narrow it down to True or False
res = sym_new_type(ctx, &PyBool_Type);
Expand All@@ -1013,7 +1019,8 @@ 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);
}
}

Expand Down
24 changes: 22 additions & 2 deletionsPython/optimizer_cases.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.


[8]ページ先頭

©2009-2025 Movatter.jp