Polly 23.0.0git
isl_map.c
Go to the documentation of this file.
1/*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2014 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
6 * Copyright 2016 INRIA Paris
7 * Copyright 2016 Sven Verdoolaege
8 * Copyright 2018-2019 Cerebras Systems
9 * Copyright 2021-2022 Cerebras Systems
10 *
11 * Use of this software is governed by the MIT license
12 *
13 * Written by Sven Verdoolaege, K.U.Leuven, Departement
14 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
15 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
16 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
17 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
18 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
19 * B.P. 105 - 78153 Le Chesnay, France
20 * and Centre de Recherche Inria de Paris, 2 rue Simone Iff - Voie DQ12,
21 * CS 42112, 75589 Paris Cedex 12, France
22 * and Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA
23 * and Cerebras Systems, 1237 E Arques Ave, Sunnyvale, CA, USA
24 */
25
26#include <string.h>
27#include <isl_ctx_private.h>
28#include <isl_map_private.h>
29#include <isl_blk.h>
30#include <isl_id_private.h>
31#include <isl/constraint.h>
32#include "isl_space_private.h"
33#include "isl_equalities.h"
34#include <isl_lp_private.h>
35#include <isl_seq.h>
36#include <isl/set.h>
37#include <isl/map.h>
38#include <isl_reordering.h>
39#include "isl_sample.h"
40#include <isl_sort.h>
41#include "isl_tab.h"
42#include <isl/vec.h>
43#include <isl_mat_private.h>
44#include <isl_vec_private.h>
45#include <isl_dim_map.h>
47#include <isl_aff_private.h>
48#include <isl_options_private.h>
49#include <isl_morph.h>
50#include <isl_val_private.h>
51#include <isl_printer_private.h>
52#include <isl_maybe_aff.h>
53
54#include <bset_to_bmap.c>
55#include <bset_from_bmap.c>
56#include <set_to_map.c>
57#include <set_from_map.c>
58
59/* Treat "bset" as a basic map.
60 * Internally, isl_basic_set is defined to isl_basic_map, so in practice,
61 * this function performs a redundant cast.
62 */
64 __isl_keep const isl_basic_set *bset)
65{
66 return (const isl_basic_map *) bset;
67}
68
69#undef TYPE
70#define TYPE isl_basic_map
72
73static unsigned pos(__isl_keep isl_space *space, enum isl_dim_type type)
74{
75 switch (type) {
76 case isl_dim_param: return 1;
77 case isl_dim_in: return 1 + space->nparam;
78 case isl_dim_out: return 1 + space->nparam + space->n_in;
79 default: return 0;
80 }
81}
82
84 enum isl_dim_type type)
85{
86 if (!bmap)
87 return isl_size_error;
88 switch (type) {
89 case isl_dim_cst: return 1;
90 case isl_dim_param:
91 case isl_dim_in:
92 case isl_dim_out: return isl_space_dim(bmap->dim, type);
93 case isl_dim_div: return bmap->n_div;
94 case isl_dim_all: return isl_basic_map_total_dim(bmap);
95 default: return 0;
96 }
97}
98
99/* Return the space of "map".
100 */
102{
103 return map ? map->dim : NULL;
104}
105
106/* Return the space of "set".
107 */
112
117
118/* Return the dimensionality of the domain (tuple) of the map.
119 */
124
125/* Return the dimensionality of the range (tuple) of the map.
126 */
131
136
137/* Return the dimensionality of the (tuple of the) set.
138 */
143
144/* Return the position of the variables of the given type
145 * within the sequence of variables of "bmap".
146 */
148 enum isl_dim_type type)
149{
150 isl_space *space;
151
152 space = isl_basic_map_peek_space(bmap);
153
154 switch (type) {
155 case isl_dim_param:
156 case isl_dim_in:
157 case isl_dim_out: return isl_space_offset(space, type);
158 case isl_dim_div: return isl_space_dim(space, isl_dim_all);
159 case isl_dim_cst:
160 default:
162 "invalid dimension type", return isl_size_error);
163 }
164}
165
166/* Return the position of the variables of the given type
167 * within the sequence of variables of "bset".
168 */
174
175/* Return the position of the coefficients of the variables of the given type
176 * within the sequence of coefficients of "bmap".
177 */
179 enum isl_dim_type type)
180{
181 switch (type) {
182 case isl_dim_cst: return 0;
183 case isl_dim_param:
184 case isl_dim_in:
185 case isl_dim_out:
186 case isl_dim_div: return 1 + isl_basic_map_var_offset(bmap, type);
187 default: return 0;
188 }
189}
190
192 enum isl_dim_type type)
193{
194 return isl_basic_map_offset(bset, type);
195}
196
198{
199 return pos(map->dim, type);
200}
201
207
212
217
222
227
232
234{
235 isl_size dim;
236
237 if (!bmap)
238 return isl_size_error;
239 dim = isl_space_dim(bmap->dim, isl_dim_all);
240 if (dim < 0)
241 return isl_size_error;
242 return dim + bmap->n_div;
243}
244
245/* Return the number of equality constraints in the description of "bmap".
246 * Return isl_size_error on error.
247 */
249{
250 if (!bmap)
251 return isl_size_error;
252 return bmap->n_eq;
253}
254
255/* Return the number of equality constraints in the description of "bset".
256 * Return isl_size_error on error.
257 */
262
263/* Return the number of inequality constraints in the description of "bmap".
264 * Return isl_size_error on error.
265 */
267{
268 if (!bmap)
269 return isl_size_error;
270 return bmap->n_ineq;
271}
272
273/* Return the number of inequality constraints in the description of "bset".
274 * Return isl_size_error on error.
275 */
280
281/* Do "bmap1" and "bmap2" have the same parameters?
282 */
285{
286 isl_space *space1, *space2;
287
288 space1 = isl_basic_map_peek_space(bmap1);
289 space2 = isl_basic_map_peek_space(bmap2);
290 return isl_space_has_equal_params(space1, space2);
291}
292
293/* Do "map1" and "map2" have the same parameters?
294 */
297{
298 isl_space *space1, *space2;
299
300 space1 = isl_map_peek_space(map1);
301 space2 = isl_map_peek_space(map2);
302 return isl_space_has_equal_params(space1, space2);
303}
304
305/* Do "map" and "set" have the same parameters?
306 */
312
313/* Is the tuple of type "type" of "bmap" the same as the single tuple of "bset"?
314 */
317{
318 isl_space *bmap_space, *bset_space;
319
320 bmap_space = isl_basic_map_peek_space(bmap);
321 bset_space = isl_basic_set_peek_space(bset);
322 return isl_space_tuple_is_equal(bmap_space, type,
323 bset_space, isl_dim_set);
324}
325
326/* Is the tuple of type "type" of "map" the same as the single tuple of "set"?
327 */
333
336{
337 isl_bool m;
338 if (!map || !set)
339 return isl_bool_error;
341 if (m < 0 || !m)
342 return m;
344}
345
348{
349 isl_bool m;
350 if (!bmap || !bset)
351 return isl_bool_error;
353 if (m < 0 || !m)
354 return m;
356}
357
360{
361 isl_bool m;
362 if (!map || !set)
363 return isl_bool_error;
365 if (m < 0 || !m)
366 return m;
368}
369
372{
373 isl_bool m;
374 if (!bmap || !bset)
375 return isl_bool_error;
377 if (m < 0 || !m)
378 return m;
380}
381
383{
384 return bmap ? bmap->ctx : NULL;
385}
386
388{
389 return bset ? bset->ctx : NULL;
390}
391
393{
394 return map ? map->ctx : NULL;
395}
396
398{
399 return set ? set->ctx : NULL;
400}
401
402/* Return the space of "bmap".
403 */
405 __isl_keep const isl_basic_map *bmap)
406{
407 return bmap ? bmap->dim : NULL;
408}
409
410/* Return the space of "bset".
411 */
416
421
426
427/* Return the space of "bmap".
428 * This may be either a copy or the space itself
429 * if there is only one reference to "bmap".
430 * This allows the space to be modified inplace
431 * if both the basic map and its space have only a single reference.
432 * The caller is not allowed to modify "bmap" between this call and
433 * a subsequent call to isl_basic_map_restore_space.
434 * The only exception is that isl_basic_map_free can be called instead.
435 */
438{
439 isl_space *space;
440
441 if (!bmap)
442 return NULL;
443 if (bmap->ref != 1)
444 return isl_basic_map_get_space(bmap);
445 space = bmap->dim;
446 bmap->dim = NULL;
447 return space;
448}
449
450/* Set the space of "bmap" to "space", where the space of "bmap" may be missing
451 * due to a preceding call to isl_basic_map_take_space.
452 * However, in this case, "bmap" only has a single reference and
453 * then the call to isl_basic_map_cow has no effect.
454 */
457{
458 if (!bmap || !space)
459 goto error;
460
461 if (bmap->dim == space) {
462 isl_space_free(space);
463 return bmap;
464 }
465
466 bmap = isl_basic_map_cow(bmap);
467 if (!bmap)
468 goto error;
469 isl_space_free(bmap->dim);
470 bmap->dim = space;
471
472 return bmap;
473error:
474 isl_basic_map_free(bmap);
475 isl_space_free(space);
476 return NULL;
477}
478
479/* Extract the divs in "bmap" as a matrix.
480 */
482{
483 int i;
484 isl_ctx *ctx;
485 isl_mat *div;
486 isl_size v_div;
487 unsigned cols;
488
490 if (v_div < 0)
491 return NULL;
492
493 ctx = isl_basic_map_get_ctx(bmap);
494 cols = 1 + 1 + v_div + bmap->n_div;
495 div = isl_mat_alloc(ctx, bmap->n_div, cols);
496 if (!div)
497 return NULL;
498
499 for (i = 0; i < bmap->n_div; ++i)
500 isl_seq_cpy(div->row[i], bmap->div[i], cols);
501
502 return div;
503}
504
505/* Extract the divs in "bset" as a matrix.
506 */
511
514{
515 isl_mat *div;
516
517 if (!bmap)
518 return NULL;
519
520 div = isl_basic_map_get_divs(bmap);
521 return isl_local_space_alloc_div(isl_space_copy(bmap->dim), div);
522}
523
529
530/* For each known div d = floor(f/m), add the constraints
531 *
532 * f - m d >= 0
533 * -(f-(m-1)) + m d >= 0
534 *
535 * Do not finalize the result.
536 */
539{
540 int i;
541 isl_size n_div;
542
543 n_div = isl_basic_map_dim(bmap, isl_dim_div);
544 if (n_div < 0)
545 return isl_basic_map_free(bmap);
546 if (n_div == 0)
547 return bmap;
548 bmap = isl_basic_map_cow(bmap);
549 bmap = isl_basic_map_extend_constraints(bmap, 0, 2 * n_div);
550 if (!bmap)
551 return NULL;
552 for (i = 0; i < n_div; ++i) {
553 if (isl_int_is_zero(bmap->div[i][0]))
554 continue;
555 bmap = isl_basic_map_add_div_constraints(bmap, i);
556 }
557
558 return bmap;
559}
560
563{
564 int i;
565 isl_size n_div;
566 isl_basic_map *bmap;
567
568 n_div = isl_local_space_dim(ls, isl_dim_div);
569 if (n_div < 0)
570 ls = isl_local_space_free(ls);
571 if (!ls)
572 return NULL;
573
575 n_div, 0, 2 * n_div);
576
577 for (i = 0; i < n_div; ++i)
578 if (isl_basic_map_alloc_div(bmap) < 0)
579 goto error;
580
581 for (i = 0; i < n_div; ++i)
582 isl_seq_cpy(bmap->div[i], ls->div->row[i], ls->div->n_col);
583 bmap = add_known_div_constraints(bmap);
584
586 return bmap;
587error:
589 isl_basic_map_free(bmap);
590 return NULL;
591}
592
598
603
605{
606 if (!set)
607 return NULL;
608 return isl_space_copy(set->dim);
609}
610
611/* Return the space of "map".
612 * This may be either a copy or the space itself
613 * if there is only one reference to "map".
614 * This allows the space to be modified inplace
615 * if both the map and its space have only a single reference.
616 * The caller is not allowed to modify "map" between this call and
617 * a subsequent call to isl_map_restore_space.
618 * The only exception is that isl_map_free can be called instead.
619 */
621{
622 isl_space *space;
623
624 if (!map)
625 return NULL;
626 if (map->ref != 1)
627 return isl_map_get_space(map);
628 space = map->dim;
629 map->dim = NULL;
630 return space;
631}
632
633/* Set the space of "map" to "space", where the space of "map" may be missing
634 * due to a preceding call to isl_map_take_space.
635 * However, in this case, "map" only has a single reference and
636 * then the call to isl_map_cow has no effect.
637 */
639 __isl_take isl_space *space)
640{
641 if (!map || !space)
642 goto error;
643
644 if (map->dim == space) {
645 isl_space_free(space);
646 return map;
647 }
648
650 if (!map)
651 goto error;
652 isl_space_free(map->dim);
653 map->dim = space;
654
655 return map;
656error:
658 isl_space_free(space);
659 return NULL;
660}
661
663 __isl_take isl_basic_map *bmap, enum isl_dim_type type, const char *s)
664{
665 isl_space *space;
666
667 space = isl_basic_map_take_space(bmap);
668 space = isl_space_set_tuple_name(space, type, s);
669 bmap = isl_basic_map_restore_space(bmap, space);
670 bmap = isl_basic_map_finalize(bmap);
671 return bmap;
672}
673
679
681 enum isl_dim_type type)
682{
683 return bmap ? isl_space_get_tuple_name(bmap->dim, type) : NULL;
684}
685
687 enum isl_dim_type type, const char *s)
688{
689 int i;
690 isl_space *space;
691
693 if (!map)
694 return NULL;
695
696 for (i = 0; i < map->n; ++i) {
697 map->p[i] = isl_basic_map_set_tuple_name(map->p[i], type, s);
698 if (!map->p[i])
699 goto error;
700 }
701
702 space = isl_map_take_space(map);
703 space = isl_space_set_tuple_name(space, type, s);
704 map = isl_map_restore_space(map, space);
705
706 return map;
707error:
709 return NULL;
710}
711
712/* Replace the identifier of the tuple of type "type" by "id".
713 */
717{
718 isl_space *space;
719
720 space = isl_basic_map_take_space(bmap);
721 space = isl_space_set_tuple_id(space, type, id);
722 bmap = isl_basic_map_restore_space(bmap, space);
723 bmap = isl_basic_map_finalize(bmap);
724 return bmap;
725}
726
727/* Replace the identifier of the tuple by "id".
728 */
734
735/* Does the input or output tuple have a name?
736 */
741
743 enum isl_dim_type type)
744{
745 return map ? isl_space_get_tuple_name(map->dim, type) : NULL;
746}
747
754
766
767/* Replace the identifier of the domain tuple of "map" by "id".
768 */
774
775/* Replace the identifier of the range tuple of "map" by "id".
776 */
782
788
800
805
810
811/* Does the domain tuple of "map" have an identifier?
812 */
817
818/* Does the range tuple of "map" have an identifier?
819 */
824
830
831/* Return the identifier of the domain tuple of "map", assuming it has one.
832 */
837
838/* Return the identifier of the range tuple of "map", assuming it has one.
839 */
844
849
854
855/* Does the set tuple have a name?
856 */
863
864
866{
867 return bset ? isl_space_get_tuple_name(bset->dim, isl_dim_set) : NULL;
868}
869
871{
872 return set ? isl_space_get_tuple_name(set->dim, isl_dim_set) : NULL;
873}
874
876 enum isl_dim_type type, unsigned pos)
877{
878 return bmap ? isl_space_get_dim_name(bmap->dim, type, pos) : NULL;
879}
880
882 enum isl_dim_type type, unsigned pos)
883{
884 return bset ? isl_space_get_dim_name(bset->dim, type, pos) : NULL;
885}
886
887/* Does the given dimension have a name?
888 */
890 enum isl_dim_type type, unsigned pos)
891{
892 if (!map)
893 return isl_bool_error;
894 return isl_space_has_dim_name(map->dim, type, pos);
895}
896
898 enum isl_dim_type type, unsigned pos)
899{
900 return map ? isl_space_get_dim_name(map->dim, type, pos) : NULL;
901}
902
904 enum isl_dim_type type, unsigned pos)
905{
906 return set ? isl_space_get_dim_name(set->dim, type, pos) : NULL;
907}
908
909/* Does the given dimension have a name?
910 */
912 enum isl_dim_type type, unsigned pos)
913{
914 if (!set)
915 return isl_bool_error;
916 return isl_space_has_dim_name(set->dim, type, pos);
917}
918
921 enum isl_dim_type type, unsigned pos, const char *s)
922{
923 isl_space *space;
924
925 space = isl_basic_map_take_space(bmap);
926 space = isl_space_set_dim_name(space, type, pos, s);
927 bmap = isl_basic_map_restore_space(bmap, space);
928 return isl_basic_map_finalize(bmap);
929}
930
932 enum isl_dim_type type, unsigned pos, const char *s)
933{
934 int i;
935 isl_space *space;
936
938 if (!map)
939 return NULL;
940
941 for (i = 0; i < map->n; ++i) {
942 map->p[i] = isl_basic_map_set_dim_name(map->p[i], type, pos, s);
943 if (!map->p[i])
944 goto error;
945 }
946
947 space = isl_map_take_space(map);
948 space = isl_space_set_dim_name(space, type, pos, s);
949 map = isl_map_restore_space(map, space);
950
951 return map;
952error:
954 return NULL;
955}
956
964
971
973 enum isl_dim_type type, unsigned pos)
974{
975 if (!bmap)
976 return isl_bool_error;
977 return isl_space_has_dim_id(bmap->dim, type, pos);
978}
979
981 enum isl_dim_type type, unsigned pos)
982{
983 return bset ? isl_space_get_dim_id(bset->dim, type, pos) : NULL;
984}
985
991
993 enum isl_dim_type type, unsigned pos)
994{
995 return map ? isl_space_get_dim_id(map->dim, type, pos) : NULL;
996}
997
1003
1009
1011 enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
1012{
1013 isl_space *space;
1014
1015 space = isl_map_take_space(map);
1016 space = isl_space_set_dim_id(space, type, pos, id);
1017 map = isl_map_restore_space(map, space);
1018
1020}
1021
1027
1029 __isl_keep isl_id *id)
1030{
1031 if (!map)
1032 return -1;
1033 return isl_space_find_dim_by_id(map->dim, type, id);
1034}
1035
1041
1042/* Return the position of the dimension of the given type and name
1043 * in "bmap".
1044 * Return -1 if no such dimension can be found.
1045 */
1047 enum isl_dim_type type, const char *name)
1048{
1049 if (!bmap)
1050 return -1;
1051 return isl_space_find_dim_by_name(bmap->dim, type, name);
1052}
1053
1055 const char *name)
1056{
1057 if (!map)
1058 return -1;
1059 return isl_space_find_dim_by_name(map->dim, type, name);
1060}
1061
1067
1068/* Check whether equality i of bset is a pure stride constraint
1069 * on a single dimension, i.e., of the form
1070 *
1071 * v = k e
1072 *
1073 * with k a constant and e an existentially quantified variable.
1074 */
1076{
1077 isl_size nparam;
1078 isl_size d;
1079 isl_size n_div;
1080 int pos1;
1081 int pos2;
1082
1083 nparam = isl_basic_set_dim(bset, isl_dim_param);
1084 d = isl_basic_set_dim(bset, isl_dim_set);
1085 n_div = isl_basic_set_dim(bset, isl_dim_div);
1086 if (nparam < 0 || d < 0 || n_div < 0)
1087 return isl_bool_error;
1088
1089 if (!isl_int_is_zero(bset->eq[i][0]))
1090 return isl_bool_false;
1091
1092 if (isl_seq_any_non_zero(bset->eq[i] + 1, nparam))
1093 return isl_bool_false;
1094 pos1 = isl_seq_first_non_zero(bset->eq[i] + 1 + nparam, d);
1095 if (pos1 == -1)
1096 return isl_bool_false;
1097 if (isl_seq_any_non_zero(bset->eq[i] + 1 + nparam + pos1 + 1,
1098 d - pos1 - 1))
1099 return isl_bool_false;
1100
1101 pos2 = isl_seq_first_non_zero(bset->eq[i] + 1 + nparam + d, n_div);
1102 if (pos2 == -1)
1103 return isl_bool_false;
1104 if (isl_seq_any_non_zero(bset->eq[i] + 1 + nparam + d + pos2 + 1,
1105 n_div - pos2 - 1))
1106 return isl_bool_false;
1107 if (!isl_int_is_one(bset->eq[i][1 + nparam + pos1]) &&
1108 !isl_int_is_negone(bset->eq[i][1 + nparam + pos1]))
1109 return isl_bool_false;
1110
1111 return isl_bool_true;
1112}
1113
1114/* Reset the user pointer on all identifiers of parameters and tuples
1115 * of the space of "map".
1116 */
1118{
1119 isl_space *space;
1120
1121 space = isl_map_get_space(map);
1122 space = isl_space_reset_user(space);
1123 map = isl_map_reset_space(map, space);
1124
1125 return map;
1126}
1127
1128/* Reset the user pointer on all identifiers of parameters and tuples
1129 * of the space of "set".
1130 */
1135
1137{
1138 if (!bmap)
1139 return isl_bool_error;
1140 return ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL);
1141}
1142
1143/* Has "map" been marked as a rational map?
1144 * In particular, have all basic maps in "map" been marked this way?
1145 * An empty map is not considered to be rational.
1146 * Maps where only some of the basic maps are marked rational
1147 * are not allowed.
1148 */
1150{
1151 int i;
1152 isl_bool rational;
1153
1154 if (!map)
1155 return isl_bool_error;
1156 if (map->n == 0)
1157 return isl_bool_false;
1158 rational = isl_basic_map_is_rational(map->p[0]);
1159 if (rational < 0)
1160 return rational;
1161 for (i = 1; i < map->n; ++i) {
1162 isl_bool rational_i;
1163
1164 rational_i = isl_basic_map_is_rational(map->p[i]);
1165 if (rational_i < 0)
1166 return rational_i;
1167 if (rational != rational_i)
1169 "mixed rational and integer basic maps "
1170 "not supported", return isl_bool_error);
1171 }
1172
1173 return rational;
1174}
1175
1176/* Has "set" been marked as a rational set?
1177 * In particular, have all basic set in "set" been marked this way?
1178 * An empty set is not considered to be rational.
1179 * Sets where only some of the basic sets are marked rational
1180 * are not allowed.
1181 */
1186
1191
1192/* Does "bmap" contain any rational points?
1193 *
1194 * If "bmap" has an equality for each dimension, equating the dimension
1195 * to an integer constant, then it has no rational points, even if it
1196 * is marked as rational.
1197 */
1199{
1200 isl_bool has_rational = isl_bool_true;
1202
1203 if (!bmap)
1204 return isl_bool_error;
1206 return isl_bool_false;
1207 if (!isl_basic_map_is_rational(bmap))
1208 return isl_bool_false;
1209 bmap = isl_basic_map_copy(bmap);
1212 if (total < 0)
1213 return isl_bool_error;
1214 if (bmap->n_eq == total) {
1215 int i, j;
1216 for (i = 0; i < bmap->n_eq; ++i) {
1217 j = isl_seq_first_non_zero(bmap->eq[i] + 1, total);
1218 if (j < 0)
1219 break;
1220 if (!isl_int_is_one(bmap->eq[i][1 + j]) &&
1221 !isl_int_is_negone(bmap->eq[i][1 + j]))
1222 break;
1223 if (isl_seq_any_non_zero(bmap->eq[i] + 1 + j + 1,
1224 total - j - 1))
1225 break;
1226 }
1227 if (i == bmap->n_eq)
1228 has_rational = isl_bool_false;
1229 }
1230 isl_basic_map_free(bmap);
1231
1232 return has_rational;
1233}
1234
1235/* Does "map" contain any rational points?
1236 */
1238{
1239 int i;
1240 isl_bool has_rational;
1241
1242 if (!map)
1243 return isl_bool_error;
1244 for (i = 0; i < map->n; ++i) {
1245 has_rational = isl_basic_map_has_rational(map->p[i]);
1246 if (has_rational < 0 || has_rational)
1247 return has_rational;
1248 }
1249 return isl_bool_false;
1250}
1251
1252/* Does "set" contain any rational points?
1253 */
1258
1259/* Is this basic set a parameter domain?
1260 */
1262{
1263 if (!bset)
1264 return isl_bool_error;
1265 return isl_space_is_params(bset->dim);
1266}
1267
1268/* Is this set a parameter domain?
1269 */
1271{
1272 if (!set)
1273 return isl_bool_error;
1274 return isl_space_is_params(set->dim);
1275}
1276
1277/* Is this map actually a parameter domain?
1278 * Users should never call this function. Outside of isl,
1279 * a map can never be a parameter domain.
1280 */
1282{
1283 if (!map)
1284 return isl_bool_error;
1285 return isl_space_is_params(map->dim);
1286}
1287
1289 __isl_take isl_basic_map *bmap, unsigned extra,
1290 unsigned n_eq, unsigned n_ineq)
1291{
1292 int i;
1293 isl_space *space = isl_basic_map_peek_space(bmap);
1294 isl_size n_var = isl_space_dim(space, isl_dim_all);
1295 size_t row_size = 1 + n_var + extra;
1296
1297 bmap->ctx = ctx;
1298 isl_ctx_ref(ctx);
1299
1300 if (n_var < 0)
1301 return isl_basic_map_free(bmap);
1302
1303 bmap->block = isl_blk_alloc(ctx, (n_ineq + n_eq) * row_size);
1304 if (isl_blk_is_error(bmap->block))
1305 goto error;
1306
1307 bmap->ineq = isl_alloc_array(ctx, isl_int *, n_ineq + n_eq);
1308 if ((n_ineq + n_eq) && !bmap->ineq)
1309 goto error;
1310
1311 if (extra == 0) {
1312 bmap->block2 = isl_blk_empty();
1313 bmap->div = NULL;
1314 } else {
1315 bmap->block2 = isl_blk_alloc(ctx, extra * (1 + row_size));
1316 if (isl_blk_is_error(bmap->block2))
1317 goto error;
1318
1319 bmap->div = isl_alloc_array(ctx, isl_int *, extra);
1320 if (!bmap->div)
1321 goto error;
1322 }
1323
1324 for (i = 0; i < n_ineq + n_eq; ++i)
1325 bmap->ineq[i] = bmap->block.data + i * row_size;
1326
1327 for (i = 0; i < extra; ++i)
1328 bmap->div[i] = bmap->block2.data + i * (1 + row_size);
1329
1330 bmap->ref = 1;
1331 bmap->flags = 0;
1332 bmap->c_size = n_eq + n_ineq;
1333 bmap->eq = bmap->ineq + n_ineq;
1334 bmap->extra = extra;
1335 bmap->n_eq = 0;
1336 bmap->n_ineq = 0;
1337 bmap->n_div = 0;
1338 bmap->sample = NULL;
1339
1340 return bmap;
1341error:
1342 isl_basic_map_free(bmap);
1343 return NULL;
1344}
1345
1347 unsigned nparam, unsigned dim, unsigned extra,
1348 unsigned n_eq, unsigned n_ineq)
1349{
1350 struct isl_basic_map *bmap;
1351 isl_space *space;
1352
1353 space = isl_space_set_alloc(ctx, nparam, dim);
1354 if (!space)
1355 return NULL;
1356
1357 bmap = isl_basic_map_alloc_space(space, extra, n_eq, n_ineq);
1358 return bset_from_bmap(bmap);
1359}
1360
1362 unsigned extra, unsigned n_eq, unsigned n_ineq)
1363{
1364 struct isl_basic_map *bmap;
1365 if (!space)
1366 return NULL;
1367 isl_assert(space->ctx, space->n_in == 0, goto error);
1368 bmap = isl_basic_map_alloc_space(space, extra, n_eq, n_ineq);
1369 return bset_from_bmap(bmap);
1370error:
1371 isl_space_free(space);
1372 return NULL;
1373}
1374
1376 unsigned extra, unsigned n_eq, unsigned n_ineq)
1377{
1378 struct isl_basic_map *bmap;
1379
1380 if (!space)
1381 return NULL;
1382 bmap = isl_calloc_type(space->ctx, struct isl_basic_map);
1383 if (!bmap)
1384 goto error;
1385 bmap->dim = space;
1386
1387 return basic_map_init(space->ctx, bmap, extra, n_eq, n_ineq);
1388error:
1389 isl_space_free(space);
1390 return NULL;
1391}
1392
1394 unsigned nparam, unsigned in, unsigned out, unsigned extra,
1395 unsigned n_eq, unsigned n_ineq)
1396{
1397 struct isl_basic_map *bmap;
1398 isl_space *space;
1399
1400 space = isl_space_alloc(ctx, nparam, in, out);
1401 if (!space)
1402 return NULL;
1403
1404 bmap = isl_basic_map_alloc_space(space, extra, n_eq, n_ineq);
1405 return bmap;
1406}
1407
1410{
1411 int i;
1413
1414 if (!dst || total < 0)
1415 return isl_basic_map_free(dst);
1416
1417 for (i = 0; i < src->n_eq; ++i) {
1418 int j = isl_basic_map_alloc_equality(dst);
1419 if (j < 0)
1420 return isl_basic_map_free(dst);
1421 isl_seq_cpy(dst->eq[j], src->eq[i], 1+total);
1422 }
1423
1424 for (i = 0; i < src->n_ineq; ++i) {
1425 int j = isl_basic_map_alloc_inequality(dst);
1426 if (j < 0)
1427 return isl_basic_map_free(dst);
1428 isl_seq_cpy(dst->ineq[j], src->ineq[i], 1+total);
1429 }
1430
1431 for (i = 0; i < src->n_div; ++i) {
1432 int j = isl_basic_map_alloc_div(dst);
1433 if (j < 0)
1434 return isl_basic_map_free(dst);
1435 isl_seq_cpy(dst->div[j], src->div[i], 1+1+total);
1436 }
1438 return dst;
1439}
1440
1442{
1443 struct isl_basic_map *dup;
1444
1445 if (!bmap)
1446 return NULL;
1448 bmap->n_div, bmap->n_eq, bmap->n_ineq);
1449 dup = dup_constraints(dup, bmap);
1450 if (!dup)
1451 return NULL;
1452 dup->flags = bmap->flags;
1453 dup->sample = isl_vec_copy(bmap->sample);
1454 return dup;
1455}
1456
1464
1469
1471{
1472 if (!set)
1473 return NULL;
1474
1475 set->ref++;
1476 return set;
1477}
1478
1480{
1481 if (!bmap)
1482 return NULL;
1483
1484 if (ISL_F_ISSET(bmap, ISL_BASIC_SET_FINAL)) {
1485 bmap->ref++;
1486 return bmap;
1487 }
1488 bmap = isl_basic_map_dup(bmap);
1489 if (bmap)
1491 return bmap;
1492}
1493
1495{
1496 if (!map)
1497 return NULL;
1498
1499 map->ref++;
1500 return map;
1501}
1502
1504{
1505 if (!bmap)
1506 return NULL;
1507
1508 if (--bmap->ref > 0)
1509 return NULL;
1510
1511 isl_ctx_deref(bmap->ctx);
1512 free(bmap->div);
1513 isl_blk_free(bmap->ctx, bmap->block2);
1514 free(bmap->ineq);
1515 isl_blk_free(bmap->ctx, bmap->block);
1516 isl_vec_free(bmap->sample);
1517 isl_space_free(bmap->dim);
1518 free(bmap);
1519
1520 return NULL;
1521}
1522
1527
1528static int room_for_con(__isl_keep isl_basic_map *bmap, unsigned n)
1529{
1530 return bmap->n_eq + bmap->n_ineq + n <= bmap->c_size;
1531}
1532
1533/* Check that "bset" does not involve any parameters.
1534 */
1536{
1537 isl_size nparam;
1538
1539 nparam = isl_basic_set_dim(bset, isl_dim_param);
1540 if (nparam < 0)
1541 return isl_stat_error;
1542 if (nparam != 0)
1544 "basic set should not have any parameters",
1545 return isl_stat_error);
1546 return isl_stat_ok;
1547}
1548
1549/* Check that "bset" does not involve any local variables.
1550 */
1552{
1554
1556 if (n_div < 0)
1557 return isl_stat_error;
1558 if (n_div != 0)
1560 "basic set should not have any local variables",
1561 return isl_stat_error);
1562 return isl_stat_ok;
1563}
1564
1565#undef TYPE
1566#define TYPE isl_map
1567
1569
1570#undef TYPE
1571#define TYPE isl_basic_map
1572
1573static
1575
1576/* Check that "bmap1" and "bmap2" have the same parameters,
1577 * reporting an error if they do not.
1578 */
1581{
1583
1584 match = isl_basic_map_has_equal_params(bmap1, bmap2);
1585 if (match < 0)
1586 return isl_stat_error;
1587 if (!match)
1589 "parameters don't match", return isl_stat_error);
1590 return isl_stat_ok;
1591}
1592
1593#undef TYPE
1594#define TYPE isl_map
1595
1597
1598#undef SUFFIX
1599#define SUFFIX set
1600#undef ARG1
1601#define ARG1 isl_map
1602#undef ARG2
1603#define ARG2 isl_set
1604
1605#include "isl_align_params_templ.c"
1606
1630
1632{
1634 struct isl_ctx *ctx;
1635
1637 if (total < 0)
1638 return -1;
1639 ctx = bmap->ctx;
1640 isl_assert(ctx, room_for_con(bmap, 1), return -1);
1641 isl_assert(ctx, (bmap->eq - bmap->ineq) + bmap->n_eq <= bmap->c_size,
1642 return -1);
1647 if ((bmap->eq - bmap->ineq) + bmap->n_eq == bmap->c_size) {
1648 isl_int *t;
1649 int j = isl_basic_map_alloc_inequality(bmap);
1650 if (j < 0)
1651 return -1;
1652 t = bmap->ineq[j];
1653 bmap->ineq[j] = bmap->ineq[bmap->n_ineq - 1];
1654 bmap->ineq[bmap->n_ineq - 1] = bmap->eq[-1];
1655 bmap->eq[-1] = t;
1656 bmap->n_eq++;
1657 bmap->n_ineq--;
1658 bmap->eq--;
1659 return 0;
1660 }
1661 isl_seq_clr(bmap->eq[bmap->n_eq] + 1 + total,
1662 bmap->extra - bmap->n_div);
1663 return bmap->n_eq++;
1664}
1665
1670
1672 __isl_take isl_basic_map *bmap, unsigned n)
1673{
1674 if (!bmap)
1675 return NULL;
1676 if (n > bmap->n_eq)
1678 "invalid number of equalities",
1679 isl_basic_map_free(bmap));
1680 bmap->n_eq -= n;
1681 return bmap;
1682}
1683
1690
1691/* Drop the equality constraint at position "pos",
1692 * preserving the order of the other equality constraints.
1693 */
1695{
1696 isl_int *t;
1697 int r;
1698
1699 if (!bmap)
1700 return -1;
1701 isl_assert(bmap->ctx, pos < bmap->n_eq, return -1);
1702
1703 t = bmap->eq[pos];
1704 bmap->n_eq--;
1705 for (r = pos; r < bmap->n_eq; ++r)
1706 bmap->eq[r] = bmap->eq[r + 1];
1707 bmap->eq[bmap->n_eq] = t;
1708
1709 return 0;
1710}
1711
1712/* Turn inequality "pos" of "bmap" into an equality.
1713 *
1714 * In particular, we move the inequality in front of the equalities
1715 * and move the last inequality in the position of the moved inequality.
1716 * Note that isl_tab_make_equalities_explicit depends on this particular
1717 * change in the ordering of the constraints.
1718 */
1720 __isl_keep isl_basic_map *bmap, unsigned pos)
1721{
1722 isl_int *t;
1723
1724 t = bmap->ineq[pos];
1725 bmap->ineq[pos] = bmap->ineq[bmap->n_ineq - 1];
1726 bmap->ineq[bmap->n_ineq - 1] = bmap->eq[-1];
1727 bmap->eq[-1] = t;
1728 bmap->n_eq++;
1729 bmap->n_ineq--;
1730 bmap->eq--;
1735}
1736
1737static int room_for_ineq(__isl_keep isl_basic_map *bmap, unsigned n)
1738{
1739 return bmap->n_ineq + n <= bmap->eq - bmap->ineq;
1740}
1741
1743{
1745 struct isl_ctx *ctx;
1746
1748 if (total < 0)
1749 return -1;
1750 ctx = bmap->ctx;
1751 isl_assert(ctx, room_for_ineq(bmap, 1), return -1);
1757 isl_seq_clr(bmap->ineq[bmap->n_ineq] + 1 + total,
1758 bmap->extra - bmap->n_div);
1759 return bmap->n_ineq++;
1760}
1761
1766
1768 __isl_take isl_basic_map *bmap, unsigned n)
1769{
1770 if (!bmap)
1771 return NULL;
1772 if (n > bmap->n_ineq)
1774 "invalid number of inequalities",
1775 return isl_basic_map_free(bmap));
1776 bmap->n_ineq -= n;
1777 return bmap;
1778}
1779
1786
1788{
1789 isl_int *t;
1790 if (!bmap)
1791 return -1;
1792 isl_assert(bmap->ctx, pos < bmap->n_ineq, return -1);
1793
1794 if (pos != bmap->n_ineq - 1) {
1795 t = bmap->ineq[pos];
1796 bmap->ineq[pos] = bmap->ineq[bmap->n_ineq - 1];
1797 bmap->ineq[bmap->n_ineq - 1] = t;
1799 }
1800 bmap->n_ineq--;
1801 return 0;
1802}
1803
1808
1810 isl_int *eq)
1811{
1812 isl_bool empty;
1814 int k;
1815
1816 empty = isl_basic_map_plain_is_empty(bmap);
1817 if (empty < 0)
1818 return isl_basic_map_free(bmap);
1819 if (empty)
1820 return bmap;
1821
1822 bmap = isl_basic_map_cow(bmap);
1823 bmap = isl_basic_map_extend_constraints(bmap, 1, 0);
1825 if (total < 0)
1826 return isl_basic_map_free(bmap);
1828 if (k < 0)
1829 goto error;
1830 isl_seq_cpy(bmap->eq[k], eq, 1 + total);
1831 return bmap;
1832error:
1833 isl_basic_map_free(bmap);
1834 return NULL;
1835}
1836
1842
1844 isl_int *ineq)
1845{
1847 int k;
1848
1849 bmap = isl_basic_map_cow(bmap);
1850 bmap = isl_basic_map_extend_constraints(bmap, 0, 1);
1852 if (total < 0)
1853 return isl_basic_map_free(bmap);
1855 if (k < 0)
1856 goto error;
1857 isl_seq_cpy(bmap->ineq[k], ineq, 1 + total);
1858 return bmap;
1859error:
1860 isl_basic_map_free(bmap);
1861 return NULL;
1862}
1863
1869
1871{
1873
1875 if (total < 0)
1876 return -1;
1877 isl_assert(bmap->ctx, bmap->n_div < bmap->extra, return -1);
1878 isl_seq_clr(bmap->div[bmap->n_div] + 1 + 1 + total,
1879 bmap->extra - bmap->n_div);
1881 return bmap->n_div++;
1882}
1883
1888
1889#undef TYPE
1890#define TYPE isl_basic_map
1891#include "check_type_range_templ.c"
1892
1893/* Check that there are "n" dimensions of type "type" starting at "first"
1894 * in "bset".
1895 */
1897 enum isl_dim_type type, unsigned first, unsigned n)
1898{
1900 type, first, n);
1901}
1902
1903/* Insert an extra integer division, prescribed by "div", to "bmap"
1904 * at (integer division) position "pos".
1905 *
1906 * The integer division is first added at the end and then moved
1907 * into the right position.
1908 */
1911{
1912 int i, k;
1914
1915 bmap = isl_basic_map_cow(bmap);
1917 if (total < 0 || !div)
1918 return isl_basic_map_free(bmap);
1919
1920 if (div->size != 1 + 1 + total)
1922 "unexpected size", return isl_basic_map_free(bmap));
1923 if (isl_basic_map_check_range(bmap, isl_dim_div, pos, 0) < 0)
1924 return isl_basic_map_free(bmap);
1925
1926 bmap = isl_basic_map_extend(bmap, 1, 0, 2);
1927 k = isl_basic_map_alloc_div(bmap);
1928 if (k < 0)
1929 return isl_basic_map_free(bmap);
1930 isl_seq_cpy(bmap->div[k], div->el, div->size);
1931 isl_int_set_si(bmap->div[k][div->size], 0);
1932
1933 for (i = k; i > pos; --i)
1934 bmap = isl_basic_map_swap_div(bmap, i, i - 1);
1935
1936 return bmap;
1937}
1938
1939/* Insert an extra integer division, prescribed by "div", to "bset"
1940 * at (integer division) position "pos".
1941 */
1944{
1945 isl_basic_map *bmap = bset_to_bmap(bset);
1946 bmap = isl_basic_map_insert_div(bmap, pos, div);
1947 return bset_from_bmap(bmap);
1948}
1949
1951{
1952 if (!bmap)
1953 return isl_stat_error;
1954 isl_assert(bmap->ctx, n <= bmap->n_div, return isl_stat_error);
1955 bmap->n_div -= n;
1956 return isl_stat_ok;
1957}
1958
1961 unsigned i_pos, unsigned o_pos)
1962{
1963 isl_size total, n_param, n_in, n_out, n_div;
1964 unsigned o_in, o_out;
1965 isl_ctx *ctx;
1966 isl_space *space;
1967 struct isl_dim_map *dim_map;
1968
1969 space = isl_basic_map_peek_space(bmap2);
1970 if (!bmap1 || !space)
1971 goto error;
1972
1974 n_param = isl_basic_map_dim(bmap2, isl_dim_param);
1975 n_in = isl_basic_map_dim(bmap2, isl_dim_in);
1976 o_in = isl_basic_map_offset(bmap1, isl_dim_in) - 1 + i_pos;
1977 n_out = isl_basic_map_dim(bmap2, isl_dim_out);
1978 o_out = isl_basic_map_offset(bmap1, isl_dim_out) - 1 + o_pos;
1979 n_div = isl_basic_map_dim(bmap2, isl_dim_div);
1980 if (total < 0 || n_param < 0 || n_in < 0 || n_out < 0 || n_div < 0)
1981 goto error;
1982 ctx = isl_basic_map_get_ctx(bmap1);
1983 dim_map = isl_dim_map_alloc(ctx, total + n_div);
1984 isl_dim_map_dim_range(dim_map, space, isl_dim_param, 0, n_param, 0);
1985 isl_dim_map_dim_range(dim_map, space, isl_dim_in, 0, n_in, o_in);
1986 isl_dim_map_dim_range(dim_map, space, isl_dim_out, 0, n_out, o_out);
1987 isl_dim_map_div(dim_map, bmap2, total);
1988
1989 return isl_basic_map_add_constraints_dim_map(bmap1, bmap2, dim_map);
1990error:
1991 isl_basic_map_free(bmap1);
1992 isl_basic_map_free(bmap2);
1993 return NULL;
1994}
1995
1997 unsigned extra, unsigned n_eq, unsigned n_ineq)
1998{
1999 isl_space *space;
2000 struct isl_basic_map *ext;
2001 unsigned flags;
2002 int dims_ok;
2003
2004 if (!base)
2005 goto error;
2006
2007 dims_ok = base->extra >= base->n_div + extra;
2008
2009 if (dims_ok && room_for_con(base, n_eq + n_ineq) &&
2010 room_for_ineq(base, n_ineq))
2011 return base;
2012
2013 extra += base->extra;
2014 n_eq += base->n_eq;
2015 n_ineq += base->n_ineq;
2016
2017 space = isl_basic_map_get_space(base);
2019 if (!ext)
2020 goto error;
2021
2022 if (dims_ok)
2023 ext->sample = isl_vec_copy(base->sample);
2024 flags = base->flags;
2025 ext = add_constraints(ext, base, 0, 0);
2026 if (ext) {
2027 ext->flags = flags;
2029 }
2030
2031 return ext;
2032
2033error:
2034 isl_basic_map_free(base);
2035 return NULL;
2036}
2037
2039 unsigned extra, unsigned n_eq, unsigned n_ineq)
2040{
2042 extra, n_eq, n_ineq));
2043}
2044
2050
2052 __isl_take isl_basic_set *base, unsigned n_eq, unsigned n_ineq)
2053{
2054 isl_basic_map *bmap = bset_to_bmap(base);
2056 return bset_from_bmap(bmap);
2057}
2058
2063
2065{
2066 if (!bmap)
2067 return NULL;
2068
2069 if (bmap->ref > 1) {
2070 bmap->ref--;
2071 bmap = isl_basic_map_dup(bmap);
2072 }
2073 if (bmap)
2075 return bmap;
2076}
2077
2078/* Clear all cached information in "map", either because it is about
2079 * to be modified or because it is being freed.
2080 * Always return the same pointer that is passed in.
2081 * This is needed for the use in isl_map_free.
2082 */
2084{
2085 isl_basic_map_free(map->cached_simple_hull[0]);
2086 isl_basic_map_free(map->cached_simple_hull[1]);
2087 map->cached_simple_hull[0] = NULL;
2088 map->cached_simple_hull[1] = NULL;
2089 return map;
2090}
2091
2096
2097/* Return an isl_map that is equal to "map" and that has only
2098 * a single reference.
2099 *
2100 * If the original input already has only one reference, then
2101 * simply return it, but clear all cached information, since
2102 * it may be rendered invalid by the operations that will be
2103 * performed on the result.
2104 *
2105 * Otherwise, create a duplicate (without any cached information).
2106 */
2108{
2109 if (!map)
2110 return NULL;
2111
2112 if (map->ref == 1)
2113 return clear_caches(map);
2114 map->ref--;
2115 return isl_map_dup(map);
2116}
2117
2118static void swap_vars(struct isl_blk blk, isl_int *a,
2119 unsigned a_len, unsigned b_len)
2120{
2121 isl_seq_cpy(blk.data, a+a_len, b_len);
2122 isl_seq_cpy(blk.data+b_len, a, a_len);
2123 isl_seq_cpy(a, blk.data, b_len+a_len);
2124}
2125
2127 __isl_take isl_basic_map *bmap, unsigned pos, unsigned n1, unsigned n2)
2128{
2129 int i;
2130 struct isl_blk blk;
2131
2132 if (isl_basic_map_check_range(bmap, isl_dim_all, pos - 1, n1 + n2) < 0)
2133 goto error;
2134
2135 if (n1 == 0 || n2 == 0)
2136 return bmap;
2137
2138 bmap = isl_basic_map_cow(bmap);
2139 if (!bmap)
2140 return NULL;
2141
2142 blk = isl_blk_alloc(bmap->ctx, n1 + n2);
2143 if (isl_blk_is_error(blk))
2144 goto error;
2145
2146 for (i = 0; i < bmap->n_eq; ++i)
2147 swap_vars(blk,
2148 bmap->eq[i] + pos, n1, n2);
2149
2150 for (i = 0; i < bmap->n_ineq; ++i)
2151 swap_vars(blk,
2152 bmap->ineq[i] + pos, n1, n2);
2153
2154 for (i = 0; i < bmap->n_div; ++i)
2155 swap_vars(blk,
2156 bmap->div[i]+1 + pos, n1, n2);
2157
2158 isl_blk_free(bmap->ctx, blk);
2159
2161 bmap = isl_basic_map_gauss(bmap, NULL);
2162 return isl_basic_map_finalize(bmap);
2163error:
2164 isl_basic_map_free(bmap);
2165 return NULL;
2166}
2167
2168/* The given basic map has turned out to be empty.
2169 * Explicitly mark it as such and change the representation
2170 * to a canonical representation of the empty basic map.
2171 * Since the basic map has conflicting constraints,
2172 * it must have at least one constraint, except perhaps
2173 * if it was already explicitly marked as being empty.
2174 * Do nothing in the latter case, i.e., if it has been marked empty and
2175 * has no constraints.
2176 */
2179{
2180 int i = 0;
2181 isl_bool empty;
2182 isl_size n;
2184
2186 empty = isl_basic_map_plain_is_empty(bmap);
2187 if (n < 0 || empty < 0)
2188 return isl_basic_map_free(bmap);
2189 if (n == 0 && empty)
2190 return bmap;
2192 if (total < 0)
2193 return isl_basic_map_free(bmap);
2194 if (isl_basic_map_free_div(bmap, bmap->n_div) < 0)
2195 return isl_basic_map_free(bmap);
2196 bmap = isl_basic_map_free_inequality(bmap, bmap->n_ineq);
2197 if (!bmap)
2198 return NULL;
2199 if (bmap->n_eq > 0) {
2200 bmap = isl_basic_map_free_equality(bmap, bmap->n_eq - 1);
2201 if (!bmap)
2202 return NULL;
2203 } else {
2205 if (i < 0)
2206 goto error;
2207 }
2208 isl_int_set_si(bmap->eq[i][0], 1);
2209 isl_seq_clr(bmap->eq[i]+1, total);
2211 isl_vec_free(bmap->sample);
2212 bmap->sample = NULL;
2213 return isl_basic_map_finalize(bmap);
2214error:
2215 isl_basic_map_free(bmap);
2216 return NULL;
2217}
2218
2224
2227{
2228 if (!bmap)
2229 return NULL;
2230
2232 return bmap;
2233
2234 bmap = isl_basic_map_cow(bmap);
2235 if (!bmap)
2236 return NULL;
2237
2239
2240 return isl_basic_map_finalize(bmap);
2241}
2242
2248
2251{
2252 if (!bset)
2253 return NULL;
2254
2256 return bset;
2257
2258 bset = isl_basic_set_cow(bset);
2259 if (!bset)
2260 return NULL;
2261
2263
2264 return isl_basic_set_finalize(bset);
2265}
2266
2268{
2269 int i;
2270
2271 map = isl_map_cow(map);
2272 if (!map)
2273 return NULL;
2274 for (i = 0; i < map->n; ++i) {
2275 map->p[i] = isl_basic_map_set_rational(map->p[i]);
2276 if (!map->p[i])
2277 goto error;
2278 }
2279 return map;
2280error:
2282 return NULL;
2283}
2284
2289
2290/* Given a constraint "c" that expresses a bound
2291 * on the variable at position "pos" in terms of the first "len" variables
2292 * (other than the variable itself if pos < len), extract this bound
2293 * as a function of those first "len" variables.
2294 *
2295 * That is, the constraint is of one of the following forms
2296 *
2297 * -e(...) + m x >= 0
2298 * e(...) - m x >= 0
2299 * -e(...) + m x = 0
2300 * e(...) - m x = 0
2301 *
2302 * Return (e(...)) / m, with the denominator m in the first position.
2303 */
2305 isl_int *c, int len, int pos)
2306{
2307 isl_vec *v;
2308
2309 v = isl_vec_alloc(ctx, 1 + 1 + len);
2310 if (!v)
2311 return NULL;
2312 if (isl_int_is_pos(c[1 + pos])) {
2313 isl_int_set(v->el[0], c[1 + pos]);
2314 isl_seq_neg(v->el + 1, c, 1 + len);
2315 } else {
2316 isl_int_neg(v->el[0], c[1 + pos]);
2317 isl_seq_cpy(v->el + 1, c, 1 + len);
2318 }
2319 if (pos < len)
2320 isl_int_set_si(v->el[1 + 1 + pos], 0);
2321
2322 return v;
2323}
2324
2325/* Return the position of the last non-zero coefficient of
2326 * inequality constraint "ineq" of "bmap" or length "len",
2327 * given that the coefficient at position "first" is non-zero,
2328 * or that it is known that there is at least one coefficient
2329 * after "first" that is non-zero.
2330 */
2332 int first, unsigned len)
2333{
2334 int last;
2335
2336 last = isl_seq_last_non_zero(bmap->ineq[ineq] + 1 + first + 1,
2337 len - (first + 1));
2338 if (last < 0)
2339 return first;
2340 else
2341 return first + 1 + last;
2342}
2343
2344/* Do the inequality constraints "i" and "j" of "bmap"
2345 * form a pair of opposite constraints, in the (first) "len" coefficients?
2346 */
2347static int is_constraint_pair(__isl_keep isl_basic_map *bmap, int i, int j,
2348 unsigned len)
2349{
2350 return isl_seq_is_neg(bmap->ineq[i] + 1, bmap->ineq[j] + 1, len);
2351}
2352
2353/* Given that inequality constraints "i" and "j" of "bmap"
2354 * form a pair of opposite constraints
2355 *
2356 * f(x) + c1 >= 0
2357 * -f(x) + c2 >= 0
2358 *
2359 * or
2360 *
2361 * -c1 <= f(x) <= c2
2362 *
2363 * do they allow for at most "bound" values in that direction?
2364 * That is, is the sum of their constant terms smaller than "bound"?
2365 *
2366 * "tmp" is a temporary location that can be used to store the sum.
2367 */
2369 int i, int j, isl_int bound, isl_int *tmp)
2370{
2371 isl_int_add(*tmp, bmap->ineq[i][0], bmap->ineq[j][0]);
2372 return isl_int_abs_lt(*tmp, bound);
2373}
2374
2375/* Return the position of an inequality constraint in "bmap"
2376 * that together with inequality constraint "ineq" forms
2377 * a pair of opposite constraints that allow at most "bound" values
2378 * in their shared direction and that appears before "ineq".
2379 * Return a position beyond the number of inequality constraints
2380 * if no such constraint can be found.
2381 *
2382 * The constraints of "bmap" are assumed to have been sorted.
2383 * This means that as soon as a constraint is found where the value
2384 * of the last coefficient (in absolute value) is different from that of "ineq",
2385 * no opposite constraint can be found.
2386 * It also means that only the coefficients up to this last coefficient
2387 * need to be compared.
2388 *
2389 * "pos" is the position of a coefficient that is known to be non-zero.
2390 * If no such position is known a priori, then the value 0 can be passed in.
2391 * "len" is the number of (relevant) coefficients in the constraints.
2392 * "tmp" is a temporary location that can be used to store the sum.
2393 */
2395 int ineq, int pos, int len, isl_int bound, isl_int *tmp)
2396{
2397 int j;
2398 int last;
2399 isl_size n_ineq;
2400
2401 n_ineq = isl_basic_map_n_inequality(bmap);
2402 if (n_ineq < 0)
2403 return isl_size_error;
2404
2405 last = extend_last_non_zero(bmap, ineq, pos, len);
2406
2407 for (j = ineq - 1; j >= 0; --j) {
2408 if (!isl_int_abs_eq(bmap->ineq[ineq][1 + last],
2409 bmap->ineq[j][1 + last]))
2410 return n_ineq;
2411 if (!is_constraint_pair(bmap, ineq, j, last + 1))
2412 continue;
2413 if (constraint_pair_has_bound(bmap, ineq, j, bound, tmp))
2414 return j;
2415 return n_ineq;
2416 }
2417
2418 return n_ineq;
2419}
2420
2421/* Return the position of an inequality constraint in "bmap"
2422 * that together with inequality constraint "ineq" forms
2423 * a pair of opposite constraints that allow at most "bound" values
2424 * in their shared direction and that appears after "ineq".
2425 * Return a position beyond the number of inequality constraints
2426 * if no such constraint can be found.
2427 *
2428 * The constraints of "bmap" are assumed to have been sorted.
2429 * This means that as soon as a constraint is found where the value
2430 * of the last coefficient (in absolute value) is different from that of "ineq",
2431 * no opposite constraint can be found.
2432 * It also means that only the coefficients up to this last coefficient
2433 * need to be compared.
2434 *
2435 * "pos" is the position of a coefficient that is known to be non-zero.
2436 * If no such position is known a priori, then the value 0 can be passed in.
2437 * "len" is the number of (relevant) coefficients in the constraints.
2438 * "tmp" is a temporary location that can be used to store the sum.
2439 */
2441 int ineq, int pos, int len, isl_int bound, isl_int *tmp)
2442{
2443 int j;
2444 int last;
2445 isl_size n_ineq;
2446
2447 n_ineq = isl_basic_map_n_inequality(bmap);
2448 if (n_ineq < 0)
2449 return isl_size_error;
2450
2451 last = extend_last_non_zero(bmap, ineq, pos, len);
2452
2453 for (j = ineq + 1; j < n_ineq; ++j) {
2454 if (!isl_int_abs_eq(bmap->ineq[ineq][1 + last],
2455 bmap->ineq[j][1 + last]))
2456 return n_ineq;
2457 if (isl_seq_any_non_zero(bmap->ineq[j] + 1 + last + 1,
2458 len - (last + 1)))
2459 return n_ineq;
2460 if (!is_constraint_pair(bmap, ineq, j, last + 1))
2461 continue;
2462 if (constraint_pair_has_bound(bmap, ineq, j, bound, tmp))
2463 return j;
2464 return n_ineq;
2465 }
2466
2467 return n_ineq;
2468}
2469
2470/* Swap divs "a" and "b" in "bmap" (without modifying any of the constraints
2471 * of "bmap").
2472 */
2473static void swap_div(__isl_keep isl_basic_map *bmap, int a, int b)
2474{
2475 isl_int *t = bmap->div[a];
2476 bmap->div[a] = bmap->div[b];
2477 bmap->div[b] = t;
2478}
2479
2480/* Swap divs "a" and "b" in "bmap" and adjust the constraints and
2481 * div definitions accordingly.
2482 */
2484 int a, int b)
2485{
2486 int i;
2487 isl_size off;
2488
2490 if (off < 0)
2491 return isl_basic_map_free(bmap);
2492
2493 swap_div(bmap, a, b);
2494
2495 for (i = 0; i < bmap->n_eq; ++i)
2496 isl_int_swap(bmap->eq[i][1+off+a], bmap->eq[i][1+off+b]);
2497
2498 for (i = 0; i < bmap->n_ineq; ++i)
2499 isl_int_swap(bmap->ineq[i][1+off+a], bmap->ineq[i][1+off+b]);
2500
2501 for (i = 0; i < bmap->n_div; ++i)
2502 isl_int_swap(bmap->div[i][1+1+off+a], bmap->div[i][1+1+off+b]);
2504
2505 return bmap;
2506}
2507
2508static void constraint_drop_vars(isl_int *c, unsigned n, unsigned rem)
2509{
2510 isl_seq_cpy(c, c + n, rem);
2511 isl_seq_clr(c + rem, n);
2512}
2513
2514/* Drop n dimensions starting at first.
2515 *
2516 * In principle, this frees up some extra variables as the number
2517 * of columns remains constant, but we would have to extend
2518 * the div array too as the number of rows in this array is assumed
2519 * to be equal to extra.
2520 */
2522 __isl_take isl_basic_set *bset, unsigned first, unsigned n)
2523{
2524 return isl_basic_map_drop(bset_to_bmap(bset), isl_dim_set, first, n);
2525}
2526
2527/* Move "n" divs starting at "first" to the end of the list of divs.
2528 */
2530 unsigned first, unsigned n)
2531{
2532 isl_int **div;
2533 int i;
2534
2535 if (first + n == bmap->n_div)
2536 return bmap;
2537
2538 div = isl_alloc_array(bmap->ctx, isl_int *, n);
2539 if (!div)
2540 goto error;
2541 for (i = 0; i < n; ++i)
2542 div[i] = bmap->div[first + i];
2543 for (i = 0; i < bmap->n_div - first - n; ++i)
2544 bmap->div[first + i] = bmap->div[first + n + i];
2545 for (i = 0; i < n; ++i)
2546 bmap->div[bmap->n_div - n + i] = div[i];
2547 free(div);
2548 return bmap;
2549error:
2550 isl_basic_map_free(bmap);
2551 return NULL;
2552}
2553
2554#undef TYPE
2555#define TYPE isl_map
2556static
2557#include "check_type_range_templ.c"
2558
2559/* Check that there are "n" dimensions of type "type" starting at "first"
2560 * in "set".
2561 */
2563 enum isl_dim_type type, unsigned first, unsigned n)
2564{
2565 return isl_map_check_range(set_to_map(set), type, first, n);
2566}
2567
2568/* Drop "n" dimensions of type "type" starting at "first".
2569 * Perform the core computation, without cowing or
2570 * simplifying and finalizing the result.
2571 *
2572 * In principle, this frees up some extra variables as the number
2573 * of columns remains constant, but we would have to extend
2574 * the div array too as the number of rows in this array is assumed
2575 * to be equal to extra.
2576 */
2579 unsigned first, unsigned n)
2580{
2581 int i;
2582 unsigned offset;
2583 unsigned left;
2585
2586 if (isl_basic_map_check_range(bmap, type, first, n) < 0)
2587 return isl_basic_map_free(bmap);
2588
2590 if (total < 0)
2591 return isl_basic_map_free(bmap);
2592
2593 offset = isl_basic_map_offset(bmap, type) + first;
2594 left = total - (offset - 1) - n;
2595 for (i = 0; i < bmap->n_eq; ++i)
2596 constraint_drop_vars(bmap->eq[i]+offset, n, left);
2597
2598 for (i = 0; i < bmap->n_ineq; ++i)
2599 constraint_drop_vars(bmap->ineq[i]+offset, n, left);
2600
2601 for (i = 0; i < bmap->n_div; ++i)
2602 constraint_drop_vars(bmap->div[i]+1+offset, n, left);
2603
2604 if (type == isl_dim_div) {
2605 bmap = move_divs_last(bmap, first, n);
2606 if (!bmap)
2607 return NULL;
2608 if (isl_basic_map_free_div(bmap, n) < 0)
2609 return isl_basic_map_free(bmap);
2610 } else
2611 bmap->dim = isl_space_drop_dims(bmap->dim, type, first, n);
2612 if (!bmap->dim)
2613 return isl_basic_map_free(bmap);
2614
2618 return bmap;
2619}
2620
2621/* Drop "n" dimensions of type "type" starting at "first".
2622 *
2623 * In principle, this frees up some extra variables as the number
2624 * of columns remains constant, but we would have to extend
2625 * the div array too as the number of rows in this array is assumed
2626 * to be equal to extra.
2627 */
2629 enum isl_dim_type type, unsigned first, unsigned n)
2630{
2631 if (!bmap)
2632 return NULL;
2633 if (n == 0 && !isl_space_is_named_or_nested(bmap->dim, type))
2634 return bmap;
2635
2636 bmap = isl_basic_map_cow(bmap);
2637 if (!bmap)
2638 return NULL;
2639
2640 bmap = isl_basic_map_drop_core(bmap, type, first, n);
2641
2642 bmap = isl_basic_map_simplify(bmap);
2643 return isl_basic_map_finalize(bmap);
2644}
2645
2647 enum isl_dim_type type, unsigned first, unsigned n)
2648{
2650 type, first, n));
2651}
2652
2653/* No longer consider "map" to be normalized.
2654 */
2656{
2657 if (!map)
2658 return NULL;
2660 return map;
2661}
2662
2664 enum isl_dim_type type, unsigned first, unsigned n)
2665{
2666 int i;
2667 isl_space *space;
2668
2669 if (isl_map_check_range(map, type, first, n) < 0)
2670 return isl_map_free(map);
2671
2672 if (n == 0 && !isl_space_is_named_or_nested(map->dim, type))
2673 return map;
2674 map = isl_map_cow(map);
2675 if (!map)
2676 goto error;
2677
2678 for (i = 0; i < map->n; ++i) {
2679 map->p[i] = isl_basic_map_drop(map->p[i], type, first, n);
2680 if (!map->p[i])
2681 goto error;
2682 }
2684
2685 space = isl_map_take_space(map);
2686 space = isl_space_drop_dims(space, type, first, n);
2687 map = isl_map_restore_space(map, space);
2688
2689 return map;
2690error:
2692 return NULL;
2693}
2694
2696 enum isl_dim_type type, unsigned first, unsigned n)
2697{
2698 return set_from_map(isl_map_drop(set_to_map(set), type, first, n));
2699}
2700
2701/* Drop the integer division at position "div", which is assumed
2702 * not to appear in any of the constraints or
2703 * in any of the other integer divisions.
2704 *
2705 * Since the integer division is redundant, there is no need to cow.
2706 */
2708 __isl_take isl_basic_map *bmap, unsigned div)
2709{
2710 return isl_basic_map_drop_core(bmap, isl_dim_div, div, 1);
2711}
2712
2713/* Eliminate the specified n dimensions starting at first from the
2714 * constraints, without removing the dimensions from the space.
2715 * If the set is rational, the dimensions are eliminated using Fourier-Motzkin.
2716 */
2718 enum isl_dim_type type, unsigned first, unsigned n)
2719{
2720 int i;
2721
2722 if (n == 0)
2723 return map;
2724
2725 if (isl_map_check_range(map, type, first, n) < 0)
2726 return isl_map_free(map);
2727
2728 map = isl_map_cow(map);
2729 if (!map)
2730 return NULL;
2731
2732 for (i = 0; i < map->n; ++i) {
2733 map->p[i] = isl_basic_map_eliminate(map->p[i], type, first, n);
2734 if (!map->p[i])
2735 goto error;
2736 }
2737 return map;
2738error:
2740 return NULL;
2741}
2742
2743/* Eliminate the specified n dimensions starting at first from the
2744 * constraints, without removing the dimensions from the space.
2745 * If the set is rational, the dimensions are eliminated using Fourier-Motzkin.
2746 */
2748 enum isl_dim_type type, unsigned first, unsigned n)
2749{
2751}
2752
2753/* Eliminate the specified n dimensions starting at first from the
2754 * constraints, without removing the dimensions from the space.
2755 * If the set is rational, the dimensions are eliminated using Fourier-Motzkin.
2756 */
2758 unsigned first, unsigned n)
2759{
2760 return isl_set_eliminate(set, isl_dim_set, first, n);
2761}
2762
2765{
2766 isl_size v_div;
2767
2769 if (v_div < 0)
2770 return isl_basic_map_free(bmap);
2771 bmap = isl_basic_map_eliminate_vars(bmap, v_div, bmap->n_div);
2772 if (!bmap)
2773 return NULL;
2774 bmap->n_div = 0;
2775 return isl_basic_map_finalize(bmap);
2776}
2777
2783
2785{
2786 int i;
2787
2788 if (!map)
2789 return NULL;
2790 if (map->n == 0)
2791 return map;
2792
2793 map = isl_map_cow(map);
2794 if (!map)
2795 return NULL;
2796
2797 for (i = 0; i < map->n; ++i) {
2798 map->p[i] = isl_basic_map_remove_divs(map->p[i]);
2799 if (!map->p[i])
2800 goto error;
2801 }
2802 return map;
2803error:
2805 return NULL;
2806}
2807
2812
2815 unsigned first, unsigned n)
2816{
2817 if (isl_basic_map_check_range(bmap, type, first, n) < 0)
2818 return isl_basic_map_free(bmap);
2819 if (n == 0 && !isl_space_is_named_or_nested(bmap->dim, type))
2820 return bmap;
2821 bmap = isl_basic_map_eliminate_vars(bmap,
2822 isl_basic_map_offset(bmap, type) - 1 + first, n);
2823 if (!bmap)
2824 return bmap;
2826 return bmap;
2827 bmap = isl_basic_map_drop(bmap, type, first, n);
2828 return bmap;
2829}
2830
2831/* Does the local variable "div" of "bmap" have a known expression
2832 * that involves the "n" variables starting at "first"?
2833 */
2835 int div, unsigned first, unsigned n)
2836{
2837 isl_bool unknown;
2838
2839 unknown = isl_basic_map_div_is_marked_unknown(bmap, div);
2840 if (unknown < 0 || unknown)
2841 return isl_bool_not(unknown);
2842 if (isl_seq_any_non_zero(bmap->div[div] + 1 + 1 + first, n))
2843 return isl_bool_true;
2844
2845 return isl_bool_false;
2846}
2847
2848/* Return true if the definition of the given div (recursively) involves
2849 * any of the given variables.
2850 */
2852 unsigned first, unsigned n)
2853{
2854 int i;
2855 isl_bool involves;
2856 isl_size n_div, v_div;
2857
2858 involves = isl_basic_map_div_expr_involves_vars(bmap, div, first, n);
2859 if (involves < 0 || involves)
2860 return involves;
2861
2862 n_div = isl_basic_map_dim(bmap, isl_dim_div);
2864 if (n_div < 0 || v_div < 0)
2865 return isl_bool_error;
2866 for (i = n_div - 1; i >= 0; --i) {
2867 isl_bool involves;
2868
2869 if (isl_int_is_zero(bmap->div[div][1 + 1 + v_div + i]))
2870 continue;
2871 involves = div_involves_vars(bmap, i, first, n);
2872 if (involves < 0 || involves)
2873 return involves;
2874 }
2875
2876 return isl_bool_false;
2877}
2878
2879/* Does the definition of any integer division involve
2880 * any of the given variables?
2881 */
2883 unsigned first, unsigned n)
2884{
2885 int i;
2886 isl_size n_div;
2887
2888 n_div = isl_basic_map_dim(bmap, isl_dim_div);
2889 if (n_div < 0)
2890 return isl_bool_error;
2891
2892 for (i = 0; i < n_div; ++i) {
2893 isl_bool has;
2894
2895 has = isl_basic_map_div_expr_involves_vars(bmap, i, first, n);
2896 if (has < 0 || has)
2897 return has;
2898 }
2899
2900 return isl_bool_false;
2901}
2902
2903/* Try and add a lower and/or upper bound on "div" to "bmap"
2904 * based on inequality "i".
2905 * "total" is the total number of variables (excluding the divs).
2906 * "v" is a temporary object that can be used during the calculations.
2907 * If "lb" is set, then a lower bound should be constructed.
2908 * If "ub" is set, then an upper bound should be constructed.
2909 *
2910 * The calling function has already checked that the inequality does not
2911 * reference "div", but we still need to check that the inequality is
2912 * of the right form. We'll consider the case where we want to construct
2913 * a lower bound. The construction of upper bounds is similar.
2914 *
2915 * Let "div" be of the form
2916 *
2917 * q = floor((a + f(x))/d)
2918 *
2919 * We essentially check if constraint "i" is of the form
2920 *
2921 * b + f(x) >= 0
2922 *
2923 * so that we can use it to derive a lower bound on "div".
2924 * However, we allow a slightly more general form
2925 *
2926 * b + g(x) >= 0
2927 *
2928 * with the condition that the coefficients of g(x) - f(x) are all
2929 * divisible by d.
2930 * Rewriting this constraint as
2931 *
2932 * 0 >= -b - g(x)
2933 *
2934 * adding a + f(x) to both sides and dividing by d, we obtain
2935 *
2936 * (a + f(x))/d >= (a-b)/d + (f(x)-g(x))/d
2937 *
2938 * Taking the floor on both sides, we obtain
2939 *
2940 * q >= floor((a-b)/d) + (f(x)-g(x))/d
2941 *
2942 * or
2943 *
2944 * (g(x)-f(x))/d + ceil((b-a)/d) + q >= 0
2945 *
2946 * In the case of an upper bound, we construct the constraint
2947 *
2948 * (g(x)+f(x))/d + floor((b+a)/d) - q >= 0
2949 *
2950 */
2952 __isl_take isl_basic_map *bmap, int div, int i,
2953 unsigned total, isl_int v, int lb, int ub)
2954{
2955 int j;
2956
2957 for (j = 0; (lb || ub) && j < total + bmap->n_div; ++j) {
2958 if (lb) {
2959 isl_int_sub(v, bmap->ineq[i][1 + j],
2960 bmap->div[div][1 + 1 + j]);
2961 lb = isl_int_is_divisible_by(v, bmap->div[div][0]);
2962 }
2963 if (ub) {
2964 isl_int_add(v, bmap->ineq[i][1 + j],
2965 bmap->div[div][1 + 1 + j]);
2966 ub = isl_int_is_divisible_by(v, bmap->div[div][0]);
2967 }
2968 }
2969 if (!lb && !ub)
2970 return bmap;
2971
2972 bmap = isl_basic_map_cow(bmap);
2973 bmap = isl_basic_map_extend_constraints(bmap, 0, lb + ub);
2974 if (lb) {
2975 int k = isl_basic_map_alloc_inequality(bmap);
2976 if (k < 0)
2977 goto error;
2978 for (j = 0; j < 1 + total + bmap->n_div; ++j) {
2979 isl_int_sub(bmap->ineq[k][j], bmap->ineq[i][j],
2980 bmap->div[div][1 + j]);
2981 isl_int_cdiv_q(bmap->ineq[k][j],
2982 bmap->ineq[k][j], bmap->div[div][0]);
2983 }
2984 isl_int_set_si(bmap->ineq[k][1 + total + div], 1);
2985 }
2986 if (ub) {
2987 int k = isl_basic_map_alloc_inequality(bmap);
2988 if (k < 0)
2989 goto error;
2990 for (j = 0; j < 1 + total + bmap->n_div; ++j) {
2991 isl_int_add(bmap->ineq[k][j], bmap->ineq[i][j],
2992 bmap->div[div][1 + j]);
2993 isl_int_fdiv_q(bmap->ineq[k][j],
2994 bmap->ineq[k][j], bmap->div[div][0]);
2995 }
2996 isl_int_set_si(bmap->ineq[k][1 + total + div], -1);
2997 }
2998
2999 return bmap;
3000error:
3001 isl_basic_map_free(bmap);
3002 return NULL;
3003}
3004
3005/* This function is called right before "div" is eliminated from "bmap"
3006 * using Fourier-Motzkin.
3007 * Look through the constraints of "bmap" for constraints on the argument
3008 * of the integer division and use them to construct constraints on the
3009 * integer division itself. These constraints can then be combined
3010 * during the Fourier-Motzkin elimination.
3011 * Note that it is only useful to introduce lower bounds on "div"
3012 * if "bmap" already contains upper bounds on "div" as the newly
3013 * introduce lower bounds can then be combined with the pre-existing
3014 * upper bounds. Similarly for upper bounds.
3015 * We therefore first check if "bmap" contains any lower and/or upper bounds
3016 * on "div".
3017 *
3018 * It is interesting to note that the introduction of these constraints
3019 * can indeed lead to more accurate results, even when compared to
3020 * deriving constraints on the argument of "div" from constraints on "div".
3021 * Consider, for example, the set
3022 *
3023 * { [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }
3024 *
3025 * The second constraint can be rewritten as
3026 *
3027 * 2 * [(-i-2j+3)/4] + k >= 0
3028 *
3029 * from which we can derive
3030 *
3031 * -i - 2j + 3 >= -2k
3032 *
3033 * or
3034 *
3035 * i + 2j <= 3 + 2k
3036 *
3037 * Combined with the first constraint, we obtain
3038 *
3039 * -3 <= 3 + 2k or k >= -3
3040 *
3041 * If, on the other hand we derive a constraint on [(i+2j)/4] from
3042 * the first constraint, we obtain
3043 *
3044 * [(i + 2j)/4] >= [-3/4] = -1
3045 *
3046 * Combining this constraint with the second constraint, we obtain
3047 *
3048 * k >= -2
3049 */
3051 __isl_take isl_basic_map *bmap, int div)
3052{
3053 int i;
3054 int check_lb, check_ub;
3055 isl_int v;
3056 isl_size v_div;
3057
3058 if (!bmap)
3059 return NULL;
3060
3061 if (isl_int_is_zero(bmap->div[div][0]))
3062 return bmap;
3063
3065 if (v_div < 0)
3066 return isl_basic_map_free(bmap);
3067
3068 check_lb = 0;
3069 check_ub = 0;
3070 for (i = 0; (!check_lb || !check_ub) && i < bmap->n_ineq; ++i) {
3071 int s = isl_int_sgn(bmap->ineq[i][1 + v_div + div]);
3072 if (s > 0)
3073 check_ub = 1;
3074 if (s < 0)
3075 check_lb = 1;
3076 }
3077
3078 if (!check_lb && !check_ub)
3079 return bmap;
3080
3081 isl_int_init(v);
3082
3083 for (i = 0; bmap && i < bmap->n_ineq; ++i) {
3084 if (!isl_int_is_zero(bmap->ineq[i][1 + v_div + div]))
3085 continue;
3086
3087 bmap = insert_bounds_on_div_from_ineq(bmap, div, i, v_div, v,
3088 check_lb, check_ub);
3089 }
3090
3091 isl_int_clear(v);
3092
3093 return bmap;
3094}
3095
3096/* Remove all divs (recursively) involving any of the given variables
3097 * in their definitions.
3098 */
3100 __isl_take isl_basic_map *bmap, unsigned first, unsigned n)
3101{
3102 int i;
3103
3104 for (i = bmap->n_div - 1; i >= 0; --i) {
3105 isl_bool involves;
3106
3107 involves = div_involves_vars(bmap, i, first, n);
3108 if (involves < 0)
3109 return isl_basic_map_free(bmap);
3110 if (!involves)
3111 continue;
3112 bmap = insert_bounds_on_div(bmap, i);
3113 bmap = isl_basic_map_remove_dims(bmap, isl_dim_div, i, 1);
3114 if (!bmap)
3115 return NULL;
3116 i = bmap->n_div;
3117 }
3118
3119 return bmap;
3120}
3121
3122/* Data structure for communicating data between detect_mod and
3123 * substitute_div_mod.
3124 *
3125 * "pos" is the position of the variable that is being examined.
3126 *
3127 * "lower_f" is the index of the constraint
3128 * -f(x) + m i + t m n h(alpha) >= 0
3129 * "lower_g" is the index of the constraint
3130 * -g(x) + i >= 0
3131 * "m" and "n" correspond to the values in the first constraint.
3132 * "sum" is a temporary variable that is used internally inside detect_mod.
3133 */
3145
3146/* Initialize "data".
3147 */
3149{
3150 isl_int_init(data->m);
3151 isl_int_init(data->n);
3152 isl_int_init(data->sum);
3153}
3154
3155/* Free any memory allocated by "data".
3156 */
3158{
3159 isl_int_clear(data->sum);
3160 isl_int_clear(data->n);
3161 isl_int_clear(data->m);
3162}
3163
3164/* Is the variable at position data->pos
3165 * equal to a specific case of a nested modulo?
3166 *
3167 * In particular, look for two pairs of constraints
3168 *
3169 * -f(x) + m i + t m n h(alpha) >= 0
3170 * f(x) - m i - t m n h(alpha) + c >= 0
3171 *
3172 * and
3173 *
3174 * -g(x) + i >= 0
3175 * g(x) - i + d >= 0
3176 *
3177 * where f(x) and g(x) are expressions in the other variables,
3178 * excluding local variables,
3179 * h(alpha) is a non-zero expression in the local variable,
3180 * t is +1 or -1,
3181 * c < m, and
3182 * d < n.
3183 *
3184 * If these pairs of constraints are found,
3185 * then store the constraint index of the first f-constraint in data->lower_f,
3186 * the index of the first g-constraint in data->lower_g and
3187 * the values m and n in data->m and data->n.
3188 *
3189 * The constraints are assumed to have been sorted,
3190 * which means that the constraints in a pair are close to each other.
3191 * The sorting also means that the f-constraints appear
3192 * after the g-constraints.
3193 */
3195 struct isl_detect_mod_data *data)
3196{
3197 int i;
3198 isl_size j;
3199 isl_size n_ineq;
3200 isl_size v_div, n_div, total;
3201
3202 n_ineq = isl_basic_map_n_inequality(bmap);
3204 n_div = isl_basic_map_dim(bmap, isl_dim_div);
3206 if (n_ineq < 0 || v_div < 0 || n_div < 0 || total < 0)
3207 return isl_bool_error;
3208 if (n_ineq < 4)
3209 return isl_bool_false;
3210
3211 for (i = n_ineq - 1; i >= 1; --i) {
3212 isl_seq_gcd(bmap->ineq[i] + 1 + v_div, n_div, &data->n);
3213 if (isl_int_is_zero(data->n))
3214 return isl_bool_false;
3215 isl_int_abs(data->m, bmap->ineq[i][1 + data->pos]);
3216 j = find_earlier_constraint_in_pair(bmap, i, data->pos, total,
3217 data->m, &data->sum);
3218 if (j < 0)
3219 return isl_bool_error;
3220 if (j >= n_ineq)
3221 continue;
3222 if (!isl_int_is_divisible_by(data->n, data->m))
3223 continue;
3224 if (isl_int_is_pos(bmap->ineq[i][1 + data->pos]))
3225 data->lower_f = i;
3226 else
3227 data->lower_f = j;
3228 isl_int_divexact(data->n, data->n, data->m);
3229 isl_int_abs(data->n, data->n);
3230 break;
3231 }
3232 if (i < 1)
3233 return isl_bool_false;
3234 for (i = j - 1; i >= 1; --i) {
3235 if (isl_seq_any_non_zero(bmap->ineq[i] + 1 + v_div, n_div))
3236 continue;
3237 if (!isl_int_is_one(bmap->ineq[i][1 + data->pos]) &&
3238 !isl_int_is_negone(bmap->ineq[i][1 + data->pos]))
3239 continue;
3240 j = find_earlier_constraint_in_pair(bmap, i, data->pos, v_div,
3241 data->m, &data->sum);
3242 if (j < 0)
3243 return isl_bool_error;
3244 if (j >= n_ineq)
3245 continue;
3246 if (isl_int_is_pos(bmap->ineq[i][1 + data->pos]))
3247 data->lower_g = i;
3248 else
3249 data->lower_g = j;
3250 break;
3251 }
3252 if (i < 1)
3253 return isl_bool_false;
3254 return isl_bool_true;
3255}
3256
3257/* Given an affine expression "aff" in the variables of "bset" that expresses
3258 * a bound on the variable at position "pos" in terms of the other variables,
3259 * extract this expression as a function of those other variables,
3260 * excluding any local variables.
3261 */
3263 __isl_keep isl_basic_set *bset, isl_int *aff, int pos)
3264{
3265 isl_size dim;
3266 isl_ctx *ctx;
3267 isl_vec *v;
3268 isl_space *space;
3269 isl_local_space *ls;
3270
3271 space = isl_basic_set_peek_space(bset);
3272 dim = isl_space_dim(space, isl_dim_all);
3273 if (dim < 0)
3274 return NULL;
3276 ctx = isl_basic_set_get_ctx(bset);
3277 v = extract_bound_from_constraint(ctx, aff, dim, pos);
3278 return isl_aff_alloc_vec(ls, v);
3279}
3280
3281/* Given that inequality "ineq" of "bset" expresses a lower bound
3282 * on the variable at position "pos" in terms of the other variables,
3283 * extract this lower bound as a function of those other variables,
3284 * excluding any local variables.
3285 */
3287 __isl_keep isl_basic_set *bset, int ineq, int pos)
3288{
3289 if (!bset)
3290 return NULL;
3291 return extract_aff(bset, bset->ineq[ineq], pos);
3292}
3293
3294/* Given that there are two pairs of constraints
3295 *
3296 * -f(x) + m i + t m n h(alpha) >= 0
3297 * f(x) - m i - t m n h(alpha) + c >= 0
3298 *
3299 * and
3300 *
3301 * -g(x) + i >= 0
3302 * g(x) - i + d >= 0
3303 *
3304 * where f(x) and g(x) are expressions in the other variables,
3305 * excluding local variables,
3306 * h(alpha) is a non-zero expression in the local variable,
3307 * t is +1 or -1,
3308 * c < m, and
3309 * d < n,
3310 * derive an expression for i and plug that into "bmap".
3311 *
3312 * In particular, the first pair of constraints implies
3313 *
3314 * 0 <= (-f(x) + m i) % (m n) <= c
3315 * 0 <= (m floor(-f(x)/m) + (-f(x)) mod m + m i) % (m n) <= c
3316 * 0 <= (m floor(-f(x)/m) + m i) % (m n) + (-f(x)) mod m <= c
3317 * 0 <= m ((floor(-f(x)/m) + i) % n) + (-f(x)) mod m <= c
3318 *
3319 * or
3320 *
3321 * (floor(-f(x)/m) + i) % n = 0
3322 *
3323 * because c < m, which can be rewritten to
3324 *
3325 * (floor(-f(x)/m) + g(x) - g(x) + i) % n = 0
3326 *
3327 * or
3328 *
3329 * (-g(x) + i) % n = (-floor(-f(x)/m) - g(x)) % n
3330 *
3331 * Since 0 <= -g(x) + i <= d < n,
3332 *
3333 * -g(x) + i = (-floor(-f(x)/m) - g(x)) % n
3334 *
3335 * or
3336 *
3337 * i = (-floor(-f(x)/m) - g(x)) % n + g(x)
3338 *
3339 * Note that the lower bounds on i derived from the original constraints are
3340 *
3341 * i >= f(x)/m
3342 * i >= g(x)
3343 *
3344 * (ignoring local variables).
3345 *
3346 * The expression for i is plugged into "bmap", which results
3347 * in a basic map equivalent to "bmap" given i is equal to the expression,
3348 * so an equality constraint is added to ensure the meaning is preserved.
3349 */
3351 __isl_take isl_basic_map *bmap, unsigned pos,
3352 struct isl_detect_mod_data *data)
3353{
3354 isl_ctx *ctx;
3355 isl_basic_set *bset, *eq;
3356 isl_space *space;
3357 isl_aff *g, *f, *aff, *it;
3358 isl_val *v;
3359 isl_size v_in;
3361
3363 if (v_in < 0)
3364 return isl_basic_map_free(bmap);
3365
3366 ctx = isl_basic_map_get_ctx(bmap);
3367 bset = isl_basic_map_wrap(bmap);
3368 space = isl_basic_set_get_space(bset);
3369 g = extract_lower_bound_aff(bset, data->lower_g, pos);
3370 f = extract_lower_bound_aff(bset, data->lower_f, pos);
3371 ma = isl_space_identity_multi_aff_on_domain(space);
3374 v = isl_val_int_from_isl_int(ctx, data->n);
3375 aff = isl_aff_mod_val(aff, v);
3376 aff = isl_aff_add(aff, g);
3377 it = isl_multi_aff_get_at(ma, pos - v_in);
3379 ma = isl_multi_aff_set_at(ma, pos - v_in, aff);
3381 bset = isl_basic_set_intersect(bset, eq);
3382 return isl_basic_set_unwrap(bset);
3383}
3384
3385/* Remove all divs (recursively) involving any of the given dimensions
3386 * in their definitions.
3387 *
3388 * If it is a single input or output dimension that
3389 * should not appear in any integer division expression and
3390 * if there is indeed an integer division expression
3391 * involving that dimension, then check if there are any constraints
3392 * that imply that the given dimension is equal to some expression
3393 * in the other dimensions.
3394 * If so, plug in that expression for the given dimension
3395 * so that the integer division expressions no longer
3396 * involve that dimension.
3397 */
3400 enum isl_dim_type type, unsigned first, unsigned n)
3401{
3402 isl_size off;
3403 isl_bool used;
3404 isl_bool found;
3405 struct isl_detect_mod_data data;
3406
3407 if (isl_basic_map_check_range(bmap, type, first, n) < 0)
3408 return isl_basic_map_free(bmap);
3409 off = isl_basic_map_var_offset(bmap, type);
3410 if (off < 0)
3411 return isl_basic_map_free(bmap);
3412 first += off;
3413
3414 if (type == isl_dim_param || type == isl_dim_div || n != 1)
3415 return remove_divs_involving_vars(bmap, first, n);
3416 used = isl_basic_map_any_div_involves_vars(bmap, first, n);
3417 if (used < 0)
3418 return isl_basic_map_free(bmap);
3419 if (!used)
3420 return bmap;
3421 bmap = isl_basic_map_sort_constraints(bmap);
3423 data.pos = first;
3424 found = detect_mod(bmap, &data);
3425 if (!found)
3426 bmap = remove_divs_involving_vars(bmap, first, n);
3427 else
3428 bmap = substitute_div_mod(bmap, first, &data);
3430 return bmap;
3431}
3432
3435 enum isl_dim_type type, unsigned first, unsigned n)
3436{
3437 return isl_basic_map_remove_divs_involving_dims(bset, type, first, n);
3438}
3439
3441 enum isl_dim_type type, unsigned first, unsigned n)
3442{
3443 int i;
3444
3445 if (!map)
3446 return NULL;
3447 if (map->n == 0)
3448 return map;
3449
3450 map = isl_map_cow(map);
3451 if (!map)
3452 return NULL;
3453
3454 for (i = 0; i < map->n; ++i) {
3456 type, first, n);
3457 if (!map->p[i])
3458 goto error;
3459 }
3460 return map;
3461error:
3463 return NULL;
3464}
3465
3472
3473/* Does the description of "bmap" depend on the specified dimensions?
3474 * We also check whether the dimensions appear in any of the div definitions.
3475 * In principle there is no need for this check. If the dimensions appear
3476 * in a div definition, they also appear in the defining constraints of that
3477 * div.
3478 */
3480 enum isl_dim_type type, unsigned first, unsigned n)
3481{
3482 int i;
3483
3484 if (isl_basic_map_check_range(bmap, type, first, n) < 0)
3485 return isl_bool_error;
3486
3487 first += isl_basic_map_offset(bmap, type);
3488 for (i = 0; i < bmap->n_eq; ++i)
3489 if (isl_seq_any_non_zero(bmap->eq[i] + first, n))
3490 return isl_bool_true;
3491 for (i = 0; i < bmap->n_ineq; ++i)
3492 if (isl_seq_any_non_zero(bmap->ineq[i] + first, n))
3493 return isl_bool_true;
3494 for (i = 0; i < bmap->n_div; ++i) {
3495 if (isl_int_is_zero(bmap->div[i][0]))
3496 continue;
3497 if (isl_seq_any_non_zero(bmap->div[i] + 1 + first, n))
3498 return isl_bool_true;
3499 }
3500
3501 return isl_bool_false;
3502}
3503
3505 enum isl_dim_type type, unsigned first, unsigned n)
3506{
3507 int i;
3508
3509 if (isl_map_check_range(map, type, first, n) < 0)
3510 return isl_bool_error;
3511
3512 for (i = 0; i < map->n; ++i) {
3513 isl_bool involves = isl_basic_map_involves_dims(map->p[i],
3514 type, first, n);
3515 if (involves < 0 || involves)
3516 return involves;
3517 }
3518
3519 return isl_bool_false;
3520}
3521
3523 enum isl_dim_type type, unsigned first, unsigned n)
3524{
3525 return isl_basic_map_involves_dims(bset, type, first, n);
3526}
3527
3529 enum isl_dim_type type, unsigned first, unsigned n)
3530{
3531 return isl_map_involves_dims(set, type, first, n);
3532}
3533
3534/* Does "bset" involve any local variables, i.e., integer divisions?
3535 */
3537{
3538 isl_size n;
3539
3541 if (n < 0)
3542 return isl_bool_error;
3543 return isl_bool_ok(n > 0);
3544}
3545
3546/* isl_set_every_basic_set callback that checks whether "bset"
3547 * is free of local variables.
3548 */
3553
3554/* Does "set" involve any local variables, i.e., integer divisions?
3555 */
3557{
3558 isl_bool no_locals;
3559
3560 no_locals = isl_set_every_basic_set(set, &basic_set_no_locals, NULL);
3561 return isl_bool_not(no_locals);
3562}
3563
3564/* Drop all constraints in bmap that involve any of the dimensions
3565 * first to first+n-1.
3566 * This function only performs the actual removal of constraints.
3567 *
3568 * This function should not call finalize since it is used by
3569 * remove_redundant_divs, which in turn is called by isl_basic_map_finalize.
3570 */
3572 __isl_take isl_basic_map *bmap, unsigned first, unsigned n)
3573{
3574 int i;
3575
3576 if (n == 0)
3577 return bmap;
3578
3579 bmap = isl_basic_map_cow(bmap);
3580
3581 if (!bmap)
3582 return NULL;
3583
3584 for (i = bmap->n_eq - 1; i >= 0; --i) {
3585 if (!isl_seq_any_non_zero(bmap->eq[i] + 1 + first, n))
3586 continue;
3587 if (isl_basic_map_drop_equality(bmap, i) < 0)
3588 return isl_basic_map_free(bmap);
3589 }
3590
3591 for (i = bmap->n_ineq - 1; i >= 0; --i) {
3592 if (!isl_seq_any_non_zero(bmap->ineq[i] + 1 + first, n))
3593 continue;
3594 if (isl_basic_map_drop_inequality(bmap, i) < 0)
3595 return isl_basic_map_free(bmap);
3596 }
3597
3598 return bmap;
3599}
3600
3601/* Drop all constraints in bset that involve any of the dimensions
3602 * first to first+n-1.
3603 * This function only performs the actual removal of constraints.
3604 */
3610
3611/* Drop all constraints in bmap that do not involve any of the dimensions
3612 * first to first + n - 1 of the given type.
3613 */
3616 enum isl_dim_type type, unsigned first, unsigned n)
3617{
3618 int i;
3619
3620 if (n == 0) {
3621 isl_space *space = isl_basic_map_get_space(bmap);
3622 isl_basic_map_free(bmap);
3623 return isl_basic_map_universe(space);
3624 }
3625 bmap = isl_basic_map_cow(bmap);
3626 if (!bmap)
3627 return NULL;
3628
3629 if (isl_basic_map_check_range(bmap, type, first, n) < 0)
3630 return isl_basic_map_free(bmap);
3631
3632 first += isl_basic_map_offset(bmap, type) - 1;
3633
3634 for (i = bmap->n_eq - 1; i >= 0; --i) {
3635 if (isl_seq_any_non_zero(bmap->eq[i] + 1 + first, n))
3636 continue;
3637 if (isl_basic_map_drop_equality(bmap, i) < 0)
3638 return isl_basic_map_free(bmap);
3639 }
3640
3641 for (i = bmap->n_ineq - 1; i >= 0; --i) {
3642 if (isl_seq_any_non_zero(bmap->ineq[i] + 1 + first, n))
3643 continue;
3644 if (isl_basic_map_drop_inequality(bmap, i) < 0)
3645 return isl_basic_map_free(bmap);
3646 }
3647
3649 return bmap;
3650}
3651
3652/* Drop all constraints in bset that do not involve any of the dimensions
3653 * first to first + n - 1 of the given type.
3654 */
3662
3663/* Drop all constraints in bmap that involve any of the dimensions
3664 * first to first + n - 1 of the given type.
3665 */
3668 enum isl_dim_type type, unsigned first, unsigned n)
3669{
3670 if (!bmap)
3671 return NULL;
3672 if (n == 0)
3673 return bmap;
3674
3675 if (isl_basic_map_check_range(bmap, type, first, n) < 0)
3676 return isl_basic_map_free(bmap);
3677
3678 bmap = isl_basic_map_remove_divs_involving_dims(bmap, type, first, n);
3679 first += isl_basic_map_offset(bmap, type) - 1;
3680 bmap = isl_basic_map_drop_constraints_involving(bmap, first, n);
3682 return bmap;
3683}
3684
3685/* Drop all constraints in bset that involve any of the dimensions
3686 * first to first + n - 1 of the given type.
3687 */
3695
3696/* Drop constraints from "map" by applying "drop" to each basic map.
3697 */
3699 enum isl_dim_type type, unsigned first, unsigned n,
3701 enum isl_dim_type type, unsigned first, unsigned n))
3702{
3703 int i;
3704
3705 if (isl_map_check_range(map, type, first, n) < 0)
3706 return isl_map_free(map);
3707
3708 map = isl_map_cow(map);
3709 if (!map)
3710 return NULL;
3711
3712 for (i = 0; i < map->n; ++i) {
3713 map->p[i] = drop(map->p[i], type, first, n);
3714 if (!map->p[i])
3715 return isl_map_free(map);
3716 }
3717
3718 if (map->n > 1)
3720
3721 return map;
3722}
3723
3724/* Drop all constraints in map that involve any of the dimensions
3725 * first to first + n - 1 of the given type.
3726 */
3729 enum isl_dim_type type, unsigned first, unsigned n)
3730{
3731 if (n == 0)
3732 return map;
3733 return drop_constraints(map, type, first, n,
3735}
3736
3737/* Drop all constraints in "map" that do not involve any of the dimensions
3738 * first to first + n - 1 of the given type.
3739 */
3742 enum isl_dim_type type, unsigned first, unsigned n)
3743{
3744 if (n == 0) {
3747 return isl_map_universe(space);
3748 }
3749 return drop_constraints(map, type, first, n,
3751}
3752
3753/* Drop all constraints in set that involve any of the dimensions
3754 * first to first + n - 1 of the given type.
3755 */
3762
3763/* Drop all constraints in "set" that do not involve any of the dimensions
3764 * first to first + n - 1 of the given type.
3765 */
3772
3773/* Does local variable "div" of "bmap" have a complete explicit representation?
3774 * Having a complete explicit representation requires not only
3775 * an explicit representation, but also that all local variables
3776 * that appear in this explicit representation in turn have
3777 * a complete explicit representation.
3778 */
3780{
3781 int i;
3782 unsigned div_offset = isl_basic_map_offset(bmap, isl_dim_div);
3783 isl_bool marked;
3784
3785 marked = isl_basic_map_div_is_marked_unknown(bmap, div);
3786 if (marked < 0 || marked)
3787 return isl_bool_not(marked);
3788
3789 for (i = bmap->n_div - 1; i >= 0; --i) {
3790 isl_bool known;
3791
3792 if (isl_int_is_zero(bmap->div[div][1 + div_offset + i]))
3793 continue;
3794 known = isl_basic_map_div_is_known(bmap, i);
3795 if (known < 0 || !known)
3796 return known;
3797 }
3798
3799 return isl_bool_true;
3800}
3801
3802/* Remove all divs that are unknown or defined in terms of unknown divs.
3803 */
3806{
3807 int i;
3808
3809 if (!bmap)
3810 return NULL;
3811
3812 for (i = bmap->n_div - 1; i >= 0; --i) {
3813 if (isl_basic_map_div_is_known(bmap, i))
3814 continue;
3815 bmap = isl_basic_map_remove_dims(bmap, isl_dim_div, i, 1);
3816 if (!bmap)
3817 return NULL;
3818 i = bmap->n_div;
3819 }
3820
3821 return bmap;
3822}
3823
3824/* Remove all divs that are unknown or defined in terms of unknown divs.
3825 */
3831
3833{
3834 int i;
3835
3836 if (!map)
3837 return NULL;
3838 if (map->n == 0)
3839 return map;
3840
3841 map = isl_map_cow(map);
3842 if (!map)
3843 return NULL;
3844
3845 for (i = 0; i < map->n; ++i) {
3847 if (!map->p[i])
3848 goto error;
3849 }
3850 return map;
3851error:
3853 return NULL;
3854}
3855
3860
3863 enum isl_dim_type type, unsigned first, unsigned n)
3864{
3865 isl_basic_map *bmap = bset_to_bmap(bset);
3866 bmap = isl_basic_map_remove_dims(bmap, type, first, n);
3867 return bset_from_bmap(bmap);
3868}
3869
3871 enum isl_dim_type type, unsigned first, unsigned n)
3872{
3873 int i;
3874
3875 if (n == 0)
3876 return map;
3877
3878 map = isl_map_cow(map);
3879 if (isl_map_check_range(map, type, first, n) < 0)
3880 return isl_map_free(map);
3881
3882 for (i = 0; i < map->n; ++i) {
3883 map->p[i] = isl_basic_map_eliminate_vars(map->p[i],
3884 isl_basic_map_offset(map->p[i], type) - 1 + first, n);
3885 if (!map->p[i])
3886 goto error;
3887 }
3888 map = isl_map_drop(map, type, first, n);
3889 return map;
3890error:
3892 return NULL;
3893}
3894
3896 enum isl_dim_type type, unsigned first, unsigned n)
3897{
3899 type, first, n));
3900}
3901
3902/* Project out n inputs starting at first using Fourier-Motzkin */
3904 unsigned first, unsigned n)
3905{
3906 return isl_map_remove_dims(map, isl_dim_in, first, n);
3907}
3908
3910 FILE *out, int indent)
3911{
3912 isl_printer *p;
3913
3914 if (!bset) {
3915 fprintf(out, "null basic set\n");
3916 return;
3917 }
3918
3919 fprintf(out, "%*s", indent, "");
3920 fprintf(out, "ref: %d, nparam: %d, dim: %d, extra: %d, flags: %x\n",
3921 bset->ref, bset->dim->nparam, bset->dim->n_out,
3922 bset->extra, bset->flags);
3923
3925 p = isl_printer_set_dump(p, 1);
3926 p = isl_printer_set_indent(p, indent);
3931}
3932
3934 FILE *out, int indent)
3935{
3936 isl_printer *p;
3937
3938 if (!bmap) {
3939 fprintf(out, "null basic map\n");
3940 return;
3941 }
3942
3943 fprintf(out, "%*s", indent, "");
3944 fprintf(out, "ref: %d, nparam: %d, in: %d, out: %d, extra: %d, "
3945 "flags: %x, n_name: %d\n",
3946 bmap->ref,
3947 bmap->dim->nparam, bmap->dim->n_in, bmap->dim->n_out,
3948 bmap->extra, bmap->flags, bmap->dim->n_id);
3949
3951 p = isl_printer_set_dump(p, 1);
3952 p = isl_printer_set_indent(p, indent);
3957}
3958
3960 unsigned pos)
3961{
3963
3965 if (total < 0)
3966 return isl_basic_map_free(bmap);
3967 if (pos >= bmap->n_ineq)
3969 "invalid position", return isl_basic_map_free(bmap));
3970 isl_seq_neg(bmap->ineq[pos], bmap->ineq[pos], 1 + total);
3971 isl_int_sub_ui(bmap->ineq[pos][0], bmap->ineq[pos][0], 1);
3974 return bmap;
3975}
3976
3978 unsigned flags)
3979{
3980 if (isl_space_check_is_set(space) < 0)
3981 goto error;
3982 return isl_map_alloc_space(space, n, flags);
3983error:
3984 isl_space_free(space);
3985 return NULL;
3986}
3987
3988/* Make sure "map" has room for at least "n" more basic maps.
3989 */
3991{
3992 int i;
3993 struct isl_map *grown = NULL;
3994
3995 if (!map)
3996 return NULL;
3997 isl_assert(map->ctx, n >= 0, goto error);
3998 if (map->n + n <= map->size)
3999 return map;
4000 grown = isl_map_alloc_space(isl_map_get_space(map), map->n + n, map->flags);
4001 if (!grown)
4002 goto error;
4003 for (i = 0; i < map->n; ++i) {
4004 grown->p[i] = isl_basic_map_copy(map->p[i]);
4005 if (!grown->p[i])
4006 goto error;
4007 grown->n++;
4008 }
4010 return grown;
4011error:
4012 isl_map_free(grown);
4014 return NULL;
4015}
4016
4017/* Make sure "set" has room for at least "n" more basic sets.
4018 */
4023
4028
4029/* This function performs the same operation as isl_set_from_basic_set,
4030 * but is considered as a function on an isl_basic_set when exported.
4031 */
4036
4038{
4039 struct isl_map *map;
4040
4041 if (!bmap)
4042 return NULL;
4043
4045 return isl_map_add_basic_map(map, bmap);
4046}
4047
4054
4059
4060void isl_set_print_internal(__isl_keep isl_set *set, FILE *out, int indent)
4061{
4062 int i;
4063
4064 if (!set) {
4065 fprintf(out, "null set\n");
4066 return;
4067 }
4068
4069 fprintf(out, "%*s", indent, "");
4070 fprintf(out, "ref: %d, n: %d, nparam: %d, dim: %d, flags: %x\n",
4071 set->ref, set->n, set->dim->nparam, set->dim->n_out,
4072 set->flags);
4073 for (i = 0; i < set->n; ++i) {
4074 fprintf(out, "%*s", indent, "");
4075 fprintf(out, "basic set %d:\n", i);
4076 isl_basic_set_print_internal(set->p[i], out, indent+4);
4077 }
4078}
4079
4080void isl_map_print_internal(__isl_keep isl_map *map, FILE *out, int indent)
4081{
4082 int i;
4083
4084 if (!map) {
4085 fprintf(out, "null map\n");
4086 return;
4087 }
4088
4089 fprintf(out, "%*s", indent, "");
4090 fprintf(out, "ref: %d, n: %d, nparam: %d, in: %d, out: %d, "
4091 "flags: %x, n_name: %d\n",
4092 map->ref, map->n, map->dim->nparam, map->dim->n_in,
4093 map->dim->n_out, map->flags, map->dim->n_id);
4094 for (i = 0; i < map->n; ++i) {
4095 fprintf(out, "%*s", indent, "");
4096 fprintf(out, "basic map %d:\n", i);
4097 isl_basic_map_print_internal(map->p[i], out, indent+4);
4098 }
4099}
4100
4101/* Check that the space of "bset" is the same as that of the domain of "bmap".
4102 */
4105{
4106 isl_bool ok;
4107
4108 ok = isl_basic_map_compatible_domain(bmap, bset);
4109 if (ok < 0)
4110 return isl_stat_error;
4111 if (!ok)
4113 "incompatible spaces", return isl_stat_error);
4114
4115 return isl_stat_ok;
4116}
4117
4120{
4121 struct isl_basic_map *bmap_domain;
4122 isl_size dim;
4123
4125 goto error;
4126
4128 if (dim < 0)
4129 goto error;
4130 if (dim != 0 &&
4132 goto error;
4133
4134 bmap = isl_basic_map_cow(bmap);
4135 if (!bmap)
4136 goto error;
4137 bmap = isl_basic_map_extend(bmap,
4138 bset->n_div, bset->n_eq, bset->n_ineq);
4139 bmap_domain = isl_basic_map_from_domain(bset);
4140 bmap = add_constraints(bmap, bmap_domain, 0, 0);
4141
4142 bmap = isl_basic_map_simplify(bmap);
4143 return isl_basic_map_finalize(bmap);
4144error:
4145 isl_basic_map_free(bmap);
4146 isl_basic_set_free(bset);
4147 return NULL;
4148}
4149
4150/* Check that the space of "bset" is the same as that of the range of "bmap".
4151 */
4154{
4155 isl_bool ok;
4156
4157 ok = isl_basic_map_compatible_range(bmap, bset);
4158 if (ok < 0)
4159 return isl_stat_error;
4160 if (!ok)
4162 "incompatible spaces", return isl_stat_error);
4163
4164 return isl_stat_ok;
4165}
4166
4169{
4170 struct isl_basic_map *bmap_range;
4171 isl_size dim;
4172
4174 goto error;
4175
4177 if (dim < 0)
4178 goto error;
4179 if (dim != 0 && isl_basic_map_check_compatible_range(bmap, bset) < 0)
4180 goto error;
4181
4183 isl_basic_set_free(bset);
4184 return bmap;
4185 }
4186
4187 bmap = isl_basic_map_cow(bmap);
4188 if (!bmap)
4189 goto error;
4190 bmap = isl_basic_map_extend(bmap,
4191 bset->n_div, bset->n_eq, bset->n_ineq);
4192 bmap_range = bset_to_bmap(bset);
4193 bmap = add_constraints(bmap, bmap_range, 0, 0);
4194
4195 bmap = isl_basic_map_simplify(bmap);
4196 return isl_basic_map_finalize(bmap);
4197error:
4198 isl_basic_map_free(bmap);
4199 isl_basic_set_free(bset);
4200 return NULL;
4201}
4202
4204 __isl_keep isl_vec *vec)
4205{
4206 int i;
4208 isl_int s;
4209
4211 if (total < 0 || !vec)
4212 return isl_bool_error;
4213
4214 if (1 + total != vec->size)
4215 return isl_bool_false;
4216
4217 isl_int_init(s);
4218
4219 for (i = 0; i < bmap->n_eq; ++i) {
4220 isl_seq_inner_product(vec->el, bmap->eq[i], 1 + total, &s);
4221 if (!isl_int_is_zero(s)) {
4222 isl_int_clear(s);
4223 return isl_bool_false;
4224 }
4225 }
4226
4227 for (i = 0; i < bmap->n_ineq; ++i) {
4228 isl_seq_inner_product(vec->el, bmap->ineq[i], 1 + total, &s);
4229 if (isl_int_is_neg(s)) {
4230 isl_int_clear(s);
4231 return isl_bool_false;
4232 }
4233 }
4234
4235 isl_int_clear(s);
4236
4237 return isl_bool_true;
4238}
4239
4245
4248{
4249 struct isl_vec *sample = NULL;
4250 isl_space *space1, *space2;
4251 isl_size dim1, dim2, nparam1, nparam2;
4252
4253 if (isl_basic_map_check_equal_params(bmap1, bmap2) < 0)
4254 goto error;
4255 space1 = isl_basic_map_peek_space(bmap1);
4256 space2 = isl_basic_map_peek_space(bmap2);
4257 dim1 = isl_space_dim(space1, isl_dim_all);
4258 dim2 = isl_space_dim(space2, isl_dim_all);
4259 nparam1 = isl_space_dim(space1, isl_dim_param);
4260 nparam2 = isl_space_dim(space2, isl_dim_param);
4261 if (dim1 < 0 || dim2 < 0 || nparam1 < 0 || nparam2 < 0)
4262 goto error;
4263 if (dim1 == nparam1 && dim2 != nparam2)
4264 return isl_basic_map_intersect(bmap2, bmap1);
4265
4266 if (dim2 != nparam2 &&
4267 isl_basic_map_check_equal_space(bmap1, bmap2) < 0)
4268 goto error;
4269
4270 if (isl_basic_map_plain_is_empty(bmap1)) {
4271 isl_basic_map_free(bmap2);
4272 return bmap1;
4273 }
4274 if (isl_basic_map_plain_is_empty(bmap2)) {
4275 isl_basic_map_free(bmap1);
4276 return bmap2;
4277 }
4278
4279 if (bmap1->sample &&
4280 isl_basic_map_contains(bmap1, bmap1->sample) > 0 &&
4281 isl_basic_map_contains(bmap2, bmap1->sample) > 0)
4282 sample = isl_vec_copy(bmap1->sample);
4283 else if (bmap2->sample &&
4284 isl_basic_map_contains(bmap1, bmap2->sample) > 0 &&
4285 isl_basic_map_contains(bmap2, bmap2->sample) > 0)
4286 sample = isl_vec_copy(bmap2->sample);
4287
4288 bmap1 = isl_basic_map_cow(bmap1);
4289 if (!bmap1)
4290 goto error;
4291 bmap1 = isl_basic_map_extend(bmap1,
4292 bmap2->n_div, bmap2->n_eq, bmap2->n_ineq);
4293 bmap1 = add_constraints(bmap1, bmap2, 0, 0);
4294
4295 if (!bmap1)
4296 isl_vec_free(sample);
4297 else if (sample) {
4298 isl_vec_free(bmap1->sample);
4299 bmap1->sample = sample;
4300 }
4301
4302 bmap1 = isl_basic_map_simplify(bmap1);
4303 return isl_basic_map_finalize(bmap1);
4304error:
4305 if (sample)
4306 isl_vec_free(sample);
4307 isl_basic_map_free(bmap1);
4308 isl_basic_map_free(bmap2);
4309 return NULL;
4310}
4311
4318
4319/* Intersect the parameter domain of "bmap" with "bset".
4320 *
4321 * isl_basic_map_intersect handles this as a special case.
4322 */
4328
4331{
4332 isl_basic_map *bmap;
4333
4334 bmap = bset_to_bmap(bset1);
4335 bmap = isl_basic_map_intersect_params(bmap, bset2);
4336 return bset_from_bmap(bmap);
4337}
4338
4339/* Does "map" consist of a single disjunct, without any local variables?
4340 */
4342{
4343 isl_size n_div;
4344
4345 if (!map)
4346 return isl_bool_error;
4347 if (map->n != 1)
4348 return isl_bool_false;
4349 n_div = isl_basic_map_dim(map->p[0], isl_dim_div);
4350 if (n_div < 0)
4351 return isl_bool_error;
4352 if (n_div != 0)
4353 return isl_bool_false;
4354 return isl_bool_true;
4355}
4356
4357/* Check that "map" consists of a single disjunct, without any local variables.
4358 */
4360{
4361 isl_bool ok;
4362
4364 if (ok < 0)
4365 return isl_stat_error;
4366 if (ok)
4367 return isl_stat_ok;
4368
4370 "unexpectedly not convex or involving local variables",
4371 return isl_stat_error);
4372}
4373
4374/* Special case of isl_map_intersect, where both map1 and map2
4375 * are convex, without any divs and such that either map1 or map2
4376 * contains a single constraint. This constraint is then simply
4377 * added to the other map.
4378 */
4381{
4382 if (check_convex_no_locals(map1) < 0 ||
4384 goto error;
4385
4386 if (map2->p[0]->n_eq + map2->p[0]->n_ineq != 1)
4387 return isl_map_intersect(map2, map1);
4388
4390 if (!map1)
4391 goto error;
4394 return map1;
4395 }
4396 if (map2->p[0]->n_eq == 1)
4397 map1->p[0] = isl_basic_map_add_eq(map1->p[0], map2->p[0]->eq[0]);
4398 else
4399 map1->p[0] = isl_basic_map_add_ineq(map1->p[0],
4400 map2->p[0]->ineq[0]);
4401
4402 map1->p[0] = isl_basic_map_simplify(map1->p[0]);
4403 map1->p[0] = isl_basic_map_finalize(map1->p[0]);
4404 if (!map1->p[0])
4405 goto error;
4406
4408 isl_basic_map_free(map1->p[0]);
4409 map1->n = 0;
4410 }
4411
4413
4415 return map1;
4416error:
4419 return NULL;
4420}
4421
4422/* map2 may be either a parameter domain or a map living in the same
4423 * space as map1.
4424 */
4427{
4428 unsigned flags = 0;
4430 isl_map *result;
4431 int i, j;
4432 isl_size dim2, nparam2;
4433
4434 if (!map1 || !map2)
4435 goto error;
4436
4439 isl_space_is_equal(map1->dim, map2->dim)) {
4441 return map1;
4442 }
4445 isl_space_is_equal(map1->dim, map2->dim)) {
4447 return map2;
4448 }
4449
4452 isl_space_is_equal(map1->dim, map2->dim) &&
4453 (map1->p[0]->n_eq + map1->p[0]->n_ineq == 1 ||
4454 map2->p[0]->n_eq + map2->p[0]->n_ineq == 1))
4456
4458 if (equal < 0)
4459 goto error;
4460 if (equal) {
4462 return map1;
4463 }
4464
4465 dim2 = isl_map_dim(map2, isl_dim_all);
4466 nparam2 = isl_map_dim(map2, isl_dim_param);
4467 if (dim2 < 0 || nparam2 < 0)
4468 goto error;
4469 if (dim2 != nparam2)
4470 isl_assert(map1->ctx,
4471 isl_space_is_equal(map1->dim, map2->dim), goto error);
4472
4476
4478 map1->n * map2->n, flags);
4479 if (!result)
4480 goto error;
4481 for (i = 0; i < map1->n; ++i)
4482 for (j = 0; j < map2->n; ++j) {
4483 struct isl_basic_map *part;
4485 isl_basic_map_copy(map1->p[i]),
4486 isl_basic_map_copy(map2->p[j]));
4487 if (isl_basic_map_is_empty(part) < 0)
4488 part = isl_basic_map_free(part);
4489 result = isl_map_add_basic_map(result, part);
4490 if (!result)
4491 goto error;
4492 }
4495 return result;
4496error:
4499 return NULL;
4500}
4501
4504{
4506 goto error;
4508error:
4511 return NULL;
4512}
4513
4520
4527
4528/* map_intersect_internal accepts intersections
4529 * with parameter domains, so we can just call that function.
4530 */
4537
4543
4545{
4546 isl_space *space;
4547 unsigned pos;
4548 isl_size n1, n2;
4549
4550 if (!bmap)
4551 return NULL;
4552 bmap = isl_basic_map_cow(bmap);
4553 if (!bmap)
4554 return NULL;
4555 space = isl_space_reverse(isl_space_copy(bmap->dim));
4557 n1 = isl_basic_map_dim(bmap, isl_dim_in);
4558 n2 = isl_basic_map_dim(bmap, isl_dim_out);
4559 if (n1 < 0 || n2 < 0)
4560 bmap = isl_basic_map_free(bmap);
4561 bmap = isl_basic_map_swap_vars(bmap, pos, n1, n2);
4562 return isl_basic_map_reset_space(bmap, space);
4563}
4564
4565/* Given a basic map where the tuple of type "type" is a wrapped map,
4566 * swap domain and range of that wrapped map.
4567 */
4570{
4571 isl_space *space;
4572 isl_size offset, n1, n2;
4573
4574 space = isl_basic_map_peek_space(bmap);
4578 if (offset < 0 || n1 < 0 || n2 < 0)
4579 return isl_basic_map_free(bmap);
4580
4581 bmap = isl_basic_map_swap_vars(bmap, 1 + offset, n1, n2);
4582
4583 space = isl_basic_map_take_space(bmap);
4584 space = isl_space_reverse_wrapped(space, type);
4585 bmap = isl_basic_map_restore_space(bmap, space);
4586
4587 return bmap;
4588}
4589
4590/* Given a basic map (A -> B) -> C, return the corresponding basic map
4591 * (B -> A) -> C.
4592 */
4595{
4596 isl_space *space;
4597
4598 space = isl_basic_map_peek_space(bmap);
4600 return isl_basic_map_free(bmap);
4602
4603 return bmap;
4604}
4605
4606/* Given a basic map A -> (B -> C), return the corresponding basic map
4607 * A -> (C -> B).
4608 */
4611{
4612 isl_space *space;
4613
4614 space = isl_basic_map_peek_space(bmap);
4615 if (isl_space_check_range_is_wrapping(space) < 0)
4616 return isl_basic_map_free(bmap);
4618
4619 return bmap;
4620}
4621
4622/* Given a basic map that is actually a basic set (A -> B),
4623 * return the corresponding basic set (B -> A) as a basic map.
4624 */
4627{
4628 isl_space *space;
4629
4630 space = isl_basic_map_peek_space(bmap);
4631 if (isl_space_check_is_wrapping(space) < 0)
4632 return isl_basic_map_free(bmap);
4634
4635 return bmap;
4636}
4637
4640{
4641 isl_space *space;
4642
4643 if (!bmap)
4644 return NULL;
4645 if (!isl_space_is_named_or_nested(bmap->dim, type))
4646 return bmap;
4647
4648 space = isl_basic_map_get_space(bmap);
4649 space = isl_space_reset(space, type);
4650 bmap = isl_basic_map_reset_space(bmap, space);
4651 return bmap;
4652}
4653
4656 unsigned pos, unsigned n)
4657{
4658 isl_bool rational, is_empty;
4659 isl_space *res_space;
4660 struct isl_basic_map *res;
4661 struct isl_dim_map *dim_map;
4663 unsigned off;
4664 enum isl_dim_type t;
4665
4666 if (n == 0)
4667 return basic_map_space_reset(bmap, type);
4668
4669 is_empty = isl_basic_map_plain_is_empty(bmap);
4671 if (is_empty < 0 || total < 0)
4672 return isl_basic_map_free(bmap);
4674 type, pos, n);
4675 if (!res_space)
4676 return isl_basic_map_free(bmap);
4677 if (is_empty) {
4678 isl_basic_map_free(bmap);
4679 return isl_basic_map_empty(res_space);
4680 }
4681
4682 dim_map = isl_dim_map_alloc(bmap->ctx, total + n);
4683 off = 0;
4684 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
4685 isl_size dim;
4686
4687 if (t != type) {
4688 isl_dim_map_dim(dim_map, bmap->dim, t, off);
4689 } else {
4691 if (size < 0)
4692 dim_map = isl_dim_map_free(dim_map);
4693 isl_dim_map_dim_range(dim_map, bmap->dim, t,
4694 0, pos, off);
4695 isl_dim_map_dim_range(dim_map, bmap->dim, t,
4696 pos, size - pos, off + pos + n);
4697 }
4698 dim = isl_space_dim(res_space, t);
4699 if (dim < 0)
4700 dim_map = isl_dim_map_free(dim_map);
4701 off += dim;
4702 }
4703 isl_dim_map_div(dim_map, bmap, off);
4704
4705 res = isl_basic_map_alloc_space(res_space,
4706 bmap->n_div, bmap->n_eq, bmap->n_ineq);
4707 rational = isl_basic_map_is_rational(bmap);
4708 if (rational < 0)
4710 if (rational)
4714}
4715
4718 enum isl_dim_type type, unsigned pos, unsigned n)
4719{
4720 return isl_basic_map_insert_dims(bset, type, pos, n);
4721}
4722
4724 enum isl_dim_type type, unsigned n)
4725{
4726 isl_size dim;
4727
4728 dim = isl_basic_map_dim(bmap, type);
4729 if (dim < 0)
4730 return isl_basic_map_free(bmap);
4731 return isl_basic_map_insert_dims(bmap, type, dim, n);
4732}
4733
4735 enum isl_dim_type type, unsigned n)
4736{
4737 if (!bset)
4738 return NULL;
4739 isl_assert(bset->ctx, type != isl_dim_in, goto error);
4740 return isl_basic_map_add_dims(bset, type, n);
4741error:
4742 isl_basic_set_free(bset);
4743 return NULL;
4744}
4745
4747 enum isl_dim_type type)
4748{
4749 isl_space *space;
4750
4751 if (!map || !isl_space_is_named_or_nested(map->dim, type))
4752 return map;
4753
4754 space = isl_map_get_space(map);
4755 space = isl_space_reset(space, type);
4756 map = isl_map_reset_space(map, space);
4757 return map;
4758}
4759
4761 enum isl_dim_type type, unsigned pos, unsigned n)
4762{
4763 int i;
4764 isl_space *space;
4765
4766 if (n == 0)
4767 return map_space_reset(map, type);
4768
4769 map = isl_map_cow(map);
4770 if (!map)
4771 return NULL;
4772
4773 for (i = 0; i < map->n; ++i) {
4774 map->p[i] = isl_basic_map_insert_dims(map->p[i], type, pos, n);
4775 if (!map->p[i])
4776 goto error;
4777 }
4778
4779 space = isl_map_take_space(map);
4780 space = isl_space_insert_dims(space, type, pos, n);
4781 map = isl_map_restore_space(map, space);
4782
4783 return map;
4784error:
4786 return NULL;
4787}
4788
4790 enum isl_dim_type type, unsigned pos, unsigned n)
4791{
4792 return isl_map_insert_dims(set, type, pos, n);
4793}
4794
4796 enum isl_dim_type type, unsigned n)
4797{
4798 isl_size dim;
4799
4800 dim = isl_map_dim(map, type);
4801 if (dim < 0)
4802 return isl_map_free(map);
4803 return isl_map_insert_dims(map, type, dim, n);
4804}
4805
4807 enum isl_dim_type type, unsigned n)
4808{
4809 if (!set)
4810 return NULL;
4811 isl_assert(set->ctx, type != isl_dim_in, goto error);
4813error:
4815 return NULL;
4816}
4817
4820 enum isl_dim_type dst_type, unsigned dst_pos,
4821 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
4822{
4823 isl_space *space;
4824 struct isl_dim_map *dim_map;
4825 struct isl_basic_map *res;
4826 enum isl_dim_type t;
4828 unsigned off;
4829
4830 if (!bmap)
4831 return NULL;
4832 if (n == 0) {
4833 bmap = isl_basic_map_reset(bmap, src_type);
4834 bmap = isl_basic_map_reset(bmap, dst_type);
4835 return bmap;
4836 }
4837
4838 if (isl_basic_map_check_range(bmap, src_type, src_pos, n) < 0)
4839 return isl_basic_map_free(bmap);
4840
4841 if (dst_type == src_type && dst_pos == src_pos)
4842 return bmap;
4843
4844 isl_assert(bmap->ctx, dst_type != src_type, goto error);
4845
4846 if (pos(bmap->dim, dst_type) + dst_pos ==
4847 pos(bmap->dim, src_type) + src_pos +
4848 ((src_type < dst_type) ? n : 0)) {
4849 space = isl_basic_map_take_space(bmap);
4850 space = isl_space_move_dims(space, dst_type, dst_pos,
4851 src_type, src_pos, n);
4852 bmap = isl_basic_map_restore_space(bmap, space);
4853 bmap = isl_basic_map_finalize(bmap);
4854
4855 return bmap;
4856 }
4857
4859 if (total < 0)
4860 return isl_basic_map_free(bmap);
4861 dim_map = isl_dim_map_alloc(bmap->ctx, total);
4862
4863 off = 0;
4864 space = isl_basic_map_peek_space(bmap);
4865 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
4866 isl_size size = isl_space_dim(space, t);
4867 if (size < 0)
4868 dim_map = isl_dim_map_free(dim_map);
4869 if (t == dst_type) {
4870 isl_dim_map_dim_range(dim_map, space, t,
4871 0, dst_pos, off);
4872 off += dst_pos;
4873 isl_dim_map_dim_range(dim_map, space, src_type,
4874 src_pos, n, off);
4875 off += n;
4876 isl_dim_map_dim_range(dim_map, space, t,
4877 dst_pos, size - dst_pos, off);
4878 off += size - dst_pos;
4879 } else if (t == src_type) {
4880 isl_dim_map_dim_range(dim_map, space, t,
4881 0, src_pos, off);
4882 off += src_pos;
4883 isl_dim_map_dim_range(dim_map, space, t,
4884 src_pos + n, size - src_pos - n, off);
4885 off += size - src_pos - n;
4886 } else {
4887 isl_dim_map_dim(dim_map, space, t, off);
4888 off += size;
4889 }
4890 }
4891 isl_dim_map_div(dim_map, bmap, off);
4892
4894 bmap->n_div, bmap->n_eq, bmap->n_ineq);
4895 bmap = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map);
4896 space = isl_basic_map_take_space(bmap);
4897 space = isl_space_move_dims(space, dst_type, dst_pos,
4898 src_type, src_pos, n);
4899 bmap = isl_basic_map_restore_space(bmap, space);
4900 if (!bmap)
4901 goto error;
4902
4904 bmap = isl_basic_map_gauss(bmap, NULL);
4905 bmap = isl_basic_map_finalize(bmap);
4906
4907 return bmap;
4908error:
4909 isl_basic_map_free(bmap);
4910 return NULL;
4911}
4912
4914 enum isl_dim_type dst_type, unsigned dst_pos,
4915 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
4916{
4917 isl_basic_map *bmap = bset_to_bmap(bset);
4918 bmap = isl_basic_map_move_dims(bmap, dst_type, dst_pos,
4919 src_type, src_pos, n);
4920 return bset_from_bmap(bmap);
4921}
4922
4924 enum isl_dim_type dst_type, unsigned dst_pos,
4925 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
4926{
4927 if (!set)
4928 return NULL;
4929 isl_assert(set->ctx, dst_type != isl_dim_in, goto error);
4931 dst_type, dst_pos, src_type, src_pos, n));
4932error:
4934 return NULL;
4935}
4936
4938 enum isl_dim_type dst_type, unsigned dst_pos,
4939 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
4940{
4941 int i;
4942 isl_space *space;
4943
4944 if (n == 0) {
4945 map = isl_map_reset(map, src_type);
4946 map = isl_map_reset(map, dst_type);
4947 return map;
4948 }
4949
4950 if (isl_map_check_range(map, src_type, src_pos, n))
4951 return isl_map_free(map);
4952
4953 if (dst_type == src_type && dst_pos == src_pos)
4954 return map;
4955
4956 isl_assert(map->ctx, dst_type != src_type, goto error);
4957
4958 map = isl_map_cow(map);
4959 if (!map)
4960 return NULL;
4961
4962 for (i = 0; i < map->n; ++i) {
4963 map->p[i] = isl_basic_map_move_dims(map->p[i],
4964 dst_type, dst_pos,
4965 src_type, src_pos, n);
4966 if (!map->p[i])
4967 goto error;
4968 }
4969
4970 space = isl_map_take_space(map);
4971 space = isl_space_move_dims(space, dst_type, dst_pos,
4972 src_type, src_pos, n);
4973 map = isl_map_restore_space(map, space);
4974
4975 return map;
4976error:
4978 return NULL;
4979}
4980
4981/* Move the specified dimensions to the last columns right before
4982 * the divs. Don't change the dimension specification of bmap.
4983 * That's the responsibility of the caller.
4984 */
4986 enum isl_dim_type type, unsigned first, unsigned n)
4987{
4988 isl_space *space;
4989 struct isl_dim_map *dim_map;
4990 struct isl_basic_map *res;
4991 enum isl_dim_type t;
4993 unsigned off;
4994
4995 if (!bmap)
4996 return NULL;
4997 if (isl_basic_map_offset(bmap, type) + first + n ==
4999 return bmap;
5000
5002 if (total < 0)
5003 return isl_basic_map_free(bmap);
5004 dim_map = isl_dim_map_alloc(bmap->ctx, total);
5005
5006 off = 0;
5007 space = isl_basic_map_peek_space(bmap);
5008 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
5009 isl_size size = isl_space_dim(space, t);
5010 if (size < 0)
5011 dim_map = isl_dim_map_free(dim_map);
5012 if (t == type) {
5013 isl_dim_map_dim_range(dim_map, space, t,
5014 0, first, off);
5015 off += first;
5016 isl_dim_map_dim_range(dim_map, space, t,
5017 first, n, total - bmap->n_div - n);
5018 isl_dim_map_dim_range(dim_map, space, t,
5019 first + n, size - (first + n), off);
5020 off += size - (first + n);
5021 } else {
5022 isl_dim_map_dim(dim_map, space, t, off);
5023 off += size;
5024 }
5025 }
5026 isl_dim_map_div(dim_map, bmap, off + n);
5027
5029 bmap->n_div, bmap->n_eq, bmap->n_ineq);
5031 return res;
5032}
5033
5034/* Insert "n" rows in the divs of "bmap".
5035 *
5036 * The number of columns is not changed, which means that the last
5037 * dimensions of "bmap" are being reintepreted as the new divs.
5038 * The space of "bmap" is not adjusted, however, which means
5039 * that "bmap" is left in an inconsistent state. Removing "n" dimensions
5040 * from the space of "bmap" is the responsibility of the caller.
5041 */
5043 int n)
5044{
5045 int i;
5046 size_t row_size;
5047 isl_int **new_div;
5048 isl_int *old;
5049
5050 bmap = isl_basic_map_cow(bmap);
5051 if (!bmap)
5052 return NULL;
5053
5054 row_size = isl_basic_map_offset(bmap, isl_dim_div) + bmap->extra;
5055 old = bmap->block2.data;
5056 bmap->block2 = isl_blk_extend(bmap->ctx, bmap->block2,
5057 (bmap->extra + n) * (1 + row_size));
5058 if (!bmap->block2.data)
5059 return isl_basic_map_free(bmap);
5060 new_div = isl_alloc_array(bmap->ctx, isl_int *, bmap->extra + n);
5061 if (!new_div)
5062 return isl_basic_map_free(bmap);
5063 for (i = 0; i < n; ++i) {
5064 new_div[i] = bmap->block2.data +
5065 (bmap->extra + i) * (1 + row_size);
5066 isl_seq_clr(new_div[i], 1 + row_size);
5067 }
5068 for (i = 0; i < bmap->extra; ++i)
5069 new_div[n + i] = bmap->block2.data + (bmap->div[i] - old);
5070 free(bmap->div);
5071 bmap->div = new_div;
5072 bmap->n_div += n;
5073 bmap->extra += n;
5074
5075 return bmap;
5076}
5077
5078/* Drop constraints from "bmap" that only involve the variables
5079 * of "type" in the range [first, first + n] that are not related
5080 * to any of the variables outside that interval.
5081 * These constraints cannot influence the values for the variables
5082 * outside the interval, except in case they cause "bmap" to be empty.
5083 * Only drop the constraints if "bmap" is known to be non-empty.
5084 */
5087 unsigned first, unsigned n)
5088{
5089 int i;
5090 int *groups;
5092 isl_bool non_empty;
5093
5094 non_empty = isl_basic_map_plain_is_non_empty(bmap);
5095 if (non_empty < 0)
5096 return isl_basic_map_free(bmap);
5097 if (!non_empty)
5098 return bmap;
5099
5102 if (dim < 0 || n_div < 0)
5103 return isl_basic_map_free(bmap);
5104 groups = isl_calloc_array(isl_basic_map_get_ctx(bmap), int, dim);
5105 if (!groups)
5106 return isl_basic_map_free(bmap);
5107 first += isl_basic_map_offset(bmap, type) - 1;
5108 for (i = 0; i < first; ++i)
5109 groups[i] = -1;
5110 for (i = first + n; i < dim - n_div; ++i)
5111 groups[i] = -1;
5112
5113 bmap = isl_basic_map_drop_unrelated_constraints(bmap, groups);
5114
5115 return bmap;
5116}
5117
5118/* Turn the n dimensions of type type, starting at first
5119 * into existentially quantified variables.
5120 *
5121 * If a subset of the projected out variables are unrelated
5122 * to any of the variables that remain, then the constraints
5123 * involving this subset are simply dropped first.
5124 */
5127 enum isl_dim_type type, unsigned first, unsigned n)
5128{
5129 isl_bool empty;
5130 isl_space *space;
5131
5132 if (n == 0)
5133 return basic_map_space_reset(bmap, type);
5134 if (type == isl_dim_div)
5136 "cannot project out existentially quantified variables",
5137 return isl_basic_map_free(bmap));
5138
5139 empty = isl_basic_map_plain_is_empty(bmap);
5140 if (empty < 0)
5141 return isl_basic_map_free(bmap);
5142 if (empty)
5143 bmap = isl_basic_map_set_to_empty(bmap);
5144
5145 bmap = drop_irrelevant_constraints(bmap, type, first, n);
5146 if (!bmap)
5147 return NULL;
5148
5150 return isl_basic_map_remove_dims(bmap, type, first, n);
5151
5152 if (isl_basic_map_check_range(bmap, type, first, n) < 0)
5153 return isl_basic_map_free(bmap);
5154
5155 bmap = move_last(bmap, type, first, n);
5156 bmap = isl_basic_map_cow(bmap);
5157 bmap = insert_div_rows(bmap, n);
5158
5159 space = isl_basic_map_take_space(bmap);
5160 space = isl_space_drop_dims(space, type, first, n);
5161 bmap = isl_basic_map_restore_space(bmap, space);
5162 bmap = isl_basic_map_simplify(bmap);
5164 return isl_basic_map_finalize(bmap);
5165}
5166
5167/* Turn the n dimensions of type type, starting at first
5168 * into existentially quantified variables.
5169 */
5172 unsigned first, unsigned n)
5173{
5175 type, first, n));
5176}
5177
5178/* Turn the n dimensions of type type, starting at first
5179 * into existentially quantified variables.
5180 */
5182 enum isl_dim_type type, unsigned first, unsigned n)
5183{
5184 int i;
5185 isl_space *space;
5186
5187 if (n == 0)
5188 return map_space_reset(map, type);
5189
5190 if (isl_map_check_range(map, type, first, n) < 0)
5191 return isl_map_free(map);
5192
5193 map = isl_map_cow(map);
5194 if (!map)
5195 return NULL;
5196
5197 for (i = 0; i < map->n; ++i) {
5198 map->p[i] = isl_basic_map_project_out(map->p[i], type, first, n);
5199 if (!map->p[i])
5200 goto error;
5201 }
5202
5203 if (map->n > 1)
5206
5207 space = isl_map_take_space(map);
5208 space = isl_space_drop_dims(space, type, first, n);
5209 map = isl_map_restore_space(map, space);
5210
5211 return map;
5212error:
5214 return NULL;
5215}
5216
5217#undef TYPE
5218#define TYPE isl_map
5221
5222/* Turn all the dimensions of type "type", except the "n" starting at "first"
5223 * into existentially quantified variables.
5224 */
5226 enum isl_dim_type type, unsigned first, unsigned n)
5227{
5228 isl_size dim;
5229
5230 dim = isl_map_dim(map, type);
5231 if (isl_map_check_range(map, type, first, n) < 0 || dim < 0)
5232 return isl_map_free(map);
5233 map = isl_map_project_out(map, type, first + n, dim - (first + n));
5234 map = isl_map_project_out(map, type, 0, first);
5235 return map;
5236}
5237
5238/* Turn the n dimensions of type type, starting at first
5239 * into existentially quantified variables.
5240 */
5242 enum isl_dim_type type, unsigned first, unsigned n)
5243{
5245 type, first, n));
5246}
5247
5248/* If "set" involves a parameter with identifier "id",
5249 * then turn it into an existentially quantified variable.
5250 */
5256
5257/* If "set" involves any of the parameters with identifiers in "list",
5258 * then turn them into existentially quantified variables.
5259 */
5269
5270/* Project out all parameters from "set" by existentially quantifying
5271 * over them.
5272 */
5277
5278/* Return a map that projects the elements in "set" onto their
5279 * "n" set dimensions starting at "first".
5280 * "type" should be equal to isl_dim_set.
5281 */
5283 enum isl_dim_type type, unsigned first, unsigned n)
5284{
5285 int i;
5286 isl_map *map;
5287
5288 if (type != isl_dim_set)
5290 "only set dimensions can be projected out", goto error);
5291 if (isl_set_check_range(set, type, first, n) < 0)
5292 return isl_set_free(set);
5293
5296 for (i = 0; i < n; ++i)
5297 map = isl_map_equate(map, isl_dim_in, first + i,
5298 isl_dim_out, i);
5299 return map;
5300error:
5302 return NULL;
5303}
5304
5306 unsigned n)
5307{
5308 int i, j;
5310
5312 if (total < 0)
5313 return isl_basic_map_free(bmap);
5314 for (i = 0; i < n; ++i) {
5315 j = isl_basic_map_alloc_div(bmap);
5316 if (j < 0)
5317 goto error;
5318 isl_seq_clr(bmap->div[j], 1 + 1 + total);
5319 }
5320 return bmap;
5321error:
5322 isl_basic_map_free(bmap);
5323 return NULL;
5324}
5325
5326/* Does "bmap2" apply to the range of "bmap1" (ignoring parameters)?
5327 */
5330{
5331 isl_space *space1, *space2;
5332
5333 space1 = isl_basic_map_peek_space(bmap1);
5334 space2 = isl_basic_map_peek_space(bmap2);
5336 space2, isl_dim_in);
5337}
5338
5339/* Check that "bmap2" applies to the range of "bmap1" (ignoring parameters).
5340 */
5343{
5345
5346 equal = isl_basic_map_applies_range(bmap1, bmap2);
5347 if (equal < 0)
5348 return isl_stat_error;
5349 if (!equal)
5351 "spaces don't match", return isl_stat_error);
5352 return isl_stat_ok;
5353}
5354
5357{
5358 isl_space *space_result = NULL;
5359 struct isl_basic_map *bmap;
5360 isl_size n_in, n_out, n, nparam;
5361 unsigned total, pos;
5362 struct isl_dim_map *dim_map1, *dim_map2;
5363
5364 if (isl_basic_map_check_equal_params(bmap1, bmap2) < 0)
5365 goto error;
5366 if (isl_basic_map_check_applies_range(bmap1, bmap2) < 0)
5367 goto error;
5368
5369 n_in = isl_basic_map_dim(bmap1, isl_dim_in);
5370 n_out = isl_basic_map_dim(bmap2, isl_dim_out);
5372 nparam = isl_basic_map_dim(bmap1, isl_dim_param);
5373 if (n_in < 0 || n_out < 0 || n < 0 || nparam < 0)
5374 goto error;
5375
5376 space_result = isl_space_join(isl_basic_map_get_space(bmap1),
5378
5379 total = nparam + n_in + n_out + bmap1->n_div + bmap2->n_div + n;
5380 dim_map1 = isl_dim_map_alloc(bmap1->ctx, total);
5381 dim_map2 = isl_dim_map_alloc(bmap1->ctx, total);
5382 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_param, pos = 0);
5383 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_param, pos = 0);
5384 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_in, pos += nparam);
5385 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_out, pos += n_in);
5386 isl_dim_map_div(dim_map1, bmap1, pos += n_out);
5387 isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div);
5388 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += bmap2->n_div);
5389 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_in, pos);
5390
5391 bmap = isl_basic_map_alloc_space(space_result,
5392 bmap1->n_div + bmap2->n_div + n,
5393 bmap1->n_eq + bmap2->n_eq,
5394 bmap1->n_ineq + bmap2->n_ineq);
5395 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap1, dim_map1);
5396 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap2, dim_map2);
5397 bmap = add_divs(bmap, n);
5398 bmap = isl_basic_map_simplify(bmap);
5400 return isl_basic_map_finalize(bmap);
5401error:
5402 isl_basic_map_free(bmap1);
5403 isl_basic_map_free(bmap2);
5404 return NULL;
5405}
5406
5409{
5410 if (isl_basic_map_check_compatible_domain(bmap, bset) < 0)
5411 goto error;
5412
5414 bmap));
5415error:
5416 isl_basic_set_free(bset);
5417 isl_basic_map_free(bmap);
5418 return NULL;
5419}
5420
5423{
5424 if (isl_basic_map_check_equal_params(bmap1, bmap2) < 0)
5425 goto error;
5426 if (!isl_space_tuple_is_equal(bmap1->dim, isl_dim_in,
5427 bmap2->dim, isl_dim_in))
5429 "spaces don't match", goto error);
5430
5431 bmap1 = isl_basic_map_reverse(bmap1);
5432 bmap1 = isl_basic_map_apply_range(bmap1, bmap2);
5433 return isl_basic_map_reverse(bmap1);
5434error:
5435 isl_basic_map_free(bmap1);
5436 isl_basic_map_free(bmap2);
5437 return NULL;
5438}
5439
5440/* Given two basic maps A -> f(A) and B -> g(B), construct a basic map
5441 * A \cap B -> f(A) + f(B)
5442 */
5445{
5446 isl_size n_in, n_out, nparam;
5447 unsigned total, pos;
5448 struct isl_basic_map *bmap = NULL;
5449 struct isl_dim_map *dim_map1, *dim_map2;
5450 int i;
5451
5452 if (isl_basic_map_check_equal_space(bmap1, bmap2) < 0)
5453 goto error;
5454
5455 nparam = isl_basic_map_dim(bmap1, isl_dim_param);
5456 n_in = isl_basic_map_dim(bmap1, isl_dim_in);
5457 n_out = isl_basic_map_dim(bmap1, isl_dim_out);
5458 if (nparam < 0 || n_in < 0 || n_out < 0)
5459 goto error;
5460
5461 total = nparam + n_in + n_out + bmap1->n_div + bmap2->n_div + 2 * n_out;
5462 dim_map1 = isl_dim_map_alloc(bmap1->ctx, total);
5463 dim_map2 = isl_dim_map_alloc(bmap2->ctx, total);
5464 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_param, pos = 0);
5465 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_param, pos);
5466 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_in, pos += nparam);
5467 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_in, pos);
5468 isl_dim_map_div(dim_map1, bmap1, pos += n_in + n_out);
5469 isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div);
5470 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += bmap2->n_div);
5471 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_out, pos += n_out);
5472
5473 bmap = isl_basic_map_alloc_space(isl_space_copy(bmap1->dim),
5474 bmap1->n_div + bmap2->n_div + 2 * n_out,
5475 bmap1->n_eq + bmap2->n_eq + n_out,
5476 bmap1->n_ineq + bmap2->n_ineq);
5477 for (i = 0; i < n_out; ++i) {
5478 int j = isl_basic_map_alloc_equality(bmap);
5479 if (j < 0)
5480 goto error;
5481 isl_seq_clr(bmap->eq[j], 1+total);
5482 isl_int_set_si(bmap->eq[j][1+nparam+n_in+i], -1);
5483 isl_int_set_si(bmap->eq[j][1+pos+i], 1);
5484 isl_int_set_si(bmap->eq[j][1+pos-n_out+i], 1);
5485 }
5486 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap1, dim_map1);
5487 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap2, dim_map2);
5488 bmap = add_divs(bmap, 2 * n_out);
5489
5490 bmap = isl_basic_map_simplify(bmap);
5491 return isl_basic_map_finalize(bmap);
5492error:
5493 isl_basic_map_free(bmap);
5494 isl_basic_map_free(bmap1);
5495 isl_basic_map_free(bmap2);
5496 return NULL;
5497}
5498
5499/* Given two maps A -> f(A) and B -> g(B), construct a map
5500 * A \cap B -> f(A) + f(B)
5501 */
5504{
5505 struct isl_map *result;
5506 int i, j;
5507
5509 goto error;
5510
5512 map1->n * map2->n, 0);
5513 if (!result)
5514 goto error;
5515 for (i = 0; i < map1->n; ++i)
5516 for (j = 0; j < map2->n; ++j) {
5517 struct isl_basic_map *part;
5518 part = isl_basic_map_sum(
5519 isl_basic_map_copy(map1->p[i]),
5520 isl_basic_map_copy(map2->p[j]));
5521 if (isl_basic_map_is_empty(part))
5522 isl_basic_map_free(part);
5523 else
5524 result = isl_map_add_basic_map(result, part);
5525 if (!result)
5526 goto error;
5527 }
5530 return result;
5531error:
5534 return NULL;
5535}
5536
5542
5543/* Given a basic map A -> f(A), construct A -> -f(A).
5544 */
5546{
5547 int i, j;
5548 unsigned off;
5549 isl_size n;
5550
5551 bmap = isl_basic_map_cow(bmap);
5553 if (n < 0)
5554 return isl_basic_map_free(bmap);
5555
5556 off = isl_basic_map_offset(bmap, isl_dim_out);
5557 for (i = 0; i < bmap->n_eq; ++i)
5558 for (j = 0; j < n; ++j)
5559 isl_int_neg(bmap->eq[i][off+j], bmap->eq[i][off+j]);
5560 for (i = 0; i < bmap->n_ineq; ++i)
5561 for (j = 0; j < n; ++j)
5562 isl_int_neg(bmap->ineq[i][off+j], bmap->ineq[i][off+j]);
5563 for (i = 0; i < bmap->n_div; ++i)
5564 for (j = 0; j < n; ++j)
5565 isl_int_neg(bmap->div[i][1+off+j], bmap->div[i][1+off+j]);
5566 bmap = isl_basic_map_gauss(bmap, NULL);
5567 return isl_basic_map_finalize(bmap);
5568}
5569
5574
5575/* Given a map A -> f(A), construct A -> -f(A).
5576 */
5578{
5579 int i;
5580
5581 map = isl_map_cow(map);
5582 if (!map)
5583 return NULL;
5584
5585 for (i = 0; i < map->n; ++i) {
5586 map->p[i] = isl_basic_map_neg(map->p[i]);
5587 if (!map->p[i])
5588 goto error;
5589 }
5590
5591 return map;
5592error:
5594 return NULL;
5595}
5596
5601
5602/* Given a basic map A -> f(A) and an integer d, construct a basic map
5603 * A -> floor(f(A)/d).
5604 */
5606 isl_int d)
5607{
5608 isl_size n_in, n_out, nparam;
5609 unsigned total, pos;
5610 struct isl_basic_map *result = NULL;
5611 struct isl_dim_map *dim_map;
5612 int i;
5613
5614 nparam = isl_basic_map_dim(bmap, isl_dim_param);
5615 n_in = isl_basic_map_dim(bmap, isl_dim_in);
5616 n_out = isl_basic_map_dim(bmap, isl_dim_out);
5617 if (nparam < 0 || n_in < 0 || n_out < 0)
5618 return isl_basic_map_free(bmap);
5619
5620 total = nparam + n_in + n_out + bmap->n_div + n_out;
5621 dim_map = isl_dim_map_alloc(bmap->ctx, total);
5622 isl_dim_map_dim(dim_map, bmap->dim, isl_dim_param, pos = 0);
5623 isl_dim_map_dim(dim_map, bmap->dim, isl_dim_in, pos += nparam);
5624 isl_dim_map_div(dim_map, bmap, pos += n_in + n_out);
5625 isl_dim_map_dim(dim_map, bmap->dim, isl_dim_out, pos += bmap->n_div);
5626
5627 result = isl_basic_map_alloc_space(isl_space_copy(bmap->dim),
5628 bmap->n_div + n_out,
5629 bmap->n_eq, bmap->n_ineq + 2 * n_out);
5630 result = isl_basic_map_add_constraints_dim_map(result, bmap, dim_map);
5631 result = add_divs(result, n_out);
5632 for (i = 0; i < n_out; ++i) {
5633 int j;
5635 if (j < 0)
5636 goto error;
5637 isl_seq_clr(result->ineq[j], 1+total);
5638 isl_int_neg(result->ineq[j][1+nparam+n_in+i], d);
5639 isl_int_set_si(result->ineq[j][1+pos+i], 1);
5641 if (j < 0)
5642 goto error;
5643 isl_seq_clr(result->ineq[j], 1+total);
5644 isl_int_set(result->ineq[j][1+nparam+n_in+i], d);
5645 isl_int_set_si(result->ineq[j][1+pos+i], -1);
5646 isl_int_sub_ui(result->ineq[j][0], d, 1);
5647 }
5648
5649 result = isl_basic_map_simplify(result);
5650 return isl_basic_map_finalize(result);
5651error:
5652 isl_basic_map_free(result);
5653 return NULL;
5654}
5655
5656/* Given a map A -> f(A) and an integer d, construct a map
5657 * A -> floor(f(A)/d).
5658 */
5660{
5661 int i;
5662
5663 map = isl_map_cow(map);
5664 if (!map)
5665 return NULL;
5666
5668 for (i = 0; i < map->n; ++i) {
5669 map->p[i] = isl_basic_map_floordiv(map->p[i], d);
5670 if (!map->p[i])
5671 goto error;
5672 }
5674
5675 return map;
5676error:
5678 return NULL;
5679}
5680
5681/* Given a map A -> f(A) and an integer d, construct a map
5682 * A -> floor(f(A)/d).
5683 */
5686{
5687 if (!map || !d)
5688 goto error;
5689 if (!isl_val_is_int(d))
5691 "expecting integer denominator", goto error);
5692 map = isl_map_floordiv(map, d->n);
5693 isl_val_free(d);
5694 return map;
5695error:
5697 isl_val_free(d);
5698 return NULL;
5699}
5700
5702 unsigned pos)
5703{
5704 int i;
5705 isl_size nparam;
5706 isl_size n_in;
5708
5710 nparam = isl_basic_map_dim(bmap, isl_dim_param);
5711 n_in = isl_basic_map_dim(bmap, isl_dim_in);
5712 if (total < 0 || nparam < 0 || n_in < 0)
5713 return isl_basic_map_free(bmap);
5715 if (i < 0)
5716 goto error;
5717 isl_seq_clr(bmap->eq[i], 1 + total);
5718 isl_int_set_si(bmap->eq[i][1+nparam+pos], -1);
5719 isl_int_set_si(bmap->eq[i][1+nparam+n_in+pos], 1);
5720 return isl_basic_map_finalize(bmap);
5721error:
5722 isl_basic_map_free(bmap);
5723 return NULL;
5724}
5725
5726/* Add a constraint to "bmap" expressing i_pos < o_pos
5727 */
5729 unsigned pos)
5730{
5731 int i;
5732 isl_size nparam;
5733 isl_size n_in;
5735
5737 nparam = isl_basic_map_dim(bmap, isl_dim_param);
5738 n_in = isl_basic_map_dim(bmap, isl_dim_in);
5739 if (total < 0 || nparam < 0 || n_in < 0)
5740 return isl_basic_map_free(bmap);
5742 if (i < 0)
5743 goto error;
5744 isl_seq_clr(bmap->ineq[i], 1 + total);
5745 isl_int_set_si(bmap->ineq[i][0], -1);
5746 isl_int_set_si(bmap->ineq[i][1+nparam+pos], -1);
5747 isl_int_set_si(bmap->ineq[i][1+nparam+n_in+pos], 1);
5748 return isl_basic_map_finalize(bmap);
5749error:
5750 isl_basic_map_free(bmap);
5751 return NULL;
5752}
5753
5754/* Add a constraint to "bmap" expressing i_pos <= o_pos
5755 */
5757 __isl_take isl_basic_map *bmap, unsigned pos)
5758{
5759 int i;
5760 isl_size nparam;
5761 isl_size n_in;
5763
5765 nparam = isl_basic_map_dim(bmap, isl_dim_param);
5766 n_in = isl_basic_map_dim(bmap, isl_dim_in);
5767 if (total < 0 || nparam < 0 || n_in < 0)
5768 return isl_basic_map_free(bmap);
5770 if (i < 0)
5771 goto error;
5772 isl_seq_clr(bmap->ineq[i], 1 + total);
5773 isl_int_set_si(bmap->ineq[i][1+nparam+pos], -1);
5774 isl_int_set_si(bmap->ineq[i][1+nparam+n_in+pos], 1);
5775 return isl_basic_map_finalize(bmap);
5776error:
5777 isl_basic_map_free(bmap);
5778 return NULL;
5779}
5780
5781/* Add a constraint to "bmap" expressing i_pos > o_pos
5782 */
5784 unsigned pos)
5785{
5786 int i;
5787 isl_size nparam;
5788 isl_size n_in;
5790
5792 nparam = isl_basic_map_dim(bmap, isl_dim_param);
5793 n_in = isl_basic_map_dim(bmap, isl_dim_in);
5794 if (total < 0 || nparam < 0 || n_in < 0)
5795 return isl_basic_map_free(bmap);
5797 if (i < 0)
5798 goto error;
5799 isl_seq_clr(bmap->ineq[i], 1 + total);
5800 isl_int_set_si(bmap->ineq[i][0], -1);
5801 isl_int_set_si(bmap->ineq[i][1+nparam+pos], 1);
5802 isl_int_set_si(bmap->ineq[i][1+nparam+n_in+pos], -1);
5803 return isl_basic_map_finalize(bmap);
5804error:
5805 isl_basic_map_free(bmap);
5806 return NULL;
5807}
5808
5809/* Add a constraint to "bmap" expressing i_pos >= o_pos
5810 */
5812 __isl_take isl_basic_map *bmap, unsigned pos)
5813{
5814 int i;
5815 isl_size nparam;
5816 isl_size n_in;
5818
5820 nparam = isl_basic_map_dim(bmap, isl_dim_param);
5821 n_in = isl_basic_map_dim(bmap, isl_dim_in);
5822 if (total < 0 || nparam < 0 || n_in < 0)
5823 return isl_basic_map_free(bmap);
5825 if (i < 0)
5826 goto error;
5827 isl_seq_clr(bmap->ineq[i], 1 + total);
5828 isl_int_set_si(bmap->ineq[i][1+nparam+pos], 1);
5829 isl_int_set_si(bmap->ineq[i][1+nparam+n_in+pos], -1);
5830 return isl_basic_map_finalize(bmap);
5831error:
5832 isl_basic_map_free(bmap);
5833 return NULL;
5834}
5835
5837 __isl_take isl_space *space, unsigned n_equal)
5838{
5839 int i;
5840 struct isl_basic_map *bmap;
5841 bmap = isl_basic_map_alloc_space(space, 0, n_equal, 0);
5842 if (!bmap)
5843 return NULL;
5844 for (i = 0; i < n_equal && bmap; ++i)
5845 bmap = var_equal(bmap, i);
5846 return isl_basic_map_finalize(bmap);
5847}
5848
5849/* Return a relation on of dimension "space" expressing i_[0..pos] << o_[0..pos]
5850 */
5852 unsigned pos)
5853{
5854 int i;
5855 struct isl_basic_map *bmap;
5856 bmap = isl_basic_map_alloc_space(space, 0, pos, 1);
5857 if (!bmap)
5858 return NULL;
5859 for (i = 0; i < pos && bmap; ++i)
5860 bmap = var_equal(bmap, i);
5861 if (bmap)
5862 bmap = var_less(bmap, pos);
5863 return isl_basic_map_finalize(bmap);
5864}
5865
5866/* Return a relation on "space" expressing i_[0..pos] <<= o_[0..pos]
5867 */
5869 __isl_take isl_space *space, unsigned pos)
5870{
5871 int i;
5872 isl_basic_map *bmap;
5873
5874 bmap = isl_basic_map_alloc_space(space, 0, pos, 1);
5875 for (i = 0; i < pos; ++i)
5876 bmap = var_equal(bmap, i);
5877 bmap = var_less_or_equal(bmap, pos);
5878 return isl_basic_map_finalize(bmap);
5879}
5880
5881/* Return a relation on "space" expressing i_pos > o_pos
5882 */
5884 unsigned pos)
5885{
5886 int i;
5887 struct isl_basic_map *bmap;
5888 bmap = isl_basic_map_alloc_space(space, 0, pos, 1);
5889 if (!bmap)
5890 return NULL;
5891 for (i = 0; i < pos && bmap; ++i)
5892 bmap = var_equal(bmap, i);
5893 if (bmap)
5894 bmap = var_more(bmap, pos);
5895 return isl_basic_map_finalize(bmap);
5896}
5897
5898/* Return a relation on "space" expressing i_[0..pos] >>= o_[0..pos]
5899 */
5901 __isl_take isl_space *space, unsigned pos)
5902{
5903 int i;
5904 isl_basic_map *bmap;
5905
5906 bmap = isl_basic_map_alloc_space(space, 0, pos, 1);
5907 for (i = 0; i < pos; ++i)
5908 bmap = var_equal(bmap, i);
5909 bmap = var_more_or_equal(bmap, pos);
5910 return isl_basic_map_finalize(bmap);
5911}
5912
5914 unsigned n, int equal)
5915{
5916 struct isl_map *map;
5917 int i;
5918
5919 if (n == 0 && equal)
5920 return isl_map_universe(space);
5921
5923
5924 for (i = 0; i + 1 < n; ++i)
5927 if (n > 0) {
5928 if (equal)
5930 isl_basic_map_less_or_equal_at(space, n - 1));
5931 else
5933 isl_basic_map_less_at(space, n - 1));
5934 } else
5935 isl_space_free(space);
5936
5937 return map;
5938}
5939
5941{
5942 if (!space)
5943 return NULL;
5944 return map_lex_lte_first(space, space->n_out, equal);
5945}
5946
5948 unsigned n)
5949{
5950 return map_lex_lte_first(space, n, 0);
5951}
5952
5954 unsigned n)
5955{
5956 return map_lex_lte_first(space, n, 1);
5957}
5958
5960{
5961 return map_lex_lte(isl_space_map_from_set(set_space), 0);
5962}
5963
5965{
5966 return map_lex_lte(isl_space_map_from_set(set_space), 1);
5967}
5968
5970 unsigned n, int equal)
5971{
5972 struct isl_map *map;
5973 int i;
5974
5975 if (n == 0 && equal)
5976 return isl_map_universe(space);
5977
5979
5980 for (i = 0; i + 1 < n; ++i)
5983 if (n > 0) {
5984 if (equal)
5986 isl_basic_map_more_or_equal_at(space, n - 1));
5987 else
5989 isl_basic_map_more_at(space, n - 1));
5990 } else
5991 isl_space_free(space);
5992
5993 return map;
5994}
5995
5997{
5998 if (!space)
5999 return NULL;
6000 return map_lex_gte_first(space, space->n_out, equal);
6001}
6002
6004 unsigned n)
6005{
6006 return map_lex_gte_first(space, n, 0);
6007}
6008
6010 unsigned n)
6011{
6012 return map_lex_gte_first(space, n, 1);
6013}
6014
6016{
6017 return map_lex_gte(isl_space_map_from_set(set_space), 0);
6018}
6019
6021{
6022 return map_lex_gte(isl_space_map_from_set(set_space), 1);
6023}
6024
6034
6044
6054
6064
6074
6084
6094
6104
6105/* For the div d = floor(f/m) at position "div", add the constraint
6106 *
6107 * f - m d >= 0
6108 */
6110 __isl_take isl_basic_map *bmap, unsigned div)
6111{
6112 int i;
6114 isl_size n_div;
6115 unsigned pos;
6116
6117 n_div = isl_basic_map_dim(bmap, isl_dim_div);
6118 if (v_div < 0 || n_div < 0)
6119 return isl_basic_map_free(bmap);
6120 pos = v_div + div;
6122 if (i < 0)
6123 return isl_basic_map_free(bmap);
6124 isl_seq_cpy(bmap->ineq[i], bmap->div[div] + 1, 1 + v_div + n_div);
6125 isl_int_neg(bmap->ineq[i][1 + pos], bmap->div[div][0]);
6126
6127 return bmap;
6128}
6129
6130/* For the div d = floor(f/m) at position "div", add the constraint
6131 *
6132 * -(f-(m-1)) + m d >= 0
6133 */
6135 __isl_take isl_basic_map *bmap, unsigned div)
6136{
6137 int i;
6139 isl_size n_div;
6140 unsigned pos;
6141
6142 n_div = isl_basic_map_dim(bmap, isl_dim_div);
6143 if (v_div < 0 || n_div < 0)
6144 return isl_basic_map_free(bmap);
6145 pos = v_div + div;
6147 if (i < 0)
6148 return isl_basic_map_free(bmap);
6149 isl_seq_neg(bmap->ineq[i], bmap->div[div] + 1, 1 + v_div + n_div);
6150 isl_int_set(bmap->ineq[i][1 + pos], bmap->div[div][0]);
6151 isl_int_add(bmap->ineq[i][0], bmap->ineq[i][0], bmap->ineq[i][1 + pos]);
6152 isl_int_sub_ui(bmap->ineq[i][0], bmap->ineq[i][0], 1);
6153
6154 return bmap;
6155}
6156
6157/* For the div d = floor(f/m) at position "pos", add the constraints
6158 *
6159 * f - m d >= 0
6160 * -(f-(m-1)) + m d >= 0
6161 *
6162 * Note that the second constraint is the negation of
6163 *
6164 * f - m d >= m
6165 */
6167 __isl_take isl_basic_map *bmap, unsigned pos)
6168{
6169 bmap = add_upper_div_constraint(bmap, pos);
6170 bmap = add_lower_div_constraint(bmap, pos);
6171 return bmap;
6172}
6173
6174/* For the div d = floor(f/m) at position "pos", add the constraints
6175 *
6176 * f - m d >= 0
6177 * -(f-(m-1)) + m d >= 0
6178 *
6179 * Note that the second constraint is the negation of
6180 *
6181 * f - m d >= m
6182 */
6190
6191/* For each known div d = floor(f/m), add the constraints
6192 *
6193 * f - m d >= 0
6194 * -(f-(m-1)) + m d >= 0
6195 *
6196 * Remove duplicate constraints in case of some these div constraints
6197 * already appear in "bmap".
6198 */
6201{
6202 isl_size n_div;
6203
6204 n_div = isl_basic_map_dim(bmap, isl_dim_div);
6205 if (n_div < 0)
6206 return isl_basic_map_free(bmap);
6207 if (n_div == 0)
6208 return bmap;
6209
6210 bmap = add_known_div_constraints(bmap);
6211 bmap = isl_basic_map_remove_duplicate_constraints(bmap, NULL, 0);
6212 bmap = isl_basic_map_finalize(bmap);
6213 return bmap;
6214}
6215
6216/* Add the div constraint of sign "sign" for div "div" of "bmap".
6217 *
6218 * In particular, if this div is of the form d = floor(f/m),
6219 * then add the constraint
6220 *
6221 * f - m d >= 0
6222 *
6223 * if sign < 0 or the constraint
6224 *
6225 * -(f-(m-1)) + m d >= 0
6226 *
6227 * if sign > 0.
6228 */
6230 __isl_take isl_basic_map *bmap, unsigned div, int sign)
6231{
6232 if (sign < 0)
6233 return add_upper_div_constraint(bmap, div);
6234 else
6235 return add_lower_div_constraint(bmap, div);
6236}
6237
6240{
6241 isl_space *space;
6242
6243 if (!bmap)
6244 goto error;
6245 if (bmap->dim->nparam == 0 && bmap->dim->n_in == 0 &&
6246 bmap->n_div == 0 &&
6249 return bset_from_bmap(bmap);
6250 bmap = isl_basic_map_cow(bmap);
6251 if (!bmap)
6252 return NULL;
6253 space = isl_basic_map_take_space(bmap);
6254 space = isl_space_underlying(space, bmap->n_div);
6255 bmap = isl_basic_map_restore_space(bmap, space);
6256 if (!bmap)
6257 return NULL;
6258 bmap->extra -= bmap->n_div;
6259 bmap->n_div = 0;
6260 bmap = isl_basic_map_finalize(bmap);
6261 return bset_from_bmap(bmap);
6262error:
6263 isl_basic_map_free(bmap);
6264 return NULL;
6265}
6266
6272
6273/* Replace each element in "list" by the result of applying
6274 * isl_basic_map_underlying_set to the element.
6275 */
6277 __isl_take isl_basic_map_list *list)
6278{
6279 int i;
6280 isl_size n;
6281
6282 n = isl_basic_map_list_n_basic_map(list);
6283 if (n < 0)
6284 goto error;
6285
6286 for (i = 0; i < n; ++i) {
6287 isl_basic_map *bmap;
6288 isl_basic_set *bset;
6289
6290 bmap = isl_basic_map_list_get_basic_map(list, i);
6291 bset = isl_basic_set_underlying_set(bmap);
6292 list = isl_basic_set_list_set_basic_set(list, i, bset);
6293 }
6294
6295 return list;
6296error:
6297 isl_basic_map_list_free(list);
6298 return NULL;
6299}
6300
6303{
6304 struct isl_basic_map *bmap;
6305 struct isl_ctx *ctx;
6306 isl_size dim, bmap_total;
6307 unsigned total;
6308 int i;
6309
6310 if (!bset || !like)
6311 goto error;
6312 ctx = bset->ctx;
6313 if (isl_basic_set_check_no_params(bset) < 0 ||
6315 goto error;
6316 dim = isl_basic_set_dim(bset, isl_dim_set);
6317 bmap_total = isl_basic_map_dim(like, isl_dim_all);
6318 if (dim < 0 || bmap_total < 0)
6319 goto error;
6320 isl_assert(ctx, dim == bmap_total, goto error);
6321 if (like->n_div == 0) {
6322 isl_space *space = isl_basic_map_get_space(like);
6323 isl_basic_map_free(like);
6324 return isl_basic_map_reset_space(bset, space);
6325 }
6326 bset = isl_basic_set_cow(bset);
6327 if (!bset)
6328 goto error;
6329 total = dim + bset->extra;
6330 bmap = bset_to_bmap(bset);
6333 if (!bmap)
6334 goto error;
6335 bmap->n_div = like->n_div;
6336 bmap->extra += like->n_div;
6337 if (bmap->extra) {
6338 unsigned ltotal;
6339 isl_int **div;
6340 ltotal = total - bmap->extra + like->extra;
6341 if (ltotal > total)
6342 ltotal = total;
6343 bmap->block2 = isl_blk_extend(ctx, bmap->block2,
6344 bmap->extra * (1 + 1 + total));
6345 if (isl_blk_is_error(bmap->block2))
6346 goto error;
6347 div = isl_realloc_array(ctx, bmap->div, isl_int *, bmap->extra);
6348 if (!div)
6349 goto error;
6350 bmap->div = div;
6351 for (i = 0; i < bmap->extra; ++i)
6352 bmap->div[i] = bmap->block2.data + i * (1 + 1 + total);
6353 for (i = 0; i < like->n_div; ++i) {
6354 isl_seq_cpy(bmap->div[i], like->div[i], 1 + 1 + ltotal);
6355 isl_seq_clr(bmap->div[i]+1+1+ltotal, total - ltotal);
6356 }
6358 }
6359 isl_basic_map_free(like);
6360 bmap = isl_basic_map_simplify(bmap);
6361 bmap = isl_basic_map_finalize(bmap);
6362 return bmap;
6363error:
6364 isl_basic_map_free(like);
6365 isl_basic_set_free(bset);
6366 return NULL;
6367}
6368
6375
6377{
6378 int i;
6379
6380 map = isl_map_cow(map);
6381 if (!map)
6382 return NULL;
6383 map->dim = isl_space_cow(map->dim);
6384 if (!map->dim)
6385 goto error;
6386
6387 for (i = 1; i < map->n; ++i)
6388 isl_assert(map->ctx, map->p[0]->n_div == map->p[i]->n_div,
6389 goto error);
6390 for (i = 0; i < map->n; ++i) {
6391 map->p[i] = bset_to_bmap(
6393 if (!map->p[i])
6394 goto error;
6395 }
6396 if (map->n == 0)
6397 map->dim = isl_space_underlying(map->dim, 0);
6398 else {
6399 isl_space_free(map->dim);
6400 map->dim = isl_space_copy(map->p[0]->dim);
6401 }
6402 if (!map->dim)
6403 goto error;
6404 return set_from_map(map);
6405error:
6407 return NULL;
6408}
6409
6410/* Replace the space of "bmap" by "space".
6411 *
6412 * If the space of "bmap" is identical to "space" (including the identifiers
6413 * of the input and output dimensions), then simply return the original input.
6414 */
6417{
6419 isl_space *bmap_space;
6420
6421 bmap_space = isl_basic_map_peek_space(bmap);
6422 equal = isl_space_is_equal(bmap_space, space);
6423 if (equal >= 0 && equal)
6424 equal = isl_space_has_equal_ids(bmap_space, space);
6425 if (equal < 0)
6426 goto error;
6427 if (equal) {
6428 isl_space_free(space);
6429 return bmap;
6430 }
6432 bmap = isl_basic_map_restore_space(bmap, space);
6433
6434 bmap = isl_basic_map_finalize(bmap);
6435
6436 return bmap;
6437error:
6438 isl_basic_map_free(bmap);
6439 isl_space_free(space);
6440 return NULL;
6441}
6442
6449
6450/* Check that the total dimensions of "map" and "space" are the same.
6451 */
6453 __isl_keep isl_space *space)
6454{
6455 isl_size dim1, dim2;
6456
6457 dim1 = isl_map_dim(map, isl_dim_all);
6458 dim2 = isl_space_dim(space, isl_dim_all);
6459 if (dim1 < 0 || dim2 < 0)
6460 return isl_stat_error;
6461 if (dim1 == dim2)
6462 return isl_stat_ok;
6464 "total dimensions do not match", return isl_stat_error);
6465}
6466
6468 __isl_take isl_space *space)
6469{
6470 int i;
6471
6472 map = isl_map_cow(map);
6473 if (!map || !space)
6474 goto error;
6475
6476 for (i = 0; i < map->n; ++i) {
6477 map->p[i] = isl_basic_map_reset_space(map->p[i],
6478 isl_space_copy(space));
6479 if (!map->p[i])
6480 goto error;
6481 }
6483 map = isl_map_restore_space(map, space);
6484
6485 return map;
6486error:
6488 isl_space_free(space);
6489 return NULL;
6490}
6491
6492/* Replace the space of "map" by "space", without modifying
6493 * the dimension of "map".
6494 *
6495 * If the space of "map" is identical to "space" (including the identifiers
6496 * of the input and output dimensions), then simply return the original input.
6497 */
6499 __isl_take isl_space *space)
6500{
6502 isl_space *map_space;
6503
6504 map_space = isl_map_peek_space(map);
6505 equal = isl_space_is_equal(map_space, space);
6506 if (equal >= 0 && equal)
6507 equal = isl_space_has_equal_ids(map_space, space);
6508 if (equal < 0)
6509 goto error;
6510 if (equal) {
6511 isl_space_free(space);
6512 return map;
6513 }
6514 if (check_map_space_equal_total_dim(map, space) < 0)
6515 goto error;
6516 return isl_map_reset_space(map, space);
6517error:
6519 isl_space_free(space);
6520 return NULL;
6521}
6522
6528
6529/* Compute the parameter domain of the given basic set.
6530 */
6532{
6533 isl_bool is_params;
6534 isl_space *space;
6535 isl_size n;
6536
6537 is_params = isl_basic_set_is_params(bset);
6538 if (is_params < 0)
6539 return isl_basic_set_free(bset);
6540 if (is_params)
6541 return bset;
6542
6544 if (n < 0)
6545 return isl_basic_set_free(bset);
6546 bset = isl_basic_set_project_out(bset, isl_dim_set, 0, n);
6547 space = isl_basic_set_get_space(bset);
6548 space = isl_space_params(space);
6549 bset = isl_basic_set_reset_space(bset, space);
6550 return bset;
6551}
6552
6553/* Construct a zero-dimensional basic set with the given parameter domain.
6554 */
6557{
6558 isl_space *space;
6559 space = isl_basic_set_get_space(bset);
6560 space = isl_space_set_from_params(space);
6561 bset = isl_basic_set_reset_space(bset, space);
6562 return bset;
6563}
6564
6565/* Compute the parameter domain of the given set.
6566 */
6571
6572/* Construct a zero-dimensional set with the given parameter domain.
6573 */
6575{
6576 isl_space *space;
6577 space = isl_set_get_space(set);
6578 space = isl_space_set_from_params(space);
6579 set = isl_set_reset_space(set, space);
6580 return set;
6581}
6582
6583/* Compute the parameter domain of the given map.
6584 */
6586{
6587 isl_space *space;
6588 isl_size n_in, n_out;
6589
6590 n_in = isl_map_dim(map, isl_dim_in);
6591 n_out = isl_map_dim(map, isl_dim_out);
6592 if (n_in < 0 || n_out < 0)
6593 return isl_map_free(map);
6595 map = isl_map_project_out(map, isl_dim_out, 0, n_out);
6596 space = isl_map_get_space(map);
6597 space = isl_space_params(space);
6598 map = isl_map_reset_space(map, space);
6599 return map;
6600}
6601
6603{
6604 isl_space *space;
6605 isl_size n_out;
6606
6607 n_out = isl_basic_map_dim(bmap, isl_dim_out);
6608 if (n_out < 0)
6609 return isl_basic_map_free(bmap);
6611
6612 bmap = isl_basic_map_project_out(bmap, isl_dim_out, 0, n_out);
6613
6614 return isl_basic_map_reset_space(bmap, space);
6615}
6616
6618{
6619 if (!bmap)
6620 return isl_bool_error;
6621 return isl_space_may_be_set(bmap->dim);
6622}
6623
6624/* Is this basic map actually a set?
6625 * Users should never call this function. Outside of isl,
6626 * the type should indicate whether something is a set or a map.
6627 */
6629{
6630 if (!bmap)
6631 return isl_bool_error;
6632 return isl_space_is_set(bmap->dim);
6633}
6634
6636{
6637 isl_bool is_set;
6638
6639 is_set = isl_basic_map_is_set(bmap);
6640 if (is_set < 0)
6641 goto error;
6642 if (is_set)
6643 return bmap;
6645error:
6646 isl_basic_map_free(bmap);
6647 return NULL;
6648}
6649
6652{
6653 int i;
6654 isl_space *space;
6656 isl_size nparam, n_in, n_out;
6657
6658 nparam = isl_basic_map_dim(bmap, isl_dim_param);
6659 n_in = isl_basic_map_dim(bmap, isl_dim_in);
6660 n_out = isl_basic_map_dim(bmap, isl_dim_out);
6661 if (nparam < 0 || n_in < 0 || n_out < 0)
6662 return isl_basic_map_free(bmap);
6663
6664 space = isl_basic_map_get_space(bmap);
6665 space = isl_space_from_range(isl_space_domain(space));
6667
6669 bmap = isl_basic_map_apply_range(bmap, domain);
6670 bmap = isl_basic_map_extend_constraints(bmap, n_in, 0);
6671
6672 for (i = 0; i < n_in; ++i)
6673 bmap = isl_basic_map_equate(bmap, isl_dim_in, i,
6674 isl_dim_out, i);
6675
6676 bmap = isl_basic_map_gauss(bmap, NULL);
6677 return isl_basic_map_finalize(bmap);
6678}
6679
6682{
6683 int i;
6684 isl_space *space;
6686 isl_size nparam, n_in, n_out;
6687
6688 nparam = isl_basic_map_dim(bmap, isl_dim_param);
6689 n_in = isl_basic_map_dim(bmap, isl_dim_in);
6690 n_out = isl_basic_map_dim(bmap, isl_dim_out);
6691 if (nparam < 0 || n_in < 0 || n_out < 0)
6692 return isl_basic_map_free(bmap);
6693
6694 space = isl_basic_map_get_space(bmap);
6695 space = isl_space_from_range(isl_space_range(space));
6697
6699 bmap = isl_basic_map_apply_range(bmap, range);
6700 bmap = isl_basic_map_extend_constraints(bmap, n_out, 0);
6701
6702 for (i = 0; i < n_out; ++i)
6703 bmap = isl_basic_map_equate(bmap, isl_dim_in, n_in + i,
6704 isl_dim_out, i);
6705
6706 bmap = isl_basic_map_gauss(bmap, NULL);
6707 return isl_basic_map_finalize(bmap);
6708}
6709
6711{
6712 if (!map)
6713 return -1;
6714 return isl_space_may_be_set(map->dim);
6715}
6716
6717/* Is this map actually a set?
6718 * Users should never call this function. Outside of isl,
6719 * the type should indicate whether something is a set or a map.
6720 */
6722{
6723 if (!map)
6724 return isl_bool_error;
6725 return isl_space_is_set(map->dim);
6726}
6727
6729{
6730 isl_space *space;
6731 isl_size n_in;
6732
6733 n_in = isl_map_dim(map, isl_dim_in);
6734 if (n_in < 0)
6735 return set_from_map(isl_map_free(map));
6737
6739
6740 return set_from_map(isl_map_reset_space(map, space));
6741}
6742
6743/* Transform "map" by applying "fn_space" to its space and "fn_bmap"
6744 * to each of its basic maps.
6745 */
6747 __isl_give isl_space *(*fn_space)(__isl_take isl_space *space),
6749{
6750 int i;
6751 isl_space *space;
6752
6753 map = isl_map_cow(map);
6754 if (!map)
6755 return NULL;
6756
6757 for (i = 0; i < map->n; ++i) {
6758 map->p[i] = fn_bmap(map->p[i]);
6759 if (!map->p[i])
6760 return isl_map_free(map);
6761 }
6763
6764 space = isl_map_take_space(map);
6765 space = fn_space(space);
6766 map = isl_map_restore_space(map, space);
6767
6768 return map;
6769}
6770
6776
6782
6783/* Given a wrapped map of the form A[B -> C],
6784 * return the map A[B -> C] -> B.
6785 */
6787{
6788 isl_id *id;
6789 isl_map *map;
6790
6791 if (!set)
6792 return NULL;
6795
6799
6800 return map;
6801}
6802
6808
6811{
6812 isl_space *space;
6813 space = isl_basic_set_get_space(bset);
6814 space = isl_space_from_range(space);
6815 bset = isl_basic_set_reset_space(bset, space);
6816 return bset_to_bmap(bset);
6817}
6818
6819/* Create a relation with the given set as range.
6820 * The domain of the created relation is a zero-dimensional
6821 * flat anonymous space.
6822 */
6824{
6825 isl_space *space;
6826 space = isl_set_get_space(set);
6827 space = isl_space_from_range(space);
6828 set = isl_set_reset_space(set, space);
6829 return set_to_map(set);
6830}
6831
6832/* Create a relation with the given set as domain.
6833 * The range of the created relation is a zero-dimensional
6834 * flat anonymous space.
6835 */
6840
6846
6852
6853/* Return a newly allocated isl_map with given space and flags and
6854 * room for "n" basic maps.
6855 * Make sure that all cached information is cleared.
6856 */
6858 unsigned flags)
6859{
6860 struct isl_map *map;
6861
6862 if (!space)
6863 return NULL;
6864 if (n < 0)
6865 isl_die(space->ctx, isl_error_internal,
6866 "negative number of basic maps", goto error);
6867 map = isl_calloc(space->ctx, struct isl_map,
6868 sizeof(struct isl_map) +
6869 (n - 1) * sizeof(struct isl_basic_map *));
6870 if (!map)
6871 goto error;
6872
6873 map->ctx = space->ctx;
6874 isl_ctx_ref(map->ctx);
6875 map->ref = 1;
6876 map->size = n;
6877 map->n = 0;
6878 map->dim = space;
6879 map->flags = flags;
6880 return map;
6881error:
6882 isl_space_free(space);
6883 return NULL;
6884}
6885
6887{
6888 struct isl_basic_map *bmap;
6889 bmap = isl_basic_map_alloc_space(space, 0, 1, 0);
6890 bmap = isl_basic_map_set_to_empty(bmap);
6891 return bmap;
6892}
6893
6895{
6896 struct isl_basic_set *bset;
6897 bset = isl_basic_set_alloc_space(space, 0, 1, 0);
6898 bset = isl_basic_set_set_to_empty(bset);
6899 return bset;
6900}
6901
6903{
6904 struct isl_basic_map *bmap;
6905 bmap = isl_basic_map_alloc_space(space, 0, 0, 0);
6906 bmap = isl_basic_map_finalize(bmap);
6907 return bmap;
6908}
6909
6911{
6912 struct isl_basic_set *bset;
6913 bset = isl_basic_set_alloc_space(space, 0, 0, 0);
6914 bset = isl_basic_set_finalize(bset);
6915 return bset;
6916}
6917
6919 __isl_take isl_space *space)
6920{
6921 int i;
6923 isl_basic_map *bmap;
6924
6925 if (total < 0)
6926 space = isl_space_free(space);
6927 bmap = isl_basic_map_alloc_space(space, 0, 0, total);
6928 for (i = 0; i < total; ++i) {
6929 int k = isl_basic_map_alloc_inequality(bmap);
6930 if (k < 0)
6931 goto error;
6932 isl_seq_clr(bmap->ineq[k], 1 + total);
6933 isl_int_set_si(bmap->ineq[k][1 + i], 1);
6934 }
6935 return bmap;
6936error:
6937 isl_basic_map_free(bmap);
6938 return NULL;
6939}
6940
6946
6951
6956
6961
6966
6968{
6969 struct isl_map *map;
6970 if (!space)
6971 return NULL;
6974 return map;
6975}
6976
6977/* This function performs the same operation as isl_map_universe,
6978 * but is considered as a function on an isl_space when exported.
6979 */
6984
6986{
6987 struct isl_set *set;
6988 if (!space)
6989 return NULL;
6992 return set;
6993}
6994
6995/* This function performs the same operation as isl_set_universe,
6996 * but is considered as a function on an isl_space when exported.
6997 */
7002
7004{
7005 int i;
7006 struct isl_map *dup;
7007
7008 if (!map)
7009 return NULL;
7010 dup = isl_map_alloc_space(isl_space_copy(map->dim), map->n, map->flags);
7011 for (i = 0; i < map->n; ++i)
7013 return dup;
7014}
7015
7018{
7019 if (!bmap || !map)
7020 goto error;
7021 if (isl_basic_map_plain_is_empty(bmap)) {
7022 isl_basic_map_free(bmap);
7023 return map;
7024 }
7026 goto error;
7027 isl_assert(map->ctx, map->n < map->size, goto error);
7028 map->p[map->n] = bmap;
7029 map->n++;
7031 return map;
7032error:
7033 if (map)
7035 if (bmap)
7036 isl_basic_map_free(bmap);
7037 return NULL;
7038}
7039
7041{
7042 int i;
7043
7044 if (!map)
7045 return NULL;
7046
7047 if (--map->ref > 0)
7048 return NULL;
7049
7051 isl_ctx_deref(map->ctx);
7052 for (i = 0; i < map->n; ++i)
7053 isl_basic_map_free(map->p[i]);
7054 isl_space_free(map->dim);
7055 free(map);
7056
7057 return NULL;
7058}
7059
7061 __isl_take isl_basic_map *bmap, unsigned pos, int value)
7062{
7063 int j;
7065
7067 if (total < 0)
7068 return isl_basic_map_free(bmap);
7069
7070 bmap = isl_basic_map_cow(bmap);
7071 bmap = isl_basic_map_extend_constraints(bmap, 1, 0);
7073 if (j < 0)
7074 goto error;
7075 isl_seq_clr(bmap->eq[j] + 1, total);
7076 isl_int_set_si(bmap->eq[j][pos], -1);
7077 isl_int_set_si(bmap->eq[j][0], value);
7078 bmap = isl_basic_map_simplify(bmap);
7079 return isl_basic_map_finalize(bmap);
7080error:
7081 isl_basic_map_free(bmap);
7082 return NULL;
7083}
7084
7086 __isl_take isl_basic_map *bmap, unsigned pos, isl_int value)
7087{
7088 int j;
7090
7092 if (total < 0)
7093 return isl_basic_map_free(bmap);
7094
7095 bmap = isl_basic_map_cow(bmap);
7096 bmap = isl_basic_map_extend_constraints(bmap, 1, 0);
7098 if (j < 0)
7099 goto error;
7100 isl_seq_clr(bmap->eq[j] + 1, total);
7101 isl_int_set_si(bmap->eq[j][pos], -1);
7102 isl_int_set(bmap->eq[j][0], value);
7103 bmap = isl_basic_map_simplify(bmap);
7104 return isl_basic_map_finalize(bmap);
7105error:
7106 isl_basic_map_free(bmap);
7107 return NULL;
7108}
7109
7111 enum isl_dim_type type, unsigned pos, int value)
7112{
7113 if (isl_basic_map_check_range(bmap, type, pos, 1) < 0)
7114 return isl_basic_map_free(bmap);
7115 return isl_basic_map_fix_pos_si(bmap,
7116 isl_basic_map_offset(bmap, type) + pos, value);
7117}
7118
7120 enum isl_dim_type type, unsigned pos, isl_int value)
7121{
7122 if (isl_basic_map_check_range(bmap, type, pos, 1) < 0)
7123 return isl_basic_map_free(bmap);
7124 return isl_basic_map_fix_pos(bmap,
7125 isl_basic_map_offset(bmap, type) + pos, value);
7126}
7127
7128/* Fix the value of the variable at position "pos" of type "type" of "bmap"
7129 * to be equal to "v".
7130 */
7132 enum isl_dim_type type, unsigned pos, __isl_take isl_val *v)
7133{
7134 if (!bmap || !v)
7135 goto error;
7136 if (!isl_val_is_int(v))
7138 "expecting integer value", goto error);
7139 if (isl_basic_map_check_range(bmap, type, pos, 1) < 0)
7140 goto error;
7141 pos += isl_basic_map_offset(bmap, type);
7142 bmap = isl_basic_map_fix_pos(bmap, pos, v->n);
7143 isl_val_free(v);
7144 return bmap;
7145error:
7146 isl_basic_map_free(bmap);
7147 isl_val_free(v);
7148 return NULL;
7149}
7150
7151/* Fix the value of the variable at position "pos" of type "type" of "bset"
7152 * to be equal to "v".
7153 */
7159
7161 enum isl_dim_type type, unsigned pos, int value)
7162{
7164 type, pos, value));
7165}
7166
7168 enum isl_dim_type type, unsigned pos, isl_int value)
7169{
7171 type, pos, value));
7172}
7173
7174/* Remove the basic map at position "i" from "map" if this basic map
7175 * is (obviously) empty.
7176 */
7178{
7179 isl_bool empty;
7180
7181 if (!map)
7182 return NULL;
7183
7184 empty = isl_basic_map_plain_is_empty(map->p[i]);
7185 if (empty < 0)
7186 return isl_map_free(map);
7187 if (!empty)
7188 return map;
7189
7190 isl_basic_map_free(map->p[i]);
7191 map->n--;
7192 if (i != map->n) {
7193 map->p[i] = map->p[map->n];
7195
7196 }
7197
7198 return map;
7199}
7200
7201/* Perform "fn" on each basic map of "map", where we may not be holding
7202 * the only reference to "map".
7203 * In particular, "fn" should be a semantics preserving operation
7204 * that we want to apply to all copies of "map". We therefore need
7205 * to be careful not to modify "map" in a way that breaks "map"
7206 * in case anything goes wrong.
7207 */
7210{
7211 struct isl_basic_map *bmap;
7212 int i;
7213
7214 if (!map)
7215 return NULL;
7216
7217 for (i = map->n - 1; i >= 0; --i) {
7218 bmap = isl_basic_map_copy(map->p[i]);
7219 bmap = fn(bmap);
7220 if (!bmap)
7221 goto error;
7222 isl_basic_map_free(map->p[i]);
7223 map->p[i] = bmap;
7224 map = remove_if_empty(map, i);
7225 if (!map)
7226 return NULL;
7227 }
7228
7229 return map;
7230error:
7232 return NULL;
7233}
7234
7236 enum isl_dim_type type, unsigned pos, int value)
7237{
7238 int i;
7239
7240 map = isl_map_cow(map);
7241 if (isl_map_check_range(map, type, pos, 1) < 0)
7242 return isl_map_free(map);
7243 for (i = map->n - 1; i >= 0; --i) {
7244 map->p[i] = isl_basic_map_fix_si(map->p[i], type, pos, value);
7245 map = remove_if_empty(map, i);
7246 if (!map)
7247 return NULL;
7248 }
7250 return map;
7251}
7252
7254 enum isl_dim_type type, unsigned pos, int value)
7255{
7256 return set_from_map(isl_map_fix_si(set_to_map(set), type, pos, value));
7257}
7258
7260 enum isl_dim_type type, unsigned pos, isl_int value)
7261{
7262 int i;
7263
7264 map = isl_map_cow(map);
7265 if (isl_map_check_range(map, type, pos, 1) < 0)
7266 return isl_map_free(map);
7267 for (i = 0; i < map->n; ++i) {
7268 map->p[i] = isl_basic_map_fix(map->p[i], type, pos, value);
7269 if (!map->p[i])
7270 goto error;
7271 }
7273 return map;
7274error:
7276 return NULL;
7277}
7278
7280 enum isl_dim_type type, unsigned pos, isl_int value)
7281{
7282 return set_from_map(isl_map_fix(set_to_map(set), type, pos, value));
7283}
7284
7285/* Fix the value of the variable at position "pos" of type "type" of "map"
7286 * to be equal to "v".
7287 */
7289 enum isl_dim_type type, unsigned pos, __isl_take isl_val *v)
7290{
7291 int i;
7292
7293 map = isl_map_cow(map);
7294 if (!map || !v)
7295 goto error;
7296
7297 if (!isl_val_is_int(v))
7299 "expecting integer value", goto error);
7300 if (isl_map_check_range(map, type, pos, 1) < 0)
7301 goto error;
7302 for (i = map->n - 1; i >= 0; --i) {
7303 map->p[i] = isl_basic_map_fix_val(map->p[i], type, pos,
7304 isl_val_copy(v));
7305 map = remove_if_empty(map, i);
7306 if (!map)
7307 goto error;
7308 }
7310 isl_val_free(v);
7311 return map;
7312error:
7314 isl_val_free(v);
7315 return NULL;
7316}
7317
7318/* Fix the value of the variable at position "pos" of type "type" of "set"
7319 * to be equal to "v".
7320 */
7326
7328 unsigned input, int value)
7329{
7330 return isl_map_fix_si(map, isl_dim_in, input, value);
7331}
7332
7334 int value)
7335{
7337 isl_dim_set, dim, value));
7338}
7339
7342 enum isl_dim_type type, unsigned pos, int value, int upper)
7343{
7344 int j;
7346
7347 if (isl_basic_map_check_range(bmap, type, pos, 1) < 0)
7348 return isl_basic_map_free(bmap);
7350 if (total < 0)
7351 return isl_basic_map_free(bmap);
7352 pos += isl_basic_map_offset(bmap, type);
7353 bmap = isl_basic_map_cow(bmap);
7354 bmap = isl_basic_map_extend_constraints(bmap, 0, 1);
7356 if (j < 0)
7357 goto error;
7358 isl_seq_clr(bmap->ineq[j], 1 + total);
7359 if (upper) {
7360 isl_int_set_si(bmap->ineq[j][pos], -1);
7361 isl_int_set_si(bmap->ineq[j][0], value);
7362 } else {
7363 isl_int_set_si(bmap->ineq[j][pos], 1);
7364 isl_int_set_si(bmap->ineq[j][0], -value);
7365 }
7366 bmap = isl_basic_map_simplify(bmap);
7367 return isl_basic_map_finalize(bmap);
7368error:
7369 isl_basic_map_free(bmap);
7370 return NULL;
7371}
7372
7375 enum isl_dim_type type, unsigned pos, int value)
7376{
7377 return basic_map_bound_si(bmap, type, pos, value, 0);
7378}
7379
7380/* Constrain the values of the given dimension to be no greater than "value".
7381 */
7384 enum isl_dim_type type, unsigned pos, int value)
7385{
7386 return basic_map_bound_si(bmap, type, pos, value, 1);
7387}
7388
7390 enum isl_dim_type type, unsigned pos, int value, int upper)
7391{
7392 int i;
7393
7394 map = isl_map_cow(map);
7395 if (isl_map_check_range(map, type, pos, 1) < 0)
7396 return isl_map_free(map);
7397 for (i = 0; i < map->n; ++i) {
7398 map->p[i] = basic_map_bound_si(map->p[i],
7399 type, pos, value, upper);
7400 if (!map->p[i])
7401 goto error;
7402 }
7404 return map;
7405error:
7407 return NULL;
7408}
7409
7411 enum isl_dim_type type, unsigned pos, int value)
7412{
7413 return map_bound_si(map, type, pos, value, 0);
7414}
7415
7417 enum isl_dim_type type, unsigned pos, int value)
7418{
7419 return map_bound_si(map, type, pos, value, 1);
7420}
7421
7423 enum isl_dim_type type, unsigned pos, int value)
7424{
7426 type, pos, value));
7427}
7428
7430 enum isl_dim_type type, unsigned pos, int value)
7431{
7432 return isl_map_upper_bound_si(set, type, pos, value);
7433}
7434
7435/* Bound the given variable of "bmap" from below (or above is "upper"
7436 * is set) to "value".
7437 */
7440 enum isl_dim_type type, unsigned pos, isl_int value, int upper)
7441{
7442 int j;
7444
7445 if (isl_basic_map_check_range(bmap, type, pos, 1) < 0)
7446 return isl_basic_map_free(bmap);
7448 if (total < 0)
7449 return isl_basic_map_free(bmap);
7450 pos += isl_basic_map_offset(bmap, type);
7451 bmap = isl_basic_map_cow(bmap);
7452 bmap = isl_basic_map_extend_constraints(bmap, 0, 1);
7454 if (j < 0)
7455 goto error;
7456 isl_seq_clr(bmap->ineq[j], 1 + total);
7457 if (upper) {
7458 isl_int_set_si(bmap->ineq[j][pos], -1);
7459 isl_int_set(bmap->ineq[j][0], value);
7460 } else {
7461 isl_int_set_si(bmap->ineq[j][pos], 1);
7462 isl_int_neg(bmap->ineq[j][0], value);
7463 }
7464 bmap = isl_basic_map_simplify(bmap);
7465 return isl_basic_map_finalize(bmap);
7466error:
7467 isl_basic_map_free(bmap);
7468 return NULL;
7469}
7470
7471/* Bound the given variable of "map" from below (or above is "upper"
7472 * is set) to "value".
7473 */
7475 enum isl_dim_type type, unsigned pos, isl_int value, int upper)
7476{
7477 int i;
7478
7479 map = isl_map_cow(map);
7480 if (isl_map_check_range(map, type, pos, 1) < 0)
7481 return isl_map_free(map);
7482 for (i = map->n - 1; i >= 0; --i) {
7483 map->p[i] = basic_map_bound(map->p[i], type, pos, value, upper);
7484 map = remove_if_empty(map, i);
7485 if (!map)
7486 return NULL;
7487 }
7489 return map;
7490}
7491
7493 enum isl_dim_type type, unsigned pos, isl_int value)
7494{
7495 return map_bound(map, type, pos, value, 0);
7496}
7497
7499 enum isl_dim_type type, unsigned pos, isl_int value)
7500{
7501 return map_bound(map, type, pos, value, 1);
7502}
7503
7505 enum isl_dim_type type, unsigned pos, isl_int value)
7506{
7507 return isl_map_lower_bound(set, type, pos, value);
7508}
7509
7511 enum isl_dim_type type, unsigned pos, isl_int value)
7512{
7513 return isl_map_upper_bound(set, type, pos, value);
7514}
7515
7516/* Force the values of the variable at position "pos" of type "type" of "map"
7517 * to be no smaller than "value".
7518 */
7520 enum isl_dim_type type, unsigned pos, __isl_take isl_val *value)
7521{
7522 if (!value)
7523 goto error;
7524 if (!isl_val_is_int(value))
7526 "expecting integer value", goto error);
7527 map = isl_map_lower_bound(map, type, pos, value->n);
7528 isl_val_free(value);
7529 return map;
7530error:
7531 isl_val_free(value);
7533 return NULL;
7534}
7535
7536/* Force the values of the variable at position "pos" of type "type" of "set"
7537 * to be no smaller than "value".
7538 */
7547
7548/* Force the values of the variable at position "pos" of type "type" of "map"
7549 * to be no greater than "value".
7550 */
7552 enum isl_dim_type type, unsigned pos, __isl_take isl_val *value)
7553{
7554 if (!value)
7555 goto error;
7556 if (!isl_val_is_int(value))
7558 "expecting integer value", goto error);
7559 map = isl_map_upper_bound(map, type, pos, value->n);
7560 isl_val_free(value);
7561 return map;
7562error:
7563 isl_val_free(value);
7565 return NULL;
7566}
7567
7568/* Force the values of the variable at position "pos" of type "type" of "set"
7569 * to be no greater than "value".
7570 */
7579
7580/* If "mv" has an explicit domain, then intersect the domain of "map"
7581 * with this explicit domain.
7582 *
7583 * An isl_multi_val object never has an explicit domain,
7584 * so simply return "map".
7585 */
7591
7592#undef BASE
7593#define BASE val
7594#include "isl_map_bound_templ.c"
7595
7596/* Apply "map_bound" to "set" with the corresponding value in "bound"
7597 * for each set dimension, by treating the set as a map.
7598 */
7602 unsigned pos, __isl_take isl_val *value))
7603{
7604 isl_map *map;
7605
7606 map = set_to_map(set);
7607 return set_from_map(map_bound_multi_val(map, bound, map_bound));
7608}
7609
7610#undef BASE
7611#define BASE pw_aff
7612#include "isl_map_bound_templ.c"
7613
7614/* Apply "map_bound" to "set" with the corresponding value in "bound"
7615 * for each set dimension, by converting the set and the bound
7616 * to objects living in a map space.
7617 */
7621 unsigned pos, __isl_take TYPE *value))
7622{
7623 isl_map *map;
7624
7626 bound = isl_multi_pw_aff_from_range(bound);
7627 map = map_bound_multi_pw_aff(map, bound, set_bound);
7628 return isl_map_range(map);
7629}
7630
7631/* Wrapper around isl_map_lower_bound_val for use in map_bound_multi_val,
7632 * setting a bound on the given output dimension.
7633 */
7639
7640/* Force the values of the set dimensions of "set"
7641 * to be no smaller than the corresponding values in "lower".
7642 */
7648
7649/* Wrapper around isl_map_upper_bound_val for use in map_bound_multi_val,
7650 * setting a bound on the given output dimension.
7651 */
7657
7658/* Force the values of the set dimensions of "set"
7659 * to be no greater than the corresponding values in "upper".
7660 */
7666
7667/* Force the symbolic constant expression "bound"
7668 * to satisfy the relation "order" with respect to
7669 * the output variable at position "pos" of "map".
7670 *
7671 * Create an affine expression representing the output variable
7672 * in terms of the range and
7673 * compare it using "order" to "bound" (defined on the domain).
7674 * The result is a relation between elements in domain and range that
7675 * can be intersected with "map".
7676 */
7678 unsigned pos, __isl_take isl_pw_aff *bound,
7679 __isl_give isl_map *(*order)(__isl_take isl_pw_aff *pa1,
7680 __isl_take isl_pw_aff *pa2))
7681{
7682 isl_space *space;
7683 isl_local_space *ls;
7684 isl_pw_aff *var;
7685
7687 ls = isl_local_space_from_space(space);
7689 map = isl_map_intersect(map, order(bound, var));
7690 return map;
7691}
7692
7693/* Force the values of the output variable at position "pos" of "map"
7694 * to be no smaller than the symbolic constant expression "lower".
7695 */
7701
7702/* Force the values of the output variable at position "pos" of "map"
7703 * to be no greater than the symbolic constant expression "upper".
7704 */
7710
7711/* Force the values of the set dimensions of "set"
7712 * to be no smaller than the corresponding constant symbolic expressions
7713 * in "lower".
7714 */
7720
7721/* Force the values of the set dimensions of "set"
7722 * to be no greater than the corresponding constant symbolic expressions
7723 * in "upper".
7724 */
7730
7731/* Force the values of the output dimensions of "map"
7732 * to be no smaller than the corresponding constant symbolic expressions
7733 * in "lower".
7734 */
7737{
7738 return map_bound_multi_pw_aff(map, lower, &map_lower_bound_pw_aff);
7739}
7740
7741/* Force the values of the output dimensions of "map"
7742 * to be no greater than the corresponding constant symbolic expressions
7743 * in "upper".
7744 */
7747{
7748 return map_bound_multi_pw_aff(map, upper, &map_upper_bound_pw_aff);
7749}
7750
7751/* Bound the given variable of "bset" from below (or above is "upper"
7752 * is set) to "value".
7753 */
7755 __isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos,
7756 isl_int value, int upper)
7757{
7759 type, pos, value, upper));
7760}
7761
7762/* Bound the given variable of "bset" from below (or above is "upper"
7763 * is set) to "value".
7764 */
7766 __isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos,
7767 __isl_take isl_val *value, int upper)
7768{
7769 if (!value)
7770 goto error;
7771 if (!isl_val_is_int(value))
7773 "expecting integer value", goto error);
7774 bset = isl_basic_set_bound(bset, type, pos, value->n, upper);
7775 isl_val_free(value);
7776 return bset;
7777error:
7778 isl_val_free(value);
7779 isl_basic_set_free(bset);
7780 return NULL;
7781}
7782
7783/* Bound the given variable of "bset" from below to "value".
7784 */
7786 __isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos,
7787 __isl_take isl_val *value)
7788{
7789 return isl_basic_set_bound_val(bset, type, pos, value, 0);
7790}
7791
7792/* Bound the given variable of "bset" from above to "value".
7793 */
7795 __isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos,
7796 __isl_take isl_val *value)
7797{
7798 return isl_basic_set_bound_val(bset, type, pos, value, 1);
7799}
7800
7806
7807/* Given a map (A -> B) -> C, return the corresponding map (B -> A) -> C.
7808 */
7814
7815/* Given a map A -> (B -> C), return the corresponding map A -> (C -> B).
7816 */
7822
7823/* Given a set (A -> B), return the corresponding set (B -> A).
7824 */
7833
7834#undef TYPE
7835#define TYPE isl_pw_multi_aff
7836#undef SUFFIX
7837#define SUFFIX _pw_multi_aff
7838#undef EMPTY
7839#define EMPTY isl_pw_multi_aff_empty
7840#undef ADD
7841#define ADD isl_pw_multi_aff_union_add
7842#include "isl_map_lexopt_templ.c"
7843
7844/* Given a map "map", compute the lexicographically minimal
7845 * (or maximal) image element for each domain element in dom,
7846 * in the form of an isl_pw_multi_aff.
7847 * If "empty" is not NULL, then set *empty to those elements in dom that
7848 * do not have an image element.
7849 * If "flags" includes ISL_OPT_FULL, then "dom" is NULL and the optimum
7850 * should be computed over the domain of "map". "empty" is also NULL
7851 * in this case.
7852 *
7853 * We first compute the lexicographically minimal or maximal element
7854 * in the first basic map. This results in a partial solution "res"
7855 * and a subset "todo" of dom that still need to be handled.
7856 * We then consider each of the remaining maps in "map" and successively
7857 * update both "res" and "todo".
7858 * If "empty" is NULL, then the todo sets are not needed and therefore
7859 * also not computed.
7860 */
7863 __isl_give isl_set **empty, unsigned flags)
7864{
7865 int i;
7866 int full;
7868 isl_set *todo;
7869
7871 if (!map || (!full && !dom))
7872 goto error;
7873
7875 if (empty)
7876 *empty = dom;
7877 else
7878 isl_set_free(dom);
7880 }
7881
7883 isl_basic_map_copy(map->p[0]),
7884 isl_set_copy(dom), empty, flags);
7885
7886 if (empty)
7887 todo = *empty;
7888 for (i = 1; i < map->n; ++i) {
7889 isl_pw_multi_aff *res_i;
7890
7892 isl_basic_map_copy(map->p[i]),
7893 isl_set_copy(dom), empty, flags);
7894
7897 else
7899
7900 if (empty)
7901 todo = isl_set_intersect(todo, *empty);
7902 }
7903
7904 isl_set_free(dom);
7906
7907 if (empty)
7908 *empty = todo;
7909
7910 return res;
7911error:
7912 if (empty)
7913 *empty = NULL;
7914 isl_set_free(dom);
7916 return NULL;
7917}
7918
7919#undef TYPE
7920#define TYPE isl_map
7921#undef SUFFIX
7922#define SUFFIX
7923#undef EMPTY
7924#define EMPTY isl_map_empty
7925#undef ADD
7926#define ADD isl_map_union_disjoint
7927#include "isl_map_lexopt_templ.c"
7928
7929/* Given a map "map", compute the lexicographically minimal
7930 * (or maximal) image element for each domain element in "dom",
7931 * in the form of an isl_map.
7932 * If "empty" is not NULL, then set *empty to those elements in "dom" that
7933 * do not have an image element.
7934 * If "flags" includes ISL_OPT_FULL, then "dom" is NULL and the optimum
7935 * should be computed over the domain of "map". "empty" is also NULL
7936 * in this case.
7937 *
7938 * If the input consists of more than one disjunct, then first
7939 * compute the desired result in the form of an isl_pw_multi_aff and
7940 * then convert that into an isl_map.
7941 *
7942 * This function used to have an explicit implementation in terms
7943 * of isl_maps, but it would continually intersect the domains of
7944 * partial results with the complement of the domain of the next
7945 * partial solution, potentially leading to an explosion in the number
7946 * of disjuncts if there are several disjuncts in the input.
7947 * An even earlier implementation of this function would look for
7948 * better results in the domain of the partial result and for extra
7949 * results in the complement of this domain, which would lead to
7950 * even more splintering.
7951 */
7954 __isl_give isl_set **empty, unsigned flags)
7955{
7956 int full;
7957 struct isl_map *res;
7959
7961 if (!map || (!full && !dom))
7962 goto error;
7963
7965 if (empty)
7966 *empty = dom;
7967 else
7968 isl_set_free(dom);
7969 return map;
7970 }
7971
7972 if (map->n == 1) {
7974 dom, empty, flags);
7976 return res;
7977 }
7978
7980 flags);
7982error:
7983 if (empty)
7984 *empty = NULL;
7985 isl_set_free(dom);
7987 return NULL;
7988}
7989
7992 __isl_give isl_set **empty)
7993{
7994 return isl_map_partial_lexopt(map, dom, empty, ISL_OPT_MAX);
7995}
7996
7999 __isl_give isl_set **empty)
8000{
8001 return isl_map_partial_lexopt(map, dom, empty, 0);
8002}
8003
8011
8019
8020/* Compute the lexicographic minimum (or maximum if "flags" includes
8021 * ISL_OPT_MAX) of "bset" over its parametric domain.
8022 */
8024 unsigned flags)
8025{
8026 return isl_basic_map_lexopt(bset, flags);
8027}
8028
8030{
8031 return isl_basic_map_lexopt(bmap, ISL_OPT_MAX);
8032}
8033
8038
8043
8044/* Compute the lexicographic minimum of "bset" over its parametric domain
8045 * for the purpose of quantifier elimination.
8046 * That is, find an explicit representation for all the existentially
8047 * quantified variables in "bset" by computing their lexicographic
8048 * minimum.
8049 */
8055
8056/* Given a basic map with one output dimension, compute the minimum or
8057 * maximum of that dimension as an isl_pw_aff.
8058 *
8059 * Compute the optimum as a lexicographic optimum over the single
8060 * output dimension and extract the single isl_pw_aff from the result.
8061 */
8063 int max)
8064{
8066 isl_pw_aff *pwaff;
8067
8068 bmap = isl_basic_map_copy(bmap);
8069 pma = isl_basic_map_lexopt_pw_multi_aff(bmap, max ? ISL_OPT_MAX : 0);
8070 pwaff = isl_pw_multi_aff_get_pw_aff(pma, 0);
8072
8073 return pwaff;
8074}
8075
8076/* Compute the minimum or maximum of the given output dimension
8077 * as a function of the parameters and the input dimensions,
8078 * but independently of the other output dimensions.
8079 *
8080 * We first project out the other output dimension and then compute
8081 * the "lexicographic" maximum in each basic map, combining the results
8082 * using isl_pw_aff_union_max.
8083 */
8085 int max)
8086{
8087 int i;
8088 isl_pw_aff *pwaff;
8089 isl_size n_out;
8090
8091 n_out = isl_map_dim(map, isl_dim_out);
8092 if (n_out < 0)
8093 map = isl_map_free(map);
8094 map = isl_map_project_out(map, isl_dim_out, pos + 1, n_out - (pos + 1));
8096 if (!map)
8097 return NULL;
8098
8099 if (map->n == 0) {
8102 return isl_pw_aff_empty(space);
8103 }
8104
8105 pwaff = basic_map_dim_opt(map->p[0], max);
8106 for (i = 1; i < map->n; ++i) {
8107 isl_pw_aff *pwaff_i;
8108
8109 pwaff_i = basic_map_dim_opt(map->p[i], max);
8110 pwaff = isl_pw_aff_union_opt(pwaff, pwaff_i, max);
8111 }
8112
8114
8115 return pwaff;
8116}
8117
8118/* Compute the minimum of the given output dimension as a function of the
8119 * parameters and input dimensions, but independently of
8120 * the other output dimensions.
8121 */
8126
8127/* Compute the maximum of the given output dimension as a function of the
8128 * parameters and input dimensions, but independently of
8129 * the other output dimensions.
8130 */
8135
8136/* Compute the minimum or maximum of the given set dimension
8137 * as a function of the parameters,
8138 * but independently of the other set dimensions.
8139 */
8141 int max)
8142{
8143 return map_dim_opt(set, pos, max);
8144}
8145
8146/* Compute the maximum of the given set dimension as a function of the
8147 * parameters, but independently of the other set dimensions.
8148 */
8153
8154/* Compute the minimum of the given set dimension as a function of the
8155 * parameters, but independently of the other set dimensions.
8156 */
8161
8162/* Apply a preimage specified by "mat" on the parameters of "bset".
8163 * bset is assumed to have only parameters and divs.
8164 */
8167{
8168 isl_size nparam;
8169
8170 nparam = isl_basic_set_dim(bset, isl_dim_param);
8171 if (nparam < 0 || !mat)
8172 goto error;
8173
8174 bset->dim = isl_space_cow(bset->dim);
8175 if (!bset->dim)
8176 goto error;
8177
8178 isl_assert(bset->ctx, mat->n_row == 1 + nparam, goto error);
8179
8180 bset->dim->nparam = 0;
8181 bset->dim->n_out = nparam;
8182 bset = isl_basic_set_preimage(bset, mat);
8183 if (bset) {
8184 bset->dim->nparam = bset->dim->n_out;
8185 bset->dim->n_out = 0;
8186 }
8187 return bset;
8188error:
8189 isl_mat_free(mat);
8190 isl_basic_set_free(bset);
8191 return NULL;
8192}
8193
8194/* Apply a preimage specified by "mat" on the parameters of "set".
8195 * set is assumed to have only parameters and divs.
8196 */
8198 __isl_take isl_mat *mat)
8199{
8200 isl_space *space;
8201 isl_size nparam;
8202
8203 nparam = isl_set_dim(set, isl_dim_param);
8204 if (nparam < 0 || !mat)
8205 goto error;
8206
8207 if (mat->n_row != 1 + nparam)
8209 "unexpected number of rows", goto error);
8210
8211 space = isl_set_get_space(set);
8212 space = isl_space_move_dims(space, isl_dim_set, 0,
8213 isl_dim_param, 0, nparam);
8214 set = isl_set_reset_space(set, space);
8215 set = isl_set_preimage(set, mat);
8216 nparam = isl_set_dim(set, isl_dim_out);
8217 if (nparam < 0)
8218 set = isl_set_free(set);
8219 space = isl_set_get_space(set);
8220 space = isl_space_move_dims(space, isl_dim_param, 0,
8221 isl_dim_out, 0, nparam);
8222 set = isl_set_reset_space(set, space);
8223 return set;
8224error:
8225 isl_mat_free(mat);
8227 return NULL;
8228}
8229
8230/* Intersect the basic set "bset" with the affine space specified by the
8231 * equalities in "eq".
8232 */
8235{
8236 int i, k;
8237 unsigned len;
8238
8239 if (!bset || !eq)
8240 goto error;
8241
8242 bset = isl_basic_set_extend(bset, 0, eq->n_row, 0);
8243 if (!bset)
8244 goto error;
8245
8246 len = isl_basic_set_offset(bset, isl_dim_div) + bset->extra;
8247 for (i = 0; i < eq->n_row; ++i) {
8249 if (k < 0)
8250 goto error;
8251 isl_seq_cpy(bset->eq[k], eq->row[i], eq->n_col);
8252 isl_seq_clr(bset->eq[k] + eq->n_col, len - eq->n_col);
8253 }
8254 isl_mat_free(eq);
8255
8256 bset = isl_basic_set_gauss(bset, NULL);
8257 bset = isl_basic_set_finalize(bset);
8258
8259 return bset;
8260error:
8261 isl_mat_free(eq);
8262 isl_basic_set_free(bset);
8263 return NULL;
8264}
8265
8266/* Intersect the set "set" with the affine space specified by the
8267 * equalities in "eq".
8268 */
8270 __isl_take isl_mat *eq)
8271{
8272 int i;
8273
8274 if (!set || !eq)
8275 goto error;
8276
8277 for (i = 0; i < set->n; ++i) {
8278 set->p[i] = basic_set_append_equalities(set->p[i],
8279 isl_mat_copy(eq));
8280 if (!set->p[i])
8281 goto error;
8282 }
8283 isl_mat_free(eq);
8284 return set;
8285error:
8286 isl_mat_free(eq);
8288 return NULL;
8289}
8290
8291/* Given a basic set "bset" that only involves parameters and existentially
8292 * quantified variables, return the index of the first equality
8293 * that only involves parameters. If there is no such equality then
8294 * return bset->n_eq.
8295 *
8296 * This function assumes that isl_basic_set_gauss has been called on "bset".
8297 */
8299{
8300 int i, j;
8301 isl_size nparam, n_div;
8302
8303 nparam = isl_basic_set_dim(bset, isl_dim_param);
8304 n_div = isl_basic_set_dim(bset, isl_dim_div);
8305 if (nparam < 0 || n_div < 0)
8306 return -1;
8307
8308 for (i = 0, j = n_div - 1; i < bset->n_eq && j >= 0; --j) {
8309 if (!isl_int_is_zero(bset->eq[i][1 + nparam + j]))
8310 ++i;
8311 }
8312
8313 return i;
8314}
8315
8316/* Compute an explicit representation for the existentially quantified
8317 * variables in "bset" by computing the "minimal value" of the set
8318 * variables. Since there are no set variables, the computation of
8319 * the minimal value essentially computes an explicit representation
8320 * of the non-empty part(s) of "bset".
8321 *
8322 * The input only involves parameters and existentially quantified variables.
8323 * All equalities among parameters have been removed.
8324 *
8325 * Since the existentially quantified variables in the result are in general
8326 * going to be different from those in the input, we first replace
8327 * them by the minimal number of variables based on their equalities.
8328 * This should simplify the parametric integer programming.
8329 */
8331{
8332 isl_morph *morph1, *morph2;
8333 isl_set *set;
8334 isl_size n;
8335
8336 if (!bset)
8337 return NULL;
8338 if (bset->n_eq == 0)
8340
8342 bset = isl_morph_basic_set(isl_morph_copy(morph1), bset);
8343 bset = isl_basic_set_lift(bset);
8345 bset = isl_morph_basic_set(morph2, bset);
8347 if (n < 0)
8348 bset = isl_basic_set_free(bset);
8349 bset = isl_basic_set_project_out(bset, isl_dim_set, 0, n);
8350
8352
8354
8355 return set;
8356}
8357
8358/* Project the given basic set onto its parameter domain, possibly introducing
8359 * new, explicit, existential variables in the constraints.
8360 * The input has parameters and (possibly implicit) existential variables.
8361 * The output has the same parameters, but only
8362 * explicit existentially quantified variables.
8363 *
8364 * The actual projection is performed by pip, but pip doesn't seem
8365 * to like equalities very much, so we first remove the equalities
8366 * among the parameters by performing a variable compression on
8367 * the parameters. Afterward, an inverse transformation is performed
8368 * and the equalities among the parameters are inserted back in.
8369 *
8370 * The variable compression on the parameters may uncover additional
8371 * equalities that were only implicit before. We therefore check
8372 * if there are any new parameter equalities in the result and
8373 * if so recurse. The removal of parameter equalities is required
8374 * for the parameter compression performed by base_compute_divs.
8375 */
8378{
8379 int i;
8380 struct isl_mat *eq;
8381 struct isl_mat *T, *T2;
8382 struct isl_set *set;
8383 isl_size nparam;
8384
8385 bset = isl_basic_set_cow(bset);
8386 if (!bset)
8387 return NULL;
8388
8389 if (bset->n_eq == 0)
8390 return base_compute_divs(bset);
8391
8392 bset = isl_basic_set_gauss(bset, NULL);
8393 if (!bset)
8394 return NULL;
8396 return isl_set_from_basic_set(bset);
8397
8398 i = first_parameter_equality(bset);
8399 if (i == bset->n_eq)
8400 return base_compute_divs(bset);
8401
8402 nparam = isl_basic_set_dim(bset, isl_dim_param);
8403 if (nparam < 0)
8405 eq = isl_mat_sub_alloc6(bset->ctx, bset->eq, i, bset->n_eq - i,
8406 0, 1 + nparam);
8407 eq = isl_mat_cow(eq);
8409 if (T && T->n_col == 0) {
8410 isl_mat_free(T);
8411 isl_mat_free(T2);
8412 isl_mat_free(eq);
8413 bset = isl_basic_set_set_to_empty(bset);
8414 return isl_set_from_basic_set(bset);
8415 }
8416 bset = basic_set_parameter_preimage(bset, T);
8417
8418 i = first_parameter_equality(bset);
8419 if (!bset)
8420 set = NULL;
8421 else if (i == bset->n_eq)
8422 set = base_compute_divs(bset);
8423 else
8427 return set;
8428}
8429
8430/* Insert the divs from "ls" before those of "bmap".
8431 *
8432 * The number of columns is not changed, which means that the last
8433 * dimensions of "bmap" are being reintepreted as the divs from "ls".
8434 * The caller is responsible for removing the same number of dimensions
8435 * from the space of "bmap".
8436 */
8439{
8440 int i;
8441 isl_size n_div;
8442 int old_n_div;
8443
8444 n_div = isl_local_space_dim(ls, isl_dim_div);
8445 if (n_div < 0)
8446 return isl_basic_map_free(bmap);
8447 if (n_div == 0)
8448 return bmap;
8449
8450 old_n_div = bmap->n_div;
8451 bmap = insert_div_rows(bmap, n_div);
8452 if (!bmap)
8453 return NULL;
8454
8455 for (i = 0; i < n_div; ++i) {
8456 isl_seq_cpy(bmap->div[i], ls->div->row[i], ls->div->n_col);
8457 isl_seq_clr(bmap->div[i] + ls->div->n_col, old_n_div);
8458 }
8459
8460 return bmap;
8461}
8462
8463/* Replace the space of "bmap" by the space and divs of "ls".
8464 *
8465 * If "ls" has any divs, then we simplify the result since we may
8466 * have discovered some additional equalities that could simplify
8467 * the div expressions.
8468 */
8471{
8472 isl_size n_div;
8473
8474 bmap = isl_basic_map_cow(bmap);
8475 n_div = isl_local_space_dim(ls, isl_dim_div);
8476 if (!bmap || n_div < 0)
8477 goto error;
8478
8479 bmap = insert_divs_from_local_space(bmap, ls);
8480 if (!bmap)
8481 goto error;
8482
8483 isl_space_free(bmap->dim);
8484 bmap->dim = isl_local_space_get_space(ls);
8485 if (!bmap->dim)
8486 goto error;
8487
8489 if (n_div > 0)
8490 bmap = isl_basic_map_simplify(bmap);
8491 bmap = isl_basic_map_finalize(bmap);
8492 return bmap;
8493error:
8494 isl_basic_map_free(bmap);
8496 return NULL;
8497}
8498
8499/* Replace the space of "map" by the space and divs of "ls".
8500 */
8503{
8504 int i;
8505
8506 map = isl_map_cow(map);
8507 if (!map || !ls)
8508 goto error;
8509
8510 for (i = 0; i < map->n; ++i) {
8513 if (!map->p[i])
8514 goto error;
8515 }
8518
8520 return map;
8521error:
8524 return NULL;
8525}
8526
8527/* Compute an explicit representation for the existentially
8528 * quantified variables for which do not know any explicit representation yet.
8529 *
8530 * We first sort the existentially quantified variables so that the
8531 * existentially quantified variables for which we already have an explicit
8532 * representation are placed before those for which we do not.
8533 * The input dimensions, the output dimensions and the existentially
8534 * quantified variables for which we already have an explicit
8535 * representation are then turned into parameters.
8536 * compute_divs returns a map with the same parameters and
8537 * no input or output dimensions and the dimension specification
8538 * is reset to that of the input, including the existentially quantified
8539 * variables for which we already had an explicit representation.
8540 */
8542{
8543 struct isl_basic_set *bset;
8544 struct isl_set *set;
8545 struct isl_map *map;
8546 isl_space *space;
8547 isl_local_space *ls;
8548 isl_size nparam;
8549 isl_size n_in;
8550 isl_size n_out;
8551 int n_known;
8552 int i;
8553
8554 bmap = isl_basic_map_sort_divs(bmap);
8555 bmap = isl_basic_map_cow(bmap);
8556 if (!bmap)
8557 return NULL;
8558
8559 n_known = isl_basic_map_first_unknown_div(bmap);
8560 nparam = isl_basic_map_dim(bmap, isl_dim_param);
8561 n_in = isl_basic_map_dim(bmap, isl_dim_in);
8562 n_out = isl_basic_map_dim(bmap, isl_dim_out);
8563 if (n_known < 0 || nparam < 0 || n_in < 0 || n_out < 0)
8565
8566 space = isl_space_set_alloc(bmap->ctx,
8567 nparam + n_in + n_out + n_known, 0);
8568 if (!space)
8569 goto error;
8570
8573 n_known, bmap->n_div - n_known);
8574 if (n_known > 0) {
8575 for (i = n_known; i < bmap->n_div; ++i)
8576 swap_div(bmap, i - n_known, i);
8577 bmap->n_div -= n_known;
8578 bmap->extra -= n_known;
8579 }
8580 bmap = isl_basic_map_reset_space(bmap, space);
8581 bset = bset_from_bmap(bmap);
8582
8584 map = set_to_map(set);
8586
8587 return map;
8588error:
8589 isl_basic_map_free(bmap);
8590 return NULL;
8591}
8592
8593/* Is the integer division at position "div" of "bmap" integral?
8594 * That is, does it have denominator 1?
8595 */
8597{
8598 if (isl_basic_map_check_range(bmap, isl_dim_div, div, 1) < 0)
8599 return isl_bool_error;
8600 return isl_int_is_one(bmap->div[div][0]);
8601}
8602
8603/* Remove the explicit representation of local variable "div",
8604 * if there is any.
8605 */
8607 __isl_take isl_basic_map *bmap, int div)
8608{
8609 isl_bool unknown;
8610
8611 unknown = isl_basic_map_div_is_marked_unknown(bmap, div);
8612 if (unknown < 0)
8613 return isl_basic_map_free(bmap);
8614 if (unknown)
8615 return bmap;
8616
8617 bmap = isl_basic_map_cow(bmap);
8618 if (!bmap)
8619 return NULL;
8620 isl_int_set_si(bmap->div[div][0], 0);
8621 return bmap;
8622}
8623
8624/* Is local variable "div" of "bmap" marked as not having an explicit
8625 * representation?
8626 * Note that even if "div" is not marked in this way and therefore
8627 * has an explicit representation, this representation may still
8628 * depend (indirectly) on other local variables that do not
8629 * have an explicit representation.
8630 */
8632 int div)
8633{
8634 if (isl_basic_map_check_range(bmap, isl_dim_div, div, 1) < 0)
8635 return isl_bool_error;
8636 return isl_int_is_zero(bmap->div[div][0]);
8637}
8638
8639/* Return the position of the first local variable that does not
8640 * have an explicit representation.
8641 * Return the total number of local variables if they all have
8642 * an explicit representation.
8643 * Return -1 on error.
8644 */
8646{
8647 int i;
8648
8649 if (!bmap)
8650 return -1;
8651
8652 for (i = 0; i < bmap->n_div; ++i) {
8653 if (!isl_basic_map_div_is_known(bmap, i))
8654 return i;
8655 }
8656 return bmap->n_div;
8657}
8658
8659/* Return the position of the first local variable that does not
8660 * have an explicit representation.
8661 * Return the total number of local variables if they all have
8662 * an explicit representation.
8663 * Return -1 on error.
8664 */
8669
8670/* Does "bmap" have an explicit representation for all local variables?
8671 */
8673{
8674 int first;
8675 isl_size n;
8676
8678 first = isl_basic_map_first_unknown_div(bmap);
8679 if (n < 0 || first < 0)
8680 return isl_bool_error;
8681 return first == n;
8682}
8683
8684/* Do all basic maps in "map" have an explicit representation
8685 * for all local variables?
8686 */
8688{
8689 int i;
8690
8691 if (!map)
8692 return isl_bool_error;
8693
8694 for (i = 0; i < map->n; ++i) {
8695 int known = isl_basic_map_divs_known(map->p[i]);
8696 if (known <= 0)
8697 return known;
8698 }
8699
8700 return isl_bool_true;
8701}
8702
8703/* If bmap contains any unknown divs, then compute explicit
8704 * expressions for them. However, this computation may be
8705 * quite expensive, so first try to remove divs that aren't
8706 * strictly needed.
8707 */
8709{
8710 int known;
8711 struct isl_map *map;
8712
8713 known = isl_basic_map_divs_known(bmap);
8714 if (known < 0)
8715 goto error;
8716 if (known)
8717 return isl_map_from_basic_map(bmap);
8718
8720
8721 known = isl_basic_map_divs_known(bmap);
8722 if (known < 0)
8723 goto error;
8724 if (known)
8725 return isl_map_from_basic_map(bmap);
8726
8727 map = compute_divs(bmap);
8728 return map;
8729error:
8730 isl_basic_map_free(bmap);
8731 return NULL;
8732}
8733
8735{
8736 int i;
8737 int known;
8738 struct isl_map *res;
8739
8740 if (!map)
8741 return NULL;
8742 if (map->n == 0)
8743 return map;
8744
8745 known = isl_map_divs_known(map);
8746 if (known < 0) {
8748 return NULL;
8749 }
8750 if (known)
8751 return map;
8752
8754 for (i = 1 ; i < map->n; ++i) {
8755 struct isl_map *r2;
8759 else
8760 res = isl_map_union(res, r2);
8761 }
8763
8764 return res;
8765}
8766
8771
8776
8778{
8779 isl_space *space;
8780 isl_size n_out;
8781
8782 n_out = isl_map_dim(map, isl_dim_out);
8783 if (n_out < 0)
8784 return set_from_map(isl_map_free(map));
8786
8787 map = isl_map_project_out(map, isl_dim_out, 0, n_out);
8788
8789 return set_from_map(isl_map_reset_space(map, space));
8790}
8791
8792/* Return the union of "map1" and "map2", where we assume for now that
8793 * "map1" and "map2" are disjoint. Note that the basic maps inside
8794 * "map1" or "map2" may not be disjoint from each other.
8795 * Also note that this function is also called from isl_map_union,
8796 * which takes care of handling the situation where "map1" and "map2"
8797 * may not be disjoint.
8798 *
8799 * If one of the inputs is empty, we can simply return the other input.
8800 * Similarly, if one of the inputs is universal, then it is equal to the union.
8801 */
8804{
8805 int i;
8806 unsigned flags = 0;
8807 struct isl_map *map = NULL;
8808 int is_universe;
8809
8811 goto error;
8812
8813 if (map1->n == 0) {
8815 return map2;
8816 }
8817 if (map2->n == 0) {
8819 return map1;
8820 }
8821
8822 is_universe = isl_map_plain_is_universe(map1);
8823 if (is_universe < 0)
8824 goto error;
8825 if (is_universe) {
8827 return map1;
8828 }
8829
8830 is_universe = isl_map_plain_is_universe(map2);
8831 if (is_universe < 0)
8832 goto error;
8833 if (is_universe) {
8835 return map2;
8836 }
8837
8841
8843 map1->n + map2->n, flags);
8844 if (!map)
8845 goto error;
8846 for (i = 0; i < map1->n; ++i) {
8848 isl_basic_map_copy(map1->p[i]));
8849 if (!map)
8850 goto error;
8851 }
8852 for (i = 0; i < map2->n; ++i) {
8854 isl_basic_map_copy(map2->p[i]));
8855 if (!map)
8856 goto error;
8857 }
8860 return map;
8861error:
8865 return NULL;
8866}
8867
8868/* Return the union of "map1" and "map2", where "map1" and "map2" are
8869 * guaranteed to be disjoint by the caller.
8870 *
8871 * Note that this functions is called from within isl_map_make_disjoint,
8872 * so we have to be careful not to touch the constraints of the inputs
8873 * in any way.
8874 */
8881
8882/* Return the union of "map1" and "map2", where "map1" and "map2" may
8883 * not be disjoint.
8884 *
8885 * We currently simply call map_union_disjoint, the internal operation
8886 * of which does not really depend on the inputs being disjoint.
8887 * If the result contains more than one basic map, then we clear
8888 * the disjoint flag since the result may contain basic maps from
8889 * both inputs and these are not guaranteed to be disjoint.
8890 *
8891 * As a special case, if "map1" and "map2" are obviously equal,
8892 * then we simply return "map1".
8893 */
8896{
8897 int equal;
8898
8900 goto error;
8901
8903 if (equal < 0)
8904 goto error;
8905 if (equal) {
8907 return map1;
8908 }
8909
8911 if (!map1)
8912 return NULL;
8913 if (map1->n > 1)
8915 return map1;
8916error:
8919 return NULL;
8920}
8921
8928
8934
8935/* Apply "fn" to pairs of elements from "map" and "set" and collect
8936 * the results in a map living in "space".
8937 *
8938 * "map" and "set" are assumed to be compatible and non-NULL.
8939 */
8944{
8945 unsigned flags = 0;
8946 struct isl_map *result;
8947 int i, j;
8948
8951 return isl_map_reset_equal_dim_space(map, space);
8952 }
8953
8957
8958 result = isl_map_alloc_space(space, map->n * set->n, flags);
8959 for (i = 0; result && i < map->n; ++i)
8960 for (j = 0; j < set->n; ++j) {
8961 result = isl_map_add_basic_map(result,
8962 fn(isl_basic_map_copy(map->p[i]),
8963 isl_basic_set_copy(set->p[j])));
8964 if (!result)
8965 break;
8966 }
8967
8970 return result;
8971}
8972
8975{
8976 isl_bool ok;
8977 isl_space *space;
8978
8981 if (ok < 0)
8982 goto error;
8983 if (!ok)
8985 "incompatible spaces", goto error);
8986
8987 space = isl_map_get_space(map);
8988 return map_intersect_set(map, space, set,
8990error:
8993 return NULL;
8994}
8995
8996/* Intersect the domain of "map" with "set".
8997 *
8998 * If the domain dimensions of "map" do not have any identifiers,
8999 * then copy them over from "set".
9000 */
9003{
9004 isl_bool ok;
9005 isl_space *space;
9006
9009 if (ok < 0)
9010 goto error;
9011 if (!ok)
9013 "incompatible spaces", goto error);
9014
9015 space = isl_map_get_space(map);
9018 return map_intersect_set(map, space, set,
9020error:
9023 return NULL;
9024}
9025
9026#undef BASE
9027#define BASE map
9028static
9030
9031/* Data structure that specifies how isl_map_intersect_factor
9032 * should operate.
9033 *
9034 * "preserve_type" is the tuple where the factor differs from
9035 * the input map and of which the identifiers needs
9036 * to be preserved explicitly.
9037 * "other_factor" is used to extract the space of the other factor
9038 * from the space of the product ("map").
9039 * "product" is used to combine the given factor and a universe map
9040 * in the space returned by "other_factor" to produce a map
9041 * that lives in the same space as the input map.
9042 */
9049
9050/* Given a map "map" in some product space and a map "factor"
9051 * living in some factor space, return the intersection.
9052 *
9053 * After aligning the parameters,
9054 * the map "factor" is first extended to a map living in the same space
9055 * as "map" and then a regular intersection is computed.
9056 *
9057 * Note that the extension is computed as a product, which is anonymous
9058 * by default. If "map" has an identifier on the corresponding tuple,
9059 * then this identifier needs to be set on the product
9060 * before the intersection is computed.
9061 */
9064 struct isl_intersect_factor_control *control)
9065{
9067 isl_space *space;
9068 isl_map *other, *product;
9069
9071 if (equal < 0)
9072 goto error;
9073 if (!equal) {
9075 factor = isl_map_align_params(factor, isl_map_get_space(map));
9076 }
9077
9078 space = isl_map_get_space(map);
9079 other = isl_map_universe(control->other_factor(space));
9080 product = control->product(factor, other);
9081
9082 space = isl_map_peek_space(map);
9083 product = isl_map_copy_tuple_id(product, control->preserve_type,
9084 space, control->preserve_type);
9085 return map_intersect(map, product);
9086error:
9088 isl_map_free(factor);
9089 return NULL;
9090}
9091
9092/* Return the domain product of "map2" and "map1".
9093 */
9099
9100/* Return the range product of "map2" and "map1".
9101 */
9107
9108/* Given a map "map" in a space [A -> B] -> C and a map "factor"
9109 * in the space A -> C, return the intersection.
9110 */
9113{
9114 struct isl_intersect_factor_control control = {
9115 .preserve_type = isl_dim_in,
9116 .other_factor = isl_space_domain_factor_range,
9117 .product = isl_map_domain_product,
9118 };
9119
9120 return isl_map_intersect_factor(map, factor, &control);
9121}
9122
9123/* Given a map "map" in a space [A -> B] -> C and a map "factor"
9124 * in the space B -> C, return the intersection.
9125 */
9128{
9129 struct isl_intersect_factor_control control = {
9130 .preserve_type = isl_dim_in,
9131 .other_factor = isl_space_domain_factor_domain,
9133 };
9134
9135 return isl_map_intersect_factor(map, factor, &control);
9136}
9137
9138/* Given a map "map" in a space A -> [B -> C] and a map "factor"
9139 * in the space A -> B, return the intersection.
9140 */
9143{
9144 struct isl_intersect_factor_control control = {
9145 .preserve_type = isl_dim_out,
9146 .other_factor = isl_space_range_factor_range,
9147 .product = isl_map_range_product,
9148 };
9149
9150 return isl_map_intersect_factor(map, factor, &control);
9151}
9152
9153/* Given a map "map" in a space A -> [B -> C] and a map "factor"
9154 * in the space A -> C, return the intersection.
9155 */
9158{
9159 struct isl_intersect_factor_control control = {
9160 .preserve_type = isl_dim_out,
9161 .other_factor = isl_space_range_factor_domain,
9163 };
9164
9165 return isl_map_intersect_factor(map, factor, &control);
9166}
9167
9168/* Given a set "set" in a space [A -> B] and a set "domain"
9169 * in the space A, return the intersection.
9170 *
9171 * The set "domain" is first extended to a set living in the space
9172 * [A -> B] and then a regular intersection is computed.
9173 */
9176{
9177 struct isl_intersect_factor_control control = {
9178 .preserve_type = isl_dim_set,
9179 .other_factor = isl_space_factor_range,
9180 .product = isl_map_range_product,
9181 };
9182
9184 set_to_map(domain), &control));
9185}
9186
9187/* Given a set "set" in a space [A -> B] and a set "range"
9188 * in the space B, return the intersection.
9189 *
9190 * The set "range" is first extended to a set living in the space
9191 * [A -> B] and then a regular intersection is computed.
9192 */
9195{
9196 struct isl_intersect_factor_control control = {
9197 .preserve_type = isl_dim_set,
9198 .other_factor = isl_space_factor_domain,
9200 };
9201
9203 set_to_map(range), &control));
9204}
9205
9206#undef BASE
9207#define BASE set
9208static
9210
9211/* Given a map "map" in a space [A -> B] -> C and a set "domain"
9212 * in the space A, return the intersection.
9213 *
9214 * The set "domain" is extended to a set living in the space [A -> B] and
9215 * the domain of "map" is intersected with this set.
9216 *
9217 * If "map" has an identifier on the domain tuple,
9218 * then this identifier needs to be set on this product
9219 * before the intersection is computed.
9220 */
9223{
9224 isl_space *space;
9225 isl_set *factor;
9226
9228 space = isl_map_get_space(map);
9229 space = isl_space_domain_wrapped_range(space);
9230 factor = isl_set_universe(space);
9231 domain = isl_set_product(domain, factor);
9232 space = isl_map_peek_space(map);
9233 domain = isl_set_copy_tuple_id(domain, isl_dim_set, space, isl_dim_in);
9235}
9236
9237/* Given a map "map" in a space A -> [B -> C] and a set "domain"
9238 * in the space B, return the intersection.
9239 *
9240 * The set "domain" is extended to a set living in the space [B -> C] and
9241 * the range of "map" is intersected with this set.
9242 *
9243 * If "map" has an identifier on the range tuple,
9244 * then this identifier needs to be set on this product
9245 * before the intersection is computed.
9246 */
9249{
9250 isl_space *space;
9251 isl_set *factor;
9252
9254 space = isl_map_get_space(map);
9255 space = isl_space_range_wrapped_range(space);
9256 factor = isl_set_universe(space);
9257 domain = isl_set_product(domain, factor);
9258 space = isl_map_peek_space(map);
9259 domain = isl_set_copy_tuple_id(domain, isl_dim_set, space, isl_dim_out);
9261}
9262
9265{
9267 goto error;
9270 return isl_map_reverse(map1);
9271error:
9274 return NULL;
9275}
9276
9279{
9280 isl_space *space;
9281 struct isl_map *result;
9282 int i, j;
9283
9285 goto error;
9286
9287 space = isl_space_join(isl_space_copy(map1->dim),
9288 isl_space_copy(map2->dim));
9289
9290 result = isl_map_alloc_space(space, map1->n * map2->n, 0);
9291 if (!result)
9292 goto error;
9293 for (i = 0; i < map1->n; ++i)
9294 for (j = 0; j < map2->n; ++j) {
9295 result = isl_map_add_basic_map(result,
9297 isl_basic_map_copy(map1->p[i]),
9298 isl_basic_map_copy(map2->p[j])));
9299 if (!result)
9300 goto error;
9301 }
9304 if (result && result->n <= 1)
9305 ISL_F_SET(result, ISL_MAP_DISJOINT);
9306 return result;
9307error:
9310 return NULL;
9311}
9312
9313/* Is "bmap" a transformation, i.e.,
9314 * does it relate elements from the same space.
9315 */
9323
9324/* Check that "bmap" is a transformation, i.e.,
9325 * that it relates elements from the same space.
9326 */
9329{
9331
9333 if (equal < 0)
9334 return isl_stat_error;
9335 if (!equal)
9337 "domain and range don't match", return isl_stat_error);
9338 return isl_stat_ok;
9339}
9340
9341/*
9342 * returns range - domain
9343 */
9345{
9346 isl_space *target_space;
9347 struct isl_basic_set *bset;
9348 isl_size dim;
9349 isl_size nparam;
9351 int i;
9352
9354 return isl_basic_map_free(bmap);
9355 dim = isl_basic_map_dim(bmap, isl_dim_in);
9356 nparam = isl_basic_map_dim(bmap, isl_dim_param);
9357 if (dim < 0 || nparam < 0)
9358 goto error;
9359 target_space = isl_space_domain(isl_basic_map_get_space(bmap));
9361 bmap = isl_basic_map_add_dims(bmap, isl_dim_in, dim);
9363 if (total < 0)
9364 bmap = isl_basic_map_free(bmap);
9365 bmap = isl_basic_map_extend_constraints(bmap, dim, 0);
9366 for (i = 0; i < dim; ++i) {
9367 int j = isl_basic_map_alloc_equality(bmap);
9368 if (j < 0) {
9369 bmap = isl_basic_map_free(bmap);
9370 break;
9371 }
9372 isl_seq_clr(bmap->eq[j], 1 + total);
9373 isl_int_set_si(bmap->eq[j][1+nparam+i], 1);
9374 isl_int_set_si(bmap->eq[j][1+nparam+dim+i], 1);
9375 isl_int_set_si(bmap->eq[j][1+nparam+2*dim+i], -1);
9376 }
9377 bset = isl_basic_map_domain(bmap);
9378 bset = isl_basic_set_reset_space(bset, target_space);
9379 return bset;
9380error:
9381 isl_basic_map_free(bmap);
9382 return NULL;
9383}
9384
9385/* Is the tuple of type "type1" of "map" the same as
9386 * the tuple of type "type2" of "space"?
9387 */
9389 enum isl_dim_type type1, __isl_keep isl_space *space,
9390 enum isl_dim_type type2)
9391{
9392 isl_space *map_space;
9393
9394 map_space = isl_map_peek_space(map);
9395 return isl_space_tuple_is_equal(map_space, type1, space, type2);
9396}
9397
9398/* Is the tuple of type "type1" of "map1" the same as
9399 * the tuple of type "type2" of "map2"?
9400 */
9402 enum isl_dim_type type1, __isl_keep isl_map *map2,
9403 enum isl_dim_type type2)
9404{
9405 isl_space *space1, *space2;
9406
9407 space1 = isl_map_peek_space(map1);
9408 space2 = isl_map_peek_space(map2);
9409 return isl_space_tuple_is_equal(space1, type1, space2, type2);
9410}
9411
9412/* Is the space of "obj" equal to "space", ignoring parameters?
9413 */
9415 __isl_keep isl_space *space)
9416{
9417 isl_space *map_space;
9418
9419 map_space = isl_map_peek_space(map);
9420 return isl_space_has_equal_tuples(map_space, space);
9421}
9422
9423/* Check that "map" is a transformation, i.e.,
9424 * that it relates elements from the same space.
9425 */
9427{
9429
9431 if (equal < 0)
9432 return isl_stat_error;
9433 if (!equal)
9435 "domain and range don't match", return isl_stat_error);
9436 return isl_stat_ok;
9437}
9438
9439/*
9440 * returns range - domain
9441 */
9443{
9444 int i;
9445 isl_space *space;
9446 struct isl_set *result;
9447
9449 goto error;
9450 space = isl_map_get_space(map);
9451 space = isl_space_domain(space);
9452 result = isl_set_alloc_space(space, map->n, 0);
9453 if (!result)
9454 goto error;
9455 for (i = 0; i < map->n; ++i)
9456 result = isl_set_add_basic_set(result,
9459 return result;
9460error:
9462 return NULL;
9463}
9464
9465/*
9466 * returns [domain -> range] -> range - domain
9467 */
9470{
9471 int i, k;
9472 isl_space *space;
9474 isl_size nparam, n;
9476
9478 return isl_basic_map_free(bmap);
9479
9480 nparam = isl_basic_map_dim(bmap, isl_dim_param);
9482 if (nparam < 0 || n < 0)
9483 return isl_basic_map_free(bmap);
9484
9485 space = isl_basic_map_get_space(bmap);
9486 space = isl_space_from_range(isl_space_domain(space));
9488
9490 bmap = isl_basic_map_apply_range(bmap, domain);
9491 bmap = isl_basic_map_extend_constraints(bmap, n, 0);
9492
9494 if (total < 0)
9495 return isl_basic_map_free(bmap);
9496
9497 for (i = 0; i < n; ++i) {
9499 if (k < 0)
9500 goto error;
9501 isl_seq_clr(bmap->eq[k], 1 + total);
9502 isl_int_set_si(bmap->eq[k][1 + nparam + i], 1);
9503 isl_int_set_si(bmap->eq[k][1 + nparam + n + i], -1);
9504 isl_int_set_si(bmap->eq[k][1 + nparam + n + n + i], 1);
9505 }
9506
9507 bmap = isl_basic_map_gauss(bmap, NULL);
9508 return isl_basic_map_finalize(bmap);
9509error:
9510 isl_basic_map_free(bmap);
9511 return NULL;
9512}
9513
9514/*
9515 * returns [domain -> range] -> range - domain
9516 */
9525
9526/* Return pairs of elements { x -> y } such that y - x is in "deltas".
9527 */
9529{
9530 isl_space *space;
9531 isl_map *map;
9532
9535 map = isl_map_intersect_range(map, deltas);
9536
9538}
9539
9541{
9542 isl_size n_in, n_out;
9543
9544 n_in = isl_space_dim(space, isl_dim_in);
9545 n_out = isl_space_dim(space, isl_dim_out);
9546 if (n_in < 0 || n_out < 0)
9547 goto error;
9548 if (n_in != n_out)
9549 isl_die(space->ctx, isl_error_invalid,
9550 "number of input and output dimensions needs to be "
9551 "the same", goto error);
9552 return isl_basic_map_equal(space, n_in);
9553error:
9554 isl_space_free(space);
9555 return NULL;
9556}
9557
9562
9570
9571/* Construct a basic set with all set dimensions having only non-negative
9572 * values.
9573 */
9575 __isl_take isl_space *space)
9576{
9577 int i;
9578 isl_size nparam;
9579 isl_size dim;
9581 struct isl_basic_set *bset;
9582
9583 nparam = isl_space_dim(space, isl_dim_param);
9584 dim = isl_space_dim(space, isl_dim_set);
9586 if (nparam < 0 || dim < 0 || total < 0)
9587 space = isl_space_free(space);
9588 bset = isl_basic_set_alloc_space(space, 0, 0, dim);
9589 if (!bset)
9590 return NULL;
9591 for (i = 0; i < dim; ++i) {
9592 int k = isl_basic_set_alloc_inequality(bset);
9593 if (k < 0)
9594 goto error;
9595 isl_seq_clr(bset->ineq[k], 1 + total);
9596 isl_int_set_si(bset->ineq[k][1 + nparam + i], 1);
9597 }
9598 return bset;
9599error:
9600 isl_basic_set_free(bset);
9601 return NULL;
9602}
9603
9604/* Construct the half-space x_pos >= 0.
9605 */
9607 int pos)
9608{
9609 int k;
9611 isl_basic_set *nonneg;
9612
9614 if (total < 0)
9615 space = isl_space_free(space);
9616 nonneg = isl_basic_set_alloc_space(space, 0, 0, 1);
9618 if (k < 0)
9619 goto error;
9620 isl_seq_clr(nonneg->ineq[k], 1 + total);
9621 isl_int_set_si(nonneg->ineq[k][pos], 1);
9622
9623 return isl_basic_set_finalize(nonneg);
9624error:
9625 isl_basic_set_free(nonneg);
9626 return NULL;
9627}
9628
9629/* Construct the half-space x_pos <= -1.
9630 */
9632 int pos)
9633{
9634 int k;
9637
9639 if (total < 0)
9640 space = isl_space_free(space);
9641 neg = isl_basic_set_alloc_space(space, 0, 0, 1);
9643 if (k < 0)
9644 goto error;
9645 isl_seq_clr(neg->ineq[k], 1 + total);
9646 isl_int_set_si(neg->ineq[k][0], -1);
9647 isl_int_set_si(neg->ineq[k][pos], -1);
9648
9650error:
9652 return NULL;
9653}
9654
9656 enum isl_dim_type type, unsigned first, unsigned n)
9657{
9658 int i;
9659 unsigned offset;
9660 isl_basic_set *nonneg;
9662
9663 if (n == 0)
9664 return set;
9665
9666 if (isl_set_check_range(set, type, first, n) < 0)
9667 return isl_set_free(set);
9668
9669 offset = pos(set->dim, type);
9670 for (i = 0; i < n; ++i) {
9672 offset + first + i);
9673 neg = neg_halfspace(isl_set_get_space(set), offset + first + i);
9674
9676 }
9677
9678 return set;
9679}
9680
9681static isl_stat foreach_orthant(__isl_take isl_set *set, int *signs, int first,
9682 int len,
9683 isl_stat (*fn)(__isl_take isl_set *orthant, int *signs, void *user),
9684 void *user)
9685{
9686 isl_set *half;
9687
9688 if (!set)
9689 return isl_stat_error;
9692 return isl_stat_ok;
9693 }
9694 if (first == len)
9695 return fn(set, signs, user);
9696
9697 signs[first] = 1;
9699 1 + first));
9700 half = isl_set_intersect(half, isl_set_copy(set));
9701 if (foreach_orthant(half, signs, first + 1, len, fn, user) < 0)
9702 goto error;
9703
9704 signs[first] = -1;
9706 1 + first));
9707 half = isl_set_intersect(half, set);
9708 return foreach_orthant(half, signs, first + 1, len, fn, user);
9709error:
9711 return isl_stat_error;
9712}
9713
9714/* Call "fn" on the intersections of "set" with each of the orthants
9715 * (except for obviously empty intersections). The orthant is identified
9716 * by the signs array, with each entry having value 1 or -1 according
9717 * to the sign of the corresponding variable.
9718 */
9720 isl_stat (*fn)(__isl_take isl_set *orthant, int *signs, void *user),
9721 void *user)
9722{
9723 isl_size nparam;
9724 isl_size nvar;
9725 int *signs;
9726 isl_stat r;
9727
9728 if (!set)
9729 return isl_stat_error;
9731 return isl_stat_ok;
9732
9733 nparam = isl_set_dim(set, isl_dim_param);
9734 nvar = isl_set_dim(set, isl_dim_set);
9735 if (nparam < 0 || nvar < 0)
9736 return isl_stat_error;
9737
9738 signs = isl_alloc_array(set->ctx, int, nparam + nvar);
9739
9740 r = foreach_orthant(isl_set_copy(set), signs, 0, nparam + nvar,
9741 fn, user);
9742
9743 free(signs);
9744
9745 return r;
9746}
9747
9752
9755{
9756 isl_bool is_subset;
9757 struct isl_map *map1;
9758 struct isl_map *map2;
9759
9760 if (!bmap1 || !bmap2)
9761 return isl_bool_error;
9762
9765
9766 is_subset = isl_map_is_subset(map1, map2);
9767
9770
9771 return is_subset;
9772}
9773
9779
9782{
9783 isl_bool is_subset;
9784
9785 if (!bmap1 || !bmap2)
9786 return isl_bool_error;
9787 is_subset = isl_basic_map_is_subset(bmap1, bmap2);
9788 if (is_subset != isl_bool_true)
9789 return is_subset;
9790 is_subset = isl_basic_map_is_subset(bmap2, bmap1);
9791 return is_subset;
9792}
9793
9800
9802{
9803 int i;
9804 int is_empty;
9805
9806 if (!map)
9807 return isl_bool_error;
9808 for (i = 0; i < map->n; ++i) {
9809 is_empty = isl_basic_map_is_empty(map->p[i]);
9810 if (is_empty < 0)
9811 return isl_bool_error;
9812 if (!is_empty)
9813 return isl_bool_false;
9814 }
9815 return isl_bool_true;
9816}
9817
9822
9827
9832
9833#undef TYPE
9834#define TYPE isl_basic_map
9835
9836static
9839
9840/* Check that "bset1" and "bset2" live in the same space,
9841 * reporting an error if they do not.
9842 */
9849
9850#undef TYPE
9851#define TYPE isl_map
9852
9856
9862
9863#undef TYPE1
9864#define TYPE1 isl_map
9865#undef TYPE2
9866#define TYPE2 isl_basic_map
9867#undef TYPE_PAIR
9868#define TYPE_PAIR isl_map_basic_map
9869
9870static
9873
9874/* Check that "set" and "bset" live in the same space,
9875 * reporting an error if they do not.
9876 */
9883
9885{
9886 isl_bool is_subset;
9887
9888 if (!map1 || !map2)
9889 return isl_bool_error;
9890 is_subset = isl_map_is_subset(map1, map2);
9891 if (is_subset != isl_bool_true)
9892 return is_subset;
9893 is_subset = isl_map_is_subset(map2, map1);
9894 return is_subset;
9895}
9896
9897/* Is "map1" equal to "map2"?
9898 *
9899 * First check if they are obviously equal.
9900 * If not, then perform a more detailed analysis.
9901 */
9911
9914{
9915 isl_bool is_subset;
9916
9917 if (!bmap1 || !bmap2)
9918 return isl_bool_error;
9919 is_subset = isl_basic_map_is_subset(bmap1, bmap2);
9920 if (is_subset != isl_bool_true)
9921 return is_subset;
9922 is_subset = isl_basic_map_is_subset(bmap2, bmap1);
9923 return isl_bool_not(is_subset);
9924}
9925
9928{
9929 isl_bool is_subset;
9930
9931 if (!map1 || !map2)
9932 return isl_bool_error;
9933 is_subset = isl_map_is_subset(map1, map2);
9934 if (is_subset != isl_bool_true)
9935 return is_subset;
9936 is_subset = isl_map_is_subset(map2, map1);
9937 return isl_bool_not(is_subset);
9938}
9939
9945
9946/* Is "bmap" obviously equal to the universe with the same space?
9947 *
9948 * That is, does it not have any constraints?
9949 */
9951{
9952 if (!bmap)
9953 return isl_bool_error;
9954 return bmap->n_eq == 0 && bmap->n_ineq == 0;
9955}
9956
9957/* Is "bset" obviously equal to the universe with the same space?
9958 */
9963
9964/* If "c" does not involve any existentially quantified variables,
9965 * then set *univ to false and abort
9966 */
9968{
9969 isl_bool *univ = user;
9970 isl_size n;
9971
9973 if (n < 0)
9974 c = isl_constraint_free(c);
9977 if (*univ < 0 || !*univ)
9978 return isl_stat_error;
9979 return isl_stat_ok;
9980}
9981
9982/* Is "bmap" equal to the universe with the same space?
9983 *
9984 * First check if it is obviously equal to the universe.
9985 * If not and if there are any constraints not involving
9986 * existentially quantified variables, then it is certainly
9987 * not equal to the universe.
9988 * Otherwise, check if the universe is a subset of "bmap".
9989 */
9991{
9992 isl_size n_div;
9993 isl_bool univ;
9995
9997 if (univ < 0 || univ)
9998 return univ;
9999 n_div = isl_basic_map_dim(bmap, isl_dim_div);
10000 if (n_div < 0)
10001 return isl_bool_error;
10002 if (n_div == 0)
10003 return isl_bool_false;
10004 univ = isl_bool_true;
10005 if (isl_basic_map_foreach_constraint(bmap, &involves_divs, &univ) < 0 &&
10006 univ)
10007 return isl_bool_error;
10008 if (univ < 0 || !univ)
10009 return univ;
10011 univ = isl_basic_map_is_subset(test, bmap);
10013 return univ;
10014}
10015
10016/* Is "bset" equal to the universe with the same space?
10017 */
10022
10024{
10025 int i;
10026
10027 if (!map)
10028 return isl_bool_error;
10029
10030 for (i = 0; i < map->n; ++i) {
10032 if (r < 0 || r)
10033 return r;
10034 }
10035
10036 return isl_bool_false;
10037}
10038
10043
10045{
10046 struct isl_basic_set *bset = NULL;
10047 struct isl_vec *sample = NULL;
10048 isl_bool empty, non_empty;
10049
10050 if (!bmap)
10051 return isl_bool_error;
10052
10054 return isl_bool_true;
10055
10057 return isl_bool_false;
10058
10060 struct isl_basic_map *copy = isl_basic_map_copy(bmap);
10062 empty = isl_basic_map_plain_is_empty(copy);
10063 isl_basic_map_free(copy);
10064 return empty;
10065 }
10066
10067 non_empty = isl_basic_map_plain_is_non_empty(bmap);
10068 if (non_empty < 0)
10069 return isl_bool_error;
10070 if (non_empty)
10071 return isl_bool_false;
10072 isl_vec_free(bmap->sample);
10073 bmap->sample = NULL;
10075 if (!bset)
10076 return isl_bool_error;
10078 if (!sample)
10079 return isl_bool_error;
10080 empty = sample->size == 0;
10081 isl_vec_free(bmap->sample);
10082 bmap->sample = sample;
10083 if (empty)
10085
10086 return empty;
10087}
10088
10090{
10091 if (!bmap)
10092 return isl_bool_error;
10093 return ISL_F_ISSET(bmap, ISL_BASIC_MAP_EMPTY);
10094}
10095
10097{
10098 if (!bset)
10099 return isl_bool_error;
10100 return ISL_F_ISSET(bset, ISL_BASIC_SET_EMPTY);
10101}
10102
10103/* Is "bmap" known to be non-empty?
10104 *
10105 * That is, is the cached sample still valid?
10106 */
10108{
10110
10111 if (!bmap)
10112 return isl_bool_error;
10113 if (!bmap->sample)
10114 return isl_bool_false;
10116 if (total < 0)
10117 return isl_bool_error;
10118 if (bmap->sample->size != 1 + total)
10119 return isl_bool_false;
10120 return isl_basic_map_contains(bmap, bmap->sample);
10121}
10122
10127
10130{
10131 struct isl_map *map;
10132
10133 if (isl_basic_map_check_equal_space(bmap1, bmap2) < 0)
10134 goto error;
10135
10136 map = isl_map_alloc_space(isl_space_copy(bmap1->dim), 2, 0);
10137 if (!map)
10138 goto error;
10139 map = isl_map_add_basic_map(map, bmap1);
10140 map = isl_map_add_basic_map(map, bmap2);
10141 return map;
10142error:
10143 isl_basic_map_free(bmap1);
10144 isl_basic_map_free(bmap2);
10145 return NULL;
10146}
10147
10154
10155/* Order divs such that any div only depends on previous divs */
10158{
10159 int i;
10160 isl_size off;
10161
10163 if (off < 0)
10164 return isl_basic_map_free(bmap);
10165
10166 for (i = 0; i < bmap->n_div; ++i) {
10167 int pos;
10168 if (isl_int_is_zero(bmap->div[i][0]))
10169 continue;
10170 pos = isl_seq_first_non_zero(bmap->div[i]+1+1+off+i,
10171 bmap->n_div-i);
10172 if (pos == -1)
10173 continue;
10174 if (pos == 0)
10176 "integer division depends on itself",
10177 return isl_basic_map_free(bmap));
10178 bmap = isl_basic_map_swap_div(bmap, i, i + pos);
10179 if (!bmap)
10180 return NULL;
10181 --i;
10182 }
10183 return bmap;
10184}
10185
10187{
10188 int i;
10189
10190 if (!map)
10191 return 0;
10192
10193 for (i = 0; i < map->n; ++i) {
10194 map->p[i] = isl_basic_map_order_divs(map->p[i]);
10195 if (!map->p[i])
10196 goto error;
10197 }
10198
10199 return map;
10200error:
10202 return NULL;
10203}
10204
10205/* Sort the local variables of "bset".
10206 */
10212
10213/* Apply the expansion computed by isl_merge_divs.
10214 * The expansion itself is given by "exp" while the resulting
10215 * list of divs is given by "div".
10216 *
10217 * Move the integer divisions of "bmap" into the right position
10218 * according to "exp" and then introduce the additional integer
10219 * divisions, adding div constraints.
10220 * The moving should be done first to avoid moving coefficients
10221 * in the definitions of the extra integer divisions.
10222 */
10224 __isl_take isl_basic_map *bmap, __isl_take isl_mat *div, int *exp)
10225{
10226 int i, j;
10227 int n_div;
10228
10229 bmap = isl_basic_map_cow(bmap);
10230 if (!bmap || !div)
10231 goto error;
10232
10233 if (div->n_row < bmap->n_div)
10235 "not an expansion", goto error);
10236
10237 n_div = bmap->n_div;
10238 bmap = isl_basic_map_extend(bmap, div->n_row - n_div, 0,
10239 2 * (div->n_row - n_div));
10240
10241 for (i = n_div; i < div->n_row; ++i)
10242 if (isl_basic_map_alloc_div(bmap) < 0)
10243 goto error;
10244
10245 for (j = n_div - 1; j >= 0; --j) {
10246 if (exp[j] == j)
10247 break;
10248 bmap = isl_basic_map_swap_div(bmap, j, exp[j]);
10249 if (!bmap)
10250 goto error;
10251 }
10252 j = 0;
10253 for (i = 0; i < div->n_row; ++i) {
10254 if (j < n_div && exp[j] == i) {
10255 j++;
10256 } else {
10257 isl_seq_cpy(bmap->div[i], div->row[i], div->n_col);
10259 continue;
10260 bmap = isl_basic_map_add_div_constraints(bmap, i);
10261 if (!bmap)
10262 goto error;
10263 }
10264 }
10265
10266 isl_mat_free(div);
10267 return bmap;
10268error:
10269 isl_basic_map_free(bmap);
10270 isl_mat_free(div);
10271 return NULL;
10272}
10273
10274/* Apply the expansion computed by isl_merge_divs.
10275 * The expansion itself is given by "exp" while the resulting
10276 * list of divs is given by "div".
10277 */
10279 __isl_take isl_basic_set *bset, __isl_take isl_mat *div, int *exp)
10280{
10281 return isl_basic_map_expand_divs(bset, div, exp);
10282}
10283
10284/* Look for a div in dst that corresponds to the div "div" in src.
10285 * The divs before "div" in src and dst are assumed to be the same.
10286 *
10287 * Return the position of the corresponding div in dst
10288 * if there is one. Otherwise, return a position beyond the integer divisions.
10289 * Return isl_size_error on error.
10290 */
10292 __isl_keep isl_basic_map *src, unsigned div)
10293{
10294 int i;
10295 isl_size n_div;
10296 isl_size v_div;
10297
10299 n_div = isl_basic_map_dim(dst, isl_dim_div);
10300 if (n_div < 0 || v_div < 0)
10301 return isl_size_error;
10302 isl_assert(dst->ctx, div <= n_div, return isl_size_error);
10303 for (i = div; i < n_div; ++i)
10304 if (isl_seq_eq(dst->div[i], src->div[div], 1+1+v_div+div) &&
10305 !isl_seq_any_non_zero(dst->div[i] + 1 + 1 + v_div + div,
10306 n_div - div))
10307 return i;
10308 return n_div;
10309}
10310
10311/* Align the local variables of "dst" to those of "src",
10312 * adding local variables from "src" if needed.
10313 * That is, make sure that the first src->n_div local variables
10314 * of the result correspond to those of src.
10315 * For any integer division that is copied to "dst",
10316 * the defining constraints are also introduced to "dst".
10317 * For an existentially quantified variable (without an explicit definition)
10318 * only an unconstrained existentially quantified variable
10319 * in the same positions is introduced.
10320 * The integer division of "src" are assumed to be ordered.
10321 *
10322 * The integer divisions are swapped into the right position
10323 * (possibly after adding them first). This may result
10324 * in the remaining integer divisions appearing in the wrong order,
10325 * i.e., with some integer division appearing before
10326 * some other integer division on which it depends.
10327 * The integer divisions therefore need to be ordered.
10328 * This will not affect the integer divisions aligned to those of "src",
10329 * since "src" is assumed to have ordered integer divisions.
10330 *
10331 * The result is not finalized as by design it will have redundant
10332 * divs if any divs from "src" were copied.
10333 */
10336{
10337 int i;
10338 int extended;
10339 isl_size v_div;
10340 isl_size dst_n_div, src_n_div;
10341
10342 src_n_div = isl_basic_map_dim(src, isl_dim_div);
10343 if (!dst || src_n_div < 0)
10344 return isl_basic_map_free(dst);
10345
10346 if (src_n_div == 0)
10347 return dst;
10348
10350 if (v_div < 0)
10351 return isl_basic_map_free(dst);
10352
10353 extended = 0;
10354 dst_n_div = isl_basic_map_dim(dst, isl_dim_div);
10355 if (dst_n_div < 0)
10356 dst = isl_basic_map_free(dst);
10357 for (i = 0; i < src_n_div; ++i) {
10358 isl_bool known;
10359 isl_size j;
10360
10361 known = isl_basic_map_div_is_known(src, i);
10362 if (known < 0)
10363 return isl_basic_map_free(dst);
10364 j = known ? find_div(dst, src, i) : dst_n_div;
10365 if (j < 0)
10366 dst = isl_basic_map_free(dst);
10367 if (j == dst_n_div) {
10368 if (!extended) {
10369 int extra = src_n_div - i;
10370 dst = isl_basic_map_cow(dst);
10371 if (!dst)
10372 return isl_basic_map_free(dst);
10373 dst = isl_basic_map_extend(dst,
10374 extra, 0, 2 * extra);
10375 extended = 1;
10376 }
10377 j = isl_basic_map_alloc_div(dst);
10378 if (j < 0)
10379 return isl_basic_map_free(dst);
10380 dst_n_div++;
10381 if (!known)
10382 continue;
10383 isl_seq_cpy(dst->div[j], src->div[i], 1+1+v_div+i);
10384 isl_seq_clr(dst->div[j]+1+1+v_div+i, dst_n_div - i);
10386 if (!dst)
10387 return isl_basic_map_free(dst);
10388 }
10389 if (j != i)
10390 dst = isl_basic_map_swap_div(dst, i, j);
10391 if (!dst)
10392 return isl_basic_map_free(dst);
10393 }
10394 return isl_basic_map_order_divs(dst);
10395}
10396
10398{
10399 int i;
10400
10401 if (!map)
10402 return NULL;
10403 if (map->n == 0)
10404 return map;
10407 map = isl_map_cow(map);
10408 if (!map)
10409 return NULL;
10410
10411 for (i = 1; i < map->n; ++i)
10412 map->p[0] = isl_basic_map_align_divs(map->p[0], map->p[i]);
10413 for (i = 1; i < map->n; ++i) {
10414 map->p[i] = isl_basic_map_align_divs(map->p[i], map->p[0]);
10415 if (!map->p[i])
10416 return isl_map_free(map);
10417 }
10418
10420 return map;
10421}
10422
10427
10432
10433/* Align the divs of the basic maps in "map" to those
10434 * of the basic maps in "list", as well as to the other basic maps in "map".
10435 * The elements in "list" are assumed to have known divs.
10436 */
10438 __isl_take isl_map *map, __isl_keep isl_basic_map_list *list)
10439{
10440 int i;
10441 isl_size n;
10442
10443 n = isl_basic_map_list_n_basic_map(list);
10445 map = isl_map_cow(map);
10446 if (!map || n < 0)
10447 return isl_map_free(map);
10448 if (map->n == 0)
10449 return map;
10450
10451 for (i = 0; i < n; ++i) {
10452 isl_basic_map *bmap;
10453
10454 bmap = isl_basic_map_list_get_basic_map(list, i);
10455 bmap = isl_basic_map_order_divs(bmap);
10456 map->p[0] = isl_basic_map_align_divs(map->p[0], bmap);
10457 isl_basic_map_free(bmap);
10458 }
10459 if (!map->p[0])
10460 return isl_map_free(map);
10461
10463}
10464
10465/* Align the divs of each element of "list" to those of "bmap".
10466 * Both "bmap" and the elements of "list" are assumed to have known divs.
10467 */
10469 __isl_take isl_basic_map_list *list, __isl_keep isl_basic_map *bmap)
10470{
10471 int i;
10472 isl_size n;
10473
10474 n = isl_basic_map_list_n_basic_map(list);
10475 if (n < 0 || !bmap)
10476 return isl_basic_map_list_free(list);
10477
10478 for (i = 0; i < n; ++i) {
10479 isl_basic_map *bmap_i;
10480
10481 bmap_i = isl_basic_map_list_get_basic_map(list, i);
10482 bmap_i = isl_basic_map_align_divs(bmap_i, bmap);
10483 list = isl_basic_map_list_set_basic_map(list, i, bmap_i);
10484 }
10485
10486 return list;
10487}
10488
10491{
10492 isl_bool ok;
10493
10496 if (ok < 0)
10497 goto error;
10498 if (!ok)
10500 "incompatible spaces", goto error);
10503 return set;
10504error:
10507 return NULL;
10508}
10509
10510/* There is no need to cow as removing empty parts doesn't change
10511 * the meaning of the set.
10512 */
10514{
10515 int i;
10516
10517 if (!map)
10518 return NULL;
10519
10520 for (i = map->n - 1; i >= 0; --i)
10521 map = remove_if_empty(map, i);
10522
10523 return map;
10524}
10525
10530
10531/* Create a binary relation that maps the shared initial "pos" dimensions
10532 * of "bset1" and "bset2" to the remaining dimensions of "bset1" and "bset2".
10533 */
10535 __isl_keep isl_basic_set *bset2, int pos)
10536{
10537 isl_basic_map *bmap1;
10538 isl_basic_map *bmap2;
10539
10542 bmap1 = isl_basic_map_move_dims(bmap1, isl_dim_in, 0,
10543 isl_dim_out, 0, pos);
10544 bmap2 = isl_basic_map_move_dims(bmap2, isl_dim_in, 0,
10545 isl_dim_out, 0, pos);
10546 return isl_basic_map_range_product(bmap1, bmap2);
10547}
10548
10549/* Given two basic sets bset1 and bset2, compute the maximal difference
10550 * between the values of dimension pos in bset1 and those in bset2
10551 * for any common value of the parameters and dimensions preceding pos.
10552 */
10555 int pos, isl_int *opt)
10556{
10557 isl_basic_map *bmap1;
10558 struct isl_ctx *ctx;
10559 struct isl_vec *obj;
10561 isl_size nparam;
10562 isl_size dim1;
10563 enum isl_lp_result res;
10564
10565 nparam = isl_basic_set_dim(bset1, isl_dim_param);
10566 dim1 = isl_basic_set_dim(bset1, isl_dim_set);
10567 if (nparam < 0 || dim1 < 0 || !bset2)
10568 return isl_lp_error;
10569
10570 bmap1 = join_initial(bset1, bset2, pos);
10572 if (total < 0)
10573 return isl_lp_error;
10574
10575 ctx = bmap1->ctx;
10576 obj = isl_vec_alloc(ctx, 1 + total);
10577 if (!obj)
10578 goto error;
10579 isl_seq_clr(obj->block.data, 1 + total);
10580 isl_int_set_si(obj->block.data[1+nparam+pos], 1);
10581 isl_int_set_si(obj->block.data[1+nparam+pos+(dim1-pos)], -1);
10582 res = isl_basic_map_solve_lp(bmap1, 1, obj->block.data, ctx->one,
10583 opt, NULL, NULL);
10584 isl_basic_map_free(bmap1);
10586 return res;
10587error:
10588 isl_basic_map_free(bmap1);
10589 return isl_lp_error;
10590}
10591
10592/* Given two _disjoint_ basic sets bset1 and bset2, check whether
10593 * for any common value of the parameters and dimensions preceding pos
10594 * in both basic sets, the values of dimension pos in bset1 are
10595 * smaller or larger than those in bset2.
10596 *
10597 * Returns
10598 * 1 if bset1 follows bset2
10599 * -1 if bset1 precedes bset2
10600 * 0 if bset1 and bset2 are incomparable
10601 * -2 if some error occurred.
10602 */
10604 __isl_keep isl_basic_set *bset2, int pos)
10605{
10606 isl_int opt;
10607 enum isl_lp_result res;
10608 int cmp;
10609
10610 isl_int_init(opt);
10611
10612 res = basic_set_maximal_difference_at(bset1, bset2, pos, &opt);
10613
10614 if (res == isl_lp_empty)
10615 cmp = 0;
10616 else if ((res == isl_lp_ok && isl_int_is_pos(opt)) ||
10618 cmp = 1;
10619 else if (res == isl_lp_ok && isl_int_is_neg(opt))
10620 cmp = -1;
10621 else
10622 cmp = -2;
10623
10624 isl_int_clear(opt);
10625 return cmp;
10626}
10627
10628/* Given two basic sets bset1 and bset2, check whether
10629 * for any common value of the parameters and dimensions preceding pos
10630 * there is a value of dimension pos in bset1 that is larger
10631 * than a value of the same dimension in bset2.
10632 *
10633 * Return
10634 * 1 if there exists such a pair
10635 * 0 if there is no such pair, but there is a pair of equal values
10636 * -1 otherwise
10637 * -2 if some error occurred.
10638 */
10640 __isl_keep isl_basic_set *bset2, int pos)
10641{
10642 isl_bool empty;
10643 isl_basic_map *bmap;
10644 isl_size dim1;
10645
10646 dim1 = isl_basic_set_dim(bset1, isl_dim_set);
10647 if (dim1 < 0)
10648 return -2;
10649 bmap = join_initial(bset1, bset2, pos);
10650 bmap = isl_basic_map_order_ge(bmap, isl_dim_out, 0,
10651 isl_dim_out, dim1 - pos);
10652 empty = isl_basic_map_is_empty(bmap);
10653 if (empty < 0)
10654 goto error;
10655 if (empty) {
10656 isl_basic_map_free(bmap);
10657 return -1;
10658 }
10659 bmap = isl_basic_map_order_gt(bmap, isl_dim_out, 0,
10660 isl_dim_out, dim1 - pos);
10661 empty = isl_basic_map_is_empty(bmap);
10662 if (empty < 0)
10663 goto error;
10664 isl_basic_map_free(bmap);
10665 if (empty)
10666 return 0;
10667 return 1;
10668error:
10669 isl_basic_map_free(bmap);
10670 return -2;
10671}
10672
10673/* Given two sets set1 and set2, check whether
10674 * for any common value of the parameters and dimensions preceding pos
10675 * there is a value of dimension pos in set1 that is larger
10676 * than a value of the same dimension in set2.
10677 *
10678 * Return
10679 * 1 if there exists such a pair
10680 * 0 if there is no such pair, but there is a pair of equal values
10681 * -1 otherwise
10682 * -2 if some error occurred.
10683 */
10685 __isl_keep isl_set *set2, int pos)
10686{
10687 int i, j;
10688 int follows = -1;
10689
10690 if (!set1 || !set2)
10691 return -2;
10692
10693 for (i = 0; i < set1->n; ++i)
10694 for (j = 0; j < set2->n; ++j) {
10695 int f;
10696 f = isl_basic_set_follows_at(set1->p[i], set2->p[j], pos);
10697 if (f == 1 || f == -2)
10698 return f;
10699 if (f > follows)
10700 follows = f;
10701 }
10702
10703 return follows;
10704}
10705
10707 __isl_keep isl_basic_map *bmap, unsigned pos, isl_int *val)
10708{
10709 int i;
10710 int d;
10712
10714 if (total < 0)
10715 return isl_bool_error;
10716 for (i = 0, d = total-1; i < bmap->n_eq && d+1 > pos; ++i) {
10717 for (; d+1 > pos; --d)
10718 if (!isl_int_is_zero(bmap->eq[i][1+d]))
10719 break;
10720 if (d != pos)
10721 continue;
10722 if (isl_seq_any_non_zero(bmap->eq[i]+1, d))
10723 return isl_bool_false;
10724 if (isl_seq_any_non_zero(bmap->eq[i]+1+d+1, total-d-1))
10725 return isl_bool_false;
10726 if (!isl_int_is_one(bmap->eq[i][1+d]))
10727 return isl_bool_false;
10728 if (val)
10729 isl_int_neg(*val, bmap->eq[i][0]);
10730 return isl_bool_true;
10731 }
10732 return isl_bool_false;
10733}
10734
10736 unsigned pos, isl_int *val)
10737{
10738 int i;
10739 isl_int v;
10740 isl_int tmp;
10741 isl_bool fixed;
10742
10743 if (!map)
10744 return isl_bool_error;
10745 if (map->n == 0)
10746 return isl_bool_false;
10747 if (map->n == 1)
10749 isl_int_init(v);
10750 isl_int_init(tmp);
10751 fixed = isl_basic_map_plain_has_fixed_var(map->p[0], pos, &v);
10752 for (i = 1; fixed == isl_bool_true && i < map->n; ++i) {
10753 fixed = isl_basic_map_plain_has_fixed_var(map->p[i], pos, &tmp);
10754 if (fixed == isl_bool_true && isl_int_ne(tmp, v))
10755 fixed = isl_bool_false;
10756 }
10757 if (val)
10758 isl_int_set(*val, v);
10759 isl_int_clear(tmp);
10760 isl_int_clear(v);
10761 return fixed;
10762}
10763
10770
10772 enum isl_dim_type type, unsigned pos, isl_int *val)
10773{
10774 if (isl_basic_map_check_range(bmap, type, pos, 1) < 0)
10775 return isl_bool_error;
10777 isl_basic_map_offset(bmap, type) - 1 + pos, val);
10778}
10779
10780/* If "bmap" obviously lies on a hyperplane where the given dimension
10781 * has a fixed value, then return that value.
10782 * Otherwise return NaN.
10783 */
10786 enum isl_dim_type type, unsigned pos)
10787{
10788 isl_ctx *ctx;
10789 isl_val *v;
10790 isl_bool fixed;
10791
10792 if (!bmap)
10793 return NULL;
10794 ctx = isl_basic_map_get_ctx(bmap);
10795 v = isl_val_alloc(ctx);
10796 if (!v)
10797 return NULL;
10798 fixed = isl_basic_map_plain_is_fixed(bmap, type, pos, &v->n);
10799 if (fixed < 0)
10800 return isl_val_free(v);
10801 if (fixed) {
10802 isl_int_set_si(v->d, 1);
10803 return v;
10804 }
10805 isl_val_free(v);
10806 return isl_val_nan(ctx);
10807}
10808
10810 enum isl_dim_type type, unsigned pos, isl_int *val)
10811{
10812 if (isl_map_check_range(map, type, pos, 1) < 0)
10813 return isl_bool_error;
10815 map_offset(map, type) - 1 + pos, val);
10816}
10817
10818/* If "map" obviously lies on a hyperplane where the given dimension
10819 * has a fixed value, then return that value.
10820 * Otherwise return NaN.
10821 */
10823 enum isl_dim_type type, unsigned pos)
10824{
10825 isl_ctx *ctx;
10826 isl_val *v;
10827 isl_bool fixed;
10828
10829 if (!map)
10830 return NULL;
10832 v = isl_val_alloc(ctx);
10833 if (!v)
10834 return NULL;
10835 fixed = isl_map_plain_is_fixed(map, type, pos, &v->n);
10836 if (fixed < 0)
10837 return isl_val_free(v);
10838 if (fixed) {
10839 isl_int_set_si(v->d, 1);
10840 return v;
10841 }
10842 isl_val_free(v);
10843 return isl_val_nan(ctx);
10844}
10845
10846/* If "set" obviously lies on a hyperplane where the given dimension
10847 * has a fixed value, then return that value.
10848 * Otherwise return NaN.
10849 */
10855
10856/* Return a sequence of values in the same space as "set"
10857 * that are equal to the corresponding set dimensions of "set"
10858 * for those set dimensions that obviously lie on a hyperplane
10859 * where the dimension has a fixed value.
10860 * The other elements are set to NaN.
10861 */
10864{
10865 int i;
10866 isl_size n;
10867 isl_space *space;
10868 isl_multi_val *mv;
10869
10871 mv = isl_multi_val_alloc(space);
10872 n = isl_multi_val_size(mv);
10873 if (n < 0)
10874 return isl_multi_val_free(mv);
10875
10876 for (i = 0; i < n; ++i) {
10877 isl_val *v;
10878
10880 mv = isl_multi_val_set_val(mv, i, v);
10881 }
10882
10883 return mv;
10884}
10885
10886/* Check if dimension dim has fixed value and if so and if val is not NULL,
10887 * then return this fixed value in *val.
10888 */
10890 unsigned dim, isl_int *val)
10891{
10892 isl_size nparam;
10893
10894 nparam = isl_basic_set_dim(bset, isl_dim_param);
10895 if (nparam < 0)
10896 return isl_bool_error;
10897 return isl_basic_set_plain_has_fixed_var(bset, nparam + dim, val);
10898}
10899
10900/* Return -1 if the constraint "c1" should be sorted before "c2"
10901 * and 1 if it should be sorted after "c2".
10902 * Return 0 if the two constraints are the same (up to the constant term).
10903 *
10904 * In particular, if a constraint involves later variables than another
10905 * then it is sorted after this other constraint.
10906 * uset_gist depends on constraints without existentially quantified
10907 * variables sorting first.
10908 *
10909 * For constraints that have the same latest variable, those
10910 * with the same coefficient for this latest variable (first in absolute value
10911 * and then in actual value) are grouped together.
10912 * This is useful for detecting pairs of constraints that can
10913 * be chained in their printed representation.
10914 *
10915 * Finally, within a group, constraints are sorted according to
10916 * their coefficients (excluding the constant term).
10917 */
10918static int sort_constraint_cmp(const void *p1, const void *p2, void *arg)
10919{
10920 isl_int **c1 = (isl_int **) p1;
10921 isl_int **c2 = (isl_int **) p2;
10922 int l1, l2;
10923 unsigned size = *(unsigned *) arg;
10924 int cmp;
10925
10926 l1 = isl_seq_last_non_zero(*c1 + 1, size);
10927 l2 = isl_seq_last_non_zero(*c2 + 1, size);
10928
10929 if (l1 != l2)
10930 return l1 - l2;
10931
10932 cmp = isl_int_abs_cmp((*c1)[1 + l1], (*c2)[1 + l1]);
10933 if (cmp != 0)
10934 return cmp;
10935 cmp = isl_int_cmp((*c1)[1 + l1], (*c2)[1 + l1]);
10936 if (cmp != 0)
10937 return -cmp;
10938
10939 return isl_seq_cmp(*c1 + 1, *c2 + 1, size);
10940}
10941
10942/* Return -1 if the constraint "c1" of "bmap" is sorted before "c2"
10943 * by isl_basic_map_sort_constraints, 1 if it is sorted after "c2"
10944 * and 0 if the two constraints are the same (up to the constant term).
10945 */
10947 isl_int *c1, isl_int *c2)
10948{
10950 unsigned size;
10951
10953 if (total < 0)
10954 return -2;
10955 size = total;
10956 return sort_constraint_cmp(&c1, &c2, &size);
10957}
10958
10961{
10963 unsigned size;
10964
10965 if (!bmap)
10966 return NULL;
10967 if (bmap->n_ineq == 0)
10968 return bmap;
10970 return bmap;
10972 if (total < 0)
10973 return isl_basic_map_free(bmap);
10974 size = total;
10975 if (isl_sort(bmap->ineq, bmap->n_ineq, sizeof(isl_int *),
10976 &sort_constraint_cmp, &size) < 0)
10977 return isl_basic_map_free(bmap);
10979 return bmap;
10980}
10981
10988
10991{
10993 bmap = isl_basic_map_sort_constraints(bmap);
10994 return bmap;
10995}
10998{
10999 int i, cmp;
11001 isl_space *space1, *space2;
11002
11003 if (!bmap1 || !bmap2)
11004 return -1;
11005
11006 if (bmap1 == bmap2)
11007 return 0;
11008 space1 = isl_basic_map_peek_space(bmap1);
11009 space2 = isl_basic_map_peek_space(bmap2);
11010 cmp = isl_space_cmp(space1, space2);
11011 if (cmp)
11012 return cmp;
11013 if (ISL_F_ISSET(bmap1, ISL_BASIC_MAP_RATIONAL) !=
11015 return ISL_F_ISSET(bmap1, ISL_BASIC_MAP_RATIONAL) ? -1 : 1;
11016 if (ISL_F_ISSET(bmap1, ISL_BASIC_MAP_EMPTY) &&
11018 return 0;
11019 if (ISL_F_ISSET(bmap1, ISL_BASIC_MAP_EMPTY))
11020 return 1;
11021 if (ISL_F_ISSET(bmap2, ISL_BASIC_MAP_EMPTY))
11022 return -1;
11023 if (bmap1->n_eq != bmap2->n_eq)
11024 return bmap1->n_eq - bmap2->n_eq;
11025 if (bmap1->n_ineq != bmap2->n_ineq)
11026 return bmap1->n_ineq - bmap2->n_ineq;
11027 if (bmap1->n_div != bmap2->n_div)
11028 return bmap1->n_div - bmap2->n_div;
11030 if (total < 0)
11031 return -1;
11032 for (i = 0; i < bmap1->n_eq; ++i) {
11033 cmp = isl_seq_cmp(bmap1->eq[i], bmap2->eq[i], 1+total);
11034 if (cmp)
11035 return cmp;
11036 }
11037 for (i = 0; i < bmap1->n_ineq; ++i) {
11038 cmp = isl_seq_cmp(bmap1->ineq[i], bmap2->ineq[i], 1+total);
11039 if (cmp)
11040 return cmp;
11041 }
11042 for (i = 0; i < bmap1->n_div; ++i) {
11043 isl_bool unknown1, unknown2;
11044
11045 unknown1 = isl_basic_map_div_is_marked_unknown(bmap1, i);
11046 unknown2 = isl_basic_map_div_is_marked_unknown(bmap2, i);
11047 if (unknown1 < 0 || unknown2 < 0)
11048 return -1;
11049 if (unknown1 && unknown2)
11050 continue;
11051 if (unknown1)
11052 return 1;
11053 if (unknown2)
11054 return -1;
11055 cmp = isl_seq_cmp(bmap1->div[i], bmap2->div[i], 1+1+total);
11056 if (cmp)
11057 return cmp;
11058 }
11059 return 0;
11060}
11061
11064{
11065 return isl_basic_map_plain_cmp(bset1, bset2);
11066}
11067
11069{
11070 int i, cmp;
11071
11072 if (set1 == set2)
11073 return 0;
11074 if (set1->n != set2->n)
11075 return set1->n - set2->n;
11076
11077 for (i = 0; i < set1->n; ++i) {
11078 cmp = isl_basic_set_plain_cmp(set1->p[i], set2->p[i]);
11079 if (cmp)
11080 return cmp;
11081 }
11082
11083 return 0;
11084}
11085
11088{
11089 if (!bmap1 || !bmap2)
11090 return isl_bool_error;
11091 return isl_basic_map_plain_cmp(bmap1, bmap2) == 0;
11092}
11093
11100
11101static int qsort_bmap_cmp(const void *p1, const void *p2)
11102{
11103 isl_basic_map *bmap1 = *(isl_basic_map **) p1;
11104 isl_basic_map *bmap2 = *(isl_basic_map **) p2;
11105
11106 return isl_basic_map_plain_cmp(bmap1, bmap2);
11107}
11108
11109/* Sort the basic maps of "map" and remove duplicate basic maps.
11110 *
11111 * While removing basic maps, we make sure that the basic maps remain
11112 * sorted because isl_map_normalize expects the basic maps of the result
11113 * to be sorted.
11114 */
11116{
11117 int i, j;
11118
11120 if (!map)
11121 return NULL;
11122 qsort(map->p, map->n, sizeof(struct isl_basic_map *), qsort_bmap_cmp);
11123 for (i = map->n - 1; i >= 1; --i) {
11124 if (!isl_basic_map_plain_is_equal(map->p[i - 1], map->p[i]))
11125 continue;
11126 isl_basic_map_free(map->p[i-1]);
11127 for (j = i; j < map->n; ++j)
11128 map->p[j - 1] = map->p[j];
11129 map->n--;
11130 }
11131
11132 return map;
11133}
11134
11135/* Remove obvious duplicates among the basic maps of "map".
11136 *
11137 * Unlike isl_map_normalize, this function does not remove redundant
11138 * constraints and only removes duplicates that have exactly the same
11139 * constraints in the input. It does sort the constraints and
11140 * the basic maps to ease the detection of duplicates.
11141 *
11142 * If "map" has already been normalized or if the basic maps are
11143 * disjoint, then there can be no duplicates.
11144 */
11146{
11147 int i;
11148 isl_basic_map *bmap;
11149
11150 if (!map)
11151 return NULL;
11152 if (map->n <= 1)
11153 return map;
11155 return map;
11156 for (i = 0; i < map->n; ++i) {
11157 bmap = isl_basic_map_copy(map->p[i]);
11158 bmap = isl_basic_map_sort_constraints(bmap);
11159 if (!bmap)
11160 return isl_map_free(map);
11161 isl_basic_map_free(map->p[i]);
11162 map->p[i] = bmap;
11163 }
11164
11166 return map;
11167}
11168
11169/* We normalize in place, but if anything goes wrong we need
11170 * to return NULL, so we need to make sure we don't change the
11171 * meaning of any possible other copies of map.
11172 */
11174{
11175 int i;
11176 struct isl_basic_map *bmap;
11177
11178 if (!map)
11179 return NULL;
11181 return map;
11182 for (i = 0; i < map->n; ++i) {
11184 if (!bmap)
11185 goto error;
11186 isl_basic_map_free(map->p[i]);
11187 map->p[i] = bmap;
11188 }
11189
11191 if (map)
11193 return map;
11194error:
11196 return NULL;
11197}
11198
11203
11206{
11207 int i;
11209
11210 if (!map1 || !map2)
11211 return isl_bool_error;
11212
11213 if (map1 == map2)
11214 return isl_bool_true;
11216 if (equal < 0 || !equal)
11217 return equal;
11218
11223 if (!map1 || !map2)
11224 goto error;
11225 equal = map1->n == map2->n;
11226 for (i = 0; equal && i < map1->n; ++i) {
11228 if (equal < 0)
11229 goto error;
11230 }
11233 return equal;
11234error:
11237 return isl_bool_error;
11238}
11239
11245
11246/* Return the basic maps in "map" as a list.
11247 */
11250{
11251 int i;
11252 isl_ctx *ctx;
11253 isl_basic_map_list *list;
11254
11255 if (!map)
11256 return NULL;
11258 list = isl_basic_map_list_alloc(ctx, map->n);
11259
11260 for (i = 0; i < map->n; ++i) {
11261 isl_basic_map *bmap;
11262
11263 bmap = isl_basic_map_copy(map->p[i]);
11264 list = isl_basic_map_list_add(list, bmap);
11265 }
11266
11267 return list;
11268}
11269
11270/* Return the intersection of the elements in the non-empty list "list".
11271 * All elements are assumed to live in the same space.
11272 */
11274 __isl_take isl_basic_map_list *list)
11275{
11276 int i;
11277 isl_size n;
11278 isl_basic_map *bmap;
11279
11280 n = isl_basic_map_list_n_basic_map(list);
11281 if (n < 0)
11282 goto error;
11283 if (n < 1)
11284 isl_die(isl_basic_map_list_get_ctx(list), isl_error_invalid,
11285 "expecting non-empty list", goto error);
11286
11287 bmap = isl_basic_map_list_get_basic_map(list, 0);
11288 for (i = 1; i < n; ++i) {
11289 isl_basic_map *bmap_i;
11290
11291 bmap_i = isl_basic_map_list_get_basic_map(list, i);
11292 bmap = isl_basic_map_intersect(bmap, bmap_i);
11293 }
11294
11295 isl_basic_map_list_free(list);
11296 return bmap;
11297error:
11298 isl_basic_map_list_free(list);
11299 return NULL;
11300}
11301
11302/* Return the intersection of the elements in the non-empty list "list".
11303 * All elements are assumed to live in the same space.
11304 */
11310
11311/* Return the union of the elements of "list".
11312 * The list is required to have at least one element.
11313 */
11316{
11317 int i;
11318 isl_size n;
11319 isl_space *space;
11320 isl_basic_set *bset;
11321 isl_set *set;
11322
11323 n = isl_basic_set_list_n_basic_set(list);
11324 if (n < 0)
11325 goto error;
11326 if (n < 1)
11327 isl_die(isl_basic_set_list_get_ctx(list), isl_error_invalid,
11328 "expecting non-empty list", goto error);
11329
11330 bset = isl_basic_set_list_get_basic_set(list, 0);
11331 space = isl_basic_set_get_space(bset);
11332 isl_basic_set_free(bset);
11333
11334 set = isl_set_alloc_space(space, n, 0);
11335 for (i = 0; i < n; ++i) {
11336 bset = isl_basic_set_list_get_basic_set(list, i);
11337 set = isl_set_add_basic_set(set, bset);
11338 }
11339
11340 isl_basic_set_list_free(list);
11341 return set;
11342error:
11343 isl_basic_set_list_free(list);
11344 return NULL;
11345}
11346
11347/* Return the union of the elements in the non-empty list "list".
11348 * All elements are assumed to live in the same space.
11349 */
11351{
11352 int i;
11353 isl_size n;
11354 isl_set *set;
11355
11356 n = isl_set_list_n_set(list);
11357 if (n < 0)
11358 goto error;
11359 if (n < 1)
11360 isl_die(isl_set_list_get_ctx(list), isl_error_invalid,
11361 "expecting non-empty list", goto error);
11362
11363 set = isl_set_list_get_set(list, 0);
11364 for (i = 1; i < n; ++i) {
11365 isl_set *set_i;
11366
11367 set_i = isl_set_list_get_set(list, i);
11368 set = isl_set_union(set, set_i);
11369 }
11370
11371 isl_set_list_free(list);
11372 return set;
11373error:
11374 isl_set_list_free(list);
11375 return NULL;
11376}
11377
11380{
11381 isl_space *space_result = NULL;
11382 struct isl_basic_map *bmap;
11383 unsigned in1, in2, out1, out2, nparam, total, pos;
11384 struct isl_dim_map *dim_map1, *dim_map2;
11385
11386 if (isl_basic_map_check_equal_params(bmap1, bmap2) < 0)
11387 goto error;
11388 space_result = isl_space_product(isl_space_copy(bmap1->dim),
11389 isl_space_copy(bmap2->dim));
11390
11391 in1 = isl_basic_map_dim(bmap1, isl_dim_in);
11392 in2 = isl_basic_map_dim(bmap2, isl_dim_in);
11393 out1 = isl_basic_map_dim(bmap1, isl_dim_out);
11394 out2 = isl_basic_map_dim(bmap2, isl_dim_out);
11395 nparam = isl_basic_map_dim(bmap1, isl_dim_param);
11396
11397 total = nparam + in1 + in2 + out1 + out2 + bmap1->n_div + bmap2->n_div;
11398 dim_map1 = isl_dim_map_alloc(bmap1->ctx, total);
11399 dim_map2 = isl_dim_map_alloc(bmap1->ctx, total);
11400 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_param, pos = 0);
11401 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_param, pos = 0);
11402 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_in, pos += nparam);
11403 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_in, pos += in1);
11404 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += in2);
11405 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_out, pos += out1);
11406 isl_dim_map_div(dim_map1, bmap1, pos += out2);
11407 isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div);
11408
11409 bmap = isl_basic_map_alloc_space(space_result,
11410 bmap1->n_div + bmap2->n_div,
11411 bmap1->n_eq + bmap2->n_eq,
11412 bmap1->n_ineq + bmap2->n_ineq);
11413 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap1, dim_map1);
11414 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap2, dim_map2);
11415 bmap = isl_basic_map_simplify(bmap);
11416 return isl_basic_map_finalize(bmap);
11417error:
11418 isl_basic_map_free(bmap1);
11419 isl_basic_map_free(bmap2);
11420 return NULL;
11421}
11422
11425{
11426 isl_basic_map *prod;
11427
11428 prod = isl_basic_map_product(bmap1, bmap2);
11429 prod = isl_basic_map_flatten(prod);
11430 return prod;
11431}
11432
11438
11441{
11442 isl_space *space1, *space2;
11443 isl_space *space_result = NULL;
11444 isl_basic_map *bmap;
11445 isl_size in1, in2, out, nparam;
11446 unsigned total, pos;
11447 struct isl_dim_map *dim_map1, *dim_map2;
11448
11449 in1 = isl_basic_map_dim(bmap1, isl_dim_in);
11450 in2 = isl_basic_map_dim(bmap2, isl_dim_in);
11451 out = isl_basic_map_dim(bmap1, isl_dim_out);
11452 nparam = isl_basic_map_dim(bmap1, isl_dim_param);
11453 if (in1 < 0 || in2 < 0 || out < 0 || nparam < 0)
11454 goto error;
11455
11456 space1 = isl_basic_map_get_space(bmap1);
11457 space2 = isl_basic_map_get_space(bmap2);
11458 space_result = isl_space_domain_product(space1, space2);
11459
11460 total = nparam + in1 + in2 + out + bmap1->n_div + bmap2->n_div;
11461 dim_map1 = isl_dim_map_alloc(bmap1->ctx, total);
11462 dim_map2 = isl_dim_map_alloc(bmap1->ctx, total);
11463 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_param, pos = 0);
11464 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_param, pos = 0);
11465 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_in, pos += nparam);
11466 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_in, pos += in1);
11467 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += in2);
11468 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_out, pos);
11469 isl_dim_map_div(dim_map1, bmap1, pos += out);
11470 isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div);
11471
11472 bmap = isl_basic_map_alloc_space(space_result,
11473 bmap1->n_div + bmap2->n_div,
11474 bmap1->n_eq + bmap2->n_eq,
11475 bmap1->n_ineq + bmap2->n_ineq);
11476 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap1, dim_map1);
11477 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap2, dim_map2);
11478 bmap = isl_basic_map_simplify(bmap);
11479 return isl_basic_map_finalize(bmap);
11480error:
11481 isl_basic_map_free(bmap1);
11482 isl_basic_map_free(bmap2);
11483 return NULL;
11484}
11485
11488{
11489 isl_bool rational;
11490 isl_space *space_result = NULL;
11491 isl_basic_map *bmap;
11492 isl_size in, out1, out2, nparam;
11493 unsigned total, pos;
11494 struct isl_dim_map *dim_map1, *dim_map2;
11495
11496 rational = isl_basic_map_is_rational(bmap1);
11497 if (rational >= 0 && rational)
11498 rational = isl_basic_map_is_rational(bmap2);
11499 in = isl_basic_map_dim(bmap1, isl_dim_in);
11500 out1 = isl_basic_map_dim(bmap1, isl_dim_out);
11501 out2 = isl_basic_map_dim(bmap2, isl_dim_out);
11502 nparam = isl_basic_map_dim(bmap1, isl_dim_param);
11503 if (in < 0 || out1 < 0 || out2 < 0 || nparam < 0 || rational < 0)
11504 goto error;
11505
11506 if (isl_basic_map_check_equal_params(bmap1, bmap2) < 0)
11507 goto error;
11508
11509 space_result = isl_space_range_product(isl_space_copy(bmap1->dim),
11510 isl_space_copy(bmap2->dim));
11511
11512 total = nparam + in + out1 + out2 + bmap1->n_div + bmap2->n_div;
11513 dim_map1 = isl_dim_map_alloc(bmap1->ctx, total);
11514 dim_map2 = isl_dim_map_alloc(bmap1->ctx, total);
11515 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_param, pos = 0);
11516 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_param, pos = 0);
11517 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_in, pos += nparam);
11518 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_in, pos);
11519 isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += in);
11520 isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_out, pos += out1);
11521 isl_dim_map_div(dim_map1, bmap1, pos += out2);
11522 isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div);
11523
11524 bmap = isl_basic_map_alloc_space(space_result,
11525 bmap1->n_div + bmap2->n_div,
11526 bmap1->n_eq + bmap2->n_eq,
11527 bmap1->n_ineq + bmap2->n_ineq);
11528 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap1, dim_map1);
11529 bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap2, dim_map2);
11530 if (rational)
11531 bmap = isl_basic_map_set_rational(bmap);
11532 bmap = isl_basic_map_simplify(bmap);
11533 return isl_basic_map_finalize(bmap);
11534error:
11535 isl_basic_map_free(bmap1);
11536 isl_basic_map_free(bmap2);
11537 return NULL;
11538}
11539
11542{
11543 isl_basic_map *prod;
11544
11545 prod = isl_basic_map_range_product(bmap1, bmap2);
11546 prod = isl_basic_map_flatten_range(prod);
11547 return prod;
11548}
11549
11550/* Apply "basic_map_product" to each pair of basic maps in "map1" and "map2"
11551 * and collect the results.
11552 * The result live in the space obtained by calling "space_product"
11553 * on the spaces of "map1" and "map2".
11554 * If "remove_duplicates" is set then the result may contain duplicates
11555 * (even if the inputs do not) and so we try and remove the obvious
11556 * duplicates.
11557 */
11560 __isl_give isl_space *(*space_product)(__isl_take isl_space *left,
11561 __isl_take isl_space *right),
11562 __isl_give isl_basic_map *(*basic_map_product)(
11564 __isl_take isl_basic_map *right),
11565 int remove_duplicates)
11566{
11567 unsigned flags = 0;
11568 struct isl_map *result;
11569 int i, j;
11570 isl_bool m;
11571
11573 if (m < 0)
11574 goto error;
11575 if (!m)
11577 "parameters don't match", goto error);
11578
11582
11583 result = isl_map_alloc_space(space_product(isl_space_copy(map1->dim),
11584 isl_space_copy(map2->dim)),
11585 map1->n * map2->n, flags);
11586 if (!result)
11587 goto error;
11588 for (i = 0; i < map1->n; ++i)
11589 for (j = 0; j < map2->n; ++j) {
11590 struct isl_basic_map *part;
11591 part = basic_map_product(isl_basic_map_copy(map1->p[i]),
11592 isl_basic_map_copy(map2->p[j]));
11593 if (isl_basic_map_is_empty(part))
11594 isl_basic_map_free(part);
11595 else
11596 result = isl_map_add_basic_map(result, part);
11597 if (!result)
11598 goto error;
11599 }
11600 if (remove_duplicates)
11601 result = isl_map_remove_obvious_duplicates(result);
11604 return result;
11605error:
11608 return NULL;
11609}
11610
11611/* Given two maps A -> B and C -> D, construct a map [A -> C] -> [B -> D]
11612 */
11620
11621/* Given two maps A -> B and C -> D, construct a map (A, C) -> (B, D)
11622 */
11625{
11626 isl_map *prod;
11627
11628 prod = isl_map_product(map1, map2);
11629 prod = isl_map_flatten(prod);
11630 return prod;
11631}
11632
11633/* Given two set A and B, construct its Cartesian product A x B.
11634 */
11640
11646
11647/* Given two maps A -> B and C -> D, construct a map [A -> C] -> (B * D)
11648 */
11656
11657/* Given two maps A -> B and C -> D, construct a map (A * C) -> [B -> D]
11658 */
11666
11667/* Given a map of the form [A -> B] -> [C -> D], return the map A -> C.
11668 */
11670{
11671 isl_space *space;
11672 isl_size total1, keep1, total2, keep2;
11673
11674 total1 = isl_map_dim(map, isl_dim_in);
11675 total2 = isl_map_dim(map, isl_dim_out);
11676 if (total1 < 0 || total2 < 0)
11677 return isl_map_free(map);
11678 if (!isl_space_domain_is_wrapping(map->dim) ||
11681 "not a product", return isl_map_free(map));
11682
11683 space = isl_map_get_space(map);
11684 space = isl_space_factor_domain(space);
11685 keep1 = isl_space_dim(space, isl_dim_in);
11686 keep2 = isl_space_dim(space, isl_dim_out);
11687 if (keep1 < 0 || keep2 < 0)
11688 map = isl_map_free(map);
11689 map = isl_map_project_out(map, isl_dim_in, keep1, total1 - keep1);
11690 map = isl_map_project_out(map, isl_dim_out, keep2, total2 - keep2);
11691 map = isl_map_reset_space(map, space);
11692
11693 return map;
11694}
11695
11696/* Given a map of the form [A -> B] -> [C -> D], return the map B -> D.
11697 */
11699{
11700 isl_space *space;
11701 isl_size total1, keep1, total2, keep2;
11702
11703 total1 = isl_map_dim(map, isl_dim_in);
11704 total2 = isl_map_dim(map, isl_dim_out);
11705 if (total1 < 0 || total2 < 0)
11706 return isl_map_free(map);
11707 if (!isl_space_domain_is_wrapping(map->dim) ||
11710 "not a product", return isl_map_free(map));
11711
11712 space = isl_map_get_space(map);
11713 space = isl_space_factor_range(space);
11714 keep1 = isl_space_dim(space, isl_dim_in);
11715 keep2 = isl_space_dim(space, isl_dim_out);
11716 if (keep1 < 0 || keep2 < 0)
11717 map = isl_map_free(map);
11718 map = isl_map_project_out(map, isl_dim_in, 0, total1 - keep1);
11719 map = isl_map_project_out(map, isl_dim_out, 0, total2 - keep2);
11720 map = isl_map_reset_space(map, space);
11721
11722 return map;
11723}
11724
11725/* Given a map of the form [A -> B] -> C, return the map A -> C.
11726 */
11728{
11729 isl_space *space;
11730 isl_size total, keep;
11731
11733 if (total < 0)
11734 return isl_map_free(map);
11737 "domain is not a product", return isl_map_free(map));
11738
11739 space = isl_map_get_space(map);
11740 space = isl_space_domain_factor_domain(space);
11741 keep = isl_space_dim(space, isl_dim_in);
11742 if (keep < 0)
11743 map = isl_map_free(map);
11744 map = isl_map_project_out(map, isl_dim_in, keep, total - keep);
11745 map = isl_map_reset_space(map, space);
11746
11747 return map;
11748}
11749
11750/* Given a map of the form [A -> B] -> C, return the map B -> C.
11751 */
11753{
11754 isl_space *space;
11755 isl_size total, keep;
11756
11758 if (total < 0)
11759 return isl_map_free(map);
11762 "domain is not a product", return isl_map_free(map));
11763
11764 space = isl_map_get_space(map);
11765 space = isl_space_domain_factor_range(space);
11766 keep = isl_space_dim(space, isl_dim_in);
11767 if (keep < 0)
11768 map = isl_map_free(map);
11770 map = isl_map_reset_space(map, space);
11771
11772 return map;
11773}
11774
11775/* Given a map A -> [B -> C], extract the map A -> B.
11776 */
11778{
11779 isl_space *space;
11780 isl_size total, keep;
11781
11783 if (total < 0)
11784 return isl_map_free(map);
11787 "range is not a product", return isl_map_free(map));
11788
11789 space = isl_map_get_space(map);
11790 space = isl_space_range_factor_domain(space);
11791 keep = isl_space_dim(space, isl_dim_out);
11792 if (keep < 0)
11793 map = isl_map_free(map);
11794 map = isl_map_project_out(map, isl_dim_out, keep, total - keep);
11795 map = isl_map_reset_space(map, space);
11796
11797 return map;
11798}
11799
11800/* Given a map A -> [B -> C], extract the map A -> C.
11801 */
11803{
11804 isl_space *space;
11805 isl_size total, keep;
11806
11808 if (total < 0)
11809 return isl_map_free(map);
11812 "range is not a product", return isl_map_free(map));
11813
11814 space = isl_map_get_space(map);
11815 space = isl_space_range_factor_range(space);
11816 keep = isl_space_dim(space, isl_dim_out);
11817 if (keep < 0)
11818 map = isl_map_free(map);
11820 map = isl_map_reset_space(map, space);
11821
11822 return map;
11823}
11824
11825/* Given two maps A -> B and C -> D, construct a map (A, C) -> (B * D)
11826 */
11829{
11830 isl_map *prod;
11831
11833 prod = isl_map_flatten_domain(prod);
11834 return prod;
11835}
11836
11837/* Given two maps A -> B and C -> D, construct a map (A * C) -> (B, D)
11838 */
11841{
11842 isl_map *prod;
11843
11845 prod = isl_map_flatten_range(prod);
11846 return prod;
11847}
11848
11850{
11851 int i;
11852 uint32_t hash = isl_hash_init();
11854
11855 if (!bmap)
11856 return 0;
11857 bmap = isl_basic_map_copy(bmap);
11858 bmap = isl_basic_map_normalize(bmap);
11860 if (total < 0)
11861 return 0;
11862 isl_hash_byte(hash, bmap->n_eq & 0xFF);
11863 for (i = 0; i < bmap->n_eq; ++i) {
11864 uint32_t c_hash;
11865 c_hash = isl_seq_get_hash(bmap->eq[i], 1 + total);
11866 isl_hash_hash(hash, c_hash);
11867 }
11868 isl_hash_byte(hash, bmap->n_ineq & 0xFF);
11869 for (i = 0; i < bmap->n_ineq; ++i) {
11870 uint32_t c_hash;
11871 c_hash = isl_seq_get_hash(bmap->ineq[i], 1 + total);
11872 isl_hash_hash(hash, c_hash);
11873 }
11874 isl_hash_byte(hash, bmap->n_div & 0xFF);
11875 for (i = 0; i < bmap->n_div; ++i) {
11876 uint32_t c_hash;
11877 if (isl_int_is_zero(bmap->div[i][0]))
11878 continue;
11879 isl_hash_byte(hash, i & 0xFF);
11880 c_hash = isl_seq_get_hash(bmap->div[i], 1 + 1 + total);
11881 isl_hash_hash(hash, c_hash);
11882 }
11883 isl_basic_map_free(bmap);
11884 return hash;
11885}
11886
11888{
11890}
11891
11893{
11894 int i;
11895 uint32_t hash;
11896
11897 if (!map)
11898 return 0;
11899 map = isl_map_copy(map);
11901 if (!map)
11902 return 0;
11903
11904 hash = isl_hash_init();
11905 for (i = 0; i < map->n; ++i) {
11906 uint32_t bmap_hash;
11907 bmap_hash = isl_basic_map_get_hash(map->p[i]);
11908 isl_hash_hash(hash, bmap_hash);
11909 }
11910
11912
11913 return hash;
11914}
11915
11917{
11919}
11920
11921/* Return the number of basic maps in the (current) representation of "map".
11922 */
11927
11932
11934 isl_stat (*fn)(__isl_take isl_basic_map *bmap, void *user), void *user)
11935{
11936 int i;
11937
11938 if (!map)
11939 return isl_stat_error;
11940
11941 for (i = 0; i < map->n; ++i)
11942 if (fn(isl_basic_map_copy(map->p[i]), user) < 0)
11943 return isl_stat_error;
11944
11945 return isl_stat_ok;
11946}
11947
11949 isl_stat (*fn)(__isl_take isl_basic_set *bset, void *user), void *user)
11950{
11951 int i;
11952
11953 if (!set)
11954 return isl_stat_error;
11955
11956 for (i = 0; i < set->n; ++i)
11957 if (fn(isl_basic_set_copy(set->p[i]), user) < 0)
11958 return isl_stat_error;
11959
11960 return isl_stat_ok;
11961}
11962
11963/* Does "test" succeed on every basic set in "set"?
11964 */
11966 isl_bool (*test)(__isl_keep isl_basic_set *bset, void *user),
11967 void *user)
11968{
11969 int i;
11970
11971 if (!set)
11972 return isl_bool_error;
11973
11974 for (i = 0; i < set->n; ++i) {
11975 isl_bool r;
11976
11977 r = test(set->p[i], user);
11978 if (r < 0 || !r)
11979 return r;
11980 }
11981
11982 return isl_bool_true;
11983}
11984
11985/* Return a list of basic sets, the union of which is equal to "set".
11986 */
11989{
11990 int i;
11991 isl_basic_set_list *list;
11992
11993 if (!set)
11994 return NULL;
11995
11996 list = isl_basic_set_list_alloc(isl_set_get_ctx(set), set->n);
11997 for (i = 0; i < set->n; ++i) {
11998 isl_basic_set *bset;
11999
12000 bset = isl_basic_set_copy(set->p[i]);
12001 list = isl_basic_set_list_add(list, bset);
12002 }
12003
12004 return list;
12005}
12006
12008{
12009 isl_space *space;
12010
12011 if (!bset)
12012 return NULL;
12013
12014 bset = isl_basic_set_cow(bset);
12015 if (!bset)
12016 return NULL;
12017
12018 space = isl_basic_set_get_space(bset);
12019 space = isl_space_lift(space, bset->n_div);
12020 if (!space)
12021 goto error;
12022 isl_space_free(bset->dim);
12023 bset->dim = space;
12024 bset->extra -= bset->n_div;
12025 bset->n_div = 0;
12026
12027 bset = isl_basic_set_finalize(bset);
12028
12029 return bset;
12030error:
12031 isl_basic_set_free(bset);
12032 return NULL;
12033}
12034
12036{
12037 int i;
12038 isl_space *space;
12039 unsigned n_div;
12040
12042
12043 if (!set)
12044 return NULL;
12045
12046 set = isl_set_cow(set);
12047 if (!set)
12048 return NULL;
12049
12050 n_div = set->p[0]->n_div;
12051 space = isl_set_get_space(set);
12052 space = isl_space_lift(space, n_div);
12053 if (!space)
12054 goto error;
12055 isl_space_free(set->dim);
12056 set->dim = space;
12057
12058 for (i = 0; i < set->n; ++i) {
12059 set->p[i] = isl_basic_set_lift(set->p[i]);
12060 if (!set->p[i])
12061 goto error;
12062 }
12063
12064 return set;
12065error:
12067 return NULL;
12068}
12069
12071{
12072 isl_size dim;
12073 int size = 0;
12074
12076 if (dim < 0)
12077 return -1;
12078 size += bset->n_eq * (1 + dim);
12079 size += bset->n_ineq * (1 + dim);
12080 size += bset->n_div * (2 + dim);
12081
12082 return size;
12083}
12084
12086{
12087 int i;
12088 int size = 0;
12089
12090 if (!set)
12091 return -1;
12092
12093 for (i = 0; i < set->n; ++i)
12094 size += isl_basic_set_size(set->p[i]);
12095
12096 return size;
12097}
12098
12099/* Check if there is any lower bound (if lower == 0) and/or upper
12100 * bound (if upper == 0) on the specified dim.
12101 */
12103 enum isl_dim_type type, unsigned pos, int lower, int upper)
12104{
12105 int i;
12106 isl_bool involves;
12107 isl_size off;
12108
12109 if (isl_basic_map_check_range(bmap, type, pos, 1) < 0)
12110 return isl_bool_error;
12111
12112 off = isl_basic_map_var_offset(bmap, type);
12113 if (off < 0)
12114 return isl_bool_error;
12115 involves = isl_basic_map_any_div_involves_vars(bmap, off + pos, 1);
12116 if (involves < 0 || involves)
12117 return involves;
12118
12119 for (i = 0; i < bmap->n_eq; ++i)
12120 if (!isl_int_is_zero(bmap->eq[i][1 + off + pos]))
12121 return isl_bool_true;
12122
12123 for (i = 0; i < bmap->n_ineq; ++i) {
12124 int sgn = isl_int_sgn(bmap->ineq[i][1 + off + pos]);
12125 if (sgn > 0)
12126 lower = 1;
12127 if (sgn < 0)
12128 upper = 1;
12129 }
12130
12131 return lower && upper;
12132}
12133
12135 enum isl_dim_type type, unsigned pos)
12136{
12137 return basic_map_dim_is_bounded(bmap, type, pos, 0, 0);
12138}
12139
12141 enum isl_dim_type type, unsigned pos)
12142{
12143 return basic_map_dim_is_bounded(bmap, type, pos, 0, 1);
12144}
12145
12147 enum isl_dim_type type, unsigned pos)
12148{
12149 return basic_map_dim_is_bounded(bmap, type, pos, 1, 0);
12150}
12151
12153 enum isl_dim_type type, unsigned pos)
12154{
12155 int i;
12156
12157 if (!map)
12158 return isl_bool_error;
12159
12160 for (i = 0; i < map->n; ++i) {
12161 isl_bool bounded;
12162 bounded = isl_basic_map_dim_is_bounded(map->p[i], type, pos);
12163 if (bounded < 0 || !bounded)
12164 return bounded;
12165 }
12166
12167 return isl_bool_true;
12168}
12169
12170/* Return true if the specified dim is involved in both an upper bound
12171 * and a lower bound.
12172 */
12178
12179/* Does "map" have a bound (according to "fn") for any of its basic maps?
12180 */
12182 enum isl_dim_type type, unsigned pos,
12184 enum isl_dim_type type, unsigned pos))
12185{
12186 int i;
12187
12188 if (!map)
12189 return isl_bool_error;
12190
12191 for (i = 0; i < map->n; ++i) {
12192 isl_bool bounded;
12193 bounded = fn(map->p[i], type, pos);
12194 if (bounded < 0 || bounded)
12195 return bounded;
12196 }
12197
12198 return isl_bool_false;
12199}
12200
12201/* Return 1 if the specified dim is involved in any lower bound.
12202 */
12209
12210/* Return 1 if the specified dim is involved in any upper bound.
12211 */
12218
12219/* Does "map" have a bound (according to "fn") for all of its basic maps?
12220 */
12222 enum isl_dim_type type, unsigned pos,
12224 enum isl_dim_type type, unsigned pos))
12225{
12226 int i;
12227
12228 if (!map)
12229 return isl_bool_error;
12230
12231 for (i = 0; i < map->n; ++i) {
12232 isl_bool bounded;
12233 bounded = fn(map->p[i], type, pos);
12234 if (bounded < 0 || !bounded)
12235 return bounded;
12236 }
12237
12238 return isl_bool_true;
12239}
12240
12241/* Return 1 if the specified dim has a lower bound (in each of its basic sets).
12242 */
12248
12249/* Return 1 if the specified dim has an upper bound (in each of its basic sets).
12250 */
12256
12257/* For each of the "n" variables starting at "first", determine
12258 * the sign of the variable and put the results in the first "n"
12259 * elements of the array "signs".
12260 * Sign
12261 * 1 means that the variable is non-negative
12262 * -1 means that the variable is non-positive
12263 * 0 means the variable attains both positive and negative values.
12264 */
12266 unsigned first, unsigned n, int *signs)
12267{
12268 isl_vec *bound = NULL;
12269 struct isl_tab *tab = NULL;
12270 struct isl_tab_undo *snap;
12271 int i;
12273
12275 if (total < 0 || !signs)
12276 return isl_stat_error;
12277
12278 bound = isl_vec_alloc(bset->ctx, 1 + total);
12279 tab = isl_tab_from_basic_set(bset, 0);
12280 if (!bound || !tab)
12281 goto error;
12282
12283 isl_seq_clr(bound->el, bound->size);
12284 isl_int_set_si(bound->el[0], -1);
12285
12286 snap = isl_tab_snap(tab);
12287 for (i = 0; i < n; ++i) {
12288 int empty;
12289
12290 isl_int_set_si(bound->el[1 + first + i], -1);
12291 if (isl_tab_add_ineq(tab, bound->el) < 0)
12292 goto error;
12293 empty = tab->empty;
12294 isl_int_set_si(bound->el[1 + first + i], 0);
12295 if (isl_tab_rollback(tab, snap) < 0)
12296 goto error;
12297
12298 if (empty) {
12299 signs[i] = 1;
12300 continue;
12301 }
12302
12303 isl_int_set_si(bound->el[1 + first + i], 1);
12304 if (isl_tab_add_ineq(tab, bound->el) < 0)
12305 goto error;
12306 empty = tab->empty;
12307 isl_int_set_si(bound->el[1 + first + i], 0);
12308 if (isl_tab_rollback(tab, snap) < 0)
12309 goto error;
12310
12311 signs[i] = empty ? -1 : 0;
12312 }
12313
12314 isl_tab_free(tab);
12316 return isl_stat_ok;
12317error:
12318 isl_tab_free(tab);
12320 return isl_stat_error;
12321}
12322
12324 enum isl_dim_type type, unsigned first, unsigned n, int *signs)
12325{
12326 if (!bset || !signs)
12327 return isl_stat_error;
12328 if (isl_basic_set_check_range(bset, type, first, n) < 0)
12329 return isl_stat_error;
12330
12331 first += pos(bset->dim, type) - 1;
12332 return isl_basic_set_vars_get_sign(bset, first, n, signs);
12333}
12334
12335/* Is it possible for the integer division "div" to depend (possibly
12336 * indirectly) on any output dimensions?
12337 *
12338 * If the div is undefined, then we conservatively assume that it
12339 * may depend on them.
12340 * Otherwise, we check if it actually depends on them or on any integer
12341 * divisions that may depend on them.
12342 */
12344{
12345 int i;
12346 isl_size n_out, n_div;
12347 unsigned o_out, o_div;
12348
12349 if (isl_int_is_zero(bmap->div[div][0]))
12350 return isl_bool_true;
12351
12352 n_out = isl_basic_map_dim(bmap, isl_dim_out);
12353 if (n_out < 0)
12354 return isl_bool_error;
12355 o_out = isl_basic_map_offset(bmap, isl_dim_out);
12356
12357 if (isl_seq_any_non_zero(bmap->div[div] + 1 + o_out, n_out))
12358 return isl_bool_true;
12359
12360 n_div = isl_basic_map_dim(bmap, isl_dim_div);
12361 if (n_div < 0)
12362 return isl_bool_error;
12363 o_div = isl_basic_map_offset(bmap, isl_dim_div);
12364
12365 for (i = 0; i < n_div; ++i) {
12366 isl_bool may_involve;
12367
12368 if (isl_int_is_zero(bmap->div[div][1 + o_div + i]))
12369 continue;
12370 may_involve = div_may_involve_output(bmap, i);
12371 if (may_involve < 0 || may_involve)
12372 return may_involve;
12373 }
12374
12375 return isl_bool_false;
12376}
12377
12378/* Return the first integer division of "bmap" in the range
12379 * [first, first + n[ that may depend on any output dimensions and
12380 * that has a non-zero coefficient in "c" (where the first coefficient
12381 * in "c" corresponds to integer division "first").
12382 */
12384 isl_int *c, int first, int n)
12385{
12386 int k;
12387
12388 if (!bmap)
12389 return -1;
12390
12391 for (k = first; k < first + n; ++k) {
12392 isl_bool may_involve;
12393
12394 if (isl_int_is_zero(c[k]))
12395 continue;
12396 may_involve = div_may_involve_output(bmap, k);
12397 if (may_involve < 0)
12398 return -1;
12399 if (may_involve)
12400 return k;
12401 }
12402
12403 return first + n;
12404}
12405
12406/* Look for a pair of inequality constraints in "bmap" of the form
12407 *
12408 * -l + i >= 0 or i >= l
12409 * and
12410 * n + l - i >= 0 or i <= l + n
12411 *
12412 * with n < "m" and i the output dimension at position "pos".
12413 * (Note that n >= 0 as otherwise the two constraints would conflict.)
12414 * Furthermore, "l" is only allowed to involve parameters, input dimensions
12415 * and earlier output dimensions, as well as integer divisions that do
12416 * not involve any of the output dimensions.
12417 *
12418 * Return the index of the first inequality constraint or bmap->n_ineq
12419 * if no such pair can be found.
12420 */
12422 int pos, isl_int m)
12423{
12424 int i, j;
12425 isl_ctx *ctx;
12427 isl_size n_div, n_out;
12428 unsigned o_div, o_out;
12429 int less;
12430
12432 n_out = isl_basic_map_dim(bmap, isl_dim_out);
12433 n_div = isl_basic_map_dim(bmap, isl_dim_div);
12434 if (total < 0 || n_out < 0 || n_div < 0)
12435 return -1;
12436
12437 ctx = isl_basic_map_get_ctx(bmap);
12438 o_out = isl_basic_map_offset(bmap, isl_dim_out);
12439 o_div = isl_basic_map_offset(bmap, isl_dim_div);
12440 for (i = 0; i < bmap->n_ineq; ++i) {
12441 if (!isl_int_abs_eq(bmap->ineq[i][o_out + pos], ctx->one))
12442 continue;
12443 if (isl_seq_any_non_zero(bmap->ineq[i] + o_out + pos + 1,
12444 n_out - (pos + 1)))
12445 continue;
12446 if (first_div_may_involve_output(bmap, bmap->ineq[i] + o_div,
12447 0, n_div) < n_div)
12448 continue;
12449 for (j = i + 1; j < bmap->n_ineq; ++j) {
12450 if (!isl_int_abs_eq(bmap->ineq[j][o_out + pos],
12451 ctx->one))
12452 continue;
12453 if (!isl_seq_is_neg(bmap->ineq[i] + 1,
12454 bmap->ineq[j] + 1, total))
12455 continue;
12456 break;
12457 }
12458 if (j >= bmap->n_ineq)
12459 continue;
12460 isl_int_add(bmap->ineq[i][0],
12461 bmap->ineq[i][0], bmap->ineq[j][0]);
12462 less = isl_int_abs_lt(bmap->ineq[i][0], m);
12463 isl_int_sub(bmap->ineq[i][0],
12464 bmap->ineq[i][0], bmap->ineq[j][0]);
12465 if (!less)
12466 continue;
12467 if (isl_int_is_one(bmap->ineq[i][o_out + pos]))
12468 return i;
12469 else
12470 return j;
12471 }
12472
12473 return bmap->n_ineq;
12474}
12475
12476/* Return the index of the equality of "bmap" that defines
12477 * the output dimension "pos" in terms of earlier dimensions.
12478 * The equality may also involve integer divisions, as long
12479 * as those integer divisions are defined in terms of
12480 * parameters or input dimensions.
12481 * In this case, *div is set to the number of integer divisions and
12482 * *ineq is set to the number of inequality constraints (provided
12483 * div and ineq are not NULL).
12484 *
12485 * The equality may also involve a single integer division involving
12486 * the output dimensions (typically only output dimension "pos") as
12487 * long as the coefficient of output dimension "pos" is 1 or -1 and
12488 * there is a pair of constraints i >= l and i <= l + n, with i referring
12489 * to output dimension "pos", l an expression involving only earlier
12490 * dimensions and n smaller than the coefficient of the integer division
12491 * in the equality. In this case, the output dimension can be defined
12492 * in terms of a modulo expression that does not involve the integer division.
12493 * *div is then set to this single integer division and
12494 * *ineq is set to the index of constraint i >= l.
12495 *
12496 * Return bmap->n_eq if there is no such equality.
12497 * Return -1 on error.
12498 */
12500 int pos, int *div, int *ineq)
12501{
12502 int j, k, l;
12503 isl_size n_div, n_out;
12504 unsigned o_div, o_out;
12505
12506 n_out = isl_basic_map_dim(bmap, isl_dim_out);
12507 n_div = isl_basic_map_dim(bmap, isl_dim_div);
12508 if (n_out < 0 || n_div < 0)
12509 return -1;
12510
12511 o_out = isl_basic_map_offset(bmap, isl_dim_out);
12512 o_div = isl_basic_map_offset(bmap, isl_dim_div);
12513
12514 if (ineq)
12515 *ineq = bmap->n_ineq;
12516 if (div)
12517 *div = n_div;
12518 for (j = 0; j < bmap->n_eq; ++j) {
12519 if (isl_int_is_zero(bmap->eq[j][o_out + pos]))
12520 continue;
12521 if (isl_seq_any_non_zero(bmap->eq[j] + o_out + pos + 1,
12522 n_out - (pos + 1)))
12523 continue;
12524 k = first_div_may_involve_output(bmap, bmap->eq[j] + o_div,
12525 0, n_div);
12526 if (k >= n_div)
12527 return j;
12528 if (!isl_int_is_one(bmap->eq[j][o_out + pos]) &&
12529 !isl_int_is_negone(bmap->eq[j][o_out + pos]))
12530 continue;
12531 if (first_div_may_involve_output(bmap, bmap->eq[j] + o_div,
12532 k + 1, n_div - (k+1)) < n_div)
12533 continue;
12535 bmap->eq[j][o_div + k]);
12536 if (l < 0)
12537 return -1;
12538 if (l >= bmap->n_ineq)
12539 continue;
12540 if (div)
12541 *div = k;
12542 if (ineq)
12543 *ineq = l;
12544 return j;
12545 }
12546
12547 return bmap->n_eq;
12548}
12549
12550/* Check if the given basic map is obviously single-valued.
12551 * In particular, for each output dimension, check that there is
12552 * an equality that defines the output dimension in terms of
12553 * earlier dimensions.
12554 */
12556{
12557 int i;
12558 isl_size n_out;
12559
12560 n_out = isl_basic_map_dim(bmap, isl_dim_out);
12561 if (n_out < 0)
12562 return isl_bool_error;
12563
12564 for (i = 0; i < n_out; ++i) {
12565 int eq;
12566
12568 NULL, NULL);
12569 if (eq < 0)
12570 return isl_bool_error;
12571 if (eq >= bmap->n_eq)
12572 return isl_bool_false;
12573 }
12574
12575 return isl_bool_true;
12576}
12577
12578/* Check if the given basic map is single-valued.
12579 * We simply compute
12580 *
12581 * M \circ M^-1
12582 *
12583 * and check if the result is a subset of the identity mapping.
12584 */
12586{
12587 isl_space *space;
12590 isl_bool sv;
12591
12593 if (sv < 0 || sv)
12594 return sv;
12595
12598
12599 space = isl_basic_map_get_space(bmap);
12601 id = isl_basic_map_identity(space);
12602
12604
12607
12608 return sv;
12609}
12610
12611/* Check if the given map is obviously single-valued.
12612 */
12614{
12615 if (!map)
12616 return isl_bool_error;
12617 if (map->n == 0)
12618 return isl_bool_true;
12619 if (map->n >= 2)
12620 return isl_bool_false;
12621
12623}
12624
12625/* Check if the given map is single-valued.
12626 * We simply compute
12627 *
12628 * M \circ M^-1
12629 *
12630 * and check if the result is a subset of the identity mapping.
12631 */
12633{
12634 isl_space *space;
12635 isl_map *test;
12636 isl_map *id;
12637 isl_bool sv;
12638
12640 if (sv < 0 || sv)
12641 return sv;
12642
12645
12647 id = isl_map_identity(space);
12648
12649 sv = isl_map_is_subset(test, id);
12650
12652 isl_map_free(id);
12653
12654 return sv;
12655}
12656
12658{
12659 isl_bool in;
12660
12661 map = isl_map_copy(map);
12665
12666 return in;
12667}
12668
12669/* Check if the given map is obviously injective.
12670 */
12672{
12673 isl_bool in;
12674
12675 map = isl_map_copy(map);
12679
12680 return in;
12681}
12682
12684{
12685 isl_bool sv;
12686
12688 if (sv < 0 || !sv)
12689 return sv;
12690
12691 return isl_map_is_injective(map);
12692}
12693
12698
12699/* Does "map" only map elements to themselves?
12700 *
12701 * If the domain and range spaces are different, then "map"
12702 * is considered not to be an identity relation, even if it is empty.
12703 * Otherwise, construct the maximal identity relation and
12704 * check whether "map" is a subset of this relation.
12705 */
12707{
12708 isl_map *id;
12709 isl_bool equal, is_identity;
12710
12712 if (equal < 0 || !equal)
12713 return equal;
12714
12716 is_identity = isl_map_is_subset(map, id);
12717 isl_map_free(id);
12718
12719 return is_identity;
12720}
12721
12723{
12724 int ok;
12725 isl_set *delta;
12726
12728 ok = isl_set_is_singleton(delta);
12729 isl_set_free(delta);
12730
12731 return ok;
12732}
12733
12734static int unique(isl_int *p, unsigned pos, unsigned len)
12735{
12737 return 0;
12738 if (isl_seq_any_non_zero(p + pos + 1, len - pos - 1))
12739 return 0;
12740 return 1;
12741}
12742
12744{
12745 int i, j;
12746 isl_size nvar, ovar, n_div;
12747
12748 n_div = isl_basic_set_dim(bset, isl_dim_div);
12749 if (n_div < 0)
12750 return isl_bool_error;
12751 if (n_div != 0)
12752 return isl_bool_false;
12753
12754 nvar = isl_basic_set_dim(bset, isl_dim_set);
12755 ovar = isl_space_offset(bset->dim, isl_dim_set);
12756 if (nvar < 0 || ovar < 0)
12757 return isl_bool_error;
12758 for (j = 0; j < nvar; ++j) {
12759 int lower = 0, upper = 0;
12760 for (i = 0; i < bset->n_eq; ++i) {
12761 if (isl_int_is_zero(bset->eq[i][1 + ovar + j]))
12762 continue;
12763 if (!unique(bset->eq[i] + 1 + ovar, j, nvar))
12764 return isl_bool_false;
12765 break;
12766 }
12767 if (i < bset->n_eq)
12768 continue;
12769 for (i = 0; i < bset->n_ineq; ++i) {
12770 if (isl_int_is_zero(bset->ineq[i][1 + ovar + j]))
12771 continue;
12772 if (!unique(bset->ineq[i] + 1 + ovar, j, nvar))
12773 return isl_bool_false;
12774 if (isl_int_is_pos(bset->ineq[i][1 + ovar + j]))
12775 lower = 1;
12776 else
12777 upper = 1;
12778 }
12779 if (!lower || !upper)
12780 return isl_bool_false;
12781 }
12782
12783 return isl_bool_true;
12784}
12785
12787{
12788 if (!set)
12789 return isl_bool_error;
12790 if (set->n != 1)
12791 return isl_bool_false;
12792
12793 return isl_basic_set_is_box(set->p[0]);
12794}
12795
12797{
12798 if (!bset)
12799 return isl_bool_error;
12800
12801 return isl_space_is_wrapping(bset->dim);
12802}
12803
12805{
12806 if (!set)
12807 return isl_bool_error;
12808
12809 return isl_space_is_wrapping(set->dim);
12810}
12811
12812/* Modify the space of "map" through a call to "change".
12813 * If "can_change" is set (not NULL), then first call it to check
12814 * if the modification is allowed, printing the error message "cannot_change"
12815 * if it is not.
12816 */
12818 isl_bool (*can_change)(__isl_keep isl_map *map),
12819 const char *cannot_change,
12820 __isl_give isl_space *(*change)(__isl_take isl_space *space))
12821{
12822 isl_bool ok;
12823 isl_space *space;
12824
12825 if (!map)
12826 return NULL;
12827
12828 ok = can_change ? can_change(map) : isl_bool_true;
12829 if (ok < 0)
12830 return isl_map_free(map);
12831 if (!ok)
12833 return isl_map_free(map));
12834
12835 space = change(isl_map_get_space(map));
12836 map = isl_map_reset_space(map, space);
12837
12838 return map;
12839}
12840
12841/* Is the domain of "map" a wrapped relation?
12842 */
12844{
12845 if (!map)
12846 return isl_bool_error;
12847
12848 return isl_space_domain_is_wrapping(map->dim);
12849}
12850
12851/* Does "map" have a wrapped relation in both domain and range?
12852 */
12857
12858/* Is the range of "map" a wrapped relation?
12859 */
12861{
12862 if (!map)
12863 return isl_bool_error;
12864
12865 return isl_space_range_is_wrapping(map->dim);
12866}
12867
12869{
12870 isl_space *space;
12871
12872 space = isl_basic_map_take_space(bmap);
12873 space = isl_space_wrap(space);
12874 bmap = isl_basic_map_restore_space(bmap, space);
12875
12876 bmap = isl_basic_map_finalize(bmap);
12877
12878 return bset_from_bmap(bmap);
12879}
12880
12881/* Given a map A -> B, return the set (A -> B).
12882 */
12887
12889{
12890 bset = isl_basic_set_cow(bset);
12891 if (!bset)
12892 return NULL;
12893
12894 bset->dim = isl_space_unwrap(bset->dim);
12895 if (!bset->dim)
12896 goto error;
12897
12898 bset = isl_basic_set_finalize(bset);
12899
12900 return bset_to_bmap(bset);
12901error:
12902 isl_basic_set_free(bset);
12903 return NULL;
12904}
12905
12906/* Given a set (A -> B), return the map A -> B.
12907 * Error out if "set" is not of the form (A -> B).
12908 */
12914
12916 enum isl_dim_type type)
12917{
12918 isl_space *space;
12919
12920 space = isl_basic_map_take_space(bmap);
12921 space = isl_space_reset(space, type);
12922 bmap = isl_basic_map_restore_space(bmap, space);
12923
12924 bmap = isl_basic_map_mark_final(bmap);
12925
12926 return bmap;
12927}
12928
12930 enum isl_dim_type type)
12931{
12932 int i;
12933 isl_space *space;
12934
12935 if (!map)
12936 return NULL;
12937
12939 return map;
12940
12941 map = isl_map_cow(map);
12942 if (!map)
12943 return NULL;
12944
12945 for (i = 0; i < map->n; ++i) {
12946 map->p[i] = isl_basic_map_reset(map->p[i], type);
12947 if (!map->p[i])
12948 goto error;
12949 }
12950
12951 space = isl_map_take_space(map);
12952 space = isl_space_reset(space, type);
12953 map = isl_map_restore_space(map, space);
12954
12955 return map;
12956error:
12958 return NULL;
12959}
12960
12962{
12963 isl_space *space;
12964
12965 space = isl_basic_map_take_space(bmap);
12966 space = isl_space_flatten(space);
12967 bmap = isl_basic_map_restore_space(bmap, space);
12968
12969 bmap = isl_basic_map_mark_final(bmap);
12970
12971 return bmap;
12972}
12973
12978
12981{
12982 isl_space *space;
12983
12984 space = isl_basic_map_take_space(bmap);
12985 space = isl_space_flatten_domain(space);
12986 bmap = isl_basic_map_restore_space(bmap, space);
12987
12988 bmap = isl_basic_map_mark_final(bmap);
12989
12990 return bmap;
12991}
12992
12995{
12996 isl_space *space;
12997
12998 space = isl_basic_map_take_space(bmap);
12999 space = isl_space_flatten_range(space);
13000 bmap = isl_basic_map_restore_space(bmap, space);
13001
13002 bmap = isl_basic_map_mark_final(bmap);
13003
13004 return bmap;
13005}
13006
13007/* Remove any internal structure from the spaces of domain and range of "map".
13008 */
13010{
13011 if (!map)
13012 return NULL;
13013
13014 if (!map->dim->nested[0] && !map->dim->nested[1])
13015 return map;
13016
13017 return isl_map_change_space(map, NULL, NULL, &isl_space_flatten);
13018}
13019
13024
13026{
13027 isl_space *space, *flat_space;
13028 isl_map *map;
13029
13030 space = isl_set_get_space(set);
13031 flat_space = isl_space_flatten(isl_space_copy(space));
13033 flat_space));
13035
13036 return map;
13037}
13038
13039/* Remove any internal structure from the space of the domain of "map".
13040 */
13042{
13043 if (!map)
13044 return NULL;
13045
13046 if (!map->dim->nested[0])
13047 return map;
13048
13050}
13051
13052/* Remove any internal structure from the space of the range of "map".
13053 */
13055{
13056 if (!map)
13057 return NULL;
13058
13059 if (!map->dim->nested[1])
13060 return map;
13061
13062 return isl_map_change_space(map, NULL, NULL, &isl_space_flatten_range);
13063}
13064
13065/* Reorder the dimensions of "bmap" according to the given dim_map
13066 * and set the dimension specification to "space" and
13067 * perform Gaussian elimination on the result.
13068 */
13070 __isl_take isl_space *space, __isl_take struct isl_dim_map *dim_map)
13071{
13073 unsigned flags;
13074 isl_size n_div;
13075
13076 n_div = isl_basic_map_dim(bmap, isl_dim_div);
13077 if (n_div < 0 || !space || !dim_map)
13078 goto error;
13079
13080 flags = bmap->flags;
13084 res = isl_basic_map_alloc_space(space, n_div, bmap->n_eq, bmap->n_ineq);
13086 if (res)
13087 res->flags = flags;
13088 res = isl_basic_map_gauss(res, NULL);
13090 return res;
13091error:
13092 isl_dim_map_free(dim_map);
13093 isl_basic_map_free(bmap);
13094 isl_space_free(space);
13095 return NULL;
13096}
13097
13098/* Reorder the dimensions of "map" according to given reordering.
13099 */
13102{
13103 int i;
13104 struct isl_dim_map *dim_map;
13105
13106 map = isl_map_cow(map);
13107 dim_map = isl_dim_map_from_reordering(r);
13108 if (!map || !r || !dim_map)
13109 goto error;
13110
13111 for (i = 0; i < map->n; ++i) {
13112 struct isl_dim_map *dim_map_i;
13113 isl_space *space;
13114
13115 dim_map_i = isl_dim_map_extend(dim_map, map->p[i]);
13116
13117 space = isl_reordering_get_space(r);
13118 map->p[i] = isl_basic_map_realign(map->p[i], space, dim_map_i);
13119
13120 if (!map->p[i])
13121 goto error;
13122 }
13123
13126
13128 isl_dim_map_free(dim_map);
13129 return map;
13130error:
13131 isl_dim_map_free(dim_map);
13134 return NULL;
13135}
13136
13142
13144 __isl_take isl_space *model)
13145{
13146 isl_ctx *ctx;
13147 isl_bool aligned;
13148
13149 if (!map || !model)
13150 goto error;
13151
13152 ctx = isl_space_get_ctx(model);
13153 if (!isl_space_has_named_params(model))
13155 "model has unnamed parameters", goto error);
13157 goto error;
13158 aligned = isl_map_space_has_equal_params(map, model);
13159 if (aligned < 0)
13160 goto error;
13161 if (!aligned) {
13162 isl_space *space;
13163 isl_reordering *exp;
13164
13165 space = isl_map_peek_space(map);
13166 exp = isl_parameter_alignment_reordering(space, model);
13167 map = isl_map_realign(map, exp);
13168 }
13169
13170 isl_space_free(model);
13171 return map;
13172error:
13173 isl_space_free(model);
13175 return NULL;
13176}
13177
13183
13184/* Align the parameters of "bmap" to those of "model", introducing
13185 * additional parameters if needed.
13186 */
13189{
13190 isl_ctx *ctx;
13191 isl_bool equal_params;
13192 isl_space *bmap_space;
13193
13194 if (!bmap || !model)
13195 goto error;
13196
13197 ctx = isl_space_get_ctx(model);
13198 if (!isl_space_has_named_params(model))
13200 "model has unnamed parameters", goto error);
13201 if (isl_basic_map_check_named_params(bmap) < 0)
13202 goto error;
13203 bmap_space = isl_basic_map_peek_space(bmap);
13204 equal_params = isl_space_has_equal_params(bmap_space, model);
13205 if (equal_params < 0)
13206 goto error;
13207 if (!equal_params) {
13208 isl_reordering *exp;
13209 struct isl_dim_map *dim_map;
13210
13211 exp = isl_parameter_alignment_reordering(bmap_space, model);
13212 dim_map = isl_dim_map_from_reordering(exp);
13213 bmap = isl_basic_map_realign(bmap,
13215 isl_dim_map_extend(dim_map, bmap));
13217 isl_dim_map_free(dim_map);
13218 }
13219
13220 isl_space_free(model);
13221 return bmap;
13222error:
13223 isl_space_free(model);
13224 isl_basic_map_free(bmap);
13225 return NULL;
13226}
13227
13228/* Do "bset" and "space" have the same parameters?
13229 */
13231 __isl_keep isl_space *space)
13232{
13233 isl_space *bset_space;
13234
13235 bset_space = isl_basic_set_peek_space(bset);
13236 return isl_space_has_equal_params(bset_space, space);
13237}
13238
13239/* Do "map" and "space" have the same parameters?
13240 */
13242 __isl_keep isl_space *space)
13243{
13244 isl_space *map_space;
13245
13246 map_space = isl_map_peek_space(map);
13247 return isl_space_has_equal_params(map_space, space);
13248}
13249
13250/* Do "set" and "space" have the same parameters?
13251 */
13257
13258/* Align the parameters of "bset" to those of "model", introducing
13259 * additional parameters if needed.
13260 */
13266
13267#undef TYPE
13268#define TYPE isl_map
13269#define isl_map_drop_dims isl_map_drop
13271
13272/* Drop all parameters not referenced by "set".
13273 */
13279
13280#undef TYPE
13281#define TYPE isl_basic_map
13282#define isl_basic_map_drop_dims isl_basic_map_drop
13284
13285/* Drop all parameters not referenced by "bset".
13286 */
13293
13294/* Given a tuple of identifiers "tuple" in a space that corresponds
13295 * to that of "set", if any of those identifiers appear as parameters
13296 * in "set", then equate those parameters with the corresponding
13297 * set dimensions and project out the parameters.
13298 * The result therefore has no such parameters.
13299 */
13302{
13303 int i;
13304 isl_size n;
13305 isl_space *set_space, *tuple_space;
13306
13307 set_space = isl_set_peek_space(set);
13308 tuple_space = isl_multi_id_peek_space(tuple);
13309 if (isl_space_check_equal_tuples(tuple_space, set_space) < 0)
13310 return isl_set_free(set);
13311 n = isl_multi_id_size(tuple);
13312 if (n < 0)
13313 return isl_set_free(set);
13314 for (i = 0; i < n; ++i) {
13315 isl_id *id;
13316 int pos;
13317
13318 id = isl_multi_id_get_at(tuple, i);
13319 if (!id)
13320 return isl_set_free(set);
13322 isl_id_free(id);
13323 if (pos < 0)
13324 continue;
13327 }
13328 return set;
13329}
13330
13331/* Bind the set dimensions of "set" to parameters with identifiers
13332 * specified by "tuple", living in the same space as "set".
13333 *
13334 * If no parameters with these identifiers appear in "set" already,
13335 * then the set dimensions are simply reinterpreted as parameters.
13336 * Otherwise, the parameters are first equated to the corresponding
13337 * set dimensions.
13338 */
13341{
13342 isl_space *space;
13343
13345 space = isl_set_get_space(set);
13346 space = isl_space_bind_set(space, tuple);
13347 isl_multi_id_free(tuple);
13348 set = isl_set_reset_space(set, space);
13349
13350 return set;
13351}
13352
13353/* Given a tuple of identifiers "tuple" in a space that corresponds
13354 * to the domain of "map", if any of those identifiers appear as parameters
13355 * in "map", then equate those parameters with the corresponding
13356 * input dimensions and project out the parameters.
13357 * The result therefore has no such parameters.
13358 */
13361{
13362 int i;
13363 isl_size n;
13364 isl_space *map_space, *tuple_space;
13365
13366 map_space = isl_map_peek_space(map);
13367 tuple_space = isl_multi_id_peek_space(tuple);
13368 if (isl_space_check_domain_tuples(tuple_space, map_space) < 0)
13369 return isl_map_free(map);
13370 n = isl_multi_id_size(tuple);
13371 if (n < 0)
13372 return isl_map_free(map);
13373 for (i = 0; i < n; ++i) {
13374 isl_id *id;
13375 int pos;
13376
13377 id = isl_multi_id_get_at(tuple, i);
13378 if (!id)
13379 return isl_map_free(map);
13381 isl_id_free(id);
13382 if (pos < 0)
13383 continue;
13386 }
13387 return map;
13388}
13389
13390/* Bind the input dimensions of "map" to parameters with identifiers
13391 * specified by "tuple", living in the domain space of "map".
13392 *
13393 * If no parameters with these identifiers appear in "map" already,
13394 * then the input dimensions are simply reinterpreted as parameters.
13395 * Otherwise, the parameters are first equated to the corresponding
13396 * input dimensions.
13397 */
13400{
13401 isl_space *space;
13402 isl_set *set;
13403
13405 space = isl_map_get_space(map);
13406 space = isl_space_bind_map_domain(space, tuple);
13407 isl_multi_id_free(tuple);
13409
13410 return set;
13411}
13412
13413/* Bind the output dimensions of "map" to parameters with identifiers
13414 * specified by "tuple", living in the range space of "map".
13415 *
13416 * Since binding is more easily implemented on the domain,
13417 * bind the input dimensions of the inverse of "map".
13418 */
13424
13425/* Insert a domain corresponding to "tuple"
13426 * into the nullary or unary relation "set".
13427 * The result has an extra initial tuple and is therefore
13428 * either a unary or binary relation.
13429 * Any parameters with identifiers in "tuple" are reinterpreted
13430 * as the corresponding domain dimensions.
13431 */
13434{
13435 isl_space *space;
13436 isl_reordering *r;
13437
13438 space = isl_set_peek_space(set);
13440 isl_multi_id_free(tuple);
13441
13442 return isl_map_realign(set_to_map(set), r);
13443}
13444
13445/* Construct a set with "tuple" as domain from the parameter domain "set".
13446 * Any parameters with identifiers in "tuple" are reinterpreted
13447 * as the corresponding set dimensions.
13448 */
13451{
13452 isl_bool is_params;
13453
13454 is_params = isl_set_is_params(set);
13455 if (is_params < 0)
13456 set = isl_set_free(set);
13457 else if (!is_params)
13459 "expecting parameter domain", set = isl_set_free(set));
13461}
13462
13463/* Check that "set" is a proper set, i.e., that it is not a parameter domain.
13464 */
13466{
13467 isl_bool is_params;
13468
13469 is_params = isl_set_is_params(set);
13470 if (is_params < 0)
13471 return isl_stat_error;
13472 else if (is_params)
13474 "expecting proper set", return isl_stat_error);
13475
13476 return isl_stat_ok;
13477}
13478
13479/* Construct a map with "domain" as domain and "set" as range.
13480 * Any parameters with identifiers in "domain" are reinterpreted
13481 * as the corresponding domain dimensions.
13482 */
13490
13491/* Construct a map with "domain" as domain and "set" as range.
13492 */
13495{
13496 isl_size dim;
13497 isl_space *space;
13498 isl_map *map;
13499
13503 if (dim < 0)
13505 space = isl_set_get_space(set);
13508
13511 map = isl_map_reset_space(map, space);
13512
13513 return map;
13514}
13515
13518 enum isl_dim_type c2, enum isl_dim_type c3,
13519 enum isl_dim_type c4, enum isl_dim_type c5)
13520{
13521 enum isl_dim_type c[5] = { c1, c2, c3, c4, c5 };
13522 struct isl_mat *mat;
13523 int i, j, k;
13524 int pos;
13526
13528 if (total < 0)
13529 return NULL;
13530 mat = isl_mat_alloc(bmap->ctx, bmap->n_eq, total + 1);
13531 if (!mat)
13532 return NULL;
13533 for (i = 0; i < bmap->n_eq; ++i)
13534 for (j = 0, pos = 0; j < 5; ++j) {
13535 int off = isl_basic_map_offset(bmap, c[j]);
13536 isl_size dim = isl_basic_map_dim(bmap, c[j]);
13537 if (dim < 0)
13538 return isl_mat_free(mat);
13539 for (k = 0; k < dim; ++k) {
13540 isl_int_set(mat->row[i][pos],
13541 bmap->eq[i][off + k]);
13542 ++pos;
13543 }
13544 }
13545
13546 return mat;
13547}
13548
13551 enum isl_dim_type c2, enum isl_dim_type c3,
13552 enum isl_dim_type c4, enum isl_dim_type c5)
13553{
13554 enum isl_dim_type c[5] = { c1, c2, c3, c4, c5 };
13555 struct isl_mat *mat;
13556 int i, j, k;
13557 int pos;
13559
13561 if (total < 0)
13562 return NULL;
13563 mat = isl_mat_alloc(bmap->ctx, bmap->n_ineq, total + 1);
13564 if (!mat)
13565 return NULL;
13566 for (i = 0; i < bmap->n_ineq; ++i)
13567 for (j = 0, pos = 0; j < 5; ++j) {
13568 int off = isl_basic_map_offset(bmap, c[j]);
13569 isl_size dim = isl_basic_map_dim(bmap, c[j]);
13570 if (dim < 0)
13571 return isl_mat_free(mat);
13572 for (k = 0; k < dim; ++k) {
13573 isl_int_set(mat->row[i][pos],
13574 bmap->ineq[i][off + k]);
13575 ++pos;
13576 }
13577 }
13578
13579 return mat;
13580}
13581
13583 __isl_take isl_space *space,
13585 enum isl_dim_type c2, enum isl_dim_type c3,
13586 enum isl_dim_type c4, enum isl_dim_type c5)
13587{
13588 enum isl_dim_type c[5] = { c1, c2, c3, c4, c5 };
13589 isl_basic_map *bmap = NULL;
13590 isl_size dim;
13591 unsigned total;
13592 unsigned extra;
13593 int i, j, k, l;
13594 int pos;
13595
13596 dim = isl_space_dim(space, isl_dim_all);
13597 if (dim < 0 || !eq || !ineq)
13598 goto error;
13599
13600 if (eq->n_col != ineq->n_col)
13601 isl_die(space->ctx, isl_error_invalid,
13602 "equalities and inequalities matrices should have "
13603 "same number of columns", goto error);
13604
13605 total = 1 + dim;
13606
13607 if (eq->n_col < total)
13608 isl_die(space->ctx, isl_error_invalid,
13609 "number of columns too small", goto error);
13610
13611 extra = eq->n_col - total;
13612
13613 bmap = isl_basic_map_alloc_space(isl_space_copy(space), extra,
13614 eq->n_row, ineq->n_row);
13615 if (!bmap)
13616 goto error;
13617 for (i = 0; i < extra; ++i) {
13618 k = isl_basic_map_alloc_div(bmap);
13619 if (k < 0)
13620 goto error;
13621 isl_int_set_si(bmap->div[k][0], 0);
13622 }
13623 for (i = 0; i < eq->n_row; ++i) {
13625 if (l < 0)
13626 goto error;
13627 for (j = 0, pos = 0; j < 5; ++j) {
13628 int off = isl_basic_map_offset(bmap, c[j]);
13629 isl_size dim = isl_basic_map_dim(bmap, c[j]);
13630 if (dim < 0)
13631 goto error;
13632 for (k = 0; k < dim; ++k) {
13633 isl_int_set(bmap->eq[l][off + k],
13634 eq->row[i][pos]);
13635 ++pos;
13636 }
13637 }
13638 }
13639 for (i = 0; i < ineq->n_row; ++i) {
13641 if (l < 0)
13642 goto error;
13643 for (j = 0, pos = 0; j < 5; ++j) {
13644 int off = isl_basic_map_offset(bmap, c[j]);
13645 isl_size dim = isl_basic_map_dim(bmap, c[j]);
13646 if (dim < 0)
13647 goto error;
13648 for (k = 0; k < dim; ++k) {
13649 isl_int_set(bmap->ineq[l][off + k],
13650 ineq->row[i][pos]);
13651 ++pos;
13652 }
13653 }
13654 }
13655
13656 isl_space_free(space);
13657 isl_mat_free(eq);
13658 isl_mat_free(ineq);
13659
13660 bmap = isl_basic_map_simplify(bmap);
13661 return isl_basic_map_finalize(bmap);
13662error:
13663 isl_space_free(space);
13664 isl_mat_free(eq);
13665 isl_mat_free(ineq);
13666 isl_basic_map_free(bmap);
13667 return NULL;
13668}
13669
13677
13685
13687 __isl_take isl_space *space,
13689 enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4)
13690{
13691 isl_basic_map *bmap;
13692 bmap = isl_basic_map_from_constraint_matrices(space, eq, ineq,
13693 c1, c2, c3, c4, isl_dim_in);
13694 return bset_from_bmap(bmap);
13695}
13696
13698{
13699 if (!bmap)
13700 return isl_bool_error;
13701
13702 return isl_space_can_zip(bmap->dim);
13703}
13704
13706{
13707 if (!map)
13708 return isl_bool_error;
13709
13710 return isl_space_can_zip(map->dim);
13711}
13712
13713/* Given a basic map (A -> B) -> (C -> D), return the corresponding basic map
13714 * (A -> C) -> (B -> D).
13715 */
13717{
13718 unsigned pos;
13719 isl_size n_in;
13720 isl_size n1;
13721 isl_size n2;
13722
13723 if (!bmap)
13724 return NULL;
13725
13726 if (!isl_basic_map_can_zip(bmap))
13727 isl_die(bmap->ctx, isl_error_invalid,
13728 "basic map cannot be zipped", goto error);
13729 n_in = isl_space_dim(bmap->dim->nested[0], isl_dim_in);
13730 n1 = isl_space_dim(bmap->dim->nested[0], isl_dim_out);
13731 n2 = isl_space_dim(bmap->dim->nested[1], isl_dim_in);
13732 if (n_in < 0 || n1 < 0 || n2 < 0)
13733 return isl_basic_map_free(bmap);
13734 pos = isl_basic_map_offset(bmap, isl_dim_in) + n_in;
13735 bmap = isl_basic_map_cow(bmap);
13736 bmap = isl_basic_map_swap_vars(bmap, pos, n1, n2);
13737 if (!bmap)
13738 return NULL;
13739 bmap->dim = isl_space_zip(bmap->dim);
13740 if (!bmap->dim)
13741 goto error;
13742 bmap = isl_basic_map_mark_final(bmap);
13743 return bmap;
13744error:
13745 isl_basic_map_free(bmap);
13746 return NULL;
13747}
13748
13749/* Given a map (A -> B) -> (C -> D), return the corresponding map
13750 * (A -> C) -> (B -> D).
13751 */
13753{
13754 if (!map)
13755 return NULL;
13756
13757 if (!isl_map_can_zip(map))
13758 isl_die(map->ctx, isl_error_invalid, "map cannot be zipped",
13759 goto error);
13760
13762error:
13764 return NULL;
13765}
13766
13767/* Can we apply isl_basic_map_curry to "bmap"?
13768 * That is, does it have a nested relation in its domain?
13769 */
13771{
13772 if (!bmap)
13773 return isl_bool_error;
13774
13775 return isl_space_can_curry(bmap->dim);
13776}
13777
13778/* Can we apply isl_map_curry to "map"?
13779 * That is, does it have a nested relation in its domain?
13780 */
13782{
13783 if (!map)
13784 return isl_bool_error;
13785
13786 return isl_space_can_curry(map->dim);
13787}
13788
13789/* Given a basic map (A -> B) -> C, return the corresponding basic map
13790 * A -> (B -> C).
13791 */
13793{
13794
13795 if (!bmap)
13796 return NULL;
13797
13798 if (!isl_basic_map_can_curry(bmap))
13799 isl_die(bmap->ctx, isl_error_invalid,
13800 "basic map cannot be curried", goto error);
13801 bmap = isl_basic_map_cow(bmap);
13802 if (!bmap)
13803 return NULL;
13804 bmap->dim = isl_space_curry(bmap->dim);
13805 if (!bmap->dim)
13806 goto error;
13807 bmap = isl_basic_map_mark_final(bmap);
13808 return bmap;
13809error:
13810 isl_basic_map_free(bmap);
13811 return NULL;
13812}
13813
13814/* Given a map (A -> B) -> C, return the corresponding map
13815 * A -> (B -> C).
13816 */
13818{
13820 "map cannot be curried", &isl_space_curry);
13821}
13822
13823/* Can isl_map_range_curry be applied to "map"?
13824 * That is, does it have a nested relation in its range,
13825 * the domain of which is itself a nested relation?
13826 */
13828{
13829 if (!map)
13830 return isl_bool_error;
13831
13832 return isl_space_can_range_curry(map->dim);
13833}
13834
13835/* Given a map A -> ((B -> C) -> D), return the corresponding map
13836 * A -> (B -> (C -> D)).
13837 */
13839{
13841 "map range cannot be curried",
13843}
13844
13845/* Can we apply isl_basic_map_uncurry to "bmap"?
13846 * That is, does it have a nested relation in its domain?
13847 */
13849{
13850 if (!bmap)
13851 return isl_bool_error;
13852
13853 return isl_space_can_uncurry(bmap->dim);
13854}
13855
13856/* Can we apply isl_map_uncurry to "map"?
13857 * That is, does it have a nested relation in its domain?
13858 */
13860{
13861 if (!map)
13862 return isl_bool_error;
13863
13864 return isl_space_can_uncurry(map->dim);
13865}
13866
13867/* Given a basic map A -> (B -> C), return the corresponding basic map
13868 * (A -> B) -> C.
13869 */
13871{
13872
13873 if (!bmap)
13874 return NULL;
13875
13876 if (!isl_basic_map_can_uncurry(bmap))
13877 isl_die(bmap->ctx, isl_error_invalid,
13878 "basic map cannot be uncurried",
13879 return isl_basic_map_free(bmap));
13880 bmap = isl_basic_map_cow(bmap);
13881 if (!bmap)
13882 return NULL;
13883 bmap->dim = isl_space_uncurry(bmap->dim);
13884 if (!bmap->dim)
13885 return isl_basic_map_free(bmap);
13886 bmap = isl_basic_map_mark_final(bmap);
13887 return bmap;
13888}
13889
13890/* Given a map A -> (B -> C), return the corresponding map
13891 * (A -> B) -> C.
13892 */
13894{
13896 "map cannot be uncurried", &isl_space_uncurry);
13897}
13898
13900 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
13901{
13902 return isl_map_equate(set, type1, pos1, type2, pos2);
13903}
13904
13905/* Construct a basic map where the given dimensions are equal to each other.
13906 */
13908 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
13909{
13910 isl_basic_map *bmap = NULL;
13911 int i;
13913
13915 if (total < 0 ||
13916 isl_space_check_range(space, type1, pos1, 1) < 0 ||
13917 isl_space_check_range(space, type2, pos2, 1) < 0)
13918 goto error;
13919
13920 if (type1 == type2 && pos1 == pos2)
13921 return isl_basic_map_universe(space);
13922
13923 bmap = isl_basic_map_alloc_space(isl_space_copy(space), 0, 1, 0);
13925 if (i < 0)
13926 goto error;
13927 isl_seq_clr(bmap->eq[i], 1 + total);
13928 pos1 += isl_basic_map_offset(bmap, type1);
13929 pos2 += isl_basic_map_offset(bmap, type2);
13930 isl_int_set_si(bmap->eq[i][pos1], -1);
13931 isl_int_set_si(bmap->eq[i][pos2], 1);
13932 bmap = isl_basic_map_finalize(bmap);
13933 isl_space_free(space);
13934 return bmap;
13935error:
13936 isl_space_free(space);
13937 isl_basic_map_free(bmap);
13938 return NULL;
13939}
13940
13941/* Add a constraint imposing that the given two dimensions are equal.
13942 */
13944 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
13945{
13946 isl_basic_map *eq;
13947
13948 eq = equator(isl_basic_map_get_space(bmap), type1, pos1, type2, pos2);
13949
13950 bmap = isl_basic_map_intersect(bmap, eq);
13951
13952 return bmap;
13953}
13954
13955/* Add a constraint imposing that the given two dimensions are equal.
13956 */
13958 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
13959{
13960 isl_basic_map *bmap;
13961
13962 bmap = equator(isl_map_get_space(map), type1, pos1, type2, pos2);
13963
13965
13966 return map;
13967}
13968
13969/* Add a constraint imposing that the given two dimensions have opposite values.
13970 */
13972 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
13973{
13974 isl_basic_map *bmap = NULL;
13975 int i;
13977
13978 if (isl_map_check_range(map, type1, pos1, 1) < 0)
13979 return isl_map_free(map);
13980 if (isl_map_check_range(map, type2, pos2, 1) < 0)
13981 return isl_map_free(map);
13982
13984 if (total < 0)
13985 return isl_map_free(map);
13988 if (i < 0)
13989 goto error;
13990 isl_seq_clr(bmap->eq[i], 1 + total);
13991 pos1 += isl_basic_map_offset(bmap, type1);
13992 pos2 += isl_basic_map_offset(bmap, type2);
13993 isl_int_set_si(bmap->eq[i][pos1], 1);
13994 isl_int_set_si(bmap->eq[i][pos2], 1);
13995 bmap = isl_basic_map_finalize(bmap);
13996
13998
13999 return map;
14000error:
14001 isl_basic_map_free(bmap);
14003 return NULL;
14004}
14005
14006/* Construct a constraint imposing that the value of the first dimension is
14007 * greater than or equal to that of the second.
14008 */
14010 __isl_take isl_space *space, enum isl_dim_type type1, int pos1,
14011 enum isl_dim_type type2, int pos2)
14012{
14013 isl_constraint *c;
14014
14015 if (isl_space_check_range(space, type1, pos1, 1) < 0 ||
14016 isl_space_check_range(space, type2, pos2, 1) < 0)
14017 space = isl_space_free(space);
14018 if (!space)
14019 return NULL;
14020
14022
14023 if (type1 == type2 && pos1 == pos2)
14024 return c;
14025
14026 c = isl_constraint_set_coefficient_si(c, type1, pos1, 1);
14027 c = isl_constraint_set_coefficient_si(c, type2, pos2, -1);
14028
14029 return c;
14030}
14031
14032/* Add a constraint imposing that the value of the first dimension is
14033 * greater than or equal to that of the second.
14034 */
14036 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
14037{
14038 isl_constraint *c;
14039 isl_space *space;
14040
14041 if (type1 == type2 && pos1 == pos2)
14042 return bmap;
14043 space = isl_basic_map_get_space(bmap);
14044 c = constraint_order_ge(space, type1, pos1, type2, pos2);
14045 bmap = isl_basic_map_add_constraint(bmap, c);
14046
14047 return bmap;
14048}
14049
14050/* Add a constraint imposing that the value of the first dimension is
14051 * greater than or equal to that of the second.
14052 */
14054 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
14055{
14056 isl_constraint *c;
14057 isl_space *space;
14058
14059 if (type1 == type2 && pos1 == pos2)
14060 return map;
14061 space = isl_map_get_space(map);
14062 c = constraint_order_ge(space, type1, pos1, type2, pos2);
14064
14065 return map;
14066}
14067
14068/* Add a constraint imposing that the value of the first dimension is
14069 * less than or equal to that of the second.
14070 */
14072 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
14073{
14074 return isl_map_order_ge(map, type2, pos2, type1, pos1);
14075}
14076
14077/* Construct a basic map where the value of the first dimension is
14078 * greater than that of the second.
14079 */
14081 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
14082{
14083 isl_basic_map *bmap = NULL;
14084 int i;
14086
14087 if (isl_space_check_range(space, type1, pos1, 1) < 0 ||
14088 isl_space_check_range(space, type2, pos2, 1) < 0)
14089 goto error;
14090
14091 if (type1 == type2 && pos1 == pos2)
14092 return isl_basic_map_empty(space);
14093
14094 bmap = isl_basic_map_alloc_space(space, 0, 0, 1);
14097 if (total < 0 || i < 0)
14098 return isl_basic_map_free(bmap);
14099 isl_seq_clr(bmap->ineq[i], 1 + total);
14100 pos1 += isl_basic_map_offset(bmap, type1);
14101 pos2 += isl_basic_map_offset(bmap, type2);
14102 isl_int_set_si(bmap->ineq[i][pos1], 1);
14103 isl_int_set_si(bmap->ineq[i][pos2], -1);
14104 isl_int_set_si(bmap->ineq[i][0], -1);
14105 bmap = isl_basic_map_finalize(bmap);
14106
14107 return bmap;
14108error:
14109 isl_space_free(space);
14110 isl_basic_map_free(bmap);
14111 return NULL;
14112}
14113
14114/* Add a constraint imposing that the value of the first dimension is
14115 * greater than that of the second.
14116 */
14118 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
14119{
14120 isl_basic_map *gt;
14121
14122 gt = greator(isl_basic_map_get_space(bmap), type1, pos1, type2, pos2);
14123
14124 bmap = isl_basic_map_intersect(bmap, gt);
14125
14126 return bmap;
14127}
14128
14129/* Add a constraint imposing that the value of the first dimension is
14130 * greater than that of the second.
14131 */
14133 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
14134{
14135 isl_basic_map *bmap;
14136
14137 bmap = greator(isl_map_get_space(map), type1, pos1, type2, pos2);
14138
14140
14141 return map;
14142}
14143
14144/* Add a constraint imposing that the value of the first dimension is
14145 * smaller than that of the second.
14146 */
14148 enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
14149{
14150 return isl_map_order_gt(map, type2, pos2, type1, pos1);
14151}
14152
14154 int pos)
14155{
14156 isl_aff *div;
14157 isl_local_space *ls;
14158
14159 if (!bmap)
14160 return NULL;
14161
14162 if (!isl_basic_map_divs_known(bmap))
14164 "some divs are unknown", return NULL);
14165
14167 div = isl_local_space_get_div(ls, pos);
14169
14170 return div;
14171}
14172
14174 int pos)
14175{
14176 return isl_basic_map_get_div(bset, pos);
14177}
14178
14179/* Plug in "subs" for set dimension "pos" of "set".
14180 */
14182 unsigned pos, __isl_keep isl_aff *subs)
14183{
14185
14187 return set;
14188
14189 ma = isl_multi_aff_identity_on_domain_space(isl_set_get_space(set));
14190 ma = isl_multi_aff_set_aff(ma, pos, isl_aff_copy(subs));
14192}
14193
14194/* Check if the range of "ma" is compatible with the domain or range
14195 * (depending on "type") of "bmap".
14196 */
14200{
14201 isl_bool m;
14202 isl_space *ma_space;
14203
14204 ma_space = isl_multi_aff_get_space(ma);
14205
14206 m = isl_space_has_equal_params(bmap->dim, ma_space);
14207 if (m < 0)
14208 goto error;
14209 if (!m)
14211 "parameters don't match", goto error);
14212 m = isl_space_tuple_is_equal(bmap->dim, type, ma_space, isl_dim_out);
14213 if (m < 0)
14214 goto error;
14215 if (!m)
14217 "spaces don't match", goto error);
14218
14219 isl_space_free(ma_space);
14220 return isl_stat_ok;
14221error:
14222 isl_space_free(ma_space);
14223 return isl_stat_error;
14224}
14225
14226/* Copy the divs from "ma" to "bmap", adding zeros for the "n_before"
14227 * coefficients before the transformed range of dimensions,
14228 * the "n_after" coefficients after the transformed range of dimensions
14229 * and the coefficients of the other divs in "bmap".
14230 */
14232 __isl_keep isl_multi_aff *ma, int n_before, int n_after, int n_div)
14233{
14234 int i;
14235 isl_size n_param;
14236 isl_size n_set;
14237 isl_local_space *ls;
14238
14239 if (n_div == 0)
14240 return bmap;
14241
14242 ls = isl_aff_get_domain_local_space(ma->u.p[0]);
14243 n_param = isl_local_space_dim(ls, isl_dim_param);
14244 n_set = isl_local_space_dim(ls, isl_dim_set);
14245 if (n_param < 0 || n_set < 0)
14246 return isl_basic_map_free(bmap);
14247
14248 for (i = 0; i < n_div; ++i) {
14249 int o_bmap = 0, o_ls = 0;
14250
14251 isl_seq_cpy(bmap->div[i], ls->div->row[i], 1 + 1 + n_param);
14252 o_bmap += 1 + 1 + n_param;
14253 o_ls += 1 + 1 + n_param;
14254 isl_seq_clr(bmap->div[i] + o_bmap, n_before);
14255 o_bmap += n_before;
14256 isl_seq_cpy(bmap->div[i] + o_bmap,
14257 ls->div->row[i] + o_ls, n_set);
14258 o_bmap += n_set;
14259 o_ls += n_set;
14260 isl_seq_clr(bmap->div[i] + o_bmap, n_after);
14261 o_bmap += n_after;
14262 isl_seq_cpy(bmap->div[i] + o_bmap,
14263 ls->div->row[i] + o_ls, n_div);
14264 o_bmap += n_div;
14265 o_ls += n_div;
14266 isl_seq_clr(bmap->div[i] + o_bmap, bmap->n_div - n_div);
14267 bmap = isl_basic_map_add_div_constraints(bmap, i);
14268 if (!bmap)
14269 goto error;
14270 }
14271
14273 return bmap;
14274error:
14276 return isl_basic_map_free(bmap);
14277}
14278
14279/* How many stride constraints does "ma" enforce?
14280 * That is, how many of the affine expressions have a denominator
14281 * different from one?
14282 */
14284{
14285 int i;
14286 int strides = 0;
14287
14288 for (i = 0; i < ma->n; ++i)
14289 if (!isl_int_is_one(ma->u.p[i]->v->el[0]))
14290 strides++;
14291
14292 return strides;
14293}
14294
14295/* For each affine expression in ma of the form
14296 *
14297 * x_i = (f_i y + h_i)/m_i
14298 *
14299 * with m_i different from one, add a constraint to "bmap"
14300 * of the form
14301 *
14302 * f_i y + h_i = m_i alpha_i
14303 *
14304 * with alpha_i an additional existentially quantified variable.
14305 *
14306 * The input variables of "ma" correspond to a subset of the variables
14307 * of "bmap". There are "n_before" variables in "bmap" before this
14308 * subset and "n_after" variables after this subset.
14309 * The integer divisions of the affine expressions in "ma" are assumed
14310 * to have been aligned. There are "n_div_ma" of them and
14311 * they appear first in "bmap", straight after the "n_after" variables.
14312 */
14315 int n_before, int n_after, int n_div_ma)
14316{
14317 int i, k;
14318 int div;
14320 isl_size n_param;
14321 isl_size n_in;
14322
14324 n_param = isl_multi_aff_dim(ma, isl_dim_param);
14325 n_in = isl_multi_aff_dim(ma, isl_dim_in);
14326 if (total < 0 || n_param < 0 || n_in < 0)
14327 return isl_basic_map_free(bmap);
14328 for (i = 0; i < ma->n; ++i) {
14329 int o_bmap = 0, o_ma = 1;
14330
14331 if (isl_int_is_one(ma->u.p[i]->v->el[0]))
14332 continue;
14333 div = isl_basic_map_alloc_div(bmap);
14335 if (div < 0 || k < 0)
14336 goto error;
14337 isl_int_set_si(bmap->div[div][0], 0);
14338 isl_seq_cpy(bmap->eq[k] + o_bmap,
14339 ma->u.p[i]->v->el + o_ma, 1 + n_param);
14340 o_bmap += 1 + n_param;
14341 o_ma += 1 + n_param;
14342 isl_seq_clr(bmap->eq[k] + o_bmap, n_before);
14343 o_bmap += n_before;
14344 isl_seq_cpy(bmap->eq[k] + o_bmap,
14345 ma->u.p[i]->v->el + o_ma, n_in);
14346 o_bmap += n_in;
14347 o_ma += n_in;
14348 isl_seq_clr(bmap->eq[k] + o_bmap, n_after);
14349 o_bmap += n_after;
14350 isl_seq_cpy(bmap->eq[k] + o_bmap,
14351 ma->u.p[i]->v->el + o_ma, n_div_ma);
14352 o_bmap += n_div_ma;
14353 o_ma += n_div_ma;
14354 isl_seq_clr(bmap->eq[k] + o_bmap, 1 + total - o_bmap);
14355 isl_int_neg(bmap->eq[k][1 + total], ma->u.p[i]->v->el[0]);
14356 total++;
14357 }
14358
14359 return bmap;
14360error:
14361 isl_basic_map_free(bmap);
14362 return NULL;
14363}
14364
14365/* Replace the domain or range space (depending on "type) of "space" by "set".
14366 */
14369{
14370 if (type == isl_dim_in) {
14371 space = isl_space_range(space);
14373 } else {
14374 space = isl_space_domain(space);
14376 }
14377
14378 return space;
14379}
14380
14381/* Compute the preimage of the domain or range (depending on "type")
14382 * of "bmap" under the function represented by "ma".
14383 * In other words, plug in "ma" in the domain or range of "bmap".
14384 * The result is a basic map that lives in the same space as "bmap"
14385 * except that the domain or range has been replaced by
14386 * the domain space of "ma".
14387 *
14388 * If bmap is represented by
14389 *
14390 * A(p) + S u + B x + T v + C(divs) >= 0,
14391 *
14392 * where u and x are input and output dimensions if type == isl_dim_out
14393 * while x and v are input and output dimensions if type == isl_dim_in,
14394 * and ma is represented by
14395 *
14396 * x = D(p) + F(y) + G(divs')
14397 *
14398 * then the result is
14399 *
14400 * A(p) + B D(p) + S u + B F(y) + T v + B G(divs') + C(divs) >= 0
14401 *
14402 * The divs in the input set are similarly adjusted.
14403 * In particular
14404 *
14405 * floor((a_i(p) + s u + b_i x + t v + c_i(divs))/n_i)
14406 *
14407 * becomes
14408 *
14409 * floor((a_i(p) + b_i D(p) + s u + b_i F(y) + t v +
14410 * B_i G(divs') + c_i(divs))/n_i)
14411 *
14412 * If bmap is not a rational map and if F(y) involves any denominators
14413 *
14414 * x_i = (f_i y + h_i)/m_i
14415 *
14416 * then additional constraints are added to ensure that we only
14417 * map back integer points. That is we enforce
14418 *
14419 * f_i y + h_i = m_i alpha_i
14420 *
14421 * with alpha_i an additional existentially quantified variable.
14422 *
14423 * We first copy over the divs from "ma".
14424 * Then we add the modified constraints and divs from "bmap".
14425 * Finally, we add the stride constraints, if needed.
14426 */
14430{
14431 int i, k;
14432 isl_space *space;
14433 isl_basic_map *res = NULL;
14434 isl_size n_before, n_after, n_div_bmap, n_div_ma;
14435 isl_int f, c1, c2, g;
14436 isl_bool rational;
14437 int strides;
14438
14439 isl_int_init(f);
14442 isl_int_init(g);
14443
14445 if (!bmap || !ma)
14446 goto error;
14448 goto error;
14449
14450 if (type == isl_dim_in) {
14451 n_before = 0;
14452 n_after = isl_basic_map_dim(bmap, isl_dim_out);
14453 } else {
14454 n_before = isl_basic_map_dim(bmap, isl_dim_in);
14455 n_after = 0;
14456 }
14457 n_div_bmap = isl_basic_map_dim(bmap, isl_dim_div);
14458 n_div_ma = ma->n ? isl_aff_dim(ma->u.p[0], isl_dim_div) : 0;
14459 if (n_before < 0 || n_after < 0 || n_div_bmap < 0 || n_div_ma < 0)
14460 goto error;
14461
14462 space = isl_multi_aff_get_domain_space(ma);
14463 space = isl_space_set(isl_basic_map_get_space(bmap), type, space);
14464 rational = isl_basic_map_is_rational(bmap);
14465 strides = rational ? 0 : multi_aff_strides(ma);
14466 res = isl_basic_map_alloc_space(space, n_div_ma + n_div_bmap + strides,
14467 bmap->n_eq + strides, bmap->n_ineq + 2 * n_div_ma);
14468 if (rational)
14470
14471 for (i = 0; i < n_div_ma + n_div_bmap; ++i)
14473 goto error;
14474
14475 res = set_ma_divs(res, ma, n_before, n_after, n_div_ma);
14476 if (!res)
14477 goto error;
14478
14479 for (i = 0; i < bmap->n_eq; ++i) {
14481 if (k < 0)
14482 goto error;
14483 if (isl_seq_preimage(res->eq[k], bmap->eq[i], ma, n_before,
14484 n_after, n_div_ma, n_div_bmap,
14485 f, c1, c2, g, 0) < 0)
14486 goto error;
14487 }
14488
14489 for (i = 0; i < bmap->n_ineq; ++i) {
14491 if (k < 0)
14492 goto error;
14493 if (isl_seq_preimage(res->ineq[k], bmap->ineq[i], ma, n_before,
14494 n_after, n_div_ma, n_div_bmap,
14495 f, c1, c2, g, 0) < 0)
14496 goto error;
14497 }
14498
14499 for (i = 0; i < bmap->n_div; ++i) {
14500 if (isl_int_is_zero(bmap->div[i][0])) {
14501 isl_int_set_si(res->div[n_div_ma + i][0], 0);
14502 continue;
14503 }
14504 if (isl_seq_preimage(res->div[n_div_ma + i], bmap->div[i], ma,
14505 n_before, n_after, n_div_ma, n_div_bmap,
14506 f, c1, c2, g, 1) < 0)
14507 goto error;
14508 }
14509
14510 if (strides)
14511 res = add_ma_strides(res, ma, n_before, n_after, n_div_ma);
14512
14516 isl_int_clear(g);
14517 isl_basic_map_free(bmap);
14518 isl_multi_aff_free(ma);
14521error:
14525 isl_int_clear(g);
14526 isl_basic_map_free(bmap);
14527 isl_multi_aff_free(ma);
14529 return NULL;
14530}
14531
14532/* Compute the preimage of "bset" under the function represented by "ma".
14533 * In other words, plug in "ma" in "bset". The result is a basic set
14534 * that lives in the domain space of "ma".
14535 */
14541
14542/* Compute the preimage of the domain of "bmap" under the function
14543 * represented by "ma".
14544 * In other words, plug in "ma" in the domain of "bmap".
14545 * The result is a basic map that lives in the same space as "bmap"
14546 * except that the domain has been replaced by the domain space of "ma".
14547 */
14553
14554/* Compute the preimage of the range of "bmap" under the function
14555 * represented by "ma".
14556 * In other words, plug in "ma" in the range of "bmap".
14557 * The result is a basic map that lives in the same space as "bmap"
14558 * except that the range has been replaced by the domain space of "ma".
14559 */
14565
14566/* Check if the range of "ma" is compatible with the domain or range
14567 * (depending on "type") of "map".
14568 * Return isl_stat_error if anything is wrong.
14569 */
14573{
14574 isl_bool m;
14575 isl_space *ma_space;
14576
14577 ma_space = isl_multi_aff_get_space(ma);
14579 isl_space_free(ma_space);
14580 if (m < 0)
14581 return isl_stat_error;
14582 if (!m)
14584 "spaces don't match", return isl_stat_error);
14585 return isl_stat_ok;
14586}
14587
14588/* Compute the preimage of the domain or range (depending on "type")
14589 * of "map" under the function represented by "ma".
14590 * In other words, plug in "ma" in the domain or range of "map".
14591 * The result is a map that lives in the same space as "map"
14592 * except that the domain or range has been replaced by
14593 * the domain space of "ma".
14594 *
14595 * The parameters are assumed to have been aligned.
14596 */
14599{
14600 int i;
14601 isl_space *space;
14602
14603 map = isl_map_cow(map);
14605 if (!map || !ma)
14606 goto error;
14608 goto error;
14609
14610 for (i = 0; i < map->n; ++i) {
14612 isl_multi_aff_copy(ma));
14613 if (!map->p[i])
14614 goto error;
14615 }
14616
14617 space = isl_multi_aff_get_domain_space(ma);
14618 space = isl_space_set(isl_map_get_space(map), type, space);
14619
14621 map = isl_map_restore_space(map, space);
14622 if (!map)
14623 goto error;
14624
14625 isl_multi_aff_free(ma);
14626 if (map->n > 1)
14629 return map;
14630error:
14631 isl_multi_aff_free(ma);
14633 return NULL;
14634}
14635
14636/* Compute the preimage of the domain or range (depending on "type")
14637 * of "map" under the function represented by "ma".
14638 * In other words, plug in "ma" in the domain or range of "map".
14639 * The result is a map that lives in the same space as "map"
14640 * except that the domain or range has been replaced by
14641 * the domain space of "ma".
14642 */
14645{
14646 isl_bool aligned;
14647
14648 if (!map || !ma)
14649 goto error;
14650
14651 aligned = isl_map_space_has_equal_params(map, ma->space);
14652 if (aligned < 0)
14653 goto error;
14654 if (aligned)
14656
14658 goto error;
14659 if (!isl_space_has_named_params(ma->space))
14661 "unaligned unnamed parameters", goto error);
14662 map = isl_map_align_params(map, isl_multi_aff_get_space(ma));
14663 ma = isl_multi_aff_align_params(ma, isl_map_get_space(map));
14664
14666error:
14667 isl_multi_aff_free(ma);
14668 return isl_map_free(map);
14669}
14670
14671/* Compute the preimage of "set" under the function represented by "ma".
14672 * In other words, plug in "ma" in "set". The result is a set
14673 * that lives in the domain space of "ma".
14674 */
14680
14681/* Compute the preimage of the domain of "map" under the function
14682 * represented by "ma".
14683 * In other words, plug in "ma" in the domain of "map".
14684 * The result is a map that lives in the same space as "map"
14685 * except that the domain has been replaced by the domain space of "ma".
14686 */
14692
14693/* Compute the preimage of the range of "map" under the function
14694 * represented by "ma".
14695 * In other words, plug in "ma" in the range of "map".
14696 * The result is a map that lives in the same space as "map"
14697 * except that the range has been replaced by the domain space of "ma".
14698 */
14704
14705/* Compute the preimage of "map" under the function represented by "pma".
14706 * In other words, plug in "pma" in the domain or range of "map".
14707 * The result is a map that lives in the same space as "map",
14708 * except that the space of type "type" has been replaced by
14709 * the domain space of "pma".
14710 *
14711 * The parameters of "map" and "pma" are assumed to have been aligned.
14712 */
14716{
14717 int i;
14718 isl_map *res;
14719
14720 if (!pma)
14721 goto error;
14722
14723 if (pma->n == 0) {
14724 isl_space *space;
14725
14728 space = isl_space_set(isl_map_get_space(map), type, space);
14730 return isl_map_empty(space);
14731 }
14732
14734 isl_multi_aff_copy(pma->p[0].maff));
14735 if (type == isl_dim_in)
14737 isl_map_copy(pma->p[0].set));
14738 else
14740 isl_map_copy(pma->p[0].set));
14741
14742 for (i = 1; i < pma->n; ++i) {
14743 isl_map *res_i;
14744
14746 isl_multi_aff_copy(pma->p[i].maff));
14747 if (type == isl_dim_in)
14748 res_i = isl_map_intersect_domain(res_i,
14749 isl_map_copy(pma->p[i].set));
14750 else
14751 res_i = isl_map_intersect_range(res_i,
14752 isl_map_copy(pma->p[i].set));
14753 res = isl_map_union(res, res_i);
14754 }
14755
14758 return res;
14759error:
14762 return NULL;
14763}
14764
14765/* Compute the preimage of "map" under the function represented by "pma".
14766 * In other words, plug in "pma" in the domain or range of "map".
14767 * The result is a map that lives in the same space as "map",
14768 * except that the space of type "type" has been replaced by
14769 * the domain space of "pma".
14770 */
14773{
14774 isl_bool aligned;
14775
14776 if (!map || !pma)
14777 goto error;
14778
14779 aligned = isl_map_space_has_equal_params(map, pma->dim);
14780 if (aligned < 0)
14781 goto error;
14782 if (aligned)
14784
14786 goto error;
14788 goto error;
14791
14793error:
14795 return isl_map_free(map);
14796}
14797
14798/* Compute the preimage of "set" under the function represented by "pma".
14799 * In other words, plug in "pma" in "set". The result is a set
14800 * that lives in the domain space of "pma".
14801 */
14807
14808/* Compute the preimage of the domain of "map" under the function
14809 * represented by "pma".
14810 * In other words, plug in "pma" in the domain of "map".
14811 * The result is a map that lives in the same space as "map",
14812 * except that domain space has been replaced by the domain space of "pma".
14813 */
14819
14820/* Compute the preimage of the range of "map" under the function
14821 * represented by "pma".
14822 * In other words, plug in "pma" in the range of "map".
14823 * The result is a map that lives in the same space as "map",
14824 * except that range space has been replaced by the domain space of "pma".
14825 */
14831
14832/* Compute the preimage of "map" under the function represented by "mpa".
14833 * In other words, plug in "mpa" in the domain or range of "map".
14834 * The result is a map that lives in the same space as "map",
14835 * except that the space of type "type" has been replaced by
14836 * the domain space of "mpa".
14837 *
14838 * If the map does not involve any constraints that refer to the
14839 * dimensions of the substituted space, then the only possible
14840 * effect of "mpa" on the map is to map the space to a different space.
14841 * We create a separate isl_multi_aff to effectuate this change
14842 * in order to avoid spurious splitting of the map along the pieces
14843 * of "mpa".
14844 * If "mpa" has a non-trivial explicit domain, however,
14845 * then the full substitution should be performed.
14846 */
14849{
14850 isl_size n;
14851 isl_bool full;
14853
14854 n = isl_map_dim(map, type);
14855 if (n < 0 || !mpa)
14856 goto error;
14857
14858 full = isl_map_involves_dims(map, type, 0, n);
14859 if (full >= 0 && !full)
14861 if (full < 0)
14862 goto error;
14863 if (!full) {
14864 isl_space *space;
14866
14867 space = isl_multi_pw_aff_get_space(mpa);
14868 isl_multi_pw_aff_free(mpa);
14869 ma = isl_multi_aff_zero(space);
14871 }
14872
14875error:
14877 isl_multi_pw_aff_free(mpa);
14878 return NULL;
14879}
14880
14881/* Compute the preimage of "map" under the function represented by "mpa".
14882 * In other words, plug in "mpa" in the domain "map".
14883 * The result is a map that lives in the same space as "map",
14884 * except that domain space has been replaced by the domain space of "mpa".
14885 */
14891
14892/* Compute the preimage of "set" by the function represented by "mpa".
14893 * In other words, plug in "mpa" in "set".
14894 */
14900
14901/* Given that inequality "ineq" of "bmap" expresses an upper bound
14902 * on the output dimension "pos" in terms of the parameters,
14903 * the input dimensions and possibly some integer divisions,
14904 * but not any other output dimensions, extract this upper bound
14905 * as a function of all dimensions (with zero coefficients
14906 * for the output dimensions).
14907 *
14908 * That is, the inequality is of the form
14909 *
14910 * e(...) + c - m x >= 0
14911 *
14912 * where e does not depend on any other output dimensions.
14913 * Return (e(...) + c) / m, with the denominator m in the first position.
14914 */
14916 __isl_keep isl_basic_map *bmap, int ineq, int pos)
14917{
14918 isl_ctx *ctx;
14919 isl_size v_out, total;
14920
14923 if (v_out < 0 || total < 0)
14924 return NULL;
14925 ctx = isl_basic_map_get_ctx(bmap);
14926 return extract_bound_from_constraint(ctx, bmap->ineq[ineq],
14927 total, v_out + pos);
14928}
14929
14930/* Is constraint "c" of "bmap" of the form
14931 *
14932 * e(...) + c1 - m x >= 0
14933 *
14934 * or
14935 *
14936 * -e(...) + c2 + m x >= 0
14937 *
14938 * where m > 1 and e does not involve any other output variables?
14939 *
14940 * "v_out" is the offset to the output variables.
14941 * "d" is the position of x among the output variables.
14942 * "v_div" is the offset to the local variables.
14943 * "total" is the total number of variables.
14944 *
14945 * Since the purpose of this function is to use the constraint
14946 * to express the output variable as an integer division,
14947 * do not allow the constraint to involve any local variables
14948 * that do not have an explicit representation.
14949 */
14951 isl_int *c, int v_out, int d, int v_div, int total)
14952{
14953 int i = 0;
14954
14955 if (isl_int_is_zero(c[1 + v_out + d]))
14956 return isl_bool_false;
14957 if (isl_int_is_one(c[1 + v_out + d]))
14958 return isl_bool_false;
14959 if (isl_int_is_negone(c[1 + v_out + d]))
14960 return isl_bool_false;
14961 if (isl_seq_any_non_zero(c + 1 + v_out, d))
14962 return isl_bool_false;
14963 if (isl_seq_any_non_zero(c + 1 + v_out + d + 1, v_div - (v_out + d + 1)))
14964 return isl_bool_false;
14965 for (i = 0; v_div + i < total; ++i) {
14966 isl_bool known, involves;
14967
14968 if (isl_int_is_zero(c[1 + v_div + i]))
14969 continue;
14970 known = isl_basic_map_div_is_known(bmap, i);
14971 if (known < 0 || !known)
14972 return known;
14973 involves = div_involves_vars(bmap, i, v_out, v_div - v_out);
14974 if (involves < 0 || involves)
14975 return isl_bool_not(involves);
14976 }
14977 return isl_bool_true;
14978}
14979
14980/* Look for a pair of constraints
14981 *
14982 * e(...) + c1 - m x >= 0 i.e., m x <= e(...) + c1
14983 *
14984 * and
14985 *
14986 * -e(...) + c2 + m x >= 0 i.e., m x >= e(...) - c2
14987 *
14988 * that express that the output dimension x at position "pos"
14989 * is some integer division of an expression in terms of the parameters,
14990 * input dimensions and integer divisions.
14991 * If such a pair can be found, then return the index
14992 * of the upper bound constraint, m x <= e(...) + c1.
14993 * Otherwise, return an index beyond the number of constraints.
14994 *
14995 * The constraints of "bmap" are assumed to have been sorted.
14996 *
14997 * In order for the constraints above to express an integer division,
14998 * m needs to be greater than 1 and such that
14999 *
15000 * c1 + c2 < m i.e., -c2 >= c1 - (m - 1)
15001 *
15002 * In particular, this ensures that
15003 *
15004 * x = floor((e(...) + c1) / m)
15005 */
15007 __isl_keep isl_basic_map *bmap, int pos)
15008{
15009 int i;
15010 isl_size j;
15011 isl_size n_ineq;
15012 isl_size v_out, v_div;
15014 isl_int sum;
15015
15019 n_ineq = isl_basic_map_n_inequality(bmap);
15020 if (total < 0 || v_out < 0 || v_div < 0 || n_ineq < 0)
15021 return isl_size_error;
15022
15023 isl_int_init(sum);
15024 for (i = 0; i < n_ineq; ++i) {
15025 isl_bool potential;
15026
15027 potential = is_potential_div_constraint(bmap, bmap->ineq[i],
15028 v_out, pos, v_div, total);
15029 if (potential < 0)
15030 goto error;
15031 if (!potential)
15032 continue;
15033
15034 j = find_later_constraint_in_pair(bmap, i, v_out + pos, total,
15035 bmap->ineq[i][1 + v_out + pos], &sum);
15036 if (j < 0)
15037 goto error;
15038 if (j < n_ineq)
15039 break;
15040 }
15041 isl_int_clear(sum);
15042
15043 if (i >= n_ineq)
15044 return n_ineq;
15045 if (isl_int_is_pos(bmap->ineq[j][1 + v_out + pos]))
15046 return i;
15047 else
15048 return j;
15049error:
15050 isl_int_clear(sum);
15051 return isl_size_error;
15052}
15053
15054/* Look for a pair of constraints
15055 *
15056 * -g(x) + i >= 0
15057 * g(x) - i + d >= 0
15058 *
15059 * in "bmap" on the output dimension at position "pos" such that
15060 * g(x) is an expression in the parameters and input dimensions, and
15061 * d < "n".
15062 * Return the index of the first constraint if such a pair can be found.
15063 * Otherwise, return an index beyond the number of inequality constraints.
15064 *
15065 * The constraints are assumed to have been sorted.
15066 */
15068 int pos, isl_int n)
15069{
15070 int i;
15071 isl_size n_ineq;
15072 isl_size v_out, n_out;
15073 isl_size v_div, n_div;
15074 isl_size j;
15075 isl_int tmp;
15076
15077 n_ineq = isl_basic_map_n_inequality(bmap);
15079 n_out = isl_basic_map_dim(bmap, isl_dim_out);
15081 n_div = isl_basic_map_dim(bmap, isl_dim_div);
15082 if (n_ineq < 0 || v_out < 0 || n_out < 0 || v_div < 0 || n_div < 0)
15083 return isl_size_error;
15084
15085 isl_int_init(tmp);
15086 for (i = n_ineq - 1; i >= 0; --i) {
15087 if (!isl_int_is_one(bmap->ineq[i][1 + v_out + pos]) &&
15088 !isl_int_is_negone(bmap->ineq[i][1 + v_out + pos]))
15089 continue;
15090 if (isl_seq_any_non_zero(bmap->ineq[i] + 1 + v_div, n_div))
15091 continue;
15092 if (isl_seq_any_non_zero(bmap->ineq[i] + 1 + v_out, pos))
15093 continue;
15094 if (isl_seq_any_non_zero(bmap->ineq[i] + 1 + v_out + pos + 1,
15095 n_out - (pos + 1)))
15096 continue;
15097 j = find_earlier_constraint_in_pair(bmap, i, v_out + pos, v_div,
15098 n, &tmp);
15099 if (j >= n_ineq)
15100 continue;
15101 isl_int_clear(tmp);
15102 if (j < 0)
15103 return j;
15104 if (isl_int_is_one(bmap->ineq[i][1 + v_out + pos]))
15105 return i;
15106 return j;
15107 }
15108
15109 isl_int_clear(tmp);
15110 return n_ineq;
15111}
15112
15113/* Turn "bmap" into a basic set for constructing an affine expression
15114 * that can later be plugged into an output dimension of "bmap".
15115 * "is_set" is set if "bmap" is actually a basic set already.
15116 *
15117 * If "bmap" is a basic set already, then simply cast it.
15118 * Otherwise, wrap "bmap" into a basic set.
15119 */
15121 __isl_take isl_basic_map *bmap, int is_set)
15122{
15123 if (is_set)
15124 return bset_from_bmap(bmap);
15125 else
15126 return isl_basic_map_wrap(bmap);
15127}
15128
15129/* Given an affine expression "aff" that was constructed on top of
15130 * the result of wrap_for_plug_in and that does not depend on the output space,
15131 * project out this output space.
15132 * "is_set" is the same as in the call to wrap_for_plug_in.
15133 *
15134 * If "is_set" is set then the output space is actually the set space
15135 * of the original basic set and this appears as the domain of "aff".
15136 * Otherwise, the output space appears as the range in the nested domain.
15137 */
15139{
15140 if (is_set)
15142 else
15144}
15145
15146/* Given that equality "eq" of "bset" expresses
15147 * the variable at position "pos" in terms of the other variables,
15148 * extract this expression as a function of those other variables,
15149 * excluding any local variables.
15150 */
15152 __isl_keep isl_basic_set *bset, int eq, int pos)
15153{
15154 if (!bset)
15155 return NULL;
15156 return extract_aff(bset, bset->eq[eq], pos);
15157}
15158
15159/* Given an integer division "div" of the form
15160 *
15161 * (f(x) + a i)//m
15162 *
15163 * with i the variable at position "pos" and f not involving
15164 * any local variables, return the expression
15165 *
15166 * -f(x)/a
15167 */
15169 __isl_keep isl_basic_set *bset, int div, int pos)
15170{
15171 if (!bset)
15172 return NULL;
15173 return extract_aff(bset, bset->div[div] + 1, pos);
15174}
15175
15176/* Given the presence in "bmap" of an equality constraint "eq"
15177 *
15178 * f(x) + t m i + m n h(y) = 0
15179 *
15180 * and a pair of inequality constraints
15181 *
15182 * -g(x) + i >= 0 ("lower")
15183 * g(x) - i + d >= 0
15184 *
15185 * where i is the output dimension at position "pos",
15186 * f(x) and g(x) are expressions in the parameters and
15187 * input dimensions (if any),
15188 * h(y) is an expression in the other output dimensions,
15189 * t is +1 or -1, and
15190 * d < "n",
15191 * return the expression
15192 *
15193 * (-t f(x)/m - g(x)) mod n + g(x)
15194 *
15195 * The expression is first constructed in terms of the wrapped space of "bmap".
15196 * Since this expression does not depend on the original output dimensions,
15197 * they can be removed, resulting in an expression in terms
15198 * of the input dimensions.
15199 * If "bmap" is actually a set, then the resulting expression has no domain.
15200 *
15201 * Also note that the "f" variable contains "-t (f(x)/m + n h(y))"
15202 * but the "n h(y)" part is removed by taking the modulo with respect to n.
15203 */
15205 int pos, int eq, int lower, isl_int n)
15206{
15207 isl_ctx *ctx;
15208 isl_basic_set *bset;
15209 isl_aff *f, *g, *mod;
15210 isl_val *v;
15211 isl_bool is_set;
15212
15213 is_set = isl_basic_map_is_set(bmap);
15214 if (is_set < 0)
15215 return NULL;
15216 ctx = isl_basic_map_get_ctx(bmap);
15217
15218 bset = wrap_for_plug_in(isl_basic_map_copy(bmap), is_set);
15219 g = extract_lower_bound_aff(bset, lower, pos);
15220 f = extract_expr_aff(bset, eq, pos);
15221 isl_basic_set_free(bset);
15222
15223 mod = isl_aff_sub(f, isl_aff_copy(g));
15225 mod = isl_aff_mod_val(mod, v);
15226 mod = isl_aff_add(mod, g);
15227 mod = unwrap_plug_in(mod, is_set);
15228
15229 return mod;
15230}
15231
15232/* Look for a combination of constraints in "bmap" (including
15233 * an equality constraint) that ensure
15234 * that output dimension "pos" is equal to some modulo expression
15235 * in the parameters and input dimensions and
15236 * return this expression if found.
15237 *
15238 * The constraints are assumed to have been sorted.
15239 *
15240 * In particular look for an equality constraint
15241 *
15242 * f(x) + t m i + m n h(y) = 0
15243 *
15244 * and a pair of inequality constraints
15245 *
15246 * -g(x) + i >= 0
15247 * g(x) - i + d >= 0
15248 *
15249 * where f(x) and g(x) are expressions in the parameters and input dimensions,
15250 * h(y) is an expression in local variables and other output dimensions,
15251 * t is +1 or -1, and
15252 * d < n.
15253 *
15254 * If such a combination of constraints can be found
15255 * then
15256 *
15257 * i = -t f(x)/m - t n h(y)
15258 * i - g(x) = -t f(x)/m - t n h(y) - g(x)
15259 *
15260 * and so, because 0 <= i - g(x) <= d < n,
15261 *
15262 * i - g(x) = (-t f(x)/m - t n h(y) - g(x)) mod n
15263 * = (-t f(x)/m - g(x)) mod n
15264 *
15265 * That is,
15266 *
15267 * i = (-t f(x)/m - g(x)) mod n + g(x)
15268 */
15270 __isl_keep isl_basic_map *bmap, int pos)
15271{
15272 int i, j;
15273 isl_size n_eq, n_ineq;
15274 isl_size v_out, n_out;
15275 isl_size v_div, n_div;
15276 isl_size lower;
15277 isl_int gcd;
15278 isl_maybe_isl_aff res = { isl_bool_false, NULL };
15279
15280 n_eq = isl_basic_map_n_equality(bmap);
15281 n_ineq = isl_basic_map_n_inequality(bmap);
15283 n_out = isl_basic_map_dim(bmap, isl_dim_out);
15285 n_div = isl_basic_map_dim(bmap, isl_dim_div);
15286 if (n_eq < 0 || n_ineq < 0 ||
15287 v_out < 0 || n_out < 0 || v_div < 0 || n_div < 0)
15288 goto error;
15289 if (n_eq == 0 || n_ineq < 2 || n_out == 1)
15290 return res;
15291
15293 for (i = 0; i < n_eq; ++i) {
15294 if (isl_int_is_zero(bmap->eq[i][1 + v_out + pos]))
15295 continue;
15296 isl_seq_gcd(bmap->eq[i] + 1 + v_div, n_div, &gcd);
15297 for (j = 0; j < n_out; ++j) {
15298 if (j == pos)
15299 continue;
15300 isl_int_gcd(gcd, gcd, bmap->eq[i][1 + v_out + j]);
15301 }
15302 if (!isl_int_abs_gt(gcd, bmap->eq[i][1 + v_out + pos]))
15303 continue;
15304 if (!isl_int_is_divisible_by(gcd, bmap->eq[i][1 + v_out + pos]))
15305 continue;
15306 isl_int_divexact(gcd, gcd, bmap->eq[i][1 + v_out + pos]);
15309 if (lower >= n_ineq)
15310 continue;
15311 res.valid = isl_bool_true;
15312 if (lower >= 0)
15313 res.value = construct_mod(bmap, v_out + pos, i,
15314 lower, gcd);
15315 if (!res.value)
15316 res.valid = isl_bool_error;
15318 return res;
15319 }
15320
15322 return res;
15323error:
15324 res.valid = isl_bool_error;
15325 return res;
15326}
15327
15328/* Given that the integer division "div" of "bmap" is of the form
15329 *
15330 * (f(x) + t m i)//(m n)
15331 *
15332 * with t equal to 1 or -1 and n positive,
15333 * while the inequality constraint "lower" is of the form
15334 *
15335 * -g(x) + i >= 0
15336 *
15337 * with neither involving any local variables or output dimensions other than i,
15338 * construct the expression
15339 *
15340 * (t (n - 1) - t f(x)//m - g(x)) mod n + g(x)
15341 *
15342 * "pos" is the position of the variable i.
15343 * "t" and "n" are the values t and n.
15344 *
15345 * The expression is first constructed in terms of the wrapped space of "bmap".
15346 * Since this expression does not depend on the original output dimensions,
15347 * these can be removed, resulting in an expression in terms
15348 * of the input dimensions.
15349 * If "bmap" is actually a set, then the resulting expression has no domain.
15350 *
15351 * First obtain the expressions
15352 *
15353 * -t f(x)/m
15354 * g(x)
15355 *
15356 * multiply the first with -t, take the floor and multiply with -t again,
15357 * to obtain
15358 *
15359 * -t f(x)//m
15360 *
15361 * Add t (n - 1) and subtract g(x) to obtain
15362 *
15363 * t (n - 1) - t f(x)//m - g(x)
15364 *
15365 * Finally, compute the modulo with respect to m and add g(x) back.
15366 */
15368 int pos, int div, int lower, int t, isl_int n)
15369{
15370 isl_ctx *ctx;
15371 isl_basic_set *bset;
15372 isl_aff *f, *g;
15373 isl_val *v;
15374 isl_bool is_set;
15375
15376 is_set = isl_basic_map_is_set(bmap);
15377 if (is_set < 0)
15378 return NULL;
15379 ctx = isl_basic_map_get_ctx(bmap);
15380
15381 bset = wrap_for_plug_in(isl_basic_map_copy(bmap), is_set);
15382 f = extract_div_expr_aff(bset, div, pos);
15383 g = extract_lower_bound_aff(bset, lower, pos);
15384 isl_basic_set_free(bset);
15385
15386 if (t > 0)
15387 isl_aff_neg(f);
15388 f = isl_aff_floor(f);
15389 if (t > 0)
15390 isl_aff_neg(f);
15391
15393 v = isl_val_sub_ui(v, 1);
15394 if (t < 0)
15395 v = isl_val_neg(v);
15397
15398 f = isl_aff_sub(f, isl_aff_copy(g));
15400 f = isl_aff_mod_val(f, v);
15401 f = isl_aff_add(f, g);
15402
15403 f = unwrap_plug_in(f, is_set);
15404
15405 return f;
15406}
15407
15408/* Given that inequality constraint "ineq" of "bmap" is of the form
15409 *
15410 * f(x) + t m i - m n e + c >= 0
15411 *
15412 * with integer division "e" of the form
15413 *
15414 * e = (f(x) + t m i)//(m n)
15415 *
15416 * f(x) an expression in the parameters and input dimensions and
15417 * t is +1 or -1,
15418 * check whether c <= -(n - 1) m and then look for
15419 * a pair of inequality constraints
15420 *
15421 * -g(x) + i >= 0
15422 * g(x) - i + d >= 0
15423 *
15424 * where g(x) is an expression in the parameters and input dimensions and
15425 * d < n.
15426 * If successful, return the expression
15427 *
15428 * (t (n - 1) - t f(x)//m - g(x)) mod n + g(x)
15429 *
15430 * "v_out" is the position of the output dimensions among the variables.
15431 * "pos" is the position of the output dimension i.
15432 * "n_ineq" is the number of inequality constraints.
15433 * "v_div" is the position of the local dimensions among the variables.
15434 *
15435 *
15436 * First extract the constant value "n".
15437 * If c' is the constant term of f(x), then the constant term
15438 * of the inequality constraint is c' + c.
15439 * Check that c' + c <= c' - (n - 1) m.
15440 * If so, and if the pair of inequality constraints can be found,
15441 * then extract the expression above.
15442 */
15444 __isl_keep isl_basic_map *bmap, int v_out, int pos,
15445 int ineq, int n_ineq, int v_div, int e)
15446{
15447 isl_int n, t;
15448 isl_size lower;
15449 isl_maybe_isl_aff res = { isl_bool_false, NULL };
15450
15451 isl_int_init(n);
15452 isl_int_init(t);
15453
15454 isl_int_divexact(n, bmap->ineq[ineq][1 + v_div + e],
15455 bmap->ineq[ineq][1 + v_out + pos]);
15456 isl_int_abs(n, n);
15457 isl_int_sub_ui(t, n, 1);
15458 isl_int_mul(t, t, bmap->ineq[ineq][1 + v_out + pos]);
15459 isl_int_abs(t, t);
15460 isl_int_neg(t, t);
15461 isl_int_add(t, t, bmap->div[e][1]);
15462 if (isl_int_le(bmap->ineq[ineq][0], t)) {
15463 lower = find_output_lower_mod_constraint(bmap, pos, n);
15464 if (lower < n_ineq) {
15465 int t;
15466
15467 t = isl_int_sgn(bmap->ineq[ineq][1 + v_out + pos]);
15468 res.valid = isl_bool_true;
15469 res.value = construct_mod_ineq(bmap, v_out + pos,
15470 e, lower, t, n);
15471 }
15472 }
15473
15476
15477 return res;
15478}
15479
15480/* In the sequence of length "len" starting at "p",
15481 * is the element at "pos" the only non-zero element?
15482 */
15483static int only_non_zero(isl_int *p, unsigned pos, unsigned len)
15484{
15485 if (isl_int_is_zero(p[pos]))
15486 return 0;
15487 return unique(p, pos, len);
15488}
15489
15490/* Look for a combination of inequality constraints in "bmap" that ensure
15491 * that output dimension "pos" is equal to some modulo expression
15492 * in the parameters and input dimensions and
15493 * return this expression if found.
15494 *
15495 * The constraints are assumed to have been sorted.
15496 *
15497 * In particular, look for an integer division of the form
15498 *
15499 * e = (f(x) + t m i)//(m n)
15500 *
15501 * with a corresponding inequality constraint
15502 *
15503 * f(x) + t m i - m n e + c >= 0 (*)
15504 *
15505 * and a pair of inequality constraints
15506 *
15507 * -g(x) + i >= 0
15508 * g(x) - i + d >= 0
15509 *
15510 * where f(x) and g(x) are expressions in the parameters and input dimensions,
15511 * c <= -(n - 1) m
15512 * t is +1 or -1, and
15513 * d < n.
15514 *
15515 * Note that
15516 *
15517 * e = (f(x) + t m i)//(m n) = (f(x)//m + t i)//n
15518 *
15519 * and so
15520 *
15521 * f(x)//m + t i - (n - 1) <= n e <= f(x)//m + t i
15522 *
15523 * and in particular
15524 *
15525 * f(x)//m <= - t i + n e + (n - 1)
15526 *
15527 * Constraint (*) implies
15528 *
15529 * f(x) >= -t m i + m n e - c >= -t m i + m n e + (n - 1) m
15530 *
15531 * and so
15532 *
15533 * f(x)//m >= - t i + n e + (n - 1)
15534 *
15535 * Together, this implies
15536 *
15537 * f(x)//m = -t i + n e + (n - 1)
15538 * t i = n e + (n - 1) - f(x)//m
15539 * i = t n e + t (n - 1) - t f(x)//m
15540 * i - g(x) = t n e + t (n - 1) - t f(x)//m - g(x)
15541 *
15542 * and so, because 0 <= i - g(x) <= d < n,
15543 *
15544 * i - g(x) = (t (n - 1) - t f(x)//m - g(x)) mod n
15545 *
15546 * That is,
15547 *
15548 * i = (t (n - 1) - t f(x)//m - g(x)) mod n + g(x)
15549 *
15550 *
15551 * First look for a suitable inequality constraint for (*),
15552 * with the corresponding integer division.
15553 * If any such combination is found, look for an appropriate g(x) and
15554 * construct the corresponding expression in try_find_output_mod_ineq_at.
15555 */
15557 __isl_keep isl_basic_map *bmap, int pos)
15558{
15559 int i;
15560 isl_size n_ineq;
15561 isl_size v_out, n_out;
15562 isl_size v_div, n_div;
15563 isl_maybe_isl_aff no = { isl_bool_false, NULL };
15564 isl_maybe_isl_aff error = { isl_bool_error, NULL };
15565
15566 n_ineq = isl_basic_map_n_inequality(bmap);
15568 n_out = isl_basic_map_dim(bmap, isl_dim_out);
15570 n_div = isl_basic_map_dim(bmap, isl_dim_div);
15571 if (n_ineq < 0 || v_out < 0 || n_out < 0 || v_div < 0 || n_div < 0)
15572 return error;
15573 if (n_div < 1 || n_ineq < 4)
15574 return no;
15575
15576 for (i = 0; i < n_ineq; ++i) {
15577 isl_bool unknown;
15578 int e;
15579
15580 if (!only_non_zero(bmap->ineq[i] + 1 + v_out, pos, n_out))
15581 continue;
15582 e = isl_seq_last_non_zero(bmap->ineq[i] + 1 + v_div, n_div);
15583 if (e == -1)
15584 continue;
15585 unknown = isl_basic_map_div_is_marked_unknown(bmap, e);
15586 if (unknown < 0)
15587 return error;
15588 if (unknown)
15589 continue;
15590 if (isl_seq_any_non_zero(bmap->ineq[i] + 1 + v_div, e))
15591 continue;
15592 if (isl_int_is_pos(bmap->ineq[i][1 + v_div + e]))
15593 continue;
15594 if (!isl_int_is_divisible_by(bmap->ineq[i][1 + v_div + e],
15595 bmap->ineq[i][1 + v_out + pos]))
15596 continue;
15597 if (!isl_int_abs_eq(bmap->ineq[i][1 + v_div + e],
15598 bmap->div[e][0]))
15599 continue;
15600 if (!isl_seq_eq(bmap->ineq[i] + 1, bmap->div[e] + 2, v_div + e))
15601 continue;
15602 return try_find_output_mod_ineq_at(bmap, v_out, pos, i, n_ineq,
15603 v_div, e);
15604 }
15605
15606 return no;
15607}
15608
15609/* Look for a combination of constraints in "bmap" that ensure
15610 * that output dimension "pos" is equal to some modulo expression
15611 * in the parameters and input dimensions and
15612 * return this expression if found.
15613 *
15614 * The constraints are assumed to have been sorted.
15615 *
15616 * First look for a pattern involving an equality constraint and
15617 * then look for a pattern involving only inequality constraints.
15618 */
15620 __isl_keep isl_basic_map *bmap, int pos)
15621{
15622 isl_maybe_isl_aff mod;
15623
15625 if (mod.valid < 0 || mod.valid)
15626 return mod;
15628}
15629
15630/* Construct an isl_aff from the given domain local space "ls" and
15631 * coefficients "v", where the local space may involve
15632 * local variables without a known expression, as long as these
15633 * do not have a non-zero coefficient in "v".
15634 * These need to be pruned away first since an isl_aff cannot
15635 * reference any local variables without a known expression.
15636 * For simplicity, remove all local variables that have a zero coefficient and
15637 * that are not used in other local variables with a non-zero coefficient.
15638 */
15641{
15642 int i;
15643 isl_size n_div, v_div;
15644
15645 n_div = isl_local_space_dim(ls, isl_dim_div);
15647 if (n_div < 0 || v_div < 0 || !v)
15648 goto error;
15649 for (i = n_div - 1; i >= 0; --i) {
15650 isl_bool involves;
15651
15652 if (!isl_int_is_zero(v->el[1 + 1 + v_div + i]))
15653 continue;
15654 involves = isl_local_space_involves_dims(ls, isl_dim_div, i, 1);
15655 if (involves < 0)
15656 goto error;
15657 if (involves)
15658 continue;
15659 ls = isl_local_space_drop_dims(ls, isl_dim_div, i, 1);
15660 v = isl_vec_drop_els(v, 1 + 1 + v_div + i, 1);
15661 if (!v)
15662 goto error;
15663 }
15664
15665 return isl_aff_alloc_vec(ls, v);
15666error:
15668 isl_vec_free(v);
15669 return NULL;
15670}
15671
15672/* Look for a pair of constraints in "bmap" that ensure
15673 * that output dimension "pos" is equal to some integer division expression
15674 * in the parameters and input dimensions and
15675 * return this expression if found.
15676 *
15677 * In particular, looks for a pair of constraints
15678 *
15679 * e(...) + c1 - m x >= 0 i.e., m x <= e(...) + c1
15680 *
15681 * and
15682 *
15683 * -e(...) + c2 + m x >= 0 i.e., m x >= e(...) - c2
15684 *
15685 * where m > 1 and e only depends on parameters and input dimensions,
15686 * and such that
15687 *
15688 * c1 + c2 < m i.e., -c2 >= c1 - (m - 1)
15689 *
15690 * If such a pair of constraints can be found
15691 * then
15692 *
15693 * x = floor((e(...) + c1) / m)
15694 *
15695 * with e(...) an expression that does not involve any other output dimensions.
15696 *
15697 * Note that we know that
15698 *
15699 * c1 + c2 >= 1
15700 *
15701 * If c1 + c2 were 0, then we would have detected an equality during
15702 * simplification. If c1 + c2 were negative, then we would have detected
15703 * a contradiction.
15704 *
15705 * The constraint defining the integer division is guaranteed not to involve
15706 * any local variables without a known expression, but such local variables
15707 * may appear in other constraints. They therefore need to be removed
15708 * during the construction of the affine expression.
15709 */
15711 __isl_keep isl_basic_map *bmap, int pos)
15712{
15713 isl_size i;
15714 isl_size n_ineq;
15715 isl_maybe_isl_aff res = { isl_bool_false, NULL };
15716 isl_local_space *ls;
15717 isl_aff *aff;
15718 isl_vec *v;
15719 isl_bool is_set;
15720
15721 n_ineq = isl_basic_map_n_inequality(bmap);
15722 if (n_ineq < 0)
15723 goto error;
15724
15726 if (i < 0)
15727 goto error;
15728 if (i >= n_ineq)
15729 return res;
15730
15731 is_set = isl_basic_map_is_set(bmap);
15732 if (is_set < 0)
15733 bmap = isl_basic_map_free(bmap);
15734
15736 if (!is_set)
15737 ls = isl_local_space_wrap(ls);
15739
15742
15743 if (is_set)
15745 else
15747
15748 res.valid = isl_bool_true;
15749 res.value = aff;
15750 return res;
15751error:
15752 res.valid = isl_bool_error;
15753 return res;
15754}
15755
15756/* Look for a combination of constraints in "bmap" that ensure
15757 * that output dimension "pos" is equal to some integer division or
15758 * modulo expression in the parameters and input dimensions and
15759 * return this expression if found.
15760 */
15762 __isl_keep isl_basic_map *bmap, int pos)
15763{
15764 isl_maybe_isl_aff div;
15765
15767 if (div.valid < 0 || div.valid)
15768 return div;
15770}
15771
15772/* Look for a combination of constraints in "bmap" that ensure
15773 * that any output dimension is equal to some integer division or
15774 * modulo expression in the parameters and input dimensions and
15775 * return this expression if found.
15776 * The position of the output dimension (if any) is returned in "pos".
15777 */
15779 __isl_keep isl_basic_map *bmap, int *pos)
15780{
15781 isl_size dim;
15782 isl_maybe_isl_aff res = { isl_bool_false, NULL };
15783
15784 dim = isl_basic_map_dim(bmap, isl_dim_out);
15785 if (dim < 0)
15786 goto error;
15787
15788 for (*pos = 0; *pos < dim; ++*pos) {
15790 if (res.valid < 0 || res.valid)
15791 return res;
15792 }
15793
15794 return res;
15795error:
15796 res.valid = isl_bool_error;
15797 return res;
15798}
15799
15800/* Return a copy of the equality constraints of "bset" as a matrix.
15801 */
15804{
15805 isl_ctx *ctx;
15807
15809 if (total < 0)
15810 return NULL;
15811
15812 ctx = isl_basic_set_get_ctx(bset);
15813 return isl_mat_sub_alloc6(ctx, bset->eq, 0, bset->n_eq, 0, 1 + total);
15814}
15815
15816/* Are the "n" "coefficients" starting at "first" of the integer division
15817 * expressions at position "pos1" in "bmap1" and "pos2" in "bmap2" equal
15818 * to each other?
15819 * The "coefficient" at position 0 is the denominator.
15820 * The "coefficient" at position 1 is the constant term.
15821 */
15823 int pos1, __isl_keep isl_basic_map *bmap2, int pos2,
15824 unsigned first, unsigned n)
15825{
15826 if (isl_basic_map_check_range(bmap1, isl_dim_div, pos1, 1) < 0)
15827 return isl_bool_error;
15828 if (isl_basic_map_check_range(bmap2, isl_dim_div, pos2, 1) < 0)
15829 return isl_bool_error;
15830 return isl_seq_eq(bmap1->div[pos1] + first,
15831 bmap2->div[pos2] + first, n);
15832}
15833
15834/* Are the integer division expressions at position "pos1" in "bmap1" and
15835 * "pos2" in "bmap2" equal to each other, except that the constant terms
15836 * are different?
15837 */
15839 __isl_keep isl_basic_map *bmap1, int pos1,
15840 __isl_keep isl_basic_map *bmap2, int pos2)
15841{
15843 isl_size total, total2;
15844
15846 total2 = isl_basic_map_dim(bmap2, isl_dim_all);
15847 if (total < 0 || total2 < 0)
15848 return isl_bool_error;
15849 if (total != total2)
15851 "incomparable div expressions", return isl_bool_error);
15852 equal = isl_basic_map_equal_div_expr_part(bmap1, pos1, bmap2, pos2,
15853 0, 1);
15854 if (equal < 0 || !equal)
15855 return equal;
15856 equal = isl_basic_map_equal_div_expr_part(bmap1, pos1, bmap2, pos2,
15857 1, 1);
15858 if (equal < 0 || equal)
15859 return isl_bool_not(equal);
15860 return isl_basic_map_equal_div_expr_part(bmap1, pos1, bmap2, pos2,
15861 2, total);
15862}
15863
15864/* Replace the numerator of the constant term of the integer division
15865 * expression at position "div" in "bmap" by "value".
15866 * The caller guarantees that this does not change the meaning
15867 * of the input.
15868 */
15870 __isl_take isl_basic_map *bmap, int div, int value)
15871{
15872 if (isl_basic_map_check_range(bmap, isl_dim_div, div, 1) < 0)
15873 return isl_basic_map_free(bmap);
15874
15875 isl_int_set_si(bmap->div[div][1], value);
15876
15877 return bmap;
15878}
15879
15880/* Is the point "inner" internal to inequality constraint "ineq"
15881 * of "bset"?
15882 * The point is considered to be internal to the inequality constraint,
15883 * if it strictly lies on the positive side of the inequality constraint,
15884 * or if it lies on the constraint and the constraint is lexico-positive.
15885 */
15887 __isl_keep isl_basic_set *bset, int ineq)
15888{
15889 isl_ctx *ctx;
15890 int pos;
15892
15893 if (!inner || !bset)
15894 return isl_bool_error;
15895
15896 ctx = isl_basic_set_get_ctx(bset);
15897 isl_seq_inner_product(inner->el, bset->ineq[ineq], inner->size,
15898 &ctx->normalize_gcd);
15901
15903 if (total < 0)
15904 return isl_bool_error;
15905 pos = isl_seq_first_non_zero(bset->ineq[ineq] + 1, total);
15906 return isl_int_is_pos(bset->ineq[ineq][1 + pos]);
15907}
15908
15909/* Tighten the inequality constraints of "bset" that are outward with respect
15910 * to the point "vec".
15911 * That is, tighten the constraints that are not satisfied by "vec".
15912 *
15913 * "vec" is a point internal to some superset S of "bset" that is used
15914 * to make the subsets of S disjoint, by tightening one half of the constraints
15915 * that separate two subsets. In particular, the constraints of S
15916 * are all satisfied by "vec" and should not be tightened.
15917 * Of the internal constraints, those that have "vec" on the outside
15918 * are tightened. The shared facet is included in the adjacent subset
15919 * with the opposite constraint.
15920 * For constraints that saturate "vec", this criterion cannot be used
15921 * to determine which of the two sides should be tightened.
15922 * Instead, the sign of the first non-zero coefficient is used
15923 * to make this choice. Note that this second criterion is never used
15924 * on the constraints of S since "vec" is interior to "S".
15925 */
15928{
15929 int j;
15930
15931 bset = isl_basic_set_cow(bset);
15932 if (!bset)
15933 return NULL;
15934 for (j = 0; j < bset->n_ineq; ++j) {
15935 isl_bool internal;
15936
15937 internal = is_internal(vec, bset, j);
15938 if (internal < 0)
15939 return isl_basic_set_free(bset);
15940 if (internal)
15941 continue;
15942 isl_int_sub_ui(bset->ineq[j][0], bset->ineq[j][0], 1);
15943 }
15944
15945 return bset;
15946}
15947
15948/* Replace the variables x of type "type" starting at "first" in "bmap"
15949 * by x' with x = M x' with M the matrix trans.
15950 * That is, replace the corresponding coefficients c by c M.
15951 *
15952 * The transformation matrix should be a square matrix.
15953 */
15955 __isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first,
15956 __isl_take isl_mat *trans)
15957{
15958 unsigned pos;
15959
15960 bmap = isl_basic_map_cow(bmap);
15961 if (!bmap || !trans)
15962 goto error;
15963
15964 if (trans->n_row != trans->n_col)
15965 isl_die(trans->ctx, isl_error_invalid,
15966 "expecting square transformation matrix", goto error);
15967 if (isl_basic_map_check_range(bmap, type, first, trans->n_row) < 0)
15968 goto error;
15969
15970 pos = isl_basic_map_offset(bmap, type) + first;
15971
15972 if (isl_mat_sub_transform(bmap->eq, bmap->n_eq, pos,
15973 isl_mat_copy(trans)) < 0)
15974 goto error;
15975 if (isl_mat_sub_transform(bmap->ineq, bmap->n_ineq, pos,
15976 isl_mat_copy(trans)) < 0)
15977 goto error;
15978 if (isl_mat_sub_transform(bmap->div, bmap->n_div, 1 + pos,
15979 isl_mat_copy(trans)) < 0)
15980 goto error;
15981
15985
15986 isl_mat_free(trans);
15987 return bmap;
15988error:
15989 isl_mat_free(trans);
15990 isl_basic_map_free(bmap);
15991 return NULL;
15992}
15993
15994/* Replace the variables x of type "type" starting at "first" in "bset"
15995 * by x' with x = M x' with M the matrix trans.
15996 * That is, replace the corresponding coefficients c by c M.
15997 *
15998 * The transformation matrix should be a square matrix.
15999 */
16001 __isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first,
16002 __isl_take isl_mat *trans)
16003{
16004 return isl_basic_map_transform_dims(bset, type, first, trans);
16005}
__isl_give isl_pw_aff * isl_pw_aff_var_on_domain(__isl_take isl_local_space *ls, enum isl_dim_type type, unsigned pos)
Definition isl_aff.c:409
__isl_export __isl_give isl_space * isl_pw_multi_aff_get_space(__isl_keep isl_pw_multi_aff *pma)
__isl_give isl_aff * isl_aff_project_domain_on_params(__isl_take isl_aff *aff)
Definition isl_aff.c:2708
__isl_give isl_map * isl_pw_aff_le_map(__isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2)
Definition isl_aff.c:3239
__isl_give isl_pw_multi_aff * isl_pw_multi_aff_align_params(__isl_take isl_pw_multi_aff *pma, __isl_take isl_space *model)
__isl_give isl_local_space * isl_aff_get_domain_local_space(__isl_keep isl_aff *aff)
Definition isl_aff.c:586
__isl_give isl_map * isl_pw_aff_ge_map(__isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2)
Definition isl_aff.c:3258
__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_give isl_pw_multi_aff * isl_pw_multi_aff_union_lexmax(__isl_take isl_pw_multi_aff *pma1, __isl_take isl_pw_multi_aff *pma2)
Definition isl_aff.c:4835
__isl_give isl_basic_set * isl_aff_eq_basic_set(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2)
Definition isl_aff.c:2556
__isl_give isl_pw_aff * isl_pw_aff_empty(__isl_take isl_space *space)
__isl_give isl_pw_multi_aff * isl_pw_multi_aff_union_lexmin(__isl_take isl_pw_multi_aff *pma1, __isl_take isl_pw_multi_aff *pma2)
Definition isl_aff.c:4850
__isl_give isl_aff * isl_aff_copy(__isl_keep isl_aff *aff)
Definition isl_aff.c:145
__isl_export __isl_give isl_aff * isl_aff_floor(__isl_take isl_aff *aff)
Definition isl_aff.c:1729
__isl_give isl_space * isl_pw_multi_aff_get_domain_space(__isl_keep isl_pw_multi_aff *pma)
__isl_give isl_pw_multi_aff * isl_pw_multi_aff_from_multi_pw_aff(__isl_take isl_multi_pw_aff *mpa)
Definition isl_aff.c:7021
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_overload __isl_give isl_aff * isl_aff_mod_val(__isl_take isl_aff *aff, __isl_take isl_val *mod)
Definition isl_aff.c:1796
__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_null isl_pw_multi_aff * isl_pw_multi_aff_free(__isl_take isl_pw_multi_aff *pma)
__isl_give isl_pw_aff * isl_pw_multi_aff_get_pw_aff(__isl_keep isl_pw_multi_aff *pma, int pos)
Definition isl_aff.c:6332
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
static __isl_give isl_basic_set * bset_from_bmap(__isl_take isl_basic_map *bmap)
static __isl_give isl_basic_map * bset_to_bmap(__isl_take isl_basic_set *bset)
Definition bset_to_bmap.c:7
isl_size isl_constraint_dim(__isl_keep isl_constraint *constraint, enum isl_dim_type type)
__isl_give isl_map * isl_map_add_constraint(__isl_take isl_map *map, __isl_take isl_constraint *constraint)
isl_size isl_basic_map_n_constraint(__isl_keep isl_basic_map *bmap)
__isl_null isl_constraint * isl_constraint_free(__isl_take isl_constraint *c)
__isl_give isl_basic_map * isl_basic_map_add_constraint(__isl_take isl_basic_map *bmap, __isl_take 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 * isl_constraint_alloc_inequality(__isl_take isl_local_space *ls)
isl_stat isl_basic_map_foreach_constraint(__isl_keep isl_basic_map *bmap, isl_stat(*fn)(__isl_take isl_constraint *c, void *user), void *user)
__isl_give isl_constraint * isl_constraint_set_coefficient_si(__isl_take isl_constraint *constraint, enum isl_dim_type type, int pos, int v)
#define __isl_take
Definition ctx.h:22
#define isl_calloc_type(ctx, type)
Definition ctx.h:130
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_size_error
Definition ctx.h:98
#define __isl_null
Definition ctx.h:28
#define ISL_FL_ISSET(l, f)
Definition ctx.h:113
#define isl_die(ctx, errno, msg, code)
Definition ctx.h:138
void isl_ctx_deref(struct isl_ctx *ctx)
Definition isl_ctx.c:287
#define isl_assert(ctx, test, code)
Definition ctx.h:153
isl_bool isl_bool_ok(int b)
Definition isl_ctx.c:58
@ isl_error_unsupported
Definition ctx.h:82
@ isl_error_invalid
Definition ctx.h:80
@ isl_error_internal
Definition ctx.h:79
#define isl_alloc_array(ctx, type, n)
Definition ctx.h:132
#define isl_calloc_array(ctx, type, n)
Definition ctx.h:133
#define ISL_F_ISSET(p, f)
Definition ctx.h:118
#define __isl_keep
Definition ctx.h:25
#define isl_calloc(ctx, type, size)
Definition ctx.h:125
int isl_size
Definition ctx.h:97
#define isl_realloc_array(ctx, ptr, type, n)
Definition ctx.h:135
void isl_ctx_ref(struct isl_ctx *ctx)
Definition isl_ctx.c:282
isl_bool isl_bool_not(isl_bool b)
Definition isl_ctx.c:44
#define ISL_FL_CLR(l, f)
Definition ctx.h:112
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
#define ISL_F_SET(p, f)
Definition ctx.h:116
#define ISL_FL_SET(l, f)
Definition ctx.h:111
#define ISL_F_CLR(p, f)
Definition ctx.h:117
c1
Definition dot.c:2
m
Definition guard1-0.c:2
#define isl_hash_hash(h, h2)
Definition hash.h:26
#define isl_hash_byte(h, b)
Definition hash.h:22
#define isl_hash_init()
Definition hash.h:21
__isl_export __isl_give ISL_HMAP __isl_take ISL_KEY __isl_take ISL_VAL * val
Definition hmap.h:32
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_null isl_id * isl_id_free(__isl_take isl_id *id)
Definition isl_id.c:207
struct isl_multi_id isl_multi_id
Definition id_type.h:16
int GMPQAPI cmp(mp_rat op1, mp_rat op2)
int GMPQAPI sgn(mp_rat op)
void GMPZAPI neg(mp_int rop, mp_int op)
void GMPZAPI gcd(mp_int rop, mp_int op1, mp_int op2)
__isl_give isl_pw_aff * isl_pw_aff_union_opt(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2, int max)
Definition isl_aff.c:2968
isl_stat isl_seq_preimage(isl_int *dst, isl_int *src, __isl_keep isl_multi_aff *ma, int n_before, int n_after, int n_div_ma, int n_div_bmap, isl_int f, isl_int c1, isl_int c2, isl_int g, int has_denom)
Definition isl_aff.c:5944
isl_bool isl_multi_pw_aff_has_non_trivial_domain(__isl_keep isl_multi_pw_aff *mpa)
Definition isl_aff.c:6796
__isl_give isl_multi_aff * isl_multi_aff_align_divs(__isl_take isl_multi_aff *maff)
Definition isl_aff.c:6188
__isl_give isl_aff * isl_aff_alloc_vec(__isl_take isl_local_space *ls, __isl_take isl_vec *v)
Definition isl_aff.c:101
static __isl_give isl_set * less(__isl_keep isl_pw_aff_list *list, int pos1, int pos2)
Definition isl_aff.c:3870
__isl_give isl_map * isl_map_from_pw_multi_aff_internal(__isl_take isl_pw_multi_aff *pma)
isl_stat isl_pw_multi_aff_check_named_params(__isl_keep isl_pw_multi_aff *pma)
__isl_give isl_aff * isl_aff_domain_factor_domain(__isl_take isl_aff *aff)
__isl_give isl_basic_map * isl_basic_map_implicit_equalities(__isl_take isl_basic_map *bmap)
static __isl_give isl_ast_expr * var(struct isl_ast_add_term_data *data, enum isl_dim_type type, int pos)
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block, size_t new_n)
Definition isl_blk.c:107
int isl_blk_is_error(struct isl_blk block)
Definition isl_blk.c:37
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
Definition isl_blk.c:116
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
Definition isl_blk.c:74
struct isl_blk isl_blk_empty()
Definition isl_blk.c:16
static void drop(struct isl_coalesce_info *info)
void isl_dim_map_dim_range(__isl_keep isl_dim_map *dim_map, __isl_keep isl_space *space, enum isl_dim_type type, unsigned first, unsigned n, unsigned dst_pos)
Definition isl_dim_map.c:70
__isl_give isl_basic_map * isl_basic_map_add_constraints_dim_map(__isl_take isl_basic_map *dst, __isl_take isl_basic_map *src, __isl_take isl_dim_map *dim_map)
__isl_null isl_dim_map * isl_dim_map_free(__isl_take isl_dim_map *dim_map)
Definition isl_dim_map.c:47
__isl_give isl_dim_map * isl_dim_map_extend(__isl_keep isl_dim_map *dim_map, __isl_keep isl_basic_map *bmap)
__isl_give isl_dim_map * isl_dim_map_from_reordering(__isl_keep isl_reordering *exp)
void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_space *space, enum isl_dim_type type, unsigned dst_pos)
Definition isl_dim_map.c:87
__isl_give isl_dim_map * isl_dim_map_alloc(isl_ctx *ctx, unsigned len)
Definition isl_dim_map.c:29
void isl_dim_map_div(__isl_keep isl_dim_map *dim_map, __isl_keep isl_basic_map *bmap, unsigned dst_pos)
Definition isl_dim_map.c:97
__isl_give isl_mat * isl_mat_variable_compression(__isl_take isl_mat *B, __isl_give isl_mat **T2)
static isl_bool no(const void *entry, const void *val)
Definition isl_hash.c:66
#define isl_int_is_nonneg(i)
Definition isl_int.h:37
#define isl_int_is_zero(i)
Definition isl_int.h:31
#define isl_int_is_one(i)
Definition isl_int.h:32
#define isl_int_is_pos(i)
Definition isl_int.h:34
#define isl_int_is_negone(i)
Definition isl_int.h:33
#define isl_int_is_neg(i)
Definition isl_int.h:35
#define isl_int_gcd(r, i, j)
Definition isl_int_gmp.h:42
#define isl_int_neg(r, i)
Definition isl_int_gmp.h:24
#define isl_int_abs_eq(i, j)
Definition isl_int_gmp.h:64
#define isl_int_le(i, j)
Definition isl_int_gmp.h:60
#define isl_int_add(r, i, j)
Definition isl_int_gmp.h:30
#define isl_int_cmp(i, j)
Definition isl_int_gmp.h:55
#define isl_int_ne(i, j)
Definition isl_int_gmp.h:58
#define isl_int_is_divisible_by(i, j)
Definition isl_int_gmp.h:69
#define isl_int_abs_lt(i, j)
Definition isl_int_gmp.h:66
#define isl_int_abs_gt(i, j)
Definition isl_int_gmp.h:67
#define isl_int_set(r, i)
Definition isl_int_gmp.h:14
#define isl_int_cdiv_q(r, i, j)
Definition isl_int_gmp.h:47
#define isl_int_abs_cmp(i, j)
Definition isl_int_gmp.h:63
#define isl_int_divexact(r, i, j)
Definition isl_int_gmp.h:44
#define isl_int_sgn(i)
Definition isl_int_gmp.h:54
#define isl_int_mul(r, i, j)
Definition isl_int_gmp.h:32
#define isl_int_set_si(r, i)
Definition isl_int_gmp.h:15
mpz_t isl_int
Definition isl_int_gmp.h:9
#define isl_int_sub_ui(r, i, j)
Definition isl_int_gmp.h:28
#define isl_int_fdiv_q(r, i, j)
Definition isl_int_gmp.h:49
#define isl_int_swap(i, j)
Definition isl_int_gmp.h:25
#define isl_int_sub(r, i, j)
Definition isl_int_gmp.h:31
#define isl_int_init(i)
Definition isl_int_gmp.h:11
#define isl_int_abs(r, i)
Definition isl_int_gmp.h:23
#define isl_int_clear(i)
Definition isl_int_gmp.h:12
__isl_give dup(__isl_keep LIST(EL) *list)
__isl_give isl_local_space * isl_local_space_alloc_div(__isl_take isl_space *space, __isl_take isl_mat *div)
isl_bool isl_local_space_involves_dims(__isl_keep isl_local_space *ls, enum isl_dim_type type, unsigned first, unsigned n)
__isl_give isl_basic_map * isl_basic_map_sort_divs(__isl_take isl_basic_map *bmap)
isl_size isl_local_space_var_offset(__isl_keep isl_local_space *ls, enum isl_dim_type type)
enum isl_lp_result isl_basic_map_solve_lp(__isl_keep isl_basic_map *bmap, int max, isl_int *f, isl_int d, isl_int *opt, isl_int *opt_denom, __isl_give isl_vec **sol)
Definition isl_lp.c:66
__isl_give isl_basic_set * isl_basic_map_domain(__isl_take isl_basic_map *bmap)
Definition isl_map.c:6602
__isl_give isl_basic_map * isl_basic_map_drop_constraints_not_involving_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3614
__isl_give isl_basic_set * isl_basic_set_alloc_space(__isl_take isl_space *space, unsigned extra, unsigned n_eq, unsigned n_ineq)
Definition isl_map.c:1361
isl_bool isl_basic_set_contains(__isl_keep isl_basic_set *bset, __isl_keep isl_vec *vec)
Definition isl_map.c:4240
__isl_give isl_map * isl_map_preimage_range_pw_multi_aff(__isl_take isl_map *map, __isl_take isl_pw_multi_aff *pma)
Definition isl_map.c:14826
static __isl_give isl_map * map_union_disjoint(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:8802
__isl_give isl_basic_map * isl_basic_map_flat_product(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:11423
__isl_give isl_map * isl_map_flat_domain_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11827
static isl_stat isl_set_check_is_set(__isl_keep isl_set *set)
Definition isl_map.c:13465
isl_bool isl_set_has_equal_space(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
Definition isl_map.c:9857
__isl_give isl_basic_set * isl_basic_set_drop(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2646
__isl_give isl_basic_map * isl_basic_map_nat_universe(__isl_take isl_space *space)
Definition isl_map.c:6918
isl_bool isl_basic_set_plain_dim_is_fixed(__isl_keep isl_basic_set *bset, unsigned dim, isl_int *val)
Definition isl_map.c:10889
__isl_give isl_basic_map * isl_basic_map_apply_range(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:5355
isl_size isl_basic_map_var_offset(__isl_keep isl_basic_map *bmap, enum isl_dim_type type)
Definition isl_map.c:147
isl_size isl_basic_map_total_dim(__isl_keep const isl_basic_map *bmap)
Definition isl_map.c:233
static __isl_give isl_basic_map * add_upper_div_constraint(__isl_take isl_basic_map *bmap, unsigned div)
Definition isl_map.c:6109
__isl_give isl_map * isl_map_drop(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2663
__isl_give isl_basic_map_list * isl_basic_map_list_align_divs_to_basic_map(__isl_take isl_basic_map_list *list, __isl_keep isl_basic_map *bmap)
Definition isl_map.c:10468
static __isl_give isl_basic_map * add_lower_div_constraint(__isl_take isl_basic_map *bmap, unsigned div)
Definition isl_map.c:6134
static __isl_give isl_map * compute_divs(__isl_take isl_basic_map *bmap)
Definition isl_map.c:8541
__isl_give isl_basic_map * isl_basic_map_free_inequality(__isl_take isl_basic_map *bmap, unsigned n)
Definition isl_map.c:1767
__isl_give isl_basic_map * isl_basic_map_add_ineq(__isl_take isl_basic_map *bmap, isl_int *ineq)
Definition isl_map.c:1843
isl_size isl_basic_set_n_equality(__isl_keep isl_basic_set *bset)
Definition isl_map.c:258
__isl_give isl_space * isl_set_get_space(__isl_keep isl_set *set)
Definition isl_map.c:604
__isl_give isl_basic_set * isl_basic_set_from_params(__isl_take isl_basic_set *bset)
Definition isl_map.c:6555
static __isl_give isl_basic_map * var_more_or_equal(__isl_take isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:5811
static isl_bool detect_mod(__isl_keep isl_basic_map *bmap, struct isl_detect_mod_data *data)
Definition isl_map.c:3194
__isl_give isl_map * isl_map_nat_universe(__isl_take isl_space *space)
Definition isl_map.c:6947
__isl_give isl_basic_map * isl_basic_map_drop_core(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2577
__isl_give isl_set * isl_set_lower_bound(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, isl_int value)
Definition isl_map.c:7504
static isl_stat check_map_space_equal_total_dim(__isl_keep isl_map *map, __isl_keep isl_space *space)
Definition isl_map.c:6452
__isl_give isl_basic_map * isl_basic_map_order_divs(__isl_take isl_basic_map *bmap)
Definition isl_map.c:10156
__isl_give isl_set * isl_set_upper_bound(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, isl_int value)
Definition isl_map.c:7510
isl_bool isl_set_dim_is_bounded(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12173
__isl_give isl_basic_map * isl_basic_map_deltas_map(__isl_take isl_basic_map *bmap)
Definition isl_map.c:9468
__isl_give isl_basic_set * isl_basic_set_drop_constraints_involving(__isl_take isl_basic_set *bset, unsigned first, unsigned n)
Definition isl_map.c:3605
__isl_give isl_basic_set * isl_basic_set_drop_constraints_not_involving_dims(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3655
__isl_give isl_set * isl_set_union(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:8929
__isl_give isl_basic_map * isl_basic_map_list_intersect(__isl_take isl_basic_map_list *list)
Definition isl_map.c:11273
static __isl_give isl_map * map_lex_lte_first(__isl_take isl_space *space, unsigned n, int equal)
Definition isl_map.c:5913
__isl_give isl_map * isl_map_order_ge(__isl_take isl_map *map, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14053
static __isl_give isl_map * replace_space_by_local_space(__isl_take isl_map *map, __isl_take isl_local_space *ls)
Definition isl_map.c:8501
isl_bool isl_basic_map_any_div_involves_vars(__isl_keep isl_basic_map *bmap, unsigned first, unsigned n)
Definition isl_map.c:2882
isl_size isl_basic_set_dim(__isl_keep isl_basic_set *bset, enum isl_dim_type type)
Definition isl_map.c:202
__isl_give isl_set * isl_set_from_basic_set(__isl_take isl_basic_set *bset)
Definition isl_map.c:4024
__isl_give isl_map * isl_map_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11613
isl_bool isl_map_is_identity(__isl_keep isl_map *map)
Definition isl_map.c:12706
static __isl_give isl_basic_set * wrap_for_plug_in(__isl_take isl_basic_map *bmap, int is_set)
Definition isl_map.c:15120
static __isl_give isl_map * drop_constraints(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n, __isl_give isl_basic_map *(*drop)(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n))
Definition isl_map.c:3698
static isl_bool basic_set_no_locals(__isl_keep isl_basic_set *bset, void *user)
Definition isl_map.c:3549
isl_bool isl_basic_set_plain_is_universe(__isl_keep isl_basic_set *bset)
Definition isl_map.c:9959
__isl_give isl_map * isl_map_sum(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:5502
__isl_give isl_set * isl_set_preimage_pw_multi_aff(__isl_take isl_set *set, __isl_take isl_pw_multi_aff *pma)
Definition isl_map.c:14802
__isl_give isl_set * isl_set_alloc_space(__isl_take isl_space *space, int n, unsigned flags)
Definition isl_map.c:3977
__isl_give isl_basic_map * isl_basic_map_equate(__isl_take isl_basic_map *bmap, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:13943
isl_bool isl_basic_map_div_expr_involves_vars(__isl_keep isl_basic_map *bmap, int div, unsigned first, unsigned n)
Definition isl_map.c:2834
__isl_give isl_basic_map * isl_basic_map_drop_constraints_involving(__isl_take isl_basic_map *bmap, unsigned first, unsigned n)
Definition isl_map.c:3571
isl_bool isl_basic_map_may_be_set(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:6617
isl_size isl_set_n_basic_set(__isl_keep isl_set *set)
Definition isl_map.c:11928
int isl_basic_set_alloc_div(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1884
__isl_give isl_mat * isl_basic_set_equalities_matrix(__isl_keep isl_basic_set *bset, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4)
Definition isl_map.c:13670
__isl_give isl_basic_set * isl_basic_set_set_to_empty(__isl_take isl_basic_set *bset)
Definition isl_map.c:2219
isl_bool isl_set_is_strict_subset(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
Definition isl_map.c:9940
__isl_give isl_map * isl_set_lex_lt_set(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:6035
__isl_give isl_basic_map * isl_basic_map_more_or_equal_at(__isl_take isl_space *space, unsigned pos)
Definition isl_map.c:5900
static __isl_keep const isl_basic_map * const_bset_to_bmap(__isl_keep const isl_basic_set *bset)
Definition isl_map.c:63
__isl_give isl_space * isl_basic_map_get_space(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:417
isl_bool isl_basic_map_plain_is_universe(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:9950
isl_bool isl_map_plain_is_single_valued(__isl_keep isl_map *map)
Definition isl_map.c:12613
__isl_give isl_map * isl_map_intersect_domain_factor_domain(__isl_take isl_map *map, __isl_take isl_map *factor)
Definition isl_map.c:9111
static isl_bool isl_basic_map_set_tuple_is_equal(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, __isl_keep isl_basic_set *bset)
Definition isl_map.c:315
static isl_stat foreach_orthant(__isl_take isl_set *set, int *signs, int first, int len, isl_stat(*fn)(__isl_take isl_set *orthant, int *signs, void *user), void *user)
Definition isl_map.c:9681
static __isl_give isl_set * parameter_compute_divs(__isl_take isl_basic_set *bset)
Definition isl_map.c:8376
static __isl_give isl_map * clear_caches(__isl_take isl_map *map)
Definition isl_map.c:2083
static __isl_give isl_set * set_append_equalities(__isl_take isl_set *set, __isl_take isl_mat *eq)
Definition isl_map.c:8269
__isl_give isl_mat * isl_basic_map_equalities_matrix(__isl_keep isl_basic_map *bmap, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4, enum isl_dim_type c5)
Definition isl_map.c:13516
__isl_give isl_basic_set * isl_basic_set_dup(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1457
isl_bool isl_set_involves_locals(__isl_keep isl_set *set)
Definition isl_map.c:3556
__isl_give isl_basic_map * isl_basic_map_remove_divs_involving_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3398
__isl_give isl_basic_map * isl_basic_map_zip(__isl_take isl_basic_map *bmap)
Definition isl_map.c:13716
__isl_give isl_pw_aff * isl_map_dim_min(__isl_take isl_map *map, int pos)
Definition isl_map.c:8122
static __isl_give isl_map * isl_map_intersect_multi_val_explicit_domain(__isl_take isl_map *map, __isl_keep isl_multi_val *mv)
Definition isl_map.c:7586
__isl_give isl_basic_map * isl_basic_map_equal(__isl_take isl_space *space, unsigned n_equal)
Definition isl_map.c:5836
static __isl_give isl_map * sort_and_remove_duplicates(__isl_take isl_map *map)
Definition isl_map.c:11115
static __isl_give isl_basic_map * equator(__isl_take isl_space *space, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:13907
isl_bool isl_map_dim_is_bounded(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12152
__isl_give isl_map * isl_map_lower_bound_multi_pw_aff(__isl_take isl_map *map, __isl_take isl_multi_pw_aff *lower)
Definition isl_map.c:7735
isl_bool isl_map_has_dim_id(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:986
const char * isl_map_get_dim_name(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:897
__isl_give isl_basic_map * isl_basic_map_alloc(isl_ctx *ctx, unsigned nparam, unsigned in, unsigned out, unsigned extra, unsigned n_eq, unsigned n_ineq)
Definition isl_map.c:1393
static __isl_give isl_space * isl_basic_map_take_space(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:436
__isl_give isl_set * isl_map_range(__isl_take isl_map *map)
Definition isl_map.c:6728
isl_bool isl_basic_map_is_empty(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:10044
static __isl_give isl_basic_set * isl_basic_set_bound_val(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos, __isl_take isl_val *value, int upper)
Definition isl_map.c:7765
isl_bool isl_basic_set_involves_dims(__isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3522
__isl_give isl_map * isl_set_lex_le_set(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:6025
__isl_give isl_set * isl_set_set_dim_name(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, const char *s)
Definition isl_map.c:965
__isl_give isl_set * isl_set_remove_divs(__isl_take isl_set *set)
Definition isl_map.c:2808
static __isl_give isl_map * map_lex_lte(__isl_take isl_space *space, int equal)
Definition isl_map.c:5940
isl_bool isl_map_involves_dims(__isl_keep isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3504
__isl_give isl_set * isl_set_preimage_multi_pw_aff(__isl_take isl_set *set, __isl_take isl_multi_pw_aff *mpa)
Definition isl_map.c:14895
static __isl_give isl_basic_set * basic_set_parameter_preimage(__isl_take isl_basic_set *bset, __isl_take isl_mat *mat)
Definition isl_map.c:8165
__isl_give isl_set * isl_map_underlying_set(__isl_take isl_map *map)
Definition isl_map.c:6376
static __isl_give isl_basic_map * var_less(__isl_take isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:5728
__isl_give isl_map * isl_set_insert_domain(__isl_take isl_set *set, __isl_take isl_space *domain)
Definition isl_map.c:13493
static __isl_give isl_set * set_bound_multi_val(__isl_take isl_set *set, __isl_take isl_multi_val *bound, __isl_give isl_map *map_bound(__isl_take isl_map *map, unsigned pos, __isl_take isl_val *value))
Definition isl_map.c:7599
__isl_give isl_basic_set * isl_basic_set_set_tuple_name(__isl_take isl_basic_set *bset, const char *s)
Definition isl_map.c:674
__isl_give isl_map * isl_map_upper_bound_val(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, __isl_take isl_val *value)
Definition isl_map.c:7551
__isl_give isl_map * isl_map_inline_foreach_basic_map(__isl_take isl_map *map, __isl_give isl_basic_map *(*fn)(__isl_take isl_basic_map *bmap))
Definition isl_map.c:7208
__isl_give isl_set * isl_set_list_union(__isl_take isl_set_list *list)
Definition isl_map.c:11350
__isl_give isl_map * isl_map_intersect_domain_factor_range(__isl_take isl_map *map, __isl_take isl_map *factor)
Definition isl_map.c:9126
isl_bool isl_set_has_dim_name(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:911
isl_bool isl_basic_map_plain_is_equal(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
Definition isl_map.c:11086
const char * isl_map_get_tuple_name(__isl_keep isl_map *map, enum isl_dim_type type)
Definition isl_map.c:742
__isl_give isl_set * isl_set_lift(__isl_take isl_set *set)
Definition isl_map.c:12035
__isl_give isl_map * isl_map_apply_range(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:9277
isl_bool isl_basic_map_is_equal(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
Definition isl_map.c:9780
__isl_give isl_map * isl_map_uncurry(__isl_take isl_map *map)
Definition isl_map.c:13893
__isl_give isl_map * isl_basic_map_lexmax(__isl_take isl_basic_map *bmap)
Definition isl_map.c:8029
__isl_give isl_map * isl_map_eliminate(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2717
__isl_give isl_set * isl_set_set_tuple_name(__isl_take isl_set *set, const char *s)
Definition isl_map.c:748
isl_bool isl_set_dim_has_upper_bound(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12251
isl_ctx * isl_set_get_ctx(__isl_keep isl_set *set)
Definition isl_map.c:397
isl_bool isl_basic_map_applies_range(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
Definition isl_map.c:5328
__isl_give isl_basic_set * isl_basic_set_drop_dims(__isl_take isl_basic_set *bset, unsigned first, unsigned n)
Definition isl_map.c:2521
__isl_give isl_map * isl_map_domain_factor_range(__isl_take isl_map *map)
Definition isl_map.c:11752
__isl_give isl_map * isl_map_preimage_range_multi_aff(__isl_take isl_map *map, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14699
__isl_give isl_set * isl_set_add_basic_set(__isl_take isl_set *set, __isl_take isl_basic_set *bset)
Definition isl_map.c:4048
void isl_basic_map_inequality_to_equality(__isl_keep isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:1719
isl_size isl_map_n_basic_map(__isl_keep isl_map *map)
Definition isl_map.c:11923
__isl_give isl_basic_map * isl_basic_map_normalize(__isl_take isl_basic_map *bmap)
Definition isl_map.c:10989
__isl_give isl_map * isl_map_floordiv(__isl_take isl_map *map, isl_int d)
Definition isl_map.c:5659
__isl_give isl_set * isl_set_lower_bound_si(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7422
__isl_give isl_map * isl_map_union_disjoint(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:8875
__isl_give isl_basic_map * isl_basic_map_project_out(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:5125
__isl_give isl_basic_set * isl_basic_set_intersect(__isl_take isl_basic_set *bset1, __isl_take isl_basic_set *bset2)
Definition isl_map.c:4312
__isl_give isl_map * isl_map_align_divs_internal(__isl_take isl_map *map)
Definition isl_map.c:10397
isl_bool isl_set_plain_is_empty(__isl_keep isl_set *set)
Definition isl_map.c:9823
__isl_give isl_set * isl_set_reset_space(__isl_take isl_set *set, __isl_take isl_space *space)
Definition isl_map.c:6523
static __isl_give isl_aff * extract_aff(__isl_keep isl_basic_set *bset, isl_int *aff, int pos)
Definition isl_map.c:3262
__isl_give isl_vec * isl_basic_map_inequality_extract_output_upper_bound(__isl_keep isl_basic_map *bmap, int ineq, int pos)
Definition isl_map.c:14915
isl_size isl_basic_map_n_equality(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:248
__isl_give isl_set * isl_set_lower_bound_val(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, __isl_take isl_val *value)
Definition isl_map.c:7539
static isl_stat involves_divs(__isl_take isl_constraint *c, void *user)
Definition isl_map.c:9967
isl_size isl_basic_set_n_dim(__isl_keep isl_basic_set *bset)
Definition isl_map.c:208
isl_size isl_basic_map_n_inequality(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:266
static __isl_give isl_basic_map * isl_basic_map_fix_pos(__isl_take isl_basic_map *bmap, unsigned pos, isl_int value)
Definition isl_map.c:7085
__isl_give isl_basic_set * isl_basic_set_insert_div(__isl_take isl_basic_set *bset, int pos, __isl_keep isl_vec *div)
Definition isl_map.c:1942
isl_bool isl_basic_set_is_empty(__isl_keep isl_basic_set *bset)
Definition isl_map.c:10123
__isl_give isl_set * isl_basic_set_compute_divs(__isl_take isl_basic_set *bset)
Definition isl_map.c:8767
__isl_give isl_basic_map * isl_basic_map_from_constraint_matrices(__isl_take isl_space *space, __isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4, enum isl_dim_type c5)
Definition isl_map.c:13582
static isl_bool isl_basic_set_involves_locals(__isl_keep isl_basic_set *bset)
Definition isl_map.c:3536
__isl_give isl_map * isl_map_empty(__isl_take isl_space *space)
Definition isl_map.c:6957
int isl_basic_map_drop_equality(__isl_keep isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:1694
__isl_give isl_mat * isl_basic_set_inequalities_matrix(__isl_keep isl_basic_set *bset, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4)
Definition isl_map.c:13678
__isl_give isl_basic_map * isl_inequality_negate(__isl_take isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:3959
static __isl_give isl_map * map_bound_pw_aff(__isl_take isl_map *map, unsigned pos, __isl_take isl_pw_aff *bound, __isl_give isl_map *(*order)(__isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2))
Definition isl_map.c:7677
__isl_give isl_set * isl_set_set_dim_id(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
Definition isl_map.c:1022
isl_bool isl_basic_map_div_is_known(__isl_keep isl_basic_map *bmap, int div)
Definition isl_map.c:3779
void isl_map_print_internal(__isl_keep isl_map *map, FILE *out, int indent)
Definition isl_map.c:4080
__isl_give isl_basic_set * isl_basic_set_expand_divs(__isl_take isl_basic_set *bset, __isl_take isl_mat *div, int *exp)
Definition isl_map.c:10278
static __isl_give isl_vec * extract_bound_from_constraint(isl_ctx *ctx, isl_int *c, int len, int pos)
Definition isl_map.c:2304
isl_bool isl_set_is_singleton(__isl_keep isl_set *set)
Definition isl_map.c:12694
__isl_give isl_space * isl_map_get_space(__isl_keep isl_map *map)
Definition isl_map.c:599
__isl_give isl_basic_map * isl_basic_map_add_div_constraints(__isl_take isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:6166
__isl_give isl_map * isl_map_lex_gt_map(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:6095
isl_bool isl_basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12134
__isl_give isl_set * isl_map_domain(__isl_take isl_map *map)
Definition isl_map.c:8777
__isl_give isl_val * isl_set_plain_get_val_if_fixed(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:10850
__isl_give isl_set * isl_set_sum(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:5537
__isl_give isl_map * isl_map_reverse(__isl_take isl_map *map)
Definition isl_map.c:7801
isl_size isl_basic_set_n_param(__isl_keep isl_basic_set *bset)
Definition isl_map.c:213
int isl_basic_set_plain_cmp(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2)
Definition isl_map.c:11062
static __isl_give isl_aff * construct_mod(__isl_keep isl_basic_map *bmap, int pos, int eq, int lower, isl_int n)
Definition isl_map.c:15204
isl_bool isl_basic_map_can_curry(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:13770
isl_bool isl_set_dim_has_any_lower_bound(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12203
__isl_give isl_multi_val * isl_set_get_plain_multi_val_if_fixed(__isl_keep isl_set *set)
Definition isl_map.c:10862
static __isl_give isl_map * unbind_params_insert_domain(__isl_take isl_set *set, __isl_take isl_multi_id *tuple)
Definition isl_map.c:13432
__isl_give isl_basic_map * isl_basic_map_insert_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, unsigned n)
Definition isl_map.c:4654
__isl_give isl_set * isl_set_normalize(__isl_take isl_set *set)
Definition isl_map.c:11199
__isl_give isl_set * isl_set_fix(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, isl_int value)
Definition isl_map.c:7279
__isl_give isl_map * isl_map_reset(__isl_take isl_map *map, enum isl_dim_type type)
Definition isl_map.c:12929
__isl_give isl_set * isl_map_bind_domain(__isl_take isl_map *map, __isl_take isl_multi_id *tuple)
Definition isl_map.c:13398
unsigned isl_basic_map_offset(__isl_keep isl_basic_map *bmap, enum isl_dim_type type)
Definition isl_map.c:178
__isl_give isl_basic_map * isl_basic_map_floordiv(__isl_take isl_basic_map *bmap, isl_int d)
Definition isl_map.c:5605
static __isl_give isl_map * isl_map_partial_lexopt_aligned(__isl_take isl_map *map, __isl_take isl_set *dom, __isl_give isl_set **empty, unsigned flags)
Definition isl_map.c:7952
isl_bool isl_map_is_empty(__isl_keep isl_map *map)
Definition isl_map.c:9801
__isl_give isl_basic_map * isl_basic_map_dup(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:1441
static void swap_div(__isl_keep isl_basic_map *bmap, int a, int b)
Definition isl_map.c:2473
isl_bool isl_map_is_equal(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
Definition isl_map.c:9902
__isl_give isl_map * isl_map_flat_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11623
__isl_give isl_map * isl_map_project_onto(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:5225
isl_bool isl_basic_map_plain_is_empty(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:10089
__isl_give isl_basic_map * isl_basic_map_drop_constraints_involving_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3666
__isl_give isl_map * isl_map_fix(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, isl_int value)
Definition isl_map.c:7259
int isl_basic_set_is_rational(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1187
__isl_give isl_map * isl_map_remove_inputs(__isl_take isl_map *map, unsigned first, unsigned n)
Definition isl_map.c:3903
__isl_give isl_basic_map * isl_basic_map_from_range(__isl_take isl_basic_set *bset)
Definition isl_map.c:6809
__isl_give isl_set * isl_set_fix_val(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, __isl_take isl_val *v)
Definition isl_map.c:7321
isl_bool isl_set_dim_has_lower_bound(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12243
isl_bool isl_set_has_rational(__isl_keep isl_set *set)
Definition isl_map.c:1254
static isl_bool map_is_equal(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
Definition isl_map.c:9884
__isl_give isl_set * isl_set_cow(__isl_take isl_set *set)
Definition isl_map.c:2092
__isl_give isl_basic_map * isl_basic_map_realign(__isl_take isl_basic_map *bmap, __isl_take isl_space *space, __isl_take struct isl_dim_map *dim_map)
Definition isl_map.c:13069
isl_bool isl_basic_set_space_has_equal_params(__isl_keep isl_basic_set *bset, __isl_keep isl_space *space)
Definition isl_map.c:13230
__isl_give isl_set * isl_map_wrap(__isl_take isl_map *map)
Definition isl_map.c:12883
__isl_give isl_basic_map * isl_basic_map_neg(__isl_take isl_basic_map *bmap)
Definition isl_map.c:5545
static isl_stat isl_basic_map_check_compatible_range(__isl_keep isl_basic_map *bmap, __isl_keep isl_basic_set *bset)
Definition isl_map.c:4152
__isl_give isl_map * isl_map_lex_ge_first(__isl_take isl_space *space, unsigned n)
Definition isl_map.c:6009
__isl_give isl_space * isl_basic_set_get_space(__isl_keep isl_basic_set *bset)
Definition isl_map.c:422
static __isl_give isl_basic_map * move_divs_last(__isl_take isl_basic_map *bmap, unsigned first, unsigned n)
Definition isl_map.c:2529
isl_bool isl_set_every_basic_set(__isl_keep isl_set *set, isl_bool(*test)(__isl_keep isl_basic_set *bset, void *user), void *user)
Definition isl_map.c:11965
__isl_give isl_map * isl_map_copy(__isl_keep isl_map *map)
Definition isl_map.c:1494
__isl_give isl_basic_map * isl_basic_map_add_known_div_constraints(__isl_take isl_basic_map *bmap)
Definition isl_map.c:6199
static __isl_give isl_map * map_upper_bound_val(__isl_take isl_map *map, unsigned pos, __isl_take isl_val *v)
Definition isl_map.c:7652
static __isl_give isl_map * isl_map_intersect_factor(__isl_take isl_map *map, __isl_take isl_map *factor, struct isl_intersect_factor_control *control)
Definition isl_map.c:9062
__isl_give isl_basic_set * isl_basic_set_add_ineq(__isl_take isl_basic_set *bset, isl_int *ineq)
Definition isl_map.c:1864
__isl_give isl_basic_map * isl_basic_map_from_local_space(__isl_take isl_local_space *ls)
Definition isl_map.c:561
__isl_give isl_map * isl_map_move_dims(__isl_take isl_map *map, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n)
Definition isl_map.c:4937
__isl_give isl_set * isl_set_unbind_params(__isl_take isl_set *set, __isl_take isl_multi_id *tuple)
Definition isl_map.c:13449
__isl_give isl_basic_map * isl_basic_map_add_eq(__isl_take isl_basic_map *bmap, isl_int *eq)
Definition isl_map.c:1809
static __isl_give isl_basic_map * isl_basic_map_restore_space(__isl_take isl_basic_map *bmap, __isl_take isl_space *space)
Definition isl_map.c:455
__isl_give isl_set * isl_set_upper_bound_multi_pw_aff(__isl_take isl_set *set, __isl_take isl_multi_pw_aff *upper)
Definition isl_map.c:7725
isl_bool isl_basic_map_dim_has_lower_bound(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12140
__isl_give isl_set * isl_set_reset_user(__isl_take isl_set *set)
Definition isl_map.c:1131
const char * isl_set_get_tuple_name(__isl_keep isl_set *set)
Definition isl_map.c:870
static __isl_give isl_basic_map * add_constraints(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2, unsigned i_pos, unsigned o_pos)
Definition isl_map.c:1959
static void constraint_drop_vars(isl_int *c, unsigned n, unsigned rem)
Definition isl_map.c:2508
__isl_give isl_map * isl_map_flatten_domain(__isl_take isl_map *map)
Definition isl_map.c:13041
__isl_give isl_map * isl_basic_map_union(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:10128
static __isl_give isl_map * map_bound(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, isl_int value, int upper)
Definition isl_map.c:7474
__isl_give isl_set * isl_set_empty(__isl_take isl_space *space)
Definition isl_map.c:6962
__isl_give isl_basic_set * isl_basic_set_extend_constraints(__isl_take isl_basic_set *base, unsigned n_eq, unsigned n_ineq)
Definition isl_map.c:2051
__isl_give isl_basic_set * isl_basic_set_remove_dims(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3861
__isl_give isl_basic_set * isl_basic_set_fix_val(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos, __isl_take isl_val *v)
Definition isl_map.c:7154
static __isl_give isl_map * isl_map_intersect_domain_wrapped_domain(__isl_take isl_map *map, __isl_take isl_set *domain)
Definition isl_map.c:9221
int isl_basic_set_first_unknown_div(__isl_keep isl_basic_set *bset)
Definition isl_map.c:8665
static isl_bool is_internal(__isl_keep isl_vec *inner, __isl_keep isl_basic_set *bset, int ineq)
Definition isl_map.c:15886
isl_stat isl_basic_set_check_range(__isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:1896
__isl_give isl_map * isl_map_lower_bound_si(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7410
__isl_give isl_aff * isl_basic_map_get_div(__isl_keep isl_basic_map *bmap, int pos)
Definition isl_map.c:14153
static isl_bool is_convex_no_locals(__isl_keep isl_map *map)
Definition isl_map.c:4341
__isl_give isl_map * isl_map_partial_lexmin(__isl_take isl_map *map, __isl_take isl_set *dom, __isl_give isl_set **empty)
Definition isl_map.c:7997
__isl_give isl_map * isl_map_factor_range(__isl_take isl_map *map)
Definition isl_map.c:11698
static __isl_give isl_map * map_lower_bound_val(__isl_take isl_map *map, unsigned pos, __isl_take isl_val *v)
Definition isl_map.c:7634
__isl_give isl_map * isl_map_lex_gt(__isl_take isl_space *set_space)
Definition isl_map.c:6015
__isl_give isl_map * isl_map_reset_space(__isl_take isl_map *map, __isl_take isl_space *space)
Definition isl_map.c:6467
__isl_give isl_map * isl_map_flatten_range(__isl_take isl_map *map)
Definition isl_map.c:13054
__isl_give isl_basic_set * isl_basic_set_preimage_multi_aff(__isl_take isl_basic_set *bset, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14536
__isl_give isl_set * isl_set_set_tuple_id(__isl_take isl_set *set, __isl_take isl_id *id)
Definition isl_map.c:783
static __isl_give isl_pw_aff * map_dim_opt(__isl_take isl_map *map, int pos, int max)
Definition isl_map.c:8084
static __isl_give isl_basic_map * move_last(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:4985
int isl_basic_set_alloc_equality(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1666
__isl_give isl_basic_map * isl_basic_map_fix(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, isl_int value)
Definition isl_map.c:7119
unsigned isl_basic_set_offset(__isl_keep isl_basic_set *bset, enum isl_dim_type type)
Definition isl_map.c:191
isl_bool isl_basic_set_is_wrapping(__isl_keep isl_basic_set *bset)
Definition isl_map.c:12796
static __isl_give isl_map * map_lower_bound_pw_aff(__isl_take isl_map *map, unsigned pos, __isl_take isl_pw_aff *lower)
Definition isl_map.c:7696
static __isl_give isl_aff * extract_div_expr_aff(__isl_keep isl_basic_set *bset, int div, int pos)
Definition isl_map.c:15168
static unsigned pos(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_map.c:73
isl_bool isl_set_is_rational(__isl_keep isl_set *set)
Definition isl_map.c:1182
static __isl_give isl_map * isl_map_reverse_range_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:9102
static __isl_give isl_map * remove_if_empty(__isl_take isl_map *map, int i)
Definition isl_map.c:7177
__isl_give isl_map * isl_map_union(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:8894
__isl_null isl_basic_map * isl_basic_map_free(__isl_take isl_basic_map *bmap)
Definition isl_map.c:1503
__isl_give isl_basic_map * isl_basic_map_drop(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2628
__isl_give isl_basic_set * isl_basic_set_project_out(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:5170
__isl_give isl_basic_set * isl_basic_set_extend(__isl_take isl_basic_set *base, unsigned extra, unsigned n_eq, unsigned n_ineq)
Definition isl_map.c:2038
isl_bool isl_basic_map_equal_div_expr_part(__isl_keep isl_basic_map *bmap1, int pos1, __isl_keep isl_basic_map *bmap2, int pos2, unsigned first, unsigned n)
Definition isl_map.c:15822
__isl_give isl_basic_map * isl_basic_map_domain_map(__isl_take isl_basic_map *bmap)
Definition isl_map.c:6650
static __isl_give isl_space * isl_space_set(__isl_take isl_space *space, enum isl_dim_type type, __isl_take isl_space *set)
Definition isl_map.c:14367
static __isl_give isl_map * map_intersect_internal(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:4425
__isl_give isl_basic_set * isl_basic_set_fix_si(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7160
isl_ctx * isl_basic_map_get_ctx(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:382
__isl_give isl_basic_map * isl_basic_map_remove_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2813
__isl_give isl_basic_map * isl_basic_map_range_product(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:11486
isl_size isl_basic_set_total_dim(__isl_keep const isl_basic_set *bset)
Definition isl_map.c:218
__isl_give isl_basic_map * isl_basic_map_set_div_expr_constant_num_si_inplace(__isl_take isl_basic_map *bmap, int div, int value)
Definition isl_map.c:15869
__isl_give isl_set * isl_set_reset_tuple_id(__isl_take isl_set *set)
Definition isl_map.c:801
int isl_basic_map_constraint_cmp(__isl_keep isl_basic_map *bmap, isl_int *c1, isl_int *c2)
Definition isl_map.c:10946
static __isl_give isl_basic_map * basic_map_space_reset(__isl_take isl_basic_map *bmap, enum isl_dim_type type)
Definition isl_map.c:4638
__isl_give isl_map * isl_map_normalize(__isl_take isl_map *map)
Definition isl_map.c:11173
__isl_give isl_map * isl_set_identity(__isl_take isl_set *set)
Definition isl_map.c:9563
int isl_basic_map_alloc_div(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:1870
__isl_give isl_map * isl_map_set_tuple_name(__isl_take isl_map *map, enum isl_dim_type type, const char *s)
Definition isl_map.c:686
isl_bool isl_basic_map_div_is_marked_unknown(__isl_keep isl_basic_map *bmap, int div)
Definition isl_map.c:8631
__isl_give isl_map * isl_map_order_divs(__isl_take isl_map *map)
Definition isl_map.c:10186
static __isl_give isl_map * map_lex_gte(__isl_take isl_space *space, int equal)
Definition isl_map.c:5996
isl_bool isl_map_has_space_tuples(__isl_keep isl_map *map, __isl_keep isl_space *space)
Definition isl_map.c:9414
static __isl_give isl_maybe_isl_aff isl_basic_map_try_find_output_mod_eq(__isl_keep isl_basic_map *bmap, int pos)
Definition isl_map.c:15269
__isl_give isl_map * isl_map_from_domain_and_range(__isl_take isl_set *domain, __isl_take isl_set *range)
Definition isl_map.c:6847
__isl_give isl_map * isl_map_drop_constraints_involving_dims(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3727
__isl_give isl_map * isl_map_order_gt(__isl_take isl_map *map, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14132
static __isl_give isl_basic_map * var_more(__isl_take isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:5783
__isl_give isl_set * isl_set_eliminate(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2747
isl_bool isl_map_is_strict_subset(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
Definition isl_map.c:9926
isl_size isl_set_n_param(__isl_keep isl_set *set)
Definition isl_map.c:228
__isl_give isl_basic_set * isl_basic_set_tighten_outward(__isl_take isl_basic_set *bset, __isl_keep isl_vec *vec)
Definition isl_map.c:15926
isl_size isl_basic_set_n_inequality(__isl_keep isl_basic_set *bset)
Definition isl_map.c:276
__isl_null isl_basic_set * isl_basic_set_free(__isl_take isl_basic_set *bset)
Definition isl_map.c:1523
isl_stat isl_basic_set_check_no_locals(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1551
isl_stat isl_basic_set_vars_get_sign(__isl_keep isl_basic_set *bset, unsigned first, unsigned n, int *signs)
Definition isl_map.c:12265
__isl_give isl_set * isl_set_align_divs(__isl_take isl_set *set)
Definition isl_map.c:10428
__isl_give isl_map * isl_map_fix_val(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, __isl_take isl_val *v)
Definition isl_map.c:7288
__isl_give isl_val * isl_map_plain_get_val_if_fixed(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:10822
static int constraint_pair_has_bound(__isl_keep isl_basic_map *bmap, int i, int j, isl_int bound, isl_int *tmp)
Definition isl_map.c:2368
int isl_basic_set_compare_at(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2, int pos)
Definition isl_map.c:10603
static isl_bool isl_basic_set_plain_has_fixed_var(__isl_keep isl_basic_set *bset, unsigned pos, isl_int *val)
Definition isl_map.c:10764
__isl_give isl_map * isl_map_upper_bound_multi_pw_aff(__isl_take isl_map *map, __isl_take isl_multi_pw_aff *upper)
Definition isl_map.c:7745
__isl_give isl_map * isl_space_universe_map(__isl_take isl_space *space)
Definition isl_map.c:6980
__isl_give isl_basic_set * isl_basic_set_fix(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos, isl_int value)
Definition isl_map.c:7167
__isl_give isl_map * isl_map_upper_bound(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, isl_int value)
Definition isl_map.c:7498
__isl_give isl_basic_map * isl_basic_map_set_dim_name(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, const char *s)
Definition isl_map.c:919
isl_size isl_basic_map_dim(__isl_keep isl_basic_map *bmap, enum isl_dim_type type)
Definition isl_map.c:83
isl_bool isl_map_plain_is_universe(__isl_keep isl_map *map)
Definition isl_map.c:10023
isl_ctx * isl_map_get_ctx(__isl_keep isl_map *map)
Definition isl_map.c:392
isl_bool isl_set_is_box(__isl_keep isl_set *set)
Definition isl_map.c:12786
__isl_give isl_set * isl_set_equate(__isl_take isl_set *set, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:13899
__isl_give isl_map * isl_map_flatten(__isl_take isl_map *map)
Definition isl_map.c:13009
__isl_give isl_basic_map * isl_basic_map_set_to_empty(__isl_take isl_basic_map *bmap)
Definition isl_map.c:2177
__isl_give isl_basic_map * isl_basic_map_remove_unknown_divs(__isl_take isl_basic_map *bmap)
Definition isl_map.c:3804
__isl_give isl_basic_map * isl_basic_map_intersect_params(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset)
Definition isl_map.c:4323
__isl_give isl_basic_map * isl_basic_map_less_at(__isl_take isl_space *space, unsigned pos)
Definition isl_map.c:5851
static isl_stat isl_set_check_range(__isl_keep isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2562
__isl_give isl_map * isl_map_preimage_multi_pw_aff(__isl_take isl_map *map, enum isl_dim_type type, __isl_take isl_multi_pw_aff *mpa)
Definition isl_map.c:14847
__isl_give isl_maybe_isl_aff isl_basic_map_try_find_any_output_div_mod(__isl_keep isl_basic_map *bmap, int *pos)
Definition isl_map.c:15778
static __isl_give isl_map * map_equate_params(__isl_take isl_map *map, __isl_keep isl_multi_id *tuple)
Definition isl_map.c:13359
static isl_bool isl_map_plain_has_fixed_var(__isl_keep isl_map *map, unsigned pos, isl_int *val)
Definition isl_map.c:10735
__isl_give isl_map * isl_map_domain_factor_domain(__isl_take isl_map *map)
Definition isl_map.c:11727
__isl_give isl_basic_map * isl_basic_map_more_at(__isl_take isl_space *space, unsigned pos)
Definition isl_map.c:5883
static __isl_give isl_basic_map * insert_bounds_on_div_from_ineq(__isl_take isl_basic_map *bmap, int div, int i, unsigned total, isl_int v, int lb, int ub)
Definition isl_map.c:2951
isl_bool isl_basic_set_is_equal(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2)
Definition isl_map.c:9794
static isl_stat check_map_compatible_range_multi_aff(__isl_keep isl_map *map, enum isl_dim_type type, __isl_keep isl_multi_aff *ma)
Definition isl_map.c:14570
__isl_give isl_basic_map * isl_basic_map_preimage_range_multi_aff(__isl_take isl_basic_map *bmap, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14560
static __isl_give isl_map * isl_map_transform(__isl_take isl_map *map, __isl_give isl_space *(*fn_space)(__isl_take isl_space *space), __isl_give isl_basic_map *(*fn_bmap)(__isl_take isl_basic_map *bmap))
Definition isl_map.c:6746
static int sort_constraint_cmp(const void *p1, const void *p2, void *arg)
Definition isl_map.c:10918
isl_bool isl_basic_map_has_dim_id(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:972
__isl_give isl_id * isl_map_get_domain_tuple_id(__isl_keep isl_map *map)
Definition isl_map.c:833
__isl_give isl_pw_aff * isl_set_dim_min(__isl_take isl_set *set, int pos)
Definition isl_map.c:8157
static __isl_give isl_basic_map * var_equal(__isl_take isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:5701
__isl_give isl_set * isl_set_drop_unused_params(__isl_take isl_set *set)
Definition isl_map.c:13274
int isl_basic_map_first_unknown_div(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:8645
int isl_set_find_dim_by_name(__isl_keep isl_set *set, enum isl_dim_type type, const char *name)
Definition isl_map.c:1062
__isl_give isl_map * isl_map_apply_domain(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:9263
__isl_give isl_map * isl_map_lex_le_map(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:6065
__isl_give isl_basic_set_list * isl_basic_map_list_underlying_set(__isl_take isl_basic_map_list *list)
Definition isl_map.c:6276
__isl_give isl_basic_set * isl_basic_set_free_inequality(__isl_take isl_basic_set *bset, unsigned n)
Definition isl_map.c:1780
isl_bool isl_set_is_equal(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
Definition isl_map.c:9748
static __isl_give isl_map * map_intersect(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:4502
isl_bool isl_map_plain_is_injective(__isl_keep isl_map *map)
Definition isl_map.c:12671
__isl_give isl_map * isl_map_set_dim_name(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, const char *s)
Definition isl_map.c:931
__isl_give isl_basic_set * isl_basic_set_insert_dims(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos, unsigned n)
Definition isl_map.c:4716
static __isl_give isl_map * map_intersect_set(__isl_take isl_map *map, __isl_take isl_space *space, __isl_take isl_set *set, __isl_give isl_basic_map *fn(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset))
Definition isl_map.c:8940
isl_bool isl_map_can_zip(__isl_keep isl_map *map)
Definition isl_map.c:13705
__isl_give isl_basic_map * isl_basic_map_free_equality(__isl_take isl_basic_map *bmap, unsigned n)
Definition isl_map.c:1671
static __isl_give isl_basic_map * add_known_div_constraints(__isl_take isl_basic_map *bmap)
Definition isl_map.c:537
__isl_give isl_map * isl_map_curry(__isl_take isl_map *map)
Definition isl_map.c:13817
isl_bool isl_map_domain_is_wrapping(__isl_keep isl_map *map)
Definition isl_map.c:12843
static void isl_detect_mod_data_clear(struct isl_detect_mod_data *data)
Definition isl_map.c:3157
int isl_basic_map_output_defining_equality(__isl_keep isl_basic_map *bmap, int pos, int *div, int *ineq)
Definition isl_map.c:12499
__isl_give isl_map * isl_map_lex_le_first(__isl_take isl_space *space, unsigned n)
Definition isl_map.c:5953
int isl_basic_map_drop_inequality(__isl_keep isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:1787
__isl_give isl_map * isl_map_lex_lt(__isl_take isl_space *set_space)
Definition isl_map.c:5959
isl_bool isl_basic_set_plain_is_empty(__isl_keep isl_basic_set *bset)
Definition isl_map.c:10096
__isl_give isl_set * isl_set_project_out_param_id_list(__isl_take isl_set *set, __isl_take isl_id_list *list)
Definition isl_map.c:5260
int isl_basic_map_alloc_inequality(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:1742
__isl_give isl_map * isl_map_oppose(__isl_take isl_map *map, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:13971
uint32_t isl_basic_set_get_hash(__isl_keep isl_basic_set *bset)
Definition isl_map.c:11887
__isl_give isl_map * isl_map_intersect_range(__isl_take isl_map *map, __isl_take isl_set *set)
Definition isl_map.c:8973
int isl_map_find_dim_by_name(__isl_keep isl_map *map, enum isl_dim_type type, const char *name)
Definition isl_map.c:1054
__isl_give isl_set * isl_basic_set_lexmax(__isl_take isl_basic_set *bset)
Definition isl_map.c:8039
__isl_give isl_map * isl_map_lower_bound(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, isl_int value)
Definition isl_map.c:7492
isl_bool isl_map_can_range_curry(__isl_keep isl_map *map)
Definition isl_map.c:13827
__isl_null isl_set * isl_set_free(__isl_take isl_set *set)
Definition isl_map.c:4055
__isl_give isl_basic_map * isl_basic_map_remove_divs(__isl_take isl_basic_map *bmap)
Definition isl_map.c:2763
__isl_give isl_set * isl_set_eliminate_dims(__isl_take isl_set *set, unsigned first, unsigned n)
Definition isl_map.c:2757
int isl_set_follows_at(__isl_keep isl_set *set1, __isl_keep isl_set *set2, int pos)
Definition isl_map.c:10684
__isl_give isl_basic_map * isl_basic_map_add_div_constraint(__isl_take isl_basic_map *bmap, unsigned div, int sign)
Definition isl_map.c:6229
__isl_give isl_id * isl_basic_set_get_dim_id(__isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:980
__isl_give isl_map * isl_map_realign(__isl_take isl_map *map, __isl_take isl_reordering *r)
Definition isl_map.c:13100
static __isl_give isl_basic_map * isl_basic_map_set_reverse(__isl_take isl_basic_map *bmap)
Definition isl_map.c:4625
__isl_give isl_map * isl_map_remove_divs_involving_dims(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3440
__isl_give isl_set * isl_set_universe(__isl_take isl_space *space)
Definition isl_map.c:6985
static __isl_give isl_basic_map * isl_basic_map_range_reverse(__isl_take isl_basic_map *bmap)
Definition isl_map.c:4609
__isl_give isl_map * isl_map_lex_ge_map(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:6085
__isl_give isl_set * isl_set_remove_divs_involving_dims(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3466
__isl_give isl_set * isl_set_drop_constraints_not_involving_dims(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3766
__isl_give isl_set * isl_set_add_dims(__isl_take isl_set *set, enum isl_dim_type type, unsigned n)
Definition isl_map.c:4806
__isl_give isl_set * isl_set_intersect_factor_range(__isl_take isl_set *set, __isl_take isl_set *range)
Definition isl_map.c:9193
static enum isl_lp_result basic_set_maximal_difference_at(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2, int pos, isl_int *opt)
Definition isl_map.c:10553
__isl_give isl_basic_set * isl_basic_set_add_eq(__isl_take isl_basic_set *bset, isl_int *eq)
Definition isl_map.c:1837
__isl_give isl_set * isl_set_intersect_params(__isl_take isl_set *set, __isl_take isl_set *params)
Definition isl_map.c:4538
__isl_give isl_map * isl_map_preimage_multi_aff(__isl_take isl_map *map, enum isl_dim_type type, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14643
isl_bool isl_map_has_equal_params(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
Definition isl_map.c:295
isl_stat isl_basic_set_check_no_params(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1535
isl_bool isl_map_space_tuple_is_equal(__isl_keep isl_map *map, enum isl_dim_type type1, __isl_keep isl_space *space, enum isl_dim_type type2)
Definition isl_map.c:9388
static __isl_give isl_constraint * constraint_order_ge(__isl_take isl_space *space, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14009
int isl_map_is_translation(__isl_keep isl_map *map)
Definition isl_map.c:12722
static isl_bool is_potential_div_constraint(__isl_keep isl_basic_map *bmap, isl_int *c, int v_out, int d, int v_div, int total)
Definition isl_map.c:14950
static isl_bool basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, int lower, int upper)
Definition isl_map.c:12102
__isl_give isl_set * isl_basic_set_union(__isl_take isl_basic_set *bset1, __isl_take isl_basic_set *bset2)
Definition isl_map.c:10148
static __isl_give isl_set * set_parameter_preimage(__isl_take isl_set *set, __isl_take isl_mat *mat)
Definition isl_map.c:8197
__isl_give isl_set * isl_set_remove_unknown_divs(__isl_take isl_set *set)
Definition isl_map.c:3856
__isl_give isl_map * isl_map_cow(__isl_take isl_map *map)
Definition isl_map.c:2107
isl_size isl_basic_set_var_offset(__isl_keep isl_basic_set *bset, enum isl_dim_type type)
Definition isl_map.c:169
__isl_give isl_map * isl_map_from_basic_map(__isl_take isl_basic_map *bmap)
Definition isl_map.c:4037
__isl_give isl_map * isl_map_intersect_params(__isl_take isl_map *map, __isl_take isl_set *params)
Definition isl_map.c:4531
__isl_give isl_basic_map * isl_basic_map_flat_range_product(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:11540
__isl_give isl_basic_map * isl_basic_map_uncurry(__isl_take isl_basic_map *bmap)
Definition isl_map.c:13870
isl_size isl_set_n_dim(__isl_keep isl_set *set)
Definition isl_map.c:223
__isl_give isl_basic_map * isl_basic_map_mark_div_unknown(__isl_take isl_basic_map *bmap, int div)
Definition isl_map.c:8606
__isl_give isl_set * isl_set_copy(__isl_keep isl_set *set)
Definition isl_map.c:1470
isl_stat isl_set_foreach_orthant(__isl_keep isl_set *set, isl_stat(*fn)(__isl_take isl_set *orthant, int *signs, void *user), void *user)
Definition isl_map.c:9719
__isl_give isl_basic_set * isl_basic_map_underlying_set(__isl_take isl_basic_map *bmap)
Definition isl_map.c:6238
isl_size isl_basic_map_find_output_upper_div_constraint(__isl_keep isl_basic_map *bmap, int pos)
Definition isl_map.c:15006
static __isl_give isl_map * map_space_reset(__isl_take isl_map *map, enum isl_dim_type type)
Definition isl_map.c:4746
__isl_give isl_basic_set * isl_basic_set_list_intersect(__isl_take isl_basic_set_list *list)
Definition isl_map.c:11305
static isl_size find_div(__isl_keep isl_basic_map *dst, __isl_keep isl_basic_map *src, unsigned div)
Definition isl_map.c:10291
static __isl_give isl_map * map_lex_gte_first(__isl_take isl_space *space, unsigned n, int equal)
Definition isl_map.c:5969
__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_give isl_map * isl_map_remove_obvious_duplicates(__isl_take isl_map *map)
Definition isl_map.c:11145
int isl_map_find_dim_by_id(__isl_keep isl_map *map, enum isl_dim_type type, __isl_keep isl_id *id)
Definition isl_map.c:1028
isl_bool isl_basic_map_plain_is_fixed(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, isl_int *val)
Definition isl_map.c:10771
__isl_give isl_set * isl_set_intersect_factor_domain(__isl_take isl_set *set, __isl_take isl_set *domain)
Definition isl_map.c:9174
__isl_give isl_basic_set * isl_basic_set_free_equality(__isl_take isl_basic_set *bset, unsigned n)
Definition isl_map.c:1684
__isl_give isl_set * isl_set_params(__isl_take isl_set *set)
Definition isl_map.c:6567
__isl_give isl_maybe_isl_aff isl_basic_map_try_find_output_div_mod(__isl_keep isl_basic_map *bmap, int pos)
Definition isl_map.c:15761
__isl_give isl_basic_map * isl_basic_map_preimage_domain_multi_aff(__isl_take isl_basic_map *bmap, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14548
static int extend_last_non_zero(__isl_keep isl_basic_map *bmap, int ineq, int first, unsigned len)
Definition isl_map.c:2331
__isl_give isl_map * isl_map_intersect(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:4514
__isl_give isl_basic_map * isl_basic_map_cow(__isl_take isl_basic_map *bmap)
Definition isl_map.c:2064
isl_bool isl_basic_map_is_transformation(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:9316
__isl_give isl_basic_map * isl_basic_map_fix_si(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7110
isl_bool isl_basic_map_is_single_valued(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:12585
__isl_give isl_local_space * isl_basic_map_get_local_space(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:512
static isl_size find_output_lower_mod_constraint(__isl_keep isl_basic_map *bmap, int pos, isl_int n)
Definition isl_map.c:15067
static __isl_give isl_basic_map * basic_map_bound_si(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, int value, int upper)
Definition isl_map.c:7340
static isl_bool isl_basic_map_plain_has_fixed_var(__isl_keep isl_basic_map *bmap, unsigned pos, isl_int *val)
Definition isl_map.c:10706
static isl_stat check_convex_no_locals(__isl_keep isl_map *map)
Definition isl_map.c:4359
__isl_give isl_map * isl_map_set_dim_id(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
Definition isl_map.c:1010
isl_stat isl_basic_set_dims_get_sign(__isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n, int *signs)
Definition isl_map.c:12323
isl_size isl_set_tuple_dim(__isl_keep isl_set *set)
Definition isl_map.c:139
isl_bool isl_map_plain_is_empty(__isl_keep isl_map *map)
Definition isl_map.c:9818
__isl_give isl_basic_set * isl_basic_set_neg(__isl_take isl_basic_set *bset)
Definition isl_map.c:5570
isl_bool isl_map_can_uncurry(__isl_keep isl_map *map)
Definition isl_map.c:13859
__isl_give isl_basic_map * isl_basic_map_upper_bound_si(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7382
__isl_give isl_map * isl_map_intersect_range_factor_domain(__isl_take isl_map *map, __isl_take isl_map *factor)
Definition isl_map.c:9141
static __isl_give isl_map * map_preimage_multi_aff(__isl_take isl_map *map, enum isl_dim_type type, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14597
__isl_give isl_map * isl_map_order_le(__isl_take isl_map *map, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14071
static int room_for_con(__isl_keep isl_basic_map *bmap, unsigned n)
Definition isl_map.c:1528
isl_bool isl_map_align_params_map_map_and_test(__isl_keep isl_map *map1, __isl_keep isl_map *map2, isl_bool(*fn)(__isl_keep isl_map *map1, __isl_keep isl_map *map2))
Definition isl_map.c:1607
__isl_give isl_maybe_isl_aff isl_basic_map_try_find_output_mod(__isl_keep isl_basic_map *bmap, int pos)
Definition isl_map.c:15619
__isl_give isl_map * isl_map_range_map(__isl_take isl_map *map)
Definition isl_map.c:6777
__isl_give isl_map * isl_map_lex_gt_first(__isl_take isl_space *space, unsigned n)
Definition isl_map.c:6003
__isl_give isl_set * isl_set_project_out(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:5241
__isl_give isl_basic_set_list * isl_set_get_basic_set_list(__isl_keep isl_set *set)
Definition isl_map.c:11987
static __isl_give isl_aff * extract_lower_bound_aff(__isl_keep isl_basic_set *bset, int ineq, int pos)
Definition isl_map.c:3286
__isl_give isl_mat * isl_basic_map_get_divs(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:481
__isl_give isl_basic_set * isl_basic_set_cow(__isl_take isl_basic_set *bset)
Definition isl_map.c:2059
uint32_t isl_map_get_hash(__isl_keep isl_map *map)
Definition isl_map.c:11892
uint32_t isl_set_get_hash(__isl_keep isl_set *set)
Definition isl_map.c:11916
isl_bool isl_set_involves_dims(__isl_keep isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3528
__isl_give isl_id * isl_map_get_range_tuple_id(__isl_keep isl_map *map)
Definition isl_map.c:840
int isl_set_size(__isl_keep isl_set *set)
Definition isl_map.c:12085
static __isl_give isl_map * map_intersect_add_constraint(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:4379
isl_bool isl_map_is_single_valued(__isl_keep isl_map *map)
Definition isl_map.c:12632
isl_bool isl_basic_map_is_universe(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:9990
isl_stat isl_set_foreach_basic_set(__isl_keep isl_set *set, isl_stat(*fn)(__isl_take isl_basic_set *bset, void *user), void *user)
Definition isl_map.c:11948
__isl_give isl_basic_set * isl_basic_set_set_rational(__isl_take isl_basic_set *bset)
Definition isl_map.c:2243
__isl_give isl_basic_map * isl_basic_map_insert_div(__isl_take isl_basic_map *bmap, int pos, __isl_keep isl_vec *div)
Definition isl_map.c:1909
static int multi_aff_strides(__isl_keep isl_multi_aff *ma)
Definition isl_map.c:14283
__isl_give isl_map * isl_map_intersect_domain(__isl_take isl_map *map, __isl_take isl_set *set)
Definition isl_map.c:9001
__isl_give isl_basic_map * isl_basic_map_flatten_domain(__isl_take isl_basic_map *bmap)
Definition isl_map.c:12979
isl_bool isl_map_is_params(__isl_keep isl_map *map)
Definition isl_map.c:1281
__isl_give isl_basic_map * isl_basic_map_sort_constraints(__isl_take isl_basic_map *bmap)
Definition isl_map.c:10959
__isl_give isl_set * isl_set_compute_divs(__isl_take isl_set *set)
Definition isl_map.c:8772
__isl_give isl_id * isl_map_get_dim_id(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:992
int isl_set_find_dim_by_id(__isl_keep isl_set *set, enum isl_dim_type type, __isl_keep isl_id *id)
Definition isl_map.c:1036
isl_bool isl_set_plain_is_equal(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
Definition isl_map.c:11240
__isl_give isl_set * isl_set_nat_universe(__isl_take isl_space *space)
Definition isl_map.c:6952
__isl_give isl_basic_set * isl_basic_set_flat_product(__isl_take isl_basic_set *bset1, __isl_take isl_basic_set *bset2)
Definition isl_map.c:11433
static int first_div_may_involve_output(__isl_keep isl_basic_map *bmap, isl_int *c, int first, int n)
Definition isl_map.c:12383
__isl_give isl_map * isl_map_flat_range_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11839
static int only_non_zero(isl_int *p, unsigned pos, unsigned len)
Definition isl_map.c:15483
__isl_give isl_map * isl_map_zip(__isl_take isl_map *map)
Definition isl_map.c:13752
isl_size isl_map_domain_tuple_dim(__isl_keep isl_map *map)
Definition isl_map.c:120
static int find_modulo_constraint_pair(__isl_keep isl_basic_map *bmap, int pos, isl_int m)
Definition isl_map.c:12421
__isl_give isl_basic_set * isl_basic_set_move_dims(__isl_take isl_basic_set *bset, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n)
Definition isl_map.c:4913
__isl_give isl_map * isl_set_translation(__isl_take isl_set *deltas)
Definition isl_map.c:9528
__isl_give isl_pw_aff * isl_map_dim_max(__isl_take isl_map *map, int pos)
Definition isl_map.c:8131
__isl_give isl_basic_set * isl_basic_set_intersect_params(__isl_take isl_basic_set *bset1, __isl_take isl_basic_set *bset2)
Definition isl_map.c:4329
static __isl_give isl_basic_map * insert_bounds_on_div(__isl_take isl_basic_map *bmap, int div)
Definition isl_map.c:3050
__isl_give isl_basic_set * isl_basic_set_sort_divs(__isl_take isl_basic_set *bset)
Definition isl_map.c:10207
__isl_give isl_basic_map * isl_basic_map_flatten(__isl_take isl_basic_map *bmap)
Definition isl_map.c:12961
__isl_give isl_set * isl_set_remove_dims(__isl_take isl_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3895
__isl_give isl_basic_map * isl_basic_map_reset(__isl_take isl_basic_map *bmap, enum isl_dim_type type)
Definition isl_map.c:12915
__isl_give isl_map * isl_map_range_reverse(__isl_take isl_map *map)
Definition isl_map.c:7817
__isl_give isl_local_space * isl_basic_set_get_local_space(__isl_keep isl_basic_set *bset)
Definition isl_map.c:524
static void swap_vars(struct isl_blk blk, isl_int *a, unsigned a_len, unsigned b_len)
Definition isl_map.c:2118
__isl_give isl_basic_set * isl_basic_set_underlying_set(__isl_take isl_basic_set *bset)
Definition isl_map.c:6267
static int first_parameter_equality(__isl_keep isl_basic_set *bset)
Definition isl_map.c:8298
__isl_give isl_map * isl_map_alloc_space(__isl_take isl_space *space, int n, unsigned flags)
Definition isl_map.c:6857
__isl_give isl_basic_set * isl_basic_set_positive_orthant(__isl_take isl_space *space)
Definition isl_map.c:9574
const char * isl_basic_map_get_dim_name(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:875
__isl_give isl_basic_map * isl_basic_map_drop_div(__isl_take isl_basic_map *bmap, unsigned div)
Definition isl_map.c:2707
__isl_give isl_basic_set * isl_basic_set_set_integral(__isl_take isl_basic_set *bset)
Definition isl_map.c:2249
__isl_give isl_basic_set * isl_basic_set_add_dims(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned n)
Definition isl_map.c:4734
__isl_give isl_set * isl_set_from_params(__isl_take isl_set *set)
Definition isl_map.c:6574
__isl_give isl_basic_set * isl_basic_set_lower_bound_val(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos, __isl_take isl_val *value)
Definition isl_map.c:7785
__isl_give isl_map * isl_set_lex_ge_set(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:6045
__isl_give isl_basic_map * isl_basic_map_sum(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:5443
__isl_give isl_basic_set * isl_basic_set_remove_divs(__isl_take isl_basic_set *bset)
Definition isl_map.c:2778
isl_bool isl_basic_map_is_subset(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
Definition isl_map.c:9753
__isl_give isl_set * isl_map_params(__isl_take isl_map *map)
Definition isl_map.c:6585
int isl_basic_set_follows_at(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2, int pos)
Definition isl_map.c:10639
isl_bool isl_map_can_curry(__isl_keep isl_map *map)
Definition isl_map.c:13781
__isl_give isl_set * isl_set_wrapped_reverse(__isl_take isl_set *set)
Definition isl_map.c:7825
isl_bool isl_basic_map_can_zip(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:13697
__isl_give isl_map * isl_map_lex_lt_first(__isl_take isl_space *space, unsigned n)
Definition isl_map.c:5947
static __isl_give isl_set * set_bound_multi_pw_aff(__isl_take isl_set *set, __isl_take isl_multi_pw_aff *bound, __isl_give isl_map *set_bound(__isl_take isl_map *map, unsigned pos, __isl_take TYPE *value))
Definition isl_map.c:7618
__isl_give isl_mat * isl_basic_set_get_divs(__isl_keep isl_basic_set *bset)
Definition isl_map.c:507
isl_bool isl_set_is_params(__isl_keep isl_set *set)
Definition isl_map.c:1270
isl_size isl_map_range_tuple_dim(__isl_keep isl_map *map)
Definition isl_map.c:127
__isl_give isl_map * isl_map_order_lt(__isl_take isl_map *map, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14147
static isl_bool isl_map_set_has_equal_params(__isl_keep isl_map *map, __isl_keep isl_set *set)
Definition isl_map.c:307
__isl_give isl_basic_set * isl_basic_set_upper_bound_val(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos, __isl_take isl_val *value)
Definition isl_map.c:7794
__isl_give isl_basic_set * isl_basic_set_params(__isl_take isl_basic_set *bset)
Definition isl_map.c:6531
__isl_give isl_map * isl_map_set_domain_tuple_id(__isl_take isl_map *map, __isl_take isl_id *id)
Definition isl_map.c:769
const char * isl_basic_set_get_dim_name(__isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:881
__isl_give isl_map * isl_map_domain_reverse(__isl_take isl_map *map)
Definition isl_map.c:7809
isl_bool isl_set_space_has_equal_params(__isl_keep isl_set *set, __isl_keep isl_space *space)
Definition isl_map.c:13252
isl_bool isl_basic_map_compatible_domain(__isl_keep isl_basic_map *bmap, __isl_keep isl_basic_set *bset)
Definition isl_map.c:346
__isl_give isl_map * isl_map_align_params(__isl_take isl_map *map, __isl_take isl_space *model)
Definition isl_map.c:13143
__isl_give isl_set * isl_basic_set_lexmin(__isl_take isl_basic_set *bset)
Definition isl_map.c:8034
isl_size isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type)
Definition isl_map.c:113
isl_bool isl_map_compatible_range(__isl_keep isl_map *map, __isl_keep isl_set *set)
Definition isl_map.c:358
int isl_basic_set_size(__isl_keep isl_basic_set *bset)
Definition isl_map.c:12070
static __isl_give isl_basic_map * isl_basic_map_swap_vars(__isl_take isl_basic_map *bmap, unsigned pos, unsigned n1, unsigned n2)
Definition isl_map.c:2126
__isl_give isl_map * isl_map_intersect_range_factor_range(__isl_take isl_map *map, __isl_take isl_map *factor)
Definition isl_map.c:9156
static isl_bool has_bound(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos, isl_bool(*fn)(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos))
Definition isl_map.c:12221
isl_bool isl_basic_map_plain_is_non_empty(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:10107
__isl_give isl_basic_set * isl_basic_set_empty(__isl_take isl_space *space)
Definition isl_map.c:6894
void isl_set_print_internal(__isl_keep isl_set *set, FILE *out, int indent)
Definition isl_map.c:4060
__isl_give isl_map * isl_map_align_divs_to_basic_map_list(__isl_take isl_map *map, __isl_keep isl_basic_map_list *list)
Definition isl_map.c:10437
__isl_give isl_map * isl_map_range_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11659
__isl_give isl_map * isl_map_reset_user(__isl_take isl_map *map)
Definition isl_map.c:1117
static __isl_give isl_basic_map * basic_map_bound(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, isl_int value, int upper)
Definition isl_map.c:7438
static isl_stat check_basic_map_compatible_range_multi_aff(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, __isl_keep isl_multi_aff *ma)
Definition isl_map.c:14197
__isl_give isl_basic_map * isl_basic_map_intersect_domain(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset)
Definition isl_map.c:4118
isl_bool isl_basic_set_is_subset(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2)
Definition isl_map.c:9774
isl_bool isl_map_has_tuple_id(__isl_keep isl_map *map, enum isl_dim_type type)
Definition isl_map.c:806
__isl_give isl_basic_map * isl_basic_map_order_ge(__isl_take isl_basic_map *bmap, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14035
isl_stat isl_map_foreach_basic_map(__isl_keep isl_map *map, isl_stat(*fn)(__isl_take isl_basic_map *bmap, void *user), void *user)
Definition isl_map.c:11933
__isl_give isl_map * isl_map_preimage_domain_pw_multi_aff(__isl_take isl_map *map, __isl_take isl_pw_multi_aff *pma)
Definition isl_map.c:14814
__isl_give isl_basic_map * isl_basic_map_intersect_range(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset)
Definition isl_map.c:4167
isl_bool isl_set_is_empty(__isl_keep isl_set *set)
Definition isl_map.c:9828
__isl_give isl_map * isl_map_reset_equal_dim_space(__isl_take isl_map *map, __isl_take isl_space *space)
Definition isl_map.c:6498
__isl_give isl_set * isl_set_flat_product(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:11641
__isl_give isl_set * isl_set_neg(__isl_take isl_set *set)
Definition isl_map.c:5597
__isl_give isl_map * isl_map_set_tuple_id(__isl_take isl_map *map, enum isl_dim_type type, __isl_take isl_id *id)
Definition isl_map.c:755
static int qsort_bmap_cmp(const void *p1, const void *p2)
Definition isl_map.c:11101
isl_bool isl_set_dim_has_any_upper_bound(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12212
static __isl_give isl_basic_map * remove_divs_involving_vars(__isl_take isl_basic_map *bmap, unsigned first, unsigned n)
Definition isl_map.c:3099
static isl_stat isl_set_basic_set_check_equal_space(__isl_keep isl_set *set, __isl_keep isl_basic_set *bset)
Definition isl_map.c:9877
isl_bool isl_basic_set_plain_is_equal(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2)
Definition isl_map.c:11094
__isl_give isl_map * isl_map_remove_empty_parts(__isl_take isl_map *map)
Definition isl_map.c:10513
static __isl_give isl_basic_map * dup_constraints(__isl_take isl_basic_map *dst, __isl_keep isl_basic_map *src)
Definition isl_map.c:1408
isl_bool isl_basic_set_is_box(__isl_keep isl_basic_set *bset)
Definition isl_map.c:12743
__isl_give isl_map * isl_map_lex_le(__isl_take isl_space *set_space)
Definition isl_map.c:5964
static __isl_give isl_pw_aff * basic_map_dim_opt(__isl_keep isl_basic_map *bmap, int max)
Definition isl_map.c:8062
__isl_give isl_map * isl_map_fix_input_si(__isl_take isl_map *map, unsigned input, int value)
Definition isl_map.c:7327
__isl_give isl_basic_map * isl_basic_map_range_map(__isl_take isl_basic_map *bmap)
Definition isl_map.c:6680
__isl_give isl_basic_set * isl_basic_set_reset_space(__isl_take isl_basic_set *bset, __isl_take isl_space *space)
Definition isl_map.c:6443
static int unique(isl_int *p, unsigned pos, unsigned len)
Definition isl_map.c:12734
__isl_give isl_set * isl_set_intersect(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:4521
isl_bool isl_map_is_injective(__isl_keep isl_map *map)
Definition isl_map.c:12657
static __isl_give isl_basic_map * add_divs(__isl_take isl_basic_map *bmap, unsigned n)
Definition isl_map.c:5305
__isl_give isl_basic_set * isl_basic_set_set_tuple_id(__isl_take isl_basic_set *bset, __isl_take isl_id *id)
Definition isl_map.c:729
__isl_give isl_set * isl_basic_set_to_set(__isl_take isl_basic_set *bset)
Definition isl_map.c:4032
__isl_give isl_map * isl_map_deltas_map(__isl_take isl_map *map)
Definition isl_map.c:9517
int isl_basic_set_drop_inequality(__isl_keep isl_basic_set *bset, unsigned pos)
Definition isl_map.c:1804
isl_size isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type)
Definition isl_map.c:132
__isl_give isl_map * isl_basic_map_compute_divs(__isl_take isl_basic_map *bmap)
Definition isl_map.c:8708
static void isl_detect_mod_data_init(struct isl_detect_mod_data *data)
Definition isl_map.c:3148
isl_bool isl_map_has_range_tuple_id(__isl_keep isl_map *map)
Definition isl_map.c:820
__isl_give isl_basic_map * isl_basic_map_flatten_range(__isl_take isl_basic_map *bmap)
Definition isl_map.c:12993
__isl_give isl_map * isl_map_reset_tuple_id(__isl_take isl_map *map, enum isl_dim_type type)
Definition isl_map.c:789
__isl_give isl_set * isl_set_partial_lexmax(__isl_take isl_set *set, __isl_take isl_set *dom, __isl_give isl_set **empty)
Definition isl_map.c:8012
static __isl_give isl_map * map_upper_bound_pw_aff(__isl_take isl_map *map, unsigned pos, __isl_take isl_pw_aff *upper)
Definition isl_map.c:7705
__isl_give isl_map * isl_map_upper_bound_si(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7416
__isl_give isl_basic_set * isl_basic_set_add_div_constraints(__isl_take isl_basic_set *bset, unsigned pos)
Definition isl_map.c:6183
isl_bool isl_set_is_wrapping(__isl_keep isl_set *set)
Definition isl_map.c:12804
__isl_give isl_set * isl_set_partial_lexmin(__isl_take isl_set *set, __isl_take isl_set *dom, __isl_give isl_set **empty)
Definition isl_map.c:8004
isl_bool isl_basic_set_is_universe(__isl_keep isl_basic_set *bset)
Definition isl_map.c:10018
static __isl_give isl_pw_aff * set_dim_opt(__isl_take isl_set *set, int pos, int max)
Definition isl_map.c:8140
int isl_set_plain_cmp(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
Definition isl_map.c:11068
__isl_give isl_map * isl_map_partial_lexmax(__isl_take isl_map *map, __isl_take isl_set *dom, __isl_give isl_set **empty)
Definition isl_map.c:7990
__isl_give isl_map * isl_map_from_range(__isl_take isl_set *set)
Definition isl_map.c:6823
__isl_give isl_map * isl_map_preimage_domain_multi_pw_aff(__isl_take isl_map *map, __isl_take isl_multi_pw_aff *mpa)
Definition isl_map.c:14886
int isl_basic_map_alloc_equality(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:1631
isl_bool isl_basic_map_contains(__isl_keep isl_basic_map *bmap, __isl_keep isl_vec *vec)
Definition isl_map.c:4203
__isl_give isl_map * isl_map_intersect_range_wrapped_domain(__isl_take isl_map *map, __isl_take isl_set *domain)
Definition isl_map.c:9247
__isl_give isl_map * isl_set_unbind_params_insert_domain(__isl_take isl_set *set, __isl_take isl_multi_id *domain)
Definition isl_map.c:13483
isl_bool isl_map_plain_is_fixed(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos, isl_int *val)
Definition isl_map.c:10809
isl_bool isl_basic_map_dim_has_upper_bound(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12146
__isl_give isl_basic_map * isl_basic_map_identity(__isl_take isl_space *space)
Definition isl_map.c:9540
__isl_give isl_set * isl_set_project_out_all_params(__isl_take isl_set *set)
Definition isl_map.c:5273
isl_bool isl_map_has_rational(__isl_keep isl_map *map)
Definition isl_map.c:1237
static __isl_give isl_maybe_isl_aff isl_basic_map_try_find_output_div(__isl_keep isl_basic_map *bmap, int pos)
Definition isl_map.c:15710
__isl_give isl_set * isl_set_align_params(__isl_take isl_set *set, __isl_take isl_space *model)
Definition isl_map.c:13178
isl_bool isl_basic_map_compatible_range(__isl_keep isl_basic_map *bmap, __isl_keep isl_basic_set *bset)
Definition isl_map.c:370
__isl_give isl_basic_map * isl_basic_map_curry(__isl_take isl_basic_map *bmap)
Definition isl_map.c:13792
__isl_give isl_map * isl_map_universe(__isl_take isl_space *space)
Definition isl_map.c:6967
__isl_give isl_basic_map * isl_basic_map_order_gt(__isl_take isl_basic_map *bmap, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14117
__isl_keep isl_space * isl_set_peek_space(__isl_keep isl_set *set)
Definition isl_map.c:108
static isl_size find_earlier_constraint_in_pair(__isl_keep isl_basic_map *bmap, int ineq, int pos, int len, isl_int bound, isl_int *tmp)
Definition isl_map.c:2394
__isl_give isl_set * isl_set_split_dims(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:9655
__isl_give isl_basic_map * isl_basic_map_move_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n)
Definition isl_map.c:4818
__isl_give isl_set * isl_set_move_dims(__isl_take isl_set *set, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n)
Definition isl_map.c:4923
__isl_give isl_basic_set * isl_basic_set_drop_constraints_involving_dims(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3688
__isl_give isl_map * isl_map_factor_domain(__isl_take isl_map *map)
Definition isl_map.c:11669
__isl_give isl_map * isl_map_range_factor_range(__isl_take isl_map *map)
Definition isl_map.c:11802
__isl_give isl_map * isl_map_domain_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11649
__isl_give isl_basic_map * isl_basic_map_transform_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, __isl_take isl_mat *trans)
Definition isl_map.c:15954
static int is_constraint_pair(__isl_keep isl_basic_map *bmap, int i, int j, unsigned len)
Definition isl_map.c:2347
__isl_give isl_set * isl_basic_set_lexopt(__isl_take isl_basic_set *bset, unsigned flags)
Definition isl_map.c:8023
__isl_give isl_basic_set * isl_basic_set_from_underlying_set(__isl_take isl_basic_set *bset, __isl_take isl_basic_set *like)
Definition isl_map.c:6369
isl_stat isl_basic_map_free_div(__isl_keep isl_basic_map *bmap, unsigned n)
Definition isl_map.c:1950
__isl_give isl_basic_map * isl_basic_map_apply_domain(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:5421
__isl_give isl_set * isl_set_grow(__isl_take isl_set *set, int n)
Definition isl_map.c:4019
__isl_give isl_map * isl_map_domain_map(__isl_take isl_map *map)
Definition isl_map.c:6771
__isl_give isl_basic_map * isl_basic_set_unwrap(__isl_take isl_basic_set *bset)
Definition isl_map.c:12888
__isl_give isl_basic_map * isl_basic_map_lower_bound_si(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7373
isl_stat isl_map_check_transformation(__isl_keep isl_map *map)
Definition isl_map.c:9426
__isl_give isl_mat * isl_basic_map_inequalities_matrix(__isl_keep isl_basic_map *bmap, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4, enum isl_dim_type c5)
Definition isl_map.c:13549
__isl_give isl_val * isl_basic_map_plain_get_val_if_fixed(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:10784
isl_bool isl_set_plain_is_universe(__isl_keep isl_set *set)
Definition isl_map.c:10039
static __isl_give isl_map * isl_map_reverse_domain_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:9094
static __isl_give isl_basic_map * basic_map_init(isl_ctx *ctx, __isl_take isl_basic_map *bmap, unsigned extra, unsigned n_eq, unsigned n_ineq)
Definition isl_map.c:1288
__isl_give isl_set * isl_set_upper_bound_multi_val(__isl_take isl_set *set, __isl_take isl_multi_val *upper)
Definition isl_map.c:7661
__isl_give isl_map * isl_map_align_divs(__isl_take isl_map *map)
Definition isl_map.c:10423
static __isl_give isl_basic_set * neg_halfspace(__isl_take isl_space *space, int pos)
Definition isl_map.c:9631
__isl_give isl_basic_map * isl_basic_map_add_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned n)
Definition isl_map.c:4723
__isl_give isl_basic_set * isl_basic_map_wrap(__isl_take isl_basic_map *bmap)
Definition isl_map.c:12868
static __isl_give isl_aff * unwrap_plug_in(__isl_take isl_aff *aff, int is_set)
Definition isl_map.c:15138
static __isl_give isl_basic_map * substitute_div_mod(__isl_take isl_basic_map *bmap, unsigned pos, struct isl_detect_mod_data *data)
Definition isl_map.c:3350
static __isl_give isl_aff * extract_expr_aff(__isl_keep isl_basic_set *bset, int eq, int pos)
Definition isl_map.c:15151
static isl_stat isl_basic_map_check_applies_range(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
Definition isl_map.c:5341
isl_bool isl_basic_map_div_is_integral(__isl_keep isl_basic_map *bmap, int div)
Definition isl_map.c:8596
static __isl_give isl_basic_map * var_less_or_equal(__isl_take isl_basic_map *bmap, unsigned pos)
Definition isl_map.c:5756
isl_bool isl_basic_set_eq_is_stride(__isl_keep isl_basic_set *bset, int i)
Definition isl_map.c:1075
static __isl_give isl_map * isl_map_unmark_normalized(__isl_take isl_map *map)
Definition isl_map.c:2655
__isl_give isl_basic_set * isl_basic_set_from_constraint_matrices(__isl_take isl_space *space, __isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4)
Definition isl_map.c:13686
__isl_give isl_map * isl_map_equate(__isl_take isl_map *map, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:13957
static __isl_give isl_maybe_isl_aff try_find_output_mod_ineq_at(__isl_keep isl_basic_map *bmap, int v_out, int pos, int ineq, int n_ineq, int v_div, int e)
Definition isl_map.c:15443
void isl_basic_set_print_internal(__isl_keep isl_basic_set *bset, FILE *out, int indent)
Definition isl_map.c:3909
isl_bool isl_basic_map_is_strict_subset(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
Definition isl_map.c:9912
__isl_give isl_basic_map * isl_basic_map_fix_val(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, __isl_take isl_val *v)
Definition isl_map.c:7131
__isl_give isl_set * isl_set_apply(__isl_take isl_set *set, __isl_take isl_map *map)
Definition isl_map.c:10489
__isl_give isl_basic_map * isl_basic_map_expand_divs(__isl_take isl_basic_map *bmap, __isl_take isl_mat *div, int *exp)
Definition isl_map.c:10223
__isl_give isl_basic_set * isl_basic_set_flatten(__isl_take isl_basic_set *bset)
Definition isl_map.c:12974
uint32_t isl_basic_map_get_hash(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:11849
__isl_give isl_set * isl_set_lower_bound_multi_pw_aff(__isl_take isl_set *set, __isl_take isl_multi_pw_aff *lower)
Definition isl_map.c:7715
isl_bool isl_basic_map_equal_div_expr_except_constant(__isl_keep isl_basic_map *bmap1, int pos1, __isl_keep isl_basic_map *bmap2, int pos2)
Definition isl_map.c:15838
static __isl_give isl_map * isl_map_change_space(__isl_take isl_map *map, isl_bool(*can_change)(__isl_keep isl_map *map), const char *cannot_change, __isl_give isl_space *(*change)(__isl_take isl_space *space))
Definition isl_map.c:12817
__isl_give isl_map * isl_map_remove_divs(__isl_take isl_map *map)
Definition isl_map.c:2784
static __isl_give isl_aff * construct_mod_ineq(__isl_keep isl_basic_map *bmap, int pos, int div, int lower, int t, isl_int n)
Definition isl_map.c:15367
__isl_give isl_map * isl_map_preimage_domain_multi_aff(__isl_take isl_map *map, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14687
__isl_give isl_basic_set * isl_basic_set_nat_universe(__isl_take isl_space *space)
Definition isl_map.c:6941
const char * isl_basic_map_get_tuple_name(__isl_keep isl_basic_map *bmap, enum isl_dim_type type)
Definition isl_map.c:680
__isl_give isl_set * isl_basic_set_list_union(__isl_take isl_basic_set_list *list)
Definition isl_map.c:11314
__isl_give isl_basic_set * isl_basic_set_remove_divs_involving_dims(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3433
__isl_give isl_id * isl_set_get_dim_id(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:1004
static isl_bool isl_map_set_tuple_is_equal(__isl_keep isl_map *map, enum isl_dim_type type, __isl_keep isl_set *set)
Definition isl_map.c:328
__isl_give isl_basic_map * isl_basic_map_extend_constraints(__isl_take isl_basic_map *base, unsigned n_eq, unsigned n_ineq)
Definition isl_map.c:2045
isl_bool isl_basic_map_divs_known(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:8672
__isl_give isl_map * isl_map_lex_ge(__isl_take isl_space *set_space)
Definition isl_map.c:6020
__isl_give isl_set * isl_set_insert_dims(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, unsigned n)
Definition isl_map.c:4789
__isl_give isl_basic_map * isl_basic_map_reset_space(__isl_take isl_basic_map *bmap, __isl_take isl_space *space)
Definition isl_map.c:6415
__isl_give isl_map * isl_map_set_rational(__isl_take isl_map *map)
Definition isl_map.c:2267
static __isl_give isl_basic_map * join_initial(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2, int pos)
Definition isl_map.c:10534
static __isl_give isl_space * isl_map_take_space(__isl_keep isl_map *map)
Definition isl_map.c:620
__isl_give isl_map * isl_map_remove_unknown_divs(__isl_take isl_map *map)
Definition isl_map.c:3832
__isl_give isl_set * isl_map_bind_range(__isl_take isl_map *map, __isl_take isl_multi_id *tuple)
Definition isl_map.c:13419
isl_bool isl_basic_map_involves_dims(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3479
static __isl_give isl_basic_map * basic_replace_space_by_local_space(__isl_take isl_basic_map *bmap, __isl_take isl_local_space *ls)
Definition isl_map.c:8469
__isl_give isl_map * isl_map_range_curry(__isl_take isl_map *map)
Definition isl_map.c:13838
isl_bool isl_basic_map_is_rational(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:1136
__isl_give isl_basic_map * isl_basic_map_extend(__isl_take isl_basic_map *base, unsigned extra, unsigned n_eq, unsigned n_ineq)
Definition isl_map.c:1996
isl_bool isl_map_is_rational(__isl_keep isl_map *map)
Definition isl_map.c:1149
isl_bool isl_map_compatible_domain(__isl_keep isl_map *map, __isl_keep isl_set *set)
Definition isl_map.c:334
__isl_give isl_map * isl_set_unwrap(__isl_take isl_set *set)
Definition isl_map.c:12909
isl_bool isl_map_range_is_wrapping(__isl_keep isl_map *map)
Definition isl_map.c:12860
__isl_give isl_map * isl_map_from_domain(__isl_take isl_set *set)
Definition isl_map.c:6836
static __isl_give isl_map * isl_map_preimage_pw_multi_aff_aligned(__isl_take isl_map *map, enum isl_dim_type type, __isl_take isl_pw_multi_aff *pma)
Definition isl_map.c:14713
__isl_give isl_set * isl_set_upper_bound_val(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, __isl_take isl_val *value)
Definition isl_map.c:7571
static __isl_give isl_set * equate_params(__isl_take isl_set *set, __isl_keep isl_multi_id *tuple)
Definition isl_map.c:13300
static __isl_give isl_pw_multi_aff * isl_map_partial_lexopt_aligned_pw_multi_aff(__isl_take isl_map *map, __isl_take isl_set *dom, __isl_give isl_set **empty, unsigned flags)
Definition isl_map.c:7861
const char * isl_set_get_dim_name(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:903
isl_bool isl_map_has_dim_name(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:889
isl_ctx * isl_basic_set_get_ctx(__isl_keep isl_basic_set *bset)
Definition isl_map.c:387
__isl_give isl_map * isl_map_fix_si(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7235
__isl_give isl_map * isl_map_add_basic_map(__isl_take isl_map *map, __isl_take isl_basic_map *bmap)
Definition isl_map.c:7016
__isl_give isl_set * isl_set_union_disjoint(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:8922
__isl_give isl_map * isl_set_lex_gt_set(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:6055
__isl_give isl_basic_set * isl_basic_set_apply(__isl_take isl_basic_set *bset, __isl_take isl_basic_map *bmap)
Definition isl_map.c:5407
__isl_give isl_basic_map * isl_basic_map_empty(__isl_take isl_space *space)
Definition isl_map.c:6886
int isl_map_may_be_set(__isl_keep isl_map *map)
Definition isl_map.c:6710
__isl_give isl_basic_map * isl_basic_map_overlying_set(__isl_take isl_basic_set *bset, __isl_take isl_basic_map *like)
Definition isl_map.c:6301
__isl_keep isl_space * isl_map_peek_space(__isl_keep const isl_map *map)
Definition isl_map.c:101
__isl_give isl_basic_set * isl_basic_set_copy(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1465
isl_bool isl_map_is_bijective(__isl_keep isl_map *map)
Definition isl_map.c:12683
__isl_give isl_map * isl_set_flatten_map(__isl_take isl_set *set)
Definition isl_map.c:13025
isl_bool isl_basic_map_is_set(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:6628
__isl_give isl_basic_set * isl_basic_set_universe(__isl_take isl_space *space)
Definition isl_map.c:6910
__isl_give isl_map * isl_map_identity(__isl_take isl_space *space)
Definition isl_map.c:9558
__isl_give isl_map * isl_set_wrapped_domain_map(__isl_take isl_set *set)
Definition isl_map.c:6786
__isl_give isl_basic_map * isl_basic_map_align_divs(__isl_take isl_basic_map *dst, __isl_keep isl_basic_map *src)
Definition isl_map.c:10334
__isl_keep isl_space * isl_basic_set_peek_space(__isl_keep isl_basic_set *bset)
Definition isl_map.c:412
__isl_give isl_map * isl_map_insert_dims(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, unsigned n)
Definition isl_map.c:4760
__isl_give isl_map * isl_map_add_dims(__isl_take isl_map *map, enum isl_dim_type type, unsigned n)
Definition isl_map.c:4795
static isl_bool div_involves_vars(__isl_keep isl_basic_map *bmap, int div, unsigned first, unsigned n)
Definition isl_map.c:2851
__isl_give isl_basic_map * isl_basic_map_reverse(__isl_take isl_basic_map *bmap)
Definition isl_map.c:4544
static isl_bool isl_basic_map_has_equal_params(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
Definition isl_map.c:283
__isl_null isl_map * isl_map_free(__isl_take isl_map *map)
Definition isl_map.c:7040
__isl_give isl_basic_map_list * isl_map_get_basic_map_list(__isl_keep isl_map *map)
Definition isl_map.c:11248
__isl_give isl_mat * isl_basic_set_extract_equalities(__isl_keep isl_basic_set *bset)
Definition isl_map.c:15802
isl_bool isl_set_has_tuple_id(__isl_keep isl_set *set)
Definition isl_map.c:845
__isl_give isl_map * isl_map_grow(__isl_take isl_map *map, int n)
Definition isl_map.c:3990
static __isl_give isl_basic_map * isl_basic_map_fix_pos_si(__isl_take isl_basic_map *bmap, unsigned pos, int value)
Definition isl_map.c:7060
__isl_give isl_map * isl_map_neg(__isl_take isl_map *map)
Definition isl_map.c:5577
isl_bool isl_basic_map_has_rational(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:1198
const char * isl_basic_set_get_tuple_name(__isl_keep isl_basic_set *bset)
Definition isl_map.c:865
__isl_give isl_map * isl_map_floordiv_val(__isl_take isl_map *map, __isl_take isl_val *d)
Definition isl_map.c:5684
__isl_give isl_map * isl_map_project_out(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:5181
__isl_give isl_basic_set * isl_basic_set_alloc(isl_ctx *ctx, unsigned nparam, unsigned dim, unsigned extra, unsigned n_eq, unsigned n_ineq)
Definition isl_map.c:1346
isl_bool isl_map_divs_known(__isl_keep isl_map *map)
Definition isl_map.c:8687
isl_bool isl_basic_map_can_uncurry(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:13848
__isl_give isl_basic_set * isl_basic_set_from_local_space(__isl_take isl_local_space *ls)
Definition isl_map.c:593
__isl_give isl_basic_map * isl_basic_map_align_params(__isl_take isl_basic_map *bmap, __isl_take isl_space *model)
Definition isl_map.c:13187
__isl_give isl_basic_map * isl_basic_map_swap_div(__isl_take isl_basic_map *bmap, int a, int b)
Definition isl_map.c:2483
isl_bool isl_set_has_dim_id(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:998
__isl_give isl_map * isl_map_drop_constraints_not_involving_dims(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3740
__isl_give isl_map * isl_map_lex_lt_map(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:6075
__isl_give isl_set * isl_set_drop(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2695
__isl_give isl_map * isl_map_dup(__isl_keep isl_map *map)
Definition isl_map.c:7003
__isl_give isl_id * isl_set_get_tuple_id(__isl_keep isl_set *set)
Definition isl_map.c:850
static __isl_give isl_set * base_compute_divs(__isl_take isl_basic_set *bset)
Definition isl_map.c:8330
__isl_give isl_basic_map * isl_basic_map_copy(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:1479
__isl_give isl_basic_set * isl_basic_set_set_dim_name(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos, const char *s)
Definition isl_map.c:957
__isl_give isl_set * isl_set_fix_si(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7253
__isl_give isl_basic_set * isl_basic_set_lift(__isl_take isl_basic_set *bset)
Definition isl_map.c:12007
__isl_give isl_aff * isl_basic_set_get_div(__isl_keep isl_basic_set *bset, int pos)
Definition isl_map.c:14173
__isl_give isl_basic_set * isl_basic_set_transform_dims(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, __isl_take isl_mat *trans)
Definition isl_map.c:16000
static __isl_give isl_basic_map * isl_basic_map_reverse_wrapped(__isl_take isl_basic_map *bmap, enum isl_dim_type type)
Definition isl_map.c:4568
__isl_give isl_map * isl_map_remove_dims(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3870
__isl_give isl_basic_map * isl_basic_map_intersect(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:4246
static __isl_give isl_basic_map * insert_div_rows(__isl_take isl_basic_map *bmap, int n)
Definition isl_map.c:5042
static isl_size find_later_constraint_in_pair(__isl_keep isl_basic_map *bmap, int ineq, int pos, int len, isl_int bound, isl_int *tmp)
Definition isl_map.c:2440
static __isl_give isl_basic_map * insert_divs_from_local_space(__isl_take isl_basic_map *bmap, __isl_keep isl_local_space *ls)
Definition isl_map.c:8437
__isl_give isl_set * isl_set_set_rational(__isl_take isl_set *set)
Definition isl_map.c:2285
static __isl_give isl_basic_set * isl_basic_set_bound(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned pos, isl_int value, int upper)
Definition isl_map.c:7754
__isl_give isl_basic_set * isl_basic_set_drop_unused_params(__isl_take isl_basic_set *bset)
Definition isl_map.c:13287
__isl_give isl_set * isl_set_remove_empty_parts(__isl_take isl_set *set)
Definition isl_map.c:10526
isl_bool isl_map_space_has_equal_params(__isl_keep isl_map *map, __isl_keep isl_space *space)
Definition isl_map.c:13241
__isl_give isl_set * isl_set_bind(__isl_take isl_set *set, __isl_take isl_multi_id *tuple)
Definition isl_map.c:13339
__isl_give isl_set * isl_set_project_out_param_id(__isl_take isl_set *set, __isl_take isl_id *id)
Definition isl_map.c:5251
__isl_give isl_set * isl_set_lower_bound_multi_val(__isl_take isl_set *set, __isl_take isl_multi_val *lower)
Definition isl_map.c:7643
__isl_give isl_map * isl_map_preimage_pw_multi_aff(__isl_take isl_map *map, enum isl_dim_type type, __isl_take isl_pw_multi_aff *pma)
Definition isl_map.c:14771
static int room_for_ineq(__isl_keep isl_basic_map *bmap, unsigned n)
Definition isl_map.c:1737
int isl_basic_map_find_dim_by_name(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, const char *name)
Definition isl_map.c:1046
__isl_give isl_set * isl_set_realign(__isl_take isl_set *set, __isl_take isl_reordering *r)
Definition isl_map.c:13137
__isl_give isl_basic_map * isl_basic_map_preimage_multi_aff(__isl_take isl_basic_map *bmap, enum isl_dim_type type, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14427
isl_bool isl_map_has_domain_tuple_id(__isl_keep isl_map *map)
Definition isl_map.c:813
__isl_give isl_map * isl_set_project_onto_map(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:5282
isl_bool isl_map_plain_is_equal(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
Definition isl_map.c:11204
__isl_give isl_set * isl_set_substitute(__isl_take isl_set *set, unsigned pos, __isl_keep isl_aff *subs)
Definition isl_map.c:14181
__isl_give isl_map * isl_map_range_factor_domain(__isl_take isl_map *map)
Definition isl_map.c:11777
void isl_basic_map_print_internal(__isl_keep isl_basic_map *bmap, FILE *out, int indent)
Definition isl_map.c:3933
__isl_give isl_basic_map * isl_basic_map_set_tuple_id(__isl_take isl_basic_map *bmap, enum isl_dim_type type, __isl_take isl_id *id)
Definition isl_map.c:714
__isl_give isl_set * isl_map_deltas(__isl_take isl_map *map)
Definition isl_map.c:9442
__isl_give isl_basic_map * isl_basic_map_set_rational(__isl_take isl_basic_map *bmap)
Definition isl_map.c:2225
isl_bool isl_map_tuple_is_equal(__isl_keep isl_map *map1, enum isl_dim_type type1, __isl_keep isl_map *map2, enum isl_dim_type type2)
Definition isl_map.c:9401
static __isl_give isl_basic_set * nonneg_halfspace(__isl_take isl_space *space, int pos)
Definition isl_map.c:9606
int isl_basic_set_alloc_inequality(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1762
isl_bool isl_map_is_set(__isl_keep isl_map *map)
Definition isl_map.c:6721
static isl_stat isl_basic_set_check_equal_space(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2)
Definition isl_map.c:9843
static isl_stat isl_basic_map_check_compatible_domain(__isl_keep isl_basic_map *bmap, __isl_keep isl_basic_set *bset)
Definition isl_map.c:4103
__isl_give isl_map * isl_map_compute_divs(__isl_take isl_map *map)
Definition isl_map.c:8734
static isl_stat isl_basic_map_check_transformation(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:9327
static __isl_give isl_map * isl_map_restore_space(__isl_take isl_map *map, __isl_take isl_space *space)
Definition isl_map.c:638
static __isl_give isl_map * map_bound_si(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, int value, int upper)
Definition isl_map.c:7389
isl_bool isl_basic_map_plain_is_single_valued(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:12555
__isl_keep isl_space * isl_basic_map_peek_space(__isl_keep const isl_basic_map *bmap)
Definition isl_map.c:404
__isl_give isl_basic_map * isl_basic_map_from_domain(__isl_take isl_basic_set *bset)
Definition isl_map.c:6803
__isl_give isl_set * isl_set_drop_constraints_involving_dims(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3756
static __isl_give isl_basic_map * drop_irrelevant_constraints(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:5085
__isl_give isl_basic_set * isl_basic_set_align_params(__isl_take isl_basic_set *bset, __isl_take isl_space *model)
Definition isl_map.c:13261
__isl_give isl_set * isl_space_universe_set(__isl_take isl_space *space)
Definition isl_map.c:6998
int isl_basic_map_plain_cmp(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
Definition isl_map.c:10996
static __isl_give isl_basic_map * greator(__isl_take isl_space *space, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14080
static __isl_give isl_basic_map * isl_basic_map_domain_reverse(__isl_take isl_basic_map *bmap)
Definition isl_map.c:4593
__isl_give isl_basic_map * isl_basic_map_from_domain_and_range(__isl_take isl_basic_set *domain, __isl_take isl_basic_set *range)
Definition isl_map.c:6841
static __isl_give isl_basic_map * set_ma_divs(__isl_take isl_basic_map *bmap, __isl_keep isl_multi_aff *ma, int n_before, int n_after, int n_div)
Definition isl_map.c:14231
static __isl_give isl_basic_set * basic_set_append_equalities(__isl_take isl_basic_set *bset, __isl_take isl_mat *eq)
Definition isl_map.c:8233
__isl_give isl_basic_map * isl_basic_map_product(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:11378
static __isl_give isl_basic_map * add_ma_strides(__isl_take isl_basic_map *bmap, __isl_keep isl_multi_aff *ma, int n_before, int n_after, int n_div_ma)
Definition isl_map.c:14313
__isl_give isl_basic_map * isl_basic_map_less_or_equal_at(__isl_take isl_space *space, unsigned pos)
Definition isl_map.c:5868
static __isl_give isl_maybe_isl_aff isl_basic_map_try_find_output_mod_ineq(__isl_keep isl_basic_map *bmap, int pos)
Definition isl_map.c:15556
__isl_give isl_basic_map * isl_basic_map_set_tuple_name(__isl_take isl_basic_map *bmap, enum isl_dim_type type, const char *s)
Definition isl_map.c:662
__isl_give isl_basic_set * isl_basic_set_sort_constraints(__isl_take isl_basic_set *bset)
Definition isl_map.c:10982
__isl_give isl_basic_set * isl_basic_set_remove_unknown_divs(__isl_take isl_basic_set *bset)
Definition isl_map.c:3826
__isl_give isl_set * isl_set_product(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:11635
__isl_give isl_set * isl_set_upper_bound_si(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, int value)
Definition isl_map.c:7429
__isl_give isl_id * isl_map_get_tuple_id(__isl_keep isl_map *map, enum isl_dim_type type)
Definition isl_map.c:825
__isl_give isl_set * isl_set_fix_dim_si(__isl_take isl_set *set, unsigned dim, int value)
Definition isl_map.c:7333
isl_bool isl_map_has_tuple_name(__isl_keep isl_map *map, enum isl_dim_type type)
Definition isl_map.c:737
static __isl_give isl_set * isl_basic_set_lexmin_compute_divs(__isl_take isl_basic_set *bset)
Definition isl_map.c:8050
__isl_give isl_map * isl_map_lower_bound_val(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, __isl_take isl_val *value)
Definition isl_map.c:7519
__isl_give isl_basic_set * isl_basic_map_range(__isl_take isl_basic_map *bmap)
Definition isl_map.c:6635
static isl_bool div_may_involve_output(__isl_keep isl_basic_map *bmap, int div)
Definition isl_map.c:12343
static unsigned map_offset(__isl_keep isl_map *map, enum isl_dim_type type)
Definition isl_map.c:197
__isl_give isl_basic_map * isl_basic_map_domain_product(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:11439
static static isl_stat isl_basic_map_check_equal_params(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
Definition isl_map.c:1579
__isl_give isl_basic_set * isl_basic_map_deltas(__isl_take isl_basic_map *bmap)
Definition isl_map.c:9344
isl_bool isl_basic_set_is_params(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1261
isl_bool isl_map_is_product(__isl_keep isl_map *map)
Definition isl_map.c:12853
__isl_give isl_set * isl_set_flatten(__isl_take isl_set *set)
Definition isl_map.c:13020
__isl_give isl_basic_map * isl_basic_map_alloc_space(__isl_take isl_space *space, unsigned extra, unsigned n_eq, unsigned n_ineq)
Definition isl_map.c:1375
__isl_give isl_pw_aff * isl_set_dim_max(__isl_take isl_set *set, int pos)
Definition isl_map.c:8149
isl_bool isl_set_has_tuple_name(__isl_keep isl_set *set)
Definition isl_map.c:857
static __isl_give isl_aff * isl_aff_alloc_vec_prune(__isl_take isl_local_space *ls, __isl_take isl_vec *v)
Definition isl_map.c:15639
__isl_give isl_basic_map * isl_basic_map_universe(__isl_take isl_space *space)
Definition isl_map.c:6902
__isl_give isl_map * isl_map_set_range_tuple_id(__isl_take isl_map *map, __isl_take isl_id *id)
Definition isl_map.c:777
static isl_bool has_any_bound(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos, isl_bool(*fn)(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned pos))
Definition isl_map.c:12181
#define ISL_BASIC_MAP_SORTED
#define ISL_BASIC_MAP_NO_REDUNDANT
isl_stat isl_map_align_params_bin(__isl_keep isl_map **map1, __isl_keep isl_map **map2)
__isl_give isl_basic_map * isl_basic_map_remove_duplicate_constraints(__isl_take isl_basic_map *bmap, int *progress, int detect_divs)
__isl_give isl_basic_map * isl_basic_map_eliminate_vars(__isl_take isl_basic_map *bmap, unsigned pos, unsigned n)
__isl_give isl_basic_map * isl_basic_map_simplify(__isl_take isl_basic_map *bmap)
#define ISL_BASIC_MAP_EMPTY
__isl_give isl_basic_set * isl_basic_set_preimage(__isl_take isl_basic_set *bset, __isl_take isl_mat *mat)
Definition isl_mat.c:1360
#define isl_basic_set_list
isl_stat isl_map_align_params_set(__isl_keep isl_map **map, __isl_keep isl_set **set)
__isl_give isl_basic_map * isl_basic_map_finalize(__isl_take isl_basic_map *bmap)
isl_stat isl_basic_map_check_equal_space(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2)
#define ISL_MAP_DISJOINT
__isl_give isl_basic_map * isl_basic_map_gauss(__isl_take isl_basic_map *bmap, int *progress)
#define ISL_BASIC_MAP_ALL_EQUALITIES
#define ISL_BASIC_MAP_REDUCED_COEFFICIENTS
#define ISL_BASIC_SET_FINAL
isl_stat isl_map_basic_map_check_equal_space(__isl_keep isl_map *map, __isl_keep isl_basic_map *bmap)
#define ISL_BASIC_MAP_RATIONAL
isl_stat isl_map_check_equal_space(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
#define ISL_BASIC_SET_EMPTY
__isl_give isl_basic_map * isl_basic_map_drop_redundant_divs(__isl_take isl_basic_map *bmap)
#define ISL_SET_NORMALIZED
#define isl_set_list
#define ISL_BASIC_SET_SORTED
#define ISL_BASIC_MAP_NO_IMPLICIT
isl_stat isl_map_check_named_params(__isl_keep isl_map *map)
#define ISL_BASIC_MAP_NORMALIZED_DIVS
__isl_give isl_basic_map * isl_basic_map_mark_final(__isl_take isl_basic_map *bmap)
#define ISL_MAP_NORMALIZED
#define isl_set
__isl_give isl_basic_set * isl_basic_set_gauss(__isl_take isl_basic_set *bset, int *progress)
__isl_give isl_basic_set * isl_basic_set_finalize(__isl_take isl_basic_set *bset)
__isl_give isl_basic_map * isl_basic_map_drop_unrelated_constraints(__isl_take isl_basic_map *bmap, __isl_take int *group)
__isl_give isl_set * isl_set_preimage(__isl_take isl_set *set, __isl_take isl_mat *mat)
Definition isl_mat.c:1417
#define isl_basic_set
isl_stat isl_basic_map_check_range(__isl_keep isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
#define ISL_BASIC_MAP_FINAL
__isl_give isl_mat * isl_mat_cow(__isl_take isl_mat *mat)
Definition isl_mat.c:226
__isl_give isl_mat * isl_mat_sub_alloc6(isl_ctx *ctx, isl_int **row, unsigned first_row, unsigned n_row, unsigned first_col, unsigned n_col)
Definition isl_mat.c:148
isl_stat isl_mat_sub_transform(isl_int **row, unsigned n_row, unsigned first_col, __isl_take isl_mat *mat)
Definition isl_mat.c:1452
__isl_give isl_set * isl_morph_set(__isl_take isl_morph *morph, __isl_take isl_set *set)
Definition isl_morph.c:682
__isl_give isl_morph * isl_morph_inverse(__isl_take isl_morph *morph)
Definition isl_morph.c:743
__isl_give isl_morph * isl_basic_set_variable_compression(__isl_keep isl_basic_set *bset, enum isl_dim_type type)
Definition isl_morph.c:476
__isl_give isl_morph * isl_basic_set_parameter_compression(__isl_keep isl_basic_set *bset)
Definition isl_morph.c:568
__isl_give isl_basic_set * isl_morph_basic_set(__isl_take isl_morph *morph, __isl_take isl_basic_set *bset)
Definition isl_morph.c:645
__isl_give isl_morph * isl_morph_copy(__isl_keep isl_morph *morph)
Definition isl_morph.c:59
static struct isl_arg_choice bound[]
Definition isl_options.c:39
__isl_give isl_printer * isl_printer_set_dump(__isl_take isl_printer *p, int dump)
__isl_null isl_reordering * isl_reordering_free(__isl_take isl_reordering *exp)
__isl_give isl_reordering * isl_parameter_alignment_reordering(__isl_keep isl_space *alignee, __isl_keep isl_space *aligner)
__isl_give isl_reordering * isl_reordering_unbind_params_insert_domain(__isl_keep isl_space *space, __isl_keep isl_multi_id *tuple)
__isl_give isl_space * isl_reordering_get_space(__isl_keep isl_reordering *r)
__isl_give isl_vec * isl_basic_set_sample_vec(__isl_take isl_basic_set *bset)
int isl_seq_last_non_zero(isl_int *p, unsigned len)
Definition isl_seq.c:217
void isl_seq_inner_product(isl_int *p1, isl_int *p2, unsigned len, isl_int *prod)
Definition isl_seq.c:301
int isl_seq_is_neg(isl_int *p1, isl_int *p2, unsigned len)
Definition isl_seq.c:192
int isl_seq_first_non_zero(isl_int *p, unsigned len)
Definition isl_seq.c:207
void isl_seq_gcd(isl_int *p, unsigned len, isl_int *gcd)
Definition isl_seq.c:260
void isl_seq_clr(isl_int *p, unsigned len)
Definition isl_seq.c:14
int isl_seq_cmp(isl_int *p1, isl_int *p2, unsigned len)
Definition isl_seq.c:182
void isl_seq_cpy(isl_int *dst, isl_int *src, unsigned len)
Definition isl_seq.c:42
uint32_t isl_seq_get_hash(isl_int *p, unsigned len)
Definition isl_seq.c:357
int isl_seq_eq(isl_int *p1, isl_int *p2, unsigned len)
Definition isl_seq.c:173
int isl_seq_any_non_zero(isl_int *p, unsigned len)
Definition isl_seq.c:230
void isl_seq_neg(isl_int *dst, isl_int *src, unsigned len)
Definition isl_seq.c:35
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
isl_stat isl_space_check_is_set(__isl_keep isl_space *space)
Definition isl_space.c:83
isl_size isl_space_wrapped_dim(__isl_keep isl_space *space, enum isl_dim_type outer, enum isl_dim_type inner)
Definition isl_space.c:382
__isl_give isl_space * isl_space_flatten(__isl_take isl_space *space)
Definition isl_space.c:3023
isl_size isl_space_offset(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:397
__isl_give isl_space * isl_space_bind_set(__isl_take isl_space *space, __isl_keep isl_multi_id *tuple)
Definition isl_space.c:2435
__isl_give isl_space * isl_space_cow(__isl_take isl_space *space)
Definition isl_space.c:458
isl_bool isl_space_has_named_params(__isl_keep isl_space *space)
Definition isl_space.c:3319
static isl_bool match(__isl_keep isl_space *space1, enum isl_dim_type type1, __isl_keep isl_space *space2, enum isl_dim_type type2)
Definition isl_space.c:1145
__isl_give isl_space * isl_space_reset(__isl_take isl_space *space, enum isl_dim_type type)
Definition isl_space.c:3005
__isl_give isl_space * isl_space_bind_map_domain(__isl_take isl_space *space, __isl_keep isl_multi_id *tuple)
Definition isl_space.c:2458
__isl_give isl_space * isl_space_lift(__isl_take isl_space *space, unsigned n_local)
Definition isl_space.c:3149
__isl_give isl_space * isl_space_reverse_wrapped(__isl_take isl_space *space, enum isl_dim_type type)
Definition isl_space.c:2061
__isl_give isl_space * isl_space_copy_ids_if_unset(__isl_take isl_space *dst, enum isl_dim_type dst_type, __isl_keep isl_space *src, enum isl_dim_type src_type)
Definition isl_space.c:3111
isl_bool isl_space_has_equal_ids(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:1182
isl_stat isl_space_check_range_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:175
__isl_give isl_space * isl_space_underlying(__isl_take isl_space *space, unsigned n_div)
Definition isl_space.c:2574
isl_stat isl_space_check_domain_tuples(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2661
__isl_give isl_space * isl_space_replace_params(__isl_take isl_space *dst, __isl_keep isl_space *src)
Definition isl_space.c:3060
isl_stat isl_space_check_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:143
isl_bool isl_space_may_be_set(__isl_keep isl_space *space)
Definition isl_space.c:2985
isl_stat isl_space_check_equal_tuples(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:1059
isl_bool isl_space_is_named_or_nested(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:2971
isl_stat isl_space_check_domain_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:159
int isl_space_cmp(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:3460
isl_stat isl_space_check_range(__isl_keep isl_space *space, enum isl_dim_type type, unsigned first, unsigned n)
void isl_tab_free(struct isl_tab *tab)
Definition isl_tab.c:204
struct isl_tab_undo * isl_tab_snap(struct isl_tab *tab)
Definition isl_tab.c:3754
isl_stat isl_tab_add_ineq(struct isl_tab *tab, isl_int *ineq)
Definition isl_tab.c:1906
__isl_give struct isl_tab * isl_tab_from_basic_set(__isl_keep isl_basic_set *bset, int track)
Definition isl_tab.c:2434
isl_stat isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap)
Definition isl_tab.c:4096
#define ISL_OPT_MAX
Definition isl_tab.h:253
#define ISL_OPT_FULL
Definition isl_tab.h:255
#define ISL_OPT_QE
Definition isl_tab.h:257
static __isl_give isl_map * basic_map_partial_lexopt(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *dom, __isl_give isl_set **empty, int max)
static __isl_give isl_pw_multi_aff * basic_map_partial_lexopt_pw_multi_aff(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *dom, __isl_give isl_set **empty, int max)
int sv
Definition isl_test.c:3554
enum isl_fold type
Definition isl_test.c:3867
const char * set
Definition isl_test.c:1364
const char * ma
Definition isl_test.c:7387
const char * map
Definition isl_test.c:1791
int equal
Definition isl_test.c:7720
const char * pma
Definition isl_test.c:3019
const char * p
Definition isl_test.c:8454
const char * offset
Definition isl_test.c:1577
const char * name
Definition isl_test.c:10749
const char * map1
Definition isl_test.c:365
const char * aff
Definition isl_test.c:7130
const char * obj
Definition isl_test.c:3166
const char * map2
Definition isl_test.c:366
const char * set1
Definition isl_test.c:4055
const char * tuple
Definition isl_test.c:6860
const char * res
Definition isl_test.c:783
const char * set2
Definition isl_test.c:4056
const char * arg
Definition isl_test.c:782
const char * size
Definition isl_test.c:1578
const char * f
Definition isl_test.c:8453
const char * id
Definition isl_test.c:7131
static __isl_give isl_union_map * total(__isl_take isl_union_map *umap, __isl_give isl_map *(*fn)(__isl_take isl_map *))
__isl_give isl_val * isl_val_int_from_isl_int(isl_ctx *ctx, isl_int n)
Definition isl_val.c:185
__isl_give isl_val * isl_val_alloc(isl_ctx *ctx)
Definition isl_val.c:22
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_give isl_local_space * isl_local_space_from_space(__isl_take isl_space *space)
__isl_give isl_local_space * isl_local_space_drop_dims(__isl_take isl_local_space *ls, enum isl_dim_type type, unsigned first, unsigned n)
isl_size isl_local_space_dim(__isl_keep isl_local_space *ls, enum isl_dim_type type)
__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_local_space * isl_local_space_wrap(__isl_take isl_local_space *ls)
__isl_give isl_space * isl_local_space_get_space(__isl_keep isl_local_space *ls)
isl_lp_result
Definition lp.h:17
@ isl_lp_error
Definition lp.h:18
@ isl_lp_ok
Definition lp.h:19
@ isl_lp_empty
Definition lp.h:21
@ isl_lp_unbounded
Definition lp.h:20
__isl_give isl_basic_map * isl_basic_map_drop_constraints_not_involving_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3614
__isl_export __isl_give isl_map * isl_map_domain_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11649
__isl_give isl_basic_map * isl_basic_map_deltas_map(__isl_take isl_basic_map *bmap)
Definition isl_map.c:9468
__isl_give isl_basic_map * isl_basic_map_zip(__isl_take isl_basic_map *bmap)
Definition isl_map.c:13716
__isl_give isl_basic_map * isl_basic_map_drop_unused_params(__isl_take isl_basic_map *bmap)
__isl_give isl_printer * isl_printer_print_basic_map(__isl_take isl_printer *printer, __isl_keep isl_basic_map *bmap)
isl_bool isl_map_has_equal_space(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
__isl_export __isl_give isl_map * isl_map_drop_unused_params(__isl_take isl_map *map)
__isl_give isl_basic_map * isl_basic_map_drop_constraints_involving_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3666
__isl_null isl_basic_map * isl_basic_map_free(__isl_take isl_basic_map *bmap)
Definition isl_map.c:1503
__isl_give isl_basic_map * isl_basic_map_domain_map(__isl_take isl_basic_map *bmap)
Definition isl_map.c:6650
__isl_give isl_basic_map * isl_basic_map_range_product(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:11486
__isl_give isl_basic_map * isl_basic_map_eliminate(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n)
__isl_export isl_bool isl_set_is_wrapping(__isl_keep isl_set *set)
Definition isl_map.c:12804
isl_bool isl_map_can_range_curry(__isl_keep isl_map *map)
Definition isl_map.c:13827
isl_bool isl_map_can_uncurry(__isl_keep isl_map *map)
Definition isl_map.c:13859
__isl_export __isl_give isl_basic_map * isl_basic_map_reverse(__isl_take isl_basic_map *bmap)
Definition isl_map.c:4544
__isl_give isl_basic_map * isl_basic_map_remove_redundancies(__isl_take isl_basic_map *bmap)
isl_bool isl_map_can_curry(__isl_keep isl_map *map)
Definition isl_map.c:13781
__isl_export __isl_give isl_basic_map * isl_basic_map_intersect_domain(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset)
Definition isl_map.c:4118
__isl_give isl_basic_map * isl_basic_map_range_map(__isl_take isl_basic_map *bmap)
Definition isl_map.c:6680
__isl_export __isl_give isl_map * isl_map_range_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11659
__isl_export __isl_give isl_map * isl_map_project_out_all_params(__isl_take isl_map *map)
__isl_export __isl_give isl_basic_map * isl_basic_map_intersect_range(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset)
Definition isl_map.c:4167
__isl_give isl_basic_map * isl_basic_map_copy(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:1479
__isl_overload __isl_give isl_map * isl_map_project_out_param_id_list(__isl_take isl_map *map, __isl_take isl_id_list *list)
__isl_export __isl_give isl_map * isl_basic_map_lexmin(__isl_take isl_basic_map *bmap)
__isl_give isl_basic_map * isl_basic_map_product(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:11378
__isl_give isl_basic_map * isl_basic_map_domain_product(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
Definition isl_map.c:11439
__isl_overload __isl_give isl_map * isl_map_project_out_param_id(__isl_take isl_map *map, __isl_take isl_id *id)
__isl_export isl_bool isl_map_is_subset(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
__isl_give isl_mat * isl_mat_copy(__isl_keep isl_mat *mat)
Definition isl_mat.c:202
__isl_null isl_mat * isl_mat_free(__isl_take isl_mat *mat)
Definition isl_mat.c:240
__isl_give isl_mat * isl_mat_alloc(isl_ctx *ctx, unsigned n_row, unsigned n_col)
Definition isl_mat.c:53
isl_ctx * isl_mat_get_ctx(__isl_keep isl_mat *mat)
Definition isl_mat.c:25
__isl_give isl_printer * isl_printer_set_indent(__isl_take isl_printer *p, int indent)
__isl_null isl_printer * isl_printer_free(__isl_take isl_printer *printer)
__isl_give isl_printer * isl_printer_to_file(isl_ctx *ctx, FILE *file)
__isl_give isl_printer * isl_printer_start_line(__isl_take isl_printer *p)
__isl_give isl_printer * isl_printer_end_line(__isl_take isl_printer *p)
a(0)
b(9)
__isl_give isl_set * isl_set_copy(__isl_keep isl_set *set)
Definition isl_map.c:1470
__isl_give isl_printer * isl_printer_print_basic_set(__isl_take isl_printer *printer, __isl_keep isl_basic_set *bset)
__isl_give isl_basic_set * isl_basic_set_copy(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1465
static __isl_give isl_set * set_from_map(__isl_take isl_map *map)
Definition set_from_map.c:5
isl_bool isl_space_has_equal_params(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:1173
__isl_give isl_space * isl_space_set_tuple_id(__isl_take isl_space *space, enum isl_dim_type type, __isl_take isl_id *id)
Definition isl_space.c:669
__isl_null isl_space * isl_space_free(__isl_take isl_space *space)
Definition isl_space.c:478
__isl_export __isl_give isl_space * isl_space_reverse(__isl_take isl_space *space)
Definition isl_space.c:1997
__isl_export __isl_give isl_space * isl_space_flatten_range(__isl_take isl_space *space)
Definition isl_space.c:3048
__isl_give isl_space * isl_space_range_factor_range(__isl_take isl_space *space)
Definition isl_space.c:1859
__isl_give isl_space * isl_space_range_map(__isl_take isl_space *space)
Definition isl_space.c:2294
__isl_give isl_space * isl_space_from_range(__isl_take isl_space *space)
Definition isl_space.c:2266
__isl_export __isl_give isl_space * isl_space_params(__isl_take isl_space *space)
Definition isl_space.c:2305
__isl_export __isl_give isl_space * isl_space_product(__isl_take isl_space *left, __isl_take isl_space *right)
Definition isl_space.c:1585
__isl_export __isl_give isl_space * isl_space_curry(__isl_take isl_space *space)
Definition isl_space.c:3222
__isl_give isl_space * isl_space_domain_wrapped_range(__isl_take isl_space *space)
Definition isl_space.c:1905
isl_bool isl_space_has_tuple_id(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:605
__isl_give isl_space * isl_space_insert_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, unsigned n)
Definition isl_space.c:1345
isl_ctx * isl_space_get_ctx(__isl_keep isl_space *space)
Definition isl_space.c:23
isl_bool isl_space_range_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:2895
__isl_give isl_id * isl_space_get_tuple_id(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:631
__isl_give isl_space * isl_space_set_from_params(__isl_take isl_space *space)
Definition isl_space.c:2321
__isl_give isl_space * isl_space_factor_domain(__isl_take isl_space *space)
Definition isl_space.c:1809
__isl_give isl_space * isl_space_copy(__isl_keep isl_space *space)
Definition isl_space.c:469
isl_bool isl_space_has_dim_name(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos)
Definition isl_space.c:885
__isl_give isl_space * isl_space_range_curry(__isl_take isl_space *space)
Definition isl_space.c:3266
__isl_give isl_space * isl_space_map_from_domain_and_range(__isl_take isl_space *domain, __isl_take isl_space *range)
Definition isl_space.c:1967
__isl_give isl_space * isl_space_set_dim_id(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
Definition isl_space.c:737
__isl_give isl_space * isl_space_set_tuple_name(__isl_take isl_space *space, enum isl_dim_type type, const char *s)
Definition isl_space.c:818
__isl_keep const char * isl_space_get_dim_name(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos)
Definition isl_space.c:896
__isl_export __isl_give isl_space * isl_space_wrap(__isl_take isl_space *space)
Definition isl_space.c:2926
__isl_export isl_bool isl_space_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:2869
__isl_export __isl_give isl_space * isl_space_range_reverse(__isl_take isl_space *space)
Definition isl_space.c:2132
__isl_give isl_space * isl_space_join(__isl_take isl_space *left, __isl_take isl_space *right)
Definition isl_space.c:1537
__isl_give isl_space * isl_space_domain_factor_domain(__isl_take isl_space *space)
Definition isl_space.c:1675
__isl_export __isl_give isl_space * isl_space_range(__isl_take isl_space *space)
Definition isl_space.c:2257
isl_bool isl_space_is_params(__isl_keep isl_space *space)
Definition isl_space.c:211
__isl_keep const char * isl_space_get_tuple_name(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:852
__isl_export __isl_give isl_space * isl_space_unwrap(__isl_take isl_space *space)
Definition isl_space.c:2951
__isl_give isl_space * isl_space_set_alloc(isl_ctx *ctx, unsigned nparam, unsigned dim)
Definition isl_space.c:188
__isl_export __isl_give isl_space * isl_space_uncurry(__isl_take isl_space *space)
Definition isl_space.c:3296
__isl_export __isl_give isl_space * isl_space_flatten_domain(__isl_take isl_space *space)
Definition isl_space.c:3038
__isl_export __isl_give isl_space * isl_space_map_from_set(__isl_take isl_space *space)
Definition isl_space.c:1927
isl_bool isl_space_has_tuple_name(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:841
isl_bool isl_space_can_curry(__isl_keep isl_space *space)
Definition isl_space.c:3214
__isl_give isl_space * isl_space_domain_product(__isl_take isl_space *left, __isl_take isl_space *right)
Definition isl_space.c:1623
int isl_space_find_dim_by_id(__isl_keep isl_space *space, enum isl_dim_type type, __isl_keep isl_id *id)
Definition isl_space.c:903
__isl_give isl_space * isl_space_set_dim_name(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, __isl_keep const char *name)
isl_bool isl_space_has_dim_id(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos)
Definition isl_space.c:799
__isl_export isl_bool isl_space_is_equal(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2605
__isl_give isl_space * isl_space_range_factor_domain(__isl_take isl_space *space)
Definition isl_space.c:1784
__isl_give isl_space * isl_space_drop_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned first, unsigned num)
Definition isl_space.c:2141
__isl_give isl_id * isl_space_get_dim_id(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos)
Definition isl_space.c:807
__isl_give isl_space * isl_space_range_product(__isl_take isl_space *left, __isl_take isl_space *right)
Definition isl_space.c:1648
__isl_give isl_space * isl_space_domain_map(__isl_take isl_space *space)
Definition isl_space.c:2281
__isl_give isl_space * isl_space_zip(__isl_take isl_space *space)
Definition isl_space.c:3183
__isl_export __isl_give isl_space * isl_space_domain_reverse(__isl_take isl_space *space)
Definition isl_space.c:2115
isl_size isl_space_dim(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:372
isl_bool isl_space_is_set(__isl_keep isl_space *space)
Definition isl_space.c:70
__isl_export __isl_give isl_space * isl_space_drop_all_params(__isl_take isl_space *space)
Definition isl_space.c:2222
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_bool isl_space_can_zip(__isl_keep isl_space *space)
Definition isl_space.c:3171
__isl_give isl_space * isl_space_domain_factor_range(__isl_take isl_space *space)
Definition isl_space.c:1711
isl_bool isl_space_has_equal_tuples(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:1029
isl_bool isl_space_can_uncurry(__isl_keep isl_space *space)
Definition isl_space.c:3288
__isl_give isl_space * isl_space_reset_tuple_id(__isl_take isl_space *space, enum isl_dim_type type)
Definition isl_space.c:712
__isl_export __isl_give isl_space * isl_space_wrapped_reverse(__isl_take isl_space *space)
Definition isl_space.c:2098
__isl_give isl_space * isl_space_factor_range(__isl_take isl_space *space)
Definition isl_space.c:1884
__isl_give isl_space * isl_space_alloc(isl_ctx *ctx, unsigned nparam, unsigned n_in, unsigned n_out)
Definition isl_space.c:28
__isl_give isl_space * isl_space_reset_user(__isl_take isl_space *space)
Definition isl_space.c:946
isl_bool isl_space_domain_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:2882
isl_bool isl_space_can_range_curry(__isl_keep isl_space *space)
Definition isl_space.c:3251
__isl_give isl_space * isl_space_range_wrapped_range(__isl_take isl_space *space)
Definition isl_space.c:1921
__isl_give isl_space * isl_space_move_dims(__isl_take isl_space *space, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n)
Definition isl_space.c:1422
int isl_space_find_dim_by_name(__isl_keep isl_space *space, enum isl_dim_type type, const char *name)
Definition isl_space.c:922
isl_bool isl_space_is_product(__isl_keep isl_space *space)
Definition isl_space.c:2910
__isl_export __isl_give isl_space * isl_space_domain(__isl_take isl_space *space)
Definition isl_space.c:2232
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_all
Definition space_type.h:20
@ isl_dim_div
Definition space_type.h:19
@ isl_dim_out
Definition space_type.h:17
@ isl_dim_cst
Definition space_type.h:14
struct isl_blk block2
struct isl_vec * sample
struct isl_ctx * ctx
isl_int ** ineq
isl_space * dim
isl_int * data
Definition isl_blk.h:21
enum isl_error error
isl_int normalize_gcd
isl_int one
enum isl_dim_type preserve_type
Definition isl_map.c:9044
__isl_give isl_space *(* other_factor)(__isl_take isl_space *space)
Definition isl_map.c:9045
__isl_give isl_map *(* product)(__isl_take isl_map *factor, __isl_take isl_map *other)
Definition isl_map.c:9046
struct isl_basic_map * p[1]
unsigned flags
unsigned n_col
struct isl_ctx * ctx
isl_int ** row
unsigned empty
Definition isl_tab.h:179
isl_int d
isl_int n
isl_int * el
struct isl_ctx * ctx
unsigned size
static Kind params
static Signature map_product
static Signature range
static Signature set_to_map
static Signature domain
__isl_give isl_val * isl_val_copy(__isl_keep isl_val *v)
Definition isl_val.c:219
__isl_give isl_val * isl_val_sub_ui(__isl_take isl_val *v1, unsigned long v2)
Definition isl_val.c:763
isl_ctx * isl_val_get_ctx(__isl_keep isl_val *val)
Definition isl_val.c:355
__isl_export __isl_give isl_val * isl_val_nan(isl_ctx *ctx)
Definition isl_val.c:62
__isl_null isl_val * isl_val_free(__isl_take isl_val *v)
Definition isl_val.c:263
__isl_export __isl_give isl_val * isl_val_neg(__isl_take isl_val *v)
Definition isl_val.c:410
__isl_export isl_bool isl_val_is_int(__isl_keep isl_val *v)
Definition isl_val.c:1141
struct isl_multi_val isl_multi_val
Definition val_type.h:16
__isl_null isl_vec * isl_vec_free(__isl_take isl_vec *vec)
Definition isl_vec.c:234
__isl_give isl_vec * isl_vec_copy(__isl_keep isl_vec *vec)
Definition isl_vec.c:198
__isl_give isl_vec * isl_vec_drop_els(__isl_take isl_vec *vec, unsigned pos, unsigned n)
Definition isl_vec.c:535
__isl_give isl_vec * isl_vec_alloc(isl_ctx *ctx, unsigned size)
Definition isl_vec.c:33
n
Definition youcefn.c:8