11#include "Python.h"
22#include "pycore_uops.h"
33#include "pycore_uop_ids.h"
4+ #include "internal/pycore_moduleobject.h"
45
56#define op (name , ...) /* NAME is ignored */
67
@@ -87,11 +88,11 @@ dummy_func(void) {
8788 }
8889
8990 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 ));
9596 if (temp == NULL ) {
9697 goto error ;
9798 }
@@ -105,11 +106,11 @@ dummy_func(void) {
105106 }
106107
107108 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 ));
113114 if (temp == NULL ) {
114115 goto error ;
115116 }
@@ -123,11 +124,11 @@ dummy_func(void) {
123124 }
124125
125126 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 ));
131132 if (temp == NULL ) {
132133 goto error ;
133134 }
@@ -141,12 +142,12 @@ dummy_func(void) {
141142 }
142143
143144 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 )));
147148 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 )));
150151 if (temp == NULL ) {
151152 goto error ;
152153 }
@@ -160,12 +161,12 @@ dummy_func(void) {
160161 }
161162
162163 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 )));
166167 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 )));
169170 if (temp == NULL ) {
170171 goto error ;
171172 }
@@ -179,12 +180,12 @@ dummy_func(void) {
179180 }
180181
181182 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 )));
185186 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 )));
188189 if (temp == NULL ) {
189190 goto error ;
190191 }
@@ -237,10 +238,43 @@ dummy_func(void) {
237238 (void )owner ;
238239 }
239240
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+
240258 op (_LOAD_ATTR_MODULE , (index /1 , owner -- attr , null if (oparg & 1 ))) {
241- _LOAD_ATTR_NOT_NULL
242259 (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+ }
244278 }
245279
246280 op (_LOAD_ATTR_WITH_HINT , (hint /1 , owner -- attr , null if (oparg & 1 ))) {
@@ -347,4 +381,4 @@ dummy_func(void) {
347381
348382// END BYTECODES //
349383
350- }
384+ }
0 commit comments