add isl_aff_mod_val
[platform/upstream/isl.git] / isl_ast_graft.c
index 2f21e8e..0ec839b 100644 (file)
@@ -7,7 +7,6 @@
  * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
  */
 
-#include <isl_list_private.h>
 #include <isl_ast_private.h>
 #include <isl_ast_build_expr.h>
 #include <isl_ast_build_private.h>
@@ -686,7 +685,8 @@ static __isl_give isl_basic_set *extract_shared_enforced(
 /* Record "guard" in "graft" so that it will be enforced somewhere
  * up the tree.  If the graft already has a guard, then it may be partially
  * redundant in combination with the new guard and in the context
- * of build->domain.  We therefore (re)compute the gist of the intersection.
+ * of build->domain.  We therefore (re)compute the gist of the intersection
+ * and coalesce the result.
  */
 static __isl_give isl_ast_graft *store_guard(__isl_take isl_ast_graft *graft,
        __isl_take isl_set *guard, __isl_keep isl_ast_build *build)
@@ -706,6 +706,7 @@ static __isl_give isl_ast_graft *store_guard(__isl_take isl_ast_graft *graft,
 
        graft->guard = isl_set_intersect(graft->guard, guard);
        graft->guard = isl_ast_build_compute_gist(build, graft->guard);
+       graft->guard = isl_set_coalesce(graft->guard);
        if (!graft->guard)
                return isl_ast_graft_free(graft);
 
@@ -1073,27 +1074,18 @@ __isl_give isl_ast_graft_list *isl_ast_graft_list_preimage_multi_aff(
 
 /* Compare two grafts based on their guards.
  */
-static int cmp_graft(const void *a, const void *b)
+static int cmp_graft(__isl_keep isl_ast_graft *a, __isl_keep isl_ast_graft *b,
+       void *user)
 {
-       isl_ast_graft * const *g1 = a;
-       isl_ast_graft * const *g2 = b;
-
-       return isl_set_plain_cmp((*g1)->guard, (*g2)->guard);
+       return isl_set_plain_cmp(a->guard, b->guard);
 }
 
 /* Order the elements in "list" based on their guards.
  */
-__isl_give isl_ast_graft_list *isl_ast_graft_list_sort(
+__isl_give isl_ast_graft_list *isl_ast_graft_list_sort_guard(
        __isl_take isl_ast_graft_list *list)
 {
-       if (!list)
-               return NULL;
-       if (list->n <= 1)
-               return list;
-
-       qsort(list->p, list->n, sizeof(list->p[0]), &cmp_graft);
-
-       return list;
+       return isl_ast_graft_list_sort(list, &cmp_graft, NULL);
 }
 
 /* Merge the given two lists into a single list of grafts,