From b99709f113b02fc5b997f59ad1b6aebefe922275 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 16 Nov 2011 12:05:09 +0100 Subject: [PATCH] add pet_scop_writes Signed-off-by: Sven Verdoolaege --- scop.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ scop.h | 2 ++ 2 files changed, 56 insertions(+) diff --git a/scop.c b/scop.c index b64d51f..ea9e70a 100644 --- a/scop.c +++ b/scop.c @@ -1698,3 +1698,57 @@ __isl_give isl_union_map *pet_scop_collect_schedule(struct pet_scop *scop) return schedule; } + +/* Does expression "expr" write to "id"? + */ +static int expr_writes(struct pet_expr *expr, __isl_keep isl_id *id) +{ + int i; + isl_id *write_id; + + for (i = 0; i < expr->n_arg; ++i) { + int writes = expr_writes(expr->args[i], id); + if (writes < 0 || writes) + return writes; + } + + if (expr->type != pet_expr_access) + return 0; + if (!expr->acc.write) + return 0; + if (!isl_map_has_tuple_id(expr->acc.access, isl_dim_out)) + return 0; + + write_id = isl_map_get_tuple_id(expr->acc.access, isl_dim_out); + isl_id_free(write_id); + + if (!write_id) + return -1; + + return write_id == id; +} + +/* Does statement "stmt" write to "id"? + */ +static int stmt_writes(struct pet_stmt *stmt, __isl_keep isl_id *id) +{ + return expr_writes(stmt->body, id); +} + +/* Is there any write access in "scop" that accesses "id"? + */ +int pet_scop_writes(struct pet_scop *scop, __isl_keep isl_id *id) +{ + int i; + + if (!scop) + return -1; + + for (i = 0; i < scop->n_stmt; ++i) { + int writes = stmt_writes(scop->stmts[i], id); + if (writes < 0 || writes) + return writes; + } + + return 0; +} diff --git a/scop.h b/scop.h index c0b65fc..aa07df7 100644 --- a/scop.h +++ b/scop.h @@ -62,6 +62,8 @@ struct pet_expr *pet_expr_foreach_access(struct pet_expr *expr, __isl_give isl_map *(*fn)(__isl_take isl_map *access, void *user), void *user); +int pet_scop_writes(struct pet_scop *scop, __isl_keep isl_id *id); + #if defined(__cplusplus) } #endif -- 2.11.4.GIT