-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
GH-128685: Specialize (rather than quicken) LOAD_CONST into LOAD_CONST_[IM]MORTAL #128708
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 all commits
e7a7f22
043f978
d342864
6cc0241
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.
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 | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -285,11 +285,25 @@ dummy_func( | |||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
family(LOAD_CONST, 0) = { | ||||||||||||||||||||||||||||||||||||||||||
LOAD_CONST_MORTAL, | ||||||||||||||||||||||||||||||||||||||||||
LOAD_CONST_IMMORTAL, | ||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
pure inst(LOAD_CONST, (-- value)) { | ||||||||||||||||||||||||||||||||||||||||||
value = PyStackRef_FromPyObjectNew(GETITEM(FRAME_CO_CONSTS, oparg)); | ||||||||||||||||||||||||||||||||||||||||||
inst(LOAD_CONST, (-- value)) { | ||||||||||||||||||||||||||||||||||||||||||
/* We can't do this in the bytecode compiler as | ||||||||||||||||||||||||||||||||||||||||||
* marshalling can intern strings and make them immortal. */ | ||||||||||||||||||||||||||||||||||||||||||
PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg); | ||||||||||||||||||||||||||||||||||||||||||
value = PyStackRef_FromPyObjectNew(obj); | ||||||||||||||||||||||||||||||||||||||||||
#if ENABLE_SPECIALIZATION | ||||||||||||||||||||||||||||||||||||||||||
if (this_instr->op.code == LOAD_CONST) { | ||||||||||||||||||||||||||||||||||||||||||
this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+292
to
+302
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. Why the check for Also, minor, but maybe a bit more idiomatic with the rest of the bytecode definitions to split the specializing part out and reuse the code for loading the const? I think this would also make
Suggested change
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.
Instrumentation. The opcode might be 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.
The specializing part needs to load the value to test it, so separating out the specialization just duplicates that. |
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
inst(LOAD_CONST_MORTAL, (-- value)) { | ||||||||||||||||||||||||||||||||||||||||||
PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg); | ||||||||||||||||||||||||||||||||||||||||||
value = PyStackRef_FromPyObjectNew(obj); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
inst(LOAD_CONST_IMMORTAL, (-- value)) { | ||||||||||||||||||||||||||||||||||||||||||
|
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.
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.
This is a specialization, right? So we shouldn't need a magic bump (since the specialized variants don't occur in marshalled data).
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.
Adding the extra instruction changes the allocated numbers for other instructions.
Even if it isn't absolutely necessary, it is harmless.