Skip to content

Commit 7c7aa5a

Browse files
[3.13] gh-119258: Backport optimizer frame fixes in GH-119365 (GH-120699)
(cherry picked from commit 55402d3)
1 parent b8fd80f commit 7c7aa5a

File tree

5 files changed

+21
-35
lines changed

5 files changed

+21
-35
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);
107107
extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
108108
_Py_UOpsContext *ctx,
109109
PyCodeObject *co,
110-
_Py_UopsSymbol **localsplus_start,
111-
int n_locals_already_filled,
112-
int curr_stackentries);
110+
int curr_stackentries,
111+
_Py_UopsSymbol **args,
112+
int arg_len);
113113
extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);
114114

115115
PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);

Python/optimizer_analysis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ optimize_uops(
411411
if (_Py_uop_abstractcontext_init(ctx) < 0) {
412412
goto out_of_space;
413413
}
414-
_Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, ctx->n_consumed, 0, curr_stacklen);
414+
_Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, curr_stacklen, NULL, 0);
415415
if (frame == NULL) {
416416
return -1;
417417
}

Python/optimizer_bytecodes.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,17 +616,12 @@ dummy_func(void) {
616616
argcount++;
617617
}
618618

619-
_Py_UopsSymbol **localsplus_start = ctx->n_consumed;
620-
int n_locals_already_filled = 0;
621-
// Can determine statically, so we interleave the new locals
622-
// and make the current stack the new locals.
623-
// This also sets up for true call inlining.
619+
624620
if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
625-
localsplus_start = args;
626-
n_locals_already_filled = argcount;
621+
OUT_OF_SPACE_IF_NULL(new_frame = frame_new(ctx, co, 0, args, argcount));
622+
} else {
623+
OUT_OF_SPACE_IF_NULL(new_frame = frame_new(ctx, co, 0, NULL, 0));
627624
}
628-
OUT_OF_SPACE_IF_NULL(new_frame =
629-
frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0));
630625
}
631626

632627
op(_PY_FRAME_GENERAL, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {

Python/optimizer_cases.c.h

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

Python/optimizer_symbols.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -303,41 +303,38 @@ _Py_UOpsAbstractFrame *
303303
_Py_uop_frame_new(
304304
_Py_UOpsContext *ctx,
305305
PyCodeObject *co,
306-
_Py_UopsSymbol **localsplus_start,
307-
int n_locals_already_filled,
308-
int curr_stackentries)
306+
int curr_stackentries,
307+
_Py_UopsSymbol **args,
308+
int arg_len)
309309
{
310310
assert(ctx->curr_frame_depth < MAX_ABSTRACT_FRAME_DEPTH);
311311
_Py_UOpsAbstractFrame *frame = &ctx->frames[ctx->curr_frame_depth];
312312

313313
frame->stack_len = co->co_stacksize;
314314
frame->locals_len = co->co_nlocalsplus;
315315

316-
frame->locals = localsplus_start;
316+
frame->locals = ctx->n_consumed;
317317
frame->stack = frame->locals + co->co_nlocalsplus;
318318
frame->stack_pointer = frame->stack + curr_stackentries;
319-
ctx->n_consumed = localsplus_start + (co->co_nlocalsplus + co->co_stacksize);
319+
ctx->n_consumed = ctx->n_consumed + (co->co_nlocalsplus + co->co_stacksize);
320320
if (ctx->n_consumed >= ctx->limit) {
321321
return NULL;
322322
}
323323

324-
325324
// Initialize with the initial state of all local variables
326-
for (int i = n_locals_already_filled; i < co->co_nlocalsplus; i++) {
325+
for (int i = 0; i < arg_len; i++) {
326+
frame->locals[i] = args[i];
327+
}
328+
329+
for (int i = arg_len; i < co->co_nlocalsplus; i++) {
327330
_Py_UopsSymbol *local = _Py_uop_sym_new_unknown(ctx);
328-
if (local == NULL) {
329-
return NULL;
330-
}
331331
frame->locals[i] = local;
332332
}
333333

334334

335335
// Initialize the stack as well
336336
for (int i = 0; i < curr_stackentries; i++) {
337337
_Py_UopsSymbol *stackvar = _Py_uop_sym_new_unknown(ctx);
338-
if (stackvar == NULL) {
339-
return NULL;
340-
}
341338
frame->stack[i] = stackvar;
342339
}
343340

0 commit comments

Comments
 (0)