From c0db3358d6ecaffec71c08a08e9e116ab548a25b Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 11 Mar 2014 14:20:05 +0100 Subject: [PATCH] pet_context_evaluate_expr: also plug in affine expressions for scalar reads Whenever we access an outer loop iterator, this access is converted to an access to an iteration domain dimension inside pet_scop_embed when the scop that is begin built from the bottom up is embedded in the corresponding loop. When we change the extraction of a pet_scop from a pet_tree from a bottom-up process to a top-down process, this special handling of loop iterators is removed, but we still need to convert those accesses. We therefore convert them in advance inside pet_context_evaluate_expr. This currently converts those accesses to parameters that are then later converted to accesses to iteration domain dimensions (again inside pet_scop_embed), but when we perform the switch, they will be converted directly inside pet_context_evaluate_expr. As a side effect of this change in treatment, we also plug in affine expressions for accesses to scalar variables that are not loop iterators. Signed-off-by: Sven Verdoolaege --- context.c | 42 +++++++++++++++++++++++++++++++++++++++- tests/autodetect/decl.scop | 4 ++-- tests/cast.scop | 18 +++++++---------- tests/forward_substitution1.scop | 4 ++-- tests/forward_substitution3.scop | 4 ++-- tests/inc5.scop | 8 ++------ tests/quasi_affine.scop | 41 ++++++++++++++++++--------------------- 7 files changed, 75 insertions(+), 46 deletions(-) diff --git a/context.c b/context.c index 1f6c0c4..eb02497 100644 --- a/context.c +++ b/context.c @@ -368,13 +368,53 @@ __isl_give pet_context *pet_context_clear_writes_in_tree( return pc; } +/* Given an access expression, check if it reads a scalar variable + * that has a known value in "pc". + * If so, then replace the access by an access to that value. + */ +static __isl_give pet_expr *access_plug_in_affine_read( + __isl_take pet_expr *expr, void *user) +{ + pet_context *pc = user; + isl_pw_aff *pa; + + if (pet_expr_access_is_write(expr)) + return expr; + if (!pet_expr_is_scalar_access(expr)) + return expr; + + pa = pet_expr_extract_affine(expr, pc); + if (!pa) + return pet_expr_free(expr); + if (isl_pw_aff_involves_nan(pa)) { + isl_pw_aff_free(pa); + return expr; + } + + pet_expr_free(expr); + expr = pet_expr_from_index(isl_multi_pw_aff_from_pw_aff(pa)); + + return expr; +} + +/* Replace every read access in "expr" to a scalar variable + * that has a known value in "pc" by that known value. + */ +static __isl_give pet_expr *plug_in_affine_read(__isl_take pet_expr *expr, + __isl_keep pet_context *pc) +{ + return pet_expr_map_access(expr, &access_plug_in_affine_read, pc); +} + /* Evaluate "expr" in the context of "pc". * - * In particular, plug in the arguments of all access expressions in 'expr". + * In particular, plug in affine expressions for scalar reads and + * plug in the arguments of all access expressions in "expr". */ __isl_give pet_expr *pet_context_evaluate_expr(__isl_keep pet_context *pc, __isl_take pet_expr *expr) { + expr = plug_in_affine_read(expr, pc); return pet_expr_plug_in_args(expr, pc); } diff --git a/tests/autodetect/decl.scop b/tests/autodetect/decl.scop index 8b56b27..c98bab7 100644 --- a/tests/autodetect/decl.scop +++ b/tests/autodetect/decl.scop @@ -74,8 +74,8 @@ statements: read: 0 write: 1 - type: access - relation: '{ S_3[] -> c[] }' - index: '{ S_3[] -> c[] }' + relation: '{ S_3[] -> [5] }' + index: '{ S_3[] -> [(5)] }' reference: __pet_ref_4 read: 1 write: 0 diff --git a/tests/cast.scop b/tests/cast.scop index 5497160..a83f0b7 100644 --- a/tests/cast.scop +++ b/tests/cast.scop @@ -1,26 +1,22 @@ start: 37 end: 80 -context: '{ : }' +context: '[c] -> { : c <= 127 and c >= -128 }' arrays: - context: '{ : }' - extent: '{ a[] }' + extent: '[c] -> { a[] }' element_type: int element_size: 4 -- context: '{ : }' - extent: '{ c[] }' - element_type: char - element_size: 1 statements: - line: 7 - domain: '{ S_0[] }' + domain: '[c] -> { S_0[] }' schedule: '{ S_0[] -> [0] }' body: type: op operation: = arguments: - type: access - relation: '{ S_0[] -> a[] }' - index: '{ S_0[] -> a[] }' + relation: '[c] -> { S_0[] -> a[] }' + index: '[c] -> { S_0[] -> a[] }' reference: __pet_ref_0 read: 0 write: 1 @@ -28,8 +24,8 @@ statements: type_name: int arguments: - type: access - relation: '{ S_0[] -> c[] }' - index: '{ S_0[] -> c[] }' + relation: '[c] -> { S_0[] -> [c] }' + index: '[c] -> { S_0[] -> [(c)] }' reference: __pet_ref_1 read: 1 write: 0 diff --git a/tests/forward_substitution1.scop b/tests/forward_substitution1.scop index b00c90b..99bdfe3 100644 --- a/tests/forward_substitution1.scop +++ b/tests/forward_substitution1.scop @@ -44,8 +44,8 @@ statements: read: 0 write: 1 - type: access - relation: '{ S_1[] -> b[] }' - index: '{ S_1[] -> b[] }' + relation: '{ S_1[] -> [1] }' + index: '{ S_1[] -> [(1)] }' reference: __pet_ref_2 read: 1 write: 0 diff --git a/tests/forward_substitution3.scop b/tests/forward_substitution3.scop index 442b4f3..ab63295 100644 --- a/tests/forward_substitution3.scop +++ b/tests/forward_substitution3.scop @@ -74,8 +74,8 @@ statements: read: 0 write: 1 - type: access - relation: '{ S_3[] -> b[] }' - index: '{ S_3[] -> b[] }' + relation: '{ S_3[] -> [1] }' + index: '{ S_3[] -> [(1)] }' reference: __pet_ref_4 read: 1 write: 0 diff --git a/tests/inc5.scop b/tests/inc5.scop index d995df9..cdcb21b 100644 --- a/tests/inc5.scop +++ b/tests/inc5.scop @@ -8,10 +8,6 @@ arrays: element_type: int element_size: 4 uniquely_defined: 1 -- context: '{ : }' - extent: '[N] -> { N[] }' - element_type: int - element_size: 4 - context: '[N] -> { : N >= 0 }' extent: '[N] -> { a[i0] : i0 <= -1 + N and i0 >= 0 }' element_type: int @@ -74,8 +70,8 @@ statements: read: 1 write: 0 - type: access - relation: '[N] -> { S_2[t] -> N[] }' - index: '[N] -> { S_2[t] -> N[] }' + relation: '[N] -> { S_2[t] -> [N] }' + index: '[N] -> { S_2[t] -> [(N)] }' reference: __pet_ref_5 read: 1 write: 0 diff --git a/tests/quasi_affine.scop b/tests/quasi_affine.scop index 1f2034f..c18b0a6 100644 --- a/tests/quasi_affine.scop +++ b/tests/quasi_affine.scop @@ -1,49 +1,46 @@ start: 84 end: 218 -context: '[N] -> { : N <= 2147483647 and N >= 0 }' +context: '[N, in] -> { : N <= 2147483647 and N >= 0 and in <= 2147483647 and in >= + -2147483648 }' arrays: - context: '[N] -> { : N >= 0 }' - extent: '[N] -> { A[i0] : i0 <= -1 + N and i0 >= 0 }' + extent: '[N, in] -> { A[i0] : i0 <= -1 + N and i0 >= 0 }' element_type: int element_size: 4 - context: '{ : }' - extent: '[N] -> { in[] }' - element_type: int - element_size: 4 -- context: '{ : }' - extent: '[N] -> { out[] }' + extent: '[N, in] -> { out[] }' element_type: int element_size: 4 statements: - line: 14 - domain: '[N] -> { S_0[] }' + domain: '[N, in] -> { S_0[] }' schedule: '{ S_0[] -> [0, 0] }' body: type: op operation: = arguments: - type: access - relation: '[N] -> { S_0[] -> A[0] }' - index: '[N] -> { S_0[] -> A[(0)] }' + relation: '[N, in] -> { S_0[] -> A[0] }' + index: '[N, in] -> { S_0[] -> A[(0)] }' reference: __pet_ref_0 read: 0 write: 1 - type: access - relation: '[N] -> { S_0[] -> in[] }' - index: '[N] -> { S_0[] -> in[] }' + relation: '[N, in] -> { S_0[] -> [in] }' + index: '[N, in] -> { S_0[] -> [(in)] }' reference: __pet_ref_1 read: 1 write: 0 - line: 16 - domain: '[N] -> { S_1[i] : i <= N and i >= 1 }' + domain: '[N, in] -> { S_1[i] : i <= N and i >= 1 }' schedule: '[N] -> { S_1[i] -> [0, 1, i, 0] }' body: type: op operation: = arguments: - type: access - relation: '[N] -> { S_1[i] -> A[i] }' - index: '[N] -> { S_1[i] -> A[(i)] }' + relation: '[N, in] -> { S_1[i] -> A[i] }' + index: '[N, in] -> { S_1[i] -> A[(i)] }' reference: __pet_ref_2 read: 0 write: 1 @@ -54,21 +51,21 @@ statements: name: g arguments: - type: access - relation: '[N] -> { S_1[i] -> A[o0] : 2o0 >= -1 + i and 2o0 <= i }' - index: '[N] -> { S_1[i] -> A[(floor((i)/2))] }' + relation: '[N, in] -> { S_1[i] -> A[o0] : 2o0 >= -1 + i and 2o0 <= i }' + index: '[N, in] -> { S_1[i] -> A[(floor((i)/2))] }' reference: __pet_ref_3 read: 1 write: 0 - line: 18 - domain: '[N] -> { S_2[] }' + domain: '[N, in] -> { S_2[] }' schedule: '{ S_2[] -> [0, 2] }' body: type: op operation: = arguments: - type: access - relation: '[N] -> { S_2[] -> out[] }' - index: '[N] -> { S_2[] -> out[] }' + relation: '[N, in] -> { S_2[] -> out[] }' + index: '[N, in] -> { S_2[] -> out[] }' reference: __pet_ref_4 read: 0 write: 1 @@ -76,8 +73,8 @@ statements: name: g arguments: - type: access - relation: '[N] -> { S_2[] -> A[N] }' - index: '[N] -> { S_2[] -> A[(N)] }' + relation: '[N, in] -> { S_2[] -> A[N] }' + index: '[N, in] -> { S_2[] -> A[(N)] }' reference: __pet_ref_5 read: 1 write: 0 -- 2.11.4.GIT