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
;
158 isl_assert(ctx
, pos
< space
->nparam
,
159 return isl_space_dim(space
, isl_dim_all
));
162 isl_assert(ctx
, pos
< space
->n_in
,
163 return isl_space_dim(space
, isl_dim_all
));
164 return pos
+ space
->nparam
;
166 isl_assert(ctx
, pos
< space
->n_out
,
167 return isl_space_dim(space
, isl_dim_all
));
168 return pos
+ space
->nparam
+ space
->n_in
;
170 isl_assert(ctx
, 0, return isl_space_dim(space
, isl_dim_all
));
172 return isl_space_dim(space
, isl_dim_all
);
175 /* Extend length of ids array to the total number of dimensions.
177 static __isl_give isl_space
*extend_ids(__isl_take isl_space
*space
)
182 if (isl_space_dim(space
, isl_dim_all
) <= space
->n_id
)
186 space
->ids
= isl_calloc_array(space
->ctx
,
187 isl_id
*, isl_space_dim(space
, isl_dim_all
));
191 ids
= isl_realloc_array(space
->ctx
, space
->ids
,
192 isl_id
*, isl_space_dim(space
, isl_dim_all
));
196 for (i
= space
->n_id
; i
< isl_space_dim(space
, isl_dim_all
); ++i
)
197 space
->ids
[i
] = NULL
;
200 space
->n_id
= isl_space_dim(space
, isl_dim_all
);
204 isl_space_free(space
);
208 static __isl_give isl_space
*set_id(__isl_take isl_space
*space
,
209 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
211 space
= isl_space_cow(space
);
216 pos
= global_pos(space
, type
, pos
);
217 if (pos
== isl_space_dim(space
, isl_dim_all
))
220 if (pos
>= space
->n_id
) {
223 space
= extend_ids(space
);
228 space
->ids
[pos
] = id
;
233 isl_space_free(space
);
237 static __isl_keep isl_id
*get_id(__isl_keep isl_space
*space
,
238 enum isl_dim_type type
, unsigned pos
)
243 pos
= global_pos(space
, type
, pos
);
244 if (pos
== isl_space_dim(space
, isl_dim_all
))
246 if (pos
>= space
->n_id
)
248 return space
->ids
[pos
];
251 static unsigned offset(__isl_keep isl_space
*space
, enum isl_dim_type type
)
254 case isl_dim_param
: return 0;
255 case isl_dim_in
: return space
->nparam
;
256 case isl_dim_out
: return space
->nparam
+ space
->n_in
;
261 static unsigned n(__isl_keep isl_space
*space
, enum isl_dim_type type
)
264 case isl_dim_param
: return space
->nparam
;
265 case isl_dim_in
: return space
->n_in
;
266 case isl_dim_out
: return space
->n_out
;
268 return space
->nparam
+ space
->n_in
+ space
->n_out
;
273 unsigned isl_space_dim(__isl_keep isl_space
*space
, enum isl_dim_type type
)
277 return n(space
, type
);
280 unsigned isl_space_offset(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
284 return offset(dim
, type
);
287 static __isl_give isl_space
*copy_ids(__isl_take isl_space
*dst
,
288 enum isl_dim_type dst_type
, unsigned offset
, __isl_keep isl_space
*src
,
289 enum isl_dim_type src_type
)
297 for (i
= 0; i
< n(src
, src_type
); ++i
) {
298 id
= get_id(src
, src_type
, i
);
301 dst
= set_id(dst
, dst_type
, offset
+ i
, isl_id_copy(id
));
308 __isl_take isl_space
*isl_space_dup(__isl_keep isl_space
*space
)
313 dup
= isl_space_alloc(space
->ctx
,
314 space
->nparam
, space
->n_in
, space
->n_out
);
317 if (space
->tuple_id
[0] &&
318 !(dup
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[0])))
320 if (space
->tuple_id
[1] &&
321 !(dup
->tuple_id
[1] = isl_id_copy(space
->tuple_id
[1])))
323 if (space
->nested
[0] &&
324 !(dup
->nested
[0] = isl_space_copy(space
->nested
[0])))
326 if (space
->nested
[1] &&
327 !(dup
->nested
[1] = isl_space_copy(space
->nested
[1])))
331 dup
= copy_ids(dup
, isl_dim_param
, 0, space
, isl_dim_param
);
332 dup
= copy_ids(dup
, isl_dim_in
, 0, space
, isl_dim_in
);
333 dup
= copy_ids(dup
, isl_dim_out
, 0, space
, isl_dim_out
);
340 __isl_give isl_space
*isl_space_cow(__isl_take isl_space
*space
)
348 return isl_space_dup(space
);
351 __isl_give isl_space
*isl_space_copy(__isl_keep isl_space
*dim
)
360 __isl_null isl_space
*isl_space_free(__isl_take isl_space
*space
)
367 if (--space
->ref
> 0)
370 isl_id_free(space
->tuple_id
[0]);
371 isl_id_free(space
->tuple_id
[1]);
373 isl_space_free(space
->nested
[0]);
374 isl_space_free(space
->nested
[1]);
376 for (i
= 0; i
< space
->n_id
; ++i
)
377 isl_id_free(space
->ids
[i
]);
379 isl_ctx_deref(space
->ctx
);
386 /* Check if "s" is a valid dimension or tuple name.
387 * We currently only forbid names that look like a number.
389 * s is assumed to be non-NULL.
391 static int name_ok(isl_ctx
*ctx
, const char *s
)
396 dummy
= strtol(s
, &p
, 0);
398 isl_die(ctx
, isl_error_invalid
, "name looks like a number",
404 /* Is it possible for the given dimension type to have a tuple id?
406 static int space_can_have_id(__isl_keep isl_space
*space
,
407 enum isl_dim_type type
)
411 if (isl_space_is_params(space
))
412 isl_die(space
->ctx
, isl_error_invalid
,
413 "parameter spaces don't have tuple ids", return 0);
414 if (isl_space_is_set(space
) && type
!= isl_dim_set
)
415 isl_die(space
->ctx
, isl_error_invalid
,
416 "set spaces can only have a set id", return 0);
417 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
418 isl_die(space
->ctx
, isl_error_invalid
,
419 "only input, output and set tuples can have ids",
425 /* Does the tuple have an id?
427 isl_bool
isl_space_has_tuple_id(__isl_keep isl_space
*space
,
428 enum isl_dim_type type
)
430 if (!space_can_have_id(space
, type
))
431 return isl_bool_error
;
432 return space
->tuple_id
[type
- isl_dim_in
] != NULL
;
435 __isl_give isl_id
*isl_space_get_tuple_id(__isl_keep isl_space
*space
,
436 enum isl_dim_type type
)
442 has_id
= isl_space_has_tuple_id(space
, type
);
446 isl_die(space
->ctx
, isl_error_invalid
,
447 "tuple has no id", return NULL
);
448 return isl_id_copy(space
->tuple_id
[type
- isl_dim_in
]);
451 __isl_give isl_space
*isl_space_set_tuple_id(__isl_take isl_space
*space
,
452 enum isl_dim_type type
, __isl_take isl_id
*id
)
454 space
= isl_space_cow(space
);
457 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
458 isl_die(space
->ctx
, isl_error_invalid
,
459 "only input, output and set tuples can have names",
462 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
463 space
->tuple_id
[type
- isl_dim_in
] = id
;
468 isl_space_free(space
);
472 __isl_give isl_space
*isl_space_reset_tuple_id(__isl_take isl_space
*space
,
473 enum isl_dim_type type
)
475 space
= isl_space_cow(space
);
478 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
479 isl_die(space
->ctx
, isl_error_invalid
,
480 "only input, output and set tuples can have names",
483 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
484 space
->tuple_id
[type
- isl_dim_in
] = NULL
;
488 isl_space_free(space
);
492 /* Set the id of the given dimension of "space" to "id".
493 * If the dimension already has an id, then it is replaced.
494 * If the dimension is a parameter, then we need to change it
495 * in the nested spaces (if any) as well.
497 __isl_give isl_space
*isl_space_set_dim_id(__isl_take isl_space
*space
,
498 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
500 space
= isl_space_cow(space
);
504 if (type
== isl_dim_param
) {
507 for (i
= 0; i
< 2; ++i
) {
508 if (!space
->nested
[i
])
511 isl_space_set_dim_id(space
->nested
[i
],
512 type
, pos
, isl_id_copy(id
));
513 if (!space
->nested
[i
])
518 isl_id_free(get_id(space
, type
, pos
));
519 return set_id(space
, type
, pos
, id
);
522 isl_space_free(space
);
526 /* Reset the id of the given dimension of "space".
527 * If the dimension already has an id, then it is removed.
528 * If the dimension is a parameter, then we need to reset it
529 * in the nested spaces (if any) as well.
531 __isl_give isl_space
*isl_space_reset_dim_id(__isl_take isl_space
*space
,
532 enum isl_dim_type type
, unsigned pos
)
534 space
= isl_space_cow(space
);
538 if (type
== isl_dim_param
) {
541 for (i
= 0; i
< 2; ++i
) {
542 if (!space
->nested
[i
])
545 isl_space_reset_dim_id(space
->nested
[i
],
547 if (!space
->nested
[i
])
552 isl_id_free(get_id(space
, type
, pos
));
553 return set_id(space
, type
, pos
, NULL
);
555 isl_space_free(space
);
559 isl_bool
isl_space_has_dim_id(__isl_keep isl_space
*space
,
560 enum isl_dim_type type
, unsigned pos
)
563 return isl_bool_error
;
564 return get_id(space
, type
, pos
) != NULL
;
567 __isl_give isl_id
*isl_space_get_dim_id(__isl_keep isl_space
*space
,
568 enum isl_dim_type type
, unsigned pos
)
572 if (!get_id(space
, type
, pos
))
573 isl_die(space
->ctx
, isl_error_invalid
,
574 "dim has no id", return NULL
);
575 return isl_id_copy(get_id(space
, type
, pos
));
578 __isl_give isl_space
*isl_space_set_tuple_name(__isl_take isl_space
*space
,
579 enum isl_dim_type type
, const char *s
)
587 return isl_space_reset_tuple_id(space
, type
);
589 if (!name_ok(space
->ctx
, s
))
592 id
= isl_id_alloc(space
->ctx
, s
, NULL
);
593 return isl_space_set_tuple_id(space
, type
, id
);
595 isl_space_free(space
);
599 /* Does the tuple have a name?
601 isl_bool
isl_space_has_tuple_name(__isl_keep isl_space
*space
,
602 enum isl_dim_type type
)
606 if (!space_can_have_id(space
, type
))
607 return isl_bool_error
;
608 id
= space
->tuple_id
[type
- isl_dim_in
];
609 return id
&& id
->name
;
612 __isl_keep
const char *isl_space_get_tuple_name(__isl_keep isl_space
*space
,
613 enum isl_dim_type type
)
618 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
620 id
= space
->tuple_id
[type
- isl_dim_in
];
621 return id
? id
->name
: NULL
;
624 __isl_give isl_space
*isl_space_set_dim_name(__isl_take isl_space
*space
,
625 enum isl_dim_type type
, unsigned pos
,
633 return isl_space_reset_dim_id(space
, type
, pos
);
634 if (!name_ok(space
->ctx
, s
))
636 id
= isl_id_alloc(space
->ctx
, s
, NULL
);
637 return isl_space_set_dim_id(space
, type
, pos
, id
);
639 isl_space_free(space
);
643 /* Does the given dimension have a name?
645 isl_bool
isl_space_has_dim_name(__isl_keep isl_space
*space
,
646 enum isl_dim_type type
, unsigned pos
)
651 return isl_bool_error
;
652 id
= get_id(space
, type
, pos
);
653 return id
&& id
->name
;
656 __isl_keep
const char *isl_space_get_dim_name(__isl_keep isl_space
*space
,
657 enum isl_dim_type type
, unsigned pos
)
659 isl_id
*id
= get_id(space
, type
, pos
);
660 return id
? id
->name
: NULL
;
663 int isl_space_find_dim_by_id(__isl_keep isl_space
*space
,
664 enum isl_dim_type type
, __isl_keep isl_id
*id
)
673 offset
= isl_space_offset(space
, type
);
674 n
= isl_space_dim(space
, type
);
675 for (i
= 0; i
< n
&& offset
+ i
< space
->n_id
; ++i
)
676 if (space
->ids
[offset
+ i
] == id
)
682 int isl_space_find_dim_by_name(__isl_keep isl_space
*space
,
683 enum isl_dim_type type
, const char *name
)
692 offset
= isl_space_offset(space
, type
);
693 n
= isl_space_dim(space
, type
);
694 for (i
= 0; i
< n
&& offset
+ i
< space
->n_id
; ++i
) {
695 isl_id
*id
= get_id(space
, type
, i
);
696 if (id
&& id
->name
&& !strcmp(id
->name
, name
))
703 /* Reset the user pointer on all identifiers of parameters and tuples
706 __isl_give isl_space
*isl_space_reset_user(__isl_take isl_space
*space
)
716 ctx
= isl_space_get_ctx(space
);
718 for (i
= 0; i
< space
->nparam
&& i
< space
->n_id
; ++i
) {
719 if (!isl_id_get_user(space
->ids
[i
]))
721 space
= isl_space_cow(space
);
724 name
= isl_id_get_name(space
->ids
[i
]);
725 id
= isl_id_alloc(ctx
, name
, NULL
);
726 isl_id_free(space
->ids
[i
]);
729 return isl_space_free(space
);
732 for (i
= 0; i
< 2; ++i
) {
733 if (!space
->tuple_id
[i
])
735 if (!isl_id_get_user(space
->tuple_id
[i
]))
737 space
= isl_space_cow(space
);
740 name
= isl_id_get_name(space
->tuple_id
[i
]);
741 id
= isl_id_alloc(ctx
, name
, NULL
);
742 isl_id_free(space
->tuple_id
[i
]);
743 space
->tuple_id
[i
] = id
;
745 return isl_space_free(space
);
748 for (i
= 0; i
< 2; ++i
) {
749 if (!space
->nested
[i
])
751 space
= isl_space_cow(space
);
754 space
->nested
[i
] = isl_space_reset_user(space
->nested
[i
]);
755 if (!space
->nested
[i
])
756 return isl_space_free(space
);
762 static __isl_keep isl_id
*tuple_id(__isl_keep isl_space
*dim
,
763 enum isl_dim_type type
)
767 if (type
== isl_dim_in
)
768 return dim
->tuple_id
[0];
769 if (type
== isl_dim_out
)
770 return dim
->tuple_id
[1];
774 static __isl_keep isl_space
*nested(__isl_keep isl_space
*dim
,
775 enum isl_dim_type type
)
779 if (type
== isl_dim_in
)
780 return dim
->nested
[0];
781 if (type
== isl_dim_out
)
782 return dim
->nested
[1];
786 /* Are the two spaces the same, apart from positions and names of parameters?
788 isl_bool
isl_space_has_equal_tuples(__isl_keep isl_space
*space1
,
789 __isl_keep isl_space
*space2
)
791 if (!space1
|| !space2
)
792 return isl_bool_error
;
793 if (space1
== space2
)
794 return isl_bool_true
;
795 return isl_space_tuple_is_equal(space1
, isl_dim_in
,
796 space2
, isl_dim_in
) &&
797 isl_space_tuple_is_equal(space1
, isl_dim_out
,
798 space2
, isl_dim_out
);
801 /* Check if the tuple of type "type1" of "space1" is the same as
802 * the tuple of type "type2" of "space2".
804 * That is, check if the tuples have the same identifier, the same dimension
805 * and the same internal structure.
806 * The identifiers of the dimensions inside the tuples do not affect the result.
808 * Note that this function only checks the tuples themselves.
809 * If nested tuples are involved, then we need to be careful not
810 * to have result affected by possibly differing parameters
811 * in those nested tuples.
813 isl_bool
isl_space_tuple_is_equal(__isl_keep isl_space
*space1
,
814 enum isl_dim_type type1
, __isl_keep isl_space
*space2
,
815 enum isl_dim_type type2
)
818 isl_space
*nested1
, *nested2
;
820 if (!space1
|| !space2
)
821 return isl_bool_error
;
823 if (space1
== space2
&& type1
== type2
)
824 return isl_bool_true
;
826 if (n(space1
, type1
) != n(space2
, type2
))
827 return isl_bool_false
;
828 id1
= tuple_id(space1
, type1
);
829 id2
= tuple_id(space2
, type2
);
831 return isl_bool_false
;
832 if (id1
&& id1
!= id2
)
833 return isl_bool_false
;
834 nested1
= nested(space1
, type1
);
835 nested2
= nested(space2
, type2
);
836 if (!nested1
^ !nested2
)
837 return isl_bool_false
;
838 if (nested1
&& !isl_space_has_equal_tuples(nested1
, nested2
))
839 return isl_bool_false
;
840 return isl_bool_true
;
843 static isl_bool
match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
844 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
848 if (space1
== space2
&& type1
== type2
)
849 return isl_bool_true
;
851 if (!isl_space_tuple_is_equal(space1
, type1
, space2
, type2
))
852 return isl_bool_false
;
854 if (!space1
->ids
&& !space2
->ids
)
855 return isl_bool_true
;
857 for (i
= 0; i
< n(space1
, type1
); ++i
) {
858 if (get_id(space1
, type1
, i
) != get_id(space2
, type2
, i
))
859 return isl_bool_false
;
861 return isl_bool_true
;
864 /* Do "space1" and "space2" have the same parameters?
866 isl_bool
isl_space_has_equal_params(__isl_keep isl_space
*space1
,
867 __isl_keep isl_space
*space2
)
869 if (!space1
|| !space2
)
870 return isl_bool_error
;
872 return match(space1
, isl_dim_param
, space2
, isl_dim_param
);
875 /* Do "space1" and "space2" have the same identifiers for all
876 * the tuple variables?
878 isl_bool
isl_space_has_equal_ids(__isl_keep isl_space
*space1
,
879 __isl_keep isl_space
*space2
)
883 if (!space1
|| !space2
)
884 return isl_bool_error
;
886 equal
= match(space1
, isl_dim_in
, space2
, isl_dim_in
);
887 if (equal
< 0 || !equal
)
889 return match(space1
, isl_dim_out
, space2
, isl_dim_out
);
892 isl_bool
isl_space_match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
893 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
895 if (!space1
|| !space2
)
896 return isl_bool_error
;
898 return match(space1
, type1
, space2
, type2
);
901 static void get_ids(__isl_keep isl_space
*dim
, enum isl_dim_type type
,
902 unsigned first
, unsigned n
, __isl_keep isl_id
**ids
)
906 for (i
= 0; i
< n
; ++i
)
907 ids
[i
] = get_id(dim
, type
, first
+ i
);
910 static __isl_give isl_space
*space_extend(__isl_take isl_space
*space
,
911 unsigned nparam
, unsigned n_in
, unsigned n_out
)
917 if (space
->nparam
== nparam
&&
918 space
->n_in
== n_in
&& space
->n_out
== n_out
)
921 isl_assert(space
->ctx
, space
->nparam
<= nparam
, goto error
);
922 isl_assert(space
->ctx
, space
->n_in
<= n_in
, goto error
);
923 isl_assert(space
->ctx
, space
->n_out
<= n_out
, goto error
);
925 space
= isl_space_cow(space
);
931 n
= nparam
+ n_in
+ n_out
;
932 if (n
< nparam
|| n
< n_in
|| n
< n_out
)
933 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
934 "overflow in total number of dimensions",
936 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n
);
939 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
940 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
+ nparam
);
941 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
942 ids
+ nparam
+ n_in
);
945 space
->n_id
= nparam
+ n_in
+ n_out
;
947 space
->nparam
= nparam
;
949 space
->n_out
= n_out
;
954 isl_space_free(space
);
958 __isl_give isl_space
*isl_space_extend(__isl_take isl_space
*space
,
959 unsigned nparam
, unsigned n_in
, unsigned n_out
)
961 return space_extend(space
, nparam
, n_in
, n_out
);
964 __isl_give isl_space
*isl_space_add_dims(__isl_take isl_space
*space
,
965 enum isl_dim_type type
, unsigned n
)
967 space
= isl_space_reset(space
, type
);
972 space
= space_extend(space
,
973 space
->nparam
+ n
, space
->n_in
, space
->n_out
);
974 if (space
&& space
->nested
[0] &&
975 !(space
->nested
[0] = isl_space_add_dims(space
->nested
[0],
978 if (space
&& space
->nested
[1] &&
979 !(space
->nested
[1] = isl_space_add_dims(space
->nested
[1],
984 return space_extend(space
,
985 space
->nparam
, space
->n_in
+ n
, space
->n_out
);
987 return space_extend(space
,
988 space
->nparam
, space
->n_in
, space
->n_out
+ n
);
990 isl_die(space
->ctx
, isl_error_invalid
,
991 "cannot add dimensions of specified type", goto error
);
994 isl_space_free(space
);
998 /* Add a parameter with identifier "id" to "space", provided
999 * it does not already appear in "space".
1001 __isl_give isl_space
*isl_space_add_param_id(__isl_take isl_space
*space
,
1002 __isl_take isl_id
*id
)
1009 if (isl_space_find_dim_by_id(space
, isl_dim_param
, id
) >= 0) {
1014 pos
= isl_space_dim(space
, isl_dim_param
);
1015 space
= isl_space_add_dims(space
, isl_dim_param
, 1);
1016 space
= isl_space_set_dim_id(space
, isl_dim_param
, pos
, id
);
1020 isl_space_free(space
);
1025 static int valid_dim_type(enum isl_dim_type type
)
1037 /* Insert "n" dimensions of type "type" at position "pos".
1038 * If we are inserting parameters, then they are also inserted in
1039 * any nested spaces.
1041 __isl_give isl_space
*isl_space_insert_dims(__isl_take isl_space
*space
,
1042 enum isl_dim_type type
, unsigned pos
, unsigned n
)
1045 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 total
= isl_space_dim(space
, isl_dim_all
);
1060 if (total
+ n
< total
)
1061 isl_die(ctx
, isl_error_invalid
,
1062 "overflow in total number of dimensions",
1063 return isl_space_free(space
));
1064 isl_assert(ctx
, pos
<= isl_space_dim(space
, type
), goto error
);
1066 space
= isl_space_cow(space
);
1071 enum isl_dim_type t
, o
= isl_dim_param
;
1074 ids
= isl_calloc_array(ctx
, isl_id
*,
1075 space
->nparam
+ space
->n_in
+ space
->n_out
+ n
);
1079 s
[isl_dim_param
- o
] = space
->nparam
;
1080 s
[isl_dim_in
- o
] = space
->n_in
;
1081 s
[isl_dim_out
- o
] = space
->n_out
;
1082 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1084 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1087 get_ids(space
, t
, 0, pos
, ids
+ off
);
1089 get_ids(space
, t
, pos
, s
[t
- o
] - pos
,
1091 off
+= s
[t
- o
] - pos
;
1096 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
+ n
;
1099 case isl_dim_param
: space
->nparam
+= n
; break;
1100 case isl_dim_in
: space
->n_in
+= n
; break;
1101 case isl_dim_out
: space
->n_out
+= n
; break;
1104 space
= isl_space_reset(space
, type
);
1106 if (type
== isl_dim_param
) {
1107 if (space
&& space
->nested
[0] &&
1108 !(space
->nested
[0] = isl_space_insert_dims(space
->nested
[0],
1109 isl_dim_param
, pos
, n
)))
1111 if (space
&& space
->nested
[1] &&
1112 !(space
->nested
[1] = isl_space_insert_dims(space
->nested
[1],
1113 isl_dim_param
, pos
, n
)))
1119 isl_space_free(space
);
1123 __isl_give isl_space
*isl_space_move_dims(__isl_take isl_space
*space
,
1124 enum isl_dim_type dst_type
, unsigned dst_pos
,
1125 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1129 space
= isl_space_reset(space
, src_type
);
1130 space
= isl_space_reset(space
, dst_type
);
1136 isl_assert(space
->ctx
, src_pos
+ n
<= isl_space_dim(space
, src_type
),
1139 if (dst_type
== src_type
&& dst_pos
== src_pos
)
1142 isl_assert(space
->ctx
, dst_type
!= src_type
, goto error
);
1144 space
= isl_space_cow(space
);
1150 enum isl_dim_type t
, o
= isl_dim_param
;
1153 ids
= isl_calloc_array(space
->ctx
, isl_id
*,
1154 space
->nparam
+ space
->n_in
+ space
->n_out
);
1158 s
[isl_dim_param
- o
] = space
->nparam
;
1159 s
[isl_dim_in
- o
] = space
->n_in
;
1160 s
[isl_dim_out
- o
] = space
->n_out
;
1161 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1162 if (t
== dst_type
) {
1163 get_ids(space
, t
, 0, dst_pos
, ids
+ off
);
1165 get_ids(space
, src_type
, src_pos
, n
, ids
+ off
);
1167 get_ids(space
, t
, dst_pos
, s
[t
- o
] - dst_pos
,
1169 off
+= s
[t
- o
] - dst_pos
;
1170 } else if (t
== src_type
) {
1171 get_ids(space
, t
, 0, src_pos
, ids
+ off
);
1173 get_ids(space
, t
, src_pos
+ n
,
1174 s
[t
- o
] - src_pos
- n
, ids
+ off
);
1175 off
+= s
[t
- o
] - src_pos
- n
;
1177 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1183 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
;
1187 case isl_dim_param
: space
->nparam
+= n
; break;
1188 case isl_dim_in
: space
->n_in
+= n
; break;
1189 case isl_dim_out
: space
->n_out
+= n
; break;
1194 case isl_dim_param
: space
->nparam
-= n
; break;
1195 case isl_dim_in
: space
->n_in
-= n
; break;
1196 case isl_dim_out
: space
->n_out
-= n
; break;
1200 if (dst_type
!= isl_dim_param
&& src_type
!= isl_dim_param
)
1203 for (i
= 0; i
< 2; ++i
) {
1204 if (!space
->nested
[i
])
1206 space
->nested
[i
] = isl_space_replace_params(space
->nested
[i
],
1208 if (!space
->nested
[i
])
1214 isl_space_free(space
);
1218 /* Check that "space1" and "space2" have the same parameters,
1219 * reporting an error if they do not.
1221 isl_stat
isl_space_check_equal_params(__isl_keep isl_space
*space1
,
1222 __isl_keep isl_space
*space2
)
1226 equal
= isl_space_has_equal_params(space1
, space2
);
1228 return isl_stat_error
;
1230 isl_die(isl_space_get_ctx(space1
), isl_error_invalid
,
1231 "parameters need to match", return isl_stat_error
);
1235 __isl_give isl_space
*isl_space_join(__isl_take isl_space
*left
,
1236 __isl_take isl_space
*right
)
1240 if (isl_space_check_equal_params(left
, right
) < 0)
1243 isl_assert(left
->ctx
,
1244 isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_in
),
1247 space
= isl_space_alloc(left
->ctx
,
1248 left
->nparam
, left
->n_in
, right
->n_out
);
1252 space
= copy_ids(space
, isl_dim_param
, 0, left
, isl_dim_param
);
1253 space
= copy_ids(space
, isl_dim_in
, 0, left
, isl_dim_in
);
1254 space
= copy_ids(space
, isl_dim_out
, 0, right
, isl_dim_out
);
1256 if (space
&& left
->tuple_id
[0] &&
1257 !(space
->tuple_id
[0] = isl_id_copy(left
->tuple_id
[0])))
1259 if (space
&& right
->tuple_id
[1] &&
1260 !(space
->tuple_id
[1] = isl_id_copy(right
->tuple_id
[1])))
1262 if (space
&& left
->nested
[0] &&
1263 !(space
->nested
[0] = isl_space_copy(left
->nested
[0])))
1265 if (space
&& right
->nested
[1] &&
1266 !(space
->nested
[1] = isl_space_copy(right
->nested
[1])))
1269 isl_space_free(left
);
1270 isl_space_free(right
);
1274 isl_space_free(left
);
1275 isl_space_free(right
);
1279 /* Given two map spaces { A -> C } and { B -> D }, construct the space
1280 * { [A -> B] -> [C -> D] }.
1281 * Given two set spaces { A } and { B }, construct the space { [A -> B] }.
1283 __isl_give isl_space
*isl_space_product(__isl_take isl_space
*left
,
1284 __isl_take isl_space
*right
)
1286 isl_space
*dom1
, *dom2
, *nest1
, *nest2
;
1289 if (!left
|| !right
)
1292 is_set
= isl_space_is_set(left
);
1293 if (is_set
!= isl_space_is_set(right
))
1294 isl_die(isl_space_get_ctx(left
), isl_error_invalid
,
1295 "expecting either two set spaces or two map spaces",
1298 return isl_space_range_product(left
, right
);
1300 if (isl_space_check_equal_params(left
, right
) < 0)
1303 dom1
= isl_space_domain(isl_space_copy(left
));
1304 dom2
= isl_space_domain(isl_space_copy(right
));
1305 nest1
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1307 dom1
= isl_space_range(left
);
1308 dom2
= isl_space_range(right
);
1309 nest2
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1311 return isl_space_join(isl_space_reverse(nest1
), nest2
);
1313 isl_space_free(left
);
1314 isl_space_free(right
);
1318 /* Given two spaces { A -> C } and { B -> C }, construct the space
1321 __isl_give isl_space
*isl_space_domain_product(__isl_take isl_space
*left
,
1322 __isl_take isl_space
*right
)
1324 isl_space
*ran
, *dom1
, *dom2
, *nest
;
1326 if (isl_space_check_equal_params(left
, right
) < 0)
1329 if (!isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_out
))
1330 isl_die(left
->ctx
, isl_error_invalid
,
1331 "ranges need to match", goto error
);
1333 ran
= isl_space_range(isl_space_copy(left
));
1335 dom1
= isl_space_domain(left
);
1336 dom2
= isl_space_domain(right
);
1337 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1339 return isl_space_join(isl_space_reverse(nest
), ran
);
1341 isl_space_free(left
);
1342 isl_space_free(right
);
1346 __isl_give isl_space
*isl_space_range_product(__isl_take isl_space
*left
,
1347 __isl_take isl_space
*right
)
1349 isl_space
*dom
, *ran1
, *ran2
, *nest
;
1351 if (isl_space_check_equal_params(left
, right
) < 0)
1354 if (!isl_space_tuple_is_equal(left
, isl_dim_in
, right
, isl_dim_in
))
1355 isl_die(left
->ctx
, isl_error_invalid
,
1356 "domains need to match", goto error
);
1358 dom
= isl_space_domain(isl_space_copy(left
));
1360 ran1
= isl_space_range(left
);
1361 ran2
= isl_space_range(right
);
1362 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(ran1
), ran2
));
1364 return isl_space_join(isl_space_reverse(dom
), nest
);
1366 isl_space_free(left
);
1367 isl_space_free(right
);
1371 /* Given a space of the form [A -> B] -> C, return the space A -> C.
1373 __isl_give isl_space
*isl_space_domain_factor_domain(
1374 __isl_take isl_space
*space
)
1381 if (!isl_space_domain_is_wrapping(space
))
1382 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1383 "domain not a product", return isl_space_free(space
));
1385 nested
= space
->nested
[0];
1386 domain
= isl_space_copy(space
);
1387 domain
= isl_space_drop_dims(domain
, isl_dim_in
,
1388 nested
->n_in
, nested
->n_out
);
1390 return isl_space_free(space
);
1391 if (nested
->tuple_id
[0]) {
1392 domain
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[0]);
1393 if (!domain
->tuple_id
[0])
1396 if (nested
->nested
[0]) {
1397 domain
->nested
[0] = isl_space_copy(nested
->nested
[0]);
1398 if (!domain
->nested
[0])
1402 isl_space_free(space
);
1405 isl_space_free(space
);
1406 isl_space_free(domain
);
1410 /* Given a space of the form [A -> B] -> C, return the space B -> C.
1412 __isl_give isl_space
*isl_space_domain_factor_range(
1413 __isl_take isl_space
*space
)
1420 if (!isl_space_domain_is_wrapping(space
))
1421 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1422 "domain not a product", return isl_space_free(space
));
1424 nested
= space
->nested
[0];
1425 range
= isl_space_copy(space
);
1426 range
= isl_space_drop_dims(range
, isl_dim_in
, 0, nested
->n_in
);
1428 return isl_space_free(space
);
1429 if (nested
->tuple_id
[1]) {
1430 range
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[1]);
1431 if (!range
->tuple_id
[0])
1434 if (nested
->nested
[1]) {
1435 range
->nested
[0] = isl_space_copy(nested
->nested
[1]);
1436 if (!range
->nested
[0])
1440 isl_space_free(space
);
1443 isl_space_free(space
);
1444 isl_space_free(range
);
1448 /* Internal function that selects the domain of the map that is
1449 * embedded in either a set space or the range of a map space.
1450 * In particular, given a space of the form [A -> B], return the space A.
1451 * Given a space of the form A -> [B -> C], return the space A -> B.
1453 static __isl_give isl_space
*range_factor_domain(__isl_take isl_space
*space
)
1461 nested
= space
->nested
[1];
1462 domain
= isl_space_copy(space
);
1463 domain
= isl_space_drop_dims(domain
, isl_dim_out
,
1464 nested
->n_in
, nested
->n_out
);
1466 return isl_space_free(space
);
1467 if (nested
->tuple_id
[0]) {
1468 domain
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[0]);
1469 if (!domain
->tuple_id
[1])
1472 if (nested
->nested
[0]) {
1473 domain
->nested
[1] = isl_space_copy(nested
->nested
[0]);
1474 if (!domain
->nested
[1])
1478 isl_space_free(space
);
1481 isl_space_free(space
);
1482 isl_space_free(domain
);
1486 /* Given a space of the form A -> [B -> C], return the space A -> B.
1488 __isl_give isl_space
*isl_space_range_factor_domain(
1489 __isl_take isl_space
*space
)
1493 if (!isl_space_range_is_wrapping(space
))
1494 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1495 "range not a product", return isl_space_free(space
));
1497 return range_factor_domain(space
);
1500 /* Given a space of the form [A -> B], return the space A.
1502 static __isl_give isl_space
*set_factor_domain(__isl_take isl_space
*space
)
1506 if (!isl_space_is_wrapping(space
))
1507 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1508 "not a product", return isl_space_free(space
));
1510 return range_factor_domain(space
);
1513 /* Given a space of the form [A -> B] -> [C -> D], return the space A -> C.
1514 * Given a space of the form [A -> B], return the space A.
1516 __isl_give isl_space
*isl_space_factor_domain(__isl_take isl_space
*space
)
1520 if (isl_space_is_set(space
))
1521 return set_factor_domain(space
);
1522 space
= isl_space_domain_factor_domain(space
);
1523 space
= isl_space_range_factor_domain(space
);
1527 /* Internal function that selects the range of the map that is
1528 * embedded in either a set space or the range of a map space.
1529 * In particular, given a space of the form [A -> B], return the space B.
1530 * Given a space of the form A -> [B -> C], return the space A -> C.
1532 static __isl_give isl_space
*range_factor_range(__isl_take isl_space
*space
)
1540 nested
= space
->nested
[1];
1541 range
= isl_space_copy(space
);
1542 range
= isl_space_drop_dims(range
, isl_dim_out
, 0, nested
->n_in
);
1544 return isl_space_free(space
);
1545 if (nested
->tuple_id
[1]) {
1546 range
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[1]);
1547 if (!range
->tuple_id
[1])
1550 if (nested
->nested
[1]) {
1551 range
->nested
[1] = isl_space_copy(nested
->nested
[1]);
1552 if (!range
->nested
[1])
1556 isl_space_free(space
);
1559 isl_space_free(space
);
1560 isl_space_free(range
);
1564 /* Given a space of the form A -> [B -> C], return the space A -> C.
1566 __isl_give isl_space
*isl_space_range_factor_range(
1567 __isl_take isl_space
*space
)
1571 if (!isl_space_range_is_wrapping(space
))
1572 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1573 "range not a product", return isl_space_free(space
));
1575 return range_factor_range(space
);
1578 /* Given a space of the form [A -> B], return the space B.
1580 static __isl_give isl_space
*set_factor_range(__isl_take isl_space
*space
)
1584 if (!isl_space_is_wrapping(space
))
1585 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1586 "not a product", return isl_space_free(space
));
1588 return range_factor_range(space
);
1591 /* Given a space of the form [A -> B] -> [C -> D], return the space B -> D.
1592 * Given a space of the form [A -> B], return the space B.
1594 __isl_give isl_space
*isl_space_factor_range(__isl_take isl_space
*space
)
1598 if (isl_space_is_set(space
))
1599 return set_factor_range(space
);
1600 space
= isl_space_domain_factor_range(space
);
1601 space
= isl_space_range_factor_range(space
);
1605 __isl_give isl_space
*isl_space_map_from_set(__isl_take isl_space
*space
)
1608 isl_id
**ids
= NULL
;
1613 ctx
= isl_space_get_ctx(space
);
1614 if (!isl_space_is_set(space
))
1615 isl_die(ctx
, isl_error_invalid
, "not a set space", goto error
);
1616 space
= isl_space_cow(space
);
1619 n_id
= space
->nparam
+ space
->n_out
+ space
->n_out
;
1620 if (n_id
> 0 && space
->ids
) {
1621 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n_id
);
1624 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
1625 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1626 ids
+ space
->nparam
);
1628 space
->n_in
= space
->n_out
;
1633 space
= copy_ids(space
, isl_dim_out
, 0, space
, isl_dim_in
);
1635 isl_id_free(space
->tuple_id
[0]);
1636 space
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[1]);
1637 isl_space_free(space
->nested
[0]);
1638 space
->nested
[0] = isl_space_copy(space
->nested
[1]);
1641 isl_space_free(space
);
1645 __isl_give isl_space
*isl_space_map_from_domain_and_range(
1646 __isl_take isl_space
*domain
, __isl_take isl_space
*range
)
1648 if (!domain
|| !range
)
1650 if (!isl_space_is_set(domain
))
1651 isl_die(isl_space_get_ctx(domain
), isl_error_invalid
,
1652 "domain is not a set space", goto error
);
1653 if (!isl_space_is_set(range
))
1654 isl_die(isl_space_get_ctx(range
), isl_error_invalid
,
1655 "range is not a set space", goto error
);
1656 return isl_space_join(isl_space_reverse(domain
), range
);
1658 isl_space_free(domain
);
1659 isl_space_free(range
);
1663 static __isl_give isl_space
*set_ids(__isl_take isl_space
*dim
,
1664 enum isl_dim_type type
,
1665 unsigned first
, unsigned n
, __isl_take isl_id
**ids
)
1669 for (i
= 0; i
< n
; ++i
)
1670 dim
= set_id(dim
, type
, first
+ i
, ids
[i
]);
1675 __isl_give isl_space
*isl_space_reverse(__isl_take isl_space
*space
)
1679 isl_id
**ids
= NULL
;
1684 if (match(space
, isl_dim_in
, space
, isl_dim_out
))
1687 space
= isl_space_cow(space
);
1691 id
= space
->tuple_id
[0];
1692 space
->tuple_id
[0] = space
->tuple_id
[1];
1693 space
->tuple_id
[1] = id
;
1695 nested
= space
->nested
[0];
1696 space
->nested
[0] = space
->nested
[1];
1697 space
->nested
[1] = nested
;
1700 int n_id
= space
->n_in
+ space
->n_out
;
1701 ids
= isl_alloc_array(space
->ctx
, isl_id
*, n_id
);
1704 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
);
1705 get_ids(space
, isl_dim_out
, 0, space
->n_out
, ids
+ space
->n_in
);
1709 space
->n_in
= space
->n_out
;
1713 space
= set_ids(space
, isl_dim_out
, 0, space
->n_out
, ids
);
1714 space
= set_ids(space
, isl_dim_in
, 0, space
->n_in
,
1715 ids
+ space
->n_out
);
1722 isl_space_free(space
);
1726 __isl_give isl_space
*isl_space_drop_dims(__isl_take isl_space
*space
,
1727 enum isl_dim_type type
, unsigned first
, unsigned num
)
1735 return isl_space_reset(space
, type
);
1737 if (!valid_dim_type(type
))
1738 isl_die(space
->ctx
, isl_error_invalid
,
1739 "cannot drop dimensions of specified type", goto error
);
1741 if (first
+ num
> n(space
, type
) || first
+ num
< first
)
1742 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1743 "index out of bounds", return isl_space_free(space
));
1744 space
= isl_space_cow(space
);
1748 space
= extend_ids(space
);
1751 for (i
= 0; i
< num
; ++i
)
1752 isl_id_free(get_id(space
, type
, first
+ i
));
1753 for (i
= first
+num
; i
< n(space
, type
); ++i
)
1754 set_id(space
, type
, i
- num
, get_id(space
, type
, i
));
1757 get_ids(space
, isl_dim_in
, 0, space
->n_in
,
1758 space
->ids
+ offset(space
, isl_dim_in
) - num
);
1760 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1761 space
->ids
+ offset(space
, isl_dim_out
) - num
);
1768 case isl_dim_param
: space
->nparam
-= num
; break;
1769 case isl_dim_in
: space
->n_in
-= num
; break;
1770 case isl_dim_out
: space
->n_out
-= num
; break;
1773 space
= isl_space_reset(space
, type
);
1774 if (type
== isl_dim_param
) {
1775 if (space
&& space
->nested
[0] &&
1776 !(space
->nested
[0] = isl_space_drop_dims(space
->nested
[0],
1777 isl_dim_param
, first
, num
)))
1779 if (space
&& space
->nested
[1] &&
1780 !(space
->nested
[1] = isl_space_drop_dims(space
->nested
[1],
1781 isl_dim_param
, first
, num
)))
1786 isl_space_free(space
);
1790 __isl_give isl_space
*isl_space_drop_inputs(__isl_take isl_space
*dim
,
1791 unsigned first
, unsigned n
)
1795 return isl_space_drop_dims(dim
, isl_dim_in
, first
, n
);
1798 __isl_give isl_space
*isl_space_drop_outputs(__isl_take isl_space
*dim
,
1799 unsigned first
, unsigned n
)
1803 return isl_space_drop_dims(dim
, isl_dim_out
, first
, n
);
1806 __isl_give isl_space
*isl_space_domain(__isl_take isl_space
*space
)
1810 space
= isl_space_drop_dims(space
, isl_dim_out
, 0, space
->n_out
);
1811 space
= isl_space_reverse(space
);
1812 space
= mark_as_set(space
);
1816 __isl_give isl_space
*isl_space_from_domain(__isl_take isl_space
*space
)
1820 if (!isl_space_is_set(space
))
1821 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1822 "not a set space", goto error
);
1823 space
= isl_space_reverse(space
);
1824 space
= isl_space_reset(space
, isl_dim_out
);
1827 isl_space_free(space
);
1831 __isl_give isl_space
*isl_space_range(__isl_take isl_space
*space
)
1835 space
= isl_space_drop_dims(space
, isl_dim_in
, 0, space
->n_in
);
1836 space
= mark_as_set(space
);
1840 __isl_give isl_space
*isl_space_from_range(__isl_take isl_space
*space
)
1844 if (!isl_space_is_set(space
))
1845 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1846 "not a set space", goto error
);
1847 return isl_space_reset(space
, isl_dim_in
);
1849 isl_space_free(space
);
1853 /* Given a map space A -> B, return the map space [A -> B] -> A.
1855 __isl_give isl_space
*isl_space_domain_map(__isl_take isl_space
*space
)
1859 domain
= isl_space_from_range(isl_space_domain(isl_space_copy(space
)));
1860 space
= isl_space_from_domain(isl_space_wrap(space
));
1861 space
= isl_space_join(space
, domain
);
1866 /* Given a map space A -> B, return the map space [A -> B] -> B.
1868 __isl_give isl_space
*isl_space_range_map(__isl_take isl_space
*space
)
1872 range
= isl_space_from_range(isl_space_range(isl_space_copy(space
)));
1873 space
= isl_space_from_domain(isl_space_wrap(space
));
1874 space
= isl_space_join(space
, range
);
1879 __isl_give isl_space
*isl_space_params(__isl_take isl_space
*space
)
1881 if (isl_space_is_params(space
))
1883 space
= isl_space_drop_dims(space
,
1884 isl_dim_in
, 0, isl_space_dim(space
, isl_dim_in
));
1885 space
= isl_space_drop_dims(space
,
1886 isl_dim_out
, 0, isl_space_dim(space
, isl_dim_out
));
1887 space
= mark_as_params(space
);
1891 __isl_give isl_space
*isl_space_set_from_params(__isl_take isl_space
*space
)
1895 if (!isl_space_is_params(space
))
1896 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1897 "not a parameter space", goto error
);
1898 return isl_space_reset(space
, isl_dim_set
);
1900 isl_space_free(space
);
1904 __isl_give isl_space
*isl_space_underlying(__isl_take isl_space
*space
,
1910 is_set
= isl_space_is_set(space
);
1912 return isl_space_free(space
);
1913 if (n_div
== 0 && is_set
&&
1914 space
->nparam
== 0 && space
->n_in
== 0 && space
->n_id
== 0)
1915 return isl_space_reset(space
, isl_dim_out
);
1916 space
= isl_space_cow(space
);
1919 space
->n_out
+= space
->nparam
+ space
->n_in
+ n_div
;
1923 for (i
= 0; i
< space
->n_id
; ++i
)
1924 isl_id_free(get_id(space
, isl_dim_out
, i
));
1926 space
= isl_space_reset(space
, isl_dim_in
);
1927 space
= isl_space_reset(space
, isl_dim_out
);
1928 space
= mark_as_set(space
);
1933 /* Are the two spaces the same, including positions and names of parameters?
1935 isl_bool
isl_space_is_equal(__isl_keep isl_space
*space1
,
1936 __isl_keep isl_space
*space2
)
1940 if (!space1
|| !space2
)
1941 return isl_bool_error
;
1942 if (space1
== space2
)
1943 return isl_bool_true
;
1944 equal
= isl_space_has_equal_params(space1
, space2
);
1945 if (equal
< 0 || !equal
)
1947 return isl_space_has_equal_tuples(space1
, space2
);
1950 /* Do the tuples of "space1" correspond to those of the domain of "space2"?
1951 * That is, is "space1" eqaul to the domain of "space2", ignoring parameters.
1953 * "space2" is allowed to be a set space, in which case "space1"
1954 * should be a parameter space.
1956 isl_bool
isl_space_has_domain_tuples(__isl_keep isl_space
*space1
,
1957 __isl_keep isl_space
*space2
)
1961 is_set
= isl_space_is_set(space1
);
1962 if (is_set
< 0 || !is_set
)
1964 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
1965 space2
, isl_dim_in
);
1968 /* Is space1 equal to the domain of space2?
1970 * In the internal version we also allow space2 to be the space of a set,
1971 * provided space1 is a parameter space.
1973 isl_bool
isl_space_is_domain_internal(__isl_keep isl_space
*space1
,
1974 __isl_keep isl_space
*space2
)
1976 isl_bool equal_params
;
1978 if (!space1
|| !space2
)
1979 return isl_bool_error
;
1980 equal_params
= isl_space_has_equal_params(space1
, space2
);
1981 if (equal_params
< 0 || !equal_params
)
1982 return equal_params
;
1983 return isl_space_has_domain_tuples(space1
, space2
);
1986 /* Is space1 equal to the domain of space2?
1988 isl_bool
isl_space_is_domain(__isl_keep isl_space
*space1
,
1989 __isl_keep isl_space
*space2
)
1992 return isl_bool_error
;
1993 if (!isl_space_is_map(space2
))
1994 return isl_bool_false
;
1995 return isl_space_is_domain_internal(space1
, space2
);
1998 /* Is space1 equal to the range of space2?
2000 * In the internal version, space2 is allowed to be the space of a set,
2001 * in which case it should be equal to space1.
2003 isl_bool
isl_space_is_range_internal(__isl_keep isl_space
*space1
,
2004 __isl_keep isl_space
*space2
)
2006 isl_bool equal_params
;
2008 if (!space1
|| !space2
)
2009 return isl_bool_error
;
2010 if (!isl_space_is_set(space1
))
2011 return isl_bool_false
;
2012 equal_params
= isl_space_has_equal_params(space1
, space2
);
2013 if (equal_params
< 0 || !equal_params
)
2014 return equal_params
;
2015 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
2016 space2
, isl_dim_out
);
2019 /* Is space1 equal to the range of space2?
2021 isl_bool
isl_space_is_range(__isl_keep isl_space
*space1
,
2022 __isl_keep isl_space
*space2
)
2025 return isl_bool_error
;
2026 if (!isl_space_is_map(space2
))
2027 return isl_bool_false
;
2028 return isl_space_is_range_internal(space1
, space2
);
2031 /* Update "hash" by hashing in the parameters of "space".
2033 static uint32_t isl_hash_params(uint32_t hash
, __isl_keep isl_space
*space
)
2041 isl_hash_byte(hash
, space
->nparam
% 256);
2043 for (i
= 0; i
< space
->nparam
; ++i
) {
2044 id
= get_id(space
, isl_dim_param
, i
);
2045 hash
= isl_hash_id(hash
, id
);
2051 /* Update "hash" by hashing in the tuples of "space".
2052 * Changes in this function should be reflected in isl_hash_tuples_domain.
2054 static uint32_t isl_hash_tuples(uint32_t hash
, __isl_keep isl_space
*space
)
2061 isl_hash_byte(hash
, space
->n_in
% 256);
2062 isl_hash_byte(hash
, space
->n_out
% 256);
2064 id
= tuple_id(space
, isl_dim_in
);
2065 hash
= isl_hash_id(hash
, id
);
2066 id
= tuple_id(space
, isl_dim_out
);
2067 hash
= isl_hash_id(hash
, id
);
2069 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2070 hash
= isl_hash_tuples(hash
, space
->nested
[1]);
2075 /* Update "hash" by hashing in the domain tuple of "space".
2076 * The result of this function is equal to the result of applying
2077 * isl_hash_tuples to the domain of "space".
2079 static uint32_t isl_hash_tuples_domain(uint32_t hash
,
2080 __isl_keep isl_space
*space
)
2087 isl_hash_byte(hash
, 0);
2088 isl_hash_byte(hash
, space
->n_in
% 256);
2090 hash
= isl_hash_id(hash
, &isl_id_none
);
2091 id
= tuple_id(space
, isl_dim_in
);
2092 hash
= isl_hash_id(hash
, id
);
2094 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2099 /* Return a hash value that digests the tuples of "space",
2100 * i.e., that ignores the parameters.
2102 uint32_t isl_space_get_tuple_hash(__isl_keep isl_space
*space
)
2109 hash
= isl_hash_init();
2110 hash
= isl_hash_tuples(hash
, space
);
2115 uint32_t isl_space_get_hash(__isl_keep isl_space
*space
)
2122 hash
= isl_hash_init();
2123 hash
= isl_hash_params(hash
, space
);
2124 hash
= isl_hash_tuples(hash
, space
);
2129 /* Return the hash value of the domain of "space".
2130 * That is, isl_space_get_domain_hash(space) is equal to
2131 * isl_space_get_hash(isl_space_domain(space)).
2133 uint32_t isl_space_get_domain_hash(__isl_keep isl_space
*space
)
2140 hash
= isl_hash_init();
2141 hash
= isl_hash_params(hash
, space
);
2142 hash
= isl_hash_tuples_domain(hash
, space
);
2147 isl_bool
isl_space_is_wrapping(__isl_keep isl_space
*space
)
2150 return isl_bool_error
;
2152 if (!isl_space_is_set(space
))
2153 return isl_bool_false
;
2155 return space
->nested
[1] != NULL
;
2158 /* Is "space" the space of a map where the domain is a wrapped map space?
2160 isl_bool
isl_space_domain_is_wrapping(__isl_keep isl_space
*space
)
2163 return isl_bool_error
;
2165 if (isl_space_is_set(space
))
2166 return isl_bool_false
;
2168 return space
->nested
[0] != NULL
;
2171 /* Is "space" the space of a map where the range is a wrapped map space?
2173 isl_bool
isl_space_range_is_wrapping(__isl_keep isl_space
*space
)
2176 return isl_bool_error
;
2178 if (isl_space_is_set(space
))
2179 return isl_bool_false
;
2181 return space
->nested
[1] != NULL
;
2184 /* Is "space" a product of two spaces?
2185 * That is, is it a wrapping set space or a map space
2186 * with wrapping domain and range?
2188 isl_bool
isl_space_is_product(__isl_keep isl_space
*space
)
2191 isl_bool is_product
;
2193 is_set
= isl_space_is_set(space
);
2195 return isl_bool_error
;
2197 return isl_space_is_wrapping(space
);
2198 is_product
= isl_space_domain_is_wrapping(space
);
2199 if (is_product
< 0 || !is_product
)
2201 return isl_space_range_is_wrapping(space
);
2204 __isl_give isl_space
*isl_space_wrap(__isl_take isl_space
*space
)
2211 wrap
= isl_space_set_alloc(space
->ctx
,
2212 space
->nparam
, space
->n_in
+ space
->n_out
);
2214 wrap
= copy_ids(wrap
, isl_dim_param
, 0, space
, isl_dim_param
);
2215 wrap
= copy_ids(wrap
, isl_dim_set
, 0, space
, isl_dim_in
);
2216 wrap
= copy_ids(wrap
, isl_dim_set
, space
->n_in
, space
, isl_dim_out
);
2221 wrap
->nested
[1] = space
;
2225 isl_space_free(space
);
2229 __isl_give isl_space
*isl_space_unwrap(__isl_take isl_space
*space
)
2236 if (!isl_space_is_wrapping(space
))
2237 isl_die(space
->ctx
, isl_error_invalid
, "not a wrapping space",
2240 unwrap
= isl_space_copy(space
->nested
[1]);
2241 isl_space_free(space
);
2245 isl_space_free(space
);
2249 isl_bool
isl_space_is_named_or_nested(__isl_keep isl_space
*space
,
2250 enum isl_dim_type type
)
2252 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
2253 return isl_bool_false
;
2255 return isl_bool_error
;
2256 if (space
->tuple_id
[type
- isl_dim_in
])
2257 return isl_bool_true
;
2258 if (space
->nested
[type
- isl_dim_in
])
2259 return isl_bool_true
;
2260 return isl_bool_false
;
2263 isl_bool
isl_space_may_be_set(__isl_keep isl_space
*space
)
2268 return isl_bool_error
;
2269 if (isl_space_is_set(space
))
2270 return isl_bool_true
;
2271 if (isl_space_dim(space
, isl_dim_in
) != 0)
2272 return isl_bool_false
;
2273 nested
= isl_space_is_named_or_nested(space
, isl_dim_in
);
2274 if (nested
< 0 || nested
)
2275 return isl_bool_not(nested
);
2276 return isl_bool_true
;
2279 __isl_give isl_space
*isl_space_reset(__isl_take isl_space
*space
,
2280 enum isl_dim_type type
)
2282 if (!isl_space_is_named_or_nested(space
, type
))
2285 space
= isl_space_cow(space
);
2289 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
2290 space
->tuple_id
[type
- isl_dim_in
] = NULL
;
2291 isl_space_free(space
->nested
[type
- isl_dim_in
]);
2292 space
->nested
[type
- isl_dim_in
] = NULL
;
2297 __isl_give isl_space
*isl_space_flatten(__isl_take isl_space
*space
)
2301 if (!space
->nested
[0] && !space
->nested
[1])
2304 if (space
->nested
[0])
2305 space
= isl_space_reset(space
, isl_dim_in
);
2306 if (space
&& space
->nested
[1])
2307 space
= isl_space_reset(space
, isl_dim_out
);
2312 __isl_give isl_space
*isl_space_flatten_domain(__isl_take isl_space
*space
)
2316 if (!space
->nested
[0])
2319 return isl_space_reset(space
, isl_dim_in
);
2322 __isl_give isl_space
*isl_space_flatten_range(__isl_take isl_space
*space
)
2326 if (!space
->nested
[1])
2329 return isl_space_reset(space
, isl_dim_out
);
2332 /* Replace the parameters of dst by those of src.
2334 __isl_give isl_space
*isl_space_replace_params(__isl_take isl_space
*dst
,
2335 __isl_keep isl_space
*src
)
2337 isl_bool equal_params
;
2338 enum isl_dim_type type
= isl_dim_param
;
2340 equal_params
= isl_space_has_equal_params(dst
, src
);
2341 if (equal_params
< 0)
2342 return isl_space_free(dst
);
2346 dst
= isl_space_cow(dst
);
2351 dst
= isl_space_drop_dims(dst
, type
, 0, isl_space_dim(dst
, type
));
2352 dst
= isl_space_add_dims(dst
, type
, isl_space_dim(src
, type
));
2353 dst
= copy_ids(dst
, type
, 0, src
, type
);
2357 for (i
= 0; i
<= 1; ++i
) {
2358 if (!dst
->nested
[i
])
2360 dst
->nested
[i
] = isl_space_replace_params(
2361 dst
->nested
[i
], src
);
2362 if (!dst
->nested
[i
])
2369 isl_space_free(dst
);
2373 /* Given a dimension specification "dim" of a set, create a dimension
2374 * specification for the lift of the set. In particular, the result
2375 * is of the form [dim -> local[..]], with n_local variables in the
2376 * range of the wrapped map.
2378 __isl_give isl_space
*isl_space_lift(__isl_take isl_space
*space
,
2381 isl_space
*local_space
;
2386 local_space
= isl_space_dup(space
);
2387 local_space
= isl_space_drop_dims(local_space
, isl_dim_set
, 0,
2389 local_space
= isl_space_add_dims(local_space
, isl_dim_set
, n_local
);
2390 local_space
= isl_space_set_tuple_name(local_space
,
2391 isl_dim_set
, "local");
2392 space
= isl_space_join(isl_space_from_domain(space
),
2393 isl_space_from_range(local_space
));
2394 space
= isl_space_wrap(space
);
2395 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "lifted");
2400 isl_bool
isl_space_can_zip(__isl_keep isl_space
*space
)
2404 is_set
= isl_space_is_set(space
);
2406 return isl_bool_error
;
2408 return isl_bool_false
;
2409 return isl_space_is_product(space
);
2412 __isl_give isl_space
*isl_space_zip(__isl_take isl_space
*space
)
2414 isl_space
*dom
, *ran
;
2415 isl_space
*dom_dom
, *dom_ran
, *ran_dom
, *ran_ran
;
2417 if (!isl_space_can_zip(space
))
2418 isl_die(space
->ctx
, isl_error_invalid
, "dim cannot be zipped",
2423 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(space
)));
2424 ran
= isl_space_unwrap(isl_space_range(space
));
2425 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2426 dom_ran
= isl_space_range(dom
);
2427 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2428 ran_ran
= isl_space_range(ran
);
2429 dom
= isl_space_join(isl_space_from_domain(dom_dom
),
2430 isl_space_from_range(ran_dom
));
2431 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2432 isl_space_from_range(ran_ran
));
2433 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2434 isl_space_from_range(isl_space_wrap(ran
)));
2436 isl_space_free(space
);
2440 /* Can we apply isl_space_curry to "space"?
2441 * That is, does it have a nested relation in its domain?
2443 isl_bool
isl_space_can_curry(__isl_keep isl_space
*space
)
2446 return isl_bool_error
;
2448 return !!space
->nested
[0];
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 nested relation in its range?
2521 isl_bool
isl_space_can_uncurry(__isl_keep isl_space
*space
)
2524 return isl_bool_error
;
2526 return !!space
->nested
[1];
2529 /* Given a space A -> (B -> C), return the corresponding space
2532 __isl_give isl_space
*isl_space_uncurry(__isl_take isl_space
*space
)
2534 isl_space
*dom
, *ran
;
2535 isl_space
*ran_dom
, *ran_ran
;
2540 if (!isl_space_can_uncurry(space
))
2541 isl_die(space
->ctx
, isl_error_invalid
,
2542 "space cannot be uncurried",
2543 return isl_space_free(space
));
2545 dom
= isl_space_domain(isl_space_copy(space
));
2546 ran
= isl_space_unwrap(isl_space_range(space
));
2547 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2548 ran_ran
= isl_space_range(ran
);
2549 dom
= isl_space_join(isl_space_from_domain(dom
),
2550 isl_space_from_range(ran_dom
));
2551 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2552 isl_space_from_range(ran_ran
));
2555 isl_bool
isl_space_has_named_params(__isl_keep isl_space
*space
)
2561 return isl_bool_error
;
2562 if (space
->nparam
== 0)
2563 return isl_bool_true
;
2564 off
= isl_space_offset(space
, isl_dim_param
);
2565 if (off
+ space
->nparam
> space
->n_id
)
2566 return isl_bool_false
;
2567 for (i
= 0; i
< space
->nparam
; ++i
)
2568 if (!space
->ids
[off
+ i
])
2569 return isl_bool_false
;
2570 return isl_bool_true
;
2573 /* Check that "space" has only named parameters, reporting an error
2576 isl_stat
isl_space_check_named_params(__isl_keep isl_space
*space
)
2580 named
= isl_space_has_named_params(space
);
2582 return isl_stat_error
;
2584 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2585 "unexpected unnamed parameters", return isl_stat_error
);
2590 /* Align the initial parameters of space1 to match the order in space2.
2592 __isl_give isl_space
*isl_space_align_params(__isl_take isl_space
*space1
,
2593 __isl_take isl_space
*space2
)
2595 isl_reordering
*exp
;
2597 if (isl_space_check_named_params(space1
) < 0 ||
2598 isl_space_check_named_params(space2
) < 0)
2601 exp
= isl_parameter_alignment_reordering(space1
, space2
);
2602 exp
= isl_reordering_extend_space(exp
, space1
);
2603 isl_space_free(space2
);
2604 space1
= isl_reordering_get_space(exp
);
2605 isl_reordering_free(exp
);
2608 isl_space_free(space1
);
2609 isl_space_free(space2
);
2613 /* Given the space of set (domain), construct a space for a map
2614 * with as domain the given space and as range the range of "model".
2616 __isl_give isl_space
*isl_space_extend_domain_with_range(
2617 __isl_take isl_space
*space
, __isl_take isl_space
*model
)
2622 space
= isl_space_from_domain(space
);
2623 space
= isl_space_add_dims(space
, isl_dim_out
,
2624 isl_space_dim(model
, isl_dim_out
));
2625 if (isl_space_has_tuple_id(model
, isl_dim_out
))
2626 space
= isl_space_set_tuple_id(space
, isl_dim_out
,
2627 isl_space_get_tuple_id(model
, isl_dim_out
));
2630 if (model
->nested
[1]) {
2631 isl_space
*nested
= isl_space_copy(model
->nested
[1]);
2632 int n_nested
, n_space
;
2633 nested
= isl_space_align_params(nested
, isl_space_copy(space
));
2634 n_nested
= isl_space_dim(nested
, isl_dim_param
);
2635 n_space
= isl_space_dim(space
, isl_dim_param
);
2636 if (n_nested
> n_space
)
2637 nested
= isl_space_drop_dims(nested
, isl_dim_param
,
2638 n_space
, n_nested
- n_space
);
2641 space
->nested
[1] = nested
;
2643 isl_space_free(model
);
2646 isl_space_free(model
);
2647 isl_space_free(space
);
2651 /* Compare the "type" dimensions of two isl_spaces.
2653 * The order is fairly arbitrary.
2655 static int isl_space_cmp_type(__isl_keep isl_space
*space1
,
2656 __isl_keep isl_space
*space2
, enum isl_dim_type type
)
2659 isl_space
*nested1
, *nested2
;
2661 if (isl_space_dim(space1
, type
) != isl_space_dim(space2
, type
))
2662 return isl_space_dim(space1
, type
) -
2663 isl_space_dim(space2
, type
);
2665 cmp
= isl_id_cmp(tuple_id(space1
, type
), tuple_id(space2
, type
));
2669 nested1
= nested(space1
, type
);
2670 nested2
= nested(space2
, type
);
2671 if (!nested1
!= !nested2
)
2672 return !nested1
- !nested2
;
2675 return isl_space_cmp(nested1
, nested2
);
2680 /* Compare two isl_spaces.
2682 * The order is fairly arbitrary.
2684 int isl_space_cmp(__isl_keep isl_space
*space1
, __isl_keep isl_space
*space2
)
2689 if (space1
== space2
)
2696 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_param
);
2699 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_in
);
2702 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_out
);
2706 if (!space1
->ids
&& !space2
->ids
)
2709 for (i
= 0; i
< n(space1
, isl_dim_param
); ++i
) {
2710 cmp
= isl_id_cmp(get_id(space1
, isl_dim_param
, i
),
2711 get_id(space2
, isl_dim_param
, i
));