* 91893 Orsay, France
*/
-#include <isl_ctx.h>
-#include <isl_hash.h>
-#include <isl_map.h>
-#include <isl_set.h>
-#include <isl_dim_private.h>
#include <isl_map_private.h>
+#include <isl/ctx.h>
+#include <isl/hash.h>
+#include <isl/map.h>
+#include <isl/set.h>
+#include <isl_dim_private.h>
#include <isl_union_map_private.h>
-#include <isl_union_set.h>
+#include <isl/union_set.h>
static __isl_give isl_union_map *isl_union_map_alloc(__isl_take isl_dim *dim,
int size)
uint32_t hash;
struct isl_hash_table_entry *entry;
- if (isl_map_fast_is_empty(map)) {
+ if (isl_map_plain_is_empty(map)) {
isl_map_free(map);
return umap;
}
return data->fn(isl_map_copy(map), data->user);
}
+int isl_union_map_n_map(__isl_keep isl_union_map *umap)
+{
+ return umap ? umap->table.n : 0;
+}
+
+int isl_union_set_n_set(__isl_keep isl_union_set *uset)
+{
+ return uset ? uset->table.n : 0;
+}
+
int isl_union_map_foreach_map(__isl_keep isl_union_map *umap,
int (*fn)(__isl_take isl_map *map, void *user), void *user)
{
&call_on_copy, &data);
}
+static int copy_map(void **entry, void *user)
+{
+ isl_map *map = *entry;
+ isl_map **map_p = user;
+
+ *map_p = isl_map_copy(map);
+
+ return -1;
+}
+
+__isl_give isl_map *isl_union_map_copy_map(__isl_keep isl_union_map *umap)
+{
+ isl_map *map = NULL;
+
+ if (!umap || umap->table.n == 0)
+ return NULL;
+
+ isl_hash_table_foreach(umap->dim->ctx, &umap->table, ©_map, &map);
+
+ return map;
+}
+
+__isl_give isl_set *isl_union_set_copy_set(__isl_keep isl_union_set *uset)
+{
+ return isl_union_map_copy_map(uset);
+}
+
+__isl_give isl_map *isl_union_map_extract_map(__isl_keep isl_union_map *umap,
+ __isl_take isl_dim *dim)
+{
+ uint32_t hash;
+ struct isl_hash_table_entry *entry;
+
+ if (!umap || !dim)
+ goto error;
+
+ hash = isl_dim_get_hash(dim);
+ entry = isl_hash_table_find(umap->dim->ctx, &umap->table, hash,
+ &has_dim, dim, 0);
+ if (!entry)
+ return isl_map_empty(dim);
+ isl_dim_free(dim);
+ return isl_map_copy(entry->data);
+error:
+ isl_dim_free(dim);
+ return NULL;
+}
+
+__isl_give isl_set *isl_union_set_extract_set(__isl_keep isl_union_set *uset,
+ __isl_take isl_dim *dim)
+{
+ return (isl_set *)isl_union_map_extract_map(uset, dim);
+}
+
+/* Check if umap contains a map in the given space.
+ */
+__isl_give int isl_union_map_contains(__isl_keep isl_union_map *umap,
+ __isl_keep isl_dim *dim)
+{
+ uint32_t hash;
+ struct isl_hash_table_entry *entry;
+
+ if (!umap || !dim)
+ return -1;
+
+ hash = isl_dim_get_hash(dim);
+ entry = isl_hash_table_find(umap->dim->ctx, &umap->table, hash,
+ &has_dim, dim, 0);
+ return !!entry;
+}
+
+__isl_give int isl_union_set_contains(__isl_keep isl_union_set *uset,
+ __isl_keep isl_dim *dim)
+{
+ return isl_union_map_contains(uset, dim);
+}
+
int isl_union_set_foreach_set(__isl_keep isl_union_set *uset,
int (*fn)(__isl_take isl_set *set, void *user), void *user)
{
__isl_give isl_union_map *isl_union_set_lex_gt_union_set(
__isl_take isl_union_set *uset1, __isl_take isl_union_set *uset2)
{
- return isl_union_set_lex_lt_union_set(uset2, uset1);
+ return isl_union_map_reverse(isl_union_set_lex_lt_union_set(uset2, uset1));
}
__isl_give isl_union_map *isl_union_set_lex_ge_union_set(
__isl_take isl_union_set *uset1, __isl_take isl_union_set *uset2)
{
- return isl_union_set_lex_le_union_set(uset2, uset1);
+ return isl_union_map_reverse(isl_union_set_lex_le_union_set(uset2, uset1));
}
__isl_give isl_union_map *isl_union_map_lex_gt_union_map(
__isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2)
{
- return isl_union_map_lex_lt_union_map(umap2, umap1);
+ return isl_union_map_reverse(isl_union_map_lex_lt_union_map(umap2, umap1));
}
__isl_give isl_union_map *isl_union_map_lex_ge_union_map(
__isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2)
{
- return isl_union_map_lex_le_union_map(umap2, umap1);
+ return isl_union_map_reverse(isl_union_map_lex_le_union_map(umap2, umap1));
}
static int intersect_domain_entry(void **entry, void *user)
return gen_bin_op(umap, uset, &intersect_domain_entry);
}
+static int intersect_range_entry(void **entry, void *user)
+{
+ struct isl_union_map_gen_bin_data *data = user;
+ uint32_t hash;
+ struct isl_hash_table_entry *entry2;
+ isl_dim *dim;
+ isl_map *map = *entry;
+ int empty;
+
+ dim = isl_map_get_dim(map);
+ dim = isl_dim_range(dim);
+ hash = isl_dim_get_hash(dim);
+ entry2 = isl_hash_table_find(data->umap2->dim->ctx, &data->umap2->table,
+ hash, &has_dim, dim, 0);
+ isl_dim_free(dim);
+ if (!entry2)
+ return 0;
+
+ map = isl_map_copy(map);
+ map = isl_map_intersect_range(map, isl_set_copy(entry2->data));
+
+ empty = isl_map_is_empty(map);
+ if (empty < 0) {
+ isl_map_free(map);
+ return -1;
+ }
+ if (empty) {
+ isl_map_free(map);
+ return 0;
+ }
+
+ data->res = isl_union_map_add_map(data->res, map);
+
+ return 0;
+}
+
+__isl_give isl_union_map *isl_union_map_intersect_range(
+ __isl_take isl_union_map *umap, __isl_take isl_union_set *uset)
+{
+ return gen_bin_op(umap, uset, &intersect_range_entry);
+}
+
struct isl_union_map_bin_data {
isl_union_map *umap2;
isl_union_map *res;
return isl_union_map_product(uset1, uset2);
}
+static int range_product_entry(void **entry, void *user)
+{
+ struct isl_union_map_bin_data *data = user;
+ isl_map *map2 = *entry;
+
+ map2 = isl_map_range_product(isl_map_copy(data->map),
+ isl_map_copy(map2));
+
+ data->res = isl_union_map_add_map(data->res, map2);
+
+ return 0;
+}
+
+__isl_give isl_union_map *isl_union_map_range_product(
+ __isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2)
+{
+ return bin_op(umap1, umap2, &range_product_entry);
+}
+
__isl_give isl_union_map *isl_union_map_from_range(
__isl_take isl_union_set *uset)
{
}
static __isl_give isl_union_map *un_op(__isl_take isl_union_map *umap,
- int (*fn)(void **, void *), int cow)
+ int (*fn)(void **, void *))
{
- if (cow)
- umap = isl_union_map_cow(umap);
+ umap = isl_union_map_cow(umap);
if (!umap)
return NULL;
__isl_give isl_union_map *isl_union_map_affine_hull(
__isl_take isl_union_map *umap)
{
- return un_op(umap, &affine_entry, 1);
+ return un_op(umap, &affine_entry);
}
__isl_give isl_union_set *isl_union_set_affine_hull(
return isl_union_map_affine_hull(uset);
}
-static int coalesce_entry(void **entry, void *user)
+static int polyhedral_entry(void **entry, void *user)
{
isl_map **map = (isl_map **)entry;
- *map = isl_map_coalesce(*map);
+ *map = isl_map_from_basic_map(isl_map_polyhedral_hull(*map));
return *map ? 0 : -1;
}
-__isl_give isl_union_map *isl_union_map_coalesce(
+__isl_give isl_union_map *isl_union_map_polyhedral_hull(
__isl_take isl_union_map *umap)
{
- return un_op(umap, &coalesce_entry, 0);
+ return un_op(umap, &polyhedral_entry);
}
-__isl_give isl_union_set *isl_union_set_coalesce(
+__isl_give isl_union_set *isl_union_set_polyhedral_hull(
__isl_take isl_union_set *uset)
{
- return isl_union_map_coalesce(uset);
+ return isl_union_map_polyhedral_hull(uset);
}
-static int compute_divs_entry(void **entry, void *user)
+static int simple_entry(void **entry, void *user)
{
isl_map **map = (isl_map **)entry;
- *map = isl_map_compute_divs(*map);
+ *map = isl_map_from_basic_map(isl_map_simple_hull(*map));
return *map ? 0 : -1;
}
+__isl_give isl_union_map *isl_union_map_simple_hull(
+ __isl_take isl_union_map *umap)
+{
+ return un_op(umap, &simple_entry);
+}
+
+__isl_give isl_union_set *isl_union_set_simple_hull(
+ __isl_take isl_union_set *uset)
+{
+ return isl_union_map_simple_hull(uset);
+}
+
+static int inplace_entry(void **entry, void *user)
+{
+ __isl_give isl_map *(*fn)(__isl_take isl_map *);
+ isl_map **map = (isl_map **)entry;
+ isl_map *copy;
+
+ fn = *(__isl_give isl_map *(**)(__isl_take isl_map *)) user;
+ copy = fn(isl_map_copy(*map));
+ if (!copy)
+ return -1;
+
+ isl_map_free(*map);
+ *map = copy;
+
+ return 0;
+}
+
+static __isl_give isl_union_map *inplace(__isl_take isl_union_map *umap,
+ __isl_give isl_map *(*fn)(__isl_take isl_map *))
+{
+ if (!umap)
+ return NULL;
+
+ if (isl_hash_table_foreach(umap->dim->ctx, &umap->table,
+ &inplace_entry, &fn) < 0)
+ goto error;
+
+ return umap;
+error:
+ isl_union_map_free(umap);
+ return NULL;
+}
+
+__isl_give isl_union_map *isl_union_map_coalesce(
+ __isl_take isl_union_map *umap)
+{
+ return inplace(umap, &isl_map_coalesce);
+}
+
+__isl_give isl_union_set *isl_union_set_coalesce(
+ __isl_take isl_union_set *uset)
+{
+ return isl_union_map_coalesce(uset);
+}
+
+__isl_give isl_union_map *isl_union_map_detect_equalities(
+ __isl_take isl_union_map *umap)
+{
+ return inplace(umap, &isl_map_detect_equalities);
+}
+
+__isl_give isl_union_set *isl_union_set_detect_equalities(
+ __isl_take isl_union_set *uset)
+{
+ return isl_union_map_detect_equalities(uset);
+}
+
__isl_give isl_union_map *isl_union_map_compute_divs(
__isl_take isl_union_map *umap)
{
- return un_op(umap, &compute_divs_entry, 0);
+ return inplace(umap, &isl_map_compute_divs);
}
__isl_give isl_union_set *isl_union_set_compute_divs(
__isl_give isl_union_map *isl_union_map_lexmin(
__isl_take isl_union_map *umap)
{
- return un_op(umap, &lexmin_entry, 1);
+ return un_op(umap, &lexmin_entry);
}
__isl_give isl_union_set *isl_union_set_lexmin(
__isl_give isl_union_map *isl_union_map_lexmax(
__isl_take isl_union_map *umap)
{
- return un_op(umap, &lexmax_entry, 1);
+ return un_op(umap, &lexmax_entry);
}
__isl_give isl_union_set *isl_union_set_lexmax(
return cond_un_op(umap, &deltas_entry);
}
+static int deltas_map_entry(void **entry, void *user)
+{
+ isl_map *map = *entry;
+ isl_union_map **res = user;
+
+ if (!isl_dim_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
+ return 0;
+
+ *res = isl_union_map_add_map(*res,
+ isl_map_deltas_map(isl_map_copy(map)));
+
+ return 0;
+}
+
+__isl_give isl_union_map *isl_union_map_deltas_map(
+ __isl_take isl_union_map *umap)
+{
+ return cond_un_op(umap, &deltas_map_entry);
+}
+
+static int identity_entry(void **entry, void *user)
+{
+ isl_set *set = *entry;
+ isl_union_map **res = user;
+
+ *res = isl_union_map_add_map(*res, isl_set_identity(isl_set_copy(set)));
+
+ return 0;
+}
+
+__isl_give isl_union_map *isl_union_set_identity(__isl_take isl_union_set *uset)
+{
+ return cond_un_op(uset, &identity_entry);
+}
+
static int unwrap_entry(void **entry, void *user)
{
isl_set *set = *entry;
return -1;
}
+int isl_union_set_is_subset(__isl_keep isl_union_set *uset1,
+ __isl_keep isl_union_set *uset2)
+{
+ return isl_union_map_is_subset(uset1, uset2);
+}
+
int isl_union_map_is_equal(__isl_keep isl_union_map *umap1,
__isl_keep isl_union_map *umap2)
{
return is_subset;
}
+int isl_union_set_is_equal(__isl_keep isl_union_set *uset1,
+ __isl_keep isl_union_set *uset2)
+{
+ return isl_union_map_is_equal(uset1, uset2);
+}
+
int isl_union_map_is_strict_subset(__isl_keep isl_union_map *umap1,
__isl_keep isl_union_map *umap2)
{
return !is_subset;
}
+int isl_union_set_is_strict_subset(__isl_keep isl_union_set *uset1,
+ __isl_keep isl_union_set *uset2)
+{
+ return isl_union_map_is_strict_subset(uset1, uset2);
+}
+
static int sample_entry(void **entry, void *user)
{
isl_basic_map **sample = (isl_basic_map **)user;
*sample = isl_map_sample(isl_map_copy(map));
if (!*sample)
return -1;
- if (!isl_basic_map_fast_is_empty(*sample))
+ if (!isl_basic_map_plain_is_empty(*sample))
return -1;
return 0;
}
!sample)
goto error;
+ if (!sample)
+ sample = isl_basic_map_empty(isl_union_map_get_dim(umap));
+
isl_union_map_free(umap);
return sample;
return (isl_basic_set *)isl_union_map_sample(uset);
}
-static int empty_entry(void **entry, void *user)
+struct isl_forall_data {
+ int res;
+ int (*fn)(__isl_keep isl_map *map);
+};
+
+static int forall_entry(void **entry, void *user)
{
- int *empty = user;
+ struct isl_forall_data *data = user;
isl_map *map = *entry;
- if (isl_map_is_empty(map))
- return 0;
+ data->res = data->fn(map);
+ if (data->res < 0)
+ return -1;
- *empty = 0;
+ if (!data->res)
+ return -1;
- return -1;
+ return 0;
}
-__isl_give int isl_union_map_is_empty(__isl_keep isl_union_map *umap)
+static int union_map_forall(__isl_keep isl_union_map *umap,
+ int (*fn)(__isl_keep isl_map *map))
{
- int empty = 1;
+ struct isl_forall_data data = { 1, fn };
if (!umap)
return -1;
if (isl_hash_table_foreach(umap->dim->ctx, &umap->table,
- &empty_entry, &empty) < 0 && empty)
+ &forall_entry, &data) < 0 && data.res)
return -1;
- return empty;
+ return data.res;
+}
+
+int isl_union_map_is_empty(__isl_keep isl_union_map *umap)
+{
+ return union_map_forall(umap, &isl_map_is_empty);
}
int isl_union_set_is_empty(__isl_keep isl_union_set *uset)
{
return isl_union_map_is_empty(uset);
}
+
+static int is_subset_of_identity(__isl_keep isl_map *map)
+{
+ int is_subset;
+ isl_dim *dim;
+ isl_map *id;
+
+ if (!map)
+ return -1;
+
+ if (!isl_dim_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
+ return 0;
+
+ dim = isl_map_get_dim(map);
+ id = isl_map_identity(dim);
+
+ is_subset = isl_map_is_subset(map, id);
+
+ isl_map_free(id);
+
+ return is_subset;
+}
+
+/* Check if the given map is single-valued.
+ * We simply compute
+ *
+ * M \circ M^-1
+ *
+ * and check if the result is a subset of the identity mapping.
+ */
+int isl_union_map_is_single_valued(__isl_keep isl_union_map *umap)
+{
+ isl_union_map *test;
+ int sv;
+
+ if (isl_union_map_n_map(umap) == 1) {
+ isl_map *map = isl_union_map_copy_map(umap);
+ sv = isl_map_is_single_valued(map);
+ isl_map_free(map);
+ return sv;
+ }
+
+ test = isl_union_map_reverse(isl_union_map_copy(umap));
+ test = isl_union_map_apply_range(test, isl_union_map_copy(umap));
+
+ sv = union_map_forall(test, &is_subset_of_identity);
+
+ isl_union_map_free(test);
+
+ return sv;
+}
+
+int isl_union_map_is_injective(__isl_keep isl_union_map *umap)
+{
+ int in;
+
+ umap = isl_union_map_copy(umap);
+ umap = isl_union_map_reverse(umap);
+ in = isl_union_map_is_single_valued(umap);
+ isl_union_map_free(umap);
+
+ return in;
+}
+
+int isl_union_map_is_bijective(__isl_keep isl_union_map *umap)
+{
+ int sv;
+
+ sv = isl_union_map_is_single_valued(umap);
+ if (sv < 0 || !sv)
+ return sv;
+
+ return isl_union_map_is_injective(umap);
+}
+
+static int zip_entry(void **entry, void *user)
+{
+ isl_map *map = *entry;
+ isl_union_map **res = user;
+
+ if (!isl_map_can_zip(map))
+ return 0;
+
+ *res = isl_union_map_add_map(*res, isl_map_zip(isl_map_copy(map)));
+
+ return 0;
+}
+
+__isl_give isl_union_map *isl_union_map_zip(__isl_take isl_union_map *umap)
+{
+ return cond_un_op(umap, &zip_entry);
+}
+
+static int lift_entry(void **entry, void *user)
+{
+ isl_set *set = *entry;
+ isl_union_set **res = user;
+
+ *res = isl_union_set_add_set(*res, isl_set_lift(isl_set_copy(set)));
+
+ return 0;
+}
+
+__isl_give isl_union_set *isl_union_set_lift(__isl_take isl_union_set *uset)
+{
+ return cond_un_op(uset, &lift_entry);
+}
+
+static int coefficients_entry(void **entry, void *user)
+{
+ isl_set *set = *entry;
+ isl_union_set **res = user;
+
+ set = isl_set_copy(set);
+ set = isl_set_from_basic_set(isl_set_coefficients(set));
+ *res = isl_union_set_add_set(*res, set);
+
+ return 0;
+}
+
+__isl_give isl_union_set *isl_union_set_coefficients(
+ __isl_take isl_union_set *uset)
+{
+ isl_ctx *ctx;
+ isl_dim *dim;
+ isl_union_set *res;
+
+ if (!uset)
+ return NULL;
+
+ ctx = isl_union_set_get_ctx(uset);
+ dim = isl_dim_set_alloc(ctx, 0, 0);
+ res = isl_union_map_alloc(dim, uset->table.n);
+ if (isl_hash_table_foreach(uset->dim->ctx, &uset->table,
+ &coefficients_entry, &res) < 0)
+ goto error;
+
+ isl_union_set_free(uset);
+ return res;
+error:
+ isl_union_set_free(uset);
+ isl_union_set_free(res);
+ return NULL;
+}
+
+static int solutions_entry(void **entry, void *user)
+{
+ isl_set *set = *entry;
+ isl_union_set **res = user;
+
+ set = isl_set_copy(set);
+ set = isl_set_from_basic_set(isl_set_solutions(set));
+ if (!*res)
+ *res = isl_union_set_from_set(set);
+ else
+ *res = isl_union_set_add_set(*res, set);
+
+ if (!*res)
+ return -1;
+
+ return 0;
+}
+
+__isl_give isl_union_set *isl_union_set_solutions(
+ __isl_take isl_union_set *uset)
+{
+ isl_ctx *ctx;
+ isl_dim *dim;
+ isl_union_set *res = NULL;
+
+ if (!uset)
+ return NULL;
+
+ if (uset->table.n == 0) {
+ res = isl_union_set_empty(isl_union_set_get_dim(uset));
+ isl_union_set_free(uset);
+ return res;
+ }
+
+ if (isl_hash_table_foreach(uset->dim->ctx, &uset->table,
+ &solutions_entry, &res) < 0)
+ goto error;
+
+ isl_union_set_free(uset);
+ return res;
+error:
+ isl_union_set_free(uset);
+ isl_union_set_free(res);
+ return NULL;
+}