isl_basic_map_is_empty: keep sample found for possible later reuse
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 12 Aug 2008 11:44:30 +0000 (13:44 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 25 Aug 2008 08:15:06 +0000 (10:15 +0200)
include/isl_map.h
include/isl_set.h
isl_map.c

index 8af220c..e78580c 100644 (file)
@@ -33,6 +33,7 @@ extern "C" {
  * n_out is the number of out variables
  * n_in + n_out should be equal to set.dim
  */
+struct isl_vec;
 struct isl_basic_map {
        int ref;
 #define ISL_BASIC_MAP_FINAL            (1 << 0)
@@ -55,6 +56,8 @@ struct isl_basic_map {
 
        isl_int **div;
 
+       struct isl_vec *sample;
+
        struct isl_blk block;
        struct isl_blk block2;
 };
index b45a301..7ab4f2e 100644 (file)
@@ -32,6 +32,8 @@ struct isl_basic_set {
 
        isl_int **div;
 
+       struct isl_vec *sample;
+
        struct isl_blk block;
        struct isl_blk block2;
 };
index 78cde5c..0398288 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -71,6 +71,7 @@ static struct isl_basic_map *basic_map_init(struct isl_ctx *ctx,
        bmap->n_eq = 0;
        bmap->n_ineq = 0;
        bmap->n_div = 0;
+       bmap->sample = NULL;
 
        return bmap;
 }
@@ -132,6 +133,7 @@ struct isl_basic_map *isl_basic_map_dup(struct isl_ctx *ctx,
        if (!dup)
                return NULL;
        dup_constraints(ctx, dup, bmap);
+       dup->sample = isl_vec_copy(ctx, bmap->sample);
        return dup;
 }
 
@@ -200,6 +202,7 @@ void isl_basic_map_free(struct isl_ctx *ctx, struct isl_basic_map *bmap)
        isl_blk_free(ctx, bmap->block2);
        free(bmap->eq);
        isl_blk_free(ctx, bmap->block);
+       isl_vec_free(ctx, bmap->sample);
        free(bmap);
 }
 
@@ -2582,12 +2585,47 @@ int isl_basic_map_is_strict_subset(struct isl_ctx *ctx,
        return !is_subset;
 }
 
+static int basic_map_contains(struct isl_ctx *ctx, struct isl_basic_map *bmap,
+                                        struct isl_vec *vec)
+{
+       int i;
+       unsigned total;
+       isl_int s;
+
+       total = 1 + bmap->nparam + bmap->n_in + bmap->n_out + bmap->n_div;
+       if (total != vec->size)
+               return -1;
+
+       isl_int_init(s);
+
+       for (i = 0; i < bmap->n_eq; ++i) {
+               isl_seq_inner_product(vec->block.data, bmap->eq[i], total, &s);
+               if (!isl_int_is_zero(s)) {
+                       isl_int_clear(s);
+                       return 0;
+               }
+       }
+
+       for (i = 0; i < bmap->n_ineq; ++i) {
+               isl_seq_inner_product(vec->block.data, bmap->ineq[i], total, &s);
+               if (isl_int_is_neg(s)) {
+                       isl_int_clear(s);
+                       return 0;
+               }
+       }
+
+       isl_int_clear(s);
+
+       return 1;
+}
+
 int isl_basic_map_is_empty(struct isl_ctx *ctx,
                struct isl_basic_map *bmap)
 {
        struct isl_basic_set *bset = NULL;
        struct isl_vec *sample = NULL;
        int empty;
+       unsigned total;
 
        if (!bmap)
                return -1;
@@ -2595,6 +2633,14 @@ int isl_basic_map_is_empty(struct isl_ctx *ctx,
        if (F_ISSET(bmap, ISL_BASIC_MAP_EMPTY))
                return 1;
 
+       total = 1 + bmap->nparam + bmap->n_in + bmap->n_out + bmap->n_div;
+       if (bmap->sample && bmap->sample->size == total) {
+               int contains = basic_map_contains(ctx, bmap, bmap->sample);
+               if (contains < 0)
+                       return -1;
+               if (contains)
+                       return 0;
+       }
        bset = isl_basic_map_underlying_set(ctx,
                        isl_basic_map_copy(ctx, bmap));
        if (!bset)
@@ -2603,7 +2649,9 @@ int isl_basic_map_is_empty(struct isl_ctx *ctx,
        if (!sample)
                return -1;
        empty = sample->size == 0;
-       isl_vec_free(ctx, sample);
+       if (bmap->sample)
+               isl_vec_free(ctx, bmap->sample);
+       bmap->sample = sample;
 
        return empty;
 }