-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-130704: Strength reduce LOAD_FAST{_LOAD_FAST}
#130708
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 51 commits
d716faa
3736923
7a14254
b1607aa
e765735
291ace9
17d6dd6
0a74052
afbfd88
696c630
483ac7a
259d5db
aeafa98
85f9a64
b6ab2f7
fd1ad3d
eee2195
d75ec9a
66f5351
7ef6a0b
2af2bbc
bf19b7d
a9bca03
293c317
a12ccd9
1ef26c5
1eb9226
7291c49
90bf8df
9bfa922
bf6222b
dd97d0c
6680709
6568fd9
6fde7b0
de13810
fdeae7d
1aed281
c332912
76a75a7
dd6426f
bf68eb9
474a587
4b3aacf
e692037
2ecfe08
f98d91d
725dc8e
03d35b2
39ff3f0
f012a9f
b4b7f73
8ea82b5
9bec9f5
902ae84
b0ea38f
1f5cfcd
d1e8e45
00c95cc
cc01a30
6c5faab
32bd0c6
fdb8a82
a962017
6c2f07d
85b0b00
5ff2dea
0c1e67f
ae2ec65
03c474e
60665c9
ac8940b
f12573f
44f7ffc
818e94e
c30e1e9
112cee6
80fc5aa
492cce1
2e38f0d
2c55722
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,12 @@ PyStackRef_IsNone(_PyStackRef ref) | |
return _Py_stackref_get_object(ref) == Py_None; | ||
} | ||
|
||
static inline bool | ||
PyStackRef_IsBorrowed(_PyStackRef ref) | ||
|
||
{ | ||
return false; | ||
} | ||
|
||
static inline PyObject * | ||
_PyStackRef_AsPyObjectBorrow(_PyStackRef ref, const char *filename, int linenumber) | ||
{ | ||
|
@@ -146,6 +152,12 @@ PyStackRef_CLOSE(_PyStackRef ref) | |
Py_DECREF(obj); | ||
} | ||
|
||
static inline _PyStackRef | ||
_PyStackRef_NewIfBorrowedOrSteal(_PyStackRef ref) | ||
|
||
{ | ||
return ref; | ||
} | ||
|
||
static inline _PyStackRef | ||
_PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber) | ||
{ | ||
|
@@ -213,6 +225,27 @@ _PyStackRef_FromPyObjectSteal(PyObject *obj) | |
} | ||
# define PyStackRef_FromPyObjectSteal(obj) _PyStackRef_FromPyObjectSteal(_PyObject_CAST(obj)) | ||
|
||
static inline bool | ||
PyStackRef_IsBorrowed(_PyStackRef stackref) | ||
mpage marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
if (PyStackRef_IsNull(stackref) || !PyStackRef_IsDeferred(stackref)) { | ||
return false; | ||
} | ||
PyObject *obj = PyStackRef_AsPyObjectBorrow(stackref); | ||
return !(_Py_IsImmortal(obj) || _PyObject_HasDeferredRefcount(obj)); | ||
mpage marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
|
||
static inline _PyStackRef | ||
_PyStackRef_NewIfBorrowedOrSteal(_PyStackRef stackref) | ||
{ | ||
if (PyStackRef_IsBorrowed(stackref)) { | ||
PyObject *obj = PyStackRef_AsPyObjectBorrow(stackref); | ||
return (_PyStackRef){ .bits = (uintptr_t)(Py_NewRef(obj)) | Py_TAG_PTR }; | ||
} | ||
return stackref; | ||
} | ||
|
||
static inline _PyStackRef | ||
PyStackRef_FromPyObjectNew(PyObject *obj) | ||
{ | ||
|
@@ -253,15 +286,18 @@ PyStackRef_DUP(_PyStackRef stackref) | |
{ | ||
assert(!PyStackRef_IsNull(stackref)); | ||
if (PyStackRef_IsDeferred(stackref)) { | ||
assert(_Py_IsImmortal(PyStackRef_AsPyObjectBorrow(stackref)) || | ||
_PyObject_HasDeferredRefcount(PyStackRef_AsPyObjectBorrow(stackref)) | ||
); | ||
return stackref; | ||
} | ||
Py_INCREF(PyStackRef_AsPyObjectBorrow(stackref)); | ||
return stackref; | ||
} | ||
|
||
static inline _PyStackRef | ||
PyStackRef_AsDeferred(_PyStackRef stackref) | ||
mpage marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
return (_PyStackRef){ .bits = stackref.bits | Py_TAG_DEFERRED }; | ||
} | ||
|
||
// Convert a possibly deferred reference to a strong reference. | ||
static inline _PyStackRef | ||
PyStackRef_AsStrongReference(_PyStackRef stackref) | ||
|
@@ -280,6 +316,7 @@ static const _PyStackRef PyStackRef_NULL = { .bits = 0 }; | |
#define PyStackRef_True ((_PyStackRef){.bits = (uintptr_t)&_Py_TrueStruct }) | ||
#define PyStackRef_False ((_PyStackRef){.bits = ((uintptr_t)&_Py_FalseStruct) }) | ||
#define PyStackRef_None ((_PyStackRef){.bits = ((uintptr_t)&_Py_NoneStruct) }) | ||
#define PyStackRef_IsBorrowed(stackref) false | ||
|
||
#define PyStackRef_AsPyObjectBorrow(stackref) ((PyObject *)(stackref).bits) | ||
|
||
|
@@ -295,6 +332,8 @@ static const _PyStackRef PyStackRef_NULL = { .bits = 0 }; | |
|
||
#define PyStackRef_DUP(stackref) PyStackRef_FromPyObjectSteal(Py_NewRef(PyStackRef_AsPyObjectBorrow(stackref))) | ||
|
||
#define _PyStackRef_NewIfBorrowedOrSteal(stackref) stackref | ||
|
||
#define PyStackRef_CLOSE_SPECIALIZED(stackref, dealloc) _Py_DECREF_SPECIALIZED(PyStackRef_AsPyObjectBorrow(stackref), dealloc) | ||
|
||
#endif // Py_GIL_DISABLED | ||
|
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.
We don't tend to expose individual peephole optimisations, we test them through OptimizeCFG (see DirectCfgOptimizerTests). Is there a reason why you can't do that for this optimization?
Uh oh!
There was an error while loading. Please reload this page.
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.
Sure, I can add a call to
optimize_load_fast
into_PyCompile_OptimizeCFG
. I wasn't sure if_PyCompile_OptimizeCFG
was intended to only test_PyCfg_OptimizeCodeUnit
. We want this pass to be called as late as possible in compilation, which is why it is called in_PyCfg_OptimizedCfgToInstructionSequence
instead of_PyCfg_OptimizeCodeUnit
.