Polly 19.0.0git
isl_bound.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 INRIA Saclay
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8 * 91893 Orsay, France
9 */
10
11#include <isl_ctx_private.h>
12#include <isl_map_private.h>
13#include <isl_bound.h>
14#include <isl_bernstein.h>
15#include <isl_range.h>
17#include <isl_options_private.h>
18
19/* Given a polynomial "poly" that is constant in terms
20 * of the domain variables, construct a polynomial reduction
21 * of type "type" that is equal to "poly" on "bset",
22 * with the domain projected onto the parameters.
23 */
27{
28 isl_set *dom;
31
33 dom = isl_set_from_basic_set(bset);
34 if (tight)
36 pwf = isl_pw_qpolynomial_fold_alloc(type, dom, fold);
38}
39
40/* Add the bound "pwf", which is not known to be tight,
41 * to the output of "bound".
42 */
45{
47 return isl_stat_non_null(bound->pwf);
48}
49
50/* Add the bound "pwf", which is known to be tight,
51 * to the output of "bound".
52 */
55{
56 bound->pwf_tight = isl_pw_qpolynomial_fold_fold(bound->pwf_tight, pwf);
57 return isl_stat_non_null(bound->pwf);
58}
59
60/* Given a polynomial "poly" that is constant in terms
61 * of the domain variables and the domain "bset",
62 * construct the corresponding polynomial reduction and
63 * add it to the tight bounds of "bound".
64 */
67{
69
70 pwf = isl_qpolynomial_cst_bound(bset, poly, bound->type, NULL);
71 return isl_bound_add_tight(bound, pwf);
72}
73
74/* Compute a bound on the polynomial defined over the parametric polytope
75 * using either range propagation or bernstein expansion and
76 * store the result in bound->pwf and bound->pwf_tight.
77 * Since bernstein expansion requires bounded domains, we apply
78 * range propagation on unbounded domains. Otherwise, we respect the choice
79 * of the user.
80 *
81 * If the polynomial does not depend on the set variables
82 * then the bound is equal to the polynomial and
83 * it can be added to "bound" directly.
84 */
87{
88 struct isl_bound *bound = (struct isl_bound *)user;
89 isl_ctx *ctx;
90 int bounded;
91 int degree;
92
93 if (!bset || !poly)
94 goto error;
95
97 if (degree < -1)
98 goto error;
99 if (degree <= 0)
101
103 if (ctx->opt->bound == ISL_BOUND_RANGE)
105
107 if (bounded < 0)
108 goto error;
109 if (bounded)
111 else
113error:
116 return isl_stat_error;
117}
118
121{
122 struct isl_bound *bound = (struct isl_bound *)user;
124 isl_pw_qpolynomial_fold *top_pwf_tight;
125 isl_space *space;
126 isl_morph *morph;
127 isl_stat r;
128
130
131 if (!bset)
132 goto error;
133
134 if (bset->n_eq == 0)
136
138
141
142 space = isl_morph_get_ran_space(morph);
143 space = isl_space_params(space);
144
145 top_pwf = bound->pwf;
146 top_pwf_tight = bound->pwf_tight;
147
148 space = isl_space_from_domain(space);
149 space = isl_space_add_dims(space, isl_dim_out, 1);
151 bound->type);
152 bound->pwf_tight = isl_pw_qpolynomial_fold_zero(space, bound->type);
153
155
156 morph = isl_morph_dom_params(morph);
157 morph = isl_morph_ran_params(morph);
158 morph = isl_morph_inverse(morph);
159
161 isl_morph_copy(morph));
163 bound->pwf_tight, morph);
164
165 isl_bound_add(bound, top_pwf);
166 isl_bound_add_tight(bound, top_pwf_tight);
167
168 return r;
169error:
172 return isl_stat_error;
173}
174
175/* Update bound->pwf and bound->pwf_tight with a bound
176 * of type bound->type on the polynomial "poly" over the domain "bset".
177 *
178 * If the original problem had a wrapped relation in the domain,
179 * meaning that the bound should be computed over the range
180 * of this relation, then temporarily treat the domain dimensions
181 * of this wrapped relation as parameters, compute a bound
182 * in terms of these and the original parameters,
183 * turn the parameters back into set dimensions and
184 * add the results to bound->pwf and bound->pwf_tight.
185 *
186 * Note that even though "bset" is known to live in the same space
187 * as the domain of "poly", the names of the set dimensions
188 * may be different (or missing). Make sure the naming is exactly
189 * the same before turning these dimensions into parameters
190 * to ensure that the spaces are still the same after
191 * this operation.
192 */
195{
196 struct isl_bound *bound = (struct isl_bound *)user;
197 isl_space *space;
199 isl_pw_qpolynomial_fold *top_pwf_tight;
200 isl_size nparam;
201 isl_size n_in;
202 isl_stat r;
203
204 if (!bound->wrapping)
206
207 nparam = isl_space_dim(bound->dim, isl_dim_param);
208 n_in = isl_space_dim(bound->dim, isl_dim_in);
209 if (nparam < 0 || n_in < 0)
210 goto error;
211
214
216 isl_dim_set, 0, n_in);
218 isl_dim_in, 0, n_in);
219
221 space = isl_space_params(space);
222
223 top_pwf = bound->pwf;
224 top_pwf_tight = bound->pwf_tight;
225
226 space = isl_space_from_domain(space);
227 space = isl_space_add_dims(space, isl_dim_out, 1);
229 bound->type);
230 bound->pwf_tight = isl_pw_qpolynomial_fold_zero(space, bound->type);
231
233
235 isl_space_copy(bound->dim));
236 bound->pwf_tight = isl_pw_qpolynomial_fold_reset_space(bound->pwf_tight,
237 isl_space_copy(bound->dim));
238
239 isl_bound_add(bound, top_pwf);
240 isl_bound_add_tight(bound, top_pwf_tight);
241
242 return r;
243error:
246 return isl_stat_error;
247}
248
250{
251 struct isl_bound *bound = (struct isl_bound *)user;
252 isl_stat r;
253
257 return r;
258}
259
261{
262 struct isl_bound *bound = (struct isl_bound *)user;
263 isl_stat r;
264
265 bound->bset = bset;
267 &guarded_qp, user);
269 return r;
270}
271
274{
275 struct isl_bound *bound = (struct isl_bound *)user;
276
277 if (!set || !fold)
278 goto error;
279
281
282 bound->fold = fold;
284
286 goto error;
287
290
291 return isl_stat_ok;
292error:
295 return isl_stat_error;
296}
297
300{
301 isl_size nvar;
302 struct isl_bound bound;
303 isl_bool covers;
304
305 if (!pwf)
306 return NULL;
307
309
310 bound.wrapping = isl_space_is_wrapping(bound.dim);
311 if (bound.wrapping)
312 bound.dim = isl_space_unwrap(bound.dim);
313 nvar = isl_space_dim(bound.dim, isl_dim_out);
314 if (nvar < 0)
315 bound.dim = isl_space_free(bound.dim);
316 bound.dim = isl_space_domain(bound.dim);
319
320 if (nvar == 0) {
321 if (tight)
324 }
325
327 enum isl_fold type = pwf->type;
329 if (tight)
332 }
333
335 pwf->type);
337 pwf->type);
338 bound.check_tight = !!tight;
339
341 guarded_fold, &bound) < 0)
342 goto error;
343
344 covers = isl_pw_qpolynomial_fold_covers(bound.pwf_tight, bound.pwf);
345 if (covers < 0)
346 goto error;
347
348 if (tight)
349 *tight = covers;
350
353
354 if (covers) {
356 return bound.pwf_tight;
357 }
358
359 bound.pwf = isl_pw_qpolynomial_fold_fold(bound.pwf, bound.pwf_tight);
360
361 return bound.pwf;
362error:
367 return NULL;
368}
369
373{
375
378}
379
384};
385
387{
388 struct isl_union_bound_data *data = user;
390
392 data->tight ? &data->tight : NULL);
394 data->res, pwf);
395
396 return isl_stat_ok;
397}
398
402{
403 isl_space *space;
404 struct isl_union_bound_data data = { type, 1, NULL };
405
406 if (!upwqp)
407 return NULL;
408
409 if (!tight)
410 data.tight = isl_bool_false;
411
415 &bound_pw, &data) < 0)
416 goto error;
417
419 if (tight)
420 *tight = data.tight;
421
422 return data.res;
423error:
426 return NULL;
427}
isl_stat isl_stat_non_null(void *obj)
Definition: isl_ctx.c:22
#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
int isl_size
Definition: ctx.h:96
isl_bool
Definition: ctx.h:89
@ isl_bool_false
Definition: ctx.h:91
@ isl_bool_true
Definition: ctx.h:92
isl_stat isl_stat(*) void user)
Definition: hmap.h:39
isl_stat isl_qpolynomial_bound_on_domain_bernstein(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, struct isl_bound *bound)
static isl_stat compressed_guarded_poly_bound(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, void *user)
Definition: isl_bound.c:85
static isl_stat guarded_poly_bound(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, void *user)
Definition: isl_bound.c:193
__isl_give isl_pw_qpolynomial_fold * isl_qpolynomial_cst_bound(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, enum isl_fold type, isl_bool *tight)
Definition: isl_bound.c:24
isl_stat isl_bound_add(struct isl_bound *bound, __isl_take isl_pw_qpolynomial_fold *pwf)
Definition: isl_bound.c:43
static isl_stat add_constant_poly(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, struct isl_bound *bound)
Definition: isl_bound.c:65
isl_stat isl_bound_add_tight(struct isl_bound *bound, __isl_take isl_pw_qpolynomial_fold *pwf)
Definition: isl_bound.c:53
static isl_stat guarded_qp(__isl_take isl_qpolynomial *qp, void *user)
Definition: isl_bound.c:249
__isl_give isl_union_pw_qpolynomial_fold * isl_union_pw_qpolynomial_bound(__isl_take isl_union_pw_qpolynomial *upwqp, enum isl_fold type, isl_bool *tight)
Definition: isl_bound.c:399
static isl_stat bound_pw(__isl_take isl_pw_qpolynomial *pwqp, void *user)
Definition: isl_bound.c:386
static isl_stat unwrapped_guarded_poly_bound(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, void *user)
Definition: isl_bound.c:119
__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_bound(__isl_take isl_pw_qpolynomial *pwqp, enum isl_fold type, isl_bool *tight)
Definition: isl_bound.c:370
static isl_stat guarded_fold(__isl_take isl_set *set, __isl_take isl_qpolynomial_fold *fold, void *user)
Definition: isl_bound.c:272
static isl_stat basic_guarded_fold(__isl_take isl_basic_set *bset, void *user)
Definition: isl_bound.c:260
isl_bool isl_pw_qpolynomial_fold_covers(__isl_keep isl_pw_qpolynomial_fold *pwf1, __isl_keep isl_pw_qpolynomial_fold *pwf2)
Definition: isl_fold.c:1543
__isl_give isl_basic_set * isl_basic_set_reset_space(__isl_take isl_basic_set *bset, __isl_take isl_space *space)
Definition: isl_map.c:5824
__isl_give isl_morph * isl_basic_set_full_compression(__isl_keep isl_basic_set *bset)
Definition: isl_morph.c:766
__isl_give isl_space * isl_morph_get_ran_space(__isl_keep isl_morph *morph)
Definition: isl_morph.c:226
__isl_give isl_morph * isl_morph_inverse(__isl_take isl_morph *morph)
Definition: isl_morph.c:739
__isl_give isl_morph * isl_morph_ran_params(__isl_take isl_morph *morph)
Definition: isl_morph.c:329
__isl_give isl_morph * isl_morph_dom_params(__isl_take isl_morph *morph)
Definition: isl_morph.c:306
__isl_give isl_basic_set * isl_morph_basic_set(__isl_take isl_morph *morph, __isl_take isl_basic_set *bset)
Definition: isl_morph.c:641
__isl_give isl_morph * isl_morph_copy(__isl_keep isl_morph *morph)
Definition: isl_morph.c:59
static struct isl_arg_choice bound[]
Definition: isl_options.c:39
int isl_qpolynomial_degree(__isl_keep isl_qpolynomial *poly)
__isl_give isl_qpolynomial * isl_qpolynomial_morph_domain(__isl_take isl_qpolynomial *qp, __isl_take isl_morph *morph)
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_morph_domain(__isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_morph *morph)
isl_stat isl_qpolynomial_bound_on_domain_range(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, struct isl_bound *bound)
Definition: isl_range.c:542
const char * pwqp
Definition: isl_test.c:3786
const char * poly
Definition: isl_test.c:4018
enum isl_fold type
Definition: isl_test.c:4017
const char * set
Definition: isl_test.c:1356
int tight
Definition: isl_test.c:4016
struct isl_set isl_set
Definition: map_type.h:26
struct isl_basic_set isl_basic_set
Definition: map_type.h:20
#define ISL_BOUND_RANGE
Definition: options.h:25
__isl_give isl_space * isl_pw_qpolynomial_fold_get_domain_space(__isl_keep isl_pw_qpolynomial_fold *pwf)
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_fold(__isl_take isl_pw_qpolynomial_fold *pwf1, __isl_take isl_pw_qpolynomial_fold *pwf2)
Definition: isl_fold.c:1115
__isl_null isl_qpolynomial_fold * isl_qpolynomial_fold_free(__isl_take isl_qpolynomial_fold *fold)
Definition: isl_fold.c:1035
__isl_give isl_union_pw_qpolynomial_fold * isl_union_pw_qpolynomial_fold_zero(__isl_take isl_space *space, enum isl_fold type)
isl_stat isl_pw_qpolynomial_fold_foreach_lifted_piece(__isl_keep isl_pw_qpolynomial_fold *pwf, isl_stat(*fn)(__isl_take isl_set *set, __isl_take isl_qpolynomial_fold *fold, void *user), void *user)
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_reset_space(__isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_space *space)
isl_stat isl_qpolynomial_fold_foreach_qpolynomial(__isl_keep isl_qpolynomial_fold *fold, isl_stat(*fn)(__isl_take isl_qpolynomial *qp, void *user), void *user)
Definition: isl_fold.c:1695
__isl_give isl_qpolynomial * isl_qpolynomial_move_dims(__isl_take isl_qpolynomial *qp, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n)
__isl_give isl_space * isl_qpolynomial_get_domain_space(__isl_keep isl_qpolynomial *qp)
__isl_null isl_qpolynomial * isl_qpolynomial_free(__isl_take isl_qpolynomial *qp)
isl_stat isl_qpolynomial_as_polynomial_on_domain(__isl_keep isl_qpolynomial *qp, __isl_keep isl_basic_set *bset, isl_stat(*fn)(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, void *user), void *user)
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_alloc(enum isl_fold type, __isl_take isl_set *set, __isl_take isl_qpolynomial_fold *fold)
__isl_give isl_qpolynomial_fold * isl_qpolynomial_fold_alloc(enum isl_fold type, __isl_take isl_qpolynomial *qp)
Definition: isl_fold.c:989
__isl_null isl_union_pw_qpolynomial_fold * isl_union_pw_qpolynomial_fold_free(__isl_take isl_union_pw_qpolynomial_fold *upwf)
isl_bool isl_pw_qpolynomial_fold_is_zero(__isl_keep isl_pw_qpolynomial_fold *pwf)
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_project_domain_on_params(__isl_take isl_pw_qpolynomial_fold *pwf)
__isl_null isl_union_pw_qpolynomial * isl_union_pw_qpolynomial_free(__isl_take isl_union_pw_qpolynomial *upwqp)
isl_stat isl_union_pw_qpolynomial_foreach_pw_qpolynomial(__isl_keep isl_union_pw_qpolynomial *upwqp, isl_stat(*fn)(__isl_take isl_pw_qpolynomial *pwqp, void *user), void *user)
__isl_null isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_free(__isl_take isl_pw_qpolynomial_fold *pwf)
__isl_give isl_union_pw_qpolynomial_fold * isl_union_pw_qpolynomial_fold_fold_pw_qpolynomial_fold(__isl_take isl_union_pw_qpolynomial_fold *upwqp, __isl_take isl_pw_qpolynomial_fold *pwqp)
Definition: isl_fold.c:1188
__isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_fold_zero(__isl_take isl_space *space, enum isl_fold type)
__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_space * isl_union_pw_qpolynomial_get_space(__isl_keep isl_union_pw_qpolynomial *upwqp)
enum isl_fold isl_qpolynomial_fold_get_type(__isl_keep isl_qpolynomial_fold *fold)
Definition: isl_fold.c:1632
struct isl_union_pw_qpolynomial_fold isl_union_pw_qpolynomial_fold
struct isl_union_pw_qpolynomial isl_union_pw_qpolynomial
isl_fold
__isl_export __isl_give isl_basic_set * isl_basic_set_detect_equalities(__isl_take isl_basic_set *bset)
__isl_give isl_set * isl_set_make_disjoint(__isl_take isl_set *set)
__isl_give isl_space * isl_basic_set_get_space(__isl_keep isl_basic_set *bset)
Definition: isl_map.c:421
__isl_null isl_basic_set * isl_basic_set_free(__isl_take isl_basic_set *bset)
Definition: isl_map.c:1523
isl_bool isl_basic_set_is_bounded(__isl_keep isl_basic_set *bset)
__isl_null isl_set * isl_set_free(__isl_take isl_set *set)
Definition: isl_map.c:3513
__isl_give isl_basic_set * isl_basic_set_move_dims(__isl_take isl_basic_set *bset, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n)
Definition: isl_map.c:4311
__isl_export isl_stat isl_set_foreach_basic_set(__isl_keep isl_set *set, isl_stat(*fn)(__isl_take isl_basic_set *bset, void *user), void *user)
Definition: isl_map.c:11277
isl_ctx * isl_basic_set_get_ctx(__isl_keep isl_basic_set *bset)
Definition: isl_map.c:386
__isl_constructor __isl_give isl_set * isl_set_from_basic_set(__isl_take isl_basic_set *bset)
Definition: isl_map.c:3482
__isl_null isl_space * isl_space_free(__isl_take isl_space *space)
Definition: isl_space.c:445
__isl_give isl_space * isl_space_from_domain(__isl_take isl_space *space)
Definition: isl_space.c:2148
__isl_export __isl_give isl_space * isl_space_params(__isl_take isl_space *space)
Definition: isl_space.c:2211
__isl_give isl_space * isl_space_copy(__isl_keep isl_space *space)
Definition: isl_space.c:436
__isl_export isl_bool isl_space_is_wrapping(__isl_keep isl_space *space)
Definition: isl_space.c:2775
__isl_export __isl_give isl_space * isl_space_unwrap(__isl_take isl_space *space)
Definition: isl_space.c:2857
isl_size isl_space_dim(__isl_keep isl_space *space, enum isl_dim_type type)
Definition: isl_space.c:340
__isl_give isl_space * isl_space_add_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned n)
Definition: isl_space.c:1229
__isl_export __isl_give isl_space * isl_space_domain(__isl_take isl_space *space)
Definition: isl_space.c:2138
@ isl_dim_param
Definition: space_type.h:15
@ isl_dim_in
Definition: space_type.h:16
@ isl_dim_set
Definition: space_type.h:18
@ isl_dim_out
Definition: space_type.h:17
isl_basic_set * bset
Definition: isl_bound.h:12
isl_pw_qpolynomial_fold * pwf
Definition: isl_bound.h:16
isl_qpolynomial_fold * fold
Definition: isl_bound.h:13
struct isl_options * opt
isl_union_pw_qpolynomial_fold * res
Definition: isl_bound.c:383
enum isl_fold type
Definition: isl_bound.c:381