Polly 23.0.0git
isl_ast_build_expr.c
Go to the documentation of this file.
1/*
2 * Copyright 2012-2014 Ecole Normale Superieure
3 * Copyright 2014 INRIA Rocquencourt
4 *
5 * Use of this software is governed by the MIT license
6 *
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
9 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
10 * B.P. 105 - 78153 Le Chesnay, France
11 */
12
13#include <isl/id.h>
14#include <isl/space.h>
15#include <isl/constraint.h>
16#include <isl/ilp.h>
17#include <isl/val.h>
18#include <isl_ast_build_expr.h>
19#include <isl_ast_private.h>
21#include <isl_sort.h>
22
23/* Compute the "opposite" of the (numerator of the) argument of a div
24 * with denominator "d".
25 *
26 * In particular, compute
27 *
28 * -aff + (d - 1)
29 */
39
40/* Internal data structure used inside isl_ast_expr_add_term.
41 * The domain of "build" is used to simplify the expressions.
42 * "build" needs to be set by the caller of isl_ast_expr_add_term.
43 * "ls" is the domain local space of the affine expression
44 * of which a term is being added.
45 * "cst" is the constant term of the expression in which the added term
46 * appears. It may be modified by isl_ast_expr_add_term.
47 *
48 * "v" is the coefficient of the term that is being constructed and
49 * is set internally by isl_ast_expr_add_term.
50 */
57
58/* Given the numerator "aff" of the argument of an integer division
59 * with denominator "d", check if it can be made non-negative over
60 * data->build->domain by stealing part of the constant term of
61 * the expression in which the integer division appears.
62 *
63 * In particular, the outer expression is of the form
64 *
65 * v * floor(aff/d) + cst
66 *
67 * We already know that "aff" itself may attain negative values.
68 * Here we check if aff + d*floor(cst/v) is non-negative, such
69 * that we could rewrite the expression to
70 *
71 * v * floor((aff + d*floor(cst/v))/d) + cst - v*floor(cst/v)
72 *
73 * Note that aff + d*floor(cst/v) can only possibly be non-negative
74 * if data->cst and data->v have the same sign.
75 * Similarly, if floor(cst/v) is zero, then there is no point in
76 * checking again.
77 */
80{
81 isl_aff *shifted;
82 isl_val *shift;
83 isl_bool is_zero;
84 isl_bool non_neg;
85
86 if (isl_val_sgn(data->cst) != isl_val_sgn(data->v))
87 return isl_bool_false;
88
89 shift = isl_val_div(isl_val_copy(data->cst), isl_val_copy(data->v));
90 shift = isl_val_floor(shift);
91 is_zero = isl_val_is_zero(shift);
92 if (is_zero < 0 || is_zero) {
93 isl_val_free(shift);
94 return isl_bool_not(is_zero);
95 }
96 shift = isl_val_mul(shift, isl_val_copy(d));
97 shifted = isl_aff_copy(aff);
98 shifted = isl_aff_add_constant_val(shifted, shift);
99 non_neg = isl_ast_build_aff_is_nonneg(data->build, shifted);
100 isl_aff_free(shifted);
101
102 return non_neg;
103}
104
105/* Given the numerator "aff" of the argument of an integer division
106 * with denominator "d", steal part of the constant term of
107 * the expression in which the integer division appears to make it
108 * non-negative over data->build->domain.
109 *
110 * In particular, the outer expression is of the form
111 *
112 * v * floor(aff/d) + cst
113 *
114 * We know that "aff" itself may attain negative values,
115 * but that aff + d*floor(cst/v) is non-negative.
116 * Find the minimal positive value that we need to add to "aff"
117 * to make it positive and adjust data->cst accordingly.
118 * That is, compute the minimal value "m" of "aff" over
119 * data->build->domain and take
120 *
121 * s = ceil(-m/d)
122 *
123 * such that
124 *
125 * aff + d * s >= 0
126 *
127 * and rewrite the expression to
128 *
129 * v * floor((aff + s*d)/d) + (cst - v*s)
130 */
133{
135 isl_val *shift, *t;
136
138 shift = isl_set_min_val(domain, aff);
140
141 shift = isl_val_neg(shift);
142 shift = isl_val_div(shift, isl_val_copy(d));
143 shift = isl_val_ceil(shift);
144
145 t = isl_val_copy(shift);
146 t = isl_val_mul(t, isl_val_copy(data->v));
147 data->cst = isl_val_sub(data->cst, t);
148
149 shift = isl_val_mul(shift, isl_val_copy(d));
150 return isl_aff_add_constant_val(aff, shift);
151}
152
153/* Construct an expression representing the binary operation "type"
154 * (some division or modulo) applied to the expressions
155 * constructed from "aff" and "v".
156 */
160{
161 isl_ast_expr *expr1, *expr2;
162
163 expr1 = isl_ast_expr_from_aff(aff, build);
164 expr2 = isl_ast_expr_from_val(v);
165 return isl_ast_expr_alloc_binary(type, expr1, expr2);
166}
167
168/* Create an isl_ast_expr evaluating the div at position "pos" in data->ls.
169 * The result is simplified in terms of data->build->domain.
170 * This function may change (the sign of) data->v.
171 *
172 * data->ls is known to be non-NULL.
173 *
174 * Let the div be of the form floor(e/d).
175 * If the ast_build_prefer_pdiv option is set then we check if "e"
176 * is non-negative, so that we can generate
177 *
178 * (pdiv_q, expr(e), expr(d))
179 *
180 * instead of
181 *
182 * (fdiv_q, expr(e), expr(d))
183 *
184 * If the ast_build_prefer_pdiv option is set and
185 * if "e" is not non-negative, then we check if "-e + d - 1" is non-negative.
186 * If so, we can rewrite
187 *
188 * floor(e/d) = -ceil(-e/d) = -floor((-e + d - 1)/d)
189 *
190 * and still use pdiv_q, while changing the sign of data->v.
191 *
192 * Otherwise, we check if
193 *
194 * e + d*floor(cst/v)
195 *
196 * is non-negative and if so, replace floor(e/d) by
197 *
198 * floor((e + s*d)/d) - s
199 *
200 * with s the minimal shift that makes the argument non-negative.
201 */
203 int pos)
204{
205 isl_ctx *ctx = isl_local_space_get_ctx(data->ls);
206 isl_aff *aff;
207 isl_val *d;
209
213
216 isl_bool non_neg;
217 non_neg = isl_ast_build_aff_is_nonneg(data->build, aff);
218 if (non_neg >= 0 && !non_neg) {
220 isl_val_copy(d));
221 non_neg = isl_ast_build_aff_is_nonneg(data->build, opp);
222 if (non_neg >= 0 && non_neg) {
223 data->v = isl_val_neg(data->v);
225 aff = opp;
226 } else
227 isl_aff_free(opp);
228 }
229 if (non_neg >= 0 && !non_neg) {
230 non_neg = is_non_neg_after_stealing(aff, d, data);
231 if (non_neg >= 0 && non_neg)
232 aff = steal_from_cst(aff, d, data);
233 }
234 if (non_neg < 0)
236 else if (non_neg)
238 }
239
240 return div_mod(type, aff, d, data->build);
241}
242
243/* Create an isl_ast_expr evaluating the specified dimension of data->ls.
244 * The result is simplified in terms of data->build->domain.
245 * This function may change (the sign of) data->v.
246 *
247 * The isl_ast_expr is constructed based on the type of the dimension.
248 * - divs are constructed by var_div
249 * - set variables are constructed from the iterator isl_ids in data->build
250 * - parameters are constructed from the isl_ids in data->ls
251 */
253 enum isl_dim_type type, int pos)
254{
255 isl_ctx *ctx = isl_local_space_get_ctx(data->ls);
256 isl_id *id;
257
258 if (type == isl_dim_div)
259 return var_div(data, pos);
260
261 if (type == isl_dim_set) {
263 return isl_ast_expr_from_id(id);
264 }
265
267 isl_die(ctx, isl_error_internal, "unnamed dimension",
268 return NULL);
270 return isl_ast_expr_from_id(id);
271}
272
273/* Does "expr" represent the zero integer?
274 */
276{
277 if (!expr)
278 return isl_bool_error;
279 if (expr->type != isl_ast_expr_int)
280 return isl_bool_false;
281 return isl_val_is_zero(expr->u.v);
282}
283
284/* Create an expression representing the sum of "expr1" and "expr2",
285 * provided neither of the two expressions is identically zero.
286 */
289{
290 if (!expr1 || !expr2)
291 goto error;
292
293 if (ast_expr_is_zero(expr1)) {
294 isl_ast_expr_free(expr1);
295 return expr2;
296 }
297
298 if (ast_expr_is_zero(expr2)) {
299 isl_ast_expr_free(expr2);
300 return expr1;
301 }
302
303 return isl_ast_expr_add(expr1, expr2);
304error:
305 isl_ast_expr_free(expr1);
306 isl_ast_expr_free(expr2);
307 return NULL;
308}
309
310/* Subtract expr2 from expr1.
311 *
312 * If expr2 is zero, we simply return expr1.
313 * If expr1 is zero, we return
314 *
315 * (isl_ast_expr_op_minus, expr2)
316 *
317 * Otherwise, we return
318 *
319 * (isl_ast_expr_op_sub, expr1, expr2)
320 */
323{
324 if (!expr1 || !expr2)
325 goto error;
326
327 if (ast_expr_is_zero(expr2)) {
328 isl_ast_expr_free(expr2);
329 return expr1;
330 }
331
332 if (ast_expr_is_zero(expr1)) {
333 isl_ast_expr_free(expr1);
334 return isl_ast_expr_neg(expr2);
335 }
336
337 return isl_ast_expr_sub(expr1, expr2);
338error:
339 isl_ast_expr_free(expr1);
340 isl_ast_expr_free(expr2);
341 return NULL;
342}
343
344/* Return an isl_ast_expr that represents
345 *
346 * v * (aff mod d)
347 *
348 * v is assumed to be non-negative.
349 * The result is simplified in terms of build->domain.
350 */
354{
355 isl_ast_expr *expr;
356 isl_ast_expr *c;
357
358 if (!aff)
359 return NULL;
360
362 isl_aff_copy(aff), isl_val_copy(d), build);
363
364 if (!isl_val_is_one(v)) {
366 expr = isl_ast_expr_mul(c, expr);
367 }
368
369 return expr;
370}
371
372/* Create an isl_ast_expr that scales "expr" by "v".
373 *
374 * If v is 1, we simply return expr.
375 * If v is -1, we return
376 *
377 * (isl_ast_expr_op_minus, expr)
378 *
379 * Otherwise, we return
380 *
381 * (isl_ast_expr_op_mul, expr(v), expr)
382 */
385{
386 isl_ast_expr *c;
387
388 if (!expr || !v)
389 goto error;
390 if (isl_val_is_one(v)) {
391 isl_val_free(v);
392 return expr;
393 }
394
395 if (isl_val_is_negone(v)) {
396 isl_val_free(v);
397 expr = isl_ast_expr_neg(expr);
398 } else {
400 expr = isl_ast_expr_mul(c, expr);
401 }
402
403 return expr;
404error:
405 isl_val_free(v);
406 isl_ast_expr_free(expr);
407 return NULL;
408}
409
410/* Add an expression for "*v" times the specified dimension of data->ls
411 * to expr.
412 * If the dimension is an integer division, then this function
413 * may modify data->cst in order to make the numerator non-negative.
414 * The result is simplified in terms of data->build->domain.
415 *
416 * Let e be the expression for the specified dimension,
417 * multiplied by the absolute value of "*v".
418 * If "*v" is negative, we create
419 *
420 * (isl_ast_expr_op_sub, expr, e)
421 *
422 * except when expr is trivially zero, in which case we create
423 *
424 * (isl_ast_expr_op_minus, e)
425 *
426 * instead.
427 *
428 * If "*v" is positive, we simply create
429 *
430 * (isl_ast_expr_op_add, expr, e)
431 *
432 */
436{
437 isl_ast_expr *term;
438
439 if (!expr)
440 return NULL;
441
442 data->v = v;
443 term = var(data, type, pos);
444 v = data->v;
445
446 if (isl_val_is_neg(v) && !ast_expr_is_zero(expr)) {
447 v = isl_val_neg(v);
448 term = scale(term, v);
449 return ast_expr_sub(expr, term);
450 } else {
451 term = scale(term, v);
452 return ast_expr_add(expr, term);
453 }
454}
455
456/* Add an expression for "v" to expr.
457 */
460{
461 isl_ast_expr *expr_int;
462
463 if (!expr || !v)
464 goto error;
465
466 if (isl_val_is_zero(v)) {
467 isl_val_free(v);
468 return expr;
469 }
470
471 if (isl_val_is_neg(v) && !ast_expr_is_zero(expr)) {
472 v = isl_val_neg(v);
473 expr_int = isl_ast_expr_from_val(v);
474 return ast_expr_sub(expr, expr_int);
475 } else {
476 expr_int = isl_ast_expr_from_val(v);
477 return ast_expr_add(expr, expr_int);
478 }
479error:
480 isl_ast_expr_free(expr);
481 isl_val_free(v);
482 return NULL;
483}
484
485/* Internal data structure used inside extract_modulos.
486 *
487 * If any modulo expressions are detected in "aff", then the
488 * expression is removed from "aff" and added to either "pos" or "neg"
489 * depending on the sign of the coefficient of the modulo expression
490 * inside "aff".
491 *
492 * "add" is an expression that needs to be added to "aff" at the end of
493 * the computation. It is NULL as long as no modulos have been extracted.
494 *
495 * "i" is the position in "aff" of the div under investigation
496 * "v" is the coefficient in "aff" of the div
497 * "div" is the argument of the div, with the denominator removed
498 * "d" is the original denominator of the argument of the div
499 *
500 * If set, then "partial" is the (positively weighted) sum
501 * of the affine expressions of one or more previously considered constraints
502 * that could still be complemented to an expression equal to "div".
503 * "nonneg" is an affine expression that is non-negative over "build"
504 * and that can be used to extract a modulo expression from "div".
505 * In particular, if "sign" is 1, then the coefficients of "nonneg"
506 * are equal to those of "div" modulo "d". If "sign" is -1, then
507 * the coefficients of "nonneg" are opposite to those of "div" modulo "d".
508 * If "sign" is 0, then no such affine expression has been found (yet).
509 */
528
529/* Does
530 *
531 * arg mod data->d
532 *
533 * represent (a special case of) a test for some linear expression
534 * being even?
535 *
536 * In particular, is it of the form
537 *
538 * (lin - 1) mod 2
539 *
540 * ?
541 */
544{
546 isl_val *cst;
547
548 res = isl_val_eq_si(data->d, 2);
549 if (res < 0 || !res)
550 return res;
551
553 res = isl_val_eq_si(cst, -1);
554 isl_val_free(cst);
555
556 return res;
557}
558
559/* Given that data->v * div_i in data->aff is equal to
560 *
561 * f * (term - (arg mod d))
562 *
563 * with data->d * f = data->v and "arg" non-negative on data->build, add
564 *
565 * f * term
566 *
567 * to data->add and
568 *
569 * abs(f) * (arg mod d)
570 *
571 * to data->neg or data->pos depending on the sign of -f.
572 *
573 * In the special case that "arg mod d" is of the form "(lin - 1) mod 2",
574 * with "lin" some linear expression, first replace
575 *
576 * f * (term - ((lin - 1) mod 2))
577 *
578 * by
579 *
580 * -f * (1 - term - (lin mod 2))
581 *
582 * These two are equal because
583 *
584 * ((lin - 1) mod 2) + (lin mod 2) = 1
585 *
586 * Also, if "lin - 1" is non-negative, then "lin" is non-negative too.
587 */
590{
591 isl_bool even;
592 isl_ast_expr *expr;
593 int s;
594
595 even = is_even_test(data, arg);
596 if (even < 0) {
598 } else if (even) {
599 term = oppose_div_arg(term, isl_val_copy(data->d));
600 data->v = isl_val_neg(data->v);
602 }
603
604 data->v = isl_val_div(data->v, isl_val_copy(data->d));
605 s = isl_val_sgn(data->v);
606 data->v = isl_val_abs(data->v);
607 expr = isl_ast_expr_mod(data->v, arg, data->d, data->build);
609 if (s > 0)
610 data->neg = ast_expr_add(data->neg, expr);
611 else
612 data->pos = ast_expr_add(data->pos, expr);
613 data->aff = isl_aff_set_coefficient_si(data->aff,
614 isl_dim_div, data->i, 0);
615 if (s < 0)
616 data->v = isl_val_neg(data->v);
617 term = isl_aff_scale_val(term, isl_val_copy(data->v));
618
619 if (!data->add)
620 data->add = term;
621 else
622 data->add = isl_aff_add(data->add, term);
623 if (!data->add)
624 return isl_stat_error;
625
626 return isl_stat_ok;
627}
628
629/* Given that data->v * div_i in data->aff is of the form
630 *
631 * f * d * floor(div/d)
632 *
633 * with div nonnegative on data->build, rewrite it as
634 *
635 * f * (div - (div mod d)) = f * div - f * (div mod d)
636 *
637 * and add
638 *
639 * f * div
640 *
641 * to data->add and
642 *
643 * abs(f) * (div mod d)
644 *
645 * to data->neg or data->pos depending on the sign of -f.
646 */
648{
649 return extract_term_and_mod(data, isl_aff_copy(data->div),
650 isl_aff_copy(data->div));
651}
652
653/* Given that data->v * div_i in data->aff is of the form
654 *
655 * f * d * floor(div/d) (1)
656 *
657 * check if div is non-negative on data->build and, if so,
658 * extract the corresponding modulo from data->aff.
659 * If not, then check if
660 *
661 * -div + d - 1
662 *
663 * is non-negative on data->build. If so, replace (1) by
664 *
665 * -f * d * floor((-div + d - 1)/d)
666 *
667 * and extract the corresponding modulo from data->aff.
668 *
669 * This function may modify data->div.
670 */
672{
673 isl_bool mod;
674
675 mod = isl_ast_build_aff_is_nonneg(data->build, data->div);
676 if (mod < 0)
677 goto error;
678 if (mod)
679 return extract_mod(data);
680
681 data->div = oppose_div_arg(data->div, isl_val_copy(data->d));
682 mod = isl_ast_build_aff_is_nonneg(data->build, data->div);
683 if (mod < 0)
684 goto error;
685 if (mod) {
686 data->v = isl_val_neg(data->v);
687 return extract_mod(data);
688 }
689
690 return isl_stat_ok;
691error:
692 data->aff = isl_aff_free(data->aff);
693 return isl_stat_error;
694}
695
696/* Does "c" have a constant term that is "too large"?
697 * Here, "too large" is fairly arbitrarily set to 1 << 15.
698 */
700{
701 isl_val *v;
702 int sign;
703
705 if (!v)
706 return isl_bool_error;
707 sign = isl_val_cmp_si(v, 1 << 15);
708 isl_val_free(v);
709 return isl_bool_ok(sign > 0);
710}
711
712/* Is the affine expression with constant term returned by "get_constant"
713 * "simpler" than data->nonneg
714 * for use in extracting a modulo expression?
715 *
716 * Currently, only this constant term is considered.
717 * In particular, we prefer the affine expression with the smallest constant
718 * term.
719 * This means that if there are two constraints, say x >= 0 and -x + 10 >= 0,
720 * then we would pick x >= 0
721 *
722 * More detailed heuristics could be used if it turns out that there is a need.
723 */
726 void *user), void *user)
727{
728 isl_val *v1, *v2;
729 isl_bool simpler;
730
731 if (!data->nonneg)
732 return isl_bool_true;
733
734 v1 = isl_val_abs(get_constant(data, user));
736 simpler = isl_val_lt(v1, v2);
737 isl_val_free(v1);
738 isl_val_free(v2);
739
740 return simpler;
741}
742
743/* Return the constant term of "c".
744 */
746 struct isl_extract_mod_data *data, void *user)
747{
748 isl_constraint *c = user;
749
751}
752
753/* Is the affine expression of constraint "c" "simpler" than data->nonneg
754 * for use in extracting a modulo expression?
755 *
756 * The test is based on the constant term of "c".
757 */
763
764/* Replace data->nonneg by the affine expression "aff" and
765 * set data->sign to "sign".
766 */
768 __isl_take isl_aff *aff, int sign)
769{
770 isl_aff_free(data->nonneg);
771 data->nonneg = aff;
772 data->sign = sign;
773
774 return isl_stat_non_null(data->nonneg);
775}
776
777/* If "c" is "simpler" than data->nonneg,
778 * then replace data->nonneg by the affine expression of "c" and
779 * set data->sign to "sign".
780 */
782 __isl_keep isl_constraint *c, int sign)
783{
784 isl_bool simpler;
785
786 simpler = mod_constraint_is_simpler(data, c);
787 if (simpler < 0 || !simpler)
788 return isl_stat_non_error_bool(simpler);
789
790 return replace_nonneg(data, isl_constraint_get_aff(c), sign);
791}
792
793/* Internal data structure used inside check_parallel_or_opposite.
794 *
795 * "data" is the information passed down from the caller.
796 * "c" is the constraint being inspected.
797 *
798 * "n" contains the number of parameters and the number of input dimensions and
799 * is set by the first call to parallel_or_opposite_scan.
800 * "parallel" is set as long as the coefficients of "c" are still potentially
801 * equal to those of data->div modulo data->d.
802 * "opposite" is set as long as the coefficients of "c" are still potentially
803 * opposite to those of data->div modulo data->d.
804 * "partial" is set if the coefficients of "c" are still potentially
805 * a subset of those of data->div.
806 * "final" is set is the coefficients in data->partial together with those
807 * of "c" still cover the coefficients of data->div.
808 *
809 * If "f" is set, then it is the factor with which the coefficients
810 * of "c" need to be multiplied to match those of data->div.
811 */
824
825/* Should the scan of coefficients be continued?
826 * That is, are the coefficients still (potentially) (partially) equal or
827 * opposite?
828 */
830{
831 if (stat->parallel < 0 || stat->opposite < 0 || stat->partial < 0)
832 return isl_bool_error;
833
834 return isl_bool_ok(stat->parallel || stat->opposite || stat->partial);
835}
836
837/* Is coefficient "i" of type "c_type" of stat->c potentially equal or
838 * opposite to coefficient "i" of type "a_type" of stat->data->div
839 * modulo stat->data->div?
840 * In particular, are they both zero or both non-zero?
841 *
842 * Note that while the coefficients of stat->data->div can be reasonably
843 * expected not to involve any coefficients that are multiples of stat->data->d,
844 * "c" may very well involve such coefficients.
845 * This means that some cases of equal or opposite constraints can be missed
846 * this way.
847 *
848 * If the coefficient of stat->data->div is zero, but that of "c" is not,
849 * then the coefficients of "c" cannot form a subset of those
850 * of stat->data->div.
851 * If the coefficient of stat->data->div is not zero,
852 * then check that it does not appear in both "c" and stat->data->partial.
853 * If it does not appear in either, then it must appear in some later constraint
854 * and "c" can therefore not be the last in the sequence of constraints
855 * that sum up to stat->data->div.
856 */
858 enum isl_dim_type c_type, enum isl_dim_type a_type, int i)
859{
860 isl_bool a, b;
861
862 a = isl_constraint_involves_dims(stat->c, c_type, i, 1);
863 b = isl_aff_involves_dims(stat->data->div, a_type, i, 1);
864 if (a < 0 || b < 0)
865 return isl_bool_error;
866 if (a != b)
867 stat->parallel = stat->opposite = isl_bool_false;
868 if (!stat->partial)
870 if (!b && a)
871 stat->partial = isl_bool_false;
872 if (b && (a || stat->final) && stat->data->partial) {
873 isl_bool c;
874
875 c = isl_aff_involves_dims(stat->data->partial, a_type, i, 1);
876 if (c < 0)
877 return isl_bool_error;
878 if (a && c)
879 stat->partial = isl_bool_false;
880 if (!a && !c)
881 stat->final = 0;
882 }
883
885}
886
887/* Update stat->partial based on the coefficient "v1" of stat->c and
888 * "v2" of stat->data->div, where "v2" is known not to be zero.
889 * "v1" may be modified by this function and the modified value is returned.
890 * This function may also set stat->f.
891 *
892 * If "v1" is zero, then no update needs to be performed.
893 * Otherwise, stat->partial can only remain set if "c" is part
894 * of some positively weighted sum that is equal to stat->data->div.
895 * This means that v2 divided by v1 needs to be a positive integer.
896 * This quotient is stored in stat->f. If this quotient has already
897 * been set for a previous coefficient, then it needs to be the same.
898 */
901{
902 if (!stat->partial)
903 return v1;
904 if (isl_val_is_zero(v1))
905 return v1;
906
907 stat->partial = isl_val_is_divisible_by(v2, v1);
908 if (stat->partial < 0 || !stat->partial)
909 return v1;
910
911 v1 = isl_val_div(isl_val_copy(v2), v1);
912 stat->partial = isl_val_is_pos(v1);
913 if (stat->partial < 0 || !stat->partial)
914 return v1;
915 if (!stat->f)
916 stat->f = isl_val_copy(v1);
917 stat->partial = isl_val_eq(v1, stat->f);
918 return v1;
919}
920
921/* Is coefficient "i" of type "c_type" of stat->c equal or
922 * opposite to coefficient "i" of type "a_type" of stat->data->div
923 * modulo stat->data->div, or
924 * could stat->c be part of a positively weighted sum equal to stat->data->div?
925 * This function may set stat->f (at most once).
926 *
927 * If the coefficient of stat->data->div is zero,
928 * then parallel_or_opposite_feasible has already checked
929 * that the coefficient of stat->c is zero as well,
930 * so no further checks are needed.
931 */
933 enum isl_dim_type c_type, enum isl_dim_type a_type, int i)
934{
935 isl_val *v1, *v2;
936 isl_bool b;
937
938 b = isl_aff_involves_dims(stat->data->div, a_type, i, 1);
939 if (b < 0 || !b)
940 return isl_bool_not(b);
941
942 v1 = isl_constraint_get_coefficient_val(stat->c, c_type, i);
943 v2 = isl_aff_get_coefficient_val(stat->data->div, a_type, i);
944 if (stat->parallel) {
945 v1 = isl_val_sub(v1, isl_val_copy(v2));
946 stat->parallel = isl_val_is_divisible_by(v1, stat->data->d);
947 v1 = isl_val_add(v1, isl_val_copy(v2));
948 }
949 if (stat->opposite) {
950 v1 = isl_val_add(v1, isl_val_copy(v2));
951 stat->opposite = isl_val_is_divisible_by(v1, stat->data->d);
952 }
953 v1 = update_is_partial(stat, v1, v2);
954 isl_val_free(v1);
955 isl_val_free(v2);
956
958}
959
960/* Scan the coefficients of stat->c to see if they are (potentially)
961 * equal or opposite to those of stat->data->div modulo stat->data->d,
962 * calling "fn" on each coefficient.
963 * IF "init" is set, then this is the first call to this function and
964 * then stat->n is initialized.
965 */
967 isl_bool (*fn)(struct isl_parallel_stat *stat,
968 enum isl_dim_type c_type, enum isl_dim_type a_type, int i),
969 int init)
970{
971 enum isl_dim_type c_type[2] = { isl_dim_param, isl_dim_set };
972 enum isl_dim_type a_type[2] = { isl_dim_param, isl_dim_in };
973 int i, t;
974
975 for (t = 0; t < 2; ++t) {
976 if (init) {
977 stat->n[t] = isl_constraint_dim(stat->c, c_type[t]);
978 if (stat->n[t] < 0)
979 return isl_bool_error;
980 }
981 for (i = 0; i < stat->n[t]; ++i) {
982 isl_bool ok;
983
984 ok = fn(stat, c_type[t], a_type[t], i);
985 if (ok < 0 || !ok)
986 return ok;
987 }
988 }
989
990 return isl_bool_true;
991}
992
993/* Update stat->data->partial with stat->c.
994 *
995 * In particular, if stat->c with weight stat->f turns out
996 * to potentially be a part of a weighted sum equal to stat->data->div
997 * (i.e., stat->partial is set), then add this scaled version of stat->c
998 * to stat->data->partial or initialize stat->data->partial if it has not
999 * been set yet.
1000 */
1002{
1003 isl_aff *aff;
1004
1005 if (!stat->partial)
1006 return isl_stat_ok;
1007
1008 aff = isl_constraint_get_aff(stat->c);
1010 if (!stat->data->partial)
1011 stat->data->partial = aff;
1012 else
1013 stat->data->partial = isl_aff_add(stat->data->partial, aff);
1014
1015 return isl_stat_non_null(stat->data->partial);
1016}
1017
1018/* Return the constant term of data->partial.
1019 */
1021 struct isl_extract_mod_data *data, void *user)
1022{
1023 return isl_aff_get_constant_val(data->partial);
1024}
1025
1026/* Is the affine expression data->partial "simpler" than data->nonneg
1027 * for use in extracting a modulo expression?
1028 *
1029 * The test is based on the constant term of data->partial.
1030 */
1032{
1033 return is_simpler(data, &get_partial_constant, NULL);
1034}
1035
1036/* If stat->data->partial is complete and is "simpler" than data->nonneg,
1037 * then replace stat->data->nonneg by stat->data->partial.
1038 */
1040{
1041 isl_bool simpler;
1043
1044 if (!stat->final)
1045 return isl_stat_ok;
1046
1047 simpler = partial_is_simpler(stat->data);
1048 if (simpler < 0 || !simpler)
1049 return isl_stat_non_error_bool(simpler);
1050
1051 partial = stat->data->partial;
1052 stat->data->partial = NULL;
1053
1054 return replace_nonneg(stat->data, partial, 1);
1055}
1056
1057/* Check if the coefficients of "c" are either equal or opposite to those
1058 * of data->div modulo data->d. If so, and if "c" is "simpler" than
1059 * data->nonneg, then replace data->nonneg by the affine expression of "c"
1060 * and set data->sign accordingly.
1061 * Also check if "c" is part of a positively weighted sum of constraints
1062 * that is equal to data->div, where each constraint has distinct non-zero
1063 * coefficients. If "c" is the last constraint in this sum
1064 * (and the sum is "simpler" than data->nonneg)
1065 * then also replace data->nonneg by this sum.
1066 * If "c" is equal or opposite to data->div, then it is not considered
1067 * to be part of a sum.
1068 *
1069 * Both "c" and data->div are assumed not to involve any integer divisions.
1070 *
1071 * Before we start the actual comparison, we first quickly check if
1072 * "c" and data->div have the same non-zero coefficients.
1073 * If not, then we assume that "c" is not of the desired form.
1074 *
1075 * If the constant term is "too large", then the constraint is rejected.
1076 * We do this to avoid picking up constraints that bound a variable
1077 * by a very large number, say the largest or smallest possible
1078 * variable in the representation of some integer type.
1079 */
1082{
1083 struct isl_parallel_stat stat = {
1084 .data = data,
1085 .c = c,
1086 .parallel = isl_bool_true,
1087 .opposite = isl_bool_true,
1088 .partial = isl_bool_true,
1089 .final = data->partial != NULL,
1090 .f = NULL,
1091 };
1092 isl_bool skip, ok;
1093
1094 ok = parallel_or_opposite_scan(&stat,
1096 if (ok < 0 || !ok)
1097 return isl_stat_non_error_bool(ok);
1098
1099 skip = has_large_constant_term(c);
1100 if (skip < 0 || skip)
1101 return isl_stat_non_error_bool(skip);
1102
1103 if (stat.parallel || stat.opposite)
1104 stat.partial = isl_bool_false;
1105
1107 if (ok >= 0 && ok)
1108 if (update_partial(&stat) < 0)
1109 ok = isl_bool_error;
1110 isl_val_free(stat.f);
1111 if (ok < 0 || !ok)
1112 return isl_stat_non_error_bool(ok);
1113
1114 if (stat.partial)
1115 return replace_by_partial_if_simpler(&stat);
1116
1117 return replace_if_simpler(data, c, stat.parallel ? 1 : -1);
1118}
1119
1120/* Wrapper around check_parallel_or_opposite for use
1121 * as a isl_basic_set_foreach_constraint callback.
1122 */
1124 void *user)
1125{
1126 struct isl_extract_mod_data *data = user;
1127 isl_stat res;
1128
1131
1132 return res;
1133}
1134
1135/* Given that data->v * div_i in data->aff is of the form
1136 *
1137 * f * d * floor(div/d) (1)
1138 *
1139 * see if we can find an expression div' that is non-negative over data->build
1140 * and that is related to div through
1141 *
1142 * div' = div + d * e
1143 *
1144 * or
1145 *
1146 * div' = -div + d - 1 + d * e
1147 *
1148 * with e some affine expression.
1149 * If so, we write (1) as
1150 *
1151 * f * div + f * (div' mod d)
1152 *
1153 * or
1154 *
1155 * -f * (-div + d - 1) - f * (div' mod d)
1156 *
1157 * exploiting (in the second case) the fact that
1158 *
1159 * f * d * floor(div/d) = -f * d * floor((-div + d - 1)/d)
1160 *
1161 *
1162 * We first try to find an appropriate expression for div'
1163 * from the constraints of data->build->domain (which is therefore
1164 * guaranteed to be non-negative on data->build), where we remove
1165 * any integer divisions from the constraints and skip this step
1166 * if "div" itself involves any integer divisions.
1167 * The following cases are considered for div':
1168 * - individual constraints, or
1169 * - a sum of constraints that involve disjoint sets of variables and
1170 * where the sum is exactly equal to div (i.e., e = 0).
1171 * If we cannot find an appropriate expression this way, then
1172 * we pass control to extract_nonneg_mod where check
1173 * if div or "-div + d -1" themselves happen to be
1174 * non-negative on data->build.
1175 *
1176 * While looking for an appropriate constraint in data->build->domain,
1177 * we ignore the constant term, so after finding such a constraint,
1178 * we still need to fix up the constant term.
1179 * In particular, if a is the constant term of "div"
1180 * (or d - 1 - the constant term of "div" if data->sign < 0)
1181 * and b is the constant term of the constraint, then we need to find
1182 * a non-negative constant c such that
1183 *
1184 * b + c \equiv a mod d
1185 *
1186 * We therefore take
1187 *
1188 * c = (a - b) mod d
1189 *
1190 * and add it to b to obtain the constant term of div'.
1191 * If this constant term is "too negative", then we add an appropriate
1192 * multiple of d to make it positive.
1193 *
1194 *
1195 * Note that the above is only a very simple heuristic for finding an
1196 * appropriate expression. We could try a bit harder by also considering
1197 * arbitrary linear combinations of constraints,
1198 * although that could potentially be much more expensive as it involves
1199 * the solution of an LP problem.
1200 *
1201 * In particular, if v_i is a column vector representing constraint i,
1202 * w represents div and e_i is the i-th unit vector, then we are looking
1203 * for a solution of the constraints
1204 *
1205 * \sum_i lambda_i v_i = w + \sum_i alpha_i d e_i
1206 *
1207 * with \lambda_i >= 0 and alpha_i of unrestricted sign.
1208 * If we are not just interested in a non-negative expression, but
1209 * also in one with a minimal range, then we don't just want
1210 * c = \sum_i lambda_i v_i to be non-negative over the domain,
1211 * but also beta - c = \sum_i mu_i v_i, where beta is a scalar
1212 * that we want to minimize and we now also have to take into account
1213 * the constant terms of the constraints.
1214 * Alternatively, we could first compute the dual of the domain
1215 * and plug in the constraints on the coefficients.
1216 */
1218{
1220 isl_val *v1, *v2;
1221 isl_stat r;
1222 isl_size n;
1223
1224 if (!data->build)
1225 goto error;
1226
1227 n = isl_aff_dim(data->div, isl_dim_div);
1228 if (n < 0)
1229 goto error;
1230
1231 if (isl_aff_involves_dims(data->div, isl_dim_div, 0, n))
1232 return extract_nonneg_mod(data);
1233
1236 data->sign = 0;
1237 data->nonneg = NULL;
1238 data->partial = NULL;
1241 isl_aff_free(data->partial);
1243
1244 if (!data->sign || r < 0) {
1245 isl_aff_free(data->nonneg);
1246 if (r < 0)
1247 goto error;
1248 return extract_nonneg_mod(data);
1249 }
1250
1251 v1 = isl_aff_get_constant_val(data->div);
1252 v2 = isl_aff_get_constant_val(data->nonneg);
1253 if (data->sign < 0) {
1254 v1 = isl_val_neg(v1);
1255 v1 = isl_val_add(v1, isl_val_copy(data->d));
1256 v1 = isl_val_sub_ui(v1, 1);
1257 }
1258 v1 = isl_val_sub(v1, isl_val_copy(v2));
1259 v1 = isl_val_mod(v1, isl_val_copy(data->d));
1260 v1 = isl_val_add(v1, v2);
1261 v2 = isl_val_div(isl_val_copy(v1), isl_val_copy(data->d));
1262 v2 = isl_val_ceil(v2);
1263 if (isl_val_is_neg(v2)) {
1264 v2 = isl_val_mul(v2, isl_val_copy(data->d));
1265 v1 = isl_val_sub(v1, isl_val_copy(v2));
1266 }
1267 data->nonneg = isl_aff_set_constant_val(data->nonneg, v1);
1268 isl_val_free(v2);
1269
1270 if (data->sign < 0) {
1271 data->div = oppose_div_arg(data->div, isl_val_copy(data->d));
1272 data->v = isl_val_neg(data->v);
1273 }
1274
1275 return extract_term_and_mod(data,
1276 isl_aff_copy(data->div), data->nonneg);
1277error:
1278 data->aff = isl_aff_free(data->aff);
1279 return isl_stat_error;
1280}
1281
1282/* Check if "data->aff" involves any (implicit) modulo computations based
1283 * on div "data->i".
1284 * If so, remove them from aff and add expressions corresponding
1285 * to those modulo computations to data->pos and/or data->neg.
1286 *
1287 * "aff" is assumed to be an integer affine expression.
1288 *
1289 * In particular, check if (v * div_j) is of the form
1290 *
1291 * f * m * floor(a / m)
1292 *
1293 * and, if so, rewrite it as
1294 *
1295 * f * (a - (a mod m)) = f * a - f * (a mod m)
1296 *
1297 * and extract out -f * (a mod m).
1298 * In particular, if f > 0, we add (f * (a mod m)) to *neg.
1299 * If f < 0, we add ((-f) * (a mod m)) to *pos.
1300 *
1301 * Note that in order to represent "a mod m" as
1302 *
1303 * (isl_ast_expr_op_pdiv_r, a, m)
1304 *
1305 * we need to make sure that a is non-negative.
1306 * If not, we check if "-a + m - 1" is non-negative.
1307 * If so, we can rewrite
1308 *
1309 * floor(a/m) = -ceil(-a/m) = -floor((-a + m - 1)/m)
1310 *
1311 * and still extract a modulo.
1312 */
1313static int extract_modulo(struct isl_extract_mod_data *data)
1314{
1315 data->div = isl_aff_get_div(data->aff, data->i);
1316 data->d = isl_aff_get_denominator_val(data->div);
1317 if (isl_val_is_divisible_by(data->v, data->d)) {
1318 data->div = isl_aff_scale_val(data->div, isl_val_copy(data->d));
1319 if (try_extract_mod(data) < 0)
1320 data->aff = isl_aff_free(data->aff);
1321 }
1322 isl_aff_free(data->div);
1323 isl_val_free(data->d);
1324 return 0;
1325}
1326
1327/* Check if "aff" involves any (implicit) modulo computations.
1328 * If so, remove them from aff and add expressions corresponding
1329 * to those modulo computations to *pos and/or *neg.
1330 * We only do this if the option ast_build_prefer_pdiv is set.
1331 *
1332 * "aff" is assumed to be an integer affine expression.
1333 *
1334 * A modulo expression is of the form
1335 *
1336 * a mod m = a - m * floor(a / m)
1337 *
1338 * To detect them in aff, we look for terms of the form
1339 *
1340 * f * m * floor(a / m)
1341 *
1342 * rewrite them as
1343 *
1344 * f * (a - (a mod m)) = f * a - f * (a mod m)
1345 *
1346 * and extract out -f * (a mod m).
1347 * In particular, if f > 0, we add (f * (a mod m)) to *neg.
1348 * If f < 0, we add ((-f) * (a mod m)) to *pos.
1349 */
1353{
1354 struct isl_extract_mod_data data = { build, aff, *pos, *neg };
1355 isl_ctx *ctx;
1356 isl_size n;
1357
1358 if (!aff)
1359 return NULL;
1360
1361 ctx = isl_aff_get_ctx(aff);
1363 return aff;
1364
1365 n = isl_aff_dim(data.aff, isl_dim_div);
1366 if (n < 0)
1367 return isl_aff_free(aff);
1368 for (data.i = 0; data.i < n; ++data.i) {
1369 data.v = isl_aff_get_coefficient_val(data.aff,
1370 isl_dim_div, data.i);
1371 if (!data.v)
1372 return isl_aff_free(aff);
1373 if (isl_val_is_zero(data.v) ||
1374 isl_val_is_one(data.v) || isl_val_is_negone(data.v)) {
1375 isl_val_free(data.v);
1376 continue;
1377 }
1378 if (extract_modulo(&data) < 0)
1379 data.aff = isl_aff_free(data.aff);
1380 isl_val_free(data.v);
1381 if (!data.aff)
1382 break;
1383 }
1384
1385 if (data.add)
1386 data.aff = isl_aff_add(data.aff, data.add);
1387
1388 *pos = data.pos;
1389 *neg = data.neg;
1390 return data.aff;
1391}
1392
1393/* Call "fn" on every non-zero coefficient of "aff",
1394 * passing it in the type of dimension (in terms of the domain),
1395 * the position and the value, as long as "fn" returns isl_bool_true.
1396 * If "reverse" is set, then the coefficients are considered in reverse order
1397 * within each type.
1398 */
1400 int reverse,
1402 void *user),
1403 void *user)
1404{
1405 int i, j;
1408 isl_val *v;
1409
1410 for (i = 0; i < 3; ++i) {
1411 isl_size n;
1412
1413 n = isl_aff_dim(aff, t[i]);
1414 if (n < 0)
1415 return isl_bool_error;
1416 for (j = 0; j < n; ++j) {
1417 isl_bool ok;
1418 int pos;
1419
1420 pos = reverse ? n - 1 - j : j;
1422 ok = isl_val_is_zero(v);
1423 if (ok >= 0 && !ok)
1424 ok = fn(l[i], pos, v, user);
1425 else
1426 isl_val_free(v);
1427 if (ok < 0 || !ok)
1428 return ok;
1429 }
1430 }
1431
1432 return isl_bool_true;
1433}
1434
1435/* Internal data structure for extract_rational.
1436 *
1437 * "d" is the denominator of the original affine expression.
1438 * "ls" is its domain local space.
1439 * "rat" collects the rational part.
1440 */
1447
1448/* Given a non-zero term in an affine expression equal to "v" times
1449 * the variable of type "type" at position "pos",
1450 * add it to data->rat if "v" is not a multiple of data->d.
1451 */
1453 __isl_take isl_val *v, void *user)
1454{
1455 struct isl_ast_extract_rational_data *data = user;
1456 isl_aff *rat;
1457
1458 if (isl_val_is_divisible_by(v, data->d)) {
1459 isl_val_free(v);
1460 return isl_bool_true;
1461 }
1464 data->rat = isl_aff_add(data->rat, rat);
1465 return isl_bool_true;
1466}
1467
1468/* Check if aff involves any non-integer coefficients.
1469 * If so, split aff into
1470 *
1471 * aff = aff1 + (aff2 / d)
1472 *
1473 * with both aff1 and aff2 having only integer coefficients.
1474 * Return aff1 and add (aff2 / d) to *expr.
1475 */
1478{
1479 struct isl_ast_extract_rational_data data = { NULL };
1480 isl_ast_expr *rat_expr;
1481 isl_val *v;
1482
1483 if (!aff)
1484 return NULL;
1486 if (!data.d)
1487 goto error;
1488 if (isl_val_is_one(data.d)) {
1489 isl_val_free(data.d);
1490 return aff;
1491 }
1492
1494
1497
1498 if (every_non_zero_coefficient(aff, 0, &add_rational, &data) < 0)
1499 goto error;
1500
1502 if (isl_val_is_divisible_by(v, data.d)) {
1503 isl_val_free(v);
1504 } else {
1505 isl_aff *rat_0;
1506
1508 data.rat = isl_aff_add(data.rat, rat_0);
1509 }
1510
1512
1515
1516 rat_expr = div_mod(isl_ast_expr_op_div, data.rat, data.d, build);
1517 *expr = ast_expr_add(*expr, rat_expr);
1518
1519 return aff;
1520error:
1521 isl_aff_free(data.rat);
1524 isl_val_free(data.d);
1525 return NULL;
1526}
1527
1528/* Internal data structure for isl_ast_expr_from_aff.
1529 *
1530 * "term" contains the information for adding a term.
1531 * "expr" collects the results.
1532 */
1537
1538/* Given a non-zero term in an affine expression equal to "v" times
1539 * the variable of type "type" at position "pos",
1540 * add the corresponding AST expression to data->expr.
1541 */
1543 __isl_take isl_val *v, void *user)
1544{
1545 struct isl_ast_add_terms_data *data = user;
1546
1547 data->expr =
1548 isl_ast_expr_add_term(data->expr, type, pos, v, data->term);
1549
1550 return isl_bool_true;
1551}
1552
1553/* Add terms to "expr" for each variable in "aff".
1554 * The result is simplified in terms of data->build->domain.
1555 */
1558{
1559 struct isl_ast_add_terms_data terms_data = { data, expr };
1560
1561 if (every_non_zero_coefficient(aff, 0, &add_term, &terms_data) < 0)
1562 return isl_ast_expr_free(terms_data.expr);
1563
1564 return terms_data.expr;
1565}
1566
1567/* Construct an isl_ast_expr that evaluates the affine expression "aff".
1568 * The result is simplified in terms of build->domain.
1569 *
1570 * We first extract hidden modulo computations from the affine expression
1571 * and then add terms for each variable with a non-zero coefficient.
1572 * Finally, if the affine expression has a non-trivial denominator,
1573 * we divide the resulting isl_ast_expr by this denominator.
1574 */
1577{
1578 isl_ctx *ctx = isl_aff_get_ctx(aff);
1579 isl_ast_expr *expr, *expr_neg;
1580 struct isl_ast_add_term_data term_data;
1581
1582 if (!aff)
1583 return NULL;
1584
1585 expr = isl_ast_expr_alloc_int_si(ctx, 0);
1586 expr_neg = isl_ast_expr_alloc_int_si(ctx, 0);
1587
1588 aff = extract_rational(aff, &expr, build);
1589
1590 aff = extract_modulos(aff, &expr, &expr_neg, build);
1591 expr = ast_expr_sub(expr, expr_neg);
1592
1593 term_data.build = build;
1595 term_data.cst = isl_aff_get_constant_val(aff);
1596 expr = add_terms(expr, aff, &term_data);
1597
1598 expr = isl_ast_expr_add_int(expr, term_data.cst);
1599 isl_local_space_free(term_data.ls);
1600
1602 return expr;
1603}
1604
1605/* Internal data structure for coefficients_of_sign.
1606 *
1607 * "sign" is the sign of the coefficients that should be retained.
1608 * "aff" is the affine expression of which some coefficients are zeroed out.
1609 */
1614
1615/* Clear the specified coefficient of data->aff if the value "v"
1616 * does not have the required sign.
1617 */
1619 __isl_take isl_val *v, void *user)
1620{
1622
1623 if (type == isl_dim_set)
1624 type = isl_dim_in;
1625 if (data->sign * isl_val_sgn(v) < 0)
1626 data->aff = isl_aff_set_coefficient_si(data->aff, type, pos, 0);
1627 isl_val_free(v);
1628
1629 return isl_bool_true;
1630}
1631
1632/* Extract the coefficients of "aff" (excluding the constant term)
1633 * that have the given sign.
1634 *
1635 * Take a copy of "aff" and clear the coefficients that do not have
1636 * the required sign.
1637 * Consider the coefficients in reverse order since clearing
1638 * the coefficient of an integer division in data.aff
1639 * could result in the removal of that integer division from data.aff,
1640 * changing the positions of all subsequent integer divisions of data.aff,
1641 * while those of "aff" remain the same.
1642 */
1644 int sign)
1645{
1647
1648 data.sign = sign;
1649 data.aff = isl_aff_copy(aff);
1651 data.aff = isl_aff_free(data.aff);
1653
1654 data.aff = isl_aff_set_constant_si(data.aff, 0);
1655
1656 return data.aff;
1657}
1658
1659/* Should the constant term "v" be considered positive?
1660 *
1661 * A positive constant will be added to "pos" by the caller,
1662 * while a negative constant will be added to "neg".
1663 * If either "pos" or "neg" is exactly zero, then we prefer
1664 * to add the constant "v" to that side, irrespective of the sign of "v".
1665 * This results in slightly shorter expressions and may reduce the risk
1666 * of overflows.
1667 */
1670{
1671 isl_bool zero;
1672
1673 zero = ast_expr_is_zero(pos);
1674 if (zero < 0 || zero)
1675 return zero;
1676 zero = ast_expr_is_zero(neg);
1677 if (zero < 0 || zero)
1678 return isl_bool_not(zero);
1679 return isl_val_is_pos(v);
1680}
1681
1682/* Check if the equality
1683 *
1684 * aff = 0
1685 *
1686 * represents a stride constraint on the integer division "pos".
1687 *
1688 * In particular, if the integer division "pos" is equal to
1689 *
1690 * floor(e/d)
1691 *
1692 * then check if aff is equal to
1693 *
1694 * e - d floor(e/d)
1695 *
1696 * or its opposite.
1697 *
1698 * If so, the equality is exactly
1699 *
1700 * e mod d = 0
1701 *
1702 * Note that in principle we could also accept
1703 *
1704 * e - d floor(e'/d)
1705 *
1706 * where e and e' differ by a constant.
1707 */
1709{
1710 isl_aff *div;
1711 isl_val *c, *d;
1712 isl_bool eq;
1713
1714 div = isl_aff_get_div(aff, pos);
1717 eq = isl_val_abs_eq(c, d);
1718 if (eq >= 0 && eq) {
1719 aff = isl_aff_copy(aff);
1721 div = isl_aff_scale_val(div, d);
1722 if (isl_val_is_pos(c))
1723 div = isl_aff_neg(div);
1724 eq = isl_aff_plain_is_equal(div, aff);
1726 } else
1727 isl_val_free(d);
1728 isl_val_free(c);
1729 isl_aff_free(div);
1730
1731 return eq;
1732}
1733
1734/* Are all coefficients of "aff" (zero or) negative?
1735 */
1737{
1738 int i;
1739 isl_size n;
1740
1742 if (n < 0)
1743 return isl_bool_error;
1744 for (i = 0; i < n; ++i)
1746 return isl_bool_false;
1747
1749 if (n < 0)
1750 return isl_bool_error;
1751 for (i = 0; i < n; ++i)
1753 return isl_bool_false;
1754
1755 return isl_bool_true;
1756}
1757
1758/* Give an equality of the form
1759 *
1760 * aff = e - d floor(e/d) = 0
1761 *
1762 * or
1763 *
1764 * aff = -e + d floor(e/d) = 0
1765 *
1766 * with the integer division "pos" equal to floor(e/d),
1767 * construct the AST expression
1768 *
1769 * (isl_ast_expr_op_eq,
1770 * (isl_ast_expr_op_zdiv_r, expr(e), expr(d)), expr(0))
1771 *
1772 * If e only has negative coefficients, then construct
1773 *
1774 * (isl_ast_expr_op_eq,
1775 * (isl_ast_expr_op_zdiv_r, expr(-e), expr(d)), expr(0))
1776 *
1777 * instead.
1778 */
1781{
1783 isl_ctx *ctx;
1784 isl_val *c;
1785 isl_ast_expr *expr, *cst;
1786
1787 if (!aff)
1788 return NULL;
1789
1790 ctx = isl_aff_get_ctx(aff);
1791
1794
1796 if (all_neg < 0)
1797 aff = isl_aff_free(aff);
1798 else if (all_neg)
1799 aff = isl_aff_neg(aff);
1800
1802 expr = isl_ast_expr_from_aff(aff, build);
1803
1805 cst = isl_ast_expr_alloc_int_si(ctx, 0);
1807
1808 return expr;
1809}
1810
1811/* Construct an isl_ast_expr evaluating
1812 *
1813 * "expr_pos" == "expr_neg", if "eq" is set, or
1814 * "expr_pos" >= "expr_neg", if "eq" is not set
1815 *
1816 * However, if "expr_pos" is an integer constant (and "expr_neg" is not),
1817 * then the two expressions are interchanged. This ensures that,
1818 * e.g., "i <= 5" is constructed rather than "5 >= i".
1819 */
1821 __isl_take isl_ast_expr *expr_pos, __isl_take isl_ast_expr *expr_neg)
1822{
1823 isl_ast_expr *expr;
1825 int pos_is_cst, neg_is_cst;
1826
1827 pos_is_cst = isl_ast_expr_get_type(expr_pos) == isl_ast_expr_int;
1828 neg_is_cst = isl_ast_expr_get_type(expr_neg) == isl_ast_expr_int;
1829 if (pos_is_cst && !neg_is_cst) {
1831 expr = isl_ast_expr_alloc_binary(type, expr_neg, expr_pos);
1832 } else {
1834 expr = isl_ast_expr_alloc_binary(type, expr_pos, expr_neg);
1835 }
1836
1837 return expr;
1838}
1839
1840/* Construct an isl_ast_expr that evaluates the condition "aff" == 0
1841 * (if "eq" is set) or "aff" >= 0 (otherwise).
1842 * The result is simplified in terms of build->domain.
1843 *
1844 * We first extract hidden modulo computations from "aff"
1845 * and then collect all the terms with a positive coefficient in cons_pos
1846 * and the terms with a negative coefficient in cons_neg.
1847 *
1848 * The result is then essentially of the form
1849 *
1850 * (isl_ast_expr_op_ge, expr(pos), expr(-neg)))
1851 *
1852 * or
1853 *
1854 * (isl_ast_expr_op_eq, expr(pos), expr(-neg)))
1855 *
1856 * However, if there are no terms with positive coefficients (or no terms
1857 * with negative coefficients), then the constant term is added to "pos"
1858 * (or "neg"), ignoring the sign of the constant term.
1859 */
1862{
1863 isl_bool cst_is_pos;
1864 isl_ctx *ctx;
1865 isl_ast_expr *expr_pos;
1866 isl_ast_expr *expr_neg;
1867 isl_aff *aff_pos, *aff_neg;
1868 struct isl_ast_add_term_data data;
1869
1870 ctx = isl_aff_get_ctx(aff);
1871 expr_pos = isl_ast_expr_alloc_int_si(ctx, 0);
1872 expr_neg = isl_ast_expr_alloc_int_si(ctx, 0);
1873
1874 aff = extract_modulos(aff, &expr_pos, &expr_neg, build);
1875
1876 data.build = build;
1879
1880 aff_pos = coefficients_of_sign(isl_aff_copy(aff), 1);
1881 aff_neg = isl_aff_neg(coefficients_of_sign(aff, -1));
1882
1883 expr_pos = add_terms(expr_pos, aff_pos, &data);
1884 data.cst = isl_val_neg(data.cst);
1885 expr_neg = add_terms(expr_neg, aff_neg, &data);
1886 data.cst = isl_val_neg(data.cst);
1888
1889 cst_is_pos =
1890 constant_is_considered_positive(data.cst, expr_pos, expr_neg);
1891 if (cst_is_pos < 0)
1892 expr_pos = isl_ast_expr_free(expr_pos);
1893
1894 if (cst_is_pos) {
1895 expr_pos = isl_ast_expr_add_int(expr_pos, data.cst);
1896 } else {
1897 data.cst = isl_val_neg(data.cst);
1898 expr_neg = isl_ast_expr_add_int(expr_neg, data.cst);
1899 }
1900
1901 isl_aff_free(aff_pos);
1902 isl_aff_free(aff_neg);
1903 return construct_constraint_expr(eq, expr_pos, expr_neg);
1904}
1905
1906/* Construct an isl_ast_expr that evaluates the condition "constraint".
1907 * The result is simplified in terms of build->domain.
1908 *
1909 * We first check if the constraint is an equality of the form
1910 *
1911 * e - d floor(e/d) = 0
1912 *
1913 * i.e.,
1914 *
1915 * e mod d = 0
1916 *
1917 * If so, we convert it to
1918 *
1919 * (isl_ast_expr_op_eq,
1920 * (isl_ast_expr_op_zdiv_r, expr(e), expr(d)), expr(0))
1921 */
1924{
1925 int i;
1926 isl_size n;
1927 isl_aff *aff;
1928 isl_bool eq;
1929
1930 aff = isl_constraint_get_aff(constraint);
1931 eq = isl_constraint_is_equality(constraint);
1932 isl_constraint_free(constraint);
1933 if (eq < 0)
1934 goto error;
1935
1937 if (n < 0)
1938 aff = isl_aff_free(aff);
1939 if (eq && n > 0)
1940 for (i = 0; i < n; ++i) {
1941 isl_bool is_stride;
1942 is_stride = is_stride_constraint(aff, i);
1943 if (is_stride < 0)
1944 goto error;
1945 if (is_stride)
1947 }
1948
1950error:
1952 return NULL;
1953}
1954
1955/* Wrapper around isl_constraint_cmp_last_non_zero for use
1956 * as a callback to isl_constraint_list_sort.
1957 * If isl_constraint_cmp_last_non_zero cannot tell the constraints
1958 * apart, then use isl_constraint_plain_cmp instead.
1959 */
1962{
1963 int cmp;
1964
1966 if (cmp != 0)
1967 return cmp;
1968 return isl_constraint_plain_cmp(a, b);
1969}
1970
1971/* Construct an isl_ast_expr that evaluates the conditions defining "bset".
1972 * The result is simplified in terms of build->domain.
1973 *
1974 * If "bset" is not bounded by any constraint, then we construct
1975 * the expression "1", i.e., "true".
1976 *
1977 * Otherwise, we sort the constraints, putting constraints that involve
1978 * integer divisions after those that do not, and construct an "and"
1979 * of the ast expressions of the individual constraints.
1980 *
1981 * Each constraint is added to the generated constraints of the build
1982 * after it has been converted to an AST expression so that it can be used
1983 * to simplify the following constraints. This may change the truth value
1984 * of subsequent constraints that do not satisfy the earlier constraints,
1985 * but this does not affect the outcome of the conjunction as it is
1986 * only true if all the conjuncts are true (no matter in what order
1987 * they are evaluated). In particular, the constraints that do not
1988 * involve integer divisions may serve to simplify some constraints
1989 * that do involve integer divisions.
1990 */
1993{
1994 int i;
1995 isl_size n;
1996 isl_constraint *c;
1997 isl_constraint_list *list;
1999 isl_set *set;
2000
2002 isl_basic_set_free(bset);
2003 list = isl_constraint_list_sort(list, &cmp_constraint, NULL);
2004 n = isl_constraint_list_n_constraint(list);
2005 if (n < 0)
2006 build = NULL;
2007 if (n == 0) {
2008 isl_ctx *ctx = isl_constraint_list_get_ctx(list);
2009 isl_constraint_list_free(list);
2010 return isl_ast_expr_alloc_int_si(ctx, 1);
2011 }
2012
2014
2015 c = isl_constraint_list_get_constraint(list, 0);
2020
2021 for (i = 1; i < n; ++i) {
2022 isl_ast_expr *expr;
2023
2024 c = isl_constraint_list_get_constraint(list, i);
2029 res = isl_ast_expr_and(res, expr);
2030 }
2031
2032 isl_constraint_list_free(list);
2034 return res;
2035}
2036
2037/* Construct an isl_ast_expr that evaluates the conditions defining "set".
2038 * The result is simplified in terms of build->domain.
2039 *
2040 * If "set" is an (obviously) empty set, then return the expression "0".
2041 *
2042 * If there are multiple disjuncts in the description of the set,
2043 * then subsequent disjuncts are simplified in a context where
2044 * the previous disjuncts have been removed from build->domain.
2045 * In particular, constraints that ensure that there is no overlap
2046 * with these previous disjuncts, can be removed.
2047 * This is mostly useful for disjuncts that are only defined by
2048 * a single constraint (relative to the build domain) as the opposite
2049 * of that single constraint can then be removed from the other disjuncts.
2050 * In order not to increase the number of disjuncts in the build domain
2051 * after subtracting the previous disjuncts of "set", the simple hull
2052 * is computed after taking the difference with each of these disjuncts.
2053 * This means that constraints that prevent overlap with a union
2054 * of multiple previous disjuncts are not removed.
2055 *
2056 * "set" lives in the internal schedule space.
2057 */
2060{
2061 int i;
2062 isl_size n;
2063 isl_basic_set *bset;
2064 isl_basic_set_list *list;
2065 isl_set *domain;
2067
2070
2071 n = isl_basic_set_list_n_basic_set(list);
2072 if (n < 0)
2073 build = NULL;
2074 if (n == 0) {
2076 isl_basic_set_list_free(list);
2078 }
2079
2081
2082 bset = isl_basic_set_list_get_basic_set(list, 0);
2085
2086 for (i = 1; i < n; ++i) {
2087 isl_ast_expr *expr;
2088 isl_set *rest;
2089
2093 bset = isl_basic_set_list_get_basic_set(list, i);
2095 bset = isl_basic_set_gist(bset,
2098 res = isl_ast_expr_or(res, expr);
2099 }
2100
2103 isl_basic_set_list_free(list);
2104 return res;
2105}
2106
2107/* Construct an isl_ast_expr that evaluates the conditions defining "set".
2108 * The result is simplified in terms of build->domain.
2109 *
2110 * If "set" is an (obviously) empty set, then return the expression "0".
2111 *
2112 * "set" lives in the external schedule space.
2113 *
2114 * The internal AST expression generation assumes that there are
2115 * no unknown divs, so make sure an explicit representation is available.
2116 * Since the set comes from the outside, it may have constraints that
2117 * are redundant with respect to the build domain. Remove them first.
2118 */
2137
2138/* State of data about previous pieces in
2139 * isl_ast_build_expr_from_pw_aff_internal.
2140 *
2141 * isl_state_none: no data about previous pieces
2142 * isl_state_single: data about a single previous piece
2143 * isl_state_min: data represents minimum of several pieces
2144 * isl_state_max: data represents maximum of several pieces
2145 */
2152
2153/* Internal date structure representing a single piece in the input of
2154 * isl_ast_build_expr_from_pw_aff_internal.
2155 *
2156 * If "state" is isl_state_none, then "set_list" and "aff_list" are not used.
2157 * If "state" is isl_state_single, then "set_list" and "aff_list" contain the
2158 * single previous subpiece.
2159 * If "state" is isl_state_min, then "set_list" and "aff_list" contain
2160 * a sequence of several previous subpieces that are equal to the minimum
2161 * of the entries in "aff_list" over the union of "set_list"
2162 * If "state" is isl_state_max, then "set_list" and "aff_list" contain
2163 * a sequence of several previous subpieces that are equal to the maximum
2164 * of the entries in "aff_list" over the union of "set_list"
2165 *
2166 * During the construction of the pieces, "set" is NULL.
2167 * After the construction, "set" is set to the union of the elements
2168 * in "set_list", at which point "set_list" is set to NULL.
2169 */
2176
2177/* Internal data structure for isl_ast_build_expr_from_pw_aff_internal.
2178 *
2179 * "build" specifies the domain against which the result is simplified.
2180 * "dom" is the domain of the entire isl_pw_aff.
2181 *
2182 * "n" is the number of pieces constructed already.
2183 * In particular, during the construction of the pieces, "n" points to
2184 * the piece that is being constructed. After the construction of the
2185 * pieces, "n" is set to the total number of pieces.
2186 * "max" is the total number of allocated entries.
2187 * "p" contains the individual pieces.
2188 */
2197
2198/* Initialize "data" based on "build" and "pa".
2199 */
2202{
2203 isl_size n;
2204 isl_ctx *ctx;
2205
2206 ctx = isl_pw_aff_get_ctx(pa);
2208 if (n < 0)
2209 return isl_stat_error;
2210 if (n == 0)
2212 "cannot handle void expression", return isl_stat_error);
2213 data->max = n;
2214 data->p = isl_calloc_array(ctx, struct isl_from_pw_aff_piece, n);
2215 if (!data->p)
2216 return isl_stat_error;
2217 data->build = build;
2219 data->n = 0;
2220
2221 return isl_stat_ok;
2222}
2223
2224/* Free all memory allocated for "data".
2225 */
2227{
2228 int i;
2229
2230 isl_set_free(data->dom);
2231 if (!data->p)
2232 return;
2233
2234 for (i = 0; i < data->max; ++i) {
2235 isl_set_free(data->p[i].set);
2236 isl_set_list_free(data->p[i].set_list);
2237 isl_aff_list_free(data->p[i].aff_list);
2238 }
2239 free(data->p);
2240}
2241
2242/* Initialize the current entry of "data" to an unused piece.
2243 */
2244static void set_none(struct isl_from_pw_aff_data *data)
2245{
2246 data->p[data->n].state = isl_state_none;
2247 data->p[data->n].set_list = NULL;
2248 data->p[data->n].aff_list = NULL;
2249}
2250
2251/* Store "set" and "aff" in the current entry of "data" as a single subpiece.
2252 */
2253static void set_single(struct isl_from_pw_aff_data *data,
2255{
2256 data->p[data->n].state = isl_state_single;
2257 data->p[data->n].set_list = isl_set_list_from_set(set);
2258 data->p[data->n].aff_list = isl_aff_list_from_aff(aff);
2259}
2260
2261/* Extend the current entry of "data" with "set" and "aff"
2262 * as a minimum expression.
2263 */
2266{
2267 int n = data->n;
2268 data->p[n].state = isl_state_min;
2269 data->p[n].set_list = isl_set_list_add(data->p[n].set_list, set);
2270 data->p[n].aff_list = isl_aff_list_add(data->p[n].aff_list, aff);
2271
2272 if (!data->p[n].set_list || !data->p[n].aff_list)
2273 return isl_stat_error;
2274 return isl_stat_ok;
2275}
2276
2277/* Extend the current entry of "data" with "set" and "aff"
2278 * as a maximum expression.
2279 */
2282{
2283 int n = data->n;
2284 data->p[n].state = isl_state_max;
2285 data->p[n].set_list = isl_set_list_add(data->p[n].set_list, set);
2286 data->p[n].aff_list = isl_aff_list_add(data->p[n].aff_list, aff);
2287
2288 if (!data->p[n].set_list || !data->p[n].aff_list)
2289 return isl_stat_error;
2290 return isl_stat_ok;
2291}
2292
2293/* Extend the domain of the current entry of "data", which is assumed
2294 * to contain a single subpiece, with "set". If "replace" is set,
2295 * then also replace the affine function by "aff". Otherwise,
2296 * simply free "aff".
2297 */
2300{
2301 int n = data->n;
2302 isl_set *set_n;
2303
2304 set_n = isl_set_list_get_set(data->p[n].set_list, 0);
2305 set_n = isl_set_union(set_n, set);
2306 data->p[n].set_list =
2307 isl_set_list_set_set(data->p[n].set_list, 0, set_n);
2308
2309 if (replace)
2310 data->p[n].aff_list =
2311 isl_aff_list_set_aff(data->p[n].aff_list, 0, aff);
2312 else
2314
2315 if (!data->p[n].set_list || !data->p[n].aff_list)
2316 return isl_stat_error;
2317 return isl_stat_ok;
2318}
2319
2320/* Construct an isl_ast_expr from "list" within "build".
2321 * If "state" is isl_state_single, then "list" contains a single entry and
2322 * an isl_ast_expr is constructed for that entry.
2323 * Otherwise a min or max expression is constructed from "list"
2324 * depending on "state".
2325 */
2327 __isl_take isl_aff_list *list, enum isl_from_pw_aff_state state,
2329{
2330 int i;
2331 isl_size n;
2332 isl_aff *aff;
2333 isl_ast_expr *expr = NULL;
2334 enum isl_ast_expr_op_type op_type;
2335
2336 if (state == isl_state_single) {
2337 aff = isl_aff_list_get_aff(list, 0);
2338 isl_aff_list_free(list);
2339 return isl_ast_expr_from_aff(aff, build);
2340 }
2341 n = isl_aff_list_n_aff(list);
2342 if (n < 0)
2343 goto error;
2346 expr = isl_ast_expr_alloc_op(isl_ast_build_get_ctx(build), op_type, n);
2347
2348 for (i = 0; i < n; ++i) {
2349 isl_ast_expr *expr_i;
2350
2351 aff = isl_aff_list_get_aff(list, i);
2352 expr_i = isl_ast_expr_from_aff(aff, build);
2353 expr = isl_ast_expr_op_add_arg(expr, expr_i);
2354 }
2355
2356 isl_aff_list_free(list);
2357 return expr;
2358error:
2359 isl_aff_list_free(list);
2360 isl_ast_expr_free(expr);
2361 return NULL;
2362}
2363
2364/* Extend the list of expressions in "next" to take into account
2365 * the piece at position "pos" in "data", allowing for a further extension
2366 * for the next piece(s).
2367 * In particular, "next" is extended with a select operation that selects
2368 * an isl_ast_expr corresponding to data->aff_list on data->set and
2369 * to an expression that will be filled in by later calls.
2370 * Return a pointer to the arguments of this select operation.
2371 * Afterwards, the state of "data" is set to isl_state_none.
2372 *
2373 * The constraints of data->set are added to the generated
2374 * constraints of the build such that they can be exploited to simplify
2375 * the AST expression constructed from data->aff_list.
2376 */
2377static isl_ast_expr_list **add_intermediate_piece(
2378 struct isl_from_pw_aff_data *data,
2379 int pos, isl_ast_expr_list **next)
2380{
2381 isl_ctx *ctx;
2382 isl_ast_build *build;
2384 isl_set *set, *gist;
2385
2386 set = data->p[pos].set;
2387 data->p[pos].set = NULL;
2388 ctx = isl_ast_build_get_ctx(data->build);
2393 build = isl_ast_build_copy(data->build);
2394 build = isl_ast_build_restrict_generated(build, set);
2396 data->p[pos].state, build);
2397 data->p[pos].aff_list = NULL;
2398 isl_ast_build_free(build);
2400 data->p[pos].state = isl_state_none;
2401 if (!ternary)
2402 return NULL;
2403
2404 *next = isl_ast_expr_list_add(*next, ternary);
2405 return &ternary->u.op.args;
2406}
2407
2408/* Extend the list of expressions in "next" to take into account
2409 * the final piece, located at position "pos" in "data".
2410 * In particular, "next" is extended with an expression
2411 * to evaluate data->aff_list and the domain is ignored.
2412 * Return isl_stat_ok on success and isl_stat_error on failure.
2413 *
2414 * The constraints of data->set are however added to the generated
2415 * constraints of the build such that they can be exploited to simplify
2416 * the AST expression constructed from data->aff_list.
2417 */
2419 int pos, isl_ast_expr_list **next)
2420{
2421 isl_ast_build *build;
2422 isl_ast_expr *last;
2423
2424 if (data->p[pos].state == isl_state_none)
2426 "cannot handle void expression", return isl_stat_error);
2427
2428 build = isl_ast_build_copy(data->build);
2429 build = isl_ast_build_restrict_generated(build, data->p[pos].set);
2430 data->p[pos].set = NULL;
2431 last = ast_expr_from_aff_list(data->p[pos].aff_list,
2432 data->p[pos].state, build);
2433 *next = isl_ast_expr_list_add(*next, last);
2434 data->p[pos].aff_list = NULL;
2435 isl_ast_build_free(build);
2436 data->p[pos].state = isl_state_none;
2437 if (!*next)
2438 return isl_stat_error;
2439
2440 return isl_stat_ok;
2441}
2442
2443/* Return -1 if the piece "p1" should be sorted before "p2"
2444 * and 1 if it should be sorted after "p2".
2445 * Return 0 if they do not need to be sorted in a specific order.
2446 *
2447 * Pieces are sorted according to the number of disjuncts
2448 * in their domains.
2449 */
2450static int sort_pieces_cmp(const void *p1, const void *p2, void *arg)
2451{
2452 const struct isl_from_pw_aff_piece *piece1 = p1;
2453 const struct isl_from_pw_aff_piece *piece2 = p2;
2454 isl_size n1, n2;
2455
2456 n1 = isl_set_n_basic_set(piece1->set);
2457 n2 = isl_set_n_basic_set(piece2->set);
2458
2459 return n1 - n2;
2460}
2461
2462/* Construct an isl_ast_expr from the pieces in "data".
2463 * Return the result or NULL on failure.
2464 *
2465 * When this function is called, data->n points to the current piece.
2466 * If this is an effective piece, then first increment data->n such
2467 * that data->n contains the number of pieces.
2468 * The "set_list" fields are subsequently replaced by the corresponding
2469 * "set" fields, after which the pieces are sorted according to
2470 * the number of disjuncts in these "set" fields.
2471 *
2472 * Construct intermediate AST expressions for the initial pieces and
2473 * finish off with the final pieces.
2474 *
2475 * Any piece that is not the very first is added to the list of arguments
2476 * of the previously constructed piece.
2477 * In order not to have to special case the first piece,
2478 * an extra list is created to hold the final result.
2479 */
2481{
2482 int i;
2483 isl_ctx *ctx;
2484 isl_ast_expr_list *res_list;
2485 isl_ast_expr_list **next = &res_list;
2487
2488 if (data->p[data->n].state != isl_state_none)
2489 data->n++;
2490 ctx = isl_ast_build_get_ctx(data->build);
2491 if (data->n == 0)
2493 "cannot handle void expression", return NULL);
2494
2495 for (i = 0; i < data->n; ++i) {
2496 data->p[i].set = isl_set_list_union(data->p[i].set_list);
2497 if (data->p[i].state != isl_state_single)
2498 data->p[i].set = isl_set_coalesce(data->p[i].set);
2499 data->p[i].set_list = NULL;
2500 }
2501
2502 if (isl_sort(data->p, data->n, sizeof(data->p[0]),
2503 &sort_pieces_cmp, NULL) < 0)
2504 return NULL;
2505
2506 res_list = isl_ast_expr_list_alloc(ctx, 1);
2507 if (!res_list)
2508 return NULL;
2509 for (i = 0; i + 1 < data->n; ++i) {
2510 next = add_intermediate_piece(data, i, next);
2511 if (!next)
2512 goto error;
2513 }
2514
2515 if (add_last_piece(data, data->n - 1, next) < 0)
2516 goto error;
2517
2518 res = isl_ast_expr_list_get_at(res_list, 0);
2519 isl_ast_expr_list_free(res_list);
2520 return res;
2521error:
2522 isl_ast_expr_list_free(res_list);
2523 return NULL;
2524}
2525
2526/* Is the domain of the current entry of "data", which is assumed
2527 * to contain a single subpiece, a subset of "set"?
2528 */
2531{
2533 isl_set *set_n;
2534
2535 set_n = isl_set_list_get_set(data->p[data->n].set_list, 0);
2536 subset = isl_set_is_subset(set_n, set);
2537 isl_set_free(set_n);
2538
2539 return subset;
2540}
2541
2542/* Is "aff" a rational expression, i.e., does it have a denominator
2543 * different from one?
2544 */
2546{
2547 isl_bool rational;
2548 isl_val *den;
2549
2551 rational = isl_bool_not(isl_val_is_one(den));
2552 isl_val_free(den);
2553
2554 return rational;
2555}
2556
2557/* Does "list" consist of a single rational affine expression?
2558 */
2560{
2561 isl_size n;
2562 isl_bool rational;
2563 isl_aff *aff;
2564
2565 n = isl_aff_list_n_aff(list);
2566 if (n < 0)
2567 return isl_bool_error;
2568 if (n != 1)
2569 return isl_bool_false;
2570 aff = isl_aff_list_get_aff(list, 0);
2571 rational = aff_is_rational(aff);
2573
2574 return rational;
2575}
2576
2577/* Can the list of subpieces in the last piece of "data" be extended with
2578 * "set" and "aff" based on "test"?
2579 * In particular, is it the case for each entry (set_i, aff_i) that
2580 *
2581 * test(aff, aff_i) holds on set_i, and
2582 * test(aff_i, aff) holds on set?
2583 *
2584 * "test" returns the set of elements where the tests holds, meaning
2585 * that test(aff_i, aff) holds on set if set is a subset of test(aff_i, aff).
2586 *
2587 * This function is used to detect min/max expressions.
2588 * If the ast_build_detect_min_max option is turned off, then
2589 * do not even try and perform any detection and return false instead.
2590 *
2591 * Rational affine expressions are not considered for min/max expressions
2592 * since the combined expression will be defined on the union of the domains,
2593 * while a rational expression may only yield integer values
2594 * on its own definition domain.
2595 */
2599 __isl_take isl_aff *aff2))
2600{
2601 int i;
2602 isl_size n;
2604 isl_ctx *ctx;
2605 isl_set *dom;
2606
2608 if (is_rational >= 0 && !is_rational)
2610 if (is_rational < 0 || is_rational)
2611 return isl_bool_not(is_rational);
2612
2613 ctx = isl_ast_build_get_ctx(data->build);
2615 return isl_bool_false;
2616
2617 n = isl_set_list_n_set(data->p[data->n].set_list);
2618 if (n < 0)
2619 return isl_bool_error;
2620
2621 dom = isl_ast_build_get_domain(data->build);
2623
2624 for (i = 0; i < n ; ++i) {
2625 isl_aff *aff_i;
2626 isl_set *valid;
2627 isl_set *dom, *required;
2628 isl_bool is_valid;
2629
2630 aff_i = isl_aff_list_get_aff(data->p[data->n].aff_list, i);
2631 valid = isl_set_from_basic_set(test(isl_aff_copy(aff), aff_i));
2632 required = isl_set_list_get_set(data->p[data->n].set_list, i);
2633 dom = isl_ast_build_get_domain(data->build);
2634 required = isl_set_intersect(dom, required);
2635 is_valid = isl_set_is_subset(required, valid);
2636 isl_set_free(required);
2637 isl_set_free(valid);
2638 if (is_valid < 0 || !is_valid) {
2640 return is_valid;
2641 }
2642
2643 aff_i = isl_aff_list_get_aff(data->p[data->n].aff_list, i);
2644 valid = isl_set_from_basic_set(test(aff_i, isl_aff_copy(aff)));
2645 is_valid = isl_set_is_subset(set, valid);
2646 isl_set_free(valid);
2647 if (is_valid < 0 || !is_valid) {
2649 return is_valid;
2650 }
2651 }
2652
2654 return isl_bool_true;
2655}
2656
2657/* Can the list of pieces in "data" be extended with "set" and "aff"
2658 * to form/preserve a minimum expression?
2659 * In particular, is it the case for each entry (set_i, aff_i) that
2660 *
2661 * aff >= aff_i on set_i, and
2662 * aff_i >= aff on set?
2663 */
2666{
2667 return extends(data, set, aff, &isl_aff_ge_basic_set);
2668}
2669
2670/* Can the list of pieces in "data" be extended with "set" and "aff"
2671 * to form/preserve a maximum expression?
2672 * In particular, is it the case for each entry (set_i, aff_i) that
2673 *
2674 * aff <= aff_i on set_i, and
2675 * aff_i <= aff on set?
2676 */
2679{
2680 return extends(data, set, aff, &isl_aff_le_basic_set);
2681}
2682
2683/* This function is called during the construction of an isl_ast_expr
2684 * that evaluates an isl_pw_aff.
2685 * If the last piece of "data" contains a single subpiece and
2686 * if its affine function is equal to "aff" on a part of the domain
2687 * that includes either "set" or the domain of that single subpiece,
2688 * then extend the domain of that single subpiece with "set".
2689 * If it was the original domain of the single subpiece where
2690 * the two affine functions are equal, then also replace
2691 * the affine function of the single subpiece by "aff".
2692 * If the last piece of "data" contains either a single subpiece
2693 * or a minimum, then check if this minimum expression can be extended
2694 * with (set, aff).
2695 * If so, extend the sequence and return.
2696 * Perform the same operation for maximum expressions.
2697 * If no such extension can be performed, then move to the next piece
2698 * in "data" (if the current piece contains any data), and then store
2699 * the current subpiece in the current piece of "data" for later handling.
2700 */
2702 __isl_take isl_aff *aff, void *user)
2703{
2704 struct isl_from_pw_aff_data *data = user;
2705 isl_bool test;
2706 enum isl_from_pw_aff_state state;
2707
2708 state = data->p[data->n].state;
2709 if (state == isl_state_single) {
2710 isl_aff *aff0;
2711 isl_set *eq;
2712 isl_bool subset1, subset2 = isl_bool_false;
2713 aff0 = isl_aff_list_get_aff(data->p[data->n].aff_list, 0);
2714 eq = isl_aff_eq_set(isl_aff_copy(aff), aff0);
2715 subset1 = isl_set_is_subset(set, eq);
2716 if (subset1 >= 0 && !subset1)
2717 subset2 = single_is_subset(data, eq);
2718 isl_set_free(eq);
2719 if (subset1 < 0 || subset2 < 0)
2720 goto error;
2721 if (subset1)
2722 return extend_domain(data, set, aff, 0);
2723 if (subset2)
2724 return extend_domain(data, set, aff, 1);
2725 }
2726 if (state == isl_state_single || state == isl_state_min) {
2727 test = extends_min(data, set, aff);
2728 if (test < 0)
2729 goto error;
2730 if (test)
2731 return extend_min(data, set, aff);
2732 }
2733 if (state == isl_state_single || state == isl_state_max) {
2734 test = extends_max(data, set, aff);
2735 if (test < 0)
2736 goto error;
2737 if (test)
2738 return extend_max(data, set, aff);
2739 }
2740 if (state != isl_state_none)
2741 data->n++;
2742 set_single(data, set, aff);
2743
2744 return isl_stat_ok;
2745error:
2748 return isl_stat_error;
2749}
2750
2751/* Construct an isl_ast_expr that evaluates "pa".
2752 * The result is simplified in terms of build->domain.
2753 *
2754 * The domain of "pa" lives in the internal schedule space.
2755 */
2758{
2759 struct isl_from_pw_aff_data data = { NULL };
2760 isl_ast_expr *res = NULL;
2761
2764 if (!pa)
2765 return NULL;
2766
2767 if (isl_from_pw_aff_data_init(&data, build, pa) < 0)
2768 goto error;
2769 set_none(&data);
2770
2772 res = build_pieces(&data);
2773
2776 return res;
2777error:
2780 return NULL;
2781}
2782
2783/* Construct an isl_ast_expr that evaluates "pa".
2784 * The result is simplified in terms of build->domain.
2785 *
2786 * The domain of "pa" lives in the external schedule space.
2787 */
2790{
2791 isl_ast_expr *expr;
2792 isl_bool needs_map;
2793
2795 if (needs_map < 0) {
2797 } else if (needs_map) {
2801 }
2803 return expr;
2804}
2805
2806/* Set the ids of the input dimensions of "mpa" to the iterator ids
2807 * of "build".
2808 *
2809 * The domain of "mpa" is assumed to live in the internal schedule domain.
2810 */
2813{
2814 int i;
2815 isl_size n;
2816
2817 n = isl_multi_pw_aff_dim(mpa, isl_dim_in);
2818 if (n < 0)
2819 return isl_multi_pw_aff_free(mpa);
2820 for (i = 0; i < n; ++i) {
2821 isl_id *id;
2822
2824 mpa = isl_multi_pw_aff_set_dim_id(mpa, isl_dim_in, i, id);
2825 }
2826
2827 return mpa;
2828}
2829
2830/* Construct an isl_ast_expr of type "type" with as first argument "arg0" and
2831 * the remaining arguments derived from "mpa".
2832 * That is, construct a call or access expression that calls/accesses "arg0"
2833 * with arguments/indices specified by "mpa".
2834 */
2838{
2839 int i;
2840 isl_size n;
2841 isl_ctx *ctx;
2842 isl_ast_expr *expr;
2843
2845
2846 n = isl_multi_pw_aff_dim(mpa, isl_dim_out);
2847 expr = n >= 0 ? isl_ast_expr_alloc_op(ctx, type, 1 + n) : NULL;
2848 expr = isl_ast_expr_op_add_arg(expr, arg0);
2849 for (i = 0; i < n; ++i) {
2850 isl_pw_aff *pa;
2852
2853 pa = isl_multi_pw_aff_get_pw_aff(mpa, i);
2855 expr = isl_ast_expr_op_add_arg(expr, arg);
2856 }
2857
2858 isl_multi_pw_aff_free(mpa);
2859 return expr;
2860}
2861
2865
2866/* Construct an isl_ast_expr that accesses the member specified by "mpa".
2867 * The range of "mpa" is assumed to be wrapped relation.
2868 * The domain of this wrapped relation specifies the structure being
2869 * accessed, while the range of this wrapped relation spacifies the
2870 * member of the structure being accessed.
2871 *
2872 * The domain of "mpa" is assumed to live in the internal schedule domain.
2873 */
2876{
2877 isl_id *id;
2879 isl_ast_expr *domain_expr, *expr;
2881
2882 domain = isl_multi_pw_aff_copy(mpa);
2883 domain = isl_multi_pw_aff_range_factor_domain(domain);
2885 type, domain);
2886 mpa = isl_multi_pw_aff_range_factor_range(mpa);
2887 if (!isl_multi_pw_aff_has_tuple_id(mpa, isl_dim_out))
2889 "missing field name", goto error);
2890 id = isl_multi_pw_aff_get_tuple_id(mpa, isl_dim_out);
2891 expr = isl_ast_expr_from_id(id);
2893 domain_expr, expr);
2894 return isl_ast_build_with_arguments(build, type, expr, mpa);
2895error:
2896 isl_multi_pw_aff_free(mpa);
2897 return NULL;
2898}
2899
2900/* Construct an isl_ast_expr of type "type" that calls or accesses
2901 * the element specified by "mpa".
2902 * The first argument is obtained from the output tuple name.
2903 * The remaining arguments are given by the piecewise affine expressions.
2904 *
2905 * If the range of "mpa" is a mapped relation, then we assume it
2906 * represents an access to a member of a structure.
2907 *
2908 * The domain of "mpa" is assumed to live in the internal schedule domain.
2909 */
2913{
2914 isl_ctx *ctx;
2915 isl_id *id;
2916 isl_ast_expr *expr;
2917
2918 if (!mpa)
2919 goto error;
2920
2922 isl_multi_pw_aff_range_is_wrapping(mpa))
2924
2925 mpa = set_iterator_names(build, mpa);
2926 if (!build || !mpa)
2927 goto error;
2928
2930
2931 if (isl_multi_pw_aff_has_tuple_id(mpa, isl_dim_out))
2932 id = isl_multi_pw_aff_get_tuple_id(mpa, isl_dim_out);
2933 else
2934 id = isl_id_alloc(ctx, "", NULL);
2935
2936 expr = isl_ast_expr_from_id(id);
2937 return isl_ast_build_with_arguments(build, type, expr, mpa);
2938error:
2939 isl_multi_pw_aff_free(mpa);
2940 return NULL;
2941}
2942
2943/* Construct an isl_ast_expr of type "type" that calls or accesses
2944 * the element specified by "pma".
2945 * The first argument is obtained from the output tuple name.
2946 * The remaining arguments are given by the piecewise affine expressions.
2947 *
2948 * The domain of "pma" is assumed to live in the internal schedule domain.
2949 */
2959
2960/* Construct an isl_ast_expr of type "type" that calls or accesses
2961 * the element specified by "mpa".
2962 * The first argument is obtained from the output tuple name.
2963 * The remaining arguments are given by the piecewise affine expressions.
2964 *
2965 * The domain of "mpa" is assumed to live in the external schedule domain.
2966 */
2970{
2971 isl_bool is_domain;
2972 isl_bool needs_map;
2973 isl_ast_expr *expr;
2974 isl_space *space_build, *space_mpa;
2975
2976 space_build = isl_ast_build_get_space(build, 0);
2977 space_mpa = isl_multi_pw_aff_get_space(mpa);
2978 is_domain = isl_space_tuple_is_equal(space_build, isl_dim_set,
2979 space_mpa, isl_dim_in);
2980 isl_space_free(space_build);
2981 isl_space_free(space_mpa);
2982 if (is_domain < 0)
2983 goto error;
2984 if (!is_domain)
2986 "spaces don't match", goto error);
2987
2989 if (needs_map < 0)
2990 goto error;
2991 if (needs_map) {
2995 }
2996
2998 return expr;
2999error:
3000 isl_multi_pw_aff_free(mpa);
3001 return NULL;
3002}
3003
3004/* Construct an isl_ast_expr that calls the domain element specified by "mpa".
3005 * The name of the function is obtained from the output tuple name.
3006 * The arguments are given by the piecewise affine expressions.
3007 *
3008 * The domain of "mpa" is assumed to live in the external schedule domain.
3009 */
3016
3017/* Construct an isl_ast_expr that accesses the array element specified by "mpa".
3018 * The name of the array is obtained from the output tuple name.
3019 * The index expressions are given by the piecewise affine expressions.
3020 *
3021 * The domain of "mpa" is assumed to live in the external schedule domain.
3022 */
3029
3030/* Construct an isl_ast_expr of type "type" that calls or accesses
3031 * the element specified by "pma".
3032 * The first argument is obtained from the output tuple name.
3033 * The remaining arguments are given by the piecewise affine expressions.
3034 *
3035 * The domain of "pma" is assumed to live in the external schedule domain.
3036 */
3046
3047/* Construct an isl_ast_expr that calls the domain element specified by "pma".
3048 * The name of the function is obtained from the output tuple name.
3049 * The arguments are given by the piecewise affine expressions.
3050 *
3051 * The domain of "pma" is assumed to live in the external schedule domain.
3052 */
3059
3060/* Construct an isl_ast_expr that accesses the array element specified by "pma".
3061 * The name of the array is obtained from the output tuple name.
3062 * The index expressions are given by the piecewise affine expressions.
3063 *
3064 * The domain of "pma" is assumed to live in the external schedule domain.
3065 */
3072
3073/* Construct an isl_ast_expr that calls the domain element
3074 * specified by "executed".
3075 *
3076 * "executed" is assumed to be single-valued, with a domain that lives
3077 * in the internal schedule space.
3078 */
static void replace(std::string &str, StringRef find, StringRef replace)
__isl_give isl_aff * isl_aff_add_constant_si(__isl_take isl_aff *aff, int v)
Definition isl_aff.c:1099
isl_ctx * isl_aff_get_ctx(__isl_keep isl_aff *aff)
Definition isl_aff.c:465
__isl_null isl_aff * isl_aff_free(__isl_take isl_aff *aff)
Definition isl_aff.c:449
isl_ctx * isl_pw_aff_get_ctx(__isl_keep isl_pw_aff *pwaff)
__isl_give isl_local_space * isl_aff_get_domain_local_space(__isl_keep isl_aff *aff)
Definition isl_aff.c:586
__isl_export __isl_give isl_pw_multi_aff * isl_pw_multi_aff_intersect_domain(__isl_take isl_pw_multi_aff *pma, __isl_take isl_set *set)
__isl_give isl_aff * isl_aff_val_on_domain(__isl_take isl_local_space *ls, __isl_take isl_val *val)
Definition isl_aff.c:331
__isl_give isl_aff * isl_aff_set_constant_si(__isl_take isl_aff *aff, int v)
Definition isl_aff.c:1160
__isl_give isl_val * isl_aff_get_coefficient_val(__isl_keep isl_aff *aff, enum isl_dim_type type, int pos)
Definition isl_aff.c:852
__isl_give isl_aff * isl_aff_var_on_domain(__isl_take isl_local_space *ls, enum isl_dim_type type, unsigned pos)
Definition isl_aff.c:370
__isl_overload __isl_give isl_pw_aff * isl_pw_aff_pullback_multi_aff(__isl_take isl_pw_aff *pa, __isl_take isl_multi_aff *ma)
__isl_export __isl_give isl_aff * isl_aff_neg(__isl_take isl_aff *aff)
Definition isl_aff.c:1451
__isl_overload __isl_give isl_aff * isl_aff_add_constant_val(__isl_take isl_aff *aff, __isl_take isl_val *v)
Definition isl_aff.c:1070
__isl_export isl_bool isl_aff_plain_is_equal(__isl_keep isl_aff *aff1, __isl_keep isl_aff *aff2)
Definition isl_aff.c:784
__isl_overload __isl_give isl_aff * isl_aff_scale_val(__isl_take isl_aff *aff, __isl_take isl_val *v)
Definition isl_aff.c:2075
__isl_give isl_val * isl_aff_get_denominator_val(__isl_keep isl_aff *aff)
Definition isl_aff.c:819
isl_stat isl_pw_aff_foreach_piece(__isl_keep isl_pw_aff *pwaff, isl_stat(*fn)(__isl_take isl_set *set, __isl_take isl_aff *aff, void *user), void *user)
__isl_give isl_aff * isl_aff_set_coefficient_si(__isl_take isl_aff *aff, enum isl_dim_type type, int pos, int v)
Definition isl_aff.c:1221
__isl_null isl_pw_aff * isl_pw_aff_free(__isl_take isl_pw_aff *pwaff)
__isl_overload __isl_give isl_aff * isl_aff_scale_down_val(__isl_take isl_aff *aff, __isl_take isl_val *v)
Definition isl_aff.c:2142
__isl_give isl_basic_set * isl_aff_ge_basic_set(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2)
Definition isl_aff.c:2477
__isl_give isl_aff * isl_aff_copy(__isl_keep isl_aff *aff)
Definition isl_aff.c:145
__isl_give isl_aff * isl_aff_zero_on_domain(__isl_take isl_local_space *ls)
Definition isl_aff.c:235
isl_size isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type)
Definition isl_aff.c:509
__isl_export __isl_give isl_aff * isl_aff_sub(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2)
Definition isl_aff.c:2029
__isl_constructor __isl_give isl_multi_pw_aff * isl_multi_pw_aff_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma)
Definition isl_aff.c:7106
__isl_export __isl_give isl_val * isl_aff_get_constant_val(__isl_keep isl_aff *aff)
Definition isl_aff.c:834
__isl_give isl_pw_multi_aff * isl_pw_multi_aff_from_map(__isl_take isl_map *map)
Definition isl_aff.c:5617
__isl_export __isl_give isl_aff * isl_aff_add(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2)
Definition isl_aff.c:1976
__isl_export __isl_give isl_set * isl_aff_eq_set(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2)
Definition isl_aff.c:2567
int isl_aff_coefficient_sgn(__isl_keep isl_aff *aff, enum isl_dim_type type, int pos)
Definition isl_aff.c:882
__isl_give isl_basic_set * isl_aff_le_basic_set(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2)
Definition isl_aff.c:2520
__isl_export __isl_give isl_pw_aff * isl_pw_aff_coalesce(__isl_take isl_pw_aff *pa)
isl_bool isl_aff_involves_dims(__isl_keep isl_aff *aff, enum isl_dim_type type, unsigned first, unsigned n)
__isl_give isl_aff * isl_aff_get_div(__isl_keep isl_aff *aff, int pos)
Definition isl_aff.c:1439
isl_size isl_pw_aff_n_piece(__isl_keep isl_pw_aff *pwaff)
__isl_export __isl_give isl_set * isl_pw_aff_domain(__isl_take isl_pw_aff *pwaff)
__isl_overload __isl_give isl_multi_pw_aff * isl_multi_pw_aff_pullback_multi_aff(__isl_take isl_multi_pw_aff *mpa, __isl_take isl_multi_aff *ma)
__isl_give isl_pw_aff * isl_pw_aff_copy(__isl_keep isl_pw_aff *pwaff)
__isl_give isl_aff * isl_aff_set_constant_val(__isl_take isl_aff *aff, __isl_take isl_val *v)
Definition isl_aff.c:932
struct isl_multi_aff isl_multi_aff
Definition aff_type.h:29
struct isl_multi_pw_aff isl_multi_pw_aff
Definition aff_type.h:43
__isl_null isl_ast_expr * isl_ast_expr_free(__isl_take isl_ast_expr *expr)
Definition isl_ast.c:243
__isl_give isl_ast_expr * isl_ast_expr_neg(__isl_take isl_ast_expr *expr)
Definition isl_ast.c:642
__isl_give isl_ast_expr * isl_ast_expr_or(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2)
Definition isl_ast.c:763
__isl_give isl_ast_expr * isl_ast_expr_mul(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2)
Definition isl_ast.c:710
__isl_give isl_ast_expr * isl_ast_expr_add(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2)
Definition isl_ast.c:694
__isl_give isl_ast_expr * isl_ast_expr_from_id(__isl_take isl_id *id)
Definition isl_ast.c:541
__isl_give isl_ast_expr * isl_ast_expr_sub(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2)
Definition isl_ast.c:702
__isl_give isl_ast_expr * isl_ast_expr_from_val(__isl_take isl_val *v)
Definition isl_ast.c:589
__isl_give isl_ast_expr * isl_ast_expr_and(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2)
Definition isl_ast.c:746
__isl_give isl_ast_node * isl_ast_node_alloc_user(__isl_take isl_ast_expr *expr)
Definition isl_ast.c:1030
__isl_give isl_ast_build * isl_ast_build_copy(__isl_keep isl_ast_build *build)
__isl_null isl_ast_build * isl_ast_build_free(__isl_take isl_ast_build *build)
isl_ctx * isl_ast_build_get_ctx(__isl_keep isl_ast_build *build)
int isl_options_get_ast_build_prefer_pdiv(isl_ctx *ctx)
int isl_options_get_ast_build_detect_min_max(isl_ctx *ctx)
@ isl_ast_expr_int
Definition ast_type.h:79
isl_ast_expr_op_type
Definition ast_type.h:16
@ isl_ast_expr_op_member
Definition ast_type.h:42
@ isl_ast_expr_op_pdiv_r
Definition ast_type.h:31
@ isl_ast_expr_op_min
Definition ast_type.h:23
@ isl_ast_expr_op_fdiv_q
Definition ast_type.h:29
@ isl_ast_expr_op_call
Definition ast_type.h:40
@ isl_ast_expr_op_le
Definition ast_type.h:36
@ isl_ast_expr_op_ge
Definition ast_type.h:38
@ isl_ast_expr_op_div
Definition ast_type.h:28
@ isl_ast_expr_op_select
Definition ast_type.h:34
@ isl_ast_expr_op_max
Definition ast_type.h:22
@ isl_ast_expr_op_access
Definition ast_type.h:41
@ isl_ast_expr_op_zdiv_r
Definition ast_type.h:32
@ isl_ast_expr_op_eq
Definition ast_type.h:35
@ isl_ast_expr_op_pdiv_q
Definition ast_type.h:30
isl_size isl_constraint_dim(__isl_keep isl_constraint *constraint, enum isl_dim_type type)
int isl_constraint_plain_cmp(__isl_keep isl_constraint *c1, __isl_keep isl_constraint *c2)
__isl_null isl_constraint * isl_constraint_free(__isl_take isl_constraint *c)
__isl_give isl_constraint * isl_constraint_copy(__isl_keep isl_constraint *c)
__isl_give isl_val * isl_constraint_get_constant_val(__isl_keep isl_constraint *constraint)
isl_bool isl_constraint_involves_dims(__isl_keep isl_constraint *constraint, enum isl_dim_type type, unsigned first, unsigned n)
__isl_give isl_constraint_list * isl_basic_set_get_constraint_list(__isl_keep isl_basic_set *bset)
isl_stat isl_basic_set_foreach_constraint(__isl_keep isl_basic_set *bset, isl_stat(*fn)(__isl_take isl_constraint *c, void *user), void *user)
__isl_give isl_basic_set * isl_basic_set_from_constraint(__isl_take isl_constraint *constraint)
__isl_give isl_val * isl_constraint_get_coefficient_val(__isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos)
__isl_give isl_aff * isl_constraint_get_aff(__isl_keep isl_constraint *constraint)
int isl_constraint_cmp_last_non_zero(__isl_keep isl_constraint *c1, __isl_keep isl_constraint *c2)
isl_bool isl_constraint_is_equality(__isl_keep isl_constraint *constraint)
isl_stat isl_stat_non_null(void *obj)
Definition isl_ctx.c:34
#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:138
isl_bool isl_bool_ok(int b)
Definition isl_ctx.c:58
@ isl_error_invalid
Definition ctx.h:80
@ isl_error_internal
Definition ctx.h:79
#define isl_calloc_array(ctx, type, n)
Definition ctx.h:133
#define __isl_keep
Definition ctx.h:25
int isl_size
Definition ctx.h:97
isl_stat isl_stat_non_error_bool(isl_bool b)
Definition isl_ctx.c:22
isl_bool isl_bool_not(isl_bool b)
Definition isl_ctx.c:44
isl_bool
Definition ctx.h:89
@ isl_bool_false
Definition ctx.h:91
@ isl_bool_true
Definition ctx.h:92
@ isl_bool_error
Definition ctx.h:90
isl_stat isl_stat(* fn)(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user)
Definition hmap.h:37
isl_stat isl_stat void * user
Definition hmap.h:39
isl_bool isl_bool(* test)(__isl_keep ISL_KEY *key, __isl_keep ISL_VAL *val, void *user)
Definition hmap.h:41
__isl_give isl_id * isl_id_alloc(isl_ctx *ctx, __isl_keep const char *name, void *user)
__isl_export __isl_give isl_val * isl_set_min_val(__isl_keep isl_set *set, __isl_keep isl_aff *obj)
Definition isl_ilp.c:600
int GMPQAPI cmp(mp_rat op1, mp_rat op2)
void GMPZAPI neg(mp_int rop, mp_int op)
void GMPQAPI init(mp_rat x)
enum isl_ast_expr_type isl_ast_expr_get_type(__isl_keep isl_ast_expr *expr)
Definition isl_ast.c:276
__isl_give isl_ast_expr * isl_ast_expr_op_add_arg(__isl_take isl_ast_expr *expr, __isl_take isl_ast_expr *arg)
Definition isl_ast.c:448
__isl_give isl_ast_expr * isl_ast_expr_alloc_int_si(isl_ctx *ctx, int i)
Definition isl_ast.c:568
__isl_give isl_ast_expr * isl_ast_expr_alloc_binary(enum isl_ast_expr_op_type type, __isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2)
Definition isl_ast.c:666
__isl_give isl_ast_expr * isl_ast_expr_alloc_op(isl_ctx *ctx, enum isl_ast_expr_op_type op, int n_arg)
Definition isl_ast.c:186
isl_bool isl_ast_build_need_schedule_map(__isl_keep isl_ast_build *build)
isl_bool isl_ast_build_aff_is_nonneg(__isl_keep isl_ast_build *build, __isl_keep isl_aff *aff)
__isl_give isl_pw_aff * isl_ast_build_compute_gist_pw_aff(__isl_keep isl_ast_build *build, __isl_take isl_pw_aff *pa)
__isl_give isl_set * isl_ast_build_compute_gist(__isl_keep isl_ast_build *build, __isl_take isl_set *set)
__isl_give isl_space * isl_ast_build_get_space(__isl_keep isl_ast_build *build, int internal)
__isl_give isl_set * isl_ast_build_get_domain(__isl_keep isl_ast_build *build)
__isl_give isl_ast_build * isl_ast_build_restrict_generated(__isl_take isl_ast_build *build, __isl_take isl_set *set)
__isl_give isl_id * isl_ast_build_get_iterator_id(__isl_keep isl_ast_build *build, int pos)
__isl_give isl_pw_multi_aff * isl_ast_build_compute_gist_pw_multi_aff(__isl_keep isl_ast_build *build, __isl_take isl_pw_multi_aff *pma)
__isl_give isl_multi_aff * isl_ast_build_get_schedule_map_multi_aff(__isl_keep isl_ast_build *build)
static isl_bool extends(struct isl_from_pw_aff_data *data, __isl_keep isl_set *set, __isl_keep isl_aff *aff, __isl_give isl_basic_set *(*test)(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2))
static __isl_give isl_ast_expr * var(struct isl_ast_add_term_data *data, enum isl_dim_type type, int pos)
isl_from_pw_aff_state
@ isl_state_none
@ isl_state_max
@ isl_state_single
@ isl_state_min
static isl_bool parallel_or_opposite_scan(struct isl_parallel_stat *stat, isl_bool(*fn)(struct isl_parallel_stat *stat, enum isl_dim_type c_type, enum isl_dim_type a_type, int i), int init)
static isl_stat extend_min(struct isl_from_pw_aff_data *data, __isl_take isl_set *set, __isl_take isl_aff *aff)
static __isl_give isl_val * update_is_partial(struct isl_parallel_stat *stat, __isl_take isl_val *v1, __isl_keep isl_val *v2)
static __isl_give isl_ast_expr * isl_ast_expr_from_constraint_no_stride(int eq, __isl_take isl_aff *aff, __isl_keep isl_ast_build *build)
static isl_bool aff_is_rational(__isl_keep isl_aff *aff)
static __isl_give isl_ast_expr * isl_ast_build_from_multi_pw_aff_internal(__isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_multi_pw_aff *mpa)
static __isl_give isl_ast_expr * construct_constraint_expr(int eq, __isl_take isl_ast_expr *expr_pos, __isl_take isl_ast_expr *expr_neg)
__isl_give isl_ast_expr * isl_ast_build_expr_from_pw_aff_internal(__isl_keep isl_ast_build *build, __isl_take isl_pw_aff *pa)
static __isl_give isl_ast_expr * isl_ast_expr_add_term(__isl_take isl_ast_expr *expr, enum isl_dim_type type, int pos, __isl_take isl_val *v, struct isl_ast_add_term_data *data)
static isl_stat extend_domain(struct isl_from_pw_aff_data *data, __isl_take isl_set *set, __isl_take isl_aff *aff, int replace)
static isl_bool add_term(enum isl_dim_type type, int pos, __isl_take isl_val *v, void *user)
static isl_bool every_non_zero_coefficient(__isl_keep isl_aff *aff, int reverse, isl_bool(*fn)(enum isl_dim_type type, int pos, __isl_take isl_val *v, void *user), void *user)
static isl_stat check_parallel_or_opposite(struct isl_extract_mod_data *data, __isl_keep isl_constraint *c)
__isl_give isl_ast_expr * isl_ast_build_call_from_pw_multi_aff(__isl_keep isl_ast_build *build, __isl_take isl_pw_multi_aff *pma)
static isl_bool clear_opposite_sign(enum isl_dim_type type, int pos, __isl_take isl_val *v, void *user)
static void set_single(struct isl_from_pw_aff_data *data, __isl_take isl_set *set, __isl_take isl_aff *aff)
static isl_stat replace_nonneg(struct isl_extract_mod_data *data, __isl_take isl_aff *aff, int sign)
static __isl_give isl_ast_expr * isl_ast_build_from_multi_pw_aff_member(__isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa)
static __isl_give isl_aff * extract_rational(__isl_take isl_aff *aff, __isl_keep isl_ast_expr **expr, __isl_keep isl_ast_build *build)
static isl_bool ast_expr_is_zero(__isl_keep isl_ast_expr *expr)
static int extract_modulo(struct isl_extract_mod_data *data)
static int sort_pieces_cmp(const void *p1, const void *p2, void *arg)
static __isl_give isl_ast_expr * div_mod(enum isl_ast_expr_op_type type, __isl_take isl_aff *aff, __isl_take isl_val *v, __isl_keep isl_ast_build *build)
__isl_give isl_ast_expr * isl_ast_build_access_from_pw_multi_aff(__isl_keep isl_ast_build *build, __isl_take isl_pw_multi_aff *pma)
static void set_none(struct isl_from_pw_aff_data *data)
static isl_bool constant_is_considered_positive(__isl_keep isl_val *v, __isl_keep isl_ast_expr *pos, __isl_keep isl_ast_expr *neg)
static isl_bool extends_max(struct isl_from_pw_aff_data *data, __isl_keep isl_set *set, __isl_keep isl_aff *aff)
static __isl_give isl_ast_expr * isl_ast_build_with_arguments(__isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_ast_expr *arg0, __isl_take isl_multi_pw_aff *mpa)
static __isl_give isl_aff * steal_from_cst(__isl_take isl_aff *aff, __isl_keep isl_val *d, struct isl_ast_add_term_data *data)
static isl_bool single_is_subset(struct isl_from_pw_aff_data *data, __isl_keep isl_set *set)
static __isl_give isl_aff * coefficients_of_sign(__isl_take isl_aff *aff, int sign)
static int cmp_constraint(__isl_keep isl_constraint *a, __isl_keep isl_constraint *b, void *user)
__isl_give isl_ast_expr * isl_ast_build_expr_from_set(__isl_keep isl_ast_build *build, __isl_take isl_set *set)
__isl_give isl_ast_expr * isl_ast_build_expr_from_pw_aff(__isl_keep isl_ast_build *build, __isl_take isl_pw_aff *pa)
static isl_stat isl_from_pw_aff_data_init(struct isl_from_pw_aff_data *data, __isl_keep isl_ast_build *build, __isl_keep isl_pw_aff *pa)
static isl_bool is_stride_constraint(__isl_keep isl_aff *aff, int pos)
__isl_give isl_ast_expr * isl_ast_expr_from_aff(__isl_take isl_aff *aff, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_expr * extract_stride_constraint(__isl_take isl_aff *aff, int pos, __isl_keep isl_ast_build *build)
static isl_bool is_even_test(struct isl_extract_mod_data *data, __isl_keep isl_aff *arg)
static __isl_give isl_ast_expr * isl_ast_build_from_pw_multi_aff_internal(__isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_pw_multi_aff *pma)
static __isl_give isl_ast_expr * scale(__isl_take isl_ast_expr *expr, __isl_take isl_val *v)
__isl_give isl_ast_expr * isl_ast_build_expr_from_basic_set(__isl_keep isl_ast_build *build, __isl_take isl_basic_set *bset)
static isl_bool all_negative_coefficients(__isl_keep isl_aff *aff)
static __isl_give isl_ast_expr * isl_ast_expr_mod(__isl_keep isl_val *v, __isl_keep isl_aff *aff, __isl_keep isl_val *d, __isl_keep isl_ast_build *build)
static isl_ast_expr * build_pieces(struct isl_from_pw_aff_data *data)
static isl_stat add_last_piece(struct isl_from_pw_aff_data *data, int pos, isl_ast_expr_list **next)
static __isl_give isl_ast_expr * isl_ast_expr_add_int(__isl_take isl_ast_expr *expr, __isl_take isl_val *v)
static __isl_give isl_val * get_constraint_constant(struct isl_extract_mod_data *data, void *user)
static isl_stat ast_expr_from_pw_aff(__isl_take isl_set *set, __isl_take isl_aff *aff, void *user)
static isl_bool is_single_rational_aff(__isl_keep isl_aff_list *list)
static isl_stat replace_by_partial_if_simpler(struct isl_parallel_stat *stat)
static isl_stat check_parallel_or_opposite_wrap(__isl_take isl_constraint *c, void *user)
static isl_ast_expr_list ** add_intermediate_piece(struct isl_from_pw_aff_data *data, int pos, isl_ast_expr_list **next)
static isl_bool is_non_neg_after_stealing(__isl_keep isl_aff *aff, __isl_keep isl_val *d, struct isl_ast_add_term_data *data)
static isl_stat extract_mod(struct isl_extract_mod_data *data)
__isl_give isl_ast_expr * isl_ast_build_expr_from_set_internal(__isl_keep isl_ast_build *build, __isl_take isl_set *set)
static __isl_give isl_aff * extract_modulos(__isl_take isl_aff *aff, __isl_keep isl_ast_expr **pos, __isl_keep isl_ast_expr **neg, __isl_keep isl_ast_build *build)
static isl_bool parallel_or_opposite_feasible(struct isl_parallel_stat *stat, enum isl_dim_type c_type, enum isl_dim_type a_type, int i)
__isl_give isl_ast_node * isl_ast_build_call_from_executed(__isl_keep isl_ast_build *build, __isl_take isl_map *executed)
static isl_bool has_large_constant_term(__isl_keep isl_constraint *c)
static isl_bool extends_min(struct isl_from_pw_aff_data *data, __isl_keep isl_set *set, __isl_keep isl_aff *aff)
static isl_stat update_partial(struct isl_parallel_stat *stat)
static isl_bool add_rational(enum isl_dim_type type, int pos, __isl_take isl_val *v, void *user)
static __isl_give isl_aff * oppose_div_arg(__isl_take isl_aff *aff, __isl_take isl_val *d)
static __isl_give isl_ast_expr * isl_ast_build_from_pw_multi_aff(__isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_pw_multi_aff *pma)
static __isl_give isl_ast_expr * ast_expr_add(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2)
static isl_stat extract_nonneg_mod(struct isl_extract_mod_data *data)
static isl_bool partial_is_simpler(struct isl_extract_mod_data *data)
static isl_bool mod_constraint_is_simpler(struct isl_extract_mod_data *data, __isl_keep isl_constraint *c)
__isl_give isl_ast_expr * isl_ast_build_access_from_multi_pw_aff(__isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa)
static __isl_give isl_ast_expr * isl_ast_build_from_multi_pw_aff(__isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_multi_pw_aff *mpa)
static isl_bool parallel_or_opposite_continue(struct isl_parallel_stat *stat)
static isl_stat extend_max(struct isl_from_pw_aff_data *data, __isl_take isl_set *set, __isl_take isl_aff *aff)
static isl_stat replace_if_simpler(struct isl_extract_mod_data *data, __isl_keep isl_constraint *c, int sign)
static isl_stat try_extract_mod(struct isl_extract_mod_data *data)
__isl_give isl_ast_expr * isl_ast_build_call_from_multi_pw_aff(__isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa)
static __isl_give isl_ast_expr * isl_ast_expr_from_constraint(__isl_take isl_constraint *constraint, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_expr * var_div(struct isl_ast_add_term_data *data, int pos)
static isl_stat extract_term_and_mod(struct isl_extract_mod_data *data, __isl_take isl_aff *term, __isl_take isl_aff *arg)
static isl_bool is_parallel_or_opposite(struct isl_parallel_stat *stat, enum isl_dim_type c_type, enum isl_dim_type a_type, int i)
static void isl_from_pw_aff_data_clear(struct isl_from_pw_aff_data *data)
static __isl_give isl_ast_expr * ast_expr_sub(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2)
static __isl_give isl_multi_pw_aff * set_iterator_names(__isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa)
static isl_bool is_simpler(struct isl_extract_mod_data *data, __isl_give isl_val *get_constant(struct isl_extract_mod_data *data, void *user), void *user)
static __isl_give isl_ast_expr * add_terms(__isl_take isl_ast_expr *expr, __isl_keep isl_aff *aff, struct isl_ast_add_term_data *data)
static __isl_give isl_val * get_partial_constant(struct isl_extract_mod_data *data, void *user)
static __isl_give isl_ast_expr * ast_expr_from_aff_list(__isl_take isl_aff_list *list, enum isl_from_pw_aff_state state, __isl_keep isl_ast_build *build)
static int is_rational(__isl_keep isl_stream *s)
Definition isl_input.c:2774
static unsigned pos(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_map.c:73
#define isl_basic_set_list
#define isl_set_list
#define isl_set
#define isl_basic_set
static int all_neg(int *row, int n)
int isl_sort(void *const pbase, size_t total_elems, size_t size, int(*cmp)(const void *, const void *, void *arg), void *arg)
Definition isl_sort.c:153
static isl_bool get_constant(struct isl_tab *tab, struct isl_tab_var *var, isl_int *value)
Definition isl_tab.c:3682
enum isl_fold type
Definition isl_test.c:3867
const char * pa
Definition isl_test.c:7173
const char * set
Definition isl_test.c:1364
const char * hull
Definition isl_test.c:1493
const char * ma
Definition isl_test.c:7387
const char * pma
Definition isl_test.c:3019
const char * aff
Definition isl_test.c:7130
const char * res
Definition isl_test.c:783
int subset
Definition isl_test.c:4057
const char * arg
Definition isl_test.c:782
const char * gist
Definition isl_test.c:1793
const char * id
Definition isl_test.c:7131
t0 *a *b *t *a *b * t
__isl_give isl_aff * isl_local_space_get_div(__isl_keep isl_local_space *ls, int pos)
isl_ctx * isl_local_space_get_ctx(__isl_keep isl_local_space *ls)
__isl_null isl_local_space * isl_local_space_free(__isl_take isl_local_space *ls)
__isl_give isl_local_space * isl_local_space_copy(__isl_keep isl_local_space *ls)
__isl_give isl_id * isl_local_space_get_dim_id(__isl_keep isl_local_space *ls, enum isl_dim_type type, unsigned pos)
isl_bool isl_local_space_has_dim_id(__isl_keep isl_local_space *ls, enum isl_dim_type type, unsigned pos)
a(0)
b(9)
__isl_export __isl_give isl_set * isl_set_coalesce(__isl_take isl_set *set)
__isl_give isl_set * isl_set_list_union(__isl_take isl_set_list *list)
Definition isl_map.c:11350
__isl_export __isl_give isl_set * isl_set_subtract(__isl_take isl_set *set1, __isl_take isl_set *set2)
__isl_export __isl_give isl_set * isl_set_union(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:8929
__isl_overload __isl_give isl_set * isl_set_preimage_multi_aff(__isl_take isl_set *set, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14675
__isl_null isl_basic_set * isl_basic_set_free(__isl_take isl_basic_set *bset)
Definition isl_map.c:1523
__isl_give isl_basic_set * isl_set_simple_hull(__isl_take isl_set *set)
__isl_null isl_set * isl_set_free(__isl_take isl_set *set)
Definition isl_map.c:4055
__isl_export isl_bool isl_set_is_subset(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
__isl_give isl_set * isl_set_copy(__isl_keep isl_set *set)
Definition isl_map.c:1470
__isl_give isl_basic_set_list * isl_set_get_basic_set_list(__isl_keep isl_set *set)
Definition isl_map.c:11987
__isl_export __isl_give isl_set * isl_set_gist(__isl_take isl_set *set, __isl_take isl_set *context)
__isl_give isl_set * isl_set_compute_divs(__isl_take isl_set *set)
Definition isl_map.c:8772
__isl_give isl_basic_set * isl_basic_set_remove_divs(__isl_take isl_basic_set *bset)
Definition isl_map.c:2778
__isl_export __isl_give isl_basic_set * isl_basic_set_gist(__isl_take isl_basic_set *bset, __isl_take isl_basic_set *context)
__isl_export isl_size isl_set_n_basic_set(__isl_keep isl_set *set)
Definition isl_map.c:11928
__isl_export __isl_give isl_set * isl_set_intersect(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:4521
__isl_constructor __isl_give isl_set * isl_set_from_basic_set(__isl_take isl_basic_set *bset)
Definition isl_map.c:4024
__isl_give isl_basic_set * isl_basic_set_copy(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1465
__isl_null isl_space * isl_space_free(__isl_take isl_space *space)
Definition isl_space.c:478
isl_bool isl_space_tuple_is_equal(__isl_keep isl_space *space1, enum isl_dim_type type1, __isl_keep isl_space *space2, enum isl_dim_type type2)
Definition isl_space.c:1080
isl_dim_type
Definition space_type.h:13
@ 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_div
Definition space_type.h:19
@ isl_dim_out
Definition space_type.h:17
struct isl_ast_add_term_data * term
struct isl_from_pw_aff_piece * p
enum isl_from_pw_aff_state state
struct isl_extract_mod_data * data
static Signature domain
__isl_export __isl_give isl_val * isl_val_abs(__isl_take isl_val *v)
Definition isl_val.c:456
__isl_export isl_bool isl_val_lt(__isl_keep isl_val *v1, __isl_keep isl_val *v2)
Definition isl_val.c:1285
__isl_export __isl_give isl_val * isl_val_mod(__isl_take isl_val *v1, __isl_take isl_val *v2)
Definition isl_val.c:979
__isl_give isl_val * isl_val_copy(__isl_keep isl_val *v)
Definition isl_val.c:219
__isl_export int isl_val_cmp_si(__isl_keep isl_val *v, long i)
Definition isl_val.c:1394
__isl_export isl_bool isl_val_is_negone(__isl_keep isl_val *v)
Definition isl_val.c:1214
__isl_export __isl_give isl_val * isl_val_floor(__isl_take isl_val *v)
Definition isl_val.c:470
__isl_export __isl_give isl_val * isl_val_ceil(__isl_take isl_val *v)
Definition isl_val.c:491
__isl_export __isl_give isl_val * isl_val_div(__isl_take isl_val *v1, __isl_take isl_val *v2)
Definition isl_val.c:875
__isl_give isl_val * isl_val_sub_ui(__isl_take isl_val *v1, unsigned long v2)
Definition isl_val.c:763
__isl_export __isl_give isl_val * isl_val_add(__isl_take isl_val *v1, __isl_take isl_val *v2)
Definition isl_val.c:626
__isl_export isl_bool isl_val_is_pos(__isl_keep isl_val *v)
Definition isl_val.c:1224
__isl_export __isl_give isl_val * isl_val_zero(isl_ctx *ctx)
Definition isl_val.c:41
__isl_export isl_bool isl_val_abs_eq(__isl_keep isl_val *v1, __isl_keep isl_val *v2)
Definition isl_val.c:1445
__isl_export int isl_val_sgn(__isl_keep isl_val *v)
Definition isl_val.c:1272
__isl_export isl_bool isl_val_is_divisible_by(__isl_keep isl_val *v1, __isl_keep isl_val *v2)
Definition isl_val.c:964
__isl_export isl_bool isl_val_is_neg(__isl_keep isl_val *v)
Definition isl_val.c:1234
isl_bool isl_val_eq_si(__isl_keep isl_val *v, long i)
Definition isl_val.c:1434
__isl_null isl_val * isl_val_free(__isl_take isl_val *v)
Definition isl_val.c:263
__isl_export isl_bool isl_val_is_zero(__isl_keep isl_val *v)
Definition isl_val.c:1191
__isl_export __isl_give isl_val * isl_val_sub(__isl_take isl_val *v1, __isl_take isl_val *v2)
Definition isl_val.c:704
__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_is_one(__isl_keep isl_val *v)
Definition isl_val.c:1201
__isl_export __isl_give isl_val * isl_val_neg(__isl_take isl_val *v)
Definition isl_val.c:410
__isl_export __isl_give isl_val * isl_val_mul(__isl_take isl_val *v1, __isl_take isl_val *v2)
Definition isl_val.c:782
n
Definition youcefn.c:8