Skip to content
Prev Previous commit
Next Next commit
Modernize LOAD_ATTR_SLOT
  • Loading branch information
gvanrossum committed Feb 1, 2023
commit 2a417e965b25d3fdaea04f4aa30b89f47e3a2434
16 changes: 4 additions & 12 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ dummy_func(
LOAD_ATTR_INSTANCE_VALUE,
LOAD_ATTR_MODULE,
// LOAD_ATTR_PROPERTY,
// LOAD_ATTR_SLOT,
LOAD_ATTR_SLOT,
LOAD_ATTR_WITH_HINT,
// LOAD_ATTR_METHOD_LAZY_DICT,
// LOAD_ATTR_METHOD_NO_DICT,
Expand Down Expand Up @@ -1564,26 +1564,18 @@ dummy_func(
Py_DECREF(owner);
}

// error: LOAD_ATTR has irregular stack effect
inst(LOAD_ATTR_SLOT) {
inst(LOAD_ATTR_SLOT, (unused/1, type_version/2, index/1, unused/5, owner -- res2 if (oparg & 1), res)) {
assert(cframe.use_tracing == 0);
PyObject *owner = TOP();
PyObject *res;
PyTypeObject *tp = Py_TYPE(owner);
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
uint32_t type_version = read_u32(cache->version);
assert(type_version != 0);
DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR);
char *addr = (char *)owner + cache->index;
char *addr = (char *)owner + index;
res = *(PyObject **)addr;
DEOPT_IF(res == NULL, LOAD_ATTR);
STAT_INC(LOAD_ATTR, hit);
Py_INCREF(res);
SET_TOP(NULL);
STACK_GROW((oparg & 1));
SET_TOP(res);
res2 = NULL;
Py_DECREF(owner);
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
}

// error: LOAD_ATTR has irregular stack effect
Expand Down
20 changes: 11 additions & 9 deletions Python/generated_cases.c.h

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

6 changes: 3 additions & 3 deletions Python/opcode_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
case LOAD_ATTR_WITH_HINT:
return 1;
case LOAD_ATTR_SLOT:
return -1;
return 1;
case LOAD_ATTR_CLASS:
return -1;
case LOAD_ATTR_PROPERTY:
Expand Down Expand Up @@ -539,7 +539,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
case LOAD_ATTR_WITH_HINT:
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_SLOT:
return -1;
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_CLASS:
return -1;
case LOAD_ATTR_PROPERTY:
Expand Down Expand Up @@ -795,7 +795,7 @@ struct opcode_metadata {
[LOAD_ATTR_INSTANCE_VALUE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_MODULE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_WITH_HINT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_SLOT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_ATTR_SLOT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
[LOAD_ATTR_CLASS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_ATTR_PROPERTY] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
Expand Down