Skip to content

Commit a62fe40

Browse files
Clean up macros
1 parent c23e591 commit a62fe40

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
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-
/* Back up over EXTENDED_ARGs so executor is inserted at the corret place */
2982+
/* Back up over EXTENDED_ARGs so executor is inserted at the correct place */
29832983
_Py_CODEUNIT *insert_exec_at = this_instr;
29842984
while (oparg > 255) {
29852985
oparg >>= 8;

Python/ceval.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,20 @@ add_to_code_trace(PyThreadState *tstate, _PyInterpreterFrame *frame, PyCodeObjec
993993
assert(tstate->interp->jit_state.code_curr_size < UOP_MAX_TRACE_LENGTH);
994994
return !_PyJit_translate_single_bytecode_to_trace(tstate, frame, this_instr, next_instr, old_code, old_func, old_stack_level, opcode, oparg, jump_taken);
995995
}
996+
997+
998+
// 0 for success, -1 for error.
999+
static int
1000+
bail_tracing_and_jit(PyThreadState *tstate, _PyInterpreterFrame *frame)
1001+
{
1002+
int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);
1003+
int err = 0;
1004+
if (!_PyErr_Occurred(tstate) && !_is_sys_tracing) {
1005+
err = _PyOptimizer_Optimize(frame, tstate);
1006+
}
1007+
_PyJit_FinalizeTracing(tstate);
1008+
return err;
1009+
}
9961010
#endif
9971011

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

Python/ceval_macros.h

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,32 +144,19 @@
144144
DISPATCH_TABLE_VAR = TRACING_DISPATCH_TABLE;
145145
# define LEAVE_TRACING() \
146146
DISPATCH_TABLE_VAR = DISPATCH_TABLE;
147-
# define BAIL_TRACING_NO_DISPATCH() \
148-
do { \
149-
LEAVE_TRACING(); \
150-
if (!_PyErr_Occurred(tstate) && !_is_sys_tracing) { \
151-
_PyFrame_SetStackPointer(frame, stack_pointer); \
152-
int _err = _PyOptimizer_Optimize(frame, tstate); \
153-
_PyJit_FinalizeTracing(tstate); \
154-
stack_pointer = _PyFrame_GetStackPointer(frame); \
155-
if (_err < 0) { \
156-
JUMP_TO_LABEL(error); \
157-
} \
158-
} \
159-
else { \
160-
_PyFrame_SetStackPointer(frame, stack_pointer); \
161-
_PyJit_FinalizeTracing(tstate); \
162-
stack_pointer = _PyFrame_GetStackPointer(frame); \
163-
} \
164-
} while (0);
165147
# define RECORD_TRACE_NO_DISPATCH() do { \
166-
int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL); \
167-
if (_is_sys_tracing) { \
168-
LEAVE_TRACING(); \
169-
} \
170-
else if ((IS_JIT_TRACING() && add_to_code_trace(tstate, frame, old_code, old_func, _old_stack_level, this_instr, next_instr, opcode, oparg, _jump_taken))) { \
171-
BAIL_TRACING_NO_DISPATCH(); \
148+
int err = 0; \
149+
_PyFrame_SetStackPointer(frame, stack_pointer); \
150+
/* We need to check once more here in case it swapped out halfway. */ \
151+
if (IS_JIT_TRACING()) { \
152+
int full = add_to_code_trace(tstate, frame, old_code, old_func, _old_stack_level, this_instr, next_instr, opcode, oparg, _jump_taken); \
153+
if (full) { \
154+
LEAVE_TRACING(); \
155+
err = bail_tracing_and_jit(tstate, frame); \
156+
} \
172157
} \
158+
stack_pointer = _PyFrame_GetStackPointer(frame); \
159+
if (err < 0) { JUMP_TO_LABEL(error); } \
173160
} while (0);
174161
#endif
175162

Python/optimizer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ _PyJit_translate_single_bytecode_to_trace(
572572
_PyUOpInstruction *trace = tstate->interp->jit_state.code_buffer;
573573
int max_length = tstate->interp->jit_state.code_max_size;
574574

575+
int is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);
576+
if (is_sys_tracing) {
577+
goto full;
578+
}
579+
575580
#ifdef Py_DEBUG
576581
char *python_lltrace = Py_GETENV("PYTHON_LLTRACE");
577582
int lltrace = 0;

0 commit comments

Comments
 (0)