Skip to content

Commit fac8c74

Browse files
fix problem with jumping labels
1 parent 108ab7f commit fac8c74

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

Python/ceval_macros.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@
132132

133133
#define TRACING_JUMP_TO_LABEL(label) \
134134
RECORD_JUMP_TAKEN() \
135-
RECORD_TRACE() \
136-
BAIL_TRACING_NO_DISPATCH() \
135+
RECORD_TRACE_NO_DISPATCH() \
137136
JUMP_TO_LABEL(label);
138137

139138
#if _Py_TAIL_CALL_INTERP || USE_COMPUTED_GOTOS

Python/generated_cases.c.h

Lines changed: 19 additions & 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: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,12 @@ _PyJIT_translate_single_bytecode_to_trace(
607607
!(opcode == JUMP_BACKWARD_NO_INTERRUPT || opcode == JUMP_BACKWARD || opcode == JUMP_BACKWARD_JIT) &&
608608
!(opcode == POP_JUMP_IF_TRUE || opcode == POP_JUMP_IF_FALSE || opcode == POP_JUMP_IF_NONE || opcode == POP_JUMP_IF_NOT_NONE);
609609

610+
assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
611+
612+
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
610613

611-
// Strange control-flow
612-
if (jump_taken || opcode == WITH_EXCEPT_START || opcode == RERAISE || opcode == CLEANUP_THROW || opcode == PUSH_EXC_INFO) {
614+
// Strange control-flow, unsupported opcode, etc.
615+
if (jump_taken || expansion->nuops == 0 || opcode == WITH_EXCEPT_START || opcode == RERAISE || opcode == CLEANUP_THROW || opcode == PUSH_EXC_INFO) {
613616
// Rewind to previous instruction and replace with _EXIT_TRACE.
614617
_PyUOpInstruction *curr = &trace[trace_length-1];
615618
while (curr->opcode != _SET_IP && trace_length > 1) {
@@ -620,10 +623,6 @@ _PyJIT_translate_single_bytecode_to_trace(
620623
curr->opcode = _EXIT_TRACE;
621624
goto done;
622625
}
623-
624-
assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
625-
626-
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
627626
RESERVE_RAW(expansion->nuops + needs_guard_ip + 3, "uop and various checks");
628627

629628
ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, target);
@@ -692,12 +691,9 @@ _PyJIT_translate_single_bytecode_to_trace(
692691
default:
693692
{
694693
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
695-
if (expansion->nuops == 0) {
696-
DPRINTF(2, "Unsupported opcode %s\n", _PyOpcode_OpName[opcode]);
697-
goto full;
698-
}
699694
// Reserve space for nuops (+ _SET_IP + _EXIT_TRACE)
700695
int nuops = expansion->nuops;
696+
assert(nuops > 0);
701697
RESERVE(nuops + 1); /* One extra for exit */
702698
uint32_t orig_oparg = oparg; // For OPARG_TOP/BOTTOM
703699
for (int i = 0; i < nuops; i++) {
@@ -906,6 +902,9 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length)
906902
for (int i = 0; i < length; i++) {
907903
_PyUOpInstruction *inst = &buffer[i];
908904
int opcode = inst->opcode;
905+
if (inst->format != UOP_FORMAT_TARGET) {
906+
fprintf(stdout, "I: %d\n", i);
907+
}
909908
int32_t target = (int32_t)uop_get_target(inst);
910909
uint16_t exit_flags = _PyUop_Flags[opcode] & (HAS_EXIT_FLAG | HAS_DEOPT_FLAG | HAS_PERIODIC_FLAG);
911910
if (exit_flags) {

Python/optimizer_analysis.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,12 @@ _Py_uop_analyze_and_optimize(
528528
{
529529
OPT_STAT_INC(optimizer_attempts);
530530

531-
// length = optimize_uops(
531+
// int err = optimize_uops(
532532
// _PyFrame_GetFunction(frame), buffer,
533533
// length, curr_stacklen, dependencies);
534534
//
535-
// if (length == 0) {
536-
// return length;
535+
// if (err == 0) {
536+
// return err;
537537
// }
538538

539539
assert(length > 0);

0 commit comments

Comments
 (0)