isl_flow.c: before: use isl_vec_cmp_element
[platform/upstream/isl.git] / isl_pw_templ.c
index 3993974..fb60651 100644 (file)
@@ -1,4 +1,5 @@
 #include <isl/aff.h>
+#include <isl_val_private.h>
 
 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
 #define FN(TYPE,NAME) xFN(TYPE,NAME)
@@ -1121,6 +1122,27 @@ error:
        return NULL;
 }
 
+/* Fix the value of the variable at position "pos" of type "type" of "pw"
+ * to be equal to "v".
+ */
+__isl_give PW *FN(PW,fix_val)(__isl_take PW *pw,
+       enum isl_dim_type type, unsigned pos, __isl_take isl_val *v)
+{
+       if (!v)
+               return FN(PW,free)(pw);
+       if (!isl_val_is_int(v))
+               isl_die(FN(PW,get_ctx)(pw), isl_error_invalid,
+                       "expecting integer value", goto error);
+
+       pw = FN(PW,fix_dim)(pw, type, pos, v->n);
+       isl_val_free(v);
+
+       return pw;
+error:
+       isl_val_free(v);
+       return FN(PW,free)(pw);
+}
+
 unsigned FN(PW,dim)(__isl_keep PW *pw, enum isl_dim_type type)
 {
        return pw ? isl_space_dim(pw->dim, type) : 0;
@@ -1524,6 +1546,58 @@ error:
        return NULL;
 }
 
+/* Multiply the pieces of "pw" by "v" and return the result.
+ */
+__isl_give PW *FN(PW,scale_val)(__isl_take PW *pw, __isl_take isl_val *v)
+{
+       int i;
+
+       if (!pw || !v)
+               goto error;
+
+       if (isl_val_is_one(v)) {
+               isl_val_free(v);
+               return pw;
+       }
+       if (pw && DEFAULT_IS_ZERO && isl_val_is_zero(v)) {
+               PW *zero;
+               isl_space *space = FN(PW,get_space)(pw);
+#ifdef HAS_TYPE
+               zero = FN(PW,ZERO)(space, pw->type);
+#else
+               zero = FN(PW,ZERO)(space);
+#endif
+               FN(PW,free)(pw);
+               isl_val_free(v);
+               return zero;
+       }
+       if (pw->n == 0) {
+               isl_val_free(v);
+               return pw;
+       }
+       pw = FN(PW,cow)(pw);
+       if (!pw)
+               goto error;
+
+#ifdef HAS_TYPE
+       if (isl_val_is_neg(v))
+               pw->type = isl_fold_type_negate(pw->type);
+#endif
+       for (i = 0; i < pw->n; ++i) {
+               pw->p[i].FIELD = FN(EL,scale_val)(pw->p[i].FIELD,
+                                                   isl_val_copy(v));
+               if (!pw->p[i].FIELD)
+                       goto error;
+       }
+
+       isl_val_free(v);
+       return pw;
+error:
+       isl_val_free(v);
+       FN(PW,free)(pw);
+       return NULL;
+}
+
 __isl_give PW *FN(PW,scale)(__isl_take PW *pw, isl_int v)
 {
        return FN(PW,mul_isl_int)(pw, v);