Skip to content

Commit a98b1c8

Browse files
committed
Remove old shim code
1 parent 0dd2c49 commit a98b1c8

File tree

8 files changed

+22
-45
lines changed

8 files changed

+22
-45
lines changed

Include/internal/pycore_ceval.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,19 @@ _PyEval_EvalFrame(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwfl
123123
return tstate->interp->eval_frame(tstate, frame, throwflag);
124124
}
125125

126-
#if defined(_Py_TIER2) && !defined(_Py_JIT)
126+
#ifdef _Py_TIER2
127+
#ifdef _Py_JIT
128+
_Py_CODEUNIT *_Py_LazyJitTrampoline(
129+
struct _PyExecutorObject *current_executor, _PyInterpreterFrame *frame,
130+
_PyStackRef *stack_pointer, PyThreadState *tstate
131+
);
132+
#else
127133
_Py_CODEUNIT *_PyTier2Interpreter(
128134
struct _PyExecutorObject *current_executor, _PyInterpreterFrame *frame,
129135
_PyStackRef *stack_pointer, PyThreadState *tstate
130136
);
131137
#endif
138+
#endif
132139

133140
extern _PyJitEntryFuncPtr _Py_jit_entry;
134141

Include/internal/pycore_optimizer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ typedef struct _PyExecutorObject {
8282
uint32_t code_size;
8383
size_t jit_size;
8484
void *jit_code;
85-
void *jit_side_entry;
8685
_PyExitData exits[1];
8786
} _PyExecutorObject;
8887

Python/jit.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
494494
size_t code_size = 0;
495495
size_t data_size = 0;
496496
jit_state state = {0};
497-
group = &shim;
498-
code_size += group->code_size;
499-
data_size += group->data_size;
500-
combine_symbol_mask(group->trampoline_mask, state.trampolines.mask);
501497
for (size_t i = 0; i < length; i++) {
502498
const _PyUOpInstruction *instruction = &trace[i];
503499
group = &stencil_groups[instruction->opcode];
@@ -539,13 +535,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
539535
unsigned char *code = memory;
540536
state.trampolines.mem = memory + code_size;
541537
unsigned char *data = memory + code_size + state.trampolines.size + code_padding;
542-
// Compile the shim, which handles converting between the native
543-
// calling convention and the calling convention used by jitted code
544-
// (which may be different for efficiency reasons).
545-
group = &shim;
546-
group->emit(code, data, executor, NULL, &state);
547-
code += group->code_size;
548-
data += group->data_size;
549538
assert(trace[0].opcode == _START_EXECUTOR || trace[0].opcode == _COLD_EXIT);
550539
for (size_t i = 0; i < length; i++) {
551540
const _PyUOpInstruction *instruction = &trace[i];
@@ -566,7 +555,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
566555
return -1;
567556
}
568557
executor->jit_code = memory;
569-
executor->jit_side_entry = memory + shim.code_size;
570558
executor->jit_size = total_size;
571559
return 0;
572560
}
@@ -615,19 +603,23 @@ compile_trampoline(void)
615603
return (_PyJitEntryFuncPtr)memory;
616604
}
617605

606+
static PyMutex lazy_jit_mutex = { 0 };
618607

619608
_Py_CODEUNIT *
620609
_Py_LazyJitTrampoline(
621610
_PyExecutorObject *executor, _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate
622611
) {
623-
assert(_Py_jit_entry == _Py_LazyJitTrampoline);
624-
PyInterpreterState *interp = PyInterpreterState_Get();
625-
_PyJitEntryFuncPtr trampoline = compile_trampoline();
626-
if (trampoline == NULL) {
627-
Py_FatalError("Cannot allocate core JIT code");
612+
PyMutex_Lock(&lazy_jit_mutex);
613+
if (_Py_jit_entry == _Py_LazyJitTrampoline) {
614+
_PyJitEntryFuncPtr trampoline = compile_trampoline();
615+
if (trampoline == NULL) {
616+
PyMutex_Unlock(&lazy_jit_mutex);
617+
Py_FatalError("Cannot allocate core JIT code");
618+
}
619+
_Py_jit_entry = trampoline;
628620
}
629-
_Py_jit_entry = trampoline;
630-
return trampoline(executor, frame, stack_pointer, tstate);
621+
PyMutex_Unlock(&lazy_jit_mutex);
622+
return _Py_jit_entry(executor, frame, stack_pointer, tstate);
631623
}
632624

633625
void
@@ -637,7 +629,6 @@ _PyJIT_Free(_PyExecutorObject *executor)
637629
size_t size = executor->jit_size;
638630
if (memory) {
639631
executor->jit_code = NULL;
640-
executor->jit_side_entry = NULL;
641632
executor->jit_size = 0;
642633
if (jit_free(memory, size)) {
643634
PyErr_FormatUnraisable("Exception ignored while "

Python/optimizer.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,6 @@ make_executor_from_uops(_PyUOpInstruction *buffer, int length, const _PyBloomFil
12381238
#endif
12391239
#ifdef _Py_JIT
12401240
executor->jit_code = NULL;
1241-
executor->jit_side_entry = NULL;
12421241
executor->jit_size = 0;
12431242
// This is initialized to true so we can prevent the executor
12441243
// from being immediately detected as cold and invalidated.
@@ -1490,7 +1489,6 @@ _PyExecutor_GetColdExecutor(void)
14901489
((_PyUOpInstruction *)cold->trace)->opcode = _COLD_EXIT;
14911490
#ifdef _Py_JIT
14921491
cold->jit_code = NULL;
1493-
cold->jit_side_entry = NULL;
14941492
cold->jit_size = 0;
14951493
// This is initialized to true so we can prevent the executor
14961494
// from being immediately detected as cold and invalidated.

Tools/jit/_targets.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
191191
with tempfile.TemporaryDirectory() as tempdir:
192192
work = pathlib.Path(tempdir).resolve()
193193
async with asyncio.TaskGroup() as group:
194-
coro = self._compile("shim", TOOLS_JIT / "shim.c", work)
195-
tasks.append(group.create_task(coro, name="shim"))
196194
coro = self._compile("trampoline", TOOLS_JIT / "trampoline.c", work)
197195
tasks.append(group.create_task(coro, name="trampoline"))
198196
template = TOOLS_JIT_TEMPLATE_C.read_text()

Tools/jit/_writer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ def _dump_footer(
2222
yield " symbol_mask trampoline_mask;"
2323
yield "} StencilGroup;"
2424
yield ""
25-
yield f"static const StencilGroup shim = {groups['shim'].as_c('shim')};"
2625
yield f"static const StencilGroup trampoline = {groups['trampoline'].as_c('trampoline')};"
2726
yield ""
2827
yield "static const StencilGroup stencil_groups[MAX_UOP_ID + 1] = {"
2928
for opname, group in sorted(groups.items()):
30-
if opname in ("shim", "trampoline"):
29+
if opname == "trampoline":
3130
continue
3231
yield f" [{opname}] = {group.as_c(opname)},"
3332
yield "};"

Tools/jit/shim.c

Lines changed: 0 additions & 15 deletions
This file was deleted.

Tools/jit/template.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
#define CURRENT_TARGET() (_target)
4848

4949
#undef TIER2_TO_TIER2
50-
#define TIER2_TO_TIER2(EXECUTOR) \
50+
#define TIER2_TO_TIER2(EXECUTOR) \
5151
do { \
5252
OPT_STAT_INC(traces_executed); \
5353
_PyExecutorObject *_executor = (EXECUTOR); \
54-
jit_func_preserve_none jitted = _executor->jit_side_entry; \
54+
jit_func_preserve_none jitted = _executor->jit_code; \
5555
__attribute__((musttail)) return jitted(frame, stack_pointer, tstate); \
5656
} while (0)
5757

0 commit comments

Comments
 (0)