summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c5
-rw-r--r--Python/executor_cases.c.h11
-rw-r--r--Python/optimizer_bytecodes.c61
-rw-r--r--Python/optimizer_cases.c.h73
4 files changed, 140 insertions, 10 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 1d51509..095982d 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -4043,6 +4043,11 @@ dummy_func(
value = ptr;
}
+ tier2 pure op (_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop -- value)) {
+ Py_DECREF(pop);
+ value = ptr;
+ }
+
tier2 pure op(_LOAD_CONST_INLINE_WITH_NULL, (ptr/4 -- value, null)) {
value = Py_NewRef(ptr);
null = NULL;
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index 9ec1be9..e84c332 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -3759,6 +3759,17 @@
break;
}
+ case _POP_TOP_LOAD_CONST_INLINE_BORROW: {
+ PyObject *pop;
+ PyObject *value;
+ pop = stack_pointer[-1];
+ PyObject *ptr = (PyObject *)CURRENT_OPERAND();
+ Py_DECREF(pop);
+ value = ptr;
+ stack_pointer[-1] = value;
+ break;
+ }
+
case _LOAD_CONST_INLINE_WITH_NULL: {
PyObject *value;
PyObject *null;
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index aa19a50..2b47381 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -254,6 +254,67 @@ dummy_func(void) {
}
}
+ op(_TO_BOOL, (value -- res)) {
+ (void)value;
+ res = sym_new_type(ctx, &PyBool_Type);
+ OUT_OF_SPACE_IF_NULL(res);
+ }
+
+ op(_TO_BOOL_BOOL, (value -- value)) {
+ if (sym_matches_type(value, &PyBool_Type)) {
+ REPLACE_OP(this_instr, _NOP, 0, 0);
+ }
+ else {
+ if(!sym_set_type(value, &PyBool_Type)) {
+ goto hit_bottom;
+ }
+ }
+ }
+
+ op(_TO_BOOL_INT, (value -- res)) {
+ if (sym_is_const(value) && sym_matches_type(value, &PyLong_Type)) {
+ PyObject *load = _PyLong_IsZero((PyLongObject *)sym_get_const(value))
+ ? Py_False : Py_True;
+ REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, load));
+ }
+ else {
+ OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+ }
+ if(!sym_set_type(value, &PyLong_Type)) {
+ goto hit_bottom;
+ }
+ }
+
+ op(_TO_BOOL_LIST, (value -- res)) {
+ if(!sym_set_type(value, &PyList_Type)) {
+ goto hit_bottom;
+ }
+ OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+ }
+
+ op(_TO_BOOL_NONE, (value -- res)) {
+ if (sym_get_const(value) == Py_None) {
+ REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_False);
+ }
+ sym_set_const(value, Py_None);
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, Py_False));
+ }
+
+ op(_TO_BOOL_STR, (value -- res)) {
+ if (sym_is_const(value) && sym_matches_type(value, &PyUnicode_Type)) {
+ PyObject *load = sym_get_const(value) == &_Py_STR(empty) ? Py_False : Py_True;
+ REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, load));
+ }
+ else {
+ OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+ }
+ if(!sym_set_type(value, &PyUnicode_Type)) {
+ goto hit_bottom;
+ }
+ }
+
op(_LOAD_CONST, (-- value)) {
// There should be no LOAD_CONST. It should be all
// replaced by peephole_opt.
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index b34c573..9d7ebb8 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -104,45 +104,90 @@
}
case _TO_BOOL: {
+ _Py_UopsSymbol *value;
_Py_UopsSymbol *res;
- res = sym_new_unknown(ctx);
- if (res == NULL) goto out_of_space;
+ value = stack_pointer[-1];
+ (void)value;
+ res = sym_new_type(ctx, &PyBool_Type);
+ OUT_OF_SPACE_IF_NULL(res);
stack_pointer[-1] = res;
break;
}
case _TO_BOOL_BOOL: {
+ _Py_UopsSymbol *value;
+ value = stack_pointer[-1];
+ if (sym_matches_type(value, &PyBool_Type)) {
+ REPLACE_OP(this_instr, _NOP, 0, 0);
+ }
+ else {
+ if(!sym_set_type(value, &PyBool_Type)) {
+ goto hit_bottom;
+ }
+ }
break;
}
case _TO_BOOL_INT: {
+ _Py_UopsSymbol *value;
_Py_UopsSymbol *res;
- res = sym_new_unknown(ctx);
- if (res == NULL) goto out_of_space;
+ value = stack_pointer[-1];
+ if (sym_is_const(value) && sym_matches_type(value, &PyLong_Type)) {
+ PyObject *load = _PyLong_IsZero((PyLongObject *)sym_get_const(value))
+ ? Py_False : Py_True;
+ REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, load));
+ }
+ else {
+ OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+ }
+ if(!sym_set_type(value, &PyLong_Type)) {
+ goto hit_bottom;
+ }
stack_pointer[-1] = res;
break;
}
case _TO_BOOL_LIST: {
+ _Py_UopsSymbol *value;
_Py_UopsSymbol *res;
- res = sym_new_unknown(ctx);
- if (res == NULL) goto out_of_space;
+ value = stack_pointer[-1];
+ if(!sym_set_type(value, &PyList_Type)) {
+ goto hit_bottom;
+ }
+ OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
stack_pointer[-1] = res;
break;
}
case _TO_BOOL_NONE: {
+ _Py_UopsSymbol *value;
_Py_UopsSymbol *res;
- res = sym_new_unknown(ctx);
- if (res == NULL) goto out_of_space;
+ value = stack_pointer[-1];
+ if (sym_get_const(value) == Py_None) {
+ REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_False);
+ }
+ sym_set_const(value, Py_None);
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, Py_False));
stack_pointer[-1] = res;
break;
}
case _TO_BOOL_STR: {
+ _Py_UopsSymbol *value;
_Py_UopsSymbol *res;
- res = sym_new_unknown(ctx);
- if (res == NULL) goto out_of_space;
+ value = stack_pointer[-1];
+ if (sym_is_const(value) && sym_matches_type(value, &PyUnicode_Type)) {
+ PyObject *load = sym_get_const(value) == &_Py_STR(empty) ? Py_False : Py_True;
+ REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, load));
+ }
+ else {
+ OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+ }
+ if(!sym_set_type(value, &PyUnicode_Type)) {
+ goto hit_bottom;
+ }
stack_pointer[-1] = res;
break;
}
@@ -1789,6 +1834,14 @@
break;
}
+ case _POP_TOP_LOAD_CONST_INLINE_BORROW: {
+ _Py_UopsSymbol *value;
+ value = sym_new_unknown(ctx);
+ if (value == NULL) goto out_of_space;
+ stack_pointer[-1] = value;
+ break;
+ }
+
case _LOAD_CONST_INLINE_WITH_NULL: {
_Py_UopsSymbol *value;
_Py_UopsSymbol *null;