Skip to content

Commit 5f60011

Browse files
authored
GH-118093: Add tier two support for LOAD_ATTR_PROPERTY (GH-122283)
1 parent 5e686ff commit 5f60011

File tree

9 files changed

+168
-99
lines changed

9 files changed

+168
-99
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 49 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,32 +2243,30 @@ dummy_func(
22432243
unused/2 +
22442244
_LOAD_ATTR_CLASS;
22452245

2246-
inst(LOAD_ATTR_PROPERTY, (unused/1, type_version/2, func_version/2, fget/4, owner -- unused, unused if (0))) {
2247-
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
2248-
2246+
op(_LOAD_ATTR_PROPERTY_FRAME, (fget/4, owner -- new_frame: _PyInterpreterFrame *)) {
22492247
assert((oparg & 1) == 0);
2250-
DEOPT_IF(tstate->interp->eval_frame);
2251-
2252-
PyTypeObject *cls = Py_TYPE(owner_o);
2253-
assert(type_version != 0);
2254-
DEOPT_IF(cls->tp_version_tag != type_version);
22552248
assert(Py_IS_TYPE(fget, &PyFunction_Type));
22562249
PyFunctionObject *f = (PyFunctionObject *)fget;
2257-
assert(func_version != 0);
2258-
DEOPT_IF(f->func_version != func_version);
22592250
PyCodeObject *code = (PyCodeObject *)f->func_code;
2260-
assert(code->co_argcount == 1);
2251+
DEOPT_IF((code->co_flags & (CO_VARKEYWORDS | CO_VARARGS | CO_OPTIMIZED)) != CO_OPTIMIZED);
2252+
DEOPT_IF(code->co_kwonlyargcount);
2253+
DEOPT_IF(code->co_argcount != 1);
22612254
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize));
22622255
STAT_INC(LOAD_ATTR, hit);
22632256
Py_INCREF(fget);
2264-
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 1);
2265-
// Manipulate stack directly because we exit with DISPATCH_INLINED().
2266-
STACK_SHRINK(1);
2257+
new_frame = _PyFrame_PushUnchecked(tstate, f, 1);
22672258
new_frame->localsplus[0] = owner;
2268-
frame->return_offset = (uint16_t)(next_instr - this_instr);
2269-
DISPATCH_INLINED(new_frame);
22702259
}
22712260

2261+
macro(LOAD_ATTR_PROPERTY) =
2262+
unused/1 +
2263+
_CHECK_PEP_523 +
2264+
_GUARD_TYPE_VERSION +
2265+
unused/2 +
2266+
_LOAD_ATTR_PROPERTY_FRAME +
2267+
_SAVE_RETURN_OFFSET +
2268+
_PUSH_FRAME;
2269+
22722270
inst(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN, (unused/1, type_version/2, func_version/2, getattribute/4, owner -- unused, unused if (0))) {
22732271
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
22742272

Python/executor_cases.c.h

Lines changed: 33 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 55 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,10 @@ translate_bytecode_to_trace(
797797

798798
if (uop == _PUSH_FRAME) {
799799
assert(i + 1 == nuops);
800-
if (opcode == FOR_ITER_GEN || opcode == SEND_GEN) {
800+
if (opcode == FOR_ITER_GEN ||
801+
opcode == LOAD_ATTR_PROPERTY ||
802+
opcode == SEND_GEN)
803+
{
801804
DPRINTF(2, "Bailing due to dynamic target\n");
802805
ADD_TO_TRACE(uop, oparg, 0, target);
803806
ADD_TO_TRACE(_DYNAMIC_EXIT, 0, 0, 0);

0 commit comments

Comments
 (0)