-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-115999: Enable specialization of CALL
instructions in free-threaded builds
#127123
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
Changes from 23 commits
6d9b6a2
30e25d2
92160de
4754921
6a20bb0
ea7206d
d5375f1
a2ca192
2ab08f2
3534246
acda1c6
fdfa678
ad2e15c
0003d00
8ebd331
4c1ad6c
57ba52d
8ebd73d
8651ebe
4c7837f
4b0a850
d8a67c2
3e8d85e
de0e2ee
1cb6260
b3aa63c
6b591c3
a5fdc59
bc65932
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3325,15 +3325,15 @@ dummy_func( | |
}; | ||
|
||
specializing op(_SPECIALIZE_CALL, (counter/1, callable[1], self_or_null[1], args[oparg] -- callable[1], self_or_null[1], args[oparg])) { | ||
#if ENABLE_SPECIALIZATION | ||
#if ENABLE_SPECIALIZATION_FT | ||
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) { | ||
next_instr = this_instr; | ||
_Py_Specialize_Call(callable[0], next_instr, oparg + !PyStackRef_IsNull(self_or_null[0])); | ||
DISPATCH_SAME_OPARG(); | ||
} | ||
OPCODE_DEFERRED_INC(CALL); | ||
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter); | ||
#endif /* ENABLE_SPECIALIZATION */ | ||
#endif /* ENABLE_SPECIALIZATION_FT */ | ||
} | ||
|
||
op(_MAYBE_EXPAND_METHOD, (callable[1], self_or_null[1], args[oparg] -- func[1], maybe_self[1], args[oparg])) { | ||
|
@@ -3718,10 +3718,10 @@ dummy_func( | |
DEOPT_IF(!PyStackRef_IsNull(null[0])); | ||
DEOPT_IF(!PyType_Check(callable_o)); | ||
PyTypeObject *tp = (PyTypeObject *)callable_o; | ||
DEOPT_IF(tp->tp_version_tag != type_version); | ||
DEOPT_IF(FT_ATOMIC_LOAD_UINT32_RELAXED(tp->tp_version_tag) != type_version); | ||
assert(tp->tp_flags & Py_TPFLAGS_INLINE_VALUES); | ||
PyHeapTypeObject *cls = (PyHeapTypeObject *)callable_o; | ||
PyFunctionObject *init_func = (PyFunctionObject *)cls->_spec_cache.init; | ||
PyFunctionObject *init_func = (PyFunctionObject *)FT_ATOMIC_LOAD_PTR_RELAXED(cls->_spec_cache.init); | ||
PyCodeObject *code = (PyCodeObject *)init_func->func_code; | ||
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize + _Py_InitCleanup.co_framesize)); | ||
STAT_INC(CALL, hit); | ||
|
@@ -3739,6 +3739,7 @@ dummy_func( | |
_PyInterpreterFrame *shim = _PyFrame_PushTrampolineUnchecked( | ||
tstate, (PyCodeObject *)&_Py_InitCleanup, 1, frame); | ||
assert(_PyFrame_GetBytecode(shim)[0].op.code == EXIT_INIT_CHECK); | ||
assert(_PyFrame_GetBytecode(shim)[1].op.code == RETURN_VALUE); | ||
/* Push self onto stack of shim */ | ||
shim->localsplus[0] = PyStackRef_DUP(self[0]); | ||
DEAD(init); | ||
|
@@ -3997,7 +3998,11 @@ dummy_func( | |
assert(self_o != NULL); | ||
DEOPT_IF(!PyList_Check(self_o)); | ||
STAT_INC(CALL, hit); | ||
#ifdef Py_GIL_DISABLED | ||
int err = _PyList_AppendTakeRefAndLock((PyListObject *)self_o, PyStackRef_AsPyObjectSteal(arg)); | ||
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. I think we should use the I'm a bit uneasy about the critical section after the In other words, this adds a potentially escaping call in a place where we previously didn't have one. The |
||
#else | ||
int err = _PyList_AppendTakeRef((PyListObject *)self_o, PyStackRef_AsPyObjectSteal(arg)); | ||
#endif | ||
PyStackRef_CLOSE(self); | ||
PyStackRef_CLOSE(callable); | ||
ERROR_IF(err, error); | ||
|
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.
I think this should be "release" so that the contents of
init
are visible beforeinit
is written totype->_spec_cache.init
.(There might be other synchronization of the thread-local specialization process that makes relaxed okay, but it seems easier to reason about to me if it's at least "release")