Polly 20.0.0git
bound.c
Go to the documentation of this file.
1#include <assert.h>
2#include <isl/stream.h>
3#include <isl_map_private.h>
4#include <isl/polynomial.h>
5#include <isl_scan.h>
6#include <isl/val.h>
7#include <isl/options.h>
8
11 unsigned verify;
14};
15
16ISL_ARGS_START(struct bound_options, bound_options_args)
17ISL_ARG_CHILD(struct bound_options, isl, "isl", &isl_options_args,
18 "isl options")
19ISL_ARG_BOOL(struct bound_options, verify, 'T', "verify", 0, NULL)
20ISL_ARG_BOOL(struct bound_options, print_all, 'A', "print-all", 0, NULL)
21ISL_ARG_BOOL(struct bound_options, continue_on_error, '\0', "continue-on-error", 0, NULL)
23
24ISL_ARG_DEF(bound_options, struct bound_options, bound_options_args)
25
27{
28 isl_size nparam;
29 int i, r;
30 isl_point *pt, *pt2;
31 isl_set *box;
32
33 nparam = isl_set_dim(set, isl_dim_param);
34 if (nparam < 0)
35 return isl_set_free(set);
36 r = nparam >= 8 ? 5 : nparam >= 5 ? 15 : 50;
37
39 pt2 = isl_point_copy(pt);
40
41 for (i = 0; i < nparam; ++i) {
42 pt = isl_point_add_ui(pt, isl_dim_param, i, r);
43 pt2 = isl_point_sub_ui(pt2, isl_dim_param, i, r);
44 }
45
46 box = isl_set_box_from_points(pt, pt2);
47
48 return isl_set_intersect(set, box);
49}
50
53 int stride;
54 int n;
55 int exact;
56 int error;
57
60};
61
63{
64 int i;
65 isl_size nparam;
66 struct verify_point_bound *vpb = (struct verify_point_bound *) user;
67 isl_val *v;
68 isl_ctx *ctx;
70 isl_val *bound = NULL;
71 isl_val *opt = NULL;
72 isl_set *dom = NULL;
74 const char *minmax;
75 isl_bool bounded;
76 int sign;
77 int ok;
78 FILE *out = vpb->options->print_all ? stdout : stderr;
79
80 vpb->n--;
81
82 if (1) {
83 minmax = "ub";
84 sign = 1;
85 } else {
86 minmax = "lb";
87 sign = -1;
88 }
89
90 ctx = isl_point_get_ctx(pnt);
91 p = isl_printer_to_file(ctx, out);
92
94
96 if (nparam < 0)
98 for (i = 0; i < nparam; ++i) {
101 }
102
105 isl_point_copy(pnt));
106
108 bounded = isl_set_is_bounded(dom);
109
110 if (bounded < 0)
111 goto error;
112
113 if (!bounded)
117 else if (sign > 0)
119 else
121
122 if (vpb->exact && bounded)
123 ok = isl_val_eq(opt, bound);
124 else if (sign > 0)
125 ok = isl_val_le(opt, bound);
126 else
127 ok = isl_val_le(bound, opt);
128 if (ok < 0)
129 goto error;
130
131 if (vpb->options->print_all || !ok) {
132 p = isl_printer_print_str(p, minmax);
133 p = isl_printer_print_str(p, "(");
134 for (i = 0; i < nparam; ++i) {
135 if (i)
136 p = isl_printer_print_str(p, ", ");
139 isl_val_free(v);
140 }
141 p = isl_printer_print_str(p, ") = ");
143 p = isl_printer_print_str(p, ", ");
144 p = isl_printer_print_str(p, bounded ? "opt" : "sample");
145 p = isl_printer_print_str(p, " = ");
146 p = isl_printer_print_val(p, opt);
147 if (ok)
148 p = isl_printer_print_str(p, ". OK");
149 else
150 p = isl_printer_print_str(p, ". NOT OK");
152 } else if ((vpb->n % vpb->stride) == 0) {
153 p = isl_printer_print_str(p, "o");
155 }
156
157 if (0) {
158error:
159 ok = 0;
160 }
161
164 isl_val_free(opt);
165 isl_point_free(pnt);
166 isl_set_free(dom);
167
169
170 if (!ok)
171 vpb->error = 1;
172
173 if (vpb->options->continue_on_error)
174 ok = 1;
175
176 return (vpb->n >= 1 && ok) ? isl_stat_ok : isl_stat_error;
177}
178
181 struct bound_options *options)
182{
183 struct verify_point_bound vpb;
184 isl_int count, max;
185 isl_set *dom;
187 int i, r, n;
188
193
195 isl_int_init(max);
196
197 isl_int_set_si(max, 200);
198 r = isl_set_count_upto(context, max, &count);
199 assert(r >= 0);
201
202 isl_int_clear(max);
204
205 vpb.options = options;
206 vpb.pwf = pwf;
207 vpb.bound = bound;
208 vpb.n = n;
209 vpb.stride = n > 70 ? 1 + (n + 1)/70 : 1;
210 vpb.error = 0;
211 vpb.exact = exact;
212
213 if (!options->print_all) {
214 for (i = 0; i < vpb.n; i += vpb.stride)
215 printf(".");
216 printf("\r");
217 fflush(stdout);
218 }
219
221
223 isl_set_free(dom);
226
227 if (!options->print_all)
228 printf("\n");
229
230 if (vpb.error) {
231 fprintf(stderr, "Check failed !\n");
232 return -1;
233 }
234
235 return 0;
236}
237
238int main(int argc, char **argv)
239{
240 isl_ctx *ctx;
243 isl_stream *s;
244 struct isl_obj obj;
245 struct bound_options *options;
246 isl_bool exact;
247 int r = 0;
248
249 options = bound_options_new_with_defaults();
251 argc = bound_options_parse(options, argc, argv, ISL_ARG_ALL);
252
253 ctx = isl_ctx_alloc_with_options(&bound_options_args, options);
254
255 s = isl_stream_new_file(ctx, stdin);
257 if (obj.type == isl_obj_pw_qpolynomial)
259 obj.v);
260 else if (obj.type == isl_obj_pw_qpolynomial_fold)
261 pwf = obj.v;
262 else {
263 obj.type->free(obj.v);
264 isl_die(ctx, isl_error_invalid, "invalid input", goto error);
265 }
266
267 if (options->verify)
269
270 pwf = isl_pw_qpolynomial_fold_bound(pwf, &exact);
272
273 if (options->verify) {
274 r = check_solution(copy, pwf, exact, options);
275 } else {
276 if (!exact)
277 printf("# NOT exact\n");
278 isl_pw_qpolynomial_fold_print(pwf, stdout, 0);
279 fprintf(stdout, "\n");
281 }
282
283error:
285
286 isl_ctx_free(ctx);
287
288 return r;
289}
#define ISL_ARG_DEF(prefix, st, args)
Definition: arg.h:302
#define ISL_ARG_BOOL(st, f, s, l, d, h)
Definition: arg.h:182
#define ISL_ARG_CHILD(st, f, l, c, h)
Definition: arg.h:264
#define ISL_ARG_ALL
Definition: arg.h:288
#define ISL_ARGS_START(s, name)
Definition: arg.h:113
#define ISL_ARGS_END
Definition: arg.h:117
static int check_solution(__isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_pw_qpolynomial_fold *bound, int exact, struct bound_options *options)
Definition: bound.c:179
static isl_stat verify_point(__isl_take isl_point *pnt, void *user)
Definition: bound.c:62
A()
isl_ctx * isl_ctx_alloc_with_options(struct isl_args *args, __isl_take void *opt)
#define __isl_take
Definition: ctx.h:22
isl_stat
Definition: ctx.h:84
@ isl_stat_error
Definition: ctx.h:85
@ isl_stat_ok
Definition: ctx.h:86
#define __isl_give
Definition: ctx.h:19
#define isl_die(ctx, errno, msg, code)
Definition: ctx.h:137
@ isl_error_invalid
Definition: ctx.h:80
int isl_size
Definition: ctx.h:96
isl_bool
Definition: ctx.h:89
void isl_ctx_free(isl_ctx *ctx)
Definition: isl_ctx.c:288
isl_stat isl_stat(*) void user)
Definition: hmap.h:39
static int all(int *con, unsigned len, int status)
Definition: isl_coalesce.c:163
static int count(int *con, unsigned len, int status)
Definition: isl_coalesce.c:152
static __isl_give isl_basic_set * set_bounds(__isl_keep isl_set *set, int dim)
#define isl_int_get_si(r)
Definition: isl_int_gmp.h:18
#define isl_int_set_si(r, i)
Definition: isl_int_gmp.h:15
#define isl_int_init(i)
Definition: isl_int_gmp.h:11
#define isl_int_clear(i)
Definition: isl_int_gmp.h:12
int isl_set_count_upto(__isl_keep isl_set *set, isl_int max, isl_int *count)
Definition: isl_scan.c:278
static struct isl_arg_choice bound[]
Definition: isl_options.c:39
const char * set
Definition: isl_test.c:1356
const char * p
Definition: isl_test.c:8643
const char * context
Definition: isl_test.c:1784
const char * obj
Definition: isl_test.c:3316
#define assert(exp)
struct isl_set isl_set
Definition: map_type.h:26
These are automatically generated checked C++ bindings for isl.
Definition: ISLTools.h:45
#define isl_obj_pw_qpolynomial_fold
Definition: obj.h:43
#define isl_obj_pw_qpolynomial
Definition: obj.h:39
__isl_give isl_point * isl_point_copy(__isl_keep isl_point *pnt)
Definition: isl_point.c:141
__isl_null isl_point * isl_point_free(__isl_take isl_point *pnt)
Definition: isl_point.c:150
__isl_give isl_point * isl_point_add_ui(__isl_take isl_point *pnt, enum isl_dim_type type, int pos, unsigned val)
Definition: isl_point.c:502
__isl_give isl_point * isl_point_sub_ui(__isl_take isl_point *pnt, enum isl_dim_type type, int pos, unsigned val)
Definition: isl_point.c:530
isl_ctx * isl_point_get_ctx(__isl_keep isl_point *pnt)
Definition: isl_point.c:32
__isl_give isl_val * isl_point_get_coordinate_val(__isl_keep isl_point *pnt, enum isl_dim_type type, int pos)
__isl_give isl_val * isl_pw_qpolynomial_fold_min(__isl_take isl_pw_qpolynomial_fold *pwf)
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_fix_val(__isl_take isl_pw_qpolynomial_fold *pwf, enum isl_dim_type type, unsigned n, __isl_take isl_val *v)
isl_size isl_pw_qpolynomial_fold_dim(__isl_keep isl_pw_qpolynomial_fold *pwf, enum isl_dim_type type)
__isl_give isl_set * isl_pw_qpolynomial_fold_domain(__isl_take isl_pw_qpolynomial_fold *pwf)
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_copy(__isl_keep isl_pw_qpolynomial_fold *pwf)
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_coalesce(__isl_take isl_pw_qpolynomial_fold *pwf)
void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold *pwf, FILE *out, unsigned output_format)
Definition: isl_output.c:2359
__isl_null isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_free(__isl_take isl_pw_qpolynomial_fold *pwf)
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_bound(__isl_take isl_pw_qpolynomial_fold *pwf, isl_bool *tight)
Definition: isl_bound.c:298
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_from_pw_qpolynomial(enum isl_fold type, __isl_take isl_pw_qpolynomial *pwqp)
Definition: isl_fold.c:1254
__isl_give isl_val * isl_pw_qpolynomial_fold_eval(__isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_point *pnt)
__isl_give isl_val * isl_pw_qpolynomial_fold_max(__isl_take isl_pw_qpolynomial_fold *pwf)
@ isl_fold_max
__isl_null isl_printer * isl_printer_free(__isl_take isl_printer *printer)
Definition: isl_printer.c:269
__isl_give isl_printer * isl_printer_flush(__isl_take isl_printer *p)
Definition: isl_printer.c:690
__isl_give isl_printer * isl_printer_to_file(isl_ctx *ctx, FILE *file)
Definition: isl_printer.c:217
__isl_give isl_printer * isl_printer_print_str(__isl_take isl_printer *p, const char *s)
Definition: isl_printer.c:617
__isl_give isl_printer * isl_printer_end_line(__isl_take isl_printer *p)
Definition: isl_printer.c:667
__isl_export __isl_give isl_point * isl_set_sample_point(__isl_take isl_set *set)
Definition: isl_sample.c:1312
__isl_give isl_set * isl_set_remove_divs(__isl_take isl_set *set)
Definition: isl_map.c:2617
__isl_give isl_set * isl_set_box_from_points(__isl_take isl_point *pnt1, __isl_take isl_point *pnt2)
Definition: isl_point.c:810
__isl_null isl_set * isl_set_free(__isl_take isl_set *set)
Definition: isl_map.c:3513
__isl_give isl_set * isl_set_copy(__isl_keep isl_set *set)
Definition: isl_map.c:1470
__isl_export isl_stat isl_set_foreach_point(__isl_keep isl_set *set, isl_stat(*fn)(__isl_take isl_point *pnt, void *user), void *user)
Definition: isl_point.c:576
isl_size isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type)
Definition: isl_map.c:129
isl_bool isl_set_is_bounded(__isl_keep isl_set *set)
__isl_export __isl_give isl_set * isl_set_intersect(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition: isl_map.c:3965
__isl_export __isl_give isl_set * isl_set_params(__isl_take isl_set *set)
Definition: isl_map.c:5948
@ isl_dim_param
Definition: space_type.h:15
struct isl_obj isl_stream_read_obj(__isl_keep isl_stream *s)
Definition: isl_input.c:3135
__isl_give isl_stream * isl_stream_new_file(isl_ctx *ctx, FILE *file)
Definition: isl_stream.c:219
void isl_stream_free(__isl_take isl_stream *s)
Definition: isl_stream.c:805
unsigned verify
Definition: bound.c:11
int print_all
Definition: bound.c:12
int continue_on_error
Definition: bound.c:13
struct isl_options * isl
Definition: bound.c:10
Definition: obj.h:48
unsigned verify
Definition: pip.c:43
isl_pw_qpolynomial_fold * bound
Definition: bound.c:59
struct bound_options * options
Definition: bound.c:52
isl_pw_qpolynomial_fold * pwf
Definition: bound.c:58
__isl_give isl_printer * isl_printer_print_val(__isl_take isl_printer *p, __isl_keep isl_val *v)
Definition: isl_val.c:1471
__isl_null isl_val * isl_val_free(__isl_take isl_val *v)
Definition: isl_val.c:263
__isl_export isl_bool isl_val_eq(__isl_keep isl_val *v1, __isl_keep isl_val *v2)
Definition: isl_val.c:1421
__isl_export isl_bool isl_val_le(__isl_keep isl_val *v1, __isl_keep isl_val *v2)
Definition: isl_val.c:1350
n
Definition: youcefn.c:8