Skip to content

gh-104909: Make LOAD_ATTR_PROPERTY a viable uop #110560

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 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
Prev Previous commit
Make _LOAD_ATTR_PROPERTY viable; at the cost of hacks
  • Loading branch information
gvanrossum committed Nov 18, 2023
commit 0b71d63562c01f218e1033f4f58b08ae414c209a
1 change: 1 addition & 0 deletions Include/internal/pycore_opcode_metadata.h

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

7 changes: 7 additions & 0 deletions Python/abstract_interp_cases.c.h

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

18 changes: 9 additions & 9 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2021,28 +2021,26 @@ dummy_func(
unused/2 +
_LOAD_ATTR_CLASS;

op(_HELPER_LOAD_FUNC_FROM_CACHE, (fget/4 -- func: PyFunctionObject *)) {
op(_HELPER_LOAD_FUNC_FROM_CACHE, (fget/4 -- func: PyFunctionObject*)) {
assert(Py_IS_TYPE(fget, &PyFunction_Type));
func = (PyFunctionObject *)fget;
}

op(_CHECK_FUNC_VERSION, (func_version/2, func: PyFunctionObject * -- func: PyFunctionObject *)) {
op(_CHECK_FUNC_VERSION, (func_version/2, func: PyFunctionObject* -- func: PyFunctionObject*)) {
assert(func_version != 0);
DEOPT_IF(func->func_version != func_version);
}

op(_LOAD_ATTR_PROPERTY, (owner, func: PyFunctionObject * -- unused, unused if (0))) {
op(_LOAD_ATTR_PROPERTY, (owner, func: PyFunctionObject* -- new_frame: _PyInterpreterFrame*, unused if (0))) {
assert((oparg & 1) == 0);
PyCodeObject *code = (PyCodeObject *)func->func_code;
assert(code->co_argcount == 1);
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize));
STAT_INC(LOAD_ATTR, hit);
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, Py_NewRef(func), 1);
// Manipulate stack directly because we exit with DISPATCH_INLINED().
STACK_SHRINK(1);
Py_INCREF(func);
new_frame = _PyFrame_PushUnchecked(tstate, func, 1);
new_frame->localsplus[0] = owner;
frame->return_offset = (uint16_t)(next_instr - this_instr);
DISPATCH_INLINED(new_frame);
stack_pointer[-1] = (PyObject *)new_frame; // Unfortunately this is needed
}

macro(LOAD_ATTR_PROPERTY) =
Expand All @@ -2051,7 +2049,9 @@ dummy_func(
_GUARD_TYPE_VERSION +
_HELPER_LOAD_FUNC_FROM_CACHE +
_CHECK_FUNC_VERSION +
_LOAD_ATTR_PROPERTY;
_LOAD_ATTR_PROPERTY +
_SAVE_RETURN_OFFSET +
_PUSH_FRAME;

inst(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN, (unused/1, type_version/2, func_version/2, getattribute/4, owner -- unused, unused if (0))) {
assert((oparg & 1) == 0);
Expand Down
20 changes: 20 additions & 0 deletions Python/executor_cases.c.h

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

38 changes: 34 additions & 4 deletions Python/generated_cases.c.h

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

3 changes: 3 additions & 0 deletions Tools/cases_generator/stacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def as_variable(self, lax: bool = False) -> str:
if not lax:
# Check that we're not reading or writing above stack top.
# Skip this for output variable initialization (lax=True).
if not (self.effect in self.offset.deep and not self.offset.high): # DO NOT COMMIT
return res # DO NOT COMMIT
assert (
self.effect in self.offset.deep and not self.offset.high
), f"Push or pop above current stack level: {res}"
Expand Down Expand Up @@ -478,6 +480,7 @@ def write_components(


def assert_no_pokes(managers: list[EffectManager]) -> None:
return # DO NOT COMMIT
for mgr in managers:
for poke in mgr.pokes:
if not poke.effect.size and poke.effect.name not in mgr.instr.unmoved_names:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy