Commit Graph

91 Commits

Author SHA1 Message Date
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
mpage 78adb63ee1
gh-133371: Don't optimize `LOAD_FAST` instructions whose local is killed by `DELETE_FAST` (#133383)
In certain cases it's possible for locals loaded by `LOAD_FAST` instructions
to be on the stack when the local is killed by `DEL_FAST`. These `LOAD_FAST`
instructions should not be optimized into `LOAD_FAST_BORROW` as the strong
reference in the frame is killed while there is still a reference on the stack.
2025-05-04 21:00:11 -07:00
Eric Snow 96a7fb93a8
gh-132775: Add _PyCode_ReturnsOnlyNone() (gh-132981)
The function indicates whether or not the function has a return statement.

This is used by a later change related treating some functions like scripts.
2025-04-28 20:12:52 -06:00
Jelle Zijlstra 922049b613
gh-130907: Treat all module-level annotations as conditional (#131550) 2025-04-28 06:10:28 -07: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
Mark Shannon 83d54fa876
GH-130296: Remove `_PyOpcode_max_stack_effect` as it is no longer used (GH-131493) 2025-03-20 11:42:54 +00:00
Yan Yanchii 75103d975c
gh-126835: Move constant tuple folding from ast_opt to CFG (#130769) 2025-03-19 20:59:55 +00: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
Irit Katriel 4242c2b8d0
gh-130080: move _Py_EnsureArrayLargeEnough to a separate header so it can be used outside of the compiler (#130930) 2025-03-13 16:02:58 +00:00
Yan Yanchii 3618240624
gh-126835: Avoid creating unnecessary tuple when looking for constant sequence during constant folding (#131054) 2025-03-12 21:45:54 +00:00
Mark Shannon be046ee6e0
GH-123044: Give the `POP_TOP` after a case test a location in the body, not the pattern. (GH-130627) 2025-03-10 17:31:16 +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
Hugo Beauzée-Luyssen 214562ed4d
gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738)
Move some `#include <stdbool.h>` after `#include "Python.h"` when `pyconfig.h` is not
included first and when we are in a platform-agnostic context. This is to avoid having
features defined by `stdbool.h` before those decided by `Python.h`.
2025-03-02 09:56:49 +00:00
Yan Yanchii 38642bff13
gh-126835: Move constant unaryop & binop folding to CFG (#129550) 2025-02-21 17:54:22 +00:00
Yan Yanchii 334589f619
gh-126835: Set location for noped out instructions after constant folding in CFG. (#130109) 2025-02-14 14:15:08 +00:00
Yan Yanchii 140e69c4a8
gh-126835: Move const folding of lists & sets from ast_opt.c to flowgraph.c (#130032) 2025-02-13 12:11:07 +00:00
Yan Yanchii 91d9544112
gh-126835: Make CFG optimizer skip over NOP's when looking for const sequence construction (#129703)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2025-02-09 18:00:41 +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
Yan Yanchii d3c54f3788
gh-126835: Fix reference leak in `Python/flowgrapc.::optimize_if_const_subscr` (#129634) 2025-02-04 10:38:06 +00:00
Yan Yanchii 0664c1af9b
gh-126835: Move constant subscript folding to CFG (#129568)
Move folding of constant subscription from AST optimizer to CFG.

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2025-02-04 10:10:55 +02: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
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
Brandt Bucher 004f9fd1f2
Remove unnecessary LIST_TO_TUPLE conversions (GH-126558) 2025-01-08 09:00:11 -08: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 d2f1d917e8
GH-122548: Implement branch taken and not taken events for sys.monitoring (GH-122564) 2024-12-19 16:59:51 +00:00
mpage 193890c1cc
gh-126612: Include stack effects of uops when computing maximum stack depth (#126894) 2024-11-26 00:53:49 +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
Irit Katriel f474391b26
gh-124871: fix 'visited' tracking in compiler's reachability analysis (#124952) 2024-10-04 17:37:38 +01:00
Irit Katriel 78aeb38f7d
gh-124285: Fix bug where bool() is called multiple times for the same part of a boolean expression (#124394) 2024-09-25 15:51:25 +01:00
Irit Katriel 1a9d8917a3
gh-121404: split compile.c into compile.c and codegen.c (#123651) 2024-09-09 18:21:51 +01:00
Steve Dower e731554337
Fixes loop variables to be the same types as their limit (GH-120958) 2024-06-24 17:11:47 +01:00
Irit Katriel b7f478948f
gh-120367: fix bug where compiler detects redundant jump after pseudo op replacement (#120714) 2024-06-18 22:09:23 +00:00
Irit Katriel 21866c8ed2
gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (#120425) 2024-06-17 10:10:06 +00:00
Irit Katriel 4fc82b6d3b
gh-120225: fix crash in compiler on empty block at end of exception handler (#120235) 2024-06-07 22:37:35 +01:00
Xie Yanbo 9e052619a6
Fix typos in documentation and comments (#119763) 2024-06-04 10:22:22 +00:00
Irit Katriel 13a5fdc72f
gh-119744: move a few functions from compile.c to flowgraph.c (#119745) 2024-05-30 21:55:06 +01:00
Irit Katriel 04697bcfaf
gh-117494: extract the Instruction Sequence data structure into a separate file (#117496) 2024-04-04 15:47:26 +00:00
Irit Katriel 1d5479b236
gh-117411: move PyFutureFeatures to pycore_symtable.h and make it private (#117412) 2024-04-02 10:34:49 +00:00
Irit Katriel 262fb911ab
gh-117288: Allocate fewer label IDs in _PyCfg_ToInstructionSequence (#117290) 2024-03-27 17:38:19 +00:00
Irit Katriel 96c1737591
gh-115796: fix exception table construction in _testinternalcapi.assemble_code_object (#115797) 2024-02-22 12:36:44 +00:00
Irit Katriel f42e112fd8
gh-115420: Fix translation of exception hander targets by _testinternalcapi.optimize_cfg. (#115425) 2024-02-15 14:32:52 +00:00
Irit Katriel 2091fb2a85
gh-107901: make compiler inline basic blocks with no line number and no fallthrough (#114750) 2024-02-02 11:26:31 +00:00
Erlend E. Aasland 8612230c1c
gh-114569: Use PyMem_* APIs for non-PyObjects in compiler (#114587) 2024-01-30 00:04:34 +01:00
Irit Katriel ac5e53e150
gh-107901: compiler replaces POP_BLOCK instruction by NOPs before optimisations (#114530) 2024-01-25 20:06:48 +00:00
Irit Katriel 0315941441
gh-114265: remove i_loc_propagated, jump threading does not consider line numbers anymore (#114535) 2024-01-25 12:54:19 +00:00
Irit Katriel ed30a3c337
gh-114083: apply optimization of LOAD_CONST instructions to the whole CFG before optimize_basic_block. (#114408) 2024-01-22 17:12:06 +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
Irit Katriel 8aa0088ea2
gh-107901: duplicate blocks with no lineno that have an eval break and multiple predecessors (#113950) 2024-01-12 15:38:09 +00:00
Irit Katriel 0d8fec79ca
gh-107901: jump leaving an exception handler doesn't need an eval break check (#113943) 2024-01-11 14:27:41 +00:00