summaryrefslogtreecommitdiffstats
path: root/Python/optimizer.c
Commit message (Collapse)AuthorAgeFilesLines
* GH-116422: Tier2 hot/cold splitting (GH-116813)Mark Shannon2024-03-261-97/+282
| | | | | 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-117180: Complete call sequence when trace stack overflow (GH-117184)Ken Jin2024-03-231-0/+1
| | | | | | | --------- Co-authored-by: Peter Lazorchak <lazorchakp@gmail.com> Co-authored-by: Guido van Rossum <gvanrossum@users.noreply.github.com> Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
* gh-117045: Add code object to function version cache (#117028)Guido van Rossum2024-03-211-17/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-108362: Incremental Cycle GC (GH-116206)Mark Shannon2024-03-201-1/+1
|
* gh-116808: Fix optimized trace length histogram (GH-116827)Michael Droettboom2024-03-191-1/+2
|
* Cleanup tier2 debug output (#116920)Guido van Rossum2024-03-181-16/+27
| | | Various tweaks, including a slight refactor of the special cases for `_PUSH_FRAME`/`_POP_FRAME` to show the actual operand emitted.
* gh-116760: Fix pystats for trace attempts (GH-116761)Michael Droettboom2024-03-131-0/+1
| | | | | | | | There are now at least two bytecodes that may attempt to optimize, JUMP_BACK, and more recently, COLD_EXIT. Only the JUMP_BACK was counting the attempt in the stats. This moves that counter to uop_optimize itself so it should always happen no matter where it is called from.
* GH-116596: Better determination of escaping uops. (GH-116597)Mark Shannon2024-03-111-0/+1
|
* Fix debug output for optimized executor (#116337)Guido van Rossum2024-03-051-3/+4
| | | | This adjusts `length` rather than using `length+1` all over the place.
* gh-115859: Re-enable T2 optimizer pass by default (#116062)Guido van Rossum2024-02-281-2/+2
| | | | | | | | | | | | | 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-115168: Add pystats counter for invalidated executors (GH-115169)Michael Droettboom2024-02-261-2/+8
|
* gh-115727: Reduce confidence even on 100% predicted jumps (#115748)Guido van Rossum2024-02-221-7/+13
| | | | | | | | The theory is that even if we saw a jump go in the same direction the last 16 times we got there, we shouldn't be overly confident that it's still going to go the same way in the future. This PR makes it so that in the extreme cases, the confidence is multiplied by 0.9 instead of remaining unchanged. For unpredictable jumps, there is no difference (still 0.5). For somewhat predictable jumps, we interpolate.
* Tier 2 cleanups and tweaks (#115534)Guido van Rossum2024-02-201-14/+63
| | | | | | | | | * 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-115457: Support splitting and replication of micro ops. (GH-115558)Mark Shannon2024-02-201-0/+15
|
* GH-112354: Initial implementation of warm up on exits and trace-stitching ↵Mark Shannon2024-02-201-40/+165
| | | | (GH-114142)
* GH-113710: Improve `_SET_IP` and `_CHECK_VALIDITY` (GH-115248)Mark Shannon2024-02-131-3/+2
|
* GH-113710: Backedge counter improvements. (GH-115166)Mark Shannon2024-02-131-15/+33
|
* gh-114058: Foundations of the Tier2 redundancy eliminator (GH-115085)Ken Jin2024-02-131-7/+6
| | | | | | | --------- 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-114695: Add `sys._clear_internal_caches` (GH-115152)Brandt Bucher2024-02-121-29/+35
|
* GH-113710: Add a "globals to constants" pass (GH-114592)Mark Shannon2024-02-021-23/+29
| | | Converts specializations of `LOAD_GLOBAL` into constants during tier 2 optimization.
* GH-113464: Add a JIT backend for tier 2 (GH-113465)Brandt Bucher2024-01-291-0/+12
| | | | | | | Add an option (--enable-experimental-jit for configure-based builds or --experimental-jit for PCbuild-based ones) to build an *experimental* just-in-time compiler, based on copy-and-patch (https://fredrikbk.com/publications/copy-and-patch.pdf). See Tools/jit/README.md for more information on how to install the required build-time tooling.
* GH-112354: `END_FOR` instruction to only pop one value. (GH-114247)Mark Shannon2024-01-241-3/+4
| | | | * Compiler emits END_FOR; POP_TOP instead of END_FOR. To support tier 2 side exits in loops.
* GH-113710: Add a tier 2 peephole optimization pass. (GH-114487)Mark Shannon2024-01-241-0/+6
| | | | | * Convert _LOAD_CONST to inline versions * Remove PEP 523 checks
* GH-112354: `_GUARD_IS_TRUE_POP` side-exits to target the next instruction, ↵Mark Shannon2024-01-151-3/+4
| | | | not themselves. (GH-114078)
* GH-113860: Get rid of `_PyUOpExecutorObject` (GH-113954)Brandt Bucher2024-01-121-19/+19
|
* GH-113853: Guarantee forward progress in executors (GH-113854)Mark Shannon2024-01-111-63/+92
|
* GH-113860: All executors are now defined in terms of micro ops. Convert ↵Mark Shannon2024-01-101-110/+79
| | | | counter executor to use uops. (GH-113864)
* Fix opcode name printing in debug mode (#113870)Guido van Rossum2024-01-091-3/+3
| | | Fix a few places where the lltrace debug output printed ``(null)`` instead of an opcode name, because it was calling ``_PyUOpName()`` on a Tier-1 opcode.
* GH-111485: Fix handling of FOR_ITER in Tier 2 (GH-113394)Mark Shannon2023-12-241-12/+5
|
* GH-111485: Generate instruction and uop metadata (GH-113287)Mark Shannon2023-12-201-14/+18
|
* gh-112320: Implement on-trace confidence tracking for branches (#112321)Guido van Rossum2023-12-121-3/+17
| | | We track the confidence as a scaled int.
* GH-108866: Guarantee forward progress in executors. (GH-113006)Mark Shannon2023-12-121-4/+4
|
* Rename ...Uop... to ...UOp... (uppercase O) for consistency (#112327)Guido van Rossum2023-11-291-14/+14
| | | | * Rename _PyUopExecute to _PyUOpExecute (uppercase O) for consistency * Also rename _PyUopName and _PyUOp_Replacements, and some output strings
* gh-111848: Clean up RESERVE() macro (#112274)Guido van Rossum2023-11-201-14/+9
| | | Also avoid compiler warnings about unused 'reserved' variable.
* gh-106529: Make FOR_ITER a viable uop (#112134)Guido van Rossum2023-11-201-0/+6
| | | | | | | | | | This uses the new mechanism whereby certain uops are replaced by others during translation, using the `_PyUop_Replacements` table. We further special-case the `_FOR_ITER_TIER_TWO` uop to update the deoptimization target to point just past the corresponding `END_FOR` opcode. Two tiny code cleanups are also part of this PR.
* Various small improvements to uop debug output (#112218)Guido van Rossum2023-11-171-9/+9
| | | | | - Show uop name in Error/DEOPT messages - Add target to some messages - Expose uop_name() as _PyUopName()
* gh-106529: Cleanups split off gh-112134 (#112214)Guido van Rossum2023-11-171-1/+20
| | | | | | | - Double max trace size to 256 - Add a dependency on executor_cases.c.h for ceval.o - Mark `_SPECIALIZE_UNPACK_SEQUENCE` as `TIER_ONE_ONLY` - Add debug output back showing the optimized trace - Bunch of cleanups to Tools/cases_generator/
* GH-111848: Set the IP when de-optimizing (GH-112065)Mark Shannon2023-11-151-26/+22
| | | | | | | | | | | | * Replace jumps with deopts in tier 2 * Fewer special cases of uop names * Add target field to uop IR * Remove more redundant SET_IP and _CHECK_VALIDITY micro-ops * Extend whitelist of non-escaping API functions.
* GH-111848: Convert remaining jumps to deopts into tier 2 code. (GH-112045)Mark Shannon2023-11-141-39/+26
|
* GH-111843: Tier 2 exponential backoff (GH-111850)Mark Shannon2023-11-091-4/+5
|
* GH-109369: Exit tier 2 if executor is invalid (GH-111657)Mark Shannon2023-11-091-3/+4
|
* GH-111848: Tidy up tier 2 handling of FOR_ITER specialization by using ↵Mark Shannon2023-11-081-40/+11
| | | | DEOPT_IF instead of jumps. (GH-111849)
* GH-111646: Simplify optimizer, by compacting uops when making executor. ↵Mark Shannon2023-11-061-114/+87
| | | | (GH-111647)
* gh-111520: Integrate the Tier 2 interpreter in the Tier 1 interpreter (#111428)Guido van Rossum2023-11-011-6/+15
| | | | | | | | | | | - There is no longer a separate Python/executor.c file. - Conventions in Python/bytecodes.c are slightly different -- don't use `goto error`, you must use `GOTO_ERROR(error)` (same for others like `unused_local_error`). - The `TIER_ONE` and `TIER_TWO` symbols are only valid in the generated (.c.h) files. - In Lib/test/support/__init__.py, `Py_C_RECURSION_LIMIT` is imported from `_testcapi`. - On Windows, in debug mode, stack allocation grows from 8MiB to 12MiB. - **Beware!** This changes the env vars to enable uops and their debugging to `PYTHON_UOPS` and `PYTHON_LLTRACE`.
* GH-111339: Fix initialization and finalization of static optimizer types ↵Savannah Ostrowski2023-10-291-14/+10
| | | | (GH-111430)
* gh-109094: replace frame->prev_instr by frame->instr_ptr (#109095)Irit Katriel2023-10-261-6/+4
|
* GH-111339: Change `valid` property of executors to `is_valid()` method ↵Mark Shannon2023-10-261-13/+13
| | | | (GH-111350)
* GH-109214: _SET_IP before _PUSH_FRAME (but not _POP_FRAME) (GH-111001)Brandt Bucher2023-10-241-8/+6
|
* GH-109369: Add machinery for deoptimizing tier2 executors, both individually ↵Mark Shannon2023-10-231-2/+233
| | | | and globally. (GH-110384)
* GH-109214: Convert _SAVE_CURRENT_IP to _SET_IP in tier 2 trace creation. ↵Mark Shannon2023-10-121-3/+5
| | | | (GH-110755)