Thanks to visit codestin.com
Credit goes to github.com

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 all commits
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
9 changes: 8 additions & 1 deletion Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,15 @@ typedef struct {
uint16_t descr[4];
} _PyLoadMethodCache;

typedef struct {
uint16_t counter;
uint16_t type_version[2];
uint16_t func[4];
uint16_t func_version[2];
} _PyLoadPropertyCache;


// MUST be the max(_PyAttrCache, _PyLoadMethodCache)
// MUST be max(_PyAttrCache, _PyLoadMethodCache, _PyLoadPropertyCache)
#define INLINE_CACHE_ENTRIES_LOAD_ATTR CACHE_ENTRIES(_PyLoadMethodCache)

#define INLINE_CACHE_ENTRIES_STORE_ATTR CACHE_ENTRIES(_PyAttrCache)
Expand Down
120 changes: 71 additions & 49 deletions Include/internal/pycore_opcode_metadata.h

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

17 changes: 17 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.

40 changes: 24 additions & 16 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2021,30 +2021,38 @@ dummy_func(
unused/2 +
_LOAD_ATTR_CLASS;

inst(LOAD_ATTR_PROPERTY, (unused/1, type_version/2, func_version/2, fget/4, owner -- unused, unused if (0))) {
assert((oparg & 1) == 0);
DEOPT_IF(tstate->interp->eval_frame);

PyTypeObject *cls = Py_TYPE(owner);
assert(type_version != 0);
DEOPT_IF(cls->tp_version_tag != type_version);
op(_HELPER_LOAD_FUNC_FROM_CACHE, (fget/4 -- func: PyFunctionObject*)) {
assert(Py_IS_TYPE(fget, &PyFunction_Type));
PyFunctionObject *f = (PyFunctionObject *)fget;
func = (PyFunctionObject *)fget;
}

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

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);
Py_INCREF(fget);
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 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) =
unused/1 +
_CHECK_PEP_523 +
_GUARD_TYPE_VERSION +
_HELPER_LOAD_FUNC_FROM_CACHE +
_CHECK_FUNC_VERSION +
_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);
DEOPT_IF(tstate->interp->eval_frame);
Expand Down
39 changes: 39 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.

Loading