Skip to content

Commit 754b3b7

Browse files
Close loops
1 parent b00252e commit 754b3b7

File tree

8 files changed

+16
-15
lines changed

8 files changed

+16
-15
lines changed

Include/internal/pycore_interp_structs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ typedef struct _PyJitState {
763763
_PyBloomFilter jit_tracer_dependencies;
764764
bool jit_tracer_dependencies_still_valid;
765765
_PyUOpInstruction *jit_tracer_code_buffer;
766-
_Py_CODEUNIT *jit_tracer_initial_instr;
766+
_Py_CODEUNIT *jit_tracer_insert_exec_instr;
767+
_Py_CODEUNIT *jit_tracer_close_loop_instr;
767768
int jit_tracer_initial_stack_depth;
768769
int jit_tracer_initial_chain_depth;
769770
PyCodeObject *jit_tracer_initial_code; // Strong

Include/internal/pycore_optimizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ _PyJIT_translate_single_bytecode_to_trace(
373373
int jump_taken);
374374

375375
void
376-
_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit);
376+
_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *insert_exec_instr, _Py_CODEUNIT *close_loop_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit);
377377

378378
void _PyJIT_FinalizeTracing(PyThreadState *tstate);
379379

Python/bytecodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,7 +2979,7 @@ dummy_func(
29792979
}
29802980
int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);
29812981
if (!_is_sys_tracing) {
2982-
_PyJIT_InitializeTracing(tstate, frame, this_instr, STACK_LEVEL(), 0, NULL);
2982+
_PyJIT_InitializeTracing(tstate, frame, this_instr, next_instr, STACK_LEVEL(), 0, NULL);
29832983
ENTER_TRACING();
29842984
}
29852985
int _jump_taken = false;
@@ -5451,7 +5451,7 @@ dummy_func(
54515451
_PyExecutorObject *previous_executor = _PyExecutor_FromExit(exit);
54525452
assert(tstate->current_executor == (PyObject *)previous_executor);
54535453
int chain_depth = previous_executor->vm_data.chain_depth + 1;
5454-
_PyJIT_InitializeTracing(tstate, frame, target, STACK_LEVEL(), chain_depth, exit);
5454+
_PyJIT_InitializeTracing(tstate, frame, target, target, STACK_LEVEL(), chain_depth, exit);
54555455
exit->temperature = initial_temperature_backoff_counter();
54565456
GOTO_TIER_ONE(target, 1);
54575457
}

Python/executor_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_tracer_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ _PyOptimizer_Optimize(
131131
chain_depth %= MAX_CHAIN_DEPTH;
132132
bool progress_needed = chain_depth == 0;
133133
PyCodeObject *code = (PyCodeObject *)tstate->interp->jit_state.jit_tracer_initial_code;
134-
_Py_CODEUNIT *start = tstate->interp->jit_state.jit_tracer_initial_instr;
134+
_Py_CODEUNIT *start = tstate->interp->jit_state.jit_tracer_insert_exec_instr;
135135
// A recursive trace might've cleared the values. In that case, bail.
136136
if (code == NULL) {
137137
interp->compiling = false;
@@ -570,7 +570,7 @@ _PyJIT_translate_single_bytecode_to_trace(
570570
int jump_taken)
571571
{
572572

573-
int is_first_instr = tstate->interp->jit_state.jit_tracer_initial_instr == this_instr;
573+
int is_first_instr = tstate->interp->jit_state.jit_tracer_close_loop_instr == this_instr;
574574
bool progress_needed = (tstate->interp->jit_state.jit_tracer_initial_chain_depth % MAX_CHAIN_DEPTH) == 0;;
575575
_PyBloomFilter *dependencies = &tstate->interp->jit_state.jit_tracer_dependencies;
576576
_Py_BloomFilter_Add(dependencies, old_code);
@@ -686,7 +686,7 @@ _PyJIT_translate_single_bytecode_to_trace(
686686
}
687687

688688
// Loop back to the start
689-
if (is_first_instr && tstate->interp->jit_state.jit_tracer_code_curr_size > 2) {
689+
if (is_first_instr && tstate->interp->jit_state.jit_tracer_code_curr_size > 5) {
690690
ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 0);
691691
goto done;
692692
}
@@ -876,7 +876,7 @@ _PyJIT_translate_single_bytecode_to_trace(
876876
}
877877

878878
void
879-
_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit)
879+
_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *insert_exec_instr, _Py_CODEUNIT *close_loop_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit)
880880
{
881881
PyCodeObject *code = _PyFrame_GetCode(frame);
882882
#ifdef Py_DEBUG
@@ -890,14 +890,15 @@ _PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_
890890
PyUnicode_AsUTF8(code->co_qualname),
891891
PyUnicode_AsUTF8(code->co_filename),
892892
code->co_firstlineno,
893-
2 * INSTR_IP(next_instr, code),
893+
2 * INSTR_IP(close_loop_instr, code),
894894
chain_depth);
895895
#endif
896-
add_to_trace(tstate->interp->jit_state.jit_tracer_code_buffer, 0, _START_EXECUTOR, 0, (uintptr_t)next_instr, INSTR_IP(next_instr, code));
896+
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));
897897
add_to_trace(tstate->interp->jit_state.jit_tracer_code_buffer, 1, _MAKE_WARM, 0, 0, 0);
898898
tstate->interp->jit_state.jit_tracer_code_curr_size = 2;
899899
tstate->interp->jit_state.jit_tracer_code_max_size = UOP_MAX_TRACE_LENGTH;
900-
tstate->interp->jit_state.jit_tracer_initial_instr = next_instr;
900+
tstate->interp->jit_state.jit_tracer_insert_exec_instr = insert_exec_instr;
901+
tstate->interp->jit_state.jit_tracer_close_loop_instr = close_loop_instr;
901902
tstate->interp->jit_state.jit_tracer_initial_code = (PyCodeObject *)Py_NewRef(code);
902903
tstate->interp->jit_state.jit_tracer_initial_func = (PyFunctionObject *)Py_NewRef(_PyFrame_GetFunction(frame));
903904
tstate->interp->jit_state.jit_tracer_previous_exit = exit;

Python/pystate.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ init_interpreter(PyInterpreterState *interp,
557557

558558
#ifdef _Py_TIER2
559559
interp->jit_state.jit_tracer_code_buffer = NULL;
560-
interp->jit_state.jit_tracer_initial_instr = NULL;
561560
interp->jit_state.jit_tracer_initial_stack_depth = -1;
562561
interp->jit_state.jit_tracer_initial_chain_depth = -1;
563562
interp->jit_state.jit_tracer_initial_code = NULL;

0 commit comments

Comments
 (0)