-static __isl_give isl_map *set_minmax(__isl_take isl_map *map,
- struct variable *var)
-{
- int i, j, k;
- isl_basic_map *bmap = NULL;
- isl_ctx *ctx;
- isl_map *split = NULL;
- int total;
-
- ctx = isl_map_get_ctx(map);
- total = isl_map_dim(map, isl_dim_all);
- split = isl_map_alloc_dim(isl_map_get_dim(map),
- var->list->n_row, ISL_SET_DISJOINT);
-
- for (i = 0; i < var->list->n_row; ++i) {
- bmap = isl_basic_map_alloc_dim(isl_map_get_dim(map), 0,
- 1, var->list->n_row - 1);
- k = isl_basic_map_alloc_equality(bmap);
- if (k < 0)
- goto error;
- isl_seq_cpy(bmap->eq[k], var->list->row[i], var->list->n_col);
- isl_int_set_si(bmap->eq[k][1 + var->pos], -1);
- for (j = 0; j < var->list->n_row; ++j) {
- if (j == i)
- continue;
- k = isl_basic_map_alloc_inequality(bmap);
- if (k < 0)
- goto error;
- if (var->sign < 0)
- isl_seq_combine(bmap->ineq[k],
- ctx->one, var->list->row[j],
- ctx->negone, var->list->row[i],
- var->list->n_col);
- else
- isl_seq_combine(bmap->ineq[k],
- ctx->negone, var->list->row[j],
- ctx->one, var->list->row[i],
- var->list->n_col);
- isl_seq_clr(bmap->ineq[k] + var->list->n_col,
- 1 + total - var->list->n_col);
- if (j < i)
- isl_int_sub_ui(bmap->ineq[k][0],
- bmap->ineq[k][0], 1);
- }
- bmap = isl_basic_map_finalize(bmap);
- split = isl_map_add_basic_map(split, bmap);
- }
-
- map = isl_map_intersect(map, split);
-
- return map;
-error:
- isl_basic_map_free(bmap);
- isl_map_free(split);
- isl_map_free(map);
- return NULL;
-}
-
-/* Plug in the definitions of all min and max expressions.
- * If a min expression only appears in inequalities and only
- * with a positive coefficient, then we can simply bound
- * the variable representing the min by its defining terms
- * and similarly for a max expression.
- * Otherwise, we have to assign the different terms to the
- * variable under the condition that the assigned term is smaller
- * than the other terms.
- */
-static __isl_give isl_map *add_minmax(__isl_take isl_map *map,
- struct vars *v, int n)
-{
- struct variable *var;
-
- while (n < v->n) {
- var = first_minmax(v, n);
- if (!var)
- break;
- if (all_coefficients_of_sign(map, var->pos, -var->sign))
- map = bound_minmax(map, var);
- else
- map = set_minmax(map, var);
- n = var->pos + 1;
- }
-
- return map;
-}
-
-static isl_map *read_constraint(struct isl_stream *s,
- struct vars *v, __isl_take isl_basic_map *bmap)