add isl_basic_set_foreach_lexopt
[platform/upstream/isl.git] / isl_tab_pip.c
index 00efda4..01657a0 100644 (file)
@@ -16,6 +16,8 @@
 #include "isl_tab.h"
 #include "isl_sample.h"
 #include <isl_mat_private.h>
+#include <isl_aff_private.h>
+#include <isl_config.h>
 
 /*
  * The implementation of parametric integer linear programming in this file
@@ -1116,6 +1118,7 @@ static int first_neg(struct isl_tab *tab)
  * is satisfied.  This function is not called from the current code
  * but is useful during debugging.
  */
+static void check_lexpos(struct isl_tab *tab) __attribute__ ((unused));
 static void check_lexpos(struct isl_tab *tab)
 {
        unsigned off = 2 + tab->M;
@@ -4505,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;
 };
 
@@ -4527,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);
@@ -4562,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)
 {
@@ -4607,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)
 {
@@ -4642,8 +4661,16 @@ error:
        return -1;
 }
 
+int isl_basic_set_foreach_lexopt(__isl_keep isl_basic_set *bset, int max,
+       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
+                 void *user),
+       void *user)
+{
+       return isl_basic_map_foreach_lexopt(bset, max, fn, user);
+}
+
 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)
 {
@@ -4651,13 +4678,21 @@ 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)
 {
        return isl_basic_map_foreach_lexopt(bmap, 1, fn, user);
 }
 
+int isl_basic_set_foreach_lexmax(__isl_keep isl_basic_set *bset,
+       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
+                 void *user),
+       void *user)
+{
+       return isl_basic_map_foreach_lexmax(bset, fn, user);
+}
+
 /* Check if the given sequence of len variables starting at pos
  * represents a trivial (i.e., zero) solution.
  * The variables are assumed to be non-negative and to come in pairs,