*/
#include <string.h>
-#include <strings.h>
#include <isl_ctx_private.h>
#include <isl_map_private.h>
#include <isl/blk.h>
#include "isl_dim_private.h"
#include "isl_equalities.h"
-#include <isl/list.h>
+#include <isl_list_private.h>
#include <isl/lp.h>
#include <isl/seq.h>
#include <isl/set.h>
#include <isl_mat_private.h>
#include <isl_dim_map.h>
#include <isl_local_space_private.h>
+#include <isl_aff_private.h>
static unsigned n(struct isl_dim *dim, enum isl_dim_type type)
{
return NULL;
}
+__isl_give isl_basic_set *isl_basic_set_set_tuple_name(
+ __isl_take isl_basic_set *bset, const char *s)
+{
+ return isl_basic_map_set_tuple_name(bset, isl_dim_set, s);
+}
+
const char *isl_basic_map_get_tuple_name(__isl_keep isl_basic_map *bmap,
enum isl_dim_type type)
{
return NULL;
}
-static __isl_give isl_set *isl_set_swap_vars(__isl_take isl_set *set,
- unsigned n)
-{
- int i;
- set = isl_set_cow(set);
- if (!set)
- return NULL;
-
- for (i = 0; i < set->n; ++i) {
- set->p[i] = isl_basic_set_swap_vars(set->p[i], n);
- if (!set->p[i]) {
- isl_set_free(set);
- return NULL;
- }
- }
- ISL_F_CLR(set, ISL_SET_NORMALIZED);
- return set;
-}
-
struct isl_basic_map *isl_basic_map_set_to_empty(struct isl_basic_map *bmap)
{
int i = 0;
if (!div_involves_vars(bmap, i, first, n))
continue;
bmap = isl_basic_map_remove_dims(bmap, isl_dim_div, i, 1);
+ if (!bmap)
+ return NULL;
+ i = bmap->n_div;
}
return bmap;
static __isl_give isl_map *map_intersect_add_constraint(
__isl_take isl_map *map1, __isl_take isl_map *map2)
{
- struct isl_basic_map *bmap1;
- struct isl_basic_map *bmap2;
-
isl_assert(map1->ctx, map1->n == 1, goto error);
isl_assert(map2->ctx, map1->n == 1, goto error);
isl_assert(map1->ctx, map1->p[0]->n_div == 0, goto error);
enum isl_dim_type dst_type, unsigned dst_pos,
enum isl_dim_type src_type, unsigned src_pos, unsigned n)
{
- int i;
struct isl_dim_map *dim_map;
struct isl_basic_map *res;
enum isl_dim_type t;
int i, k;
isl_dim *dim;
isl_basic_map *domain;
- isl_basic_set *bset;
int nparam, n_in, n_out;
unsigned total;
int i, k;
isl_dim *dim;
isl_basic_map *range;
- isl_basic_set *bset;
int nparam, n_in, n_out;
unsigned total;
return (isl_set *)isl_map_lexmax((isl_map *)set);
}
+/* Construct a map that equates the two given dimensions in the given space.
+ */
+static __isl_give isl_map *equate(__isl_take isl_dim *dim,
+ enum isl_dim_type src_type, int src_pos,
+ enum isl_dim_type dst_type, int dst_pos)
+{
+ isl_basic_map *bmap;
+ int k;
+
+ bmap = isl_basic_map_alloc_dim(dim, 0, 1, 0);
+ k = isl_basic_map_alloc_equality(bmap);
+ if (k < 0)
+ goto error;
+ isl_seq_clr(bmap->eq[k], 1 + isl_basic_map_total_dim(bmap));
+ src_pos += isl_basic_map_offset(bmap, src_type);
+ dst_pos += isl_basic_map_offset(bmap, dst_type);
+ isl_int_set_si(bmap->eq[k][src_pos], 1);
+ isl_int_set_si(bmap->eq[k][dst_pos], -1);
+
+ return isl_map_from_basic_map(bmap);
+error:
+ isl_basic_map_free(bmap);
+ return NULL;
+}
+
+/* Extract the first and only affine expression from list
+ * and then add it to *pwaff with the given dom.
+ * This domain is known to be disjoint from other domains
+ * because of the way isl_basic_set_foreach_lexmax works.
+ */
+static int update_dim_max(__isl_take isl_basic_set *dom,
+ __isl_take isl_aff_list *list, void *user)
+{
+ isl_ctx *ctx = isl_basic_set_get_ctx(dom);
+ isl_aff *aff;
+ isl_pw_aff **pwaff = user;
+ isl_pw_aff *pwaff_i;
+
+ if (isl_aff_list_n_aff(list) != 1)
+ isl_die(ctx, isl_error_internal,
+ "expecting single element list", goto error);
+
+ aff = isl_aff_list_get_aff(list, 0);
+ pwaff_i = isl_pw_aff_alloc(isl_set_from_basic_set(dom), aff);
+
+ *pwaff = isl_pw_aff_add_disjoint(*pwaff, pwaff_i);
+
+ isl_aff_list_free(list);
+
+ return 0;
+error:
+ isl_basic_set_free(dom);
+ isl_aff_list_free(list);
+ return -1;
+}
+
+/* Given a one-dimensional basic set, compute the maximum of that
+ * dimension as an isl_pw_aff.
+ *
+ * The isl_pw_aff is constructed by having isl_basic_set_foreach_lexmax
+ * call update_dim_max on each leaf of the result.
+ */
+static __isl_give isl_pw_aff *basic_set_dim_max(__isl_keep isl_basic_set *bset)
+{
+ isl_dim *dim = isl_basic_set_get_dim(bset);
+ isl_pw_aff *pwaff;
+ int r;
+
+ dim = isl_dim_domain(isl_dim_from_range(dim));
+ pwaff = isl_pw_aff_empty(dim);
+
+ r = isl_basic_set_foreach_lexmax(bset, &update_dim_max, &pwaff);
+ if (r < 0)
+ return isl_pw_aff_free(pwaff);
+
+ return pwaff;
+}
+
+/* Compute the maximum of the given set dimension as a function of the
+ * parameters, but independently of the other set dimensions.
+ *
+ * We first project the set onto the given dimension and then compute
+ * the "lexicographic" maximum in each basic set, combining the results
+ * using isl_pw_aff_max.
+ */
+__isl_give isl_pw_aff *isl_set_dim_max(__isl_take isl_set *set, int pos)
+{
+ int i;
+ isl_map *map;
+ isl_pw_aff *pwaff;
+
+ map = isl_map_from_domain(set);
+ map = isl_map_add_dims(map, isl_dim_out, 1);
+ map = isl_map_intersect(map,
+ equate(isl_map_get_dim(map), isl_dim_in, pos,
+ isl_dim_out, 0));
+ set = isl_map_range(map);
+ if (!set)
+ return NULL;
+
+ if (set->n == 0) {
+ isl_dim *dim = isl_set_get_dim(set);
+ dim = isl_dim_domain(isl_dim_from_range(dim));
+ isl_set_free(set);
+ return isl_pw_aff_empty(dim);
+ }
+
+ pwaff = basic_set_dim_max(set->p[0]);
+ for (i = 1; i < set->n; ++i) {
+ isl_pw_aff *pwaff_i;
+
+ pwaff_i = basic_set_dim_max(set->p[i]);
+ pwaff = isl_pw_aff_max(pwaff, pwaff_i);
+ }
+
+ isl_set_free(set);
+
+ return pwaff;
+}
+
/* Apply a preimage specified by "mat" on the parameters of "bset".
* bset is assumed to have only parameters and divs.
*/
return NULL;
}
-static int basic_map_divs_known(__isl_keep isl_basic_map *bmap)
+int isl_basic_map_divs_known(__isl_keep isl_basic_map *bmap)
{
int i;
unsigned off;
return -1;
for (i = 0; i < map->n; ++i) {
- int known = basic_map_divs_known(map->p[i]);
+ int known = isl_basic_map_divs_known(map->p[i]);
if (known <= 0)
return known;
}
*/
struct isl_map *isl_basic_map_compute_divs(struct isl_basic_map *bmap)
{
- int i;
int known;
struct isl_map *map;
- known = basic_map_divs_known(bmap);
+ known = isl_basic_map_divs_known(bmap);
if (known < 0)
goto error;
if (known)
bmap = isl_basic_map_drop_redundant_divs(bmap);
- known = basic_map_divs_known(bmap);
+ known = isl_basic_map_divs_known(bmap);
if (known < 0)
goto error;
if (known)
int i, k;
isl_dim *dim;
isl_basic_map *domain;
- isl_basic_set *bset;
int nparam, n;
unsigned total;
return NULL;
}
+__isl_give isl_basic_map *isl_basic_map_flat_range_product(
+ __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
+{
+ isl_basic_map *prod;
+
+ prod = isl_basic_map_range_product(bmap1, bmap2);
+ prod = isl_basic_map_flatten_range(prod);
+ return prod;
+}
+
static __isl_give isl_map *map_product(__isl_take isl_map *map1,
__isl_take isl_map *map2,
__isl_give isl_dim *(*dim_product)(__isl_take isl_dim *left,
&isl_basic_map_range_product);
}
+/* Given two maps A -> B and C -> D, construct a map (A * C) -> (B, D)
+ */
+__isl_give isl_map *isl_map_flat_range_product(__isl_take isl_map *map1,
+ __isl_take isl_map *map2)
+{
+ isl_map *prod;
+
+ prod = isl_map_range_product(map1, map2);
+ prod = isl_map_flatten_range(prod);
+ return prod;
+}
+
uint32_t isl_basic_map_get_hash(__isl_keep isl_basic_map *bmap)
{
int i;
*/
int isl_map_plain_is_single_valued(__isl_keep isl_map *map)
{
- int sv;
-
if (!map)
return -1;
if (map->n == 0)
return (isl_basic_set *)isl_basic_map_flatten((isl_basic_map *)bset);
}
+__isl_give isl_basic_map *isl_basic_map_flatten_range(
+ __isl_take isl_basic_map *bmap)
+{
+ if (!bmap)
+ return NULL;
+
+ if (!bmap->dim->nested[1])
+ return bmap;
+
+ bmap = isl_basic_map_cow(bmap);
+ if (!bmap)
+ return NULL;
+
+ bmap->dim = isl_dim_flatten_range(bmap->dim);
+ if (!bmap->dim)
+ goto error;
+
+ bmap = isl_basic_map_finalize(bmap);
+
+ return bmap;
+error:
+ isl_basic_map_free(bmap);
+ return NULL;
+}
+
__isl_give isl_map *isl_map_flatten(__isl_take isl_map *map)
{
int i;
return map;
}
+__isl_give isl_map *isl_map_flatten_range(__isl_take isl_map *map)
+{
+ int i;
+
+ if (!map)
+ return NULL;
+
+ if (!map->dim->nested[1])
+ return map;
+
+ map = isl_map_cow(map);
+ if (!map)
+ return NULL;
+
+ for (i = 0; i < map->n; ++i) {
+ map->p[i] = isl_basic_map_flatten_range(map->p[i]);
+ if (!map->p[i])
+ goto error;
+ }
+ map->dim = isl_dim_flatten_range(map->dim);
+ if (!map->dim)
+ goto error;
+
+ return map;
+error:
+ isl_map_free(map);
+ return NULL;
+}
+
/* Reorder the dimensions of "bmap" according to the given dim_map
* and set the dimension specification to "dim".
*/
isl_map_free(map);
return NULL;
}
+
+/* Construct a basic map mapping the domain of the affine expression
+ * to a one-dimensional range prescribed by the affine expression.
+ */
+__isl_give isl_basic_map *isl_basic_map_from_aff(__isl_take isl_aff *aff)
+{
+ int k;
+ int pos;
+ isl_local_space *ls;
+ isl_basic_map *bmap;
+
+ if (!aff)
+ return NULL;
+
+ ls = isl_aff_get_local_space(aff);
+ ls = isl_local_space_from_domain(ls);
+ ls = isl_local_space_add_dims(ls, isl_dim_out, 1);
+ bmap = isl_basic_map_from_local_space(ls);
+ bmap = isl_basic_map_extend_constraints(bmap, 1, 0);
+ k = isl_basic_map_alloc_equality(bmap);
+ if (k < 0)
+ goto error;
+
+ pos = isl_basic_map_offset(bmap, isl_dim_out);
+ isl_seq_cpy(bmap->eq[k], aff->v->el + 1, pos);
+ isl_int_neg(bmap->eq[k][pos], aff->v->el[0]);
+ isl_seq_cpy(bmap->eq[k] + pos + 1, aff->v->el + 1 + pos,
+ aff->v->size - (pos + 1));
+
+ isl_aff_free(aff);
+ bmap = isl_basic_map_finalize(bmap);
+ return bmap;
+error:
+ isl_aff_free(aff);
+ isl_basic_map_free(bmap);
+ return NULL;
+}
+
+/* Construct a basic map mapping a domain in the given space to
+ * to an n-dimensional range, with n the number of elements in the list,
+ * where each coordinate in the range is prescribed by the
+ * corresponding affine expression.
+ * The domains of all affine expressions in the list are assumed to match
+ * domain_dim.
+ */
+__isl_give isl_basic_map *isl_basic_map_from_aff_list(
+ __isl_take isl_dim *domain_dim, __isl_take isl_aff_list *list)
+{
+ int i;
+ isl_dim *dim;
+ isl_basic_map *bmap;
+
+ if (!list)
+ return NULL;
+
+ dim = isl_dim_from_domain(domain_dim);
+ bmap = isl_basic_map_universe(dim);
+
+ for (i = 0; i < list->n; ++i) {
+ isl_aff *aff;
+ isl_basic_map *bmap_i;
+
+ aff = isl_aff_copy(list->p[i]);
+ bmap_i = isl_basic_map_from_aff(aff);
+
+ bmap = isl_basic_map_flat_range_product(bmap, bmap_i);
+ }
+
+ isl_aff_list_free(list);
+ return bmap;
+}