add isl_local_space_is_div_constraint
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 1 Jul 2011 15:20:27 +0000 (17:20 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 23 Jul 2011 14:25:51 +0000 (16:25 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_local_space.c
isl_local_space_private.h

index 17ac9ea..8cf99a6 100644 (file)
@@ -610,3 +610,51 @@ __isl_give isl_local_space *isl_local_space_insert_dims(
 
        return ls;
 }
+
+/* Check if the constraints pointed to by "constraint" is a div
+ * constraint corresponding to div "div" in "ls".
+ *
+ * That is, if div = floor(f/m), then check if the constraint is
+ *
+ *             f - m d >= 0
+ * or
+ *             -(f-(m-1)) + m d >= 0
+ */
+int isl_local_space_is_div_constraint(__isl_keep isl_local_space *ls,
+       isl_int *constraint, unsigned div)
+{
+       unsigned pos;
+
+       if (!ls)
+               return -1;
+
+       if (isl_int_is_zero(ls->div->row[div][0]))
+               return 0;
+
+       pos = isl_local_space_offset(ls, isl_dim_div) + div;
+
+       if (isl_int_eq(constraint[pos], ls->div->row[div][0])) {
+               int neg;
+               isl_int_sub(ls->div->row[div][1],
+                               ls->div->row[div][1], ls->div->row[div][0]);
+               isl_int_add_ui(ls->div->row[div][1], ls->div->row[div][1], 1);
+               neg = isl_seq_is_neg(constraint, ls->div->row[div]+1, pos);
+               isl_int_sub_ui(ls->div->row[div][1], ls->div->row[div][1], 1);
+               isl_int_add(ls->div->row[div][1],
+                               ls->div->row[div][1], ls->div->row[div][0]);
+               if (!neg)
+                       return 0;
+               if (isl_seq_first_non_zero(constraint+pos+1,
+                                           ls->div->n_row-div-1) != -1)
+                       return 0;
+       } else if (isl_int_abs_eq(constraint[pos], ls->div->row[div][0])) {
+               if (!isl_seq_eq(constraint, ls->div->row[div]+1, pos))
+                       return 0;
+               if (isl_seq_first_non_zero(constraint+pos+1,
+                                           ls->div->n_row-div-1) != -1)
+                       return 0;
+       } else
+               return 0;
+
+       return 1;
+}
index 6f3e93d..de8a760 100644 (file)
@@ -40,4 +40,7 @@ __isl_give isl_local_space *isl_local_space_reset_dim(
 __isl_give isl_local_space *isl_local_space_realign(
        __isl_take isl_local_space *ls, __isl_take isl_reordering *r);
 
+int isl_local_space_is_div_constraint(__isl_keep isl_local_space *ls,
+       isl_int *constraint, unsigned div);
+
 #endif