change isl_basic_map_foreach_lexmin prototype
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 16 Apr 2011 17:39:53 +0000 (19:39 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 14 Jun 2011 15:33:20 +0000 (17:33 +0200)
In particular, the callback now receives an isl_aff_list instead
of an isl_mat.  The use of an isl_mat exposed too much of the internal
details of isl.  On top of that, it was also very fragile as the meaning
of the columns in the matrix depended on the internal representation
of the separate basic set.  Any change in this internal representation,
including any simplification step, would change the meaning of the matrix.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
include/isl/map.h
isl_tab_pip.c
isl_test.c

index 7c37ec5..0afcba3 100644 (file)
@@ -218,7 +218,7 @@ __isl_give isl_map *isl_basic_map_lexmax(__isl_take isl_basic_map *bmap);
 __isl_give isl_map *isl_map_lexmin(__isl_take isl_map *map);
 __isl_give isl_map *isl_map_lexmax(__isl_take isl_map *map);
 int isl_basic_map_foreach_lexmin(__isl_keep isl_basic_map *bmap,
-       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_mat *map,
+       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
                  void *user),
        void *user);
 
index 5bf39ef..073380e 100644 (file)
@@ -16,6 +16,7 @@
 #include "isl_tab.h"
 #include "isl_sample.h"
 #include <isl_mat_private.h>
+#include <isl_aff_private.h>
 #include <isl_config.h>
 
 /*
@@ -4507,7 +4508,7 @@ error:
 struct isl_sol_for {
        struct isl_sol  sol;
        int             (*fn)(__isl_take isl_basic_set *dom,
-                               __isl_take isl_mat *map, void *user);
+                               __isl_take isl_aff_list *list, void *user);
        void            *user;
 };
 
@@ -4529,23 +4530,39 @@ static void sol_for_free_wrap(struct isl_sol *sol)
  *
  * Instead of constructing a basic map, this function calls a user
  * defined function with the current context as a basic set and
- * an affine matrix representing the relation between the input and output.
- * The number of rows in this matrix is equal to one plus the number
- * of output variables.  The number of columns is equal to one plus
- * the total dimension of the context, i.e., the number of parameters,
- * input variables and divs.  Since some of the columns in the matrix
- * may refer to the divs, the basic set is not simplified.
- * (Simplification may reorder or remove divs.)
+ * a list of affine expressions representing the relation between
+ * the input and output.  The space over which the affine expressions
+ * are defined is the same as that of the domain.  The number of
+ * affine expressions in the list is equal to the number of output variables.
  */
 static void sol_for_add(struct isl_sol_for *sol,
        struct isl_basic_set *dom, struct isl_mat *M)
 {
+       int i;
+       isl_ctx *ctx;
+       isl_local_space *ls;
+       isl_aff *aff;
+       isl_aff_list *list;
+
        if (sol->sol.error || !dom || !M)
                goto error;
 
+       ctx = isl_basic_set_get_ctx(dom);
+       ls = isl_basic_set_get_local_space(dom);
+       list = isl_aff_list_alloc(ctx, M->n_row - 1);
+       for (i = 1; i < M->n_row; ++i) {
+               aff = isl_aff_alloc(isl_local_space_copy(ls));
+               if (aff) {
+                       isl_int_set_si(aff->v->el[0], 1);
+                       isl_seq_cpy(aff->v->el + 1, M->row[i], M->n_col);
+               }
+               list = isl_aff_list_add(list, aff);
+       }
+       isl_local_space_free(ls);
+
        dom = isl_basic_set_finalize(dom);
 
-       if (sol->fn(isl_basic_set_copy(dom), isl_mat_copy(M), sol->user) < 0)
+       if (sol->fn(isl_basic_set_copy(dom), list, sol->user) < 0)
                goto error;
 
        isl_basic_set_free(dom);
@@ -4564,7 +4581,7 @@ static void sol_for_add_wrap(struct isl_sol *sol,
 }
 
 static struct isl_sol_for *sol_for_init(struct isl_basic_map *bmap, int max,
-       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_mat *map,
+       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
                  void *user),
        void *user)
 {
@@ -4609,7 +4626,7 @@ static void sol_for_find_solutions(struct isl_sol_for *sol_for,
 }
 
 int isl_basic_map_foreach_lexopt(__isl_keep isl_basic_map *bmap, int max,
-       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_mat *map,
+       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
                  void *user),
        void *user)
 {
@@ -4645,7 +4662,7 @@ error:
 }
 
 int isl_basic_map_foreach_lexmin(__isl_keep isl_basic_map *bmap,
-       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_mat *map,
+       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
                  void *user),
        void *user)
 {
@@ -4653,7 +4670,7 @@ int isl_basic_map_foreach_lexmin(__isl_keep isl_basic_map *bmap,
 }
 
 int isl_basic_map_foreach_lexmax(__isl_keep isl_basic_map *bmap,
-       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_mat *map,
+       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
                  void *user),
        void *user)
 {
index 87a4bad..5f41579 100644 (file)
@@ -1228,9 +1228,26 @@ void test_lex(struct isl_ctx *ctx)
        isl_map_free(map);
 }
 
+static int consume_lexmin(__isl_take isl_basic_set *dom,
+       __isl_take isl_aff_list *list, void *user)
+{
+       isl_dim *dim;
+       isl_basic_map *bmap;
+       isl_map **map = user;
+
+       dim = isl_basic_set_get_dim(dom);
+       bmap = isl_basic_map_from_aff_list(dim, list);
+       bmap = isl_basic_map_intersect_domain(bmap, dom);
+
+       *map = isl_map_union(*map, isl_map_from_basic_map(bmap));
+
+       return 0;
+}
+
 void test_lexmin(struct isl_ctx *ctx)
 {
        const char *str;
+       isl_basic_map *bmap;
        isl_map *map, *map2;
        isl_set *set;
        isl_set *set2;
@@ -1290,6 +1307,16 @@ void test_lexmin(struct isl_ctx *ctx)
        assert(isl_map_is_equal(map, map2));
        isl_map_free(map);
        isl_map_free(map2);
+
+       str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
+                               " 8i' <= i and 8i' >= -7 + i }";
+       bmap = isl_basic_map_read_from_str(ctx, str, -1);
+       map2 = isl_map_empty(isl_basic_map_get_dim(bmap));
+       isl_basic_map_foreach_lexmin(bmap, &consume_lexmin, &map2);
+       map = isl_map_from_basic_map(bmap);
+       assert(isl_map_is_equal(map, map2));
+       isl_map_free(map);
+       isl_map_free(map2);
 }
 
 struct must_may {