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 unsigned global_pos(__isl_keep isl_space
*space
,
152 enum isl_dim_type type
, unsigned pos
)
154 struct isl_ctx
*ctx
= space
->ctx
;
156 if (isl_space_check_range(space
, type
, pos
, 1) < 0)
157 return isl_space_dim(space
, isl_dim_all
);
163 return pos
+ space
->nparam
;
165 return pos
+ space
->nparam
+ space
->n_in
;
167 isl_assert(ctx
, 0, return isl_space_dim(space
, isl_dim_all
));
169 return isl_space_dim(space
, isl_dim_all
);
172 /* Extend length of ids array to the total number of dimensions.
174 static __isl_give isl_space
*extend_ids(__isl_take isl_space
*space
)
179 if (isl_space_dim(space
, isl_dim_all
) <= space
->n_id
)
183 space
->ids
= isl_calloc_array(space
->ctx
,
184 isl_id
*, isl_space_dim(space
, isl_dim_all
));
188 ids
= isl_realloc_array(space
->ctx
, space
->ids
,
189 isl_id
*, isl_space_dim(space
, isl_dim_all
));
193 for (i
= space
->n_id
; i
< isl_space_dim(space
, isl_dim_all
); ++i
)
194 space
->ids
[i
] = NULL
;
197 space
->n_id
= isl_space_dim(space
, isl_dim_all
);
201 isl_space_free(space
);
205 static __isl_give isl_space
*set_id(__isl_take isl_space
*space
,
206 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
208 space
= isl_space_cow(space
);
213 pos
= global_pos(space
, type
, pos
);
214 if (pos
== isl_space_dim(space
, isl_dim_all
))
217 if (pos
>= space
->n_id
) {
220 space
= extend_ids(space
);
225 space
->ids
[pos
] = id
;
230 isl_space_free(space
);
234 static __isl_keep isl_id
*get_id(__isl_keep isl_space
*space
,
235 enum isl_dim_type type
, unsigned pos
)
240 pos
= global_pos(space
, type
, pos
);
241 if (pos
== isl_space_dim(space
, isl_dim_all
))
243 if (pos
>= space
->n_id
)
245 return space
->ids
[pos
];
248 static unsigned offset(__isl_keep isl_space
*space
, enum isl_dim_type type
)
251 case isl_dim_param
: return 0;
252 case isl_dim_in
: return space
->nparam
;
253 case isl_dim_out
: return space
->nparam
+ space
->n_in
;
258 static unsigned n(__isl_keep isl_space
*space
, enum isl_dim_type type
)
261 case isl_dim_param
: return space
->nparam
;
262 case isl_dim_in
: return space
->n_in
;
263 case isl_dim_out
: return space
->n_out
;
265 return space
->nparam
+ space
->n_in
+ space
->n_out
;
270 unsigned isl_space_dim(__isl_keep isl_space
*space
, enum isl_dim_type type
)
274 return n(space
, type
);
277 unsigned isl_space_offset(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
281 return offset(dim
, type
);
284 static __isl_give isl_space
*copy_ids(__isl_take isl_space
*dst
,
285 enum isl_dim_type dst_type
, unsigned offset
, __isl_keep isl_space
*src
,
286 enum isl_dim_type src_type
)
294 for (i
= 0; i
< n(src
, src_type
); ++i
) {
295 id
= get_id(src
, src_type
, i
);
298 dst
= set_id(dst
, dst_type
, offset
+ i
, isl_id_copy(id
));
305 __isl_take isl_space
*isl_space_dup(__isl_keep isl_space
*space
)
310 dup
= isl_space_alloc(space
->ctx
,
311 space
->nparam
, space
->n_in
, space
->n_out
);
314 if (space
->tuple_id
[0] &&
315 !(dup
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[0])))
317 if (space
->tuple_id
[1] &&
318 !(dup
->tuple_id
[1] = isl_id_copy(space
->tuple_id
[1])))
320 if (space
->nested
[0] &&
321 !(dup
->nested
[0] = isl_space_copy(space
->nested
[0])))
323 if (space
->nested
[1] &&
324 !(dup
->nested
[1] = isl_space_copy(space
->nested
[1])))
328 dup
= copy_ids(dup
, isl_dim_param
, 0, space
, isl_dim_param
);
329 dup
= copy_ids(dup
, isl_dim_in
, 0, space
, isl_dim_in
);
330 dup
= copy_ids(dup
, isl_dim_out
, 0, space
, isl_dim_out
);
337 __isl_give isl_space
*isl_space_cow(__isl_take isl_space
*space
)
345 return isl_space_dup(space
);
348 __isl_give isl_space
*isl_space_copy(__isl_keep isl_space
*dim
)
357 __isl_null isl_space
*isl_space_free(__isl_take isl_space
*space
)
364 if (--space
->ref
> 0)
367 isl_id_free(space
->tuple_id
[0]);
368 isl_id_free(space
->tuple_id
[1]);
370 isl_space_free(space
->nested
[0]);
371 isl_space_free(space
->nested
[1]);
373 for (i
= 0; i
< space
->n_id
; ++i
)
374 isl_id_free(space
->ids
[i
]);
376 isl_ctx_deref(space
->ctx
);
383 /* Check if "s" is a valid dimension or tuple name.
384 * We currently only forbid names that look like a number.
386 * s is assumed to be non-NULL.
388 static int name_ok(isl_ctx
*ctx
, const char *s
)
393 dummy
= strtol(s
, &p
, 0);
395 isl_die(ctx
, isl_error_invalid
, "name looks like a number",
401 /* Is it possible for the given dimension type to have a tuple id?
403 static int space_can_have_id(__isl_keep isl_space
*space
,
404 enum isl_dim_type type
)
408 if (isl_space_is_params(space
))
409 isl_die(space
->ctx
, isl_error_invalid
,
410 "parameter spaces don't have tuple ids", return 0);
411 if (isl_space_is_set(space
) && type
!= isl_dim_set
)
412 isl_die(space
->ctx
, isl_error_invalid
,
413 "set spaces can only have a set id", return 0);
414 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
415 isl_die(space
->ctx
, isl_error_invalid
,
416 "only input, output and set tuples can have ids",
422 /* Does the tuple have an id?
424 isl_bool
isl_space_has_tuple_id(__isl_keep isl_space
*space
,
425 enum isl_dim_type type
)
427 if (!space_can_have_id(space
, type
))
428 return isl_bool_error
;
429 return space
->tuple_id
[type
- isl_dim_in
] != NULL
;
432 __isl_give isl_id
*isl_space_get_tuple_id(__isl_keep isl_space
*space
,
433 enum isl_dim_type type
)
439 has_id
= isl_space_has_tuple_id(space
, type
);
443 isl_die(space
->ctx
, isl_error_invalid
,
444 "tuple has no id", return NULL
);
445 return isl_id_copy(space
->tuple_id
[type
- isl_dim_in
]);
448 __isl_give isl_space
*isl_space_set_tuple_id(__isl_take isl_space
*space
,
449 enum isl_dim_type type
, __isl_take isl_id
*id
)
451 space
= isl_space_cow(space
);
454 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
455 isl_die(space
->ctx
, isl_error_invalid
,
456 "only input, output and set tuples can have names",
459 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
460 space
->tuple_id
[type
- isl_dim_in
] = id
;
465 isl_space_free(space
);
469 __isl_give isl_space
*isl_space_reset_tuple_id(__isl_take isl_space
*space
,
470 enum isl_dim_type type
)
472 space
= isl_space_cow(space
);
475 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
476 isl_die(space
->ctx
, isl_error_invalid
,
477 "only input, output and set tuples can have names",
480 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
481 space
->tuple_id
[type
- isl_dim_in
] = NULL
;
485 isl_space_free(space
);
489 /* Set the id of the given dimension of "space" to "id".
490 * If the dimension already has an id, then it is replaced.
491 * If the dimension is a parameter, then we need to change it
492 * in the nested spaces (if any) as well.
494 __isl_give isl_space
*isl_space_set_dim_id(__isl_take isl_space
*space
,
495 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
497 space
= isl_space_cow(space
);
501 if (type
== isl_dim_param
) {
504 for (i
= 0; i
< 2; ++i
) {
505 if (!space
->nested
[i
])
508 isl_space_set_dim_id(space
->nested
[i
],
509 type
, pos
, isl_id_copy(id
));
510 if (!space
->nested
[i
])
515 isl_id_free(get_id(space
, type
, pos
));
516 return set_id(space
, type
, pos
, id
);
519 isl_space_free(space
);
523 /* Reset the id of the given dimension of "space".
524 * If the dimension already has an id, then it is removed.
525 * If the dimension is a parameter, then we need to reset it
526 * in the nested spaces (if any) as well.
528 __isl_give isl_space
*isl_space_reset_dim_id(__isl_take isl_space
*space
,
529 enum isl_dim_type type
, unsigned pos
)
531 space
= isl_space_cow(space
);
535 if (type
== isl_dim_param
) {
538 for (i
= 0; i
< 2; ++i
) {
539 if (!space
->nested
[i
])
542 isl_space_reset_dim_id(space
->nested
[i
],
544 if (!space
->nested
[i
])
549 isl_id_free(get_id(space
, type
, pos
));
550 return set_id(space
, type
, pos
, NULL
);
552 isl_space_free(space
);
556 isl_bool
isl_space_has_dim_id(__isl_keep isl_space
*space
,
557 enum isl_dim_type type
, unsigned pos
)
560 return isl_bool_error
;
561 return get_id(space
, type
, pos
) != NULL
;
564 __isl_give isl_id
*isl_space_get_dim_id(__isl_keep isl_space
*space
,
565 enum isl_dim_type type
, unsigned pos
)
569 if (!get_id(space
, type
, pos
))
570 isl_die(space
->ctx
, isl_error_invalid
,
571 "dim has no id", return NULL
);
572 return isl_id_copy(get_id(space
, type
, pos
));
575 __isl_give isl_space
*isl_space_set_tuple_name(__isl_take isl_space
*space
,
576 enum isl_dim_type type
, const char *s
)
584 return isl_space_reset_tuple_id(space
, type
);
586 if (!name_ok(space
->ctx
, s
))
589 id
= isl_id_alloc(space
->ctx
, s
, NULL
);
590 return isl_space_set_tuple_id(space
, type
, id
);
592 isl_space_free(space
);
596 /* Does the tuple have a name?
598 isl_bool
isl_space_has_tuple_name(__isl_keep isl_space
*space
,
599 enum isl_dim_type type
)
603 if (!space_can_have_id(space
, type
))
604 return isl_bool_error
;
605 id
= space
->tuple_id
[type
- isl_dim_in
];
606 return id
&& id
->name
;
609 __isl_keep
const char *isl_space_get_tuple_name(__isl_keep isl_space
*space
,
610 enum isl_dim_type type
)
615 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
617 id
= space
->tuple_id
[type
- isl_dim_in
];
618 return id
? id
->name
: NULL
;
621 __isl_give isl_space
*isl_space_set_dim_name(__isl_take isl_space
*space
,
622 enum isl_dim_type type
, unsigned pos
,
630 return isl_space_reset_dim_id(space
, type
, pos
);
631 if (!name_ok(space
->ctx
, s
))
633 id
= isl_id_alloc(space
->ctx
, s
, NULL
);
634 return isl_space_set_dim_id(space
, type
, pos
, id
);
636 isl_space_free(space
);
640 /* Does the given dimension have a name?
642 isl_bool
isl_space_has_dim_name(__isl_keep isl_space
*space
,
643 enum isl_dim_type type
, unsigned pos
)
648 return isl_bool_error
;
649 id
= get_id(space
, type
, pos
);
650 return id
&& id
->name
;
653 __isl_keep
const char *isl_space_get_dim_name(__isl_keep isl_space
*space
,
654 enum isl_dim_type type
, unsigned pos
)
656 isl_id
*id
= get_id(space
, type
, pos
);
657 return id
? id
->name
: NULL
;
660 int isl_space_find_dim_by_id(__isl_keep isl_space
*space
,
661 enum isl_dim_type type
, __isl_keep isl_id
*id
)
670 offset
= isl_space_offset(space
, type
);
671 n
= isl_space_dim(space
, type
);
672 for (i
= 0; i
< n
&& offset
+ i
< space
->n_id
; ++i
)
673 if (space
->ids
[offset
+ i
] == id
)
679 int isl_space_find_dim_by_name(__isl_keep isl_space
*space
,
680 enum isl_dim_type type
, const char *name
)
689 offset
= isl_space_offset(space
, type
);
690 n
= isl_space_dim(space
, type
);
691 for (i
= 0; i
< n
&& offset
+ i
< space
->n_id
; ++i
) {
692 isl_id
*id
= get_id(space
, type
, i
);
693 if (id
&& id
->name
&& !strcmp(id
->name
, name
))
700 /* Reset the user pointer on all identifiers of parameters and tuples
703 __isl_give isl_space
*isl_space_reset_user(__isl_take isl_space
*space
)
713 ctx
= isl_space_get_ctx(space
);
715 for (i
= 0; i
< space
->nparam
&& i
< space
->n_id
; ++i
) {
716 if (!isl_id_get_user(space
->ids
[i
]))
718 space
= isl_space_cow(space
);
721 name
= isl_id_get_name(space
->ids
[i
]);
722 id
= isl_id_alloc(ctx
, name
, NULL
);
723 isl_id_free(space
->ids
[i
]);
726 return isl_space_free(space
);
729 for (i
= 0; i
< 2; ++i
) {
730 if (!space
->tuple_id
[i
])
732 if (!isl_id_get_user(space
->tuple_id
[i
]))
734 space
= isl_space_cow(space
);
737 name
= isl_id_get_name(space
->tuple_id
[i
]);
738 id
= isl_id_alloc(ctx
, name
, NULL
);
739 isl_id_free(space
->tuple_id
[i
]);
740 space
->tuple_id
[i
] = id
;
742 return isl_space_free(space
);
745 for (i
= 0; i
< 2; ++i
) {
746 if (!space
->nested
[i
])
748 space
= isl_space_cow(space
);
751 space
->nested
[i
] = isl_space_reset_user(space
->nested
[i
]);
752 if (!space
->nested
[i
])
753 return isl_space_free(space
);
759 static __isl_keep isl_id
*tuple_id(__isl_keep isl_space
*dim
,
760 enum isl_dim_type type
)
764 if (type
== isl_dim_in
)
765 return dim
->tuple_id
[0];
766 if (type
== isl_dim_out
)
767 return dim
->tuple_id
[1];
771 static __isl_keep isl_space
*nested(__isl_keep isl_space
*dim
,
772 enum isl_dim_type type
)
776 if (type
== isl_dim_in
)
777 return dim
->nested
[0];
778 if (type
== isl_dim_out
)
779 return dim
->nested
[1];
783 /* Are the two spaces the same, apart from positions and names of parameters?
785 isl_bool
isl_space_has_equal_tuples(__isl_keep isl_space
*space1
,
786 __isl_keep isl_space
*space2
)
788 if (!space1
|| !space2
)
789 return isl_bool_error
;
790 if (space1
== space2
)
791 return isl_bool_true
;
792 return isl_space_tuple_is_equal(space1
, isl_dim_in
,
793 space2
, isl_dim_in
) &&
794 isl_space_tuple_is_equal(space1
, isl_dim_out
,
795 space2
, isl_dim_out
);
798 /* Check if the tuple of type "type1" of "space1" is the same as
799 * the tuple of type "type2" of "space2".
801 * That is, check if the tuples have the same identifier, the same dimension
802 * and the same internal structure.
803 * The identifiers of the dimensions inside the tuples do not affect the result.
805 * Note that this function only checks the tuples themselves.
806 * If nested tuples are involved, then we need to be careful not
807 * to have result affected by possibly differing parameters
808 * in those nested tuples.
810 isl_bool
isl_space_tuple_is_equal(__isl_keep isl_space
*space1
,
811 enum isl_dim_type type1
, __isl_keep isl_space
*space2
,
812 enum isl_dim_type type2
)
815 isl_space
*nested1
, *nested2
;
817 if (!space1
|| !space2
)
818 return isl_bool_error
;
820 if (space1
== space2
&& type1
== type2
)
821 return isl_bool_true
;
823 if (n(space1
, type1
) != n(space2
, type2
))
824 return isl_bool_false
;
825 id1
= tuple_id(space1
, type1
);
826 id2
= tuple_id(space2
, type2
);
828 return isl_bool_false
;
829 if (id1
&& id1
!= id2
)
830 return isl_bool_false
;
831 nested1
= nested(space1
, type1
);
832 nested2
= nested(space2
, type2
);
833 if (!nested1
^ !nested2
)
834 return isl_bool_false
;
835 if (nested1
&& !isl_space_has_equal_tuples(nested1
, nested2
))
836 return isl_bool_false
;
837 return isl_bool_true
;
840 static isl_bool
match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
841 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
845 if (space1
== space2
&& type1
== type2
)
846 return isl_bool_true
;
848 if (!isl_space_tuple_is_equal(space1
, type1
, space2
, type2
))
849 return isl_bool_false
;
851 if (!space1
->ids
&& !space2
->ids
)
852 return isl_bool_true
;
854 for (i
= 0; i
< n(space1
, type1
); ++i
) {
855 if (get_id(space1
, type1
, i
) != get_id(space2
, type2
, i
))
856 return isl_bool_false
;
858 return isl_bool_true
;
861 /* Do "space1" and "space2" have the same parameters?
863 isl_bool
isl_space_has_equal_params(__isl_keep isl_space
*space1
,
864 __isl_keep isl_space
*space2
)
866 if (!space1
|| !space2
)
867 return isl_bool_error
;
869 return match(space1
, isl_dim_param
, space2
, isl_dim_param
);
872 /* Do "space1" and "space2" have the same identifiers for all
873 * the tuple variables?
875 isl_bool
isl_space_has_equal_ids(__isl_keep isl_space
*space1
,
876 __isl_keep isl_space
*space2
)
880 if (!space1
|| !space2
)
881 return isl_bool_error
;
883 equal
= match(space1
, isl_dim_in
, space2
, isl_dim_in
);
884 if (equal
< 0 || !equal
)
886 return match(space1
, isl_dim_out
, space2
, isl_dim_out
);
889 isl_bool
isl_space_match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
890 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
892 if (!space1
|| !space2
)
893 return isl_bool_error
;
895 return match(space1
, type1
, space2
, type2
);
898 static void get_ids(__isl_keep isl_space
*dim
, enum isl_dim_type type
,
899 unsigned first
, unsigned n
, __isl_keep isl_id
**ids
)
903 for (i
= 0; i
< n
; ++i
)
904 ids
[i
] = get_id(dim
, type
, first
+ i
);
907 static __isl_give isl_space
*space_extend(__isl_take isl_space
*space
,
908 unsigned nparam
, unsigned n_in
, unsigned n_out
)
914 if (space
->nparam
== nparam
&&
915 space
->n_in
== n_in
&& space
->n_out
== n_out
)
918 isl_assert(space
->ctx
, space
->nparam
<= nparam
, goto error
);
919 isl_assert(space
->ctx
, space
->n_in
<= n_in
, goto error
);
920 isl_assert(space
->ctx
, space
->n_out
<= n_out
, goto error
);
922 space
= isl_space_cow(space
);
928 n
= nparam
+ n_in
+ n_out
;
929 if (n
< nparam
|| n
< n_in
|| n
< n_out
)
930 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
931 "overflow in total number of dimensions",
933 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n
);
936 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
937 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
+ nparam
);
938 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
939 ids
+ nparam
+ n_in
);
942 space
->n_id
= nparam
+ n_in
+ n_out
;
944 space
->nparam
= nparam
;
946 space
->n_out
= n_out
;
951 isl_space_free(space
);
955 __isl_give isl_space
*isl_space_extend(__isl_take isl_space
*space
,
956 unsigned nparam
, unsigned n_in
, unsigned n_out
)
958 return space_extend(space
, nparam
, n_in
, n_out
);
961 __isl_give isl_space
*isl_space_add_dims(__isl_take isl_space
*space
,
962 enum isl_dim_type type
, unsigned n
)
964 space
= isl_space_reset(space
, type
);
969 space
= space_extend(space
,
970 space
->nparam
+ n
, space
->n_in
, space
->n_out
);
971 if (space
&& space
->nested
[0] &&
972 !(space
->nested
[0] = isl_space_add_dims(space
->nested
[0],
975 if (space
&& space
->nested
[1] &&
976 !(space
->nested
[1] = isl_space_add_dims(space
->nested
[1],
981 return space_extend(space
,
982 space
->nparam
, space
->n_in
+ n
, space
->n_out
);
984 return space_extend(space
,
985 space
->nparam
, space
->n_in
, space
->n_out
+ n
);
987 isl_die(space
->ctx
, isl_error_invalid
,
988 "cannot add dimensions of specified type", goto error
);
991 isl_space_free(space
);
995 /* Add a parameter with identifier "id" to "space", provided
996 * it does not already appear in "space".
998 __isl_give isl_space
*isl_space_add_param_id(__isl_take isl_space
*space
,
999 __isl_take isl_id
*id
)
1006 if (isl_space_find_dim_by_id(space
, isl_dim_param
, id
) >= 0) {
1011 pos
= isl_space_dim(space
, isl_dim_param
);
1012 space
= isl_space_add_dims(space
, isl_dim_param
, 1);
1013 space
= isl_space_set_dim_id(space
, isl_dim_param
, pos
, id
);
1017 isl_space_free(space
);
1022 static int valid_dim_type(enum isl_dim_type type
)
1035 #define TYPE isl_space
1036 #include "check_type_range_templ.c"
1038 /* Insert "n" dimensions of type "type" at position "pos".
1039 * If we are inserting parameters, then they are also inserted in
1040 * any nested spaces.
1042 __isl_give isl_space
*isl_space_insert_dims(__isl_take isl_space
*space
,
1043 enum isl_dim_type type
, unsigned pos
, unsigned n
)
1046 isl_id
**ids
= NULL
;
1051 return isl_space_reset(space
, type
);
1053 ctx
= isl_space_get_ctx(space
);
1054 if (!valid_dim_type(type
))
1055 isl_die(ctx
, isl_error_invalid
,
1056 "cannot insert dimensions of specified type",
1059 if (isl_space_check_range(space
, type
, pos
, 0) < 0)
1060 return isl_space_free(space
);
1062 space
= isl_space_cow(space
);
1067 enum isl_dim_type t
, o
= isl_dim_param
;
1070 ids
= isl_calloc_array(ctx
, isl_id
*,
1071 space
->nparam
+ space
->n_in
+ space
->n_out
+ n
);
1075 s
[isl_dim_param
- o
] = space
->nparam
;
1076 s
[isl_dim_in
- o
] = space
->n_in
;
1077 s
[isl_dim_out
- o
] = space
->n_out
;
1078 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1080 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1083 get_ids(space
, t
, 0, pos
, ids
+ off
);
1085 get_ids(space
, t
, pos
, s
[t
- o
] - pos
,
1087 off
+= s
[t
- o
] - pos
;
1092 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
+ n
;
1095 case isl_dim_param
: space
->nparam
+= n
; break;
1096 case isl_dim_in
: space
->n_in
+= n
; break;
1097 case isl_dim_out
: space
->n_out
+= n
; break;
1100 space
= isl_space_reset(space
, type
);
1102 if (type
== isl_dim_param
) {
1103 if (space
&& space
->nested
[0] &&
1104 !(space
->nested
[0] = isl_space_insert_dims(space
->nested
[0],
1105 isl_dim_param
, pos
, n
)))
1107 if (space
&& space
->nested
[1] &&
1108 !(space
->nested
[1] = isl_space_insert_dims(space
->nested
[1],
1109 isl_dim_param
, pos
, n
)))
1115 isl_space_free(space
);
1119 __isl_give isl_space
*isl_space_move_dims(__isl_take isl_space
*space
,
1120 enum isl_dim_type dst_type
, unsigned dst_pos
,
1121 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1125 space
= isl_space_reset(space
, src_type
);
1126 space
= isl_space_reset(space
, dst_type
);
1132 if (isl_space_check_range(space
, src_type
, src_pos
, n
) < 0)
1133 return isl_space_free(space
);
1135 if (dst_type
== src_type
&& dst_pos
== src_pos
)
1138 isl_assert(space
->ctx
, dst_type
!= src_type
, goto error
);
1140 space
= isl_space_cow(space
);
1146 enum isl_dim_type t
, o
= isl_dim_param
;
1149 ids
= isl_calloc_array(space
->ctx
, isl_id
*,
1150 space
->nparam
+ space
->n_in
+ space
->n_out
);
1154 s
[isl_dim_param
- o
] = space
->nparam
;
1155 s
[isl_dim_in
- o
] = space
->n_in
;
1156 s
[isl_dim_out
- o
] = space
->n_out
;
1157 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1158 if (t
== dst_type
) {
1159 get_ids(space
, t
, 0, dst_pos
, ids
+ off
);
1161 get_ids(space
, src_type
, src_pos
, n
, ids
+ off
);
1163 get_ids(space
, t
, dst_pos
, s
[t
- o
] - dst_pos
,
1165 off
+= s
[t
- o
] - dst_pos
;
1166 } else if (t
== src_type
) {
1167 get_ids(space
, t
, 0, src_pos
, ids
+ off
);
1169 get_ids(space
, t
, src_pos
+ n
,
1170 s
[t
- o
] - src_pos
- n
, ids
+ off
);
1171 off
+= s
[t
- o
] - src_pos
- n
;
1173 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1179 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
;
1183 case isl_dim_param
: space
->nparam
+= n
; break;
1184 case isl_dim_in
: space
->n_in
+= n
; break;
1185 case isl_dim_out
: space
->n_out
+= n
; break;
1190 case isl_dim_param
: space
->nparam
-= n
; break;
1191 case isl_dim_in
: space
->n_in
-= n
; break;
1192 case isl_dim_out
: space
->n_out
-= n
; break;
1196 if (dst_type
!= isl_dim_param
&& src_type
!= isl_dim_param
)
1199 for (i
= 0; i
< 2; ++i
) {
1200 if (!space
->nested
[i
])
1202 space
->nested
[i
] = isl_space_replace_params(space
->nested
[i
],
1204 if (!space
->nested
[i
])
1210 isl_space_free(space
);
1214 /* Check that "space1" and "space2" have the same parameters,
1215 * reporting an error if they do not.
1217 isl_stat
isl_space_check_equal_params(__isl_keep isl_space
*space1
,
1218 __isl_keep isl_space
*space2
)
1222 equal
= isl_space_has_equal_params(space1
, space2
);
1224 return isl_stat_error
;
1226 isl_die(isl_space_get_ctx(space1
), isl_error_invalid
,
1227 "parameters need to match", return isl_stat_error
);
1231 __isl_give isl_space
*isl_space_join(__isl_take isl_space
*left
,
1232 __isl_take isl_space
*right
)
1236 if (isl_space_check_equal_params(left
, right
) < 0)
1239 isl_assert(left
->ctx
,
1240 isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_in
),
1243 space
= isl_space_alloc(left
->ctx
,
1244 left
->nparam
, left
->n_in
, right
->n_out
);
1248 space
= copy_ids(space
, isl_dim_param
, 0, left
, isl_dim_param
);
1249 space
= copy_ids(space
, isl_dim_in
, 0, left
, isl_dim_in
);
1250 space
= copy_ids(space
, isl_dim_out
, 0, right
, isl_dim_out
);
1252 if (space
&& left
->tuple_id
[0] &&
1253 !(space
->tuple_id
[0] = isl_id_copy(left
->tuple_id
[0])))
1255 if (space
&& right
->tuple_id
[1] &&
1256 !(space
->tuple_id
[1] = isl_id_copy(right
->tuple_id
[1])))
1258 if (space
&& left
->nested
[0] &&
1259 !(space
->nested
[0] = isl_space_copy(left
->nested
[0])))
1261 if (space
&& right
->nested
[1] &&
1262 !(space
->nested
[1] = isl_space_copy(right
->nested
[1])))
1265 isl_space_free(left
);
1266 isl_space_free(right
);
1270 isl_space_free(left
);
1271 isl_space_free(right
);
1275 /* Given two map spaces { A -> C } and { B -> D }, construct the space
1276 * { [A -> B] -> [C -> D] }.
1277 * Given two set spaces { A } and { B }, construct the space { [A -> B] }.
1279 __isl_give isl_space
*isl_space_product(__isl_take isl_space
*left
,
1280 __isl_take isl_space
*right
)
1282 isl_space
*dom1
, *dom2
, *nest1
, *nest2
;
1285 if (!left
|| !right
)
1288 is_set
= isl_space_is_set(left
);
1289 if (is_set
!= isl_space_is_set(right
))
1290 isl_die(isl_space_get_ctx(left
), isl_error_invalid
,
1291 "expecting either two set spaces or two map spaces",
1294 return isl_space_range_product(left
, right
);
1296 if (isl_space_check_equal_params(left
, right
) < 0)
1299 dom1
= isl_space_domain(isl_space_copy(left
));
1300 dom2
= isl_space_domain(isl_space_copy(right
));
1301 nest1
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1303 dom1
= isl_space_range(left
);
1304 dom2
= isl_space_range(right
);
1305 nest2
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1307 return isl_space_join(isl_space_reverse(nest1
), nest2
);
1309 isl_space_free(left
);
1310 isl_space_free(right
);
1314 /* Given two spaces { A -> C } and { B -> C }, construct the space
1317 __isl_give isl_space
*isl_space_domain_product(__isl_take isl_space
*left
,
1318 __isl_take isl_space
*right
)
1320 isl_space
*ran
, *dom1
, *dom2
, *nest
;
1322 if (isl_space_check_equal_params(left
, right
) < 0)
1325 if (!isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_out
))
1326 isl_die(left
->ctx
, isl_error_invalid
,
1327 "ranges need to match", goto error
);
1329 ran
= isl_space_range(isl_space_copy(left
));
1331 dom1
= isl_space_domain(left
);
1332 dom2
= isl_space_domain(right
);
1333 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1335 return isl_space_join(isl_space_reverse(nest
), ran
);
1337 isl_space_free(left
);
1338 isl_space_free(right
);
1342 __isl_give isl_space
*isl_space_range_product(__isl_take isl_space
*left
,
1343 __isl_take isl_space
*right
)
1345 isl_space
*dom
, *ran1
, *ran2
, *nest
;
1347 if (isl_space_check_equal_params(left
, right
) < 0)
1350 if (!isl_space_tuple_is_equal(left
, isl_dim_in
, right
, isl_dim_in
))
1351 isl_die(left
->ctx
, isl_error_invalid
,
1352 "domains need to match", goto error
);
1354 dom
= isl_space_domain(isl_space_copy(left
));
1356 ran1
= isl_space_range(left
);
1357 ran2
= isl_space_range(right
);
1358 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(ran1
), ran2
));
1360 return isl_space_join(isl_space_reverse(dom
), nest
);
1362 isl_space_free(left
);
1363 isl_space_free(right
);
1367 /* Given a space of the form [A -> B] -> C, return the space A -> C.
1369 __isl_give isl_space
*isl_space_domain_factor_domain(
1370 __isl_take isl_space
*space
)
1377 if (!isl_space_domain_is_wrapping(space
))
1378 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1379 "domain not a product", return isl_space_free(space
));
1381 nested
= space
->nested
[0];
1382 domain
= isl_space_copy(space
);
1383 domain
= isl_space_drop_dims(domain
, isl_dim_in
,
1384 nested
->n_in
, nested
->n_out
);
1386 return isl_space_free(space
);
1387 if (nested
->tuple_id
[0]) {
1388 domain
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[0]);
1389 if (!domain
->tuple_id
[0])
1392 if (nested
->nested
[0]) {
1393 domain
->nested
[0] = isl_space_copy(nested
->nested
[0]);
1394 if (!domain
->nested
[0])
1398 isl_space_free(space
);
1401 isl_space_free(space
);
1402 isl_space_free(domain
);
1406 /* Given a space of the form [A -> B] -> C, return the space B -> C.
1408 __isl_give isl_space
*isl_space_domain_factor_range(
1409 __isl_take isl_space
*space
)
1416 if (!isl_space_domain_is_wrapping(space
))
1417 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1418 "domain not a product", return isl_space_free(space
));
1420 nested
= space
->nested
[0];
1421 range
= isl_space_copy(space
);
1422 range
= isl_space_drop_dims(range
, isl_dim_in
, 0, nested
->n_in
);
1424 return isl_space_free(space
);
1425 if (nested
->tuple_id
[1]) {
1426 range
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[1]);
1427 if (!range
->tuple_id
[0])
1430 if (nested
->nested
[1]) {
1431 range
->nested
[0] = isl_space_copy(nested
->nested
[1]);
1432 if (!range
->nested
[0])
1436 isl_space_free(space
);
1439 isl_space_free(space
);
1440 isl_space_free(range
);
1444 /* Internal function that selects the domain of the map that is
1445 * embedded in either a set space or the range of a map space.
1446 * In particular, given a space of the form [A -> B], return the space A.
1447 * Given a space of the form A -> [B -> C], return the space A -> B.
1449 static __isl_give isl_space
*range_factor_domain(__isl_take isl_space
*space
)
1457 nested
= space
->nested
[1];
1458 domain
= isl_space_copy(space
);
1459 domain
= isl_space_drop_dims(domain
, isl_dim_out
,
1460 nested
->n_in
, nested
->n_out
);
1462 return isl_space_free(space
);
1463 if (nested
->tuple_id
[0]) {
1464 domain
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[0]);
1465 if (!domain
->tuple_id
[1])
1468 if (nested
->nested
[0]) {
1469 domain
->nested
[1] = isl_space_copy(nested
->nested
[0]);
1470 if (!domain
->nested
[1])
1474 isl_space_free(space
);
1477 isl_space_free(space
);
1478 isl_space_free(domain
);
1482 /* Given a space of the form A -> [B -> C], return the space A -> B.
1484 __isl_give isl_space
*isl_space_range_factor_domain(
1485 __isl_take isl_space
*space
)
1489 if (!isl_space_range_is_wrapping(space
))
1490 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1491 "range not a product", return isl_space_free(space
));
1493 return range_factor_domain(space
);
1496 /* Given a space of the form [A -> B], return the space A.
1498 static __isl_give isl_space
*set_factor_domain(__isl_take isl_space
*space
)
1502 if (!isl_space_is_wrapping(space
))
1503 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1504 "not a product", return isl_space_free(space
));
1506 return range_factor_domain(space
);
1509 /* Given a space of the form [A -> B] -> [C -> D], return the space A -> C.
1510 * Given a space of the form [A -> B], return the space A.
1512 __isl_give isl_space
*isl_space_factor_domain(__isl_take isl_space
*space
)
1516 if (isl_space_is_set(space
))
1517 return set_factor_domain(space
);
1518 space
= isl_space_domain_factor_domain(space
);
1519 space
= isl_space_range_factor_domain(space
);
1523 /* Internal function that selects the range of the map that is
1524 * embedded in either a set space or the range of a map space.
1525 * In particular, given a space of the form [A -> B], return the space B.
1526 * Given a space of the form A -> [B -> C], return the space A -> C.
1528 static __isl_give isl_space
*range_factor_range(__isl_take isl_space
*space
)
1536 nested
= space
->nested
[1];
1537 range
= isl_space_copy(space
);
1538 range
= isl_space_drop_dims(range
, isl_dim_out
, 0, nested
->n_in
);
1540 return isl_space_free(space
);
1541 if (nested
->tuple_id
[1]) {
1542 range
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[1]);
1543 if (!range
->tuple_id
[1])
1546 if (nested
->nested
[1]) {
1547 range
->nested
[1] = isl_space_copy(nested
->nested
[1]);
1548 if (!range
->nested
[1])
1552 isl_space_free(space
);
1555 isl_space_free(space
);
1556 isl_space_free(range
);
1560 /* Given a space of the form A -> [B -> C], return the space A -> C.
1562 __isl_give isl_space
*isl_space_range_factor_range(
1563 __isl_take isl_space
*space
)
1567 if (!isl_space_range_is_wrapping(space
))
1568 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1569 "range not a product", return isl_space_free(space
));
1571 return range_factor_range(space
);
1574 /* Given a space of the form [A -> B], return the space B.
1576 static __isl_give isl_space
*set_factor_range(__isl_take isl_space
*space
)
1580 if (!isl_space_is_wrapping(space
))
1581 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1582 "not a product", return isl_space_free(space
));
1584 return range_factor_range(space
);
1587 /* Given a space of the form [A -> B] -> [C -> D], return the space B -> D.
1588 * Given a space of the form [A -> B], return the space B.
1590 __isl_give isl_space
*isl_space_factor_range(__isl_take isl_space
*space
)
1594 if (isl_space_is_set(space
))
1595 return set_factor_range(space
);
1596 space
= isl_space_domain_factor_range(space
);
1597 space
= isl_space_range_factor_range(space
);
1601 __isl_give isl_space
*isl_space_map_from_set(__isl_take isl_space
*space
)
1604 isl_id
**ids
= NULL
;
1609 ctx
= isl_space_get_ctx(space
);
1610 if (!isl_space_is_set(space
))
1611 isl_die(ctx
, isl_error_invalid
, "not a set space", goto error
);
1612 space
= isl_space_cow(space
);
1615 n_id
= space
->nparam
+ space
->n_out
+ space
->n_out
;
1616 if (n_id
> 0 && space
->ids
) {
1617 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n_id
);
1620 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
1621 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1622 ids
+ space
->nparam
);
1624 space
->n_in
= space
->n_out
;
1629 space
= copy_ids(space
, isl_dim_out
, 0, space
, isl_dim_in
);
1631 isl_id_free(space
->tuple_id
[0]);
1632 space
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[1]);
1633 isl_space_free(space
->nested
[0]);
1634 space
->nested
[0] = isl_space_copy(space
->nested
[1]);
1637 isl_space_free(space
);
1641 __isl_give isl_space
*isl_space_map_from_domain_and_range(
1642 __isl_take isl_space
*domain
, __isl_take isl_space
*range
)
1644 if (!domain
|| !range
)
1646 if (!isl_space_is_set(domain
))
1647 isl_die(isl_space_get_ctx(domain
), isl_error_invalid
,
1648 "domain is not a set space", goto error
);
1649 if (!isl_space_is_set(range
))
1650 isl_die(isl_space_get_ctx(range
), isl_error_invalid
,
1651 "range is not a set space", goto error
);
1652 return isl_space_join(isl_space_reverse(domain
), range
);
1654 isl_space_free(domain
);
1655 isl_space_free(range
);
1659 static __isl_give isl_space
*set_ids(__isl_take isl_space
*dim
,
1660 enum isl_dim_type type
,
1661 unsigned first
, unsigned n
, __isl_take isl_id
**ids
)
1665 for (i
= 0; i
< n
; ++i
)
1666 dim
= set_id(dim
, type
, first
+ i
, ids
[i
]);
1671 __isl_give isl_space
*isl_space_reverse(__isl_take isl_space
*space
)
1675 isl_id
**ids
= NULL
;
1680 if (match(space
, isl_dim_in
, space
, isl_dim_out
))
1683 space
= isl_space_cow(space
);
1687 id
= space
->tuple_id
[0];
1688 space
->tuple_id
[0] = space
->tuple_id
[1];
1689 space
->tuple_id
[1] = id
;
1691 nested
= space
->nested
[0];
1692 space
->nested
[0] = space
->nested
[1];
1693 space
->nested
[1] = nested
;
1696 int n_id
= space
->n_in
+ space
->n_out
;
1697 ids
= isl_alloc_array(space
->ctx
, isl_id
*, n_id
);
1700 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
);
1701 get_ids(space
, isl_dim_out
, 0, space
->n_out
, ids
+ space
->n_in
);
1705 space
->n_in
= space
->n_out
;
1709 space
= set_ids(space
, isl_dim_out
, 0, space
->n_out
, ids
);
1710 space
= set_ids(space
, isl_dim_in
, 0, space
->n_in
,
1711 ids
+ space
->n_out
);
1718 isl_space_free(space
);
1722 __isl_give isl_space
*isl_space_drop_dims(__isl_take isl_space
*space
,
1723 enum isl_dim_type type
, unsigned first
, unsigned num
)
1731 return isl_space_reset(space
, type
);
1733 if (!valid_dim_type(type
))
1734 isl_die(space
->ctx
, isl_error_invalid
,
1735 "cannot drop dimensions of specified type", goto error
);
1737 if (isl_space_check_range(space
, type
, first
, num
) < 0)
1738 return isl_space_free(space
);
1739 space
= isl_space_cow(space
);
1743 space
= extend_ids(space
);
1746 for (i
= 0; i
< num
; ++i
)
1747 isl_id_free(get_id(space
, type
, first
+ i
));
1748 for (i
= first
+num
; i
< n(space
, type
); ++i
)
1749 set_id(space
, type
, i
- num
, get_id(space
, type
, i
));
1752 get_ids(space
, isl_dim_in
, 0, space
->n_in
,
1753 space
->ids
+ offset(space
, isl_dim_in
) - num
);
1755 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1756 space
->ids
+ offset(space
, isl_dim_out
) - num
);
1763 case isl_dim_param
: space
->nparam
-= num
; break;
1764 case isl_dim_in
: space
->n_in
-= num
; break;
1765 case isl_dim_out
: space
->n_out
-= num
; break;
1768 space
= isl_space_reset(space
, type
);
1769 if (type
== isl_dim_param
) {
1770 if (space
&& space
->nested
[0] &&
1771 !(space
->nested
[0] = isl_space_drop_dims(space
->nested
[0],
1772 isl_dim_param
, first
, num
)))
1774 if (space
&& space
->nested
[1] &&
1775 !(space
->nested
[1] = isl_space_drop_dims(space
->nested
[1],
1776 isl_dim_param
, first
, num
)))
1781 isl_space_free(space
);
1785 __isl_give isl_space
*isl_space_drop_inputs(__isl_take isl_space
*dim
,
1786 unsigned first
, unsigned n
)
1790 return isl_space_drop_dims(dim
, isl_dim_in
, first
, n
);
1793 __isl_give isl_space
*isl_space_drop_outputs(__isl_take isl_space
*dim
,
1794 unsigned first
, unsigned n
)
1798 return isl_space_drop_dims(dim
, isl_dim_out
, first
, n
);
1801 /* Remove all parameters from "space".
1803 __isl_give isl_space
*isl_space_drop_all_params(__isl_take isl_space
*space
)
1807 nparam
= isl_space_dim(space
, isl_dim_param
);
1808 return isl_space_drop_dims(space
, isl_dim_param
, 0, nparam
);
1811 __isl_give isl_space
*isl_space_domain(__isl_take isl_space
*space
)
1815 space
= isl_space_drop_dims(space
, isl_dim_out
, 0, space
->n_out
);
1816 space
= isl_space_reverse(space
);
1817 space
= mark_as_set(space
);
1821 __isl_give isl_space
*isl_space_from_domain(__isl_take isl_space
*space
)
1825 if (!isl_space_is_set(space
))
1826 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1827 "not a set space", goto error
);
1828 space
= isl_space_reverse(space
);
1829 space
= isl_space_reset(space
, isl_dim_out
);
1832 isl_space_free(space
);
1836 __isl_give isl_space
*isl_space_range(__isl_take isl_space
*space
)
1840 space
= isl_space_drop_dims(space
, isl_dim_in
, 0, space
->n_in
);
1841 space
= mark_as_set(space
);
1845 __isl_give isl_space
*isl_space_from_range(__isl_take isl_space
*space
)
1849 if (!isl_space_is_set(space
))
1850 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1851 "not a set space", goto error
);
1852 return isl_space_reset(space
, isl_dim_in
);
1854 isl_space_free(space
);
1858 /* Given a map space A -> B, return the map space [A -> B] -> A.
1860 __isl_give isl_space
*isl_space_domain_map(__isl_take isl_space
*space
)
1864 domain
= isl_space_from_range(isl_space_domain(isl_space_copy(space
)));
1865 space
= isl_space_from_domain(isl_space_wrap(space
));
1866 space
= isl_space_join(space
, domain
);
1871 /* Given a map space A -> B, return the map space [A -> B] -> B.
1873 __isl_give isl_space
*isl_space_range_map(__isl_take isl_space
*space
)
1877 range
= isl_space_from_range(isl_space_range(isl_space_copy(space
)));
1878 space
= isl_space_from_domain(isl_space_wrap(space
));
1879 space
= isl_space_join(space
, range
);
1884 __isl_give isl_space
*isl_space_params(__isl_take isl_space
*space
)
1886 if (isl_space_is_params(space
))
1888 space
= isl_space_drop_dims(space
,
1889 isl_dim_in
, 0, isl_space_dim(space
, isl_dim_in
));
1890 space
= isl_space_drop_dims(space
,
1891 isl_dim_out
, 0, isl_space_dim(space
, isl_dim_out
));
1892 space
= mark_as_params(space
);
1896 __isl_give isl_space
*isl_space_set_from_params(__isl_take isl_space
*space
)
1900 if (!isl_space_is_params(space
))
1901 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1902 "not a parameter space", goto error
);
1903 return isl_space_reset(space
, isl_dim_set
);
1905 isl_space_free(space
);
1909 __isl_give isl_space
*isl_space_underlying(__isl_take isl_space
*space
,
1915 is_set
= isl_space_is_set(space
);
1917 return isl_space_free(space
);
1918 if (n_div
== 0 && is_set
&&
1919 space
->nparam
== 0 && space
->n_in
== 0 && space
->n_id
== 0)
1920 return isl_space_reset(space
, isl_dim_out
);
1921 space
= isl_space_cow(space
);
1924 space
->n_out
+= space
->nparam
+ space
->n_in
+ n_div
;
1928 for (i
= 0; i
< space
->n_id
; ++i
)
1929 isl_id_free(get_id(space
, isl_dim_out
, i
));
1931 space
= isl_space_reset(space
, isl_dim_in
);
1932 space
= isl_space_reset(space
, isl_dim_out
);
1933 space
= mark_as_set(space
);
1938 /* Are the two spaces the same, including positions and names of parameters?
1940 isl_bool
isl_space_is_equal(__isl_keep isl_space
*space1
,
1941 __isl_keep isl_space
*space2
)
1945 if (!space1
|| !space2
)
1946 return isl_bool_error
;
1947 if (space1
== space2
)
1948 return isl_bool_true
;
1949 equal
= isl_space_has_equal_params(space1
, space2
);
1950 if (equal
< 0 || !equal
)
1952 return isl_space_has_equal_tuples(space1
, space2
);
1955 /* Do the tuples of "space1" correspond to those of the domain of "space2"?
1956 * That is, is "space1" eqaul to the domain of "space2", ignoring parameters.
1958 * "space2" is allowed to be a set space, in which case "space1"
1959 * should be a parameter space.
1961 isl_bool
isl_space_has_domain_tuples(__isl_keep isl_space
*space1
,
1962 __isl_keep isl_space
*space2
)
1966 is_set
= isl_space_is_set(space1
);
1967 if (is_set
< 0 || !is_set
)
1969 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
1970 space2
, isl_dim_in
);
1973 /* Is space1 equal to the domain of space2?
1975 * In the internal version we also allow space2 to be the space of a set,
1976 * provided space1 is a parameter space.
1978 isl_bool
isl_space_is_domain_internal(__isl_keep isl_space
*space1
,
1979 __isl_keep isl_space
*space2
)
1981 isl_bool equal_params
;
1983 if (!space1
|| !space2
)
1984 return isl_bool_error
;
1985 equal_params
= isl_space_has_equal_params(space1
, space2
);
1986 if (equal_params
< 0 || !equal_params
)
1987 return equal_params
;
1988 return isl_space_has_domain_tuples(space1
, space2
);
1991 /* Is space1 equal to the domain of space2?
1993 isl_bool
isl_space_is_domain(__isl_keep isl_space
*space1
,
1994 __isl_keep isl_space
*space2
)
1997 return isl_bool_error
;
1998 if (!isl_space_is_map(space2
))
1999 return isl_bool_false
;
2000 return isl_space_is_domain_internal(space1
, space2
);
2003 /* Is space1 equal to the range of space2?
2005 * In the internal version, space2 is allowed to be the space of a set,
2006 * in which case it should be equal to space1.
2008 isl_bool
isl_space_is_range_internal(__isl_keep isl_space
*space1
,
2009 __isl_keep isl_space
*space2
)
2011 isl_bool equal_params
;
2013 if (!space1
|| !space2
)
2014 return isl_bool_error
;
2015 if (!isl_space_is_set(space1
))
2016 return isl_bool_false
;
2017 equal_params
= isl_space_has_equal_params(space1
, space2
);
2018 if (equal_params
< 0 || !equal_params
)
2019 return equal_params
;
2020 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
2021 space2
, isl_dim_out
);
2024 /* Is space1 equal to the range of space2?
2026 isl_bool
isl_space_is_range(__isl_keep isl_space
*space1
,
2027 __isl_keep isl_space
*space2
)
2030 return isl_bool_error
;
2031 if (!isl_space_is_map(space2
))
2032 return isl_bool_false
;
2033 return isl_space_is_range_internal(space1
, space2
);
2036 /* Update "hash" by hashing in the parameters of "space".
2038 static uint32_t isl_hash_params(uint32_t hash
, __isl_keep isl_space
*space
)
2046 isl_hash_byte(hash
, space
->nparam
% 256);
2048 for (i
= 0; i
< space
->nparam
; ++i
) {
2049 id
= get_id(space
, isl_dim_param
, i
);
2050 hash
= isl_hash_id(hash
, id
);
2056 /* Update "hash" by hashing in the tuples of "space".
2057 * Changes in this function should be reflected in isl_hash_tuples_domain.
2059 static uint32_t isl_hash_tuples(uint32_t hash
, __isl_keep isl_space
*space
)
2066 isl_hash_byte(hash
, space
->n_in
% 256);
2067 isl_hash_byte(hash
, space
->n_out
% 256);
2069 id
= tuple_id(space
, isl_dim_in
);
2070 hash
= isl_hash_id(hash
, id
);
2071 id
= tuple_id(space
, isl_dim_out
);
2072 hash
= isl_hash_id(hash
, id
);
2074 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2075 hash
= isl_hash_tuples(hash
, space
->nested
[1]);
2080 /* Update "hash" by hashing in the domain tuple of "space".
2081 * The result of this function is equal to the result of applying
2082 * isl_hash_tuples to the domain of "space".
2084 static uint32_t isl_hash_tuples_domain(uint32_t hash
,
2085 __isl_keep isl_space
*space
)
2092 isl_hash_byte(hash
, 0);
2093 isl_hash_byte(hash
, space
->n_in
% 256);
2095 hash
= isl_hash_id(hash
, &isl_id_none
);
2096 id
= tuple_id(space
, isl_dim_in
);
2097 hash
= isl_hash_id(hash
, id
);
2099 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2104 /* Return a hash value that digests the tuples of "space",
2105 * i.e., that ignores the parameters.
2107 uint32_t isl_space_get_tuple_hash(__isl_keep isl_space
*space
)
2114 hash
= isl_hash_init();
2115 hash
= isl_hash_tuples(hash
, space
);
2120 uint32_t isl_space_get_hash(__isl_keep isl_space
*space
)
2127 hash
= isl_hash_init();
2128 hash
= isl_hash_params(hash
, space
);
2129 hash
= isl_hash_tuples(hash
, space
);
2134 /* Return the hash value of the domain of "space".
2135 * That is, isl_space_get_domain_hash(space) is equal to
2136 * isl_space_get_hash(isl_space_domain(space)).
2138 uint32_t isl_space_get_domain_hash(__isl_keep isl_space
*space
)
2145 hash
= isl_hash_init();
2146 hash
= isl_hash_params(hash
, space
);
2147 hash
= isl_hash_tuples_domain(hash
, space
);
2152 /* Is "space" the space of a set wrapping a map space?
2154 isl_bool
isl_space_is_wrapping(__isl_keep isl_space
*space
)
2157 return isl_bool_error
;
2159 if (!isl_space_is_set(space
))
2160 return isl_bool_false
;
2162 return space
->nested
[1] != NULL
;
2165 /* Is "space" the space of a map where the domain is a wrapped map space?
2167 isl_bool
isl_space_domain_is_wrapping(__isl_keep isl_space
*space
)
2170 return isl_bool_error
;
2172 if (isl_space_is_set(space
))
2173 return isl_bool_false
;
2175 return space
->nested
[0] != NULL
;
2178 /* Is "space" the space of a map where the range is a wrapped map space?
2180 isl_bool
isl_space_range_is_wrapping(__isl_keep isl_space
*space
)
2183 return isl_bool_error
;
2185 if (isl_space_is_set(space
))
2186 return isl_bool_false
;
2188 return space
->nested
[1] != NULL
;
2191 /* Is "space" a product of two spaces?
2192 * That is, is it a wrapping set space or a map space
2193 * with wrapping domain and range?
2195 isl_bool
isl_space_is_product(__isl_keep isl_space
*space
)
2198 isl_bool is_product
;
2200 is_set
= isl_space_is_set(space
);
2202 return isl_bool_error
;
2204 return isl_space_is_wrapping(space
);
2205 is_product
= isl_space_domain_is_wrapping(space
);
2206 if (is_product
< 0 || !is_product
)
2208 return isl_space_range_is_wrapping(space
);
2211 __isl_give isl_space
*isl_space_wrap(__isl_take isl_space
*space
)
2218 wrap
= isl_space_set_alloc(space
->ctx
,
2219 space
->nparam
, space
->n_in
+ space
->n_out
);
2221 wrap
= copy_ids(wrap
, isl_dim_param
, 0, space
, isl_dim_param
);
2222 wrap
= copy_ids(wrap
, isl_dim_set
, 0, space
, isl_dim_in
);
2223 wrap
= copy_ids(wrap
, isl_dim_set
, space
->n_in
, space
, isl_dim_out
);
2228 wrap
->nested
[1] = space
;
2232 isl_space_free(space
);
2236 __isl_give isl_space
*isl_space_unwrap(__isl_take isl_space
*space
)
2243 if (!isl_space_is_wrapping(space
))
2244 isl_die(space
->ctx
, isl_error_invalid
, "not a wrapping space",
2247 unwrap
= isl_space_copy(space
->nested
[1]);
2248 isl_space_free(space
);
2252 isl_space_free(space
);
2256 isl_bool
isl_space_is_named_or_nested(__isl_keep isl_space
*space
,
2257 enum isl_dim_type type
)
2259 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
2260 return isl_bool_false
;
2262 return isl_bool_error
;
2263 if (space
->tuple_id
[type
- isl_dim_in
])
2264 return isl_bool_true
;
2265 if (space
->nested
[type
- isl_dim_in
])
2266 return isl_bool_true
;
2267 return isl_bool_false
;
2270 isl_bool
isl_space_may_be_set(__isl_keep isl_space
*space
)
2275 return isl_bool_error
;
2276 if (isl_space_is_set(space
))
2277 return isl_bool_true
;
2278 if (isl_space_dim(space
, isl_dim_in
) != 0)
2279 return isl_bool_false
;
2280 nested
= isl_space_is_named_or_nested(space
, isl_dim_in
);
2281 if (nested
< 0 || nested
)
2282 return isl_bool_not(nested
);
2283 return isl_bool_true
;
2286 __isl_give isl_space
*isl_space_reset(__isl_take isl_space
*space
,
2287 enum isl_dim_type type
)
2289 if (!isl_space_is_named_or_nested(space
, type
))
2292 space
= isl_space_cow(space
);
2296 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
2297 space
->tuple_id
[type
- isl_dim_in
] = NULL
;
2298 isl_space_free(space
->nested
[type
- isl_dim_in
]);
2299 space
->nested
[type
- isl_dim_in
] = NULL
;
2304 __isl_give isl_space
*isl_space_flatten(__isl_take isl_space
*space
)
2308 if (!space
->nested
[0] && !space
->nested
[1])
2311 if (space
->nested
[0])
2312 space
= isl_space_reset(space
, isl_dim_in
);
2313 if (space
&& space
->nested
[1])
2314 space
= isl_space_reset(space
, isl_dim_out
);
2319 __isl_give isl_space
*isl_space_flatten_domain(__isl_take isl_space
*space
)
2323 if (!space
->nested
[0])
2326 return isl_space_reset(space
, isl_dim_in
);
2329 __isl_give isl_space
*isl_space_flatten_range(__isl_take isl_space
*space
)
2333 if (!space
->nested
[1])
2336 return isl_space_reset(space
, isl_dim_out
);
2339 /* Replace the parameters of dst by those of src.
2341 __isl_give isl_space
*isl_space_replace_params(__isl_take isl_space
*dst
,
2342 __isl_keep isl_space
*src
)
2344 isl_bool equal_params
;
2345 enum isl_dim_type type
= isl_dim_param
;
2347 equal_params
= isl_space_has_equal_params(dst
, src
);
2348 if (equal_params
< 0)
2349 return isl_space_free(dst
);
2353 dst
= isl_space_cow(dst
);
2358 dst
= isl_space_drop_dims(dst
, type
, 0, isl_space_dim(dst
, type
));
2359 dst
= isl_space_add_dims(dst
, type
, isl_space_dim(src
, type
));
2360 dst
= copy_ids(dst
, type
, 0, src
, type
);
2364 for (i
= 0; i
<= 1; ++i
) {
2365 if (!dst
->nested
[i
])
2367 dst
->nested
[i
] = isl_space_replace_params(
2368 dst
->nested
[i
], src
);
2369 if (!dst
->nested
[i
])
2376 isl_space_free(dst
);
2380 /* Given a dimension specification "dim" of a set, create a dimension
2381 * specification for the lift of the set. In particular, the result
2382 * is of the form [dim -> local[..]], with n_local variables in the
2383 * range of the wrapped map.
2385 __isl_give isl_space
*isl_space_lift(__isl_take isl_space
*space
,
2388 isl_space
*local_space
;
2393 local_space
= isl_space_dup(space
);
2394 local_space
= isl_space_drop_dims(local_space
, isl_dim_set
, 0,
2396 local_space
= isl_space_add_dims(local_space
, isl_dim_set
, n_local
);
2397 local_space
= isl_space_set_tuple_name(local_space
,
2398 isl_dim_set
, "local");
2399 space
= isl_space_join(isl_space_from_domain(space
),
2400 isl_space_from_range(local_space
));
2401 space
= isl_space_wrap(space
);
2402 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "lifted");
2407 isl_bool
isl_space_can_zip(__isl_keep isl_space
*space
)
2411 is_set
= isl_space_is_set(space
);
2413 return isl_bool_error
;
2415 return isl_bool_false
;
2416 return isl_space_is_product(space
);
2419 __isl_give isl_space
*isl_space_zip(__isl_take isl_space
*space
)
2421 isl_space
*dom
, *ran
;
2422 isl_space
*dom_dom
, *dom_ran
, *ran_dom
, *ran_ran
;
2424 if (!isl_space_can_zip(space
))
2425 isl_die(space
->ctx
, isl_error_invalid
, "dim cannot be zipped",
2430 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(space
)));
2431 ran
= isl_space_unwrap(isl_space_range(space
));
2432 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2433 dom_ran
= isl_space_range(dom
);
2434 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2435 ran_ran
= isl_space_range(ran
);
2436 dom
= isl_space_join(isl_space_from_domain(dom_dom
),
2437 isl_space_from_range(ran_dom
));
2438 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2439 isl_space_from_range(ran_ran
));
2440 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2441 isl_space_from_range(isl_space_wrap(ran
)));
2443 isl_space_free(space
);
2447 /* Can we apply isl_space_curry to "space"?
2448 * That is, does is it have a map space with a nested relation in its domain?
2450 isl_bool
isl_space_can_curry(__isl_keep isl_space
*space
)
2452 return isl_space_domain_is_wrapping(space
);
2455 /* Given a space (A -> B) -> C, return the corresponding space
2458 __isl_give isl_space
*isl_space_curry(__isl_take isl_space
*space
)
2460 isl_space
*dom
, *ran
;
2461 isl_space
*dom_dom
, *dom_ran
;
2466 if (!isl_space_can_curry(space
))
2467 isl_die(space
->ctx
, isl_error_invalid
,
2468 "space cannot be curried", goto error
);
2470 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(space
)));
2471 ran
= isl_space_range(space
);
2472 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2473 dom_ran
= isl_space_range(dom
);
2474 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2475 isl_space_from_range(ran
));
2476 return isl_space_join(isl_space_from_domain(dom_dom
),
2477 isl_space_from_range(isl_space_wrap(ran
)));
2479 isl_space_free(space
);
2483 /* Can isl_space_range_curry be applied to "space"?
2484 * That is, does it have a nested relation in its range,
2485 * the domain of which is itself a nested relation?
2487 isl_bool
isl_space_can_range_curry(__isl_keep isl_space
*space
)
2492 return isl_bool_error
;
2493 can
= isl_space_range_is_wrapping(space
);
2494 if (can
< 0 || !can
)
2496 return isl_space_can_curry(space
->nested
[1]);
2499 /* Given a space A -> ((B -> C) -> D), return the corresponding space
2500 * A -> (B -> (C -> D)).
2502 __isl_give isl_space
*isl_space_range_curry(__isl_take isl_space
*space
)
2507 if (!isl_space_can_range_curry(space
))
2508 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2509 "space range cannot be curried",
2510 return isl_space_free(space
));
2512 space
= isl_space_cow(space
);
2515 space
->nested
[1] = isl_space_curry(space
->nested
[1]);
2516 if (!space
->nested
[1])
2517 return isl_space_free(space
);
2522 /* Can we apply isl_space_uncurry to "space"?
2523 * That is, does it have a map space with a nested relation in its range?
2525 isl_bool
isl_space_can_uncurry(__isl_keep isl_space
*space
)
2527 return isl_space_range_is_wrapping(space
);
2530 /* Given a space A -> (B -> C), return the corresponding space
2533 __isl_give isl_space
*isl_space_uncurry(__isl_take isl_space
*space
)
2535 isl_space
*dom
, *ran
;
2536 isl_space
*ran_dom
, *ran_ran
;
2541 if (!isl_space_can_uncurry(space
))
2542 isl_die(space
->ctx
, isl_error_invalid
,
2543 "space cannot be uncurried",
2544 return isl_space_free(space
));
2546 dom
= isl_space_domain(isl_space_copy(space
));
2547 ran
= isl_space_unwrap(isl_space_range(space
));
2548 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2549 ran_ran
= isl_space_range(ran
);
2550 dom
= isl_space_join(isl_space_from_domain(dom
),
2551 isl_space_from_range(ran_dom
));
2552 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2553 isl_space_from_range(ran_ran
));
2556 isl_bool
isl_space_has_named_params(__isl_keep isl_space
*space
)
2562 return isl_bool_error
;
2563 if (space
->nparam
== 0)
2564 return isl_bool_true
;
2565 off
= isl_space_offset(space
, isl_dim_param
);
2566 if (off
+ space
->nparam
> space
->n_id
)
2567 return isl_bool_false
;
2568 for (i
= 0; i
< space
->nparam
; ++i
)
2569 if (!space
->ids
[off
+ i
])
2570 return isl_bool_false
;
2571 return isl_bool_true
;
2574 /* Check that "space" has only named parameters, reporting an error
2577 isl_stat
isl_space_check_named_params(__isl_keep isl_space
*space
)
2581 named
= isl_space_has_named_params(space
);
2583 return isl_stat_error
;
2585 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2586 "unexpected unnamed parameters", return isl_stat_error
);
2591 /* Align the initial parameters of space1 to match the order in space2.
2593 __isl_give isl_space
*isl_space_align_params(__isl_take isl_space
*space1
,
2594 __isl_take isl_space
*space2
)
2596 isl_reordering
*exp
;
2598 if (isl_space_check_named_params(space1
) < 0 ||
2599 isl_space_check_named_params(space2
) < 0)
2602 exp
= isl_parameter_alignment_reordering(space1
, space2
);
2603 exp
= isl_reordering_extend_space(exp
, space1
);
2604 isl_space_free(space2
);
2605 space1
= isl_reordering_get_space(exp
);
2606 isl_reordering_free(exp
);
2609 isl_space_free(space1
);
2610 isl_space_free(space2
);
2614 /* Given the space of set (domain), construct a space for a map
2615 * with as domain the given space and as range the range of "model".
2617 __isl_give isl_space
*isl_space_extend_domain_with_range(
2618 __isl_take isl_space
*space
, __isl_take isl_space
*model
)
2623 space
= isl_space_from_domain(space
);
2624 space
= isl_space_add_dims(space
, isl_dim_out
,
2625 isl_space_dim(model
, isl_dim_out
));
2626 if (isl_space_has_tuple_id(model
, isl_dim_out
))
2627 space
= isl_space_set_tuple_id(space
, isl_dim_out
,
2628 isl_space_get_tuple_id(model
, isl_dim_out
));
2631 if (model
->nested
[1]) {
2632 isl_space
*nested
= isl_space_copy(model
->nested
[1]);
2633 int n_nested
, n_space
;
2634 nested
= isl_space_align_params(nested
, isl_space_copy(space
));
2635 n_nested
= isl_space_dim(nested
, isl_dim_param
);
2636 n_space
= isl_space_dim(space
, isl_dim_param
);
2637 if (n_nested
> n_space
)
2638 nested
= isl_space_drop_dims(nested
, isl_dim_param
,
2639 n_space
, n_nested
- n_space
);
2642 space
->nested
[1] = nested
;
2644 isl_space_free(model
);
2647 isl_space_free(model
);
2648 isl_space_free(space
);
2652 /* Compare the "type" dimensions of two isl_spaces.
2654 * The order is fairly arbitrary.
2656 static int isl_space_cmp_type(__isl_keep isl_space
*space1
,
2657 __isl_keep isl_space
*space2
, enum isl_dim_type type
)
2660 isl_space
*nested1
, *nested2
;
2662 if (isl_space_dim(space1
, type
) != isl_space_dim(space2
, type
))
2663 return isl_space_dim(space1
, type
) -
2664 isl_space_dim(space2
, type
);
2666 cmp
= isl_id_cmp(tuple_id(space1
, type
), tuple_id(space2
, type
));
2670 nested1
= nested(space1
, type
);
2671 nested2
= nested(space2
, type
);
2672 if (!nested1
!= !nested2
)
2673 return !nested1
- !nested2
;
2676 return isl_space_cmp(nested1
, nested2
);
2681 /* Compare two isl_spaces.
2683 * The order is fairly arbitrary.
2685 int isl_space_cmp(__isl_keep isl_space
*space1
, __isl_keep isl_space
*space2
)
2690 if (space1
== space2
)
2697 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_param
);
2700 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_in
);
2703 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_out
);
2707 if (!space1
->ids
&& !space2
->ids
)
2710 for (i
= 0; i
< n(space1
, isl_dim_param
); ++i
) {
2711 cmp
= isl_id_cmp(get_id(space1
, isl_dim_param
, i
),
2712 get_id(space2
, isl_dim_param
, i
));