X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=pip.c;h=da08d2e19ac97a1d69d1e331de680610a425cc2a;hb=63fb8a7f484648c3caa25351c8c94ac2395ec563;hp=7f84327f80e1cd068c30043a639cebbede78093b;hpb=c34923b539e2f5e80a3d61019a5fd5cef5db4f72;p=platform%2Fupstream%2Fisl.git diff --git a/pip.c b/pip.c index 7f84327..da08d2e 100644 --- a/pip.c +++ b/pip.c @@ -1,7 +1,7 @@ /* * Copyright 2008-2009 Katholieke Universiteit Leuven * - * Use of this software is governed by the GNU LGPLv2.1 license + * 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 @@ -9,14 +9,18 @@ #include #include +#include +#include +#include #include #include "isl_tab.h" -#include "isl_map_private.h" #include "isl_sample.h" #include "isl_scan.h" #include #include +#include #include +#include /* The input of this program is the same as that of the "example" program * from the PipLib distribution, except that the "big parameter column" @@ -37,15 +41,26 @@ struct options { struct isl_options *isl; unsigned verify; + unsigned format; }; -struct isl_arg options_arg[] = { -ISL_ARG_CHILD(struct options, isl, "isl", isl_options_arg, "isl options") -ISL_ARG_BOOL(struct options, verify, 'T', "verify", 0, NULL) -ISL_ARG_END +#define FORMAT_SET 0 +#define FORMAT_AFF 1 + +struct isl_arg_choice pip_format[] = { + {"set", FORMAT_SET}, + {"affine", FORMAT_AFF}, + {0} }; -ISL_ARG_DEF(options, struct options, options_arg) +ISL_ARGS_START(struct options, options_args) +ISL_ARG_CHILD(struct options, isl, "isl", &isl_options_args, "isl options") +ISL_ARG_BOOL(struct options, verify, 'T', "verify", 0, NULL) +ISL_ARG_CHOICE(struct options, format, 0, "format", + pip_format, FORMAT_SET, "output format") +ISL_ARGS_END + +ISL_ARG_DEF(options, struct options, options_args) static __isl_give isl_basic_set *set_bounds(__isl_take isl_basic_set *bset) { @@ -72,8 +87,10 @@ static __isl_give isl_basic_set *set_bounds(__isl_take isl_basic_set *bset) static struct isl_basic_set *to_parameter_domain(struct isl_basic_set *context) { - return isl_basic_set_move_dims(context, isl_dim_param, 0, isl_dim_set, 0, - isl_basic_set_dim(context, isl_dim_set)); + context = isl_basic_set_move_dims(context, isl_dim_param, 0, + isl_dim_set, 0, isl_basic_set_dim(context, isl_dim_set)); + context = isl_basic_set_params(context); + return context; } isl_basic_set *plug_in_parameters(isl_basic_set *bset, struct isl_vec *params) @@ -122,7 +139,7 @@ struct isl_vec *opt_at(struct isl_basic_set *bset, bset = plug_in_parameters(bset, params); - if (isl_basic_set_fast_is_empty(bset)) { + if (isl_basic_set_plain_is_empty(bset)) { opt = isl_vec_alloc(bset->ctx, 0); isl_basic_set_free(bset); return opt; @@ -194,7 +211,7 @@ static int scan_one(struct isl_scan_callback *callback, if (opt->size == 0) { isl_point *sample_pnt; - sample_pnt = isl_point_alloc(isl_set_get_dim(sp->empty), sample); + sample_pnt = isl_point_alloc(isl_set_get_space(sp->empty), sample); assert(isl_set_contains_point(sp->empty, sample_pnt)); isl_point_free(sample_pnt); isl_vec_free(opt); @@ -262,8 +279,9 @@ int main(int argc, char **argv) { struct isl_ctx *ctx; struct isl_basic_set *context, *bset, *copy, *context_copy; - struct isl_set *set; + struct isl_set *set = NULL; struct isl_set *empty; + isl_pw_multi_aff *pma = NULL; int neg_one; char s[1024]; int urs_parms = 0; @@ -271,21 +289,21 @@ int main(int argc, char **argv) int max = 0; int rational = 0; int n; + int nparam; struct options *options; options = options_new_with_defaults(); assert(options); argc = options_parse(options, argc, argv, ISL_ARG_ALL); - ctx = isl_ctx_alloc_with_options(options_arg, options); + ctx = isl_ctx_alloc_with_options(&options_args, options); - context = isl_basic_set_read_from_file(ctx, stdin, 0); + context = isl_basic_set_read_from_file(ctx, stdin); assert(context); n = fscanf(stdin, "%d", &neg_one); assert(n == 1); assert(neg_one == -1); - bset = isl_basic_set_read_from_file(ctx, stdin, - isl_basic_set_dim(context, isl_dim_set)); + bset = isl_basic_set_read_from_file(ctx, stdin); while (fgets(s, sizeof(s), stdin)) { if (strncasecmp(s, "Maximize", 8) == 0) @@ -301,34 +319,61 @@ int main(int argc, char **argv) } if (!urs_parms) context = isl_basic_set_intersect(context, - isl_basic_set_positive_orthant(isl_basic_set_get_dim(context))); + isl_basic_set_positive_orthant(isl_basic_set_get_space(context))); context = to_parameter_domain(context); + nparam = isl_basic_set_dim(context, isl_dim_param); + if (nparam != isl_basic_set_dim(bset, isl_dim_param)) { + int dim = isl_basic_set_dim(bset, isl_dim_set); + bset = isl_basic_set_move_dims(bset, isl_dim_param, 0, + isl_dim_set, dim - nparam, nparam); + } if (!urs_unknowns) bset = isl_basic_set_intersect(bset, - isl_basic_set_positive_orthant(isl_basic_set_get_dim(bset))); + isl_basic_set_positive_orthant(isl_basic_set_get_space(bset))); if (options->verify) { copy = isl_basic_set_copy(bset); context_copy = isl_basic_set_copy(context); } - if (max) - set = isl_basic_set_partial_lexmax(bset, context, &empty); - else - set = isl_basic_set_partial_lexmin(bset, context, &empty); + if (options->format == FORMAT_AFF) { + if (max) + pma = isl_basic_set_partial_lexmax_pw_multi_aff(bset, + context, &empty); + else + pma = isl_basic_set_partial_lexmin_pw_multi_aff(bset, + context, &empty); + } else { + if (max) + set = isl_basic_set_partial_lexmax(bset, + context, &empty); + else + set = isl_basic_set_partial_lexmin(bset, + context, &empty); + } if (options->verify) { assert(!rational); + if (options->format == FORMAT_AFF) + set = isl_set_from_pw_multi_aff(pma); check_solution(copy, context_copy, set, empty, max); + isl_set_free(set); } else { - isl_set_print(set, stdout, 0, ISL_FORMAT_ISL); - fprintf(stdout, "\n"); - fprintf(stdout, "no solution: "); - isl_set_print(empty, stdout, 0, ISL_FORMAT_ISL); - fprintf(stdout, "\n"); + isl_printer *p; + p = isl_printer_to_file(ctx, stdout); + if (options->format == FORMAT_AFF) + p = isl_printer_print_pw_multi_aff(p, pma); + else + p = isl_printer_print_set(p, set); + p = isl_printer_end_line(p); + p = isl_printer_print_str(p, "no solution: "); + p = isl_printer_print_set(p, empty); + p = isl_printer_end_line(p); + isl_printer_free(p); + isl_set_free(set); + isl_pw_multi_aff_free(pma); } - isl_set_free(set); isl_set_free(empty); isl_ctx_free(ctx);