From 248388821d68a1c2ab5a1efb8181b4ddd466e86c Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 10 Mar 2014 11:17:20 +0100 Subject: [PATCH] tree2scop.c: scop_from_non_affine_if: delay construction of body pet_scop(s) In particular, delay their construction until after the construction of the scop evaluating the condition. This results in a more transparent numbering of the virtual arrays. Signed-off-by: Sven Verdoolaege --- tests/break4.scop | 104 +++++++++++++++++++++++++-------------------------- tests/continue2.scop | 44 +++++++++++----------- tree2scop.c | 33 ++++++++-------- 3 files changed, 90 insertions(+), 91 deletions(-) diff --git a/tests/break4.scop b/tests/break4.scop index 853275f..3c12701 100644 --- a/tests/break4.scop +++ b/tests/break4.scop @@ -15,25 +15,25 @@ arrays: element_size: 4 uniquely_defined: 1 - context: '{ : }' - extent: '{ __pet_test_5[i, j] : i >= 0 and i <= 99 and j >= 0 and j <= 99 }' + extent: '{ __pet_test_2[i, j] : i >= 0 and i <= 99 and j >= 0 and j <= 99 }' value_bounds: '{ [i0] : i0 >= 0 and i0 <= 1 }' element_type: int element_size: 4 uniquely_defined: 1 - context: '{ : }' - extent: '{ __pet_test_2[i, j] : i >= 0 and i <= 99 and j >= 0 and j <= 99 }' + extent: '{ __pet_test_3[i, j] : i >= 0 and i <= 99 and j >= 0 and j <= 99 }' value_bounds: '{ [i0] : i0 >= 0 and i0 <= 1 }' element_type: int element_size: 4 uniquely_defined: 1 - context: '{ : }' - extent: '{ __pet_test_3[i, j] : i >= 0 and i <= 99 and j >= 0 and j <= 99 }' + extent: '{ __pet_test_4[i, j] : i >= 0 and i <= 99 and j >= 0 and j <= 99 }' value_bounds: '{ [i0] : i0 >= 0 and i0 <= 1 }' element_type: int element_size: 4 uniquely_defined: 1 - context: '{ : }' - extent: '{ __pet_test_4[i, j] : i >= 0 and i <= 99 and j >= 0 and j <= 99 }' + extent: '{ __pet_test_5[i, j] : i >= 0 and i <= 99 and j >= 0 and j <= 99 }' value_bounds: '{ [i0] : i0 >= 0 and i0 <= 1 }' element_type: int element_size: 4 @@ -178,8 +178,8 @@ statements: operation: = arguments: - type: access - relation: '{ S_3[i, j] -> __pet_test_5[i, j] }' - index: '{ S_3[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_3[i, j] -> __pet_test_2[i, j] }' + index: '{ S_3[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_11 read: 0 write: 1 @@ -207,8 +207,8 @@ statements: operation: = arguments: - type: access - relation: '{ S_4[i, j] -> __pet_test_2[i, j] }' - index: '{ S_4[i, j] -> __pet_test_2[(i), (j)] }' + relation: '{ S_4[i, j] -> __pet_test_3[i, j] }' + index: '{ S_4[i, j] -> __pet_test_3[(i), (j)] }' reference: __pet_ref_15 read: 0 write: 1 @@ -228,8 +228,8 @@ statements: read: 1 write: 0 - type: access - relation: '{ S_4[i, j] -> __pet_test_5[i, j] }' - index: '{ S_4[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_4[i, j] -> __pet_test_2[i, j] }' + index: '{ S_4[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_14 read: 1 write: 0 @@ -263,14 +263,14 @@ statements: read: 1 write: 0 - type: access - relation: '{ S_5[i, j] -> __pet_test_5[i, j] }' - index: '{ S_5[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_5[i, j] -> __pet_test_2[i, j] }' + index: '{ S_5[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_18 read: 1 write: 0 - type: access - relation: '{ S_5[i, j] -> __pet_test_2[i, j] }' - index: '{ S_5[i, j] -> __pet_test_2[(i), (j)] }' + relation: '{ S_5[i, j] -> __pet_test_3[i, j] }' + index: '{ S_5[i, j] -> __pet_test_3[(i), (j)] }' reference: __pet_ref_19 read: 1 write: 0 @@ -283,8 +283,8 @@ statements: operation: = arguments: - type: access - relation: '{ S_6[i, j] -> __pet_test_3[i, j] }' - index: '{ S_6[i, j] -> __pet_test_3[(i), (j)] }' + relation: '{ S_6[i, j] -> __pet_test_4[i, j] }' + index: '{ S_6[i, j] -> __pet_test_4[(i), (j)] }' reference: __pet_ref_25 read: 0 write: 1 @@ -304,14 +304,14 @@ statements: read: 1 write: 0 - type: access - relation: '{ S_6[i, j] -> __pet_test_5[i, j] }' - index: '{ S_6[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_6[i, j] -> __pet_test_2[i, j] }' + index: '{ S_6[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_23 read: 1 write: 0 - type: access - relation: '{ S_6[i, j] -> __pet_test_2[i, j] }' - index: '{ S_6[i, j] -> __pet_test_2[(i), (j)] }' + relation: '{ S_6[i, j] -> __pet_test_3[i, j] }' + index: '{ S_6[i, j] -> __pet_test_3[(i), (j)] }' reference: __pet_ref_24 read: 1 write: 0 @@ -345,20 +345,20 @@ statements: read: 1 write: 0 - type: access - relation: '{ S_7[i, j] -> __pet_test_5[i, j] }' - index: '{ S_7[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_7[i, j] -> __pet_test_2[i, j] }' + index: '{ S_7[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_28 read: 1 write: 0 - type: access - relation: '{ S_7[i, j] -> __pet_test_2[i, j] }' - index: '{ S_7[i, j] -> __pet_test_2[(i), (j)] }' + relation: '{ S_7[i, j] -> __pet_test_3[i, j] }' + index: '{ S_7[i, j] -> __pet_test_3[(i), (j)] }' reference: __pet_ref_29 read: 1 write: 0 - type: access - relation: '{ S_7[i, j] -> __pet_test_3[i, j] }' - index: '{ S_7[i, j] -> __pet_test_3[(i), (j)] }' + relation: '{ S_7[i, j] -> __pet_test_4[i, j] }' + index: '{ S_7[i, j] -> __pet_test_4[(i), (j)] }' reference: __pet_ref_30 read: 1 write: 0 @@ -371,8 +371,8 @@ statements: operation: = arguments: - type: access - relation: '{ S_8[i, j] -> __pet_test_4[i, j] }' - index: '{ S_8[i, j] -> __pet_test_4[(i), (j)] }' + relation: '{ S_8[i, j] -> __pet_test_5[i, j] }' + index: '{ S_8[i, j] -> __pet_test_5[(i), (j)] }' reference: __pet_ref_35 read: 0 write: 1 @@ -380,8 +380,8 @@ statements: operation: '?:' arguments: - type: access - relation: '{ S_8[i, j] -> __pet_test_2[i, j] }' - index: '{ S_8[i, j] -> __pet_test_2[(i), (j)] }' + relation: '{ S_8[i, j] -> __pet_test_3[i, j] }' + index: '{ S_8[i, j] -> __pet_test_3[(i), (j)] }' reference: __pet_ref_36 read: 1 write: 0 @@ -392,15 +392,15 @@ statements: read: 1 write: 0 - type: access - relation: '{ [S_8[i, j] -> [0]] -> __pet_test_3[i, j] }' - index: '{ [S_8[i, j] -> [__pet_test_2]] -> __pet_test_3[(i), (j)] }' + relation: '{ [S_8[i, j] -> [0]] -> __pet_test_4[i, j] }' + index: '{ [S_8[i, j] -> [__pet_test_3]] -> __pet_test_4[(i), (j)] }' reference: __pet_ref_39 read: 1 write: 0 arguments: - type: access - relation: '{ S_8[i, j] -> __pet_test_2[i, j] }' - index: '{ S_8[i, j] -> __pet_test_2[(i), (j)] }' + relation: '{ S_8[i, j] -> __pet_test_3[i, j] }' + index: '{ S_8[i, j] -> __pet_test_3[(i), (j)] }' reference: __pet_ref_38 read: 1 write: 0 @@ -418,8 +418,8 @@ statements: read: 1 write: 0 - type: access - relation: '{ S_8[i, j] -> __pet_test_5[i, j] }' - index: '{ S_8[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_8[i, j] -> __pet_test_2[i, j] }' + index: '{ S_8[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_34 read: 1 write: 0 @@ -453,14 +453,14 @@ statements: read: 1 write: 0 - type: access - relation: '{ S_9[i, j] -> __pet_test_5[i, j] }' - index: '{ S_9[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_9[i, j] -> __pet_test_2[i, j] }' + index: '{ S_9[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_42 read: 1 write: 0 - type: access - relation: '{ S_9[i, j] -> __pet_test_4[i, j] }' - index: '{ S_9[i, j] -> __pet_test_4[(i), (j)] }' + relation: '{ S_9[i, j] -> __pet_test_5[i, j] }' + index: '{ S_9[i, j] -> __pet_test_5[(i), (j)] }' reference: __pet_ref_43 read: 1 write: 0 @@ -481,21 +481,21 @@ statements: operation: '?:' arguments: - type: access - relation: '{ S_10[i, j] -> __pet_test_5[i, j] }' - index: '{ S_10[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_10[i, j] -> __pet_test_2[i, j] }' + index: '{ S_10[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_48 read: 1 write: 0 - type: access - relation: '{ [S_10[i, j] -> [1]] -> __pet_test_4[i, j] }' - index: '{ [S_10[i, j] -> [__pet_test_5]] -> __pet_test_4[(i), (j)] }' + relation: '{ [S_10[i, j] -> [1]] -> __pet_test_5[i, j] }' + index: '{ [S_10[i, j] -> [__pet_test_2]] -> __pet_test_5[(i), (j)] }' reference: __pet_ref_50 read: 1 write: 0 arguments: - type: access - relation: '{ S_10[i, j] -> __pet_test_5[i, j] }' - index: '{ S_10[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_10[i, j] -> __pet_test_2[i, j] }' + index: '{ S_10[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_49 read: 1 write: 0 @@ -535,21 +535,21 @@ statements: operation: '?:' arguments: - type: access - relation: '{ S_11[i, j] -> __pet_test_5[i, j] }' - index: '{ S_11[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_11[i, j] -> __pet_test_2[i, j] }' + index: '{ S_11[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_55 read: 1 write: 0 - type: access - relation: '{ [S_11[i, j] -> [1]] -> __pet_test_2[i, j] }' - index: '{ [S_11[i, j] -> [__pet_test_5]] -> __pet_test_2[(i), (j)] }' + relation: '{ [S_11[i, j] -> [1]] -> __pet_test_3[i, j] }' + index: '{ [S_11[i, j] -> [__pet_test_2]] -> __pet_test_3[(i), (j)] }' reference: __pet_ref_57 read: 1 write: 0 arguments: - type: access - relation: '{ S_11[i, j] -> __pet_test_5[i, j] }' - index: '{ S_11[i, j] -> __pet_test_5[(i), (j)] }' + relation: '{ S_11[i, j] -> __pet_test_2[i, j] }' + index: '{ S_11[i, j] -> __pet_test_2[(i), (j)] }' reference: __pet_ref_56 read: 1 write: 0 diff --git a/tests/continue2.scop b/tests/continue2.scop index 2c9b009..b49b2d0 100644 --- a/tests/continue2.scop +++ b/tests/continue2.scop @@ -3,13 +3,13 @@ end: 289 context: '{ : }' arrays: - context: '{ : }' - extent: '{ __pet_test_1[i] : i >= 0 and i <= 99 }' + extent: '{ __pet_test_0[i] : i >= 0 and i <= 99 }' value_bounds: '{ [i0] : i0 >= 0 and i0 <= 1 }' element_type: int element_size: 4 uniquely_defined: 1 - context: '{ : }' - extent: '{ __pet_test_0[i] : i >= 0 and i <= 99 }' + extent: '{ __pet_test_1[i] : i >= 0 and i <= 99 }' value_bounds: '{ [i0] : i0 >= 0 and i0 <= 1 }' element_type: int element_size: 4 @@ -43,8 +43,8 @@ statements: operation: = arguments: - type: access - relation: '{ S_0[i] -> __pet_test_1[i] }' - index: '{ S_0[i] -> __pet_test_1[(i)] }' + relation: '{ S_0[i] -> __pet_test_0[i] }' + index: '{ S_0[i] -> __pet_test_0[(i)] }' reference: __pet_ref_0 read: 0 write: 1 @@ -76,8 +76,8 @@ statements: name: f arguments: - type: access - relation: '{ S_1[i] -> __pet_test_1[i] }' - index: '{ S_1[i] -> __pet_test_1[(i)] }' + relation: '{ S_1[i] -> __pet_test_0[i] }' + index: '{ S_1[i] -> __pet_test_0[(i)] }' reference: __pet_ref_2 read: 1 write: 0 @@ -89,8 +89,8 @@ statements: operation: = arguments: - type: access - relation: '{ S_2[i] -> __pet_test_0[i] }' - index: '{ S_2[i] -> __pet_test_0[(i)] }' + relation: '{ S_2[i] -> __pet_test_1[i] }' + index: '{ S_2[i] -> __pet_test_1[(i)] }' reference: __pet_ref_5 read: 0 write: 1 @@ -107,8 +107,8 @@ statements: value: 0 arguments: - type: access - relation: '{ S_2[i] -> __pet_test_1[i] }' - index: '{ S_2[i] -> __pet_test_1[(i)] }' + relation: '{ S_2[i] -> __pet_test_0[i] }' + index: '{ S_2[i] -> __pet_test_0[(i)] }' reference: __pet_ref_4 read: 1 write: 0 @@ -133,14 +133,14 @@ statements: write: 0 arguments: - type: access - relation: '{ S_3[i] -> __pet_test_1[i] }' - index: '{ S_3[i] -> __pet_test_1[(i)] }' + relation: '{ S_3[i] -> __pet_test_0[i] }' + index: '{ S_3[i] -> __pet_test_0[(i)] }' reference: __pet_ref_7 read: 1 write: 0 - type: access - relation: '{ S_3[i] -> __pet_test_0[i] }' - index: '{ S_3[i] -> __pet_test_0[(i)] }' + relation: '{ S_3[i] -> __pet_test_1[i] }' + index: '{ S_3[i] -> __pet_test_1[(i)] }' reference: __pet_ref_8 read: 1 write: 0 @@ -161,8 +161,8 @@ statements: value: 0 arguments: - type: access - relation: '{ S_4[i] -> __pet_test_1[i] }' - index: '{ S_4[i] -> __pet_test_1[(i)] }' + relation: '{ S_4[i] -> __pet_test_0[i] }' + index: '{ S_4[i] -> __pet_test_0[(i)] }' reference: __pet_ref_11 read: 1 write: 0 @@ -183,21 +183,21 @@ statements: operation: '?:' arguments: - type: access - relation: '{ S_5[i] -> __pet_test_1[i] }' - index: '{ S_5[i] -> __pet_test_1[(i)] }' + relation: '{ S_5[i] -> __pet_test_0[i] }' + index: '{ S_5[i] -> __pet_test_0[(i)] }' reference: __pet_ref_14 read: 1 write: 0 - type: access - relation: '{ [S_5[i] -> [1]] -> __pet_test_0[i] }' - index: '{ [S_5[i] -> [__pet_test_1]] -> __pet_test_0[(i)] }' + relation: '{ [S_5[i] -> [1]] -> __pet_test_1[i] }' + index: '{ [S_5[i] -> [__pet_test_0]] -> __pet_test_1[(i)] }' reference: __pet_ref_16 read: 1 write: 0 arguments: - type: access - relation: '{ S_5[i] -> __pet_test_1[i] }' - index: '{ S_5[i] -> __pet_test_1[(i)] }' + relation: '{ S_5[i] -> __pet_test_0[i] }' + index: '{ S_5[i] -> __pet_test_0[(i)] }' reference: __pet_ref_15 read: 1 write: 0 diff --git a/tree2scop.c b/tree2scop.c index 61624db..9de84ed 100644 --- a/tree2scop.c +++ b/tree2scop.c @@ -1506,14 +1506,13 @@ static struct pet_scop *scop_from_conditional_assignment( * adds them in pet_skip_info_if_add. */ static struct pet_scop *scop_from_non_affine_if(__isl_keep pet_tree *tree, - struct pet_scop *scop_then, struct pet_scop *scop_else, int stmt_id, - __isl_take pet_context *pc, struct pet_state *state) + int stmt_id, __isl_take pet_context *pc, struct pet_state *state) { int has_else; int save_n_stmt = state->n_stmt; isl_multi_pw_aff *test_index; struct pet_skip_info skip; - struct pet_scop *scop; + struct pet_scop *scop, *scop_then, *scop_else = NULL; has_else = tree->type == pet_tree_if_else; @@ -1526,6 +1525,10 @@ static struct pet_scop *scop_from_non_affine_if(__isl_keep pet_tree *tree, scop = pet_scop_add_boolean_array(scop, isl_multi_pw_aff_copy(test_index), state->int_size); + scop_then = scop_from_tree(tree->u.i.then_body, pc, state); + if (has_else) + scop_else = scop_from_tree(tree->u.i.else_body, pc, state); + pet_skip_info_if_init(&skip, state->ctx, scop_then, scop_else, has_else, 0); pet_skip_info_if_extract_index(&skip, test_index, state); @@ -1563,8 +1566,7 @@ static struct pet_scop *scop_from_non_affine_if(__isl_keep pet_tree *tree, * adds them in pet_skip_info_if_add. */ static struct pet_scop *scop_from_affine_if(__isl_keep pet_tree *tree, - __isl_take isl_pw_aff *cond, - struct pet_scop *scop_then, struct pet_scop *scop_else, + __isl_take isl_pw_aff *cond, __isl_take pet_context *pc, struct pet_state *state) { int has_else; @@ -1572,12 +1574,16 @@ static struct pet_scop *scop_from_affine_if(__isl_keep pet_tree *tree, isl_set *set; isl_set *valid; struct pet_skip_info skip; - struct pet_scop *scop; + struct pet_scop *scop, *scop_then, *scop_else = NULL; ctx = pet_tree_get_ctx(tree); has_else = tree->type == pet_tree_if_else; + scop_then = scop_from_tree(tree->u.i.then_body, pc, state); + if (has_else) + scop_else = scop_from_tree(tree->u.i.else_body, pc, state); + pet_skip_info_if_init(&skip, ctx, scop_then, scop_else, has_else, 1); pet_skip_info_if_extract_cond(&skip, cond, state); @@ -1598,6 +1604,7 @@ static struct pet_scop *scop_from_affine_if(__isl_keep pet_tree *tree, scop = pet_scop_prefix(scop, 0); scop = pet_skip_info_if_add(&skip, scop, 1); + pet_context_free(pc); return scop; } @@ -1632,7 +1639,6 @@ static struct pet_scop *scop_from_if(__isl_keep pet_tree *tree, int stmt_id; isl_pw_aff *cond; pet_expr *cond_expr; - struct pet_scop *scop_then, *scop_else = NULL; pet_context *pc_nested; if (!tree) @@ -1664,25 +1670,18 @@ static struct pet_scop *scop_from_if(__isl_keep pet_tree *tree, if (isl_pw_aff_involves_nan(cond) || pet_nested_any_in_pw_aff(cond)) stmt_id = state->n_stmt++; - scop_then = scop_from_tree(tree->u.i.then_body, pc, state); - if (has_else) - scop_else = scop_from_tree(tree->u.i.else_body, pc, state); - if (isl_pw_aff_involves_nan(cond)) { isl_pw_aff_free(cond); - return scop_from_non_affine_if(tree, scop_then, scop_else, - stmt_id, pc, state); + return scop_from_non_affine_if(tree, stmt_id, pc, state); } if ((!is_nested_allowed(cond, tree->u.i.then_body) || (has_else && !is_nested_allowed(cond, tree->u.i.else_body)))) { isl_pw_aff_free(cond); - return scop_from_non_affine_if(tree, scop_then, scop_else, - stmt_id, pc, state); + return scop_from_non_affine_if(tree, stmt_id, pc, state); } - pet_context_free(pc); - return scop_from_affine_if(tree, cond, scop_then, scop_else, state); + return scop_from_affine_if(tree, cond, pc, state); } /* Return a one-dimensional multi piecewise affine expression that is equal -- 2.11.4.GIT