@@ -1225,8 +1225,16 @@ int effective_trace_length(_PyUOpInstruction *buffer, int length)
12251225}
12261226#endif
12271227
1228- static int uop_optimize_initialized = 0 ;
1229- static int uop_optimize_flag = 0 ;
1228+ static void
1229+ initialize_uops_optimize_flag () {
1230+ PyInterpreterState * interp = _PyInterpreterState_GET ();
1231+ if (!python_uops_optimize_initialized ) {
1232+ char * env_var = Py_GETENV ("PYTHON_UOPS_OPTIMIZE" );
1233+ interp -> uops_optimize_flag = (env_var == NULL || * env_var == '\0' || * env_var > '0' );
1234+ uops_optimize_initialized = true;
1235+ }
1236+ uops_optimize_flag = interp -> uops_optimize_flag ;
1237+ }
12301238
12311239static int
12321240uop_optimize (
@@ -1237,6 +1245,8 @@ uop_optimize(
12371245 int curr_stackentries ,
12381246 bool progress_needed )
12391247{
1248+ initialize_uops_optimize_flag ();
1249+
12401250 _PyBloomFilter dependencies ;
12411251 _Py_BloomFilter_Init (& dependencies );
12421252 _PyUOpInstruction buffer [UOP_MAX_TRACE_LENGTH ];
@@ -1248,18 +1258,7 @@ uop_optimize(
12481258 }
12491259 assert (length < UOP_MAX_TRACE_LENGTH );
12501260 OPT_STAT_INC (traces_created );
1251-
1252- if (!uop_optimize_initialized ) {
1253- char * env_var = Py_GETENV ("PYTHON_UOPS_OPTIMIZE" );
1254- if (env_var == NULL || * env_var == '\0' || * env_var > '0' ) {
1255- uop_optimize_flag = 1 ;
1256- } else {
1257- uop_optimize_flag = 0 ;
1258- }
1259- uop_optimize_initialized = 1 ;
1260- }
1261-
1262- if (uop_optimize_flag ) {
1261+ if (uops_optimize_flag ) {
12631262 length = _Py_uop_analyze_and_optimize (frame , buffer ,
12641263 length ,
12651264 curr_stackentries , & dependencies );
0 commit comments