mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-133273: Keep instruction definitions in bytecodes.c
and optimizer_bytecodes.c
in sync (GH-133320)
This commit is contained in:
parent
5f3d3f2a6c
commit
3f2f59a91d
4 changed files with 372 additions and 134 deletions
|
@ -104,18 +104,18 @@ dummy_func(void) {
|
|||
res = sym_new_null(ctx);
|
||||
}
|
||||
|
||||
op(_GUARD_TOS_INT, (tos -- tos)) {
|
||||
if (sym_matches_type(tos, &PyLong_Type)) {
|
||||
op(_GUARD_TOS_INT, (value -- value)) {
|
||||
if (sym_matches_type(value, &PyLong_Type)) {
|
||||
REPLACE_OP(this_instr, _NOP, 0, 0);
|
||||
}
|
||||
sym_set_type(tos, &PyLong_Type);
|
||||
sym_set_type(value, &PyLong_Type);
|
||||
}
|
||||
|
||||
op(_GUARD_NOS_INT, (nos, unused -- nos, unused)) {
|
||||
if (sym_matches_type(nos, &PyLong_Type)) {
|
||||
op(_GUARD_NOS_INT, (left, unused -- left, unused)) {
|
||||
if (sym_matches_type(left, &PyLong_Type)) {
|
||||
REPLACE_OP(this_instr, _NOP, 0, 0);
|
||||
}
|
||||
sym_set_type(nos, &PyLong_Type);
|
||||
sym_set_type(left, &PyLong_Type);
|
||||
}
|
||||
|
||||
op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) {
|
||||
|
@ -141,25 +141,25 @@ dummy_func(void) {
|
|||
}
|
||||
}
|
||||
|
||||
op(_GUARD_TOS_FLOAT, (tos -- tos)) {
|
||||
if (sym_matches_type(tos, &PyFloat_Type)) {
|
||||
op(_GUARD_TOS_FLOAT, (value -- value)) {
|
||||
if (sym_matches_type(value, &PyFloat_Type)) {
|
||||
REPLACE_OP(this_instr, _NOP, 0, 0);
|
||||
}
|
||||
sym_set_type(tos, &PyFloat_Type);
|
||||
sym_set_type(value, &PyFloat_Type);
|
||||
}
|
||||
|
||||
op(_GUARD_NOS_FLOAT, (nos, unused -- nos, unused)) {
|
||||
if (sym_matches_type(nos, &PyFloat_Type)) {
|
||||
op(_GUARD_NOS_FLOAT, (left, unused -- left, unused)) {
|
||||
if (sym_matches_type(left, &PyFloat_Type)) {
|
||||
REPLACE_OP(this_instr, _NOP, 0, 0);
|
||||
}
|
||||
sym_set_type(nos, &PyFloat_Type);
|
||||
sym_set_type(left, &PyFloat_Type);
|
||||
}
|
||||
|
||||
op(_BINARY_OP, (left, right -- res)) {
|
||||
bool lhs_int = sym_matches_type(left, &PyLong_Type);
|
||||
bool rhs_int = sym_matches_type(right, &PyLong_Type);
|
||||
bool lhs_float = sym_matches_type(left, &PyFloat_Type);
|
||||
bool rhs_float = sym_matches_type(right, &PyFloat_Type);
|
||||
op(_BINARY_OP, (lhs, rhs -- res)) {
|
||||
bool lhs_int = sym_matches_type(lhs, &PyLong_Type);
|
||||
bool rhs_int = sym_matches_type(rhs, &PyLong_Type);
|
||||
bool lhs_float = sym_matches_type(lhs, &PyFloat_Type);
|
||||
bool rhs_float = sym_matches_type(rhs, &PyFloat_Type);
|
||||
if (!((lhs_int || lhs_float) && (rhs_int || rhs_float))) {
|
||||
// There's something other than an int or float involved:
|
||||
res = sym_new_unknown(ctx);
|
||||
|
@ -185,11 +185,11 @@ dummy_func(void) {
|
|||
// Case C:
|
||||
res = sym_new_type(ctx, &PyFloat_Type);
|
||||
}
|
||||
else if (!sym_is_const(ctx, right)) {
|
||||
else if (!sym_is_const(ctx, rhs)) {
|
||||
// Case A or B... can't know without the sign of the RHS:
|
||||
res = sym_new_unknown(ctx);
|
||||
}
|
||||
else if (_PyLong_IsNegative((PyLongObject *)sym_get_const(ctx, right))) {
|
||||
else if (_PyLong_IsNegative((PyLongObject *)sym_get_const(ctx, rhs))) {
|
||||
// Case B:
|
||||
res = sym_new_type(ctx, &PyFloat_Type);
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ dummy_func(void) {
|
|||
ctx->done = true;
|
||||
}
|
||||
|
||||
op(_BINARY_OP_SUBSCR_STR_INT, (left, right -- res)) {
|
||||
op(_BINARY_OP_SUBSCR_STR_INT, (str_st, sub_st -- res)) {
|
||||
res = sym_new_type(ctx, &PyUnicode_Type);
|
||||
}
|
||||
|
||||
|
@ -398,11 +398,11 @@ dummy_func(void) {
|
|||
}
|
||||
}
|
||||
|
||||
op(_TO_BOOL_BOOL, (value -- res)) {
|
||||
int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
|
||||
op(_TO_BOOL_BOOL, (value -- value)) {
|
||||
int already_bool = optimize_to_bool(this_instr, ctx, value, &value);
|
||||
if (!already_bool) {
|
||||
sym_set_type(value, &PyBool_Type);
|
||||
res = sym_new_truthiness(ctx, value, true);
|
||||
value = sym_new_truthiness(ctx, value, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -493,20 +493,20 @@ dummy_func(void) {
|
|||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
}
|
||||
|
||||
op(_IS_OP, (left, right -- res)) {
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
op(_IS_OP, (left, right -- b)) {
|
||||
b = sym_new_type(ctx, &PyBool_Type);
|
||||
}
|
||||
|
||||
op(_CONTAINS_OP, (left, right -- res)) {
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
op(_CONTAINS_OP, (left, right -- b)) {
|
||||
b = sym_new_type(ctx, &PyBool_Type);
|
||||
}
|
||||
|
||||
op(_CONTAINS_OP_SET, (left, right -- res)) {
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
op(_CONTAINS_OP_SET, (left, right -- b)) {
|
||||
b = sym_new_type(ctx, &PyBool_Type);
|
||||
}
|
||||
|
||||
op(_CONTAINS_OP_DICT, (left, right -- res)) {
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
op(_CONTAINS_OP_DICT, (left, right -- b)) {
|
||||
b = sym_new_type(ctx, &PyBool_Type);
|
||||
}
|
||||
|
||||
op(_LOAD_CONST, (-- value)) {
|
||||
|
@ -707,10 +707,10 @@ dummy_func(void) {
|
|||
}
|
||||
}
|
||||
|
||||
op(_MAYBE_EXPAND_METHOD, (callable, self_or_null, args[oparg] -- func, maybe_self, args[oparg])) {
|
||||
op(_MAYBE_EXPAND_METHOD, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
|
||||
(void)args;
|
||||
func = sym_new_not_null(ctx);
|
||||
maybe_self = sym_new_not_null(ctx);
|
||||
callable = sym_new_not_null(ctx);
|
||||
self_or_null = sym_new_not_null(ctx);
|
||||
}
|
||||
|
||||
op(_PY_FRAME_GENERAL, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
|
||||
|
@ -730,14 +730,14 @@ dummy_func(void) {
|
|||
ctx->done = true;
|
||||
}
|
||||
|
||||
op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable, null, args[oparg] -- self, init, args[oparg])) {
|
||||
op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
|
||||
(void)type_version;
|
||||
(void)args;
|
||||
self = sym_new_not_null(ctx);
|
||||
init = sym_new_not_null(ctx);
|
||||
callable = sym_new_not_null(ctx);
|
||||
self_or_null = sym_new_not_null(ctx);
|
||||
}
|
||||
|
||||
op(_CREATE_INIT_FRAME, (self, init, args[oparg] -- init_frame: _Py_UOpsAbstractFrame *)) {
|
||||
op(_CREATE_INIT_FRAME, (init, self, args[oparg] -- init_frame: _Py_UOpsAbstractFrame *)) {
|
||||
init_frame = NULL;
|
||||
ctx->done = true;
|
||||
}
|
||||
|
@ -789,21 +789,23 @@ dummy_func(void) {
|
|||
}
|
||||
}
|
||||
|
||||
op(_YIELD_VALUE, (unused -- res)) {
|
||||
res = sym_new_unknown(ctx);
|
||||
op(_YIELD_VALUE, (unused -- value)) {
|
||||
value = sym_new_unknown(ctx);
|
||||
}
|
||||
|
||||
op(_FOR_ITER_GEN_FRAME, ( -- )) {
|
||||
op(_FOR_ITER_GEN_FRAME, (unused -- unused, gen_frame: _Py_UOpsAbstractFrame*)) {
|
||||
gen_frame = NULL;
|
||||
/* We are about to hit the end of the trace */
|
||||
ctx->done = true;
|
||||
}
|
||||
|
||||
op(_SEND_GEN_FRAME, ( -- )) {
|
||||
op(_SEND_GEN_FRAME, (unused, unused -- unused, gen_frame: _Py_UOpsAbstractFrame *)) {
|
||||
gen_frame = NULL;
|
||||
// We are about to hit the end of the trace:
|
||||
ctx->done = true;
|
||||
}
|
||||
|
||||
op(_CHECK_STACK_SPACE, ( --)) {
|
||||
op(_CHECK_STACK_SPACE, (unused, unused, unused[oparg] -- unused, unused, unused[oparg])) {
|
||||
assert(corresponding_check_stack == NULL);
|
||||
corresponding_check_stack = this_instr;
|
||||
}
|
||||
|
@ -848,14 +850,16 @@ dummy_func(void) {
|
|||
corresponding_check_stack = NULL;
|
||||
}
|
||||
|
||||
op(_UNPACK_SEQUENCE, (seq -- values[oparg])) {
|
||||
op(_UNPACK_SEQUENCE, (seq -- values[oparg], top[0])) {
|
||||
(void)top;
|
||||
/* This has to be done manually */
|
||||
for (int i = 0; i < oparg; i++) {
|
||||
values[i] = sym_new_unknown(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
op(_UNPACK_EX, (seq -- values[oparg & 0xFF], unused, unused[oparg >> 8])) {
|
||||
op(_UNPACK_EX, (seq -- values[oparg & 0xFF], unused, unused[oparg >> 8], top[0])) {
|
||||
(void)top;
|
||||
/* This has to be done manually */
|
||||
int totalargs = (oparg & 0xFF) + (oparg >> 8) + 1;
|
||||
for (int i = 0; i < totalargs; i++) {
|
||||
|
@ -904,27 +908,27 @@ dummy_func(void) {
|
|||
sym_set_const(flag, Py_False);
|
||||
}
|
||||
|
||||
op(_GUARD_IS_NONE_POP, (flag -- )) {
|
||||
if (sym_is_const(ctx, flag)) {
|
||||
PyObject *value = sym_get_const(ctx, flag);
|
||||
op(_GUARD_IS_NONE_POP, (val -- )) {
|
||||
if (sym_is_const(ctx, val)) {
|
||||
PyObject *value = sym_get_const(ctx, val);
|
||||
assert(value != NULL);
|
||||
eliminate_pop_guard(this_instr, !Py_IsNone(value));
|
||||
}
|
||||
else if (sym_has_type(flag)) {
|
||||
assert(!sym_matches_type(flag, &_PyNone_Type));
|
||||
else if (sym_has_type(val)) {
|
||||
assert(!sym_matches_type(val, &_PyNone_Type));
|
||||
eliminate_pop_guard(this_instr, true);
|
||||
}
|
||||
sym_set_const(flag, Py_None);
|
||||
sym_set_const(val, Py_None);
|
||||
}
|
||||
|
||||
op(_GUARD_IS_NOT_NONE_POP, (flag -- )) {
|
||||
if (sym_is_const(ctx, flag)) {
|
||||
PyObject *value = sym_get_const(ctx, flag);
|
||||
op(_GUARD_IS_NOT_NONE_POP, (val -- )) {
|
||||
if (sym_is_const(ctx, val)) {
|
||||
PyObject *value = sym_get_const(ctx, val);
|
||||
assert(value != NULL);
|
||||
eliminate_pop_guard(this_instr, Py_IsNone(value));
|
||||
}
|
||||
else if (sym_has_type(flag)) {
|
||||
assert(!sym_matches_type(flag, &_PyNone_Type));
|
||||
else if (sym_has_type(val)) {
|
||||
assert(!sym_matches_type(val, &_PyNone_Type));
|
||||
eliminate_pop_guard(this_instr, false);
|
||||
}
|
||||
}
|
||||
|
@ -969,7 +973,7 @@ dummy_func(void) {
|
|||
list = sym_new_type(ctx, &PyList_Type);
|
||||
}
|
||||
|
||||
op(_BUILD_SLICE, (values[oparg] -- slice)) {
|
||||
op(_BUILD_SLICE, (args[oparg] -- slice)) {
|
||||
slice = sym_new_type(ctx, &PySlice_Type);
|
||||
}
|
||||
|
||||
|
@ -977,7 +981,7 @@ dummy_func(void) {
|
|||
map = sym_new_type(ctx, &PyDict_Type);
|
||||
}
|
||||
|
||||
op(_BUILD_STRING, (values[oparg] -- str)) {
|
||||
op(_BUILD_STRING, (pieces[oparg] -- str)) {
|
||||
str = sym_new_type(ctx, &PyUnicode_Type);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue