]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91276: remove unused _PyOpcode_RelativeJump (#103156)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Tue, 11 Apr 2023 10:20:39 +0000 (11:20 +0100)
committerGitHub <noreply@github.com>
Tue, 11 Apr 2023 10:20:39 +0000 (11:20 +0100)
Include/internal/pycore_opcode.h
Include/internal/pycore_opcode_utils.h
Python/flowgraph.c
Tools/build/generate_opcode_h.py

index 81ca91465950b70aa5785a1d0446bce33e74f39d..f5e9176a3e66c791c0fb1e914e5a716b6749e981 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
 #include "opcode.h"
 
-extern const uint32_t _PyOpcode_RelativeJump[9];
-
 extern const uint32_t _PyOpcode_Jump[9];
 
 extern const uint8_t _PyOpcode_Caches[256];
@@ -21,17 +19,6 @@ extern const uint8_t _PyOpcode_Caches[256];
 extern const uint8_t _PyOpcode_Deopt[256];
 
 #ifdef NEED_OPCODE_TABLES
-const uint32_t _PyOpcode_RelativeJump[9] = {
-    0U,
-    0U,
-    536870912U,
-    135020544U,
-    4163U,
-    0U,
-    0U,
-    0U,
-    48U,
-};
 const uint32_t _PyOpcode_Jump[9] = {
     0U,
     0U,
index 96bb4d743bf29f6bf43dfef0668bd2c4c84673af..1d5ff988290bd49d74bdf4776df254e545a1ec74 100644 (file)
@@ -8,7 +8,7 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "pycore_opcode.h"        // _PyOpcode_RelativeJump
+#include "pycore_opcode.h"        // _PyOpcode_Jump
 
 
 #define MAX_REAL_OPCODE 254
@@ -85,9 +85,6 @@ is_bit_set_in_table(const uint32_t *table, int bitindex) {
 #undef LOG_BITS_PER_INT
 #undef MASK_LOW_LOG_BITS
 
-#define IS_RELATIVE_JUMP(opcode) (is_bit_set_in_table(_PyOpcode_RelativeJump, opcode))
-
-
 
 #ifdef __cplusplus
 }
index d97de0c5877178bdec0e35a129a9c3810763d452..67cc5c5e88be10a0ec840d031ec7e3e5dded7f7b 100644 (file)
@@ -42,12 +42,6 @@ is_block_push(cfg_instr *i)
     return IS_BLOCK_PUSH_OPCODE(i->i_opcode);
 }
 
-static inline int
-is_relative_jump(cfg_instr *i)
-{
-    return IS_RELATIVE_JUMP(i->i_opcode);
-}
-
 static inline int
 is_jump(cfg_instr *i)
 {
@@ -199,8 +193,7 @@ blocksize(basicblock *b)
 static void
 dump_instr(cfg_instr *i)
 {
-    const char *jrel = (is_relative_jump(i)) ? "jrel " : "";
-    const char *jabs = (is_jump(i) && !is_relative_jump(i))? "jabs " : "";
+    const char *jump = is_jump(i) ? "jump " : "";
 
     char arg[128];
 
@@ -211,8 +204,8 @@ dump_instr(cfg_instr *i)
     if (HAS_TARGET(i->i_opcode)) {
         sprintf(arg, "target: %p [%d] ", i->i_target, i->i_oparg);
     }
-    fprintf(stderr, "line: %d, opcode: %d %s%s%s\n",
-                    i->i_loc.lineno, i->i_opcode, arg, jabs, jrel);
+    fprintf(stderr, "line: %d, opcode: %d %s%s\n",
+                    i->i_loc.lineno, i->i_opcode, arg, jump);
 }
 
 static inline int
@@ -500,25 +493,20 @@ resolve_jump_offsets(basicblock *entryblock)
             for (int i = 0; i < b->b_iused; i++) {
                 cfg_instr *instr = &b->b_instr[i];
                 int isize = _PyCfg_InstrSize(instr);
-                /* Relative jumps are computed relative to
-                   the instruction pointer after fetching
-                   the jump instruction.
-                */
+                /* jump offsets are computed relative to
+                 * the instruction pointer after fetching
+                 * the jump instruction.
+                 */
                 bsize += isize;
                 if (is_jump(instr)) {
                     instr->i_oparg = instr->i_target->b_offset;
-                    if (is_relative_jump(instr)) {
-                        if (instr->i_oparg < bsize) {
-                            assert(IS_BACKWARDS_JUMP_OPCODE(instr->i_opcode));
-                            instr->i_oparg = bsize - instr->i_oparg;
-                        }
-                        else {
-                            assert(!IS_BACKWARDS_JUMP_OPCODE(instr->i_opcode));
-                            instr->i_oparg -= bsize;
-                        }
+                    if (instr->i_oparg < bsize) {
+                        assert(IS_BACKWARDS_JUMP_OPCODE(instr->i_opcode));
+                        instr->i_oparg = bsize - instr->i_oparg;
                     }
                     else {
                         assert(!IS_BACKWARDS_JUMP_OPCODE(instr->i_opcode));
+                        instr->i_oparg -= bsize;
                     }
                     if (_PyCfg_InstrSize(instr) != isize) {
                         extended_arg_recompile = 1;
index 614b17df7409296cb8a1f896a4f0289312cbdff1..12fdd3ac84b3468678d969783b413ed55162125d 100644 (file)
@@ -130,12 +130,10 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna
         for name, op in specialized_opmap.items():
             fobj.write(DEFINE.format(name, op))
 
-        iobj.write("\nextern const uint32_t _PyOpcode_RelativeJump[9];\n")
         iobj.write("\nextern const uint32_t _PyOpcode_Jump[9];\n")
         iobj.write("\nextern const uint8_t _PyOpcode_Caches[256];\n")
         iobj.write("\nextern const uint8_t _PyOpcode_Deopt[256];\n")
         iobj.write("\n#ifdef NEED_OPCODE_TABLES\n")
-        write_int_array_from_ops("_PyOpcode_RelativeJump", opcode['hasjrel'], iobj)
         write_int_array_from_ops("_PyOpcode_Jump", opcode['hasjrel'] + opcode['hasjabs'], iobj)
 
         iobj.write("\nconst uint8_t _PyOpcode_Caches[256] = {\n")