Skip to content

Commit e28b0dc

Browse files
Fidget-SpinnergvanrossumJuliaPoo
authored
pythongh-107557: Setup abstract interpretation (python#107847)
Co-authored-by: Guido van Rossum <[email protected]> Co-authored-by: Jules <[email protected]>
1 parent 34e1917 commit e28b0dc

21 files changed

+1118
-9
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Programs/test_frozenmain.h generated
9090
Python/Python-ast.c generated
9191
Python/executor_cases.c.h generated
9292
Python/generated_cases.c.h generated
93+
Python/abstract_interp_cases.c.h generated
9394
Python/opcode_targets.h generated
9495
Python/stdlib_module_names.h generated
9596
Tools/peg_generator/pegen/grammar_parser.py generated

Include/cpython/optimizer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typedef struct _PyExecutorObject {
2222
typedef struct _PyOptimizerObject _PyOptimizerObject;
2323

2424
/* Should return > 0 if a new executor is created. O if no executor is produced and < 0 if an error occurred. */
25-
typedef int (*optimize_func)(_PyOptimizerObject* self, PyCodeObject *code, _Py_CODEUNIT *instr, _PyExecutorObject **);
25+
typedef int (*optimize_func)(_PyOptimizerObject* self, PyCodeObject *code, _Py_CODEUNIT *instr, _PyExecutorObject **, int curr_stackentries);
2626

2727
typedef struct _PyOptimizerObject {
2828
PyObject_HEAD

Include/internal/pycore_opcode_metadata.h

+142
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_optimizer.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef Py_INTERNAL_OPTIMIZER_H
2+
#define Py_INTERNAL_OPTIMIZER_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
#include "pycore_uops.h"
12+
13+
int _Py_uop_analyze_and_optimize(PyCodeObject *code,
14+
_PyUOpInstruction *trace, int trace_len, int curr_stackentries);
15+
16+
17+
#ifdef __cplusplus
18+
}
19+
#endif
20+
#endif /* !Py_INTERNAL_OPTIMIZER_H */

Include/internal/pycore_uops.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#define _Py_UOP_MAX_TRACE_LENGTH 32
11+
#define _Py_UOP_MAX_TRACE_LENGTH 64
1212

1313
typedef struct {
1414
uint32_t opcode;

Makefile.pre.in

+11-1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ PYTHON_OBJS= \
405405
Python/mysnprintf.o \
406406
Python/mystrtoul.o \
407407
Python/optimizer.o \
408+
Python/optimizer_analysis.o \
408409
Python/pathconfig.o \
409410
Python/preconfig.o \
410411
Python/pyarena.o \
@@ -1552,10 +1553,12 @@ regen-cases:
15521553
-m $(srcdir)/Include/internal/pycore_opcode_metadata.h.new \
15531554
-e $(srcdir)/Python/executor_cases.c.h.new \
15541555
-p $(srcdir)/Lib/_opcode_metadata.py.new \
1556+
-a $(srcdir)/Python/abstract_interp_cases.c.h.new \
15551557
$(srcdir)/Python/bytecodes.c
15561558
$(UPDATE_FILE) $(srcdir)/Python/generated_cases.c.h $(srcdir)/Python/generated_cases.c.h.new
15571559
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_opcode_metadata.h $(srcdir)/Include/internal/pycore_opcode_metadata.h.new
15581560
$(UPDATE_FILE) $(srcdir)/Python/executor_cases.c.h $(srcdir)/Python/executor_cases.c.h.new
1561+
$(UPDATE_FILE) $(srcdir)/Python/abstract_interp_cases.c.h $(srcdir)/Python/abstract_interp_cases.c.h.new
15591562
$(UPDATE_FILE) $(srcdir)/Lib/_opcode_metadata.py $(srcdir)/Lib/_opcode_metadata.py.new
15601563

15611564
Python/compile.o: $(srcdir)/Include/internal/pycore_opcode_metadata.h
@@ -1568,6 +1571,7 @@ Python/ceval.o: \
15681571

15691572
Python/executor.o: \
15701573
$(srcdir)/Include/internal/pycore_opcode_metadata.h \
1574+
$(srcdir)/Include/internal/pycore_optimizer.h \
15711575
$(srcdir)/Python/ceval_macros.h \
15721576
$(srcdir)/Python/executor_cases.c.h
15731577

@@ -1576,7 +1580,12 @@ Python/flowgraph.o: \
15761580

15771581
Python/optimizer.o: \
15781582
$(srcdir)/Python/executor_cases.c.h \
1579-
$(srcdir)/Include/internal/pycore_opcode_metadata.h
1583+
$(srcdir)/Include/internal/pycore_opcode_metadata.h \
1584+
$(srcdir)/Include/internal/pycore_optimizer.h
1585+
1586+
Python/optimizer_analysis.o: \
1587+
$(srcdir)/Include/internal/pycore_opcode_metadata.h \
1588+
$(srcdir)/Include/internal/pycore_optimizer.h
15801589

15811590
Python/frozen.o: $(FROZEN_FILES_OUT)
15821591

@@ -1786,6 +1795,7 @@ PYTHON_HEADERS= \
17861795
$(srcdir)/Include/internal/pycore_obmalloc_init.h \
17871796
$(srcdir)/Include/internal/pycore_opcode.h \
17881797
$(srcdir)/Include/internal/pycore_opcode_utils.h \
1798+
$(srcdir)/Include/internal/pycore_optimizer.h \
17891799
$(srcdir)/Include/internal/pycore_pathconfig.h \
17901800
$(srcdir)/Include/internal/pycore_pyarena.h \
17911801
$(srcdir)/Include/internal/pycore_pyerrors.h \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generate the cases needed for the barebones tier 2 abstract interpreter for optimization passes in CPython.

PCbuild/_freeze_module.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@
218218
<ClCompile Include="..\Python\mysnprintf.c" />
219219
<ClCompile Include="..\Python\mystrtoul.c" />
220220
<ClCompile Include="..\Python\optimizer.c" />
221+
<ClCompile Include="..\Python\optimizer_analysis.c" />
221222
<ClCompile Include="..\Python\pathconfig.c" />
222223
<ClCompile Include="..\Python\perf_trampoline.c" />
223224
<ClCompile Include="..\Python\preconfig.c" />

0 commit comments

Comments
 (0)