2015-02-05 04:55:43 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2008-2009 Katholieke Universiteit Leuven
|
|
|
|
*
|
|
|
|
* 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_ctx_private.h>
|
|
|
|
#include <isl_map_private.h>
|
|
|
|
#include <isl/lp.h>
|
|
|
|
#include <isl_seq.h>
|
|
|
|
#include "isl_tab.h"
|
|
|
|
#include <isl_options_private.h>
|
|
|
|
#include <isl_local_space_private.h>
|
|
|
|
#include <isl_aff_private.h>
|
|
|
|
#include <isl_mat_private.h>
|
|
|
|
#include <isl_val_private.h>
|
|
|
|
#include <isl_vec_private.h>
|
|
|
|
|
2016-11-16 19:06:47 +08:00
|
|
|
#include <bset_to_bmap.c>
|
|
|
|
#include <set_to_map.c>
|
|
|
|
|
2017-04-28 14:11:17 +08:00
|
|
|
enum isl_lp_result isl_tab_solve_lp(__isl_keep isl_basic_map *bmap,
|
|
|
|
int maximize, isl_int *f, isl_int denom, isl_int *opt,
|
|
|
|
isl_int *opt_denom, __isl_give isl_vec **sol)
|
2015-02-05 04:55:43 +08:00
|
|
|
{
|
|
|
|
struct isl_tab *tab;
|
|
|
|
enum isl_lp_result res;
|
[Polly] Update ISL to isl-0.22.1-87-gfee05a13.
The primary motivation is to fix an assertion failure in
isl_basic_map_alloc_equality:
isl_assert(ctx, room_for_con(bmap, 1), return -1);
Although the assertion does not occur anymore, I could not identify
which of ISL's commits fixed it.
Compared to the previous ISL version, Polly requires some changes for this update
* Since ISL commit
20d3574 "perform parameter alignment by modifying both arguments to function"
isl_*_gist_* and similar functions do not always align the paramter
list anymore. This caused the parameter lists in JScop files to
become out-of-sync. Since many regression tests use JScop files with
a fixed parameter list and order, we explicitly call align_params to
ensure a predictable parameter list.
* ISL changed some return types to isl_size, a typedef of (signed) int.
This caused some issues where the return type was unsigned int before:
- No overload for std::max(unsigned,isl_size)
- It cause additional 'mixed signed/unsigned comparison' warnings.
Since they do not break compilation, and sizes larger than 2^31
were never supported, I am going to fix it separately.
* With the change to isl_size, commit
57d547 "isl_*_list_size: return isl_size"
also changed the return value in case of an error from 0 to -1. This
caused undefined looping over isl_iterator since the 'end iterator'
got index -1, never reached from the 'begin iterator' with index 0.
* Some internal changes in ISL caused the number of operations to
increase when determining access ranges to determine aliasing
overlaps. In one test, this caused exceeding the default limit of
800000. The operations-limit was disabled for this test.
2020-02-11 04:51:33 +08:00
|
|
|
isl_size dim = isl_basic_map_dim(bmap, isl_dim_all);
|
2015-02-05 04:55:43 +08:00
|
|
|
|
[Polly] Update ISL to isl-0.22.1-87-gfee05a13.
The primary motivation is to fix an assertion failure in
isl_basic_map_alloc_equality:
isl_assert(ctx, room_for_con(bmap, 1), return -1);
Although the assertion does not occur anymore, I could not identify
which of ISL's commits fixed it.
Compared to the previous ISL version, Polly requires some changes for this update
* Since ISL commit
20d3574 "perform parameter alignment by modifying both arguments to function"
isl_*_gist_* and similar functions do not always align the paramter
list anymore. This caused the parameter lists in JScop files to
become out-of-sync. Since many regression tests use JScop files with
a fixed parameter list and order, we explicitly call align_params to
ensure a predictable parameter list.
* ISL changed some return types to isl_size, a typedef of (signed) int.
This caused some issues where the return type was unsigned int before:
- No overload for std::max(unsigned,isl_size)
- It cause additional 'mixed signed/unsigned comparison' warnings.
Since they do not break compilation, and sizes larger than 2^31
were never supported, I am going to fix it separately.
* With the change to isl_size, commit
57d547 "isl_*_list_size: return isl_size"
also changed the return value in case of an error from 0 to -1. This
caused undefined looping over isl_iterator since the 'end iterator'
got index -1, never reached from the 'begin iterator' with index 0.
* Some internal changes in ISL caused the number of operations to
increase when determining access ranges to determine aliasing
overlaps. In one test, this caused exceeding the default limit of
800000. The operations-limit was disabled for this test.
2020-02-11 04:51:33 +08:00
|
|
|
if (dim < 0)
|
|
|
|
return isl_lp_error;
|
2015-02-05 04:55:43 +08:00
|
|
|
if (maximize)
|
|
|
|
isl_seq_neg(f, f, 1 + dim);
|
|
|
|
|
|
|
|
bmap = isl_basic_map_gauss(bmap, NULL);
|
|
|
|
tab = isl_tab_from_basic_map(bmap, 0);
|
|
|
|
res = isl_tab_min(tab, f, denom, opt, opt_denom, 0);
|
|
|
|
if (res == isl_lp_ok && sol) {
|
|
|
|
*sol = isl_tab_get_sample_value(tab);
|
|
|
|
if (!*sol)
|
|
|
|
res = isl_lp_error;
|
|
|
|
}
|
|
|
|
isl_tab_free(tab);
|
|
|
|
|
|
|
|
if (maximize)
|
|
|
|
isl_seq_neg(f, f, 1 + dim);
|
|
|
|
if (maximize && opt)
|
|
|
|
isl_int_neg(*opt, *opt);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a basic map "bmap" and an affine combination of the variables "f"
|
|
|
|
* with denominator "denom", set *opt / *opt_denom to the minimal
|
|
|
|
* (or maximal if "maximize" is true) value attained by f/d over "bmap",
|
|
|
|
* assuming the basic map is not empty and the expression cannot attain
|
|
|
|
* arbitrarily small (or large) values.
|
|
|
|
* If opt_denom is NULL, then *opt is rounded up (or down)
|
|
|
|
* to the nearest integer.
|
|
|
|
* The return value reflects the nature of the result (empty, unbounded,
|
2017-04-03 14:46:16 +08:00
|
|
|
* minimal or maximal value returned in *opt).
|
2015-02-05 04:55:43 +08:00
|
|
|
*/
|
2017-04-28 14:11:17 +08:00
|
|
|
enum isl_lp_result isl_basic_map_solve_lp(__isl_keep isl_basic_map *bmap,
|
|
|
|
int max, isl_int *f, isl_int d, isl_int *opt, isl_int *opt_denom,
|
|
|
|
__isl_give isl_vec **sol)
|
2015-02-05 04:55:43 +08:00
|
|
|
{
|
|
|
|
if (sol)
|
|
|
|
*sol = NULL;
|
|
|
|
|
|
|
|
if (!bmap)
|
|
|
|
return isl_lp_error;
|
|
|
|
|
|
|
|
return isl_tab_solve_lp(bmap, max, f, d, opt, opt_denom, sol);
|
|
|
|
}
|
|
|
|
|
2020-08-21 13:17:29 +08:00
|
|
|
enum isl_lp_result isl_basic_set_solve_lp(__isl_keep isl_basic_set *bset,
|
|
|
|
int max, isl_int *f, isl_int d, isl_int *opt, isl_int *opt_denom,
|
|
|
|
__isl_give isl_vec **sol)
|
2015-02-05 04:55:43 +08:00
|
|
|
{
|
2016-11-16 19:06:47 +08:00
|
|
|
return isl_basic_map_solve_lp(bset_to_bmap(bset), max,
|
2015-02-05 04:55:43 +08:00
|
|
|
f, d, opt, opt_denom, sol);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum isl_lp_result isl_map_solve_lp(__isl_keep isl_map *map, int max,
|
|
|
|
isl_int *f, isl_int d, isl_int *opt,
|
|
|
|
isl_int *opt_denom,
|
2020-08-21 13:17:29 +08:00
|
|
|
__isl_give isl_vec **sol)
|
2015-02-05 04:55:43 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
isl_int o;
|
|
|
|
isl_int t;
|
|
|
|
isl_int opt_i;
|
|
|
|
isl_int opt_denom_i;
|
|
|
|
enum isl_lp_result res;
|
|
|
|
int max_div;
|
|
|
|
isl_vec *v = NULL;
|
|
|
|
|
|
|
|
if (!map)
|
|
|
|
return isl_lp_error;
|
|
|
|
if (map->n == 0)
|
|
|
|
return isl_lp_empty;
|
|
|
|
|
|
|
|
max_div = 0;
|
|
|
|
for (i = 0; i < map->n; ++i)
|
|
|
|
if (map->p[i]->n_div > max_div)
|
|
|
|
max_div = map->p[i]->n_div;
|
|
|
|
if (max_div > 0) {
|
[Polly] Update ISL to isl-0.22.1-87-gfee05a13.
The primary motivation is to fix an assertion failure in
isl_basic_map_alloc_equality:
isl_assert(ctx, room_for_con(bmap, 1), return -1);
Although the assertion does not occur anymore, I could not identify
which of ISL's commits fixed it.
Compared to the previous ISL version, Polly requires some changes for this update
* Since ISL commit
20d3574 "perform parameter alignment by modifying both arguments to function"
isl_*_gist_* and similar functions do not always align the paramter
list anymore. This caused the parameter lists in JScop files to
become out-of-sync. Since many regression tests use JScop files with
a fixed parameter list and order, we explicitly call align_params to
ensure a predictable parameter list.
* ISL changed some return types to isl_size, a typedef of (signed) int.
This caused some issues where the return type was unsigned int before:
- No overload for std::max(unsigned,isl_size)
- It cause additional 'mixed signed/unsigned comparison' warnings.
Since they do not break compilation, and sizes larger than 2^31
were never supported, I am going to fix it separately.
* With the change to isl_size, commit
57d547 "isl_*_list_size: return isl_size"
also changed the return value in case of an error from 0 to -1. This
caused undefined looping over isl_iterator since the 'end iterator'
got index -1, never reached from the 'begin iterator' with index 0.
* Some internal changes in ISL caused the number of operations to
increase when determining access ranges to determine aliasing
overlaps. In one test, this caused exceeding the default limit of
800000. The operations-limit was disabled for this test.
2020-02-11 04:51:33 +08:00
|
|
|
isl_size total = isl_map_dim(map, isl_dim_all);
|
|
|
|
if (total < 0)
|
|
|
|
return isl_lp_error;
|
2015-02-05 04:55:43 +08:00
|
|
|
v = isl_vec_alloc(map->ctx, 1 + total + max_div);
|
|
|
|
if (!v)
|
|
|
|
return isl_lp_error;
|
|
|
|
isl_seq_cpy(v->el, f, 1 + total);
|
|
|
|
isl_seq_clr(v->el + 1 + total, max_div);
|
|
|
|
f = v->el;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!opt && map->n > 1 && sol) {
|
|
|
|
isl_int_init(o);
|
|
|
|
opt = &o;
|
|
|
|
}
|
|
|
|
if (map->n > 0)
|
|
|
|
isl_int_init(opt_i);
|
|
|
|
if (map->n > 0 && opt_denom) {
|
|
|
|
isl_int_init(opt_denom_i);
|
|
|
|
isl_int_init(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = isl_basic_map_solve_lp(map->p[0], max, f, d,
|
|
|
|
opt, opt_denom, sol);
|
|
|
|
if (res == isl_lp_error || res == isl_lp_unbounded)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (sol)
|
|
|
|
*sol = NULL;
|
|
|
|
|
|
|
|
for (i = 1; i < map->n; ++i) {
|
|
|
|
isl_vec *sol_i = NULL;
|
|
|
|
enum isl_lp_result res_i;
|
|
|
|
int better;
|
|
|
|
|
|
|
|
res_i = isl_basic_map_solve_lp(map->p[i], max, f, d,
|
|
|
|
&opt_i,
|
|
|
|
opt_denom ? &opt_denom_i : NULL,
|
|
|
|
sol ? &sol_i : NULL);
|
|
|
|
if (res_i == isl_lp_error || res_i == isl_lp_unbounded) {
|
|
|
|
res = res_i;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (res_i == isl_lp_empty)
|
|
|
|
continue;
|
|
|
|
if (res == isl_lp_empty) {
|
|
|
|
better = 1;
|
|
|
|
} else if (!opt_denom) {
|
|
|
|
if (max)
|
|
|
|
better = isl_int_gt(opt_i, *opt);
|
|
|
|
else
|
|
|
|
better = isl_int_lt(opt_i, *opt);
|
|
|
|
} else {
|
|
|
|
isl_int_mul(t, opt_i, *opt_denom);
|
|
|
|
isl_int_submul(t, *opt, opt_denom_i);
|
|
|
|
if (max)
|
|
|
|
better = isl_int_is_pos(t);
|
|
|
|
else
|
|
|
|
better = isl_int_is_neg(t);
|
|
|
|
}
|
|
|
|
if (better) {
|
|
|
|
res = res_i;
|
|
|
|
if (opt)
|
|
|
|
isl_int_set(*opt, opt_i);
|
|
|
|
if (opt_denom)
|
|
|
|
isl_int_set(*opt_denom, opt_denom_i);
|
|
|
|
if (sol) {
|
|
|
|
isl_vec_free(*sol);
|
|
|
|
*sol = sol_i;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
isl_vec_free(sol_i);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
isl_vec_free(v);
|
|
|
|
if (map->n > 0 && opt_denom) {
|
|
|
|
isl_int_clear(opt_denom_i);
|
|
|
|
isl_int_clear(t);
|
|
|
|
}
|
|
|
|
if (map->n > 0)
|
|
|
|
isl_int_clear(opt_i);
|
|
|
|
if (opt == &o)
|
|
|
|
isl_int_clear(o);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum isl_lp_result isl_set_solve_lp(__isl_keep isl_set *set, int max,
|
|
|
|
isl_int *f, isl_int d, isl_int *opt,
|
|
|
|
isl_int *opt_denom,
|
2020-08-21 13:17:29 +08:00
|
|
|
__isl_give isl_vec **sol)
|
2015-02-05 04:55:43 +08:00
|
|
|
{
|
2016-11-16 19:06:47 +08:00
|
|
|
return isl_map_solve_lp(set_to_map(set), max,
|
2015-02-05 04:55:43 +08:00
|
|
|
f, d, opt, opt_denom, sol);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the optimal (rational) value of "obj" over "bset", assuming
|
|
|
|
* that "obj" and "bset" have aligned parameters and divs.
|
|
|
|
* If "max" is set, then the maximal value is computed.
|
|
|
|
* Otherwise, the minimal value is computed.
|
|
|
|
*
|
|
|
|
* Return infinity or negative infinity if the optimal value is unbounded and
|
|
|
|
* NaN if "bset" is empty.
|
|
|
|
*
|
|
|
|
* Call isl_basic_set_solve_lp and translate the results.
|
|
|
|
*/
|
|
|
|
static __isl_give isl_val *basic_set_opt_lp(
|
|
|
|
__isl_keep isl_basic_set *bset, int max, __isl_keep isl_aff *obj)
|
|
|
|
{
|
|
|
|
isl_ctx *ctx;
|
|
|
|
isl_val *res;
|
|
|
|
enum isl_lp_result lp_res;
|
|
|
|
|
|
|
|
if (!bset || !obj)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ctx = isl_aff_get_ctx(obj);
|
|
|
|
res = isl_val_alloc(ctx);
|
|
|
|
if (!res)
|
|
|
|
return NULL;
|
|
|
|
lp_res = isl_basic_set_solve_lp(bset, max, obj->v->el + 1,
|
|
|
|
obj->v->el[0], &res->n, &res->d, NULL);
|
|
|
|
if (lp_res == isl_lp_ok)
|
|
|
|
return isl_val_normalize(res);
|
|
|
|
isl_val_free(res);
|
|
|
|
if (lp_res == isl_lp_error)
|
|
|
|
return NULL;
|
|
|
|
if (lp_res == isl_lp_empty)
|
|
|
|
return isl_val_nan(ctx);
|
|
|
|
if (max)
|
|
|
|
return isl_val_infty(ctx);
|
|
|
|
else
|
|
|
|
return isl_val_neginfty(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the optimal (rational) value of "obj" over "bset", assuming
|
|
|
|
* that "obj" and "bset" have aligned parameters.
|
|
|
|
* If "max" is set, then the maximal value is computed.
|
|
|
|
* Otherwise, the minimal value is computed.
|
|
|
|
*
|
|
|
|
* Return infinity or negative infinity if the optimal value is unbounded and
|
|
|
|
* NaN if "bset" is empty.
|
|
|
|
*
|
|
|
|
* Align the divs of "bset" and "obj" and call basic_set_opt_lp.
|
|
|
|
*/
|
|
|
|
static __isl_give isl_val *isl_basic_set_opt_lp_val_aligned(
|
|
|
|
__isl_keep isl_basic_set *bset, int max, __isl_keep isl_aff *obj)
|
|
|
|
{
|
|
|
|
int *exp1 = NULL;
|
|
|
|
int *exp2 = NULL;
|
|
|
|
isl_ctx *ctx;
|
|
|
|
isl_mat *bset_div = NULL;
|
|
|
|
isl_mat *div = NULL;
|
|
|
|
isl_val *res;
|
[Polly] Update ISL to isl-0.22.1-87-gfee05a13.
The primary motivation is to fix an assertion failure in
isl_basic_map_alloc_equality:
isl_assert(ctx, room_for_con(bmap, 1), return -1);
Although the assertion does not occur anymore, I could not identify
which of ISL's commits fixed it.
Compared to the previous ISL version, Polly requires some changes for this update
* Since ISL commit
20d3574 "perform parameter alignment by modifying both arguments to function"
isl_*_gist_* and similar functions do not always align the paramter
list anymore. This caused the parameter lists in JScop files to
become out-of-sync. Since many regression tests use JScop files with
a fixed parameter list and order, we explicitly call align_params to
ensure a predictable parameter list.
* ISL changed some return types to isl_size, a typedef of (signed) int.
This caused some issues where the return type was unsigned int before:
- No overload for std::max(unsigned,isl_size)
- It cause additional 'mixed signed/unsigned comparison' warnings.
Since they do not break compilation, and sizes larger than 2^31
were never supported, I am going to fix it separately.
* With the change to isl_size, commit
57d547 "isl_*_list_size: return isl_size"
also changed the return value in case of an error from 0 to -1. This
caused undefined looping over isl_iterator since the 'end iterator'
got index -1, never reached from the 'begin iterator' with index 0.
* Some internal changes in ISL caused the number of operations to
increase when determining access ranges to determine aliasing
overlaps. In one test, this caused exceeding the default limit of
800000. The operations-limit was disabled for this test.
2020-02-11 04:51:33 +08:00
|
|
|
isl_size bset_n_div, obj_n_div;
|
2015-02-05 04:55:43 +08:00
|
|
|
|
|
|
|
if (!bset || !obj)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ctx = isl_aff_get_ctx(obj);
|
|
|
|
if (!isl_space_is_equal(bset->dim, obj->ls->dim))
|
|
|
|
isl_die(ctx, isl_error_invalid,
|
|
|
|
"spaces don't match", return NULL);
|
|
|
|
|
|
|
|
bset_n_div = isl_basic_set_dim(bset, isl_dim_div);
|
|
|
|
obj_n_div = isl_aff_dim(obj, isl_dim_div);
|
[Polly] Update ISL to isl-0.22.1-87-gfee05a13.
The primary motivation is to fix an assertion failure in
isl_basic_map_alloc_equality:
isl_assert(ctx, room_for_con(bmap, 1), return -1);
Although the assertion does not occur anymore, I could not identify
which of ISL's commits fixed it.
Compared to the previous ISL version, Polly requires some changes for this update
* Since ISL commit
20d3574 "perform parameter alignment by modifying both arguments to function"
isl_*_gist_* and similar functions do not always align the paramter
list anymore. This caused the parameter lists in JScop files to
become out-of-sync. Since many regression tests use JScop files with
a fixed parameter list and order, we explicitly call align_params to
ensure a predictable parameter list.
* ISL changed some return types to isl_size, a typedef of (signed) int.
This caused some issues where the return type was unsigned int before:
- No overload for std::max(unsigned,isl_size)
- It cause additional 'mixed signed/unsigned comparison' warnings.
Since they do not break compilation, and sizes larger than 2^31
were never supported, I am going to fix it separately.
* With the change to isl_size, commit
57d547 "isl_*_list_size: return isl_size"
also changed the return value in case of an error from 0 to -1. This
caused undefined looping over isl_iterator since the 'end iterator'
got index -1, never reached from the 'begin iterator' with index 0.
* Some internal changes in ISL caused the number of operations to
increase when determining access ranges to determine aliasing
overlaps. In one test, this caused exceeding the default limit of
800000. The operations-limit was disabled for this test.
2020-02-11 04:51:33 +08:00
|
|
|
if (bset_n_div < 0 || obj_n_div < 0)
|
|
|
|
return NULL;
|
2015-02-05 04:55:43 +08:00
|
|
|
if (bset_n_div == 0 && obj_n_div == 0)
|
|
|
|
return basic_set_opt_lp(bset, max, obj);
|
|
|
|
|
|
|
|
bset = isl_basic_set_copy(bset);
|
|
|
|
obj = isl_aff_copy(obj);
|
|
|
|
|
|
|
|
bset_div = isl_basic_set_get_divs(bset);
|
|
|
|
exp1 = isl_alloc_array(ctx, int, bset_n_div);
|
|
|
|
exp2 = isl_alloc_array(ctx, int, obj_n_div);
|
|
|
|
if (!bset_div || (bset_n_div && !exp1) || (obj_n_div && !exp2))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
div = isl_merge_divs(bset_div, obj->ls->div, exp1, exp2);
|
|
|
|
|
|
|
|
bset = isl_basic_set_expand_divs(bset, isl_mat_copy(div), exp1);
|
|
|
|
obj = isl_aff_expand_divs(obj, isl_mat_copy(div), exp2);
|
|
|
|
|
|
|
|
res = basic_set_opt_lp(bset, max, obj);
|
|
|
|
|
|
|
|
isl_mat_free(bset_div);
|
|
|
|
isl_mat_free(div);
|
|
|
|
free(exp1);
|
|
|
|
free(exp2);
|
|
|
|
isl_basic_set_free(bset);
|
|
|
|
isl_aff_free(obj);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
error:
|
|
|
|
isl_mat_free(div);
|
|
|
|
isl_mat_free(bset_div);
|
|
|
|
free(exp1);
|
|
|
|
free(exp2);
|
|
|
|
isl_basic_set_free(bset);
|
|
|
|
isl_aff_free(obj);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the optimal (rational) value of "obj" over "bset".
|
|
|
|
* If "max" is set, then the maximal value is computed.
|
|
|
|
* Otherwise, the minimal value is computed.
|
|
|
|
*
|
|
|
|
* Return infinity or negative infinity if the optimal value is unbounded and
|
|
|
|
* NaN if "bset" is empty.
|
|
|
|
*/
|
|
|
|
static __isl_give isl_val *isl_basic_set_opt_lp_val(
|
|
|
|
__isl_keep isl_basic_set *bset, int max, __isl_keep isl_aff *obj)
|
|
|
|
{
|
2017-03-10 17:17:55 +08:00
|
|
|
isl_bool equal;
|
2015-02-05 04:55:43 +08:00
|
|
|
isl_val *res;
|
|
|
|
|
|
|
|
if (!bset || !obj)
|
|
|
|
return NULL;
|
|
|
|
|
2017-03-10 17:17:55 +08:00
|
|
|
equal = isl_basic_set_space_has_equal_params(bset, obj->ls->dim);
|
|
|
|
if (equal < 0)
|
|
|
|
return NULL;
|
|
|
|
if (equal)
|
2015-02-05 04:55:43 +08:00
|
|
|
return isl_basic_set_opt_lp_val_aligned(bset, max, obj);
|
|
|
|
|
|
|
|
bset = isl_basic_set_copy(bset);
|
|
|
|
obj = isl_aff_copy(obj);
|
|
|
|
bset = isl_basic_set_align_params(bset, isl_aff_get_domain_space(obj));
|
|
|
|
obj = isl_aff_align_params(obj, isl_basic_set_get_space(bset));
|
|
|
|
|
|
|
|
res = isl_basic_set_opt_lp_val_aligned(bset, max, obj);
|
|
|
|
|
|
|
|
isl_basic_set_free(bset);
|
|
|
|
isl_aff_free(obj);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the minimal (rational) value of "obj" over "bset".
|
|
|
|
*
|
|
|
|
* Return negative infinity if the minimal value is unbounded and
|
|
|
|
* NaN if "bset" is empty.
|
|
|
|
*/
|
|
|
|
__isl_give isl_val *isl_basic_set_min_lp_val(__isl_keep isl_basic_set *bset,
|
|
|
|
__isl_keep isl_aff *obj)
|
|
|
|
{
|
|
|
|
return isl_basic_set_opt_lp_val(bset, 0, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the maximal (rational) value of "obj" over "bset".
|
|
|
|
*
|
|
|
|
* Return infinity if the maximal value is unbounded and
|
|
|
|
* NaN if "bset" is empty.
|
|
|
|
*/
|
|
|
|
__isl_give isl_val *isl_basic_set_max_lp_val(__isl_keep isl_basic_set *bset,
|
|
|
|
__isl_keep isl_aff *obj)
|
|
|
|
{
|
|
|
|
return isl_basic_set_opt_lp_val(bset, 1, obj);
|
|
|
|
}
|