Skip to content

Commit

Permalink
pythongh-117224: Move some large uops to external functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Apr 5, 2024
1 parent d9cfe7e commit 6d74608
Show file tree
Hide file tree
Showing 16 changed files with 451 additions and 189 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Doc/data/stable_abi.dat generated
Doc/library/token-list.inc generated
Include/internal/pycore_ast.h generated
Include/internal/pycore_ast_state.h generated
Include/internal/pycore_executor_externals.h generated
Include/internal/pycore_opcode.h generated
Include/internal/pycore_opcode_metadata.h generated
Include/internal/pycore_*_generated.h generated
Expand All @@ -96,6 +97,7 @@ Parser/token.c generated
Programs/test_frozenmain.h generated
Python/Python-ast.c generated
Python/executor_cases.c.h generated
Python/executor_externals.c generated
Python/generated_cases.c.h generated
Python/optimizer_cases.c.h generated
Python/opcode_targets.h generated
Expand Down
44 changes: 44 additions & 0 deletions Include/internal/pycore_executor_externals.h

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

6 changes: 5 additions & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ PYTHON_OBJS= \
Python/crossinterp.o \
Python/dynamic_annotations.o \
Python/errors.o \
Python/executor_externals.o \
Python/flowgraph.o \
Python/frame.o \
Python/frozenmain.o \
Expand Down Expand Up @@ -1145,6 +1146,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_dict_state.h \
$(srcdir)/Include/internal/pycore_dtoa.h \
$(srcdir)/Include/internal/pycore_exceptions.h \
$(srcdir)/Include/internal/pycore_executor_externals.h \
$(srcdir)/Include/internal/pycore_faulthandler.h \
$(srcdir)/Include/internal/pycore_fileutils.h \
$(srcdir)/Include/internal/pycore_floatobject.h \
Expand Down Expand Up @@ -1905,8 +1907,10 @@ regen-generated-cases:
.PHONY: regen-executor-cases
regen-executor-cases:
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/cases_generator/tier2_generator.py \
-o $(srcdir)/Python/executor_cases.c.h.new $(srcdir)/Python/bytecodes.c
-o $(srcdir)/Python/executor_cases.c.h.new $(srcdir)/Python/executor_externals.c.new $(srcdir)/Include/internal/pycore_executor_externals.h.new $(srcdir)/Python/bytecodes.c
$(UPDATE_FILE) $(srcdir)/Python/executor_cases.c.h $(srcdir)/Python/executor_cases.c.h.new
$(UPDATE_FILE) $(srcdir)/Python/executor_externals.c $(srcdir)/Python/executor_externals.c.new
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_executor_externals.h $(srcdir)/Include/internal/pycore_executor_externals.h.new

.PHONY: regen-optimizer-cases
regen-optimizer-cases:
Expand Down
1 change: 1 addition & 0 deletions PCbuild/_freeze_module.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<ClCompile Include="..\Python\dynamic_annotations.c" />
<ClCompile Include="..\Python\dynload_win.c" />
<ClCompile Include="..\Python\errors.c" />
<ClCompile Include="..\Python\executor_externals.c" />
<ClCompile Include="..\Python\fileutils.c" />
<ClCompile Include="..\Python\flowgraph.c" />
<ClCompile Include="..\Python\formatter_unicode.c" />
Expand Down
1 change: 1 addition & 0 deletions PCbuild/_freeze_module.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<ClCompile Include="..\Objects\exceptions.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\executor_externals.c" />
<ClCompile Include="..\Modules\faulthandler.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<ClInclude Include="..\Include\internal\pycore_dict_state.h" />
<ClInclude Include="..\Include\internal\pycore_dtoa.h" />
<ClInclude Include="..\Include\internal\pycore_exceptions.h" />
<ClInclude Include="..\Include\internal\pycore_executor_externals.h" />
<ClInclude Include="..\Include\internal\pycore_faulthandler.h" />
<ClInclude Include="..\Include\internal\pycore_fileutils.h" />
<ClInclude Include="..\Include\internal\pycore_fileutils_windows.h" />
Expand Down Expand Up @@ -563,6 +564,7 @@
<ClCompile Include="..\Python\dynamic_annotations.c" />
<ClCompile Include="..\Python\dynload_win.c" />
<ClCompile Include="..\Python\errors.c" />
<ClCompile Include="..\Python\executor_externals.c" />
<ClCompile Include="..\Python\fileutils.c" />
<ClCompile Include="..\Python\flowgraph.c" />
<ClCompile Include="..\Python\formatter_unicode.c" />
Expand Down
6 changes: 6 additions & 0 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@
<ClInclude Include="..\Include\cpython\initconfig.h">
<Filter>Include\cpython</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_executor_externals.h">
<Filter>Include\internal</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_unicodeobject.h">
<Filter>Include\internal</Filter>
</ClInclude>
Expand Down Expand Up @@ -1283,6 +1286,9 @@
<ClCompile Include="..\Python\errors.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\executor_externals.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\fileutils.c">
<Filter>Python</Filter>
</ClCompile>
Expand Down
10 changes: 5 additions & 5 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ dummy_func(
Py_XDECREF(oldobj);
}

inst(COPY_FREE_VARS, (--)) {
externalize inst(COPY_FREE_VARS, (--)) {
/* Copy closure variables to free variables */
PyCodeObject *co = _PyFrame_GetCode(frame);
assert(PyFunction_Check(frame->f_funcobj));
Expand Down Expand Up @@ -3129,7 +3129,7 @@ dummy_func(
DEOPT_IF(Py_TYPE(callable) != &PyMethod_Type);
}

op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, unused, unused[oparg] -- func, self, unused[oparg])) {
externalize op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, unused, unused[oparg] -- func, self, unused[oparg])) {
STAT_INC(CALL, hit);
self = Py_NewRef(((PyMethodObject *)callable)->im_self);
stack_pointer[-1 - oparg] = self; // Patch stack as it is used by _INIT_CALL_PY_EXACT_ARGS
Expand Down Expand Up @@ -3157,7 +3157,7 @@ dummy_func(
DEOPT_IF(tstate->py_recursion_remaining <= 1);
}

replicate(5) pure op(_INIT_CALL_PY_EXACT_ARGS, (callable, self_or_null, args[oparg] -- new_frame: _PyInterpreterFrame*)) {
externalize replicate(5) pure op(_INIT_CALL_PY_EXACT_ARGS, (callable, self_or_null, args[oparg] -- new_frame: _PyInterpreterFrame*)) {
int has_self = (self_or_null != NULL);
STAT_INC(CALL, hit);
PyFunctionObject *func = (PyFunctionObject *)callable;
Expand Down Expand Up @@ -3538,7 +3538,7 @@ dummy_func(
DISPATCH();
}

op(_CALL_METHOD_DESCRIPTOR_O, (callable, self_or_null, args[oparg] -- res)) {
op(_CALL_METHOD_DESCRIPTOR_O, (callable, self_or_null, args[oparg] -- res)) {
int total_args = oparg;
if (self_or_null != NULL) {
args--;
Expand Down Expand Up @@ -3847,7 +3847,7 @@ dummy_func(
func = (PyObject *)func_obj;
}

inst(SET_FUNCTION_ATTRIBUTE, (attr, func -- func)) {
externalize inst(SET_FUNCTION_ATTRIBUTE, (attr, func -- func)) {
assert(PyFunction_Check(func));
PyFunctionObject *func_obj = (PyFunctionObject *)func;
switch(oparg) {
Expand Down
1 change: 1 addition & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "pycore_ceval.h"
#include "pycore_code.h"
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
#include "pycore_executor_externals.h"
#include "pycore_function.h"
#include "pycore_instruments.h"
#include "pycore_intrinsics.h"
Expand Down
Loading

0 comments on commit 6d74608

Please sign in to comment.