summaryrefslogtreecommitdiffstats
path: root/Python/opcode_metadata.h
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2023-02-09 00:23:19 (GMT)
committerGitHub <noreply@github.com>2023-02-09 00:23:19 (GMT)
commit65b7b6bd23ea789357777f3a0a6f25a79bb04177 (patch)
treec7b79edb1ff56ab27034ca1d70ad2516cce65ad1 /Python/opcode_metadata.h
parent0e0c5d8baaa6aa91f4221c5aa57d5586e58e8652 (diff)
downloadcpython-65b7b6bd23ea789357777f3a0a6f25a79bb04177.zip
cpython-65b7b6bd23ea789357777f3a0a6f25a79bb04177.tar.gz
cpython-65b7b6bd23ea789357777f3a0a6f25a79bb04177.tar.bz2
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
Diffstat (limited to 'Python/opcode_metadata.h')
-rw-r--r--Python/opcode_metadata.h25
1 files changed, 18 insertions, 7 deletions
diff --git a/Python/opcode_metadata.h b/Python/opcode_metadata.h
index 9879104..db1dfd3 100644
--- a/Python/opcode_metadata.h
+++ b/Python/opcode_metadata.h
@@ -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