From a6706e1b674bedfc375be00660671d4d0528a599 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 16 Mar 2014 11:58:47 +0100 Subject: [PATCH] add pet_context_clear_writes_in_{expr,tree} We will need these functions in the next commit. Signed-off-by: Sven Verdoolaege --- context.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ context.h | 7 +++++++ 2 files changed, 54 insertions(+) diff --git a/context.c b/context.c index afa8c1d..723f76f 100644 --- a/context.c +++ b/context.c @@ -35,6 +35,7 @@ #include #include "context.h" +#include "expr.h" /* A pet_context represents the context in which a pet_expr * in converted to an affine expression. @@ -378,6 +379,52 @@ __isl_give pet_context *pet_context_set_allow_nested(__isl_take pet_context *pc, return pc; } +/* If the access expression "expr" writes to a (non-virtual) scalar, + * then mark the scalar as having an unknown value in "pc". + */ +static int clear_write(__isl_keep pet_expr *expr, void *user) +{ + isl_id *id; + pet_context **pc = (pet_context **) user; + + if (!pet_expr_access_is_write(expr)) + return 0; + if (!pet_expr_is_scalar_access(expr)) + return 0; + + id = pet_expr_access_get_id(expr); + if (isl_id_get_user(id)) + *pc = pet_context_mark_assigned(*pc, id); + else + isl_id_free(id); + + return 0; +} + +/* Look for any writes to scalar variables in "expr" and + * mark them as having an unknown value in "pc". + */ +__isl_give pet_context *pet_context_clear_writes_in_expr( + __isl_take pet_context *pc, __isl_keep pet_expr *expr) +{ + if (pet_expr_foreach_access_expr(expr, &clear_write, &pc) < 0) + pc = pet_context_free(pc); + + return pc; +} + +/* Look for any writes to scalar variables in "tree" and + * mark them as having an unknown value in "pc". + */ +__isl_give pet_context *pet_context_clear_writes_in_tree( + __isl_take pet_context *pc, __isl_keep pet_tree *tree) +{ + if (pet_tree_foreach_access_expr(tree, &clear_write, &pc) < 0) + pc = pet_context_free(pc); + + return pc; +} + void pet_context_dump(__isl_keep pet_context *pc) { if (!pc) diff --git a/context.h b/context.h index 20e7c8c..02d7895 100644 --- a/context.h +++ b/context.h @@ -4,6 +4,8 @@ #include #include +#include + #if defined(__cplusplus) extern "C" { #endif @@ -36,6 +38,11 @@ __isl_give pet_context *pet_context_set_allow_nested(__isl_take pet_context *pc, int allow_nested); int pet_context_allow_nesting(__isl_keep pet_context *pc); +__isl_give pet_context *pet_context_clear_writes_in_expr( + __isl_take pet_context *pc, __isl_keep pet_expr *expr); +__isl_give pet_context *pet_context_clear_writes_in_tree( + __isl_take pet_context *pc, __isl_keep pet_tree *tree); + void pet_context_dump(__isl_keep pet_context *pc); #if defined(__cplusplus) -- 2.11.4.GIT