Skip to content

Commit fa3e285

Browse files
Clean up labels
1 parent 7e2bc1d commit fa3e285

File tree

7 files changed

+91
-104
lines changed

7 files changed

+91
-104
lines changed

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_optimizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ PyAPI_FUNC(int) _PyDumpExecutors(FILE *out);
362362
extern void _Py_ClearExecutorDeletionList(PyInterpreterState *interp);
363363
#endif
364364

365-
int _PyJit_translate_single_bytecode_to_trace(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr);
365+
int _PyJit_translate_single_bytecode_to_trace(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr, bool stop_tracing);
366366

367367
int
368368
_PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame,

Python/bytecodes.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,33 +1218,19 @@ dummy_func(
12181218
tstate->current_frame = frame->previous;
12191219
assert(!_PyErr_Occurred(tstate));
12201220
PyObject *result = PyStackRef_AsPyObjectSteal(retval);
1221-
if (IS_JIT_TRACING()) {
1222-
#if _Py_TIER2
1223-
_PyJit_translate_single_bytecode_to_trace(tstate, frame, NULL);
1224-
LEAVE_TRACING();
1225-
int err = bail_tracing_and_jit(tstate, frame);
1226-
if (err < 0) {
1227-
Py_DECREF(result);
1228-
ERROR_IF(true);
1229-
}
1230-
return result;
1231-
#endif
1232-
}
1233-
else {
12341221
#if !_Py_TAIL_CALL_INTERP
1235-
assert(frame == &entry.frame);
1222+
assert(frame == &entry.frame);
12361223
#endif
12371224
#ifdef _Py_TIER2
1238-
_PyStackRef executor = frame->localsplus[0];
1239-
assert(tstate->current_executor == NULL);
1240-
if (!PyStackRef_IsNull(executor)) {
1241-
tstate->current_executor = PyStackRef_AsPyObjectBorrow(executor);
1242-
PyStackRef_CLOSE(executor);
1243-
}
1244-
#endif
1245-
LLTRACE_RESUME_FRAME();
1246-
return result;
1225+
_PyStackRef executor = frame->localsplus[0];
1226+
assert(tstate->current_executor == NULL);
1227+
if (!PyStackRef_IsNull(executor)) {
1228+
tstate->current_executor = PyStackRef_AsPyObjectBorrow(executor);
1229+
PyStackRef_CLOSE(executor);
12471230
}
1231+
#endif
1232+
LLTRACE_RESUME_FRAME();
1233+
return result;
12481234
}
12491235

12501236
// The stack effect here is a bit misleading.
@@ -3028,10 +3014,8 @@ dummy_func(
30283014
tier1 inst(ENTER_EXECUTOR, (--)) {
30293015
#ifdef _Py_TIER2
30303016
if (IS_JIT_TRACING()) {
3031-
_PyJit_translate_single_bytecode_to_trace(tstate, frame, next_instr);
3032-
LEAVE_TRACING();
3033-
int err = bail_tracing_and_jit(tstate, frame);
3034-
ERROR_IF(err < 0);
3017+
next_instr = this_instr;
3018+
goto stop_tracing;
30353019
}
30363020
PyCodeObject *code = _PyFrame_GetCode(frame);
30373021
_PyExecutorObject *executor = code->co_executors->executors[oparg & 255];
@@ -5657,7 +5641,10 @@ dummy_func(
56575641
#if _Py_TIER2
56585642
assert(IS_JIT_TRACING());
56595643
int opcode = next_instr->op.code;
5660-
int full = !_PyJit_translate_single_bytecode_to_trace(tstate, frame, next_instr);
5644+
bool stop_tracing = (opcode == WITH_EXCEPT_START ||
5645+
opcode == RERAISE || opcode == CLEANUP_THROW ||
5646+
opcode == PUSH_EXC_INFO || opcode == INTERPRETER_EXIT);
5647+
int full = !_PyJit_translate_single_bytecode_to_trace(tstate, frame, next_instr, stop_tracing);
56615648
if (full) {
56625649
LEAVE_TRACING();
56635650
int err = bail_tracing_and_jit(tstate, frame);
@@ -5677,9 +5664,9 @@ dummy_func(
56775664
_tstate->jit_state.prev_state.instr = next_instr;
56785665
}
56795666
_tstate->jit_state.prev_state.specialize_counter = 0;
5680-
PyCodeObject *prev_code = (PyCodeObject *)Py_NewRef(PyStackRef_AsPyObjectBorrow(frame->f_executable));
5681-
if (_tstate->jit_state.prev_state.instr_code != prev_code) {
5682-
Py_SETREF(_tstate->jit_state.prev_state.instr_code, prev_code);
5667+
PyObject *prev_code = PyStackRef_AsPyObjectBorrow(frame->f_executable);
5668+
if (_tstate->jit_state.prev_state.instr_code != (PyCodeObject *)prev_code) {
5669+
Py_SETREF(_tstate->jit_state.prev_state.instr_code, (PyCodeObject*)Py_NewRef((prev_code)));
56835670
}
56845671

56855672
_tstate->jit_state.prev_state.instr_frame = frame;
@@ -5691,6 +5678,19 @@ dummy_func(
56915678
#endif
56925679
}
56935680

5681+
label(stop_tracing) {
5682+
#if _Py_TIER2
5683+
assert(IS_JIT_TRACING());
5684+
_PyJit_translate_single_bytecode_to_trace(tstate, frame, NULL, true);
5685+
LEAVE_TRACING();
5686+
int err = bail_tracing_and_jit(tstate, frame);
5687+
ERROR_IF(err < 0);
5688+
DISPATCH_GOTO_NON_TRACING();
5689+
#else
5690+
Py_FatalError("JIT label executed in non-jit build.");
5691+
#endif
5692+
}
5693+
56945694

56955695
// END BYTECODES //
56965696

Python/ceval.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,13 +1017,7 @@ bail_tracing_and_jit(PyThreadState *tstate, _PyInterpreterFrame *frame)
10171017
// Likewise, we hold a strong reference to the executor containing this exit, so the exit is guaranteed
10181018
// to be valid to access.
10191019
if (err <= 0) {
1020-
// Some opcodes will forever be unchanged. Don't ever bother specializing for them ever again.
1021-
if (_tstate->jit_state.prev_state.instr->op.code == INTERPRETER_EXIT) {
1022-
exit->temperature = initial_unreachable_backoff_counter();
1023-
}
1024-
else {
1025-
exit->temperature = restart_backoff_counter(exit->temperature);
1026-
}
1020+
exit->temperature = restart_backoff_counter(exit->temperature);
10271021
}
10281022
else {
10291023
exit->temperature = initial_temperature_backoff_counter();

Python/generated_cases.c.h

Lines changed: 42 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_targets.h

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

Python/optimizer.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ int
552552
_PyJit_translate_single_bytecode_to_trace(
553553
PyThreadState *tstate,
554554
_PyInterpreterFrame *frame,
555-
_Py_CODEUNIT *next_instr)
555+
_Py_CODEUNIT *next_instr,
556+
bool stop_tracing)
556557
{
557558

558559
#ifdef Py_DEBUG
@@ -571,11 +572,6 @@ _PyJit_translate_single_bytecode_to_trace(
571572
_PyUOpInstruction *trace = _tstate->jit_state.code_buffer;
572573
int max_length = _tstate->jit_state.prev_state.code_max_size;
573574

574-
int is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);
575-
if (is_sys_tracing) {
576-
goto full;
577-
}
578-
579575
_Py_CODEUNIT *this_instr = _tstate->jit_state.prev_state.instr;
580576
_Py_CODEUNIT *target_instr = this_instr;
581577
uint32_t target = 0;
@@ -619,6 +615,17 @@ _PyJit_translate_single_bytecode_to_trace(
619615
DPRINTF(2, "Unsupported: dynamic jump taken %s\n", _PyOpcode_OpName[opcode]);
620616
goto unsupported;
621617
}
618+
619+
int is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);
620+
if (is_sys_tracing) {
621+
goto full;
622+
}
623+
624+
if (stop_tracing) {
625+
ADD_TO_TRACE(_DEOPT, 0, 0, target);
626+
goto done;
627+
}
628+
622629
DPRINTF(2, "%p %d: %s(%d) %d %d\n", old_code, target, _PyOpcode_OpName[opcode], oparg, needs_guard_ip, old_stack_level);
623630

624631
#ifdef Py_DEBUG
@@ -655,11 +662,6 @@ _PyJit_translate_single_bytecode_to_trace(
655662

656663
// TODO (gh-140277): The constituent use one extra stack slot. So we need to check for headroom.
657664
if (opcode == BINARY_OP_SUBSCR_GETITEM && old_stack_level + 1 > old_code->co_stacksize) {
658-
goto unsupported;
659-
}
660-
661-
if (opcode == WITH_EXCEPT_START || opcode == RERAISE || opcode == CLEANUP_THROW || opcode == PUSH_EXC_INFO) {
662-
DPRINTF(2, "Unsupported: strange control-flow\n");
663665
unsupported:
664666
{
665667
// Rewind to previous instruction and replace with _EXIT_TRACE.
@@ -773,9 +775,6 @@ _PyJit_translate_single_bytecode_to_trace(
773775
* start with RESUME_CHECK */
774776
ADD_TO_TRACE(_TIER2_RESUME_CHECK, 0, 0, target);
775777
break;
776-
case INTERPRETER_EXIT:
777-
ADD_TO_TRACE(_DEOPT, 0, 0, target);
778-
goto done;;
779778
default:
780779
{
781780
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];

0 commit comments

Comments
 (0)