aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/optimizer_cases.c.h
diff options
context:
space:
mode:
Diffstat (limited to 'Python/optimizer_cases.c.h')
-rw-r--r--Python/optimizer_cases.c.h238
1 files changed, 212 insertions, 26 deletions
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index deb912662e4..db86edcc785 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -66,23 +66,9 @@
break;
}
- /* _LOAD_CONST is not a viable micro-op for tier 2 */
-
- case _LOAD_CONST_MORTAL: {
- JitOptSymbol *value;
- PyObject *val = PyTuple_GET_ITEM(co->co_consts, this_instr->oparg);
- int opcode = _Py_IsImmortal(val) ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE;
- REPLACE_OP(this_instr, opcode, 0, (uintptr_t)val);
- value = sym_new_const(ctx, val);
- stack_pointer[0] = value;
- stack_pointer += 1;
- assert(WITHIN_STACK_BOUNDS());
- break;
- }
-
- case _LOAD_CONST_IMMORTAL: {
+ 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;
@@ -93,7 +79,10 @@
case _LOAD_SMALL_INT: {
JitOptSymbol *value;
- PyObject *val = PyLong_FromLong(this_instr->oparg);
+ PyObject *val = PyLong_FromLong(oparg);
+ assert(val);
+ assert(_Py_IsImmortal(val));
+ REPLACE_OP(this_instr, _LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val);
value = sym_new_const(ctx, val);
stack_pointer[0] = value;
stack_pointer += 1;
@@ -116,6 +105,12 @@
break;
}
+ case _POP_TWO: {
+ stack_pointer += -2;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
case _PUSH_NULL: {
JitOptSymbol *res;
res = sym_new_null(ctx);
@@ -131,6 +126,12 @@
break;
}
+ case _POP_ITER: {
+ stack_pointer += -2;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
case _END_SEND: {
JitOptSymbol *val;
val = sym_new_not_null(ctx);
@@ -1179,7 +1180,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;
@@ -1273,14 +1274,32 @@
}
case _CHECK_ATTR_CLASS: {
+ JitOptSymbol *owner;
+ owner = stack_pointer[-1];
+ uint32_t type_version = (uint32_t)this_instr->operand0;
+ PyObject *type = (PyObject *)_PyType_LookupByVersion(type_version);
+ if (type) {
+ if (type == sym_get_const(ctx, owner)) {
+ REPLACE_OP(this_instr, _NOP, 0, 0);
+ }
+ else {
+ sym_set_const(owner, type);
+ }
+ }
break;
}
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;
}
@@ -1477,8 +1496,29 @@
}
case _GET_LEN: {
+ JitOptSymbol *obj;
JitOptSymbol *len;
- len = sym_new_not_null(ctx);
+ obj = stack_pointer[-1];
+ int tuple_length = sym_tuple_length(obj);
+ if (tuple_length == -1) {
+ len = sym_new_type(ctx, &PyLong_Type);
+ }
+ else {
+ assert(tuple_length >= 0);
+ PyObject *temp = PyLong_FromLong(tuple_length);
+ if (temp == NULL) {
+ goto error;
+ }
+ if (_Py_IsImmortal(temp)) {
+ REPLACE_OP(this_instr, _LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)temp);
+ }
+ len = sym_new_const(ctx, temp);
+ stack_pointer[0] = len;
+ stack_pointer += 1;
+ assert(WITHIN_STACK_BOUNDS());
+ Py_DECREF(temp);
+ stack_pointer += -1;
+ }
stack_pointer[0] = len;
stack_pointer += 1;
assert(WITHIN_STACK_BOUNDS());
@@ -1523,8 +1563,13 @@
case _GET_ITER: {
JitOptSymbol *iter;
+ JitOptSymbol *index_or_null;
iter = sym_new_not_null(ctx);
+ index_or_null = sym_new_not_null(ctx);
stack_pointer[-1] = iter;
+ stack_pointer[0] = index_or_null;
+ stack_pointer += 1;
+ assert(WITHIN_STACK_BOUNDS());
break;
}
@@ -1570,6 +1615,12 @@
}
case _ITER_CHECK_TUPLE: {
+ JitOptSymbol *iter;
+ iter = stack_pointer[-2];
+ if (sym_matches_type(iter, &PyTuple_Type)) {
+ REPLACE_OP(this_instr, _NOP, 0, 0);
+ }
+ sym_set_type(iter, &PyTuple_Type);
break;
}
@@ -1673,7 +1724,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;
@@ -1689,7 +1744,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;
@@ -1699,15 +1758,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;
}
@@ -1723,7 +1798,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;
@@ -1935,6 +2014,16 @@
break;
}
+ case _GUARD_NOS_NOT_NULL: {
+ JitOptSymbol *nos;
+ nos = stack_pointer[-2];
+ if (sym_is_not_null(nos)) {
+ REPLACE_OP(this_instr, _NOP, 0, 0);
+ }
+ sym_set_non_null(nos);
+ break;
+ }
+
case _GUARD_THIRD_NULL: {
JitOptSymbol *null;
null = stack_pointer[-3];
@@ -2124,14 +2213,39 @@
}
case _CALL_ISINSTANCE: {
+ JitOptSymbol *cls;
+ JitOptSymbol *instance;
JitOptSymbol *res;
- res = sym_new_not_null(ctx);
+ cls = stack_pointer[-1];
+ instance = stack_pointer[-2];
+ res = sym_new_type(ctx, &PyBool_Type);
+ PyTypeObject *inst_type = sym_get_type(instance);
+ PyTypeObject *cls_o = (PyTypeObject *)sym_get_const(ctx, cls);
+ if (inst_type && cls_o && sym_matches_type(cls, &PyType_Type)) {
+ PyObject *out = Py_False;
+ if (inst_type == cls_o || PyType_IsSubtype(inst_type, cls_o)) {
+ out = Py_True;
+ }
+ sym_set_const(res, out);
+ REPLACE_OP(this_instr, _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)out);
+ }
stack_pointer[-4] = res;
stack_pointer += -3;
assert(WITHIN_STACK_BOUNDS());
break;
}
+ case _GUARD_CALLABLE_LIST_APPEND: {
+ JitOptSymbol *callable;
+ callable = stack_pointer[-3];
+ PyObject *list_append = _PyInterpreterState_GET()->callable_cache.list_append;
+ if (sym_get_const(ctx, callable) == list_append) {
+ REPLACE_OP(this_instr, _NOP, 0, 0);
+ }
+ sym_set_const(callable, list_append);
+ break;
+ }
+
case _CALL_LIST_APPEND: {
stack_pointer += -3;
assert(WITHIN_STACK_BOUNDS());
@@ -2504,6 +2618,24 @@
break;
}
+ case _POP_CALL: {
+ stack_pointer += -2;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
+ case _POP_CALL_ONE: {
+ stack_pointer += -3;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
+ case _POP_CALL_TWO: {
+ stack_pointer += -4;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
case _POP_TOP_LOAD_CONST_INLINE_BORROW: {
JitOptSymbol *value;
PyObject *ptr = (PyObject *)this_instr->operand0;
@@ -2521,6 +2653,60 @@
break;
}
+ case _POP_CALL_LOAD_CONST_INLINE_BORROW: {
+ JitOptSymbol *value;
+ PyObject *ptr = (PyObject *)this_instr->operand0;
+ value = sym_new_const(ctx, ptr);
+ stack_pointer[-2] = value;
+ stack_pointer += -1;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
+ case _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW: {
+ JitOptSymbol *value;
+ PyObject *ptr = (PyObject *)this_instr->operand0;
+ value = sym_new_const(ctx, ptr);
+ stack_pointer[-3] = value;
+ stack_pointer += -2;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
+ case _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW: {
+ JitOptSymbol *value;
+ PyObject *ptr = (PyObject *)this_instr->operand0;
+ value = sym_new_const(ctx, ptr);
+ stack_pointer[-4] = value;
+ stack_pointer += -3;
+ assert(WITHIN_STACK_BOUNDS());
+ 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;
}