Skip to content

Commit d25c24a

Browse files
committed
Modernize LOAD_ATTR_SLOT
1 parent 91c5802 commit d25c24a

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

Python/bytecodes.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ dummy_func(
14431443
LOAD_ATTR_INSTANCE_VALUE,
14441444
LOAD_ATTR_MODULE,
14451445
// LOAD_ATTR_PROPERTY,
1446-
// LOAD_ATTR_SLOT,
1446+
LOAD_ATTR_SLOT,
14471447
LOAD_ATTR_WITH_HINT,
14481448
// LOAD_ATTR_METHOD_LAZY_DICT,
14491449
// LOAD_ATTR_METHOD_NO_DICT,
@@ -1564,26 +1564,18 @@ dummy_func(
15641564
Py_DECREF(owner);
15651565
}
15661566

1567-
// error: LOAD_ATTR has irregular stack effect
1568-
inst(LOAD_ATTR_SLOT) {
1567+
inst(LOAD_ATTR_SLOT, (unused/1, type_version/2, index/1, unused/5, owner -- res2 if (oparg & 1), res)) {
15691568
assert(cframe.use_tracing == 0);
1570-
PyObject *owner = TOP();
1571-
PyObject *res;
15721569
PyTypeObject *tp = Py_TYPE(owner);
1573-
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
1574-
uint32_t type_version = read_u32(cache->version);
15751570
assert(type_version != 0);
15761571
DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR);
1577-
char *addr = (char *)owner + cache->index;
1572+
char *addr = (char *)owner + index;
15781573
res = *(PyObject **)addr;
15791574
DEOPT_IF(res == NULL, LOAD_ATTR);
15801575
STAT_INC(LOAD_ATTR, hit);
15811576
Py_INCREF(res);
1582-
SET_TOP(NULL);
1583-
STACK_GROW((oparg & 1));
1584-
SET_TOP(res);
1577+
res2 = NULL;
15851578
Py_DECREF(owner);
1586-
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
15871579
}
15881580

15891581
// error: LOAD_ATTR has irregular stack effect

Python/generated_cases.c.h

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

Python/opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
193193
case LOAD_ATTR_WITH_HINT:
194194
return 1;
195195
case LOAD_ATTR_SLOT:
196-
return -1;
196+
return 1;
197197
case LOAD_ATTR_CLASS:
198198
return -1;
199199
case LOAD_ATTR_PROPERTY:
@@ -539,7 +539,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
539539
case LOAD_ATTR_WITH_HINT:
540540
return ((oparg & 1) ? 1 : 0) + 1;
541541
case LOAD_ATTR_SLOT:
542-
return -1;
542+
return ((oparg & 1) ? 1 : 0) + 1;
543543
case LOAD_ATTR_CLASS:
544544
return -1;
545545
case LOAD_ATTR_PROPERTY:
@@ -795,7 +795,7 @@ struct opcode_metadata {
795795
[LOAD_ATTR_INSTANCE_VALUE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
796796
[LOAD_ATTR_MODULE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
797797
[LOAD_ATTR_WITH_HINT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
798-
[LOAD_ATTR_SLOT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
798+
[LOAD_ATTR_SLOT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
799799
[LOAD_ATTR_CLASS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
800800
[LOAD_ATTR_PROPERTY] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
801801
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },

0 commit comments

Comments
 (0)