aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/optimizer_cases.c.h
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2025-05-22 11:15:03 -0400
committerGitHub <noreply@github.com>2025-05-22 11:15:03 -0400
commitec736e7daec33cb3383865895d7ab92d4ada8bc9 (patch)
tree18b8894a74a83c08eb1da2e8cd1b71eccd95025a /Python/optimizer_cases.c.h
parent09e72cf091d03479eddcb3c4526f5c6af56d31a0 (diff)
downloadcpython-ec736e7daec33cb3383865895d7ab92d4ada8bc9.tar.gz
cpython-ec736e7daec33cb3383865895d7ab92d4ada8bc9.zip
GH-131798: Optimize cached class attributes and methods in the JIT (GH-134403)
Diffstat (limited to 'Python/optimizer_cases.c.h')
-rw-r--r--Python/optimizer_cases.c.h74
1 files changed, 66 insertions, 8 deletions
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index 0ba45e1f58f..5a9fcf3b1b6 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -68,7 +68,7 @@
case _LOAD_CONST: {
JitOptSymbol *value;
- PyObject *val = PyTuple_GET_ITEM(co->co_consts, this_instr->oparg);
+ PyObject *val = PyTuple_GET_ITEM(co->co_consts, oparg);
REPLACE_OP(this_instr, _LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val);
value = sym_new_const(ctx, val);
stack_pointer[0] = value;
@@ -1174,7 +1174,7 @@
self_or_null = &stack_pointer[0];
(void)owner;
attr = sym_new_not_null(ctx);
- if (oparg &1) {
+ if (oparg & 1) {
self_or_null[0] = sym_new_unknown(ctx);
}
stack_pointer[-1] = attr;
@@ -1284,10 +1284,16 @@
}
case _LOAD_ATTR_CLASS: {
+ JitOptSymbol *owner;
JitOptSymbol *attr;
+ owner = stack_pointer[-1];
PyObject *descr = (PyObject *)this_instr->operand0;
- attr = sym_new_not_null(ctx);
(void)descr;
+ PyTypeObject *type = (PyTypeObject *)sym_get_const(ctx, owner);
+ PyObject *name = PyTuple_GET_ITEM(co->co_names, oparg >> 1);
+ attr = lookup_attr(ctx, this_instr, type, name,
+ _POP_TOP_LOAD_CONST_INLINE_BORROW,
+ _POP_TOP_LOAD_CONST_INLINE);
stack_pointer[-1] = attr;
break;
}
@@ -1701,7 +1707,11 @@
owner = stack_pointer[-1];
PyObject *descr = (PyObject *)this_instr->operand0;
(void)descr;
- attr = sym_new_not_null(ctx);
+ PyTypeObject *type = sym_get_type(owner);
+ PyObject *name = PyTuple_GET_ITEM(co->co_names, oparg >> 1);
+ attr = lookup_attr(ctx, this_instr, type, name,
+ _LOAD_CONST_UNDER_INLINE_BORROW,
+ _LOAD_CONST_UNDER_INLINE);
self = owner;
stack_pointer[-1] = attr;
stack_pointer[0] = self;
@@ -1717,7 +1727,11 @@
owner = stack_pointer[-1];
PyObject *descr = (PyObject *)this_instr->operand0;
(void)descr;
- attr = sym_new_not_null(ctx);
+ PyTypeObject *type = sym_get_type(owner);
+ PyObject *name = PyTuple_GET_ITEM(co->co_names, oparg >> 1);
+ attr = lookup_attr(ctx, this_instr, type, name,
+ _LOAD_CONST_UNDER_INLINE_BORROW,
+ _LOAD_CONST_UNDER_INLINE);
self = owner;
stack_pointer[-1] = attr;
stack_pointer[0] = self;
@@ -1727,15 +1741,31 @@
}
case _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES: {
+ JitOptSymbol *owner;
JitOptSymbol *attr;
- attr = sym_new_not_null(ctx);
+ owner = stack_pointer[-1];
+ PyObject *descr = (PyObject *)this_instr->operand0;
+ (void)descr;
+ PyTypeObject *type = sym_get_type(owner);
+ PyObject *name = PyTuple_GET_ITEM(co->co_names, oparg >> 1);
+ attr = lookup_attr(ctx, this_instr, type, name,
+ _POP_TOP_LOAD_CONST_INLINE_BORROW,
+ _POP_TOP_LOAD_CONST_INLINE);
stack_pointer[-1] = attr;
break;
}
case _LOAD_ATTR_NONDESCRIPTOR_NO_DICT: {
+ JitOptSymbol *owner;
JitOptSymbol *attr;
- attr = sym_new_not_null(ctx);
+ owner = stack_pointer[-1];
+ PyObject *descr = (PyObject *)this_instr->operand0;
+ (void)descr;
+ PyTypeObject *type = sym_get_type(owner);
+ PyObject *name = PyTuple_GET_ITEM(co->co_names, oparg >> 1);
+ attr = lookup_attr(ctx, this_instr, type, name,
+ _POP_TOP_LOAD_CONST_INLINE_BORROW,
+ _POP_TOP_LOAD_CONST_INLINE);
stack_pointer[-1] = attr;
break;
}
@@ -1751,7 +1781,11 @@
owner = stack_pointer[-1];
PyObject *descr = (PyObject *)this_instr->operand0;
(void)descr;
- attr = sym_new_not_null(ctx);
+ PyTypeObject *type = sym_get_type(owner);
+ PyObject *name = PyTuple_GET_ITEM(co->co_names, oparg >> 1);
+ attr = lookup_attr(ctx, this_instr, type, name,
+ _LOAD_CONST_UNDER_INLINE_BORROW,
+ _LOAD_CONST_UNDER_INLINE);
self = owner;
stack_pointer[-1] = attr;
stack_pointer[0] = self;
@@ -2594,6 +2628,30 @@
break;
}
+ case _LOAD_CONST_UNDER_INLINE: {
+ JitOptSymbol *value;
+ JitOptSymbol *new;
+ value = sym_new_not_null(ctx);
+ new = sym_new_not_null(ctx);
+ stack_pointer[-1] = value;
+ stack_pointer[0] = new;
+ stack_pointer += 1;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
+ case _LOAD_CONST_UNDER_INLINE_BORROW: {
+ JitOptSymbol *value;
+ JitOptSymbol *new;
+ value = sym_new_not_null(ctx);
+ new = sym_new_not_null(ctx);
+ stack_pointer[-1] = value;
+ stack_pointer[0] = new;
+ stack_pointer += 1;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
case _CHECK_FUNCTION: {
break;
}