GH-105229: Remove remaining two-codeunit superinstructions (GH-105326)

* Remove LOAD_CONST__LOAD_FAST and LOAD_FAST__LOAD_CONST superinstructions.
This commit is contained in:
Mark Shannon 2023-06-08 12:35:34 +01:00 committed by GitHub
parent 410c2f13e5
commit e830289c52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 523 additions and 626 deletions

View file

@ -233,9 +233,6 @@ dummy_func(
SETLOCAL(oparg2, value2);
}
super(LOAD_FAST__LOAD_CONST) = LOAD_FAST + LOAD_CONST;
super(LOAD_CONST__LOAD_FAST) = LOAD_CONST + LOAD_FAST;
inst(POP_TOP, (value --)) {
DECREF_INPUTS();
}

View file

@ -1676,7 +1676,6 @@ scan_block_for_locals(basicblock *b, basicblock ***sp)
for (int i = 0; i < b->b_iused; i++) {
cfg_instr *instr = &b->b_instr[i];
assert(instr->i_opcode != EXTENDED_ARG);
assert(!IS_SUPERINSTRUCTION_OPCODE(instr->i_opcode));
if (instr->i_except != NULL) {
maybe_push(instr->i_except, unsafe_mask, sp);
}
@ -1735,7 +1734,6 @@ fast_scan_many_locals(basicblock *entryblock, int nlocals)
for (int i = 0; i < b->b_iused; i++) {
cfg_instr *instr = &b->b_instr[i];
assert(instr->i_opcode != EXTENDED_ARG);
assert(!IS_SUPERINSTRUCTION_OPCODE(instr->i_opcode));
int arg = instr->i_oparg;
if (arg < 64) {
continue;

File diff suppressed because it is too large Load diff

View file

@ -1487,17 +1487,6 @@ update_instrumentation_data(PyCodeObject *code, PyInterpreterState *interp)
return 0;
}
static const uint8_t super_instructions[256] = {
[LOAD_FAST__LOAD_CONST] = 1,
[LOAD_CONST__LOAD_FAST] = 1,
};
/* Should use instruction metadata for this */
static bool
is_super_instruction(uint8_t opcode) {
return super_instructions[opcode] != 0;
}
int
_Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
{
@ -1539,9 +1528,6 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
/* Insert instrumentation */
for (int i = 0; i < code_len; i+= _PyInstruction_GetLength(code, i)) {
_Py_CODEUNIT *instr = &_PyCode_CODE(code)[i];
if (is_super_instruction(instr->op.code)) {
instr->op.code = _PyOpcode_Deopt[instr->op.code];
}
CHECK(instr->op.code != 0);
int base_opcode = _Py_GetBaseOpcode(code, i);
if (opcode_has_event(base_opcode)) {

View file

@ -33,10 +33,6 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
return 1;
case STORE_FAST_STORE_FAST:
return 2;
case LOAD_FAST__LOAD_CONST:
return 0+0;
case LOAD_CONST__LOAD_FAST:
return 0+0;
case POP_TOP:
return 1;
case PUSH_NULL:
@ -431,10 +427,6 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
return 1;
case STORE_FAST_STORE_FAST:
return 0;
case LOAD_FAST__LOAD_CONST:
return 1+1;
case LOAD_CONST__LOAD_FAST:
return 1+1;
case POP_TOP:
return 0;
case PUSH_NULL:
@ -799,7 +791,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
}
#endif
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC00, INSTR_FMT_IBC000, INSTR_FMT_IBC00000000, INSTR_FMT_IBIB, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC00, INSTR_FMT_IBC000, INSTR_FMT_IBC00000000, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
struct opcode_metadata {
bool valid_entry;
enum InstructionFormat instr_format;
@ -821,8 +813,6 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
[STORE_FAST] = { true, INSTR_FMT_IB },
[STORE_FAST_LOAD_FAST] = { true, INSTR_FMT_IB },
[STORE_FAST_STORE_FAST] = { true, INSTR_FMT_IB },
[LOAD_FAST__LOAD_CONST] = { true, INSTR_FMT_IBIB },
[LOAD_CONST__LOAD_FAST] = { true, INSTR_FMT_IBIB },
[POP_TOP] = { true, INSTR_FMT_IX },
[PUSH_NULL] = { true, INSTR_FMT_IX },
[END_FOR] = { true, INSTR_FMT_IB },

View file

@ -83,11 +83,11 @@ static void *opcode_targets[256] = {
&&TARGET_LOAD_ATTR_METHOD_NO_DICT,
&&TARGET_LOAD_ATTR_METHOD_WITH_VALUES,
&&TARGET_RETURN_VALUE,
&&TARGET_LOAD_CONST__LOAD_FAST,
&&TARGET_SETUP_ANNOTATIONS,
&&TARGET_LOAD_FAST__LOAD_CONST,
&&TARGET_LOAD_LOCALS,
&&TARGET_LOAD_GLOBAL_BUILTIN,
&&TARGET_SETUP_ANNOTATIONS,
&&TARGET_LOAD_GLOBAL_MODULE,
&&TARGET_LOAD_LOCALS,
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
&&TARGET_POP_EXCEPT,
&&TARGET_STORE_NAME,
&&TARGET_DELETE_NAME,
@ -110,9 +110,9 @@ static void *opcode_targets[256] = {
&&TARGET_IMPORT_NAME,
&&TARGET_IMPORT_FROM,
&&TARGET_JUMP_FORWARD,
&&TARGET_LOAD_GLOBAL_MODULE,
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
&&TARGET_STORE_ATTR_SLOT,
&&TARGET_STORE_ATTR_WITH_HINT,
&&TARGET_STORE_SUBSCR_DICT,
&&TARGET_POP_JUMP_IF_FALSE,
&&TARGET_POP_JUMP_IF_TRUE,
&&TARGET_LOAD_GLOBAL,
@ -147,20 +147,20 @@ static void *opcode_targets[256] = {
&&TARGET_LIST_APPEND,
&&TARGET_SET_ADD,
&&TARGET_MAP_ADD,
&&TARGET_STORE_ATTR_WITH_HINT,
&&TARGET_STORE_SUBSCR_LIST_INT,
&&TARGET_COPY_FREE_VARS,
&&TARGET_YIELD_VALUE,
&&TARGET_RESUME,
&&TARGET_MATCH_CLASS,
&&TARGET_STORE_SUBSCR_DICT,
&&TARGET_STORE_SUBSCR_LIST_INT,
&&TARGET_UNPACK_SEQUENCE_LIST,
&&TARGET_UNPACK_SEQUENCE_TUPLE,
&&TARGET_FORMAT_VALUE,
&&TARGET_BUILD_CONST_KEY_MAP,
&&TARGET_BUILD_STRING,
&&TARGET_UNPACK_SEQUENCE_LIST,
&&TARGET_UNPACK_SEQUENCE_TUPLE,
&&TARGET_UNPACK_SEQUENCE_TWO_TUPLE,
&&TARGET_SEND_GEN,
&&_unknown_opcode,
&&_unknown_opcode,
&&TARGET_LIST_EXTEND,
&&TARGET_SET_UPDATE,
&&TARGET_DICT_MERGE,

View file

@ -273,22 +273,12 @@ _PyCode_Quicken(PyCodeObject *code)
int opcode = 0;
_Py_CODEUNIT *instructions = _PyCode_CODE(code);
for (int i = 0; i < Py_SIZE(code); i++) {
int previous_opcode = opcode;
opcode = _Py_GetBaseOpcode(code, i);
assert(opcode < MIN_INSTRUMENTED_OPCODE);
int caches = _PyOpcode_Caches[opcode];
if (caches) {
instructions[i + 1].cache = adaptive_counter_warmup();
i += caches;
continue;
}
switch (previous_opcode << 8 | opcode) {
case LOAD_CONST << 8 | LOAD_FAST:
instructions[i - 1].op.code = LOAD_CONST__LOAD_FAST;
break;
case LOAD_FAST << 8 | LOAD_CONST:
instructions[i - 1].op.code = LOAD_FAST__LOAD_CONST;
break;
}
}
#endif /* ENABLE_SPECIALIZATION */