Skip to content
Open
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
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

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

2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_ids.h

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

8 changes: 4 additions & 4 deletions Include/internal/pycore_uop_metadata.h

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

21 changes: 21 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,27 @@ class C():
self.assertNotIn("_POP_TOP", uops)
self.assertIn("_POP_TOP_NOP", uops)

def test_load_attr_with_hint(self):
def testfunc(n):
class C:
pass
c = C()
c.x = 42
for i in range(_testinternalcapi.SHARED_KEYS_MAX_SIZE - 1):
setattr(c, f"_{i}", None)
x = 0
for i in range(n):
x += c.x
return x
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, 42 * TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)

self.assertIn("_LOAD_ATTR_WITH_HINT", uops)
self.assertNotIn("_POP_TOP", uops)
self.assertIn("_POP_TOP_NOP", uops)

def test_int_add_op_refcount_elimination(self):
def testfunc(n):
c = 1
Expand Down
6 changes: 4 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2416,7 +2416,7 @@ dummy_func(
unused/5 +
_PUSH_NULL_CONDITIONAL;

op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr)) {
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr, o)) {
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
assert(Py_TYPE(owner_o)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
PyDictObject *dict = _PyObject_GetManagedDict(owner_o);
Expand Down Expand Up @@ -2452,13 +2452,15 @@ dummy_func(
#else
attr = PyStackRef_FromPyObjectNew(attr_o);
#endif
PyStackRef_CLOSE(owner);
o = owner;
DEAD(owner);
}

macro(LOAD_ATTR_WITH_HINT) =
unused/1 +
_GUARD_TYPE_VERSION +
_LOAD_ATTR_WITH_HINT +
POP_TOP +
unused/5 +
_PUSH_NULL_CONDITIONAL;

Expand Down
16 changes: 5 additions & 11 deletions Python/executor_cases.c.h

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

9 changes: 8 additions & 1 deletion Python/generated_cases.c.h

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

3 changes: 2 additions & 1 deletion Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,10 @@ dummy_func(void) {
}
}

op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr)) {
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr, o)) {
attr = sym_new_not_null(ctx);
(void)hint;
o = owner;
}

op(_LOAD_ATTR_SLOT, (index/1, owner -- attr)) {
Expand Down
8 changes: 8 additions & 0 deletions Python/optimizer_cases.c.h

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

Loading