gh-109214: Rename SAVE_IP to _SET_IP, and similar (#109285)

* Rename SAVE_IP to _SET_IP
* Rename EXIT_TRACE to _EXIT_TRACE
* Rename SAVE_CURRENT_IP to _SAVE_CURRENT_IP
* Rename INSERT to _INSERT (This is for Ken Jin's abstract interpreter)
* Rename IS_NONE to _IS_NONE
* Rename JUMP_TO_TOP to _JUMP_TO_TOP
This commit is contained in:
Guido van Rossum 2023-09-11 15:39:19 -07:00 committed by GitHub
parent 1ee50e2a78
commit fbaf77eb9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 117 additions and 117 deletions

View file

@ -25,8 +25,8 @@
((OP) == POP_BLOCK) || \ ((OP) == POP_BLOCK) || \
0) 0)
#define EXIT_TRACE 300 #define _EXIT_TRACE 300
#define SAVE_IP 301 #define _SET_IP 301
#define _GUARD_BOTH_INT 302 #define _GUARD_BOTH_INT 302
#define _BINARY_OP_MULTIPLY_INT 303 #define _BINARY_OP_MULTIPLY_INT 303
#define _BINARY_OP_ADD_INT 304 #define _BINARY_OP_ADD_INT 304
@ -46,7 +46,7 @@
#define _GUARD_TYPE_VERSION 318 #define _GUARD_TYPE_VERSION 318
#define _CHECK_MANAGED_OBJECT_HAS_VALUES 319 #define _CHECK_MANAGED_OBJECT_HAS_VALUES 319
#define _LOAD_ATTR_INSTANCE_VALUE 320 #define _LOAD_ATTR_INSTANCE_VALUE 320
#define IS_NONE 321 #define _IS_NONE 321
#define _ITER_CHECK_LIST 322 #define _ITER_CHECK_LIST 322
#define _ITER_JUMP_LIST 323 #define _ITER_JUMP_LIST 323
#define _IS_ITER_EXHAUSTED_LIST 324 #define _IS_ITER_EXHAUSTED_LIST 324
@ -68,9 +68,9 @@
#define _PUSH_FRAME 340 #define _PUSH_FRAME 340
#define _POP_JUMP_IF_FALSE 341 #define _POP_JUMP_IF_FALSE 341
#define _POP_JUMP_IF_TRUE 342 #define _POP_JUMP_IF_TRUE 342
#define JUMP_TO_TOP 343 #define _JUMP_TO_TOP 343
#define SAVE_CURRENT_IP 344 #define _SAVE_CURRENT_IP 344
#define INSERT 345 #define _INSERT 345
extern int _PyOpcode_num_popped(int opcode, int oparg, bool jump); extern int _PyOpcode_num_popped(int opcode, int oparg, bool jump);
#ifdef NEED_OPCODE_METADATA #ifdef NEED_OPCODE_METADATA
@ -402,7 +402,7 @@ int _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
return 1; return 1;
case POP_JUMP_IF_TRUE: case POP_JUMP_IF_TRUE:
return 1; return 1;
case IS_NONE: case _IS_NONE:
return 1; return 1;
case POP_JUMP_IF_NONE: case POP_JUMP_IF_NONE:
return 1; return 1;
@ -586,15 +586,15 @@ int _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
return 1; return 1;
case _POP_JUMP_IF_TRUE: case _POP_JUMP_IF_TRUE:
return 1; return 1;
case JUMP_TO_TOP: case _JUMP_TO_TOP:
return 0; return 0;
case SAVE_IP: case _SET_IP:
return 0; return 0;
case SAVE_CURRENT_IP: case _SAVE_CURRENT_IP:
return 0; return 0;
case EXIT_TRACE: case _EXIT_TRACE:
return 0; return 0;
case INSERT: case _INSERT:
return oparg + 1; return oparg + 1;
default: default:
return -1; return -1;
@ -932,7 +932,7 @@ int _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
return 0; return 0;
case POP_JUMP_IF_TRUE: case POP_JUMP_IF_TRUE:
return 0; return 0;
case IS_NONE: case _IS_NONE:
return 1; return 1;
case POP_JUMP_IF_NONE: case POP_JUMP_IF_NONE:
return 0; return 0;
@ -1116,15 +1116,15 @@ int _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
return 0; return 0;
case _POP_JUMP_IF_TRUE: case _POP_JUMP_IF_TRUE:
return 0; return 0;
case JUMP_TO_TOP: case _JUMP_TO_TOP:
return 0; return 0;
case SAVE_IP: case _SET_IP:
return 0; return 0;
case SAVE_CURRENT_IP: case _SAVE_CURRENT_IP:
return 0; return 0;
case EXIT_TRACE: case _EXIT_TRACE:
return 0; return 0;
case INSERT: case _INSERT:
return oparg + 1; return oparg + 1;
default: default:
return -1; return -1;
@ -1186,7 +1186,7 @@ struct opcode_macro_expansion {
#define OPARG_CACHE_4 4 #define OPARG_CACHE_4 4
#define OPARG_TOP 5 #define OPARG_TOP 5
#define OPARG_BOTTOM 6 #define OPARG_BOTTOM 6
#define OPARG_SAVE_IP 7 #define OPARG_SET_IP 7
#define OPCODE_METADATA_FMT(OP) (_PyOpcode_opcode_metadata[(OP)].instr_format) #define OPCODE_METADATA_FMT(OP) (_PyOpcode_opcode_metadata[(OP)].instr_format)
#define SAME_OPCODE_METADATA(OP1, OP2) \ #define SAME_OPCODE_METADATA(OP1, OP2) \
@ -1363,7 +1363,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[OPCODE_METADATA_SIZE] = {
[ENTER_EXECUTOR] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG | HAS_EVAL_BREAK_FLAG | HAS_ERROR_FLAG }, [ENTER_EXECUTOR] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG | HAS_EVAL_BREAK_FLAG | HAS_ERROR_FLAG },
[POP_JUMP_IF_FALSE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG }, [POP_JUMP_IF_FALSE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG },
[POP_JUMP_IF_TRUE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG }, [POP_JUMP_IF_TRUE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG },
[IS_NONE] = { true, INSTR_FMT_IX, 0 }, [_IS_NONE] = { true, INSTR_FMT_IX, 0 },
[POP_JUMP_IF_NONE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG }, [POP_JUMP_IF_NONE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG },
[POP_JUMP_IF_NOT_NONE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG }, [POP_JUMP_IF_NOT_NONE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_JUMP_FLAG },
[JUMP_BACKWARD_NO_INTERRUPT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG }, [JUMP_BACKWARD_NO_INTERRUPT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG },
@ -1458,11 +1458,11 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[OPCODE_METADATA_SIZE] = {
[RESERVED] = { true, INSTR_FMT_IX, 0 }, [RESERVED] = { true, INSTR_FMT_IX, 0 },
[_POP_JUMP_IF_FALSE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG }, [_POP_JUMP_IF_FALSE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
[_POP_JUMP_IF_TRUE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG }, [_POP_JUMP_IF_TRUE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
[JUMP_TO_TOP] = { true, INSTR_FMT_IX, HAS_EVAL_BREAK_FLAG }, [_JUMP_TO_TOP] = { true, INSTR_FMT_IX, HAS_EVAL_BREAK_FLAG },
[SAVE_IP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG }, [_SET_IP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
[SAVE_CURRENT_IP] = { true, INSTR_FMT_IX, 0 }, [_SAVE_CURRENT_IP] = { true, INSTR_FMT_IX, 0 },
[EXIT_TRACE] = { true, INSTR_FMT_IX, 0 }, [_EXIT_TRACE] = { true, INSTR_FMT_IX, 0 },
[INSERT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG }, [_INSERT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
}; };
#endif // NEED_OPCODE_METADATA #endif // NEED_OPCODE_METADATA
@ -1515,8 +1515,8 @@ const struct opcode_macro_expansion _PyOpcode_macro_expansion[OPCODE_MACRO_EXPAN
[DELETE_SUBSCR] = { .nuops = 1, .uops = { { DELETE_SUBSCR, 0, 0 } } }, [DELETE_SUBSCR] = { .nuops = 1, .uops = { { DELETE_SUBSCR, 0, 0 } } },
[CALL_INTRINSIC_1] = { .nuops = 1, .uops = { { CALL_INTRINSIC_1, 0, 0 } } }, [CALL_INTRINSIC_1] = { .nuops = 1, .uops = { { CALL_INTRINSIC_1, 0, 0 } } },
[CALL_INTRINSIC_2] = { .nuops = 1, .uops = { { CALL_INTRINSIC_2, 0, 0 } } }, [CALL_INTRINSIC_2] = { .nuops = 1, .uops = { { CALL_INTRINSIC_2, 0, 0 } } },
[RETURN_VALUE] = { .nuops = 3, .uops = { { SAVE_IP, 7, 0 }, { SAVE_CURRENT_IP, 0, 0 }, { _POP_FRAME, 0, 0 } } }, [RETURN_VALUE] = { .nuops = 3, .uops = { { _SET_IP, 7, 0 }, { _SAVE_CURRENT_IP, 0, 0 }, { _POP_FRAME, 0, 0 } } },
[RETURN_CONST] = { .nuops = 4, .uops = { { LOAD_CONST, 0, 0 }, { SAVE_IP, 7, 0 }, { SAVE_CURRENT_IP, 0, 0 }, { _POP_FRAME, 0, 0 } } }, [RETURN_CONST] = { .nuops = 4, .uops = { { LOAD_CONST, 0, 0 }, { _SET_IP, 7, 0 }, { _SAVE_CURRENT_IP, 0, 0 }, { _POP_FRAME, 0, 0 } } },
[GET_AITER] = { .nuops = 1, .uops = { { GET_AITER, 0, 0 } } }, [GET_AITER] = { .nuops = 1, .uops = { { GET_AITER, 0, 0 } } },
[GET_ANEXT] = { .nuops = 1, .uops = { { GET_ANEXT, 0, 0 } } }, [GET_ANEXT] = { .nuops = 1, .uops = { { GET_ANEXT, 0, 0 } } },
[GET_AWAITABLE] = { .nuops = 1, .uops = { { GET_AWAITABLE, 0, 0 } } }, [GET_AWAITABLE] = { .nuops = 1, .uops = { { GET_AWAITABLE, 0, 0 } } },
@ -1579,8 +1579,8 @@ const struct opcode_macro_expansion _PyOpcode_macro_expansion[OPCODE_MACRO_EXPAN
[GET_YIELD_FROM_ITER] = { .nuops = 1, .uops = { { GET_YIELD_FROM_ITER, 0, 0 } } }, [GET_YIELD_FROM_ITER] = { .nuops = 1, .uops = { { GET_YIELD_FROM_ITER, 0, 0 } } },
[WITH_EXCEPT_START] = { .nuops = 1, .uops = { { WITH_EXCEPT_START, 0, 0 } } }, [WITH_EXCEPT_START] = { .nuops = 1, .uops = { { WITH_EXCEPT_START, 0, 0 } } },
[PUSH_EXC_INFO] = { .nuops = 1, .uops = { { PUSH_EXC_INFO, 0, 0 } } }, [PUSH_EXC_INFO] = { .nuops = 1, .uops = { { PUSH_EXC_INFO, 0, 0 } } },
[CALL_BOUND_METHOD_EXACT_ARGS] = { .nuops = 9, .uops = { { _CHECK_PEP_523, 0, 0 }, { _CHECK_CALL_BOUND_METHOD_EXACT_ARGS, 0, 0 }, { _INIT_CALL_BOUND_METHOD_EXACT_ARGS, 0, 0 }, { _CHECK_FUNCTION_EXACT_ARGS, 2, 1 }, { _CHECK_STACK_SPACE, 0, 0 }, { _INIT_CALL_PY_EXACT_ARGS, 0, 0 }, { SAVE_IP, 7, 3 }, { SAVE_CURRENT_IP, 0, 0 }, { _PUSH_FRAME, 0, 0 } } }, [CALL_BOUND_METHOD_EXACT_ARGS] = { .nuops = 9, .uops = { { _CHECK_PEP_523, 0, 0 }, { _CHECK_CALL_BOUND_METHOD_EXACT_ARGS, 0, 0 }, { _INIT_CALL_BOUND_METHOD_EXACT_ARGS, 0, 0 }, { _CHECK_FUNCTION_EXACT_ARGS, 2, 1 }, { _CHECK_STACK_SPACE, 0, 0 }, { _INIT_CALL_PY_EXACT_ARGS, 0, 0 }, { _SET_IP, 7, 3 }, { _SAVE_CURRENT_IP, 0, 0 }, { _PUSH_FRAME, 0, 0 } } },
[CALL_PY_EXACT_ARGS] = { .nuops = 7, .uops = { { _CHECK_PEP_523, 0, 0 }, { _CHECK_FUNCTION_EXACT_ARGS, 2, 1 }, { _CHECK_STACK_SPACE, 0, 0 }, { _INIT_CALL_PY_EXACT_ARGS, 0, 0 }, { SAVE_IP, 7, 3 }, { SAVE_CURRENT_IP, 0, 0 }, { _PUSH_FRAME, 0, 0 } } }, [CALL_PY_EXACT_ARGS] = { .nuops = 7, .uops = { { _CHECK_PEP_523, 0, 0 }, { _CHECK_FUNCTION_EXACT_ARGS, 2, 1 }, { _CHECK_STACK_SPACE, 0, 0 }, { _INIT_CALL_PY_EXACT_ARGS, 0, 0 }, { _SET_IP, 7, 3 }, { _SAVE_CURRENT_IP, 0, 0 }, { _PUSH_FRAME, 0, 0 } } },
[CALL_NO_KW_TYPE_1] = { .nuops = 1, .uops = { { CALL_NO_KW_TYPE_1, 0, 0 } } }, [CALL_NO_KW_TYPE_1] = { .nuops = 1, .uops = { { CALL_NO_KW_TYPE_1, 0, 0 } } },
[CALL_NO_KW_STR_1] = { .nuops = 1, .uops = { { CALL_NO_KW_STR_1, 0, 0 } } }, [CALL_NO_KW_STR_1] = { .nuops = 1, .uops = { { CALL_NO_KW_STR_1, 0, 0 } } },
[CALL_NO_KW_TUPLE_1] = { .nuops = 1, .uops = { { CALL_NO_KW_TUPLE_1, 0, 0 } } }, [CALL_NO_KW_TUPLE_1] = { .nuops = 1, .uops = { { CALL_NO_KW_TUPLE_1, 0, 0 } } },
@ -1607,8 +1607,8 @@ const struct opcode_macro_expansion _PyOpcode_macro_expansion[OPCODE_MACRO_EXPAN
extern const char * const _PyOpcode_uop_name[OPCODE_UOP_NAME_SIZE]; extern const char * const _PyOpcode_uop_name[OPCODE_UOP_NAME_SIZE];
#ifdef NEED_OPCODE_METADATA #ifdef NEED_OPCODE_METADATA
const char * const _PyOpcode_uop_name[OPCODE_UOP_NAME_SIZE] = { const char * const _PyOpcode_uop_name[OPCODE_UOP_NAME_SIZE] = {
[EXIT_TRACE] = "EXIT_TRACE", [_EXIT_TRACE] = "_EXIT_TRACE",
[SAVE_IP] = "SAVE_IP", [_SET_IP] = "_SET_IP",
[_GUARD_BOTH_INT] = "_GUARD_BOTH_INT", [_GUARD_BOTH_INT] = "_GUARD_BOTH_INT",
[_BINARY_OP_MULTIPLY_INT] = "_BINARY_OP_MULTIPLY_INT", [_BINARY_OP_MULTIPLY_INT] = "_BINARY_OP_MULTIPLY_INT",
[_BINARY_OP_ADD_INT] = "_BINARY_OP_ADD_INT", [_BINARY_OP_ADD_INT] = "_BINARY_OP_ADD_INT",
@ -1628,7 +1628,7 @@ const char * const _PyOpcode_uop_name[OPCODE_UOP_NAME_SIZE] = {
[_GUARD_TYPE_VERSION] = "_GUARD_TYPE_VERSION", [_GUARD_TYPE_VERSION] = "_GUARD_TYPE_VERSION",
[_CHECK_MANAGED_OBJECT_HAS_VALUES] = "_CHECK_MANAGED_OBJECT_HAS_VALUES", [_CHECK_MANAGED_OBJECT_HAS_VALUES] = "_CHECK_MANAGED_OBJECT_HAS_VALUES",
[_LOAD_ATTR_INSTANCE_VALUE] = "_LOAD_ATTR_INSTANCE_VALUE", [_LOAD_ATTR_INSTANCE_VALUE] = "_LOAD_ATTR_INSTANCE_VALUE",
[IS_NONE] = "IS_NONE", [_IS_NONE] = "_IS_NONE",
[_ITER_CHECK_LIST] = "_ITER_CHECK_LIST", [_ITER_CHECK_LIST] = "_ITER_CHECK_LIST",
[_ITER_JUMP_LIST] = "_ITER_JUMP_LIST", [_ITER_JUMP_LIST] = "_ITER_JUMP_LIST",
[_IS_ITER_EXHAUSTED_LIST] = "_IS_ITER_EXHAUSTED_LIST", [_IS_ITER_EXHAUSTED_LIST] = "_IS_ITER_EXHAUSTED_LIST",
@ -1650,9 +1650,9 @@ const char * const _PyOpcode_uop_name[OPCODE_UOP_NAME_SIZE] = {
[_PUSH_FRAME] = "_PUSH_FRAME", [_PUSH_FRAME] = "_PUSH_FRAME",
[_POP_JUMP_IF_FALSE] = "_POP_JUMP_IF_FALSE", [_POP_JUMP_IF_FALSE] = "_POP_JUMP_IF_FALSE",
[_POP_JUMP_IF_TRUE] = "_POP_JUMP_IF_TRUE", [_POP_JUMP_IF_TRUE] = "_POP_JUMP_IF_TRUE",
[JUMP_TO_TOP] = "JUMP_TO_TOP", [_JUMP_TO_TOP] = "_JUMP_TO_TOP",
[SAVE_CURRENT_IP] = "SAVE_CURRENT_IP", [_SAVE_CURRENT_IP] = "_SAVE_CURRENT_IP",
[INSERT] = "INSERT", [_INSERT] = "_INSERT",
}; };
#endif // NEED_OPCODE_METADATA #endif // NEED_OPCODE_METADATA

View file

@ -2390,7 +2390,7 @@ class TestUops(unittest.TestCase):
ex = get_first_executor(testfunc) ex = get_first_executor(testfunc)
self.assertIsNotNone(ex) self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex} uops = {opname for opname, _, _ in ex}
self.assertIn("SAVE_IP", uops) self.assertIn("_SET_IP", uops)
self.assertIn("LOAD_FAST", uops) self.assertIn("LOAD_FAST", uops)
def test_extended_arg(self): def test_extended_arg(self):
@ -2536,7 +2536,7 @@ class TestUops(unittest.TestCase):
ex = get_first_executor(testfunc) ex = get_first_executor(testfunc)
self.assertIsNotNone(ex) self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex} uops = {opname for opname, _, _ in ex}
self.assertIn("JUMP_TO_TOP", uops) self.assertIn("_JUMP_TO_TOP", uops)
def test_jump_forward(self): def test_jump_forward(self):
def testfunc(n): def testfunc(n):

View file

@ -521,7 +521,7 @@
break; break;
} }
case IS_NONE: { case _IS_NONE: {
PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1)), true); PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1)), true);
break; break;
} }
@ -792,23 +792,23 @@
break; break;
} }
case JUMP_TO_TOP: { case _JUMP_TO_TOP: {
break; break;
} }
case SAVE_IP: { case _SET_IP: {
break; break;
} }
case SAVE_CURRENT_IP: { case _SAVE_CURRENT_IP: {
break; break;
} }
case EXIT_TRACE: { case _EXIT_TRACE: {
break; break;
} }
case INSERT: { case _INSERT: {
PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1 - oparg)), true); PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1 - oparg)), true);
break; break;
} }

View file

@ -803,8 +803,8 @@ dummy_func(
} }
macro(RETURN_VALUE) = macro(RETURN_VALUE) =
SAVE_IP + // Tier 2 only; special-cased oparg _SET_IP + // Tier 2 only; special-cased oparg
SAVE_CURRENT_IP + // Sets frame->prev_instr _SAVE_CURRENT_IP + // Sets frame->prev_instr
_POP_FRAME; _POP_FRAME;
inst(INSTRUMENTED_RETURN_VALUE, (retval --)) { inst(INSTRUMENTED_RETURN_VALUE, (retval --)) {
@ -828,8 +828,8 @@ dummy_func(
macro(RETURN_CONST) = macro(RETURN_CONST) =
LOAD_CONST + LOAD_CONST +
SAVE_IP + // Tier 2 only; special-cased oparg _SET_IP + // Tier 2 only; special-cased oparg
SAVE_CURRENT_IP + // Sets frame->prev_instr _SAVE_CURRENT_IP + // Sets frame->prev_instr
_POP_FRAME; _POP_FRAME;
inst(INSTRUMENTED_RETURN_CONST, (--)) { inst(INSTRUMENTED_RETURN_CONST, (--)) {
@ -2310,7 +2310,7 @@ dummy_func(
JUMPBY(oparg * flag); JUMPBY(oparg * flag);
} }
op(IS_NONE, (value -- b)) { op(_IS_NONE, (value -- b)) {
if (Py_IsNone(value)) { if (Py_IsNone(value)) {
b = Py_True; b = Py_True;
} }
@ -2320,9 +2320,9 @@ dummy_func(
} }
} }
macro(POP_JUMP_IF_NONE) = IS_NONE + POP_JUMP_IF_TRUE; macro(POP_JUMP_IF_NONE) = _IS_NONE + POP_JUMP_IF_TRUE;
macro(POP_JUMP_IF_NOT_NONE) = IS_NONE + POP_JUMP_IF_FALSE; macro(POP_JUMP_IF_NOT_NONE) = _IS_NONE + POP_JUMP_IF_FALSE;
inst(JUMP_BACKWARD_NO_INTERRUPT, (--)) { inst(JUMP_BACKWARD_NO_INTERRUPT, (--)) {
/* This bytecode is used in the `yield from` or `await` loop. /* This bytecode is used in the `yield from` or `await` loop.
@ -3069,8 +3069,8 @@ dummy_func(
_CHECK_FUNCTION_EXACT_ARGS + _CHECK_FUNCTION_EXACT_ARGS +
_CHECK_STACK_SPACE + _CHECK_STACK_SPACE +
_INIT_CALL_PY_EXACT_ARGS + _INIT_CALL_PY_EXACT_ARGS +
SAVE_IP + // Tier 2 only; special-cased oparg _SET_IP + // Tier 2 only; special-cased oparg
SAVE_CURRENT_IP + // Sets frame->prev_instr _SAVE_CURRENT_IP + // Sets frame->prev_instr
_PUSH_FRAME; _PUSH_FRAME;
macro(CALL_PY_EXACT_ARGS) = macro(CALL_PY_EXACT_ARGS) =
@ -3079,8 +3079,8 @@ dummy_func(
_CHECK_FUNCTION_EXACT_ARGS + _CHECK_FUNCTION_EXACT_ARGS +
_CHECK_STACK_SPACE + _CHECK_STACK_SPACE +
_INIT_CALL_PY_EXACT_ARGS + _INIT_CALL_PY_EXACT_ARGS +
SAVE_IP + // Tier 2 only; special-cased oparg _SET_IP + // Tier 2 only; special-cased oparg
SAVE_CURRENT_IP + // Sets frame->prev_instr _SAVE_CURRENT_IP + // Sets frame->prev_instr
_PUSH_FRAME; _PUSH_FRAME;
inst(CALL_PY_WITH_DEFAULTS, (unused/1, func_version/2, callable, self_or_null, args[oparg] -- unused)) { inst(CALL_PY_WITH_DEFAULTS, (unused/1, func_version/2, callable, self_or_null, args[oparg] -- unused)) {
@ -3851,33 +3851,33 @@ dummy_func(
} }
} }
op(JUMP_TO_TOP, (--)) { op(_JUMP_TO_TOP, (--)) {
pc = 0; pc = 0;
CHECK_EVAL_BREAKER(); CHECK_EVAL_BREAKER();
} }
op(SAVE_IP, (--)) { op(_SET_IP, (--)) {
frame->prev_instr = ip_offset + oparg; frame->prev_instr = ip_offset + oparg;
} }
op(SAVE_CURRENT_IP, (--)) { op(_SAVE_CURRENT_IP, (--)) {
#if TIER_ONE #if TIER_ONE
frame->prev_instr = next_instr - 1; frame->prev_instr = next_instr - 1;
#endif #endif
#if TIER_TWO #if TIER_TWO
// Relies on a preceding SAVE_IP // Relies on a preceding _SET_IP
frame->prev_instr--; frame->prev_instr--;
#endif #endif
} }
op(EXIT_TRACE, (--)) { op(_EXIT_TRACE, (--)) {
frame->prev_instr--; // Back up to just before destination frame->prev_instr--; // Back up to just before destination
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(self); Py_DECREF(self);
return frame; return frame;
} }
op(INSERT, (unused[oparg], top -- top, unused[oparg])) { op(_INSERT, (unused[oparg], top -- top, unused[oparg])) {
// Inserts TOS at position specified by oparg; // Inserts TOS at position specified by oparg;
memmove(&stack_pointer[-1 - oparg], &stack_pointer[-oparg], oparg * sizeof(stack_pointer[0])); memmove(&stack_pointer[-1 - oparg], &stack_pointer[-oparg], oparg * sizeof(stack_pointer[0]));
} }

View file

@ -1902,7 +1902,7 @@
break; break;
} }
case IS_NONE: { case _IS_NONE: {
PyObject *value; PyObject *value;
PyObject *b; PyObject *b;
value = stack_pointer[-1]; value = stack_pointer[-1];
@ -2887,29 +2887,29 @@
break; break;
} }
case JUMP_TO_TOP: { case _JUMP_TO_TOP: {
pc = 0; pc = 0;
CHECK_EVAL_BREAKER(); CHECK_EVAL_BREAKER();
break; break;
} }
case SAVE_IP: { case _SET_IP: {
frame->prev_instr = ip_offset + oparg; frame->prev_instr = ip_offset + oparg;
break; break;
} }
case SAVE_CURRENT_IP: { case _SAVE_CURRENT_IP: {
#if TIER_ONE #if TIER_ONE
frame->prev_instr = next_instr - 1; frame->prev_instr = next_instr - 1;
#endif #endif
#if TIER_TWO #if TIER_TWO
// Relies on a preceding SAVE_IP // Relies on a preceding _SET_IP
frame->prev_instr--; frame->prev_instr--;
#endif #endif
break; break;
} }
case EXIT_TRACE: { case _EXIT_TRACE: {
frame->prev_instr--; // Back up to just before destination frame->prev_instr--; // Back up to just before destination
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(self); Py_DECREF(self);
@ -2917,7 +2917,7 @@
break; break;
} }
case INSERT: { case _INSERT: {
PyObject *top; PyObject *top;
top = stack_pointer[-1]; top = stack_pointer[-1];
// Inserts TOS at position specified by oparg; // Inserts TOS at position specified by oparg;

View file

@ -987,13 +987,13 @@
TARGET(RETURN_VALUE) { TARGET(RETURN_VALUE) {
PyObject *retval; PyObject *retval;
// SAVE_CURRENT_IP // _SAVE_CURRENT_IP
{ {
#if TIER_ONE #if TIER_ONE
frame->prev_instr = next_instr - 1; frame->prev_instr = next_instr - 1;
#endif #endif
#if TIER_TWO #if TIER_TWO
// Relies on a preceding SAVE_IP // Relies on a preceding _SET_IP
frame->prev_instr--; frame->prev_instr--;
#endif #endif
} }
@ -1055,13 +1055,13 @@
value = GETITEM(FRAME_CO_CONSTS, oparg); value = GETITEM(FRAME_CO_CONSTS, oparg);
Py_INCREF(value); Py_INCREF(value);
} }
// SAVE_CURRENT_IP // _SAVE_CURRENT_IP
{ {
#if TIER_ONE #if TIER_ONE
frame->prev_instr = next_instr - 1; frame->prev_instr = next_instr - 1;
#endif #endif
#if TIER_TWO #if TIER_TWO
// Relies on a preceding SAVE_IP // Relies on a preceding _SET_IP
frame->prev_instr--; frame->prev_instr--;
#endif #endif
} }
@ -3024,7 +3024,7 @@
PyObject *value; PyObject *value;
PyObject *b; PyObject *b;
PyObject *cond; PyObject *cond;
// IS_NONE // _IS_NONE
value = stack_pointer[-1]; value = stack_pointer[-1];
{ {
if (Py_IsNone(value)) { if (Py_IsNone(value)) {
@ -3054,7 +3054,7 @@
PyObject *value; PyObject *value;
PyObject *b; PyObject *b;
PyObject *cond; PyObject *cond;
// IS_NONE // _IS_NONE
value = stack_pointer[-1]; value = stack_pointer[-1];
{ {
if (Py_IsNone(value)) { if (Py_IsNone(value)) {
@ -3879,14 +3879,14 @@
new_frame->localsplus[i] = args[i]; new_frame->localsplus[i] = args[i];
} }
} }
// SAVE_CURRENT_IP // _SAVE_CURRENT_IP
next_instr += 3; next_instr += 3;
{ {
#if TIER_ONE #if TIER_ONE
frame->prev_instr = next_instr - 1; frame->prev_instr = next_instr - 1;
#endif #endif
#if TIER_TWO #if TIER_TWO
// Relies on a preceding SAVE_IP // Relies on a preceding _SET_IP
frame->prev_instr--; frame->prev_instr--;
#endif #endif
} }
@ -3958,14 +3958,14 @@
new_frame->localsplus[i] = args[i]; new_frame->localsplus[i] = args[i];
} }
} }
// SAVE_CURRENT_IP // _SAVE_CURRENT_IP
next_instr += 3; next_instr += 3;
{ {
#if TIER_ONE #if TIER_ONE
frame->prev_instr = next_instr - 1; frame->prev_instr = next_instr - 1;
#endif #endif
#if TIER_TWO #if TIER_TWO
// Relies on a preceding SAVE_IP // Relies on a preceding _SET_IP
frame->prev_instr--; frame->prev_instr--;
#endif #endif
} }

View file

@ -474,14 +474,14 @@ translate_bytecode_to_trace(
} \ } \
reserved = (n); // Keep ADD_TO_TRACE / ADD_TO_STUB honest reserved = (n); // Keep ADD_TO_TRACE / ADD_TO_STUB honest
// Reserve space for main+stub uops, plus 2 for SAVE_IP and EXIT_TRACE // Reserve space for main+stub uops, plus 2 for _SET_IP and _EXIT_TRACE
#define RESERVE(main, stub) RESERVE_RAW((main) + (stub) + 2, uop_name(opcode)) #define RESERVE(main, stub) RESERVE_RAW((main) + (stub) + 2, uop_name(opcode))
// Trace stack operations (used by _PUSH_FRAME, _POP_FRAME) // Trace stack operations (used by _PUSH_FRAME, _POP_FRAME)
#define TRACE_STACK_PUSH() \ #define TRACE_STACK_PUSH() \
if (trace_stack_depth >= TRACE_STACK_SIZE) { \ if (trace_stack_depth >= TRACE_STACK_SIZE) { \
DPRINTF(2, "Trace stack overflow\n"); \ DPRINTF(2, "Trace stack overflow\n"); \
ADD_TO_TRACE(SAVE_IP, 0, 0); \ ADD_TO_TRACE(_SET_IP, 0, 0); \
goto done; \ goto done; \
} \ } \
trace_stack[trace_stack_depth].code = code; \ trace_stack[trace_stack_depth].code = code; \
@ -504,8 +504,8 @@ translate_bytecode_to_trace(
top: // Jump here after _PUSH_FRAME or likely branches top: // Jump here after _PUSH_FRAME or likely branches
for (;;) { for (;;) {
RESERVE_RAW(2, "epilogue"); // Always need space for SAVE_IP and EXIT_TRACE RESERVE_RAW(2, "epilogue"); // Always need space for _SET_IP and _EXIT_TRACE
ADD_TO_TRACE(SAVE_IP, INSTR_IP(instr, code), 0); ADD_TO_TRACE(_SET_IP, INSTR_IP(instr, code), 0);
uint32_t opcode = instr->op.code; uint32_t opcode = instr->op.code;
uint32_t oparg = instr->op.arg; uint32_t oparg = instr->op.arg;
@ -531,7 +531,7 @@ top: // Jump here after _PUSH_FRAME or likely branches
case POP_JUMP_IF_NONE: case POP_JUMP_IF_NONE:
{ {
RESERVE(2, 2); RESERVE(2, 2);
ADD_TO_TRACE(IS_NONE, 0, 0); ADD_TO_TRACE(_IS_NONE, 0, 0);
opcode = POP_JUMP_IF_TRUE; opcode = POP_JUMP_IF_TRUE;
goto pop_jump_if_bool; goto pop_jump_if_bool;
} }
@ -539,7 +539,7 @@ top: // Jump here after _PUSH_FRAME or likely branches
case POP_JUMP_IF_NOT_NONE: case POP_JUMP_IF_NOT_NONE:
{ {
RESERVE(2, 2); RESERVE(2, 2);
ADD_TO_TRACE(IS_NONE, 0, 0); ADD_TO_TRACE(_IS_NONE, 0, 0);
opcode = POP_JUMP_IF_FALSE; opcode = POP_JUMP_IF_FALSE;
goto pop_jump_if_bool; goto pop_jump_if_bool;
} }
@ -563,8 +563,8 @@ pop_jump_if_bool:
uop_name(opcode), oparg, uop_name(opcode), oparg,
counter, bitcount, jump_likely, jump_sense, uop_name(uopcode)); counter, bitcount, jump_likely, jump_sense, uop_name(uopcode));
ADD_TO_TRACE(uopcode, max_length, 0); ADD_TO_TRACE(uopcode, max_length, 0);
ADD_TO_STUB(max_length, SAVE_IP, INSTR_IP(stub_target, code), 0); ADD_TO_STUB(max_length, _SET_IP, INSTR_IP(stub_target, code), 0);
ADD_TO_STUB(max_length + 1, EXIT_TRACE, 0, 0); ADD_TO_STUB(max_length + 1, _EXIT_TRACE, 0, 0);
if (jump_likely) { if (jump_likely) {
DPRINTF(2, "Jump likely (%x = %d bits), continue at byte offset %d\n", DPRINTF(2, "Jump likely (%x = %d bits), continue at byte offset %d\n",
instr[1].cache, bitcount, 2 * INSTR_IP(target_instr, code)); instr[1].cache, bitcount, 2 * INSTR_IP(target_instr, code));
@ -578,7 +578,7 @@ pop_jump_if_bool:
{ {
if (instr + 2 - oparg == initial_instr && code == initial_code) { if (instr + 2 - oparg == initial_instr && code == initial_code) {
RESERVE(1, 0); RESERVE(1, 0);
ADD_TO_TRACE(JUMP_TO_TOP, 0, 0); ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0);
} }
else { else {
DPRINTF(2, "JUMP_BACKWARD not to top ends trace\n"); DPRINTF(2, "JUMP_BACKWARD not to top ends trace\n");
@ -589,7 +589,7 @@ pop_jump_if_bool:
case JUMP_FORWARD: case JUMP_FORWARD:
{ {
RESERVE(0, 0); RESERVE(0, 0);
// This will emit two SAVE_IP instructions; leave it to the optimizer // This will emit two _SET_IP instructions; leave it to the optimizer
instr += oparg; instr += oparg;
break; break;
} }
@ -629,8 +629,8 @@ pop_jump_if_bool:
ADD_TO_TRACE(next_op, 0, 0); ADD_TO_TRACE(next_op, 0, 0);
ADD_TO_STUB(max_length + 0, POP_TOP, 0, 0); ADD_TO_STUB(max_length + 0, POP_TOP, 0, 0);
ADD_TO_STUB(max_length + 1, SAVE_IP, INSTR_IP(target_instr, code), 0); ADD_TO_STUB(max_length + 1, _SET_IP, INSTR_IP(target_instr, code), 0);
ADD_TO_STUB(max_length + 2, EXIT_TRACE, 0, 0); ADD_TO_STUB(max_length + 2, _EXIT_TRACE, 0, 0);
break; break;
} }
@ -638,7 +638,7 @@ pop_jump_if_bool:
{ {
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode]; const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
if (expansion->nuops > 0) { if (expansion->nuops > 0) {
// Reserve space for nuops (+ SAVE_IP + EXIT_TRACE) // Reserve space for nuops (+ _SET_IP + _EXIT_TRACE)
int nuops = expansion->nuops; int nuops = expansion->nuops;
RESERVE(nuops, 0); RESERVE(nuops, 0);
if (expansion->uops[nuops-1].uop == _POP_FRAME) { if (expansion->uops[nuops-1].uop == _POP_FRAME) {
@ -682,7 +682,7 @@ pop_jump_if_bool:
case OPARG_BOTTOM: // Second half of super-instr case OPARG_BOTTOM: // Second half of super-instr
oparg = orig_oparg & 0xF; oparg = orig_oparg & 0xF;
break; break;
case OPARG_SAVE_IP: // op==SAVE_IP; oparg=next instr case OPARG_SET_IP: // op==_SET_IP; oparg=next instr
oparg = INSTR_IP(instr + offset, code); oparg = INSTR_IP(instr + offset, code);
break; break;
@ -722,7 +722,7 @@ pop_jump_if_bool:
PyUnicode_AsUTF8(new_code->co_qualname), PyUnicode_AsUTF8(new_code->co_qualname),
PyUnicode_AsUTF8(new_code->co_filename), PyUnicode_AsUTF8(new_code->co_filename),
new_code->co_firstlineno); new_code->co_firstlineno);
ADD_TO_TRACE(SAVE_IP, 0, 0); ADD_TO_TRACE(_SET_IP, 0, 0);
goto done; goto done;
} }
if (new_code->co_version != func_version) { if (new_code->co_version != func_version) {
@ -730,7 +730,7 @@ pop_jump_if_bool:
// Perhaps it may happen again, so don't bother tracing. // Perhaps it may happen again, so don't bother tracing.
// TODO: Reason about this -- is it better to bail or not? // TODO: Reason about this -- is it better to bail or not?
DPRINTF(2, "Bailing because co_version != func_version\n"); DPRINTF(2, "Bailing because co_version != func_version\n");
ADD_TO_TRACE(SAVE_IP, 0, 0); ADD_TO_TRACE(_SET_IP, 0, 0);
goto done; goto done;
} }
// Increment IP to the return address // Increment IP to the return address
@ -746,7 +746,7 @@ pop_jump_if_bool:
2 * INSTR_IP(instr, code)); 2 * INSTR_IP(instr, code));
goto top; goto top;
} }
ADD_TO_TRACE(SAVE_IP, 0, 0); ADD_TO_TRACE(_SET_IP, 0, 0);
goto done; goto done;
} }
} }
@ -768,9 +768,9 @@ done:
TRACE_STACK_POP(); TRACE_STACK_POP();
} }
assert(code == initial_code); assert(code == initial_code);
// Skip short traces like SAVE_IP, LOAD_FAST, SAVE_IP, EXIT_TRACE // Skip short traces like _SET_IP, LOAD_FAST, _SET_IP, _EXIT_TRACE
if (trace_length > 3) { if (trace_length > 3) {
ADD_TO_TRACE(EXIT_TRACE, 0, 0); ADD_TO_TRACE(_EXIT_TRACE, 0, 0);
DPRINTF(1, DPRINTF(1,
"Created a trace for %s (%s:%d) at byte offset %d -- length %d+%d\n", "Created a trace for %s (%s:%d) at byte offset %d -- length %d+%d\n",
PyUnicode_AsUTF8(code->co_qualname), PyUnicode_AsUTF8(code->co_qualname),
@ -819,25 +819,25 @@ done:
static int static int
remove_unneeded_uops(_PyUOpInstruction *trace, int trace_length) remove_unneeded_uops(_PyUOpInstruction *trace, int trace_length)
{ {
// Stage 1: Replace unneeded SAVE_IP uops with NOP. // Stage 1: Replace unneeded _SET_IP uops with NOP.
// Note that we don't enter stubs, those SAVE_IPs are needed. // Note that we don't enter stubs, those SET_IPs are needed.
int last_save_ip = -1; int last_set_ip = -1;
int last_instr = 0; int last_instr = 0;
bool need_ip = true; bool need_ip = true;
for (int pc = 0; pc < trace_length; pc++) { for (int pc = 0; pc < trace_length; pc++) {
int opcode = trace[pc].opcode; int opcode = trace[pc].opcode;
if (opcode == SAVE_CURRENT_IP) { if (opcode == _SAVE_CURRENT_IP) {
// Special case: never remove preceding SAVE_IP // Special case: never remove preceding _SET_IP
last_save_ip = -1; last_set_ip = -1;
} }
else if (opcode == SAVE_IP) { else if (opcode == _SET_IP) {
if (!need_ip && last_save_ip >= 0) { if (!need_ip && last_set_ip >= 0) {
trace[last_save_ip].opcode = NOP; trace[last_set_ip].opcode = NOP;
} }
need_ip = false; need_ip = false;
last_save_ip = pc; last_set_ip = pc;
} }
else if (opcode == JUMP_TO_TOP || opcode == EXIT_TRACE) { else if (opcode == _JUMP_TO_TOP || opcode == _EXIT_TRACE) {
last_instr = pc + 1; last_instr = pc + 1;
break; break;
} }

View file

@ -365,8 +365,8 @@ class Analyzer:
case Instruction() as instr: case Instruction() as instr:
part, offset = self.analyze_instruction(instr, offset) part, offset = self.analyze_instruction(instr, offset)
parts.append(part) parts.append(part)
if instr.name != "SAVE_IP": if instr.name != "_SET_IP":
# SAVE_IP in a macro is a no-op in Tier 1 # _SET_IP in a macro is a no-op in Tier 1
flags.add(instr.instr_flags) flags.add(instr.instr_flags)
case _: case _:
assert_never(component) assert_never(component)

View file

@ -68,7 +68,7 @@ OPARG_SIZES = {
"OPARG_CACHE_4": 4, "OPARG_CACHE_4": 4,
"OPARG_TOP": 5, "OPARG_TOP": 5,
"OPARG_BOTTOM": 6, "OPARG_BOTTOM": 6,
"OPARG_SAVE_IP": 7, "OPARG_SET_IP": 7,
} }
INSTR_FMT_PREFIX = "INSTR_FMT_" INSTR_FMT_PREFIX = "INSTR_FMT_"
@ -658,8 +658,8 @@ class Generator(Analyzer):
seen.add(name) seen.add(name)
# These two are first by convention # These two are first by convention
add("EXIT_TRACE") add("_EXIT_TRACE")
add("SAVE_IP") add("_SET_IP")
for instr in self.instrs.values(): for instr in self.instrs.values():
if instr.kind == "op": if instr.kind == "op":
@ -687,8 +687,8 @@ class Generator(Analyzer):
) )
return return
if not part.active_caches: if not part.active_caches:
if part.instr.name == "SAVE_IP": if part.instr.name == "_SET_IP":
size, offset = OPARG_SIZES["OPARG_SAVE_IP"], cache_offset size, offset = OPARG_SIZES["OPARG_SET_IP"], cache_offset
else: else:
size, offset = OPARG_SIZES["OPARG_FULL"], 0 size, offset = OPARG_SIZES["OPARG_FULL"], 0
else: else:

View file

@ -124,7 +124,7 @@ class Instruction:
if "FRAME" in self.name: if "FRAME" in self.name:
dprint = print dprint = print
if self.name == "EXIT_TRACE": if self.name == "_EXIT_TRACE":
return True # This has 'return frame' but it's okay return True # This has 'return frame' but it's okay
if self.always_exits: if self.always_exits:
dprint(f"Skipping {self.name} because it always exits: {self.always_exits}") dprint(f"Skipping {self.name} because it always exits: {self.always_exits}")

View file

@ -362,7 +362,7 @@ def write_macro_instr(
parts = [ parts = [
part part
for part in mac.parts for part in mac.parts
if isinstance(part, Component) and part.instr.name != "SAVE_IP" if isinstance(part, Component) and part.instr.name != "_SET_IP"
] ]
out.emit("") out.emit("")
with out.block(f"TARGET({mac.name})"): with out.block(f"TARGET({mac.name})"):
@ -444,7 +444,7 @@ def write_components(
), f"Expected {mgr.instr.name!r} to be the last uop" ), f"Expected {mgr.instr.name!r} to be the last uop"
assert_no_pokes(managers) assert_no_pokes(managers)
if mgr.instr.name == "SAVE_CURRENT_IP": if mgr.instr.name == "_SAVE_CURRENT_IP":
next_instr_is_set = True next_instr_is_set = True
if cache_offset: if cache_offset:
out.emit(f"next_instr += {cache_offset};") out.emit(f"next_instr += {cache_offset};")