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 |
|---|---|---|
| @@ -23,6 +23,8 @@ | ||
| #define OVERALLOCATE_FACTOR 3 | ||
| #define PEEPHOLE_MAX_ATTEMPTS 10 | ||
| #ifdef Py_DEBUG | ||
| static const char *const DEBUG_ENV = "PYTHON_OPT_DEBUG"; | ||
| #define DPRINTF(level, ...) \ | ||
| @@ -227,6 +229,7 @@ abstractinterp_dealloc(PyObject *o) | ||
| } | ||
| PyMem_Free(self->t_arena.arena); | ||
| PyMem_Free(self->s_arena.arena); | ||
| PyMem_Free(self->frame_info.arena); | ||
| Py_TYPE(self)->tp_free((PyObject *)self); | ||
| } | ||
| @@ -1207,7 +1210,7 @@ uop_abstract_interpret_single_inst( | ||
| } | ||
| staticint | ||
| uop_abstract_interpret( | ||
| PyCodeObject *co, | ||
| _PyUOpInstruction *trace, | ||
| @@ -1323,34 +1326,56 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size) | ||
| } | ||
| } | ||
| static inline bool | ||
| op_is_zappable(int opcode) | ||
| { | ||
| switch(opcode) { | ||
| case _SET_IP: | ||
| ||
| case _CHECK_VALIDITY: | ||
| case _LOAD_CONST_INLINE: | ||
| case _LOAD_CONST: | ||
| case _LOAD_FAST: | ||
| case _LOAD_CONST_INLINE_BORROW: | ||
| return true; | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
| static inline bool | ||
| op_is_load(int opcode) | ||
| { | ||
| return (opcode == _LOAD_CONST_INLINE || | ||
| opcode == _LOAD_CONST || | ||
| opcode == LOAD_FAST || | ||
| opcode == _LOAD_CONST_INLINE_BORROW); | ||
| } | ||
| static int | ||
| peephole_optimizations(_PyUOpInstruction *buffer, int buffer_size) | ||
| { | ||
| bool done = true; | ||
| for (int i = 0; i < buffer_size; i++) { | ||
| _PyUOpInstruction *curr = buffer + i; | ||
| int oparg = curr->oparg; | ||
| switch(curr->opcode) { | ||
| case _SHRINK_STACK: { | ||
| // If all that precedes a _SHRINK_STACK is a bunch of LOAD_FAST, | ||
| // then we can safely eliminate that without side effects. | ||
| intload_count = 0; | ||
| _PyUOpInstruction *back = curr-1; | ||
| while(op_is_zappable(back->opcode) && | ||
| load_count < oparg) { | ||
Fidget-Spinner marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| load_count += op_is_load(back->opcode); | ||
| back--; | ||
| } | ||
| if (load_count == oparg) { | ||
| done = false; | ||
| curr->opcode = NOP; | ||
| back = curr-1; | ||
| load_count = 0; | ||
| while(load_count < oparg) { | ||
| load_count += op_is_load(back->opcode); | ||
| back->opcode = NOP; | ||
| back--; | ||
| } | ||
| @@ -1368,6 +1393,7 @@ peephole_optimizations(_PyUOpInstruction *buffer, int buffer_size) | ||
| break; | ||
| } | ||
| } | ||
| return done; | ||
| } | ||
| @@ -1396,7 +1422,11 @@ _Py_uop_analyze_and_optimize( | ||
| goto error; | ||
| } | ||
| for (int peephole_attempts = 0; peephole_attempts < PEEPHOLE_MAX_ATTEMPTS && | ||
| !peephole_optimizations(temp_writebuffer, new_trace_len); | ||
| peephole_attempts++) { | ||
| } | ||
| remove_unneeded_uops(temp_writebuffer, new_trace_len); | ||