isl_set_intersect: properly handle intersection with parameter domains
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 22 Sep 2011 09:53:09 +0000 (11:53 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 26 Sep 2011 15:57:37 +0000 (17:57 +0200)
isl_set_intersect currently allows one of its arguments to be a parameter
domain while the other is not.  This will probably change in future, but
while we still support this situation, we should make sure that the result
lives in the same space as that of the argument that is not a parameter domain.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_map.c

index 15af7dd..571125b 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -627,6 +627,17 @@ int isl_set_is_params(__isl_keep isl_set *set)
        return isl_space_is_params(set->dim);
 }
 
+/* Is this map actually a parameter domain?
+ * Users should never call this function.  Outside of isl,
+ * a map can never be a parameter domain.
+ */
+int isl_map_is_params(__isl_keep isl_map *map)
+{
+       if (!map)
+               return -1;
+       return isl_space_is_params(map->dim);
+}
+
 static struct isl_basic_map *basic_map_init(struct isl_ctx *ctx,
                struct isl_basic_map *bmap, unsigned extra,
                unsigned n_eq, unsigned n_ineq)
@@ -2483,6 +2494,8 @@ static __isl_give isl_map *map_intersect(__isl_take isl_map *map1,
            (map1->p[0]->n_eq + map1->p[0]->n_ineq == 1 ||
             map2->p[0]->n_eq + map2->p[0]->n_ineq == 1))
                return map_intersect_add_constraint(map1, map2);
+       if (isl_map_is_params(map1) && !isl_map_is_params(map2))
+               return isl_map_intersect(map2, map1);
        if (isl_space_dim(map1->dim, isl_dim_all) ==
                                isl_space_dim(map1->dim, isl_dim_param) &&
            isl_space_dim(map2->dim, isl_dim_all) !=