]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Address review of macros
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Thu, 23 Oct 2025 23:26:49 +0000 (00:26 +0100)
committerKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Thu, 23 Oct 2025 23:26:49 +0000 (00:26 +0100)
Misc/NEWS.d/next/Core_and_Builtins/2025-10-18-21-50-44.gh-issue-139109.9QQOzN.rst
Python/bytecodes.c
Python/ceval_macros.h
Python/executor_cases.c.h

index 01e2efa4df4590aadfe72875db4da7facfbea580..3d6f45b2b44781f791049a63a0f04ba5b50e4e84 100644 (file)
@@ -1 +1 @@
-A new tracing frontend for the JIT compiler has been implemented. Patch by Ken Jin. Design for CPython by Brandt Bucher, Mark Shannon and Ken Jin.
+A new tracing frontend for the JIT compiler has been implemented. Patch by Ken Jin. Design for CPython by Mark Shannon, Ken Jin and Brandt Bucher.
index 73ee9fdb8fcca36649df3fc0472a42b43c2669e1..9c0759af7c897d46fd049fa1dbe4de6d32d7aa1a 100644 (file)
@@ -5420,12 +5420,12 @@ dummy_func(
         }
 
         tier2 op(_DEOPT, (--)) {
-            GOTO_TIER_ONE(_PyFrame_GetBytecode(frame) + CURRENT_TARGET(), 0);
+            GOTO_TIER_ONE(_PyFrame_GetBytecode(frame) + CURRENT_TARGET());
         }
 
         tier2 op(_HANDLE_PENDING_AND_DEOPT, (--)) {
             int err = _Py_HandlePending(tstate);
-            GOTO_TIER_ONE(err ? NULL : _PyFrame_GetBytecode(frame) + CURRENT_TARGET(), 0);
+            GOTO_TIER_ONE(err ? NULL : _PyFrame_GetBytecode(frame) + CURRENT_TARGET());
         }
 
         tier2 op(_ERROR_POP_N, (target/2 --)) {
@@ -5435,7 +5435,7 @@ dummy_func(
             // gh-140104: The exception handler expects frame->instr_ptr to be pointing to next_instr, not this_instr!
             frame->instr_ptr = next_instr;
             SYNC_SP();
-            GOTO_TIER_ONE(NULL, 0);
+            GOTO_TIER_ONE(NULL);
         }
 
         /* Progress is guaranteed if we DEOPT on the eval breaker, because
@@ -5457,7 +5457,7 @@ dummy_func(
             _Py_BackoffCounter temperature = exit->temperature;
             if (!backoff_counter_triggers(temperature)) {
                 exit->temperature = advance_backoff_counter(temperature);
-                GOTO_TIER_ONE(target, 0);
+                GOTO_TIER_ONE(target);
             }
             _PyExecutorObject *executor;
             if (target->op.code == ENTER_EXECUTOR) {
@@ -5474,7 +5474,7 @@ dummy_func(
                 // So setting it to anything else is wrong.
                 _PyJit_InitializeTracing(tstate, frame, target, target, target, STACK_LEVEL(), chain_depth, exit, target->op.arg);
                 exit->temperature = initial_temperature_backoff_counter();
-                GOTO_TIER_ONE(target, 1);
+                GOTO_TIER_ONE_CONTINUE_TRACING(target);
             }
             assert(tstate->jit_exit == exit);
             exit->executor = executor;
@@ -5508,7 +5508,7 @@ dummy_func(
                 TIER2_TO_TIER2(executor);
             }
             else {
-                GOTO_TIER_ONE(target, 0);
+                GOTO_TIER_ONE(target);
             }
         }
 
index 9a006e185bcea219a559d83a2c63d1e2cc6d66b6..27cc8b19f715c3dfc4326981e28e33163fe6c362 100644 (file)
@@ -440,13 +440,23 @@ do {                                                   \
     goto tier2_start;                                  \
 } while (0)
 
-#define GOTO_TIER_ONE(TARGET, SHOULD_CONTINUE_TRACING)                \
-    do                                                                \
-    {                                                                 \
-        tstate->current_executor = NULL;                              \
-        OPT_HIST(trace_uop_execution_counter, trace_run_length_hist); \
-        _PyFrame_SetStackPointer(frame, stack_pointer);               \
-        return (_Py_CODEUNIT *)(((uintptr_t)(TARGET)) | SHOULD_CONTINUE_TRACING); \
+#define GOTO_TIER_ONE_SETUP \
+    tstate->current_executor = NULL;                              \
+    OPT_HIST(trace_uop_execution_counter, trace_run_length_hist); \
+    _PyFrame_SetStackPointer(frame, stack_pointer);
+
+#define GOTO_TIER_ONE(TARGET) \
+    do \
+    { \
+        GOTO_TIER_ONE_SETUP \
+        return (_Py_CODEUNIT *)(TARGET); \
+    } while (0)
+
+#define GOTO_TIER_ONE_CONTINUE_TRACING(TARGET) \
+    do \
+    { \
+        GOTO_TIER_ONE_SETUP \
+        return (_Py_CODEUNIT *)(((uintptr_t)(TARGET))| 1); \
     } while (0)
 
 #define CURRENT_OPARG()    (next_uop[-1].oparg)
index f839b9579ef38cbed5a139b3abeffbc6cd3358bc..6d155cf8179661bd33f4a0ca33da51877f30d160 100644 (file)
         }
 
         case _DEOPT: {
-            GOTO_TIER_ONE(_PyFrame_GetBytecode(frame) + CURRENT_TARGET(), 0);
+            GOTO_TIER_ONE(_PyFrame_GetBytecode(frame) + CURRENT_TARGET());
             break;
         }
 
             _PyFrame_SetStackPointer(frame, stack_pointer);
             int err = _Py_HandlePending(tstate);
             stack_pointer = _PyFrame_GetStackPointer(frame);
-            GOTO_TIER_ONE(err ? NULL : _PyFrame_GetBytecode(frame) + CURRENT_TARGET(), 0);
+            GOTO_TIER_ONE(err ? NULL : _PyFrame_GetBytecode(frame) + CURRENT_TARGET());
             break;
         }
 
             _Py_CODEUNIT *current_instr = _PyFrame_GetBytecode(frame) + target;
             _Py_CODEUNIT *next_instr = current_instr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[current_instr->op.code]];
             frame->instr_ptr = next_instr;
-            GOTO_TIER_ONE(NULL, 0);
+            GOTO_TIER_ONE(NULL);
             break;
         }
 
             _Py_BackoffCounter temperature = exit->temperature;
             if (!backoff_counter_triggers(temperature)) {
                 exit->temperature = advance_backoff_counter(temperature);
-                GOTO_TIER_ONE(target, 0);
+                GOTO_TIER_ONE(target);
             }
             _PyExecutorObject *executor;
             if (target->op.code == ENTER_EXECUTOR) {
                 int chain_depth = previous_executor->vm_data.chain_depth + 1;
                 _PyJit_InitializeTracing(tstate, frame, target, target, target, STACK_LEVEL(), chain_depth, exit, target->op.arg);
                 exit->temperature = initial_temperature_backoff_counter();
-                GOTO_TIER_ONE(target, 1);
+                GOTO_TIER_ONE_CONTINUE_TRACING(target);
             }
             assert(tstate->jit_exit == exit);
             exit->executor = executor;
                 TIER2_TO_TIER2(executor);
             }
             else {
-                GOTO_TIER_ONE(target, 0);
+                GOTO_TIER_ONE(target);
             }
             break;
         }