mirror of https://github.com/python/cpython
GH-113464: Remove the extra jump via `_SIDE_EXIT` in `_EXIT_TRACE` (GH-118545)
This commit is contained in:
parent
0b7814e0b6
commit
da2cfc4cb6
|
@ -240,33 +240,32 @@ extern "C" {
|
|||
#define _SET_ADD SET_ADD
|
||||
#define _SET_FUNCTION_ATTRIBUTE SET_FUNCTION_ATTRIBUTE
|
||||
#define _SET_UPDATE SET_UPDATE
|
||||
#define _SIDE_EXIT 429
|
||||
#define _START_EXECUTOR 430
|
||||
#define _STORE_ATTR 431
|
||||
#define _STORE_ATTR_INSTANCE_VALUE 432
|
||||
#define _STORE_ATTR_SLOT 433
|
||||
#define _START_EXECUTOR 429
|
||||
#define _STORE_ATTR 430
|
||||
#define _STORE_ATTR_INSTANCE_VALUE 431
|
||||
#define _STORE_ATTR_SLOT 432
|
||||
#define _STORE_ATTR_WITH_HINT STORE_ATTR_WITH_HINT
|
||||
#define _STORE_DEREF STORE_DEREF
|
||||
#define _STORE_FAST 434
|
||||
#define _STORE_FAST_0 435
|
||||
#define _STORE_FAST_1 436
|
||||
#define _STORE_FAST_2 437
|
||||
#define _STORE_FAST_3 438
|
||||
#define _STORE_FAST_4 439
|
||||
#define _STORE_FAST_5 440
|
||||
#define _STORE_FAST_6 441
|
||||
#define _STORE_FAST_7 442
|
||||
#define _STORE_FAST 433
|
||||
#define _STORE_FAST_0 434
|
||||
#define _STORE_FAST_1 435
|
||||
#define _STORE_FAST_2 436
|
||||
#define _STORE_FAST_3 437
|
||||
#define _STORE_FAST_4 438
|
||||
#define _STORE_FAST_5 439
|
||||
#define _STORE_FAST_6 440
|
||||
#define _STORE_FAST_7 441
|
||||
#define _STORE_FAST_LOAD_FAST STORE_FAST_LOAD_FAST
|
||||
#define _STORE_FAST_STORE_FAST STORE_FAST_STORE_FAST
|
||||
#define _STORE_GLOBAL STORE_GLOBAL
|
||||
#define _STORE_NAME STORE_NAME
|
||||
#define _STORE_SLICE STORE_SLICE
|
||||
#define _STORE_SUBSCR 443
|
||||
#define _STORE_SUBSCR 442
|
||||
#define _STORE_SUBSCR_DICT STORE_SUBSCR_DICT
|
||||
#define _STORE_SUBSCR_LIST_INT STORE_SUBSCR_LIST_INT
|
||||
#define _SWAP SWAP
|
||||
#define _TIER2_RESUME_CHECK 444
|
||||
#define _TO_BOOL 445
|
||||
#define _TIER2_RESUME_CHECK 443
|
||||
#define _TO_BOOL 444
|
||||
#define _TO_BOOL_BOOL TO_BOOL_BOOL
|
||||
#define _TO_BOOL_INT TO_BOOL_INT
|
||||
#define _TO_BOOL_LIST TO_BOOL_LIST
|
||||
|
@ -276,13 +275,13 @@ extern "C" {
|
|||
#define _UNARY_NEGATIVE UNARY_NEGATIVE
|
||||
#define _UNARY_NOT UNARY_NOT
|
||||
#define _UNPACK_EX UNPACK_EX
|
||||
#define _UNPACK_SEQUENCE 446
|
||||
#define _UNPACK_SEQUENCE 445
|
||||
#define _UNPACK_SEQUENCE_LIST UNPACK_SEQUENCE_LIST
|
||||
#define _UNPACK_SEQUENCE_TUPLE UNPACK_SEQUENCE_TUPLE
|
||||
#define _UNPACK_SEQUENCE_TWO_TUPLE UNPACK_SEQUENCE_TWO_TUPLE
|
||||
#define _WITH_EXCEPT_START WITH_EXCEPT_START
|
||||
#define _YIELD_VALUE YIELD_VALUE
|
||||
#define MAX_UOP_ID 446
|
||||
#define MAX_UOP_ID 445
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = {
|
|||
[_SET_IP] = 0,
|
||||
[_CHECK_STACK_SPACE_OPERAND] = HAS_DEOPT_FLAG,
|
||||
[_SAVE_RETURN_OFFSET] = HAS_ARG_FLAG,
|
||||
[_EXIT_TRACE] = HAS_EXIT_FLAG,
|
||||
[_EXIT_TRACE] = 0,
|
||||
[_CHECK_VALIDITY] = HAS_DEOPT_FLAG,
|
||||
[_LOAD_CONST_INLINE] = HAS_PURE_FLAG,
|
||||
[_LOAD_CONST_INLINE_BORROW] = HAS_PURE_FLAG,
|
||||
|
@ -252,7 +252,6 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = {
|
|||
[_FATAL_ERROR] = 0,
|
||||
[_CHECK_VALIDITY_AND_SET_IP] = HAS_DEOPT_FLAG,
|
||||
[_DEOPT] = 0,
|
||||
[_SIDE_EXIT] = 0,
|
||||
[_ERROR_POP_N] = HAS_ARG_FLAG,
|
||||
[_TIER2_RESUME_CHECK] = HAS_DEOPT_FLAG,
|
||||
};
|
||||
|
@ -459,7 +458,6 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = {
|
|||
[_SET_FUNCTION_ATTRIBUTE] = "_SET_FUNCTION_ATTRIBUTE",
|
||||
[_SET_IP] = "_SET_IP",
|
||||
[_SET_UPDATE] = "_SET_UPDATE",
|
||||
[_SIDE_EXIT] = "_SIDE_EXIT",
|
||||
[_START_EXECUTOR] = "_START_EXECUTOR",
|
||||
[_STORE_ATTR] = "_STORE_ATTR",
|
||||
[_STORE_ATTR_INSTANCE_VALUE] = "_STORE_ATTR_INSTANCE_VALUE",
|
||||
|
@ -970,8 +968,6 @@ int _PyUop_num_popped(int opcode, int oparg)
|
|||
return 0;
|
||||
case _DEOPT:
|
||||
return 0;
|
||||
case _SIDE_EXIT:
|
||||
return 0;
|
||||
case _ERROR_POP_N:
|
||||
return oparg;
|
||||
case _TIER2_RESUME_CHECK:
|
||||
|
|
|
@ -4133,7 +4133,7 @@ dummy_func(
|
|||
}
|
||||
|
||||
tier2 op(_EXIT_TRACE, (--)) {
|
||||
EXIT_IF(1);
|
||||
EXIT_TO_TRACE();
|
||||
}
|
||||
|
||||
tier2 op(_CHECK_VALIDITY, (--)) {
|
||||
|
@ -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();
|
||||
|
|
|
@ -4127,10 +4127,7 @@
|
|||
}
|
||||
|
||||
case _EXIT_TRACE: {
|
||||
if (1) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
EXIT_TO_TRACE();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -4319,11 +4316,6 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _SIDE_EXIT: {
|
||||
EXIT_TO_TRACE();
|
||||
break;
|
||||
}
|
||||
|
||||
case _ERROR_POP_N: {
|
||||
oparg = CURRENT_OPARG();
|
||||
uint32_t target = (uint32_t)CURRENT_OPERAND();
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -2140,10 +2140,6 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _SIDE_EXIT: {
|
||||
break;
|
||||
}
|
||||
|
||||
case _ERROR_POP_N: {
|
||||
stack_pointer += -oparg;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue