]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Remove TIER2_STORE_IP
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Fri, 24 Oct 2025 18:27:16 +0000 (19:27 +0100)
committerKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Fri, 24 Oct 2025 18:27:16 +0000 (19:27 +0100)
Objects/frameobject.c
Python/bytecodes.c
Python/ceval.c
Python/ceval_macros.h
Python/executor_cases.c.h
Python/generated_cases.c.h
Tools/cases_generator/tier2_generator.py

index abed4547ffd05368ac1e7faff953240d2a61cc05..37d30f349fedfe3783f62639021260c76dd50e8e 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "frameobject.h"          // PyFrameLocalsProxyObject
 #include "opcode.h"               // EXTENDED_ARG
-#include "../Include/pytypedefs.h"
 #include "pycore_optimizer.h"
 
 #include "clinic/frameobject.c.h"
index ee9d41bd5194cf08f3d34ff38f33cb2538032941..e53621298553b8ed8ae63112e2347bc7fc769ceb 100644 (file)
@@ -1249,12 +1249,7 @@ dummy_func(
             frame = tstate->current_frame = dying->previous;
             _PyEval_FrameClearAndPop(tstate, dying);
             RELOAD_STACK();
-            #if TIER_ONE
             LOAD_IP(frame->return_offset);
-            #endif
-            #if TIER_TWO
-            TIER2_STORE_IP(frame->return_offset);
-            #endif
             res = temp;
             LLTRACE_RESUME_FRAME();
         }
@@ -1441,12 +1436,7 @@ dummy_func(
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
             #endif
             RELOAD_STACK();
-            #if TIER_ONE
             LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
-            #endif
-            #if TIER_TWO
-            TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_SEND);
-            #endif
             value = PyStackRef_MakeHeapSafe(temp);
             LLTRACE_RESUME_FRAME();
         }
@@ -3236,15 +3226,14 @@ dummy_func(
         }
 
         op(_FOR_ITER_TIER_TWO, (iter, null_or_index -- iter, null_or_index, next)) {
-            TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_FOR_ITER);
             _PyStackRef item = _PyForIter_VirtualIteratorNext(tstate, frame, iter, &null_or_index);
             if (!PyStackRef_IsValid(item)) {
                 if (PyStackRef_IsError(item)) {
                     ERROR_NO_POP();
                 }
                 /* iterator ended normally */
-                /* This just sets the IP to what it expects */
-                TIER2_STORE_IP(oparg + 1);
+                /* This just sets the IP to what it expects (see normal _FOR_ITER */
+                frame->instr_ptr += (oparg + 2 + INLINE_CACHE_ENTRIES_FOR_ITER);
                 EXIT_IF(true);
             }
             next = item;
@@ -4992,12 +4981,7 @@ dummy_func(
             _PyInterpreterFrame *prev = frame->previous;
             _PyThreadState_PopFrame(tstate, frame);
             frame = tstate->current_frame = prev;
-            #if TIER_ONE
             LOAD_IP(frame->return_offset);
-            #endif
-            #if TIER_TWO
-            TIER2_STORE_IP(frame->return_offset);
-            #endif
             RELOAD_STACK();
             res = PyStackRef_FromPyObjectStealMortal((PyObject *)gen);
             LLTRACE_RESUME_FRAME();
index 49c1c5986c0f03ca28d1452d01a958096dbdb409..4597cc5e641645847eff512f63455ecd5284a67b 100644 (file)
@@ -1213,20 +1213,7 @@ tier2_dispatch:
     for (;;) {
         uopcode = next_uop->opcode;
 #ifdef Py_DEBUG
-        if (frame->lltrace >= 4) {
-            if (next_uop->opcode != _START_EXECUTOR) {
-                if (next_uop->format == UOP_FORMAT_TARGET) {
-                    _Py_CODEUNIT *aim = _PyFrame_GetBytecode(frame) + next_uop->target;
-                    printf("    aim=[%s]\n", _PyOpcode_OpName[aim->op.code]);
-                }
-                else if (next_uop->format == UOP_FORMAT_JUMP) {
-                    _PyUOpInstruction *aim_uop =  current_executor->trace + next_uop->jump_target;
-                    if (aim_uop->format == UOP_FORMAT_TARGET) {
-                        _Py_CODEUNIT *aim = _PyFrame_GetBytecode(frame) + aim_uop->target;
-                        printf("    aim=[%s]\n", _PyOpcode_OpName[aim->op.code]);
-                    }
-                }
-            }
+        if (frame->lltrace >= 3) {
             dump_stack(frame, stack_pointer);
             if (next_uop->opcode == _START_EXECUTOR) {
                 printf("%4d uop: ", 0);
index f85a7f9e271a50753ad60dbbdf61f705a05ec7e8..a29e5d5cbbfd32ae3dd22a89b1ae9db3f7cc6ee6 100644 (file)
@@ -210,12 +210,14 @@ do { \
         JUMP_TO_LABEL(start_frame);                      \
     } while (0)
 #else
+
 #define DISPATCH_SAME_OPARG() \
     { \
         opcode = next_instr->op.code; \
         PRE_DISPATCH_GOTO(); \
         DISPATCH_GOTO(); \
     }
+
 #define DISPATCH_INLINED(NEW_FRAME)                     \
     do {                                                \
         assert(tstate->interp->eval_frame == NULL);     \
@@ -257,7 +259,6 @@ GETITEM(PyObject *v, Py_ssize_t i) {
  * and skipped instructions.
  */
 #define JUMPBY(x)       (next_instr += (x))
-#define TIER2_STORE_IP(x) (frame->instr_ptr += (x))
 #define SKIP_OVER(x)    (next_instr += (x))
 
 #define STACK_LEVEL()     ((int)(stack_pointer - _PyFrame_Stackbase(frame)))
index 2fa109b049d1a909e0e91f72ff8b625e16c66afd..fafaa7bd12bbb59b04a6a5b6602d4c68a8d0a166 100644 (file)
             frame = tstate->current_frame = dying->previous;
             _PyEval_FrameClearAndPop(tstate, dying);
             stack_pointer = _PyFrame_GetStackPointer(frame);
-            #if TIER_ONE
-            LOAD_IP(frame->return_offset);
-            #endif
-            #if TIER_TWO
-            TIER2_STORE_IP(frame->return_offset);
-            #endif
+            frame->instr_ptr += (frame->return_offset);
             res = temp;
             LLTRACE_RESUME_FRAME();
             stack_pointer[0] = res;
                   _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
             #endif
             stack_pointer = _PyFrame_GetStackPointer(frame);
-            #if TIER_ONE
-            LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
-            #endif
-            #if TIER_TWO
-            TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_SEND);
-            #endif
+            frame->instr_ptr += (1 + INLINE_CACHE_ENTRIES_SEND);
             value = PyStackRef_MakeHeapSafe(temp);
             LLTRACE_RESUME_FRAME();
             stack_pointer[0] = value;
             oparg = CURRENT_OPARG();
             null_or_index = stack_pointer[-1];
             iter = stack_pointer[-2];
-            TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_FOR_ITER);
             _PyFrame_SetStackPointer(frame, stack_pointer);
             _PyStackRef item = _PyForIter_VirtualIteratorNext(tstate, frame, iter, &null_or_index);
             stack_pointer = _PyFrame_GetStackPointer(frame);
                 if (PyStackRef_IsError(item)) {
                     JUMP_TO_ERROR();
                 }
-                TIER2_STORE_IP(oparg + 1);
+                frame->instr_ptr += (oparg + 2 + INLINE_CACHE_ENTRIES_FOR_ITER);
                 if (true) {
                     UOP_STAT_INC(uopcode, miss);
                     JUMP_TO_JUMP_TARGET();
             frame = tstate->current_frame = temp;
             tstate->py_recursion_remaining--;
             LOAD_SP();
-            LOAD_IP(0);
+            frame->instr_ptr += (0);
             LLTRACE_RESUME_FRAME();
             break;
         }
             _PyInterpreterFrame *prev = frame->previous;
             _PyThreadState_PopFrame(tstate, frame);
             frame = tstate->current_frame = prev;
-            #if TIER_ONE
-            LOAD_IP(frame->return_offset);
-            #endif
-            #if TIER_TWO
-            TIER2_STORE_IP(frame->return_offset);
-            #endif
+            frame->instr_ptr += (frame->return_offset);
             stack_pointer = _PyFrame_GetStackPointer(frame);
             res = PyStackRef_FromPyObjectStealMortal((PyObject *)gen);
             LLTRACE_RESUME_FRAME();
index 6ed8bce67cc1cf279b5ee3ca6559b786aec9eb12..4dc2599bff529739ce6c4f025883bb9ee44f46c7 100644 (file)
                 frame = tstate->current_frame = dying->previous;
                 _PyEval_FrameClearAndPop(tstate, dying);
                 stack_pointer = _PyFrame_GetStackPointer(frame);
-                #if TIER_ONE
                 LOAD_IP(frame->return_offset);
-                #endif
-                #if TIER_TWO
-                TIER2_STORE_IP(frame->return_offset);
-                #endif
                 res = temp;
                 LLTRACE_RESUME_FRAME();
             }
                   _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
                 #endif
                 stack_pointer = _PyFrame_GetStackPointer(frame);
-                #if TIER_ONE
                 LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
-                #endif
-                #if TIER_TWO
-                TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_SEND);
-                #endif
                 value = PyStackRef_MakeHeapSafe(temp);
                 LLTRACE_RESUME_FRAME();
             }
             _PyInterpreterFrame *prev = frame->previous;
             _PyThreadState_PopFrame(tstate, frame);
             frame = tstate->current_frame = prev;
-            #if TIER_ONE
             LOAD_IP(frame->return_offset);
-            #endif
-            #if TIER_TWO
-            TIER2_STORE_IP(frame->return_offset);
-            #endif
             stack_pointer = _PyFrame_GetStackPointer(frame);
             res = PyStackRef_FromPyObjectStealMortal((PyObject *)gen);
             LLTRACE_RESUME_FRAME();
             frame = tstate->current_frame = dying->previous;
             _PyEval_FrameClearAndPop(tstate, dying);
             stack_pointer = _PyFrame_GetStackPointer(frame);
-            #if TIER_ONE
             LOAD_IP(frame->return_offset);
-            #endif
-            #if TIER_TWO
-            TIER2_STORE_IP(frame->return_offset);
-            #endif
             res = temp;
             LLTRACE_RESUME_FRAME();
             stack_pointer[0] = res;
                   _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
             #endif
             stack_pointer = _PyFrame_GetStackPointer(frame);
-            #if TIER_ONE
             LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
-            #endif
-            #if TIER_TWO
-            TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_SEND);
-            #endif
             value = PyStackRef_MakeHeapSafe(temp);
             LLTRACE_RESUME_FRAME();
             stack_pointer[0] = value;
index 87b26b1c732599c1311e8a4a9dec635bec788cb8..e95a070b163f4c988b393eb78297616c12187950 100644 (file)
@@ -65,6 +65,7 @@ class Tier2Emitter(Emitter):
         self._replacers["oparg"] = self.oparg
         self._replacers["JUMPBY"] = self.jumpby
         self._replacers["DISPATCH"] = self.dispatch
+        self._replacers["LOAD_IP"] = self.load_ip
 
     def goto_error(self, offset: int, storage: Storage) -> str:
         # To do: Add jump targets for popping values.
@@ -169,6 +170,20 @@ class Tier2Emitter(Emitter):
         next(tkn_iter)
         return False
 
+    def load_ip(
+        self,
+        tkn: Token,
+        tkn_iter: TokenIterator,
+        uop: CodeSection,
+        storage: Storage,
+        inst: Instruction | None,
+    ) -> bool:
+        self.out.start_line()
+        self.emit("frame->instr_ptr += ")
+        emit_to(self.out, tkn_iter, "SEMI")
+        self.emit(";\n")
+        return True
+
 def write_uop(uop: Uop, emitter: Emitter, stack: Stack) -> Stack:
     locals: dict[str, Local] = {}
     try: