From d4f661e33fa3184387685ae9dc987bf5ad5bed79 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 16 Oct 2024 14:13:27 -0400 Subject: [PATCH 1/2] gh-123153: Fix PGO builds with free-threading --- Python/ceval.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index 43776e773e0deb..ee49cea7f81bca 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -761,12 +761,19 @@ _PyObjectArray_Free(PyObject **array, PyObject **scratch) * so consume 3 units of C stack */ #define PY_EVAL_C_STACK_UNITS 2 -#if defined(_MSC_VER) && defined(_Py_USING_PGO) && defined(_Py_JIT) -/* _PyEval_EvalFrameDefault is too large to optimize for speed with - PGO on MSVC when the JIT is enabled. Disable that optimization - around this function only. If this is fixed upstream, we should - gate this on the version of MSVC. + +/* _PyEval_EvalFrameDefault is too large to optimize for speed with PGO on MSVC + when the JIT is enabled or GIL is disabled. Disable that optimization around + this function only. If this is fixed upstream, we should gate this on the + version of MSVC. */ +#define DO_NOT_OPTIMIZE_INTERP_LOOP ( \ + (defined(_MSC_VER) && \ + defined(_Py_USING_PGO) && \ + (defined(_Py_JIT) || \ + defined(Py_GIL_DISABLED)))) + +#if DO_NOT_OPTIMIZE_INTERP_LOOP # pragma optimize("t", off) /* This setting is reversed below following _PyEval_EvalFrameDefault */ #endif @@ -1146,7 +1153,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } -#if defined(_MSC_VER) && defined(_Py_USING_PGO) && defined(_Py_JIT) +#if DO_NOT_OPTIMIZE_INTERP_LOOP # pragma optimize("", on) #endif From ec692b17fd94fbb497428ffd52d547f8597de5f4 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 16 Oct 2024 15:26:25 -0400 Subject: [PATCH 2/2] Redo how the #define works --- Python/ceval.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index ee49cea7f81bca..98d95b28488fd0 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -767,13 +767,14 @@ _PyObjectArray_Free(PyObject **array, PyObject **scratch) this function only. If this is fixed upstream, we should gate this on the version of MSVC. */ -#define DO_NOT_OPTIMIZE_INTERP_LOOP ( \ - (defined(_MSC_VER) && \ +#if (defined(_MSC_VER) && \ defined(_Py_USING_PGO) && \ (defined(_Py_JIT) || \ - defined(Py_GIL_DISABLED)))) + defined(Py_GIL_DISABLED))) +#define DO_NOT_OPTIMIZE_INTERP_LOOP +#endif -#if DO_NOT_OPTIMIZE_INTERP_LOOP +#ifdef DO_NOT_OPTIMIZE_INTERP_LOOP # pragma optimize("t", off) /* This setting is reversed below following _PyEval_EvalFrameDefault */ #endif @@ -1153,7 +1154,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } -#if DO_NOT_OPTIMIZE_INTERP_LOOP +#ifdef DO_NOT_OPTIMIZE_INTERP_LOOP # pragma optimize("", on) #endif