gh-148211: decompose _INSERT_1_LOAD_CONST_INLINE(_BORROW) in JIT (GH-148283)

This commit is contained in:
Neko Asakura 2026-04-10 00:45:39 +08:00 committed by GitHub
parent d8c5658156
commit 0f49232664
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 1182 additions and 1372 deletions

View file

@ -55,7 +55,7 @@ optimize_to_bool(
JitOptContext *ctx,
JitOptSymbol *value,
JitOptSymbol **result_ptr,
bool insert_mode);
uint16_t prefix, uint16_t suffix);
extern void
eliminate_pop_guard(_PyUOpInstruction *this_instr, JitOptContext *ctx, bool exit);
@ -537,7 +537,7 @@ dummy_func(void) {
op(_TO_BOOL, (value -- res)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
_POP_TOP, _LOAD_CONST_INLINE_BORROW);
_POP_TOP, _NOP);
if (!already_bool) {
res = sym_new_truthiness(ctx, value, true);
}
@ -545,7 +545,7 @@ dummy_func(void) {
op(_TO_BOOL_BOOL, (value -- value)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &value,
_POP_TOP, _LOAD_CONST_INLINE_BORROW);
_POP_TOP, _NOP);
if (!already_bool) {
sym_set_type(value, &PyBool_Type);
}
@ -553,7 +553,7 @@ dummy_func(void) {
op(_TO_BOOL_INT, (value -- res, v)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
_NOP, _INSERT_1_LOAD_CONST_INLINE_BORROW);
_NOP, _SWAP);
if (!already_bool) {
sym_set_type(value, &PyLong_Type);
res = sym_new_truthiness(ctx, value, true);
@ -563,7 +563,7 @@ dummy_func(void) {
op(_TO_BOOL_LIST, (value -- res, v)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
_NOP, _INSERT_1_LOAD_CONST_INLINE_BORROW);
_NOP, _SWAP);
if (!already_bool) {
res = sym_new_type(ctx, &PyBool_Type);
}
@ -572,7 +572,7 @@ dummy_func(void) {
op(_TO_BOOL_NONE, (value -- res)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
_POP_TOP, _LOAD_CONST_INLINE_BORROW);
_POP_TOP, _NOP);
if (!already_bool) {
sym_set_const(value, Py_None);
res = sym_new_const(ctx, Py_False);
@ -599,7 +599,7 @@ dummy_func(void) {
op(_TO_BOOL_STR, (value -- res, v)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
_NOP, _INSERT_1_LOAD_CONST_INLINE_BORROW);
_NOP, _SWAP);
v = value;
if (!already_bool) {
res = sym_new_truthiness(ctx, value, true);
@ -843,12 +843,15 @@ dummy_func(void) {
if (watched_mutations < _Py_MAX_ALLOWED_GLOBALS_MODIFICATIONS) {
PyDict_Watch(GLOBALS_WATCHER_ID, dict);
_Py_BloomFilter_Add(dependencies, dict);
PyObject *res = convert_global_to_const(this_instr, dict,
_INSERT_1_LOAD_CONST_INLINE_BORROW, _INSERT_1_LOAD_CONST_INLINE);
PyObject *res = convert_global_to_const(this_instr, dict);
if (res == NULL) {
attr = sym_new_not_null(ctx);
}
else {
bool immortal = _Py_IsImmortal(res);
ADD_OP(immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE,
0, (uintptr_t)res);
ADD_OP(_SWAP, 2, 0);
attr = sym_new_const(ctx, res);
}
@ -897,7 +900,7 @@ dummy_func(void) {
PyTypeObject *type = (PyTypeObject *)sym_get_const(ctx, owner);
PyObject *name = get_co_name(ctx, oparg >> 1);
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
_POP_TOP, _LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE);
_POP_TOP, _NOP);
}
op(_LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES, (descr/4, owner -- attr)) {
@ -905,7 +908,7 @@ dummy_func(void) {
PyTypeObject *type = sym_get_type(owner);
PyObject *name = get_co_name(ctx, oparg >> 1);
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
_POP_TOP, _LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE);
_POP_TOP, _NOP);
}
op(_LOAD_ATTR_NONDESCRIPTOR_NO_DICT, (descr/4, owner -- attr)) {
@ -913,7 +916,7 @@ dummy_func(void) {
PyTypeObject *type = sym_get_type(owner);
PyObject *name = get_co_name(ctx, oparg >> 1);
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
_POP_TOP, _LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE);
_POP_TOP, _NOP);
}
op(_LOAD_ATTR_METHOD_WITH_VALUES, (descr/4, owner -- attr, self)) {
@ -921,7 +924,7 @@ dummy_func(void) {
PyTypeObject *type = sym_get_type(owner);
PyObject *name = get_co_name(ctx, oparg >> 1);
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
_NOP, _INSERT_1_LOAD_CONST_INLINE_BORROW, _INSERT_1_LOAD_CONST_INLINE);
_NOP, _SWAP);
self = owner;
}
@ -930,7 +933,7 @@ dummy_func(void) {
PyTypeObject *type = sym_get_type(owner);
PyObject *name = get_co_name(ctx, oparg >> 1);
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
_NOP, _INSERT_1_LOAD_CONST_INLINE_BORROW, _INSERT_1_LOAD_CONST_INLINE);
_NOP, _SWAP);
self = owner;
}
@ -939,7 +942,7 @@ dummy_func(void) {
PyTypeObject *type = sym_get_type(owner);
PyObject *name = get_co_name(ctx, oparg >> 1);
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
_NOP, _INSERT_1_LOAD_CONST_INLINE_BORROW, _INSERT_1_LOAD_CONST_INLINE);
_NOP, _SWAP);
self = owner;
}
@ -967,8 +970,8 @@ dummy_func(void) {
PyObject *name = get_co_name(ctx, oparg >> 2);
attr = lookup_super_attr(ctx, dependencies, this_instr,
su_type, obj_type, name,
_INSERT_1_LOAD_CONST_INLINE_BORROW,
_INSERT_1_LOAD_CONST_INLINE);
_LOAD_CONST_INLINE_BORROW,
_LOAD_CONST_INLINE, _SWAP);
}
op(_LOAD_ATTR_PROPERTY_FRAME, (fget/4, owner -- new_frame)) {
@ -1642,7 +1645,8 @@ dummy_func(void) {
}
op(_REPLACE_WITH_TRUE, (value -- res, v)) {
ADD_OP(_INSERT_1_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_True);
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_True);
ADD_OP(_SWAP, 2, 0);
res = sym_new_const(ctx, Py_True);
v = value;
}
@ -2042,8 +2046,7 @@ dummy_func(void) {
ctx->builtins_watched = true;
}
if (ctx->frame->globals_checked_version != 0 && ctx->frame->globals_watched) {
cnst = convert_global_to_const(this_instr, builtins,
_LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE);
cnst = convert_global_to_const(this_instr, builtins);
}
}
if (cnst == NULL) {
@ -2082,8 +2085,7 @@ dummy_func(void) {
ctx->frame->globals_checked_version = version;
}
if (ctx->frame->globals_checked_version == version) {
cnst = convert_global_to_const(this_instr, globals,
_LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE);
cnst = convert_global_to_const(this_instr, globals);
}
}
}