@@ -12,6 +12,7 @@ extern "C" {
1212#include "pycore_uop.h" // _PyUOpInstruction
1313#include "pycore_uop_ids.h"
1414#include "pycore_stackref.h" // _PyStackRef
15+ #include "pycore_optimizer_types.h"
1516#include <stdbool.h>
1617
1718
@@ -84,7 +85,7 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);
8485#define JIT_CLEANUP_THRESHOLD 1000
8586
8687int _Py_uop_analyze_and_optimize (
87- PyFunctionObject * func ,
88+ _PyThreadStateImpl * tstate ,
8889 _PyUOpInstruction * trace , int trace_len , int curr_stackentries ,
8990 _PyBloomFilter * dependencies );
9091
@@ -112,86 +113,6 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
112113 return inst -> error_target ;
113114}
114115
115- // Holds locals, stack, locals, stack ... co_consts (in that order)
116- #define MAX_ABSTRACT_INTERP_SIZE 4096
117-
118- #define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)
119-
120- // Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
121- #define MAX_ABSTRACT_FRAME_DEPTH (16)
122-
123- // The maximum number of side exits that we can take before requiring forward
124- // progress (and inserting a new ENTER_EXECUTOR instruction). In practice, this
125- // is the "maximum amount of polymorphism" that an isolated trace tree can
126- // handle before rejoining the rest of the program.
127- #define MAX_CHAIN_DEPTH 4
128-
129- /* Symbols */
130- /* See explanation in optimizer_symbols.c */
131-
132-
133- typedef enum _JitSymType {
134- JIT_SYM_UNKNOWN_TAG = 1 ,
135- JIT_SYM_NULL_TAG = 2 ,
136- JIT_SYM_NON_NULL_TAG = 3 ,
137- JIT_SYM_BOTTOM_TAG = 4 ,
138- JIT_SYM_TYPE_VERSION_TAG = 5 ,
139- JIT_SYM_KNOWN_CLASS_TAG = 6 ,
140- JIT_SYM_KNOWN_VALUE_TAG = 7 ,
141- JIT_SYM_TUPLE_TAG = 8 ,
142- JIT_SYM_TRUTHINESS_TAG = 9 ,
143- JIT_SYM_COMPACT_INT = 10 ,
144- } JitSymType ;
145-
146- typedef struct _jit_opt_known_class {
147- uint8_t tag ;
148- uint32_t version ;
149- PyTypeObject * type ;
150- } JitOptKnownClass ;
151-
152- typedef struct _jit_opt_known_version {
153- uint8_t tag ;
154- uint32_t version ;
155- } JitOptKnownVersion ;
156-
157- typedef struct _jit_opt_known_value {
158- uint8_t tag ;
159- PyObject * value ;
160- } JitOptKnownValue ;
161-
162- #define MAX_SYMBOLIC_TUPLE_SIZE 7
163-
164- typedef struct _jit_opt_tuple {
165- uint8_t tag ;
166- uint8_t length ;
167- uint16_t items [MAX_SYMBOLIC_TUPLE_SIZE ];
168- } JitOptTuple ;
169-
170- typedef struct {
171- uint8_t tag ;
172- bool invert ;
173- uint16_t value ;
174- } JitOptTruthiness ;
175-
176- typedef struct {
177- uint8_t tag ;
178- } JitOptCompactInt ;
179-
180- typedef union _jit_opt_symbol {
181- uint8_t tag ;
182- JitOptKnownClass cls ;
183- JitOptKnownValue value ;
184- JitOptKnownVersion version ;
185- JitOptTuple tuple ;
186- JitOptTruthiness truthiness ;
187- JitOptCompactInt compact ;
188- } JitOptSymbol ;
189-
190-
191- // This mimics the _PyStackRef API
192- typedef union {
193- uintptr_t bits ;
194- } JitOptRef ;
195116
196117#define REF_IS_BORROWED 1
197118
@@ -238,48 +159,6 @@ PyJitRef_IsBorrowed(JitOptRef ref)
238159 return (ref .bits & REF_IS_BORROWED ) == REF_IS_BORROWED ;
239160}
240161
241- struct _Py_UOpsAbstractFrame {
242- bool globals_watched ;
243- // The version number of the globals dicts, once checked. 0 if unchecked.
244- uint32_t globals_checked_version ;
245- // Max stacklen
246- int stack_len ;
247- int locals_len ;
248- PyFunctionObject * func ;
249- PyCodeObject * code ;
250-
251- JitOptRef * stack_pointer ;
252- JitOptRef * stack ;
253- JitOptRef * locals ;
254- };
255-
256- typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame ;
257-
258- typedef struct ty_arena {
259- int ty_curr_number ;
260- int ty_max_number ;
261- JitOptSymbol arena [TY_ARENA_SIZE ];
262- } ty_arena ;
263-
264- typedef struct _JitOptContext {
265- char done ;
266- char out_of_space ;
267- bool contradiction ;
268- // Has the builtins dict been watched?
269- bool builtins_watched ;
270- // The current "executing" frame.
271- _Py_UOpsAbstractFrame * frame ;
272- _Py_UOpsAbstractFrame frames [MAX_ABSTRACT_FRAME_DEPTH ];
273- int curr_frame_depth ;
274-
275- // Arena for the symbolic types.
276- ty_arena t_arena ;
277-
278- JitOptRef * n_consumed ;
279- JitOptRef * limit ;
280- JitOptRef locals_and_stack [MAX_ABSTRACT_INTERP_SIZE ];
281- } JitOptContext ;
282-
283162extern bool _Py_uop_sym_is_null (JitOptRef sym );
284163extern bool _Py_uop_sym_is_not_null (JitOptRef sym );
285164extern bool _Py_uop_sym_is_const (JitOptContext * ctx , JitOptRef sym );
0 commit comments