2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2013-2014 Ecole Normale Superieure
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, K.U.Leuven, Departement
9 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
11 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
12 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
17 #include <isl_space_private.h>
18 #include <isl_id_private.h>
19 #include <isl_reordering.h>
24 #include <isl_list_templ.c>
26 isl_ctx
*isl_space_get_ctx(__isl_keep isl_space
*dim
)
28 return dim
? dim
->ctx
: NULL
;
31 __isl_give isl_space
*isl_space_alloc(isl_ctx
*ctx
,
32 unsigned nparam
, unsigned n_in
, unsigned n_out
)
36 dim
= isl_alloc_type(ctx
, struct isl_space
);
47 dim
->tuple_id
[0] = NULL
;
48 dim
->tuple_id
[1] = NULL
;
50 dim
->nested
[0] = NULL
;
51 dim
->nested
[1] = NULL
;
59 /* Mark the space as being that of a set, by setting the domain tuple
62 static __isl_give isl_space
*mark_as_set(__isl_take isl_space
*space
)
64 space
= isl_space_cow(space
);
67 space
= isl_space_set_tuple_id(space
, isl_dim_in
, &isl_id_none
);
71 /* Is the space that of a set?
73 isl_bool
isl_space_is_set(__isl_keep isl_space
*space
)
76 return isl_bool_error
;
77 if (space
->n_in
!= 0 || space
->nested
[0])
78 return isl_bool_false
;
79 if (space
->tuple_id
[0] != &isl_id_none
)
80 return isl_bool_false
;
84 /* Is the given space that of a map?
86 isl_bool
isl_space_is_map(__isl_keep isl_space
*space
)
89 return isl_bool_error
;
90 return space
->tuple_id
[0] != &isl_id_none
&&
91 space
->tuple_id
[1] != &isl_id_none
;
94 __isl_give isl_space
*isl_space_set_alloc(isl_ctx
*ctx
,
95 unsigned nparam
, unsigned dim
)
98 space
= isl_space_alloc(ctx
, nparam
, 0, dim
);
99 space
= mark_as_set(space
);
103 /* Mark the space as being that of a parameter domain, by setting
104 * both tuples to isl_id_none.
106 static __isl_give isl_space
*mark_as_params(isl_space
*space
)
110 space
= isl_space_set_tuple_id(space
, isl_dim_in
, &isl_id_none
);
111 space
= isl_space_set_tuple_id(space
, isl_dim_out
, &isl_id_none
);
115 /* Is the space that of a parameter domain?
117 isl_bool
isl_space_is_params(__isl_keep isl_space
*space
)
120 return isl_bool_error
;
121 if (space
->n_in
!= 0 || space
->nested
[0] ||
122 space
->n_out
!= 0 || space
->nested
[1])
123 return isl_bool_false
;
124 if (space
->tuple_id
[0] != &isl_id_none
)
125 return isl_bool_false
;
126 if (space
->tuple_id
[1] != &isl_id_none
)
127 return isl_bool_false
;
128 return isl_bool_true
;
131 /* Create a space for a parameter domain.
133 __isl_give isl_space
*isl_space_params_alloc(isl_ctx
*ctx
, unsigned nparam
)
136 space
= isl_space_alloc(ctx
, nparam
, 0, 0);
137 space
= mark_as_params(space
);
141 static unsigned global_pos(__isl_keep isl_space
*dim
,
142 enum isl_dim_type type
, unsigned pos
)
144 struct isl_ctx
*ctx
= dim
->ctx
;
148 isl_assert(ctx
, pos
< dim
->nparam
,
149 return isl_space_dim(dim
, isl_dim_all
));
152 isl_assert(ctx
, pos
< dim
->n_in
,
153 return isl_space_dim(dim
, isl_dim_all
));
154 return pos
+ dim
->nparam
;
156 isl_assert(ctx
, pos
< dim
->n_out
,
157 return isl_space_dim(dim
, isl_dim_all
));
158 return pos
+ dim
->nparam
+ dim
->n_in
;
160 isl_assert(ctx
, 0, return isl_space_dim(dim
, isl_dim_all
));
162 return isl_space_dim(dim
, isl_dim_all
);
165 /* Extend length of ids array to the total number of dimensions.
167 static __isl_give isl_space
*extend_ids(__isl_take isl_space
*dim
)
172 if (isl_space_dim(dim
, isl_dim_all
) <= dim
->n_id
)
176 dim
->ids
= isl_calloc_array(dim
->ctx
,
177 isl_id
*, isl_space_dim(dim
, isl_dim_all
));
181 ids
= isl_realloc_array(dim
->ctx
, dim
->ids
,
182 isl_id
*, isl_space_dim(dim
, isl_dim_all
));
186 for (i
= dim
->n_id
; i
< isl_space_dim(dim
, isl_dim_all
); ++i
)
190 dim
->n_id
= isl_space_dim(dim
, isl_dim_all
);
198 static __isl_give isl_space
*set_id(__isl_take isl_space
*dim
,
199 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
201 dim
= isl_space_cow(dim
);
206 pos
= global_pos(dim
, type
, pos
);
207 if (pos
== isl_space_dim(dim
, isl_dim_all
))
210 if (pos
>= dim
->n_id
) {
213 dim
= extend_ids(dim
);
227 static __isl_keep isl_id
*get_id(__isl_keep isl_space
*dim
,
228 enum isl_dim_type type
, unsigned pos
)
233 pos
= global_pos(dim
, type
, pos
);
234 if (pos
== isl_space_dim(dim
, isl_dim_all
))
236 if (pos
>= dim
->n_id
)
238 return dim
->ids
[pos
];
241 static unsigned offset(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
244 case isl_dim_param
: return 0;
245 case isl_dim_in
: return dim
->nparam
;
246 case isl_dim_out
: return dim
->nparam
+ dim
->n_in
;
251 static unsigned n(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
254 case isl_dim_param
: return dim
->nparam
;
255 case isl_dim_in
: return dim
->n_in
;
256 case isl_dim_out
: return dim
->n_out
;
257 case isl_dim_all
: return dim
->nparam
+ dim
->n_in
+ dim
->n_out
;
262 unsigned isl_space_dim(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
269 unsigned isl_space_offset(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
273 return offset(dim
, type
);
276 static __isl_give isl_space
*copy_ids(__isl_take isl_space
*dst
,
277 enum isl_dim_type dst_type
, unsigned offset
, __isl_keep isl_space
*src
,
278 enum isl_dim_type src_type
)
286 for (i
= 0; i
< n(src
, src_type
); ++i
) {
287 id
= get_id(src
, src_type
, i
);
290 dst
= set_id(dst
, dst_type
, offset
+ i
, isl_id_copy(id
));
297 __isl_take isl_space
*isl_space_dup(__isl_keep isl_space
*dim
)
302 dup
= isl_space_alloc(dim
->ctx
, dim
->nparam
, dim
->n_in
, dim
->n_out
);
305 if (dim
->tuple_id
[0] &&
306 !(dup
->tuple_id
[0] = isl_id_copy(dim
->tuple_id
[0])))
308 if (dim
->tuple_id
[1] &&
309 !(dup
->tuple_id
[1] = isl_id_copy(dim
->tuple_id
[1])))
311 if (dim
->nested
[0] && !(dup
->nested
[0] = isl_space_copy(dim
->nested
[0])))
313 if (dim
->nested
[1] && !(dup
->nested
[1] = isl_space_copy(dim
->nested
[1])))
317 dup
= copy_ids(dup
, isl_dim_param
, 0, dim
, isl_dim_param
);
318 dup
= copy_ids(dup
, isl_dim_in
, 0, dim
, isl_dim_in
);
319 dup
= copy_ids(dup
, isl_dim_out
, 0, dim
, isl_dim_out
);
326 __isl_give isl_space
*isl_space_cow(__isl_take isl_space
*dim
)
334 return isl_space_dup(dim
);
337 __isl_give isl_space
*isl_space_copy(__isl_keep isl_space
*dim
)
346 __isl_null isl_space
*isl_space_free(__isl_take isl_space
*space
)
353 if (--space
->ref
> 0)
356 isl_id_free(space
->tuple_id
[0]);
357 isl_id_free(space
->tuple_id
[1]);
359 isl_space_free(space
->nested
[0]);
360 isl_space_free(space
->nested
[1]);
362 for (i
= 0; i
< space
->n_id
; ++i
)
363 isl_id_free(space
->ids
[i
]);
365 isl_ctx_deref(space
->ctx
);
372 /* Check if "s" is a valid dimension or tuple name.
373 * We currently only forbid names that look like a number.
375 * s is assumed to be non-NULL.
377 static int name_ok(isl_ctx
*ctx
, const char *s
)
382 dummy
= strtol(s
, &p
, 0);
384 isl_die(ctx
, isl_error_invalid
, "name looks like a number",
390 /* Is it possible for the given dimension type to have a tuple id?
392 static int space_can_have_id(__isl_keep isl_space
*space
,
393 enum isl_dim_type type
)
397 if (isl_space_is_params(space
))
398 isl_die(space
->ctx
, isl_error_invalid
,
399 "parameter spaces don't have tuple ids", return 0);
400 if (isl_space_is_set(space
) && type
!= isl_dim_set
)
401 isl_die(space
->ctx
, isl_error_invalid
,
402 "set spaces can only have a set id", return 0);
403 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
404 isl_die(space
->ctx
, isl_error_invalid
,
405 "only input, output and set tuples can have ids",
411 /* Does the tuple have an id?
413 isl_bool
isl_space_has_tuple_id(__isl_keep isl_space
*dim
,
414 enum isl_dim_type type
)
416 if (!space_can_have_id(dim
, type
))
417 return isl_bool_error
;
418 return dim
->tuple_id
[type
- isl_dim_in
] != NULL
;
421 __isl_give isl_id
*isl_space_get_tuple_id(__isl_keep isl_space
*dim
,
422 enum isl_dim_type type
)
428 has_id
= isl_space_has_tuple_id(dim
, type
);
432 isl_die(dim
->ctx
, isl_error_invalid
,
433 "tuple has no id", return NULL
);
434 return isl_id_copy(dim
->tuple_id
[type
- isl_dim_in
]);
437 __isl_give isl_space
*isl_space_set_tuple_id(__isl_take isl_space
*dim
,
438 enum isl_dim_type type
, __isl_take isl_id
*id
)
440 dim
= isl_space_cow(dim
);
443 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
444 isl_die(dim
->ctx
, isl_error_invalid
,
445 "only input, output and set tuples can have names",
448 isl_id_free(dim
->tuple_id
[type
- isl_dim_in
]);
449 dim
->tuple_id
[type
- isl_dim_in
] = id
;
458 __isl_give isl_space
*isl_space_reset_tuple_id(__isl_take isl_space
*dim
,
459 enum isl_dim_type type
)
461 dim
= isl_space_cow(dim
);
464 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
465 isl_die(dim
->ctx
, isl_error_invalid
,
466 "only input, output and set tuples can have names",
469 isl_id_free(dim
->tuple_id
[type
- isl_dim_in
]);
470 dim
->tuple_id
[type
- isl_dim_in
] = NULL
;
478 /* Set the id of the given dimension of "space" to "id".
479 * If the dimension already has an id, then it is replaced.
480 * If the dimension is a parameter, then we need to change it
481 * in the nested spaces (if any) as well.
483 __isl_give isl_space
*isl_space_set_dim_id(__isl_take isl_space
*space
,
484 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
486 space
= isl_space_cow(space
);
490 if (type
== isl_dim_param
) {
493 for (i
= 0; i
< 2; ++i
) {
494 if (!space
->nested
[i
])
497 isl_space_set_dim_id(space
->nested
[i
],
498 type
, pos
, isl_id_copy(id
));
499 if (!space
->nested
[i
])
504 isl_id_free(get_id(space
, type
, pos
));
505 return set_id(space
, type
, pos
, id
);
508 isl_space_free(space
);
512 /* Reset the id of the given dimension of "space".
513 * If the dimension already has an id, then it is removed.
514 * If the dimension is a parameter, then we need to reset it
515 * in the nested spaces (if any) as well.
517 __isl_give isl_space
*isl_space_reset_dim_id(__isl_take isl_space
*space
,
518 enum isl_dim_type type
, unsigned pos
)
520 space
= isl_space_cow(space
);
524 if (type
== isl_dim_param
) {
527 for (i
= 0; i
< 2; ++i
) {
528 if (!space
->nested
[i
])
531 isl_space_reset_dim_id(space
->nested
[i
],
533 if (!space
->nested
[i
])
538 isl_id_free(get_id(space
, type
, pos
));
539 return set_id(space
, type
, pos
, NULL
);
541 isl_space_free(space
);
545 isl_bool
isl_space_has_dim_id(__isl_keep isl_space
*dim
,
546 enum isl_dim_type type
, unsigned pos
)
549 return isl_bool_error
;
550 return get_id(dim
, type
, pos
) != NULL
;
553 __isl_give isl_id
*isl_space_get_dim_id(__isl_keep isl_space
*dim
,
554 enum isl_dim_type type
, unsigned pos
)
558 if (!get_id(dim
, type
, pos
))
559 isl_die(dim
->ctx
, isl_error_invalid
,
560 "dim has no id", return NULL
);
561 return isl_id_copy(get_id(dim
, type
, pos
));
564 __isl_give isl_space
*isl_space_set_tuple_name(__isl_take isl_space
*dim
,
565 enum isl_dim_type type
, const char *s
)
573 return isl_space_reset_tuple_id(dim
, type
);
575 if (!name_ok(dim
->ctx
, s
))
578 id
= isl_id_alloc(dim
->ctx
, s
, NULL
);
579 return isl_space_set_tuple_id(dim
, type
, id
);
585 /* Does the tuple have a name?
587 isl_bool
isl_space_has_tuple_name(__isl_keep isl_space
*space
,
588 enum isl_dim_type type
)
592 if (!space_can_have_id(space
, type
))
593 return isl_bool_error
;
594 id
= space
->tuple_id
[type
- isl_dim_in
];
595 return id
&& id
->name
;
598 __isl_keep
const char *isl_space_get_tuple_name(__isl_keep isl_space
*dim
,
599 enum isl_dim_type type
)
604 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
606 id
= dim
->tuple_id
[type
- isl_dim_in
];
607 return id
? id
->name
: NULL
;
610 __isl_give isl_space
*isl_space_set_dim_name(__isl_take isl_space
*dim
,
611 enum isl_dim_type type
, unsigned pos
,
619 return isl_space_reset_dim_id(dim
, type
, pos
);
620 if (!name_ok(dim
->ctx
, s
))
622 id
= isl_id_alloc(dim
->ctx
, s
, NULL
);
623 return isl_space_set_dim_id(dim
, type
, pos
, id
);
629 /* Does the given dimension have a name?
631 isl_bool
isl_space_has_dim_name(__isl_keep isl_space
*space
,
632 enum isl_dim_type type
, unsigned pos
)
637 return isl_bool_error
;
638 id
= get_id(space
, type
, pos
);
639 return id
&& id
->name
;
642 __isl_keep
const char *isl_space_get_dim_name(__isl_keep isl_space
*dim
,
643 enum isl_dim_type type
, unsigned pos
)
645 isl_id
*id
= get_id(dim
, type
, pos
);
646 return id
? id
->name
: NULL
;
649 int isl_space_find_dim_by_id(__isl_keep isl_space
*dim
, enum isl_dim_type type
,
650 __isl_keep isl_id
*id
)
659 offset
= isl_space_offset(dim
, type
);
660 n
= isl_space_dim(dim
, type
);
661 for (i
= 0; i
< n
&& offset
+ i
< dim
->n_id
; ++i
)
662 if (dim
->ids
[offset
+ i
] == id
)
668 int isl_space_find_dim_by_name(__isl_keep isl_space
*space
,
669 enum isl_dim_type type
, const char *name
)
678 offset
= isl_space_offset(space
, type
);
679 n
= isl_space_dim(space
, type
);
680 for (i
= 0; i
< n
&& offset
+ i
< space
->n_id
; ++i
) {
681 isl_id
*id
= get_id(space
, type
, i
);
682 if (id
&& id
->name
&& !strcmp(id
->name
, name
))
689 /* Reset the user pointer on all identifiers of parameters and tuples
692 __isl_give isl_space
*isl_space_reset_user(__isl_take isl_space
*space
)
702 ctx
= isl_space_get_ctx(space
);
704 for (i
= 0; i
< space
->nparam
&& i
< space
->n_id
; ++i
) {
705 if (!isl_id_get_user(space
->ids
[i
]))
707 space
= isl_space_cow(space
);
710 name
= isl_id_get_name(space
->ids
[i
]);
711 id
= isl_id_alloc(ctx
, name
, NULL
);
712 isl_id_free(space
->ids
[i
]);
715 return isl_space_free(space
);
718 for (i
= 0; i
< 2; ++i
) {
719 if (!space
->tuple_id
[i
])
721 if (!isl_id_get_user(space
->tuple_id
[i
]))
723 space
= isl_space_cow(space
);
726 name
= isl_id_get_name(space
->tuple_id
[i
]);
727 id
= isl_id_alloc(ctx
, name
, NULL
);
728 isl_id_free(space
->tuple_id
[i
]);
729 space
->tuple_id
[i
] = id
;
731 return isl_space_free(space
);
734 for (i
= 0; i
< 2; ++i
) {
735 if (!space
->nested
[i
])
737 space
= isl_space_cow(space
);
740 space
->nested
[i
] = isl_space_reset_user(space
->nested
[i
]);
741 if (!space
->nested
[i
])
742 return isl_space_free(space
);
748 static __isl_keep isl_id
*tuple_id(__isl_keep isl_space
*dim
,
749 enum isl_dim_type type
)
753 if (type
== isl_dim_in
)
754 return dim
->tuple_id
[0];
755 if (type
== isl_dim_out
)
756 return dim
->tuple_id
[1];
760 static __isl_keep isl_space
*nested(__isl_keep isl_space
*dim
,
761 enum isl_dim_type type
)
765 if (type
== isl_dim_in
)
766 return dim
->nested
[0];
767 if (type
== isl_dim_out
)
768 return dim
->nested
[1];
772 /* Are the two spaces the same, apart from positions and names of parameters?
774 isl_bool
isl_space_has_equal_tuples(__isl_keep isl_space
*space1
,
775 __isl_keep isl_space
*space2
)
777 if (!space1
|| !space2
)
778 return isl_bool_error
;
779 if (space1
== space2
)
780 return isl_bool_true
;
781 return isl_space_tuple_is_equal(space1
, isl_dim_in
,
782 space2
, isl_dim_in
) &&
783 isl_space_tuple_is_equal(space1
, isl_dim_out
,
784 space2
, isl_dim_out
);
787 /* Check if the tuple of type "type1" of "space1" is the same as
788 * the tuple of type "type2" of "space2".
790 * That is, check if the tuples have the same identifier, the same dimension
791 * and the same internal structure.
792 * The identifiers of the dimensions inside the tuples do not affect the result.
794 * Note that this function only checks the tuples themselves.
795 * If nested tuples are involved, then we need to be careful not
796 * to have result affected by possibly differing parameters
797 * in those nested tuples.
799 isl_bool
isl_space_tuple_is_equal(__isl_keep isl_space
*space1
,
800 enum isl_dim_type type1
, __isl_keep isl_space
*space2
,
801 enum isl_dim_type type2
)
804 isl_space
*nested1
, *nested2
;
806 if (!space1
|| !space2
)
807 return isl_bool_error
;
809 if (space1
== space2
&& type1
== type2
)
810 return isl_bool_true
;
812 if (n(space1
, type1
) != n(space2
, type2
))
813 return isl_bool_false
;
814 id1
= tuple_id(space1
, type1
);
815 id2
= tuple_id(space2
, type2
);
817 return isl_bool_false
;
818 if (id1
&& id1
!= id2
)
819 return isl_bool_false
;
820 nested1
= nested(space1
, type1
);
821 nested2
= nested(space2
, type2
);
822 if (!nested1
^ !nested2
)
823 return isl_bool_false
;
824 if (nested1
&& !isl_space_has_equal_tuples(nested1
, nested2
))
825 return isl_bool_false
;
826 return isl_bool_true
;
829 /* This is the old, undocumented, name for isl_space_tuple_is_equal.
830 * It will be removed at some point.
832 int isl_space_tuple_match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
833 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
835 return isl_space_tuple_is_equal(space1
, type1
, space2
, type2
);
838 static isl_bool
match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
839 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
843 if (space1
== space2
&& type1
== type2
)
844 return isl_bool_true
;
846 if (!isl_space_tuple_is_equal(space1
, type1
, space2
, type2
))
847 return isl_bool_false
;
849 if (!space1
->ids
&& !space2
->ids
)
850 return isl_bool_true
;
852 for (i
= 0; i
< n(space1
, type1
); ++i
) {
853 if (get_id(space1
, type1
, i
) != get_id(space2
, type2
, i
))
854 return isl_bool_false
;
856 return isl_bool_true
;
859 /* Do "space1" and "space2" have the same parameters?
861 isl_bool
isl_space_has_equal_params(__isl_keep isl_space
*space1
,
862 __isl_keep isl_space
*space2
)
864 if (!space1
|| !space2
)
865 return isl_bool_error
;
867 return match(space1
, isl_dim_param
, space2
, isl_dim_param
);
870 /* Do "space1" and "space2" have the same identifiers for all
871 * the tuple variables?
873 isl_bool
isl_space_has_equal_ids(__isl_keep isl_space
*space1
,
874 __isl_keep isl_space
*space2
)
878 if (!space1
|| !space2
)
879 return isl_bool_error
;
881 equal
= match(space1
, isl_dim_in
, space2
, isl_dim_in
);
882 if (equal
< 0 || !equal
)
884 return match(space1
, isl_dim_out
, space2
, isl_dim_out
);
887 isl_bool
isl_space_match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
888 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
890 if (!space1
|| !space2
)
891 return isl_bool_error
;
893 return match(space1
, type1
, space2
, type2
);
896 static void get_ids(__isl_keep isl_space
*dim
, enum isl_dim_type type
,
897 unsigned first
, unsigned n
, __isl_keep isl_id
**ids
)
901 for (i
= 0; i
< n
; ++i
)
902 ids
[i
] = get_id(dim
, type
, first
+ i
);
905 static __isl_give isl_space
*space_extend(__isl_take isl_space
*space
,
906 unsigned nparam
, unsigned n_in
, unsigned n_out
)
912 if (space
->nparam
== nparam
&&
913 space
->n_in
== n_in
&& space
->n_out
== n_out
)
916 isl_assert(space
->ctx
, space
->nparam
<= nparam
, goto error
);
917 isl_assert(space
->ctx
, space
->n_in
<= n_in
, goto error
);
918 isl_assert(space
->ctx
, space
->n_out
<= n_out
, goto error
);
920 space
= isl_space_cow(space
);
926 n
= nparam
+ n_in
+ n_out
;
927 if (n
< nparam
|| n
< n_in
|| n
< n_out
)
928 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
929 "overflow in total number of dimensions",
931 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n
);
934 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
935 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
+ nparam
);
936 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
937 ids
+ nparam
+ n_in
);
940 space
->n_id
= nparam
+ n_in
+ n_out
;
942 space
->nparam
= nparam
;
944 space
->n_out
= n_out
;
949 isl_space_free(space
);
953 __isl_give isl_space
*isl_space_extend(__isl_take isl_space
*space
,
954 unsigned nparam
, unsigned n_in
, unsigned n_out
)
956 return space_extend(space
, nparam
, n_in
, n_out
);
959 __isl_give isl_space
*isl_space_add_dims(__isl_take isl_space
*space
,
960 enum isl_dim_type type
, unsigned n
)
962 space
= isl_space_reset(space
, type
);
967 space
= space_extend(space
,
968 space
->nparam
+ n
, space
->n_in
, space
->n_out
);
969 if (space
&& space
->nested
[0] &&
970 !(space
->nested
[0] = isl_space_add_dims(space
->nested
[0],
973 if (space
&& space
->nested
[1] &&
974 !(space
->nested
[1] = isl_space_add_dims(space
->nested
[1],
979 return space_extend(space
,
980 space
->nparam
, space
->n_in
+ n
, space
->n_out
);
982 return space_extend(space
,
983 space
->nparam
, space
->n_in
, space
->n_out
+ n
);
985 isl_die(space
->ctx
, isl_error_invalid
,
986 "cannot add dimensions of specified type", goto error
);
989 isl_space_free(space
);
993 static int valid_dim_type(enum isl_dim_type type
)
1005 /* Insert "n" dimensions of type "type" at position "pos".
1006 * If we are inserting parameters, then they are also inserted in
1007 * any nested spaces.
1009 __isl_give isl_space
*isl_space_insert_dims(__isl_take isl_space
*dim
,
1010 enum isl_dim_type type
, unsigned pos
, unsigned n
)
1012 isl_id
**ids
= NULL
;
1017 return isl_space_reset(dim
, type
);
1019 if (!valid_dim_type(type
))
1020 isl_die(dim
->ctx
, isl_error_invalid
,
1021 "cannot insert dimensions of specified type",
1024 isl_assert(dim
->ctx
, pos
<= isl_space_dim(dim
, type
), goto error
);
1026 dim
= isl_space_cow(dim
);
1031 enum isl_dim_type t
, o
= isl_dim_param
;
1034 ids
= isl_calloc_array(dim
->ctx
, isl_id
*,
1035 dim
->nparam
+ dim
->n_in
+ dim
->n_out
+ n
);
1039 s
[isl_dim_param
- o
] = dim
->nparam
;
1040 s
[isl_dim_in
- o
] = dim
->n_in
;
1041 s
[isl_dim_out
- o
] = dim
->n_out
;
1042 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1044 get_ids(dim
, t
, 0, s
[t
- o
], ids
+ off
);
1047 get_ids(dim
, t
, 0, pos
, ids
+ off
);
1049 get_ids(dim
, t
, pos
, s
[t
- o
] - pos
, ids
+ off
);
1050 off
+= s
[t
- o
] - pos
;
1055 dim
->n_id
= dim
->nparam
+ dim
->n_in
+ dim
->n_out
+ n
;
1058 case isl_dim_param
: dim
->nparam
+= n
; break;
1059 case isl_dim_in
: dim
->n_in
+= n
; break;
1060 case isl_dim_out
: dim
->n_out
+= n
; break;
1063 dim
= isl_space_reset(dim
, type
);
1065 if (type
== isl_dim_param
) {
1066 if (dim
&& dim
->nested
[0] &&
1067 !(dim
->nested
[0] = isl_space_insert_dims(dim
->nested
[0],
1068 isl_dim_param
, pos
, n
)))
1070 if (dim
&& dim
->nested
[1] &&
1071 !(dim
->nested
[1] = isl_space_insert_dims(dim
->nested
[1],
1072 isl_dim_param
, pos
, n
)))
1078 isl_space_free(dim
);
1082 __isl_give isl_space
*isl_space_move_dims(__isl_take isl_space
*space
,
1083 enum isl_dim_type dst_type
, unsigned dst_pos
,
1084 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1088 space
= isl_space_reset(space
, src_type
);
1089 space
= isl_space_reset(space
, dst_type
);
1095 isl_assert(space
->ctx
, src_pos
+ n
<= isl_space_dim(space
, src_type
),
1098 if (dst_type
== src_type
&& dst_pos
== src_pos
)
1101 isl_assert(space
->ctx
, dst_type
!= src_type
, goto error
);
1103 space
= isl_space_cow(space
);
1109 enum isl_dim_type t
, o
= isl_dim_param
;
1112 ids
= isl_calloc_array(space
->ctx
, isl_id
*,
1113 space
->nparam
+ space
->n_in
+ space
->n_out
);
1117 s
[isl_dim_param
- o
] = space
->nparam
;
1118 s
[isl_dim_in
- o
] = space
->n_in
;
1119 s
[isl_dim_out
- o
] = space
->n_out
;
1120 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1121 if (t
== dst_type
) {
1122 get_ids(space
, t
, 0, dst_pos
, ids
+ off
);
1124 get_ids(space
, src_type
, src_pos
, n
, ids
+ off
);
1126 get_ids(space
, t
, dst_pos
, s
[t
- o
] - dst_pos
,
1128 off
+= s
[t
- o
] - dst_pos
;
1129 } else if (t
== src_type
) {
1130 get_ids(space
, t
, 0, src_pos
, ids
+ off
);
1132 get_ids(space
, t
, src_pos
+ n
,
1133 s
[t
- o
] - src_pos
- n
, ids
+ off
);
1134 off
+= s
[t
- o
] - src_pos
- n
;
1136 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1142 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
;
1146 case isl_dim_param
: space
->nparam
+= n
; break;
1147 case isl_dim_in
: space
->n_in
+= n
; break;
1148 case isl_dim_out
: space
->n_out
+= n
; break;
1153 case isl_dim_param
: space
->nparam
-= n
; break;
1154 case isl_dim_in
: space
->n_in
-= n
; break;
1155 case isl_dim_out
: space
->n_out
-= n
; break;
1159 if (dst_type
!= isl_dim_param
&& src_type
!= isl_dim_param
)
1162 for (i
= 0; i
< 2; ++i
) {
1163 if (!space
->nested
[i
])
1165 space
->nested
[i
] = isl_space_replace(space
->nested
[i
],
1166 isl_dim_param
, space
);
1167 if (!space
->nested
[i
])
1173 isl_space_free(space
);
1177 /* Check that "space1" and "space2" have the same parameters,
1178 * reporting an error if they do not.
1180 isl_stat
isl_space_check_equal_params(__isl_keep isl_space
*space1
,
1181 __isl_keep isl_space
*space2
)
1185 equal
= isl_space_has_equal_params(space1
, space2
);
1187 return isl_stat_error
;
1189 isl_die(isl_space_get_ctx(space1
), isl_error_invalid
,
1190 "parameters need to match", return isl_stat_error
);
1194 __isl_give isl_space
*isl_space_join(__isl_take isl_space
*left
,
1195 __isl_take isl_space
*right
)
1199 if (isl_space_check_equal_params(left
, right
) < 0)
1202 isl_assert(left
->ctx
,
1203 isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_in
),
1206 dim
= isl_space_alloc(left
->ctx
, left
->nparam
, left
->n_in
, right
->n_out
);
1210 dim
= copy_ids(dim
, isl_dim_param
, 0, left
, isl_dim_param
);
1211 dim
= copy_ids(dim
, isl_dim_in
, 0, left
, isl_dim_in
);
1212 dim
= copy_ids(dim
, isl_dim_out
, 0, right
, isl_dim_out
);
1214 if (dim
&& left
->tuple_id
[0] &&
1215 !(dim
->tuple_id
[0] = isl_id_copy(left
->tuple_id
[0])))
1217 if (dim
&& right
->tuple_id
[1] &&
1218 !(dim
->tuple_id
[1] = isl_id_copy(right
->tuple_id
[1])))
1220 if (dim
&& left
->nested
[0] &&
1221 !(dim
->nested
[0] = isl_space_copy(left
->nested
[0])))
1223 if (dim
&& right
->nested
[1] &&
1224 !(dim
->nested
[1] = isl_space_copy(right
->nested
[1])))
1227 isl_space_free(left
);
1228 isl_space_free(right
);
1232 isl_space_free(left
);
1233 isl_space_free(right
);
1237 /* Given two map spaces { A -> C } and { B -> D }, construct the space
1238 * { [A -> B] -> [C -> D] }.
1239 * Given two set spaces { A } and { B }, construct the space { [A -> B] }.
1241 __isl_give isl_space
*isl_space_product(__isl_take isl_space
*left
,
1242 __isl_take isl_space
*right
)
1244 isl_space
*dom1
, *dom2
, *nest1
, *nest2
;
1247 if (!left
|| !right
)
1250 is_set
= isl_space_is_set(left
);
1251 if (is_set
!= isl_space_is_set(right
))
1252 isl_die(isl_space_get_ctx(left
), isl_error_invalid
,
1253 "expecting either two set spaces or two map spaces",
1256 return isl_space_range_product(left
, right
);
1258 if (isl_space_check_equal_params(left
, right
) < 0)
1261 dom1
= isl_space_domain(isl_space_copy(left
));
1262 dom2
= isl_space_domain(isl_space_copy(right
));
1263 nest1
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1265 dom1
= isl_space_range(left
);
1266 dom2
= isl_space_range(right
);
1267 nest2
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1269 return isl_space_join(isl_space_reverse(nest1
), nest2
);
1271 isl_space_free(left
);
1272 isl_space_free(right
);
1276 /* Given two spaces { A -> C } and { B -> C }, construct the space
1279 __isl_give isl_space
*isl_space_domain_product(__isl_take isl_space
*left
,
1280 __isl_take isl_space
*right
)
1282 isl_space
*ran
, *dom1
, *dom2
, *nest
;
1284 if (isl_space_check_equal_params(left
, right
) < 0)
1287 if (!isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_out
))
1288 isl_die(left
->ctx
, isl_error_invalid
,
1289 "ranges need to match", goto error
);
1291 ran
= isl_space_range(isl_space_copy(left
));
1293 dom1
= isl_space_domain(left
);
1294 dom2
= isl_space_domain(right
);
1295 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1297 return isl_space_join(isl_space_reverse(nest
), ran
);
1299 isl_space_free(left
);
1300 isl_space_free(right
);
1304 __isl_give isl_space
*isl_space_range_product(__isl_take isl_space
*left
,
1305 __isl_take isl_space
*right
)
1307 isl_space
*dom
, *ran1
, *ran2
, *nest
;
1309 if (isl_space_check_equal_params(left
, right
) < 0)
1312 if (!isl_space_tuple_is_equal(left
, isl_dim_in
, right
, isl_dim_in
))
1313 isl_die(left
->ctx
, isl_error_invalid
,
1314 "domains need to match", goto error
);
1316 dom
= isl_space_domain(isl_space_copy(left
));
1318 ran1
= isl_space_range(left
);
1319 ran2
= isl_space_range(right
);
1320 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(ran1
), ran2
));
1322 return isl_space_join(isl_space_reverse(dom
), nest
);
1324 isl_space_free(left
);
1325 isl_space_free(right
);
1329 /* Given a space of the form [A -> B] -> C, return the space A -> C.
1331 __isl_give isl_space
*isl_space_domain_factor_domain(
1332 __isl_take isl_space
*space
)
1339 if (!isl_space_domain_is_wrapping(space
))
1340 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1341 "domain not a product", return isl_space_free(space
));
1343 nested
= space
->nested
[0];
1344 domain
= isl_space_copy(space
);
1345 domain
= isl_space_drop_dims(domain
, isl_dim_in
,
1346 nested
->n_in
, nested
->n_out
);
1348 return isl_space_free(space
);
1349 if (nested
->tuple_id
[0]) {
1350 domain
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[0]);
1351 if (!domain
->tuple_id
[0])
1354 if (nested
->nested
[0]) {
1355 domain
->nested
[0] = isl_space_copy(nested
->nested
[0]);
1356 if (!domain
->nested
[0])
1360 isl_space_free(space
);
1363 isl_space_free(space
);
1364 isl_space_free(domain
);
1368 /* Given a space of the form [A -> B] -> C, return the space B -> C.
1370 __isl_give isl_space
*isl_space_domain_factor_range(
1371 __isl_take isl_space
*space
)
1378 if (!isl_space_domain_is_wrapping(space
))
1379 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1380 "domain not a product", return isl_space_free(space
));
1382 nested
= space
->nested
[0];
1383 range
= isl_space_copy(space
);
1384 range
= isl_space_drop_dims(range
, isl_dim_in
, 0, nested
->n_in
);
1386 return isl_space_free(space
);
1387 if (nested
->tuple_id
[1]) {
1388 range
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[1]);
1389 if (!range
->tuple_id
[0])
1392 if (nested
->nested
[1]) {
1393 range
->nested
[0] = isl_space_copy(nested
->nested
[1]);
1394 if (!range
->nested
[0])
1398 isl_space_free(space
);
1401 isl_space_free(space
);
1402 isl_space_free(range
);
1406 /* Internal function that selects the domain of the map that is
1407 * embedded in either a set space or the range of a map space.
1408 * In particular, given a space of the form [A -> B], return the space A.
1409 * Given a space of the form A -> [B -> C], return the space A -> B.
1411 static __isl_give isl_space
*range_factor_domain(__isl_take isl_space
*space
)
1419 nested
= space
->nested
[1];
1420 domain
= isl_space_copy(space
);
1421 domain
= isl_space_drop_dims(domain
, isl_dim_out
,
1422 nested
->n_in
, nested
->n_out
);
1424 return isl_space_free(space
);
1425 if (nested
->tuple_id
[0]) {
1426 domain
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[0]);
1427 if (!domain
->tuple_id
[1])
1430 if (nested
->nested
[0]) {
1431 domain
->nested
[1] = isl_space_copy(nested
->nested
[0]);
1432 if (!domain
->nested
[1])
1436 isl_space_free(space
);
1439 isl_space_free(space
);
1440 isl_space_free(domain
);
1444 /* Given a space of the form A -> [B -> C], return the space A -> B.
1446 __isl_give isl_space
*isl_space_range_factor_domain(
1447 __isl_take isl_space
*space
)
1451 if (!isl_space_range_is_wrapping(space
))
1452 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1453 "range not a product", return isl_space_free(space
));
1455 return range_factor_domain(space
);
1458 /* Given a space of the form [A -> B], return the space A.
1460 static __isl_give isl_space
*set_factor_domain(__isl_take isl_space
*space
)
1464 if (!isl_space_is_wrapping(space
))
1465 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1466 "not a product", return isl_space_free(space
));
1468 return range_factor_domain(space
);
1471 /* Given a space of the form [A -> B] -> [C -> D], return the space A -> C.
1472 * Given a space of the form [A -> B], return the space A.
1474 __isl_give isl_space
*isl_space_factor_domain(__isl_take isl_space
*space
)
1478 if (isl_space_is_set(space
))
1479 return set_factor_domain(space
);
1480 space
= isl_space_domain_factor_domain(space
);
1481 space
= isl_space_range_factor_domain(space
);
1485 /* Internal function that selects the range of the map that is
1486 * embedded in either a set space or the range of a map space.
1487 * In particular, given a space of the form [A -> B], return the space B.
1488 * Given a space of the form A -> [B -> C], return the space A -> C.
1490 static __isl_give isl_space
*range_factor_range(__isl_take isl_space
*space
)
1498 nested
= space
->nested
[1];
1499 range
= isl_space_copy(space
);
1500 range
= isl_space_drop_dims(range
, isl_dim_out
, 0, nested
->n_in
);
1502 return isl_space_free(space
);
1503 if (nested
->tuple_id
[1]) {
1504 range
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[1]);
1505 if (!range
->tuple_id
[1])
1508 if (nested
->nested
[1]) {
1509 range
->nested
[1] = isl_space_copy(nested
->nested
[1]);
1510 if (!range
->nested
[1])
1514 isl_space_free(space
);
1517 isl_space_free(space
);
1518 isl_space_free(range
);
1522 /* Given a space of the form A -> [B -> C], return the space A -> C.
1524 __isl_give isl_space
*isl_space_range_factor_range(
1525 __isl_take isl_space
*space
)
1529 if (!isl_space_range_is_wrapping(space
))
1530 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1531 "range not a product", return isl_space_free(space
));
1533 return range_factor_range(space
);
1536 /* Given a space of the form [A -> B], return the space B.
1538 static __isl_give isl_space
*set_factor_range(__isl_take isl_space
*space
)
1542 if (!isl_space_is_wrapping(space
))
1543 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1544 "not a product", return isl_space_free(space
));
1546 return range_factor_range(space
);
1549 /* Given a space of the form [A -> B] -> [C -> D], return the space B -> D.
1550 * Given a space of the form [A -> B], return the space B.
1552 __isl_give isl_space
*isl_space_factor_range(__isl_take isl_space
*space
)
1556 if (isl_space_is_set(space
))
1557 return set_factor_range(space
);
1558 space
= isl_space_domain_factor_range(space
);
1559 space
= isl_space_range_factor_range(space
);
1563 __isl_give isl_space
*isl_space_map_from_set(__isl_take isl_space
*space
)
1566 isl_id
**ids
= NULL
;
1571 ctx
= isl_space_get_ctx(space
);
1572 if (!isl_space_is_set(space
))
1573 isl_die(ctx
, isl_error_invalid
, "not a set space", goto error
);
1574 space
= isl_space_cow(space
);
1577 n_id
= space
->nparam
+ space
->n_out
+ space
->n_out
;
1578 if (n_id
> 0 && space
->ids
) {
1579 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n_id
);
1582 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
1583 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1584 ids
+ space
->nparam
);
1586 space
->n_in
= space
->n_out
;
1591 space
= copy_ids(space
, isl_dim_out
, 0, space
, isl_dim_in
);
1593 isl_id_free(space
->tuple_id
[0]);
1594 space
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[1]);
1595 isl_space_free(space
->nested
[0]);
1596 space
->nested
[0] = isl_space_copy(space
->nested
[1]);
1599 isl_space_free(space
);
1603 __isl_give isl_space
*isl_space_map_from_domain_and_range(
1604 __isl_take isl_space
*domain
, __isl_take isl_space
*range
)
1606 if (!domain
|| !range
)
1608 if (!isl_space_is_set(domain
))
1609 isl_die(isl_space_get_ctx(domain
), isl_error_invalid
,
1610 "domain is not a set space", goto error
);
1611 if (!isl_space_is_set(range
))
1612 isl_die(isl_space_get_ctx(range
), isl_error_invalid
,
1613 "range is not a set space", goto error
);
1614 return isl_space_join(isl_space_reverse(domain
), range
);
1616 isl_space_free(domain
);
1617 isl_space_free(range
);
1621 static __isl_give isl_space
*set_ids(__isl_take isl_space
*dim
,
1622 enum isl_dim_type type
,
1623 unsigned first
, unsigned n
, __isl_take isl_id
**ids
)
1627 for (i
= 0; i
< n
; ++i
)
1628 dim
= set_id(dim
, type
, first
+ i
, ids
[i
]);
1633 __isl_give isl_space
*isl_space_reverse(__isl_take isl_space
*dim
)
1637 isl_id
**ids
= NULL
;
1642 if (match(dim
, isl_dim_in
, dim
, isl_dim_out
))
1645 dim
= isl_space_cow(dim
);
1649 id
= dim
->tuple_id
[0];
1650 dim
->tuple_id
[0] = dim
->tuple_id
[1];
1651 dim
->tuple_id
[1] = id
;
1653 nested
= dim
->nested
[0];
1654 dim
->nested
[0] = dim
->nested
[1];
1655 dim
->nested
[1] = nested
;
1658 int n_id
= dim
->n_in
+ dim
->n_out
;
1659 ids
= isl_alloc_array(dim
->ctx
, isl_id
*, n_id
);
1662 get_ids(dim
, isl_dim_in
, 0, dim
->n_in
, ids
);
1663 get_ids(dim
, isl_dim_out
, 0, dim
->n_out
, ids
+ dim
->n_in
);
1667 dim
->n_in
= dim
->n_out
;
1671 dim
= set_ids(dim
, isl_dim_out
, 0, dim
->n_out
, ids
);
1672 dim
= set_ids(dim
, isl_dim_in
, 0, dim
->n_in
, ids
+ dim
->n_out
);
1679 isl_space_free(dim
);
1683 __isl_give isl_space
*isl_space_drop_dims(__isl_take isl_space
*dim
,
1684 enum isl_dim_type type
, unsigned first
, unsigned num
)
1692 return isl_space_reset(dim
, type
);
1694 if (!valid_dim_type(type
))
1695 isl_die(dim
->ctx
, isl_error_invalid
,
1696 "cannot drop dimensions of specified type", goto error
);
1698 if (first
+ num
> n(dim
, type
) || first
+ num
< first
)
1699 isl_die(isl_space_get_ctx(dim
), isl_error_invalid
,
1700 "index out of bounds", return isl_space_free(dim
));
1701 dim
= isl_space_cow(dim
);
1705 dim
= extend_ids(dim
);
1708 for (i
= 0; i
< num
; ++i
)
1709 isl_id_free(get_id(dim
, type
, first
+ i
));
1710 for (i
= first
+num
; i
< n(dim
, type
); ++i
)
1711 set_id(dim
, type
, i
- num
, get_id(dim
, type
, i
));
1714 get_ids(dim
, isl_dim_in
, 0, dim
->n_in
,
1715 dim
->ids
+ offset(dim
, isl_dim_in
) - num
);
1717 get_ids(dim
, isl_dim_out
, 0, dim
->n_out
,
1718 dim
->ids
+ offset(dim
, isl_dim_out
) - num
);
1725 case isl_dim_param
: dim
->nparam
-= num
; break;
1726 case isl_dim_in
: dim
->n_in
-= num
; break;
1727 case isl_dim_out
: dim
->n_out
-= num
; break;
1730 dim
= isl_space_reset(dim
, type
);
1731 if (type
== isl_dim_param
) {
1732 if (dim
&& dim
->nested
[0] &&
1733 !(dim
->nested
[0] = isl_space_drop_dims(dim
->nested
[0],
1734 isl_dim_param
, first
, num
)))
1736 if (dim
&& dim
->nested
[1] &&
1737 !(dim
->nested
[1] = isl_space_drop_dims(dim
->nested
[1],
1738 isl_dim_param
, first
, num
)))
1743 isl_space_free(dim
);
1747 __isl_give isl_space
*isl_space_drop_inputs(__isl_take isl_space
*dim
,
1748 unsigned first
, unsigned n
)
1752 return isl_space_drop_dims(dim
, isl_dim_in
, first
, n
);
1755 __isl_give isl_space
*isl_space_drop_outputs(__isl_take isl_space
*dim
,
1756 unsigned first
, unsigned n
)
1760 return isl_space_drop_dims(dim
, isl_dim_out
, first
, n
);
1763 __isl_give isl_space
*isl_space_domain(__isl_take isl_space
*space
)
1767 space
= isl_space_drop_dims(space
, isl_dim_out
, 0, space
->n_out
);
1768 space
= isl_space_reverse(space
);
1769 space
= mark_as_set(space
);
1773 __isl_give isl_space
*isl_space_from_domain(__isl_take isl_space
*dim
)
1777 if (!isl_space_is_set(dim
))
1778 isl_die(isl_space_get_ctx(dim
), isl_error_invalid
,
1779 "not a set space", goto error
);
1780 dim
= isl_space_reverse(dim
);
1781 dim
= isl_space_reset(dim
, isl_dim_out
);
1784 isl_space_free(dim
);
1788 __isl_give isl_space
*isl_space_range(__isl_take isl_space
*space
)
1792 space
= isl_space_drop_dims(space
, isl_dim_in
, 0, space
->n_in
);
1793 space
= mark_as_set(space
);
1797 __isl_give isl_space
*isl_space_from_range(__isl_take isl_space
*dim
)
1801 if (!isl_space_is_set(dim
))
1802 isl_die(isl_space_get_ctx(dim
), isl_error_invalid
,
1803 "not a set space", goto error
);
1804 return isl_space_reset(dim
, isl_dim_in
);
1806 isl_space_free(dim
);
1810 /* Given a map space A -> B, return the map space [A -> B] -> A.
1812 __isl_give isl_space
*isl_space_domain_map(__isl_take isl_space
*space
)
1816 domain
= isl_space_from_range(isl_space_domain(isl_space_copy(space
)));
1817 space
= isl_space_from_domain(isl_space_wrap(space
));
1818 space
= isl_space_join(space
, domain
);
1823 /* Given a map space A -> B, return the map space [A -> B] -> B.
1825 __isl_give isl_space
*isl_space_range_map(__isl_take isl_space
*space
)
1829 range
= isl_space_from_range(isl_space_range(isl_space_copy(space
)));
1830 space
= isl_space_from_domain(isl_space_wrap(space
));
1831 space
= isl_space_join(space
, range
);
1836 __isl_give isl_space
*isl_space_params(__isl_take isl_space
*space
)
1838 if (isl_space_is_params(space
))
1840 space
= isl_space_drop_dims(space
,
1841 isl_dim_in
, 0, isl_space_dim(space
, isl_dim_in
));
1842 space
= isl_space_drop_dims(space
,
1843 isl_dim_out
, 0, isl_space_dim(space
, isl_dim_out
));
1844 space
= mark_as_params(space
);
1848 __isl_give isl_space
*isl_space_set_from_params(__isl_take isl_space
*space
)
1852 if (!isl_space_is_params(space
))
1853 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1854 "not a parameter space", goto error
);
1855 return isl_space_reset(space
, isl_dim_set
);
1857 isl_space_free(space
);
1861 __isl_give isl_space
*isl_space_underlying(__isl_take isl_space
*dim
,
1869 dim
->nparam
== 0 && dim
->n_in
== 0 && dim
->n_id
== 0)
1870 return isl_space_reset(isl_space_reset(dim
, isl_dim_in
), isl_dim_out
);
1871 dim
= isl_space_cow(dim
);
1874 dim
->n_out
+= dim
->nparam
+ dim
->n_in
+ n_div
;
1878 for (i
= 0; i
< dim
->n_id
; ++i
)
1879 isl_id_free(get_id(dim
, isl_dim_out
, i
));
1881 dim
= isl_space_reset(dim
, isl_dim_in
);
1882 dim
= isl_space_reset(dim
, isl_dim_out
);
1887 /* Are the two spaces the same, including positions and names of parameters?
1889 isl_bool
isl_space_is_equal(__isl_keep isl_space
*space1
,
1890 __isl_keep isl_space
*space2
)
1894 if (!space1
|| !space2
)
1895 return isl_bool_error
;
1896 if (space1
== space2
)
1897 return isl_bool_true
;
1898 equal
= isl_space_has_equal_params(space1
, space2
);
1899 if (equal
< 0 || !equal
)
1901 return isl_space_has_equal_tuples(space1
, space2
);
1904 /* Is space1 equal to the domain of space2?
1906 * In the internal version we also allow space2 to be the space of a set,
1907 * provided space1 is a parameter space.
1909 isl_bool
isl_space_is_domain_internal(__isl_keep isl_space
*space1
,
1910 __isl_keep isl_space
*space2
)
1912 isl_bool equal_params
;
1914 if (!space1
|| !space2
)
1915 return isl_bool_error
;
1916 if (!isl_space_is_set(space1
))
1917 return isl_bool_false
;
1918 equal_params
= isl_space_has_equal_params(space1
, space2
);
1919 if (equal_params
< 0 || !equal_params
)
1920 return equal_params
;
1921 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
1922 space2
, isl_dim_in
);
1925 /* Is space1 equal to the domain of space2?
1927 isl_bool
isl_space_is_domain(__isl_keep isl_space
*space1
,
1928 __isl_keep isl_space
*space2
)
1931 return isl_bool_error
;
1932 if (!isl_space_is_map(space2
))
1933 return isl_bool_false
;
1934 return isl_space_is_domain_internal(space1
, space2
);
1937 /* Is space1 equal to the range of space2?
1939 * In the internal version, space2 is allowed to be the space of a set,
1940 * in which case it should be equal to space1.
1942 isl_bool
isl_space_is_range_internal(__isl_keep isl_space
*space1
,
1943 __isl_keep isl_space
*space2
)
1945 isl_bool equal_params
;
1947 if (!space1
|| !space2
)
1948 return isl_bool_error
;
1949 if (!isl_space_is_set(space1
))
1950 return isl_bool_false
;
1951 equal_params
= isl_space_has_equal_params(space1
, space2
);
1952 if (equal_params
< 0 || !equal_params
)
1953 return equal_params
;
1954 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
1955 space2
, isl_dim_out
);
1958 /* Is space1 equal to the range of space2?
1960 isl_bool
isl_space_is_range(__isl_keep isl_space
*space1
,
1961 __isl_keep isl_space
*space2
)
1964 return isl_bool_error
;
1965 if (!isl_space_is_map(space2
))
1966 return isl_bool_false
;
1967 return isl_space_is_range_internal(space1
, space2
);
1970 /* Update "hash" by hashing in the parameters of "space".
1972 static uint32_t isl_hash_params(uint32_t hash
, __isl_keep isl_space
*space
)
1980 isl_hash_byte(hash
, space
->nparam
% 256);
1982 for (i
= 0; i
< space
->nparam
; ++i
) {
1983 id
= get_id(space
, isl_dim_param
, i
);
1984 hash
= isl_hash_id(hash
, id
);
1990 /* Update "hash" by hashing in the tuples of "space".
1991 * Changes in this function should be reflected in isl_hash_tuples_domain.
1993 static uint32_t isl_hash_tuples(uint32_t hash
, __isl_keep isl_space
*space
)
2000 isl_hash_byte(hash
, space
->n_in
% 256);
2001 isl_hash_byte(hash
, space
->n_out
% 256);
2003 id
= tuple_id(space
, isl_dim_in
);
2004 hash
= isl_hash_id(hash
, id
);
2005 id
= tuple_id(space
, isl_dim_out
);
2006 hash
= isl_hash_id(hash
, id
);
2008 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2009 hash
= isl_hash_tuples(hash
, space
->nested
[1]);
2014 /* Update "hash" by hashing in the domain tuple of "space".
2015 * The result of this function is equal to the result of applying
2016 * isl_hash_tuples to the domain of "space".
2018 static uint32_t isl_hash_tuples_domain(uint32_t hash
,
2019 __isl_keep isl_space
*space
)
2026 isl_hash_byte(hash
, 0);
2027 isl_hash_byte(hash
, space
->n_in
% 256);
2029 hash
= isl_hash_id(hash
, &isl_id_none
);
2030 id
= tuple_id(space
, isl_dim_in
);
2031 hash
= isl_hash_id(hash
, id
);
2033 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2038 /* Return a hash value that digests the tuples of "space",
2039 * i.e., that ignores the parameters.
2041 uint32_t isl_space_get_tuple_hash(__isl_keep isl_space
*space
)
2048 hash
= isl_hash_init();
2049 hash
= isl_hash_tuples(hash
, space
);
2054 uint32_t isl_space_get_hash(__isl_keep isl_space
*space
)
2061 hash
= isl_hash_init();
2062 hash
= isl_hash_params(hash
, space
);
2063 hash
= isl_hash_tuples(hash
, space
);
2068 /* Return the hash value of the domain of "space".
2069 * That is, isl_space_get_domain_hash(space) is equal to
2070 * isl_space_get_hash(isl_space_domain(space)).
2072 uint32_t isl_space_get_domain_hash(__isl_keep isl_space
*space
)
2079 hash
= isl_hash_init();
2080 hash
= isl_hash_params(hash
, space
);
2081 hash
= isl_hash_tuples_domain(hash
, space
);
2086 isl_bool
isl_space_is_wrapping(__isl_keep isl_space
*dim
)
2089 return isl_bool_error
;
2091 if (!isl_space_is_set(dim
))
2092 return isl_bool_false
;
2094 return dim
->nested
[1] != NULL
;
2097 /* Is "space" the space of a map where the domain is a wrapped map space?
2099 isl_bool
isl_space_domain_is_wrapping(__isl_keep isl_space
*space
)
2102 return isl_bool_error
;
2104 if (isl_space_is_set(space
))
2105 return isl_bool_false
;
2107 return space
->nested
[0] != NULL
;
2110 /* Is "space" the space of a map where the range is a wrapped map space?
2112 isl_bool
isl_space_range_is_wrapping(__isl_keep isl_space
*space
)
2115 return isl_bool_error
;
2117 if (isl_space_is_set(space
))
2118 return isl_bool_false
;
2120 return space
->nested
[1] != NULL
;
2123 /* Is "space" a product of two spaces?
2124 * That is, is it a wrapping set space or a map space
2125 * with wrapping domain and range?
2127 isl_bool
isl_space_is_product(__isl_keep isl_space
*space
)
2130 isl_bool is_product
;
2132 is_set
= isl_space_is_set(space
);
2134 return isl_bool_error
;
2136 return isl_space_is_wrapping(space
);
2137 is_product
= isl_space_domain_is_wrapping(space
);
2138 if (is_product
< 0 || !is_product
)
2140 return isl_space_range_is_wrapping(space
);
2143 __isl_give isl_space
*isl_space_wrap(__isl_take isl_space
*dim
)
2150 wrap
= isl_space_set_alloc(dim
->ctx
,
2151 dim
->nparam
, dim
->n_in
+ dim
->n_out
);
2153 wrap
= copy_ids(wrap
, isl_dim_param
, 0, dim
, isl_dim_param
);
2154 wrap
= copy_ids(wrap
, isl_dim_set
, 0, dim
, isl_dim_in
);
2155 wrap
= copy_ids(wrap
, isl_dim_set
, dim
->n_in
, dim
, isl_dim_out
);
2160 wrap
->nested
[1] = dim
;
2164 isl_space_free(dim
);
2168 __isl_give isl_space
*isl_space_unwrap(__isl_take isl_space
*dim
)
2175 if (!isl_space_is_wrapping(dim
))
2176 isl_die(dim
->ctx
, isl_error_invalid
, "not a wrapping space",
2179 unwrap
= isl_space_copy(dim
->nested
[1]);
2180 isl_space_free(dim
);
2184 isl_space_free(dim
);
2188 isl_bool
isl_space_is_named_or_nested(__isl_keep isl_space
*space
,
2189 enum isl_dim_type type
)
2191 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
2192 return isl_bool_false
;
2194 return isl_bool_error
;
2195 if (space
->tuple_id
[type
- isl_dim_in
])
2196 return isl_bool_true
;
2197 if (space
->nested
[type
- isl_dim_in
])
2198 return isl_bool_true
;
2199 return isl_bool_false
;
2202 isl_bool
isl_space_may_be_set(__isl_keep isl_space
*space
)
2207 return isl_bool_error
;
2208 if (isl_space_is_set(space
))
2209 return isl_bool_true
;
2210 if (isl_space_dim(space
, isl_dim_in
) != 0)
2211 return isl_bool_false
;
2212 nested
= isl_space_is_named_or_nested(space
, isl_dim_in
);
2213 if (nested
< 0 || nested
)
2214 return isl_bool_not(nested
);
2215 return isl_bool_true
;
2218 __isl_give isl_space
*isl_space_reset(__isl_take isl_space
*dim
,
2219 enum isl_dim_type type
)
2221 if (!isl_space_is_named_or_nested(dim
, type
))
2224 dim
= isl_space_cow(dim
);
2228 isl_id_free(dim
->tuple_id
[type
- isl_dim_in
]);
2229 dim
->tuple_id
[type
- isl_dim_in
] = NULL
;
2230 isl_space_free(dim
->nested
[type
- isl_dim_in
]);
2231 dim
->nested
[type
- isl_dim_in
] = NULL
;
2236 __isl_give isl_space
*isl_space_flatten(__isl_take isl_space
*dim
)
2240 if (!dim
->nested
[0] && !dim
->nested
[1])
2244 dim
= isl_space_reset(dim
, isl_dim_in
);
2245 if (dim
&& dim
->nested
[1])
2246 dim
= isl_space_reset(dim
, isl_dim_out
);
2251 __isl_give isl_space
*isl_space_flatten_domain(__isl_take isl_space
*dim
)
2255 if (!dim
->nested
[0])
2258 return isl_space_reset(dim
, isl_dim_in
);
2261 __isl_give isl_space
*isl_space_flatten_range(__isl_take isl_space
*dim
)
2265 if (!dim
->nested
[1])
2268 return isl_space_reset(dim
, isl_dim_out
);
2271 /* Replace the dimensions of the given type of dst by those of src.
2273 __isl_give isl_space
*isl_space_replace(__isl_take isl_space
*dst
,
2274 enum isl_dim_type type
, __isl_keep isl_space
*src
)
2276 dst
= isl_space_cow(dst
);
2281 dst
= isl_space_drop_dims(dst
, type
, 0, isl_space_dim(dst
, type
));
2282 dst
= isl_space_add_dims(dst
, type
, isl_space_dim(src
, type
));
2283 dst
= copy_ids(dst
, type
, 0, src
, type
);
2285 if (dst
&& type
== isl_dim_param
) {
2287 for (i
= 0; i
<= 1; ++i
) {
2288 if (!dst
->nested
[i
])
2290 dst
->nested
[i
] = isl_space_replace(dst
->nested
[i
],
2292 if (!dst
->nested
[i
])
2299 isl_space_free(dst
);
2303 /* Given a dimension specification "dim" of a set, create a dimension
2304 * specification for the lift of the set. In particular, the result
2305 * is of the form [dim -> local[..]], with n_local variables in the
2306 * range of the wrapped map.
2308 __isl_give isl_space
*isl_space_lift(__isl_take isl_space
*dim
, unsigned n_local
)
2310 isl_space
*local_dim
;
2315 local_dim
= isl_space_dup(dim
);
2316 local_dim
= isl_space_drop_dims(local_dim
, isl_dim_set
, 0, dim
->n_out
);
2317 local_dim
= isl_space_add_dims(local_dim
, isl_dim_set
, n_local
);
2318 local_dim
= isl_space_set_tuple_name(local_dim
, isl_dim_set
, "local");
2319 dim
= isl_space_join(isl_space_from_domain(dim
),
2320 isl_space_from_range(local_dim
));
2321 dim
= isl_space_wrap(dim
);
2322 dim
= isl_space_set_tuple_name(dim
, isl_dim_set
, "lifted");
2327 isl_bool
isl_space_can_zip(__isl_keep isl_space
*space
)
2331 is_set
= isl_space_is_set(space
);
2333 return isl_bool_error
;
2335 return isl_bool_false
;
2336 return isl_space_is_product(space
);
2339 __isl_give isl_space
*isl_space_zip(__isl_take isl_space
*dim
)
2341 isl_space
*dom
, *ran
;
2342 isl_space
*dom_dom
, *dom_ran
, *ran_dom
, *ran_ran
;
2344 if (!isl_space_can_zip(dim
))
2345 isl_die(dim
->ctx
, isl_error_invalid
, "dim cannot be zipped",
2350 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(dim
)));
2351 ran
= isl_space_unwrap(isl_space_range(dim
));
2352 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2353 dom_ran
= isl_space_range(dom
);
2354 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2355 ran_ran
= isl_space_range(ran
);
2356 dom
= isl_space_join(isl_space_from_domain(dom_dom
),
2357 isl_space_from_range(ran_dom
));
2358 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2359 isl_space_from_range(ran_ran
));
2360 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2361 isl_space_from_range(isl_space_wrap(ran
)));
2363 isl_space_free(dim
);
2367 /* Can we apply isl_space_curry to "space"?
2368 * That is, does it have a nested relation in its domain?
2370 isl_bool
isl_space_can_curry(__isl_keep isl_space
*space
)
2373 return isl_bool_error
;
2375 return !!space
->nested
[0];
2378 /* Given a space (A -> B) -> C, return the corresponding space
2381 __isl_give isl_space
*isl_space_curry(__isl_take isl_space
*space
)
2383 isl_space
*dom
, *ran
;
2384 isl_space
*dom_dom
, *dom_ran
;
2389 if (!isl_space_can_curry(space
))
2390 isl_die(space
->ctx
, isl_error_invalid
,
2391 "space cannot be curried", goto error
);
2393 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(space
)));
2394 ran
= isl_space_range(space
);
2395 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2396 dom_ran
= isl_space_range(dom
);
2397 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2398 isl_space_from_range(ran
));
2399 return isl_space_join(isl_space_from_domain(dom_dom
),
2400 isl_space_from_range(isl_space_wrap(ran
)));
2402 isl_space_free(space
);
2406 /* Can isl_space_range_curry be applied to "space"?
2407 * That is, does it have a nested relation in its range,
2408 * the domain of which is itself a nested relation?
2410 isl_bool
isl_space_can_range_curry(__isl_keep isl_space
*space
)
2415 return isl_bool_error
;
2416 can
= isl_space_range_is_wrapping(space
);
2417 if (can
< 0 || !can
)
2419 return isl_space_can_curry(space
->nested
[1]);
2422 /* Given a space A -> ((B -> C) -> D), return the corresponding space
2423 * A -> (B -> (C -> D)).
2425 __isl_give isl_space
*isl_space_range_curry(__isl_take isl_space
*space
)
2430 if (!isl_space_can_range_curry(space
))
2431 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2432 "space range cannot be curried",
2433 return isl_space_free(space
));
2435 space
= isl_space_cow(space
);
2438 space
->nested
[1] = isl_space_curry(space
->nested
[1]);
2439 if (!space
->nested
[1])
2440 return isl_space_free(space
);
2445 /* Can we apply isl_space_uncurry to "space"?
2446 * That is, does it have a nested relation in its range?
2448 isl_bool
isl_space_can_uncurry(__isl_keep isl_space
*space
)
2451 return isl_bool_error
;
2453 return !!space
->nested
[1];
2456 /* Given a space A -> (B -> C), return the corresponding space
2459 __isl_give isl_space
*isl_space_uncurry(__isl_take isl_space
*space
)
2461 isl_space
*dom
, *ran
;
2462 isl_space
*ran_dom
, *ran_ran
;
2467 if (!isl_space_can_uncurry(space
))
2468 isl_die(space
->ctx
, isl_error_invalid
,
2469 "space cannot be uncurried",
2470 return isl_space_free(space
));
2472 dom
= isl_space_domain(isl_space_copy(space
));
2473 ran
= isl_space_unwrap(isl_space_range(space
));
2474 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2475 ran_ran
= isl_space_range(ran
);
2476 dom
= isl_space_join(isl_space_from_domain(dom
),
2477 isl_space_from_range(ran_dom
));
2478 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2479 isl_space_from_range(ran_ran
));
2482 isl_bool
isl_space_has_named_params(__isl_keep isl_space
*space
)
2488 return isl_bool_error
;
2489 if (space
->nparam
== 0)
2490 return isl_bool_true
;
2491 off
= isl_space_offset(space
, isl_dim_param
);
2492 if (off
+ space
->nparam
> space
->n_id
)
2493 return isl_bool_false
;
2494 for (i
= 0; i
< space
->nparam
; ++i
)
2495 if (!space
->ids
[off
+ i
])
2496 return isl_bool_false
;
2497 return isl_bool_true
;
2500 /* Check that "space" has only named parameters, reporting an error
2503 isl_stat
isl_space_check_named_params(__isl_keep isl_space
*space
)
2507 named
= isl_space_has_named_params(space
);
2509 return isl_stat_error
;
2511 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2512 "unaligned unnamed parameters", return isl_stat_error
);
2517 /* Align the initial parameters of dim1 to match the order in dim2.
2519 __isl_give isl_space
*isl_space_align_params(__isl_take isl_space
*dim1
,
2520 __isl_take isl_space
*dim2
)
2522 isl_reordering
*exp
;
2524 if (!isl_space_has_named_params(dim1
) || !isl_space_has_named_params(dim2
))
2525 isl_die(isl_space_get_ctx(dim1
), isl_error_invalid
,
2526 "parameter alignment requires named parameters",
2529 dim2
= isl_space_params(dim2
);
2530 exp
= isl_parameter_alignment_reordering(dim1
, dim2
);
2531 exp
= isl_reordering_extend_space(exp
, dim1
);
2532 isl_space_free(dim2
);
2535 dim1
= isl_space_copy(exp
->dim
);
2536 isl_reordering_free(exp
);
2539 isl_space_free(dim1
);
2540 isl_space_free(dim2
);
2544 /* Given the space of set (domain), construct a space for a map
2545 * with as domain the given space and as range the range of "model".
2547 __isl_give isl_space
*isl_space_extend_domain_with_range(
2548 __isl_take isl_space
*space
, __isl_take isl_space
*model
)
2553 space
= isl_space_from_domain(space
);
2554 space
= isl_space_add_dims(space
, isl_dim_out
,
2555 isl_space_dim(model
, isl_dim_out
));
2556 if (isl_space_has_tuple_id(model
, isl_dim_out
))
2557 space
= isl_space_set_tuple_id(space
, isl_dim_out
,
2558 isl_space_get_tuple_id(model
, isl_dim_out
));
2561 if (model
->nested
[1]) {
2562 isl_space
*nested
= isl_space_copy(model
->nested
[1]);
2563 int n_nested
, n_space
;
2564 nested
= isl_space_align_params(nested
, isl_space_copy(space
));
2565 n_nested
= isl_space_dim(nested
, isl_dim_param
);
2566 n_space
= isl_space_dim(space
, isl_dim_param
);
2567 if (n_nested
> n_space
)
2568 nested
= isl_space_drop_dims(nested
, isl_dim_param
,
2569 n_space
, n_nested
- n_space
);
2572 space
->nested
[1] = nested
;
2574 isl_space_free(model
);
2577 isl_space_free(model
);
2578 isl_space_free(space
);
2582 /* Compare the "type" dimensions of two isl_spaces.
2584 * The order is fairly arbitrary.
2586 static int isl_space_cmp_type(__isl_keep isl_space
*space1
,
2587 __isl_keep isl_space
*space2
, enum isl_dim_type type
)
2590 isl_space
*nested1
, *nested2
;
2592 if (isl_space_dim(space1
, type
) != isl_space_dim(space2
, type
))
2593 return isl_space_dim(space1
, type
) -
2594 isl_space_dim(space2
, type
);
2596 cmp
= isl_id_cmp(tuple_id(space1
, type
), tuple_id(space2
, type
));
2600 nested1
= nested(space1
, type
);
2601 nested2
= nested(space2
, type
);
2602 if (!nested1
!= !nested2
)
2603 return !nested1
- !nested2
;
2606 return isl_space_cmp(nested1
, nested2
);
2611 /* Compare two isl_spaces.
2613 * The order is fairly arbitrary.
2615 int isl_space_cmp(__isl_keep isl_space
*space1
, __isl_keep isl_space
*space2
)
2620 if (space1
== space2
)
2627 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_param
);
2630 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_in
);
2633 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_out
);
2637 if (!space1
->ids
&& !space2
->ids
)
2640 for (i
= 0; i
< n(space1
, isl_dim_param
); ++i
) {
2641 cmp
= isl_id_cmp(get_id(space1
, isl_dim_param
, i
),
2642 get_id(space2
, isl_dim_param
, i
));