summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorKen Jin <kenjin@python.org>2024-02-16 14:59:43 (GMT)
committerGitHub <noreply@github.com>2024-02-16 14:59:43 (GMT)
commitf92857a93016aa26ba93959d2bdb690ef52e7f07 (patch)
tree1ff8a1c20e2cc7d8f3cb2a3e79c41a1506723a42 /Python
parent144eb5605b445d22729db6c416d03cc24947ba56 (diff)
downloadcpython-f92857a93016aa26ba93959d2bdb690ef52e7f07.zip
cpython-f92857a93016aa26ba93959d2bdb690ef52e7f07.tar.gz
cpython-f92857a93016aa26ba93959d2bdb690ef52e7f07.tar.bz2
gh-115480: Minor fixups in int constant propagation (GH-115507)
Diffstat (limited to 'Python')
-rw-r--r--Python/optimizer_analysis.c17
-rw-r--r--Python/tier2_redundancy_eliminator_bytecodes.c87
-rw-r--r--Python/tier2_redundancy_eliminator_cases.c.h87
3 files changed, 59 insertions, 132 deletions
diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index d73bc31..b104d2f 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -588,16 +588,17 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
INST->oparg = ARG; \
INST->operand = OPERAND;
+#define OUT_OF_SPACE_IF_NULL(EXPR) \
+ do { \
+ if ((EXPR) == NULL) { \
+ goto out_of_space; \
+ } \
+ } while (0);
+
#define _LOAD_ATTR_NOT_NULL \
do { \
- attr = sym_new_known_notnull(ctx); \
- if (attr == NULL) { \
- goto error; \
- } \
- null = sym_new_null(ctx); \
- if (null == NULL) { \
- goto error; \
- } \
+ OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); \
+ OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx)); \
} while (0);
diff --git a/Python/tier2_redundancy_eliminator_bytecodes.c b/Python/tier2_redundancy_eliminator_bytecodes.c
index 39ea0ee..6aae590 100644
--- a/Python/tier2_redundancy_eliminator_bytecodes.c
+++ b/Python/tier2_redundancy_eliminator_bytecodes.c
@@ -43,10 +43,8 @@ dummy_func(void) {
op(_LOAD_FAST_AND_CLEAR, (-- value)) {
value = GETLOCAL(oparg);
- _Py_UOpsSymType *temp = sym_new_null(ctx);
- if (temp == NULL) {
- goto out_of_space;
- }
+ _Py_UOpsSymType *temp;
+ OUT_OF_SPACE_IF_NULL(temp = sym_new_null(ctx));
GETLOCAL(oparg) = temp;
}
@@ -89,14 +87,12 @@ dummy_func(void) {
if (temp == NULL) {
goto error;
}
- res = sym_new_const(ctx, temp);
- // TODO replace opcode with constant propagated one and add tests!
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ // TODO gh-115506:
+ // replace opcode with constant propagated one and add tests!
}
else {
- res = sym_new_known_type(ctx, &PyLong_Type);
- if (res == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyLong_Type));
}
}
@@ -109,14 +105,12 @@ dummy_func(void) {
if (temp == NULL) {
goto error;
}
- res = sym_new_const(ctx, temp);
- // TODO replace opcode with constant propagated one and add tests!
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ // TODO gh-115506:
+ // replace opcode with constant propagated one and add tests!
}
else {
- res = sym_new_known_type(ctx, &PyLong_Type);
- if (res == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyLong_Type));
}
}
@@ -129,14 +123,12 @@ dummy_func(void) {
if (temp == NULL) {
goto error;
}
- res = sym_new_const(ctx, temp);
- // TODO replace opcode with constant propagated one and add tests!
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ // TODO gh-115506:
+ // replace opcode with constant propagated one and add tests!
}
else {
- res = sym_new_known_type(ctx, &PyLong_Type);
- if (res == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyLong_Type));
}
}
@@ -147,39 +139,21 @@ dummy_func(void) {
}
op(_LOAD_CONST_INLINE, (ptr/4 -- value)) {
- value = sym_new_const(ctx, ptr);
- if (value == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
}
op(_LOAD_CONST_INLINE_BORROW, (ptr/4 -- value)) {
- value = sym_new_const(ctx, ptr);
- if (value == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
}
op(_LOAD_CONST_INLINE_WITH_NULL, (ptr/4 -- value, null)) {
- value = sym_new_const(ctx, ptr);
- if (value == NULL) {
- goto out_of_space;
- }
- null = sym_new_null(ctx);
- if (null == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
+ OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx));
}
op(_LOAD_CONST_INLINE_BORROW_WITH_NULL, (ptr/4 -- value, null)) {
- value = sym_new_const(ctx, ptr);
- if (value == NULL) {
- goto out_of_space;
- }
- null = sym_new_null(ctx);
- if (null == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
+ OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx));
}
@@ -261,10 +235,8 @@ dummy_func(void) {
localsplus_start = args;
n_locals_already_filled = argcount;
}
- new_frame = ctx_frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0);
- if (new_frame == NULL){
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(new_frame =
+ ctx_frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0));
}
op(_POP_FRAME, (retval -- res)) {
@@ -287,10 +259,7 @@ dummy_func(void) {
/* This has to be done manually */
(void)seq;
for (int i = 0; i < oparg; i++) {
- values[i] = sym_new_unknown(ctx);
- if (values[i] == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(values[i] = sym_new_unknown(ctx));
}
}
@@ -299,18 +268,12 @@ dummy_func(void) {
(void)seq;
int totalargs = (oparg & 0xFF) + (oparg >> 8) + 1;
for (int i = 0; i < totalargs; i++) {
- values[i] = sym_new_unknown(ctx);
- if (values[i] == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(values[i] = sym_new_unknown(ctx));
}
}
op(_ITER_NEXT_RANGE, (iter -- iter, next)) {
- next = sym_new_known_type(ctx, &PyLong_Type);
- if (next == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(next = sym_new_known_type(ctx, &PyLong_Type));
(void)iter;
}
diff --git a/Python/tier2_redundancy_eliminator_cases.c.h b/Python/tier2_redundancy_eliminator_cases.c.h
index a9617f5..d1301ff 100644
--- a/Python/tier2_redundancy_eliminator_cases.c.h
+++ b/Python/tier2_redundancy_eliminator_cases.c.h
@@ -36,10 +36,8 @@
case _LOAD_FAST_AND_CLEAR: {
_Py_UOpsSymType *value;
value = GETLOCAL(oparg);
- _Py_UOpsSymType *temp = sym_new_null(ctx);
- if (temp == NULL) {
- goto out_of_space;
- }
+ _Py_UOpsSymType *temp;
+ OUT_OF_SPACE_IF_NULL(temp = sym_new_null(ctx));
GETLOCAL(oparg) = temp;
stack_pointer[0] = value;
stack_pointer += 1;
@@ -193,14 +191,12 @@
if (temp == NULL) {
goto error;
}
- res = sym_new_const(ctx, temp);
- // TODO replace opcode with constant propagated one and add tests!
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ // TODO gh-115506:
+ // replace opcode with constant propagated one and add tests!
}
else {
- res = sym_new_known_type(ctx, &PyLong_Type);
- if (res == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyLong_Type));
}
stack_pointer[-2] = res;
stack_pointer += -1;
@@ -221,14 +217,12 @@
if (temp == NULL) {
goto error;
}
- res = sym_new_const(ctx, temp);
- // TODO replace opcode with constant propagated one and add tests!
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ // TODO gh-115506:
+ // replace opcode with constant propagated one and add tests!
}
else {
- res = sym_new_known_type(ctx, &PyLong_Type);
- if (res == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyLong_Type));
}
stack_pointer[-2] = res;
stack_pointer += -1;
@@ -249,14 +243,12 @@
if (temp == NULL) {
goto error;
}
- res = sym_new_const(ctx, temp);
- // TODO replace opcode with constant propagated one and add tests!
+ OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
+ // TODO gh-115506:
+ // replace opcode with constant propagated one and add tests!
}
else {
- res = sym_new_known_type(ctx, &PyLong_Type);
- if (res == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyLong_Type));
}
stack_pointer[-2] = res;
stack_pointer += -1;
@@ -514,10 +506,7 @@
/* This has to be done manually */
(void)seq;
for (int i = 0; i < oparg; i++) {
- values[i] = sym_new_unknown(ctx);
- if (values[i] == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(values[i] = sym_new_unknown(ctx));
}
stack_pointer += -1 + oparg;
break;
@@ -565,10 +554,7 @@
(void)seq;
int totalargs = (oparg & 0xFF) + (oparg >> 8) + 1;
for (int i = 0; i < totalargs; i++) {
- values[i] = sym_new_unknown(ctx);
- if (values[i] == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(values[i] = sym_new_unknown(ctx));
}
stack_pointer += (oparg >> 8) + (oparg & 0xFF);
break;
@@ -1153,10 +1139,7 @@
_Py_UOpsSymType *iter;
_Py_UOpsSymType *next;
iter = stack_pointer[-1];
- next = sym_new_known_type(ctx, &PyLong_Type);
- if (next == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(next = sym_new_known_type(ctx, &PyLong_Type));
(void)iter;
stack_pointer[0] = next;
stack_pointer += 1;
@@ -1359,10 +1342,8 @@
localsplus_start = args;
n_locals_already_filled = argcount;
}
- new_frame = ctx_frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0);
- if (new_frame == NULL){
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(new_frame =
+ ctx_frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0));
stack_pointer[-2 - oparg] = (_Py_UOpsSymType *)new_frame;
stack_pointer += -1 - oparg;
break;
@@ -1652,10 +1633,7 @@
case _LOAD_CONST_INLINE: {
_Py_UOpsSymType *value;
PyObject *ptr = (PyObject *)this_instr->operand;
- value = sym_new_const(ctx, ptr);
- if (value == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
stack_pointer[0] = value;
stack_pointer += 1;
break;
@@ -1664,10 +1642,7 @@
case _LOAD_CONST_INLINE_BORROW: {
_Py_UOpsSymType *value;
PyObject *ptr = (PyObject *)this_instr->operand;
- value = sym_new_const(ctx, ptr);
- if (value == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
stack_pointer[0] = value;
stack_pointer += 1;
break;
@@ -1677,14 +1652,8 @@
_Py_UOpsSymType *value;
_Py_UOpsSymType *null;
PyObject *ptr = (PyObject *)this_instr->operand;
- value = sym_new_const(ctx, ptr);
- if (value == NULL) {
- goto out_of_space;
- }
- null = sym_new_null(ctx);
- if (null == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
+ OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx));
stack_pointer[0] = value;
stack_pointer[1] = null;
stack_pointer += 2;
@@ -1695,14 +1664,8 @@
_Py_UOpsSymType *value;
_Py_UOpsSymType *null;
PyObject *ptr = (PyObject *)this_instr->operand;
- value = sym_new_const(ctx, ptr);
- if (value == NULL) {
- goto out_of_space;
- }
- null = sym_new_null(ctx);
- if (null == NULL) {
- goto out_of_space;
- }
+ OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
+ OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx));
stack_pointer[0] = value;
stack_pointer[1] = null;
stack_pointer += 2;