1
1
#include "Python.h"
2
2
#include "pycore_uops.h"
3
3
#include "pycore_uop_ids.h"
4
+ #include "internal/pycore_moduleobject.h"
4
5
5
6
#define op (name , ...) /* NAME is ignored */
6
7
@@ -87,11 +88,11 @@ dummy_func(void) {
87
88
}
88
89
89
90
op (_BINARY_OP_ADD_INT , (left , right -- res )) {
90
- if (is_const (left ) && is_const (right )) {
91
- assert (PyLong_CheckExact (get_const (left )));
92
- assert (PyLong_CheckExact (get_const (right )));
93
- PyObject * temp = _PyLong_Add ((PyLongObject * )get_const (left ),
94
- (PyLongObject * )get_const (right ));
91
+ if (sym_is_const (left ) && sym_is_const (right )) {
92
+ assert (PyLong_CheckExact (sym_get_const (left )));
93
+ assert (PyLong_CheckExact (sym_get_const (right )));
94
+ PyObject * temp = _PyLong_Add ((PyLongObject * )sym_get_const (left ),
95
+ (PyLongObject * )sym_get_const (right ));
95
96
if (temp == NULL ) {
96
97
goto error ;
97
98
}
@@ -105,11 +106,11 @@ dummy_func(void) {
105
106
}
106
107
107
108
op (_BINARY_OP_SUBTRACT_INT , (left , right -- res )) {
108
- if (is_const (left ) && is_const (right )) {
109
- assert (PyLong_CheckExact (get_const (left )));
110
- assert (PyLong_CheckExact (get_const (right )));
111
- PyObject * temp = _PyLong_Subtract ((PyLongObject * )get_const (left ),
112
- (PyLongObject * )get_const (right ));
109
+ if (sym_is_const (left ) && sym_is_const (right )) {
110
+ assert (PyLong_CheckExact (sym_get_const (left )));
111
+ assert (PyLong_CheckExact (sym_get_const (right )));
112
+ PyObject * temp = _PyLong_Subtract ((PyLongObject * )sym_get_const (left ),
113
+ (PyLongObject * )sym_get_const (right ));
113
114
if (temp == NULL ) {
114
115
goto error ;
115
116
}
@@ -123,11 +124,11 @@ dummy_func(void) {
123
124
}
124
125
125
126
op (_BINARY_OP_MULTIPLY_INT , (left , right -- res )) {
126
- if (is_const (left ) && is_const (right )) {
127
- assert (PyLong_CheckExact (get_const (left )));
128
- assert (PyLong_CheckExact (get_const (right )));
129
- PyObject * temp = _PyLong_Multiply ((PyLongObject * )get_const (left ),
130
- (PyLongObject * )get_const (right ));
127
+ if (sym_is_const (left ) && sym_is_const (right )) {
128
+ assert (PyLong_CheckExact (sym_get_const (left )));
129
+ assert (PyLong_CheckExact (sym_get_const (right )));
130
+ PyObject * temp = _PyLong_Multiply ((PyLongObject * )sym_get_const (left ),
131
+ (PyLongObject * )sym_get_const (right ));
131
132
if (temp == NULL ) {
132
133
goto error ;
133
134
}
@@ -141,12 +142,12 @@ dummy_func(void) {
141
142
}
142
143
143
144
op (_BINARY_OP_ADD_FLOAT , (left , right -- res )) {
144
- if (is_const (left ) && is_const (right )) {
145
- assert (PyFloat_CheckExact (get_const (left )));
146
- assert (PyFloat_CheckExact (get_const (right )));
145
+ if (sym_is_const (left ) && sym_is_const (right )) {
146
+ assert (PyFloat_CheckExact (sym_get_const (left )));
147
+ assert (PyFloat_CheckExact (sym_get_const (right )));
147
148
PyObject * temp = PyFloat_FromDouble (
148
- PyFloat_AS_DOUBLE (get_const (left )) +
149
- PyFloat_AS_DOUBLE (get_const (right )));
149
+ PyFloat_AS_DOUBLE (sym_get_const (left )) +
150
+ PyFloat_AS_DOUBLE (sym_get_const (right )));
150
151
if (temp == NULL ) {
151
152
goto error ;
152
153
}
@@ -160,12 +161,12 @@ dummy_func(void) {
160
161
}
161
162
162
163
op (_BINARY_OP_SUBTRACT_FLOAT , (left , right -- res )) {
163
- if (is_const (left ) && is_const (right )) {
164
- assert (PyFloat_CheckExact (get_const (left )));
165
- assert (PyFloat_CheckExact (get_const (right )));
164
+ if (sym_is_const (left ) && sym_is_const (right )) {
165
+ assert (PyFloat_CheckExact (sym_get_const (left )));
166
+ assert (PyFloat_CheckExact (sym_get_const (right )));
166
167
PyObject * temp = PyFloat_FromDouble (
167
- PyFloat_AS_DOUBLE (get_const (left )) -
168
- PyFloat_AS_DOUBLE (get_const (right )));
168
+ PyFloat_AS_DOUBLE (sym_get_const (left )) -
169
+ PyFloat_AS_DOUBLE (sym_get_const (right )));
169
170
if (temp == NULL ) {
170
171
goto error ;
171
172
}
@@ -179,12 +180,12 @@ dummy_func(void) {
179
180
}
180
181
181
182
op (_BINARY_OP_MULTIPLY_FLOAT , (left , right -- res )) {
182
- if (is_const (left ) && is_const (right )) {
183
- assert (PyFloat_CheckExact (get_const (left )));
184
- assert (PyFloat_CheckExact (get_const (right )));
183
+ if (sym_is_const (left ) && sym_is_const (right )) {
184
+ assert (PyFloat_CheckExact (sym_get_const (left )));
185
+ assert (PyFloat_CheckExact (sym_get_const (right )));
185
186
PyObject * temp = PyFloat_FromDouble (
186
- PyFloat_AS_DOUBLE (get_const (left )) *
187
- PyFloat_AS_DOUBLE (get_const (right )));
187
+ PyFloat_AS_DOUBLE (sym_get_const (left )) *
188
+ PyFloat_AS_DOUBLE (sym_get_const (right )));
188
189
if (temp == NULL ) {
189
190
goto error ;
190
191
}
@@ -237,10 +238,43 @@ dummy_func(void) {
237
238
(void )owner ;
238
239
}
239
240
241
+ op (_CHECK_ATTR_MODULE , (dict_version /2 , owner -- owner )) {
242
+ (void )dict_version ;
243
+ if (sym_is_const (owner )) {
244
+ PyObject * cnst = sym_get_const (owner );
245
+ if (PyModule_CheckExact (cnst )) {
246
+ PyModuleObject * mod = (PyModuleObject * )cnst ;
247
+ PyObject * dict = mod -> md_dict ;
248
+ uint64_t watched_mutations = get_mutations (dict );
249
+ if (watched_mutations < _Py_MAX_ALLOWED_GLOBALS_MODIFICATIONS ) {
250
+ PyDict_Watch (GLOBALS_WATCHER_ID , dict );
251
+ _Py_BloomFilter_Add (dependencies , dict );
252
+ this_instr -> opcode = _NOP ;
253
+ }
254
+ }
255
+ }
256
+ }
257
+
240
258
op (_LOAD_ATTR_MODULE , (index /1 , owner -- attr , null if (oparg & 1 ))) {
241
- _LOAD_ATTR_NOT_NULL
242
259
(void )index ;
243
- (void )owner ;
260
+ OUT_OF_SPACE_IF_NULL (null = sym_new_null (ctx ));
261
+ attr = NULL ;
262
+ if (this_instr [-1 ].opcode == _NOP ) {
263
+ // Preceding _CHECK_ATTR_MODULE was removed: mod is const and dict is watched.
264
+ assert (sym_is_const (owner ));
265
+ PyModuleObject * mod = (PyModuleObject * )sym_get_const (owner );
266
+ assert (PyModule_CheckExact (mod ));
267
+ PyObject * dict = mod -> md_dict ;
268
+ PyObject * res = convert_global_to_const (this_instr , dict );
269
+ if (res != NULL ) {
270
+ this_instr [-1 ].opcode = _POP_TOP ;
271
+ OUT_OF_SPACE_IF_NULL (attr = sym_new_const (ctx , res ));
272
+ }
273
+ }
274
+ if (attr == NULL ) {
275
+ /* No conversion made. We don't know what `attr` is. */
276
+ OUT_OF_SPACE_IF_NULL (attr = sym_new_known_notnull (ctx ));
277
+ }
244
278
}
245
279
246
280
op (_LOAD_ATTR_WITH_HINT , (hint /1 , owner -- attr , null if (oparg & 1 ))) {
@@ -347,4 +381,4 @@ dummy_func(void) {
347
381
348
382
// END BYTECODES //
349
383
350
- }
384
+ }
0 commit comments