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
*dim
)
23 return dim
? dim
->ctx
: NULL
;
26 __isl_give isl_space
*isl_space_alloc(isl_ctx
*ctx
,
27 unsigned nparam
, unsigned n_in
, unsigned n_out
)
31 dim
= isl_alloc_type(ctx
, struct isl_space
);
42 dim
->tuple_id
[0] = NULL
;
43 dim
->tuple_id
[1] = NULL
;
45 dim
->nested
[0] = NULL
;
46 dim
->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 /* Is the given space that of a map?
81 isl_bool
isl_space_is_map(__isl_keep isl_space
*space
)
84 return isl_bool_error
;
85 return space
->tuple_id
[0] != &isl_id_none
&&
86 space
->tuple_id
[1] != &isl_id_none
;
89 __isl_give isl_space
*isl_space_set_alloc(isl_ctx
*ctx
,
90 unsigned nparam
, unsigned dim
)
93 space
= isl_space_alloc(ctx
, nparam
, 0, dim
);
94 space
= mark_as_set(space
);
98 /* Mark the space as being that of a parameter domain, by setting
99 * both tuples to isl_id_none.
101 static __isl_give isl_space
*mark_as_params(isl_space
*space
)
105 space
= isl_space_set_tuple_id(space
, isl_dim_in
, &isl_id_none
);
106 space
= isl_space_set_tuple_id(space
, isl_dim_out
, &isl_id_none
);
110 /* Is the space that of a parameter domain?
112 isl_bool
isl_space_is_params(__isl_keep isl_space
*space
)
115 return isl_bool_error
;
116 if (space
->n_in
!= 0 || space
->nested
[0] ||
117 space
->n_out
!= 0 || space
->nested
[1])
118 return isl_bool_false
;
119 if (space
->tuple_id
[0] != &isl_id_none
)
120 return isl_bool_false
;
121 if (space
->tuple_id
[1] != &isl_id_none
)
122 return isl_bool_false
;
123 return isl_bool_true
;
126 /* Create a space for a parameter domain.
128 __isl_give isl_space
*isl_space_params_alloc(isl_ctx
*ctx
, unsigned nparam
)
131 space
= isl_space_alloc(ctx
, nparam
, 0, 0);
132 space
= mark_as_params(space
);
136 static unsigned global_pos(__isl_keep isl_space
*dim
,
137 enum isl_dim_type type
, unsigned pos
)
139 struct isl_ctx
*ctx
= dim
->ctx
;
143 isl_assert(ctx
, pos
< dim
->nparam
,
144 return isl_space_dim(dim
, isl_dim_all
));
147 isl_assert(ctx
, pos
< dim
->n_in
,
148 return isl_space_dim(dim
, isl_dim_all
));
149 return pos
+ dim
->nparam
;
151 isl_assert(ctx
, pos
< dim
->n_out
,
152 return isl_space_dim(dim
, isl_dim_all
));
153 return pos
+ dim
->nparam
+ dim
->n_in
;
155 isl_assert(ctx
, 0, return isl_space_dim(dim
, isl_dim_all
));
157 return isl_space_dim(dim
, isl_dim_all
);
160 /* Extend length of ids array to the total number of dimensions.
162 static __isl_give isl_space
*extend_ids(__isl_take isl_space
*dim
)
167 if (isl_space_dim(dim
, isl_dim_all
) <= dim
->n_id
)
171 dim
->ids
= isl_calloc_array(dim
->ctx
,
172 isl_id
*, isl_space_dim(dim
, isl_dim_all
));
176 ids
= isl_realloc_array(dim
->ctx
, dim
->ids
,
177 isl_id
*, isl_space_dim(dim
, isl_dim_all
));
181 for (i
= dim
->n_id
; i
< isl_space_dim(dim
, isl_dim_all
); ++i
)
185 dim
->n_id
= isl_space_dim(dim
, isl_dim_all
);
193 static __isl_give isl_space
*set_id(__isl_take isl_space
*dim
,
194 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
196 dim
= isl_space_cow(dim
);
201 pos
= global_pos(dim
, type
, pos
);
202 if (pos
== isl_space_dim(dim
, isl_dim_all
))
205 if (pos
>= dim
->n_id
) {
208 dim
= extend_ids(dim
);
222 static __isl_keep isl_id
*get_id(__isl_keep isl_space
*dim
,
223 enum isl_dim_type type
, unsigned pos
)
228 pos
= global_pos(dim
, type
, pos
);
229 if (pos
== isl_space_dim(dim
, isl_dim_all
))
231 if (pos
>= dim
->n_id
)
233 return dim
->ids
[pos
];
236 static unsigned offset(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
239 case isl_dim_param
: return 0;
240 case isl_dim_in
: return dim
->nparam
;
241 case isl_dim_out
: return dim
->nparam
+ dim
->n_in
;
246 static unsigned n(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
249 case isl_dim_param
: return dim
->nparam
;
250 case isl_dim_in
: return dim
->n_in
;
251 case isl_dim_out
: return dim
->n_out
;
252 case isl_dim_all
: return dim
->nparam
+ dim
->n_in
+ dim
->n_out
;
257 unsigned isl_space_dim(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
264 unsigned isl_space_offset(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
268 return offset(dim
, type
);
271 static __isl_give isl_space
*copy_ids(__isl_take isl_space
*dst
,
272 enum isl_dim_type dst_type
, unsigned offset
, __isl_keep isl_space
*src
,
273 enum isl_dim_type src_type
)
281 for (i
= 0; i
< n(src
, src_type
); ++i
) {
282 id
= get_id(src
, src_type
, i
);
285 dst
= set_id(dst
, dst_type
, offset
+ i
, isl_id_copy(id
));
292 __isl_take isl_space
*isl_space_dup(__isl_keep isl_space
*dim
)
297 dup
= isl_space_alloc(dim
->ctx
, dim
->nparam
, dim
->n_in
, dim
->n_out
);
300 if (dim
->tuple_id
[0] &&
301 !(dup
->tuple_id
[0] = isl_id_copy(dim
->tuple_id
[0])))
303 if (dim
->tuple_id
[1] &&
304 !(dup
->tuple_id
[1] = isl_id_copy(dim
->tuple_id
[1])))
306 if (dim
->nested
[0] && !(dup
->nested
[0] = isl_space_copy(dim
->nested
[0])))
308 if (dim
->nested
[1] && !(dup
->nested
[1] = isl_space_copy(dim
->nested
[1])))
312 dup
= copy_ids(dup
, isl_dim_param
, 0, dim
, isl_dim_param
);
313 dup
= copy_ids(dup
, isl_dim_in
, 0, dim
, isl_dim_in
);
314 dup
= copy_ids(dup
, isl_dim_out
, 0, dim
, isl_dim_out
);
321 __isl_give isl_space
*isl_space_cow(__isl_take isl_space
*dim
)
329 return isl_space_dup(dim
);
332 __isl_give isl_space
*isl_space_copy(__isl_keep isl_space
*dim
)
341 __isl_null isl_space
*isl_space_free(__isl_take isl_space
*space
)
348 if (--space
->ref
> 0)
351 isl_id_free(space
->tuple_id
[0]);
352 isl_id_free(space
->tuple_id
[1]);
354 isl_space_free(space
->nested
[0]);
355 isl_space_free(space
->nested
[1]);
357 for (i
= 0; i
< space
->n_id
; ++i
)
358 isl_id_free(space
->ids
[i
]);
360 isl_ctx_deref(space
->ctx
);
367 /* Check if "s" is a valid dimension or tuple name.
368 * We currently only forbid names that look like a number.
370 * s is assumed to be non-NULL.
372 static int name_ok(isl_ctx
*ctx
, const char *s
)
377 dummy
= strtol(s
, &p
, 0);
379 isl_die(ctx
, isl_error_invalid
, "name looks like a number",
385 /* Is it possible for the given dimension type to have a tuple id?
387 static int space_can_have_id(__isl_keep isl_space
*space
,
388 enum isl_dim_type type
)
392 if (isl_space_is_params(space
))
393 isl_die(space
->ctx
, isl_error_invalid
,
394 "parameter spaces don't have tuple ids", return 0);
395 if (isl_space_is_set(space
) && type
!= isl_dim_set
)
396 isl_die(space
->ctx
, isl_error_invalid
,
397 "set spaces can only have a set id", return 0);
398 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
399 isl_die(space
->ctx
, isl_error_invalid
,
400 "only input, output and set tuples can have ids",
406 /* Does the tuple have an id?
408 isl_bool
isl_space_has_tuple_id(__isl_keep isl_space
*dim
,
409 enum isl_dim_type type
)
411 if (!space_can_have_id(dim
, type
))
412 return isl_bool_error
;
413 return dim
->tuple_id
[type
- isl_dim_in
] != NULL
;
416 __isl_give isl_id
*isl_space_get_tuple_id(__isl_keep isl_space
*dim
,
417 enum isl_dim_type type
)
423 has_id
= isl_space_has_tuple_id(dim
, type
);
427 isl_die(dim
->ctx
, isl_error_invalid
,
428 "tuple has no id", return NULL
);
429 return isl_id_copy(dim
->tuple_id
[type
- isl_dim_in
]);
432 __isl_give isl_space
*isl_space_set_tuple_id(__isl_take isl_space
*dim
,
433 enum isl_dim_type type
, __isl_take isl_id
*id
)
435 dim
= isl_space_cow(dim
);
438 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
439 isl_die(dim
->ctx
, isl_error_invalid
,
440 "only input, output and set tuples can have names",
443 isl_id_free(dim
->tuple_id
[type
- isl_dim_in
]);
444 dim
->tuple_id
[type
- isl_dim_in
] = id
;
453 __isl_give isl_space
*isl_space_reset_tuple_id(__isl_take isl_space
*dim
,
454 enum isl_dim_type type
)
456 dim
= isl_space_cow(dim
);
459 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
460 isl_die(dim
->ctx
, isl_error_invalid
,
461 "only input, output and set tuples can have names",
464 isl_id_free(dim
->tuple_id
[type
- isl_dim_in
]);
465 dim
->tuple_id
[type
- isl_dim_in
] = NULL
;
473 /* Set the id of the given dimension of "space" to "id".
474 * If the dimension already has an id, then it is replaced.
475 * If the dimension is a parameter, then we need to change it
476 * in the nested spaces (if any) as well.
478 __isl_give isl_space
*isl_space_set_dim_id(__isl_take isl_space
*space
,
479 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
481 space
= isl_space_cow(space
);
485 if (type
== isl_dim_param
) {
488 for (i
= 0; i
< 2; ++i
) {
489 if (!space
->nested
[i
])
492 isl_space_set_dim_id(space
->nested
[i
],
493 type
, pos
, isl_id_copy(id
));
494 if (!space
->nested
[i
])
499 isl_id_free(get_id(space
, type
, pos
));
500 return set_id(space
, type
, pos
, id
);
503 isl_space_free(space
);
507 /* Reset the id of the given dimension of "space".
508 * If the dimension already has an id, then it is removed.
509 * If the dimension is a parameter, then we need to reset it
510 * in the nested spaces (if any) as well.
512 __isl_give isl_space
*isl_space_reset_dim_id(__isl_take isl_space
*space
,
513 enum isl_dim_type type
, unsigned pos
)
515 space
= isl_space_cow(space
);
519 if (type
== isl_dim_param
) {
522 for (i
= 0; i
< 2; ++i
) {
523 if (!space
->nested
[i
])
526 isl_space_reset_dim_id(space
->nested
[i
],
528 if (!space
->nested
[i
])
533 isl_id_free(get_id(space
, type
, pos
));
534 return set_id(space
, type
, pos
, NULL
);
536 isl_space_free(space
);
540 isl_bool
isl_space_has_dim_id(__isl_keep isl_space
*dim
,
541 enum isl_dim_type type
, unsigned pos
)
544 return isl_bool_error
;
545 return get_id(dim
, type
, pos
) != NULL
;
548 __isl_give isl_id
*isl_space_get_dim_id(__isl_keep isl_space
*dim
,
549 enum isl_dim_type type
, unsigned pos
)
553 if (!get_id(dim
, type
, pos
))
554 isl_die(dim
->ctx
, isl_error_invalid
,
555 "dim has no id", return NULL
);
556 return isl_id_copy(get_id(dim
, type
, pos
));
559 __isl_give isl_space
*isl_space_set_tuple_name(__isl_take isl_space
*dim
,
560 enum isl_dim_type type
, const char *s
)
568 return isl_space_reset_tuple_id(dim
, type
);
570 if (!name_ok(dim
->ctx
, s
))
573 id
= isl_id_alloc(dim
->ctx
, s
, NULL
);
574 return isl_space_set_tuple_id(dim
, type
, id
);
580 /* Does the tuple have a name?
582 isl_bool
isl_space_has_tuple_name(__isl_keep isl_space
*space
,
583 enum isl_dim_type type
)
587 if (!space_can_have_id(space
, type
))
588 return isl_bool_error
;
589 id
= space
->tuple_id
[type
- isl_dim_in
];
590 return id
&& id
->name
;
593 __isl_keep
const char *isl_space_get_tuple_name(__isl_keep isl_space
*dim
,
594 enum isl_dim_type type
)
599 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
601 id
= dim
->tuple_id
[type
- isl_dim_in
];
602 return id
? id
->name
: NULL
;
605 __isl_give isl_space
*isl_space_set_dim_name(__isl_take isl_space
*dim
,
606 enum isl_dim_type type
, unsigned pos
,
614 return isl_space_reset_dim_id(dim
, type
, pos
);
615 if (!name_ok(dim
->ctx
, s
))
617 id
= isl_id_alloc(dim
->ctx
, s
, NULL
);
618 return isl_space_set_dim_id(dim
, type
, pos
, id
);
624 /* Does the given dimension have a name?
626 isl_bool
isl_space_has_dim_name(__isl_keep isl_space
*space
,
627 enum isl_dim_type type
, unsigned pos
)
632 return isl_bool_error
;
633 id
= get_id(space
, type
, pos
);
634 return id
&& id
->name
;
637 __isl_keep
const char *isl_space_get_dim_name(__isl_keep isl_space
*dim
,
638 enum isl_dim_type type
, unsigned pos
)
640 isl_id
*id
= get_id(dim
, type
, pos
);
641 return id
? id
->name
: NULL
;
644 int isl_space_find_dim_by_id(__isl_keep isl_space
*dim
, enum isl_dim_type type
,
645 __isl_keep isl_id
*id
)
654 offset
= isl_space_offset(dim
, type
);
655 n
= isl_space_dim(dim
, type
);
656 for (i
= 0; i
< n
&& offset
+ i
< dim
->n_id
; ++i
)
657 if (dim
->ids
[offset
+ i
] == id
)
663 int isl_space_find_dim_by_name(__isl_keep isl_space
*space
,
664 enum isl_dim_type type
, const char *name
)
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 isl_id
*id
= get_id(space
, type
, i
);
677 if (id
&& id
->name
&& !strcmp(id
->name
, name
))
684 /* Reset the user pointer on all identifiers of parameters and tuples
687 __isl_give isl_space
*isl_space_reset_user(__isl_take isl_space
*space
)
697 ctx
= isl_space_get_ctx(space
);
699 for (i
= 0; i
< space
->nparam
&& i
< space
->n_id
; ++i
) {
700 if (!isl_id_get_user(space
->ids
[i
]))
702 space
= isl_space_cow(space
);
705 name
= isl_id_get_name(space
->ids
[i
]);
706 id
= isl_id_alloc(ctx
, name
, NULL
);
707 isl_id_free(space
->ids
[i
]);
710 return isl_space_free(space
);
713 for (i
= 0; i
< 2; ++i
) {
714 if (!space
->tuple_id
[i
])
716 if (!isl_id_get_user(space
->tuple_id
[i
]))
718 space
= isl_space_cow(space
);
721 name
= isl_id_get_name(space
->tuple_id
[i
]);
722 id
= isl_id_alloc(ctx
, name
, NULL
);
723 isl_id_free(space
->tuple_id
[i
]);
724 space
->tuple_id
[i
] = id
;
726 return isl_space_free(space
);
729 for (i
= 0; i
< 2; ++i
) {
730 if (!space
->nested
[i
])
732 space
= isl_space_cow(space
);
735 space
->nested
[i
] = isl_space_reset_user(space
->nested
[i
]);
736 if (!space
->nested
[i
])
737 return isl_space_free(space
);
743 static __isl_keep isl_id
*tuple_id(__isl_keep isl_space
*dim
,
744 enum isl_dim_type type
)
748 if (type
== isl_dim_in
)
749 return dim
->tuple_id
[0];
750 if (type
== isl_dim_out
)
751 return dim
->tuple_id
[1];
755 static __isl_keep isl_space
*nested(__isl_keep isl_space
*dim
,
756 enum isl_dim_type type
)
760 if (type
== isl_dim_in
)
761 return dim
->nested
[0];
762 if (type
== isl_dim_out
)
763 return dim
->nested
[1];
767 /* Are the two spaces the same, apart from positions and names of parameters?
769 isl_bool
isl_space_has_equal_tuples(__isl_keep isl_space
*space1
,
770 __isl_keep isl_space
*space2
)
772 if (!space1
|| !space2
)
773 return isl_bool_error
;
774 if (space1
== space2
)
775 return isl_bool_true
;
776 return isl_space_tuple_is_equal(space1
, isl_dim_in
,
777 space2
, isl_dim_in
) &&
778 isl_space_tuple_is_equal(space1
, isl_dim_out
,
779 space2
, isl_dim_out
);
782 /* Check if the tuple of type "type1" of "space1" is the same as
783 * the tuple of type "type2" of "space2".
785 * That is, check if the tuples have the same identifier, the same dimension
786 * and the same internal structure.
787 * The identifiers of the dimensions inside the tuples do not affect the result.
789 * Note that this function only checks the tuples themselves.
790 * If nested tuples are involved, then we need to be careful not
791 * to have result affected by possibly differing parameters
792 * in those nested tuples.
794 isl_bool
isl_space_tuple_is_equal(__isl_keep isl_space
*space1
,
795 enum isl_dim_type type1
, __isl_keep isl_space
*space2
,
796 enum isl_dim_type type2
)
799 isl_space
*nested1
, *nested2
;
801 if (!space1
|| !space2
)
802 return isl_bool_error
;
804 if (space1
== space2
&& type1
== type2
)
805 return isl_bool_true
;
807 if (n(space1
, type1
) != n(space2
, type2
))
808 return isl_bool_false
;
809 id1
= tuple_id(space1
, type1
);
810 id2
= tuple_id(space2
, type2
);
812 return isl_bool_false
;
813 if (id1
&& id1
!= id2
)
814 return isl_bool_false
;
815 nested1
= nested(space1
, type1
);
816 nested2
= nested(space2
, type2
);
817 if (!nested1
^ !nested2
)
818 return isl_bool_false
;
819 if (nested1
&& !isl_space_has_equal_tuples(nested1
, nested2
))
820 return isl_bool_false
;
821 return isl_bool_true
;
824 static isl_bool
match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
825 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
829 if (space1
== space2
&& type1
== type2
)
830 return isl_bool_true
;
832 if (!isl_space_tuple_is_equal(space1
, type1
, space2
, type2
))
833 return isl_bool_false
;
835 if (!space1
->ids
&& !space2
->ids
)
836 return isl_bool_true
;
838 for (i
= 0; i
< n(space1
, type1
); ++i
) {
839 if (get_id(space1
, type1
, i
) != get_id(space2
, type2
, i
))
840 return isl_bool_false
;
842 return isl_bool_true
;
845 /* Do "space1" and "space2" have the same parameters?
847 isl_bool
isl_space_has_equal_params(__isl_keep isl_space
*space1
,
848 __isl_keep isl_space
*space2
)
850 if (!space1
|| !space2
)
851 return isl_bool_error
;
853 return match(space1
, isl_dim_param
, space2
, isl_dim_param
);
856 /* Do "space1" and "space2" have the same identifiers for all
857 * the tuple variables?
859 isl_bool
isl_space_has_equal_ids(__isl_keep isl_space
*space1
,
860 __isl_keep isl_space
*space2
)
864 if (!space1
|| !space2
)
865 return isl_bool_error
;
867 equal
= match(space1
, isl_dim_in
, space2
, isl_dim_in
);
868 if (equal
< 0 || !equal
)
870 return match(space1
, isl_dim_out
, space2
, isl_dim_out
);
873 isl_bool
isl_space_match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
874 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
876 if (!space1
|| !space2
)
877 return isl_bool_error
;
879 return match(space1
, type1
, space2
, type2
);
882 static void get_ids(__isl_keep isl_space
*dim
, enum isl_dim_type type
,
883 unsigned first
, unsigned n
, __isl_keep isl_id
**ids
)
887 for (i
= 0; i
< n
; ++i
)
888 ids
[i
] = get_id(dim
, type
, first
+ i
);
891 static __isl_give isl_space
*space_extend(__isl_take isl_space
*space
,
892 unsigned nparam
, unsigned n_in
, unsigned n_out
)
898 if (space
->nparam
== nparam
&&
899 space
->n_in
== n_in
&& space
->n_out
== n_out
)
902 isl_assert(space
->ctx
, space
->nparam
<= nparam
, goto error
);
903 isl_assert(space
->ctx
, space
->n_in
<= n_in
, goto error
);
904 isl_assert(space
->ctx
, space
->n_out
<= n_out
, goto error
);
906 space
= isl_space_cow(space
);
912 n
= nparam
+ n_in
+ n_out
;
913 if (n
< nparam
|| n
< n_in
|| n
< n_out
)
914 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
915 "overflow in total number of dimensions",
917 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n
);
920 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
921 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
+ nparam
);
922 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
923 ids
+ nparam
+ n_in
);
926 space
->n_id
= nparam
+ n_in
+ n_out
;
928 space
->nparam
= nparam
;
930 space
->n_out
= n_out
;
935 isl_space_free(space
);
939 __isl_give isl_space
*isl_space_extend(__isl_take isl_space
*space
,
940 unsigned nparam
, unsigned n_in
, unsigned n_out
)
942 return space_extend(space
, nparam
, n_in
, n_out
);
945 __isl_give isl_space
*isl_space_add_dims(__isl_take isl_space
*space
,
946 enum isl_dim_type type
, unsigned n
)
948 space
= isl_space_reset(space
, type
);
953 space
= space_extend(space
,
954 space
->nparam
+ n
, space
->n_in
, space
->n_out
);
955 if (space
&& space
->nested
[0] &&
956 !(space
->nested
[0] = isl_space_add_dims(space
->nested
[0],
959 if (space
&& space
->nested
[1] &&
960 !(space
->nested
[1] = isl_space_add_dims(space
->nested
[1],
965 return space_extend(space
,
966 space
->nparam
, space
->n_in
+ n
, space
->n_out
);
968 return space_extend(space
,
969 space
->nparam
, space
->n_in
, space
->n_out
+ n
);
971 isl_die(space
->ctx
, isl_error_invalid
,
972 "cannot add dimensions of specified type", goto error
);
975 isl_space_free(space
);
979 /* Add a parameter with identifier "id" to "space", provided
980 * it does not already appear in "space".
982 __isl_give isl_space
*isl_space_add_param_id(__isl_take isl_space
*space
,
983 __isl_take isl_id
*id
)
990 if (isl_space_find_dim_by_id(space
, isl_dim_param
, id
) >= 0) {
995 pos
= isl_space_dim(space
, isl_dim_param
);
996 space
= isl_space_add_dims(space
, isl_dim_param
, 1);
997 space
= isl_space_set_dim_id(space
, isl_dim_param
, pos
, id
);
1001 isl_space_free(space
);
1006 static int valid_dim_type(enum isl_dim_type type
)
1018 /* Insert "n" dimensions of type "type" at position "pos".
1019 * If we are inserting parameters, then they are also inserted in
1020 * any nested spaces.
1022 __isl_give isl_space
*isl_space_insert_dims(__isl_take isl_space
*dim
,
1023 enum isl_dim_type type
, unsigned pos
, unsigned n
)
1025 isl_id
**ids
= NULL
;
1030 return isl_space_reset(dim
, type
);
1032 if (!valid_dim_type(type
))
1033 isl_die(dim
->ctx
, isl_error_invalid
,
1034 "cannot insert dimensions of specified type",
1037 isl_assert(dim
->ctx
, pos
<= isl_space_dim(dim
, type
), goto error
);
1039 dim
= isl_space_cow(dim
);
1044 enum isl_dim_type t
, o
= isl_dim_param
;
1047 ids
= isl_calloc_array(dim
->ctx
, isl_id
*,
1048 dim
->nparam
+ dim
->n_in
+ dim
->n_out
+ n
);
1052 s
[isl_dim_param
- o
] = dim
->nparam
;
1053 s
[isl_dim_in
- o
] = dim
->n_in
;
1054 s
[isl_dim_out
- o
] = dim
->n_out
;
1055 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1057 get_ids(dim
, t
, 0, s
[t
- o
], ids
+ off
);
1060 get_ids(dim
, t
, 0, pos
, ids
+ off
);
1062 get_ids(dim
, t
, pos
, s
[t
- o
] - pos
, ids
+ off
);
1063 off
+= s
[t
- o
] - pos
;
1068 dim
->n_id
= dim
->nparam
+ dim
->n_in
+ dim
->n_out
+ n
;
1071 case isl_dim_param
: dim
->nparam
+= n
; break;
1072 case isl_dim_in
: dim
->n_in
+= n
; break;
1073 case isl_dim_out
: dim
->n_out
+= n
; break;
1076 dim
= isl_space_reset(dim
, type
);
1078 if (type
== isl_dim_param
) {
1079 if (dim
&& dim
->nested
[0] &&
1080 !(dim
->nested
[0] = isl_space_insert_dims(dim
->nested
[0],
1081 isl_dim_param
, pos
, n
)))
1083 if (dim
&& dim
->nested
[1] &&
1084 !(dim
->nested
[1] = isl_space_insert_dims(dim
->nested
[1],
1085 isl_dim_param
, pos
, n
)))
1091 isl_space_free(dim
);
1095 __isl_give isl_space
*isl_space_move_dims(__isl_take isl_space
*space
,
1096 enum isl_dim_type dst_type
, unsigned dst_pos
,
1097 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1101 space
= isl_space_reset(space
, src_type
);
1102 space
= isl_space_reset(space
, dst_type
);
1108 isl_assert(space
->ctx
, src_pos
+ n
<= isl_space_dim(space
, src_type
),
1111 if (dst_type
== src_type
&& dst_pos
== src_pos
)
1114 isl_assert(space
->ctx
, dst_type
!= src_type
, goto error
);
1116 space
= isl_space_cow(space
);
1122 enum isl_dim_type t
, o
= isl_dim_param
;
1125 ids
= isl_calloc_array(space
->ctx
, isl_id
*,
1126 space
->nparam
+ space
->n_in
+ space
->n_out
);
1130 s
[isl_dim_param
- o
] = space
->nparam
;
1131 s
[isl_dim_in
- o
] = space
->n_in
;
1132 s
[isl_dim_out
- o
] = space
->n_out
;
1133 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1134 if (t
== dst_type
) {
1135 get_ids(space
, t
, 0, dst_pos
, ids
+ off
);
1137 get_ids(space
, src_type
, src_pos
, n
, ids
+ off
);
1139 get_ids(space
, t
, dst_pos
, s
[t
- o
] - dst_pos
,
1141 off
+= s
[t
- o
] - dst_pos
;
1142 } else if (t
== src_type
) {
1143 get_ids(space
, t
, 0, src_pos
, ids
+ off
);
1145 get_ids(space
, t
, src_pos
+ n
,
1146 s
[t
- o
] - src_pos
- n
, ids
+ off
);
1147 off
+= s
[t
- o
] - src_pos
- n
;
1149 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1155 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
;
1159 case isl_dim_param
: space
->nparam
+= n
; break;
1160 case isl_dim_in
: space
->n_in
+= n
; break;
1161 case isl_dim_out
: space
->n_out
+= n
; break;
1166 case isl_dim_param
: space
->nparam
-= n
; break;
1167 case isl_dim_in
: space
->n_in
-= n
; break;
1168 case isl_dim_out
: space
->n_out
-= n
; break;
1172 if (dst_type
!= isl_dim_param
&& src_type
!= isl_dim_param
)
1175 for (i
= 0; i
< 2; ++i
) {
1176 if (!space
->nested
[i
])
1178 space
->nested
[i
] = isl_space_replace_params(space
->nested
[i
],
1180 if (!space
->nested
[i
])
1186 isl_space_free(space
);
1190 /* Check that "space1" and "space2" have the same parameters,
1191 * reporting an error if they do not.
1193 isl_stat
isl_space_check_equal_params(__isl_keep isl_space
*space1
,
1194 __isl_keep isl_space
*space2
)
1198 equal
= isl_space_has_equal_params(space1
, space2
);
1200 return isl_stat_error
;
1202 isl_die(isl_space_get_ctx(space1
), isl_error_invalid
,
1203 "parameters need to match", return isl_stat_error
);
1207 __isl_give isl_space
*isl_space_join(__isl_take isl_space
*left
,
1208 __isl_take isl_space
*right
)
1212 if (isl_space_check_equal_params(left
, right
) < 0)
1215 isl_assert(left
->ctx
,
1216 isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_in
),
1219 dim
= isl_space_alloc(left
->ctx
, left
->nparam
, left
->n_in
, right
->n_out
);
1223 dim
= copy_ids(dim
, isl_dim_param
, 0, left
, isl_dim_param
);
1224 dim
= copy_ids(dim
, isl_dim_in
, 0, left
, isl_dim_in
);
1225 dim
= copy_ids(dim
, isl_dim_out
, 0, right
, isl_dim_out
);
1227 if (dim
&& left
->tuple_id
[0] &&
1228 !(dim
->tuple_id
[0] = isl_id_copy(left
->tuple_id
[0])))
1230 if (dim
&& right
->tuple_id
[1] &&
1231 !(dim
->tuple_id
[1] = isl_id_copy(right
->tuple_id
[1])))
1233 if (dim
&& left
->nested
[0] &&
1234 !(dim
->nested
[0] = isl_space_copy(left
->nested
[0])))
1236 if (dim
&& right
->nested
[1] &&
1237 !(dim
->nested
[1] = isl_space_copy(right
->nested
[1])))
1240 isl_space_free(left
);
1241 isl_space_free(right
);
1245 isl_space_free(left
);
1246 isl_space_free(right
);
1250 /* Given two map spaces { A -> C } and { B -> D }, construct the space
1251 * { [A -> B] -> [C -> D] }.
1252 * Given two set spaces { A } and { B }, construct the space { [A -> B] }.
1254 __isl_give isl_space
*isl_space_product(__isl_take isl_space
*left
,
1255 __isl_take isl_space
*right
)
1257 isl_space
*dom1
, *dom2
, *nest1
, *nest2
;
1260 if (!left
|| !right
)
1263 is_set
= isl_space_is_set(left
);
1264 if (is_set
!= isl_space_is_set(right
))
1265 isl_die(isl_space_get_ctx(left
), isl_error_invalid
,
1266 "expecting either two set spaces or two map spaces",
1269 return isl_space_range_product(left
, right
);
1271 if (isl_space_check_equal_params(left
, right
) < 0)
1274 dom1
= isl_space_domain(isl_space_copy(left
));
1275 dom2
= isl_space_domain(isl_space_copy(right
));
1276 nest1
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1278 dom1
= isl_space_range(left
);
1279 dom2
= isl_space_range(right
);
1280 nest2
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1282 return isl_space_join(isl_space_reverse(nest1
), nest2
);
1284 isl_space_free(left
);
1285 isl_space_free(right
);
1289 /* Given two spaces { A -> C } and { B -> C }, construct the space
1292 __isl_give isl_space
*isl_space_domain_product(__isl_take isl_space
*left
,
1293 __isl_take isl_space
*right
)
1295 isl_space
*ran
, *dom1
, *dom2
, *nest
;
1297 if (isl_space_check_equal_params(left
, right
) < 0)
1300 if (!isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_out
))
1301 isl_die(left
->ctx
, isl_error_invalid
,
1302 "ranges need to match", goto error
);
1304 ran
= isl_space_range(isl_space_copy(left
));
1306 dom1
= isl_space_domain(left
);
1307 dom2
= isl_space_domain(right
);
1308 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1310 return isl_space_join(isl_space_reverse(nest
), ran
);
1312 isl_space_free(left
);
1313 isl_space_free(right
);
1317 __isl_give isl_space
*isl_space_range_product(__isl_take isl_space
*left
,
1318 __isl_take isl_space
*right
)
1320 isl_space
*dom
, *ran1
, *ran2
, *nest
;
1322 if (isl_space_check_equal_params(left
, right
) < 0)
1325 if (!isl_space_tuple_is_equal(left
, isl_dim_in
, right
, isl_dim_in
))
1326 isl_die(left
->ctx
, isl_error_invalid
,
1327 "domains need to match", goto error
);
1329 dom
= isl_space_domain(isl_space_copy(left
));
1331 ran1
= isl_space_range(left
);
1332 ran2
= isl_space_range(right
);
1333 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(ran1
), ran2
));
1335 return isl_space_join(isl_space_reverse(dom
), nest
);
1337 isl_space_free(left
);
1338 isl_space_free(right
);
1342 /* Given a space of the form [A -> B] -> C, return the space A -> C.
1344 __isl_give isl_space
*isl_space_domain_factor_domain(
1345 __isl_take isl_space
*space
)
1352 if (!isl_space_domain_is_wrapping(space
))
1353 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1354 "domain not a product", return isl_space_free(space
));
1356 nested
= space
->nested
[0];
1357 domain
= isl_space_copy(space
);
1358 domain
= isl_space_drop_dims(domain
, isl_dim_in
,
1359 nested
->n_in
, nested
->n_out
);
1361 return isl_space_free(space
);
1362 if (nested
->tuple_id
[0]) {
1363 domain
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[0]);
1364 if (!domain
->tuple_id
[0])
1367 if (nested
->nested
[0]) {
1368 domain
->nested
[0] = isl_space_copy(nested
->nested
[0]);
1369 if (!domain
->nested
[0])
1373 isl_space_free(space
);
1376 isl_space_free(space
);
1377 isl_space_free(domain
);
1381 /* Given a space of the form [A -> B] -> C, return the space B -> C.
1383 __isl_give isl_space
*isl_space_domain_factor_range(
1384 __isl_take isl_space
*space
)
1391 if (!isl_space_domain_is_wrapping(space
))
1392 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1393 "domain not a product", return isl_space_free(space
));
1395 nested
= space
->nested
[0];
1396 range
= isl_space_copy(space
);
1397 range
= isl_space_drop_dims(range
, isl_dim_in
, 0, nested
->n_in
);
1399 return isl_space_free(space
);
1400 if (nested
->tuple_id
[1]) {
1401 range
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[1]);
1402 if (!range
->tuple_id
[0])
1405 if (nested
->nested
[1]) {
1406 range
->nested
[0] = isl_space_copy(nested
->nested
[1]);
1407 if (!range
->nested
[0])
1411 isl_space_free(space
);
1414 isl_space_free(space
);
1415 isl_space_free(range
);
1419 /* Internal function that selects the domain of the map that is
1420 * embedded in either a set space or the range of a map space.
1421 * In particular, given a space of the form [A -> B], return the space A.
1422 * Given a space of the form A -> [B -> C], return the space A -> B.
1424 static __isl_give isl_space
*range_factor_domain(__isl_take isl_space
*space
)
1432 nested
= space
->nested
[1];
1433 domain
= isl_space_copy(space
);
1434 domain
= isl_space_drop_dims(domain
, isl_dim_out
,
1435 nested
->n_in
, nested
->n_out
);
1437 return isl_space_free(space
);
1438 if (nested
->tuple_id
[0]) {
1439 domain
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[0]);
1440 if (!domain
->tuple_id
[1])
1443 if (nested
->nested
[0]) {
1444 domain
->nested
[1] = isl_space_copy(nested
->nested
[0]);
1445 if (!domain
->nested
[1])
1449 isl_space_free(space
);
1452 isl_space_free(space
);
1453 isl_space_free(domain
);
1457 /* Given a space of the form A -> [B -> C], return the space A -> B.
1459 __isl_give isl_space
*isl_space_range_factor_domain(
1460 __isl_take isl_space
*space
)
1464 if (!isl_space_range_is_wrapping(space
))
1465 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1466 "range not a product", return isl_space_free(space
));
1468 return range_factor_domain(space
);
1471 /* Given a space of the form [A -> B], return the space A.
1473 static __isl_give isl_space
*set_factor_domain(__isl_take isl_space
*space
)
1477 if (!isl_space_is_wrapping(space
))
1478 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1479 "not a product", return isl_space_free(space
));
1481 return range_factor_domain(space
);
1484 /* Given a space of the form [A -> B] -> [C -> D], return the space A -> C.
1485 * Given a space of the form [A -> B], return the space A.
1487 __isl_give isl_space
*isl_space_factor_domain(__isl_take isl_space
*space
)
1491 if (isl_space_is_set(space
))
1492 return set_factor_domain(space
);
1493 space
= isl_space_domain_factor_domain(space
);
1494 space
= isl_space_range_factor_domain(space
);
1498 /* Internal function that selects the range of the map that is
1499 * embedded in either a set space or the range of a map space.
1500 * In particular, given a space of the form [A -> B], return the space B.
1501 * Given a space of the form A -> [B -> C], return the space A -> C.
1503 static __isl_give isl_space
*range_factor_range(__isl_take isl_space
*space
)
1511 nested
= space
->nested
[1];
1512 range
= isl_space_copy(space
);
1513 range
= isl_space_drop_dims(range
, isl_dim_out
, 0, nested
->n_in
);
1515 return isl_space_free(space
);
1516 if (nested
->tuple_id
[1]) {
1517 range
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[1]);
1518 if (!range
->tuple_id
[1])
1521 if (nested
->nested
[1]) {
1522 range
->nested
[1] = isl_space_copy(nested
->nested
[1]);
1523 if (!range
->nested
[1])
1527 isl_space_free(space
);
1530 isl_space_free(space
);
1531 isl_space_free(range
);
1535 /* Given a space of the form A -> [B -> C], return the space A -> C.
1537 __isl_give isl_space
*isl_space_range_factor_range(
1538 __isl_take isl_space
*space
)
1542 if (!isl_space_range_is_wrapping(space
))
1543 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1544 "range not a product", return isl_space_free(space
));
1546 return range_factor_range(space
);
1549 /* Given a space of the form [A -> B], return the space B.
1551 static __isl_give isl_space
*set_factor_range(__isl_take isl_space
*space
)
1555 if (!isl_space_is_wrapping(space
))
1556 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1557 "not a product", return isl_space_free(space
));
1559 return range_factor_range(space
);
1562 /* Given a space of the form [A -> B] -> [C -> D], return the space B -> D.
1563 * Given a space of the form [A -> B], return the space B.
1565 __isl_give isl_space
*isl_space_factor_range(__isl_take isl_space
*space
)
1569 if (isl_space_is_set(space
))
1570 return set_factor_range(space
);
1571 space
= isl_space_domain_factor_range(space
);
1572 space
= isl_space_range_factor_range(space
);
1576 __isl_give isl_space
*isl_space_map_from_set(__isl_take isl_space
*space
)
1579 isl_id
**ids
= NULL
;
1584 ctx
= isl_space_get_ctx(space
);
1585 if (!isl_space_is_set(space
))
1586 isl_die(ctx
, isl_error_invalid
, "not a set space", goto error
);
1587 space
= isl_space_cow(space
);
1590 n_id
= space
->nparam
+ space
->n_out
+ space
->n_out
;
1591 if (n_id
> 0 && space
->ids
) {
1592 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n_id
);
1595 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
1596 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1597 ids
+ space
->nparam
);
1599 space
->n_in
= space
->n_out
;
1604 space
= copy_ids(space
, isl_dim_out
, 0, space
, isl_dim_in
);
1606 isl_id_free(space
->tuple_id
[0]);
1607 space
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[1]);
1608 isl_space_free(space
->nested
[0]);
1609 space
->nested
[0] = isl_space_copy(space
->nested
[1]);
1612 isl_space_free(space
);
1616 __isl_give isl_space
*isl_space_map_from_domain_and_range(
1617 __isl_take isl_space
*domain
, __isl_take isl_space
*range
)
1619 if (!domain
|| !range
)
1621 if (!isl_space_is_set(domain
))
1622 isl_die(isl_space_get_ctx(domain
), isl_error_invalid
,
1623 "domain is not a set space", goto error
);
1624 if (!isl_space_is_set(range
))
1625 isl_die(isl_space_get_ctx(range
), isl_error_invalid
,
1626 "range is not a set space", goto error
);
1627 return isl_space_join(isl_space_reverse(domain
), range
);
1629 isl_space_free(domain
);
1630 isl_space_free(range
);
1634 static __isl_give isl_space
*set_ids(__isl_take isl_space
*dim
,
1635 enum isl_dim_type type
,
1636 unsigned first
, unsigned n
, __isl_take isl_id
**ids
)
1640 for (i
= 0; i
< n
; ++i
)
1641 dim
= set_id(dim
, type
, first
+ i
, ids
[i
]);
1646 __isl_give isl_space
*isl_space_reverse(__isl_take isl_space
*dim
)
1650 isl_id
**ids
= NULL
;
1655 if (match(dim
, isl_dim_in
, dim
, isl_dim_out
))
1658 dim
= isl_space_cow(dim
);
1662 id
= dim
->tuple_id
[0];
1663 dim
->tuple_id
[0] = dim
->tuple_id
[1];
1664 dim
->tuple_id
[1] = id
;
1666 nested
= dim
->nested
[0];
1667 dim
->nested
[0] = dim
->nested
[1];
1668 dim
->nested
[1] = nested
;
1671 int n_id
= dim
->n_in
+ dim
->n_out
;
1672 ids
= isl_alloc_array(dim
->ctx
, isl_id
*, n_id
);
1675 get_ids(dim
, isl_dim_in
, 0, dim
->n_in
, ids
);
1676 get_ids(dim
, isl_dim_out
, 0, dim
->n_out
, ids
+ dim
->n_in
);
1680 dim
->n_in
= dim
->n_out
;
1684 dim
= set_ids(dim
, isl_dim_out
, 0, dim
->n_out
, ids
);
1685 dim
= set_ids(dim
, isl_dim_in
, 0, dim
->n_in
, ids
+ dim
->n_out
);
1692 isl_space_free(dim
);
1696 __isl_give isl_space
*isl_space_drop_dims(__isl_take isl_space
*dim
,
1697 enum isl_dim_type type
, unsigned first
, unsigned num
)
1705 return isl_space_reset(dim
, type
);
1707 if (!valid_dim_type(type
))
1708 isl_die(dim
->ctx
, isl_error_invalid
,
1709 "cannot drop dimensions of specified type", goto error
);
1711 if (first
+ num
> n(dim
, type
) || first
+ num
< first
)
1712 isl_die(isl_space_get_ctx(dim
), isl_error_invalid
,
1713 "index out of bounds", return isl_space_free(dim
));
1714 dim
= isl_space_cow(dim
);
1718 dim
= extend_ids(dim
);
1721 for (i
= 0; i
< num
; ++i
)
1722 isl_id_free(get_id(dim
, type
, first
+ i
));
1723 for (i
= first
+num
; i
< n(dim
, type
); ++i
)
1724 set_id(dim
, type
, i
- num
, get_id(dim
, type
, i
));
1727 get_ids(dim
, isl_dim_in
, 0, dim
->n_in
,
1728 dim
->ids
+ offset(dim
, isl_dim_in
) - num
);
1730 get_ids(dim
, isl_dim_out
, 0, dim
->n_out
,
1731 dim
->ids
+ offset(dim
, isl_dim_out
) - num
);
1738 case isl_dim_param
: dim
->nparam
-= num
; break;
1739 case isl_dim_in
: dim
->n_in
-= num
; break;
1740 case isl_dim_out
: dim
->n_out
-= num
; break;
1743 dim
= isl_space_reset(dim
, type
);
1744 if (type
== isl_dim_param
) {
1745 if (dim
&& dim
->nested
[0] &&
1746 !(dim
->nested
[0] = isl_space_drop_dims(dim
->nested
[0],
1747 isl_dim_param
, first
, num
)))
1749 if (dim
&& dim
->nested
[1] &&
1750 !(dim
->nested
[1] = isl_space_drop_dims(dim
->nested
[1],
1751 isl_dim_param
, first
, num
)))
1756 isl_space_free(dim
);
1760 __isl_give isl_space
*isl_space_drop_inputs(__isl_take isl_space
*dim
,
1761 unsigned first
, unsigned n
)
1765 return isl_space_drop_dims(dim
, isl_dim_in
, first
, n
);
1768 __isl_give isl_space
*isl_space_drop_outputs(__isl_take isl_space
*dim
,
1769 unsigned first
, unsigned n
)
1773 return isl_space_drop_dims(dim
, isl_dim_out
, first
, n
);
1776 __isl_give isl_space
*isl_space_domain(__isl_take isl_space
*space
)
1780 space
= isl_space_drop_dims(space
, isl_dim_out
, 0, space
->n_out
);
1781 space
= isl_space_reverse(space
);
1782 space
= mark_as_set(space
);
1786 __isl_give isl_space
*isl_space_from_domain(__isl_take isl_space
*dim
)
1790 if (!isl_space_is_set(dim
))
1791 isl_die(isl_space_get_ctx(dim
), isl_error_invalid
,
1792 "not a set space", goto error
);
1793 dim
= isl_space_reverse(dim
);
1794 dim
= isl_space_reset(dim
, isl_dim_out
);
1797 isl_space_free(dim
);
1801 __isl_give isl_space
*isl_space_range(__isl_take isl_space
*space
)
1805 space
= isl_space_drop_dims(space
, isl_dim_in
, 0, space
->n_in
);
1806 space
= mark_as_set(space
);
1810 __isl_give isl_space
*isl_space_from_range(__isl_take isl_space
*dim
)
1814 if (!isl_space_is_set(dim
))
1815 isl_die(isl_space_get_ctx(dim
), isl_error_invalid
,
1816 "not a set space", goto error
);
1817 return isl_space_reset(dim
, isl_dim_in
);
1819 isl_space_free(dim
);
1823 /* Given a map space A -> B, return the map space [A -> B] -> A.
1825 __isl_give isl_space
*isl_space_domain_map(__isl_take isl_space
*space
)
1829 domain
= isl_space_from_range(isl_space_domain(isl_space_copy(space
)));
1830 space
= isl_space_from_domain(isl_space_wrap(space
));
1831 space
= isl_space_join(space
, domain
);
1836 /* Given a map space A -> B, return the map space [A -> B] -> B.
1838 __isl_give isl_space
*isl_space_range_map(__isl_take isl_space
*space
)
1842 range
= isl_space_from_range(isl_space_range(isl_space_copy(space
)));
1843 space
= isl_space_from_domain(isl_space_wrap(space
));
1844 space
= isl_space_join(space
, range
);
1849 __isl_give isl_space
*isl_space_params(__isl_take isl_space
*space
)
1851 if (isl_space_is_params(space
))
1853 space
= isl_space_drop_dims(space
,
1854 isl_dim_in
, 0, isl_space_dim(space
, isl_dim_in
));
1855 space
= isl_space_drop_dims(space
,
1856 isl_dim_out
, 0, isl_space_dim(space
, isl_dim_out
));
1857 space
= mark_as_params(space
);
1861 __isl_give isl_space
*isl_space_set_from_params(__isl_take isl_space
*space
)
1865 if (!isl_space_is_params(space
))
1866 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1867 "not a parameter space", goto error
);
1868 return isl_space_reset(space
, isl_dim_set
);
1870 isl_space_free(space
);
1874 __isl_give isl_space
*isl_space_underlying(__isl_take isl_space
*dim
,
1882 dim
->nparam
== 0 && dim
->n_in
== 0 && dim
->n_id
== 0)
1883 return isl_space_reset(isl_space_reset(dim
, isl_dim_in
), isl_dim_out
);
1884 dim
= isl_space_cow(dim
);
1887 dim
->n_out
+= dim
->nparam
+ dim
->n_in
+ n_div
;
1891 for (i
= 0; i
< dim
->n_id
; ++i
)
1892 isl_id_free(get_id(dim
, isl_dim_out
, i
));
1894 dim
= isl_space_reset(dim
, isl_dim_in
);
1895 dim
= isl_space_reset(dim
, isl_dim_out
);
1900 /* Are the two spaces the same, including positions and names of parameters?
1902 isl_bool
isl_space_is_equal(__isl_keep isl_space
*space1
,
1903 __isl_keep isl_space
*space2
)
1907 if (!space1
|| !space2
)
1908 return isl_bool_error
;
1909 if (space1
== space2
)
1910 return isl_bool_true
;
1911 equal
= isl_space_has_equal_params(space1
, space2
);
1912 if (equal
< 0 || !equal
)
1914 return isl_space_has_equal_tuples(space1
, space2
);
1917 /* Do the tuples of "space1" correspond to those of the domain of "space2"?
1918 * That is, is "space1" eqaul to the domain of "space2", ignoring parameters.
1920 * "space2" is allowed to be a set space, in which case "space1"
1921 * should be a parameter space.
1923 isl_bool
isl_space_has_domain_tuples(__isl_keep isl_space
*space1
,
1924 __isl_keep isl_space
*space2
)
1928 is_set
= isl_space_is_set(space1
);
1929 if (is_set
< 0 || !is_set
)
1931 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
1932 space2
, isl_dim_in
);
1935 /* Is space1 equal to the domain of space2?
1937 * In the internal version we also allow space2 to be the space of a set,
1938 * provided space1 is a parameter space.
1940 isl_bool
isl_space_is_domain_internal(__isl_keep isl_space
*space1
,
1941 __isl_keep isl_space
*space2
)
1943 isl_bool equal_params
;
1945 if (!space1
|| !space2
)
1946 return isl_bool_error
;
1947 equal_params
= isl_space_has_equal_params(space1
, space2
);
1948 if (equal_params
< 0 || !equal_params
)
1949 return equal_params
;
1950 return isl_space_has_domain_tuples(space1
, space2
);
1953 /* Is space1 equal to the domain of space2?
1955 isl_bool
isl_space_is_domain(__isl_keep isl_space
*space1
,
1956 __isl_keep isl_space
*space2
)
1959 return isl_bool_error
;
1960 if (!isl_space_is_map(space2
))
1961 return isl_bool_false
;
1962 return isl_space_is_domain_internal(space1
, space2
);
1965 /* Is space1 equal to the range of space2?
1967 * In the internal version, space2 is allowed to be the space of a set,
1968 * in which case it should be equal to space1.
1970 isl_bool
isl_space_is_range_internal(__isl_keep isl_space
*space1
,
1971 __isl_keep isl_space
*space2
)
1973 isl_bool equal_params
;
1975 if (!space1
|| !space2
)
1976 return isl_bool_error
;
1977 if (!isl_space_is_set(space1
))
1978 return isl_bool_false
;
1979 equal_params
= isl_space_has_equal_params(space1
, space2
);
1980 if (equal_params
< 0 || !equal_params
)
1981 return equal_params
;
1982 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
1983 space2
, isl_dim_out
);
1986 /* Is space1 equal to the range of space2?
1988 isl_bool
isl_space_is_range(__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_range_internal(space1
, space2
);
1998 /* Update "hash" by hashing in the parameters of "space".
2000 static uint32_t isl_hash_params(uint32_t hash
, __isl_keep isl_space
*space
)
2008 isl_hash_byte(hash
, space
->nparam
% 256);
2010 for (i
= 0; i
< space
->nparam
; ++i
) {
2011 id
= get_id(space
, isl_dim_param
, i
);
2012 hash
= isl_hash_id(hash
, id
);
2018 /* Update "hash" by hashing in the tuples of "space".
2019 * Changes in this function should be reflected in isl_hash_tuples_domain.
2021 static uint32_t isl_hash_tuples(uint32_t hash
, __isl_keep isl_space
*space
)
2028 isl_hash_byte(hash
, space
->n_in
% 256);
2029 isl_hash_byte(hash
, space
->n_out
% 256);
2031 id
= tuple_id(space
, isl_dim_in
);
2032 hash
= isl_hash_id(hash
, id
);
2033 id
= tuple_id(space
, isl_dim_out
);
2034 hash
= isl_hash_id(hash
, id
);
2036 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2037 hash
= isl_hash_tuples(hash
, space
->nested
[1]);
2042 /* Update "hash" by hashing in the domain tuple of "space".
2043 * The result of this function is equal to the result of applying
2044 * isl_hash_tuples to the domain of "space".
2046 static uint32_t isl_hash_tuples_domain(uint32_t hash
,
2047 __isl_keep isl_space
*space
)
2054 isl_hash_byte(hash
, 0);
2055 isl_hash_byte(hash
, space
->n_in
% 256);
2057 hash
= isl_hash_id(hash
, &isl_id_none
);
2058 id
= tuple_id(space
, isl_dim_in
);
2059 hash
= isl_hash_id(hash
, id
);
2061 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2066 /* Return a hash value that digests the tuples of "space",
2067 * i.e., that ignores the parameters.
2069 uint32_t isl_space_get_tuple_hash(__isl_keep isl_space
*space
)
2076 hash
= isl_hash_init();
2077 hash
= isl_hash_tuples(hash
, space
);
2082 uint32_t isl_space_get_hash(__isl_keep isl_space
*space
)
2089 hash
= isl_hash_init();
2090 hash
= isl_hash_params(hash
, space
);
2091 hash
= isl_hash_tuples(hash
, space
);
2096 /* Return the hash value of the domain of "space".
2097 * That is, isl_space_get_domain_hash(space) is equal to
2098 * isl_space_get_hash(isl_space_domain(space)).
2100 uint32_t isl_space_get_domain_hash(__isl_keep isl_space
*space
)
2107 hash
= isl_hash_init();
2108 hash
= isl_hash_params(hash
, space
);
2109 hash
= isl_hash_tuples_domain(hash
, space
);
2114 isl_bool
isl_space_is_wrapping(__isl_keep isl_space
*dim
)
2117 return isl_bool_error
;
2119 if (!isl_space_is_set(dim
))
2120 return isl_bool_false
;
2122 return dim
->nested
[1] != NULL
;
2125 /* Is "space" the space of a map where the domain is a wrapped map space?
2127 isl_bool
isl_space_domain_is_wrapping(__isl_keep isl_space
*space
)
2130 return isl_bool_error
;
2132 if (isl_space_is_set(space
))
2133 return isl_bool_false
;
2135 return space
->nested
[0] != NULL
;
2138 /* Is "space" the space of a map where the range is a wrapped map space?
2140 isl_bool
isl_space_range_is_wrapping(__isl_keep isl_space
*space
)
2143 return isl_bool_error
;
2145 if (isl_space_is_set(space
))
2146 return isl_bool_false
;
2148 return space
->nested
[1] != NULL
;
2151 /* Is "space" a product of two spaces?
2152 * That is, is it a wrapping set space or a map space
2153 * with wrapping domain and range?
2155 isl_bool
isl_space_is_product(__isl_keep isl_space
*space
)
2158 isl_bool is_product
;
2160 is_set
= isl_space_is_set(space
);
2162 return isl_bool_error
;
2164 return isl_space_is_wrapping(space
);
2165 is_product
= isl_space_domain_is_wrapping(space
);
2166 if (is_product
< 0 || !is_product
)
2168 return isl_space_range_is_wrapping(space
);
2171 __isl_give isl_space
*isl_space_wrap(__isl_take isl_space
*dim
)
2178 wrap
= isl_space_set_alloc(dim
->ctx
,
2179 dim
->nparam
, dim
->n_in
+ dim
->n_out
);
2181 wrap
= copy_ids(wrap
, isl_dim_param
, 0, dim
, isl_dim_param
);
2182 wrap
= copy_ids(wrap
, isl_dim_set
, 0, dim
, isl_dim_in
);
2183 wrap
= copy_ids(wrap
, isl_dim_set
, dim
->n_in
, dim
, isl_dim_out
);
2188 wrap
->nested
[1] = dim
;
2192 isl_space_free(dim
);
2196 __isl_give isl_space
*isl_space_unwrap(__isl_take isl_space
*dim
)
2203 if (!isl_space_is_wrapping(dim
))
2204 isl_die(dim
->ctx
, isl_error_invalid
, "not a wrapping space",
2207 unwrap
= isl_space_copy(dim
->nested
[1]);
2208 isl_space_free(dim
);
2212 isl_space_free(dim
);
2216 isl_bool
isl_space_is_named_or_nested(__isl_keep isl_space
*space
,
2217 enum isl_dim_type type
)
2219 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
2220 return isl_bool_false
;
2222 return isl_bool_error
;
2223 if (space
->tuple_id
[type
- isl_dim_in
])
2224 return isl_bool_true
;
2225 if (space
->nested
[type
- isl_dim_in
])
2226 return isl_bool_true
;
2227 return isl_bool_false
;
2230 isl_bool
isl_space_may_be_set(__isl_keep isl_space
*space
)
2235 return isl_bool_error
;
2236 if (isl_space_is_set(space
))
2237 return isl_bool_true
;
2238 if (isl_space_dim(space
, isl_dim_in
) != 0)
2239 return isl_bool_false
;
2240 nested
= isl_space_is_named_or_nested(space
, isl_dim_in
);
2241 if (nested
< 0 || nested
)
2242 return isl_bool_not(nested
);
2243 return isl_bool_true
;
2246 __isl_give isl_space
*isl_space_reset(__isl_take isl_space
*dim
,
2247 enum isl_dim_type type
)
2249 if (!isl_space_is_named_or_nested(dim
, type
))
2252 dim
= isl_space_cow(dim
);
2256 isl_id_free(dim
->tuple_id
[type
- isl_dim_in
]);
2257 dim
->tuple_id
[type
- isl_dim_in
] = NULL
;
2258 isl_space_free(dim
->nested
[type
- isl_dim_in
]);
2259 dim
->nested
[type
- isl_dim_in
] = NULL
;
2264 __isl_give isl_space
*isl_space_flatten(__isl_take isl_space
*dim
)
2268 if (!dim
->nested
[0] && !dim
->nested
[1])
2272 dim
= isl_space_reset(dim
, isl_dim_in
);
2273 if (dim
&& dim
->nested
[1])
2274 dim
= isl_space_reset(dim
, isl_dim_out
);
2279 __isl_give isl_space
*isl_space_flatten_domain(__isl_take isl_space
*space
)
2283 if (!space
->nested
[0])
2286 return isl_space_reset(space
, isl_dim_in
);
2289 __isl_give isl_space
*isl_space_flatten_range(__isl_take isl_space
*space
)
2293 if (!space
->nested
[1])
2296 return isl_space_reset(space
, isl_dim_out
);
2299 /* Replace the parameters of dst by those of src.
2301 __isl_give isl_space
*isl_space_replace_params(__isl_take isl_space
*dst
,
2302 __isl_keep isl_space
*src
)
2304 isl_bool equal_params
;
2305 enum isl_dim_type type
= isl_dim_param
;
2307 equal_params
= isl_space_has_equal_params(dst
, src
);
2308 if (equal_params
< 0)
2309 return isl_space_free(dst
);
2313 dst
= isl_space_cow(dst
);
2318 dst
= isl_space_drop_dims(dst
, type
, 0, isl_space_dim(dst
, type
));
2319 dst
= isl_space_add_dims(dst
, type
, isl_space_dim(src
, type
));
2320 dst
= copy_ids(dst
, type
, 0, src
, type
);
2324 for (i
= 0; i
<= 1; ++i
) {
2325 if (!dst
->nested
[i
])
2327 dst
->nested
[i
] = isl_space_replace_params(
2328 dst
->nested
[i
], src
);
2329 if (!dst
->nested
[i
])
2336 isl_space_free(dst
);
2340 /* Given a dimension specification "dim" of a set, create a dimension
2341 * specification for the lift of the set. In particular, the result
2342 * is of the form [dim -> local[..]], with n_local variables in the
2343 * range of the wrapped map.
2345 __isl_give isl_space
*isl_space_lift(__isl_take isl_space
*dim
, unsigned n_local
)
2347 isl_space
*local_dim
;
2352 local_dim
= isl_space_dup(dim
);
2353 local_dim
= isl_space_drop_dims(local_dim
, isl_dim_set
, 0, dim
->n_out
);
2354 local_dim
= isl_space_add_dims(local_dim
, isl_dim_set
, n_local
);
2355 local_dim
= isl_space_set_tuple_name(local_dim
, isl_dim_set
, "local");
2356 dim
= isl_space_join(isl_space_from_domain(dim
),
2357 isl_space_from_range(local_dim
));
2358 dim
= isl_space_wrap(dim
);
2359 dim
= isl_space_set_tuple_name(dim
, isl_dim_set
, "lifted");
2364 isl_bool
isl_space_can_zip(__isl_keep isl_space
*space
)
2368 is_set
= isl_space_is_set(space
);
2370 return isl_bool_error
;
2372 return isl_bool_false
;
2373 return isl_space_is_product(space
);
2376 __isl_give isl_space
*isl_space_zip(__isl_take isl_space
*dim
)
2378 isl_space
*dom
, *ran
;
2379 isl_space
*dom_dom
, *dom_ran
, *ran_dom
, *ran_ran
;
2381 if (!isl_space_can_zip(dim
))
2382 isl_die(dim
->ctx
, isl_error_invalid
, "dim cannot be zipped",
2387 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(dim
)));
2388 ran
= isl_space_unwrap(isl_space_range(dim
));
2389 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2390 dom_ran
= isl_space_range(dom
);
2391 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2392 ran_ran
= isl_space_range(ran
);
2393 dom
= isl_space_join(isl_space_from_domain(dom_dom
),
2394 isl_space_from_range(ran_dom
));
2395 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2396 isl_space_from_range(ran_ran
));
2397 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2398 isl_space_from_range(isl_space_wrap(ran
)));
2400 isl_space_free(dim
);
2404 /* Can we apply isl_space_curry to "space"?
2405 * That is, does it have a nested relation in its domain?
2407 isl_bool
isl_space_can_curry(__isl_keep isl_space
*space
)
2410 return isl_bool_error
;
2412 return !!space
->nested
[0];
2415 /* Given a space (A -> B) -> C, return the corresponding space
2418 __isl_give isl_space
*isl_space_curry(__isl_take isl_space
*space
)
2420 isl_space
*dom
, *ran
;
2421 isl_space
*dom_dom
, *dom_ran
;
2426 if (!isl_space_can_curry(space
))
2427 isl_die(space
->ctx
, isl_error_invalid
,
2428 "space cannot be curried", goto error
);
2430 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(space
)));
2431 ran
= isl_space_range(space
);
2432 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2433 dom_ran
= isl_space_range(dom
);
2434 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2435 isl_space_from_range(ran
));
2436 return isl_space_join(isl_space_from_domain(dom_dom
),
2437 isl_space_from_range(isl_space_wrap(ran
)));
2439 isl_space_free(space
);
2443 /* Can isl_space_range_curry be applied to "space"?
2444 * That is, does it have a nested relation in its range,
2445 * the domain of which is itself a nested relation?
2447 isl_bool
isl_space_can_range_curry(__isl_keep isl_space
*space
)
2452 return isl_bool_error
;
2453 can
= isl_space_range_is_wrapping(space
);
2454 if (can
< 0 || !can
)
2456 return isl_space_can_curry(space
->nested
[1]);
2459 /* Given a space A -> ((B -> C) -> D), return the corresponding space
2460 * A -> (B -> (C -> D)).
2462 __isl_give isl_space
*isl_space_range_curry(__isl_take isl_space
*space
)
2467 if (!isl_space_can_range_curry(space
))
2468 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2469 "space range cannot be curried",
2470 return isl_space_free(space
));
2472 space
= isl_space_cow(space
);
2475 space
->nested
[1] = isl_space_curry(space
->nested
[1]);
2476 if (!space
->nested
[1])
2477 return isl_space_free(space
);
2482 /* Can we apply isl_space_uncurry to "space"?
2483 * That is, does it have a nested relation in its range?
2485 isl_bool
isl_space_can_uncurry(__isl_keep isl_space
*space
)
2488 return isl_bool_error
;
2490 return !!space
->nested
[1];
2493 /* Given a space A -> (B -> C), return the corresponding space
2496 __isl_give isl_space
*isl_space_uncurry(__isl_take isl_space
*space
)
2498 isl_space
*dom
, *ran
;
2499 isl_space
*ran_dom
, *ran_ran
;
2504 if (!isl_space_can_uncurry(space
))
2505 isl_die(space
->ctx
, isl_error_invalid
,
2506 "space cannot be uncurried",
2507 return isl_space_free(space
));
2509 dom
= isl_space_domain(isl_space_copy(space
));
2510 ran
= isl_space_unwrap(isl_space_range(space
));
2511 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2512 ran_ran
= isl_space_range(ran
);
2513 dom
= isl_space_join(isl_space_from_domain(dom
),
2514 isl_space_from_range(ran_dom
));
2515 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2516 isl_space_from_range(ran_ran
));
2519 isl_bool
isl_space_has_named_params(__isl_keep isl_space
*space
)
2525 return isl_bool_error
;
2526 if (space
->nparam
== 0)
2527 return isl_bool_true
;
2528 off
= isl_space_offset(space
, isl_dim_param
);
2529 if (off
+ space
->nparam
> space
->n_id
)
2530 return isl_bool_false
;
2531 for (i
= 0; i
< space
->nparam
; ++i
)
2532 if (!space
->ids
[off
+ i
])
2533 return isl_bool_false
;
2534 return isl_bool_true
;
2537 /* Check that "space" has only named parameters, reporting an error
2540 isl_stat
isl_space_check_named_params(__isl_keep isl_space
*space
)
2544 named
= isl_space_has_named_params(space
);
2546 return isl_stat_error
;
2548 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2549 "unaligned unnamed parameters", return isl_stat_error
);
2554 /* Align the initial parameters of dim1 to match the order in dim2.
2556 __isl_give isl_space
*isl_space_align_params(__isl_take isl_space
*dim1
,
2557 __isl_take isl_space
*dim2
)
2559 isl_reordering
*exp
;
2561 if (!isl_space_has_named_params(dim1
) || !isl_space_has_named_params(dim2
))
2562 isl_die(isl_space_get_ctx(dim1
), isl_error_invalid
,
2563 "parameter alignment requires named parameters",
2566 dim2
= isl_space_params(dim2
);
2567 exp
= isl_parameter_alignment_reordering(dim1
, dim2
);
2568 exp
= isl_reordering_extend_space(exp
, dim1
);
2569 isl_space_free(dim2
);
2572 dim1
= isl_space_copy(exp
->dim
);
2573 isl_reordering_free(exp
);
2576 isl_space_free(dim1
);
2577 isl_space_free(dim2
);
2581 /* Given the space of set (domain), construct a space for a map
2582 * with as domain the given space and as range the range of "model".
2584 __isl_give isl_space
*isl_space_extend_domain_with_range(
2585 __isl_take isl_space
*space
, __isl_take isl_space
*model
)
2590 space
= isl_space_from_domain(space
);
2591 space
= isl_space_add_dims(space
, isl_dim_out
,
2592 isl_space_dim(model
, isl_dim_out
));
2593 if (isl_space_has_tuple_id(model
, isl_dim_out
))
2594 space
= isl_space_set_tuple_id(space
, isl_dim_out
,
2595 isl_space_get_tuple_id(model
, isl_dim_out
));
2598 if (model
->nested
[1]) {
2599 isl_space
*nested
= isl_space_copy(model
->nested
[1]);
2600 int n_nested
, n_space
;
2601 nested
= isl_space_align_params(nested
, isl_space_copy(space
));
2602 n_nested
= isl_space_dim(nested
, isl_dim_param
);
2603 n_space
= isl_space_dim(space
, isl_dim_param
);
2604 if (n_nested
> n_space
)
2605 nested
= isl_space_drop_dims(nested
, isl_dim_param
,
2606 n_space
, n_nested
- n_space
);
2609 space
->nested
[1] = nested
;
2611 isl_space_free(model
);
2614 isl_space_free(model
);
2615 isl_space_free(space
);
2619 /* Compare the "type" dimensions of two isl_spaces.
2621 * The order is fairly arbitrary.
2623 static int isl_space_cmp_type(__isl_keep isl_space
*space1
,
2624 __isl_keep isl_space
*space2
, enum isl_dim_type type
)
2627 isl_space
*nested1
, *nested2
;
2629 if (isl_space_dim(space1
, type
) != isl_space_dim(space2
, type
))
2630 return isl_space_dim(space1
, type
) -
2631 isl_space_dim(space2
, type
);
2633 cmp
= isl_id_cmp(tuple_id(space1
, type
), tuple_id(space2
, type
));
2637 nested1
= nested(space1
, type
);
2638 nested2
= nested(space2
, type
);
2639 if (!nested1
!= !nested2
)
2640 return !nested1
- !nested2
;
2643 return isl_space_cmp(nested1
, nested2
);
2648 /* Compare two isl_spaces.
2650 * The order is fairly arbitrary.
2652 int isl_space_cmp(__isl_keep isl_space
*space1
, __isl_keep isl_space
*space2
)
2657 if (space1
== space2
)
2664 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_param
);
2667 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_in
);
2670 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_out
);
2674 if (!space1
->ids
&& !space2
->ids
)
2677 for (i
= 0; i
< n(space1
, isl_dim_param
); ++i
) {
2678 cmp
= isl_id_cmp(get_id(space1
, isl_dim_param
, i
),
2679 get_id(space2
, isl_dim_param
, i
));