From 8ebb6cbdd0ab0ae033dc864aee0d7681f4d3c82a Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Tue, 21 Oct 2025 21:30:07 +0100 Subject: [PATCH] Fix naming of things --- Include/internal/pycore_interp_structs.h | 26 +++--- Include/internal/pycore_optimizer.h | 9 +- Objects/codeobject.c | 2 +- Objects/frameobject.c | 2 +- Objects/funcobject.c | 4 +- Python/bytecodes.c | 10 +- Python/ceval.c | 4 +- Python/ceval_macros.h | 6 +- Python/executor_cases.c.h | 2 +- Python/generated_cases.c.h | 8 +- Python/generated_tracer_cases.c.h | 8 +- Python/instrumentation.c | 2 +- Python/optimizer.c | 112 +++++++++++------------ Python/pystate.c | 16 ++-- Tools/cases_generator/analyzer.py | 2 +- 15 files changed, 107 insertions(+), 106 deletions(-) diff --git a/Include/internal/pycore_interp_structs.h b/Include/internal/pycore_interp_structs.h index 5285233b6b13..ac1bcdf74ae4 100644 --- a/Include/internal/pycore_interp_structs.h +++ b/Include/internal/pycore_interp_structs.h @@ -758,20 +758,20 @@ struct _Py_unique_id_pool { typedef _Py_CODEUNIT *(*_PyJitEntryFuncPtr)(struct _PyExecutorObject *exec, _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate); typedef struct _PyJitTracerState { - int jit_tracer_code_max_size; - int jit_tracer_code_curr_size; - _PyBloomFilter jit_tracer_dependencies; - bool jit_tracer_dependencies_still_valid; - _PyUOpInstruction *jit_tracer_code_buffer; - _Py_CODEUNIT *jit_tracer_insert_exec_instr; - _Py_CODEUNIT *jit_tracer_close_loop_instr; + bool dependencies_still_valid; + int code_max_size; + int code_curr_size; + int initial_stack_depth; + int initial_chain_depth; + _PyUOpInstruction *code_buffer; + _Py_CODEUNIT *insert_exec_instr; + _Py_CODEUNIT *close_loop_instr; _Py_CODEUNIT *last_specialized_instr; - int jit_tracer_initial_stack_depth; - int jit_tracer_initial_chain_depth; - PyCodeObject *jit_tracer_initial_code; // Strong - PyFunctionObject *jit_tracer_initial_func; // Strong - struct _PyExitData *jit_tracer_previous_exit; - _PyInterpreterFrame *jit_tracer_current_frame; + PyCodeObject *initial_code; // Strong + PyFunctionObject *initial_func; // Strong + struct _PyExitData *previous_exit; + _PyInterpreterFrame *current_frame; + _PyBloomFilter dependencies; } _PyJitTracerState; /* PyInterpreterState holds the global state for one of the runtime's diff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h index 0acf19402769..a87cce85e979 100644 --- a/Include/internal/pycore_optimizer.h +++ b/Include/internal/pycore_optimizer.h @@ -359,7 +359,7 @@ extern void _Py_ClearExecutorDeletionList(PyInterpreterState *interp); #endif int -_PyJIT_translate_single_bytecode_to_trace( +_PyJit_translate_single_bytecode_to_trace( PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *this_instr, @@ -372,11 +372,12 @@ _PyJIT_translate_single_bytecode_to_trace( int jump_taken); void -_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *insert_exec_instr, _Py_CODEUNIT *close_loop_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit); +_PyJit_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *insert_exec_instr + _Py_CODEUNIT *close_loop_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit); -void _PyJIT_FinalizeTracing(PyThreadState *tstate); +void _PyJit_FinalizeTracing(PyThreadState *tstate); -void _Py_JITTracer_InvalidateDependency(PyThreadState *old_tstate, void *obj); +void _PyJit_Tracer_InvalidateDependency(PyThreadState *old_tstate, void *obj); #ifdef __cplusplus } diff --git a/Objects/codeobject.c b/Objects/codeobject.c index d0dd65300a1d..3a13cfaee2a5 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -2415,7 +2415,7 @@ code_dealloc(PyObject *self) PyMem_Free(co_extra); } #ifdef _Py_TIER2 - _Py_JITTracer_InvalidateDependency(tstate, self); + _PyJit_Tracer_InvalidateDependency(tstate, self); if (co->co_executors != NULL) { clear_executors(co); } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 156daef7f9c6..abed4547ffd0 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -264,7 +264,7 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value) #if _Py_TIER2 _Py_Executors_InvalidateDependency(PyInterpreterState_Get(), co, 1); - _Py_JITTracer_InvalidateDependency(PyThreadState_GET(), co); + _PyJit_Tracer_InvalidateDependency(PyThreadState_GET(), co); #endif _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i); diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 5a801b616fef..fcd79c7e4f4e 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -11,7 +11,7 @@ #include "pycore_setobject.h" // _PySet_NextEntry() #include "pycore_stats.h" #include "pycore_weakref.h" // FT_CLEAR_WEAKREFS() -#include "pycore_optimizer.h" // _Py_JITTracer_InvalidateDependency +#include "pycore_optimizer.h" // _PyJit_Tracer_InvalidateDependency static const char * func_event_name(PyFunction_WatchEvent event) { @@ -1152,7 +1152,7 @@ func_dealloc(PyObject *self) return; } #if _Py_TIER2 - _Py_JITTracer_InvalidateDependency(PyThreadState_GET(), self); + _PyJit_Tracer_InvalidateDependency(PyThreadState_GET(), self); #endif _PyObject_GC_UNTRACK(op); FT_CLEAR_WEAKREFS(self, op->func_weakreflist); diff --git a/Python/bytecodes.c b/Python/bytecodes.c index ab5649281d90..f8742e6212d7 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2970,9 +2970,9 @@ dummy_func( if (!IS_JIT_TRACING() && backoff_counter_triggers(counter) && this_instr->op.code == JUMP_BACKWARD_JIT && next_instr->op.code != ENTER_EXECUTOR) { - if (tstate->interp->jit_state.jit_tracer_code_buffer == NULL) { - tstate->interp->jit_state.jit_tracer_code_buffer = (_PyUOpInstruction *)_PyObject_VirtualAlloc(UOP_BUFFER_SIZE); - if (tstate->interp->jit_state.jit_tracer_code_buffer == NULL) { + if (tstate->interp->jit_state.code_buffer == NULL) { + tstate->interp->jit_state.code_buffer = (_PyUOpInstruction *)_PyObject_VirtualAlloc(UOP_BUFFER_SIZE); + if (tstate->interp->jit_state.code_buffer == NULL) { // Don't error, just go to next instruction. DISPATCH(); } @@ -2985,7 +2985,7 @@ dummy_func( oparg >>= 8; insert_exec_at--; } - _PyJIT_InitializeTracing(tstate, frame, insert_exec_at, next_instr, STACK_LEVEL(), 0, NULL); + _PyJit_InitializeTracing(tstate, frame, insert_exec_at, next_instr, STACK_LEVEL(), 0, NULL); ENTER_TRACING(); } int _jump_taken = false; @@ -5456,7 +5456,7 @@ dummy_func( _PyExecutorObject *previous_executor = _PyExecutor_FromExit(exit); assert(tstate->current_executor == (PyObject *)previous_executor); int chain_depth = previous_executor->vm_data.chain_depth + 1; - _PyJIT_InitializeTracing(tstate, frame, target, target, STACK_LEVEL(), chain_depth, exit); + _PyJit_InitializeTracing(tstate, frame, target, target, STACK_LEVEL(), chain_depth, exit); exit->temperature = initial_temperature_backoff_counter(); GOTO_TIER_ONE(target, 1); } diff --git a/Python/ceval.c b/Python/ceval.c index 08add3f75cd5..e8f1ed5f88b2 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -990,8 +990,8 @@ static inline int add_to_code_trace(PyThreadState *tstate, _PyInterpreterFrame *frame, PyCodeObject *old_code, PyFunctionObject *old_func, int old_stack_level, _Py_CODEUNIT *this_instr, _Py_CODEUNIT *next_instr, int opcode, int oparg, int jump_taken) { assert(frame != NULL); - assert(tstate->interp->jit_state.jit_tracer_code_curr_size < UOP_MAX_TRACE_LENGTH); - return !_PyJIT_translate_single_bytecode_to_trace(tstate, frame, this_instr, next_instr, old_code, old_func, old_stack_level, opcode, oparg, jump_taken); + assert(tstate->interp->jit_state.code_curr_size < UOP_MAX_TRACE_LENGTH); + return !_PyJit_translate_single_bytecode_to_trace(tstate, frame, this_instr, next_instr, old_code, old_func, old_stack_level, opcode, oparg, jump_taken); } #endif diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index e85adf88c679..1d359461ffa0 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -150,7 +150,7 @@ if (!_PyErr_Occurred(tstate) && !_is_sys_tracing) { \ _PyFrame_SetStackPointer(frame, stack_pointer); \ int _err = _PyOptimizer_Optimize(frame, tstate); \ - _PyJIT_FinalizeTracing(tstate); \ + _PyJit_FinalizeTracing(tstate); \ stack_pointer = _PyFrame_GetStackPointer(frame); \ if (_err < 0) { \ JUMP_TO_LABEL(error); \ @@ -158,7 +158,7 @@ } \ else { \ _PyFrame_SetStackPointer(frame, stack_pointer); \ - _PyJIT_FinalizeTracing(tstate); \ + _PyJit_FinalizeTracing(tstate); \ stack_pointer = _PyFrame_GetStackPointer(frame); \ } \ } while (0); @@ -451,7 +451,7 @@ do { \ } \ if (keep_tracing_bit) { \ assert(next_instr->op.code != ENTER_EXECUTOR); \ - assert(tstate->interp->jit_state.jit_tracer_code_curr_size == 2); \ + assert(tstate->interp->jit_state.code_curr_size == 2); \ ENTER_TRACING(); \ } \ DISPATCH(); \ diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 7e76e0a0719e..72927d8378c3 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -7501,7 +7501,7 @@ _PyExecutorObject *previous_executor = _PyExecutor_FromExit(exit); assert(tstate->current_executor == (PyObject *)previous_executor); int chain_depth = previous_executor->vm_data.chain_depth + 1; - _PyJIT_InitializeTracing(tstate, frame, target, target, STACK_LEVEL(), chain_depth, exit); + _PyJit_InitializeTracing(tstate, frame, target, target, STACK_LEVEL(), chain_depth, exit); exit->temperature = initial_temperature_backoff_counter(); GOTO_TIER_ONE(target, 1); } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 0aeff340806f..4fb61a06cdfe 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7661,11 +7661,11 @@ if (!IS_JIT_TRACING() && backoff_counter_triggers(counter) && this_instr->op.code == JUMP_BACKWARD_JIT && next_instr->op.code != ENTER_EXECUTOR) { - if (tstate->interp->jit_state.jit_tracer_code_buffer == NULL) { + if (tstate->interp->jit_state.code_buffer == NULL) { _PyFrame_SetStackPointer(frame, stack_pointer); - tstate->interp->jit_state.jit_tracer_code_buffer = (_PyUOpInstruction *)_PyObject_VirtualAlloc(UOP_BUFFER_SIZE); + tstate->interp->jit_state.code_buffer = (_PyUOpInstruction *)_PyObject_VirtualAlloc(UOP_BUFFER_SIZE); stack_pointer = _PyFrame_GetStackPointer(frame); - if (tstate->interp->jit_state.jit_tracer_code_buffer == NULL) { + if (tstate->interp->jit_state.code_buffer == NULL) { DISPATCH(); } } @@ -7676,7 +7676,7 @@ oparg >>= 8; insert_exec_at--; } - _PyJIT_InitializeTracing(tstate, frame, insert_exec_at, next_instr, STACK_LEVEL(), 0, NULL); + _PyJit_InitializeTracing(tstate, frame, insert_exec_at, next_instr, STACK_LEVEL(), 0, NULL); ENTER_TRACING(); } int _jump_taken = false; diff --git a/Python/generated_tracer_cases.c.h b/Python/generated_tracer_cases.c.h index 123315df9e5f..6317b02ddb93 100644 --- a/Python/generated_tracer_cases.c.h +++ b/Python/generated_tracer_cases.c.h @@ -8946,11 +8946,11 @@ if (!IS_JIT_TRACING() && backoff_counter_triggers(counter) && this_instr->op.code == JUMP_BACKWARD_JIT && next_instr->op.code != ENTER_EXECUTOR) { - if (tstate->interp->jit_state.jit_tracer_code_buffer == NULL) { + if (tstate->interp->jit_state.code_buffer == NULL) { _PyFrame_SetStackPointer(frame, stack_pointer); - tstate->interp->jit_state.jit_tracer_code_buffer = (_PyUOpInstruction *)_PyObject_VirtualAlloc(UOP_BUFFER_SIZE); + tstate->interp->jit_state.code_buffer = (_PyUOpInstruction *)_PyObject_VirtualAlloc(UOP_BUFFER_SIZE); stack_pointer = _PyFrame_GetStackPointer(frame); - if (tstate->interp->jit_state.jit_tracer_code_buffer == NULL) { + if (tstate->interp->jit_state.code_buffer == NULL) { TRACING_DISPATCH(); } } @@ -8961,7 +8961,7 @@ oparg >>= 8; insert_exec_at--; } - _PyJIT_InitializeTracing(tstate, frame, insert_exec_at, next_instr, STACK_LEVEL(), 0, NULL); + _PyJit_InitializeTracing(tstate, frame, insert_exec_at, next_instr, STACK_LEVEL(), 0, NULL); ENTER_TRACING(); } int _jump_taken = false; diff --git a/Python/instrumentation.c b/Python/instrumentation.c index 85fb73aaf098..81e46a331e0b 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -1786,7 +1786,7 @@ force_instrument_lock_held(PyCodeObject *code, PyInterpreterState *interp) _PyCode_Clear_Executors(code); } _Py_Executors_InvalidateDependency(interp, code, 1); - _Py_JITTracer_InvalidateDependency(PyThreadState_GET(), code); + _PyJit_Tracer_InvalidateDependency(PyThreadState_GET(), code); #endif int code_len = (int)Py_SIZE(code); /* Exit early to avoid creating instrumentation diff --git a/Python/optimizer.c b/Python/optimizer.c index c7967d090936..8482162d4a32 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -118,10 +118,10 @@ _PyOptimizer_Optimize( _PyInterpreterFrame *frame, PyThreadState *tstate) { PyInterpreterState *interp = _PyInterpreterState_GET(); - int chain_depth = tstate->interp->jit_state.jit_tracer_initial_chain_depth; + int chain_depth = tstate->interp->jit_state.initial_chain_depth; assert(interp->jit); assert(!interp->compiling); - assert(tstate->interp->jit_state.jit_tracer_initial_stack_depth >= 0); + assert(tstate->interp->jit_state.initial_stack_depth >= 0); #ifndef Py_GIL_DISABLED interp->compiling = true; // The first executor in a chain and the MAX_CHAIN_DEPTH'th executor *must* @@ -130,8 +130,8 @@ _PyOptimizer_Optimize( // this is true, since a deopt won't infinitely re-enter the executor: chain_depth %= MAX_CHAIN_DEPTH; bool progress_needed = chain_depth == 0; - PyCodeObject *code = (PyCodeObject *)tstate->interp->jit_state.jit_tracer_initial_code; - _Py_CODEUNIT *start = tstate->interp->jit_state.jit_tracer_insert_exec_instr; + PyCodeObject *code = (PyCodeObject *)tstate->interp->jit_state.initial_code; + _Py_CODEUNIT *start = tstate->interp->jit_state.insert_exec_instr; // A recursive trace might've cleared the values. In that case, bail. if (code == NULL) { interp->compiling = false; @@ -142,7 +142,7 @@ _PyOptimizer_Optimize( return 0; } // One of our dependencies while tracing was invalidated. Not worth compiling. - if (!tstate->interp->jit_state.jit_tracer_dependencies_still_valid) { + if (!tstate->interp->jit_state.dependencies_still_valid) { interp->compiling = false; return 0; } @@ -172,7 +172,7 @@ _PyOptimizer_Optimize( executor->vm_data.code = NULL; } if (chain_depth > 0) { - _PyExitData *prev_exit = tstate->interp->jit_state.jit_tracer_previous_exit; + _PyExitData *prev_exit = tstate->interp->jit_state.previous_exit; assert(prev_exit != NULL); prev_exit->executor = executor;; } @@ -551,7 +551,7 @@ add_to_trace( /* Returns 1 on success (added to trace), 0 on trace end. */ int -_PyJIT_translate_single_bytecode_to_trace( +_PyJit_translate_single_bytecode_to_trace( PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *this_instr, @@ -564,13 +564,13 @@ _PyJIT_translate_single_bytecode_to_trace( int jump_taken) { - int is_first_instr = tstate->interp->jit_state.jit_tracer_close_loop_instr == this_instr; - bool progress_needed = (tstate->interp->jit_state.jit_tracer_initial_chain_depth % MAX_CHAIN_DEPTH) == 0;; - _PyBloomFilter *dependencies = &tstate->interp->jit_state.jit_tracer_dependencies; + int is_first_instr = tstate->interp->jit_state.close_loop_instr == this_instr; + bool progress_needed = (tstate->interp->jit_state.initial_chain_depth % MAX_CHAIN_DEPTH) == 0;; + _PyBloomFilter *dependencies = &tstate->interp->jit_state.dependencies; _Py_BloomFilter_Add(dependencies, old_code); - int trace_length = tstate->interp->jit_state.jit_tracer_code_curr_size; - _PyUOpInstruction *trace = tstate->interp->jit_state.jit_tracer_code_buffer; - int max_length = tstate->interp->jit_state.jit_tracer_code_max_size; + int trace_length = tstate->interp->jit_state.code_curr_size; + _PyUOpInstruction *trace = tstate->interp->jit_state.code_buffer; + int max_length = tstate->interp->jit_state.code_max_size; #ifdef Py_DEBUG char *python_lltrace = Py_GETENV("PYTHON_LLTRACE"); @@ -597,7 +597,7 @@ _PyJIT_translate_single_bytecode_to_trace( } #endif - if (!tstate->interp->jit_state.jit_tracer_dependencies_still_valid) { + if (!tstate->interp->jit_state.dependencies_still_valid) { goto done; } @@ -609,7 +609,7 @@ _PyJIT_translate_single_bytecode_to_trace( if (jump_taken || // This happens when a recursive call happens that we can't trace. Such as Python -> C -> Python calls // If we haven't guarded the IP, then it's untraceable. - (frame != tstate->interp->jit_state.jit_tracer_current_frame && !needs_guard_ip) || + (frame != tstate->interp->jit_state.current_frame && !needs_guard_ip) || (oparg > 0xFFFF) || // TODO (gh-140277): The constituent use one extra stack slot. So we need to check for headroom. (opcode == BINARY_OP_SUBSCR_GETITEM && old_stack_level + 1 > old_code->co_stacksize)|| @@ -638,7 +638,7 @@ _PyJIT_translate_single_bytecode_to_trace( } } - tstate->interp->jit_state.jit_tracer_current_frame = frame; + tstate->interp->jit_state.current_frame = frame; if (opcode == NOP) { return 1; @@ -672,7 +672,7 @@ _PyJIT_translate_single_bytecode_to_trace( /* Special case the first instruction, * so that we can guarantee forward progress */ - if (progress_needed && tstate->interp->jit_state.jit_tracer_code_curr_size <= 2) { + if (progress_needed && tstate->interp->jit_state.code_curr_size <= 2) { if (OPCODE_HAS_EXIT(opcode) || OPCODE_HAS_DEOPT(opcode)) { opcode = _PyOpcode_Deopt[opcode]; } @@ -681,7 +681,7 @@ _PyJIT_translate_single_bytecode_to_trace( } // Loop back to the start - if (is_first_instr && tstate->interp->jit_state.jit_tracer_code_curr_size > 5) { + if (is_first_instr && tstate->interp->jit_state.code_curr_size > 5) { ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 0); goto done; } @@ -849,29 +849,29 @@ _PyJIT_translate_single_bytecode_to_trace( if (needs_guard_ip) { ADD_TO_TRACE(_GUARD_IP, 0, (uintptr_t)next_instr, 0); } - tstate->interp->jit_state.jit_tracer_code_curr_size = trace_length; - tstate->interp->jit_state.jit_tracer_code_max_size = max_length; + tstate->interp->jit_state.code_curr_size = trace_length; + tstate->interp->jit_state.code_max_size = max_length; return 1; done: - tstate->interp->jit_state.jit_tracer_code_curr_size = trace_length; - tstate->interp->jit_state.jit_tracer_code_max_size = max_length; + tstate->interp->jit_state.code_curr_size = trace_length; + tstate->interp->jit_state.code_max_size = max_length; return 0; full: - if (!is_terminator(&tstate->interp->jit_state.jit_tracer_code_buffer[trace_length-1])) { + if (!is_terminator(&tstate->interp->jit_state.code_buffer[trace_length-1])) { // Undo the last few instructions. - trace_length = tstate->interp->jit_state.jit_tracer_code_curr_size; - max_length = tstate->interp->jit_state.jit_tracer_code_max_size; + trace_length = tstate->interp->jit_state.code_curr_size; + max_length = tstate->interp->jit_state.code_max_size; // We previously reversed one. max_length += 1; ADD_TO_TRACE(_EXIT_TRACE, 0, 0, target); } - tstate->interp->jit_state.jit_tracer_code_curr_size = trace_length; - tstate->interp->jit_state.jit_tracer_code_max_size = max_length; + tstate->interp->jit_state.code_curr_size = trace_length; + tstate->interp->jit_state.code_max_size = max_length; return 0; } void -_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *insert_exec_instr, _Py_CODEUNIT *close_loop_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit) +_PyJit_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *insert_exec_instr, _Py_CODEUNIT *close_loop_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit) { PyCodeObject *code = _PyFrame_GetCode(frame); #ifdef Py_DEBUG @@ -888,30 +888,30 @@ _PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_ 2 * INSTR_IP(close_loop_instr, code), chain_depth); #endif - add_to_trace(tstate->interp->jit_state.jit_tracer_code_buffer, 0, _START_EXECUTOR, 0, (uintptr_t)insert_exec_instr, INSTR_IP(insert_exec_instr, code)); - add_to_trace(tstate->interp->jit_state.jit_tracer_code_buffer, 1, _MAKE_WARM, 0, 0, 0); - tstate->interp->jit_state.jit_tracer_code_curr_size = 2; - tstate->interp->jit_state.jit_tracer_code_max_size = UOP_MAX_TRACE_LENGTH; - tstate->interp->jit_state.jit_tracer_insert_exec_instr = insert_exec_instr; - tstate->interp->jit_state.jit_tracer_close_loop_instr = close_loop_instr; - tstate->interp->jit_state.jit_tracer_initial_code = (PyCodeObject *)Py_NewRef(code); - tstate->interp->jit_state.jit_tracer_initial_func = (PyFunctionObject *)Py_NewRef(_PyFrame_GetFunction(frame)); - tstate->interp->jit_state.jit_tracer_previous_exit = exit; - _Py_BloomFilter_Init(&tstate->interp->jit_state.jit_tracer_dependencies); - tstate->interp->jit_state.jit_tracer_initial_stack_depth = curr_stackdepth; - tstate->interp->jit_state.jit_tracer_initial_chain_depth = chain_depth % MAX_CHAIN_DEPTH; - tstate->interp->jit_state.jit_tracer_current_frame = frame; - tstate->interp->jit_state.jit_tracer_dependencies_still_valid = true; + add_to_trace(tstate->interp->jit_state.code_buffer, 0, _START_EXECUTOR, 0, (uintptr_t)insert_exec_instr, INSTR_IP(insert_exec_instr, code)); + add_to_trace(tstate->interp->jit_state.code_buffer, 1, _MAKE_WARM, 0, 0, 0); + tstate->interp->jit_state.code_curr_size = 2; + tstate->interp->jit_state.code_max_size = UOP_MAX_TRACE_LENGTH; + tstate->interp->jit_state.insert_exec_instr = insert_exec_instr; + tstate->interp->jit_state.close_loop_instr = close_loop_instr; + tstate->interp->jit_state.initial_code = (PyCodeObject *)Py_NewRef(code); + tstate->interp->jit_state.initial_func = (PyFunctionObject *)Py_NewRef(_PyFrame_GetFunction(frame)); + tstate->interp->jit_state.previous_exit = exit; + _Py_BloomFilter_Init(&tstate->interp->jit_state.dependencies); + tstate->interp->jit_state.initial_stack_depth = curr_stackdepth; + tstate->interp->jit_state.initial_chain_depth = chain_depth % MAX_CHAIN_DEPTH; + tstate->interp->jit_state.current_frame = frame; + tstate->interp->jit_state.dependencies_still_valid = true; tstate->interp->jit_state.last_specialized_instr = NULL; } void -_PyJIT_FinalizeTracing(PyThreadState *tstate) +_PyJit_FinalizeTracing(PyThreadState *tstate) { - Py_CLEAR(tstate->interp->jit_state.jit_tracer_initial_code); - Py_CLEAR(tstate->interp->jit_state.jit_tracer_initial_func); - tstate->interp->jit_state.jit_tracer_code_curr_size = 2; - tstate->interp->jit_state.jit_tracer_code_max_size = UOP_MAX_TRACE_LENGTH - 1; + Py_CLEAR(tstate->interp->jit_state.initial_code); + Py_CLEAR(tstate->interp->jit_state.initial_func); + tstate->interp->jit_state.code_curr_size = 2; + tstate->interp->jit_state.code_max_size = UOP_MAX_TRACE_LENGTH - 1; } @@ -1215,17 +1215,17 @@ uop_optimize( _PyExecutorObject **exec_ptr, bool progress_needed) { - _PyBloomFilter *dependencies = &tstate->interp->jit_state.jit_tracer_dependencies; + _PyBloomFilter *dependencies = &tstate->interp->jit_state.dependencies; PyInterpreterState *interp = _PyInterpreterState_GET(); - _PyUOpInstruction *buffer = interp->jit_state.jit_tracer_code_buffer; + _PyUOpInstruction *buffer = interp->jit_state.code_buffer; OPT_STAT_INC(attempts); char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE"); bool is_noopt = true; if (env_var == NULL || *env_var == '\0' || *env_var > '0') { is_noopt = false; } - int curr_stackentries = tstate->interp->jit_state.jit_tracer_initial_stack_depth; - int length = interp->jit_state.jit_tracer_code_curr_size; + int curr_stackentries = tstate->interp->jit_state.initial_stack_depth; + int length = interp->jit_state.code_curr_size; // Trace too short, don't bother. if (length <= 5) { return 0; @@ -1234,7 +1234,7 @@ uop_optimize( assert(length < UOP_MAX_TRACE_LENGTH); OPT_STAT_INC(traces_created); if (!is_noopt) { - length = _Py_uop_analyze_and_optimize(tstate->interp->jit_state.jit_tracer_initial_func, buffer, + length = _Py_uop_analyze_and_optimize(tstate->interp->jit_state.initial_func, buffer, length, curr_stackentries, dependencies); if (length <= 0) { @@ -1259,7 +1259,7 @@ uop_optimize( OPT_HIST(effective_trace_length(buffer, length), optimized_trace_length_hist); length = prepare_for_execution(buffer, length); assert(length <= UOP_MAX_TRACE_LENGTH); - _PyExecutorObject *executor = make_executor_from_uops(buffer, length, dependencies, tstate->interp->jit_state.jit_tracer_initial_chain_depth); + _PyExecutorObject *executor = make_executor_from_uops(buffer, length, dependencies, tstate->interp->jit_state.initial_chain_depth); if (executor == NULL) { return -1; } @@ -1555,15 +1555,15 @@ error: } void -_Py_JITTracer_InvalidateDependency(PyThreadState *tstate, void *obj) +_PyJit_Tracer_InvalidateDependency(PyThreadState *tstate, void *obj) { _PyBloomFilter obj_filter; _Py_BloomFilter_Init(&obj_filter); _Py_BloomFilter_Add(&obj_filter, obj); - if (bloom_filter_may_contain(&tstate->interp->jit_state.jit_tracer_dependencies, &obj_filter)) + if (bloom_filter_may_contain(&tstate->interp->jit_state.dependencies, &obj_filter)) { - tstate->interp->jit_state.jit_tracer_dependencies_still_valid = false; + tstate->interp->jit_state.dependencies_still_valid = false; } } /* Invalidate all executors */ diff --git a/Python/pystate.c b/Python/pystate.c index f0790322abd1..ebb37fc8400e 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -556,11 +556,11 @@ init_interpreter(PyInterpreterState *interp, #endif #ifdef _Py_TIER2 - interp->jit_state.jit_tracer_code_buffer = NULL; - interp->jit_state.jit_tracer_initial_stack_depth = -1; - interp->jit_state.jit_tracer_initial_chain_depth = -1; - interp->jit_state.jit_tracer_initial_code = NULL; - interp->jit_state.jit_tracer_initial_func = NULL; + interp->jit_state.code_buffer = NULL; + interp->jit_state.initial_stack_depth = -1; + interp->jit_state.initial_chain_depth = -1; + interp->jit_state.initial_code = NULL; + interp->jit_state.initial_func = NULL; #endif llist_init(&interp->mem_free_queue.head); llist_init(&interp->asyncio_tasks_head); @@ -811,9 +811,9 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate) #ifdef _Py_TIER2 _Py_ClearExecutorDeletionList(interp); - if (interp->jit_state.jit_tracer_code_buffer != NULL) { - _PyObject_VirtualFree(interp->jit_state.jit_tracer_code_buffer, UOP_BUFFER_SIZE); - interp->jit_state.jit_tracer_code_buffer = NULL; + if (interp->jit_state.code_buffer != NULL) { + _PyObject_VirtualFree(interp->jit_state.code_buffer, UOP_BUFFER_SIZE); + interp->jit_state.code_buffer = NULL; } #endif _PyAST_Fini(interp); diff --git a/Tools/cases_generator/analyzer.py b/Tools/cases_generator/analyzer.py index 720bb5f0ec61..7a5e8786f2a8 100644 --- a/Tools/cases_generator/analyzer.py +++ b/Tools/cases_generator/analyzer.py @@ -696,7 +696,7 @@ NON_ESCAPING_FUNCTIONS = ( "PyStackRef_Unwrap", "_PyLong_CheckExactAndCompact", "_PyExecutor_FromExit", - "_PyJIT_InitializeTracing", + "_PyJit_InitializeTracing", ) -- 2.47.3