add isl_point_dump
[platform/upstream/isl.git] / isl_pw_templ.c
index e65e92d..ec8f12e 100644 (file)
@@ -190,6 +190,11 @@ __isl_give isl_id *FN(PW,get_dim_id)(__isl_keep PW *pw, enum isl_dim_type type,
        return pw ? isl_space_get_dim_id(pw->dim, type, pos) : NULL;
 }
 
+int FN(PW,has_tuple_name)(__isl_keep PW *pw, enum isl_dim_type type)
+{
+       return pw ? isl_space_has_tuple_name(pw->dim, type) : -1;
+}
+
 const char *FN(PW,get_tuple_name)(__isl_keep PW *pw, enum isl_dim_type type)
 {
        return pw ? isl_space_get_tuple_name(pw->dim, type) : NULL;
@@ -221,7 +226,7 @@ __isl_give PW *FN(PW,realign_domain)(__isl_take PW *pw,
 
        pw = FN(PW,cow)(pw);
        if (!pw || !exp)
-               return NULL;
+               goto error;
 
        for (i = 0; i < pw->n; ++i) {
                pw->p[i].set = isl_set_realign(pw->p[i].set,
@@ -371,14 +376,14 @@ static __isl_give PW *FN(PW,union_add_aligned)(__isl_take PW *pw1,
                for (j = 0; j < pw2->n; ++j) {
                        struct isl_set *common;
                        EL *sum;
-                       set = isl_set_subtract(set,
-                                       isl_set_copy(pw2->p[j].set));
                        common = isl_set_intersect(isl_set_copy(pw1->p[i].set),
                                                isl_set_copy(pw2->p[j].set));
                        if (isl_set_plain_is_empty(common)) {
                                isl_set_free(common);
                                continue;
                        }
+                       set = isl_set_subtract(set,
+                                       isl_set_copy(pw2->p[j].set));
 
                        sum = FN(EL,add_on_domain)(common,
                                                   FN(EL,copy)(pw1->p[i].FIELD),
@@ -511,44 +516,51 @@ __isl_give PW *FN(PW,add_disjoint)(__isl_take PW *pw1, __isl_take PW *pw2)
 
 /* This function is currently only used from isl_aff.c
  */
-static __isl_give PW *FN(PW,on_shared_domain)(__isl_take PW *pw1,
-       __isl_take PW *pw2,
+static __isl_give PW *FN(PW,on_shared_domain_in)(__isl_take PW *pw1,
+       __isl_take PW *pw2, __isl_take isl_space *space,
        __isl_give EL *(*fn)(__isl_take EL *el1, __isl_take EL *el2))
        __attribute__ ((unused));
 
 /* Apply "fn" to pairs of elements from pw1 and pw2 on shared domains.
+ * The result of "fn" (and therefore also of this function) lives in "space".
  */
-static __isl_give PW *FN(PW,on_shared_domain)(__isl_take PW *pw1,
-       __isl_take PW *pw2,
+static __isl_give PW *FN(PW,on_shared_domain_in)(__isl_take PW *pw1,
+       __isl_take PW *pw2, __isl_take isl_space *space,
        __isl_give EL *(*fn)(__isl_take EL *el1, __isl_take EL *el2))
 {
        int i, j, n;
-       PW *res;
+       PW *res = NULL;
 
        if (!pw1 || !pw2)
                goto error;
 
        n = pw1->n * pw2->n;
 #ifdef HAS_TYPE
-       res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->type, n);
+       res = FN(PW,alloc_size)(space, pw1->type, n);
 #else
-       res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), n);
+       res = FN(PW,alloc_size)(space, n);
 #endif
 
        for (i = 0; i < pw1->n; ++i) {
                for (j = 0; j < pw2->n; ++j) {
                        isl_set *common;
                        EL *res_ij;
+                       int empty;
+
                        common = isl_set_intersect(
                                        isl_set_copy(pw1->p[i].set),
                                        isl_set_copy(pw2->p[j].set));
-                       if (isl_set_plain_is_empty(common)) {
+                       empty = isl_set_plain_is_empty(common);
+                       if (empty < 0 || empty) {
                                isl_set_free(common);
+                               if (empty < 0)
+                                       goto error;
                                continue;
                        }
 
                        res_ij = fn(FN(EL,copy)(pw1->p[i].FIELD),
                                    FN(EL,copy)(pw2->p[j].FIELD));
+                       res_ij = FN(EL,gist)(res_ij, isl_set_copy(common));
 
                        res = FN(PW,add_piece)(res, common, res_ij);
                }
@@ -558,6 +570,35 @@ static __isl_give PW *FN(PW,on_shared_domain)(__isl_take PW *pw1,
        FN(PW,free)(pw2);
        return res;
 error:
+       isl_space_free(space);
+       FN(PW,free)(pw1);
+       FN(PW,free)(pw2);
+       FN(PW,free)(res);
+       return NULL;
+}
+
+/* This function is currently only used from isl_aff.c
+ */
+static __isl_give PW *FN(PW,on_shared_domain)(__isl_take PW *pw1,
+       __isl_take PW *pw2,
+       __isl_give EL *(*fn)(__isl_take EL *el1, __isl_take EL *el2))
+       __attribute__ ((unused));
+
+/* Apply "fn" to pairs of elements from pw1 and pw2 on shared domains.
+ * The result of "fn" is assumed to live in the same space as "pw1" and "pw2".
+ */
+static __isl_give PW *FN(PW,on_shared_domain)(__isl_take PW *pw1,
+       __isl_take PW *pw2,
+       __isl_give EL *(*fn)(__isl_take EL *el1, __isl_take EL *el2))
+{
+       isl_space *space;
+
+       if (!pw1 || !pw2)
+               goto error;
+
+       space = isl_space_copy(pw1->dim);
+       return FN(PW,on_shared_domain_in)(pw1, pw2, space, fn);
+error:
        FN(PW,free)(pw1);
        FN(PW,free)(pw2);
        return NULL;
@@ -1297,6 +1338,11 @@ error:
 }
 #endif
 
+int FN(PW,n_piece)(__isl_keep PW *pw)
+{
+       return pw ? pw->n : 0;
+}
+
 int FN(PW,foreach_piece)(__isl_keep PW *pw,
        int (*fn)(__isl_take isl_set *set, __isl_take EL *el, void *user),
        void *user)
@@ -1438,7 +1484,7 @@ __isl_give PW *FN(PW,mul_isl_int)(__isl_take PW *pw, isl_int v)
 
        if (isl_int_is_one(v))
                return pw;
-       if (pw && isl_int_is_zero(v)) {
+       if (pw && DEFAULT_IS_ZERO && isl_int_is_zero(v)) {
                PW *zero;
                isl_space *dim = FN(PW,get_space)(pw);
 #ifdef HAS_TYPE