-#include "isl_set.h"
-#include "isl_map.h"
-#include "isl_seq.h"
+/*
+ * 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/set.h>
+#include <isl/map.h>
+#include <isl/mat.h>
+#include <isl/seq.h>
#include "isl_piplib.h"
#include "isl_map_piplib.h"
#include "isl_map_private.h"
if (add_equality(data->ctx, bmap, data->pos, j,
l->vector) < 0)
goto error;
- map = isl_map_add(map, isl_basic_map_copy(bmap));
+ map = isl_map_add_basic_map(map, isl_basic_map_copy(bmap));
if (isl_basic_map_free_equality(bmap, n_out))
goto error;
} else if (data->rest) {
bset = isl_basic_set_drop_dims(bset, n_in, n_out);
if (!bset)
goto error;
- *data->rest = isl_set_add(*data->rest, bset);
+ *data->rest = isl_set_add_basic_set(*data->rest, bset);
}
if (isl_basic_map_free_inequality(bmap, 2*(bmap->n_div - old_n_div)))
pip_param, extra_front, extra_back);
}
-static struct isl_map *extremum_on(
+struct isl_map *isl_pip_basic_map_lexopt(
struct isl_basic_map *bmap, struct isl_basic_set *dom,
struct isl_set **empty, int max)
{
PipMatrix *domain = NULL, *context = NULL;
unsigned nparam, n_in, n_out;
+ bmap = isl_basic_map_detect_equalities(bmap);
if (!bmap || !dom)
goto error;
isl_basic_set_free(dom);
return NULL;
}
-
-struct isl_map *isl_pip_basic_map_lexmax(
- struct isl_basic_map *bmap, struct isl_basic_set *dom,
- struct isl_set **empty)
-{
- return extremum_on(bmap, dom, empty, 1);
-}
-
-struct isl_map *isl_pip_basic_map_lexmin(
- struct isl_basic_map *bmap, struct isl_basic_set *dom,
- struct isl_set **empty)
-{
- return extremum_on(bmap, dom, empty, 0);
-}
-
-/* Project the given basic set onto its parameter domain, possibly introducing
- * new, explicit, existential variables in the constraints.
- * The input has parameters and output variables.
- * The output has the same parameters, but no output variables, only
- * explicit existentially quantified variables.
- */
-static struct isl_set *compute_divs(struct isl_basic_set *bset)
-{
- PipMatrix *domain = NULL, *context = NULL;
- PipOptions *options;
- PipQuast *sol;
- struct isl_ctx *ctx;
- struct isl_dim *dim;
- struct isl_map *map;
- struct isl_set *set;
- struct isl_basic_set *dom;
- unsigned nparam;
-
- if (!bset)
- goto error;
-
- ctx = bset->ctx;
- nparam = isl_basic_set_n_param(bset);
-
- domain = isl_basic_set_to_pip(bset, nparam, 0, 0);
- if (!domain)
- goto error;
- context = pip_matrix_alloc(0, nparam + 2);
- if (!context)
- goto error;
-
- options = pip_options_init();
- options->Simplify = 1;
- options->Urs_unknowns = -1;
- options->Urs_parms = -1;
- sol = pip_solve(domain, context, -1, options);
-
- dom = isl_basic_set_alloc(ctx, nparam, 0, 0, 0, 0);
- map = isl_map_from_quast(ctx, sol, isl_dim_copy(dom->dim), dom, NULL);
- set = (struct isl_set *)map;
-
- pip_quast_free(sol);
- pip_options_free(options);
- pip_matrix_free(domain);
- pip_matrix_free(context);
-
- isl_basic_set_free(bset);
-
- return set;
-error:
- if (domain)
- pip_matrix_free(domain);
- if (context)
- pip_matrix_free(context);
- isl_basic_set_free(dom);
- isl_basic_set_free(bset);
- return NULL;
-}
-
-static struct isl_map *isl_map_reset_dim(struct isl_map *map,
- struct isl_dim *dim)
-{
- int i;
-
- if (!map || !dim)
- goto error;
-
- for (i = 0; i < map->n; ++i) {
- isl_dim_free(map->p[i]->dim);
- map->p[i]->dim = isl_dim_copy(dim);
- }
- isl_dim_free(map->dim);
- map->dim = dim;
-
- return map;
-error:
- isl_map_free(map);
- isl_dim_free(dim);
- return NULL;
-}
-
-/* Compute an explicit representation for all the existentially
- * quantified variables.
- * The input and output dimensions are first turned into parameters
- * and the existential variables into output dimensions.
- * compute_divs then returns a map with the same parameters and
- * no input or output dimensions and the dimension specification
- * is reset to that of the input.
- */
-struct isl_map *isl_pip_basic_map_compute_divs(struct isl_basic_map *bmap)
-{
- struct isl_basic_set *bset;
- struct isl_set *set;
- struct isl_map *map;
- struct isl_dim *dim, *orig_dim = NULL;
- unsigned nparam;
- unsigned n_in;
- unsigned n_out;
-
- bmap = isl_basic_map_cow(bmap);
- if (!bmap)
- return NULL;
-
- nparam = isl_basic_map_dim(bmap, isl_dim_param);
- n_in = isl_basic_map_dim(bmap, isl_dim_in);
- n_out = isl_basic_map_dim(bmap, isl_dim_out);
- dim = isl_dim_set_alloc(bmap->ctx, nparam + n_in + n_out, bmap->n_div);
- if (!dim)
- goto error;
-
- orig_dim = bmap->dim;
- bmap->dim = dim;
- bmap->extra -= bmap->n_div;
- bmap->n_div = 0;
- bset = (struct isl_basic_set *)bmap;
-
- set = compute_divs(bset);
- map = (struct isl_map *)set;
- map = isl_map_reset_dim(map, orig_dim);
-
- return map;
-error:
- isl_basic_map_free(bmap);
- return NULL;
-}