Merge branch 'maint'
[platform/upstream/isl.git] / isl_union_templ.c
index a04759f..c06069d 100644 (file)
@@ -49,7 +49,7 @@ static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_dim *dim, int size)
        if (!dim)
                return NULL;
 
-       u = isl_calloc_type(ctx, UNION);
+       u = isl_calloc_type(dim->ctx, UNION);
        if (!u)
                return NULL;
 
@@ -279,7 +279,6 @@ static int align_entry(__isl_take PART *part, void *user)
 __isl_give UNION *FN(UNION,align_params)(__isl_take UNION *u,
        __isl_take isl_dim *model)
 {
-       int i, j;
        S(UNION,align) data = { NULL, NULL };
 
        if (!u || !model)
@@ -363,6 +362,12 @@ S(UNION,match_bin_data) {
        UNION *res;
 };
 
+/* This function is currently only used from isl_polynomial.c
+ * and not from isl_fold.c.
+ */
+static __isl_give UNION *match_bin_op(__isl_take UNION *u1,
+       __isl_take UNION *u2,
+       int (*fn)(void **, void *)) __attribute__ ((unused));
 static __isl_give UNION *match_bin_op(__isl_take UNION *u1,
        __isl_take UNION *u2, int (*fn)(void **, void *))
 {
@@ -412,7 +417,6 @@ static int match_set_entry(void **entry, void *user)
        S(UNION,match_set_data) *data = user;
        uint32_t hash;
        struct isl_hash_table_entry *entry2;
-       isl_dim *dim;
        PW *pw = *entry;
        int empty;
 
@@ -562,3 +566,49 @@ error:
        FN(UNION,free)(u);
        return NULL;
 }
+
+static int mul_isl_int(void **entry, void *user)
+{
+       PW **pw = (PW **)entry;
+       isl_int *v = user;
+
+       *pw = FN(PW,mul_isl_int)(*pw, *v);
+       if (!*pw)
+               return -1;
+
+       return 0;
+}
+
+__isl_give UNION *FN(UNION,mul_isl_int)(__isl_take UNION *u, isl_int v)
+{
+       if (isl_int_is_one(v))
+               return u;
+
+       if (u && isl_int_is_zero(v)) {
+               UNION *zero;
+               isl_dim *dim = FN(UNION,get_dim)(u);
+#ifdef HAS_TYPE
+               zero = FN(UNION,zero)(dim, u->type);
+#else
+               zero = FN(UNION,zero)(dim);
+#endif
+               FN(UNION,free)(u);
+               return zero;
+       }
+
+       u = FN(UNION,cow)(u);
+       if (!u)
+               return NULL;
+
+#ifdef HAS_TYPE
+       if (isl_int_is_neg(v))
+               u->type = isl_fold_type_negate(u->type);
+#endif
+       if (isl_hash_table_foreach(u->dim->ctx, &u->table, &mul_isl_int, v) < 0)
+               goto error;
+
+       return u;
+error:
+       FN(UNION,free)(u);
+       return NULL;
+}