isl_ast_codegen.c: create_node_scaled: reflect current domain slice in schedule
[platform/upstream/isl.git] / isl_input.c
index f2e57e7..e93233d 100644 (file)
@@ -343,6 +343,7 @@ static __isl_give isl_pw_aff *accept_affine_factor(struct isl_stream *s,
                if (pos < 0)
                        goto error;
                if (pos >= n) {
+                       vars_drop(v, v->n - n);
                        isl_stream_error(s, tok, "unknown identifier");
                        goto error;
                }
@@ -941,7 +942,11 @@ static __isl_give isl_multi_pw_aff *read_tuple_var_list(struct isl_stream *s,
                        new_name = p >= n;
                }
 
-               if (new_name) {
+               if (tok->type == '*') {
+                       if (vars_add_anon(v) < 0)
+                               goto error;
+                       isl_token_free(tok);
+               } else if (new_name) {
                        res = tuple_set_dim_name(res, i, v->v->name);
                        isl_token_free(tok);
                        if (isl_stream_eat_if_available(s, '='))
@@ -1043,6 +1048,8 @@ static __isl_give isl_map *read_map_tuple(struct isl_stream *s,
 
        n = isl_multi_pw_aff_dim(tuple, isl_dim_out);
        space = isl_space_range(isl_multi_pw_aff_get_space(tuple));
+       if (!space)
+               goto error;
 
        if (type == isl_dim_param) {
                if (isl_space_has_tuple_name(space, isl_dim_set) ||
@@ -1116,28 +1123,24 @@ static __isl_give isl_set *construct_constraints(
 {
        isl_set *cond;
 
+       left = isl_pw_aff_list_copy(left);
+       right = isl_pw_aff_list_copy(right);
        if (rational) {
                left = isl_pw_aff_list_set_rational(left);
                right = isl_pw_aff_list_set_rational(right);
        }
        if (type == ISL_TOKEN_LE)
-               cond = isl_pw_aff_list_le_set(isl_pw_aff_list_copy(left),
-                                             isl_pw_aff_list_copy(right));
+               cond = isl_pw_aff_list_le_set(left, right);
        else if (type == ISL_TOKEN_GE)
-               cond = isl_pw_aff_list_ge_set(isl_pw_aff_list_copy(left),
-                                             isl_pw_aff_list_copy(right));
+               cond = isl_pw_aff_list_ge_set(left, right);
        else if (type == ISL_TOKEN_LT)
-               cond = isl_pw_aff_list_lt_set(isl_pw_aff_list_copy(left),
-                                             isl_pw_aff_list_copy(right));
+               cond = isl_pw_aff_list_lt_set(left, right);
        else if (type == ISL_TOKEN_GT)
-               cond = isl_pw_aff_list_gt_set(isl_pw_aff_list_copy(left),
-                                             isl_pw_aff_list_copy(right));
+               cond = isl_pw_aff_list_gt_set(left, right);
        else if (type == ISL_TOKEN_NE)
-               cond = isl_pw_aff_list_ne_set(isl_pw_aff_list_copy(left),
-                                             isl_pw_aff_list_copy(right));
+               cond = isl_pw_aff_list_ne_set(left, right);
        else
-               cond = isl_pw_aff_list_eq_set(isl_pw_aff_list_copy(left),
-                                             isl_pw_aff_list_copy(right));
+               cond = isl_pw_aff_list_eq_set(left, right);
 
        return isl_set_intersect(set, cond);
 }
@@ -1350,7 +1353,7 @@ static __isl_give isl_map *read_conjuncts(struct isl_stream *s,
        if (negate)
                res = isl_map_subtract(isl_map_copy(map), res);
 
-       while (isl_stream_eat_if_available(s, ISL_TOKEN_AND)) {
+       while (res && isl_stream_eat_if_available(s, ISL_TOKEN_AND)) {
                isl_map *res_i;
 
                negate = isl_stream_eat_if_available(s, ISL_TOKEN_NOT);
@@ -2586,7 +2589,6 @@ static __isl_give isl_set *read_aff_domain(struct isl_stream *s,
 error:
        if (tok)
                isl_stream_push_token(s, tok);
-       vars_free(v);
        isl_set_free(dom);
        return NULL;
 }
@@ -2750,6 +2752,47 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_read_from_str(isl_ctx *ctx,
        return pma;
 }
 
+/* Read an isl_union_pw_multi_aff from "s".
+ * We currently read a generic object and if it turns out to be a set or
+ * a map, we convert that to an isl_union_pw_multi_aff.
+ * It would be more efficient if we were to construct
+ * the isl_union_pw_multi_aff directly.
+ */
+__isl_give isl_union_pw_multi_aff *isl_stream_read_union_pw_multi_aff(
+       struct isl_stream *s)
+{
+       struct isl_obj obj;
+
+       obj = obj_read(s);
+       if (!obj.v)
+               return NULL;
+
+       if (obj.type == isl_obj_map || obj.type == isl_obj_set)
+               obj = to_union(s->ctx, obj);
+       if (obj.type == isl_obj_union_map)
+               return isl_union_pw_multi_aff_from_union_map(obj.v);
+       if (obj.type == isl_obj_union_set)
+               return isl_union_pw_multi_aff_from_union_set(obj.v);
+
+       obj.type->free(obj.v);
+       isl_die(s->ctx, isl_error_invalid, "unexpected object type",
+               return NULL);
+}
+
+/* Read an isl_union_pw_multi_aff from "str".
+ */
+__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_read_from_str(
+       isl_ctx *ctx, const char *str)
+{
+       isl_union_pw_multi_aff *upma;
+       struct isl_stream *s = isl_stream_new_str(ctx, str);
+       if (!s)
+               return NULL;
+       upma = isl_stream_read_union_pw_multi_aff(s);
+       isl_stream_free(s);
+       return upma;
+}
+
 /* Assuming "pa" represents a single affine expression defined on a universe
  * domain, extract this affine expression.
  */