Skip to content

Commit f886c43

Browse files
Fix jump tracing
1 parent 021fc44 commit f886c43

File tree

9 files changed

+1036
-88
lines changed

9 files changed

+1036
-88
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ _PyJIT_translate_single_bytecode_to_trace(
366366
PyCodeObject *code,
367367
PyFunctionObject *func,
368368
int opcode,
369-
int oparg);
369+
int oparg,
370+
int jump_taken);
370371

371372
void
372373
_PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr, int curr_stackdepth, int chain_depth);

Python/bytecodes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,6 +3230,7 @@ dummy_func(
32303230
}
32313231
// Jump forward by oparg and skip the following END_FOR
32323232
JUMPBY(oparg + 1);
3233+
RECORD_JUMP_TAKEN();
32333234
DISPATCH();
32343235
}
32353236
next = item;
@@ -3291,6 +3292,7 @@ dummy_func(
32913292
null_or_index = PyStackRef_TagInt(-1);
32923293
/* Jump forward oparg, then skip following END_FOR instruction */
32933294
JUMPBY(oparg + 1);
3295+
RECORD_JUMP_TAKEN();
32943296
DISPATCH();
32953297
}
32963298
#endif
@@ -3368,6 +3370,7 @@ dummy_func(
33683370
null_or_index = PyStackRef_TagInt(-1);
33693371
/* Jump forward oparg, then skip following END_FOR instruction */
33703372
JUMPBY(oparg + 1);
3373+
RECORD_JUMP_TAKEN();
33713374
DISPATCH();
33723375
}
33733376
}
@@ -3412,6 +3415,7 @@ dummy_func(
34123415
if (r->len <= 0) {
34133416
// Jump over END_FOR instruction.
34143417
JUMPBY(oparg + 1);
3418+
RECORD_JUMP_TAKEN();
34153419
DISPATCH();
34163420
}
34173421
}

Python/ceval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,12 +975,12 @@ _PyObjectArray_Free(PyObject **array, PyObject **scratch)
975975

976976
// 1 for trace full, 0 for successful write.
977977
static int
978-
add_to_code_trace(PyThreadState *tstate, _PyInterpreterFrame *frame, PyCodeObject *old_code, _Py_CODEUNIT *this_instr, _Py_CODEUNIT *next_instr, int opcode, int oparg)
978+
add_to_code_trace(PyThreadState *tstate, _PyInterpreterFrame *frame, PyCodeObject *old_code, _Py_CODEUNIT *this_instr, _Py_CODEUNIT *next_instr, int opcode, int oparg, int jump_taken)
979979
{
980980
assert(frame != NULL);
981981
assert(tstate->interp->jit_tracer_code_curr_size < UOP_MAX_TRACE_LENGTH);
982982
PyFunctionObject *func = (PyFunctionObject *)PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
983-
return !_PyJIT_translate_single_bytecode_to_trace(tstate, frame, this_instr, next_instr, old_code, func, opcode, oparg);
983+
return !_PyJIT_translate_single_bytecode_to_trace(tstate, frame, this_instr, next_instr, old_code, func, opcode, oparg, jump_taken);
984984
}
985985

986986
/* _PyEval_EvalFrameDefault is too large to optimize for speed with PGO on MSVC.

Python/ceval_macros.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
DISPATCH();
145145
# define RECORD_TRACE() do { \
146146
frame->instr_ptr = next_instr; \
147-
if (add_to_code_trace(tstate, frame, old_code, this_instr, next_instr, opcode, oparg)) { \
147+
if (add_to_code_trace(tstate, frame, old_code, this_instr, next_instr, opcode, oparg, _jump_taken)) { \
148148
BAIL_TRACING(); \
149149
} \
150150
} while (0);
@@ -339,6 +339,8 @@ GETITEM(PyObject *v, Py_ssize_t i) {
339339
#define RECORD_BRANCH_TAKEN(bitset, flag)
340340
#endif
341341

342+
#define RECORD_JUMP_TAKEN() _jump_taken = 1;
343+
342344
#define UNBOUNDLOCAL_ERROR_MSG \
343345
"cannot access local variable '%s' where it is not associated with a value"
344346
#define UNBOUNDFREE_ERROR_MSG \

0 commit comments

Comments
 (0)