summaryrefslogtreecommitdiffstats
path: root/Python/optimizer_bytecodes.c
Commit message (Collapse)AuthorAgeFilesLines
* GH-134584: Remove redundant refcount from `_STORE_ATTR_SLOT` (#142729)Savannah Ostrowski11 days1-0/+6
|
* gh-134584: JIT: Eliminate redundant refcount ops for X_INT (GH-142765)Ken Jin11 days1-11/+12
|
* gh-134584: Eliminate redundant refcounting from `_STORE_ATTR_INSTANCE_VALUE` ↵Nadeshiko Manju11 days1-0/+5
| | | | | (GH-142759) Signed-off-by: Manjusaka <me@manjusaka.me>
* gh-134584: Remove custom float decref ops (GH-142576)Ken Jin11 days1-15/+15
|
* gh-134584: Eliminate redundant refcounting from _STORE_SUBSCR_DICT (GH-142712)Donghee Na11 days1-0/+5
| | | Co-authored-by: Ken Jin <kenjin4096@gmail.com>
* gh-134584: Eliminate redundant refcounting from _CALL_LIST_APPEND (GH-142711)Nadeshiko Manju11 days1-0/+6
| | | | Signed-off-by: Manjusaka <me@manjusaka.me> Co-authored-by: Ken Jin <kenjin4096@gmail.com>
* gh-134584: Eliminate redundant refcounting from _STORE_SUBSCR_LIST_INT ↵Donghee Na12 days1-0/+12
| | | | (gh-142703)
* gh-134584: Eliminate redundant refcounting from `_CALL_STR_1` (GH-136070)Nadeshiko Manju12 days1-1/+2
| | | Signed-off-by: Manjusaka <me@manjusaka.me>
* gh-134584: Cleanups for GH-135860 (GH-142604)Ken Jin13 days1-1/+2
|
* gh-134584: Revert partially GH-135860 (GH-142620)Ken Jin2025-12-121-2/+1
|
* gh-134584: Eliminate redundant refcounting from ``_CALL_LEN`` (gh-136104)Donghee Na2025-12-111-1/+3
|
* gh-134584: Eliminate redundant refcounting from `_CALL_TUPLE_1` (GH-135860)Noam Cohen2025-12-111-1/+2
|
* GH-135379: Top of stack caching for the JIT. (GH-135465)Mark Shannon2025-12-111-2/+2
| | | | Uses three registers to cache values at the top of the evaluation stack This significantly reduces memory traffic for smaller, more common uops.
* gh-142276: Watch attribute loads when promoting JIT constants (GH-142303)Ken Jin2025-12-081-6/+6
| | | | Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Savannah Ostrowski <savannah@python.org>
* gh-139109: A new tracing JIT compiler frontend for CPython (GH-140310)Ken Jin2025-11-131-52/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR changes the current JIT model from trace projection to trace recording. Benchmarking: better pyperformance (about 1.7% overall) geomean versus current https://raw.githubusercontent.com/facebookexperimental/free-threading-benchmarking/refs/heads/main/results/bm-20251108-3.15.0a1%2B-7e2bc1d-JIT/bm-20251108-vultr-x86_64-Fidget%252dSpinner-tracing_jit-3.15.0a1%2B-7e2bc1d-vs-base.svg, 100% faster Richards on the most improved benchmark versus the current JIT. Slowdown of about 10-15% on the worst benchmark versus the current JIT. **Note: the fastest version isn't the one merged, as it relies on fixing bugs in the specializing interpreter, which is left to another PR**. The speedup in the merged version is about 1.1%. https://raw.githubusercontent.com/facebookexperimental/free-threading-benchmarking/refs/heads/main/results/bm-20251112-3.15.0a1%2B-f8a764a-JIT/bm-20251112-vultr-x86_64-Fidget%252dSpinner-tracing_jit-3.15.0a1%2B-f8a764a-vs-base.svg Stats: 50% more uops executed, 30% more traces entered the last time we ran them. It also suggests our trace lengths for a real trace recording JIT are too short, as a lot of trace too long aborts https://github.com/facebookexperimental/free-threading-benchmarking/blob/main/results/bm-20251023-3.15.0a1%2B-eb73378-CLANG%2CJIT/bm-20251023-vultr-x86_64-Fidget%252dSpinner-tracing_jit-3.15.0a1%2B-eb73378-pystats-vs-base.md . This new JIT frontend is already able to record/execute significantly more instructions than the previous JIT frontend. In this PR, we are now able to record through custom dunders, simple object creation, generators, etc. None of these were done by the old JIT frontend. Some custom dunders uops were discovered to be broken as part of this work gh-140277 The optimizer stack space check is disabled, as it's no longer valid to deal with underflow. Pros: * Ignoring the generated tracer code as it's automatically created, this is only additional 1k lines of code. The maintenance burden is handled by the DSL and code generator. * `optimizer.c` is now significantly simpler, as we don't have to do strange things to recover the bytecode from a trace. * The new JIT frontend is able to handle a lot more control-flow than the old one. * Tracing is very low overhead. We use the tail calling interpreter/computed goto interpreter to switch between tracing mode and non-tracing mode. I call this mechanism dual dispatch, as we have two dispatch tables dispatching to each other. Specialization is still enabled while tracing. * Better handling of polymorphism. We leverage the specializing interpreter for this. Cons: * (For now) requires tail calling interpreter or computed gotos. This means no Windows JIT for now :(. Not to fret, tail calling is coming soon to Windows though https://github.com/python/cpython/pull/139962 Design: * After each instruction, the `record_previous_inst` function/label is executed. This does as the name suggests. * The tracing interpreter lowers bytecode to uops directly so that it can obtain "fresh" values at the point of lowering. * The tracing version behaves nearly identical to the normal interpreter, in fact it even has specialization! This allows it to run without much of a slowdown when tracing. The actual cost of tracing is only a function call and writes to memory. * The tracing interpreter uses the specializing interpreter's deopt to naturally form the side exit chains. This allows it to side exit chain effectively, without repeating much code. We force a re-specializing when tracing a deopt. * The tracing interpreter can even handle goto errors/exceptions, but I chose to disable them for now as it's not tested. * Because we do not share interpreter dispatch, there is should be no significant slowdown to the original specializing interpreter on tailcall and computed got with JIT disabled. With JIT enabled, there might be a slowdown in the form of the JIT trying to trace. * Things that could have dynamic instruction pointer effects are guarded on. The guard deopts to a new instruction --- `_DYNAMIC_EXIT`.
* GH-138378: Move globals-to-consts pass into main optimizer pass (GH-138379)Mark Shannon2025-09-181-26/+108
|
* GH-132732: Use pure op machinery to optimize various instructions with ↵Savannah Bailey2025-09-151-0/+9
| | | | `_POP_TOP` and `_POP_TWO` (#137577)
* gh-138431: JIT Optimizer --- Fix round-tripping references for str and tuple ↵Ken Jin2025-09-031-5/+8
| | | | | (GH-138458) Co-authored-by: Mark Shannon <9448417+markshannon@users.noreply.github.com>
* gh-137136: Suppress build warnings when build on Windows with ↵AN Long2025-09-031-5/+5
| | | | --experimental-jit-interpreter (GH-137137)
* GH-132732: Use pure op machinery to optimize `COMPARE_OP_INT/FLOAT/STR` ↵Savannah Bailey2025-07-261-18/+4
| | | | | (#137062) Co-authored-by: Ken Jin <kenjin4096@gmail.com>
* gh-136125: Use `_PyObject_GetMethodStackRef` for `LOAD_ATTR` (GH-136127)Ken Jin2025-07-011-2/+2
|
* gh-132732: Automatically constant evaluate pure operations (GH-132733)Ken Jin2025-06-271-64/+13
| | | | | | This adds a "macro" to the optimizer DSL called "REPLACE_OPCODE_IF_EVALUATES_PURE", which allows automatically constant evaluating a bytecode body if certain inputs have no side effects upon evaluations (such as ints, strings, and floats). Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
* gh-131798: Optimize `_UNARY_NEGATIVE` (GH-135223)Noam Cohen2025-06-231-1/+7
|
* gh-134584: Specialize POP_TOP by reference and type in JIT (GH-135761)Ken Jin2025-06-231-4/+24
|
* gh-131798: JIT: Optimize _CALL_LEN when the length is known (#135260)Tomas R.2025-06-201-1/+14
| | | | | | | * Add news entry * Optimize _CALL_LEN * Simplify tests
* gh-135608: Add a null check for attribute promotion to fix a JIT crash ↵Ken Jin2025-06-201-1/+7
| | | | | (GH-135613) Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
* GH-135379: Specialize int operations for compact ints only (GH-135668)Mark Shannon2025-06-191-7/+29
|
* gh-134584: Decref elimination for float ops in the JIT (GH-134588)Ken Jin2025-06-171-27/+39
| | | This PR adds a PyJitRef API to the JIT's optimizer that mimics the _PyStackRef API. This allows it to track references and their stack lifetimes properly. Thus opening up the doorway to refcount elimination in the JIT.
* gh-131798: JIT: replace _CHECK_METHOD_VERSION with ↵Nadeshiko Manju2025-06-161-0/+10
| | | | | | _CHECK_FUNCTION_VERSION_INLINE (GH-135022) Signed-off-by: Manjusaka <me@manjusaka.me> Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
* gh-135474: Specialize arithmetic only on compact ints (GH-135479)Ken Jin2025-06-141-48/+3
| | | | Specialize arithmetic only on compact ints. This also makes int operations non-escaping in the JIT and in tier 1.
* GH-135379: Remove types from stack items in code generator. (GH-135384)Mark Shannon2025-06-111-15/+14
| | | | * Make casts explicit in the instruction definitions
* gh-131798: Optimize `_UNARY_INVERT` (GH-135222)Noam Cohen2025-06-091-0/+9
|
* GH-131798: Type-propagate string/list/tuple slices (GH-134671)Amit Lavon2025-06-071-0/+14
|
* GH-131798: Optimize away type(x) in the JIT when the result is known (GH-135194)Tomas R.2025-06-061-2/+5
|
* GH-132554: Fix tier2 `FOR_ITER` implementation and optimizations (GH-135137)Mark Shannon2025-06-051-0/+11
|
* gh-131798: Optimize `_ITER_CHECK_TUPLE` (GH-134803)Noam Cohen2025-05-271-0/+7
|
* GH-132554: "Virtual" iterators (GH-132555)Mark Shannon2025-05-271-2/+2
| | | | | | * FOR_ITER now pushes either the iterator and NULL or leaves the iterable and pushes tagged zero * NEXT_ITER uses the tagged int as the index into the sequence or, if TOS is NULL, iterates as before.
* GH-131798: Optimize away isinstance calls in the JIT (GH-134369)Tomas R.2025-05-221-0/+8
|
* GH-131798: Optimize cached class attributes and methods in the JIT (GH-134403)Brandt Bucher2025-05-221-6/+40
|
* GH-131798: Turn _LOAD_SMALL_INT into _LOAD_CONST_INLINE_BORROW in the JIT ↵Nadeshiko Manju2025-05-221-1/+4
| | | | (GH-134406)
* GH-131798: Narrow types more aggressively in the JIT (GH-134373)Brandt Bucher2025-05-201-0/+12
|
* GH-131798: Narrow the return type of _GET_LEN to int (GH-133345)Nadeshiko Manju2025-05-201-0/+19
|
* GH-134282: Always borrow references LOAD_CONST (GH-134284)Mark Shannon2025-05-201-14/+0
|
* GH-131798: Add _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW (GH-134268)Tomas R.2025-05-191-4/+8
|
* GH-131798: Split CALL_LIST_APPEND into several uops (GH-134240)Diego Russo2025-05-191-0/+15
|
* GH-131798: Narrow the return type of isinstance for some known arguments in ↵Tomas R.2025-05-191-0/+20
| | | | the JIT (GH-133172)
* GH-131798: Split up and optimize CALL_ISINSTANCE (GH-133339)Tomas R.2025-05-081-0/+15
|
* gh-133273: Keep instruction definitions in `bytecodes.c` and ↵Tomas R.2025-05-081-58/+62
| | | | `optimizer_bytecodes.c` in sync (GH-133320)
* GH-131798: Split CALL_LEN into several uops (GH-133180)Diego Russo2025-05-051-1/+9
|
* gh-131798: JIT - Use `sym_new_type` instead of `sym_new_not_null` for ↵Nadeshiko Manju2025-04-271-0/+8
| | | | | | _BUILD_STRING, _BUILD_SET (GH-132564) Signed-off-by: Manjusaka <me@manjusaka.me>