isl_tab: drop isl_ctx argument where not absolutely required
[platform/upstream/isl.git] / isl_lp.c
1 #include "isl_ctx.h"
2 #include "isl_lp.h"
3 #include "isl_lp_piplib.h"
4 #include "isl_tab.h"
5 #include "isl_map_private.h"
6
7 enum isl_lp_result isl_tab_solve_lp(struct isl_basic_map *bmap, int maximize,
8                                       isl_int *f, isl_int denom, isl_int *opt,
9                                       isl_int *opt_denom)
10 {
11         struct isl_tab *tab;
12         enum isl_lp_result res;
13         unsigned dim = isl_basic_map_total_dim(bmap);
14
15         if (maximize)
16                 isl_seq_neg(f, f, 1 + dim);
17
18         bmap = isl_basic_map_gauss(bmap, NULL);
19         tab = isl_tab_from_basic_map(bmap);
20         res = isl_tab_min(tab, f, bmap->ctx->one, opt, opt_denom, 0);
21         isl_tab_free(tab);
22
23         if (maximize)
24                 isl_seq_neg(f, f, 1 + dim);
25
26         return res;
27 }
28
29 /* Given a basic map "bmap" and an affine combination of the variables "f"
30  * with denominator "denom", set *opt/*opt_denom to the minimal
31  * (or maximal if "maximize" is true) value attained by f/d over "bmap",
32  * assuming the basic map is not empty and the expression cannot attain
33  * arbitrarily small (or large) values.
34  * If opt_denom is NULL, then *opt is rounded up (or down)
35  * to the nearest integer.
36  * The return value reflects the nature of the result (empty, unbounded,
37  * minmimal or maximal value returned in *opt).
38  */
39 enum isl_lp_result isl_solve_lp(struct isl_basic_map *bmap, int maximize,
40                                       isl_int *f, isl_int d, isl_int *opt,
41                                       isl_int *opt_denom)
42 {
43         if (!bmap)
44                 return isl_lp_error;
45
46         switch (bmap->ctx->lp_solver) {
47         case ISL_LP_PIP:
48                 return isl_pip_solve_lp(bmap, maximize, f, d, opt, opt_denom);
49         case ISL_LP_TAB:
50                 return isl_tab_solve_lp(bmap, maximize, f, d, opt, opt_denom);
51         default:
52                 return isl_lp_error;
53         }
54 }