From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Thu, 23 Oct 2025 23:26:49 +0000 (+0100) Subject: Address review of macros X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdcce30be410c34e75c1481e22f870edb8378dcf;p=thirdparty%2FPython%2Fcpython.git Address review of macros --- diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-10-18-21-50-44.gh-issue-139109.9QQOzN.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-18-21-50-44.gh-issue-139109.9QQOzN.rst index 01e2efa4df45..3d6f45b2b447 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-10-18-21-50-44.gh-issue-139109.9QQOzN.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-18-21-50-44.gh-issue-139109.9QQOzN.rst @@ -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. diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 73ee9fdb8fcc..9c0759af7c89 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -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); } } diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index 9a006e185bce..27cc8b19f715 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -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) diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index f839b9579ef3..6d155cf81796 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -7442,7 +7442,7 @@ } case _DEOPT: { - GOTO_TIER_ONE(_PyFrame_GetBytecode(frame) + CURRENT_TARGET(), 0); + GOTO_TIER_ONE(_PyFrame_GetBytecode(frame) + CURRENT_TARGET()); break; } @@ -7450,7 +7450,7 @@ _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; } @@ -7461,7 +7461,7 @@ _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; } @@ -7489,7 +7489,7 @@ _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) { @@ -7503,7 +7503,7 @@ 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; @@ -7544,7 +7544,7 @@ TIER2_TO_TIER2(executor); } else { - GOTO_TIER_ONE(target, 0); + GOTO_TIER_ONE(target); } break; }