aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/optimizer.c
Commit message (Collapse)AuthorAge
* GH-122294: Burn in the addresses of side exits (GH-122295)Brandt Bucher2024-07-26
|
* GH-118093: Add tier two support for BINARY_OP_INPLACE_ADD_UNICODE (GH-122253)Brandt Bucher2024-07-25
|
* GH-118093: Add tier two support for LOAD_ATTR_PROPERTY (GH-122283)Brandt Bucher2024-07-25
|
* GH-118093: Remove invalidated executors from side exits (GH-121885)Brandt Bucher2024-07-24
|
* GH-118093: Add tier two support to several instructions (GH-121884)Brandt Bucher2024-07-18
|
* GH-116017: Get rid of _COLD_EXITs (GH-120960)Brandt Bucher2024-07-01
|
* gh-117139: Convert the evaluation stack to stack refs (#118450)Ken Jin2024-06-27
| | | | | | | | | | | | | | | | | This PR sets up tagged pointers for CPython. The general idea is to create a separate struct _PyStackRef for everything on the evaluation stack to store the bits. This forces the C compiler to warn us if we try to cast things or pull things out of the struct directly. Only for free threading: We tag the low bit if something is deferred - that means we skip incref and decref operations on it. This behavior may change in the future if Mark's plans to defer all objects in the interpreter loop pans out. This implies a strict stack reference discipline is required. ALL incref and decref operations on stackrefs must use the stackref variants. It is unsafe to untag something then do normal incref/decref ops on it. The new incref and decref variants are called dup and close. They mimic a "handle" API operating on these stackrefs. Please read Include/internal/pycore_stackref.h for more information! --------- Co-authored-by: Mark Shannon <9448417+markshannon@users.noreply.github.com>
* 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-117062: Make _JUMP_TO_TOP a general absolute jump (GH-120854)Brandt Bucher2024-06-24
|
* 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
* Fix typos in documentation and comments (#119763)Xie Yanbo2024-06-04
|
* gh-111389: Add PyHASH_MULTIPLIER constant (#119214)Victor Stinner2024-05-21
|
* gh-118771: Ensure names defined in optimizer.h start with Py/_Py (GH-118825)Petr Viktorin2024-05-10
|
* GH-118095: Use broader specializations of CALL in tier 1, for better tier 2 ↵Mark Shannon2024-05-04
| | | | | | | | | | support of calls. (GH-118322) * Add CALL_PY_GENERAL, CALL_BOUND_METHOD_GENERAL and call CALL_NON_PY_GENERAL specializations. * Remove CALL_PY_WITH_DEFAULTS specialization * Use CALL_NON_PY_GENERAL in more cases when otherwise failing to specialize
* GH-113464: Remove the extra jump via `_SIDE_EXIT` in `_EXIT_TRACE` (GH-118545)Mark Shannon2024-05-04
|
* GH-118095: Unify the behavior of tier 2 FOR_ITER branch micro-ops (GH-118420)Mark Shannon2024-05-02
| | | | | | * Target _FOR_ITER_TIER_TWO at POP_TOP following the matching END_FOR * Modify _GUARD_NOT_EXHAUSTED_RANGE, _GUARD_NOT_EXHAUSTED_LIST and _GUARD_NOT_EXHAUSTED_TUPLE so that they also target the POP_TOP following the matching END_FOR
* GH-117442: Check eval-breaker at start (rather than end) of tier 2 loops ↵Mark Shannon2024-05-02
| | | | (GH-118482)
* GH-115802: Use the GHC calling convention in JIT code (GH-118287)Brandt Bucher2024-05-01
|
* gh-117958: Expose JIT code via method in UOpExecutor (#117959)Anthony Shaw2024-05-01
|
* GH-118095: Make invalidating and clearing executors memory safe (GH-118459)Mark Shannon2024-05-01
|
* 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: Add tier 2 support for YIELD_VALUE (GH-118380)Mark Shannon2024-04-30
|
* GH-118095: Allow a variant of RESUME_CHECK in tier 2 (GH-118286)Mark Shannon2024-04-29
|
* GH-118095: Add dynamic exit support and FOR_ITER_GEN support to tier 2 ↵Mark Shannon2024-04-26
| | | | (GH-118279)
* 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-118095: Convert DEOPT_IFs on likely side exits to EXIT_IFs (GH-118106)Mark Shannon2024-04-24
| | | Covert DEOPT_IFs on likely side exits to EXIT_IFs
* gh-118074: Immortal executors are not GC-able (#118182)Guido van Rossum2024-04-23
| | | | | Better version of gh-118117. Just check for immortality instead of an address range check.
* GH-118074: Executors in the COLD_EXITS array are not GC'able (#118117)Guido van Rossum2024-04-22
|
* GH-116202: Incorporate invalidation check into _START_EXECUTOR. (GH-118044)Mark Shannon2024-04-19
|
* gh-116968: Reimplement Tier 2 counters (#117144)Guido van Rossum2024-04-04
| | | | | | | | | | | | Introduce a unified 16-bit backoff counter type (``_Py_BackoffCounter``), shared between the Tier 1 adaptive specializer and the Tier 2 optimizer. The API used for adaptive specialization counters is changed but the behavior is (supposed to be) identical. The behavior of the Tier 2 counters is changed: - There are no longer dynamic thresholds (we never varied these). - All counters now use the same exponential backoff. - The counter for ``JUMP_BACKWARD`` starts counting down from 16. - The ``temperature`` in side exits starts counting down from 64.
* 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-117180: Complete call sequence when trace stack overflow (GH-117184)Ken Jin2024-03-24
| | | | | | | --------- 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-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-108362: Incremental Cycle GC (GH-116206)Mark Shannon2024-03-20
|
* gh-116808: Fix optimized trace length histogram (GH-116827)Michael Droettboom2024-03-19
|
* 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-116760: Fix pystats for trace attempts (GH-116761)Michael Droettboom2024-03-13
| | | | | | | | 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-11
|
* Fix debug output for optimized executor (#116337)Guido van Rossum2024-03-05
| | | | 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-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-115168: Add pystats counter for invalidated executors (GH-115169)Michael Droettboom2024-02-26
|
* gh-115727: Reduce confidence even on 100% predicted jumps (#115748)Guido van Rossum2024-02-22
| | | | | | | | 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-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-115457: Support splitting and replication of micro ops. (GH-115558)Mark Shannon2024-02-20
|
* GH-112354: Initial implementation of warm up on exits and trace-stitching ↵Mark Shannon2024-02-20
| | | | (GH-114142)
* GH-113710: Improve `_SET_IP` and `_CHECK_VALIDITY` (GH-115248)Mark Shannon2024-02-13
|
* GH-113710: Backedge counter improvements. (GH-115166)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-114695: Add `sys._clear_internal_caches` (GH-115152)Brandt Bucher2024-02-12
|