From 55b5457dc57cf480d1d382dc030ab12e0af5c730 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 19 Jan 2012 19:27:00 +0100 Subject: [PATCH] try and extract condition of ternary operator as a single affine expression This allows us to more accurately extract contexts from expressions involving ternary operators. Signed-off-by: Sven Verdoolaege --- scan.cc | 11 ++++++++++- tests/propagate.scop | 21 +++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/scan.cc b/scan.cc index c2d9b72..d21c078 100644 --- a/scan.cc +++ b/scan.cc @@ -1345,12 +1345,21 @@ struct pet_expr *PetScan::extract_expr(BinaryOperator *expr) } /* Construct a pet_expr representing a conditional operation. + * + * We first try to extract the condition as an affine expression. + * If that fails, we construct a pet_expr tree representing the condition. */ struct pet_expr *PetScan::extract_expr(ConditionalOperator *expr) { struct pet_expr *cond, *lhs, *rhs; + isl_pw_aff *pa; - cond = extract_expr(expr->getCond()); + pa = try_extract_affine(expr->getCond()); + if (pa) { + isl_set *test = isl_set_from_pw_aff(pa); + cond = pet_expr_from_access(isl_map_from_range(test)); + } else + cond = extract_expr(expr->getCond()); lhs = extract_expr(expr->getTrueExpr()); rhs = extract_expr(expr->getFalseExpr()); diff --git a/tests/propagate.scop b/tests/propagate.scop index 3e0e82f..fbb8837 100644 --- a/tests/propagate.scop +++ b/tests/propagate.scop @@ -1,10 +1,10 @@ -context: '[N] -> { : N >= 0 and N <= 2147483647 }' +context: '[N] -> { : N <= 2147483647 and N >= 0 }' arrays: - context: '[N] -> { : N >= 0 }' - extent: '[N] -> { a[i0, i1] : i0 >= 0 and i1 >= 0 and i1 <= -1 + N }' + extent: '[N] -> { a[i0, i1] : i1 <= -1 + N and i0 >= 0 and i1 >= 0 }' element_type: int - context: '{ : }' - extent: '{ ind[] }' + extent: '[N] -> { ind[] }' element_type: int statements: - line: 9 @@ -20,17 +20,10 @@ statements: write: 1 - type: ternary arguments: - - type: binary - operation: '>' - arguments: - - type: access - relation: '[N] -> { S_0[i, j] -> [i] }' - read: 1 - write: 0 - - type: access - relation: '[N] -> { S_0[i, j] -> [0] }' - read: 1 - write: 0 + - type: access + relation: '[N] -> { S_0[i, j] -> [1] : i >= 1; S_0[0, j] -> [0] }' + read: 1 + write: 0 - type: binary operation: '-' arguments: -- 2.11.4.GIT