aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/optimizer_analysis.c
Commit message (Collapse)AuthorAge
* GH-128914: Remove conditional stack effects from `bytecodes.c` and the code ↵Mark Shannon2025-01-20
| | | | generators (GH-128918)
* GH-128939: Refactor JIT optimize structs (GH-128940)Mark Shannon2025-01-20
|
* gh-115999: Specialize loading attributes from modules in free-threaded ↵mpage2024-12-13
| | | | | | | | | builds (#127711) We use the same approach that was used for specialization of LOAD_GLOBAL in free-threaded builds: _CHECK_ATTR_MODULE is renamed to _CHECK_ATTR_MODULE_PUSH_KEYS; it pushes the keys object for the following _LOAD_ATTR_MODULE_FROM_KEYS (nee _LOAD_ATTR_MODULE). This arrangement avoids having to recheck the keys version. _LOAD_ATTR_MODULE is renamed to _LOAD_ATTR_MODULE_FROM_KEYS; it loads the value from the keys object pushed by the preceding _CHECK_ATTR_MODULE_PUSH_KEYS at the cached index.
* gh-120619: Strength reduce function guards, support 2-operand uop forms ↵Ken Jin2024-11-09
| | | | | (GH-124846) Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
* gh-115999: Refactor `LOAD_GLOBAL` specializations to avoid reloading ↵mpage2024-10-09
| | | | | | | | | | | | | | | | | | {globals, builtins} keys (gh-124953) Each of the `LOAD_GLOBAL` specializations is implemented roughly as: 1. Load keys version. 2. Load cached keys version. 3. Deopt if (1) and (2) don't match. 4. Load keys. 5. Load cached index into keys. 6. Load object from (4) at offset from (5). This is not thread-safe in free-threaded builds; the keys object may be replaced in between steps (3) and (4). This change refactors the specializations to avoid reloading the keys object and instead pass the keys object from guards to be consumed by downstream uops.
* gh-120619: Optimize through `_Py_FRAME_GENERAL` (GH-124518)Ken Jin2024-10-03
| | | | | * Optimize through _Py_FRAME_GENERAL * refactor
* gh-124296: Remove private dictionary version tag (PEP 699) (#124472)Sam Gross2024-10-01
|
* gh-123923: Defer refcounting for `f_funcobj` in `_PyInterpreterFrame` (#124026)Sam Gross2024-09-24
| | | | | | Use a `_PyStackRef` and defer the reference to `f_funcobj` when possible. This avoids some reference count contention in the common case of executing the same code object from multiple threads concurrently in the free-threaded build.
* GH-118095: Add tier two support for BINARY_SUBSCR_GETITEM (GH-120793)Mark Shannon2024-08-01
|
* gh-120642: Move private PyCode APIs to the internal C API (#120643)Victor Stinner2024-06-26
| | | | | | | | | | | | | | | * Move _Py_CODEUNIT and related functions to pycore_code.h. * Move _Py_BackoffCounter to pycore_backoff.h. * Move Include/cpython/optimizer.h content to pycore_optimizer.h. * Remove Include/cpython/optimizer.h. * Remove PyUnstable_Replace_Executor(). Rename functions: * PyUnstable_GetExecutor() => _Py_GetExecutor() * PyUnstable_GetOptimizer() => _Py_GetOptimizer() * PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer() * PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter() * PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()
* GH-120982: Add stack check assertions to generated interpreter code (GH-120992)Mark Shannon2024-06-25
|
* GH-120619: Clean up `RETURN_VALUE` instruction (GH-120624)Mark Shannon2024-06-17
| | | | | * Rename _POP_FRAME to _RETURN_VALUE as it returns a value as well as popping a frame. * Remove remaining _POP_FRAMEs
* gh-119258: Eliminate Type Guards in Tier 2 Optimizer with Watcher (GH-119365)Saul Shanabrook2024-06-08
| | | | | | | Co-authored-by: parmeggiani <parmeggiani@spaziodati.eu> Co-authored-by: dpdani <git@danieleparmeggiani.me> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com> Co-authored-by: Ken Jin <kenjin@python.org>
* GH-118910: Less boilerplate in the tier 2 optimizer (#118913)Mark Shannon2024-05-10
|
* gh-118335: Configure Tier 2 interpreter at build time (#118339)Guido van Rossum2024-04-30
| | | | | | | | | | | | | | | | | | | | | | The code for Tier 2 is now only compiled when configured with `--enable-experimental-jit[=yes|interpreter]`. We drop support for `PYTHON_UOPS` and -`Xuops`, but you can disable the interpreter or JIT at runtime by setting `PYTHON_JIT=0`. You can also build it without enabling it by default using `--enable-experimental-jit=yes-off`; enable with `PYTHON_JIT=1`. On Windows, the `build.bat` script supports `--experimental-jit`, `--experimental-jit-off`, `--experimental-interpreter`. In the C code, `_Py_JIT` is defined as before when the JIT is enabled; the new variable `_Py_TIER2` is defined when the JIT *or* the interpreter is enabled. It is actually a bitmask: 1: JIT; 2: default-off; 4: interpreter.
* GH-118095: Handle `RETURN_GENERATOR` in tier 2 (GH-118180)Mark Shannon2024-04-25
|
* GH-115419: Move setting the instruction pointer to error exit stubs (GH-118088)Mark Shannon2024-04-24
|
* GH-115480: Reduce guard strength for binary ops when type of one operand is ↵Mark Shannon2024-04-22
| | | | known already (GH-118050)
* GH-116202: Incorporate invalidation check into _START_EXECUTOR. (GH-118044)Mark Shannon2024-04-19
|
* GH-115419: Improve list of escaping functions (GH-118054)Mark Shannon2024-04-19
|
* GH-115419: Tidy up tier 2 optimizer. Merge peephole pass into main pass ↵Mark Shannon2024-04-18
| | | | (GH-117997)
* gh-116168: Remove extra `_CHECK_STACK_SPACE` uops (#117242)Peter Lazorchak2024-04-03
| | | This merges all `_CHECK_STACK_SPACE` uops in a trace into a single `_CHECK_STACK_SPACE_OPERAND` uop that checks whether there is enough stack space for all calls included in the entire trace.
* GH-116422: Tier2 hot/cold splitting (GH-116813)Mark Shannon2024-03-26
| | | | | Splits the "cold" path, deopts and exits, from the "hot" path, reducing the size of most jitted instructions, at the cost of slower exits.
* gh-117045: Add code object to function version cache (#117028)Guido van Rossum2024-03-21
| | | | | | | | | | | | | | | | | | | | | | | | | | Changes to the function version cache: - In addition to the function object, also store the code object, and allow the latter to be retrieved even if the function has been evicted. - Stop assigning new function versions after a critical attribute (e.g. `__code__`) has been modified; the version is permanently reset to zero in this case. - Changes to `__annotations__` are no longer considered critical. (This fixes gh-109998.) Changes to the Tier 2 optimization machinery: - If we cannot map a function version to a function, but it is still mapped to a code object, we continue projecting the trace. The operand of the `_PUSH_FRAME` and `_POP_FRAME` opcodes can be either NULL, a function object, or a code object with the lowest bit set. This allows us to trace through code that calls an ephemeral function, i.e., a function that may not be alive when we are constructing the executor, e.g. a generator expression or certain nested functions. We will lose globals removal inside such functions, but we can still do other peephole operations (and even possibly [call inlining](https://github.com/python/cpython/pull/116290), if we decide to do it), which only need the code object. As before, if we cannot retrieve the code object from the cache, we stop projecting.
* gh-116996: Add pystats about _Py_uop_analyse_and_optimize (GH-116997)Michael Droettboom2024-03-22
|
* GH-117066: Tier 2 optimizer: Don't throw away good traces if we can't ↵Mark Shannon2024-03-20
| | | | optimize them perfectly. (GH-117067)
* Cleanup tier2 debug output (#116920)Guido van Rossum2024-03-18
| | | Various tweaks, including a slight refactor of the special cases for `_PUSH_FRAME`/`_POP_FRAME` to show the actual operand emitted.
* GH-116596: Better determination of escaping uops. (GH-116597)Mark Shannon2024-03-11
|
* GH-113710: Fix optimization of globals using `_CHECK_FUNCTION` (GH-116460)Mark Shannon2024-03-08
|
* GH-113710: Tier 2 optimizer: check the function instead of checking globals. ↵Mark Shannon2024-03-06
| | | | (GH-116410)
* GH-115685: Split `_TO_BOOL_ALWAYS_TRUE` into micro-ops (GH-116352)Mark Shannon2024-03-05
|
* GH-115819: Eliminate Boolean guards when value is known (GH-116355)Mark Shannon2024-03-05
|
* GH-115685: Optimize `TO_BOOL` and variants based on truthiness of input. ↵Mark Shannon2024-03-05
| | | | (GH-116311)
* gh-116088: Insert bottom checks after all sym_set_...() calls (#116089)Guido van Rossum2024-02-29
| | | | | | | | | This changes the `sym_set_...()` functions to return a `bool` which is `false` when the symbol is `bottom` after the operation. All calls to such functions now check this result and go to `hit_bottom`, a special error label that prints a different message and then reports that it wasn't able to optimize the trace. No executor will be produced in this case.
* gh-115859: Re-enable T2 optimizer pass by default (#116062)Guido van Rossum2024-02-28
| | | | | | | | | | | | | This undoes the *temporary* default disabling of the T2 optimizer pass in gh-115860. - Add a new test that reproduces Brandt's example from gh-115859; it indeed crashes before gh-116028 with PYTHONUOPSOPTIMIZE=1 - Re-enable the optimizer pass in T2, stop checking PYTHONUOPSOPTIMIZE - Rename the env var to disable T2 entirely to PYTHON_UOPS_OPTIMIZE (must be explicitly set to 0 to disable) - Fix skipIf conditions on tests in test_opt.py accordingly - Export sym_is_bottom() (for debugging) - Fix various things in the `_BINARY_OP_` specializations in the abstract interpreter: - DECREF(temp) - out-of-space check after sym_new_const() - add sym_matches_type() checks, so even if we somehow reach a binary op with symbolic constants of the wrong type on the stack we won't trigger the type assert
* gh-115816: Improve internal symbols API in optimizer (#116028)Guido van Rossum2024-02-28
| | | | | | | - Any `sym_set_...` call that attempts to set conflicting information cause the symbol to become `bottom` (contradiction). - All `sym_is...` and similar calls return false or NULL for `bottom`. - Everything's tested. - The tests still pass with `PYTHONUOPSOPTIMIZE=1`.
* GH-115816: Assorted naming and formatting changes to improve ↵Mark Shannon2024-02-27
| | | | | | | maintainability. (GH-115987) * Rename _Py_UOpsAbstractInterpContext to _Py_UOpsContext and _Py_UOpsSymType to _Py_UopsSymbol. * #define shortened form of _Py_uop_... names for improved readability.
* GH-115816: Make tier2 optimizer symbols testable, and add a few tests. ↵Mark Shannon2024-02-27
| | | | (GH-115953)
* gh-115168: Add pystats counter for invalidated executors (GH-115169)Michael Droettboom2024-02-26
|
* Rename tier 2 redundancy eliminator to optimizer (#115888)Guido van Rossum2024-02-26
| | | | The original name is just too much of a mouthful.
* gh-115859: Disable the tier 2 redundancy eliminator by default (GH-115860)Ken Jin2024-02-23
|
* gh-114058: More robust method handling in redundancy eliminator (GH-115779)Ken Jin2024-02-23
|
* GH-115651: Convert `LOAD_MODULE_ATTR` into `LOAD_INLINE_CONST` when the ↵Mark Shannon2024-02-22
| | | | module is itself a constant. (GH-115711)
* Delete unused sym_clear_flag function. (#115744)Benjamin Peterson2024-02-20
|
* Tier 2 cleanups and tweaks (#115534)Guido van Rossum2024-02-20
| | | | | | | | | * Rename `_testinternalcapi.get_{uop,counter}_optimizer` to `new_*_optimizer` * Use `_PyUOpName()` instead of` _PyOpcode_uop_name[]` * Add `target` to executor iterator items -- `list(ex)` now returns `(opcode, oparg, target, operand)` quadruples * Add executor methods `get_opcode()` and `get_oparg()` to get `vmdata.opcode`, `vmdata.oparg` * Define a helper for printing uops, and unify various places where they are printed * Add a hack to summarize_stats.py to fix legacy uop names (e.g. `POP_TOP` -> `_POP_TOP`) * Define helpers in `test_opt.py` for accessing the set or list of opnames of an executor
* gh-115480: Minor fixups in int constant propagation (GH-115507)Ken Jin2024-02-16
|
* gh-115480: Type and constant propagation for int BINARY_OPs (GH-115478)Ken Jin2024-02-15
|
* GH-113710: Improve `_SET_IP` and `_CHECK_VALIDITY` (GH-115248)Mark Shannon2024-02-13
|
* gh-114058: Foundations of the Tier2 redundancy eliminator (GH-115085)Ken Jin2024-02-13
| | | | | | | --------- Co-authored-by: Mark Shannon <9448417+markshannon@users.noreply.github.com> Co-authored-by: Jules <57632293+JuliaPoo@users.noreply.github.com> Co-authored-by: Guido van Rossum <gvanrossum@users.noreply.github.com>
* GH-113710: Fix updating of dict version tag and add watched dict stats ↵Mark Shannon2024-02-12
| | | | (GH-115221)