Skip to content

Commit 27a7160

Browse files
authored
gh-141504: Move PYTHON_UOPS_OPTIMIZE to policy object (GH-144082)
1 parent 48b6866 commit 27a7160

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Include/internal/pycore_interp_structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ typedef struct _PyOptimizationConfig {
411411

412412
// Optimization flags
413413
bool specialization_enabled;
414+
bool uops_optimize_enabled;
414415
} _PyOptimizationConfig;
415416

416417
struct

Python/optimizer.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,11 +1514,7 @@ uop_optimize(
15141514
_PyBloomFilter *dependencies = &_tstate->jit_tracer_state->prev_state.dependencies;
15151515
_PyUOpInstruction *buffer = _tstate->jit_tracer_state->code_buffer;
15161516
OPT_STAT_INC(attempts);
1517-
char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
1518-
bool is_noopt = true;
1519-
if (env_var == NULL || *env_var == '\0' || *env_var > '0') {
1520-
is_noopt = false;
1521-
}
1517+
bool is_noopt = !tstate->interp->opt_config.uops_optimize_enabled;
15221518
int curr_stackentries = _tstate->jit_tracer_state->initial_state.stack_depth;
15231519
int length = _tstate->jit_tracer_state->prev_state.code_curr_size;
15241520
if (length <= CODE_SIZE_NO_PROGRESS) {

Python/pystate.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,13 @@ is_env_enabled(const char *env_name)
522522
return env && *env != '\0' && *env != '0';
523523
}
524524

525+
static inline bool
526+
is_env_disabled(const char *env_name)
527+
{
528+
char *env = Py_GETENV(env_name);
529+
return env != NULL && *env == '0';
530+
}
531+
525532
static inline void
526533
init_policy(uint16_t *target, const char *env_name, uint16_t default_value,
527534
long min_value, long max_value)
@@ -619,6 +626,7 @@ init_interpreter(PyInterpreterState *interp,
619626
SIDE_EXIT_INITIAL_BACKOFF, 0, MAX_BACKOFF);
620627

621628
interp->opt_config.specialization_enabled = !is_env_enabled("PYTHON_SPECIALIZATION_OFF");
629+
interp->opt_config.uops_optimize_enabled = !is_env_disabled("PYTHON_UOPS_OPTIMIZE");
622630
if (interp != &runtime->_main_interpreter) {
623631
/* Fix the self-referential, statically initialized fields. */
624632
interp->dtoa = (struct _dtoa_state)_dtoa_state_INIT(interp);

0 commit comments

Comments
 (0)