From 9ec03cf88cb526cff533669cb60481277768bc1a Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 5 Feb 2014 13:55:32 +0100 Subject: [PATCH] extract out pet_boolean 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 | 42 ++++++++++++++++++++++++++++++++++++++++++ aff.h | 2 ++ scan.cc | 24 ++---------------------- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/aff.c b/aff.c index 03f61b7..9125a73 100644 --- a/aff.c +++ b/aff.c @@ -136,3 +136,45 @@ __isl_give isl_pw_aff *pet_comparison(enum pet_op_type type, return res; } + +/* Return "lhs && rhs", with shortcut semantics. + * That is, if lhs is false, then the result is defined even if rhs is not. + * In practice, we compute lhs ? rhs : lhs. + */ +static __isl_give isl_pw_aff *pw_aff_and_then(__isl_take isl_pw_aff *lhs, + __isl_take isl_pw_aff *rhs) +{ + return isl_pw_aff_cond(isl_pw_aff_copy(lhs), rhs, lhs); +} + +/* Return "lhs || rhs", with shortcut semantics. + * That is, if lhs is true, then the result is defined even if rhs is not. + * In practice, we compute lhs ? lhs : rhs. + */ +static __isl_give isl_pw_aff *pw_aff_or_else(__isl_take isl_pw_aff *lhs, + __isl_take isl_pw_aff *rhs) +{ + return isl_pw_aff_cond(isl_pw_aff_copy(lhs), lhs, rhs); +} + +/* Return the result of applying the boolean operator "type" + * to "pa1" and "pa2". + */ +__isl_give isl_pw_aff *pet_boolean(enum pet_op_type type, + __isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2) +{ + isl_ctx *ctx; + + switch (type) { + case pet_op_land: + return pw_aff_and_then(pa1, pa2); + case pet_op_lor: + return pw_aff_or_else(pa1, pa2); + default: + ctx = isl_pw_aff_get_ctx(pa1); + isl_pw_aff_free(pa1); + isl_pw_aff_free(pa2); + isl_die(ctx, isl_error_internal, + "not a boolean operator", return NULL); + } +} diff --git a/aff.h b/aff.h index c7f39fb..bb4deb4 100644 --- a/aff.h +++ b/aff.h @@ -13,6 +13,8 @@ __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_boolean(enum pet_op_type type, + __isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2); __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 303234a..462b0ff 100644 --- a/scan.cc +++ b/scan.cc @@ -1369,26 +1369,6 @@ static bool is_max(Expr *expr, Expr *&lhs, Expr *&rhs) return is_minmax(expr, "max", lhs, rhs); } -/* Return "lhs && rhs", with shortcut semantics. - * That is, if lhs is false, then the result is defined even if rhs is not. - * In practice, we compute lhs ? rhs : lhs. - */ -static __isl_give isl_pw_aff *pw_aff_and_then(__isl_take isl_pw_aff *lhs, - __isl_take isl_pw_aff *rhs) -{ - return isl_pw_aff_cond(isl_pw_aff_copy(lhs), rhs, lhs); -} - -/* Return "lhs || rhs", with shortcut semantics. - * That is, if lhs is true, then the result is defined even if rhs is not. - * In practice, we compute lhs ? lhs : rhs. - */ -static __isl_give isl_pw_aff *pw_aff_or_else(__isl_take isl_pw_aff *lhs, - __isl_take isl_pw_aff *rhs) -{ - return isl_pw_aff_cond(isl_pw_aff_copy(lhs), lhs, rhs); -} - /* Extract an affine expressions representing the comparison "LHS op RHS" * "comp" is the original statement that "LHS op RHS" is derived from * and is used for diagnostics. @@ -1473,9 +1453,9 @@ __isl_give isl_pw_aff *PetScan::extract_boolean(BinaryOperator *comp) switch (comp->getOpcode()) { case BO_LAnd: - return pw_aff_and_then(lhs, rhs); + return pet_boolean(pet_op_land, lhs, rhs); case BO_LOr: - return pw_aff_or_else(lhs, rhs); + return pet_boolean(pet_op_lor, lhs, rhs); default: isl_pw_aff_free(lhs); isl_pw_aff_free(rhs); -- 2.11.4.GIT