mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
GH-119726: Deduplicate AArch64 trampolines within a trace (GH-123872)
This commit is contained in:
parent
7a178b7605
commit
b85923a0fe
5 changed files with 146 additions and 58 deletions
|
@ -2,17 +2,24 @@
|
|||
|
||||
import itertools
|
||||
import typing
|
||||
import math
|
||||
|
||||
import _stencils
|
||||
|
||||
|
||||
def _dump_footer(groups: dict[str, _stencils.StencilGroup]) -> typing.Iterator[str]:
|
||||
def _dump_footer(
|
||||
groups: dict[str, _stencils.StencilGroup], symbols: dict[str, int]
|
||||
) -> typing.Iterator[str]:
|
||||
symbol_mask_size = max(math.ceil(len(symbols) / 32), 1)
|
||||
yield f'static_assert(SYMBOL_MASK_WORDS >= {symbol_mask_size}, "SYMBOL_MASK_WORDS too small");'
|
||||
yield ""
|
||||
yield "typedef struct {"
|
||||
yield " void (*emit)("
|
||||
yield " unsigned char *code, unsigned char *data, _PyExecutorObject *executor,"
|
||||
yield " const _PyUOpInstruction *instruction, uintptr_t instruction_starts[]);"
|
||||
yield " const _PyUOpInstruction *instruction, jit_state *state);"
|
||||
yield " size_t code_size;"
|
||||
yield " size_t data_size;"
|
||||
yield " symbol_mask trampoline_mask;"
|
||||
yield "} StencilGroup;"
|
||||
yield ""
|
||||
yield f"static const StencilGroup trampoline = {groups['trampoline'].as_c('trampoline')};"
|
||||
|
@ -23,13 +30,18 @@ def _dump_footer(groups: dict[str, _stencils.StencilGroup]) -> typing.Iterator[s
|
|||
continue
|
||||
yield f" [{opname}] = {group.as_c(opname)},"
|
||||
yield "};"
|
||||
yield ""
|
||||
yield f"static const void * const symbols_map[{max(len(symbols), 1)}] = {{"
|
||||
for symbol, ordinal in symbols.items():
|
||||
yield f" [{ordinal}] = &{symbol},"
|
||||
yield "};"
|
||||
|
||||
|
||||
def _dump_stencil(opname: str, group: _stencils.StencilGroup) -> typing.Iterator[str]:
|
||||
yield "void"
|
||||
yield f"emit_{opname}("
|
||||
yield " unsigned char *code, unsigned char *data, _PyExecutorObject *executor,"
|
||||
yield " const _PyUOpInstruction *instruction, uintptr_t instruction_starts[])"
|
||||
yield " const _PyUOpInstruction *instruction, jit_state *state)"
|
||||
yield "{"
|
||||
for part, stencil in [("code", group.code), ("data", group.data)]:
|
||||
for line in stencil.disassembly:
|
||||
|
@ -58,8 +70,10 @@ def _dump_stencil(opname: str, group: _stencils.StencilGroup) -> typing.Iterator
|
|||
yield ""
|
||||
|
||||
|
||||
def dump(groups: dict[str, _stencils.StencilGroup]) -> typing.Iterator[str]:
|
||||
def dump(
|
||||
groups: dict[str, _stencils.StencilGroup], symbols: dict[str, int]
|
||||
) -> typing.Iterator[str]:
|
||||
"""Yield a JIT compiler line-by-line as a C header file."""
|
||||
for opname, group in sorted(groups.items()):
|
||||
yield from _dump_stencil(opname, group)
|
||||
yield from _dump_footer(groups)
|
||||
yield from _dump_footer(groups, symbols)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue