summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/optimizer.c4
-rw-r--r--Python/optimizer_analysis.c10
-rw-r--r--Python/optimizer_bytecodes.c43
-rw-r--r--Python/optimizer_cases.c.h42
-rw-r--r--Python/optimizer_symbols.c2
5 files changed, 74 insertions, 27 deletions
diff --git a/Python/optimizer.c b/Python/optimizer.c
index c04ee17..acd6d52 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -1008,8 +1008,8 @@ uop_optimize(
return err;
}
OPT_STAT_INC(traces_created);
- char *uop_optimize = Py_GETENV("PYTHONUOPSOPTIMIZE");
- if (uop_optimize == NULL || *uop_optimize > '0') {
+ char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
+ if (env_var == NULL || *env_var == '\0' || *env_var > '0') {
err = _Py_uop_analyze_and_optimize(frame, buffer,
UOP_MAX_TRACE_LENGTH,
curr_stackentries, &dependencies);
diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index 8e408ff..2a7ef4e 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -297,6 +297,7 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
#define sym_set_non_null _Py_uop_sym_set_non_null
#define sym_set_type _Py_uop_sym_set_type
#define sym_set_const _Py_uop_sym_set_const
+#define sym_is_bottom _Py_uop_sym_is_bottom
#define frame_new _Py_uop_frame_new
#define frame_pop _Py_uop_frame_pop
@@ -510,12 +511,9 @@ _Py_uop_analyze_and_optimize(
peephole_opt(frame, buffer, buffer_size);
- char *uop_optimize = Py_GETENV("PYTHONUOPSOPTIMIZE");
- if (uop_optimize != NULL && *uop_optimize > '0') {
- err = optimize_uops(
- (PyCodeObject *)frame->f_executable, buffer,
- buffer_size, curr_stacklen, dependencies);
- }
+ err = optimize_uops(
+ (PyCodeObject *)frame->f_executable, buffer,
+ buffer_size, curr_stacklen, dependencies);
if (err == 0) {
goto not_ready;
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index b65e90b..928c22d 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -25,6 +25,7 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
#define sym_set_non_null _Py_uop_sym_set_non_null
#define sym_set_type _Py_uop_sym_set_type
#define sym_set_const _Py_uop_sym_set_const
+#define sym_is_bottom _Py_uop_sym_is_bottom
#define frame_new _Py_uop_frame_new
#define frame_pop _Py_uop_frame_pop
@@ -107,7 +108,9 @@ dummy_func(void) {
}
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
+ {
assert(PyLong_CheckExact(sym_get_const(left)));
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Add((PyLongObject *)sym_get_const(left),
@@ -115,7 +118,9 @@ dummy_func(void) {
if (temp == NULL) {
goto error;
}
- OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
}
@@ -125,7 +130,9 @@ dummy_func(void) {
}
op(_BINARY_OP_SUBTRACT_INT, (left, right -- res)) {
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
+ {
assert(PyLong_CheckExact(sym_get_const(left)));
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(left),
@@ -133,7 +140,9 @@ dummy_func(void) {
if (temp == NULL) {
goto error;
}
- OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
}
@@ -143,7 +152,9 @@ dummy_func(void) {
}
op(_BINARY_OP_MULTIPLY_INT, (left, right -- res)) {
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
+ {
assert(PyLong_CheckExact(sym_get_const(left)));
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(left),
@@ -151,7 +162,9 @@ dummy_func(void) {
if (temp == NULL) {
goto error;
}
- OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
}
@@ -161,7 +174,9 @@ dummy_func(void) {
}
op(_BINARY_OP_ADD_FLOAT, (left, right -- res)) {
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
+ {
assert(PyFloat_CheckExact(sym_get_const(left)));
assert(PyFloat_CheckExact(sym_get_const(right)));
PyObject *temp = PyFloat_FromDouble(
@@ -171,6 +186,8 @@ dummy_func(void) {
goto error;
}
res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
@@ -180,7 +197,9 @@ dummy_func(void) {
}
op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res)) {
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
+ {
assert(PyFloat_CheckExact(sym_get_const(left)));
assert(PyFloat_CheckExact(sym_get_const(right)));
PyObject *temp = PyFloat_FromDouble(
@@ -190,6 +209,8 @@ dummy_func(void) {
goto error;
}
res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
@@ -199,7 +220,9 @@ dummy_func(void) {
}
op(_BINARY_OP_MULTIPLY_FLOAT, (left, right -- res)) {
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
+ {
assert(PyFloat_CheckExact(sym_get_const(left)));
assert(PyFloat_CheckExact(sym_get_const(right)));
PyObject *temp = PyFloat_FromDouble(
@@ -209,6 +232,8 @@ dummy_func(void) {
goto error;
}
res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index 9e99c83..9b387c0 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -183,7 +183,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
+ {
assert(PyLong_CheckExact(sym_get_const(left)));
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(left),
@@ -191,7 +193,9 @@
if (temp == NULL) {
goto error;
}
- OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
}
@@ -209,7 +213,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
+ {
assert(PyLong_CheckExact(sym_get_const(left)));
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Add((PyLongObject *)sym_get_const(left),
@@ -217,7 +223,9 @@
if (temp == NULL) {
goto error;
}
- OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
}
@@ -235,7 +243,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
+ {
assert(PyLong_CheckExact(sym_get_const(left)));
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(left),
@@ -243,7 +253,9 @@
if (temp == NULL) {
goto error;
}
- OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
}
@@ -275,7 +287,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
+ {
assert(PyFloat_CheckExact(sym_get_const(left)));
assert(PyFloat_CheckExact(sym_get_const(right)));
PyObject *temp = PyFloat_FromDouble(
@@ -285,6 +299,8 @@
goto error;
}
res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
@@ -302,7 +318,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
+ {
assert(PyFloat_CheckExact(sym_get_const(left)));
assert(PyFloat_CheckExact(sym_get_const(right)));
PyObject *temp = PyFloat_FromDouble(
@@ -312,6 +330,8 @@
goto error;
}
res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
@@ -329,7 +349,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
- if (sym_is_const(left) && sym_is_const(right)) {
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
+ {
assert(PyFloat_CheckExact(sym_get_const(left)));
assert(PyFloat_CheckExact(sym_get_const(right)));
PyObject *temp = PyFloat_FromDouble(
@@ -339,6 +361,8 @@
goto error;
}
res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c
index 158ee67..a529cc2 100644
--- a/Python/optimizer_symbols.c
+++ b/Python/optimizer_symbols.c
@@ -77,7 +77,7 @@ sym_set_bottom(_Py_UopsSymbol *sym)
Py_CLEAR(sym->const_val);
}
-static inline bool
+bool
_Py_uop_sym_is_bottom(_Py_UopsSymbol *sym)
{
if ((sym->flags & IS_NULL) && (sym->flags & NOT_NULL)) {