From c3a12ae13ee0212a096f570064407f8ba954e6aa Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski <savannahostrowski@gmail.com> Date: Tue, 5 Nov 2024 15:26:46 -0800 Subject: GH-125911: Rename big trampoline to "shim" (GH-126339) --- Python/jit.c | 12 +++++------- Tools/jit/_targets.py | 4 ++-- Tools/jit/_writer.py | 4 ++-- Tools/jit/shim.c | 24 ++++++++++++++++++++++++ Tools/jit/trampoline.c | 24 ------------------------ 5 files changed, 33 insertions(+), 35 deletions(-) create mode 100644 Tools/jit/shim.c delete mode 100644 Tools/jit/trampoline.c diff --git a/Python/jit.c b/Python/jit.c index 135daeb..90f693d 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -470,7 +470,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz size_t code_size = 0; size_t data_size = 0; jit_state state = {0}; - group = &trampoline; + group = &shim; code_size += group->code_size; data_size += group->data_size; combine_symbol_mask(group->trampoline_mask, state.trampolines.mask); @@ -507,12 +507,10 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz unsigned char *code = memory; unsigned char *data = memory + code_size; state.trampolines.mem = memory + code_size + data_size; - // Compile the trampoline, which handles converting between the native + // Compile the shim, which handles converting between the native // calling convention and the calling convention used by jitted code - // (which may be different for efficiency reasons). On platforms where - // we don't change calling conventions, the trampoline is empty and - // nothing is emitted here: - group = &trampoline; + // (which may be different for efficiency reasons). + group = &shim; group->emit(code, data, executor, NULL, &state); code += group->code_size; data += group->data_size; @@ -536,7 +534,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz return -1; } executor->jit_code = memory; - executor->jit_side_entry = memory + trampoline.code_size; + executor->jit_side_entry = memory + shim.code_size; executor->jit_size = total_size; return 0; } diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 634208d..d8dce0a 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -154,8 +154,8 @@ class _Target(typing.Generic[_S, _R]): with tempfile.TemporaryDirectory() as tempdir: work = pathlib.Path(tempdir).resolve() async with asyncio.TaskGroup() as group: - coro = self._compile("trampoline", TOOLS_JIT / "trampoline.c", work) - tasks.append(group.create_task(coro, name="trampoline")) + coro = self._compile("shim", TOOLS_JIT / "shim.c", work) + tasks.append(group.create_task(coro, name="shim")) template = TOOLS_JIT_TEMPLATE_C.read_text() for case, opname in cases_and_opnames: # Write out a copy of the template with *only* this case diff --git a/Tools/jit/_writer.py b/Tools/jit/_writer.py index f33d8ef..81a9f08 100644 --- a/Tools/jit/_writer.py +++ b/Tools/jit/_writer.py @@ -22,11 +22,11 @@ def _dump_footer( yield " symbol_mask trampoline_mask;" yield "} StencilGroup;" yield "" - yield f"static const StencilGroup trampoline = {groups['trampoline'].as_c('trampoline')};" + yield f"static const StencilGroup shim = {groups['shim'].as_c('shim')};" yield "" yield "static const StencilGroup stencil_groups[MAX_UOP_ID + 1] = {" for opname, group in sorted(groups.items()): - if opname == "trampoline": + if opname == "shim": continue yield f" [{opname}] = {group.as_c(opname)}," yield "};" diff --git a/Tools/jit/shim.c b/Tools/jit/shim.c new file mode 100644 index 0000000..f0cffa2 --- /dev/null +++ b/Tools/jit/shim.c @@ -0,0 +1,24 @@ +#include "Python.h" + +#include "pycore_ceval.h" +#include "pycore_frame.h" +#include "pycore_jit.h" + +#include "jit.h" + +_Py_CODEUNIT * +_JIT_ENTRY(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate) +{ + // This is subtle. The actual trace will return to us once it exits, so we + // need to make sure that we stay alive until then. If our trace side-exits + // into another trace, and this trace is then invalidated, the code for + // *this function* will be freed and we'll crash upon return: + PyAPI_DATA(void) _JIT_EXECUTOR; + PyObject *executor = (PyObject *)(uintptr_t)&_JIT_EXECUTOR; + Py_INCREF(executor); + // Note that this is *not* a tail call: + PyAPI_DATA(void) _JIT_CONTINUE; + _Py_CODEUNIT *target = ((jit_func_preserve_none)&_JIT_CONTINUE)(frame, stack_pointer, tstate); + Py_SETREF(tstate->previous_executor, executor); + return target; +} diff --git a/Tools/jit/trampoline.c b/Tools/jit/trampoline.c deleted file mode 100644 index f0cffa2..0000000 --- a/Tools/jit/trampoline.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "Python.h" - -#include "pycore_ceval.h" -#include "pycore_frame.h" -#include "pycore_jit.h" - -#include "jit.h" - -_Py_CODEUNIT * -_JIT_ENTRY(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate) -{ - // This is subtle. The actual trace will return to us once it exits, so we - // need to make sure that we stay alive until then. If our trace side-exits - // into another trace, and this trace is then invalidated, the code for - // *this function* will be freed and we'll crash upon return: - PyAPI_DATA(void) _JIT_EXECUTOR; - PyObject *executor = (PyObject *)(uintptr_t)&_JIT_EXECUTOR; - Py_INCREF(executor); - // Note that this is *not* a tail call: - PyAPI_DATA(void) _JIT_CONTINUE; - _Py_CODEUNIT *target = ((jit_func_preserve_none)&_JIT_CONTINUE)(frame, stack_pointer, tstate); - Py_SETREF(tstate->previous_executor, executor); - return target; -} -- cgit v0.12