mirror of
https://github.com/python/cpython.git
synced 2025-08-23 18:24:46 +00:00
gh-120619: Strength reduce function guards, support 2-operand uop forms (GH-124846)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
parent
f8276bf5f3
commit
6293d00e72
17 changed files with 379 additions and 270 deletions
|
@ -288,13 +288,13 @@ _PyUOpPrint(const _PyUOpInstruction *uop)
|
|||
printf(" (%d, target=%d, operand=%#" PRIx64,
|
||||
uop->oparg,
|
||||
uop->target,
|
||||
(uint64_t)uop->operand);
|
||||
(uint64_t)uop->operand0);
|
||||
break;
|
||||
case UOP_FORMAT_JUMP:
|
||||
printf(" (%d, jump_target=%d, operand=%#" PRIx64,
|
||||
uop->oparg,
|
||||
uop->jump_target,
|
||||
(uint64_t)uop->operand);
|
||||
(uint64_t)uop->operand0);
|
||||
break;
|
||||
default:
|
||||
printf(" (%d, Unknown format)", uop->oparg);
|
||||
|
@ -340,7 +340,7 @@ uop_item(_PyExecutorObject *self, Py_ssize_t index)
|
|||
Py_DECREF(oname);
|
||||
return NULL;
|
||||
}
|
||||
PyObject *operand = PyLong_FromUnsignedLongLong(self->trace[index].operand);
|
||||
PyObject *operand = PyLong_FromUnsignedLongLong(self->trace[index].operand0);
|
||||
if (operand == NULL) {
|
||||
Py_DECREF(target);
|
||||
Py_DECREF(oparg);
|
||||
|
@ -463,7 +463,7 @@ add_to_trace(
|
|||
trace[trace_length].format = UOP_FORMAT_TARGET;
|
||||
trace[trace_length].target = target;
|
||||
trace[trace_length].oparg = oparg;
|
||||
trace[trace_length].operand = operand;
|
||||
trace[trace_length].operand0 = operand;
|
||||
return trace_length + 1;
|
||||
}
|
||||
|
||||
|
@ -970,7 +970,7 @@ static void make_exit(_PyUOpInstruction *inst, int opcode, int target)
|
|||
{
|
||||
inst->opcode = opcode;
|
||||
inst->oparg = 0;
|
||||
inst->operand = 0;
|
||||
inst->operand0 = 0;
|
||||
inst->format = UOP_FORMAT_TARGET;
|
||||
inst->target = target;
|
||||
}
|
||||
|
@ -1033,7 +1033,7 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length)
|
|||
current_error_target = target;
|
||||
make_exit(&buffer[next_spare], _ERROR_POP_N, 0);
|
||||
buffer[next_spare].oparg = popped;
|
||||
buffer[next_spare].operand = target;
|
||||
buffer[next_spare].operand0 = target;
|
||||
next_spare++;
|
||||
}
|
||||
buffer[i].error_target = current_error;
|
||||
|
@ -1150,7 +1150,7 @@ make_executor_from_uops(_PyUOpInstruction *buffer, int length, const _PyBloomFil
|
|||
int next_exit = exit_count-1;
|
||||
_PyUOpInstruction *dest = (_PyUOpInstruction *)&executor->trace[length];
|
||||
assert(buffer[0].opcode == _START_EXECUTOR);
|
||||
buffer[0].operand = (uint64_t)executor;
|
||||
buffer[0].operand0 = (uint64_t)executor;
|
||||
for (int i = length-1; i >= 0; i--) {
|
||||
int opcode = buffer[i].opcode;
|
||||
dest--;
|
||||
|
@ -1159,13 +1159,13 @@ make_executor_from_uops(_PyUOpInstruction *buffer, int length, const _PyBloomFil
|
|||
if (opcode == _EXIT_TRACE) {
|
||||
_PyExitData *exit = &executor->exits[next_exit];
|
||||
exit->target = buffer[i].target;
|
||||
dest->operand = (uint64_t)exit;
|
||||
dest->operand0 = (uint64_t)exit;
|
||||
next_exit--;
|
||||
}
|
||||
if (opcode == _DYNAMIC_EXIT) {
|
||||
_PyExitData *exit = &executor->exits[next_exit];
|
||||
exit->target = 0;
|
||||
dest->operand = (uint64_t)exit;
|
||||
dest->operand0 = (uint64_t)exit;
|
||||
next_exit--;
|
||||
}
|
||||
}
|
||||
|
@ -1312,7 +1312,7 @@ _PyOptimizer_NewUOpOptimizer(void)
|
|||
static void
|
||||
counter_dealloc(_PyExecutorObject *self) {
|
||||
/* The optimizer is the operand of the second uop. */
|
||||
PyObject *opt = (PyObject *)self->trace[1].operand;
|
||||
PyObject *opt = (PyObject *)self->trace[1].operand0;
|
||||
Py_DECREF(opt);
|
||||
uop_dealloc(self);
|
||||
}
|
||||
|
@ -1352,7 +1352,7 @@ counter_optimize(
|
|||
_Py_CODEUNIT *target = instr + 1 + _PyOpcode_Caches[JUMP_BACKWARD] - oparg;
|
||||
_PyUOpInstruction buffer[4] = {
|
||||
{ .opcode = _START_EXECUTOR, .jump_target = 3, .format=UOP_FORMAT_JUMP },
|
||||
{ .opcode = _LOAD_CONST_INLINE, .operand = (uintptr_t)self },
|
||||
{ .opcode = _LOAD_CONST_INLINE, .operand0 = (uintptr_t)self },
|
||||
{ .opcode = _INTERNAL_INCREMENT_OPT_COUNTER },
|
||||
{ .opcode = _EXIT_TRACE, .target = (uint32_t)(target - _PyCode_CODE(code)), .format=UOP_FORMAT_TARGET }
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue