drop "nparam" argument from isl_{set,map}_read_from_{file,str}
[platform/upstream/isl.git] / isl_local_space.c
index 8cf99a6..ebf222c 100644 (file)
@@ -11,8 +11,9 @@
 #include <isl_ctx_private.h>
 #include <isl_map_private.h>
 #include <isl_local_space_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_mat_private.h>
+#include <isl_aff_private.h>
 #include <isl/seq.h>
 
 isl_ctx *isl_local_space_get_ctx(__isl_keep isl_local_space *ls)
@@ -20,7 +21,7 @@ isl_ctx *isl_local_space_get_ctx(__isl_keep isl_local_space *ls)
        return ls ? ls->dim->ctx : NULL;
 }
 
-__isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_dim *dim,
+__isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_space *dim,
        __isl_take isl_mat *div)
 {
        isl_ctx *ctx;
@@ -29,7 +30,7 @@ __isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_dim *dim,
        if (!dim)
                goto error;
 
-       ctx = isl_dim_get_ctx(dim);
+       ctx = isl_space_get_ctx(dim);
        ls = isl_calloc_type(ctx, struct isl_local_space);
        if (!ls)
                goto error;
@@ -40,12 +41,12 @@ __isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_dim *dim,
 
        return ls;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_local_space_free(ls);
        return NULL;
 }
 
-__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_dim *dim,
+__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_space *dim,
        unsigned n_div)
 {
        isl_ctx *ctx;
@@ -55,14 +56,14 @@ __isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_dim *dim,
        if (!dim)
                return NULL;
 
-       total = isl_dim_total(dim);
+       total = isl_space_dim(dim, isl_dim_all);
 
-       ctx = isl_dim_get_ctx(dim);
+       ctx = isl_space_get_ctx(dim);
        div = isl_mat_alloc(ctx, n_div, 1 + 1 + total + n_div);
        return isl_local_space_alloc_div(dim, div);
 }
 
-__isl_give isl_local_space *isl_local_space_from_dim(__isl_take isl_dim *dim)
+__isl_give isl_local_space *isl_local_space_from_space(__isl_take isl_space *dim)
 {
        return isl_local_space_alloc(dim, 0);
 }
@@ -81,7 +82,7 @@ __isl_give isl_local_space *isl_local_space_dup(__isl_keep isl_local_space *ls)
        if (!ls)
                return NULL;
 
-       return isl_local_space_alloc_div(isl_dim_copy(ls->dim),
+       return isl_local_space_alloc_div(isl_space_copy(ls->dim),
                                         isl_mat_copy(ls->div));
 
 }
@@ -105,7 +106,7 @@ void *isl_local_space_free(__isl_take isl_local_space *ls)
        if (--ls->ref > 0)
                return NULL;
 
-       isl_dim_free(ls->dim);
+       isl_space_free(ls->dim);
        isl_mat_free(ls->div);
 
        free(ls);
@@ -113,6 +114,13 @@ void *isl_local_space_free(__isl_take isl_local_space *ls)
        return NULL;
 }
 
+/* Is the local space that of a set?
+ */
+int isl_local_space_is_set(__isl_keep isl_local_space *ls)
+{
+       return ls ? isl_space_is_set(ls->dim) : -1;
+}
+
 /* Return true if the two local spaces are identical, with identical
  * expressions for the integer divisions.
  */
@@ -124,7 +132,7 @@ int isl_local_space_is_equal(__isl_keep isl_local_space *ls1,
        if (!ls1 || !ls2)
                return -1;
 
-       equal = isl_dim_equal(ls1->dim, ls2->dim);
+       equal = isl_space_is_equal(ls1->dim, ls2->dim);
        if (equal < 0 || !equal)
                return equal;
 
@@ -144,14 +152,14 @@ int isl_local_space_dim(__isl_keep isl_local_space *ls,
        if (type == isl_dim_div)
                return ls->div->n_row;
        if (type == isl_dim_all)
-               return isl_dim_size(ls->dim, isl_dim_all) + ls->div->n_row;
-       return isl_dim_size(ls->dim, type);
+               return isl_space_dim(ls->dim, isl_dim_all) + ls->div->n_row;
+       return isl_space_dim(ls->dim, type);
 }
 
 unsigned isl_local_space_offset(__isl_keep isl_local_space *ls,
        enum isl_dim_type type)
 {
-       isl_dim *dim;
+       isl_space *dim;
 
        if (!ls)
                return 0;
@@ -170,13 +178,13 @@ unsigned isl_local_space_offset(__isl_keep isl_local_space *ls,
 const char *isl_local_space_get_dim_name(__isl_keep isl_local_space *ls,
        enum isl_dim_type type, unsigned pos)
 {
-       return ls ? isl_dim_get_name(ls->dim, type, pos) : NULL;
+       return ls ? isl_space_get_dim_name(ls->dim, type, pos) : NULL;
 }
 
-__isl_give isl_div *isl_local_space_get_div(__isl_keep isl_local_space *ls,
+__isl_give isl_aff *isl_local_space_get_div(__isl_keep isl_local_space *ls,
        int pos)
 {
-       isl_basic_map *bmap;
+       isl_aff *aff;
 
        if (!ls)
                return NULL;
@@ -189,16 +197,19 @@ __isl_give isl_div *isl_local_space_get_div(__isl_keep isl_local_space *ls,
                isl_die(isl_local_space_get_ctx(ls), isl_error_invalid,
                        "expression of div unknown", return NULL);
 
-       bmap = isl_basic_map_from_local_space(isl_local_space_copy(ls));
-       return isl_basic_map_div(bmap, pos);
+       aff = isl_aff_alloc(isl_local_space_copy(ls));
+       if (!aff)
+               return NULL;
+       isl_seq_cpy(aff->v->el, ls->div->row[pos], aff->v->size);
+       return aff;
 }
 
-__isl_give isl_dim *isl_local_space_get_dim(__isl_keep isl_local_space *ls)
+__isl_give isl_space *isl_local_space_get_space(__isl_keep isl_local_space *ls)
 {
        if (!ls)
                return NULL;
 
-       return isl_dim_copy(ls->dim);
+       return isl_space_copy(ls->dim);
 }
 
 __isl_give isl_local_space *isl_local_space_set_dim_name(
@@ -208,27 +219,27 @@ __isl_give isl_local_space *isl_local_space_set_dim_name(
        ls = isl_local_space_cow(ls);
        if (!ls)
                return NULL;
-       ls->dim = isl_dim_set_name(ls->dim, type, pos, s);
+       ls->dim = isl_space_set_dim_name(ls->dim, type, pos, s);
        if (!ls->dim)
                return isl_local_space_free(ls);
 
        return ls;
 }
 
-__isl_give isl_local_space *isl_local_space_reset_dim(
-       __isl_take isl_local_space *ls, __isl_take isl_dim *dim)
+__isl_give isl_local_space *isl_local_space_reset_space(
+       __isl_take isl_local_space *ls, __isl_take isl_space *dim)
 {
        ls = isl_local_space_cow(ls);
        if (!ls || !dim)
                goto error;
 
-       isl_dim_free(ls->dim);
+       isl_space_free(ls->dim);
        ls->dim = dim;
 
        return ls;
 error:
        isl_local_space_free(ls);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -246,7 +257,7 @@ static __isl_give isl_mat *reorder_divs(__isl_take isl_mat *div,
        if (!div || !r)
                goto error;
 
-       extra = isl_dim_total(r->dim) + div->n_row - r->len;
+       extra = isl_space_dim(r->dim, isl_dim_all) + div->n_row - r->len;
        mat = isl_mat_alloc(div->ctx, div->n_row, div->n_col + extra);
        if (!mat)
                goto error;
@@ -283,7 +294,7 @@ __isl_give isl_local_space *isl_local_space_realign(
        if (!ls->div)
                goto error;
 
-       ls = isl_local_space_reset_dim(ls, isl_dim_copy(r->dim));
+       ls = isl_local_space_reset_space(ls, isl_space_copy(r->dim));
 
        isl_reordering_free(r);
        return ls;
@@ -440,6 +451,20 @@ int isl_local_space_divs_known(__isl_keep isl_local_space *ls)
        return 1;
 }
 
+__isl_give isl_local_space *isl_local_space_domain(
+       __isl_take isl_local_space *ls)
+{
+       ls = isl_local_space_drop_dims(ls, isl_dim_out,
+                                       0, isl_local_space_dim(ls, isl_dim_out));
+       ls = isl_local_space_cow(ls);
+       if (!ls)
+               return NULL;
+       ls->dim = isl_space_domain(ls->dim);
+       if (!ls->dim)
+               return isl_local_space_free(ls);
+       return ls;
+}
+
 /* Construct a local space for a map that has the given local
  * space as domain and that has a zero-dimensional range.
  */
@@ -449,7 +474,7 @@ __isl_give isl_local_space *isl_local_space_from_domain(
        ls = isl_local_space_cow(ls);
        if (!ls)
                return NULL;
-       ls->dim = isl_dim_from_domain(ls->dim);
+       ls->dim = isl_space_from_domain(ls->dim);
        if (!ls->dim)
                return isl_local_space_free(ls);
        return ls;
@@ -503,7 +528,7 @@ __isl_give isl_local_space *isl_local_space_substitute_equalities(
        if (!ls || !eq)
                goto error;
 
-       total = isl_dim_total(eq->dim);
+       total = isl_space_dim(eq->dim, isl_dim_all);
        if (isl_local_space_dim(ls, isl_dim_all) != total)
                isl_die(isl_local_space_get_ctx(ls), isl_error_invalid,
                        "dimensions don't match", goto error);
@@ -536,7 +561,7 @@ int isl_local_space_is_named_or_nested(__isl_keep isl_local_space *ls,
 {
        if (!ls)
                return -1;
-       return isl_dim_is_named_or_nested(ls->dim, type);
+       return isl_space_is_named_or_nested(ls->dim, type);
 }
 
 __isl_give isl_local_space *isl_local_space_drop_dims(
@@ -562,7 +587,7 @@ __isl_give isl_local_space *isl_local_space_drop_dims(
        if (type == isl_dim_div) {
                ls->div = isl_mat_drop_rows(ls->div, first, n);
        } else {
-               ls->dim = isl_dim_drop(ls->dim, type, first, n);
+               ls->dim = isl_space_drop_dims(ls->dim, type, first, n);
                if (!ls->dim)
                        return isl_local_space_free(ls);
        }
@@ -598,7 +623,7 @@ __isl_give isl_local_space *isl_local_space_insert_dims(
        if (type == isl_dim_div) {
                ls->div = isl_mat_insert_zero_rows(ls->div, first, n);
        } else {
-               ls->dim = isl_dim_insert(ls->dim, type, first, n);
+               ls->dim = isl_space_insert_dims(ls->dim, type, first, n);
                if (!ls->dim)
                        return isl_local_space_free(ls);
        }
@@ -658,3 +683,35 @@ int isl_local_space_is_div_constraint(__isl_keep isl_local_space *ls,
 
        return 1;
 }
+
+/*
+ * Set active[i] to 1 if the dimension at position i is involved
+ * in the linear expression l.
+ */
+int *isl_local_space_get_active(__isl_keep isl_local_space *ls, isl_int *l)
+{
+       int i, j;
+       isl_ctx *ctx;
+       int *active = NULL;
+       unsigned total;
+       unsigned offset;
+
+       ctx = isl_local_space_get_ctx(ls);
+       total = isl_local_space_dim(ls, isl_dim_all);
+       active = isl_calloc_array(ctx, int, total);
+       if (!active)
+               return NULL;
+
+       for (i = 0; i < total; ++i)
+               active[i] = !isl_int_is_zero(l[i]);
+
+       offset = isl_local_space_offset(ls, isl_dim_div) - 1;
+       for (i = ls->div->n_row - 1; i >= 0; --i) {
+               if (!active[offset + i])
+                       continue;
+               for (j = 0; j < total; ++j)
+                       active[j] |= !isl_int_is_zero(ls->div->row[i][2 + j]);
+       }
+
+       return active;
+}