isl_input.c: read_tuple: use isl_map_intersect_params where needed
[platform/upstream/isl.git] / isl_local_space.c
index 5c963d8..8a27e81 100644 (file)
@@ -451,6 +451,59 @@ __isl_give isl_mat *isl_merge_divs(__isl_keep isl_mat *div1,
        return div;
 }
 
+/* Construct a local space that contains all the divs in either
+ * "ls1" or "ls2".
+ */
+__isl_give isl_local_space *isl_local_space_intersect(
+       __isl_take isl_local_space *ls1, __isl_take isl_local_space *ls2)
+{
+       isl_ctx *ctx;
+       int *exp1 = NULL;
+       int *exp2 = NULL;
+       isl_mat *div;
+
+       if (!ls1 || !ls2)
+               goto error;
+
+       ctx = isl_local_space_get_ctx(ls1);
+       if (!isl_space_is_equal(ls1->dim, ls2->dim))
+               isl_die(ctx, isl_error_invalid,
+                       "spaces should be identical", goto error);
+
+       if (ls2->div->n_row == 0) {
+               isl_local_space_free(ls2);
+               return ls1;
+       }
+
+       if (ls1->div->n_row == 0) {
+               isl_local_space_free(ls1);
+               return ls2;
+       }
+
+       exp1 = isl_alloc_array(ctx, int, ls1->div->n_row);
+       exp2 = isl_alloc_array(ctx, int, ls2->div->n_row);
+       if (!exp1 || !exp2)
+               goto error;
+
+       div = isl_merge_divs(ls1->div, ls2->div, exp1, exp2);
+       if (!div)
+               goto error;
+
+       free(exp1);
+       free(exp2);
+       isl_local_space_free(ls2);
+       isl_mat_free(ls1->div);
+       ls1->div = div;
+
+       return ls1;
+error:
+       free(exp1);
+       free(exp2);
+       isl_local_space_free(ls1);
+       isl_local_space_free(ls2);
+       return NULL;
+}
+
 int isl_local_space_divs_known(__isl_keep isl_local_space *ls)
 {
        int i;
@@ -783,3 +836,47 @@ int *isl_local_space_get_active(__isl_keep isl_local_space *ls, isl_int *l)
 
        return active;
 }
+
+/* Given a local space "ls" of a set, create a local space
+ * for the lift of the set.  In particular, the result
+ * is of the form [dim -> local[..]], with ls->div->n_row variables in the
+ * range of the wrapped map.
+ */
+__isl_give isl_local_space *isl_local_space_lift(
+       __isl_take isl_local_space *ls)
+{
+       ls = isl_local_space_cow(ls);
+       if (!ls)
+               return NULL;
+
+       ls->dim = isl_space_lift(ls->dim, ls->div->n_row);
+       ls->div = isl_mat_drop_rows(ls->div, 0, ls->div->n_row);
+       if (!ls->dim || !ls->div)
+               return isl_local_space_free(ls);
+
+       return ls;
+}
+
+/* Construct a basic map that maps a set living in local space "ls"
+ * to the corresponding lifted local space.
+ */
+__isl_give isl_basic_map *isl_local_space_lifting(
+       __isl_take isl_local_space *ls)
+{
+       isl_basic_map *lifting;
+       isl_basic_set *bset;
+
+       if (!ls)
+               return NULL;
+       if (!isl_local_space_is_set(ls))
+               isl_die(isl_local_space_get_ctx(ls), isl_error_invalid,
+                       "lifting only defined on set spaces",
+                       return isl_local_space_free(ls));
+
+       bset = isl_basic_set_from_local_space(ls);
+       lifting = isl_basic_set_unwrap(isl_basic_set_lift(bset));
+       lifting = isl_basic_map_domain_map(lifting);
+       lifting = isl_basic_map_reverse(lifting);
+
+       return lifting;
+}