Skip to content

Commit e5a7ae9

Browse files
committed
Pass dict from _CHECK_ATTR_WITH_HINT to _LOAD_ATTR_WITH_HINT
1 parent 35b31c6 commit e5a7ae9

File tree

7 files changed

+75
-43
lines changed

7 files changed

+75
-43
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
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: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,51 +2213,60 @@ dummy_func(
22132213
_LOAD_ATTR_MODULE_FROM_KEYS +
22142214
unused/5;
22152215

2216-
op(_CHECK_ATTR_WITH_HINT, (owner -- owner)) {
2216+
op(_CHECK_ATTR_WITH_HINT, (owner -- owner, dict: PyDictObject *)) {
22172217
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
22182218

22192219
assert(Py_TYPE(owner_o)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
2220-
PyDictObject *dict = _PyObject_GetManagedDict(owner_o);
2221-
EXIT_IF(dict == NULL);
2222-
assert(PyDict_CheckExact((PyObject *)dict));
2220+
PyDictObject *dict_o = _PyObject_GetManagedDict(owner_o);
2221+
EXIT_IF(dict_o == NULL);
2222+
assert(PyDict_CheckExact((PyObject *)dict_o));
2223+
dict = dict_o;
22232224
}
22242225

2225-
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr, null if (oparg & 1))) {
2226+
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner, dict: PyDictObject * -- attr, null if (oparg & 1))) {
22262227
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
22272228
PyObject *attr_o;
22282229

2229-
PyDictObject *dict = _PyObject_GetManagedDict(owner_o);
2230-
DEOPT_IF(!LOCK_OBJECT(dict));
2231-
#ifdef Py_GIL_DISABLED
2232-
if (dict != _PyObject_GetManagedDict(owner_o)) {
2233-
UNLOCK_OBJECT(dict);
2230+
if (!LOCK_OBJECT(dict)) {
2231+
DEAD(dict);
2232+
POP_DEAD_INPUTS();
22342233
DEOPT_IF(true);
22352234
}
2236-
#endif
2235+
22372236
if (hint >= (size_t)dict->ma_keys->dk_nentries) {
22382237
UNLOCK_OBJECT(dict);
2238+
DEAD(dict);
2239+
POP_DEAD_INPUTS();
22392240
DEOPT_IF(true);
22402241
}
22412242
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
22422243
if (dict->ma_keys->dk_kind != DICT_KEYS_UNICODE) {
22432244
UNLOCK_OBJECT(dict);
2245+
DEAD(dict);
2246+
POP_DEAD_INPUTS();
22442247
DEOPT_IF(true);
22452248
}
22462249
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
22472250
if (ep->me_key != name) {
22482251
UNLOCK_OBJECT(dict);
2252+
DEAD(dict);
2253+
POP_DEAD_INPUTS();
22492254
DEOPT_IF(true);
22502255
}
22512256
attr_o = ep->me_value;
22522257
if (attr_o == NULL) {
22532258
UNLOCK_OBJECT(dict);
2259+
DEAD(dict);
2260+
POP_DEAD_INPUTS();
22542261
DEOPT_IF(true);
22552262
}
22562263
STAT_INC(LOAD_ATTR, hit);
22572264
attr = PyStackRef_FromPyObjectNew(attr_o);
22582265
UNLOCK_OBJECT(dict);
2266+
DEAD(dict);
22592267
null = PyStackRef_NULL;
2260-
DECREF_INPUTS();
2268+
PyStackRef_CLOSE(owner);
2269+
INPUTS_DEAD();
22612270
}
22622271

22632272
macro(LOAD_ATTR_WITH_HINT) =

Python/executor_cases.c.h

Lines changed: 24 additions & 15 deletions
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: 6 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_bytecodes.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,17 @@ dummy_func(void) {
542542
}
543543
}
544544

545-
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr, null if (oparg & 1))) {
545+
op(_CHECK_ATTR_WITH_HINT, (owner -- owner, dict)) {
546+
dict = sym_new_not_null(ctx);
547+
(void)owner;
548+
}
549+
550+
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner, dict -- attr, null if (oparg & 1))) {
546551
attr = sym_new_not_null(ctx);
547552
null = sym_new_null(ctx);
548553
(void)hint;
549554
(void)owner;
555+
(void)dict;
550556
}
551557

552558
op(_LOAD_ATTR_SLOT, (index/1, owner -- attr, null if (oparg & 1))) {

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)