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>
21 isl_ctx
*isl_space_get_ctx(__isl_keep isl_space
*space
)
23 return space
? space
->ctx
: NULL
;
26 __isl_give isl_space
*isl_space_alloc(isl_ctx
*ctx
,
27 unsigned nparam
, unsigned n_in
, unsigned n_out
)
31 space
= isl_alloc_type(ctx
, struct isl_space
);
38 space
->nparam
= nparam
;
42 space
->tuple_id
[0] = NULL
;
43 space
->tuple_id
[1] = NULL
;
45 space
->nested
[0] = NULL
;
46 space
->nested
[1] = NULL
;
54 /* Mark the space as being that of a set, by setting the domain tuple
57 static __isl_give isl_space
*mark_as_set(__isl_take isl_space
*space
)
59 space
= isl_space_cow(space
);
62 space
= isl_space_set_tuple_id(space
, isl_dim_in
, &isl_id_none
);
66 /* Is the space that of a set?
68 isl_bool
isl_space_is_set(__isl_keep isl_space
*space
)
71 return isl_bool_error
;
72 if (space
->n_in
!= 0 || space
->nested
[0])
73 return isl_bool_false
;
74 if (space
->tuple_id
[0] != &isl_id_none
)
75 return isl_bool_false
;
79 /* Check that "space" is a set space.
81 isl_stat
isl_space_check_is_set(__isl_keep isl_space
*space
)
85 is_set
= isl_space_is_set(space
);
87 return isl_stat_error
;
89 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
90 "space is not a set", return isl_stat_error
);
94 /* Is the given space that of a map?
96 isl_bool
isl_space_is_map(__isl_keep isl_space
*space
)
99 return isl_bool_error
;
100 return space
->tuple_id
[0] != &isl_id_none
&&
101 space
->tuple_id
[1] != &isl_id_none
;
104 __isl_give isl_space
*isl_space_set_alloc(isl_ctx
*ctx
,
105 unsigned nparam
, unsigned dim
)
108 space
= isl_space_alloc(ctx
, nparam
, 0, dim
);
109 space
= mark_as_set(space
);
113 /* Mark the space as being that of a parameter domain, by setting
114 * both tuples to isl_id_none.
116 static __isl_give isl_space
*mark_as_params(isl_space
*space
)
120 space
= isl_space_set_tuple_id(space
, isl_dim_in
, &isl_id_none
);
121 space
= isl_space_set_tuple_id(space
, isl_dim_out
, &isl_id_none
);
125 /* Is the space that of a parameter domain?
127 isl_bool
isl_space_is_params(__isl_keep isl_space
*space
)
130 return isl_bool_error
;
131 if (space
->n_in
!= 0 || space
->nested
[0] ||
132 space
->n_out
!= 0 || space
->nested
[1])
133 return isl_bool_false
;
134 if (space
->tuple_id
[0] != &isl_id_none
)
135 return isl_bool_false
;
136 if (space
->tuple_id
[1] != &isl_id_none
)
137 return isl_bool_false
;
138 return isl_bool_true
;
141 /* Create a space for a parameter domain.
143 __isl_give isl_space
*isl_space_params_alloc(isl_ctx
*ctx
, unsigned nparam
)
146 space
= isl_space_alloc(ctx
, nparam
, 0, 0);
147 space
= mark_as_params(space
);
151 static int global_pos(__isl_keep isl_space
*space
,
152 enum isl_dim_type type
, unsigned pos
)
154 if (isl_space_check_range(space
, type
, pos
, 1) < 0)
161 return pos
+ space
->nparam
;
163 return pos
+ space
->nparam
+ space
->n_in
;
165 isl_assert(isl_space_get_ctx(space
), 0, return -1);
170 /* Extend length of ids array to the total number of dimensions.
172 static __isl_give isl_space
*extend_ids(__isl_take isl_space
*space
)
177 if (isl_space_dim(space
, isl_dim_all
) <= space
->n_id
)
181 space
->ids
= isl_calloc_array(space
->ctx
,
182 isl_id
*, isl_space_dim(space
, isl_dim_all
));
186 ids
= isl_realloc_array(space
->ctx
, space
->ids
,
187 isl_id
*, isl_space_dim(space
, isl_dim_all
));
191 for (i
= space
->n_id
; i
< isl_space_dim(space
, isl_dim_all
); ++i
)
192 space
->ids
[i
] = NULL
;
195 space
->n_id
= isl_space_dim(space
, isl_dim_all
);
199 isl_space_free(space
);
203 static __isl_give isl_space
*set_id(__isl_take isl_space
*space
,
204 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
208 space
= isl_space_cow(space
);
210 gpos
= global_pos(space
, type
, pos
);
214 if (gpos
>= space
->n_id
) {
217 space
= extend_ids(space
);
222 space
->ids
[gpos
] = id
;
227 isl_space_free(space
);
231 static __isl_keep isl_id
*get_id(__isl_keep isl_space
*space
,
232 enum isl_dim_type type
, unsigned pos
)
236 gpos
= global_pos(space
, type
, pos
);
239 if (gpos
>= space
->n_id
)
241 return space
->ids
[gpos
];
244 static unsigned offset(__isl_keep isl_space
*space
, enum isl_dim_type type
)
247 case isl_dim_param
: return 0;
248 case isl_dim_in
: return space
->nparam
;
249 case isl_dim_out
: return space
->nparam
+ space
->n_in
;
254 static unsigned n(__isl_keep isl_space
*space
, enum isl_dim_type type
)
257 case isl_dim_param
: return space
->nparam
;
258 case isl_dim_in
: return space
->n_in
;
259 case isl_dim_out
: return space
->n_out
;
261 return space
->nparam
+ space
->n_in
+ space
->n_out
;
266 unsigned isl_space_dim(__isl_keep isl_space
*space
, enum isl_dim_type type
)
270 return n(space
, type
);
273 unsigned isl_space_offset(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
277 return offset(dim
, type
);
280 static __isl_give isl_space
*copy_ids(__isl_take isl_space
*dst
,
281 enum isl_dim_type dst_type
, unsigned offset
, __isl_keep isl_space
*src
,
282 enum isl_dim_type src_type
)
290 for (i
= 0; i
< n(src
, src_type
); ++i
) {
291 id
= get_id(src
, src_type
, i
);
294 dst
= set_id(dst
, dst_type
, offset
+ i
, isl_id_copy(id
));
301 __isl_take isl_space
*isl_space_dup(__isl_keep isl_space
*space
)
306 dup
= isl_space_alloc(space
->ctx
,
307 space
->nparam
, space
->n_in
, space
->n_out
);
310 if (space
->tuple_id
[0] &&
311 !(dup
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[0])))
313 if (space
->tuple_id
[1] &&
314 !(dup
->tuple_id
[1] = isl_id_copy(space
->tuple_id
[1])))
316 if (space
->nested
[0] &&
317 !(dup
->nested
[0] = isl_space_copy(space
->nested
[0])))
319 if (space
->nested
[1] &&
320 !(dup
->nested
[1] = isl_space_copy(space
->nested
[1])))
324 dup
= copy_ids(dup
, isl_dim_param
, 0, space
, isl_dim_param
);
325 dup
= copy_ids(dup
, isl_dim_in
, 0, space
, isl_dim_in
);
326 dup
= copy_ids(dup
, isl_dim_out
, 0, space
, isl_dim_out
);
333 __isl_give isl_space
*isl_space_cow(__isl_take isl_space
*space
)
341 return isl_space_dup(space
);
344 __isl_give isl_space
*isl_space_copy(__isl_keep isl_space
*dim
)
353 __isl_null isl_space
*isl_space_free(__isl_take isl_space
*space
)
360 if (--space
->ref
> 0)
363 isl_id_free(space
->tuple_id
[0]);
364 isl_id_free(space
->tuple_id
[1]);
366 isl_space_free(space
->nested
[0]);
367 isl_space_free(space
->nested
[1]);
369 for (i
= 0; i
< space
->n_id
; ++i
)
370 isl_id_free(space
->ids
[i
]);
372 isl_ctx_deref(space
->ctx
);
379 /* Check if "s" is a valid dimension or tuple name.
380 * We currently only forbid names that look like a number.
382 * s is assumed to be non-NULL.
384 static int name_ok(isl_ctx
*ctx
, const char *s
)
389 dummy
= strtol(s
, &p
, 0);
391 isl_die(ctx
, isl_error_invalid
, "name looks like a number",
397 /* Is it possible for the given dimension type to have a tuple id?
399 static int space_can_have_id(__isl_keep isl_space
*space
,
400 enum isl_dim_type type
)
404 if (isl_space_is_params(space
))
405 isl_die(space
->ctx
, isl_error_invalid
,
406 "parameter spaces don't have tuple ids", return 0);
407 if (isl_space_is_set(space
) && type
!= isl_dim_set
)
408 isl_die(space
->ctx
, isl_error_invalid
,
409 "set spaces can only have a set id", return 0);
410 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
411 isl_die(space
->ctx
, isl_error_invalid
,
412 "only input, output and set tuples can have ids",
418 /* Does the tuple have an id?
420 isl_bool
isl_space_has_tuple_id(__isl_keep isl_space
*space
,
421 enum isl_dim_type type
)
423 if (!space_can_have_id(space
, type
))
424 return isl_bool_error
;
425 return space
->tuple_id
[type
- isl_dim_in
] != NULL
;
428 __isl_give isl_id
*isl_space_get_tuple_id(__isl_keep isl_space
*space
,
429 enum isl_dim_type type
)
435 has_id
= isl_space_has_tuple_id(space
, type
);
439 isl_die(space
->ctx
, isl_error_invalid
,
440 "tuple has no id", return NULL
);
441 return isl_id_copy(space
->tuple_id
[type
- isl_dim_in
]);
444 __isl_give isl_space
*isl_space_set_tuple_id(__isl_take isl_space
*space
,
445 enum isl_dim_type type
, __isl_take isl_id
*id
)
447 space
= isl_space_cow(space
);
450 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
451 isl_die(space
->ctx
, isl_error_invalid
,
452 "only input, output and set tuples can have names",
455 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
456 space
->tuple_id
[type
- isl_dim_in
] = id
;
461 isl_space_free(space
);
465 __isl_give isl_space
*isl_space_reset_tuple_id(__isl_take isl_space
*space
,
466 enum isl_dim_type type
)
468 space
= isl_space_cow(space
);
471 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
472 isl_die(space
->ctx
, isl_error_invalid
,
473 "only input, output and set tuples can have names",
476 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
477 space
->tuple_id
[type
- isl_dim_in
] = NULL
;
481 isl_space_free(space
);
485 /* Set the id of the given dimension of "space" to "id".
486 * If the dimension already has an id, then it is replaced.
487 * If the dimension is a parameter, then we need to change it
488 * in the nested spaces (if any) as well.
490 __isl_give isl_space
*isl_space_set_dim_id(__isl_take isl_space
*space
,
491 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
493 space
= isl_space_cow(space
);
497 if (type
== isl_dim_param
) {
500 for (i
= 0; i
< 2; ++i
) {
501 if (!space
->nested
[i
])
504 isl_space_set_dim_id(space
->nested
[i
],
505 type
, pos
, isl_id_copy(id
));
506 if (!space
->nested
[i
])
511 isl_id_free(get_id(space
, type
, pos
));
512 return set_id(space
, type
, pos
, id
);
515 isl_space_free(space
);
519 /* Reset the id of the given dimension of "space".
520 * If the dimension already has an id, then it is removed.
521 * If the dimension is a parameter, then we need to reset it
522 * in the nested spaces (if any) as well.
524 __isl_give isl_space
*isl_space_reset_dim_id(__isl_take isl_space
*space
,
525 enum isl_dim_type type
, unsigned pos
)
527 space
= isl_space_cow(space
);
531 if (type
== isl_dim_param
) {
534 for (i
= 0; i
< 2; ++i
) {
535 if (!space
->nested
[i
])
538 isl_space_reset_dim_id(space
->nested
[i
],
540 if (!space
->nested
[i
])
545 isl_id_free(get_id(space
, type
, pos
));
546 return set_id(space
, type
, pos
, NULL
);
548 isl_space_free(space
);
552 isl_bool
isl_space_has_dim_id(__isl_keep isl_space
*space
,
553 enum isl_dim_type type
, unsigned pos
)
556 return isl_bool_error
;
557 return get_id(space
, type
, pos
) != NULL
;
560 __isl_give isl_id
*isl_space_get_dim_id(__isl_keep isl_space
*space
,
561 enum isl_dim_type type
, unsigned pos
)
565 if (!get_id(space
, type
, pos
))
566 isl_die(space
->ctx
, isl_error_invalid
,
567 "dim has no id", return NULL
);
568 return isl_id_copy(get_id(space
, type
, pos
));
571 __isl_give isl_space
*isl_space_set_tuple_name(__isl_take isl_space
*space
,
572 enum isl_dim_type type
, const char *s
)
580 return isl_space_reset_tuple_id(space
, type
);
582 if (!name_ok(space
->ctx
, s
))
585 id
= isl_id_alloc(space
->ctx
, s
, NULL
);
586 return isl_space_set_tuple_id(space
, type
, id
);
588 isl_space_free(space
);
592 /* Does the tuple have a name?
594 isl_bool
isl_space_has_tuple_name(__isl_keep isl_space
*space
,
595 enum isl_dim_type type
)
599 if (!space_can_have_id(space
, type
))
600 return isl_bool_error
;
601 id
= space
->tuple_id
[type
- isl_dim_in
];
602 return id
&& id
->name
;
605 __isl_keep
const char *isl_space_get_tuple_name(__isl_keep isl_space
*space
,
606 enum isl_dim_type type
)
611 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
613 id
= space
->tuple_id
[type
- isl_dim_in
];
614 return id
? id
->name
: NULL
;
617 __isl_give isl_space
*isl_space_set_dim_name(__isl_take isl_space
*space
,
618 enum isl_dim_type type
, unsigned pos
,
626 return isl_space_reset_dim_id(space
, type
, pos
);
627 if (!name_ok(space
->ctx
, s
))
629 id
= isl_id_alloc(space
->ctx
, s
, NULL
);
630 return isl_space_set_dim_id(space
, type
, pos
, id
);
632 isl_space_free(space
);
636 /* Does the given dimension have a name?
638 isl_bool
isl_space_has_dim_name(__isl_keep isl_space
*space
,
639 enum isl_dim_type type
, unsigned pos
)
644 return isl_bool_error
;
645 id
= get_id(space
, type
, pos
);
646 return id
&& id
->name
;
649 __isl_keep
const char *isl_space_get_dim_name(__isl_keep isl_space
*space
,
650 enum isl_dim_type type
, unsigned pos
)
652 isl_id
*id
= get_id(space
, type
, pos
);
653 return id
? id
->name
: NULL
;
656 int isl_space_find_dim_by_id(__isl_keep isl_space
*space
,
657 enum isl_dim_type type
, __isl_keep isl_id
*id
)
666 offset
= isl_space_offset(space
, type
);
667 n
= isl_space_dim(space
, type
);
668 for (i
= 0; i
< n
&& offset
+ i
< space
->n_id
; ++i
)
669 if (space
->ids
[offset
+ i
] == id
)
675 int isl_space_find_dim_by_name(__isl_keep isl_space
*space
,
676 enum isl_dim_type type
, const char *name
)
685 offset
= isl_space_offset(space
, type
);
686 n
= isl_space_dim(space
, type
);
687 for (i
= 0; i
< n
&& offset
+ i
< space
->n_id
; ++i
) {
688 isl_id
*id
= get_id(space
, type
, i
);
689 if (id
&& id
->name
&& !strcmp(id
->name
, name
))
696 /* Reset the user pointer on all identifiers of parameters and tuples
699 __isl_give isl_space
*isl_space_reset_user(__isl_take isl_space
*space
)
709 ctx
= isl_space_get_ctx(space
);
711 for (i
= 0; i
< space
->nparam
&& i
< space
->n_id
; ++i
) {
712 if (!isl_id_get_user(space
->ids
[i
]))
714 space
= isl_space_cow(space
);
717 name
= isl_id_get_name(space
->ids
[i
]);
718 id
= isl_id_alloc(ctx
, name
, NULL
);
719 isl_id_free(space
->ids
[i
]);
722 return isl_space_free(space
);
725 for (i
= 0; i
< 2; ++i
) {
726 if (!space
->tuple_id
[i
])
728 if (!isl_id_get_user(space
->tuple_id
[i
]))
730 space
= isl_space_cow(space
);
733 name
= isl_id_get_name(space
->tuple_id
[i
]);
734 id
= isl_id_alloc(ctx
, name
, NULL
);
735 isl_id_free(space
->tuple_id
[i
]);
736 space
->tuple_id
[i
] = id
;
738 return isl_space_free(space
);
741 for (i
= 0; i
< 2; ++i
) {
742 if (!space
->nested
[i
])
744 space
= isl_space_cow(space
);
747 space
->nested
[i
] = isl_space_reset_user(space
->nested
[i
]);
748 if (!space
->nested
[i
])
749 return isl_space_free(space
);
755 static __isl_keep isl_id
*tuple_id(__isl_keep isl_space
*dim
,
756 enum isl_dim_type type
)
760 if (type
== isl_dim_in
)
761 return dim
->tuple_id
[0];
762 if (type
== isl_dim_out
)
763 return dim
->tuple_id
[1];
767 static __isl_keep isl_space
*nested(__isl_keep isl_space
*dim
,
768 enum isl_dim_type type
)
772 if (type
== isl_dim_in
)
773 return dim
->nested
[0];
774 if (type
== isl_dim_out
)
775 return dim
->nested
[1];
779 /* Are the two spaces the same, apart from positions and names of parameters?
781 isl_bool
isl_space_has_equal_tuples(__isl_keep isl_space
*space1
,
782 __isl_keep isl_space
*space2
)
784 if (!space1
|| !space2
)
785 return isl_bool_error
;
786 if (space1
== space2
)
787 return isl_bool_true
;
788 return isl_space_tuple_is_equal(space1
, isl_dim_in
,
789 space2
, isl_dim_in
) &&
790 isl_space_tuple_is_equal(space1
, isl_dim_out
,
791 space2
, isl_dim_out
);
794 /* Check if the tuple of type "type1" of "space1" is the same as
795 * the tuple of type "type2" of "space2".
797 * That is, check if the tuples have the same identifier, the same dimension
798 * and the same internal structure.
799 * The identifiers of the dimensions inside the tuples do not affect the result.
801 * Note that this function only checks the tuples themselves.
802 * If nested tuples are involved, then we need to be careful not
803 * to have result affected by possibly differing parameters
804 * in those nested tuples.
806 isl_bool
isl_space_tuple_is_equal(__isl_keep isl_space
*space1
,
807 enum isl_dim_type type1
, __isl_keep isl_space
*space2
,
808 enum isl_dim_type type2
)
811 isl_space
*nested1
, *nested2
;
813 if (!space1
|| !space2
)
814 return isl_bool_error
;
816 if (space1
== space2
&& type1
== type2
)
817 return isl_bool_true
;
819 if (n(space1
, type1
) != n(space2
, type2
))
820 return isl_bool_false
;
821 id1
= tuple_id(space1
, type1
);
822 id2
= tuple_id(space2
, type2
);
824 return isl_bool_false
;
825 if (id1
&& id1
!= id2
)
826 return isl_bool_false
;
827 nested1
= nested(space1
, type1
);
828 nested2
= nested(space2
, type2
);
829 if (!nested1
^ !nested2
)
830 return isl_bool_false
;
831 if (nested1
&& !isl_space_has_equal_tuples(nested1
, nested2
))
832 return isl_bool_false
;
833 return isl_bool_true
;
836 static isl_bool
match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
837 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
841 if (space1
== space2
&& type1
== type2
)
842 return isl_bool_true
;
844 if (!isl_space_tuple_is_equal(space1
, type1
, space2
, type2
))
845 return isl_bool_false
;
847 if (!space1
->ids
&& !space2
->ids
)
848 return isl_bool_true
;
850 for (i
= 0; i
< n(space1
, type1
); ++i
) {
851 if (get_id(space1
, type1
, i
) != get_id(space2
, type2
, i
))
852 return isl_bool_false
;
854 return isl_bool_true
;
857 /* Do "space1" and "space2" have the same parameters?
859 isl_bool
isl_space_has_equal_params(__isl_keep isl_space
*space1
,
860 __isl_keep isl_space
*space2
)
862 if (!space1
|| !space2
)
863 return isl_bool_error
;
865 return match(space1
, isl_dim_param
, space2
, isl_dim_param
);
868 /* Do "space1" and "space2" have the same identifiers for all
869 * the tuple variables?
871 isl_bool
isl_space_has_equal_ids(__isl_keep isl_space
*space1
,
872 __isl_keep isl_space
*space2
)
876 if (!space1
|| !space2
)
877 return isl_bool_error
;
879 equal
= match(space1
, isl_dim_in
, space2
, isl_dim_in
);
880 if (equal
< 0 || !equal
)
882 return match(space1
, isl_dim_out
, space2
, isl_dim_out
);
885 isl_bool
isl_space_match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
886 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
888 if (!space1
|| !space2
)
889 return isl_bool_error
;
891 return match(space1
, type1
, space2
, type2
);
894 static void get_ids(__isl_keep isl_space
*dim
, enum isl_dim_type type
,
895 unsigned first
, unsigned n
, __isl_keep isl_id
**ids
)
899 for (i
= 0; i
< n
; ++i
)
900 ids
[i
] = get_id(dim
, type
, first
+ i
);
903 static __isl_give isl_space
*space_extend(__isl_take isl_space
*space
,
904 unsigned nparam
, unsigned n_in
, unsigned n_out
)
910 if (space
->nparam
== nparam
&&
911 space
->n_in
== n_in
&& space
->n_out
== n_out
)
914 isl_assert(space
->ctx
, space
->nparam
<= nparam
, goto error
);
915 isl_assert(space
->ctx
, space
->n_in
<= n_in
, goto error
);
916 isl_assert(space
->ctx
, space
->n_out
<= n_out
, goto error
);
918 space
= isl_space_cow(space
);
924 n
= nparam
+ n_in
+ n_out
;
925 if (n
< nparam
|| n
< n_in
|| n
< n_out
)
926 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
927 "overflow in total number of dimensions",
929 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n
);
932 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
933 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
+ nparam
);
934 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
935 ids
+ nparam
+ n_in
);
938 space
->n_id
= nparam
+ n_in
+ n_out
;
940 space
->nparam
= nparam
;
942 space
->n_out
= n_out
;
947 isl_space_free(space
);
951 __isl_give isl_space
*isl_space_extend(__isl_take isl_space
*space
,
952 unsigned nparam
, unsigned n_in
, unsigned n_out
)
954 return space_extend(space
, nparam
, n_in
, n_out
);
957 __isl_give isl_space
*isl_space_add_dims(__isl_take isl_space
*space
,
958 enum isl_dim_type type
, unsigned n
)
960 space
= isl_space_reset(space
, type
);
965 space
= space_extend(space
,
966 space
->nparam
+ n
, space
->n_in
, space
->n_out
);
967 if (space
&& space
->nested
[0] &&
968 !(space
->nested
[0] = isl_space_add_dims(space
->nested
[0],
971 if (space
&& space
->nested
[1] &&
972 !(space
->nested
[1] = isl_space_add_dims(space
->nested
[1],
977 return space_extend(space
,
978 space
->nparam
, space
->n_in
+ n
, space
->n_out
);
980 return space_extend(space
,
981 space
->nparam
, space
->n_in
, space
->n_out
+ n
);
983 isl_die(space
->ctx
, isl_error_invalid
,
984 "cannot add dimensions of specified type", goto error
);
987 isl_space_free(space
);
991 /* Add a parameter with identifier "id" to "space", provided
992 * it does not already appear in "space".
994 __isl_give isl_space
*isl_space_add_param_id(__isl_take isl_space
*space
,
995 __isl_take isl_id
*id
)
1002 if (isl_space_find_dim_by_id(space
, isl_dim_param
, id
) >= 0) {
1007 pos
= isl_space_dim(space
, isl_dim_param
);
1008 space
= isl_space_add_dims(space
, isl_dim_param
, 1);
1009 space
= isl_space_set_dim_id(space
, isl_dim_param
, pos
, id
);
1013 isl_space_free(space
);
1018 static int valid_dim_type(enum isl_dim_type type
)
1031 #define TYPE isl_space
1032 #include "check_type_range_templ.c"
1034 /* Insert "n" dimensions of type "type" at position "pos".
1035 * If we are inserting parameters, then they are also inserted in
1036 * any nested spaces.
1038 __isl_give isl_space
*isl_space_insert_dims(__isl_take isl_space
*space
,
1039 enum isl_dim_type type
, unsigned pos
, unsigned n
)
1042 isl_id
**ids
= NULL
;
1047 return isl_space_reset(space
, type
);
1049 ctx
= isl_space_get_ctx(space
);
1050 if (!valid_dim_type(type
))
1051 isl_die(ctx
, isl_error_invalid
,
1052 "cannot insert dimensions of specified type",
1055 if (isl_space_check_range(space
, type
, pos
, 0) < 0)
1056 return isl_space_free(space
);
1058 space
= isl_space_cow(space
);
1063 enum isl_dim_type t
, o
= isl_dim_param
;
1066 ids
= isl_calloc_array(ctx
, isl_id
*,
1067 space
->nparam
+ space
->n_in
+ space
->n_out
+ n
);
1071 s
[isl_dim_param
- o
] = space
->nparam
;
1072 s
[isl_dim_in
- o
] = space
->n_in
;
1073 s
[isl_dim_out
- o
] = space
->n_out
;
1074 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1076 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1079 get_ids(space
, t
, 0, pos
, ids
+ off
);
1081 get_ids(space
, t
, pos
, s
[t
- o
] - pos
,
1083 off
+= s
[t
- o
] - pos
;
1088 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
+ n
;
1091 case isl_dim_param
: space
->nparam
+= n
; break;
1092 case isl_dim_in
: space
->n_in
+= n
; break;
1093 case isl_dim_out
: space
->n_out
+= n
; break;
1096 space
= isl_space_reset(space
, type
);
1098 if (type
== isl_dim_param
) {
1099 if (space
&& space
->nested
[0] &&
1100 !(space
->nested
[0] = isl_space_insert_dims(space
->nested
[0],
1101 isl_dim_param
, pos
, n
)))
1103 if (space
&& space
->nested
[1] &&
1104 !(space
->nested
[1] = isl_space_insert_dims(space
->nested
[1],
1105 isl_dim_param
, pos
, n
)))
1111 isl_space_free(space
);
1115 __isl_give isl_space
*isl_space_move_dims(__isl_take isl_space
*space
,
1116 enum isl_dim_type dst_type
, unsigned dst_pos
,
1117 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1121 space
= isl_space_reset(space
, src_type
);
1122 space
= isl_space_reset(space
, dst_type
);
1128 if (isl_space_check_range(space
, src_type
, src_pos
, n
) < 0)
1129 return isl_space_free(space
);
1131 if (dst_type
== src_type
&& dst_pos
== src_pos
)
1134 isl_assert(space
->ctx
, dst_type
!= src_type
, goto error
);
1136 space
= isl_space_cow(space
);
1142 enum isl_dim_type t
, o
= isl_dim_param
;
1145 ids
= isl_calloc_array(space
->ctx
, isl_id
*,
1146 space
->nparam
+ space
->n_in
+ space
->n_out
);
1150 s
[isl_dim_param
- o
] = space
->nparam
;
1151 s
[isl_dim_in
- o
] = space
->n_in
;
1152 s
[isl_dim_out
- o
] = space
->n_out
;
1153 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1154 if (t
== dst_type
) {
1155 get_ids(space
, t
, 0, dst_pos
, ids
+ off
);
1157 get_ids(space
, src_type
, src_pos
, n
, ids
+ off
);
1159 get_ids(space
, t
, dst_pos
, s
[t
- o
] - dst_pos
,
1161 off
+= s
[t
- o
] - dst_pos
;
1162 } else if (t
== src_type
) {
1163 get_ids(space
, t
, 0, src_pos
, ids
+ off
);
1165 get_ids(space
, t
, src_pos
+ n
,
1166 s
[t
- o
] - src_pos
- n
, ids
+ off
);
1167 off
+= s
[t
- o
] - src_pos
- n
;
1169 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1175 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
;
1179 case isl_dim_param
: space
->nparam
+= n
; break;
1180 case isl_dim_in
: space
->n_in
+= n
; break;
1181 case isl_dim_out
: space
->n_out
+= n
; break;
1186 case isl_dim_param
: space
->nparam
-= n
; break;
1187 case isl_dim_in
: space
->n_in
-= n
; break;
1188 case isl_dim_out
: space
->n_out
-= n
; break;
1192 if (dst_type
!= isl_dim_param
&& src_type
!= isl_dim_param
)
1195 for (i
= 0; i
< 2; ++i
) {
1196 if (!space
->nested
[i
])
1198 space
->nested
[i
] = isl_space_replace_params(space
->nested
[i
],
1200 if (!space
->nested
[i
])
1206 isl_space_free(space
);
1210 /* Check that "space1" and "space2" have the same parameters,
1211 * reporting an error if they do not.
1213 isl_stat
isl_space_check_equal_params(__isl_keep isl_space
*space1
,
1214 __isl_keep isl_space
*space2
)
1218 equal
= isl_space_has_equal_params(space1
, space2
);
1220 return isl_stat_error
;
1222 isl_die(isl_space_get_ctx(space1
), isl_error_invalid
,
1223 "parameters need to match", return isl_stat_error
);
1227 __isl_give isl_space
*isl_space_join(__isl_take isl_space
*left
,
1228 __isl_take isl_space
*right
)
1232 if (isl_space_check_equal_params(left
, right
) < 0)
1235 isl_assert(left
->ctx
,
1236 isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_in
),
1239 space
= isl_space_alloc(left
->ctx
,
1240 left
->nparam
, left
->n_in
, right
->n_out
);
1244 space
= copy_ids(space
, isl_dim_param
, 0, left
, isl_dim_param
);
1245 space
= copy_ids(space
, isl_dim_in
, 0, left
, isl_dim_in
);
1246 space
= copy_ids(space
, isl_dim_out
, 0, right
, isl_dim_out
);
1248 if (space
&& left
->tuple_id
[0] &&
1249 !(space
->tuple_id
[0] = isl_id_copy(left
->tuple_id
[0])))
1251 if (space
&& right
->tuple_id
[1] &&
1252 !(space
->tuple_id
[1] = isl_id_copy(right
->tuple_id
[1])))
1254 if (space
&& left
->nested
[0] &&
1255 !(space
->nested
[0] = isl_space_copy(left
->nested
[0])))
1257 if (space
&& right
->nested
[1] &&
1258 !(space
->nested
[1] = isl_space_copy(right
->nested
[1])))
1261 isl_space_free(left
);
1262 isl_space_free(right
);
1266 isl_space_free(left
);
1267 isl_space_free(right
);
1271 /* Given two map spaces { A -> C } and { B -> D }, construct the space
1272 * { [A -> B] -> [C -> D] }.
1273 * Given two set spaces { A } and { B }, construct the space { [A -> B] }.
1275 __isl_give isl_space
*isl_space_product(__isl_take isl_space
*left
,
1276 __isl_take isl_space
*right
)
1278 isl_space
*dom1
, *dom2
, *nest1
, *nest2
;
1281 if (!left
|| !right
)
1284 is_set
= isl_space_is_set(left
);
1285 if (is_set
!= isl_space_is_set(right
))
1286 isl_die(isl_space_get_ctx(left
), isl_error_invalid
,
1287 "expecting either two set spaces or two map spaces",
1290 return isl_space_range_product(left
, right
);
1292 if (isl_space_check_equal_params(left
, right
) < 0)
1295 dom1
= isl_space_domain(isl_space_copy(left
));
1296 dom2
= isl_space_domain(isl_space_copy(right
));
1297 nest1
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1299 dom1
= isl_space_range(left
);
1300 dom2
= isl_space_range(right
);
1301 nest2
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1303 return isl_space_join(isl_space_reverse(nest1
), nest2
);
1305 isl_space_free(left
);
1306 isl_space_free(right
);
1310 /* Given two spaces { A -> C } and { B -> C }, construct the space
1313 __isl_give isl_space
*isl_space_domain_product(__isl_take isl_space
*left
,
1314 __isl_take isl_space
*right
)
1316 isl_space
*ran
, *dom1
, *dom2
, *nest
;
1318 if (isl_space_check_equal_params(left
, right
) < 0)
1321 if (!isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_out
))
1322 isl_die(left
->ctx
, isl_error_invalid
,
1323 "ranges need to match", goto error
);
1325 ran
= isl_space_range(isl_space_copy(left
));
1327 dom1
= isl_space_domain(left
);
1328 dom2
= isl_space_domain(right
);
1329 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1331 return isl_space_join(isl_space_reverse(nest
), ran
);
1333 isl_space_free(left
);
1334 isl_space_free(right
);
1338 __isl_give isl_space
*isl_space_range_product(__isl_take isl_space
*left
,
1339 __isl_take isl_space
*right
)
1341 isl_space
*dom
, *ran1
, *ran2
, *nest
;
1343 if (isl_space_check_equal_params(left
, right
) < 0)
1346 if (!isl_space_tuple_is_equal(left
, isl_dim_in
, right
, isl_dim_in
))
1347 isl_die(left
->ctx
, isl_error_invalid
,
1348 "domains need to match", goto error
);
1350 dom
= isl_space_domain(isl_space_copy(left
));
1352 ran1
= isl_space_range(left
);
1353 ran2
= isl_space_range(right
);
1354 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(ran1
), ran2
));
1356 return isl_space_join(isl_space_reverse(dom
), nest
);
1358 isl_space_free(left
);
1359 isl_space_free(right
);
1363 /* Given a space of the form [A -> B] -> C, return the space A -> C.
1365 __isl_give isl_space
*isl_space_domain_factor_domain(
1366 __isl_take isl_space
*space
)
1373 if (!isl_space_domain_is_wrapping(space
))
1374 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1375 "domain not a product", return isl_space_free(space
));
1377 nested
= space
->nested
[0];
1378 domain
= isl_space_copy(space
);
1379 domain
= isl_space_drop_dims(domain
, isl_dim_in
,
1380 nested
->n_in
, nested
->n_out
);
1382 return isl_space_free(space
);
1383 if (nested
->tuple_id
[0]) {
1384 domain
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[0]);
1385 if (!domain
->tuple_id
[0])
1388 if (nested
->nested
[0]) {
1389 domain
->nested
[0] = isl_space_copy(nested
->nested
[0]);
1390 if (!domain
->nested
[0])
1394 isl_space_free(space
);
1397 isl_space_free(space
);
1398 isl_space_free(domain
);
1402 /* Given a space of the form [A -> B] -> C, return the space B -> C.
1404 __isl_give isl_space
*isl_space_domain_factor_range(
1405 __isl_take isl_space
*space
)
1412 if (!isl_space_domain_is_wrapping(space
))
1413 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1414 "domain not a product", return isl_space_free(space
));
1416 nested
= space
->nested
[0];
1417 range
= isl_space_copy(space
);
1418 range
= isl_space_drop_dims(range
, isl_dim_in
, 0, nested
->n_in
);
1420 return isl_space_free(space
);
1421 if (nested
->tuple_id
[1]) {
1422 range
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[1]);
1423 if (!range
->tuple_id
[0])
1426 if (nested
->nested
[1]) {
1427 range
->nested
[0] = isl_space_copy(nested
->nested
[1]);
1428 if (!range
->nested
[0])
1432 isl_space_free(space
);
1435 isl_space_free(space
);
1436 isl_space_free(range
);
1440 /* Internal function that selects the domain of the map that is
1441 * embedded in either a set space or the range of a map space.
1442 * In particular, given a space of the form [A -> B], return the space A.
1443 * Given a space of the form A -> [B -> C], return the space A -> B.
1445 static __isl_give isl_space
*range_factor_domain(__isl_take isl_space
*space
)
1453 nested
= space
->nested
[1];
1454 domain
= isl_space_copy(space
);
1455 domain
= isl_space_drop_dims(domain
, isl_dim_out
,
1456 nested
->n_in
, nested
->n_out
);
1458 return isl_space_free(space
);
1459 if (nested
->tuple_id
[0]) {
1460 domain
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[0]);
1461 if (!domain
->tuple_id
[1])
1464 if (nested
->nested
[0]) {
1465 domain
->nested
[1] = isl_space_copy(nested
->nested
[0]);
1466 if (!domain
->nested
[1])
1470 isl_space_free(space
);
1473 isl_space_free(space
);
1474 isl_space_free(domain
);
1478 /* Given a space of the form A -> [B -> C], return the space A -> B.
1480 __isl_give isl_space
*isl_space_range_factor_domain(
1481 __isl_take isl_space
*space
)
1485 if (!isl_space_range_is_wrapping(space
))
1486 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1487 "range not a product", return isl_space_free(space
));
1489 return range_factor_domain(space
);
1492 /* Given a space of the form [A -> B], return the space A.
1494 static __isl_give isl_space
*set_factor_domain(__isl_take isl_space
*space
)
1498 if (!isl_space_is_wrapping(space
))
1499 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1500 "not a product", return isl_space_free(space
));
1502 return range_factor_domain(space
);
1505 /* Given a space of the form [A -> B] -> [C -> D], return the space A -> C.
1506 * Given a space of the form [A -> B], return the space A.
1508 __isl_give isl_space
*isl_space_factor_domain(__isl_take isl_space
*space
)
1512 if (isl_space_is_set(space
))
1513 return set_factor_domain(space
);
1514 space
= isl_space_domain_factor_domain(space
);
1515 space
= isl_space_range_factor_domain(space
);
1519 /* Internal function that selects the range of the map that is
1520 * embedded in either a set space or the range of a map space.
1521 * In particular, given a space of the form [A -> B], return the space B.
1522 * Given a space of the form A -> [B -> C], return the space A -> C.
1524 static __isl_give isl_space
*range_factor_range(__isl_take isl_space
*space
)
1532 nested
= space
->nested
[1];
1533 range
= isl_space_copy(space
);
1534 range
= isl_space_drop_dims(range
, isl_dim_out
, 0, nested
->n_in
);
1536 return isl_space_free(space
);
1537 if (nested
->tuple_id
[1]) {
1538 range
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[1]);
1539 if (!range
->tuple_id
[1])
1542 if (nested
->nested
[1]) {
1543 range
->nested
[1] = isl_space_copy(nested
->nested
[1]);
1544 if (!range
->nested
[1])
1548 isl_space_free(space
);
1551 isl_space_free(space
);
1552 isl_space_free(range
);
1556 /* Given a space of the form A -> [B -> C], return the space A -> C.
1558 __isl_give isl_space
*isl_space_range_factor_range(
1559 __isl_take isl_space
*space
)
1563 if (!isl_space_range_is_wrapping(space
))
1564 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1565 "range not a product", return isl_space_free(space
));
1567 return range_factor_range(space
);
1570 /* Given a space of the form [A -> B], return the space B.
1572 static __isl_give isl_space
*set_factor_range(__isl_take isl_space
*space
)
1576 if (!isl_space_is_wrapping(space
))
1577 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1578 "not a product", return isl_space_free(space
));
1580 return range_factor_range(space
);
1583 /* Given a space of the form [A -> B] -> [C -> D], return the space B -> D.
1584 * Given a space of the form [A -> B], return the space B.
1586 __isl_give isl_space
*isl_space_factor_range(__isl_take isl_space
*space
)
1590 if (isl_space_is_set(space
))
1591 return set_factor_range(space
);
1592 space
= isl_space_domain_factor_range(space
);
1593 space
= isl_space_range_factor_range(space
);
1597 __isl_give isl_space
*isl_space_map_from_set(__isl_take isl_space
*space
)
1600 isl_id
**ids
= NULL
;
1605 ctx
= isl_space_get_ctx(space
);
1606 if (!isl_space_is_set(space
))
1607 isl_die(ctx
, isl_error_invalid
, "not a set space", goto error
);
1608 space
= isl_space_cow(space
);
1611 n_id
= space
->nparam
+ space
->n_out
+ space
->n_out
;
1612 if (n_id
> 0 && space
->ids
) {
1613 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n_id
);
1616 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
1617 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1618 ids
+ space
->nparam
);
1620 space
->n_in
= space
->n_out
;
1625 space
= copy_ids(space
, isl_dim_out
, 0, space
, isl_dim_in
);
1627 isl_id_free(space
->tuple_id
[0]);
1628 space
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[1]);
1629 isl_space_free(space
->nested
[0]);
1630 space
->nested
[0] = isl_space_copy(space
->nested
[1]);
1633 isl_space_free(space
);
1637 __isl_give isl_space
*isl_space_map_from_domain_and_range(
1638 __isl_take isl_space
*domain
, __isl_take isl_space
*range
)
1640 if (!domain
|| !range
)
1642 if (!isl_space_is_set(domain
))
1643 isl_die(isl_space_get_ctx(domain
), isl_error_invalid
,
1644 "domain is not a set space", goto error
);
1645 if (!isl_space_is_set(range
))
1646 isl_die(isl_space_get_ctx(range
), isl_error_invalid
,
1647 "range is not a set space", goto error
);
1648 return isl_space_join(isl_space_reverse(domain
), range
);
1650 isl_space_free(domain
);
1651 isl_space_free(range
);
1655 static __isl_give isl_space
*set_ids(__isl_take isl_space
*dim
,
1656 enum isl_dim_type type
,
1657 unsigned first
, unsigned n
, __isl_take isl_id
**ids
)
1661 for (i
= 0; i
< n
; ++i
)
1662 dim
= set_id(dim
, type
, first
+ i
, ids
[i
]);
1667 __isl_give isl_space
*isl_space_reverse(__isl_take isl_space
*space
)
1671 isl_id
**ids
= NULL
;
1676 if (match(space
, isl_dim_in
, space
, isl_dim_out
))
1679 space
= isl_space_cow(space
);
1683 id
= space
->tuple_id
[0];
1684 space
->tuple_id
[0] = space
->tuple_id
[1];
1685 space
->tuple_id
[1] = id
;
1687 nested
= space
->nested
[0];
1688 space
->nested
[0] = space
->nested
[1];
1689 space
->nested
[1] = nested
;
1692 int n_id
= space
->n_in
+ space
->n_out
;
1693 ids
= isl_alloc_array(space
->ctx
, isl_id
*, n_id
);
1696 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
);
1697 get_ids(space
, isl_dim_out
, 0, space
->n_out
, ids
+ space
->n_in
);
1701 space
->n_in
= space
->n_out
;
1705 space
= set_ids(space
, isl_dim_out
, 0, space
->n_out
, ids
);
1706 space
= set_ids(space
, isl_dim_in
, 0, space
->n_in
,
1707 ids
+ space
->n_out
);
1714 isl_space_free(space
);
1718 __isl_give isl_space
*isl_space_drop_dims(__isl_take isl_space
*space
,
1719 enum isl_dim_type type
, unsigned first
, unsigned num
)
1727 return isl_space_reset(space
, type
);
1729 if (!valid_dim_type(type
))
1730 isl_die(space
->ctx
, isl_error_invalid
,
1731 "cannot drop dimensions of specified type", goto error
);
1733 if (isl_space_check_range(space
, type
, first
, num
) < 0)
1734 return isl_space_free(space
);
1735 space
= isl_space_cow(space
);
1739 space
= extend_ids(space
);
1742 for (i
= 0; i
< num
; ++i
)
1743 isl_id_free(get_id(space
, type
, first
+ i
));
1744 for (i
= first
+num
; i
< n(space
, type
); ++i
)
1745 set_id(space
, type
, i
- num
, get_id(space
, type
, i
));
1748 get_ids(space
, isl_dim_in
, 0, space
->n_in
,
1749 space
->ids
+ offset(space
, isl_dim_in
) - num
);
1751 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1752 space
->ids
+ offset(space
, isl_dim_out
) - num
);
1759 case isl_dim_param
: space
->nparam
-= num
; break;
1760 case isl_dim_in
: space
->n_in
-= num
; break;
1761 case isl_dim_out
: space
->n_out
-= num
; break;
1764 space
= isl_space_reset(space
, type
);
1765 if (type
== isl_dim_param
) {
1766 if (space
&& space
->nested
[0] &&
1767 !(space
->nested
[0] = isl_space_drop_dims(space
->nested
[0],
1768 isl_dim_param
, first
, num
)))
1770 if (space
&& space
->nested
[1] &&
1771 !(space
->nested
[1] = isl_space_drop_dims(space
->nested
[1],
1772 isl_dim_param
, first
, num
)))
1777 isl_space_free(space
);
1781 __isl_give isl_space
*isl_space_drop_inputs(__isl_take isl_space
*dim
,
1782 unsigned first
, unsigned n
)
1786 return isl_space_drop_dims(dim
, isl_dim_in
, first
, n
);
1789 __isl_give isl_space
*isl_space_drop_outputs(__isl_take isl_space
*dim
,
1790 unsigned first
, unsigned n
)
1794 return isl_space_drop_dims(dim
, isl_dim_out
, first
, n
);
1797 /* Remove all parameters from "space".
1799 __isl_give isl_space
*isl_space_drop_all_params(__isl_take isl_space
*space
)
1803 nparam
= isl_space_dim(space
, isl_dim_param
);
1804 return isl_space_drop_dims(space
, isl_dim_param
, 0, nparam
);
1807 __isl_give isl_space
*isl_space_domain(__isl_take isl_space
*space
)
1811 space
= isl_space_drop_dims(space
, isl_dim_out
, 0, space
->n_out
);
1812 space
= isl_space_reverse(space
);
1813 space
= mark_as_set(space
);
1817 __isl_give isl_space
*isl_space_from_domain(__isl_take isl_space
*space
)
1821 if (!isl_space_is_set(space
))
1822 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1823 "not a set space", goto error
);
1824 space
= isl_space_reverse(space
);
1825 space
= isl_space_reset(space
, isl_dim_out
);
1828 isl_space_free(space
);
1832 __isl_give isl_space
*isl_space_range(__isl_take isl_space
*space
)
1836 space
= isl_space_drop_dims(space
, isl_dim_in
, 0, space
->n_in
);
1837 space
= mark_as_set(space
);
1841 __isl_give isl_space
*isl_space_from_range(__isl_take isl_space
*space
)
1845 if (!isl_space_is_set(space
))
1846 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1847 "not a set space", goto error
);
1848 return isl_space_reset(space
, isl_dim_in
);
1850 isl_space_free(space
);
1854 /* Given a map space A -> B, return the map space [A -> B] -> A.
1856 __isl_give isl_space
*isl_space_domain_map(__isl_take isl_space
*space
)
1860 domain
= isl_space_from_range(isl_space_domain(isl_space_copy(space
)));
1861 space
= isl_space_from_domain(isl_space_wrap(space
));
1862 space
= isl_space_join(space
, domain
);
1867 /* Given a map space A -> B, return the map space [A -> B] -> B.
1869 __isl_give isl_space
*isl_space_range_map(__isl_take isl_space
*space
)
1873 range
= isl_space_from_range(isl_space_range(isl_space_copy(space
)));
1874 space
= isl_space_from_domain(isl_space_wrap(space
));
1875 space
= isl_space_join(space
, range
);
1880 __isl_give isl_space
*isl_space_params(__isl_take isl_space
*space
)
1882 if (isl_space_is_params(space
))
1884 space
= isl_space_drop_dims(space
,
1885 isl_dim_in
, 0, isl_space_dim(space
, isl_dim_in
));
1886 space
= isl_space_drop_dims(space
,
1887 isl_dim_out
, 0, isl_space_dim(space
, isl_dim_out
));
1888 space
= mark_as_params(space
);
1892 __isl_give isl_space
*isl_space_set_from_params(__isl_take isl_space
*space
)
1896 if (!isl_space_is_params(space
))
1897 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1898 "not a parameter space", goto error
);
1899 return isl_space_reset(space
, isl_dim_set
);
1901 isl_space_free(space
);
1905 __isl_give isl_space
*isl_space_underlying(__isl_take isl_space
*space
,
1911 is_set
= isl_space_is_set(space
);
1913 return isl_space_free(space
);
1914 if (n_div
== 0 && is_set
&&
1915 space
->nparam
== 0 && space
->n_in
== 0 && space
->n_id
== 0)
1916 return isl_space_reset(space
, isl_dim_out
);
1917 space
= isl_space_cow(space
);
1920 space
->n_out
+= space
->nparam
+ space
->n_in
+ n_div
;
1924 for (i
= 0; i
< space
->n_id
; ++i
)
1925 isl_id_free(get_id(space
, isl_dim_out
, i
));
1927 space
= isl_space_reset(space
, isl_dim_in
);
1928 space
= isl_space_reset(space
, isl_dim_out
);
1929 space
= mark_as_set(space
);
1934 /* Are the two spaces the same, including positions and names of parameters?
1936 isl_bool
isl_space_is_equal(__isl_keep isl_space
*space1
,
1937 __isl_keep isl_space
*space2
)
1941 if (!space1
|| !space2
)
1942 return isl_bool_error
;
1943 if (space1
== space2
)
1944 return isl_bool_true
;
1945 equal
= isl_space_has_equal_params(space1
, space2
);
1946 if (equal
< 0 || !equal
)
1948 return isl_space_has_equal_tuples(space1
, space2
);
1951 /* Do the tuples of "space1" correspond to those of the domain of "space2"?
1952 * That is, is "space1" eqaul to the domain of "space2", ignoring parameters.
1954 * "space2" is allowed to be a set space, in which case "space1"
1955 * should be a parameter space.
1957 isl_bool
isl_space_has_domain_tuples(__isl_keep isl_space
*space1
,
1958 __isl_keep isl_space
*space2
)
1962 is_set
= isl_space_is_set(space1
);
1963 if (is_set
< 0 || !is_set
)
1965 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
1966 space2
, isl_dim_in
);
1969 /* Is space1 equal to the domain of space2?
1971 * In the internal version we also allow space2 to be the space of a set,
1972 * provided space1 is a parameter space.
1974 isl_bool
isl_space_is_domain_internal(__isl_keep isl_space
*space1
,
1975 __isl_keep isl_space
*space2
)
1977 isl_bool equal_params
;
1979 if (!space1
|| !space2
)
1980 return isl_bool_error
;
1981 equal_params
= isl_space_has_equal_params(space1
, space2
);
1982 if (equal_params
< 0 || !equal_params
)
1983 return equal_params
;
1984 return isl_space_has_domain_tuples(space1
, space2
);
1987 /* Is space1 equal to the domain of space2?
1989 isl_bool
isl_space_is_domain(__isl_keep isl_space
*space1
,
1990 __isl_keep isl_space
*space2
)
1993 return isl_bool_error
;
1994 if (!isl_space_is_map(space2
))
1995 return isl_bool_false
;
1996 return isl_space_is_domain_internal(space1
, space2
);
1999 /* Is space1 equal to the range of space2?
2001 * In the internal version, space2 is allowed to be the space of a set,
2002 * in which case it should be equal to space1.
2004 isl_bool
isl_space_is_range_internal(__isl_keep isl_space
*space1
,
2005 __isl_keep isl_space
*space2
)
2007 isl_bool equal_params
;
2009 if (!space1
|| !space2
)
2010 return isl_bool_error
;
2011 if (!isl_space_is_set(space1
))
2012 return isl_bool_false
;
2013 equal_params
= isl_space_has_equal_params(space1
, space2
);
2014 if (equal_params
< 0 || !equal_params
)
2015 return equal_params
;
2016 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
2017 space2
, isl_dim_out
);
2020 /* Is space1 equal to the range of space2?
2022 isl_bool
isl_space_is_range(__isl_keep isl_space
*space1
,
2023 __isl_keep isl_space
*space2
)
2026 return isl_bool_error
;
2027 if (!isl_space_is_map(space2
))
2028 return isl_bool_false
;
2029 return isl_space_is_range_internal(space1
, space2
);
2032 /* Update "hash" by hashing in the parameters of "space".
2034 static uint32_t isl_hash_params(uint32_t hash
, __isl_keep isl_space
*space
)
2042 isl_hash_byte(hash
, space
->nparam
% 256);
2044 for (i
= 0; i
< space
->nparam
; ++i
) {
2045 id
= get_id(space
, isl_dim_param
, i
);
2046 hash
= isl_hash_id(hash
, id
);
2052 /* Update "hash" by hashing in the tuples of "space".
2053 * Changes in this function should be reflected in isl_hash_tuples_domain.
2055 static uint32_t isl_hash_tuples(uint32_t hash
, __isl_keep isl_space
*space
)
2062 isl_hash_byte(hash
, space
->n_in
% 256);
2063 isl_hash_byte(hash
, space
->n_out
% 256);
2065 id
= tuple_id(space
, isl_dim_in
);
2066 hash
= isl_hash_id(hash
, id
);
2067 id
= tuple_id(space
, isl_dim_out
);
2068 hash
= isl_hash_id(hash
, id
);
2070 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2071 hash
= isl_hash_tuples(hash
, space
->nested
[1]);
2076 /* Update "hash" by hashing in the domain tuple of "space".
2077 * The result of this function is equal to the result of applying
2078 * isl_hash_tuples to the domain of "space".
2080 static uint32_t isl_hash_tuples_domain(uint32_t hash
,
2081 __isl_keep isl_space
*space
)
2088 isl_hash_byte(hash
, 0);
2089 isl_hash_byte(hash
, space
->n_in
% 256);
2091 hash
= isl_hash_id(hash
, &isl_id_none
);
2092 id
= tuple_id(space
, isl_dim_in
);
2093 hash
= isl_hash_id(hash
, id
);
2095 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2100 /* Return a hash value that digests the tuples of "space",
2101 * i.e., that ignores the parameters.
2103 uint32_t isl_space_get_tuple_hash(__isl_keep isl_space
*space
)
2110 hash
= isl_hash_init();
2111 hash
= isl_hash_tuples(hash
, space
);
2116 uint32_t isl_space_get_hash(__isl_keep isl_space
*space
)
2123 hash
= isl_hash_init();
2124 hash
= isl_hash_params(hash
, space
);
2125 hash
= isl_hash_tuples(hash
, space
);
2130 /* Return the hash value of the domain of "space".
2131 * That is, isl_space_get_domain_hash(space) is equal to
2132 * isl_space_get_hash(isl_space_domain(space)).
2134 uint32_t isl_space_get_domain_hash(__isl_keep isl_space
*space
)
2141 hash
= isl_hash_init();
2142 hash
= isl_hash_params(hash
, space
);
2143 hash
= isl_hash_tuples_domain(hash
, space
);
2148 /* Is "space" the space of a set wrapping a map space?
2150 isl_bool
isl_space_is_wrapping(__isl_keep isl_space
*space
)
2153 return isl_bool_error
;
2155 if (!isl_space_is_set(space
))
2156 return isl_bool_false
;
2158 return space
->nested
[1] != NULL
;
2161 /* Is "space" the space of a map where the domain is a wrapped map space?
2163 isl_bool
isl_space_domain_is_wrapping(__isl_keep isl_space
*space
)
2166 return isl_bool_error
;
2168 if (isl_space_is_set(space
))
2169 return isl_bool_false
;
2171 return space
->nested
[0] != NULL
;
2174 /* Is "space" the space of a map where the range is a wrapped map space?
2176 isl_bool
isl_space_range_is_wrapping(__isl_keep isl_space
*space
)
2179 return isl_bool_error
;
2181 if (isl_space_is_set(space
))
2182 return isl_bool_false
;
2184 return space
->nested
[1] != NULL
;
2187 /* Is "space" a product of two spaces?
2188 * That is, is it a wrapping set space or a map space
2189 * with wrapping domain and range?
2191 isl_bool
isl_space_is_product(__isl_keep isl_space
*space
)
2194 isl_bool is_product
;
2196 is_set
= isl_space_is_set(space
);
2198 return isl_bool_error
;
2200 return isl_space_is_wrapping(space
);
2201 is_product
= isl_space_domain_is_wrapping(space
);
2202 if (is_product
< 0 || !is_product
)
2204 return isl_space_range_is_wrapping(space
);
2207 __isl_give isl_space
*isl_space_wrap(__isl_take isl_space
*space
)
2214 wrap
= isl_space_set_alloc(space
->ctx
,
2215 space
->nparam
, space
->n_in
+ space
->n_out
);
2217 wrap
= copy_ids(wrap
, isl_dim_param
, 0, space
, isl_dim_param
);
2218 wrap
= copy_ids(wrap
, isl_dim_set
, 0, space
, isl_dim_in
);
2219 wrap
= copy_ids(wrap
, isl_dim_set
, space
->n_in
, space
, isl_dim_out
);
2224 wrap
->nested
[1] = space
;
2228 isl_space_free(space
);
2232 __isl_give isl_space
*isl_space_unwrap(__isl_take isl_space
*space
)
2239 if (!isl_space_is_wrapping(space
))
2240 isl_die(space
->ctx
, isl_error_invalid
, "not a wrapping space",
2243 unwrap
= isl_space_copy(space
->nested
[1]);
2244 isl_space_free(space
);
2248 isl_space_free(space
);
2252 isl_bool
isl_space_is_named_or_nested(__isl_keep isl_space
*space
,
2253 enum isl_dim_type type
)
2255 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
2256 return isl_bool_false
;
2258 return isl_bool_error
;
2259 if (space
->tuple_id
[type
- isl_dim_in
])
2260 return isl_bool_true
;
2261 if (space
->nested
[type
- isl_dim_in
])
2262 return isl_bool_true
;
2263 return isl_bool_false
;
2266 isl_bool
isl_space_may_be_set(__isl_keep isl_space
*space
)
2271 return isl_bool_error
;
2272 if (isl_space_is_set(space
))
2273 return isl_bool_true
;
2274 if (isl_space_dim(space
, isl_dim_in
) != 0)
2275 return isl_bool_false
;
2276 nested
= isl_space_is_named_or_nested(space
, isl_dim_in
);
2277 if (nested
< 0 || nested
)
2278 return isl_bool_not(nested
);
2279 return isl_bool_true
;
2282 __isl_give isl_space
*isl_space_reset(__isl_take isl_space
*space
,
2283 enum isl_dim_type type
)
2285 if (!isl_space_is_named_or_nested(space
, type
))
2288 space
= isl_space_cow(space
);
2292 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
2293 space
->tuple_id
[type
- isl_dim_in
] = NULL
;
2294 isl_space_free(space
->nested
[type
- isl_dim_in
]);
2295 space
->nested
[type
- isl_dim_in
] = NULL
;
2300 __isl_give isl_space
*isl_space_flatten(__isl_take isl_space
*space
)
2304 if (!space
->nested
[0] && !space
->nested
[1])
2307 if (space
->nested
[0])
2308 space
= isl_space_reset(space
, isl_dim_in
);
2309 if (space
&& space
->nested
[1])
2310 space
= isl_space_reset(space
, isl_dim_out
);
2315 __isl_give isl_space
*isl_space_flatten_domain(__isl_take isl_space
*space
)
2319 if (!space
->nested
[0])
2322 return isl_space_reset(space
, isl_dim_in
);
2325 __isl_give isl_space
*isl_space_flatten_range(__isl_take isl_space
*space
)
2329 if (!space
->nested
[1])
2332 return isl_space_reset(space
, isl_dim_out
);
2335 /* Replace the parameters of dst by those of src.
2337 __isl_give isl_space
*isl_space_replace_params(__isl_take isl_space
*dst
,
2338 __isl_keep isl_space
*src
)
2340 isl_bool equal_params
;
2341 enum isl_dim_type type
= isl_dim_param
;
2343 equal_params
= isl_space_has_equal_params(dst
, src
);
2344 if (equal_params
< 0)
2345 return isl_space_free(dst
);
2349 dst
= isl_space_cow(dst
);
2354 dst
= isl_space_drop_dims(dst
, type
, 0, isl_space_dim(dst
, type
));
2355 dst
= isl_space_add_dims(dst
, type
, isl_space_dim(src
, type
));
2356 dst
= copy_ids(dst
, type
, 0, src
, type
);
2360 for (i
= 0; i
<= 1; ++i
) {
2361 if (!dst
->nested
[i
])
2363 dst
->nested
[i
] = isl_space_replace_params(
2364 dst
->nested
[i
], src
);
2365 if (!dst
->nested
[i
])
2372 isl_space_free(dst
);
2376 /* Given a dimension specification "dim" of a set, create a dimension
2377 * specification for the lift of the set. In particular, the result
2378 * is of the form [dim -> local[..]], with n_local variables in the
2379 * range of the wrapped map.
2381 __isl_give isl_space
*isl_space_lift(__isl_take isl_space
*space
,
2384 isl_space
*local_space
;
2389 local_space
= isl_space_dup(space
);
2390 local_space
= isl_space_drop_dims(local_space
, isl_dim_set
, 0,
2392 local_space
= isl_space_add_dims(local_space
, isl_dim_set
, n_local
);
2393 local_space
= isl_space_set_tuple_name(local_space
,
2394 isl_dim_set
, "local");
2395 space
= isl_space_join(isl_space_from_domain(space
),
2396 isl_space_from_range(local_space
));
2397 space
= isl_space_wrap(space
);
2398 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "lifted");
2403 isl_bool
isl_space_can_zip(__isl_keep isl_space
*space
)
2407 is_set
= isl_space_is_set(space
);
2409 return isl_bool_error
;
2411 return isl_bool_false
;
2412 return isl_space_is_product(space
);
2415 __isl_give isl_space
*isl_space_zip(__isl_take isl_space
*space
)
2417 isl_space
*dom
, *ran
;
2418 isl_space
*dom_dom
, *dom_ran
, *ran_dom
, *ran_ran
;
2420 if (!isl_space_can_zip(space
))
2421 isl_die(space
->ctx
, isl_error_invalid
, "dim cannot be zipped",
2426 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(space
)));
2427 ran
= isl_space_unwrap(isl_space_range(space
));
2428 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2429 dom_ran
= isl_space_range(dom
);
2430 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2431 ran_ran
= isl_space_range(ran
);
2432 dom
= isl_space_join(isl_space_from_domain(dom_dom
),
2433 isl_space_from_range(ran_dom
));
2434 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2435 isl_space_from_range(ran_ran
));
2436 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2437 isl_space_from_range(isl_space_wrap(ran
)));
2439 isl_space_free(space
);
2443 /* Can we apply isl_space_curry to "space"?
2444 * That is, does is it have a map space with a nested relation in its domain?
2446 isl_bool
isl_space_can_curry(__isl_keep isl_space
*space
)
2448 return isl_space_domain_is_wrapping(space
);
2451 /* Given a space (A -> B) -> C, return the corresponding space
2454 __isl_give isl_space
*isl_space_curry(__isl_take isl_space
*space
)
2456 isl_space
*dom
, *ran
;
2457 isl_space
*dom_dom
, *dom_ran
;
2462 if (!isl_space_can_curry(space
))
2463 isl_die(space
->ctx
, isl_error_invalid
,
2464 "space cannot be curried", goto error
);
2466 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(space
)));
2467 ran
= isl_space_range(space
);
2468 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2469 dom_ran
= isl_space_range(dom
);
2470 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2471 isl_space_from_range(ran
));
2472 return isl_space_join(isl_space_from_domain(dom_dom
),
2473 isl_space_from_range(isl_space_wrap(ran
)));
2475 isl_space_free(space
);
2479 /* Can isl_space_range_curry be applied to "space"?
2480 * That is, does it have a nested relation in its range,
2481 * the domain of which is itself a nested relation?
2483 isl_bool
isl_space_can_range_curry(__isl_keep isl_space
*space
)
2488 return isl_bool_error
;
2489 can
= isl_space_range_is_wrapping(space
);
2490 if (can
< 0 || !can
)
2492 return isl_space_can_curry(space
->nested
[1]);
2495 /* Given a space A -> ((B -> C) -> D), return the corresponding space
2496 * A -> (B -> (C -> D)).
2498 __isl_give isl_space
*isl_space_range_curry(__isl_take isl_space
*space
)
2503 if (!isl_space_can_range_curry(space
))
2504 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2505 "space range cannot be curried",
2506 return isl_space_free(space
));
2508 space
= isl_space_cow(space
);
2511 space
->nested
[1] = isl_space_curry(space
->nested
[1]);
2512 if (!space
->nested
[1])
2513 return isl_space_free(space
);
2518 /* Can we apply isl_space_uncurry to "space"?
2519 * That is, does it have a map space with a nested relation in its range?
2521 isl_bool
isl_space_can_uncurry(__isl_keep isl_space
*space
)
2523 return isl_space_range_is_wrapping(space
);
2526 /* Given a space A -> (B -> C), return the corresponding space
2529 __isl_give isl_space
*isl_space_uncurry(__isl_take isl_space
*space
)
2531 isl_space
*dom
, *ran
;
2532 isl_space
*ran_dom
, *ran_ran
;
2537 if (!isl_space_can_uncurry(space
))
2538 isl_die(space
->ctx
, isl_error_invalid
,
2539 "space cannot be uncurried",
2540 return isl_space_free(space
));
2542 dom
= isl_space_domain(isl_space_copy(space
));
2543 ran
= isl_space_unwrap(isl_space_range(space
));
2544 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2545 ran_ran
= isl_space_range(ran
);
2546 dom
= isl_space_join(isl_space_from_domain(dom
),
2547 isl_space_from_range(ran_dom
));
2548 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2549 isl_space_from_range(ran_ran
));
2552 isl_bool
isl_space_has_named_params(__isl_keep isl_space
*space
)
2558 return isl_bool_error
;
2559 if (space
->nparam
== 0)
2560 return isl_bool_true
;
2561 off
= isl_space_offset(space
, isl_dim_param
);
2562 if (off
+ space
->nparam
> space
->n_id
)
2563 return isl_bool_false
;
2564 for (i
= 0; i
< space
->nparam
; ++i
)
2565 if (!space
->ids
[off
+ i
])
2566 return isl_bool_false
;
2567 return isl_bool_true
;
2570 /* Check that "space" has only named parameters, reporting an error
2573 isl_stat
isl_space_check_named_params(__isl_keep isl_space
*space
)
2577 named
= isl_space_has_named_params(space
);
2579 return isl_stat_error
;
2581 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2582 "unexpected unnamed parameters", return isl_stat_error
);
2587 /* Align the initial parameters of space1 to match the order in space2.
2589 __isl_give isl_space
*isl_space_align_params(__isl_take isl_space
*space1
,
2590 __isl_take isl_space
*space2
)
2592 isl_reordering
*exp
;
2594 if (isl_space_check_named_params(space1
) < 0 ||
2595 isl_space_check_named_params(space2
) < 0)
2598 exp
= isl_parameter_alignment_reordering(space1
, space2
);
2599 exp
= isl_reordering_extend_space(exp
, space1
);
2600 isl_space_free(space2
);
2601 space1
= isl_reordering_get_space(exp
);
2602 isl_reordering_free(exp
);
2605 isl_space_free(space1
);
2606 isl_space_free(space2
);
2610 /* Given the space of set (domain), construct a space for a map
2611 * with as domain the given space and as range the range of "model".
2613 __isl_give isl_space
*isl_space_extend_domain_with_range(
2614 __isl_take isl_space
*space
, __isl_take isl_space
*model
)
2619 space
= isl_space_from_domain(space
);
2620 space
= isl_space_add_dims(space
, isl_dim_out
,
2621 isl_space_dim(model
, isl_dim_out
));
2622 if (isl_space_has_tuple_id(model
, isl_dim_out
))
2623 space
= isl_space_set_tuple_id(space
, isl_dim_out
,
2624 isl_space_get_tuple_id(model
, isl_dim_out
));
2627 if (model
->nested
[1]) {
2628 isl_space
*nested
= isl_space_copy(model
->nested
[1]);
2629 int n_nested
, n_space
;
2630 nested
= isl_space_align_params(nested
, isl_space_copy(space
));
2631 n_nested
= isl_space_dim(nested
, isl_dim_param
);
2632 n_space
= isl_space_dim(space
, isl_dim_param
);
2633 if (n_nested
> n_space
)
2634 nested
= isl_space_drop_dims(nested
, isl_dim_param
,
2635 n_space
, n_nested
- n_space
);
2638 space
->nested
[1] = nested
;
2640 isl_space_free(model
);
2643 isl_space_free(model
);
2644 isl_space_free(space
);
2648 /* Compare the "type" dimensions of two isl_spaces.
2650 * The order is fairly arbitrary.
2652 static int isl_space_cmp_type(__isl_keep isl_space
*space1
,
2653 __isl_keep isl_space
*space2
, enum isl_dim_type type
)
2656 isl_space
*nested1
, *nested2
;
2658 if (isl_space_dim(space1
, type
) != isl_space_dim(space2
, type
))
2659 return isl_space_dim(space1
, type
) -
2660 isl_space_dim(space2
, type
);
2662 cmp
= isl_id_cmp(tuple_id(space1
, type
), tuple_id(space2
, type
));
2666 nested1
= nested(space1
, type
);
2667 nested2
= nested(space2
, type
);
2668 if (!nested1
!= !nested2
)
2669 return !nested1
- !nested2
;
2672 return isl_space_cmp(nested1
, nested2
);
2677 /* Compare two isl_spaces.
2679 * The order is fairly arbitrary.
2681 int isl_space_cmp(__isl_keep isl_space
*space1
, __isl_keep isl_space
*space2
)
2686 if (space1
== space2
)
2693 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_param
);
2696 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_in
);
2699 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_out
);
2703 if (!space1
->ids
&& !space2
->ids
)
2706 for (i
= 0; i
< n(space1
, isl_dim_param
); ++i
) {
2707 cmp
= isl_id_cmp(get_id(space1
, isl_dim_param
, i
),
2708 get_id(space2
, isl_dim_param
, i
));