Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-114058: The Tier2 Optimizer#114059
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
29db898c1332cc9d85c3576cee0cb71aa06f0e5dec52e368fa273a2f60a1d797077ad55169bf30929bb870ee73e7d664406b18e304b1dff46a61b189e32f75119548e27ce30389157620974dadc9cd8a8eb56a90c9c78543e64d1fdf3b93881a859b7280281ac6e29f9e5ef681f27abbc88a8c6307c66f19ce538c7015813353996543c8276e554804e74c5b68298441de0ccbd2917b7553ac534555b0c4155d84e48a7947e7ba2d9aa7ccdd3d1e60d8d82e09692146fe648e22dc0d0cb132a878a726e00d9df64a72d6ef95991137de4b37acc6490cf59bba41882ce797bc1e22da28064fa51c262f9784a9e2b45868fb85a3f44ff450646d2268829a3585a882b48c551466f17a989cfcdc84c065b8a45be3458580dd14d603792f206bd017b4ae3913d95b425b40d2c884e2d7d8e8c47ee73201fb22463f8abd784d17179ba2be07ba96450154ada0b58b14573fca2096a8a4ad2804224f6b4b78461729835536a6b11fcfe1de05ad621173daf91cac3616e7df93a65fae9a3fec959dde7d1204c902b05e93c255f9bcb0726766a8adadaab60387File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -36,6 +36,9 @@ | ||
| #define PEEPHOLE_MAX_ATTEMPTS 5 | ||
| // +1 to account for implicit root frame. | ||
| #define MAX_ABSTRACT_FRAME_DEPTH (TRACE_STACK_SIZE + 1) | ||
| #ifdef Py_DEBUG | ||
| static const char *const DEBUG_ENV = "PYTHON_OPT_DEBUG"; | ||
| static inline int get_lltrace(void) { | ||
| @@ -102,7 +105,6 @@ typedef struct { | ||
| typedef struct _Py_UOpsAbstractFrame { | ||
| // Strong reference. | ||
| struct _Py_UOpsAbstractFrame *prev; | ||
Fidget-Spinner marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| // Borrowed reference. | ||
Fidget-Spinner marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| @@ -122,20 +124,13 @@ typedef struct _Py_UOpsAbstractFrame { | ||
| static void | ||
| abstractframe_dealloc(_Py_UOpsAbstractFrame *self) | ||
| { | ||
| if (self == NULL) { | ||
| return; | ||
| } | ||
| PyMem_Free(self->sym_consts); | ||
| abstractframe_dealloc(self->prev); | ||
| } | ||
| typedef struct ty_arena { | ||
| int ty_curr_number; | ||
| @@ -158,6 +153,9 @@ typedef struct _Py_UOpsAbstractInterpContext { | ||
| PyObject_HEAD | ||
| // The current "executing" frame. | ||
| _Py_UOpsAbstractFrame *frame; | ||
| // Need one more for the root frame. | ||
Fidget-Spinner marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| _Py_UOpsAbstractFrame frames[MAX_ABSTRACT_FRAME_DEPTH]; | ||
| int curr_frame_depth; | ||
| // Arena for the symbolic types. | ||
| ty_arena t_arena; | ||
| @@ -168,33 +166,26 @@ typedef struct _Py_UOpsAbstractInterpContext { | ||
| _Py_UOpsSymType **water_level; | ||
| _Py_UOpsSymType **limit; | ||
| _Py_UOpsSymType *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE]; | ||
| } _Py_UOpsAbstractInterpContext; | ||
| static void | ||
| abstractinterp_dealloc(_Py_UOpsAbstractInterpContext *self) | ||
| { | ||
| if (self == NULL) { | ||
| return; | ||
| } | ||
| abstractframe_dealloc(self->frame); | ||
| if (self->t_arena.arena != NULL) { | ||
| int tys = self->t_arena.ty_curr_number; | ||
| for (int i = 0; i < tys; i++) { | ||
| Py_CLEAR(self->t_arena.arena[i].const_val); | ||
| } | ||
| } | ||
| PyMem_Free(self->t_arena.arena); | ||
| PyMem_Free(self); | ||
| } | ||
| static inline _Py_UOpsAbstractFrame * | ||
| frame_new(_Py_UOpsAbstractInterpContext *ctx, | ||
| @@ -231,9 +222,7 @@ abstractinterp_context_new(PyCodeObject *co, | ||
| goto error; | ||
| } | ||
Fidget-Spinner marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| self = PyMem_New(_Py_UOpsAbstractInterpContext, 1); | ||
| if (self == NULL) { | ||
| goto error; | ||
| } | ||
| @@ -252,6 +241,7 @@ abstractinterp_context_new(PyCodeObject *co, | ||
| // Frame setup | ||
| self->curr_frame_depth = 0; | ||
| frame = frame_new(self, co->co_consts, stack_len, locals_len, curr_stacklen); | ||
| if (frame == NULL) { | ||
| goto error; | ||
| @@ -284,8 +274,8 @@ abstractinterp_context_new(PyCodeObject *co, | ||
| self->t_arena.arena = NULL; | ||
| self->frame = NULL; | ||
| } | ||
| abstractinterp_dealloc(self); | ||
| abstractframe_dealloc(frame); | ||
| return NULL; | ||
| } | ||
| @@ -381,8 +371,9 @@ frame_new(_Py_UOpsAbstractInterpContext *ctx, | ||
| if (sym_consts == NULL) { | ||
| return NULL; | ||
| } | ||
| _Py_UOpsAbstractFrame *frame = &ctx->frames[ctx->curr_frame_depth]; | ||
| ctx->curr_frame_depth++; | ||
| assert(ctx->curr_frame_depth <= MAX_ABSTRACT_FRAME_DEPTH); | ||
| if (frame == NULL) { | ||
| PyMem_Free(sym_consts); | ||
| return NULL; | ||
Fidget-Spinner marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| @@ -394,7 +385,6 @@ frame_new(_Py_UOpsAbstractInterpContext *ctx, | ||
| frame->stack_len = stack_len; | ||
| frame->locals_len = locals_len; | ||
| frame->prev = NULL; | ||
| return frame; | ||
| } | ||
| @@ -447,7 +437,6 @@ ctx_frame_push( | ||
| } | ||
| frame->prev = ctx->frame; | ||
| ctx->frame = frame; | ||
| @@ -465,8 +454,8 @@ ctx_frame_pop( | ||
| frame->prev = NULL; | ||
| ctx->water_level = frame->locals; | ||
| PyMem_Free(frame->sym_consts); | ||
| ctx->curr_frame_depth--; | ||
| return 0; | ||
| } | ||
| @@ -881,10 +870,15 @@ uop_abstract_interpret_single_inst( | ||
| // Don't put in the new frame. Leave it be so that _PUSH_FRAME | ||
| // can extract callable, self_or_null and args later. | ||
| // This also means our stack pointer diverges from the real VM. | ||
| // IMPORTANT: make sure there is no interference | ||
| // between this and _PUSH_FRAME. That is a required invariant. | ||
| break; | ||
| } | ||
| case _PUSH_FRAME: { | ||
| // From _INIT_CALL_PY_EXACT_ARGS | ||
| int argcount = oparg; | ||
| // _INIT_CALL_PY_EXACT_ARGS's real stack effect in the VM. | ||
| stack_pointer += -1 - oparg; | ||
| @@ -900,9 +894,10 @@ uop_abstract_interpret_single_inst( | ||
| assert(self_or_null != NULL); | ||
| _Py_UOpsSymType **args = &PEEK(-1); | ||
| assert(args != NULL); | ||
| if (!sym_is_type(self_or_null, NULL_TYPE) && | ||
| !sym_is_type(self_or_null, SELF_OR_NULL)) { | ||
| // Bound method fiddling, same as _INIT_CALL_PY_EXACT_ARGS in | ||
| // VM | ||
| args--; | ||
| argcount++; | ||
| } | ||
| @@ -1066,12 +1061,12 @@ uop_abstract_interpret( | ||
| res = ctx->emitter.curr_i; | ||
| abstractinterp_dealloc(ctx); | ||
| return res; | ||
| error: | ||
| abstractinterp_dealloc(ctx); | ||
| return -1; | ||
| } | ||