* Copyright 2008-2009 Katholieke Universiteit Leuven
* Copyright 2010 INRIA Saclay
*
- * Use of this software is governed by the GNU LGPLv2.1 license
+ * Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, K.U.Leuven, Departement
* Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
#include "isl_sample.h"
#include <isl_mat_private.h>
#include <isl_aff_private.h>
+#include <isl_options_private.h>
#include <isl_config.h>
/*
void *(*save)(struct isl_context *context);
/* restore saved context */
void (*restore)(struct isl_context *context, void *);
+ /* discard saved context */
+ void (*discard)(void *);
/* invalidate context */
void (*invalidate)(struct isl_context *context);
/* free context */
return;
error:
isl_basic_set_free(dom);
+ isl_mat_free(M);
sol->error = 1;
}
if (tab->empty && !sol->add_empty)
return;
+ if (sol->context->op->is_empty(sol->context))
+ return;
bset = sol_domain(sol);
return ineq;
}
+/* Normalize a div expression of the form
+ *
+ * [(g*f(x) + c)/(g * m)]
+ *
+ * with c the constant term and f(x) the remaining coefficients, to
+ *
+ * [(f(x) + [c/g])/m]
+ */
+static void normalize_div(__isl_keep isl_vec *div)
+{
+ isl_ctx *ctx = isl_vec_get_ctx(div);
+ int len = div->size - 2;
+
+ isl_seq_gcd(div->el + 2, len, &ctx->normalize_gcd);
+ isl_int_gcd(ctx->normalize_gcd, ctx->normalize_gcd, div->el[0]);
+
+ if (isl_int_is_one(ctx->normalize_gcd))
+ return;
+
+ isl_int_divexact(div->el[0], div->el[0], ctx->normalize_gcd);
+ isl_int_fdiv_q(div->el[1], div->el[1], ctx->normalize_gcd);
+ isl_seq_scale_down(div->el + 2, div->el + 2, ctx->normalize_gcd, len);
+}
+
/* Return a integer division for use in a parametric cut based on the given row.
* In particular, let the parametric constant of the row be
*
isl_int_set(div->el[0], tab->mat->row[row][0]);
get_row_parameter_line(tab, row, div->el + 1);
- div = isl_vec_normalize(div);
isl_seq_neg(div->el + 1, div->el + 1, div->size - 1);
+ normalize_div(div);
isl_seq_fdiv_r(div->el + 1, div->el + 1, div->el[0], div->size - 1);
return div;
isl_int_set(div->el[0], tab->mat->row[row][0]);
get_row_parameter_line(tab, row, div->el + 1);
- div = isl_vec_normalize(div);
+ normalize_div(div);
isl_seq_fdiv_r(div->el + 1, div->el + 1, div->el[0], div->size - 1);
return div;
/* Given a conflicting row in the tableau, report all constraints
* involved in the row to the caller. That is, the row itself
- * (if represents a constraint) and all constraint columns with
- * non-zero (and therefore negative) coefficient.
+ * (if it represents a constraint) and all constraint columns with
+ * non-zero (and therefore negative) coefficients.
*/
static int report_conflict(struct isl_tab *tab, int row)
{
return tab->con[r].index;
}
+#define CUT_ALL 1
+#define CUT_ONE 0
+
/* Given a non-parametric tableau, add cuts until an integer
* sample point is obtained or until the tableau is determined
* to be integer infeasible.
* combination of variables/constraints plus a non-integral constant,
* then there is no way to obtain an integer point and we return
* a tableau that is marked empty.
+ * The parameter cutting_strategy controls the strategy used when adding cuts
+ * to remove non-integer points. CUT_ALL adds all possible cuts
+ * before continuing the search. CUT_ONE adds only one cut at a time.
*/
-static struct isl_tab *cut_to_integer_lexmin(struct isl_tab *tab)
+static struct isl_tab *cut_to_integer_lexmin(struct isl_tab *tab,
+ int cutting_strategy)
{
int var;
int row;
row = add_cut(tab, row);
if (row < 0)
goto error;
+ if (cutting_strategy == CUT_ONE)
+ break;
} while ((var = next_non_integer_var(tab, var, &flags)) != -1);
if (restore_lexmin(tab) < 0)
goto error;
if (isl_tab_push_basis(tab) < 0)
goto error;
- tab = cut_to_integer_lexmin(tab);
+ tab = cut_to_integer_lexmin(tab, CUT_ALL);
if (!tab)
goto error;
n = tab->n_div;
d = context->op->get_div(context, tab, div);
+ isl_vec_free(div);
if (d < 0)
return -1;
if (tab->row_sign)
tab->row_sign[tab->con[r].index] = isl_tab_row_neg;
- isl_vec_free(div);
-
row = tab->con[r].index;
if (d >= n && context->op->detect_equalities(context, tab) < 0)
}
}
+static void context_lex_discard(void *save)
+{
+}
+
static int context_lex_is_ok(struct isl_context *context)
{
struct isl_context_lex *clex = (struct isl_context_lex *)context;
context_lex_is_ok,
context_lex_save,
context_lex_restore,
+ context_lex_discard,
context_lex_invalidate,
context_lex_free,
};
{
struct isl_tab *tab;
- bset = isl_basic_set_cow(bset);
if (!bset)
return NULL;
tab = tab_for_lexmin((struct isl_basic_map *)bset, NULL, 1, 0);
}
}
- cgbr->shifted = isl_tab_from_basic_set(bset);
+ cgbr->shifted = isl_tab_from_basic_set(bset, 0);
for (i = 0; i < bset->n_ineq; ++i)
isl_int_set(bset->ineq[i][0], cst->el[i]);
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)
+ if (isl_tab_track_bset(cgbr->cone,
+ isl_basic_set_copy(bset)) < 0)
return NULL;
}
if (isl_tab_detect_implicit_equalities(cgbr->cone) < 0)
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)
+ if (isl_tab_track_bset(cgbr->cone,
+ isl_basic_set_copy(bset)) < 0)
goto error;
}
if (isl_tab_detect_implicit_equalities(cgbr->cone) < 0)
cgbr->tab = NULL;
}
+static void context_gbr_discard(void *save)
+{
+ struct isl_gbr_tab_undo *snap = (struct isl_gbr_tab_undo *)save;
+ free(snap);
+}
+
static int context_gbr_is_ok(struct isl_context *context)
{
struct isl_context_gbr *cgbr = (struct isl_context_gbr *)context;
context_gbr_is_ok,
context_gbr_save,
context_gbr_restore,
+ context_gbr_discard,
context_gbr_invalidate,
context_gbr_free,
};
cgbr->shifted = NULL;
cgbr->cone = NULL;
- cgbr->tab = isl_tab_from_basic_set(dom);
+ cgbr->tab = isl_tab_from_basic_set(dom, 1);
cgbr->tab = isl_tab_init_samples(cgbr->tab);
if (!cgbr->tab)
goto error;
- if (isl_tab_track_bset(cgbr->tab,
- isl_basic_set_cow(isl_basic_set_copy(dom))) < 0)
- goto error;
check_gbr_integer_feasible(cgbr);
return &cgbr->context;
if (!sol->error)
sol->context->op->restore(sol->context, saved);
+ else
+ sol->context->op->discard(saved);
return;
error:
sol->error = 1;
bmap = isl_basic_map_finalize(bmap);
n_div = isl_basic_set_dim(dom, isl_dim_div);
- dom = isl_basic_set_add(dom, isl_dim_set, 1);
+ dom = isl_basic_set_add_dims(dom, isl_dim_set, 1);
dom = isl_basic_set_extend_constraints(dom, 0, n);
for (i = 0; i < n; ++i) {
k = isl_basic_set_alloc_inequality(dom);
isl_int_set(aff->v->el[0], M->row[0][0]);
isl_seq_cpy(aff->v->el + 1, M->row[i], M->n_col);
}
+ aff = isl_aff_normalize(aff);
list = isl_aff_list_add(list, aff);
}
isl_local_space_free(ls);
int side, base;
if (init) {
- tab = cut_to_integer_lexmin(tab);
+ tab = cut_to_integer_lexmin(tab, CUT_ONE);
if (!tab)
goto error;
if (tab->empty)