Skip to content

Commit

Permalink
Step 1: replace 'python -Xuops' with 'configure --enable-experimental…
Browse files Browse the repository at this point in the history
…-tier2'
  • Loading branch information
gvanrossum committed Apr 26, 2024
1 parent b43c7e1 commit 1eb8fea
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
5 changes: 2 additions & 3 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,8 @@ The internal architecture is roughly as follows.

* There is a Tier 2 interpreter, but it is mostly intended for debugging
the earlier stages of the optimization pipeline. If the JIT is not
enabled, the Tier 2 interpreter can be invoked by passing Python the
``-X uops`` option or by setting the ``PYTHON_UOPS`` environment
variable to ``1``.
enabled, the Tier 2 interpreter can be enabled by configuring Python
with the ``--enable-experimental-tier2`` option.

* When the ``--enable-experimental-jit`` option is used, the optimized
Tier 2 IR is translated to machine code, which is then executed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Change how to use the tier 2 interpreter. Instead of running Python with
``-X uops`` or setting the environment variable ``PYTHON_UOPS=1``, this
choice is now made at build time by configuring with
``--enable-experimental-tier2``.
19 changes: 4 additions & 15 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,30 +1262,19 @@ init_interp_main(PyThreadState *tstate)
}

// Turn on experimental tier 2 (uops-based) optimizer
// This is also needed when the JIT is enabled
#if defined(_Py_JIT) || defined(_Py_TIER2)
if (is_main_interp) {
#ifndef _Py_JIT
// No JIT, maybe use the tier two interpreter:
char *envvar = Py_GETENV("PYTHON_UOPS");
int enabled = envvar != NULL && *envvar > '0';
if (_Py_get_xoption(&config->xoptions, L"uops") != NULL) {
enabled = 1;
}
if (enabled) {
#else
// Always enable tier two for JIT builds (ignoring the environment
// variable and command-line option above):
if (true) {
#endif
PyObject *opt = PyUnstable_Optimizer_NewUOpOptimizer();
if (opt == NULL) {
return _PyStatus_ERR("can't initialize optimizer");
}
if (PyUnstable_SetOptimizer((_PyOptimizerObject *)opt)) {
return _PyStatus_ERR("can't initialize optimizer");
return _PyStatus_ERR("can't install optimizer");
}
Py_DECREF(opt);
}
}
#endif

if (!is_main_interp) {
// The main interpreter is handled in Py_Main(), for now.
Expand Down
24 changes: 24 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,19 @@ AC_SUBST([REGEN_JIT_COMMAND])
AC_SUBST([JIT_STENCILS_H])
AC_MSG_RESULT([$enable_experimental_jit])

# Check for --enable-experimental-tier2:
AC_MSG_CHECKING([for --enable-experimental-tier2])
AC_ARG_ENABLE([experimental-tier2],
[AS_HELP_STRING([--enable-experimental-tier2],
[use the experimental tier 2 interpreter (default is no)])],
[],
[enable_experimental_tier2=no])
AS_VAR_IF([enable_experimental_tier2],
[no],
[],
[AS_VAR_APPEND([CFLAGS_NODIST], [" -D_Py_TIER2"])])
AC_MSG_RESULT([$enable_experimental_tier2])

# Enable optimization flags
AC_SUBST([DEF_MAKE_ALL_RULE])
AC_SUBST([DEF_MAKE_RULE])
Expand Down

0 comments on commit 1eb8fea

Please sign in to comment.