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