}
-/* Remove any div that is defined in terms of the given variable.
+/* Remove definition of any div that is defined in terms of the given variable.
+ * The div itself is not removed. Functions such as
+ * eliminate_divs_ineq depend on the other divs remaining in place.
*/
static struct isl_basic_map *remove_dependent_vars(struct isl_basic_map *bmap,
int pos)
continue;
if (isl_int_is_zero(bmap->div[i][1+1+pos]))
continue;
- bmap = isl_basic_map_eliminate_vars(bmap, dim + i, 1);
- if (!bmap)
- return NULL;
+ isl_int_set_si(bmap->div[i][0], 0);
}
return bmap;
}
goto error;
for (i = 0; i < context_ineq; ++i)
tab->con[i].frozen = 1;
- tab = isl_tab_extend(bset->ctx, tab, bset->n_ineq);
+ tab = isl_tab_extend(tab, bset->n_ineq);
if (!tab)
goto error;
for (i = 0; i < bset->n_ineq; ++i)
- tab = isl_tab_add_ineq(bset->ctx, tab, bset->ineq[i]);
+ tab = isl_tab_add_ineq(tab, bset->ineq[i]);
bset = isl_basic_set_add_constraints(combined, bset, 0);
- tab = isl_tab_detect_equalities(bset->ctx, tab);
- tab = isl_tab_detect_redundant(bset->ctx, tab);
+ tab = isl_tab_detect_equalities(tab);
+ tab = isl_tab_detect_redundant(tab);
if (!tab)
goto error2;
for (i = 0; i < context_ineq; ++i) {
tab->con[i].is_redundant = 1;
}
bset = isl_basic_set_update_from_tab(bset, tab);
- isl_tab_free(bset->ctx, tab);
+ isl_tab_free(tab);
ISL_F_SET(bset, ISL_BASIC_SET_NO_IMPLICIT);
ISL_F_SET(bset, ISL_BASIC_SET_NO_REDUNDANT);
done:
* Otherwise return -1.
*
* We first check that
- * - the bounds are opposites of each other (expect for the constant
- * term
+ * - the bounds are opposites of each other (except for the constant
+ * term)
* - the bounds do not reference any other div
* - no div is defined in terms of this div
*
static struct isl_basic_map *drop_more_redundant_divs(
struct isl_basic_map *bmap, int *pairs, int n)
{
- struct isl_ctx *ctx = NULL;
struct isl_tab *tab = NULL;
struct isl_vec *vec = NULL;
unsigned dim;
if (!bmap)
goto error;
- ctx = bmap->ctx;
-
dim = isl_dim_total(bmap->dim);
- vec = isl_vec_alloc(ctx, 1 + dim + bmap->n_div);
+ vec = isl_vec_alloc(bmap->ctx, 1 + dim + bmap->n_div);
if (!vec)
goto error;
continue;
construct_test_ineq(bmap, i, l, u,
vec->el, g, fl, fu);
- res = isl_tab_min(ctx, tab, vec->el,
- ctx->one, &g, NULL, 0);
+ res = isl_tab_min(tab, vec->el,
+ bmap->ctx->one, &g, NULL, 0);
if (res == isl_lp_error)
goto error;
if (res == isl_lp_empty) {
--n;
}
- isl_tab_free(ctx, tab);
+ isl_tab_free(tab);
isl_vec_free(vec);
isl_int_clear(g);
error:
free(pairs);
isl_basic_map_free(bmap);
- if (ctx) {
- isl_tab_free(ctx, tab);
- isl_vec_free(vec);
- }
+ isl_tab_free(tab);
+ isl_vec_free(vec);
isl_int_clear(g);
isl_int_clear(fl);
isl_int_clear(fu);
int pos, neg;
int last_pos, last_neg;
int redundant;
+ int defined;
- if (!isl_int_is_zero(bmap->div[i][0]))
- continue;
+ defined = !isl_int_is_zero(bmap->div[i][0]);
for (j = 0; j < bmap->n_eq; ++j)
if (!isl_int_is_zero(bmap->eq[j][1 + off + i]))
break;
isl_int_sub(bmap->ineq[last_pos][0],
bmap->ineq[last_pos][0], bmap->ineq[last_neg][0]);
if (!redundant) {
- if (!ok_to_set_div_from_bound(bmap, i, last_pos)) {
+ if (defined ||
+ !ok_to_set_div_from_bound(bmap, i, last_pos)) {
pairs[i] = 0;
--n;
continue;
isl_basic_map_free(bmap);
return NULL;
}
+
+struct isl_basic_set *isl_basic_set_drop_redundant_divs(
+ struct isl_basic_set *bset)
+{
+ return (struct isl_basic_set *)
+ isl_basic_map_drop_redundant_divs((struct isl_basic_map *)bset);
+}
+
+struct isl_map *isl_map_drop_redundant_divs(struct isl_map *map)
+{
+ int i;
+
+ if (!map)
+ return NULL;
+ for (i = 0; i < map->n; ++i) {
+ map->p[i] = isl_basic_map_drop_redundant_divs(map->p[i]);
+ if (!map->p[i])
+ goto error;
+ }
+ ISL_F_CLR(map, ISL_MAP_NORMALIZED);
+ return map;
+error:
+ isl_map_free(map);
+ return NULL;
+}
+
+struct isl_set *isl_set_drop_redundant_divs(struct isl_set *set)
+{
+ return (struct isl_set *)
+ isl_map_drop_redundant_divs((struct isl_map *)set);
+}