mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	[3.13] gh-119258: Backport optimizer frame fixes in GH-119365 (GH-120699)
(cherry picked from commit 55402d3)
			
			
This commit is contained in:
		
							parent
							
								
									b8fd80f91b
								
							
						
					
					
						commit
						7c7aa5a99c
					
				
					 5 changed files with 21 additions and 35 deletions
				
			
		| 
						 | 
					@ -107,9 +107,9 @@ extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);
 | 
				
			||||||
extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
 | 
					extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
 | 
				
			||||||
    _Py_UOpsContext *ctx,
 | 
					    _Py_UOpsContext *ctx,
 | 
				
			||||||
    PyCodeObject *co,
 | 
					    PyCodeObject *co,
 | 
				
			||||||
    _Py_UopsSymbol **localsplus_start,
 | 
					    int curr_stackentries,
 | 
				
			||||||
    int n_locals_already_filled,
 | 
					    _Py_UopsSymbol **args,
 | 
				
			||||||
    int curr_stackentries);
 | 
					    int arg_len);
 | 
				
			||||||
extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);
 | 
					extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
 | 
					PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -411,7 +411,7 @@ optimize_uops(
 | 
				
			||||||
    if (_Py_uop_abstractcontext_init(ctx) < 0) {
 | 
					    if (_Py_uop_abstractcontext_init(ctx) < 0) {
 | 
				
			||||||
        goto out_of_space;
 | 
					        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) {
 | 
					    if (frame == NULL) {
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -616,17 +616,12 @@ dummy_func(void) {
 | 
				
			||||||
            argcount++;
 | 
					            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)) {
 | 
					        if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
 | 
				
			||||||
            localsplus_start = args;
 | 
					            OUT_OF_SPACE_IF_NULL(new_frame = frame_new(ctx, co, 0, args, argcount));
 | 
				
			||||||
            n_locals_already_filled = 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 *)) {
 | 
					    op(_PY_FRAME_GENERAL, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								Python/optimizer_cases.c.h
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										12
									
								
								Python/optimizer_cases.c.h
									
										
									
										generated
									
									
									
								
							| 
						 | 
					@ -1696,17 +1696,11 @@
 | 
				
			||||||
                args--;
 | 
					                args--;
 | 
				
			||||||
                argcount++;
 | 
					                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)) {
 | 
					            if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
 | 
				
			||||||
                localsplus_start = args;
 | 
					                OUT_OF_SPACE_IF_NULL(new_frame = frame_new(ctx, co, 0, args, argcount));
 | 
				
			||||||
                n_locals_already_filled = 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));
 | 
					 | 
				
			||||||
            stack_pointer[-2 - oparg] = (_Py_UopsSymbol *)new_frame;
 | 
					            stack_pointer[-2 - oparg] = (_Py_UopsSymbol *)new_frame;
 | 
				
			||||||
            stack_pointer += -1 - oparg;
 | 
					            stack_pointer += -1 - oparg;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -303,9 +303,9 @@ _Py_UOpsAbstractFrame *
 | 
				
			||||||
_Py_uop_frame_new(
 | 
					_Py_uop_frame_new(
 | 
				
			||||||
    _Py_UOpsContext *ctx,
 | 
					    _Py_UOpsContext *ctx,
 | 
				
			||||||
    PyCodeObject *co,
 | 
					    PyCodeObject *co,
 | 
				
			||||||
    _Py_UopsSymbol **localsplus_start,
 | 
					    int curr_stackentries,
 | 
				
			||||||
    int n_locals_already_filled,
 | 
					    _Py_UopsSymbol **args,
 | 
				
			||||||
    int curr_stackentries)
 | 
					    int arg_len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    assert(ctx->curr_frame_depth < MAX_ABSTRACT_FRAME_DEPTH);
 | 
					    assert(ctx->curr_frame_depth < MAX_ABSTRACT_FRAME_DEPTH);
 | 
				
			||||||
    _Py_UOpsAbstractFrame *frame = &ctx->frames[ctx->curr_frame_depth];
 | 
					    _Py_UOpsAbstractFrame *frame = &ctx->frames[ctx->curr_frame_depth];
 | 
				
			||||||
| 
						 | 
					@ -313,21 +313,21 @@ _Py_uop_frame_new(
 | 
				
			||||||
    frame->stack_len = co->co_stacksize;
 | 
					    frame->stack_len = co->co_stacksize;
 | 
				
			||||||
    frame->locals_len = co->co_nlocalsplus;
 | 
					    frame->locals_len = co->co_nlocalsplus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    frame->locals = localsplus_start;
 | 
					    frame->locals = ctx->n_consumed;
 | 
				
			||||||
    frame->stack = frame->locals + co->co_nlocalsplus;
 | 
					    frame->stack = frame->locals + co->co_nlocalsplus;
 | 
				
			||||||
    frame->stack_pointer = frame->stack + curr_stackentries;
 | 
					    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) {
 | 
					    if (ctx->n_consumed >= ctx->limit) {
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Initialize with the initial state of all local variables
 | 
					    // 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++) {
 | 
				
			||||||
        _Py_UopsSymbol *local = _Py_uop_sym_new_unknown(ctx);
 | 
					        frame->locals[i] = args[i];
 | 
				
			||||||
        if (local == NULL) {
 | 
					 | 
				
			||||||
            return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (int i = arg_len; i < co->co_nlocalsplus; i++) {
 | 
				
			||||||
 | 
					        _Py_UopsSymbol *local = _Py_uop_sym_new_unknown(ctx);
 | 
				
			||||||
        frame->locals[i] = local;
 | 
					        frame->locals[i] = local;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -335,9 +335,6 @@ _Py_uop_frame_new(
 | 
				
			||||||
    // Initialize the stack as well
 | 
					    // Initialize the stack as well
 | 
				
			||||||
    for (int i = 0; i < curr_stackentries; i++) {
 | 
					    for (int i = 0; i < curr_stackentries; i++) {
 | 
				
			||||||
        _Py_UopsSymbol *stackvar = _Py_uop_sym_new_unknown(ctx);
 | 
					        _Py_UopsSymbol *stackvar = _Py_uop_sym_new_unknown(ctx);
 | 
				
			||||||
        if (stackvar == NULL) {
 | 
					 | 
				
			||||||
            return NULL;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        frame->stack[i] = stackvar;
 | 
					        frame->stack[i] = stackvar;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue