add isl_local_space_substitute
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 16 Aug 2011 09:00:43 +0000 (11:00 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 2 Oct 2011 09:03:36 +0000 (11:03 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_local_space.c
isl_local_space_private.h

index 42527c7..5c963d8 100644 (file)
@@ -570,6 +570,60 @@ error:
        return NULL;
 }
 
+/* Plug in "subs" for dimension "type", "pos" in the integer divisions
+ * of "ls".
+ *
+ * Let i be the dimension to replace and let "subs" be of the form
+ *
+ *     f/d
+ *
+ * Any integer division with a non-zero coefficient for i,
+ *
+ *     floor((a i + g)/m)
+ *
+ * is replaced by
+ *
+ *     floor((a f + d g)/(m d))
+ */
+__isl_give isl_local_space *isl_local_space_substitute(
+       __isl_take isl_local_space *ls,
+       enum isl_dim_type type, unsigned pos, __isl_keep isl_aff *subs)
+{
+       int i;
+       isl_int v;
+
+       ls = isl_local_space_cow(ls);
+       if (!ls || !subs)
+               return isl_local_space_free(ls);
+
+       if (!isl_space_is_equal(ls->dim, subs->ls->dim))
+               isl_die(isl_local_space_get_ctx(ls), isl_error_invalid,
+                       "spaces don't match", return isl_local_space_free(ls));
+       if (isl_local_space_dim(subs->ls, isl_dim_div) != 0)
+               isl_die(isl_local_space_get_ctx(ls), isl_error_unsupported,
+                       "cannot handle divs yet",
+                       return isl_local_space_free(ls));
+
+       pos += isl_local_space_offset(ls, type);
+
+       isl_int_init(v);
+       for (i = 0; i < ls->div->n_row; ++i) {
+               if (isl_int_is_zero(ls->div->row[i][1 + pos]))
+                       continue;
+               isl_int_set(v, ls->div->row[i][1 + pos]);
+               isl_int_set_si(ls->div->row[i][1 + pos], 0);
+               isl_seq_combine(ls->div->row[i] + 1,
+                               subs->v->el[0], ls->div->row[i] + 1,
+                               v, subs->v->el + 1, subs->v->size - 1);
+               isl_int_mul(ls->div->row[i][0],
+                           ls->div->row[i][0], subs->v->el[0]);
+               normalize_div(ls, i);
+       }
+       isl_int_clear(v);
+
+       return ls;
+}
+
 int isl_local_space_is_named_or_nested(__isl_keep isl_local_space *ls,
        enum isl_dim_type type)
 {
index 4777753..744b513 100644 (file)
@@ -46,4 +46,8 @@ int isl_local_space_is_div_constraint(__isl_keep isl_local_space *ls,
 
 int *isl_local_space_get_active(__isl_keep isl_local_space *ls, isl_int *l);
 
+__isl_give isl_local_space *isl_local_space_substitute(
+       __isl_take isl_local_space *ls,
+       enum isl_dim_type type, unsigned pos, __isl_keep isl_aff *subs);
+
 #endif