isl 0.12
[platform/upstream/isl.git] / isl_aff.c
index 0ccab13..3b2d20e 100644 (file)
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -5186,100 +5186,107 @@ error:
 
 #include <isl_multi_templ.c>
 
-/* Scale the first elements of "ma" by the corresponding elements of "vec".
+/* Scale the elements of "pma" by the corresponding elements of "mv".
  */
-__isl_give isl_multi_aff *isl_multi_aff_scale_vec(__isl_take isl_multi_aff *ma,
-       __isl_take isl_vec *vec)
-{
-       int i, n;
-       isl_int v;
-
-       if (!ma || !vec)
-               goto error;
-
-       n = isl_multi_aff_dim(ma, isl_dim_out);
-       if (isl_vec_size(vec) < n)
-               n = isl_vec_size(vec);
-
-       isl_int_init(v);
-       for (i = 0; i < n; ++i) {
-               isl_aff *aff;
-
-               isl_vec_get_element(vec, i, &v);
-
-               aff = isl_multi_aff_get_aff(ma, i);
-               aff = isl_aff_scale(aff, v);
-               ma = isl_multi_aff_set_aff(ma, i, aff);
-       }
-       isl_int_clear(v);
-
-       isl_vec_free(vec);
-       return ma;
-error:
-       isl_vec_free(vec);
-       isl_multi_aff_free(ma);
-       return NULL;
-}
-
-/* Scale the first elements of "pma" by the corresponding elements of "vec".
- */
-__isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_vec(
-       __isl_take isl_pw_multi_aff *pma, __isl_take isl_vec *v)
+__isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_multi_val(
+       __isl_take isl_pw_multi_aff *pma, __isl_take isl_multi_val *mv)
 {
        int i;
 
        pma = isl_pw_multi_aff_cow(pma);
-       if (!pma || !v)
+       if (!pma || !mv)
                goto error;
+       if (!isl_space_tuple_match(pma->dim, isl_dim_out,
+                                       mv->space, isl_dim_set))
+               isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid,
+                       "spaces don't match", goto error);
+       if (!isl_space_match(pma->dim, isl_dim_param,
+                                       mv->space, isl_dim_param)) {
+               pma = isl_pw_multi_aff_align_params(pma,
+                                           isl_multi_val_get_space(mv));
+               mv = isl_multi_val_align_params(mv,
+                                           isl_pw_multi_aff_get_space(pma));
+               if (!pma || !mv)
+                       goto error;
+       }
 
        for (i = 0; i < pma->n; ++i) {
-               pma->p[i].maff = isl_multi_aff_scale_vec(pma->p[i].maff,
-                                                       isl_vec_copy(v));
+               pma->p[i].maff = isl_multi_aff_scale_multi_val(pma->p[i].maff,
+                                                       isl_multi_val_copy(mv));
                if (!pma->p[i].maff)
                        goto error;
        }
 
-       isl_vec_free(v);
+       isl_multi_val_free(mv);
        return pma;
 error:
-       isl_vec_free(v);
+       isl_multi_val_free(mv);
        isl_pw_multi_aff_free(pma);
        return NULL;
 }
 
+/* Internal data structure for isl_union_pw_multi_aff_scale_multi_val.
+ * mv contains the mv argument.
+ * res collects the results.
+ */
+struct isl_union_pw_multi_aff_scale_multi_val_data {
+       isl_multi_val *mv;
+       isl_union_pw_multi_aff *res;
+};
+
 /* This function is called for each entry of an isl_union_pw_multi_aff.
- * Replace the entry by the result of applying isl_pw_multi_aff_scale_vec
- * to the original entry with the isl_vec in "user" as extra argument.
+ * If the space of the entry matches that of data->mv,
+ * then apply isl_pw_multi_aff_scale_multi_val and add the result
+ * to data->res.
  */
-static int union_pw_multi_aff_scale_vec_entry(void **entry, void *user)
+static int union_pw_multi_aff_scale_multi_val_entry(void **entry, void *user)
 {
-       isl_pw_multi_aff **pma = (isl_pw_multi_aff **) entry;
-       isl_vec *v = user;
+       struct isl_union_pw_multi_aff_scale_multi_val_data *data = user;
+       isl_pw_multi_aff *pma = *entry;
+
+       if (!pma)
+               return -1;
+       if (!isl_space_tuple_match(pma->dim, isl_dim_out,
+                                   data->mv->space, isl_dim_set))
+               return 0;
 
-       *pma = isl_pw_multi_aff_scale_vec(*pma, isl_vec_copy(v));
-       if (!*pma)
+       pma = isl_pw_multi_aff_copy(pma);
+       pma = isl_pw_multi_aff_scale_multi_val(pma,
+                                               isl_multi_val_copy(data->mv));
+       data->res = isl_union_pw_multi_aff_add_pw_multi_aff(data->res, pma);
+       if (!data->res)
                return -1;
 
        return 0;
 }
 
-/* Scale the first elements of "upma" by the corresponding elements of "vec".
+/* Scale the elements of "upma" by the corresponding elements of "mv",
+ * for those entries that match the space of "mv".
  */
-__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_scale_vec(
-       __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_vec *v)
+__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_scale_multi_val(
+       __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_multi_val *mv)
 {
-       upma = isl_union_pw_multi_aff_cow(upma);
-       if (!upma || !v)
+       struct isl_union_pw_multi_aff_scale_multi_val_data data;
+
+       upma = isl_union_pw_multi_aff_align_params(upma,
+                                               isl_multi_val_get_space(mv));
+       mv = isl_multi_val_align_params(mv,
+                                       isl_union_pw_multi_aff_get_space(upma));
+       if (!upma || !mv)
                goto error;
 
+       data.mv = mv;
+       data.res = isl_union_pw_multi_aff_alloc(isl_space_copy(upma->dim),
+                                               upma->table.n);
        if (isl_hash_table_foreach(upma->dim->ctx, &upma->table,
-                                  &union_pw_multi_aff_scale_vec_entry, v) < 0)
+                      &union_pw_multi_aff_scale_multi_val_entry, &data) < 0)
                goto error;
 
-       isl_vec_free(v);
-       return upma;
+       isl_multi_val_free(mv);
+       isl_union_pw_multi_aff_free(upma);
+       return data.res;
 error:
-       isl_vec_free(v);
+       isl_multi_val_free(mv);
        isl_union_pw_multi_aff_free(upma);
        return NULL;
 }