Commit graph

276 commits

Author SHA1 Message Date
mpage
6b77af257c
gh-134889: Fix handling of a few opcodes when optimizing LOAD_FAST (#134958)
We were incorrectly handling a few opcodes that leave their operands on the stack. Treat all of these conservatively; assume that they always leave operands on the stack.
2025-06-04 16:07:58 -07:00
Mark Shannon
f6f4e8a662
GH-132554: "Virtual" iterators (GH-132555)
* 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.
2025-05-27 15:59:45 +01:00
Mark Shannon
6dcb0fdfe0
GH-134282: Always borrow references LOAD_CONST (GH-134284) 2025-05-20 11:24:11 -04:00
Brandt Bucher
b1aa515bd6
GH-133231: Add JIT utilities in sys._jit (GH-133233) 2025-05-05 15:25:22 -07:00
Jelle Zijlstra
922049b613
gh-130907: Treat all module-level annotations as conditional (#131550) 2025-04-28 06:10:28 -07:00
Mark Shannon
d87e7f3529
GH-127682: Only call __iter__ once in generator expressions. (GH-132351) 2025-04-11 09:37:22 +01:00
mpage
053c285f6b
gh-130704: Strength reduce LOAD_FAST{_LOAD_FAST} (#130708)
Optimize `LOAD_FAST` opcodes into faster versions that load borrowed references onto the operand stack when we can prove that the lifetime of the local outlives the lifetime of the temporary that is loaded onto the stack.
2025-04-01 10:18:42 -07:00
Yan Yanchii
55815a6474
gh-130480: Move duplicate LOAD_SMALL_INT optimization from codegen to CFG (#130481) 2025-03-14 21:23:27 +00:00
Mark Shannon
89df62c120
GH-128534: Fix behavior of branch monitoring for async for (GH-130847)
* Both branches in a pair now have a common source and are included in co_branches
2025-03-07 14:30:31 +00:00
Mark Shannon
885c3d126f
GH-90916: Add helper function to dis.Instruction and use it to reduce churn in test_dis (GH-130643) 2025-03-04 16:43:39 +00:00
Irit Katriel
a1417b211f
gh-100239: replace BINARY_SUBSCR & family by BINARY_OP with oparg NB_SUBSCR (#129700) 2025-02-07 22:39:54 +00:00
Kirill Podoprigora
7d0521d5fc
gh-126835: Move optimization of constant sequence creation from codegen to CFG (#129426)
Codegen phase has an optimization that transforms
```
LOAD_CONST x
LOAD_CONST y
LOAD_CONXT z
BUILD_LIST/BUILD_SET (3)
```
->
```
BUILD_LIST/BUILD_SET (0)
LOAD_CONST (x, y, z)
LIST_EXTEND/SET_UPDATE 1
```
This optimization has now been moved to CFG phase to make #128802 work.


Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
2025-02-01 11:39:44 +00:00
Brandt Bucher
674befbd7b
GH-129386: Add test.support.reset_code (GH-129486) 2025-01-31 11:50:54 +01:00
Brandt Bucher
002c4e2982
GH-129386: Use symbolic constants for specialization tests (GH-129415) 2025-01-29 10:49:58 -08:00
Brandt Bucher
828b27680f
GH-126599: Remove the PyOptimizer API (GH-129194) 2025-01-28 16:10:51 -08:00
Mark Shannon
75b4962157
GH-128914: Remove all but one conditional stack effects (GH-129226)
* Remove all 'if (0)' and 'if (1)' conditional stack effects

* Use array instead of conditional for BUILD_SLICE args

* Refactor LOAD_GLOBAL to use a common conditional uop

* Remove conditional stack effects from LOAD_ATTR specializations

* Replace conditional stack effects in LOAD_ATTR with a 0 or 1 sized array.

* Remove conditional stack effects from CALL_FUNCTION_EX
2025-01-27 16:24:48 +00:00
Sam Gross
a10f99375e
Revert "GH-128914: Remove conditional stack effects from bytecodes.c and the code generators (GH-128918)" (GH-129202)
The commit introduced a ~2.5-3% regression in the free threading build.

This reverts commit ab61d3f430.
2025-01-23 09:26:25 +00:00
Mark Shannon
ab61d3f430
GH-128914: Remove conditional stack effects from bytecodes.c and the code generators (GH-128918) 2025-01-20 17:09:23 +00:00
Irit Katriel
3893a92d95
gh-100239: specialize long tail of binary operations (#128722) 2025-01-16 15:22:13 +00:00
Irit Katriel
5eee2fe2b0
gh-128891: add specialized opcodes to opcode.opname (#128892) 2025-01-15 21:02:32 +00:00
Mark Shannon
ddd959987c
GH-128685: Specialize (rather than quicken) LOAD_CONST into LOAD_CONST_[IM]MORTAL (GH-128708) 2025-01-13 10:30:28 +00:00
Mark Shannon
2434fd2d50
GH-128533: Add NOT_TAKEN instruction after bytecode optimization. (GH-128554) 2025-01-06 22:01:07 +00:00
Mark Shannon
f826beca0c
GH-128375: Better instrument for FOR_ITER (GH-128445) 2025-01-06 17:54:47 +00:00
Mark Shannon
d2f1d917e8
GH-122548: Implement branch taken and not taken events for sys.monitoring (GH-122564) 2024-12-19 16:59:51 +00:00
Bénédikt Tran
e85f2f1703
gh-127637: add tests for dis command-line interface (#127759) 2024-12-09 18:02:22 +00:00
Donghee Na
e2713409cf
gh-115999: Add partial free-thread specialization for BINARY_SUBSCR (gh-127227) 2024-12-02 10:38:17 +09:00
Donghee Na
e56fd449fb
gh-115999: Move specializer test from test_dis to test_opcache (gh-126498) 2024-11-07 05:23:47 +09:00
Donghee Na
4ea214ea98
gh-115999: Add free-threaded specialization for CONTAINS_OP (gh-126450)
- The specialization logic determines the appropriate specialization using only the operand's type, which is safe to read non-atomically (changing it requires stopping the world). We are guaranteed that the type will not change in between when it is checked and when we specialize the bytecode because the types involved are immutable (you cannot assign to `__class__` for exact instances of `dict`, `set`, or `frozenset`). The bytecode is mutated atomically using helpers.
- The specialized instructions rely on the operand type not changing in between the `DEOPT_IF` checks and the calls to the appropriate type-specific helpers (e.g. `_PySet_Contains`). This is a correctness requirement in the default builds and there are no changes to the opcodes in the free-threaded builds that would invalidate this.
2024-11-06 03:35:10 +00:00
mpage
2e95c5ba3b
gh-115999: Implement thread-local bytecode and enable specialization for BINARY_OP (#123926)
Each thread specializes a thread-local copy of the bytecode, created on the first RESUME, in free-threaded builds. All copies of the bytecode for a code object are stored in the co_tlbc array on the code object. Threads reserve a globally unique index identifying its copy of the bytecode in all co_tlbc arrays at thread creation and release the index at thread destruction. The first entry in every co_tlbc array always points to the "main" copy of the bytecode that is stored at the end of the code object. This ensures that no bytecode is copied for programs that do not use threads.

Thread-local bytecode can be disabled at runtime by providing either -X tlbc=0 or PYTHON_TLBC=0. Disabling thread-local bytecode also disables specialization.

Concurrent modifications to the bytecode made by the specializing interpreter and instrumentation use atomics, with specialization taking care not to overwrite an instruction that was instrumented concurrently.
2024-11-04 11:13:32 -08:00
Xuanteng Huang
35df4eb959
gh-126072: do not add None to co_consts if there is no docstring (GH-126101) 2024-10-30 09:01:09 +00:00
Mark Shannon
faa3272fb8
GH-125837: Split LOAD_CONST into three. (GH-125972)
* Add LOAD_CONST_IMMORTAL opcode

* Add LOAD_SMALL_INT opcode

* Remove RETURN_CONST opcode
2024-10-29 11:15:42 +00:00
Mikhail Efimov
079875e395
gh-125038: Fix crash after genexpr.gi_frame.f_locals manipulations (#125178) 2024-10-22 09:00:25 -07:00
larryhastings
4defb58d38
Add "annotate" SET_FUNCTION_ATTRIBUTE bit to dis. (#124566) 2024-09-25 17:01:45 -07:00
Alexandr Mitin
6a7765b9fa
gh-123363: Show string value of CONTAINS_OP oparg in dis (#123387)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2024-08-28 09:15:34 +03:00
sobolevn
1eed0f968f
gh-123340: Show string value of IS_OP oparg in dis (#123348) 2024-08-26 21:59:50 +03:00
Bénédikt Tran
31acc4d243
gh-123165: correct tests for dis.dis(func, show_positions=True) (#123220) 2024-08-22 14:30:31 +01:00
Bénédikt Tran
b1d3bd2e09
gh-123165: make dis functions render positions on demand (#123168) 2024-08-21 14:46:24 +01:00
Mark Shannon
7a65439b93
GH-122390: Replace _Py_GetbaseOpcode with _Py_GetBaseCodeUnit (GH-122942) 2024-08-13 14:22:57 +01:00
Mark Shannon
fe23f8ed97
GH-122821: Simplify compilation of while statements to ensure consistency of offsets for sys.monitoring (GH-122934) 2024-08-13 10:25:44 +01:00
Mark Shannon
2e14a52cce
GH-122160: Remove BUILD_CONST_KEY_MAP opcode. (GH-122164) 2024-07-25 16:24:29 +01:00
Jelle Zijlstra
e8e151d471
gh-120780: Show attribute name for LOAD_SPECIAL in dis output (#120781) 2024-06-20 07:07:24 -07:00
Mark Shannon
9cefcc0ee7
GH-120507: Lower the BEFORE_WITH and BEFORE_ASYNC_WITH instructions. (#120640)
* Remove BEFORE_WITH and BEFORE_ASYNC_WITH instructions.

* Add LOAD_SPECIAL instruction

* Reimplement `with` and `async with` statements using LOAD_SPECIAL
2024-06-18 12:17:46 +01:00
Jelle Zijlstra
9b8611eeea
gh-119180: PEP 649 compiler changes (#119361) 2024-06-11 13:06:49 +00:00
Irit Katriel
016a46ab57
gh-93554: add test for quickening of code in loops ending with conditional statement (#119485) 2024-05-29 11:44:04 +01:00
Jelle Zijlstra
98e855fcc1
gh-119180: Add LOAD_COMMON_CONSTANT opcode (#119321)
The PEP 649 implementation will require a way to load NotImplementedError
from the bytecode. @markshannon suggested implementing this by converting
LOAD_ASSERTION_ERROR into a more general mechanism for loading constants.

This PR adds this new opcode. I will work on the rest of the implementation
of the PEP separately.

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-05-22 00:46:39 +00:00
Mark Shannon
1ab6356ebe
GH-118095: Use broader specializations of CALL in tier 1, for better tier 2 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
2024-05-04 12:11:11 +01:00
Irit Katriel
d610d821fd
gh-112383: teach dis how to interpret ENTER_EXECUTOR (#117171) 2024-03-23 22:32:33 +00:00
Irit Katriel
74e6f4b32f
gh-112720: make it easier to subclass and modify dis.ArgResolver's jump arg resolution (#115564) 2024-02-16 19:25:19 +00:00
Mark Shannon
981d172f7f
GH-112354: END_FOR instruction to only pop one value. (GH-114247)
* Compiler emits END_FOR; POP_TOP instead of END_FOR. To support tier 2 side exits in loops.
2024-01-24 15:10:17 +00:00
Irit Katriel
7e49f27b41
gh-114265: move line number propagation before cfg optimization, remove guarantee_lineno_for_exits (#114267) 2024-01-19 14:49:26 +00:00