mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-120619: Strength reduce function guards, support 2-operand uop forms (GH-124846)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
parent
f8276bf5f3
commit
6293d00e72
17 changed files with 379 additions and 270 deletions
69
Python/optimizer_cases.c.h
generated
69
Python/optimizer_cases.c.h
generated
|
@ -525,7 +525,7 @@
|
|||
res = sym_new_type(ctx, &PyUnicode_Type);
|
||||
}
|
||||
// _STORE_FAST:
|
||||
GETLOCAL(this_instr->operand) = res;
|
||||
GETLOCAL(this_instr->operand0) = res;
|
||||
stack_pointer += -2;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
break;
|
||||
|
@ -888,7 +888,7 @@
|
|||
|
||||
case _GUARD_GLOBALS_VERSION_PUSH_KEYS: {
|
||||
_Py_UopsSymbol *globals_keys;
|
||||
uint16_t version = (uint16_t)this_instr->operand;
|
||||
uint16_t version = (uint16_t)this_instr->operand0;
|
||||
globals_keys = sym_new_unknown(ctx);
|
||||
(void)version;
|
||||
stack_pointer[0] = globals_keys;
|
||||
|
@ -899,7 +899,7 @@
|
|||
|
||||
case _GUARD_BUILTINS_VERSION_PUSH_KEYS: {
|
||||
_Py_UopsSymbol *builtins_keys;
|
||||
uint16_t version = (uint16_t)this_instr->operand;
|
||||
uint16_t version = (uint16_t)this_instr->operand0;
|
||||
builtins_keys = sym_new_unknown(ctx);
|
||||
(void)version;
|
||||
stack_pointer[0] = builtins_keys;
|
||||
|
@ -1090,7 +1090,7 @@
|
|||
case _GUARD_TYPE_VERSION: {
|
||||
_Py_UopsSymbol *owner;
|
||||
owner = stack_pointer[-1];
|
||||
uint32_t type_version = (uint32_t)this_instr->operand;
|
||||
uint32_t type_version = (uint32_t)this_instr->operand0;
|
||||
assert(type_version);
|
||||
if (sym_matches_type_version(owner, type_version)) {
|
||||
REPLACE_OP(this_instr, _NOP, 0, 0);
|
||||
|
@ -1122,7 +1122,7 @@
|
|||
_Py_UopsSymbol *attr;
|
||||
_Py_UopsSymbol *null = NULL;
|
||||
owner = stack_pointer[-1];
|
||||
uint16_t offset = (uint16_t)this_instr->operand;
|
||||
uint16_t offset = (uint16_t)this_instr->operand0;
|
||||
attr = sym_new_not_null(ctx);
|
||||
null = sym_new_null(ctx);
|
||||
(void)offset;
|
||||
|
@ -1137,7 +1137,7 @@
|
|||
case _CHECK_ATTR_MODULE: {
|
||||
_Py_UopsSymbol *owner;
|
||||
owner = stack_pointer[-1];
|
||||
uint32_t dict_version = (uint32_t)this_instr->operand;
|
||||
uint32_t dict_version = (uint32_t)this_instr->operand0;
|
||||
(void)dict_version;
|
||||
if (sym_is_const(owner)) {
|
||||
PyObject *cnst = sym_get_const(owner);
|
||||
|
@ -1160,7 +1160,7 @@
|
|||
_Py_UopsSymbol *attr;
|
||||
_Py_UopsSymbol *null = NULL;
|
||||
owner = stack_pointer[-1];
|
||||
uint16_t index = (uint16_t)this_instr->operand;
|
||||
uint16_t index = (uint16_t)this_instr->operand0;
|
||||
(void)index;
|
||||
null = sym_new_null(ctx);
|
||||
attr = NULL;
|
||||
|
@ -1202,7 +1202,7 @@
|
|||
_Py_UopsSymbol *attr;
|
||||
_Py_UopsSymbol *null = NULL;
|
||||
owner = stack_pointer[-1];
|
||||
uint16_t hint = (uint16_t)this_instr->operand;
|
||||
uint16_t hint = (uint16_t)this_instr->operand0;
|
||||
attr = sym_new_not_null(ctx);
|
||||
null = sym_new_null(ctx);
|
||||
(void)hint;
|
||||
|
@ -1219,7 +1219,7 @@
|
|||
_Py_UopsSymbol *attr;
|
||||
_Py_UopsSymbol *null = NULL;
|
||||
owner = stack_pointer[-1];
|
||||
uint16_t index = (uint16_t)this_instr->operand;
|
||||
uint16_t index = (uint16_t)this_instr->operand0;
|
||||
attr = sym_new_not_null(ctx);
|
||||
null = sym_new_null(ctx);
|
||||
(void)index;
|
||||
|
@ -1240,7 +1240,7 @@
|
|||
_Py_UopsSymbol *attr;
|
||||
_Py_UopsSymbol *null = NULL;
|
||||
owner = stack_pointer[-1];
|
||||
PyObject *descr = (PyObject *)this_instr->operand;
|
||||
PyObject *descr = (PyObject *)this_instr->operand0;
|
||||
attr = sym_new_not_null(ctx);
|
||||
null = sym_new_null(ctx);
|
||||
(void)descr;
|
||||
|
@ -1256,7 +1256,7 @@
|
|||
_Py_UopsSymbol *owner;
|
||||
_Py_UOpsAbstractFrame *new_frame;
|
||||
owner = stack_pointer[-1];
|
||||
PyObject *fget = (PyObject *)this_instr->operand;
|
||||
PyObject *fget = (PyObject *)this_instr->operand0;
|
||||
(void)fget;
|
||||
(void)owner;
|
||||
new_frame = NULL;
|
||||
|
@ -1639,7 +1639,7 @@
|
|||
_Py_UopsSymbol *attr;
|
||||
_Py_UopsSymbol *self = NULL;
|
||||
owner = stack_pointer[-1];
|
||||
PyObject *descr = (PyObject *)this_instr->operand;
|
||||
PyObject *descr = (PyObject *)this_instr->operand0;
|
||||
(void)descr;
|
||||
attr = sym_new_not_null(ctx);
|
||||
self = owner;
|
||||
|
@ -1655,7 +1655,7 @@
|
|||
_Py_UopsSymbol *attr;
|
||||
_Py_UopsSymbol *self = NULL;
|
||||
owner = stack_pointer[-1];
|
||||
PyObject *descr = (PyObject *)this_instr->operand;
|
||||
PyObject *descr = (PyObject *)this_instr->operand0;
|
||||
(void)descr;
|
||||
attr = sym_new_not_null(ctx);
|
||||
self = owner;
|
||||
|
@ -1689,7 +1689,7 @@
|
|||
_Py_UopsSymbol *attr;
|
||||
_Py_UopsSymbol *self = NULL;
|
||||
owner = stack_pointer[-1];
|
||||
PyObject *descr = (PyObject *)this_instr->operand;
|
||||
PyObject *descr = (PyObject *)this_instr->operand0;
|
||||
(void)descr;
|
||||
attr = sym_new_not_null(ctx);
|
||||
self = owner;
|
||||
|
@ -1749,6 +1749,22 @@
|
|||
}
|
||||
|
||||
case _CHECK_FUNCTION_VERSION: {
|
||||
_Py_UopsSymbol *self_or_null;
|
||||
_Py_UopsSymbol *callable;
|
||||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
uint32_t func_version = (uint32_t)this_instr->operand0;
|
||||
(void)self_or_null;
|
||||
if (sym_is_const(callable) && sym_matches_type(callable, &PyFunction_Type)) {
|
||||
assert(PyFunction_Check(sym_get_const(callable)));
|
||||
REPLACE_OP(this_instr, _CHECK_FUNCTION_VERSION_INLINE, 0, func_version);
|
||||
this_instr->operand1 = (uintptr_t)sym_get_const(callable);
|
||||
}
|
||||
sym_set_type(callable, &PyFunction_Type);
|
||||
break;
|
||||
}
|
||||
|
||||
case _CHECK_FUNCTION_VERSION_INLINE: {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1816,7 +1832,16 @@
|
|||
_Py_UopsSymbol *callable;
|
||||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
sym_set_type(callable, &PyFunction_Type);
|
||||
assert(sym_matches_type(callable, &PyFunction_Type));
|
||||
if (sym_is_const(callable)) {
|
||||
if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
|
||||
PyFunctionObject *func = (PyFunctionObject *)sym_get_const(callable);
|
||||
PyCodeObject *co = (PyCodeObject *)func->func_code;
|
||||
if (co->co_argcount == oparg + !sym_is_null(self_or_null)) {
|
||||
REPLACE_OP(this_instr, _NOP, 0 ,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
(void)self_or_null;
|
||||
break;
|
||||
}
|
||||
|
@ -1939,7 +1964,7 @@
|
|||
null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
args = &stack_pointer[-oparg];
|
||||
uint32_t type_version = (uint32_t)this_instr->operand;
|
||||
uint32_t type_version = (uint32_t)this_instr->operand0;
|
||||
(void)type_version;
|
||||
(void)callable;
|
||||
(void)null;
|
||||
|
@ -2399,7 +2424,7 @@
|
|||
}
|
||||
|
||||
case _CHECK_STACK_SPACE_OPERAND: {
|
||||
uint32_t framesize = (uint32_t)this_instr->operand;
|
||||
uint32_t framesize = (uint32_t)this_instr->operand0;
|
||||
(void)framesize;
|
||||
/* We should never see _CHECK_STACK_SPACE_OPERANDs.
|
||||
* They are only created at the end of this pass. */
|
||||
|
@ -2412,7 +2437,7 @@
|
|||
}
|
||||
|
||||
case _EXIT_TRACE: {
|
||||
PyObject *exit_p = (PyObject *)this_instr->operand;
|
||||
PyObject *exit_p = (PyObject *)this_instr->operand0;
|
||||
(void)exit_p;
|
||||
ctx->done = true;
|
||||
break;
|
||||
|
@ -2424,7 +2449,7 @@
|
|||
|
||||
case _LOAD_CONST_INLINE: {
|
||||
_Py_UopsSymbol *value;
|
||||
PyObject *ptr = (PyObject *)this_instr->operand;
|
||||
PyObject *ptr = (PyObject *)this_instr->operand0;
|
||||
value = sym_new_const(ctx, ptr);
|
||||
stack_pointer[0] = value;
|
||||
stack_pointer += 1;
|
||||
|
@ -2434,7 +2459,7 @@
|
|||
|
||||
case _LOAD_CONST_INLINE_BORROW: {
|
||||
_Py_UopsSymbol *value;
|
||||
PyObject *ptr = (PyObject *)this_instr->operand;
|
||||
PyObject *ptr = (PyObject *)this_instr->operand0;
|
||||
value = sym_new_const(ctx, ptr);
|
||||
stack_pointer[0] = value;
|
||||
stack_pointer += 1;
|
||||
|
@ -2452,7 +2477,7 @@
|
|||
case _LOAD_CONST_INLINE_WITH_NULL: {
|
||||
_Py_UopsSymbol *value;
|
||||
_Py_UopsSymbol *null;
|
||||
PyObject *ptr = (PyObject *)this_instr->operand;
|
||||
PyObject *ptr = (PyObject *)this_instr->operand0;
|
||||
value = sym_new_const(ctx, ptr);
|
||||
null = sym_new_null(ctx);
|
||||
stack_pointer[0] = value;
|
||||
|
@ -2465,7 +2490,7 @@
|
|||
case _LOAD_CONST_INLINE_BORROW_WITH_NULL: {
|
||||
_Py_UopsSymbol *value;
|
||||
_Py_UopsSymbol *null;
|
||||
PyObject *ptr = (PyObject *)this_instr->operand;
|
||||
PyObject *ptr = (PyObject *)this_instr->operand0;
|
||||
value = sym_new_const(ctx, ptr);
|
||||
null = sym_new_null(ctx);
|
||||
stack_pointer[0] = value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue