+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the GNU LGPLv2.1 license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
+
#include "isl_equalities.h"
#include "isl_map.h"
#include "isl_map_private.h"
return NULL;
}
+struct isl_set *isl_set_drop(struct isl_set *set,
+ enum isl_dim_type type, unsigned first, unsigned n)
+{
+ return (isl_set *)isl_map_drop((isl_map *)set, type, first, n);
+}
+
struct isl_map *isl_map_drop_inputs(
struct isl_map *map, unsigned first, unsigned n)
{
(struct isl_basic_map *)bset);
}
-static void eliminate_div(struct isl_basic_map *bmap, isl_int *eq, unsigned div)
+/* Assumes divs have been ordered if keep_divs is set.
+ */
+static void eliminate_var_using_equality(struct isl_basic_map *bmap,
+ unsigned pos, isl_int *eq, int keep_divs, int *progress)
{
- int i;
- unsigned pos = 1 + isl_dim_total(bmap->dim) + div;
- unsigned len;
- len = 1 + isl_basic_map_total_dim(bmap);
+ unsigned total;
+ int k;
+ int last_div;
- for (i = 0; i < bmap->n_eq; ++i)
- if (bmap->eq[i] != eq)
- isl_seq_elim(bmap->eq[i], eq, pos, len, NULL);
+ total = isl_basic_map_total_dim(bmap);
+ last_div = isl_seq_last_non_zero(eq + 1 + isl_dim_total(bmap->dim),
+ bmap->n_div);
+ for (k = 0; k < bmap->n_eq; ++k) {
+ if (bmap->eq[k] == eq)
+ continue;
+ if (isl_int_is_zero(bmap->eq[k][1+pos]))
+ continue;
+ if (progress)
+ *progress = 1;
+ isl_seq_elim(bmap->eq[k], eq, 1+pos, 1+total, NULL);
+ }
- for (i = 0; i < bmap->n_ineq; ++i)
- isl_seq_elim(bmap->ineq[i], eq, pos, len, NULL);
+ for (k = 0; k < bmap->n_ineq; ++k) {
+ if (isl_int_is_zero(bmap->ineq[k][1+pos]))
+ continue;
+ if (progress)
+ *progress = 1;
+ isl_seq_elim(bmap->ineq[k], eq, 1+pos, 1+total, NULL);
+ ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED);
+ }
- /* We need to be careful about circular definitions,
- * so for now we just remove the definitions of other divs that
- * depend on this div and (possibly) recompute them later.
- */
- for (i = 0; i < bmap->n_div; ++i)
- if (!isl_int_is_zero(bmap->div[i][0]) &&
- !isl_int_is_zero(bmap->div[i][1 + pos]))
- isl_seq_clr(bmap->div[i], 1 + len);
+ for (k = 0; k < bmap->n_div; ++k) {
+ if (isl_int_is_zero(bmap->div[k][0]))
+ continue;
+ if (isl_int_is_zero(bmap->div[k][1+1+pos]))
+ continue;
+ if (progress)
+ *progress = 1;
+ /* We need to be careful about circular definitions,
+ * so for now we just remove the definition of div k
+ * if the equality contains any divs.
+ * If keep_divs is set, then the divs have been ordered
+ * and we can keep the definition as long as the result
+ * is still ordered.
+ */
+ if (last_div == -1 || (keep_divs && last_div < k))
+ isl_seq_elim(bmap->div[k]+1, eq,
+ 1+pos, 1+total, &bmap->div[k][0]);
+ else
+ isl_seq_clr(bmap->div[k], 1 + total);
+ ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED);
+ }
+}
+
+/* Assumes divs have been ordered if keep_divs is set.
+ */
+static void eliminate_div(struct isl_basic_map *bmap, isl_int *eq,
+ unsigned div, int keep_divs)
+{
+ unsigned pos = isl_dim_total(bmap->dim) + div;
+
+ eliminate_var_using_equality(bmap, pos, eq, keep_divs, NULL);
isl_basic_map_drop_div(bmap, div);
}
int modified = 0;
unsigned off;
+ bmap = isl_basic_map_order_divs(bmap);
+
if (!bmap)
return NULL;
continue;
modified = 1;
*progress = 1;
- eliminate_div(bmap, bmap->eq[i], d);
+ eliminate_div(bmap, bmap->eq[i], d, 1);
isl_basic_map_drop_equality(bmap, i);
break;
}
return bmap;
}
-/* Assumes divs have been ordered if keep_divs is set.
- */
-static void eliminate_var_using_equality(struct isl_basic_map *bmap,
- unsigned pos, isl_int *eq, int keep_divs, int *progress)
-{
- unsigned total;
- int k;
- int last_div;
-
- total = isl_basic_map_total_dim(bmap);
- last_div = isl_seq_last_non_zero(eq + 1 + isl_dim_total(bmap->dim),
- bmap->n_div);
- for (k = 0; k < bmap->n_eq; ++k) {
- if (bmap->eq[k] == eq)
- continue;
- if (isl_int_is_zero(bmap->eq[k][1+pos]))
- continue;
- if (progress)
- *progress = 1;
- isl_seq_elim(bmap->eq[k], eq, 1+pos, 1+total, NULL);
- }
-
- for (k = 0; k < bmap->n_ineq; ++k) {
- if (isl_int_is_zero(bmap->ineq[k][1+pos]))
- continue;
- if (progress)
- *progress = 1;
- isl_seq_elim(bmap->ineq[k], eq, 1+pos, 1+total, NULL);
- ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED);
- }
-
- for (k = 0; k < bmap->n_div; ++k) {
- if (isl_int_is_zero(bmap->div[k][0]))
- continue;
- if (isl_int_is_zero(bmap->div[k][1+1+pos]))
- continue;
- if (progress)
- *progress = 1;
- /* We need to be careful about circular definitions,
- * so for now we just remove the definition of div k
- * if the equality contains any divs.
- * If keep_divs is set, then the divs have been ordered
- * and we can keep the definition as long as the result
- * is still ordered.
- */
- if (last_div == -1 || (keep_divs && last_div < k))
- isl_seq_elim(bmap->div[k]+1, eq,
- 1+pos, 1+total, &bmap->div[k][0]);
- else
- isl_seq_clr(bmap->div[k], 1 + total);
- ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED);
- }
-}
-
struct isl_basic_map *isl_basic_map_gauss(
struct isl_basic_map *bmap, int *progress)
{
k = elim_for[l] - 1;
isl_int_set_si(eq.data[1+total_var+k], -1);
isl_int_set_si(eq.data[1+total_var+l], 1);
- eliminate_div(bmap, eq.data, l);
+ eliminate_div(bmap, eq.data, l, 0);
isl_int_set_si(eq.data[1+total_var+k], 0);
isl_int_set_si(eq.data[1+total_var+l], 0);
}
* will no longer be valid.
* Plus, we probably we want to regauss first.
*/
+ if (progress)
+ *progress = 1;
isl_basic_map_drop_inequality(bmap, l);
isl_basic_map_inequality_to_equality(bmap, k);
} else
bset = remove_shifted_constraints(bset, context);
if (!bset->n_ineq)
goto done;
- isl_basic_set_free_equality(context, context->n_eq);
context_ineq = context->n_ineq;
combined = isl_basic_set_cow(isl_basic_set_copy(context));
+ if (isl_basic_set_free_equality(combined, context->n_eq) < 0)
+ goto error;
combined = isl_basic_set_extend_constraints(combined,
bset->n_eq, bset->n_ineq);
tab = isl_tab_from_basic_set(combined);
if (!tab)
goto error;
for (i = 0; i < context_ineq; ++i)
- tab->con[i].frozen = 1;
+ if (isl_tab_freeze_constraint(tab, i) < 0)
+ goto error;
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(tab, bset->ineq[i]);
+ if (isl_tab_add_ineq(tab, bset->ineq[i]) < 0)
+ goto error;
bset = isl_basic_set_add_constraints(combined, bset, 0);
tab = isl_tab_detect_implicit_equalities(tab);
- tab = isl_tab_detect_redundant(tab);
- if (!tab)
+ if (isl_tab_detect_redundant(tab) < 0) {
+ isl_tab_free(tab);
goto error2;
+ }
for (i = 0; i < context_ineq; ++i) {
tab->con[i].is_zero = 0;
tab->con[i].is_redundant = 1;