isl_stream_read_map: accept floord and ceild expressions in constraints
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 18 Mar 2011 10:46:59 +0000 (11:46 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 18 Mar 2011 11:24:32 +0000 (12:24 +0100)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
include/isl/stream.h
isl_input.c
isl_stream.c
isl_test.c

index 6695157..779c6cf 100644 (file)
@@ -29,6 +29,7 @@ enum isl_token_type { ISL_TOKEN_ERROR = -1,
                        ISL_TOKEN_DEF, ISL_TOKEN_INFTY, ISL_TOKEN_NAN,
                        ISL_TOKEN_MIN, ISL_TOKEN_MAX, ISL_TOKEN_RAT,
                        ISL_TOKEN_TRUE, ISL_TOKEN_FALSE,
+                       ISL_TOKEN_CEILD, ISL_TOKEN_FLOORD,
                        ISL_TOKEN_STRING,
                        ISL_TOKEN_LAST };
 
index 319937c..d979f1e 100644 (file)
@@ -317,18 +317,26 @@ static __isl_give isl_vec *accept_affine_factor(struct isl_stream *s,
                        goto error;
                if (isl_stream_eat(s, ')'))
                        goto error;
-       } else if (tok->type == '[') {
+       } else if (tok->type == '[' ||
+                   tok->type == ISL_TOKEN_FLOORD ||
+                   tok->type == ISL_TOKEN_CEILD) {
+               int ceil = tok->type == ISL_TOKEN_CEILD;
+               struct variable *var;
                if (vars_add_anon(v) < 0)
                        goto error;
+               var = v->v;
                aff = isl_vec_alloc(v->ctx, 1 + v->n);
                if (!aff)
                        goto error;
                isl_seq_clr(aff->el, aff->size);
-               isl_int_set_si(aff->el[1 + v->n - 1], 1);
+               isl_int_set_si(aff->el[1 + v->n - 1], ceil ? -1 : 1);
                isl_stream_push_token(s, tok);
                tok = NULL;
                if (read_div_definition(s, v) < 0)
                        goto error;
+               if (ceil)
+                       isl_seq_neg(var->def->el + 1, var->def->el + 1,
+                                   var->def->size - 1);
                aff = isl_vec_zero_extend(aff, 1 + v->n);
        } else if (tok->type == ISL_TOKEN_MIN || tok->type == ISL_TOKEN_MAX) {
                if (vars_add_anon(v) < 0)
@@ -393,6 +401,8 @@ static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
                }
                if (tok->type == '(' || tok->type == '[' ||
                    tok->type == ISL_TOKEN_MIN || tok->type == ISL_TOKEN_MAX ||
+                   tok->type == ISL_TOKEN_FLOORD ||
+                   tok->type == ISL_TOKEN_CEILD ||
                    tok->type == ISL_TOKEN_IDENT) {
                        isl_vec *aff2;
                        isl_stream_push_token(s, tok);
@@ -657,18 +667,19 @@ static int read_div_definition(struct isl_stream *s, struct vars *v)
        int seen_paren = 0;
        struct isl_vec *aff;
        struct variable *var;
+       int fc = 0;
 
-       if (isl_stream_eat(s, '['))
-               return -1;
-
-       tok = isl_stream_next_token(s);
-       if (!tok)
-               return -1;
-       if (tok->type == '(') {
-               seen_paren = 1;
-               isl_token_free(tok);
-       } else
-               isl_stream_push_token(s, tok);
+       if (isl_stream_eat_if_available(s, ISL_TOKEN_FLOORD) ||
+           isl_stream_eat_if_available(s, ISL_TOKEN_CEILD)) {
+               fc = 1;
+               if (isl_stream_eat(s, '('))
+                       return -1;
+       } else {
+               if (isl_stream_eat(s, '['))
+                       return -1;
+               if (isl_stream_eat_if_available(s, '('))
+                       seen_paren = 1;
+       }
 
        var = v->v;
 
@@ -686,10 +697,15 @@ static int read_div_definition(struct isl_stream *s, struct vars *v)
 
        isl_vec_free(aff);
 
-       if (seen_paren && isl_stream_eat(s, ')'))
-               return -1;
-       if (isl_stream_eat(s, '/'))
-               return -1;
+       if (fc) {
+               if (isl_stream_eat(s, ','))
+                       return -1;
+       } else {
+               if (seen_paren && isl_stream_eat(s, ')'))
+                       return -1;
+               if (isl_stream_eat(s, '/'))
+                       return -1;
+       }
 
        tok = next_token(s);
        if (!tok)
@@ -702,8 +718,13 @@ static int read_div_definition(struct isl_stream *s, struct vars *v)
        isl_int_set(var->def->el[0], tok->u.v);
        isl_token_free(tok);
 
-       if (isl_stream_eat(s, ']'))
-               return -1;
+       if (fc) {
+               if (isl_stream_eat(s, ')'))
+                       return -1;
+       } else {
+               if (isl_stream_eat(s, ']'))
+                       return -1;
+       }
 
        return 0;
 }
index 2cb6e0b..c544149 100644 (file)
@@ -260,6 +260,10 @@ static enum isl_token_type check_keywords(struct isl_stream *s)
                return ISL_TOKEN_TRUE;
        if (!strcasecmp(s->buffer, "false"))
                return ISL_TOKEN_FALSE;
+       if (!strcasecmp(s->buffer, "ceild"))
+               return ISL_TOKEN_CEILD;
+       if (!strcasecmp(s->buffer, "floord"))
+               return ISL_TOKEN_FLOORD;
 
        if (!s->keywords)
                return ISL_TOKEN_IDENT;
index 30879d9..1f2c6f1 100644 (file)
@@ -97,6 +97,10 @@ void test_parse(struct isl_ctx *ctx)
        isl_map_free(map);
        isl_map_free(map2);
 
+       str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
+       str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
+       test_parse_map_equal(ctx, str, str2);
+
        test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
 }