Skip to content

Commit ffa2b72

Browse files
Use a different chain depth for dynamic exits
1 parent 253f230 commit ffa2b72

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
132132
// handle before rejoining the rest of the program.
133133
#define MAX_CHAIN_DEPTH 4
134134

135+
// The maximum number of side exits arising from unpredictable control-flow.
136+
#define MAX_DYNAMIC_CHAIN_DEPTH 6
137+
135138
/* Symbols */
136139
/* See explanation in optimizer_symbols.c */
137140

Python/bytecodes.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5412,7 +5412,6 @@ dummy_func(
54125412
#ifndef _Py_JIT
54135413
assert(current_executor == (_PyExecutorObject*)executor);
54145414
#endif
5415-
assert(tstate->jit_exit != NULL || tstate->jit_exit->executor == current_executor);
54165415
tstate->current_executor = (PyObject *)executor;
54175416
if (!current_executor->vm_data.valid) {
54185417
assert(tstate->jit_exit->executor == current_executor);
@@ -5507,7 +5506,7 @@ dummy_func(
55075506
if (target->op.code == ENTER_EXECUTOR) {
55085507
PyCodeObject *code = _PyFrame_GetCode(frame);
55095508
executor = code->co_executors->executors[target->op.arg];
5510-
if (executor->trace[2].opcode == _GUARD_EXECUTOR_IP && executor->vm_data.valid) {
5509+
if (executor->trace[0].opcode == _START_DYNAMIC_EXECUTOR && executor->vm_data.valid) {
55115510
Py_INCREF(executor);
55125511
assert(tstate->jit_exit == exit);
55135512
exit->executor = executor;

Python/executor_cases.c.h

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

Python/optimizer.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ _PyOptimizer_Optimize(
133133
// make progress in order to avoid infinite loops or excessively-long
134134
// side-exit chains. We can only insert the executor into the bytecode if
135135
// this is true, since a deopt won't infinitely re-enter the executor:
136-
chain_depth %= MAX_CHAIN_DEPTH;
136+
if (tstate->interp->jit_state.code_buffer[0].opcode == _START_DYNAMIC_EXECUTOR) {
137+
chain_depth %= MAX_DYNAMIC_CHAIN_DEPTH;
138+
}
139+
else {
140+
chain_depth %= MAX_CHAIN_DEPTH;
141+
}
137142
bool progress_needed = chain_depth == 0;
138143
PyCodeObject *code = (PyCodeObject *)tstate->interp->jit_state.initial_code;
139144
_Py_CODEUNIT *start = tstate->interp->jit_state.insert_exec_instr;
@@ -951,10 +956,7 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _
951956
if (oparg > 0xFFFF) {
952957
return 0;
953958
}
954-
// Dynamic exits with progress is wonky.
955-
if (is_dynamic_target && chain_depth >= MAX_CHAIN_DEPTH) {
956-
return 0;
957-
}
959+
958960
PyCodeObject *code = _PyFrame_GetCode(frame);
959961
#ifdef Py_DEBUG
960962
char *python_lltrace = Py_GETENV("PYTHON_LLTRACE");

0 commit comments

Comments
 (0)