@@ -9,6 +9,7 @@ extern "C" {
9
9
#endif
10
10
11
11
#include "pycore_uop_ids.h"
12
+ #include <stdbool.h>
12
13
13
14
// This is the length of the trace we project initially.
14
15
#define UOP_MAX_TRACE_LENGTH 512
@@ -25,6 +26,90 @@ extern PyTypeObject _PyDefaultOptimizer_Type;
25
26
extern PyTypeObject _PyUOpExecutor_Type ;
26
27
extern PyTypeObject _PyUOpOptimizer_Type ;
27
28
29
+ /* Symbols */
30
+
31
+ struct _Py_UOpsSymType {
32
+ int flags ;
33
+ PyTypeObject * typ ;
34
+ // constant propagated value (might be NULL)
35
+ PyObject * const_val ;
36
+ };
37
+
38
+ // Holds locals, stack, locals, stack ... co_consts (in that order)
39
+ #define MAX_ABSTRACT_INTERP_SIZE 4096
40
+
41
+ #define OVERALLOCATE_FACTOR 5
42
+
43
+ #define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * OVERALLOCATE_FACTOR)
44
+
45
+ // Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
46
+ #define MAX_ABSTRACT_FRAME_DEPTH (TRACE_STACK_SIZE + 2)
47
+
48
+ typedef struct _Py_UOpsSymType _Py_UOpsSymType ;
49
+
50
+ struct _Py_UOpsAbstractFrame {
51
+ // Max stacklen
52
+ int stack_len ;
53
+ int locals_len ;
54
+
55
+ _Py_UOpsSymType * * stack_pointer ;
56
+ _Py_UOpsSymType * * stack ;
57
+ _Py_UOpsSymType * * locals ;
58
+ };
59
+
60
+ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame ;
61
+
62
+ typedef struct ty_arena {
63
+ int ty_curr_number ;
64
+ int ty_max_number ;
65
+ _Py_UOpsSymType arena [TY_ARENA_SIZE ];
66
+ } ty_arena ;
67
+
68
+ struct _Py_UOpsAbstractInterpContext {
69
+ PyObject_HEAD
70
+ // The current "executing" frame.
71
+ _Py_UOpsAbstractFrame * frame ;
72
+ _Py_UOpsAbstractFrame frames [MAX_ABSTRACT_FRAME_DEPTH ];
73
+ int curr_frame_depth ;
74
+
75
+ // Arena for the symbolic types.
76
+ ty_arena t_arena ;
77
+
78
+ _Py_UOpsSymType * * n_consumed ;
79
+ _Py_UOpsSymType * * limit ;
80
+ _Py_UOpsSymType * locals_and_stack [MAX_ABSTRACT_INTERP_SIZE ];
81
+ };
82
+
83
+ typedef struct _Py_UOpsAbstractInterpContext _Py_UOpsAbstractInterpContext ;
84
+
85
+ extern bool _Py_uop_sym_is_null (_Py_UOpsSymType * sym );
86
+ extern bool _Py_uop_sym_is_not_null (_Py_UOpsSymType * sym );
87
+ extern bool _Py_uop_sym_is_const (_Py_UOpsSymType * sym );
88
+ extern PyObject * _Py_uop_sym_get_const (_Py_UOpsSymType * sym );
89
+ extern _Py_UOpsSymType * _Py_uop_sym_new_unknown (_Py_UOpsAbstractInterpContext * ctx );
90
+ extern _Py_UOpsSymType * _Py_uop_sym_new_not_null (_Py_UOpsAbstractInterpContext * ctx );
91
+ extern _Py_UOpsSymType * _Py_uop_sym_new_type (
92
+ _Py_UOpsAbstractInterpContext * ctx , PyTypeObject * typ );
93
+ extern _Py_UOpsSymType * _Py_uop_sym_new_const (_Py_UOpsAbstractInterpContext * ctx , PyObject * const_val );
94
+ extern _Py_UOpsSymType * _Py_uop_sym_new_null (_Py_UOpsAbstractInterpContext * ctx );
95
+ extern bool _Py_uop_sym_matches_type (_Py_UOpsSymType * sym , PyTypeObject * typ );
96
+ extern void _Py_uop_sym_set_null (_Py_UOpsSymType * sym );
97
+ extern void _Py_uop_sym_set_type (_Py_UOpsSymType * sym , PyTypeObject * tp );
98
+
99
+ extern int _Py_uop_abstractcontext_init (_Py_UOpsAbstractInterpContext * ctx );
100
+ extern void _Py_uop_abstractcontext_fini (_Py_UOpsAbstractInterpContext * ctx );
101
+
102
+ extern _Py_UOpsAbstractFrame * _Py_uop_ctx_frame_new (
103
+ _Py_UOpsAbstractInterpContext * ctx ,
104
+ PyCodeObject * co ,
105
+ _Py_UOpsSymType * * localsplus_start ,
106
+ int n_locals_already_filled ,
107
+ int curr_stackentries );
108
+ extern int _Py_uop_ctx_frame_pop (_Py_UOpsAbstractInterpContext * ctx );
109
+
110
+ PyAPI_FUNC (PyObject * )
111
+ _Py_uop_symbols_test (PyObject * self , PyObject * ignored );
112
+
28
113
#ifdef __cplusplus
29
114
}
30
115
#endif
0 commit comments