Skip to content

Commit 5c59297

Browse files
authored
Update optimizer.c
1 parent 537431e commit 5c59297

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Python/optimizer.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

12311239
static int
12321240
uop_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

Comments
 (0)