From 524176573fb0e5e757c78a65725815feb1f09351 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 25 Jul 2011 15:09:30 +0200 Subject: [PATCH] accept affine expressions where we expect a condition In such cases, the condition is taken to be the affine expression being non-zero. Reported-by: Sven van Haastregt Signed-off-by: Sven Verdoolaege --- scan.cc | 19 +++++++++++++------ scan.h | 2 ++ tests/implicit_condition.c | 11 +++++++++++ tests/implicit_condition.scop | 21 +++++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 tests/implicit_condition.c create mode 100644 tests/implicit_condition.scop diff --git a/scan.cc b/scan.cc index 56417ec..1b8cda1 100644 --- a/scan.cc +++ b/scan.cc @@ -830,7 +830,17 @@ __isl_give isl_set *PetScan::extract_condition(UnaryOperator *expr) } } +/* Extract a set of values satisfying the condition "expr != 0". + */ +__isl_give isl_set *PetScan::extract_implicit_condition(Expr *expr) +{ + return isl_pw_aff_non_zero_set(extract_affine(expr)); +} + /* Extract a set of values satisfying the condition expressed by "expr". + * + * If the expression doesn't look like a condition, we assume it + * is an affine expression and return the condition "expr != 0". */ __isl_give isl_set *PetScan::extract_condition(Expr *expr) { @@ -845,10 +855,8 @@ __isl_give isl_set *PetScan::extract_condition(Expr *expr) if (expr->getStmtClass() == Stmt::UnaryOperatorClass) return extract_condition(cast(expr)); - if (expr->getStmtClass() != Stmt::BinaryOperatorClass) { - unsupported(expr); - return NULL; - } + if (expr->getStmtClass() != Stmt::BinaryOperatorClass) + return extract_implicit_condition(expr); comp = cast(expr); switch (comp->getOpcode()) { @@ -863,8 +871,7 @@ __isl_give isl_set *PetScan::extract_condition(Expr *expr) case BO_LOr: return extract_boolean(comp); default: - unsupported(expr); - return NULL; + return extract_implicit_condition(expr); } } diff --git a/scan.h b/scan.h index 755233b..deae095 100644 --- a/scan.h +++ b/scan.h @@ -123,6 +123,8 @@ private: __isl_give isl_pw_aff *extract_affine(clang::ArraySubscriptExpr *expr); __isl_give isl_pw_aff *extract_affine(clang::ConditionalOperator *expr); + __isl_give isl_set *extract_implicit_condition(clang::Expr *expr); + __isl_give isl_set *extract_condition(clang::UnaryOperator *expr); __isl_give isl_set *extract_condition(clang::Expr *expr); __isl_give isl_set *extract_comparison(clang::BinaryOperator *expr); diff --git a/tests/implicit_condition.c b/tests/implicit_condition.c new file mode 100644 index 0000000..77e8835 --- /dev/null +++ b/tests/implicit_condition.c @@ -0,0 +1,11 @@ +void foo(int N) +{ + int i; + int a[N]; + +#pragma scop + for (i = 0; i < N; ++i) + if (i) + a[i] = i; +#pragma endscop +} diff --git a/tests/implicit_condition.scop b/tests/implicit_condition.scop new file mode 100644 index 0000000..6968433 --- /dev/null +++ b/tests/implicit_condition.scop @@ -0,0 +1,21 @@ +context: '[N] -> { [] : N >= 0 }' +arrays: +- context: '[N] -> { [] : N >= 0 }' + extent: '[N] -> { a[i0] : i0 >= 0 and i0 <= -1 + N }' + element_type: int +statements: +- line: 9 + domain: '[N] -> { S_0[i] : i <= -1 + N and i >= 1 }' + schedule: '[N] -> { S_0[i] -> [0, i] }' + body: + type: binary + operation: = + arguments: + - type: access + relation: '[N] -> { S_0[i] -> a[i] }' + read: 0 + write: 1 + - type: access + relation: '[N] -> { S_0[i] -> [i] }' + read: 1 + write: 0 -- 2.11.4.GIT