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) || \
0)
#define EXIT_TRACE 300
#define SAVE_IP 301
#define _EXIT_TRACE 300
#define _SET_IP 301
#define _GUARD_BOTH_INT 302
#define _BINARY_OP_MULTIPLY_INT 303
#define _BINARY_OP_ADD_INT 304
@ -46,7 +46,7 @@
#define _GUARD_TYPE_VERSION 318
#define _CHECK_MANAGED_OBJECT_HAS_VALUES 319
#define _LOAD_ATTR_INSTANCE_VALUE 320
#define IS_NONE 321
#define _IS_NONE 321
#define _ITER_CHECK_LIST 322
#define _ITER_JUMP_LIST 323
#define _IS_ITER_EXHAUSTED_LIST 324
@ -68,9 +68,9 @@
#define _PUSH_FRAME 340
#define _POP_JUMP_IF_FALSE 341
#define _POP_JUMP_IF_TRUE 342
#define JUMP_TO_TOP 343
#define SAVE_CURRENT_IP 344
#define INSERT 345
#define _JUMP_TO_TOP 343
#define _SAVE_CURRENT_IP 344
#define _INSERT 345
extern int _PyOpcode_num_popped(int opcode, int oparg, bool jump);
#ifdef NEED_OPCODE_METADATA
@ -402,7 +402,7 @@ int _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
return 1;
case POP_JUMP_IF_TRUE:
return 1;
case IS_NONE:
case _IS_NONE:
return 1;
case POP_JUMP_IF_NONE:
return 1;
@ -586,15 +586,15 @@ int _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
return 1;
case _POP_JUMP_IF_TRUE:
return 1;
case JUMP_TO_TOP:
case _JUMP_TO_TOP:
return 0;
case SAVE_IP:
case _SET_IP:
return 0;
case SAVE_CURRENT_IP:
case _SAVE_CURRENT_IP:
return 0;
case EXIT_TRACE:
case _EXIT_TRACE:
return 0;
case INSERT:
case _INSERT:
return oparg + 1;
default:
return -1;
@ -932,7 +932,7 @@ int _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
return 0;
case POP_JUMP_IF_TRUE:
return 0;
case IS_NONE:
case _IS_NONE:
return 1;
case POP_JUMP_IF_NONE:
return 0;
@ -1116,15 +1116,15 @@ int _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
return 0;
case _POP_JUMP_IF_TRUE:
return 0;
case JUMP_TO_TOP:
case _JUMP_TO_TOP:
return 0;
case SAVE_IP:
case _SET_IP:
return 0;
case SAVE_CURRENT_IP:
case _SAVE_CURRENT_IP:
return 0;
case EXIT_TRACE:
case _EXIT_TRACE:
return 0;
case INSERT:
case _INSERT:
return oparg + 1;
default:
return -1;
@ -1186,7 +1186,7 @@ struct opcode_macro_expansion {
#define OPARG_CACHE_4 4
#define OPARG_TOP 5
#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 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 },
[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 },
[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_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 },
@ -1458,11 +1458,11 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[OPCODE_METADATA_SIZE] = {
[RESERVED] = { true, INSTR_FMT_IX, 0 },
[_POP_JUMP_IF_FALSE] = { 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 },
[SAVE_IP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
[SAVE_CURRENT_IP] = { true, INSTR_FMT_IX, 0 },
[EXIT_TRACE] = { true, INSTR_FMT_IX, 0 },
[INSERT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
[_JUMP_TO_TOP] = { true, INSTR_FMT_IX, HAS_EVAL_BREAK_FLAG },
[_SET_IP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
[_SAVE_CURRENT_IP] = { true, INSTR_FMT_IX, 0 },
[_EXIT_TRACE] = { true, INSTR_FMT_IX, 0 },
[_INSERT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
};
#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 } } },
[CALL_INTRINSIC_1] = { .nuops = 1, .uops = { { CALL_INTRINSIC_1, 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_CONST] = { .nuops = 4, .uops = { { LOAD_CONST, 0, 0 }, { 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 }, { _SET_IP, 7, 0 }, { _SAVE_CURRENT_IP, 0, 0 }, { _POP_FRAME, 0, 0 } } },
[GET_AITER] = { .nuops = 1, .uops = { { GET_AITER, 0, 0 } } },
[GET_ANEXT] = { .nuops = 1, .uops = { { GET_ANEXT, 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 } } },
[WITH_EXCEPT_START] = { .nuops = 1, .uops = { { WITH_EXCEPT_START, 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_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_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 }, { _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_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 } } },
@ -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];
#ifdef NEED_OPCODE_METADATA
const char * const _PyOpcode_uop_name[OPCODE_UOP_NAME_SIZE] = {
[EXIT_TRACE] = "EXIT_TRACE",
[SAVE_IP] = "SAVE_IP",
[_EXIT_TRACE] = "_EXIT_TRACE",
[_SET_IP] = "_SET_IP",
[_GUARD_BOTH_INT] = "_GUARD_BOTH_INT",
[_BINARY_OP_MULTIPLY_INT] = "_BINARY_OP_MULTIPLY_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",
[_CHECK_MANAGED_OBJECT_HAS_VALUES] = "_CHECK_MANAGED_OBJECT_HAS_VALUES",
[_LOAD_ATTR_INSTANCE_VALUE] = "_LOAD_ATTR_INSTANCE_VALUE",
[IS_NONE] = "IS_NONE",
[_IS_NONE] = "_IS_NONE",
[_ITER_CHECK_LIST] = "_ITER_CHECK_LIST",
[_ITER_JUMP_LIST] = "_ITER_JUMP_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",
[_POP_JUMP_IF_FALSE] = "_POP_JUMP_IF_FALSE",
[_POP_JUMP_IF_TRUE] = "_POP_JUMP_IF_TRUE",
[JUMP_TO_TOP] = "JUMP_TO_TOP",
[SAVE_CURRENT_IP] = "SAVE_CURRENT_IP",
[INSERT] = "INSERT",
[_JUMP_TO_TOP] = "_JUMP_TO_TOP",
[_SAVE_CURRENT_IP] = "_SAVE_CURRENT_IP",
[_INSERT] = "_INSERT",
};
#endif // NEED_OPCODE_METADATA

View File

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

View File

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

View File

@ -803,8 +803,8 @@ dummy_func(
}
macro(RETURN_VALUE) =
SAVE_IP + // Tier 2 only; special-cased oparg
SAVE_CURRENT_IP + // Sets frame->prev_instr
_SET_IP + // Tier 2 only; special-cased oparg
_SAVE_CURRENT_IP + // Sets frame->prev_instr
_POP_FRAME;
inst(INSTRUMENTED_RETURN_VALUE, (retval --)) {
@ -828,8 +828,8 @@ dummy_func(
macro(RETURN_CONST) =
LOAD_CONST +
SAVE_IP + // Tier 2 only; special-cased oparg
SAVE_CURRENT_IP + // Sets frame->prev_instr
_SET_IP + // Tier 2 only; special-cased oparg
_SAVE_CURRENT_IP + // Sets frame->prev_instr
_POP_FRAME;
inst(INSTRUMENTED_RETURN_CONST, (--)) {
@ -2310,7 +2310,7 @@ dummy_func(
JUMPBY(oparg * flag);
}
op(IS_NONE, (value -- b)) {
op(_IS_NONE, (value -- b)) {
if (Py_IsNone(value)) {
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, (--)) {
/* This bytecode is used in the `yield from` or `await` loop.
@ -3069,8 +3069,8 @@ dummy_func(
_CHECK_FUNCTION_EXACT_ARGS +
_CHECK_STACK_SPACE +
_INIT_CALL_PY_EXACT_ARGS +
SAVE_IP + // Tier 2 only; special-cased oparg
SAVE_CURRENT_IP + // Sets frame->prev_instr
_SET_IP + // Tier 2 only; special-cased oparg
_SAVE_CURRENT_IP + // Sets frame->prev_instr
_PUSH_FRAME;
macro(CALL_PY_EXACT_ARGS) =
@ -3079,8 +3079,8 @@ dummy_func(
_CHECK_FUNCTION_EXACT_ARGS +
_CHECK_STACK_SPACE +
_INIT_CALL_PY_EXACT_ARGS +
SAVE_IP + // Tier 2 only; special-cased oparg
SAVE_CURRENT_IP + // Sets frame->prev_instr
_SET_IP + // Tier 2 only; special-cased oparg
_SAVE_CURRENT_IP + // Sets frame->prev_instr
_PUSH_FRAME;
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;
CHECK_EVAL_BREAKER();
}
op(SAVE_IP, (--)) {
op(_SET_IP, (--)) {
frame->prev_instr = ip_offset + oparg;
}
op(SAVE_CURRENT_IP, (--)) {
op(_SAVE_CURRENT_IP, (--)) {
#if TIER_ONE
frame->prev_instr = next_instr - 1;
#endif
#if TIER_TWO
// Relies on a preceding SAVE_IP
// Relies on a preceding _SET_IP
frame->prev_instr--;
#endif
}
op(EXIT_TRACE, (--)) {
op(_EXIT_TRACE, (--)) {
frame->prev_instr--; // Back up to just before destination
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(self);
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;
memmove(&stack_pointer[-1 - oparg], &stack_pointer[-oparg], oparg * sizeof(stack_pointer[0]));
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -124,7 +124,7 @@ class Instruction:
if "FRAME" in self.name:
dprint = print
if self.name == "EXIT_TRACE":
if self.name == "_EXIT_TRACE":
return True # This has 'return frame' but it's okay
if 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 = [
part
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("")
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"
assert_no_pokes(managers)
if mgr.instr.name == "SAVE_CURRENT_IP":
if mgr.instr.name == "_SAVE_CURRENT_IP":
next_instr_is_set = True
if cache_offset:
out.emit(f"next_instr += {cache_offset};")