Skip to content

[3.13] gh-119258: Backport optimizer frame fixes in GH-119365 #120699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);
extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
_Py_UOpsContext *ctx,
PyCodeObject *co,
_Py_UopsSymbol **localsplus_start,
int n_locals_already_filled,
int curr_stackentries);
int curr_stackentries,
_Py_UopsSymbol **args,
int arg_len);
extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);

PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
Expand Down
2 changes: 1 addition & 1 deletion Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ optimize_uops(
if (_Py_uop_abstractcontext_init(ctx) < 0) {
goto out_of_space;
}
_Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, ctx->n_consumed, 0, curr_stacklen);
_Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, curr_stacklen, NULL, 0);
if (frame == NULL) {
return -1;
}
Expand Down
13 changes: 4 additions & 9 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,17 +616,12 @@ dummy_func(void) {
argcount++;
}

_Py_UopsSymbol **localsplus_start = ctx->n_consumed;
int n_locals_already_filled = 0;
// Can determine statically, so we interleave the new locals
// and make the current stack the new locals.
// This also sets up for true call inlining.

if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
localsplus_start = args;
n_locals_already_filled = argcount;
OUT_OF_SPACE_IF_NULL(new_frame = frame_new(ctx, co, 0, args, argcount));
} else {
OUT_OF_SPACE_IF_NULL(new_frame = frame_new(ctx, co, 0, NULL, 0));
}
OUT_OF_SPACE_IF_NULL(new_frame =
frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0));
}

op(_PY_FRAME_GENERAL, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
Expand Down
12 changes: 3 additions & 9 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 10 additions & 13 deletions Python/optimizer_symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,41 +303,38 @@ _Py_UOpsAbstractFrame *
_Py_uop_frame_new(
_Py_UOpsContext *ctx,
PyCodeObject *co,
_Py_UopsSymbol **localsplus_start,
int n_locals_already_filled,
int curr_stackentries)
int curr_stackentries,
_Py_UopsSymbol **args,
int arg_len)
{
assert(ctx->curr_frame_depth < MAX_ABSTRACT_FRAME_DEPTH);
_Py_UOpsAbstractFrame *frame = &ctx->frames[ctx->curr_frame_depth];

frame->stack_len = co->co_stacksize;
frame->locals_len = co->co_nlocalsplus;

frame->locals = localsplus_start;
frame->locals = ctx->n_consumed;
frame->stack = frame->locals + co->co_nlocalsplus;
frame->stack_pointer = frame->stack + curr_stackentries;
ctx->n_consumed = localsplus_start + (co->co_nlocalsplus + co->co_stacksize);
ctx->n_consumed = ctx->n_consumed + (co->co_nlocalsplus + co->co_stacksize);
if (ctx->n_consumed >= ctx->limit) {
return NULL;
}


// Initialize with the initial state of all local variables
for (int i = n_locals_already_filled; i < co->co_nlocalsplus; i++) {
for (int i = 0; i < arg_len; i++) {
frame->locals[i] = args[i];
}

for (int i = arg_len; i < co->co_nlocalsplus; i++) {
_Py_UopsSymbol *local = _Py_uop_sym_new_unknown(ctx);
if (local == NULL) {
return NULL;
}
frame->locals[i] = local;
}


// Initialize the stack as well
for (int i = 0; i < curr_stackentries; i++) {
_Py_UopsSymbol *stackvar = _Py_uop_sym_new_unknown(ctx);
if (stackvar == NULL) {
return NULL;
}
frame->stack[i] = stackvar;
}

Expand Down
Loading