put options in a separate isl_options structure
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 21 Oct 2009 21:39:23 +0000 (23:39 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 21 Oct 2009 21:39:23 +0000 (23:39 +0200)
Makefile.am
basis_reduction_templ.c
include/isl_ctx.h
include/isl_options.h [new file with mode: 0644]
isl_ctx.c
isl_lp.c
isl_map.c
isl_options.c [new file with mode: 0644]
isl_sample.c
isl_tab_pip.c

index f52e720..727ef2e 100644 (file)
@@ -72,6 +72,7 @@ libisl_la_SOURCES = \
        isl_mat.c \
        isl_name.c \
        isl_name.h \
+       isl_options.c \
        isl_output.c \
        isl_piplib.h \
        isl_sample.h \
@@ -153,6 +154,7 @@ pkginclude_HEADERS = \
        include/isl_mat.h \
        include/isl_map.h \
        include/isl_map_polylib.h \
+       include/isl_options.h \
        include/isl_polylib.h \
        include/isl_seq.h \
        include/isl_set.h \
index 7481798..7d6e2e7 100644 (file)
@@ -26,7 +26,7 @@ static void save_alpha(GBR_LP *lp, int first, int n, GBR_type *alpha)
  *  for Integer Programming" of Cook el al. to compute a reduced basis.
  * We use \epsilon = 1/4.
  *
- * If ctx->gbr_only_first is set, the user is only interested
+ * If ctx->opt->gbr_only_first is set, the user is only interested
  * in the first direction.  In this case we stop the basis reduction when
  * the width in the first direction becomes smaller than 2.
  */
@@ -56,6 +56,7 @@ struct isl_tab *isl_tab_compute_reduced_basis(struct isl_tab *tab)
        int fixed_saved = 0;
        int mu_fixed[2];
        int n_bounded;
+       int gbr_only_first;
 
        if (!tab)
                return NULL;
@@ -64,6 +65,7 @@ struct isl_tab *isl_tab_compute_reduced_basis(struct isl_tab *tab)
                return tab;
 
        ctx = tab->mat->ctx;
+       gbr_only_first = ctx->opt->gbr_only_first;
        dim = tab->n_var;
        B = tab->basis;
        if (!B)
@@ -228,7 +230,7 @@ struct isl_tab *isl_tab_compute_reduced_basis(struct isl_tab *tab)
                                --i;
                        } else {
                                GBR_set(F[tab->n_zero], F_new);
-                               if (ctx->gbr_only_first && GBR_lt(F[tab->n_zero], two))
+                               if (gbr_only_first && GBR_lt(F[tab->n_zero], two))
                                        break;
 
                                if (fixed) {
index a9aea29..e1e8a56 100644 (file)
@@ -5,6 +5,7 @@
 #include <stdlib.h>
 
 #include <isl_int.h>
+#include <isl_options.h>
 #include <isl_blk.h>
 #include <isl_hash.h>
 #include <isl_config.h>
@@ -55,6 +56,8 @@ struct isl_ctx {
 
        struct isl_stats        *stats;
 
+       struct isl_options      *opt;
+
        isl_int                 one;
        isl_int                 negone;
 
@@ -66,28 +69,6 @@ struct isl_ctx {
 #ifdef ISL_POLYLIB
        unsigned                MaxRays;
 #endif
-
-       #define                 ISL_LP_TAB      0
-       #define                 ISL_LP_PIP      1
-       unsigned                lp_solver;
-
-       #define                 ISL_ILP_GBR     0
-       #define                 ISL_ILP_PIP     1
-       unsigned                ilp_solver;
-
-       #define                 ISL_PIP_TAB     0
-       #define                 ISL_PIP_PIP     1
-       unsigned                pip;
-
-       #define                 ISL_CONTEXT_GBR         0
-       #define                 ISL_CONTEXT_LEXMIN      1
-       unsigned                context;
-
-       #define                 ISL_GBR_NEVER   0
-       #define                 ISL_GBR_ONCE    1
-       #define                 ISL_GBR_ALWAYS  2
-       unsigned                gbr;
-       unsigned                gbr_only_first;
 };
 typedef struct isl_ctx isl_ctx;
 
@@ -126,6 +107,9 @@ typedef struct isl_ctx isl_ctx;
 
 /* struct isl_ctx functions */
 
+struct isl_options *isl_ctx_options(isl_ctx *ctx);
+
+isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt);
 isl_ctx *isl_ctx_alloc();
 void isl_ctx_ref(struct isl_ctx *ctx);
 void isl_ctx_deref(struct isl_ctx *ctx);
diff --git a/include/isl_options.h b/include/isl_options.h
new file mode 100644 (file)
index 0000000..d9b16ae
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef ISL_OPTIONS_H
+#define ISL_OPTIONS_H
+
+#include <isl_arg.h>
+
+struct isl_options {
+       #define                 ISL_LP_TAB      0
+       #define                 ISL_LP_PIP      1
+       unsigned                lp_solver;
+
+       #define                 ISL_ILP_GBR     0
+       #define                 ISL_ILP_PIP     1
+       unsigned                ilp_solver;
+
+       #define                 ISL_PIP_TAB     0
+       #define                 ISL_PIP_PIP     1
+       unsigned                pip;
+
+       #define                 ISL_CONTEXT_GBR         0
+       #define                 ISL_CONTEXT_LEXMIN      1
+       unsigned                context;
+
+       #define                 ISL_GBR_NEVER   0
+       #define                 ISL_GBR_ONCE    1
+       #define                 ISL_GBR_ALWAYS  2
+       unsigned                gbr;
+       unsigned                gbr_only_first;
+};
+
+ISL_ARG_DECL(isl_options, struct isl_options, isl_options_arg)
+
+extern struct isl_arg isl_options_arg[];
+
+#endif
index 66e3c6b..13f9e8a 100644 (file)
--- a/isl_ctx.c
+++ b/isl_ctx.c
@@ -4,10 +4,13 @@
 #include <polylib/polylibgmp.h>
 #endif
 
-struct isl_ctx *isl_ctx_alloc()
+isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt)
 {
        struct isl_ctx *ctx = NULL;
 
+       if (!opt)
+               return NULL;
+
        ctx = isl_calloc_type(NULL, struct isl_ctx);
        if (!ctx)
                goto error;
@@ -19,6 +22,7 @@ struct isl_ctx *isl_ctx_alloc()
        if (!ctx->stats)
                goto error;
 
+       ctx->opt = opt;
        ctx->ref = 0;
 
        isl_int_init(ctx->one);
@@ -35,20 +39,21 @@ struct isl_ctx *isl_ctx_alloc()
        ctx->MaxRays = POL_NO_DUAL | POL_INTEGER;
 #endif
 
-       ctx->lp_solver = ISL_LP_TAB;
-       ctx->ilp_solver = ISL_ILP_GBR;
-       ctx->pip = ISL_PIP_TAB;
-       ctx->context = ISL_CONTEXT_GBR;
-
-       ctx->gbr = ISL_GBR_ONCE;
-       ctx->gbr_only_first = 0;
-
        return ctx;
 error:
        free(ctx);
        return NULL;
 }
 
+struct isl_ctx *isl_ctx_alloc()
+{
+       struct isl_options *opt;
+
+       opt = isl_options_new_with_defaults();
+
+       return isl_ctx_alloc_with_options(opt);
+}
+
 void isl_ctx_ref(struct isl_ctx *ctx)
 {
        ctx->ref++;
@@ -70,6 +75,14 @@ void isl_ctx_free(struct isl_ctx *ctx)
        isl_int_clear(ctx->one);
        isl_int_clear(ctx->negone);
        isl_int_clear(ctx->normalize_gcd);
+       free(ctx->opt);
        free(ctx->stats);
        free(ctx);
 }
+
+struct isl_options *isl_ctx_options(isl_ctx *ctx)
+{
+       if (!ctx)
+               return NULL;
+       return ctx->opt;
+}
index df09b75..533f20f 100644 (file)
--- a/isl_lp.c
+++ b/isl_lp.c
@@ -54,7 +54,7 @@ enum isl_lp_result isl_basic_map_solve_lp(struct isl_basic_map *bmap, int max,
        if (!bmap)
                return isl_lp_error;
 
-       switch (bmap->ctx->lp_solver) {
+       switch (bmap->ctx->opt->lp_solver) {
        case ISL_LP_PIP:
                return isl_pip_solve_lp(bmap, max, f, d, opt, opt_denom, sol);
        case ISL_LP_TAB:
index 5927b7b..583ce6e 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -3311,7 +3311,7 @@ static struct isl_map *isl_basic_map_partial_lexopt(
 {
        if (!bmap)
                goto error;
-       if (bmap->ctx->pip == ISL_PIP_PIP)
+       if (bmap->ctx->opt->pip == ISL_PIP_PIP)
                return isl_pip_basic_map_lexopt(bmap, dom, empty, max);
        else
                return isl_tab_basic_map_partial_lexopt(bmap, dom, empty, max);
diff --git a/isl_options.c b/isl_options.c
new file mode 100644 (file)
index 0000000..4cf18fb
--- /dev/null
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "isl_ctx.h"
+#include "isl_options.h"
+
+struct isl_arg_choice isl_lp_solver_choice[] = {
+       {"tab",         ISL_LP_TAB},
+#ifdef ISL_PIPLIB
+       {"pip",         ISL_LP_PIP},
+#endif
+       {0}
+};
+
+struct isl_arg_choice isl_ilp_solver_choice[] = {
+       {"gbr",         ISL_ILP_GBR},
+#ifdef ISL_PIPLIB
+       {"pip",         ISL_ILP_PIP},
+#endif
+       {0}
+};
+
+struct isl_arg_choice isl_pip_solver_choice[] = {
+       {"tab",         ISL_PIP_TAB},
+#ifdef ISL_PIPLIB
+       {"pip",         ISL_PIP_PIP},
+#endif
+       {0}
+};
+
+struct isl_arg_choice isl_pip_context_choice[] = {
+       {"gbr",         ISL_CONTEXT_GBR},
+       {"lexmin",      ISL_CONTEXT_LEXMIN},
+       {0}
+};
+
+struct isl_arg_choice isl_gbr_choice[] = {
+       {"never",       ISL_GBR_NEVER},
+       {"once",        ISL_GBR_ONCE},
+       {"always",      ISL_GBR_ALWAYS},
+       {0}
+};
+
+struct isl_arg isl_options_arg[] = {
+ISL_ARG_CHOICE(struct isl_options, lp_solver, 0, "lp-solver", \
+       isl_lp_solver_choice,   ISL_LP_TAB)
+ISL_ARG_CHOICE(struct isl_options, ilp_solver, 0, "ilp-solver", \
+       isl_ilp_solver_choice,  ISL_ILP_GBR)
+ISL_ARG_CHOICE(struct isl_options, pip, 0, "pip", \
+       isl_pip_solver_choice,  ISL_PIP_TAB)
+ISL_ARG_CHOICE(struct isl_options, context, 0, "context", \
+       isl_pip_context_choice, ISL_CONTEXT_GBR)
+ISL_ARG_CHOICE(struct isl_options, gbr, 0, "gbr", \
+       isl_gbr_choice, ISL_GBR_ONCE)
+ISL_ARG_BOOL(struct isl_options, gbr_only_first, 0, "gbr-only-first", 0)
+ISL_ARG_END
+};
+
+ISL_ARG_DEF(isl_options, struct isl_options, isl_options_arg)
index 3e5ad39..4e2cdd6 100644 (file)
@@ -370,14 +370,14 @@ static struct isl_mat *initial_basis(struct isl_tab *tab)
  *
  * The initial basis is the identity matrix.  If the range in some direction
  * contains more than one integer value, we perform basis reduction based
- * on the value of ctx->gbr
+ * on the value of ctx->opt->gbr
  *     - ISL_GBR_NEVER:        never perform basis reduction
  *     - ISL_GBR_ONCE:         only perform basis reduction the first
  *                             time such a range is encountered
  *     - ISL_GBR_ALWAYS:       always perform basis reduction when
  *                             such a range is encountered
  *
- * When ctx->gbr is set to ISL_GBR_ALWAYS, then we allow the basis
+ * When ctx->opt->gbr is set to ISL_GBR_ALWAYS, then we allow the basis
  * reduction computation to return early.  That is, as soon as it
  * finds a reasonable first direction.
  */ 
@@ -411,7 +411,7 @@ struct isl_vec *isl_tab_sample(struct isl_tab *tab)
 
        ctx = tab->mat->ctx;
        dim = tab->n_var;
-       gbr = ctx->gbr;
+       gbr = ctx->opt->gbr;
 
        if (tab->n_unbounded == tab->n_var) {
                sample = isl_tab_get_sample_value(tab);
@@ -462,17 +462,18 @@ struct isl_vec *isl_tab_sample(struct isl_tab *tab)
                                goto error;
                        if (!empty && isl_tab_sample_is_integer(tab))
                                break;
-                       if (!empty && !reduced && ctx->gbr != ISL_GBR_NEVER &&
+                       if (!empty && !reduced &&
+                           ctx->opt->gbr != ISL_GBR_NEVER &&
                            isl_int_lt(min->el[level], max->el[level])) {
                                unsigned gbr_only_first;
-                               if (ctx->gbr == ISL_GBR_ONCE)
-                                       ctx->gbr = ISL_GBR_NEVER;
+                               if (ctx->opt->gbr == ISL_GBR_ONCE)
+                                       ctx->opt->gbr = ISL_GBR_NEVER;
                                tab->n_zero = level;
-                               gbr_only_first = ctx->gbr_only_first;
-                               ctx->gbr_only_first =
-                                       ctx->gbr == ISL_GBR_ALWAYS;
+                               gbr_only_first = ctx->opt->gbr_only_first;
+                               ctx->opt->gbr_only_first =
+                                       ctx->opt->gbr == ISL_GBR_ALWAYS;
                                tab = isl_tab_compute_reduced_basis(tab);
-                               ctx->gbr_only_first = gbr_only_first;
+                               ctx->opt->gbr_only_first = gbr_only_first;
                                if (!tab || !tab->basis)
                                        goto error;
                                reduced = 1;
@@ -516,13 +517,13 @@ struct isl_vec *isl_tab_sample(struct isl_tab *tab)
        } else
                sample = isl_vec_alloc(ctx, 0);
 
-       ctx->gbr = gbr;
+       ctx->opt->gbr = gbr;
        isl_vec_free(min);
        isl_vec_free(max);
        free(snap);
        return sample;
 error:
-       ctx->gbr = gbr;
+       ctx->opt->gbr = gbr;
        isl_vec_free(min);
        isl_vec_free(max);
        free(snap);
@@ -1116,7 +1117,7 @@ static struct isl_vec *basic_set_sample(struct isl_basic_set *bset, int bounded)
        if (dim == 1)
                return interval_sample(bset);
 
-       switch (bset->ctx->ilp_solver) {
+       switch (bset->ctx->opt->ilp_solver) {
        case ISL_ILP_PIP:
                return pip_sample(bset);
        case ISL_ILP_GBR:
index 071c719..d9bb73b 100644 (file)
@@ -3174,7 +3174,7 @@ static struct isl_context *isl_context_alloc(struct isl_basic_set *dom)
        if (!dom)
                return NULL;
 
-       if (dom->ctx->context == ISL_CONTEXT_LEXMIN)
+       if (dom->ctx->opt->context == ISL_CONTEXT_LEXMIN)
                return isl_context_lex_alloc(dom);
        else
                return isl_context_gbr_alloc(dom);