return bmap;
}
-/* Elimininate divs based on inequalities
+/* Eliminate divs based on inequalities
*/
static struct isl_basic_map *eliminate_divs_ineq(
struct isl_basic_map *bmap, int *progress)
* We therefore call isl_basic_map_detect_inequality_pairs,
* which checks for such pairs of inequalities as well as eliminate_divs_eq
* and isl_basic_map_gauss if such a pair was found.
+ *
+ * Note that this function may leave the result in an inconsistent state.
+ * In particular, the constraints may not be gaussed.
+ * Unfortunately, isl_map_coalesce actually depends on this inconsistent state
+ * for some of the test cases to pass successfully.
+ * Any potential modification of the representation is therefore only
+ * performed on a single copy of the basic map.
*/
__isl_give isl_basic_map *isl_basic_map_reduce_coefficients(
__isl_take isl_basic_map *bmap)
return isl_basic_map_set_to_empty(bmap);
}
+ bmap = isl_basic_map_cow(bmap);
+ if (!bmap)
+ goto error;
+
tightened = 0;
for (i = 0; i < bmap->n_ineq; ++i) {
isl_seq_cpy(v->el, bmap->ineq[i], 1 + total);
return NULL;
}
-__isl_give isl_space *isl_space_move_dims(__isl_take isl_space *dim,
+__isl_give isl_space *isl_space_move_dims(__isl_take isl_space *space,
enum isl_dim_type dst_type, unsigned dst_pos,
enum isl_dim_type src_type, unsigned src_pos, unsigned n)
{
int i;
- if (!dim)
+ space = isl_space_reset(space, src_type);
+ space = isl_space_reset(space, dst_type);
+ if (!space)
return NULL;
- if (n == 0) {
- dim = isl_space_reset(dim, src_type);
- return isl_space_reset(dim, dst_type);
- }
+ if (n == 0)
+ return space;
- isl_assert(dim->ctx, src_pos + n <= isl_space_dim(dim, src_type),
+ isl_assert(space->ctx, src_pos + n <= isl_space_dim(space, src_type),
goto error);
if (dst_type == src_type && dst_pos == src_pos)
- return dim;
-
- isl_assert(dim->ctx, dst_type != src_type, goto error);
+ return space;
- dim = isl_space_reset(dim, src_type);
- dim = isl_space_reset(dim, dst_type);
+ isl_assert(space->ctx, dst_type != src_type, goto error);
- dim = isl_space_cow(dim);
- if (!dim)
+ space = isl_space_cow(space);
+ if (!space)
return NULL;
- if (dim->ids) {
+ if (space->ids) {
isl_id **ids;
enum isl_dim_type t, o = isl_dim_param;
int off;
int s[3];
- ids = isl_calloc_array(dim->ctx, isl_id *,
- dim->nparam + dim->n_in + dim->n_out);
+ ids = isl_calloc_array(space->ctx, isl_id *,
+ space->nparam + space->n_in + space->n_out);
if (!ids)
goto error;
off = 0;
- s[isl_dim_param - o] = dim->nparam;
- s[isl_dim_in - o] = dim->n_in;
- s[isl_dim_out - o] = dim->n_out;
+ s[isl_dim_param - o] = space->nparam;
+ s[isl_dim_in - o] = space->n_in;
+ s[isl_dim_out - o] = space->n_out;
for (t = isl_dim_param; t <= isl_dim_out; ++t) {
if (t == dst_type) {
- get_ids(dim, t, 0, dst_pos, ids + off);
+ get_ids(space, t, 0, dst_pos, ids + off);
off += dst_pos;
- get_ids(dim, src_type, src_pos, n, ids + off);
+ get_ids(space, src_type, src_pos, n, ids + off);
off += n;
- get_ids(dim, t, dst_pos, s[t - o] - dst_pos,
+ get_ids(space, t, dst_pos, s[t - o] - dst_pos,
ids + off);
off += s[t - o] - dst_pos;
} else if (t == src_type) {
- get_ids(dim, t, 0, src_pos, ids + off);
+ get_ids(space, t, 0, src_pos, ids + off);
off += src_pos;
- get_ids(dim, t, src_pos + n,
+ get_ids(space, t, src_pos + n,
s[t - o] - src_pos - n, ids + off);
off += s[t - o] - src_pos - n;
} else {
- get_ids(dim, t, 0, s[t - o], ids + off);
+ get_ids(space, t, 0, s[t - o], ids + off);
off += s[t - o];
}
}
- free(dim->ids);
- dim->ids = ids;
- dim->n_id = dim->nparam + dim->n_in + dim->n_out;
+ free(space->ids);
+ space->ids = ids;
+ space->n_id = space->nparam + space->n_in + space->n_out;
}
switch (dst_type) {
- case isl_dim_param: dim->nparam += n; break;
- case isl_dim_in: dim->n_in += n; break;
- case isl_dim_out: dim->n_out += n; break;
+ case isl_dim_param: space->nparam += n; break;
+ case isl_dim_in: space->n_in += n; break;
+ case isl_dim_out: space->n_out += n; break;
default: ;
}
switch (src_type) {
- case isl_dim_param: dim->nparam -= n; break;
- case isl_dim_in: dim->n_in -= n; break;
- case isl_dim_out: dim->n_out -= n; break;
+ case isl_dim_param: space->nparam -= n; break;
+ case isl_dim_in: space->n_in -= n; break;
+ case isl_dim_out: space->n_out -= n; break;
default: ;
}
if (dst_type != isl_dim_param && src_type != isl_dim_param)
- return dim;
+ return space;
for (i = 0; i < 2; ++i) {
- if (!dim->nested[i])
+ if (!space->nested[i])
continue;
- dim->nested[i] = isl_space_replace(dim->nested[i],
- isl_dim_param, dim);
- if (!dim->nested[i])
+ space->nested[i] = isl_space_replace(space->nested[i],
+ isl_dim_param, space);
+ if (!space->nested[i])
goto error;
}
- return dim;
+ return space;
error:
- isl_space_free(dim);
+ isl_space_free(space);
return NULL;
}
return 0;
}
+/* Check that calling isl_set_coalesce does not leave other sets
+ * that may share some information with the input to isl_set_coalesce
+ * in an inconsistent state.
+ * In particular, older versions of isl would modify all copies
+ * of the basic sets in the isl_set_coalesce input in a way
+ * that could leave them in an inconsistent state.
+ * The result of printing any other set containing one of these
+ * basic sets would then result in an invalid set description.
+ */
+static int test_coalesce_special3(isl_ctx *ctx)
+{
+ const char *str;
+ char *s;
+ isl_set *set1, *set2;
+ isl_printer *p;
+
+ set1 = isl_set_read_from_str(ctx, "{ [0, 0, 0] }");
+ str = "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
+ set2 = isl_set_read_from_str(ctx, str);
+ set1 = isl_set_union(set1, isl_set_copy(set2));
+ set1 = isl_set_coalesce(set1);
+ isl_set_free(set1);
+
+ p = isl_printer_to_str(ctx);
+ p = isl_printer_print_set(p, set2);
+ isl_set_free(set2);
+ s = isl_printer_get_str(p);
+ isl_printer_free(p);
+ set1 = isl_set_read_from_str(ctx, s);
+ free(s);
+ isl_set_free(set1);
+
+ if (!set1)
+ return -1;
+
+ return 0;
+}
+
/* Test the functionality of isl_set_coalesce.
* That is, check that the output is always equal to the input
* and in some cases that the result consists of a single disjunct.
return -1;
if (test_coalesce_special2(ctx) < 0)
return -1;
+ if (test_coalesce_special3(ctx) < 0)
+ return -1;
return 0;
}