2024-01-28 22:48:48 -04:00
|
|
|
#include "Python.h"
|
|
|
|
|
2024-04-04 12:03:27 -03:00
|
|
|
#include "pycore_backoff.h"
|
2024-01-28 22:48:48 -04:00
|
|
|
#include "pycore_call.h"
|
|
|
|
#include "pycore_ceval.h"
|
2024-03-29 14:35:43 -03:00
|
|
|
#include "pycore_cell.h"
|
2024-01-28 22:48:48 -04:00
|
|
|
#include "pycore_dict.h"
|
|
|
|
#include "pycore_emscripten_signal.h"
|
|
|
|
#include "pycore_intrinsics.h"
|
|
|
|
#include "pycore_jit.h"
|
|
|
|
#include "pycore_long.h"
|
|
|
|
#include "pycore_opcode_metadata.h"
|
|
|
|
#include "pycore_opcode_utils.h"
|
2024-02-29 12:11:28 -04:00
|
|
|
#include "pycore_optimizer.h"
|
2024-04-19 18:47:42 -03:00
|
|
|
#include "pycore_pyatomic_ft_wrappers.h"
|
2024-01-28 22:48:48 -04:00
|
|
|
#include "pycore_range.h"
|
|
|
|
#include "pycore_setobject.h"
|
|
|
|
#include "pycore_sliceobject.h"
|
2024-03-07 12:21:21 -04:00
|
|
|
#include "pycore_descrobject.h"
|
2024-01-28 22:48:48 -04:00
|
|
|
|
|
|
|
#include "ceval_macros.h"
|
|
|
|
|
|
|
|
#undef CURRENT_OPARG
|
|
|
|
#define CURRENT_OPARG() (_oparg)
|
|
|
|
|
|
|
|
#undef CURRENT_OPERAND
|
|
|
|
#define CURRENT_OPERAND() (_operand)
|
|
|
|
|
|
|
|
#undef DEOPT_IF
|
|
|
|
#define DEOPT_IF(COND, INSTNAME) \
|
|
|
|
do { \
|
|
|
|
if ((COND)) { \
|
|
|
|
goto deoptimize; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#undef ENABLE_SPECIALIZATION
|
|
|
|
#define ENABLE_SPECIALIZATION (0)
|
|
|
|
|
|
|
|
#undef GOTO_ERROR
|
|
|
|
#define GOTO_ERROR(LABEL) \
|
|
|
|
do { \
|
|
|
|
goto LABEL ## _tier_two; \
|
|
|
|
} while (0)
|
|
|
|
|
2024-02-20 05:39:55 -04:00
|
|
|
#undef GOTO_TIER_TWO
|
|
|
|
#define GOTO_TIER_TWO(EXECUTOR) \
|
|
|
|
do { \
|
2024-03-28 19:23:08 -03:00
|
|
|
OPT_STAT_INC(traces_executed); \
|
2024-02-20 05:39:55 -04:00
|
|
|
__attribute__((musttail)) \
|
|
|
|
return ((jit_func)((EXECUTOR)->jit_code))(frame, stack_pointer, tstate); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#undef GOTO_TIER_ONE
|
|
|
|
#define GOTO_TIER_ONE(TARGET) \
|
|
|
|
do { \
|
|
|
|
_PyFrame_SetStackPointer(frame, stack_pointer); \
|
|
|
|
return TARGET; \
|
|
|
|
} while (0)
|
|
|
|
|
2024-01-28 22:48:48 -04:00
|
|
|
#undef LOAD_IP
|
|
|
|
#define LOAD_IP(UNUSED) \
|
|
|
|
do { \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define PATCH_VALUE(TYPE, NAME, ALIAS) \
|
2024-02-29 12:11:28 -04:00
|
|
|
PyAPI_DATA(void) ALIAS; \
|
2024-01-28 22:48:48 -04:00
|
|
|
TYPE NAME = (TYPE)(uint64_t)&ALIAS;
|
|
|
|
|
|
|
|
#define PATCH_JUMP(ALIAS) \
|
2024-03-26 06:35:11 -03:00
|
|
|
do { \
|
2024-02-29 12:11:28 -04:00
|
|
|
PyAPI_DATA(void) ALIAS; \
|
2024-01-28 22:48:48 -04:00
|
|
|
__attribute__((musttail)) \
|
2024-03-26 06:35:11 -03:00
|
|
|
return ((jit_func)&ALIAS)(frame, stack_pointer, tstate); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#undef JUMP_TO_JUMP_TARGET
|
|
|
|
#define JUMP_TO_JUMP_TARGET() PATCH_JUMP(_JIT_JUMP_TARGET)
|
|
|
|
|
|
|
|
#undef JUMP_TO_ERROR
|
|
|
|
#define JUMP_TO_ERROR() PATCH_JUMP(_JIT_ERROR_TARGET)
|
2024-01-28 22:48:48 -04:00
|
|
|
|
|
|
|
_Py_CODEUNIT *
|
|
|
|
_JIT_ENTRY(_PyInterpreterFrame *frame, PyObject **stack_pointer, PyThreadState *tstate)
|
|
|
|
{
|
|
|
|
// Locals that the instruction implementations expect to exist:
|
|
|
|
PATCH_VALUE(_PyExecutorObject *, current_executor, _JIT_EXECUTOR)
|
|
|
|
int oparg;
|
2024-04-04 19:49:18 -03:00
|
|
|
int uopcode = _JIT_OPCODE;
|
2024-04-26 14:08:50 -03:00
|
|
|
_Py_CODEUNIT *next_instr;
|
2024-01-28 22:48:48 -04:00
|
|
|
// Other stuff we need handy:
|
|
|
|
PATCH_VALUE(uint16_t, _oparg, _JIT_OPARG)
|
2024-04-06 12:26:43 -03:00
|
|
|
#if SIZEOF_VOID_P == 8
|
2024-01-28 22:48:48 -04:00
|
|
|
PATCH_VALUE(uint64_t, _operand, _JIT_OPERAND)
|
2024-04-06 12:26:43 -03:00
|
|
|
#else
|
|
|
|
assert(SIZEOF_VOID_P == 4);
|
|
|
|
PATCH_VALUE(uint32_t, _operand_hi, _JIT_OPERAND_HI)
|
|
|
|
PATCH_VALUE(uint32_t, _operand_lo, _JIT_OPERAND_LO)
|
|
|
|
uint64_t _operand = ((uint64_t)_operand_hi << 32) | _operand_lo;
|
|
|
|
#endif
|
2024-01-28 22:48:48 -04:00
|
|
|
PATCH_VALUE(uint32_t, _target, _JIT_TARGET)
|
2024-03-26 06:35:11 -03:00
|
|
|
PATCH_VALUE(uint16_t, _exit_index, _JIT_EXIT_INDEX)
|
2024-03-28 19:23:08 -03:00
|
|
|
|
|
|
|
OPT_STAT_INC(uops_executed);
|
2024-04-04 19:49:18 -03:00
|
|
|
UOP_STAT_INC(uopcode, execution_count);
|
2024-03-28 19:23:08 -03:00
|
|
|
|
2024-01-28 22:48:48 -04:00
|
|
|
// The actual instruction definitions (only one will be used):
|
2024-04-04 19:49:18 -03:00
|
|
|
if (uopcode == _JUMP_TO_TOP) {
|
2024-01-28 22:48:48 -04:00
|
|
|
CHECK_EVAL_BREAKER();
|
|
|
|
PATCH_JUMP(_JIT_TOP);
|
|
|
|
}
|
2024-04-04 19:49:18 -03:00
|
|
|
switch (uopcode) {
|
2024-01-28 22:48:48 -04:00
|
|
|
#include "executor_cases.c.h"
|
|
|
|
default:
|
|
|
|
Py_UNREACHABLE();
|
|
|
|
}
|
|
|
|
PATCH_JUMP(_JIT_CONTINUE);
|
|
|
|
// Labels that the instruction implementations expect to exist:
|
2024-03-26 06:35:11 -03:00
|
|
|
|
2024-01-28 22:48:48 -04:00
|
|
|
error_tier_two:
|
2024-02-20 05:39:55 -04:00
|
|
|
tstate->previous_executor = (PyObject *)current_executor;
|
|
|
|
GOTO_TIER_ONE(NULL);
|
2024-03-26 06:35:11 -03:00
|
|
|
exit_to_tier1:
|
2024-02-20 05:39:55 -04:00
|
|
|
tstate->previous_executor = (PyObject *)current_executor;
|
|
|
|
GOTO_TIER_ONE(_PyCode_CODE(_PyFrame_GetCode(frame)) + _target);
|
2024-04-26 14:08:50 -03:00
|
|
|
exit_to_tier1_dynamic:
|
|
|
|
tstate->previous_executor = (PyObject *)current_executor;
|
|
|
|
GOTO_TIER_ONE(frame->instr_ptr);
|
2024-03-26 06:35:11 -03:00
|
|
|
exit_to_trace:
|
2024-02-20 05:39:55 -04:00
|
|
|
{
|
2024-03-26 06:35:11 -03:00
|
|
|
_PyExitData *exit = ¤t_executor->exits[_exit_index];
|
2024-02-20 05:39:55 -04:00
|
|
|
Py_INCREF(exit->executor);
|
|
|
|
tstate->previous_executor = (PyObject *)current_executor;
|
|
|
|
GOTO_TIER_TWO(exit->executor);
|
|
|
|
}
|
2024-01-28 22:48:48 -04:00
|
|
|
}
|