Skip to content

Commit

Permalink
GH-113464: Remove the extra jump via _SIDE_EXIT in _EXIT_TRACE (G…
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon authored May 4, 2024
1 parent 0b7814e commit da2cfc4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 53 deletions.
37 changes: 18 additions & 19 deletions Include/internal/pycore_uop_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4133,7 +4133,7 @@ dummy_func(
}

tier2 op(_EXIT_TRACE, (--)) {
EXIT_IF(1);
EXIT_TO_TRACE();
}

tier2 op(_CHECK_VALIDITY, (--)) {
Expand Down Expand Up @@ -4266,10 +4266,6 @@ dummy_func(
EXIT_TO_TIER1();
}

tier2 op(_SIDE_EXIT, (--)) {
EXIT_TO_TRACE();
}

tier2 op(_ERROR_POP_N, (target/2, unused[oparg] --)) {
frame->instr_ptr = ((_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive) + target;
SYNC_SP();
Expand Down
10 changes: 1 addition & 9 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ count_exits(_PyUOpInstruction *buffer, int length)
int exit_count = 0;
for (int i = 0; i < length; i++) {
int opcode = buffer[i].opcode;
if (opcode == _SIDE_EXIT || opcode == _DYNAMIC_EXIT) {
if (opcode == _EXIT_TRACE || opcode == _DYNAMIC_EXIT) {
exit_count++;
}
}
Expand Down Expand Up @@ -1021,7 +1021,7 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length)
int32_t target = (int32_t)uop_get_target(inst);
if (_PyUop_Flags[opcode] & (HAS_EXIT_FLAG | HAS_DEOPT_FLAG)) {
uint16_t exit_op = (_PyUop_Flags[opcode] & HAS_EXIT_FLAG) ?
_SIDE_EXIT : _DEOPT;
_EXIT_TRACE : _DEOPT;
int32_t jump_target = target;
if (is_for_iter_test[opcode]) {
/* Target the POP_TOP immediately after the END_FOR,
Expand Down Expand Up @@ -1112,7 +1112,7 @@ sanity_check(_PyExecutorObject *executor)
CHECK(target_unused(opcode));
break;
case UOP_FORMAT_EXIT:
CHECK(opcode == _SIDE_EXIT);
CHECK(opcode == _EXIT_TRACE);
CHECK(inst->exit_index < executor->exit_count);
break;
case UOP_FORMAT_JUMP:
Expand All @@ -1138,9 +1138,9 @@ sanity_check(_PyExecutorObject *executor)
uint16_t opcode = inst->opcode;
CHECK(
opcode == _DEOPT ||
opcode == _SIDE_EXIT ||
opcode == _EXIT_TRACE ||
opcode == _ERROR_POP_N);
if (opcode == _SIDE_EXIT) {
if (opcode == _EXIT_TRACE) {
CHECK(inst->format == UOP_FORMAT_EXIT);
}
}
Expand Down Expand Up @@ -1178,7 +1178,7 @@ make_executor_from_uops(_PyUOpInstruction *buffer, int length, const _PyBloomFil
dest--;
*dest = buffer[i];
assert(opcode != _POP_JUMP_IF_FALSE && opcode != _POP_JUMP_IF_TRUE);
if (opcode == _SIDE_EXIT) {
if (opcode == _EXIT_TRACE) {
executor->exits[next_exit].target = buffer[i].target;
dest->exit_index = next_exit;
dest->format = UOP_FORMAT_EXIT;
Expand Down Expand Up @@ -1398,14 +1398,13 @@ counter_optimize(
return 0;
}
_Py_CODEUNIT *target = instr + 1 + _PyOpcode_Caches[JUMP_BACKWARD] - oparg;
_PyUOpInstruction buffer[5] = {
{ .opcode = _START_EXECUTOR, .jump_target = 4, .format=UOP_FORMAT_JUMP },
_PyUOpInstruction buffer[4] = {
{ .opcode = _START_EXECUTOR, .jump_target = 3, .format=UOP_FORMAT_JUMP },
{ .opcode = _LOAD_CONST_INLINE_BORROW, .operand = (uintptr_t)self },
{ .opcode = _INTERNAL_INCREMENT_OPT_COUNTER },
{ .opcode = _EXIT_TRACE, .jump_target = 4, .format=UOP_FORMAT_JUMP },
{ .opcode = _SIDE_EXIT, .target = (uint32_t)(target - _PyCode_CODE(code)), .format=UOP_FORMAT_TARGET }
{ .opcode = _EXIT_TRACE, .target = (uint32_t)(target - _PyCode_CODE(code)), .format=UOP_FORMAT_TARGET }
};
_PyExecutorObject *executor = make_executor_from_uops(buffer, 5, &EMPTY_FILTER);
_PyExecutorObject *executor = make_executor_from_uops(buffer, 4, &EMPTY_FILTER);
if (executor == NULL) {
return -1;
}
Expand Down
4 changes: 0 additions & 4 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da2cfc4

Please sign in to comment.