From 44d2ff86974b47485f4f2755aa00a3c78b3e9125 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 5 Feb 2014 13:50:12 +0100 Subject: [PATCH] extract out pet_to_bool During the incemental move of some functionality from operating on the clang AST to operating on pet_expr objects, this function will be used by both. Since this function only depends on isl functionality, we move it to aff.c. Signed-off-by: Sven Verdoolaege --- aff.c | 15 +++++++++++++++ aff.h | 1 + scan.cc | 9 +-------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/aff.c b/aff.c index e9c657f..03f61b7 100644 --- a/aff.c +++ b/aff.c @@ -73,6 +73,21 @@ __isl_give isl_pw_aff *pet_not(__isl_take isl_pw_aff *pa) return pa; } +/* Return "!!pa", i.e., a function that is equal to 1 when "pa" + * is non-zero and equal to 0 when "pa" is equal to zero, + * on the domain of "pa". + */ +__isl_give isl_pw_aff *pet_to_bool(__isl_take isl_pw_aff *pa) +{ + isl_set *cond, *dom; + + dom = isl_pw_aff_domain(isl_pw_aff_copy(pa)); + cond = isl_pw_aff_non_zero_set(pa); + pa = indicator_function(cond, dom); + + return pa; +} + /* Return the result of applying the comparison operator "type" * to "pa1" and "pa2". * diff --git a/aff.h b/aff.h index 8589b68..c7f39fb 100644 --- a/aff.h +++ b/aff.h @@ -12,6 +12,7 @@ extern "C" { __isl_give isl_pw_aff *pet_and(__isl_take isl_pw_aff *lhs, __isl_take isl_pw_aff *rhs); __isl_give isl_pw_aff *pet_not(__isl_take isl_pw_aff *pa); +__isl_give isl_pw_aff *pet_to_bool(__isl_take isl_pw_aff *pa); __isl_give isl_pw_aff *pet_comparison(enum pet_op_type type, __isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2); diff --git a/scan.cc b/scan.cc index 51cc613..303234a 100644 --- a/scan.cc +++ b/scan.cc @@ -1501,16 +1501,9 @@ __isl_give isl_pw_aff *PetScan::extract_condition(UnaryOperator *expr) __isl_give isl_pw_aff *PetScan::extract_implicit_condition(Expr *expr) { isl_pw_aff *res; - isl_set *set, *dom; res = extract_affine(expr); - - dom = isl_pw_aff_domain(isl_pw_aff_copy(res)); - set = isl_pw_aff_non_zero_set(res); - - res = indicator_function(set, dom); - - return res; + return pet_to_bool(res); } /* Extract an affine expression from a boolean expression. -- 2.11.4.GIT