Polly 23.0.0git
isl_space.c
Go to the documentation of this file.
1/*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2013-2014 Ecole Normale Superieure
5 * Copyright 2018-2019 Cerebras Systems
6 *
7 * Use of this software is governed by the MIT license
8 *
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA
15 */
16
17#include <stdlib.h>
18#include <string.h>
19#include <isl_space_private.h>
20#include <isl_id_private.h>
21#include <isl_reordering.h>
22
24{
25 return space ? space->ctx : NULL;
26}
27
29 unsigned nparam, unsigned n_in, unsigned n_out)
30{
31 isl_space *space;
32
33 space = isl_alloc_type(ctx, struct isl_space);
34 if (!space)
35 return NULL;
36
37 space->ctx = ctx;
38 isl_ctx_ref(ctx);
39 space->ref = 1;
40 space->nparam = nparam;
41 space->n_in = n_in;
42 space->n_out = n_out;
43
44 space->tuple_id[0] = NULL;
45 space->tuple_id[1] = NULL;
46
47 space->nested[0] = NULL;
48 space->nested[1] = NULL;
49
50 space->n_id = 0;
51 space->ids = NULL;
52
53 return space;
54}
55
56/* Mark the space as being that of a set, by setting the domain tuple
57 * to isl_id_none.
58 */
60{
61 space = isl_space_cow(space);
62 if (!space)
63 return NULL;
65 return space;
66}
67
68/* Is the space that of a set?
69 */
71{
72 if (!space)
73 return isl_bool_error;
74 if (space->n_in != 0 || space->nested[0])
75 return isl_bool_false;
76 if (space->tuple_id[0] != &isl_id_none)
77 return isl_bool_false;
78 return isl_bool_true;
79}
80
81/* Check that "space" is a set space.
82 */
84{
85 isl_bool is_set;
86
87 is_set = isl_space_is_set(space);
88 if (is_set < 0)
89 return isl_stat_error;
90 if (!is_set)
92 "space is not a set", return isl_stat_error);
93 return isl_stat_ok;
94}
95
96/* Check that "space" is a proper set space,
97 * i.e., the space of a set that is not a parameter domain.
98 */
100{
101 isl_bool is_params, is_set;
102
103 is_params = isl_space_is_params(space);
104 is_set = isl_space_is_set(space);
105 if (is_params < 0 || is_set < 0)
106 return isl_stat_error;
107 if (is_params || !is_set)
109 "space is not a proper set", return isl_stat_error);
110 return isl_stat_ok;
111}
112
113/* Is the given space that of a map?
114 */
116{
117 int r;
118
119 if (!space)
120 return isl_bool_error;
121 r = space->tuple_id[0] != &isl_id_none &&
122 space->tuple_id[1] != &isl_id_none;
123 return isl_bool_ok(r);
124}
125
126/* Check that "space" is the space of a map.
127 */
129{
130 isl_bool is_space;
131
132 is_space = isl_space_is_map(space);
133 if (is_space < 0)
134 return isl_stat_error;
135 if (!is_space)
137 "expecting map space", return isl_stat_error);
138 return isl_stat_ok;
139}
140
141/* Check that "space" is the space of a set wrapping a map space.
142 */
144{
145 isl_bool wrapping;
146
147 wrapping = isl_space_is_wrapping(space);
148 if (wrapping < 0)
149 return isl_stat_error;
150 if (!wrapping)
152 "not a product", return isl_stat_error);
153 return isl_stat_ok;
154}
155
156/* Check that "space" is the space of a map
157 * where the domain is a wrapped map space.
158 */
160{
161 isl_bool wrapping;
162
163 wrapping = isl_space_domain_is_wrapping(space);
164 if (wrapping < 0)
165 return isl_stat_error;
166 if (!wrapping)
168 "domain not a product", return isl_stat_error);
169 return isl_stat_ok;
170}
171
172/* Check that "space" is the space of a map
173 * where the range is a wrapped map space.
174 */
176{
177 isl_bool wrapping;
178
179 wrapping = isl_space_range_is_wrapping(space);
180 if (wrapping < 0)
181 return isl_stat_error;
182 if (!wrapping)
184 "range not a product", return isl_stat_error);
185 return isl_stat_ok;
186}
187
189 unsigned nparam, unsigned dim)
190{
191 isl_space *space;
192 space = isl_space_alloc(ctx, nparam, 0, dim);
193 space = mark_as_set(space);
194 return space;
195}
196
197/* Mark the space as being that of a parameter domain, by setting
198 * both tuples to isl_id_none.
199 */
201{
202 if (!space)
203 return NULL;
206 return space;
207}
208
209/* Is the space that of a parameter domain?
210 */
212{
213 if (!space)
214 return isl_bool_error;
215 if (space->n_in != 0 || space->nested[0] ||
216 space->n_out != 0 || space->nested[1])
217 return isl_bool_false;
218 if (space->tuple_id[0] != &isl_id_none)
219 return isl_bool_false;
220 if (space->tuple_id[1] != &isl_id_none)
221 return isl_bool_false;
222 return isl_bool_true;
223}
224
225/* Create a space for a parameter domain.
226 */
228{
229 isl_space *space;
230 space = isl_space_alloc(ctx, nparam, 0, 0);
231 space = mark_as_params(space);
232 return space;
233}
234
235/* Create a space for a parameter domain, without any parameters.
236 */
241
243 enum isl_dim_type type, unsigned pos)
244{
245 if (isl_space_check_range(space, type, pos, 1) < 0)
246 return isl_size_error;
247
248 switch (type) {
249 case isl_dim_param:
250 return pos;
251 case isl_dim_in:
252 return pos + space->nparam;
253 case isl_dim_out:
254 return pos + space->nparam + space->n_in;
255 default:
257 }
258 return isl_size_error;
259}
260
261/* Extend length of ids array to the total number of dimensions.
262 */
264{
265 isl_id **ids;
266 int i;
267 isl_size dim;
268
269 dim = isl_space_dim(space, isl_dim_all);
270 if (dim < 0)
271 return isl_space_free(space);
272 if (dim <= space->n_id)
273 return space;
274
275 if (!space->ids) {
276 space->ids = isl_calloc_array(space->ctx, isl_id *, dim);
277 if (!space->ids)
278 goto error;
279 } else {
280 ids = isl_realloc_array(space->ctx, space->ids, isl_id *, dim);
281 if (!ids)
282 goto error;
283 space->ids = ids;
284 for (i = space->n_id; i < dim; ++i)
285 space->ids[i] = NULL;
286 }
287
288 space->n_id = dim;
289
290 return space;
291error:
292 isl_space_free(space);
293 return NULL;
294}
295
297 enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
298{
299 isl_size gpos;
300
301 space = isl_space_cow(space);
302
303 gpos = global_pos(space, type, pos);
304 if (gpos < 0)
305 goto error;
306
307 if (gpos >= space->n_id) {
308 if (!id)
309 return space;
310 space = extend_ids(space);
311 if (!space)
312 goto error;
313 }
314
315 space->ids[gpos] = id;
316
317 return space;
318error:
319 isl_id_free(id);
320 isl_space_free(space);
321 return NULL;
322}
323
325 enum isl_dim_type type, unsigned pos)
326{
327 isl_size gpos;
328
329 gpos = global_pos(space, type, pos);
330 if (gpos < 0)
331 return NULL;
332 if (gpos >= space->n_id)
333 return NULL;
334 return space->ids[gpos];
335}
336
337/* Return the nested space at the given position.
338 */
340 int pos)
341{
342 if (!space)
343 return NULL;
344 if (!space->nested[pos])
346 "no nested space", return NULL);
347 return space->nested[pos];
348}
349
350static unsigned offset(__isl_keep isl_space *space, enum isl_dim_type type)
351{
352 switch (type) {
353 case isl_dim_param: return 0;
354 case isl_dim_in: return space->nparam;
355 case isl_dim_out: return space->nparam + space->n_in;
356 default: return 0;
357 }
358}
359
360static unsigned n(__isl_keep isl_space *space, enum isl_dim_type type)
361{
362 switch (type) {
363 case isl_dim_param: return space->nparam;
364 case isl_dim_in: return space->n_in;
365 case isl_dim_out: return space->n_out;
366 case isl_dim_all:
367 return space->nparam + space->n_in + space->n_out;
368 default: return 0;
369 }
370}
371
373{
374 if (!space)
375 return isl_size_error;
376 return n(space, type);
377}
378
379/* Return the dimensionality of tuple "inner" within the wrapped relation
380 * inside tuple "outer".
381 */
383 enum isl_dim_type outer, enum isl_dim_type inner)
384{
385 int pos;
386
387 if (!space)
388 return isl_size_error;
389 if (outer != isl_dim_in && outer != isl_dim_out)
391 "only input, output and set tuples "
392 "can have nested relations", return isl_size_error);
393 pos = outer - isl_dim_in;
394 return isl_space_dim(isl_space_peek_nested(space, pos), inner);
395}
396
398{
399 if (!space)
400 return isl_size_error;
401 return offset(space, type);
402}
403
405 enum isl_dim_type dst_type, unsigned offset, __isl_keep isl_space *src,
406 enum isl_dim_type src_type)
407{
408 int i;
409 isl_id *id;
410
411 if (!dst)
412 return NULL;
413
414 for (i = 0; i < n(src, src_type); ++i) {
415 id = get_id(src, src_type, i);
416 if (!id)
417 continue;
418 isl_id_free(get_id(dst, dst_type, offset + i));
419 dst = set_id(dst, dst_type, offset + i, isl_id_copy(id));
420 if (!dst)
421 return NULL;
422 }
423 return dst;
424}
425
427{
428 isl_space *dup;
429 if (!space)
430 return NULL;
431 dup = isl_space_alloc(space->ctx,
432 space->nparam, space->n_in, space->n_out);
433 if (!dup)
434 return NULL;
435 if (space->tuple_id[0] &&
436 !(dup->tuple_id[0] = isl_id_copy(space->tuple_id[0])))
437 goto error;
438 if (space->tuple_id[1] &&
439 !(dup->tuple_id[1] = isl_id_copy(space->tuple_id[1])))
440 goto error;
441 if (space->nested[0] &&
442 !(dup->nested[0] = isl_space_copy(space->nested[0])))
443 goto error;
444 if (space->nested[1] &&
445 !(dup->nested[1] = isl_space_copy(space->nested[1])))
446 goto error;
447 if (!space->ids)
448 return dup;
450 dup = copy_ids(dup, isl_dim_in, 0, space, isl_dim_in);
451 dup = copy_ids(dup, isl_dim_out, 0, space, isl_dim_out);
452 return dup;
453error:
455 return NULL;
456}
457
459{
460 if (!space)
461 return NULL;
462
463 if (space->ref == 1)
464 return space;
465 space->ref--;
466 return isl_space_dup(space);
467}
468
470{
471 if (!space)
472 return NULL;
473
474 space->ref++;
475 return space;
476}
477
479{
480 int i;
481
482 if (!space)
483 return NULL;
484
485 if (--space->ref > 0)
486 return NULL;
487
488 isl_id_free(space->tuple_id[0]);
489 isl_id_free(space->tuple_id[1]);
490
491 isl_space_free(space->nested[0]);
492 isl_space_free(space->nested[1]);
493
494 for (i = 0; i < space->n_id; ++i)
495 isl_id_free(space->ids[i]);
496 free(space->ids);
497 isl_ctx_deref(space->ctx);
498
499 free(space);
500
501 return NULL;
502}
503
504/* Check if "s" is a valid dimension or tuple name.
505 * We currently only forbid names that look like a number.
506 *
507 * s is assumed to be non-NULL.
508 */
509static int name_ok(isl_ctx *ctx, const char *s)
510{
511 char *p;
512
513 strtol(s, &p, 0);
514 if (p != s)
515 isl_die(ctx, isl_error_invalid, "name looks like a number",
516 return 0);
517
518 return 1;
519}
520
521/* Return a copy of the nested space at the given position.
522 */
528
529/* Return the nested space at the given position.
530 * This may be either a copy or the nested space itself
531 * if there is only one reference to "space".
532 * This allows the nested space to be modified inplace
533 * if both "space" and the nested space have only a single reference.
534 * The caller is not allowed to modify "space" between this call and
535 * a subsequent call to isl_space_restore_nested.
536 * The only exception is that isl_space_free can be called instead.
537 */
539 int pos)
540{
542
543 if (!space)
544 return NULL;
545 if (space->ref != 1)
546 return isl_space_get_nested(space, pos);
547 nested = space->nested[pos];
548 space->nested[pos] = NULL;
549 return nested;
550}
551
552/* Replace the nested space at the given position by "nested",
553 * where this nested space of "space" may be missing
554 * due to a preceding call to isl_space_take_nested.
555 * However, in this case, "space" only has a single reference and
556 * then the call to isl_space_cow has no effect.
557 */
560{
561 if (!space || !nested)
562 goto error;
563
564 if (space->nested[pos] == nested) {
566 return space;
567 }
568
569 space = isl_space_cow(space);
570 if (!space)
571 goto error;
572 isl_space_free(space->nested[pos]);
573 space->nested[pos] = nested;
574
575 return space;
576error:
577 isl_space_free(space);
579 return NULL;
580}
581
582/* Is it possible for the given dimension type to have a tuple id?
583 */
585 enum isl_dim_type type)
586{
587 if (!space)
588 return 0;
589 if (isl_space_is_params(space))
590 isl_die(space->ctx, isl_error_invalid,
591 "parameter spaces don't have tuple ids", return 0);
592 if (isl_space_is_set(space) && type != isl_dim_set)
593 isl_die(space->ctx, isl_error_invalid,
594 "set spaces can only have a set id", return 0);
595 if (type != isl_dim_in && type != isl_dim_out)
596 isl_die(space->ctx, isl_error_invalid,
597 "only input, output and set tuples can have ids",
598 return 0);
599
600 return 1;
601}
602
603/* Does the tuple have an id?
604 */
606 enum isl_dim_type type)
607{
608 if (!space_can_have_id(space, type))
609 return isl_bool_error;
610 return isl_bool_ok(space->tuple_id[type - isl_dim_in] != NULL);
611}
612
613/* Does the domain tuple of the map space "space" have an identifier?
614 */
621
622/* Does the range tuple of the map space "space" have an identifier?
623 */
630
632 enum isl_dim_type type)
633{
634 int has_id;
635
636 if (!space)
637 return NULL;
638 has_id = isl_space_has_tuple_id(space, type);
639 if (has_id < 0)
640 return NULL;
641 if (!has_id)
642 isl_die(space->ctx, isl_error_invalid,
643 "tuple has no id", return NULL);
644 return isl_id_copy(space->tuple_id[type - isl_dim_in]);
645}
646
647/* Return the identifier of the domain tuple of the map space "space",
648 * assuming it has one.
649 */
651 __isl_keep isl_space *space)
652{
653 if (isl_space_check_is_map(space) < 0)
654 return NULL;
655 return isl_space_get_tuple_id(space, isl_dim_in);
656}
657
658/* Return the identifier of the range tuple of the map space "space",
659 * assuming it has one.
660 */
662 __isl_keep isl_space *space)
663{
664 if (isl_space_check_is_map(space) < 0)
665 return NULL;
666 return isl_space_get_tuple_id(space, isl_dim_out);
667}
668
671{
672 space = isl_space_cow(space);
673 if (!space || !id)
674 goto error;
675 if (type != isl_dim_in && type != isl_dim_out)
676 isl_die(space->ctx, isl_error_invalid,
677 "only input, output and set tuples can have names",
678 goto error);
679
680 isl_id_free(space->tuple_id[type - isl_dim_in]);
681 space->tuple_id[type - isl_dim_in] = id;
682
683 return space;
684error:
685 isl_id_free(id);
686 isl_space_free(space);
687 return NULL;
688}
689
690/* Replace the identifier of the domain tuple of the map space "space"
691 * by "id".
692 */
695{
696 if (isl_space_check_is_map(space) < 0)
697 space = isl_space_free(space);
698 return isl_space_set_tuple_id(space, isl_dim_in, id);
699}
700
701/* Replace the identifier of the range tuple of the map space "space"
702 * by "id".
703 */
706{
707 if (isl_space_check_is_map(space) < 0)
708 space = isl_space_free(space);
709 return isl_space_set_tuple_id(space, isl_dim_out, id);
710}
711
713 enum isl_dim_type type)
714{
715 space = isl_space_cow(space);
716 if (!space)
717 return NULL;
718 if (type != isl_dim_in && type != isl_dim_out)
719 isl_die(space->ctx, isl_error_invalid,
720 "only input, output and set tuples can have names",
721 goto error);
722
723 isl_id_free(space->tuple_id[type - isl_dim_in]);
724 space->tuple_id[type - isl_dim_in] = NULL;
725
726 return space;
727error:
728 isl_space_free(space);
729 return NULL;
730}
731
732/* Set the id of the given dimension of "space" to "id".
733 * If the dimension already has an id, then it is replaced.
734 * If the dimension is a parameter, then we need to change it
735 * in the nested spaces (if any) as well.
736 */
738 enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
739{
740 space = isl_space_cow(space);
741 if (!space || !id)
742 goto error;
743
744 if (type == isl_dim_param) {
745 int i;
746
747 for (i = 0; i < 2; ++i) {
748 if (!space->nested[i])
749 continue;
750 space->nested[i] =
751 isl_space_set_dim_id(space->nested[i],
752 type, pos, isl_id_copy(id));
753 if (!space->nested[i])
754 goto error;
755 }
756 }
757
758 isl_id_free(get_id(space, type, pos));
759 return set_id(space, type, pos, id);
760error:
761 isl_id_free(id);
762 isl_space_free(space);
763 return NULL;
764}
765
766/* Reset the id of the given dimension of "space".
767 * If the dimension already has an id, then it is removed.
768 * If the dimension is a parameter, then we need to reset it
769 * in the nested spaces (if any) as well.
770 */
772 enum isl_dim_type type, unsigned pos)
773{
774 space = isl_space_cow(space);
775 if (!space)
776 goto error;
777
778 if (type == isl_dim_param) {
779 int i;
780
781 for (i = 0; i < 2; ++i) {
782 if (!space->nested[i])
783 continue;
784 space->nested[i] =
785 isl_space_reset_dim_id(space->nested[i],
786 type, pos);
787 if (!space->nested[i])
788 goto error;
789 }
790 }
791
792 isl_id_free(get_id(space, type, pos));
793 return set_id(space, type, pos, NULL);
794error:
795 isl_space_free(space);
796 return NULL;
797}
798
800 enum isl_dim_type type, unsigned pos)
801{
802 if (!space)
803 return isl_bool_error;
804 return isl_bool_ok(get_id(space, type, pos) != NULL);
805}
806
808 enum isl_dim_type type, unsigned pos)
809{
810 if (!space)
811 return NULL;
812 if (!get_id(space, type, pos))
813 isl_die(space->ctx, isl_error_invalid,
814 "dim has no id", return NULL);
815 return isl_id_copy(get_id(space, type, pos));
816}
817
819 enum isl_dim_type type, const char *s)
820{
821 isl_id *id;
822
823 if (!space)
824 return NULL;
825
826 if (!s)
827 return isl_space_reset_tuple_id(space, type);
828
829 if (!name_ok(space->ctx, s))
830 goto error;
831
832 id = isl_id_alloc(space->ctx, s, NULL);
833 return isl_space_set_tuple_id(space, type, id);
834error:
835 isl_space_free(space);
836 return NULL;
837}
838
839/* Does the tuple have a name?
840 */
842 enum isl_dim_type type)
843{
844 isl_id *id;
845
846 if (!space_can_have_id(space, type))
847 return isl_bool_error;
848 id = space->tuple_id[type - isl_dim_in];
849 return isl_bool_ok(id && id->name);
850}
851
853 enum isl_dim_type type)
854{
855 isl_id *id;
856 if (!space)
857 return NULL;
858 if (type != isl_dim_in && type != isl_dim_out)
859 return NULL;
860 id = space->tuple_id[type - isl_dim_in];
861 return id ? id->name : NULL;
862}
863
865 enum isl_dim_type type, unsigned pos,
866 const char *s)
867{
868 isl_id *id;
869
870 if (!space)
871 return NULL;
872 if (!s)
873 return isl_space_reset_dim_id(space, type, pos);
874 if (!name_ok(space->ctx, s))
875 goto error;
876 id = isl_id_alloc(space->ctx, s, NULL);
877 return isl_space_set_dim_id(space, type, pos, id);
878error:
879 isl_space_free(space);
880 return NULL;
881}
882
883/* Does the given dimension have a name?
884 */
886 enum isl_dim_type type, unsigned pos)
887{
888 isl_id *id;
889
890 if (!space)
891 return isl_bool_error;
892 id = get_id(space, type, pos);
893 return isl_bool_ok(id && id->name);
894}
895
897 enum isl_dim_type type, unsigned pos)
898{
899 isl_id *id = get_id(space, type, pos);
900 return id ? id->name : NULL;
901}
902
905{
906 int i;
908 isl_size n;
909
910 n = isl_space_dim(space, type);
911 offset = isl_space_offset(space, type);
912 if (n < 0 || offset < 0 || !id)
913 return -1;
914
915 for (i = 0; i < n && offset + i < space->n_id; ++i)
916 if (space->ids[offset + i] == id)
917 return i;
918
919 return -1;
920}
921
923 enum isl_dim_type type, const char *name)
924{
925 int i;
927 isl_size n;
928
929 n = isl_space_dim(space, type);
930 offset = isl_space_offset(space, type);
931 if (n < 0 || offset < 0 || !name)
932 return -1;
933
934 for (i = 0; i < n && offset + i < space->n_id; ++i) {
935 isl_id *id = get_id(space, type, i);
936 if (id && id->name && !strcmp(id->name, name))
937 return i;
938 }
939
940 return -1;
941}
942
943/* Reset the user pointer on all identifiers of parameters and tuples
944 * of "space".
945 */
947{
948 int i;
949 isl_ctx *ctx;
950 isl_id *id;
951 const char *name;
952
953 if (!space)
954 return NULL;
955
956 ctx = isl_space_get_ctx(space);
957
958 for (i = 0; i < space->nparam && i < space->n_id; ++i) {
959 if (!isl_id_get_user(space->ids[i]))
960 continue;
961 space = isl_space_cow(space);
962 if (!space)
963 return NULL;
964 name = isl_id_get_name(space->ids[i]);
965 id = isl_id_alloc(ctx, name, NULL);
966 isl_id_free(space->ids[i]);
967 space->ids[i] = id;
968 if (!id)
969 return isl_space_free(space);
970 }
971
972 for (i = 0; i < 2; ++i) {
973 if (!space->tuple_id[i])
974 continue;
975 if (!isl_id_get_user(space->tuple_id[i]))
976 continue;
977 space = isl_space_cow(space);
978 if (!space)
979 return NULL;
980 name = isl_id_get_name(space->tuple_id[i]);
981 id = isl_id_alloc(ctx, name, NULL);
982 isl_id_free(space->tuple_id[i]);
983 space->tuple_id[i] = id;
984 if (!id)
985 return isl_space_free(space);
986 }
987
988 for (i = 0; i < 2; ++i) {
990
991 if (!space->nested[i])
992 continue;
993 nested = isl_space_take_nested(space, i);
995 space = isl_space_restore_nested(space, i, nested);
996 if (!space)
997 return NULL;
998 }
999
1000 return space;
1001}
1002
1004 enum isl_dim_type type)
1005{
1006 if (!space)
1007 return NULL;
1008 if (type == isl_dim_in)
1009 return space->tuple_id[0];
1010 if (type == isl_dim_out)
1011 return space->tuple_id[1];
1012 return NULL;
1013}
1014
1016 enum isl_dim_type type)
1017{
1018 if (!space)
1019 return NULL;
1020 if (type == isl_dim_in)
1021 return space->nested[0];
1022 if (type == isl_dim_out)
1023 return space->nested[1];
1024 return NULL;
1025}
1026
1027/* Are the two spaces the same, apart from positions and names of parameters?
1028 */
1030 __isl_keep isl_space *space2)
1031{
1032 if (!space1 || !space2)
1033 return isl_bool_error;
1034 if (space1 == space2)
1035 return isl_bool_true;
1036 return isl_space_tuple_is_equal(space1, isl_dim_in,
1037 space2, isl_dim_in) &&
1039 space2, isl_dim_out);
1040}
1041
1042/* Check that a match involving "space" was successful.
1043 * That is, check that "match" is equal to isl_bool_true.
1044 */
1046{
1047 if (match < 0)
1048 return isl_stat_error;
1049 if (!match)
1051 "incompatible spaces", return isl_stat_error);
1052
1053 return isl_stat_ok;
1054}
1055
1056/* Check that the two spaces are the same,
1057 * apart from positions and names of parameters.
1058 */
1060 __isl_keep isl_space *space2)
1061{
1063
1064 is_equal = isl_space_has_equal_tuples(space1, space2);
1065 return check_match(space1, is_equal);
1066}
1067
1068/* Check if the tuple of type "type1" of "space1" is the same as
1069 * the tuple of type "type2" of "space2".
1070 *
1071 * That is, check if the tuples have the same identifier, the same dimension
1072 * and the same internal structure.
1073 * The identifiers of the dimensions inside the tuples do not affect the result.
1074 *
1075 * Note that this function only checks the tuples themselves.
1076 * If nested tuples are involved, then we need to be careful not
1077 * to have result affected by possibly differing parameters
1078 * in those nested tuples.
1079 */
1081 enum isl_dim_type type1, __isl_keep isl_space *space2,
1082 enum isl_dim_type type2)
1083{
1084 isl_id *id1, *id2;
1085 isl_space *nested1, *nested2;
1086
1087 if (!space1 || !space2)
1088 return isl_bool_error;
1089
1090 if (space1 == space2 && type1 == type2)
1091 return isl_bool_true;
1092
1093 if (n(space1, type1) != n(space2, type2))
1094 return isl_bool_false;
1095 id1 = tuple_id(space1, type1);
1096 id2 = tuple_id(space2, type2);
1097 if (!id1 ^ !id2)
1098 return isl_bool_false;
1099 if (id1 && id1 != id2)
1100 return isl_bool_false;
1101 nested1 = nested(space1, type1);
1102 nested2 = nested(space2, type2);
1103 if (!nested1 ^ !nested2)
1104 return isl_bool_false;
1105 if (nested1 && !isl_space_has_equal_tuples(nested1, nested2))
1106 return isl_bool_false;
1107 return isl_bool_true;
1108}
1109
1110/* Is the tuple "inner" within the wrapped relation inside tuple "outer"
1111 * of "space1" equal to tuple "type2" of "space2"?
1112 */
1114 enum isl_dim_type outer, enum isl_dim_type inner,
1115 __isl_keep isl_space *space2, enum isl_dim_type type2)
1116{
1117 int pos;
1119
1120 if (!space1)
1121 return isl_bool_error;
1122 if (outer != isl_dim_in && outer != isl_dim_out)
1124 "only input, output and set tuples "
1125 "can have nested relations", return isl_bool_error);
1126 pos = outer - isl_dim_in;
1127 nested = isl_space_peek_nested(space1, pos);
1128 return isl_space_tuple_is_equal(nested, inner, space2, type2);
1129}
1130
1131/* Check that the tuple "inner" within the wrapped relation inside tuple "outer"
1132 * of "space1" is equal to tuple "type2" of "space2".
1133 */
1135 enum isl_dim_type outer, enum isl_dim_type inner,
1136 __isl_keep isl_space *space2, enum isl_dim_type type2)
1137{
1139
1140 is_equal = isl_space_wrapped_tuple_is_equal(space1, outer, inner,
1141 space2, type2);
1142 return check_match(space1, is_equal);
1143}
1144
1146 __isl_keep isl_space *space2, enum isl_dim_type type2)
1147{
1148 int i;
1150
1151 if (!space1 || !space2)
1152 return isl_bool_error;
1153
1154 if (space1 == space2 && type1 == type2)
1155 return isl_bool_true;
1156
1157 equal = isl_space_tuple_is_equal(space1, type1, space2, type2);
1158 if (equal < 0 || !equal)
1159 return equal;
1160
1161 if (!space1->ids && !space2->ids)
1162 return isl_bool_true;
1163
1164 for (i = 0; i < n(space1, type1); ++i) {
1165 if (get_id(space1, type1, i) != get_id(space2, type2, i))
1166 return isl_bool_false;
1167 }
1168 return isl_bool_true;
1169}
1170
1171/* Do "space1" and "space2" have the same parameters?
1172 */
1174 __isl_keep isl_space *space2)
1175{
1176 return match(space1, isl_dim_param, space2, isl_dim_param);
1177}
1178
1179/* Do "space1" and "space2" have the same identifiers for all
1180 * the tuple variables?
1181 */
1183 __isl_keep isl_space *space2)
1184{
1186
1187 equal = match(space1, isl_dim_in, space2, isl_dim_in);
1188 if (equal < 0 || !equal)
1189 return equal;
1190 return match(space1, isl_dim_out, space2, isl_dim_out);
1191}
1192
1194 __isl_keep isl_space *space2, enum isl_dim_type type2)
1195{
1196 return match(space1, type1, space2, type2);
1197}
1198
1200 unsigned first, unsigned n, __isl_keep isl_id **ids)
1201{
1202 int i;
1203
1204 for (i = 0; i < n ; ++i)
1205 ids[i] = get_id(space, type, first + i);
1206}
1207
1209 unsigned nparam, unsigned n_in, unsigned n_out)
1210{
1211 isl_id **ids = NULL;
1212
1213 if (!space)
1214 return NULL;
1215 if (space->nparam == nparam &&
1216 space->n_in == n_in && space->n_out == n_out)
1217 return space;
1218
1219 isl_assert(space->ctx, space->nparam <= nparam, goto error);
1220 isl_assert(space->ctx, space->n_in <= n_in, goto error);
1221 isl_assert(space->ctx, space->n_out <= n_out, goto error);
1222
1223 space = isl_space_cow(space);
1224 if (!space)
1225 goto error;
1226
1227 if (space->ids) {
1228 unsigned n;
1229 n = nparam + n_in + n_out;
1230 if (n < nparam || n < n_in || n < n_out)
1232 "overflow in total number of dimensions",
1233 goto error);
1234 ids = isl_calloc_array(space->ctx, isl_id *, n);
1235 if (!ids)
1236 goto error;
1237 get_ids(space, isl_dim_param, 0, space->nparam, ids);
1238 get_ids(space, isl_dim_in, 0, space->n_in, ids + nparam);
1239 get_ids(space, isl_dim_out, 0, space->n_out,
1240 ids + nparam + n_in);
1241 free(space->ids);
1242 space->ids = ids;
1243 space->n_id = nparam + n_in + n_out;
1244 }
1245 space->nparam = nparam;
1246 space->n_in = n_in;
1247 space->n_out = n_out;
1248
1249 return space;
1250error:
1251 free(ids);
1252 isl_space_free(space);
1253 return NULL;
1254}
1255
1257 unsigned nparam, unsigned n_in, unsigned n_out)
1258{
1259 return space_extend(space, nparam, n_in, n_out);
1260}
1261
1263 enum isl_dim_type type, unsigned n)
1264{
1265 space = isl_space_reset(space, type);
1266 if (!space)
1267 return NULL;
1268 switch (type) {
1269 case isl_dim_param:
1270 space = space_extend(space,
1271 space->nparam + n, space->n_in, space->n_out);
1272 if (space && space->nested[0] &&
1273 !(space->nested[0] = isl_space_add_dims(space->nested[0],
1274 isl_dim_param, n)))
1275 goto error;
1276 if (space && space->nested[1] &&
1277 !(space->nested[1] = isl_space_add_dims(space->nested[1],
1278 isl_dim_param, n)))
1279 goto error;
1280 return space;
1281 case isl_dim_in:
1282 return space_extend(space,
1283 space->nparam, space->n_in + n, space->n_out);
1284 case isl_dim_out:
1285 return space_extend(space,
1286 space->nparam, space->n_in, space->n_out + n);
1287 default:
1288 isl_die(space->ctx, isl_error_invalid,
1289 "cannot add dimensions of specified type", goto error);
1290 }
1291error:
1292 isl_space_free(space);
1293 return NULL;
1294}
1295
1296/* Add a parameter with identifier "id" to "space", provided
1297 * it does not already appear in "space".
1298 */
1300 __isl_take isl_id *id)
1301{
1302 isl_size pos;
1303
1304 if (!space || !id)
1305 goto error;
1306
1307 if (isl_space_find_dim_by_id(space, isl_dim_param, id) >= 0) {
1308 isl_id_free(id);
1309 return space;
1310 }
1311
1313 if (pos < 0)
1314 goto error;
1315 space = isl_space_add_dims(space, isl_dim_param, 1);
1316 space = isl_space_set_dim_id(space, isl_dim_param, pos, id);
1317
1318 return space;
1319error:
1320 isl_space_free(space);
1321 isl_id_free(id);
1322 return NULL;
1323}
1324
1326{
1327 switch (type) {
1328 case isl_dim_param:
1329 case isl_dim_in:
1330 case isl_dim_out:
1331 return 1;
1332 default:
1333 return 0;
1334 }
1335}
1336
1337#undef TYPE
1338#define TYPE isl_space
1339#include "check_type_range_templ.c"
1340
1341/* Insert "n" dimensions of type "type" at position "pos".
1342 * If we are inserting parameters, then they are also inserted in
1343 * any nested spaces.
1344 */
1346 enum isl_dim_type type, unsigned pos, unsigned n)
1347{
1348 isl_ctx *ctx;
1349 isl_id **ids = NULL;
1350
1351 if (!space)
1352 return NULL;
1353 if (n == 0)
1354 return isl_space_reset(space, type);
1355
1356 ctx = isl_space_get_ctx(space);
1357 if (!valid_dim_type(type))
1359 "cannot insert dimensions of specified type",
1360 goto error);
1361
1362 if (isl_space_check_range(space, type, pos, 0) < 0)
1363 return isl_space_free(space);
1364
1365 space = isl_space_cow(space);
1366 if (!space)
1367 return NULL;
1368
1369 if (space->ids) {
1370 enum isl_dim_type t, o = isl_dim_param;
1371 int off;
1372 int s[3];
1373 ids = isl_calloc_array(ctx, isl_id *,
1374 space->nparam + space->n_in + space->n_out + n);
1375 if (!ids)
1376 goto error;
1377 off = 0;
1378 s[isl_dim_param - o] = space->nparam;
1379 s[isl_dim_in - o] = space->n_in;
1380 s[isl_dim_out - o] = space->n_out;
1381 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
1382 if (t != type) {
1383 get_ids(space, t, 0, s[t - o], ids + off);
1384 off += s[t - o];
1385 } else {
1386 get_ids(space, t, 0, pos, ids + off);
1387 off += pos + n;
1388 get_ids(space, t, pos, s[t - o] - pos,
1389 ids + off);
1390 off += s[t - o] - pos;
1391 }
1392 }
1393 free(space->ids);
1394 space->ids = ids;
1395 space->n_id = space->nparam + space->n_in + space->n_out + n;
1396 }
1397 switch (type) {
1398 case isl_dim_param: space->nparam += n; break;
1399 case isl_dim_in: space->n_in += n; break;
1400 case isl_dim_out: space->n_out += n; break;
1401 default: ;
1402 }
1403 space = isl_space_reset(space, type);
1404
1405 if (type == isl_dim_param) {
1406 if (space && space->nested[0] &&
1407 !(space->nested[0] = isl_space_insert_dims(space->nested[0],
1408 isl_dim_param, pos, n)))
1409 goto error;
1410 if (space && space->nested[1] &&
1411 !(space->nested[1] = isl_space_insert_dims(space->nested[1],
1412 isl_dim_param, pos, n)))
1413 goto error;
1414 }
1415
1416 return space;
1417error:
1418 isl_space_free(space);
1419 return NULL;
1420}
1421
1423 enum isl_dim_type dst_type, unsigned dst_pos,
1424 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
1425{
1426 int i;
1427
1428 space = isl_space_reset(space, src_type);
1429 space = isl_space_reset(space, dst_type);
1430 if (!space)
1431 return NULL;
1432 if (n == 0)
1433 return space;
1434
1435 if (isl_space_check_range(space, src_type, src_pos, n) < 0)
1436 return isl_space_free(space);
1437
1438 if (dst_type == src_type && dst_pos == src_pos)
1439 return space;
1440
1441 isl_assert(space->ctx, dst_type != src_type, goto error);
1442
1443 space = isl_space_cow(space);
1444 if (!space)
1445 return NULL;
1446
1447 if (space->ids) {
1448 isl_id **ids;
1449 enum isl_dim_type t, o = isl_dim_param;
1450 int off;
1451 int s[3];
1452 ids = isl_calloc_array(space->ctx, isl_id *,
1453 space->nparam + space->n_in + space->n_out);
1454 if (!ids)
1455 goto error;
1456 off = 0;
1457 s[isl_dim_param - o] = space->nparam;
1458 s[isl_dim_in - o] = space->n_in;
1459 s[isl_dim_out - o] = space->n_out;
1460 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
1461 if (t == dst_type) {
1462 get_ids(space, t, 0, dst_pos, ids + off);
1463 off += dst_pos;
1464 get_ids(space, src_type, src_pos, n, ids + off);
1465 off += n;
1466 get_ids(space, t, dst_pos, s[t - o] - dst_pos,
1467 ids + off);
1468 off += s[t - o] - dst_pos;
1469 } else if (t == src_type) {
1470 get_ids(space, t, 0, src_pos, ids + off);
1471 off += src_pos;
1472 get_ids(space, t, src_pos + n,
1473 s[t - o] - src_pos - n, ids + off);
1474 off += s[t - o] - src_pos - n;
1475 } else {
1476 get_ids(space, t, 0, s[t - o], ids + off);
1477 off += s[t - o];
1478 }
1479 }
1480 free(space->ids);
1481 space->ids = ids;
1482 space->n_id = space->nparam + space->n_in + space->n_out;
1483 }
1484
1485 switch (dst_type) {
1486 case isl_dim_param: space->nparam += n; break;
1487 case isl_dim_in: space->n_in += n; break;
1488 case isl_dim_out: space->n_out += n; break;
1489 default: ;
1490 }
1491
1492 switch (src_type) {
1493 case isl_dim_param: space->nparam -= n; break;
1494 case isl_dim_in: space->n_in -= n; break;
1495 case isl_dim_out: space->n_out -= n; break;
1496 default: ;
1497 }
1498
1499 if (dst_type != isl_dim_param && src_type != isl_dim_param)
1500 return space;
1501
1502 for (i = 0; i < 2; ++i) {
1504
1505 if (!space->nested[i])
1506 continue;
1507 nested = isl_space_take_nested(space, i);
1509 space = isl_space_restore_nested(space, i, nested);
1510 if (!space)
1511 return NULL;
1512 }
1513
1514 return space;
1515error:
1516 isl_space_free(space);
1517 return NULL;
1518}
1519
1520/* Check that "space1" and "space2" have the same parameters,
1521 * reporting an error if they do not.
1522 */
1524 __isl_keep isl_space *space2)
1525{
1527
1528 equal = isl_space_has_equal_params(space1, space2);
1529 if (equal < 0)
1530 return isl_stat_error;
1531 if (!equal)
1533 "parameters need to match", return isl_stat_error);
1534 return isl_stat_ok;
1535}
1536
1538 __isl_take isl_space *right)
1539{
1540 isl_space *space;
1541
1542 if (isl_space_check_equal_params(left, right) < 0)
1543 goto error;
1544
1545 isl_assert(left->ctx,
1547 goto error);
1548
1549 space = isl_space_alloc(left->ctx,
1550 left->nparam, left->n_in, right->n_out);
1551 if (!space)
1552 goto error;
1553
1554 space = copy_ids(space, isl_dim_param, 0, left, isl_dim_param);
1555 space = copy_ids(space, isl_dim_in, 0, left, isl_dim_in);
1556 space = copy_ids(space, isl_dim_out, 0, right, isl_dim_out);
1557
1558 if (space && left->tuple_id[0] &&
1559 !(space->tuple_id[0] = isl_id_copy(left->tuple_id[0])))
1560 goto error;
1561 if (space && right->tuple_id[1] &&
1562 !(space->tuple_id[1] = isl_id_copy(right->tuple_id[1])))
1563 goto error;
1564 if (space && left->nested[0] &&
1565 !(space->nested[0] = isl_space_copy(left->nested[0])))
1566 goto error;
1567 if (space && right->nested[1] &&
1568 !(space->nested[1] = isl_space_copy(right->nested[1])))
1569 goto error;
1570
1571 isl_space_free(left);
1572 isl_space_free(right);
1573
1574 return space;
1575error:
1576 isl_space_free(left);
1577 isl_space_free(right);
1578 return NULL;
1579}
1580
1581/* Given two map spaces { A -> C } and { B -> D }, construct the space
1582 * { [A -> B] -> [C -> D] }.
1583 * Given two set spaces { A } and { B }, construct the space { [A -> B] }.
1584 */
1586 __isl_take isl_space *right)
1587{
1588 isl_space *dom1, *dom2, *nest1, *nest2;
1589 int is_set;
1590
1591 if (!left || !right)
1592 goto error;
1593
1594 is_set = isl_space_is_set(left);
1595 if (is_set != isl_space_is_set(right))
1597 "expecting either two set spaces or two map spaces",
1598 goto error);
1599 if (is_set)
1600 return isl_space_range_product(left, right);
1601
1602 if (isl_space_check_equal_params(left, right) < 0)
1603 goto error;
1604
1605 dom1 = isl_space_domain(isl_space_copy(left));
1606 dom2 = isl_space_domain(isl_space_copy(right));
1607 nest1 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
1608
1609 dom1 = isl_space_range(left);
1610 dom2 = isl_space_range(right);
1611 nest2 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
1612
1613 return isl_space_join(isl_space_reverse(nest1), nest2);
1614error:
1615 isl_space_free(left);
1616 isl_space_free(right);
1617 return NULL;
1618}
1619
1620/* Given two spaces { A -> C } and { B -> C }, construct the space
1621 * { [A -> B] -> C }
1622 */
1624 __isl_take isl_space *right)
1625{
1626 isl_space *ran, *dom1, *dom2, *nest;
1627
1628 if (isl_space_check_equal_params(left, right) < 0)
1629 goto error;
1630
1632 isl_die(left->ctx, isl_error_invalid,
1633 "ranges need to match", goto error);
1634
1635 ran = isl_space_range(isl_space_copy(left));
1636
1637 dom1 = isl_space_domain(left);
1638 dom2 = isl_space_domain(right);
1639 nest = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
1640
1641 return isl_space_join(isl_space_reverse(nest), ran);
1642error:
1643 isl_space_free(left);
1644 isl_space_free(right);
1645 return NULL;
1646}
1647
1649 __isl_take isl_space *right)
1650{
1651 isl_space *dom, *ran1, *ran2, *nest;
1652
1653 if (isl_space_check_equal_params(left, right) < 0)
1654 goto error;
1655
1657 isl_die(left->ctx, isl_error_invalid,
1658 "domains need to match", goto error);
1659
1660 dom = isl_space_domain(isl_space_copy(left));
1661
1662 ran1 = isl_space_range(left);
1663 ran2 = isl_space_range(right);
1664 nest = isl_space_wrap(isl_space_join(isl_space_reverse(ran1), ran2));
1665
1666 return isl_space_join(isl_space_reverse(dom), nest);
1667error:
1668 isl_space_free(left);
1669 isl_space_free(right);
1670 return NULL;
1671}
1672
1673/* Given a space of the form [A -> B] -> C, return the space A -> C.
1674 */
1676 __isl_take isl_space *space)
1677{
1680
1682 return isl_space_free(space);
1683
1684 nested = space->nested[0];
1685 domain = isl_space_copy(space);
1687 nested->n_in, nested->n_out);
1688 if (!domain)
1689 return isl_space_free(space);
1690 if (nested->tuple_id[0]) {
1691 domain->tuple_id[0] = isl_id_copy(nested->tuple_id[0]);
1692 if (!domain->tuple_id[0])
1693 goto error;
1694 }
1695 if (nested->nested[0]) {
1696 domain->nested[0] = isl_space_copy(nested->nested[0]);
1697 if (!domain->nested[0])
1698 goto error;
1699 }
1700
1701 isl_space_free(space);
1702 return domain;
1703error:
1704 isl_space_free(space);
1706 return NULL;
1707}
1708
1709/* Given a space of the form [A -> B] -> C, return the space B -> C.
1710 */
1712 __isl_take isl_space *space)
1713{
1716
1718 return isl_space_free(space);
1719
1720 nested = space->nested[0];
1721 range = isl_space_copy(space);
1723 if (!range)
1724 return isl_space_free(space);
1725 if (nested->tuple_id[1]) {
1726 range->tuple_id[0] = isl_id_copy(nested->tuple_id[1]);
1727 if (!range->tuple_id[0])
1728 goto error;
1729 }
1730 if (nested->nested[1]) {
1731 range->nested[0] = isl_space_copy(nested->nested[1]);
1732 if (!range->nested[0])
1733 goto error;
1734 }
1735
1736 isl_space_free(space);
1737 return range;
1738error:
1739 isl_space_free(space);
1741 return NULL;
1742}
1743
1744/* Internal function that selects the domain of the map that is
1745 * embedded in either a set space or the range of a map space.
1746 * In particular, given a space of the form [A -> B], return the space A.
1747 * Given a space of the form A -> [B -> C], return the space A -> B.
1748 */
1750{
1753
1754 if (!space)
1755 return NULL;
1756
1757 nested = space->nested[1];
1758 domain = isl_space_copy(space);
1760 nested->n_in, nested->n_out);
1761 if (!domain)
1762 return isl_space_free(space);
1763 if (nested->tuple_id[0]) {
1764 domain->tuple_id[1] = isl_id_copy(nested->tuple_id[0]);
1765 if (!domain->tuple_id[1])
1766 goto error;
1767 }
1768 if (nested->nested[0]) {
1769 domain->nested[1] = isl_space_copy(nested->nested[0]);
1770 if (!domain->nested[1])
1771 goto error;
1772 }
1773
1774 isl_space_free(space);
1775 return domain;
1776error:
1777 isl_space_free(space);
1779 return NULL;
1780}
1781
1782/* Given a space of the form A -> [B -> C], return the space A -> B.
1783 */
1785 __isl_take isl_space *space)
1786{
1787 if (isl_space_check_range_is_wrapping(space) < 0)
1788 return isl_space_free(space);
1789
1790 return range_factor_domain(space);
1791}
1792
1793/* Given a space of the form [A -> B], return the space A.
1794 */
1796{
1797 if (!space)
1798 return NULL;
1799 if (!isl_space_is_wrapping(space))
1801 "not a product", return isl_space_free(space));
1802
1803 return range_factor_domain(space);
1804}
1805
1806/* Given a space of the form [A -> B] -> [C -> D], return the space A -> C.
1807 * Given a space of the form [A -> B], return the space A.
1808 */
1810{
1811 if (!space)
1812 return NULL;
1813 if (isl_space_is_set(space))
1814 return set_factor_domain(space);
1815 space = isl_space_domain_factor_domain(space);
1816 space = isl_space_range_factor_domain(space);
1817 return space;
1818}
1819
1820/* Internal function that selects the range of the map that is
1821 * embedded in either a set space or the range of a map space.
1822 * In particular, given a space of the form [A -> B], return the space B.
1823 * Given a space of the form A -> [B -> C], return the space A -> C.
1824 */
1826{
1829
1830 if (!space)
1831 return NULL;
1832
1833 nested = space->nested[1];
1834 range = isl_space_copy(space);
1836 if (!range)
1837 return isl_space_free(space);
1838 if (nested->tuple_id[1]) {
1839 range->tuple_id[1] = isl_id_copy(nested->tuple_id[1]);
1840 if (!range->tuple_id[1])
1841 goto error;
1842 }
1843 if (nested->nested[1]) {
1844 range->nested[1] = isl_space_copy(nested->nested[1]);
1845 if (!range->nested[1])
1846 goto error;
1847 }
1848
1849 isl_space_free(space);
1850 return range;
1851error:
1852 isl_space_free(space);
1854 return NULL;
1855}
1856
1857/* Given a space of the form A -> [B -> C], return the space A -> C.
1858 */
1860 __isl_take isl_space *space)
1861{
1862 if (isl_space_check_range_is_wrapping(space) < 0)
1863 return isl_space_free(space);
1864
1865 return range_factor_range(space);
1866}
1867
1868/* Given a space of the form [A -> B], return the space B.
1869 */
1871{
1872 if (!space)
1873 return NULL;
1874 if (!isl_space_is_wrapping(space))
1876 "not a product", return isl_space_free(space));
1877
1878 return range_factor_range(space);
1879}
1880
1881/* Given a space of the form [A -> B] -> [C -> D], return the space B -> D.
1882 * Given a space of the form [A -> B], return the space B.
1883 */
1885{
1886 if (!space)
1887 return NULL;
1888 if (isl_space_is_set(space))
1889 return set_factor_range(space);
1890 space = isl_space_domain_factor_range(space);
1891 space = isl_space_range_factor_range(space);
1892 return space;
1893}
1894
1895/* Given a space of the form [A -> B] -> C, return the space A.
1896 */
1902
1903/* Given a space of the form [A -> B] -> C, return the space B.
1904 */
1910
1911/* Given a space of the form A -> [B -> C], return the space B.
1912 */
1918
1919/* Given a space of the form A -> [B -> C], return the space C.
1920 */
1926
1928{
1929 isl_ctx *ctx;
1930 isl_id **ids = NULL;
1931 int n_id;
1932
1933 if (!space)
1934 return NULL;
1935 ctx = isl_space_get_ctx(space);
1936 if (!isl_space_is_set(space))
1937 isl_die(ctx, isl_error_invalid, "not a set space", goto error);
1938 space = isl_space_cow(space);
1939 if (!space)
1940 return NULL;
1941 n_id = space->nparam + space->n_out + space->n_out;
1942 if (n_id > 0 && space->ids) {
1943 ids = isl_calloc_array(space->ctx, isl_id *, n_id);
1944 if (!ids)
1945 goto error;
1946 get_ids(space, isl_dim_param, 0, space->nparam, ids);
1947 get_ids(space, isl_dim_out, 0, space->n_out,
1948 ids + space->nparam);
1949 }
1950 space->n_in = space->n_out;
1951 if (ids) {
1952 free(space->ids);
1953 space->ids = ids;
1954 space->n_id = n_id;
1955 space = copy_ids(space, isl_dim_out, 0, space, isl_dim_in);
1956 }
1957 isl_id_free(space->tuple_id[0]);
1958 space->tuple_id[0] = isl_id_copy(space->tuple_id[1]);
1959 isl_space_free(space->nested[0]);
1960 space->nested[0] = isl_space_copy(space->nested[1]);
1961 return space;
1962error:
1963 isl_space_free(space);
1964 return NULL;
1965}
1966
1969{
1970 if (!domain || !range)
1971 goto error;
1974 "domain is not a set space", goto error);
1975 if (!isl_space_is_set(range))
1977 "range is not a set space", goto error);
1979error:
1982 return NULL;
1983}
1984
1986 enum isl_dim_type type,
1987 unsigned first, unsigned n, __isl_take isl_id **ids)
1988{
1989 int i;
1990
1991 for (i = 0; i < n ; ++i)
1992 space = set_id(space, type, first + i, ids[i]);
1993
1994 return space;
1995}
1996
1998{
1999 unsigned t;
2002 isl_id **ids = NULL;
2003 isl_id *id;
2004
2005 equal = match(space, isl_dim_in, space, isl_dim_out);
2006 if (equal < 0)
2007 return isl_space_free(space);
2008 if (equal)
2009 return space;
2010
2011 space = isl_space_cow(space);
2012 if (!space)
2013 return NULL;
2014
2015 id = space->tuple_id[0];
2016 space->tuple_id[0] = space->tuple_id[1];
2017 space->tuple_id[1] = id;
2018
2019 nested = space->nested[0];
2020 space->nested[0] = space->nested[1];
2021 space->nested[1] = nested;
2022
2023 if (space->ids) {
2024 int n_id = space->n_in + space->n_out;
2025 ids = isl_alloc_array(space->ctx, isl_id *, n_id);
2026 if (n_id && !ids)
2027 goto error;
2028 get_ids(space, isl_dim_in, 0, space->n_in, ids);
2029 get_ids(space, isl_dim_out, 0, space->n_out, ids + space->n_in);
2030 }
2031
2032 t = space->n_in;
2033 space->n_in = space->n_out;
2034 space->n_out = t;
2035
2036 if (space->ids) {
2037 space = set_ids(space, isl_dim_out, 0, space->n_out, ids);
2038 space = set_ids(space, isl_dim_in, 0, space->n_in,
2039 ids + space->n_out);
2040 free(ids);
2041 }
2042
2043 return space;
2044error:
2045 free(ids);
2046 isl_space_free(space);
2047 return NULL;
2048}
2049
2050/* Given a space where the tuple of type "type" is a wrapped map space,
2051 * swap domain and range of that wrapped space.
2052 *
2053 * If the tuple is named, then the name is only preserved
2054 * if the nested tuples are equal, in which case the output
2055 * of this function is identical to the input, except possibly
2056 * for the dimension identifiers.
2057 *
2058 * Make a reasonable attempt at moving the dimension identifiers
2059 * along with the tuples.
2060 */
2062 enum isl_dim_type type)
2063{
2064 int pos = type - isl_dim_in;
2067 isl_size n_in;
2068
2072 if (equal < 0)
2073 return isl_space_free(space);
2074
2077 space = isl_space_restore_nested(space, pos, nested);
2078 if (!equal)
2079 space = isl_space_reset_tuple_id(space, type);
2082 if (n_in < 0)
2083 return isl_space_free(space);
2084 space = copy_ids(space, type, 0, nested, isl_dim_in);
2085 space = copy_ids(space, type, n_in, nested, isl_dim_out);
2086
2087 return space;
2088}
2089
2090/* Given a space (A -> B), return the corresponding space
2091 * (B -> A).
2092 *
2093 * If the domain tuple is named, then the name is only preserved
2094 * if A and B are equal tuples, in which case the output
2095 * of this function is identical to the input, except possibly
2096 * for the dimension identifiers.
2097 */
2099{
2100 if (isl_space_check_is_wrapping(space) < 0)
2101 return isl_space_free(space);
2102 space = isl_space_reverse_wrapped(space, isl_dim_set);
2103
2104 return space;
2105}
2106
2107/* Given a space (A -> B) -> C, return the corresponding space
2108 * (B -> A) -> C.
2109 *
2110 * If the domain tuple is named, then the name is only preserved
2111 * if A and B are equal tuples, in which case the output
2112 * of this function is identical to the input, except possibly
2113 * for the dimension identifiers.
2114 */
2116{
2118 return isl_space_free(space);
2119 space = isl_space_reverse_wrapped(space, isl_dim_in);
2120
2121 return space;
2122}
2123
2124/* Given a space A -> (B -> C), return the corresponding space
2125 * A -> (C -> B).
2126 *
2127 * If the range tuple is named, then the name is only preserved
2128 * if B and C are equal tuples, in which case the output
2129 * of this function is identical to the input, except possibly
2130 * for the dimension identifiers.
2131 */
2133{
2134 if (isl_space_check_range_is_wrapping(space) < 0)
2135 return isl_space_free(space);
2136 space = isl_space_reverse_wrapped(space, isl_dim_out);
2137
2138 return space;
2139}
2140
2142 enum isl_dim_type type, unsigned first, unsigned num)
2143{
2144 int i;
2145
2146 if (!space)
2147 return NULL;
2148
2149 if (num == 0)
2150 return isl_space_reset(space, type);
2151
2152 if (!valid_dim_type(type))
2153 isl_die(space->ctx, isl_error_invalid,
2154 "cannot drop dimensions of specified type", goto error);
2155
2156 if (isl_space_check_range(space, type, first, num) < 0)
2157 return isl_space_free(space);
2158 space = isl_space_cow(space);
2159 if (!space)
2160 goto error;
2161 if (space->ids) {
2162 space = extend_ids(space);
2163 if (!space)
2164 goto error;
2165 for (i = 0; i < num; ++i)
2166 isl_id_free(get_id(space, type, first + i));
2167 for (i = first+num; i < n(space, type); ++i)
2168 set_id(space, type, i - num, get_id(space, type, i));
2169 switch (type) {
2170 case isl_dim_param:
2171 get_ids(space, isl_dim_in, 0, space->n_in,
2172 space->ids + offset(space, isl_dim_in) - num);
2173 case isl_dim_in:
2174 get_ids(space, isl_dim_out, 0, space->n_out,
2175 space->ids + offset(space, isl_dim_out) - num);
2176 default:
2177 ;
2178 }
2179 space->n_id -= num;
2180 }
2181 switch (type) {
2182 case isl_dim_param: space->nparam -= num; break;
2183 case isl_dim_in: space->n_in -= num; break;
2184 case isl_dim_out: space->n_out -= num; break;
2185 default: ;
2186 }
2187 space = isl_space_reset(space, type);
2188 if (type == isl_dim_param) {
2189 if (space && space->nested[0] &&
2190 !(space->nested[0] = isl_space_drop_dims(space->nested[0],
2191 isl_dim_param, first, num)))
2192 goto error;
2193 if (space && space->nested[1] &&
2194 !(space->nested[1] = isl_space_drop_dims(space->nested[1],
2195 isl_dim_param, first, num)))
2196 goto error;
2197 }
2198 return space;
2199error:
2200 isl_space_free(space);
2201 return NULL;
2202}
2203
2205 unsigned first, unsigned n)
2206{
2207 if (!space)
2208 return NULL;
2209 return isl_space_drop_dims(space, isl_dim_in, first, n);
2210}
2211
2213 unsigned first, unsigned n)
2214{
2215 if (!space)
2216 return NULL;
2217 return isl_space_drop_dims(space, isl_dim_out, first, n);
2218}
2219
2220/* Remove all parameters from "space".
2221 */
2223{
2224 isl_size nparam;
2225
2226 nparam = isl_space_dim(space, isl_dim_param);
2227 if (nparam < 0)
2228 return isl_space_free(space);
2229 return isl_space_drop_dims(space, isl_dim_param, 0, nparam);
2230}
2231
2233{
2234 if (!space)
2235 return NULL;
2236 space = isl_space_drop_dims(space, isl_dim_out, 0, space->n_out);
2237 space = isl_space_reverse(space);
2238 space = mark_as_set(space);
2239 return space;
2240}
2241
2243{
2244 if (!space)
2245 return NULL;
2246 if (!isl_space_is_set(space))
2248 "not a set space", goto error);
2249 space = isl_space_reverse(space);
2250 space = isl_space_reset(space, isl_dim_out);
2251 return space;
2252error:
2253 isl_space_free(space);
2254 return NULL;
2255}
2256
2258{
2259 if (!space)
2260 return NULL;
2261 space = isl_space_drop_dims(space, isl_dim_in, 0, space->n_in);
2262 space = mark_as_set(space);
2263 return space;
2264}
2265
2267{
2268 if (!space)
2269 return NULL;
2270 if (!isl_space_is_set(space))
2272 "not a set space", goto error);
2273 return isl_space_reset(space, isl_dim_in);
2274error:
2275 isl_space_free(space);
2276 return NULL;
2277}
2278
2279/* Given a map space A -> B, return the map space [A -> B] -> A.
2280 */
2282{
2284
2286 space = isl_space_from_domain(isl_space_wrap(space));
2287 space = isl_space_join(space, domain);
2288
2289 return space;
2290}
2291
2292/* Given a map space A -> B, return the map space [A -> B] -> B.
2293 */
2295{
2297
2299 space = isl_space_from_domain(isl_space_wrap(space));
2300 space = isl_space_join(space, range);
2301
2302 return space;
2303}
2304
2306{
2307 isl_size n_in, n_out;
2308
2309 if (isl_space_is_params(space))
2310 return space;
2311 n_in = isl_space_dim(space, isl_dim_in);
2312 n_out = isl_space_dim(space, isl_dim_out);
2313 if (n_in < 0 || n_out < 0)
2314 return isl_space_free(space);
2315 space = isl_space_drop_dims(space, isl_dim_in, 0, n_in);
2316 space = isl_space_drop_dims(space, isl_dim_out, 0, n_out);
2317 space = mark_as_params(space);
2318 return space;
2319}
2320
2322{
2323 if (!space)
2324 return NULL;
2325 if (!isl_space_is_params(space))
2327 "not a parameter space", goto error);
2328 return isl_space_reset(space, isl_dim_set);
2329error:
2330 isl_space_free(space);
2331 return NULL;
2332}
2333
2334/* Add an unnamed tuple of dimension "dim" to "space".
2335 * This requires "space" to be a parameter or set space.
2336 *
2337 * In particular, if "space" is a parameter space, then return
2338 * a set space with the given dimension.
2339 * If "space" is a set space, then return a map space
2340 * with "space" as domain and a range of the given dimension.
2341 */
2343 __isl_take isl_space *space, unsigned dim)
2344{
2345 isl_bool is_params, is_set;
2346
2347 is_params = isl_space_is_params(space);
2348 is_set = isl_space_is_set(space);
2349 if (is_params < 0 || is_set < 0)
2350 return isl_space_free(space);
2351 if (!is_params && !is_set)
2353 "cannot add tuple to map space",
2354 return isl_space_free(space));
2355 if (is_params)
2356 space = isl_space_set_from_params(space);
2357 else
2358 space = isl_space_from_domain(space);
2359 space = isl_space_add_dims(space, isl_dim_out, dim);
2360 return space;
2361}
2362
2363/* Add a tuple of dimension "dim" and with tuple identifier "tuple_id"
2364 * to "space".
2365 * This requires "space" to be a parameter or set space.
2366 */
2368 __isl_take isl_space *space, __isl_take isl_id *tuple_id, unsigned dim)
2369{
2370 space = isl_space_add_unnamed_tuple_ui(space, dim);
2372 return space;
2373}
2374
2375/* Check that the identifiers in "tuple" do not appear as parameters
2376 * in "space".
2377 */
2380{
2381 int i;
2382 isl_size n;
2383
2384 n = isl_multi_id_size(tuple);
2385 if (n < 0)
2386 return isl_stat_error;
2387 for (i = 0; i < n; ++i) {
2388 isl_id *id;
2389 int pos;
2390
2391 id = isl_multi_id_get_at(tuple, i);
2392 if (!id)
2393 return isl_stat_error;
2395 isl_id_free(id);
2396 if (pos >= 0)
2398 "parameters not unique", return isl_stat_error);
2399 }
2400
2401 return isl_stat_ok;
2402}
2403
2404/* Add the identifiers in "tuple" as parameters of "space"
2405 * that are known to be fresh.
2406 */
2409{
2410 int i;
2411 isl_size first, n;
2412
2413 first = isl_space_dim(space, isl_dim_param);
2414 n = isl_multi_id_size(tuple);
2415 if (first < 0 || n < 0)
2416 return isl_space_free(space);
2417 space = isl_space_add_dims(space, isl_dim_param, n);
2418 for (i = 0; i < n; ++i) {
2419 isl_id *id;
2420
2421 id = isl_multi_id_get_at(tuple, i);
2422 space = isl_space_set_dim_id(space,
2423 isl_dim_param, first + i, id);
2424 }
2425
2426 return space;
2427}
2428
2429/* Internal function that removes the set tuple of "space",
2430 * which is assumed to correspond to the range space of "tuple", and
2431 * adds the identifiers in "tuple" as fresh parameters.
2432 * In other words, the set dimensions of "space" are reinterpreted
2433 * as parameters, but stay in the same global positions.
2434 */
2437{
2438 isl_space *tuple_space;
2439
2440 if (isl_space_check_is_proper_set(space) < 0)
2441 return isl_space_free(space);
2442 tuple_space = isl_multi_id_peek_space(tuple);
2443 if (isl_space_check_equal_tuples(tuple_space, space) < 0)
2444 return isl_space_free(space);
2445 if (check_fresh_params(space, tuple) < 0)
2446 return isl_space_free(space);
2447 space = isl_space_params(space);
2448 space = add_bind_params(space, tuple);
2449 return space;
2450}
2451
2452/* Internal function that removes the domain tuple of the map space "space",
2453 * which is assumed to correspond to the range space of "tuple", and
2454 * adds the identifiers in "tuple" as fresh parameters.
2455 * In other words, the domain dimensions of "space" are reinterpreted
2456 * as parameters, but stay in the same global positions.
2457 */
2460{
2461 isl_space *tuple_space;
2462
2463 if (isl_space_check_is_map(space) < 0)
2464 return isl_space_free(space);
2465 tuple_space = isl_multi_id_peek_space(tuple);
2466 if (isl_space_check_domain_tuples(tuple_space, space) < 0)
2467 return isl_space_free(space);
2468 if (check_fresh_params(space, tuple) < 0)
2469 return isl_space_free(space);
2470 space = isl_space_range(space);
2471 space = add_bind_params(space, tuple);
2472 return space;
2473}
2474
2475/* Internal function that, given a space of the form [A -> B] -> C and
2476 * a tuple of identifiers in A, returns a space B -> C with
2477 * the identifiers in "tuple" added as fresh parameters.
2478 * In other words, the domain dimensions of the wrapped relation
2479 * in the domain of "space" are reinterpreted
2480 * as parameters, but stay in the same global positions.
2481 */
2484{
2485 isl_space *tuple_space;
2486
2487 if (isl_space_check_is_map(space) < 0)
2488 return isl_space_free(space);
2489 tuple_space = isl_multi_id_peek_space(tuple);
2491 space) < 0)
2492 return isl_space_free(space);
2493 if (check_fresh_params(space, tuple) < 0)
2494 return isl_space_free(space);
2495 space = isl_space_domain_factor_range(space);
2496 space = add_bind_params(space, tuple);
2497 return space;
2498}
2499
2500/* Insert a domain tuple in "space" corresponding to the set space "domain".
2501 * In particular, if "space" is a parameter space, then the result
2502 * is the set space "domain" combined with the parameters of "space".
2503 * If "space" is a set space, then the result
2504 * is a map space with "domain" as domain and the original space as range.
2505 */
2508{
2509 isl_bool is_params;
2510
2512
2513 is_params = isl_space_is_params(space);
2514 if (is_params < 0) {
2516 space = isl_space_free(space);
2517 } else if (is_params) {
2518 isl_space_free(space);
2519 space = domain;
2520 } else {
2522 }
2523 return space;
2524}
2525
2526/* Internal function that introduces a domain in "space"
2527 * corresponding to the range space of "tuple".
2528 * In particular, if "space" is a parameter space, then the result
2529 * is a set space. If "space" is a set space, then the result
2530 * is a map space with the original space as range.
2531 * Parameters that correspond to the identifiers in "tuple" are removed.
2532 *
2533 * The parameters are removed in reverse order (under the assumption
2534 * that they appear in the same order in "multi") because
2535 * it is slightly more efficient to remove parameters at the end.
2536 *
2537 * For pretty-printing purposes, the identifiers of the set dimensions
2538 * of the introduced domain are set to the identifiers in "tuple".
2539 */
2542{
2543 int i;
2544 isl_size n;
2545 isl_space *tuple_space;
2546
2547 n = isl_multi_id_size(tuple);
2548 if (!space || n < 0)
2549 return isl_space_free(space);
2550 for (i = n - 1; i >= 0; --i) {
2551 isl_id *id;
2552 int pos;
2553
2554 id = isl_multi_id_get_id(tuple, i);
2555 if (!id)
2556 return isl_space_free(space);
2558 isl_id_free(id);
2559 if (pos < 0)
2560 continue;
2561 space = isl_space_drop_dims(space, isl_dim_param, pos, 1);
2562 }
2563 tuple_space = isl_multi_id_get_space(tuple);
2564 for (i = 0; i < n; ++i) {
2565 isl_id *id;
2566
2567 id = isl_multi_id_get_id(tuple, i);
2568 tuple_space = isl_space_set_dim_id(tuple_space,
2569 isl_dim_set, i, id);
2570 }
2571 return isl_space_insert_domain(space, tuple_space);
2572}
2573
2575 unsigned n_div)
2576{
2577 int i;
2578 isl_bool is_set;
2579
2580 is_set = isl_space_is_set(space);
2581 if (is_set < 0)
2582 return isl_space_free(space);
2583 if (n_div == 0 && is_set &&
2584 space->nparam == 0 && space->n_in == 0 && space->n_id == 0)
2585 return isl_space_reset(space, isl_dim_out);
2586 space = isl_space_cow(space);
2587 if (!space)
2588 return NULL;
2589 space->n_out += space->nparam + space->n_in + n_div;
2590 space->nparam = 0;
2591 space->n_in = 0;
2592
2593 for (i = 0; i < space->n_id; ++i)
2594 isl_id_free(get_id(space, isl_dim_out, i));
2595 space->n_id = 0;
2596 space = isl_space_reset(space, isl_dim_in);
2597 space = isl_space_reset(space, isl_dim_out);
2598 space = mark_as_set(space);
2599
2600 return space;
2601}
2602
2603/* Are the two spaces the same, including positions and names of parameters?
2604 */
2606 __isl_keep isl_space *space2)
2607{
2609
2610 if (!space1 || !space2)
2611 return isl_bool_error;
2612 if (space1 == space2)
2613 return isl_bool_true;
2614 equal = isl_space_has_equal_params(space1, space2);
2615 if (equal < 0 || !equal)
2616 return equal;
2617 return isl_space_has_equal_tuples(space1, space2);
2618}
2619
2620/* Do the tuples of "space1" correspond to those of the domain of "space2"?
2621 * That is, is "space1" equal to the domain of "space2", ignoring parameters.
2622 *
2623 * "space2" is allowed to be a set space, in which case "space1"
2624 * should be a parameter space.
2625 */
2627 __isl_keep isl_space *space2)
2628{
2629 isl_bool is_set;
2630
2631 is_set = isl_space_is_set(space1);
2632 if (is_set < 0 || !is_set)
2633 return is_set;
2635 space2, isl_dim_in);
2636}
2637
2638/* Do the tuples of "space1" correspond to those of the range of "space2"?
2639 * That is, is "space1" equal to the range of "space2", ignoring parameters.
2640 *
2641 * "space2" is allowed to be the space of a set,
2642 * in which case it should be equal to "space1", ignoring parameters.
2643 */
2645 __isl_keep isl_space *space2)
2646{
2647 isl_bool is_set;
2648
2649 is_set = isl_space_is_set(space1);
2650 if (is_set < 0 || !is_set)
2651 return is_set;
2653 space2, isl_dim_out);
2654}
2655
2656/* Check that the tuples of "space1" correspond to those
2657 * of the domain of "space2".
2658 * That is, check that "space1" is equal to the domain of "space2",
2659 * ignoring parameters.
2660 */
2662 __isl_keep isl_space *space2)
2663{
2665
2666 is_equal = isl_space_has_domain_tuples(space1, space2);
2667 return check_match(space1, is_equal);
2668}
2669
2670/* Check that the tuples of "space1" correspond to those
2671 * of the domain of the wrapped relation in the domain of "space2".
2672 * That is, check that "space1" is equal to this domain,
2673 * ignoring parameters.
2674 */
2687
2688/* Is space1 equal to the domain of space2?
2689 *
2690 * In the internal version we also allow space2 to be the space of a set,
2691 * provided space1 is a parameter space.
2692 */
2694 __isl_keep isl_space *space2)
2695{
2696 isl_bool equal_params;
2697
2698 if (!space1 || !space2)
2699 return isl_bool_error;
2700 equal_params = isl_space_has_equal_params(space1, space2);
2701 if (equal_params < 0 || !equal_params)
2702 return equal_params;
2703 return isl_space_has_domain_tuples(space1, space2);
2704}
2705
2706/* Is space1 equal to the domain of space2?
2707 */
2709 __isl_keep isl_space *space2)
2710{
2711 if (!space2)
2712 return isl_bool_error;
2713 if (!isl_space_is_map(space2))
2714 return isl_bool_false;
2715 return isl_space_is_domain_internal(space1, space2);
2716}
2717
2718/* Is space1 equal to the range of space2?
2719 *
2720 * In the internal version, space2 is allowed to be the space of a set,
2721 * in which case it should be equal to space1.
2722 */
2724 __isl_keep isl_space *space2)
2725{
2726 isl_bool equal_params;
2727
2728 if (!space1 || !space2)
2729 return isl_bool_error;
2730 equal_params = isl_space_has_equal_params(space1, space2);
2731 if (equal_params < 0 || !equal_params)
2732 return equal_params;
2733 return isl_space_has_range_tuples(space1, space2);
2734}
2735
2736/* Is space1 equal to the range of space2?
2737 */
2739 __isl_keep isl_space *space2)
2740{
2741 if (!space2)
2742 return isl_bool_error;
2743 if (!isl_space_is_map(space2))
2744 return isl_bool_false;
2745 return isl_space_is_range_internal(space1, space2);
2746}
2747
2748/* Update "hash" by hashing in the parameters of "space".
2749 */
2750static uint32_t isl_hash_params(uint32_t hash, __isl_keep isl_space *space)
2751{
2752 int i;
2753 isl_id *id;
2754
2755 if (!space)
2756 return hash;
2757
2758 isl_hash_byte(hash, space->nparam % 256);
2759
2760 for (i = 0; i < space->nparam; ++i) {
2761 id = get_id(space, isl_dim_param, i);
2762 hash = isl_hash_id(hash, id);
2763 }
2764
2765 return hash;
2766}
2767
2768/* Update "hash" by hashing in the tuples of "space".
2769 * Changes in this function should be reflected in isl_hash_tuples_domain.
2770 */
2771static uint32_t isl_hash_tuples(uint32_t hash, __isl_keep isl_space *space)
2772{
2773 isl_id *id;
2774
2775 if (!space)
2776 return hash;
2777
2778 isl_hash_byte(hash, space->n_in % 256);
2779 isl_hash_byte(hash, space->n_out % 256);
2780
2781 id = tuple_id(space, isl_dim_in);
2782 hash = isl_hash_id(hash, id);
2783 id = tuple_id(space, isl_dim_out);
2784 hash = isl_hash_id(hash, id);
2785
2786 hash = isl_hash_tuples(hash, space->nested[0]);
2787 hash = isl_hash_tuples(hash, space->nested[1]);
2788
2789 return hash;
2790}
2791
2792/* Update "hash" by hashing in the domain tuple of "space".
2793 * The result of this function is equal to the result of applying
2794 * isl_hash_tuples to the domain of "space".
2795 */
2796static uint32_t isl_hash_tuples_domain(uint32_t hash,
2797 __isl_keep isl_space *space)
2798{
2799 isl_id *id;
2800
2801 if (!space)
2802 return hash;
2803
2804 isl_hash_byte(hash, 0);
2805 isl_hash_byte(hash, space->n_in % 256);
2806
2807 hash = isl_hash_id(hash, &isl_id_none);
2808 id = tuple_id(space, isl_dim_in);
2809 hash = isl_hash_id(hash, id);
2810
2811 hash = isl_hash_tuples(hash, space->nested[0]);
2812
2813 return hash;
2814}
2815
2816/* Return a hash value that digests the tuples of "space",
2817 * i.e., that ignores the parameters.
2818 * Changes in this function should be reflected
2819 * in isl_space_get_tuple_domain_hash.
2820 */
2822{
2823 uint32_t hash;
2824
2825 if (!space)
2826 return 0;
2827
2828 hash = isl_hash_init();
2829 hash = isl_hash_tuples(hash, space);
2830
2831 return hash;
2832}
2833
2834/* Return the hash value of "space".
2835 */
2837{
2838 uint32_t hash;
2839
2840 if (!space)
2841 return 0;
2842
2843 hash = isl_hash_init();
2844 hash = isl_hash_params(hash, space);
2845 hash = isl_hash_tuples(hash, space);
2846
2847 return hash;
2848}
2849
2850/* Return the hash value of the domain tuple of "space".
2851 * That is, isl_space_get_tuple_domain_hash(space) is equal to
2852 * isl_space_get_tuple_hash(isl_space_domain(space)).
2853 */
2855{
2856 uint32_t hash;
2857
2858 if (!space)
2859 return 0;
2860
2861 hash = isl_hash_init();
2862 hash = isl_hash_tuples_domain(hash, space);
2863
2864 return hash;
2865}
2866
2867/* Is "space" the space of a set wrapping a map space?
2868 */
2870{
2871 if (!space)
2872 return isl_bool_error;
2873
2874 if (!isl_space_is_set(space))
2875 return isl_bool_false;
2876
2877 return isl_bool_ok(space->nested[1] != NULL);
2878}
2879
2880/* Is "space" the space of a map where the domain is a wrapped map space?
2881 */
2883{
2884 if (!space)
2885 return isl_bool_error;
2886
2887 if (isl_space_is_set(space))
2888 return isl_bool_false;
2889
2890 return isl_bool_ok(space->nested[0] != NULL);
2891}
2892
2893/* Is "space" the space of a map where the range is a wrapped map space?
2894 */
2896{
2897 if (!space)
2898 return isl_bool_error;
2899
2900 if (isl_space_is_set(space))
2901 return isl_bool_false;
2902
2903 return isl_bool_ok(space->nested[1] != NULL);
2904}
2905
2906/* Is "space" a product of two spaces?
2907 * That is, is it a wrapping set space or a map space
2908 * with wrapping domain and range?
2909 */
2911{
2912 isl_bool is_set;
2913 isl_bool is_product;
2914
2915 is_set = isl_space_is_set(space);
2916 if (is_set < 0)
2917 return isl_bool_error;
2918 if (is_set)
2919 return isl_space_is_wrapping(space);
2920 is_product = isl_space_domain_is_wrapping(space);
2921 if (is_product < 0 || !is_product)
2922 return is_product;
2923 return isl_space_range_is_wrapping(space);
2924}
2925
2927{
2928 isl_space *wrap;
2929
2930 if (!space)
2931 return NULL;
2932
2933 wrap = isl_space_set_alloc(space->ctx,
2934 space->nparam, space->n_in + space->n_out);
2935
2937 wrap = copy_ids(wrap, isl_dim_set, 0, space, isl_dim_in);
2938 wrap = copy_ids(wrap, isl_dim_set, space->n_in, space, isl_dim_out);
2939
2940 if (!wrap)
2941 goto error;
2942
2943 wrap->nested[1] = space;
2944
2945 return wrap;
2946error:
2947 isl_space_free(space);
2948 return NULL;
2949}
2950
2952{
2954
2955 if (!space)
2956 return NULL;
2957
2958 if (!isl_space_is_wrapping(space))
2959 isl_die(space->ctx, isl_error_invalid, "not a wrapping space",
2960 goto error);
2961
2962 unwrap = isl_space_copy(space->nested[1]);
2963 isl_space_free(space);
2964
2965 return unwrap;
2966error:
2967 isl_space_free(space);
2968 return NULL;
2969}
2970
2972 enum isl_dim_type type)
2973{
2974 if (type != isl_dim_in && type != isl_dim_out)
2975 return isl_bool_false;
2976 if (!space)
2977 return isl_bool_error;
2978 if (space->tuple_id[type - isl_dim_in])
2979 return isl_bool_true;
2980 if (space->nested[type - isl_dim_in])
2981 return isl_bool_true;
2982 return isl_bool_false;
2983}
2984
2986{
2988 isl_size n_in;
2989
2990 if (!space)
2991 return isl_bool_error;
2992 if (isl_space_is_set(space))
2993 return isl_bool_true;
2994 n_in = isl_space_dim(space, isl_dim_in);
2995 if (n_in < 0)
2996 return isl_bool_error;
2997 if (n_in != 0)
2998 return isl_bool_false;
3000 if (nested < 0 || nested)
3001 return isl_bool_not(nested);
3002 return isl_bool_true;
3003}
3004
3006 enum isl_dim_type type)
3007{
3009 return space;
3010
3011 space = isl_space_cow(space);
3012 if (!space)
3013 return NULL;
3014
3015 isl_id_free(space->tuple_id[type - isl_dim_in]);
3016 space->tuple_id[type - isl_dim_in] = NULL;
3017 isl_space_free(space->nested[type - isl_dim_in]);
3018 space->nested[type - isl_dim_in] = NULL;
3019
3020 return space;
3021}
3022
3024{
3025 if (!space)
3026 return NULL;
3027 if (!space->nested[0] && !space->nested[1])
3028 return space;
3029
3030 if (space->nested[0])
3031 space = isl_space_reset(space, isl_dim_in);
3032 if (space && space->nested[1])
3033 space = isl_space_reset(space, isl_dim_out);
3034
3035 return space;
3036}
3037
3039{
3040 if (!space)
3041 return NULL;
3042 if (!space->nested[0])
3043 return space;
3044
3045 return isl_space_reset(space, isl_dim_in);
3046}
3047
3049{
3050 if (!space)
3051 return NULL;
3052 if (!space->nested[1])
3053 return space;
3054
3055 return isl_space_reset(space, isl_dim_out);
3056}
3057
3058/* Replace the parameters of dst by those of src.
3059 */
3061 __isl_keep isl_space *src)
3062{
3063 isl_size dst_dim, src_dim;
3064 isl_bool equal_params;
3066
3067 equal_params = isl_space_has_equal_params(dst, src);
3068 if (equal_params < 0)
3069 return isl_space_free(dst);
3070 if (equal_params)
3071 return dst;
3072
3073 dst = isl_space_cow(dst);
3074
3075 dst_dim = isl_space_dim(dst, type);
3076 src_dim = isl_space_dim(src, type);
3077 if (dst_dim < 0 || src_dim < 0)
3078 goto error;
3079
3080 dst = isl_space_drop_dims(dst, type, 0, dst_dim);
3081 dst = isl_space_add_dims(dst, type, src_dim);
3082 dst = copy_ids(dst, type, 0, src, type);
3083
3084 if (dst) {
3085 int i;
3086 for (i = 0; i <= 1; ++i) {
3088
3089 if (!dst->nested[i])
3090 continue;
3091 nested = isl_space_take_nested(dst, i);
3093 dst = isl_space_restore_nested(dst, i, nested);
3094 if (!dst)
3095 return NULL;
3096 }
3097 }
3098
3099 return dst;
3100error:
3101 isl_space_free(dst);
3102 return NULL;
3103}
3104
3105/* Given two tuples ("dst_type" in "dst" and "src_type" in "src")
3106 * of the same size, check if any of the dimensions in the "dst" tuple
3107 * have no identifier, while the corresponding dimensions in "src"
3108 * does have an identifier,
3109 * If so, copy the identifier over to "dst".
3110 */
3112 enum isl_dim_type dst_type, __isl_keep isl_space *src,
3113 enum isl_dim_type src_type)
3114{
3115 int i;
3116 isl_size n;
3117
3118 n = isl_space_dim(dst, dst_type);
3119 if (n < 0)
3120 return isl_space_free(dst);
3121 for (i = 0; i < n; ++i) {
3122 isl_bool set;
3123 isl_id *id;
3124
3125 set = isl_space_has_dim_id(dst, dst_type, i);
3126 if (set < 0)
3127 return isl_space_free(dst);
3128 if (set)
3129 continue;
3130
3131 set = isl_space_has_dim_id(src, src_type, i);
3132 if (set < 0)
3133 return isl_space_free(dst);
3134 if (!set)
3135 continue;
3136
3137 id = isl_space_get_dim_id(src, src_type, i);
3138 dst = isl_space_set_dim_id(dst, dst_type, i, id);
3139 }
3140
3141 return dst;
3142}
3143
3144/* Given a space "space" of a set, create a space
3145 * for the lift of the set. In particular, the result
3146 * is of the form lifted[space -> local[..]], with n_local variables in the
3147 * range of the wrapped map.
3148 */
3150 unsigned n_local)
3151{
3152 isl_space *local_space;
3153
3154 if (!space)
3155 return NULL;
3156
3157 local_space = isl_space_dup(space);
3158 local_space = isl_space_drop_dims(local_space, isl_dim_set, 0,
3159 space->n_out);
3160 local_space = isl_space_add_dims(local_space, isl_dim_set, n_local);
3161 local_space = isl_space_set_tuple_name(local_space,
3162 isl_dim_set, "local");
3164 isl_space_from_range(local_space));
3165 space = isl_space_wrap(space);
3166 space = isl_space_set_tuple_name(space, isl_dim_set, "lifted");
3167
3168 return space;
3169}
3170
3172{
3173 isl_bool is_set;
3174
3175 is_set = isl_space_is_set(space);
3176 if (is_set < 0)
3177 return isl_bool_error;
3178 if (is_set)
3179 return isl_bool_false;
3180 return isl_space_is_product(space);
3181}
3182
3184{
3185 isl_space *dom, *ran;
3186 isl_space *dom_dom, *dom_ran, *ran_dom, *ran_ran;
3187
3188 if (!isl_space_can_zip(space))
3189 isl_die(space->ctx, isl_error_invalid, "space cannot be zipped",
3190 goto error);
3191
3192 if (!space)
3193 return NULL;
3195 ran = isl_space_unwrap(isl_space_range(space));
3196 dom_dom = isl_space_domain(isl_space_copy(dom));
3197 dom_ran = isl_space_range(dom);
3198 ran_dom = isl_space_domain(isl_space_copy(ran));
3199 ran_ran = isl_space_range(ran);
3201 isl_space_from_range(ran_dom));
3203 isl_space_from_range(ran_ran));
3206error:
3207 isl_space_free(space);
3208 return NULL;
3209}
3210
3211/* Can we apply isl_space_curry to "space"?
3212 * That is, does is it have a map space with a nested relation in its domain?
3213 */
3218
3219/* Given a space (A -> B) -> C, return the corresponding space
3220 * A -> (B -> C).
3221 */
3223{
3224 isl_space *dom, *ran;
3225 isl_space *dom_dom, *dom_ran;
3226
3227 if (!space)
3228 return NULL;
3229
3230 if (!isl_space_can_curry(space))
3231 isl_die(space->ctx, isl_error_invalid,
3232 "space cannot be curried", goto error);
3233
3235 ran = isl_space_range(space);
3236 dom_dom = isl_space_domain(isl_space_copy(dom));
3237 dom_ran = isl_space_range(dom);
3240 return isl_space_join(isl_space_from_domain(dom_dom),
3242error:
3243 isl_space_free(space);
3244 return NULL;
3245}
3246
3247/* Can isl_space_range_curry be applied to "space"?
3248 * That is, does it have a nested relation in its range,
3249 * the domain of which is itself a nested relation?
3250 */
3252{
3253 isl_bool can;
3254
3255 if (!space)
3256 return isl_bool_error;
3257 can = isl_space_range_is_wrapping(space);
3258 if (can < 0 || !can)
3259 return can;
3260 return isl_space_can_curry(space->nested[1]);
3261}
3262
3263/* Given a space A -> ((B -> C) -> D), return the corresponding space
3264 * A -> (B -> (C -> D)).
3265 */
3267{
3269
3270 if (!space)
3271 return NULL;
3272
3273 if (!isl_space_can_range_curry(space))
3275 "space range cannot be curried",
3276 return isl_space_free(space));
3277
3278 nested = isl_space_take_nested(space, 1);
3280 space = isl_space_restore_nested(space, 1, nested);
3281
3282 return space;
3283}
3284
3285/* Can we apply isl_space_uncurry to "space"?
3286 * That is, does it have a map space with a nested relation in its range?
3287 */
3292
3293/* Given a space A -> (B -> C), return the corresponding space
3294 * (A -> B) -> C.
3295 */
3297{
3298 isl_space *dom, *ran;
3299 isl_space *ran_dom, *ran_ran;
3300
3301 if (!space)
3302 return NULL;
3303
3304 if (!isl_space_can_uncurry(space))
3305 isl_die(space->ctx, isl_error_invalid,
3306 "space cannot be uncurried",
3307 return isl_space_free(space));
3308
3309 dom = isl_space_domain(isl_space_copy(space));
3310 ran = isl_space_unwrap(isl_space_range(space));
3311 ran_dom = isl_space_domain(isl_space_copy(ran));
3312 ran_ran = isl_space_range(ran);
3314 isl_space_from_range(ran_dom));
3316 isl_space_from_range(ran_ran));
3317}
3318
3320{
3321 int i;
3322 isl_size off;
3323
3324 if (!space)
3325 return isl_bool_error;
3326 if (space->nparam == 0)
3327 return isl_bool_true;
3328 off = isl_space_offset(space, isl_dim_param);
3329 if (off < 0)
3330 return isl_bool_error;
3331 if (off + space->nparam > space->n_id)
3332 return isl_bool_false;
3333 for (i = 0; i < space->nparam; ++i)
3334 if (!space->ids[off + i])
3335 return isl_bool_false;
3336 return isl_bool_true;
3337}
3338
3339/* Check that "space" has only named parameters, reporting an error
3340 * if it does not.
3341 */
3343{
3344 isl_bool named;
3345
3346 named = isl_space_has_named_params(space);
3347 if (named < 0)
3348 return isl_stat_error;
3349 if (!named)
3351 "unexpected unnamed parameters", return isl_stat_error);
3352
3353 return isl_stat_ok;
3354}
3355
3356/* Align the initial parameters of space1 to match the order in space2.
3357 */
3359 __isl_take isl_space *space2)
3360{
3361 isl_reordering *exp;
3362
3363 if (isl_space_check_named_params(space1) < 0 ||
3364 isl_space_check_named_params(space2) < 0)
3365 goto error;
3366
3367 exp = isl_parameter_alignment_reordering(space1, space2);
3368 isl_space_free(space1);
3369 isl_space_free(space2);
3370 space1 = isl_reordering_get_space(exp);
3372 return space1;
3373error:
3374 isl_space_free(space1);
3375 isl_space_free(space2);
3376 return NULL;
3377}
3378
3379/* Given the space of set (domain), construct a space for a map
3380 * with as domain the given space and as range the range of "model".
3381 */
3384{
3385 isl_size n_out;
3386
3387 if (!model)
3388 goto error;
3389
3390 space = isl_space_from_domain(space);
3391 n_out = isl_space_dim(model, isl_dim_out);
3392 if (n_out < 0)
3393 goto error;
3394 space = isl_space_add_dims(space, isl_dim_out, n_out);
3396 space = isl_space_set_tuple_id(space, isl_dim_out,
3398 if (!space)
3399 goto error;
3400 if (model->nested[1]) {
3401 isl_space *nested = isl_space_copy(model->nested[1]);
3402 isl_size n_nested, n_space;
3404 n_nested = isl_space_dim(nested, isl_dim_param);
3405 n_space = isl_space_dim(space, isl_dim_param);
3406 if (n_nested < 0 || n_space < 0)
3407 goto error;
3408 if (n_nested > n_space)
3410 n_space, n_nested - n_space);
3411 if (!nested)
3412 goto error;
3413 space->nested[1] = nested;
3414 }
3415 isl_space_free(model);
3416 return space;
3417error:
3418 isl_space_free(model);
3419 isl_space_free(space);
3420 return NULL;
3421}
3422
3423/* Compare the "type" dimensions of two isl_spaces.
3424 *
3425 * The order is fairly arbitrary.
3426 */
3428 __isl_keep isl_space *space2, enum isl_dim_type type)
3429{
3430 int cmp;
3431 isl_size dim1, dim2;
3432 isl_space *nested1, *nested2;
3433
3434 dim1 = isl_space_dim(space1, type);
3435 dim2 = isl_space_dim(space2, type);
3436 if (dim1 < 0 || dim2 < 0)
3437 return 0;
3438 if (dim1 != dim2)
3439 return dim1 - dim2;
3440
3441 cmp = isl_id_cmp(tuple_id(space1, type), tuple_id(space2, type));
3442 if (cmp != 0)
3443 return cmp;
3444
3445 nested1 = nested(space1, type);
3446 nested2 = nested(space2, type);
3447 if (!nested1 != !nested2)
3448 return !nested1 - !nested2;
3449
3450 if (nested1)
3451 return isl_space_cmp(nested1, nested2);
3452
3453 return 0;
3454}
3455
3456/* Compare two isl_spaces.
3457 *
3458 * The order is fairly arbitrary.
3459 */
3461{
3462 int i;
3463 int cmp;
3464
3465 if (space1 == space2)
3466 return 0;
3467 if (!space1)
3468 return -1;
3469 if (!space2)
3470 return 1;
3471
3472 cmp = isl_space_cmp_type(space1, space2, isl_dim_param);
3473 if (cmp != 0)
3474 return cmp;
3475 cmp = isl_space_cmp_type(space1, space2, isl_dim_in);
3476 if (cmp != 0)
3477 return cmp;
3478 cmp = isl_space_cmp_type(space1, space2, isl_dim_out);
3479 if (cmp != 0)
3480 return cmp;
3481
3482 if (!space1->ids && !space2->ids)
3483 return 0;
3484
3485 for (i = 0; i < n(space1, isl_dim_param); ++i) {
3486 cmp = isl_id_cmp(get_id(space1, isl_dim_param, i),
3487 get_id(space2, isl_dim_param, i));
3488 if (cmp != 0)
3489 return cmp;
3490 }
3491
3492 return 0;
3493}
#define __isl_take
Definition ctx.h:22
isl_stat
Definition ctx.h:84
@ isl_stat_error
Definition ctx.h:85
@ isl_stat_ok
Definition ctx.h:86
#define __isl_give
Definition ctx.h:19
#define isl_size_error
Definition ctx.h:98
#define __isl_null
Definition ctx.h:28
#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_invalid
Definition ctx.h:80
#define isl_alloc_array(ctx, type, n)
Definition ctx.h:132
#define isl_calloc_array(ctx, type, n)
Definition ctx.h:133
#define __isl_keep
Definition ctx.h:25
int isl_size
Definition ctx.h:97
#define isl_alloc_type(ctx, type)
Definition ctx.h:129
#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
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_hash_byte(h, b)
Definition hash.h:22
#define isl_hash_init()
Definition hash.h:21
__isl_export __isl_keep const char * isl_id_get_name(__isl_keep isl_id *id)
Definition isl_id.c:41
__isl_null isl_id * isl_id_free(__isl_take isl_id *id)
Definition isl_id.c:207
void * isl_id_get_user(__isl_keep isl_id *id)
Definition isl_id.c:36
__isl_give isl_id * isl_id_copy(isl_id *id)
Definition isl_id.c:129
__isl_give isl_id * isl_id_alloc(isl_ctx *ctx, __isl_keep const char *name, void *user)
struct isl_multi_id isl_multi_id
Definition id_type.h:16
int GMPQAPI cmp(mp_rat op1, mp_rat op2)
int isl_id_cmp(__isl_keep isl_id *id1, __isl_keep isl_id *id2)
Definition isl_id.c:147
isl_id isl_id_none
Definition isl_id.c:24
uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id)
Definition isl_id.c:173
__isl_give dup(__isl_keep LIST(EL) *list)
static unsigned pos(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_map.c:73
__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_space * isl_reordering_get_space(__isl_keep isl_reordering *r)
isl_bool isl_space_has_equal_params(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:1173
static __isl_give isl_space * set_id(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
Definition isl_space.c:296
__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_give isl_space * isl_space_from_domain(__isl_take isl_space *space)
Definition isl_space.c:2242
static __isl_keep isl_space * isl_space_peek_nested(__isl_keep isl_space *space, int pos)
Definition isl_space.c:339
isl_stat isl_space_check_is_set(__isl_keep isl_space *space)
Definition isl_space.c:83
uint32_t isl_space_get_full_hash(__isl_keep isl_space *space)
Definition isl_space.c:2836
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_range_factor_range(__isl_take isl_space *space)
Definition isl_space.c:1859
isl_bool isl_space_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:1193
__isl_give isl_space * isl_space_bind_domain_wrapped_domain(__isl_take isl_space *space, __isl_keep isl_multi_id *tuple)
Definition isl_space.c:2482
isl_bool isl_space_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:2869
__isl_give isl_space * isl_space_domain_wrapped_domain(__isl_take isl_space *space)
Definition isl_space.c:1897
__isl_give isl_space * isl_space_extend_domain_with_range(__isl_take isl_space *space, __isl_take isl_space *model)
Definition isl_space.c:3382
__isl_give isl_space * isl_space_range_map(__isl_take isl_space *space)
Definition isl_space.c:2294
static __isl_give isl_space * isl_space_take_nested(__isl_keep isl_space *space, int pos)
Definition isl_space.c:538
__isl_give isl_space * isl_space_params(__isl_take isl_space *space)
Definition isl_space.c:2305
__isl_give isl_id * isl_space_get_domain_tuple_id(__isl_keep isl_space *space)
Definition isl_space.c:650
static int isl_space_cmp_type(__isl_keep isl_space *space1, __isl_keep isl_space *space2, enum isl_dim_type type)
Definition isl_space.c:3427
__isl_give isl_space * isl_space_from_range(__isl_take isl_space *space)
Definition isl_space.c:2266
__isl_give isl_space * isl_space_reverse(__isl_take isl_space *space)
Definition isl_space.c:1997
static __isl_give isl_space * copy_ids(__isl_take isl_space *dst, enum isl_dim_type dst_type, unsigned offset, __isl_keep isl_space *src, enum isl_dim_type src_type)
Definition isl_space.c:404
__isl_give isl_space * isl_space_domain_wrapped_range(__isl_take isl_space *space)
Definition isl_space.c:1905
static __isl_give isl_space * extend_ids(__isl_take isl_space *space)
Definition isl_space.c:263
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
static __isl_give isl_space * add_bind_params(__isl_take isl_space *space, __isl_keep isl_multi_id *tuple)
Definition isl_space.c:2407
isl_bool isl_space_range_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:2895
__isl_give isl_space * isl_space_dup(__isl_keep isl_space *space)
Definition isl_space.c:426
__isl_give isl_id * isl_space_get_tuple_id(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:631
static __isl_keep isl_space * isl_space_get_nested(__isl_keep isl_space *space, int pos)
Definition isl_space.c:523
__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_flatten(__isl_take isl_space *space)
Definition isl_space.c:3023
__isl_give isl_space * isl_space_factor_domain(__isl_take isl_space *space)
Definition isl_space.c:1809
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_copy(__isl_keep isl_space *space)
Definition isl_space.c:469
__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_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_drop_inputs(__isl_take isl_space *space, unsigned first, unsigned n)
Definition isl_space.c:2204
__isl_give isl_space * isl_space_unbind_params_insert_domain(__isl_take isl_space *space, __isl_keep isl_multi_id *tuple)
Definition isl_space.c:2540
static int name_ok(isl_ctx *ctx, const char *s)
Definition isl_space.c:509
isl_bool isl_space_is_map(__isl_keep isl_space *space)
Definition isl_space.c:115
isl_bool isl_space_has_domain_tuple_id(__isl_keep isl_space *space)
Definition isl_space.c:615
__isl_give isl_space * isl_space_align_params(__isl_take isl_space *space1, __isl_take isl_space *space2)
Definition isl_space.c:3358
__isl_give isl_space * isl_space_cow(__isl_take isl_space *space)
Definition isl_space.c:458
isl_stat isl_space_check_wrapped_tuple_is_equal(__isl_keep isl_space *space1, enum isl_dim_type outer, enum isl_dim_type inner, __isl_keep isl_space *space2, enum isl_dim_type type2)
Definition isl_space.c:1134
static __isl_give isl_space * isl_space_insert_domain(__isl_take isl_space *space, __isl_take isl_space *domain)
Definition isl_space.c:2506
__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_stat isl_space_check_named_params(__isl_keep isl_space *space)
Definition isl_space.c:3342
isl_bool isl_space_has_named_params(__isl_keep isl_space *space)
Definition isl_space.c:3319
__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_give isl_space * isl_space_reset_dim_id(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos)
Definition isl_space.c:771
__isl_give isl_space * isl_space_wrapped_reverse(__isl_take isl_space *space)
Definition isl_space.c:2098
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_bool isl_space_has_range_tuple_id(__isl_keep isl_space *space)
Definition isl_space.c:624
static __isl_keep isl_id * tuple_id(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:1003
__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_give isl_space * isl_space_range_wrapped_domain(__isl_take isl_space *space)
Definition isl_space.c:1913
__isl_give isl_space * isl_space_uncurry(__isl_take isl_space *space)
Definition isl_space.c:3296
static isl_stat check_fresh_params(__isl_keep isl_space *space, __isl_keep isl_multi_id *tuple)
Definition isl_space.c:2378
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_bool isl_space_is_range(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2738
__isl_give isl_space * isl_space_set_alloc(isl_ctx *ctx, unsigned nparam, unsigned dim)
Definition isl_space.c:188
static __isl_give isl_space * set_factor_range(__isl_take isl_space *space)
Definition isl_space.c:1870
__isl_give isl_space * isl_space_map_from_set(__isl_take isl_space *space)
Definition isl_space.c:1927
static __isl_give isl_space * isl_space_restore_nested(__isl_take isl_space *space, int pos, __isl_take isl_space *nested)
Definition isl_space.c:558
__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_bool isl_space_has_tuple_name(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:841
static int space_can_have_id(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:584
isl_bool isl_space_can_curry(__isl_keep isl_space *space)
Definition isl_space.c:3214
__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_domain_product(__isl_take isl_space *left, __isl_take isl_space *right)
Definition isl_space.c:1623
static void get_ids(__isl_keep isl_space *space, enum isl_dim_type type, unsigned first, unsigned n, __isl_keep isl_id **ids)
Definition isl_space.c:1199
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_drop_all_params(__isl_take isl_space *space)
Definition isl_space.c:2222
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_give isl_space * isl_space_reverse_wrapped(__isl_take isl_space *space, enum isl_dim_type type)
Definition isl_space.c:2061
static __isl_give isl_space * mark_as_params(isl_space *space)
Definition isl_space.c:200
static int valid_dim_type(enum isl_dim_type type)
Definition isl_space.c:1325
uint32_t isl_space_get_tuple_domain_hash(__isl_keep isl_space *space)
Definition isl_space.c:2854
static uint32_t isl_hash_tuples(uint32_t hash, __isl_keep isl_space *space)
Definition isl_space.c:2771
isl_bool isl_space_is_range_internal(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2723
__isl_give isl_space * isl_space_set_range_tuple_id(__isl_take isl_space *space, __isl_take isl_id *id)
Definition isl_space.c:704
static uint32_t isl_hash_tuples_domain(uint32_t hash, __isl_keep isl_space *space)
Definition isl_space.c:2796
__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_give isl_space * isl_space_range_factor_domain(__isl_take isl_space *space)
Definition isl_space.c:1784
isl_bool isl_space_has_equal_ids(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:1182
__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_stat isl_space_check_range_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:175
__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_give isl_space * isl_space_underlying(__isl_take isl_space *space, unsigned n_div)
Definition isl_space.c:2574
isl_size isl_space_dim(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:372
static isl_stat check_match(__isl_keep isl_space *space, isl_bool match)
Definition isl_space.c:1045
__isl_give isl_space * isl_space_domain(__isl_take isl_space *space)
Definition isl_space.c:2232
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_give isl_space * isl_space_flatten_range(__isl_take isl_space *space)
Definition isl_space.c:3048
static isl_stat isl_space_check_is_map(__isl_keep isl_space *space)
Definition isl_space.c:128
static __isl_give isl_space * space_extend(__isl_take isl_space *space, unsigned nparam, unsigned n_in, unsigned n_out)
Definition isl_space.c:1208
static __isl_give isl_space * set_ids(__isl_take isl_space *space, enum isl_dim_type type, unsigned first, unsigned n, __isl_take isl_id **ids)
Definition isl_space.c:1985
isl_bool isl_space_is_set(__isl_keep isl_space *space)
Definition isl_space.c:70
isl_bool isl_space_wrapped_tuple_is_equal(__isl_keep isl_space *space1, enum isl_dim_type outer, enum isl_dim_type inner, __isl_keep isl_space *space2, enum isl_dim_type type2)
Definition isl_space.c:1113
__isl_give isl_space * isl_space_extend(__isl_take isl_space *space, unsigned nparam, unsigned n_in, unsigned n_out)
Definition isl_space.c:1256
__isl_give isl_space * isl_space_unwrap(__isl_take isl_space *space)
Definition isl_space.c:2951
__isl_give isl_space * isl_space_domain_reverse(__isl_take isl_space *space)
Definition isl_space.c:2115
__isl_give isl_space * isl_space_drop_outputs(__isl_take isl_space *space, unsigned first, unsigned n)
Definition isl_space.c:2212
__isl_give isl_space * isl_space_flatten_domain(__isl_take isl_space *space)
Definition isl_space.c:3038
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_bool isl_space_is_equal(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2605
isl_stat isl_space_check_domain_wrapped_domain_tuples(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2675
__isl_give isl_space * isl_space_domain_factor_range(__isl_take isl_space *space)
Definition isl_space.c:1711
__isl_give isl_space * isl_space_add_param_id(__isl_take isl_space *space, __isl_take isl_id *id)
Definition isl_space.c:1299
__isl_give isl_space * isl_space_set_dim_name(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, const char *s)
Definition isl_space.c:864
isl_stat isl_space_check_equal_params(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:1523
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
static __isl_keep isl_space * nested(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:1015
static isl_size global_pos(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos)
Definition isl_space.c:242
__isl_give isl_space * isl_space_wrap(__isl_take isl_space *space)
Definition isl_space.c:2926
static __isl_keep isl_id * get_id(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos)
Definition isl_space.c:324
static __isl_give isl_space * mark_as_set(__isl_take isl_space *space)
Definition isl_space.c:59
isl_stat isl_space_check_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:143
__isl_give isl_space * isl_space_factor_range(__isl_take isl_space *space)
Definition isl_space.c:1884
__isl_give isl_space * isl_space_unit(isl_ctx *ctx)
Definition isl_space.c:237
isl_bool isl_space_may_be_set(__isl_keep isl_space *space)
Definition isl_space.c:2985
__isl_give isl_space * isl_space_alloc(isl_ctx *ctx, unsigned nparam, unsigned n_in, unsigned n_out)
Definition isl_space.c:28
isl_stat isl_space_check_equal_tuples(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:1059
__isl_give isl_space * isl_space_add_named_tuple_id_ui(__isl_take isl_space *space, __isl_take isl_id *tuple_id, unsigned dim)
Definition isl_space.c:2367
__isl_give isl_space * isl_space_set_domain_tuple_id(__isl_take isl_space *space, __isl_take isl_id *id)
Definition isl_space.c:693
__isl_give isl_space * isl_space_add_unnamed_tuple_ui(__isl_take isl_space *space, unsigned dim)
Definition isl_space.c:2342
__isl_give isl_space * isl_space_reset_user(__isl_take isl_space *space)
Definition isl_space.c:946
isl_bool isl_space_has_domain_tuples(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2626
isl_bool isl_space_domain_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:2882
__isl_give isl_space * isl_space_product(__isl_take isl_space *left, __isl_take isl_space *right)
Definition isl_space.c:1585
isl_bool isl_space_can_range_curry(__isl_keep isl_space *space)
Definition isl_space.c:3251
__isl_give isl_space * isl_space_range_reverse(__isl_take isl_space *space)
Definition isl_space.c:2132
__isl_give isl_space * isl_space_range_wrapped_range(__isl_take isl_space *space)
Definition isl_space.c:1921
isl_bool isl_space_is_named_or_nested(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:2971
__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
static __isl_give isl_space * set_factor_domain(__isl_take isl_space *space)
Definition isl_space.c:1795
__isl_give isl_space * isl_space_range(__isl_take isl_space *space)
Definition isl_space.c:2257
static uint32_t isl_hash_params(uint32_t hash, __isl_keep isl_space *space)
Definition isl_space.c:2750
isl_bool isl_space_has_range_tuples(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2644
uint32_t isl_space_get_tuple_hash(__isl_keep isl_space *space)
Definition isl_space.c:2821
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_stat isl_space_check_domain_is_wrapping(__isl_keep isl_space *space)
Definition isl_space.c:159
__isl_give isl_space * isl_space_add_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned n)
Definition isl_space.c:1262
__isl_give isl_space * isl_space_params_alloc(isl_ctx *ctx, unsigned nparam)
Definition isl_space.c:227
isl_stat isl_space_check_is_proper_set(__isl_keep isl_space *space)
Definition isl_space.c:99
isl_bool isl_space_is_domain(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2708
__isl_give isl_space * isl_space_curry(__isl_take isl_space *space)
Definition isl_space.c:3222
isl_bool isl_space_is_domain_internal(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2693
__isl_give isl_id * isl_space_get_range_tuple_id(__isl_keep isl_space *space)
Definition isl_space.c:661
int isl_space_cmp(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:3460
isl_bool isl_space_is_product(__isl_keep isl_space *space)
Definition isl_space.c:2910
isl_stat isl_space_check_range(__isl_keep isl_space *space, enum isl_dim_type type, unsigned first, unsigned n)
static bool is_equal(const T &a, const T &b)
Definition isl_test2.cc:107
enum isl_fold type
Definition isl_test.c:3867
const char * set
Definition isl_test.c:1364
int equal
Definition isl_test.c:7720
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 * tuple
Definition isl_test.c:6860
const char * id
Definition isl_test.c:7131
t0 *a *b *t *a *b * t
__isl_null isl_space * isl_space_free(__isl_take isl_space *space)
Definition isl_space.c:478
__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_give isl_space * isl_space_copy(__isl_keep isl_space *space)
Definition isl_space.c:469
__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_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_give isl_space * isl_space_add_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned n)
Definition isl_space.c:1262
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_out
Definition space_type.h:17
isl_space * nested[2]
isl_id * tuple_id[2]
isl_id ** ids
struct isl_ctx * ctx
unsigned nparam
static Signature range_factor_domain
static Signature range
static Signature unwrap
static Signature wrap
static Signature range_factor_range
static Signature domain
n
Definition youcefn.c:8