@@ -19,4 +19,54 @@ index c6a7a0f841f027..5f8f0ae69ef31b 100644
1919+ defined(_Py_USING_PGO))
2020 #define DO_NOT_OPTIMIZE_INTERP_LOOP
2121 #endif
22-
22+ diff --git a/PCbuild/pyproject.props b/PCbuild/pyproject.props
23+ index dbdb6b743bea37..17abfa85201a90 100644
24+ --- a/PCbuild/pyproject.props
25+ +++ b/PCbuild/pyproject.props
26+ @@ -53,6 +53,7 @@
27+ <ClCompile>
28+ <AdditionalIncludeDirectories>$(PySourcePath)Include;$(PySourcePath)Include\internal;$(PySourcePath)Include\internal\mimalloc;$(GeneratedPyConfigDir);$(PySourcePath)PC;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
29+ <PreprocessorDefinitions>WIN32;$(_Py3NamePreprocessorDefinition);$(_PlatformPreprocessorDefinition)$(_DebugPreprocessorDefinition)$(_PyStatsPreprocessorDefinition)$(_PydPreprocessorDefinition)%(PreprocessorDefinitions)</PreprocessorDefinitions>
30+ + <PreprocessorDefinitions Condition="'$(SupportPGO)' and ($(Configuration) == 'PGInstrument' or $(Configuration) == 'PGUpdate')">_Py_USING_PGO=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
31+
32+ <Optimization>MaxSpeed</Optimization>
33+ <IntrinsicFunctions>true</IntrinsicFunctions>
34+ diff --git a/Python/ceval.c b/Python/ceval.c
35+ index 1e4f1f3af20aca..c6a7a0f841f027 100644
36+ --- a/Python/ceval.c
37+ +++ b/Python/ceval.c
38+ @@ -764,6 +764,23 @@ _PyObjectArray_Free(PyObject **array, PyObject **scratch)
39+ #define PY_EVAL_C_STACK_UNITS 2
40+
41+
42+ + /* _PyEval_EvalFrameDefault is too large to optimize for speed with PGO on MSVC
43+ + when the JIT is enabled or GIL is disabled. Disable that optimization around
44+ + this function only. If this is fixed upstream, we should gate this on the
45+ + version of MSVC.
46+ + */
47+ + #if (defined(_MSC_VER) && \
48+ + defined(_Py_USING_PGO) && \
49+ + (defined(_Py_JIT) || \
50+ + defined(Py_GIL_DISABLED)))
51+ + #define DO_NOT_OPTIMIZE_INTERP_LOOP
52+ + #endif
53+ +
54+ + #ifdef DO_NOT_OPTIMIZE_INTERP_LOOP
55+ + # pragma optimize("t", off)
56+ + /* This setting is reversed below following _PyEval_EvalFrameDefault */
57+ + #endif
58+ +
59+ #ifdef Py_TAIL_CALL_INTERP
60+ #include "opcode_targets.h"
61+ #include "generated_cases.c.h"
62+ @@ -986,6 +1003,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
63+ return NULL;
64+ }
65+
66+ + #ifdef DO_NOT_OPTIMIZE_INTERP_LOOP
67+ + # pragma optimize("", on)
68+ + #endif
69+ +
70+ #if defined(__GNUC__)
71+ # pragma GCC diagnostic pop
72+ #elif defined(_MSC_VER) /* MS_WINDOWS */
0 commit comments