gh-119676: remove several pseudo instructions which are use only in codegen (#119677)

This commit is contained in:
Irit Katriel 2024-05-28 20:05:38 +01:00 committed by GitHub
parent 6b240c2308
commit ae9140f32a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 71 deletions

View File

@ -20,10 +20,6 @@ extern "C" {
#define IS_PSEUDO_INSTR(OP) ( \
((OP) == LOAD_CLOSURE) || \
((OP) == STORE_FAST_MAYBE_NULL) || \
((OP) == LOAD_SUPER_METHOD) || \
((OP) == LOAD_ZERO_SUPER_METHOD) || \
((OP) == LOAD_ZERO_SUPER_ATTR) || \
((OP) == LOAD_METHOD) || \
((OP) == JUMP) || \
((OP) == JUMP_NO_INTERRUPT) || \
((OP) == SETUP_FINALLY) || \
@ -912,7 +908,7 @@ enum InstructionFormat {
};
#define IS_VALID_OPCODE(OP) \
(((OP) >= 0) && ((OP) < 268) && \
(((OP) >= 0) && ((OP) < 264) && \
(_PyOpcode_opcode_metadata[(OP)].valid_entry))
#define HAS_ARG_FLAG (1)
@ -961,9 +957,9 @@ struct opcode_metadata {
int16_t flags;
};
extern const struct opcode_metadata _PyOpcode_opcode_metadata[268];
extern const struct opcode_metadata _PyOpcode_opcode_metadata[264];
#ifdef NEED_OPCODE_METADATA
const struct opcode_metadata _PyOpcode_opcode_metadata[268] = {
const struct opcode_metadata _PyOpcode_opcode_metadata[264] = {
[BEFORE_ASYNC_WITH] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG },
[BEFORE_WITH] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG },
[BINARY_OP] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
@ -1178,10 +1174,6 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[268] = {
[JUMP] = { true, -1, HAS_ARG_FLAG | HAS_JUMP_FLAG | HAS_EVAL_BREAK_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[JUMP_NO_INTERRUPT] = { true, -1, HAS_ARG_FLAG | HAS_JUMP_FLAG },
[LOAD_CLOSURE] = { true, -1, HAS_ARG_FLAG | HAS_LOCAL_FLAG | HAS_PURE_FLAG },
[LOAD_METHOD] = { true, -1, HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[LOAD_SUPER_METHOD] = { true, -1, HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[LOAD_ZERO_SUPER_ATTR] = { true, -1, HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[LOAD_ZERO_SUPER_METHOD] = { true, -1, HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[POP_BLOCK] = { true, -1, HAS_PURE_FLAG },
[SETUP_CLEANUP] = { true, -1, HAS_PURE_FLAG | HAS_ARG_FLAG },
[SETUP_FINALLY] = { true, -1, HAS_PURE_FLAG | HAS_ARG_FLAG },
@ -1364,9 +1356,9 @@ _PyOpcode_macro_expansion[256] = {
};
#endif // NEED_OPCODE_METADATA
extern const char *_PyOpcode_OpName[268];
extern const char *_PyOpcode_OpName[264];
#ifdef NEED_OPCODE_METADATA
const char *_PyOpcode_OpName[268] = {
const char *_PyOpcode_OpName[264] = {
[BEFORE_ASYNC_WITH] = "BEFORE_ASYNC_WITH",
[BEFORE_WITH] = "BEFORE_WITH",
[BINARY_OP] = "BINARY_OP",
@ -1516,14 +1508,10 @@ const char *_PyOpcode_OpName[268] = {
[LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN",
[LOAD_GLOBAL_MODULE] = "LOAD_GLOBAL_MODULE",
[LOAD_LOCALS] = "LOAD_LOCALS",
[LOAD_METHOD] = "LOAD_METHOD",
[LOAD_NAME] = "LOAD_NAME",
[LOAD_SUPER_ATTR] = "LOAD_SUPER_ATTR",
[LOAD_SUPER_ATTR_ATTR] = "LOAD_SUPER_ATTR_ATTR",
[LOAD_SUPER_ATTR_METHOD] = "LOAD_SUPER_ATTR_METHOD",
[LOAD_SUPER_METHOD] = "LOAD_SUPER_METHOD",
[LOAD_ZERO_SUPER_ATTR] = "LOAD_ZERO_SUPER_ATTR",
[LOAD_ZERO_SUPER_METHOD] = "LOAD_ZERO_SUPER_METHOD",
[MAKE_CELL] = "MAKE_CELL",
[MAKE_FUNCTION] = "MAKE_FUNCTION",
[MAP_ADD] = "MAP_ADD",
@ -1887,15 +1875,11 @@ const uint8_t _PyOpcode_Deopt[256] = {
struct pseudo_targets {
uint8_t targets[3];
};
extern const struct pseudo_targets _PyOpcode_PseudoTargets[12];
extern const struct pseudo_targets _PyOpcode_PseudoTargets[8];
#ifdef NEED_OPCODE_METADATA
const struct pseudo_targets _PyOpcode_PseudoTargets[12] = {
const struct pseudo_targets _PyOpcode_PseudoTargets[8] = {
[LOAD_CLOSURE-256] = { { LOAD_FAST, 0, 0 } },
[STORE_FAST_MAYBE_NULL-256] = { { STORE_FAST, 0, 0 } },
[LOAD_SUPER_METHOD-256] = { { LOAD_SUPER_ATTR, 0, 0 } },
[LOAD_ZERO_SUPER_METHOD-256] = { { LOAD_SUPER_ATTR, 0, 0 } },
[LOAD_ZERO_SUPER_ATTR-256] = { { LOAD_SUPER_ATTR, 0, 0 } },
[LOAD_METHOD-256] = { { LOAD_ATTR, 0, 0 } },
[JUMP-256] = { { JUMP_FORWARD, JUMP_BACKWARD, 0 } },
[JUMP_NO_INTERRUPT-256] = { { JUMP_FORWARD, JUMP_BACKWARD_NO_INTERRUPT, 0 } },
[SETUP_FINALLY-256] = { { NOP, 0, 0 } },
@ -1907,7 +1891,7 @@ const struct pseudo_targets _PyOpcode_PseudoTargets[12] = {
#endif // NEED_OPCODE_METADATA
static inline bool
is_pseudo_target(int pseudo, int target) {
if (pseudo < 256 || pseudo >= 268) {
if (pseudo < 256 || pseudo >= 264) {
return false;
}
for (int i = 0; _PyOpcode_PseudoTargets[pseudo-256].targets[i]; i++) {

14
Include/opcode_ids.h generated
View File

@ -225,15 +225,11 @@ extern "C" {
#define JUMP 256
#define JUMP_NO_INTERRUPT 257
#define LOAD_CLOSURE 258
#define LOAD_METHOD 259
#define LOAD_SUPER_METHOD 260
#define LOAD_ZERO_SUPER_ATTR 261
#define LOAD_ZERO_SUPER_METHOD 262
#define POP_BLOCK 263
#define SETUP_CLEANUP 264
#define SETUP_FINALLY 265
#define SETUP_WITH 266
#define STORE_FAST_MAYBE_NULL 267
#define POP_BLOCK 259
#define SETUP_CLEANUP 260
#define SETUP_FINALLY 261
#define SETUP_WITH 262
#define STORE_FAST_MAYBE_NULL 263
#define HAVE_ARGUMENT 43
#define MIN_INSTRUMENTED_OPCODE 236

View File

@ -328,15 +328,11 @@ opmap = {
'JUMP': 256,
'JUMP_NO_INTERRUPT': 257,
'LOAD_CLOSURE': 258,
'LOAD_METHOD': 259,
'LOAD_SUPER_METHOD': 260,
'LOAD_ZERO_SUPER_ATTR': 261,
'LOAD_ZERO_SUPER_METHOD': 262,
'POP_BLOCK': 263,
'SETUP_CLEANUP': 264,
'SETUP_FINALLY': 265,
'SETUP_WITH': 266,
'STORE_FAST_MAYBE_NULL': 267,
'POP_BLOCK': 259,
'SETUP_CLEANUP': 260,
'SETUP_FINALLY': 261,
'SETUP_WITH': 262,
'STORE_FAST_MAYBE_NULL': 263,
}
HAVE_ARGUMENT = 43

View File

@ -1812,18 +1812,6 @@ dummy_func(
macro(LOAD_SUPER_ATTR) = _SPECIALIZE_LOAD_SUPER_ATTR + _LOAD_SUPER_ATTR;
pseudo(LOAD_SUPER_METHOD) = {
LOAD_SUPER_ATTR,
};
pseudo(LOAD_ZERO_SUPER_METHOD) = {
LOAD_SUPER_ATTR,
};
pseudo(LOAD_ZERO_SUPER_ATTR) = {
LOAD_SUPER_ATTR,
};
inst(LOAD_SUPER_ATTR_ATTR, (unused/1, global_super, class, self -- attr, unused if (0))) {
assert(!(oparg & 1));
DEOPT_IF(global_super != (PyObject *)&PySuper_Type);
@ -1925,10 +1913,6 @@ dummy_func(
unused/8 +
_LOAD_ATTR;
pseudo(LOAD_METHOD) = {
LOAD_ATTR,
};
op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) {
PyTypeObject *tp = Py_TYPE(owner);
assert(type_version != 0);

View File

@ -723,9 +723,6 @@ stack_effect(int opcode, int oparg, int jump)
case JUMP_NO_INTERRUPT:
return 0;
case EXIT_INIT_CHECK:
return -1;
/* Exception handling pseudo-instructions */
case SETUP_FINALLY:
/* 0 in the normal flow.
@ -746,12 +743,6 @@ stack_effect(int opcode, int oparg, int jump)
return -1;
case LOAD_CLOSURE:
return 1;
case LOAD_METHOD:
return 1;
case LOAD_SUPER_METHOD:
case LOAD_ZERO_SUPER_METHOD:
case LOAD_ZERO_SUPER_ATTR:
return -1;
default:
return PY_INVALID_STACK_EFFECT;
}
@ -997,6 +988,11 @@ compiler_addop_o(struct compiler_unit *u, location loc,
return codegen_addop_i(u->u_instr_sequence, opcode, arg, loc);
}
#define LOAD_METHOD -1
#define LOAD_SUPER_METHOD -2
#define LOAD_ZERO_SUPER_ATTR -3
#define LOAD_ZERO_SUPER_METHOD -4
static int
compiler_addop_name(struct compiler_unit *u, location loc,
int opcode, PyObject *dict, PyObject *o)
@ -1014,7 +1010,6 @@ compiler_addop_name(struct compiler_unit *u, location loc,
arg <<= 1;
}
if (opcode == LOAD_METHOD) {
assert(is_pseudo_target(LOAD_METHOD, LOAD_ATTR));
opcode = LOAD_ATTR;
arg <<= 1;
arg |= 1;
@ -1024,18 +1019,15 @@ compiler_addop_name(struct compiler_unit *u, location loc,
arg |= 2;
}
if (opcode == LOAD_SUPER_METHOD) {
assert(is_pseudo_target(LOAD_SUPER_METHOD, LOAD_SUPER_ATTR));
opcode = LOAD_SUPER_ATTR;
arg <<= 2;
arg |= 3;
}
if (opcode == LOAD_ZERO_SUPER_ATTR) {
assert(is_pseudo_target(LOAD_ZERO_SUPER_ATTR, LOAD_SUPER_ATTR));
opcode = LOAD_SUPER_ATTR;
arg <<= 2;
}
if (opcode == LOAD_ZERO_SUPER_METHOD) {
assert(is_pseudo_target(LOAD_ZERO_SUPER_METHOD, LOAD_SUPER_ATTR));
opcode = LOAD_SUPER_ATTR;
arg <<= 2;
arg |= 1;