*/
#include "isl_map_private.h"
-#include "isl_seq.h"
+#include <isl/seq.h>
#include "isl_tab.h"
#include "isl_sample.h"
+#include <isl_mat_private.h>
/*
* The implementation of parametric integer linear programming in this file
isl_seq_clr(mat->row[1 + row], mat->n_col);
if (!tab->var[i].is_row) {
- /* no unbounded */
- isl_assert(mat->ctx, !tab->M, goto error2);
+ if (tab->M)
+ isl_die(mat->ctx, isl_error_invalid,
+ "unbounded optimum", goto error2);
continue;
}
r = tab->var[i].index;
- /* no unbounded */
- if (tab->M)
- isl_assert(mat->ctx, isl_int_eq(tab->mat->row[r][2],
- tab->mat->row[r][0]),
- goto error2);
+ if (tab->M &&
+ isl_int_ne(tab->mat->row[r][2], tab->mat->row[r][0]))
+ isl_die(mat->ctx, isl_error_invalid,
+ "unbounded optimum", goto error2);
isl_int_gcd(m, mat->row[0][0], tab->mat->row[r][0]);
isl_int_divexact(m, tab->mat->row[r][0], m);
scale_rows(mat, m, 1 + row);
error:
isl_basic_set_free(bset);
isl_mat_free(mat);
- sol_free(sol);
+ sol->error = 1;
}
struct isl_sol_map {
static void sol_map_free(struct isl_sol_map *sol_map)
{
+ if (!sol_map)
+ return;
if (sol_map->sol.context)
sol_map->sol.context->op->free(sol_map->sol.context);
isl_map_free(sol_map->map);
if (isl_tab_kill_col(tab, i) < 0)
goto error;
tab->n_eq++;
-
- tab = restore_lexmin(tab);
}
return tab;
for (i = 0; i < tab->bmap->n_div; ++i) {
if (isl_int_ne(tab->bmap->div[i][0], denom))
continue;
- if (!isl_seq_eq(tab->bmap->div[i] + 1, div, total))
+ if (!isl_seq_eq(tab->bmap->div[i] + 1, div, 1 + total))
continue;
return i;
}
if (!tab || tab->empty)
return tab;
}
+ if (bmap->n_eq)
+ tab = restore_lexmin(tab);
for (i = 0; i < bmap->n_ineq; ++i) {
if (max)
isl_seq_neg(bmap->ineq[i] + 1 + tab->n_param,
int i;
int sgn;
isl_int tmp;
- int res = isl_tab_row_unknown;
+ enum isl_tab_row_sign res = isl_tab_row_unknown;
- isl_assert(tab->mat->ctx, tab->samples, return 0);
- isl_assert(tab->mat->ctx, tab->samples->n_col == 1 + tab->n_var, return 0);
+ isl_assert(tab->mat->ctx, tab->samples, return isl_tab_row_unknown);
+ isl_assert(tab->mat->ctx, tab->samples->n_col == 1 + tab->n_var,
+ return isl_tab_row_unknown);
isl_int_init(tmp);
for (i = tab->n_outside; i < tab->n_sample; ++i) {
return -1;
r = best_split(tab, clex->tab);
- if (isl_tab_rollback(clex->tab, snap) < 0)
+ if (r >= 0 && isl_tab_rollback(clex->tab, snap) < 0)
return -1;
return r;
struct isl_context_lex *clex = (struct isl_context_lex *)context;
struct isl_tab_undo *snap;
+ if (!tab)
+ return NULL;
+
snap = isl_tab_snap(clex->tab);
if (isl_tab_push_basis(clex->tab) < 0)
goto error;
struct isl_context *context, struct isl_tab *tab)
{
struct isl_context_gbr *cgbr = (struct isl_context_gbr *)context;
+ if (!tab)
+ return NULL;
return tab_detect_nonnegative_parameters(tab, cgbr->tab);
}
if (!cgbr->cone) {
bset = isl_tab_peek_bset(cgbr->tab);
- cgbr->cone = isl_tab_from_recession_cone(bset);
+ cgbr->cone = isl_tab_from_recession_cone(bset, 0);
if (!cgbr->cone)
return NULL;
if (isl_tab_track_bset(cgbr->cone, isl_basic_set_dup(bset)) < 0)
return NULL;
}
- cgbr->cone = isl_tab_detect_implicit_equalities(cgbr->cone);
- if (!cgbr->cone)
+ if (isl_tab_detect_implicit_equalities(cgbr->cone) < 0)
return NULL;
if (cgbr->cone->n_dead == cgbr->cone->n_col) {
if (cgbr->tab->basis->n_col != 1 + cgbr->tab->n_var) {
isl_mat_free(cgbr->tab->basis);
cgbr->tab->basis = NULL;
- } else {
- cgbr->tab->n_zero = 0;
- cgbr->tab->n_unbounded = 0;
}
+ cgbr->tab->n_zero = 0;
+ cgbr->tab->n_unbounded = 0;
}
snap = isl_tab_snap(cgbr->tab);
if (isl_tab_extend_cons(tab, 2) < 0)
goto error;
- tab = isl_tab_add_eq(tab, eq);
+ if (isl_tab_add_eq(tab, eq) < 0)
+ goto error;
return tab;
error:
if (cgbr->cone && cgbr->cone->n_col != cgbr->cone->n_dead) {
if (isl_tab_extend_cons(cgbr->cone, 2) < 0)
goto error;
- cgbr->cone = isl_tab_add_eq(cgbr->cone, eq);
+ if (isl_tab_add_eq(cgbr->cone, eq) < 0)
+ goto error;
}
if (check) {
if (!cgbr->cone) {
struct isl_basic_set *bset = isl_tab_peek_bset(cgbr->tab);
- cgbr->cone = isl_tab_from_recession_cone(bset);
+ cgbr->cone = isl_tab_from_recession_cone(bset, 0);
if (!cgbr->cone)
goto error;
if (isl_tab_track_bset(cgbr->cone, isl_basic_set_dup(bset)) < 0)
goto error;
}
- cgbr->cone = isl_tab_detect_implicit_equalities(cgbr->cone);
+ if (isl_tab_detect_implicit_equalities(cgbr->cone) < 0)
+ goto error;
n_ineq = cgbr->tab->bmap->n_ineq;
cgbr->tab = isl_tab_detect_equalities(cgbr->tab, cgbr->cone);
snap = isl_tab_snap(cgbr->tab);
r = best_split(tab, cgbr->tab);
- if (isl_tab_rollback(cgbr->tab, snap) < 0)
+ if (r >= 0 && isl_tab_rollback(cgbr->tab, snap) < 0)
return -1;
return r;
static struct isl_sol_map *sol_map_init(struct isl_basic_map *bmap,
struct isl_basic_set *dom, int track_empty, int max)
{
- struct isl_sol_map *sol_map;
+ struct isl_sol_map *sol_map = NULL;
- sol_map = isl_calloc_type(bset->ctx, struct isl_sol_map);
+ if (!bmap)
+ goto error;
+
+ sol_map = isl_calloc_type(bmap->ctx, struct isl_sol_map);
if (!sol_map)
goto error;
struct isl_sol *sol, int row)
{
struct isl_vec *ineq = NULL;
- int res = isl_tab_row_unknown;
+ enum isl_tab_row_sign res = isl_tab_row_unknown;
int critical;
int strict;
int row2;
return res;
error:
isl_vec_free(ineq);
- return 0;
+ return isl_tab_row_unknown;
}
static void find_solutions(struct isl_sol *sol, struct isl_tab *tab);
find_solutions(sol, tab);
- sol->context->op->restore(sol->context, saved);
+ if (!sol->error)
+ sol->context->op->restore(sol->context, saved);
return;
error:
sol->error = 1;
int empty;
void *saved;
- if (!sol->context)
+ if (!sol->context || sol->error)
goto error;
saved = sol->context->op->save(sol->context);
for (; tab && !tab->empty; tab = restore_lexmin(tab)) {
int flags;
int row;
- int sgn;
+ enum isl_tab_row_sign sgn;
int split = -1;
int n_split = 0;
row = split;
isl_seq_neg(ineq->el, ineq->el, ineq->size);
isl_int_sub_ui(ineq->el[0], ineq->el[0], 1);
- context->op->add_ineq(context, ineq->el, 0, 1);
+ if (!sol->error)
+ context->op->add_ineq(context, ineq->el, 0, 1);
isl_vec_free(ineq);
if (sol->error)
goto error;
if (d < 0)
goto error;
ineq = ineq_for_div(context->op->peek_basic_set(context), d);
+ if (!ineq)
+ goto error;
sol_inc_level(sol);
no_sol_in_strict(sol, tab, ineq);
isl_seq_neg(ineq->el, ineq->el, ineq->size);
return;
error:
isl_tab_free(tab);
- sol_free(sol);
+ sol->error = 1;
}
/* Compute the lexicographic minimum of the set represented by the main
{
int row;
+ if (!tab)
+ goto error;
+
sol->level = 0;
for (row = tab->n_redundant; row < tab->n_row; ++row) {
+ tab->n_param - (tab->n_var - tab->n_div);
eq = isl_vec_alloc(tab->mat->ctx, 1+tab->n_param+tab->n_div);
+ if (!eq)
+ goto error;
get_row_parameter_line(tab, row, eq->el);
isl_int_neg(eq->el[1 + p], tab->mat->row[row][0]);
eq = isl_vec_normalize(eq);
return;
error:
isl_tab_free(tab);
- sol_free(sol);
+ sol->error = 1;
}
static void sol_map_find_solutions(struct isl_sol_map *sol_map,
if (empty)
*empty = NULL;
if (!bmap || !dom)
- goto error;
+ goto error2;
isl_assert(bmap->ctx,
isl_basic_map_compatible_domain(bmap, dom), goto error);
sol_free(&sol_map->sol);
isl_basic_map_free(bmap);
return result;
+error2:
+ isl_basic_set_free(dom);
error:
sol_free(&sol_map->sol);
isl_basic_map_free(bmap);
struct isl_dim *dom_dim;
struct isl_basic_set *dom = NULL;
- sol_for = isl_calloc_type(bset->ctx, struct isl_sol_for);
+ sol_for = isl_calloc_type(bmap->ctx, struct isl_sol_for);
if (!sol_for)
goto error;