return isl_basic_map_drop_equality((struct isl_basic_map *)bset, pos);
}
+/* Turn inequality "pos" of "bmap" into an equality.
+ *
+ * In particular, we move the inequality in front of the equalities
+ * and move the last inequality in the position of the moved inequality.
+ * Note that isl_tab_make_equalities_explicit depends on this particular
+ * change in the ordering of the constraints.
+ */
void isl_basic_map_inequality_to_equality(
struct isl_basic_map *bmap, unsigned pos)
{
unsigned dim;
unsigned nparam;
+ if (!bset)
+ return NULL;
+
nparam = isl_basic_set_n_param(bset);
dim = isl_basic_set_n_dim(bset);
isl_assert(bset->ctx, n <= dim, goto error);
__isl_take isl_map *map2)
{
unsigned flags = 0;
- struct isl_map *result;
+ isl_map *result;
int i, j;
if (!map1 || !map2)
isl_basic_map_copy(map1->p[i]),
isl_basic_map_copy(map2->p[j]));
if (isl_basic_map_is_empty(part) < 0)
- goto error;
+ part = isl_basic_map_free(part);
result = isl_map_add_basic_map(result, part);
if (!result)
goto error;
{
isl_space *space;
+ if (!bmap)
+ return NULL;
if (!isl_space_is_named_or_nested(bmap->dim, type))
return bmap;
res = isl_basic_map_alloc_space(isl_basic_map_get_space(bmap),
bmap->n_div, bmap->n_eq, bmap->n_ineq);
bmap = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map);
+ if (!bmap)
+ goto error;
bmap->dim = isl_space_move_dims(bmap->dim, dst_type, dst_pos,
src_type, src_pos, n);
bmap = isl_basic_map_finalize(bmap);
return (struct isl_basic_set *)bmap;
error:
+ isl_basic_map_free(bmap);
return NULL;
}
bmap = isl_basic_map_extend_constraints(bmap,
0, 2 * like->n_div);
for (i = 0; i < like->n_div; ++i) {
+ if (!bmap)
+ break;
if (isl_int_is_zero(bmap->div[i][0]))
continue;
if (isl_basic_map_add_div_constraints(bmap, i) < 0)
- goto error;
+ bmap = isl_basic_map_free(bmap);
}
}
isl_basic_map_free(like);
return 0;
}
+/* Perform "fn" on each basic map of "map", where we may not be holding
+ * the only reference to "map".
+ * In particular, "fn" should be a semantics preserving operation
+ * that we want to apply to all copies of "map". We therefore need
+ * to be careful not to modify "map" in a way that breaks "map"
+ * in case anything goes wrong.
+ */
+__isl_give isl_map *isl_map_inline_foreach_basic_map(__isl_take isl_map *map,
+ __isl_give isl_basic_map *(*fn)(__isl_take isl_basic_map *bmap))
+{
+ struct isl_basic_map *bmap;
+ int i;
+
+ if (!map)
+ return NULL;
+
+ for (i = map->n - 1; i >= 0; --i) {
+ bmap = isl_basic_map_copy(map->p[i]);
+ bmap = fn(bmap);
+ if (!bmap)
+ goto error;
+ isl_basic_map_free(map->p[i]);
+ map->p[i] = bmap;
+ if (remove_if_empty(map, i) < 0)
+ goto error;
+ }
+
+ return map;
+error:
+ isl_map_free(map);
+ return NULL;
+}
+
struct isl_map *isl_map_fix_si(struct isl_map *map,
enum isl_dim_type type, unsigned pos, int value)
{
isl_pw_aff **pwaff = user;
isl_pw_aff *pwaff_i;
+ if (!list)
+ goto error;
if (isl_aff_list_n_aff(list) != 1)
isl_die(ctx, isl_error_internal,
"expecting single element list", goto error);
if (bset->n_eq == 0)
return isl_basic_set_lexmin(bset);
- isl_basic_set_gauss(bset, NULL);
+ bset = isl_basic_set_gauss(bset, NULL);
+ if (!bset)
+ return NULL;
+ if (isl_basic_set_plain_is_empty(bset))
+ return isl_set_from_basic_set(bset);
nparam = isl_basic_set_dim(bset, isl_dim_param);
n_div = isl_basic_set_dim(bset, isl_dim_div);
for (i = 0; i < dim; ++i) {
int j = isl_basic_map_alloc_equality(
(struct isl_basic_map *)bset);
- if (j < 0)
- goto error;
+ if (j < 0) {
+ bset = isl_basic_set_free(bset);
+ break;
+ }
isl_seq_clr(bset->eq[j], 1 + isl_basic_set_total_dim(bset));
isl_int_set_si(bset->eq[j][1+nparam+i], 1);
isl_int_set_si(bset->eq[j][1+nparam+dim+i], 1);
if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL)) {
struct isl_basic_map *copy = isl_basic_map_copy(bmap);
copy = isl_basic_map_remove_redundancies(copy);
- empty = ISL_F_ISSET(copy, ISL_BASIC_MAP_EMPTY);
+ empty = isl_basic_map_plain_is_empty(copy);
isl_basic_map_free(copy);
return empty;
}
isl_die(isl_mat_get_ctx(div), isl_error_invalid,
"not an expansion", goto error);
+ n_div = bset->n_div;
bset = isl_basic_map_extend_space(bset, isl_space_copy(bset->dim),
- div->n_row - bset->n_div, 0,
- 2 * (div->n_row - bset->n_div));
+ div->n_row - n_div, 0,
+ 2 * (div->n_row - n_div));
- n_div = bset->n_div;
for (i = n_div; i < div->n_row; ++i)
if (isl_basic_set_alloc_div(bset) < 0)
goto error;
total = isl_basic_map_total_dim(bmap1);
ctx = bmap1->ctx;
obj = isl_vec_alloc(ctx, 1 + total);
+ if (!obj)
+ goto error2;
isl_seq_clr(obj->block.data, 1 + total);
isl_int_set_si(obj->block.data[1+nparam+pos], 1);
isl_int_set_si(obj->block.data[1+nparam+pos+(dim1-pos)], -1);
- if (!obj)
- goto error;
res = isl_basic_map_solve_lp(bmap1, 1, obj->block.data, ctx->one,
opt, NULL, NULL);
isl_basic_map_free(bmap1);
isl_vec_free(obj);
return res;
error:
- isl_basic_map_free(bmap1);
isl_basic_map_free(bmap2);
+error2:
+ isl_basic_map_free(bmap1);
return isl_lp_error;
}
int l1, l2;
unsigned size = isl_min(c1->size, c2->size);
- l1 = isl_seq_last_non_zero(c1->c, size);
- l2 = isl_seq_last_non_zero(c2->c, size);
+ l1 = isl_seq_last_non_zero(c1->c + 1, size);
+ l2 = isl_seq_last_non_zero(c2->c + 1, size);
if (l1 != l2)
return l1 - l2;
- return isl_seq_cmp(c1->c, c2->c, size);
+ return isl_seq_cmp(c1->c + 1, c2->c + 1, size);
}
static struct isl_basic_map *isl_basic_map_sort_constraints(
return bmap;
bmap = isl_basic_map_remove_redundancies(bmap);
bmap = isl_basic_map_sort_constraints(bmap);
- ISL_F_SET(bmap, ISL_BASIC_MAP_NORMALIZED);
+ if (bmap)
+ ISL_F_SET(bmap, ISL_BASIC_MAP_NORMALIZED);
return bmap;
}
isl_mat_free(eq);
isl_mat_free(ineq);
- return bmap;
+ bmap = isl_basic_map_simplify(bmap);
+ return isl_basic_map_finalize(bmap);
error:
isl_space_free(dim);
isl_mat_free(eq);
if (!isl_basic_map_can_curry(bmap))
isl_die(bmap->ctx, isl_error_invalid,
"basic map cannot be curried", goto error);
+ bmap = isl_basic_map_cow(bmap);
+ if (!bmap)
+ return NULL;
bmap->dim = isl_space_curry(bmap->dim);
if (!bmap->dim)
goto error;
isl_die(bmap->ctx, isl_error_invalid,
"basic map cannot be uncurried",
return isl_basic_map_free(bmap));
+ bmap = isl_basic_map_cow(bmap);
+ if (!bmap)
+ return NULL;
bmap->dim = isl_space_uncurry(bmap->dim);
if (!bmap->dim)
return isl_basic_map_free(bmap);