Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,12 +1076,19 @@ _PyJit_FinalizeTracing(PyThreadState *tstate, int err)
exit->temperature = initial_temperature_backoff_counter(&tstate->interp->opt_config);
}
}
// Clear all recorded values
_PyJitUopBuffer *buffer = &tracer->code_buffer;
for (_PyUOpInstruction *inst = buffer->start; inst < buffer->next; inst++) {
if (_PyUop_Flags[inst->opcode] & HAS_RECORDS_VALUE_FLAG) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this means you can remove

        else if (_PyUop_Flags[opcode] & HAS_RECORDS_VALUE_FLAG) {
            Py_XDECREF((PyObject *)(uintptr_t)buffer[pc].operand0);
            buffer[pc].opcode = _NOP;
        }

in optimizer.c to avoid double work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do double work: https://github.com/python/cpython/pull/145420/changes#diff-de09f74c4306be5ef0284d665091976873569094d645a35b48467ea2a11d67f7R1531 and it is faster to leave the cleanup in the fixup pass as we have to do that pass anyway in the normal, non-error case.

Py_XDECREF((PyObject *)(uintptr_t)inst->operand0);
}
}
Py_CLEAR(tracer->initial_state.code);
Py_CLEAR(tracer->initial_state.func);
Py_CLEAR(tracer->initial_state.executor);
Py_CLEAR(tracer->prev_state.instr_code);
Py_CLEAR(tracer->prev_state.recorded_value);
uop_buffer_init(&tracer->code_buffer, &tracer->uop_array[0], UOP_MAX_TRACE_LENGTH);
uop_buffer_init(buffer, &tracer->uop_array[0], UOP_MAX_TRACE_LENGTH);
tracer->is_tracing = false;
}

Expand Down Expand Up @@ -1521,6 +1528,11 @@ uop_optimize(
}
assert(_PyOpcode_uop_name[buffer[pc].opcode]);
}
// We've cleaned up the references in the buffer, so discard the code buffer
// to avoid doing it again during tracer cleanup
_PyJitUopBuffer *code_buffer = &_tstate->jit_tracer_state->code_buffer;
code_buffer->next = code_buffer->start;

OPT_HIST(effective_trace_length(buffer, length), optimized_trace_length_hist);
_PyUOpInstruction *output = &_tstate->jit_tracer_state->uop_array[0];
length = stack_allocate(buffer, output, length);
Expand Down
Loading