mirror of
https://github.com/python/cpython.git
synced 2026-02-24 08:01:14 +00:00
GH-144651: Optimize the new uops added when recording values during tracing. (GH-144948)
* Handle dependencies in the optimizer, not the tracer * Strengthen some checks to avoid relying on optimizer for correctness
This commit is contained in:
parent
20caf1c084
commit
3f37b94c73
18 changed files with 277 additions and 242 deletions
|
|
@ -55,23 +55,21 @@
|
|||
static void
|
||||
dump_abstract_stack(_Py_UOpsAbstractFrame *frame, JitOptRef *stack_pointer)
|
||||
{
|
||||
JitOptRef *stack_base = frame->stack;
|
||||
JitOptRef *locals_base = frame->locals;
|
||||
printf(" locals=[");
|
||||
for (JitOptRef *ptr = locals_base; ptr < stack_base; ptr++) {
|
||||
if (ptr != locals_base) {
|
||||
for (int i = 0 ; i < frame->locals_len; i++) {
|
||||
if (i > 0) {
|
||||
printf(", ");
|
||||
}
|
||||
_PyUOpSymPrint(*ptr);
|
||||
_PyUOpSymPrint(frame->locals[i]);
|
||||
}
|
||||
printf("]\n");
|
||||
if (stack_pointer < stack_base) {
|
||||
printf(" stack=%d\n", (int)(stack_pointer - stack_base));
|
||||
if (stack_pointer < frame->stack) {
|
||||
printf(" stack=%d\n", (int)(stack_pointer - frame->stack));
|
||||
}
|
||||
else {
|
||||
printf(" stack=[");
|
||||
for (JitOptRef *ptr = stack_base; ptr < stack_pointer; ptr++) {
|
||||
if (ptr != stack_base) {
|
||||
for (JitOptRef *ptr = frame->stack; ptr < stack_pointer; ptr++) {
|
||||
if (ptr != frame->stack) {
|
||||
printf(", ");
|
||||
}
|
||||
_PyUOpSymPrint(*ptr);
|
||||
|
|
@ -291,6 +289,7 @@ add_op(JitOptContext *ctx, _PyUOpInstruction *this_instr,
|
|||
#define sym_set_recorded_gen_func(SYM, VAL) _Py_uop_sym_set_recorded_gen_func(ctx, SYM, VAL)
|
||||
#define sym_get_probable_func_code _Py_uop_sym_get_probable_func_code
|
||||
#define sym_get_probable_value _Py_uop_sym_get_probable_value
|
||||
#define sym_set_stack_depth(DEPTH, SP) _Py_uop_sym_set_stack_depth(ctx, DEPTH, SP)
|
||||
|
||||
/* Comparison oparg masks */
|
||||
#define COMPARE_LT_MASK 2
|
||||
|
|
@ -473,14 +472,15 @@ optimize_uops(
|
|||
interp->type_watchers[TYPE_WATCHER_ID] = type_watcher_callback;
|
||||
}
|
||||
|
||||
_Py_uop_abstractcontext_init(ctx);
|
||||
_Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, (PyCodeObject *)func->func_code, curr_stacklen, NULL, 0);
|
||||
_Py_uop_abstractcontext_init(ctx, dependencies);
|
||||
_Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, (PyCodeObject *)func->func_code, NULL, 0);
|
||||
if (frame == NULL) {
|
||||
return 0;
|
||||
}
|
||||
frame->func = func;
|
||||
ctx->curr_frame_depth++;
|
||||
ctx->frame = frame;
|
||||
_Py_uop_sym_set_stack_depth(ctx, curr_stacklen, frame->stack_pointer);
|
||||
|
||||
_PyUOpInstruction *this_instr = NULL;
|
||||
JitOptRef *stack_pointer = ctx->frame->stack_pointer;
|
||||
|
|
@ -718,8 +718,7 @@ _Py_uop_analyze_and_optimize(
|
|||
OPT_STAT_INC(optimizer_attempts);
|
||||
|
||||
length = optimize_uops(
|
||||
tstate, buffer, length, curr_stacklen,
|
||||
output, dependencies);
|
||||
tstate, buffer, length, curr_stacklen, output, dependencies);
|
||||
|
||||
if (length == 0) {
|
||||
return length;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue