add isl_basic_set_interval and isl_basic_set_product
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 28 Sep 2008 18:29:12 +0000 (20:29 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 14 Oct 2008 08:21:58 +0000 (10:21 +0200)
Makefile.am
include/isl_list.h [new file with mode: 0644]
include/isl_set.h
isl_list.c [new file with mode: 0644]
isl_map.c

index ac729ae..46906f1 100644 (file)
@@ -44,6 +44,7 @@ libisl_la_SOURCES = \
        isl_input.c \
        isl_input_omega.c \
        isl_input_omega.h \
+       isl_list.c \
        isl_lp.c \
        isl_map.c \
        isl_map_private.h \
@@ -79,6 +80,7 @@ pkginclude_HEADERS = \
        include/isl_blk.h \
        include/isl_ctx.h \
        include/isl_int.h \
+       include/isl_list.h \
        include/isl_lp.h \
        include/isl_lp_piplib.h \
        include/isl_map.h \
diff --git a/include/isl_list.h b/include/isl_list.h
new file mode 100644 (file)
index 0000000..44055fb
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef ISL_LIST_H
+#define ISL_LIST_H
+
+#include <isl_ctx.h>
+
+struct isl_basic_set;
+
+struct isl_basic_set_list {
+       int ref;
+       struct isl_ctx *ctx;
+
+       int n;
+
+       size_t size;
+       struct isl_basic_set *p[0];
+};
+
+struct isl_basic_set_list *isl_basic_set_list_alloc(struct isl_ctx *ctx, int n);
+void isl_basic_set_list_free(struct isl_basic_set_list *list);
+struct isl_basic_set_list *isl_basic_set_list_add(
+       struct isl_basic_set_list *list,
+       struct isl_basic_set *bset);
+
+#endif
index be6a590..a2deb08 100644 (file)
@@ -2,6 +2,7 @@
 #define ISL_SET_H
 
 #include "isl_map.h"
+#include "isl_list.h"
 
 #if defined(__cplusplus)
 extern "C" {
@@ -76,6 +77,8 @@ struct isl_basic_set *isl_basic_set_empty(struct isl_ctx *ctx,
                unsigned nparam, unsigned dim);
 struct isl_basic_set *isl_basic_set_universe(struct isl_ctx *ctx,
                unsigned nparam, unsigned dim);
+struct isl_basic_set *isl_basic_set_interval(struct isl_ctx *ctx,
+       isl_int min, isl_int max);
 void isl_basic_set_dump(struct isl_basic_set *bset,
                                FILE *out, int indent);
 struct isl_basic_set *isl_basic_set_swap_vars(
@@ -88,6 +91,8 @@ struct isl_basic_set *isl_basic_set_apply(
                struct isl_basic_map *bmap);
 struct isl_basic_set *isl_basic_set_affine_hull(struct isl_basic_set *bset);
 struct isl_basic_set *isl_basic_set_simplify(struct isl_basic_set *bset);
+struct isl_basic_set *isl_basic_set_product(struct isl_basic_set_list *list);
+
 #define ISL_FORMAT_POLYLIB             1
 #define ISL_FORMAT_OMEGA               2
 struct isl_basic_set *isl_basic_set_read_from_file(struct isl_ctx *ctx,
diff --git a/isl_list.c b/isl_list.c
new file mode 100644 (file)
index 0000000..b89078f
--- /dev/null
@@ -0,0 +1,52 @@
+#include "isl_list.h"
+
+struct isl_basic_set_list *isl_basic_set_list_alloc(struct isl_ctx *ctx, int n)
+{
+       struct isl_basic_set_list *list;
+
+       isl_assert(ctx, n >= 0, return NULL);
+       list = isl_alloc(ctx, struct isl_basic_set_list,
+                        sizeof(struct isl_basic_set_list) +
+                        n * sizeof(struct isl_basic_set *));
+       if (!list)
+               return NULL;
+
+       list->ctx = ctx;
+       isl_ctx_ref(ctx);
+       list->ref = 1;
+       list->size = n;
+       list->n = 0;
+       return list;
+}
+
+struct isl_basic_set_list *isl_basic_set_list_add(
+       struct isl_basic_set_list *list,
+       struct isl_basic_set *bset)
+{
+       if (!list || !bset)
+               goto error;
+       isl_assert(list->ctx, list->n < list->size, goto error);
+       list->p[list->n] = bset;
+       list->n++;
+       return list;
+error:
+       isl_basic_set_free(bset);
+       isl_basic_set_list_free(list);
+       return NULL;
+}
+
+void isl_basic_set_list_free(struct isl_basic_set_list *list)
+{
+       int i;
+
+       if (!list)
+               return;
+
+       if (--list->ref > 0)
+               return;
+
+       isl_ctx_deref(list->ctx);
+       for (i = 0; i < list->n; ++i)
+               isl_basic_set_free(list->p[i]);
+       free(list);
+}
index 2664131..eaeccb0 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -3,6 +3,7 @@
 #include "isl_ctx.h"
 #include "isl_blk.h"
 #include "isl_equalities.h"
+#include "isl_list.h"
 #include "isl_lp.h"
 #include "isl_seq.h"
 #include "isl_set.h"
@@ -4524,3 +4525,80 @@ int isl_set_fast_is_equal(struct isl_set *set1, struct isl_set *set2)
        return isl_map_fast_is_equal((struct isl_map *)set1,
                                                (struct isl_map *)set2);
 }
+
+/* Return an interval that ranges from min to max (inclusive)
+ */
+struct isl_basic_set *isl_basic_set_interval(struct isl_ctx *ctx,
+       isl_int min, isl_int max)
+{
+       int k;
+       struct isl_basic_set *bset = NULL;
+
+       bset = isl_basic_set_alloc(ctx, 0, 1, 0, 0, 2);
+       if (!bset)
+               goto error;
+
+       k = isl_basic_set_alloc_inequality(bset);
+       if (k < 0)
+               goto error;
+       isl_int_set_si(bset->ineq[k][1], 1);
+       isl_int_neg(bset->ineq[k][0], min);
+
+       k = isl_basic_set_alloc_inequality(bset);
+       if (k < 0)
+               goto error;
+       isl_int_set_si(bset->ineq[k][1], -1);
+       isl_int_set(bset->ineq[k][0], max);
+
+       return bset;
+error:
+       isl_basic_set_free(bset);
+       return NULL;
+}
+
+/* Return the Cartesian product of the basic sets in list (in the given order).
+ */
+struct isl_basic_set *isl_basic_set_product(struct isl_basic_set_list *list)
+{
+       int i;
+       unsigned dim;
+       unsigned nparam;
+       unsigned extra;
+       unsigned n_eq;
+       unsigned n_ineq;
+       struct isl_basic_set *product = NULL;
+
+       if (!list)
+               goto error;
+       isl_assert(list->ctx, list->n > 0, goto error);
+       isl_assert(list->ctx, list->p[0], goto error);
+       nparam = list->p[0]->nparam;
+       dim = list->p[0]->dim;
+       extra = list->p[0]->n_div;
+       n_eq = list->p[0]->n_eq;
+       n_ineq = list->p[0]->n_ineq;
+       for (i = 1; i < list->n; ++i) {
+               isl_assert(list->ctx, list->p[i], goto error);
+               isl_assert(list->ctx, nparam == list->p[i]->nparam, goto error);
+               dim += list->p[i]->dim;
+               extra += list->p[i]->n_div;
+               n_eq += list->p[i]->n_eq;
+               n_ineq += list->p[i]->n_ineq;
+       }
+       product = isl_basic_set_alloc(list->ctx, nparam, dim, extra,
+                                       n_eq, n_ineq);
+       if (!product)
+               goto error;
+       dim = 0;
+       for (i = 0; i < list->n; ++i) {
+               set_add_constraints(product,
+                                       isl_basic_set_copy(list->p[i]), dim);
+               dim += list->p[i]->dim;
+       }
+       isl_basic_set_list_free(list);
+       return product;
+error:
+       isl_basic_set_free(product);
+       isl_basic_set_list_free(list);
+       return NULL;
+}