add ISL_CTX_{GET,SET}_STR_DEF macros
[platform/upstream/isl.git] / isl_map_simplify.c
index 2582d08..90b36f4 100644 (file)
@@ -2016,11 +2016,49 @@ error:
        return NULL;
 }
 
+/* Return a map that has the same intersection with "context" as "map"
+ * and that as "simple" as possible.
+ *
+ * If "map" is already the universe, then we cannot make it any simpler.
+ * Similarly, if "context" is the universe, then we cannot exploit it
+ * to simplify "map"
+ * If "map" and "context" are identical to each other, then we can
+ * return the corresponding universe.
+ *
+ * If none of these cases apply, we have to work a bit harder.
+ */
 static __isl_give isl_map *map_gist(__isl_take isl_map *map,
        __isl_take isl_map *context)
 {
+       int equal;
+       int is_universe;
+
+       is_universe = isl_map_plain_is_universe(map);
+       if (is_universe >= 0 && !is_universe)
+               is_universe = isl_map_plain_is_universe(context);
+       if (is_universe < 0)
+               goto error;
+       if (is_universe) {
+               isl_map_free(context);
+               return map;
+       }
+
+       equal = isl_map_plain_is_equal(map, context);
+       if (equal < 0)
+               goto error;
+       if (equal) {
+               isl_map *res = isl_map_universe(isl_map_get_space(map));
+               isl_map_free(map);
+               isl_map_free(context);
+               return res;
+       }
+
        context = isl_map_compute_divs(context);
        return isl_map_gist_basic_map(map, isl_map_simple_hull(context));
+error:
+       isl_map_free(map);
+       isl_map_free(context);
+       return NULL;
 }
 
 __isl_give isl_map *isl_map_gist(__isl_take isl_map *map,
@@ -2199,6 +2237,46 @@ int isl_map_plain_is_disjoint(__isl_keep isl_map *map1,
        return 1;
 }
 
+/* Are "map1" and "map2" disjoint?
+ *
+ * They are disjoint if they are "obviously disjoint" or if one of them
+ * is empty.  Otherwise, they are not disjoint if one of them is universal.
+ * If none of these cases apply, we compute the intersection and see if
+ * the result is empty.
+ */
+int isl_map_is_disjoint(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
+{
+       int disjoint;
+       int intersect;
+       isl_map *test;
+
+       disjoint = isl_map_plain_is_disjoint(map1, map2);
+       if (disjoint < 0 || disjoint)
+               return disjoint;
+
+       disjoint = isl_map_is_empty(map1);
+       if (disjoint < 0 || disjoint)
+               return disjoint;
+
+       disjoint = isl_map_is_empty(map2);
+       if (disjoint < 0 || disjoint)
+               return disjoint;
+
+       intersect = isl_map_plain_is_universe(map1);
+       if (intersect < 0 || intersect)
+               return intersect < 0 ? -1 : 0;
+
+       intersect = isl_map_plain_is_universe(map2);
+       if (intersect < 0 || intersect)
+               return intersect < 0 ? -1 : 0;
+
+       test = isl_map_intersect(isl_map_copy(map1), isl_map_copy(map2));
+       disjoint = isl_map_is_empty(test);
+       isl_map_free(test);
+
+       return disjoint;
+}
+
 int isl_set_plain_is_disjoint(__isl_keep isl_set *set1,
        __isl_keep isl_set *set2)
 {
@@ -2206,6 +2284,13 @@ int isl_set_plain_is_disjoint(__isl_keep isl_set *set1,
                                        (struct isl_map *)set2);
 }
 
+/* Are "set1" and "set2" disjoint?
+ */
+int isl_set_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
+{
+       return isl_map_is_disjoint(set1, set2);
+}
+
 int isl_set_fast_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
 {
        return isl_set_plain_is_disjoint(set1, set2);