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

@ -172,13 +172,11 @@ const uint8_t _PyOpcode_Deopt[256] = {
[LOAD_BUILD_CLASS] = LOAD_BUILD_CLASS, [LOAD_BUILD_CLASS] = LOAD_BUILD_CLASS,
[LOAD_CLOSURE] = LOAD_CLOSURE, [LOAD_CLOSURE] = LOAD_CLOSURE,
[LOAD_CONST] = LOAD_CONST, [LOAD_CONST] = LOAD_CONST,
[LOAD_CONST__LOAD_FAST] = LOAD_CONST,
[LOAD_DEREF] = LOAD_DEREF, [LOAD_DEREF] = LOAD_DEREF,
[LOAD_FAST] = LOAD_FAST, [LOAD_FAST] = LOAD_FAST,
[LOAD_FAST_AND_CLEAR] = LOAD_FAST_AND_CLEAR, [LOAD_FAST_AND_CLEAR] = LOAD_FAST_AND_CLEAR,
[LOAD_FAST_CHECK] = LOAD_FAST_CHECK, [LOAD_FAST_CHECK] = LOAD_FAST_CHECK,
[LOAD_FAST_LOAD_FAST] = LOAD_FAST_LOAD_FAST, [LOAD_FAST_LOAD_FAST] = LOAD_FAST_LOAD_FAST,
[LOAD_FAST__LOAD_CONST] = LOAD_FAST,
[LOAD_FROM_DICT_OR_DEREF] = LOAD_FROM_DICT_OR_DEREF, [LOAD_FROM_DICT_OR_DEREF] = LOAD_FROM_DICT_OR_DEREF,
[LOAD_FROM_DICT_OR_GLOBALS] = LOAD_FROM_DICT_OR_GLOBALS, [LOAD_FROM_DICT_OR_GLOBALS] = LOAD_FROM_DICT_OR_GLOBALS,
[LOAD_GLOBAL] = LOAD_GLOBAL, [LOAD_GLOBAL] = LOAD_GLOBAL,
@ -331,11 +329,11 @@ static const char *const _PyOpcode_OpName[267] = {
[LOAD_ATTR_METHOD_NO_DICT] = "LOAD_ATTR_METHOD_NO_DICT", [LOAD_ATTR_METHOD_NO_DICT] = "LOAD_ATTR_METHOD_NO_DICT",
[LOAD_ATTR_METHOD_WITH_VALUES] = "LOAD_ATTR_METHOD_WITH_VALUES", [LOAD_ATTR_METHOD_WITH_VALUES] = "LOAD_ATTR_METHOD_WITH_VALUES",
[RETURN_VALUE] = "RETURN_VALUE", [RETURN_VALUE] = "RETURN_VALUE",
[LOAD_CONST__LOAD_FAST] = "LOAD_CONST__LOAD_FAST",
[SETUP_ANNOTATIONS] = "SETUP_ANNOTATIONS",
[LOAD_FAST__LOAD_CONST] = "LOAD_FAST__LOAD_CONST",
[LOAD_LOCALS] = "LOAD_LOCALS",
[LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN", [LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN",
[SETUP_ANNOTATIONS] = "SETUP_ANNOTATIONS",
[LOAD_GLOBAL_MODULE] = "LOAD_GLOBAL_MODULE",
[LOAD_LOCALS] = "LOAD_LOCALS",
[STORE_ATTR_INSTANCE_VALUE] = "STORE_ATTR_INSTANCE_VALUE",
[POP_EXCEPT] = "POP_EXCEPT", [POP_EXCEPT] = "POP_EXCEPT",
[STORE_NAME] = "STORE_NAME", [STORE_NAME] = "STORE_NAME",
[DELETE_NAME] = "DELETE_NAME", [DELETE_NAME] = "DELETE_NAME",
@ -358,9 +356,9 @@ static const char *const _PyOpcode_OpName[267] = {
[IMPORT_NAME] = "IMPORT_NAME", [IMPORT_NAME] = "IMPORT_NAME",
[IMPORT_FROM] = "IMPORT_FROM", [IMPORT_FROM] = "IMPORT_FROM",
[JUMP_FORWARD] = "JUMP_FORWARD", [JUMP_FORWARD] = "JUMP_FORWARD",
[LOAD_GLOBAL_MODULE] = "LOAD_GLOBAL_MODULE",
[STORE_ATTR_INSTANCE_VALUE] = "STORE_ATTR_INSTANCE_VALUE",
[STORE_ATTR_SLOT] = "STORE_ATTR_SLOT", [STORE_ATTR_SLOT] = "STORE_ATTR_SLOT",
[STORE_ATTR_WITH_HINT] = "STORE_ATTR_WITH_HINT",
[STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT",
[POP_JUMP_IF_FALSE] = "POP_JUMP_IF_FALSE", [POP_JUMP_IF_FALSE] = "POP_JUMP_IF_FALSE",
[POP_JUMP_IF_TRUE] = "POP_JUMP_IF_TRUE", [POP_JUMP_IF_TRUE] = "POP_JUMP_IF_TRUE",
[LOAD_GLOBAL] = "LOAD_GLOBAL", [LOAD_GLOBAL] = "LOAD_GLOBAL",
@ -395,20 +393,20 @@ static const char *const _PyOpcode_OpName[267] = {
[LIST_APPEND] = "LIST_APPEND", [LIST_APPEND] = "LIST_APPEND",
[SET_ADD] = "SET_ADD", [SET_ADD] = "SET_ADD",
[MAP_ADD] = "MAP_ADD", [MAP_ADD] = "MAP_ADD",
[STORE_ATTR_WITH_HINT] = "STORE_ATTR_WITH_HINT", [STORE_SUBSCR_LIST_INT] = "STORE_SUBSCR_LIST_INT",
[COPY_FREE_VARS] = "COPY_FREE_VARS", [COPY_FREE_VARS] = "COPY_FREE_VARS",
[YIELD_VALUE] = "YIELD_VALUE", [YIELD_VALUE] = "YIELD_VALUE",
[RESUME] = "RESUME", [RESUME] = "RESUME",
[MATCH_CLASS] = "MATCH_CLASS", [MATCH_CLASS] = "MATCH_CLASS",
[STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT", [UNPACK_SEQUENCE_LIST] = "UNPACK_SEQUENCE_LIST",
[STORE_SUBSCR_LIST_INT] = "STORE_SUBSCR_LIST_INT", [UNPACK_SEQUENCE_TUPLE] = "UNPACK_SEQUENCE_TUPLE",
[FORMAT_VALUE] = "FORMAT_VALUE", [FORMAT_VALUE] = "FORMAT_VALUE",
[BUILD_CONST_KEY_MAP] = "BUILD_CONST_KEY_MAP", [BUILD_CONST_KEY_MAP] = "BUILD_CONST_KEY_MAP",
[BUILD_STRING] = "BUILD_STRING", [BUILD_STRING] = "BUILD_STRING",
[UNPACK_SEQUENCE_LIST] = "UNPACK_SEQUENCE_LIST",
[UNPACK_SEQUENCE_TUPLE] = "UNPACK_SEQUENCE_TUPLE",
[UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE", [UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE",
[SEND_GEN] = "SEND_GEN", [SEND_GEN] = "SEND_GEN",
[160] = "<160>",
[161] = "<161>",
[LIST_EXTEND] = "LIST_EXTEND", [LIST_EXTEND] = "LIST_EXTEND",
[SET_UPDATE] = "SET_UPDATE", [SET_UPDATE] = "SET_UPDATE",
[DICT_MERGE] = "DICT_MERGE", [DICT_MERGE] = "DICT_MERGE",
@ -518,6 +516,8 @@ static const char *const _PyOpcode_OpName[267] = {
#endif #endif
#define EXTRA_CASES \ #define EXTRA_CASES \
case 160: \
case 161: \
case 166: \ case 166: \
case 167: \ case 167: \
case 177: \ case 177: \

View file

@ -55,11 +55,6 @@ extern "C" {
(opcode) == RAISE_VARARGS || \ (opcode) == RAISE_VARARGS || \
(opcode) == RERAISE) (opcode) == RERAISE)
#define IS_SUPERINSTRUCTION_OPCODE(opcode) \
((opcode) == LOAD_FAST__LOAD_CONST || \
(opcode) == LOAD_CONST__LOAD_FAST)
#define LOG_BITS_PER_INT 5 #define LOG_BITS_PER_INT 5
#define MASK_LOW_LOG_BITS 31 #define MASK_LOW_LOG_BITS 31

24
Include/opcode.h generated
View file

@ -204,19 +204,17 @@ extern "C" {
#define LOAD_ATTR_METHOD_LAZY_DICT 80 #define LOAD_ATTR_METHOD_LAZY_DICT 80
#define LOAD_ATTR_METHOD_NO_DICT 81 #define LOAD_ATTR_METHOD_NO_DICT 81
#define LOAD_ATTR_METHOD_WITH_VALUES 82 #define LOAD_ATTR_METHOD_WITH_VALUES 82
#define LOAD_CONST__LOAD_FAST 84 #define LOAD_GLOBAL_BUILTIN 84
#define LOAD_FAST__LOAD_CONST 86 #define LOAD_GLOBAL_MODULE 86
#define LOAD_GLOBAL_BUILTIN 88 #define STORE_ATTR_INSTANCE_VALUE 88
#define LOAD_GLOBAL_MODULE 111 #define STORE_ATTR_SLOT 111
#define STORE_ATTR_INSTANCE_VALUE 112 #define STORE_ATTR_WITH_HINT 112
#define STORE_ATTR_SLOT 113 #define STORE_SUBSCR_DICT 113
#define STORE_ATTR_WITH_HINT 148 #define STORE_SUBSCR_LIST_INT 148
#define STORE_SUBSCR_DICT 153 #define UNPACK_SEQUENCE_LIST 153
#define STORE_SUBSCR_LIST_INT 154 #define UNPACK_SEQUENCE_TUPLE 154
#define UNPACK_SEQUENCE_LIST 158 #define UNPACK_SEQUENCE_TWO_TUPLE 158
#define UNPACK_SEQUENCE_TUPLE 159 #define SEND_GEN 159
#define UNPACK_SEQUENCE_TWO_TUPLE 160
#define SEND_GEN 161
#define HAS_ARG(op) ((((op) >= HAVE_ARGUMENT) && (!IS_PSEUDO_OPCODE(op)))\ #define HAS_ARG(op) ((((op) >= HAVE_ARGUMENT) && (!IS_PSEUDO_OPCODE(op)))\
|| ((op) == JUMP) \ || ((op) == JUMP) \

View file

@ -409,12 +409,6 @@ _specializations = {
"LOAD_ATTR_METHOD_NO_DICT", "LOAD_ATTR_METHOD_NO_DICT",
"LOAD_ATTR_METHOD_WITH_VALUES", "LOAD_ATTR_METHOD_WITH_VALUES",
], ],
"LOAD_CONST": [
"LOAD_CONST__LOAD_FAST",
],
"LOAD_FAST": [
"LOAD_FAST__LOAD_CONST",
],
"LOAD_GLOBAL": [ "LOAD_GLOBAL": [
"LOAD_GLOBAL_BUILTIN", "LOAD_GLOBAL_BUILTIN",
"LOAD_GLOBAL_MODULE", "LOAD_GLOBAL_MODULE",

View file

@ -0,0 +1,3 @@
Remove remaining two-codeunit superinstructions. All remaining
superinstructions only take a single codeunit, simplifying instrumentation
and quickening.

View file

@ -233,9 +233,6 @@ dummy_func(
SETLOCAL(oparg2, value2); 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 --)) { inst(POP_TOP, (value --)) {
DECREF_INPUTS(); 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++) { for (int i = 0; i < b->b_iused; i++) {
cfg_instr *instr = &b->b_instr[i]; cfg_instr *instr = &b->b_instr[i];
assert(instr->i_opcode != EXTENDED_ARG); assert(instr->i_opcode != EXTENDED_ARG);
assert(!IS_SUPERINSTRUCTION_OPCODE(instr->i_opcode));
if (instr->i_except != NULL) { if (instr->i_except != NULL) {
maybe_push(instr->i_except, unsafe_mask, sp); 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++) { for (int i = 0; i < b->b_iused; i++) {
cfg_instr *instr = &b->b_instr[i]; cfg_instr *instr = &b->b_instr[i];
assert(instr->i_opcode != EXTENDED_ARG); assert(instr->i_opcode != EXTENDED_ARG);
assert(!IS_SUPERINSTRUCTION_OPCODE(instr->i_opcode));
int arg = instr->i_oparg; int arg = instr->i_oparg;
if (arg < 64) { if (arg < 64) {
continue; 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; 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 int
_Py_Instrument(PyCodeObject *code, PyInterpreterState *interp) _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
{ {
@ -1539,9 +1528,6 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
/* Insert instrumentation */ /* Insert instrumentation */
for (int i = 0; i < code_len; i+= _PyInstruction_GetLength(code, i)) { for (int i = 0; i < code_len; i+= _PyInstruction_GetLength(code, i)) {
_Py_CODEUNIT *instr = &_PyCode_CODE(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); CHECK(instr->op.code != 0);
int base_opcode = _Py_GetBaseOpcode(code, i); int base_opcode = _Py_GetBaseOpcode(code, i);
if (opcode_has_event(base_opcode)) { if (opcode_has_event(base_opcode)) {

View file

@ -33,10 +33,6 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
return 1; return 1;
case STORE_FAST_STORE_FAST: case STORE_FAST_STORE_FAST:
return 2; return 2;
case LOAD_FAST__LOAD_CONST:
return 0+0;
case LOAD_CONST__LOAD_FAST:
return 0+0;
case POP_TOP: case POP_TOP:
return 1; return 1;
case PUSH_NULL: case PUSH_NULL:
@ -431,10 +427,6 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
return 1; return 1;
case STORE_FAST_STORE_FAST: case STORE_FAST_STORE_FAST:
return 0; return 0;
case LOAD_FAST__LOAD_CONST:
return 1+1;
case LOAD_CONST__LOAD_FAST:
return 1+1;
case POP_TOP: case POP_TOP:
return 0; return 0;
case PUSH_NULL: case PUSH_NULL:
@ -799,7 +791,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
} }
#endif #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 { struct opcode_metadata {
bool valid_entry; bool valid_entry;
enum InstructionFormat instr_format; enum InstructionFormat instr_format;
@ -821,8 +813,6 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
[STORE_FAST] = { true, INSTR_FMT_IB }, [STORE_FAST] = { true, INSTR_FMT_IB },
[STORE_FAST_LOAD_FAST] = { true, INSTR_FMT_IB }, [STORE_FAST_LOAD_FAST] = { true, INSTR_FMT_IB },
[STORE_FAST_STORE_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 }, [POP_TOP] = { true, INSTR_FMT_IX },
[PUSH_NULL] = { true, INSTR_FMT_IX }, [PUSH_NULL] = { true, INSTR_FMT_IX },
[END_FOR] = { true, INSTR_FMT_IB }, [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_NO_DICT,
&&TARGET_LOAD_ATTR_METHOD_WITH_VALUES, &&TARGET_LOAD_ATTR_METHOD_WITH_VALUES,
&&TARGET_RETURN_VALUE, &&TARGET_RETURN_VALUE,
&&TARGET_LOAD_CONST__LOAD_FAST,
&&TARGET_SETUP_ANNOTATIONS,
&&TARGET_LOAD_FAST__LOAD_CONST,
&&TARGET_LOAD_LOCALS,
&&TARGET_LOAD_GLOBAL_BUILTIN, &&TARGET_LOAD_GLOBAL_BUILTIN,
&&TARGET_SETUP_ANNOTATIONS,
&&TARGET_LOAD_GLOBAL_MODULE,
&&TARGET_LOAD_LOCALS,
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
&&TARGET_POP_EXCEPT, &&TARGET_POP_EXCEPT,
&&TARGET_STORE_NAME, &&TARGET_STORE_NAME,
&&TARGET_DELETE_NAME, &&TARGET_DELETE_NAME,
@ -110,9 +110,9 @@ static void *opcode_targets[256] = {
&&TARGET_IMPORT_NAME, &&TARGET_IMPORT_NAME,
&&TARGET_IMPORT_FROM, &&TARGET_IMPORT_FROM,
&&TARGET_JUMP_FORWARD, &&TARGET_JUMP_FORWARD,
&&TARGET_LOAD_GLOBAL_MODULE,
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
&&TARGET_STORE_ATTR_SLOT, &&TARGET_STORE_ATTR_SLOT,
&&TARGET_STORE_ATTR_WITH_HINT,
&&TARGET_STORE_SUBSCR_DICT,
&&TARGET_POP_JUMP_IF_FALSE, &&TARGET_POP_JUMP_IF_FALSE,
&&TARGET_POP_JUMP_IF_TRUE, &&TARGET_POP_JUMP_IF_TRUE,
&&TARGET_LOAD_GLOBAL, &&TARGET_LOAD_GLOBAL,
@ -147,20 +147,20 @@ static void *opcode_targets[256] = {
&&TARGET_LIST_APPEND, &&TARGET_LIST_APPEND,
&&TARGET_SET_ADD, &&TARGET_SET_ADD,
&&TARGET_MAP_ADD, &&TARGET_MAP_ADD,
&&TARGET_STORE_ATTR_WITH_HINT, &&TARGET_STORE_SUBSCR_LIST_INT,
&&TARGET_COPY_FREE_VARS, &&TARGET_COPY_FREE_VARS,
&&TARGET_YIELD_VALUE, &&TARGET_YIELD_VALUE,
&&TARGET_RESUME, &&TARGET_RESUME,
&&TARGET_MATCH_CLASS, &&TARGET_MATCH_CLASS,
&&TARGET_STORE_SUBSCR_DICT, &&TARGET_UNPACK_SEQUENCE_LIST,
&&TARGET_STORE_SUBSCR_LIST_INT, &&TARGET_UNPACK_SEQUENCE_TUPLE,
&&TARGET_FORMAT_VALUE, &&TARGET_FORMAT_VALUE,
&&TARGET_BUILD_CONST_KEY_MAP, &&TARGET_BUILD_CONST_KEY_MAP,
&&TARGET_BUILD_STRING, &&TARGET_BUILD_STRING,
&&TARGET_UNPACK_SEQUENCE_LIST,
&&TARGET_UNPACK_SEQUENCE_TUPLE,
&&TARGET_UNPACK_SEQUENCE_TWO_TUPLE, &&TARGET_UNPACK_SEQUENCE_TWO_TUPLE,
&&TARGET_SEND_GEN, &&TARGET_SEND_GEN,
&&_unknown_opcode,
&&_unknown_opcode,
&&TARGET_LIST_EXTEND, &&TARGET_LIST_EXTEND,
&&TARGET_SET_UPDATE, &&TARGET_SET_UPDATE,
&&TARGET_DICT_MERGE, &&TARGET_DICT_MERGE,

View file

@ -273,22 +273,12 @@ _PyCode_Quicken(PyCodeObject *code)
int opcode = 0; int opcode = 0;
_Py_CODEUNIT *instructions = _PyCode_CODE(code); _Py_CODEUNIT *instructions = _PyCode_CODE(code);
for (int i = 0; i < Py_SIZE(code); i++) { for (int i = 0; i < Py_SIZE(code); i++) {
int previous_opcode = opcode;
opcode = _Py_GetBaseOpcode(code, i); opcode = _Py_GetBaseOpcode(code, i);
assert(opcode < MIN_INSTRUMENTED_OPCODE); assert(opcode < MIN_INSTRUMENTED_OPCODE);
int caches = _PyOpcode_Caches[opcode]; int caches = _PyOpcode_Caches[opcode];
if (caches) { if (caches) {
instructions[i + 1].cache = adaptive_counter_warmup(); instructions[i + 1].cache = adaptive_counter_warmup();
i += caches; 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 */ #endif /* ENABLE_SPECIALIZATION */