mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-98831: Use opcode metadata for stack_effect() (#101704)
* Write output and metadata in a single run This halves the time to run the cases generator (most of the time goes into parsing the input). * Declare or define opcode metadata based on NEED_OPCODE_TABLES * Use generated metadata for stack_effect() * compile.o depends on opcode_metadata.h * Return -1 from _PyOpcode_num_popped/pushed for unknown opcode
This commit is contained in:
parent
0e0c5d8baa
commit
65b7b6bd23
4 changed files with 88 additions and 256 deletions
|
@ -2,8 +2,10 @@
|
|||
// from Python/bytecodes.c
|
||||
// Do not edit!
|
||||
|
||||
#ifndef NDEBUG
|
||||
static int
|
||||
#ifndef NEED_OPCODE_TABLES
|
||||
extern int _PyOpcode_num_popped(int opcode, int oparg, bool jump);
|
||||
#else
|
||||
int
|
||||
_PyOpcode_num_popped(int opcode, int oparg, bool jump) {
|
||||
switch(opcode) {
|
||||
case NOP:
|
||||
|
@ -345,13 +347,15 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
|
|||
case CACHE:
|
||||
return 0;
|
||||
default:
|
||||
Py_UNREACHABLE();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
static int
|
||||
#ifndef NEED_OPCODE_TABLES
|
||||
extern int _PyOpcode_num_pushed(int opcode, int oparg, bool jump);
|
||||
#else
|
||||
int
|
||||
_PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
||||
switch(opcode) {
|
||||
case NOP:
|
||||
|
@ -693,10 +697,11 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
|||
case CACHE:
|
||||
return 0;
|
||||
default:
|
||||
Py_UNREACHABLE();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
enum Direction { DIR_NONE, DIR_READ, DIR_WRITE };
|
||||
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC0, INSTR_FMT_IBC000, INSTR_FMT_IBC0000, INSTR_FMT_IBC00000000, INSTR_FMT_IBIB, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
|
||||
struct opcode_metadata {
|
||||
|
@ -705,7 +710,12 @@ struct opcode_metadata {
|
|||
enum Direction dir_op3;
|
||||
bool valid_entry;
|
||||
enum InstructionFormat instr_format;
|
||||
} _PyOpcode_opcode_metadata[256] = {
|
||||
};
|
||||
|
||||
#ifndef NEED_OPCODE_TABLES
|
||||
extern const struct opcode_metadata _PyOpcode_opcode_metadata[256];
|
||||
#else
|
||||
const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
|
||||
[NOP] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
[RESUME] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[LOAD_CLOSURE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
|
@ -876,3 +886,4 @@ struct opcode_metadata {
|
|||
[EXTENDED_ARG] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[CACHE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue