deprecate isl_basic_set_drop_constraint
[isl.git] / isl_space.c
blob952e5b548673791a6e85b11b7dfa52a5d576159e
1 /*
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
15 #include <stdlib.h>
16 #include <string.h>
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)
29 isl_space *dim;
31 dim = isl_alloc_type(ctx, struct isl_space);
32 if (!dim)
33 return NULL;
35 dim->ctx = ctx;
36 isl_ctx_ref(ctx);
37 dim->ref = 1;
38 dim->nparam = nparam;
39 dim->n_in = n_in;
40 dim->n_out = n_out;
42 dim->tuple_id[0] = NULL;
43 dim->tuple_id[1] = NULL;
45 dim->nested[0] = NULL;
46 dim->nested[1] = NULL;
48 dim->n_id = 0;
49 dim->ids = NULL;
51 return dim;
54 /* Mark the space as being that of a set, by setting the domain tuple
55 * to isl_id_none.
57 static __isl_give isl_space *mark_as_set(__isl_take isl_space *space)
59 space = isl_space_cow(space);
60 if (!space)
61 return NULL;
62 space = isl_space_set_tuple_id(space, isl_dim_in, &isl_id_none);
63 return space;
66 /* Is the space that of a set?
68 int isl_space_is_set(__isl_keep isl_space *space)
70 if (!space)
71 return -1;
72 if (space->n_in != 0 || space->nested[0])
73 return 0;
74 if (space->tuple_id[0] != &isl_id_none)
75 return 0;
76 return 1;
79 /* Is the given space that of a map?
81 int isl_space_is_map(__isl_keep isl_space *space)
83 if (!space)
84 return -1;
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)
92 isl_space *space;
93 space = isl_space_alloc(ctx, nparam, 0, dim);
94 space = mark_as_set(space);
95 return 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)
103 if (!space)
104 return NULL;
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);
107 return space;
110 /* Is the space that of a parameter domain?
112 int isl_space_is_params(__isl_keep isl_space *space)
114 if (!space)
115 return -1;
116 if (space->n_in != 0 || space->nested[0] ||
117 space->n_out != 0 || space->nested[1])
118 return 0;
119 if (space->tuple_id[0] != &isl_id_none)
120 return 0;
121 if (space->tuple_id[1] != &isl_id_none)
122 return 0;
123 return 1;
126 /* Create a space for a parameter domain.
128 __isl_give isl_space *isl_space_params_alloc(isl_ctx *ctx, unsigned nparam)
130 isl_space *space;
131 space = isl_space_alloc(ctx, nparam, 0, 0);
132 space = mark_as_params(space);
133 return 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;
141 switch (type) {
142 case isl_dim_param:
143 isl_assert(ctx, pos < dim->nparam,
144 return isl_space_dim(dim, isl_dim_all));
145 return pos;
146 case isl_dim_in:
147 isl_assert(ctx, pos < dim->n_in,
148 return isl_space_dim(dim, isl_dim_all));
149 return pos + dim->nparam;
150 case isl_dim_out:
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;
154 default:
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)
164 isl_id **ids;
165 int i;
167 if (isl_space_dim(dim, isl_dim_all) <= dim->n_id)
168 return dim;
170 if (!dim->ids) {
171 dim->ids = isl_calloc_array(dim->ctx,
172 isl_id *, isl_space_dim(dim, isl_dim_all));
173 if (!dim->ids)
174 goto error;
175 } else {
176 ids = isl_realloc_array(dim->ctx, dim->ids,
177 isl_id *, isl_space_dim(dim, isl_dim_all));
178 if (!ids)
179 goto error;
180 dim->ids = ids;
181 for (i = dim->n_id; i < isl_space_dim(dim, isl_dim_all); ++i)
182 dim->ids[i] = NULL;
185 dim->n_id = isl_space_dim(dim, isl_dim_all);
187 return dim;
188 error:
189 isl_space_free(dim);
190 return NULL;
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);
198 if (!dim)
199 goto error;
201 pos = global_pos(dim, type, pos);
202 if (pos == isl_space_dim(dim, isl_dim_all))
203 goto error;
205 if (pos >= dim->n_id) {
206 if (!id)
207 return dim;
208 dim = extend_ids(dim);
209 if (!dim)
210 goto error;
213 dim->ids[pos] = id;
215 return dim;
216 error:
217 isl_id_free(id);
218 isl_space_free(dim);
219 return NULL;
222 static __isl_keep isl_id *get_id(__isl_keep isl_space *dim,
223 enum isl_dim_type type, unsigned pos)
225 if (!dim)
226 return NULL;
228 pos = global_pos(dim, type, pos);
229 if (pos == isl_space_dim(dim, isl_dim_all))
230 return NULL;
231 if (pos >= dim->n_id)
232 return NULL;
233 return dim->ids[pos];
236 static unsigned offset(__isl_keep isl_space *dim, enum isl_dim_type type)
238 switch (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;
242 default: return 0;
246 static unsigned n(__isl_keep isl_space *dim, enum isl_dim_type type)
248 switch (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;
253 default: return 0;
257 unsigned isl_space_dim(__isl_keep isl_space *dim, enum isl_dim_type type)
259 if (!dim)
260 return 0;
261 return n(dim, type);
264 unsigned isl_space_offset(__isl_keep isl_space *dim, enum isl_dim_type type)
266 if (!dim)
267 return 0;
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)
275 int i;
276 isl_id *id;
278 if (!dst)
279 return NULL;
281 for (i = 0; i < n(src, src_type); ++i) {
282 id = get_id(src, src_type, i);
283 if (!id)
284 continue;
285 dst = set_id(dst, dst_type, offset + i, isl_id_copy(id));
286 if (!dst)
287 return NULL;
289 return dst;
292 __isl_take isl_space *isl_space_dup(__isl_keep isl_space *dim)
294 isl_space *dup;
295 if (!dim)
296 return NULL;
297 dup = isl_space_alloc(dim->ctx, dim->nparam, dim->n_in, dim->n_out);
298 if (!dup)
299 return NULL;
300 if (dim->tuple_id[0] &&
301 !(dup->tuple_id[0] = isl_id_copy(dim->tuple_id[0])))
302 goto error;
303 if (dim->tuple_id[1] &&
304 !(dup->tuple_id[1] = isl_id_copy(dim->tuple_id[1])))
305 goto error;
306 if (dim->nested[0] && !(dup->nested[0] = isl_space_copy(dim->nested[0])))
307 goto error;
308 if (dim->nested[1] && !(dup->nested[1] = isl_space_copy(dim->nested[1])))
309 goto error;
310 if (!dim->ids)
311 return dup;
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);
315 return dup;
316 error:
317 isl_space_free(dup);
318 return NULL;
321 __isl_give isl_space *isl_space_cow(__isl_take isl_space *dim)
323 if (!dim)
324 return NULL;
326 if (dim->ref == 1)
327 return dim;
328 dim->ref--;
329 return isl_space_dup(dim);
332 __isl_give isl_space *isl_space_copy(__isl_keep isl_space *dim)
334 if (!dim)
335 return NULL;
337 dim->ref++;
338 return dim;
341 __isl_null isl_space *isl_space_free(__isl_take isl_space *space)
343 int i;
345 if (!space)
346 return NULL;
348 if (--space->ref > 0)
349 return NULL;
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]);
359 free(space->ids);
360 isl_ctx_deref(space->ctx);
362 free(space);
364 return NULL;
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)
374 char *p;
375 long dummy;
377 dummy = strtol(s, &p, 0);
378 if (p != s)
379 isl_die(ctx, isl_error_invalid, "name looks like a number",
380 return 0);
382 return 1;
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)
390 if (!space)
391 return 0;
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",
401 return 0);
403 return 1;
406 /* Does the tuple have an id?
408 int isl_space_has_tuple_id(__isl_keep isl_space *dim, enum isl_dim_type type)
410 if (!space_can_have_id(dim, type))
411 return -1;
412 return dim->tuple_id[type - isl_dim_in] != NULL;
415 __isl_give isl_id *isl_space_get_tuple_id(__isl_keep isl_space *dim,
416 enum isl_dim_type type)
418 int has_id;
420 if (!dim)
421 return NULL;
422 has_id = isl_space_has_tuple_id(dim, type);
423 if (has_id < 0)
424 return NULL;
425 if (!has_id)
426 isl_die(dim->ctx, isl_error_invalid,
427 "tuple has no id", return NULL);
428 return isl_id_copy(dim->tuple_id[type - isl_dim_in]);
431 __isl_give isl_space *isl_space_set_tuple_id(__isl_take isl_space *dim,
432 enum isl_dim_type type, __isl_take isl_id *id)
434 dim = isl_space_cow(dim);
435 if (!dim || !id)
436 goto error;
437 if (type != isl_dim_in && type != isl_dim_out)
438 isl_die(dim->ctx, isl_error_invalid,
439 "only input, output and set tuples can have names",
440 goto error);
442 isl_id_free(dim->tuple_id[type - isl_dim_in]);
443 dim->tuple_id[type - isl_dim_in] = id;
445 return dim;
446 error:
447 isl_id_free(id);
448 isl_space_free(dim);
449 return NULL;
452 __isl_give isl_space *isl_space_reset_tuple_id(__isl_take isl_space *dim,
453 enum isl_dim_type type)
455 dim = isl_space_cow(dim);
456 if (!dim)
457 return NULL;
458 if (type != isl_dim_in && type != isl_dim_out)
459 isl_die(dim->ctx, isl_error_invalid,
460 "only input, output and set tuples can have names",
461 goto error);
463 isl_id_free(dim->tuple_id[type - isl_dim_in]);
464 dim->tuple_id[type - isl_dim_in] = NULL;
466 return dim;
467 error:
468 isl_space_free(dim);
469 return NULL;
472 /* Set the id of the given dimension of "space" to "id".
473 * If the dimension already has an id, then it is replaced.
474 * If the dimension is a parameter, then we need to change it
475 * in the nested spaces (if any) as well.
477 __isl_give isl_space *isl_space_set_dim_id(__isl_take isl_space *space,
478 enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
480 space = isl_space_cow(space);
481 if (!space || !id)
482 goto error;
484 if (type == isl_dim_param) {
485 int i;
487 for (i = 0; i < 2; ++i) {
488 if (!space->nested[i])
489 continue;
490 space->nested[i] =
491 isl_space_set_dim_id(space->nested[i],
492 type, pos, isl_id_copy(id));
493 if (!space->nested[i])
494 goto error;
498 isl_id_free(get_id(space, type, pos));
499 return set_id(space, type, pos, id);
500 error:
501 isl_id_free(id);
502 isl_space_free(space);
503 return NULL;
506 /* Reset the id of the given dimension of "space".
507 * If the dimension already has an id, then it is removed.
508 * If the dimension is a parameter, then we need to reset it
509 * in the nested spaces (if any) as well.
511 __isl_give isl_space *isl_space_reset_dim_id(__isl_take isl_space *space,
512 enum isl_dim_type type, unsigned pos)
514 space = isl_space_cow(space);
515 if (!space)
516 goto error;
518 if (type == isl_dim_param) {
519 int i;
521 for (i = 0; i < 2; ++i) {
522 if (!space->nested[i])
523 continue;
524 space->nested[i] =
525 isl_space_reset_dim_id(space->nested[i],
526 type, pos);
527 if (!space->nested[i])
528 goto error;
532 isl_id_free(get_id(space, type, pos));
533 return set_id(space, type, pos, NULL);
534 error:
535 isl_space_free(space);
536 return NULL;
539 int isl_space_has_dim_id(__isl_keep isl_space *dim,
540 enum isl_dim_type type, unsigned pos)
542 if (!dim)
543 return -1;
544 return get_id(dim, type, pos) != NULL;
547 __isl_give isl_id *isl_space_get_dim_id(__isl_keep isl_space *dim,
548 enum isl_dim_type type, unsigned pos)
550 if (!dim)
551 return NULL;
552 if (!get_id(dim, type, pos))
553 isl_die(dim->ctx, isl_error_invalid,
554 "dim has no id", return NULL);
555 return isl_id_copy(get_id(dim, type, pos));
558 __isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *dim,
559 enum isl_dim_type type, const char *s)
561 isl_id *id;
563 if (!dim)
564 return NULL;
566 if (!s)
567 return isl_space_reset_tuple_id(dim, type);
569 if (!name_ok(dim->ctx, s))
570 goto error;
572 id = isl_id_alloc(dim->ctx, s, NULL);
573 return isl_space_set_tuple_id(dim, type, id);
574 error:
575 isl_space_free(dim);
576 return NULL;
579 /* Does the tuple have a name?
581 int isl_space_has_tuple_name(__isl_keep isl_space *space,
582 enum isl_dim_type type)
584 isl_id *id;
586 if (!space_can_have_id(space, type))
587 return -1;
588 id = space->tuple_id[type - isl_dim_in];
589 return id && id->name;
592 const char *isl_space_get_tuple_name(__isl_keep isl_space *dim,
593 enum isl_dim_type type)
595 isl_id *id;
596 if (!dim)
597 return NULL;
598 if (type != isl_dim_in && type != isl_dim_out)
599 return NULL;
600 id = dim->tuple_id[type - isl_dim_in];
601 return id ? id->name : NULL;
604 __isl_give isl_space *isl_space_set_dim_name(__isl_take isl_space *dim,
605 enum isl_dim_type type, unsigned pos,
606 const char *s)
608 isl_id *id;
610 if (!dim)
611 return NULL;
612 if (!s)
613 return isl_space_reset_dim_id(dim, type, pos);
614 if (!name_ok(dim->ctx, s))
615 goto error;
616 id = isl_id_alloc(dim->ctx, s, NULL);
617 return isl_space_set_dim_id(dim, type, pos, id);
618 error:
619 isl_space_free(dim);
620 return NULL;
623 /* Does the given dimension have a name?
625 int isl_space_has_dim_name(__isl_keep isl_space *space,
626 enum isl_dim_type type, unsigned pos)
628 isl_id *id;
630 if (!space)
631 return -1;
632 id = get_id(space, type, pos);
633 return id && id->name;
636 __isl_keep const char *isl_space_get_dim_name(__isl_keep isl_space *dim,
637 enum isl_dim_type type, unsigned pos)
639 isl_id *id = get_id(dim, type, pos);
640 return id ? id->name : NULL;
643 int isl_space_find_dim_by_id(__isl_keep isl_space *dim, enum isl_dim_type type,
644 __isl_keep isl_id *id)
646 int i;
647 int offset;
648 int n;
650 if (!dim || !id)
651 return -1;
653 offset = isl_space_offset(dim, type);
654 n = isl_space_dim(dim, type);
655 for (i = 0; i < n && offset + i < dim->n_id; ++i)
656 if (dim->ids[offset + i] == id)
657 return i;
659 return -1;
662 int isl_space_find_dim_by_name(__isl_keep isl_space *space,
663 enum isl_dim_type type, const char *name)
665 int i;
666 int offset;
667 int n;
669 if (!space || !name)
670 return -1;
672 offset = isl_space_offset(space, type);
673 n = isl_space_dim(space, type);
674 for (i = 0; i < n && offset + i < space->n_id; ++i)
675 if (space->ids[offset + i]->name &&
676 !strcmp(space->ids[offset + i]->name, name))
677 return i;
679 return -1;
682 /* Reset the user pointer on all identifiers of parameters and tuples
683 * of "space".
685 __isl_give isl_space *isl_space_reset_user(__isl_take isl_space *space)
687 int i;
688 isl_ctx *ctx;
689 isl_id *id;
690 const char *name;
692 if (!space)
693 return NULL;
695 ctx = isl_space_get_ctx(space);
697 for (i = 0; i < space->nparam && i < space->n_id; ++i) {
698 if (!isl_id_get_user(space->ids[i]))
699 continue;
700 space = isl_space_cow(space);
701 if (!space)
702 return NULL;
703 name = isl_id_get_name(space->ids[i]);
704 id = isl_id_alloc(ctx, name, NULL);
705 isl_id_free(space->ids[i]);
706 space->ids[i] = id;
707 if (!id)
708 return isl_space_free(space);
711 for (i = 0; i < 2; ++i) {
712 if (!space->tuple_id[i])
713 continue;
714 if (!isl_id_get_user(space->tuple_id[i]))
715 continue;
716 space = isl_space_cow(space);
717 if (!space)
718 return NULL;
719 name = isl_id_get_name(space->tuple_id[i]);
720 id = isl_id_alloc(ctx, name, NULL);
721 isl_id_free(space->tuple_id[i]);
722 space->tuple_id[i] = id;
723 if (!id)
724 return isl_space_free(space);
727 for (i = 0; i < 2; ++i) {
728 if (!space->nested[i])
729 continue;
730 space = isl_space_cow(space);
731 if (!space)
732 return NULL;
733 space->nested[i] = isl_space_reset_user(space->nested[i]);
734 if (!space->nested[i])
735 return isl_space_free(space);
738 return space;
741 static __isl_keep isl_id *tuple_id(__isl_keep isl_space *dim,
742 enum isl_dim_type type)
744 if (!dim)
745 return NULL;
746 if (type == isl_dim_in)
747 return dim->tuple_id[0];
748 if (type == isl_dim_out)
749 return dim->tuple_id[1];
750 return NULL;
753 static __isl_keep isl_space *nested(__isl_keep isl_space *dim,
754 enum isl_dim_type type)
756 if (!dim)
757 return NULL;
758 if (type == isl_dim_in)
759 return dim->nested[0];
760 if (type == isl_dim_out)
761 return dim->nested[1];
762 return NULL;
765 /* Are the two spaces the same, apart from positions and names of parameters?
767 static int isl_space_has_equal_tuples(__isl_keep isl_space *space1,
768 __isl_keep isl_space *space2)
770 if (!space1 || !space2)
771 return -1;
772 if (space1 == space2)
773 return 1;
774 return isl_space_tuple_is_equal(space1, isl_dim_in,
775 space2, isl_dim_in) &&
776 isl_space_tuple_is_equal(space1, isl_dim_out,
777 space2, isl_dim_out);
780 /* Check if the tuple of type "type1" of "space1" is the same as
781 * the tuple of type "type2" of "space2".
783 * That is, check if the tuples have the same identifier, the same dimension
784 * and the same internal structure.
785 * The identifiers of the dimensions inside the tuples do not affect the result.
787 * Note that this function only checks the tuples themselves.
788 * If nested tuples are involved, then we need to be careful not
789 * to have result affected by possibly differing parameters
790 * in those nested tuples.
792 int isl_space_tuple_is_equal(__isl_keep isl_space *space1,
793 enum isl_dim_type type1, __isl_keep isl_space *space2,
794 enum isl_dim_type type2)
796 isl_id *id1, *id2;
797 isl_space *nested1, *nested2;
799 if (!space1 || !space2)
800 return -1;
802 if (space1 == space2 && type1 == type2)
803 return 1;
805 if (n(space1, type1) != n(space2, type2))
806 return 0;
807 id1 = tuple_id(space1, type1);
808 id2 = tuple_id(space2, type2);
809 if (!id1 ^ !id2)
810 return 0;
811 if (id1 && id1 != id2)
812 return 0;
813 nested1 = nested(space1, type1);
814 nested2 = nested(space2, type2);
815 if (!nested1 ^ !nested2)
816 return 0;
817 if (nested1 && !isl_space_has_equal_tuples(nested1, nested2))
818 return 0;
819 return 1;
822 /* This is the old, undocumented, name for isl_space_tuple_is_equal.
823 * It will be removed at some point.
825 int isl_space_tuple_match(__isl_keep isl_space *space1, enum isl_dim_type type1,
826 __isl_keep isl_space *space2, enum isl_dim_type type2)
828 return isl_space_tuple_is_equal(space1, type1, space2, type2);
831 static int match(__isl_keep isl_space *dim1, enum isl_dim_type dim1_type,
832 __isl_keep isl_space *dim2, enum isl_dim_type dim2_type)
834 int i;
836 if (dim1 == dim2 && dim1_type == dim2_type)
837 return 1;
839 if (!isl_space_tuple_is_equal(dim1, dim1_type, dim2, dim2_type))
840 return 0;
842 if (!dim1->ids && !dim2->ids)
843 return 1;
845 for (i = 0; i < n(dim1, dim1_type); ++i) {
846 if (get_id(dim1, dim1_type, i) != get_id(dim2, dim2_type, i))
847 return 0;
849 return 1;
852 int isl_space_match(__isl_keep isl_space *dim1, enum isl_dim_type dim1_type,
853 __isl_keep isl_space *dim2, enum isl_dim_type dim2_type)
855 if (!dim1 || !dim2)
856 return -1;
858 return match(dim1, dim1_type, dim2, dim2_type);
861 static void get_ids(__isl_keep isl_space *dim, enum isl_dim_type type,
862 unsigned first, unsigned n, __isl_keep isl_id **ids)
864 int i;
866 for (i = 0; i < n ; ++i)
867 ids[i] = get_id(dim, type, first + i);
870 __isl_give isl_space *isl_space_extend(__isl_take isl_space *dim,
871 unsigned nparam, unsigned n_in, unsigned n_out)
873 isl_id **ids = NULL;
875 if (!dim)
876 return NULL;
877 if (dim->nparam == nparam && dim->n_in == n_in && dim->n_out == n_out)
878 return dim;
880 isl_assert(dim->ctx, dim->nparam <= nparam, goto error);
881 isl_assert(dim->ctx, dim->n_in <= n_in, goto error);
882 isl_assert(dim->ctx, dim->n_out <= n_out, goto error);
884 dim = isl_space_cow(dim);
885 if (!dim)
886 goto error;
888 if (dim->ids) {
889 ids = isl_calloc_array(dim->ctx, isl_id *,
890 nparam + n_in + n_out);
891 if (!ids)
892 goto error;
893 get_ids(dim, isl_dim_param, 0, dim->nparam, ids);
894 get_ids(dim, isl_dim_in, 0, dim->n_in, ids + nparam);
895 get_ids(dim, isl_dim_out, 0, dim->n_out, ids + nparam + n_in);
896 free(dim->ids);
897 dim->ids = ids;
898 dim->n_id = nparam + n_in + n_out;
900 dim->nparam = nparam;
901 dim->n_in = n_in;
902 dim->n_out = n_out;
904 return dim;
905 error:
906 free(ids);
907 isl_space_free(dim);
908 return NULL;
911 __isl_give isl_space *isl_space_add_dims(__isl_take isl_space *dim,
912 enum isl_dim_type type, unsigned n)
914 if (!dim)
915 return NULL;
916 dim = isl_space_reset(dim, type);
917 switch (type) {
918 case isl_dim_param:
919 dim = isl_space_extend(dim,
920 dim->nparam + n, dim->n_in, dim->n_out);
921 if (dim && dim->nested[0] &&
922 !(dim->nested[0] = isl_space_add_dims(dim->nested[0],
923 isl_dim_param, n)))
924 goto error;
925 if (dim && dim->nested[1] &&
926 !(dim->nested[1] = isl_space_add_dims(dim->nested[1],
927 isl_dim_param, n)))
928 goto error;
929 return dim;
930 case isl_dim_in:
931 return isl_space_extend(dim,
932 dim->nparam, dim->n_in + n, dim->n_out);
933 case isl_dim_out:
934 return isl_space_extend(dim,
935 dim->nparam, dim->n_in, dim->n_out + n);
936 default:
937 isl_die(dim->ctx, isl_error_invalid,
938 "cannot add dimensions of specified type", goto error);
940 error:
941 isl_space_free(dim);
942 return NULL;
945 static int valid_dim_type(enum isl_dim_type type)
947 switch (type) {
948 case isl_dim_param:
949 case isl_dim_in:
950 case isl_dim_out:
951 return 1;
952 default:
953 return 0;
957 /* Insert "n" dimensions of type "type" at position "pos".
958 * If we are inserting parameters, then they are also inserted in
959 * any nested spaces.
961 __isl_give isl_space *isl_space_insert_dims(__isl_take isl_space *dim,
962 enum isl_dim_type type, unsigned pos, unsigned n)
964 isl_id **ids = NULL;
966 if (!dim)
967 return NULL;
968 if (n == 0)
969 return isl_space_reset(dim, type);
971 if (!valid_dim_type(type))
972 isl_die(dim->ctx, isl_error_invalid,
973 "cannot insert dimensions of specified type",
974 goto error);
976 isl_assert(dim->ctx, pos <= isl_space_dim(dim, type), goto error);
978 dim = isl_space_cow(dim);
979 if (!dim)
980 return NULL;
982 if (dim->ids) {
983 enum isl_dim_type t, o = isl_dim_param;
984 int off;
985 int s[3];
986 ids = isl_calloc_array(dim->ctx, isl_id *,
987 dim->nparam + dim->n_in + dim->n_out + n);
988 if (!ids)
989 goto error;
990 off = 0;
991 s[isl_dim_param - o] = dim->nparam;
992 s[isl_dim_in - o] = dim->n_in;
993 s[isl_dim_out - o] = dim->n_out;
994 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
995 if (t != type) {
996 get_ids(dim, t, 0, s[t - o], ids + off);
997 off += s[t - o];
998 } else {
999 get_ids(dim, t, 0, pos, ids + off);
1000 off += pos + n;
1001 get_ids(dim, t, pos, s[t - o] - pos, ids + off);
1002 off += s[t - o] - pos;
1005 free(dim->ids);
1006 dim->ids = ids;
1007 dim->n_id = dim->nparam + dim->n_in + dim->n_out + n;
1009 switch (type) {
1010 case isl_dim_param: dim->nparam += n; break;
1011 case isl_dim_in: dim->n_in += n; break;
1012 case isl_dim_out: dim->n_out += n; break;
1013 default: ;
1015 dim = isl_space_reset(dim, type);
1017 if (type == isl_dim_param) {
1018 if (dim && dim->nested[0] &&
1019 !(dim->nested[0] = isl_space_insert_dims(dim->nested[0],
1020 isl_dim_param, pos, n)))
1021 goto error;
1022 if (dim && dim->nested[1] &&
1023 !(dim->nested[1] = isl_space_insert_dims(dim->nested[1],
1024 isl_dim_param, pos, n)))
1025 goto error;
1028 return dim;
1029 error:
1030 isl_space_free(dim);
1031 return NULL;
1034 __isl_give isl_space *isl_space_move_dims(__isl_take isl_space *dim,
1035 enum isl_dim_type dst_type, unsigned dst_pos,
1036 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
1038 int i;
1040 if (!dim)
1041 return NULL;
1042 if (n == 0) {
1043 dim = isl_space_reset(dim, src_type);
1044 return isl_space_reset(dim, dst_type);
1047 isl_assert(dim->ctx, src_pos + n <= isl_space_dim(dim, src_type),
1048 goto error);
1050 if (dst_type == src_type && dst_pos == src_pos)
1051 return dim;
1053 isl_assert(dim->ctx, dst_type != src_type, goto error);
1055 dim = isl_space_reset(dim, src_type);
1056 dim = isl_space_reset(dim, dst_type);
1058 dim = isl_space_cow(dim);
1059 if (!dim)
1060 return NULL;
1062 if (dim->ids) {
1063 isl_id **ids;
1064 enum isl_dim_type t, o = isl_dim_param;
1065 int off;
1066 int s[3];
1067 ids = isl_calloc_array(dim->ctx, isl_id *,
1068 dim->nparam + dim->n_in + dim->n_out);
1069 if (!ids)
1070 goto error;
1071 off = 0;
1072 s[isl_dim_param - o] = dim->nparam;
1073 s[isl_dim_in - o] = dim->n_in;
1074 s[isl_dim_out - o] = dim->n_out;
1075 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
1076 if (t == dst_type) {
1077 get_ids(dim, t, 0, dst_pos, ids + off);
1078 off += dst_pos;
1079 get_ids(dim, src_type, src_pos, n, ids + off);
1080 off += n;
1081 get_ids(dim, t, dst_pos, s[t - o] - dst_pos,
1082 ids + off);
1083 off += s[t - o] - dst_pos;
1084 } else if (t == src_type) {
1085 get_ids(dim, t, 0, src_pos, ids + off);
1086 off += src_pos;
1087 get_ids(dim, t, src_pos + n,
1088 s[t - o] - src_pos - n, ids + off);
1089 off += s[t - o] - src_pos - n;
1090 } else {
1091 get_ids(dim, t, 0, s[t - o], ids + off);
1092 off += s[t - o];
1095 free(dim->ids);
1096 dim->ids = ids;
1097 dim->n_id = dim->nparam + dim->n_in + dim->n_out;
1100 switch (dst_type) {
1101 case isl_dim_param: dim->nparam += n; break;
1102 case isl_dim_in: dim->n_in += n; break;
1103 case isl_dim_out: dim->n_out += n; break;
1104 default: ;
1107 switch (src_type) {
1108 case isl_dim_param: dim->nparam -= n; break;
1109 case isl_dim_in: dim->n_in -= n; break;
1110 case isl_dim_out: dim->n_out -= n; break;
1111 default: ;
1114 if (dst_type != isl_dim_param && src_type != isl_dim_param)
1115 return dim;
1117 for (i = 0; i < 2; ++i) {
1118 if (!dim->nested[i])
1119 continue;
1120 dim->nested[i] = isl_space_replace(dim->nested[i],
1121 isl_dim_param, dim);
1122 if (!dim->nested[i])
1123 goto error;
1126 return dim;
1127 error:
1128 isl_space_free(dim);
1129 return NULL;
1132 __isl_give isl_space *isl_space_join(__isl_take isl_space *left,
1133 __isl_take isl_space *right)
1135 isl_space *dim;
1137 if (!left || !right)
1138 goto error;
1140 isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
1141 goto error);
1142 isl_assert(left->ctx,
1143 isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_in),
1144 goto error);
1146 dim = isl_space_alloc(left->ctx, left->nparam, left->n_in, right->n_out);
1147 if (!dim)
1148 goto error;
1150 dim = copy_ids(dim, isl_dim_param, 0, left, isl_dim_param);
1151 dim = copy_ids(dim, isl_dim_in, 0, left, isl_dim_in);
1152 dim = copy_ids(dim, isl_dim_out, 0, right, isl_dim_out);
1154 if (dim && left->tuple_id[0] &&
1155 !(dim->tuple_id[0] = isl_id_copy(left->tuple_id[0])))
1156 goto error;
1157 if (dim && right->tuple_id[1] &&
1158 !(dim->tuple_id[1] = isl_id_copy(right->tuple_id[1])))
1159 goto error;
1160 if (dim && left->nested[0] &&
1161 !(dim->nested[0] = isl_space_copy(left->nested[0])))
1162 goto error;
1163 if (dim && right->nested[1] &&
1164 !(dim->nested[1] = isl_space_copy(right->nested[1])))
1165 goto error;
1167 isl_space_free(left);
1168 isl_space_free(right);
1170 return dim;
1171 error:
1172 isl_space_free(left);
1173 isl_space_free(right);
1174 return NULL;
1177 /* Given two map spaces { A -> C } and { B -> D }, construct the space
1178 * { [A -> B] -> [C -> D] }.
1179 * Given two set spaces { A } and { B }, construct the space { [A -> B] }.
1181 __isl_give isl_space *isl_space_product(__isl_take isl_space *left,
1182 __isl_take isl_space *right)
1184 isl_space *dom1, *dom2, *nest1, *nest2;
1185 int is_set;
1187 if (!left || !right)
1188 goto error;
1190 is_set = isl_space_is_set(left);
1191 if (is_set != isl_space_is_set(right))
1192 isl_die(isl_space_get_ctx(left), isl_error_invalid,
1193 "expecting either two set spaces or two map spaces",
1194 goto error);
1195 if (is_set)
1196 return isl_space_range_product(left, right);
1198 isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
1199 goto error);
1201 dom1 = isl_space_domain(isl_space_copy(left));
1202 dom2 = isl_space_domain(isl_space_copy(right));
1203 nest1 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
1205 dom1 = isl_space_range(left);
1206 dom2 = isl_space_range(right);
1207 nest2 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
1209 return isl_space_join(isl_space_reverse(nest1), nest2);
1210 error:
1211 isl_space_free(left);
1212 isl_space_free(right);
1213 return NULL;
1216 /* Given two spaces { A -> C } and { B -> C }, construct the space
1217 * { [A -> B] -> C }
1219 __isl_give isl_space *isl_space_domain_product(__isl_take isl_space *left,
1220 __isl_take isl_space *right)
1222 isl_space *ran, *dom1, *dom2, *nest;
1224 if (!left || !right)
1225 goto error;
1227 if (!match(left, isl_dim_param, right, isl_dim_param))
1228 isl_die(left->ctx, isl_error_invalid,
1229 "parameters need to match", goto error);
1230 if (!isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_out))
1231 isl_die(left->ctx, isl_error_invalid,
1232 "ranges need to match", goto error);
1234 ran = isl_space_range(isl_space_copy(left));
1236 dom1 = isl_space_domain(left);
1237 dom2 = isl_space_domain(right);
1238 nest = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
1240 return isl_space_join(isl_space_reverse(nest), ran);
1241 error:
1242 isl_space_free(left);
1243 isl_space_free(right);
1244 return NULL;
1247 __isl_give isl_space *isl_space_range_product(__isl_take isl_space *left,
1248 __isl_take isl_space *right)
1250 isl_space *dom, *ran1, *ran2, *nest;
1252 if (!left || !right)
1253 goto error;
1255 isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
1256 goto error);
1257 if (!isl_space_tuple_is_equal(left, isl_dim_in, right, isl_dim_in))
1258 isl_die(left->ctx, isl_error_invalid,
1259 "domains need to match", goto error);
1261 dom = isl_space_domain(isl_space_copy(left));
1263 ran1 = isl_space_range(left);
1264 ran2 = isl_space_range(right);
1265 nest = isl_space_wrap(isl_space_join(isl_space_reverse(ran1), ran2));
1267 return isl_space_join(isl_space_reverse(dom), nest);
1268 error:
1269 isl_space_free(left);
1270 isl_space_free(right);
1271 return NULL;
1274 /* Given a space of the form [A -> B] -> [C -> D], return the space A -> C.
1276 __isl_give isl_space *isl_space_factor_domain(__isl_take isl_space *space)
1278 space = isl_space_domain_factor_domain(space);
1279 space = isl_space_range_factor_domain(space);
1280 return space;
1283 /* Given a space of the form [A -> B] -> [C -> D], return the space B -> D.
1285 __isl_give isl_space *isl_space_factor_range(__isl_take isl_space *space)
1287 space = isl_space_domain_factor_range(space);
1288 space = isl_space_range_factor_range(space);
1289 return space;
1292 /* Given a space of the form [A -> B] -> C, return the space A -> C.
1294 __isl_give isl_space *isl_space_domain_factor_domain(
1295 __isl_take isl_space *space)
1297 isl_space *nested;
1298 isl_space *domain;
1300 if (!space)
1301 return NULL;
1302 if (!isl_space_domain_is_wrapping(space))
1303 isl_die(isl_space_get_ctx(space), isl_error_invalid,
1304 "domain not a product", return isl_space_free(space));
1306 nested = space->nested[0];
1307 domain = isl_space_copy(space);
1308 domain = isl_space_drop_dims(domain, isl_dim_in,
1309 nested->n_in, nested->n_out);
1310 if (!domain)
1311 return isl_space_free(space);
1312 if (nested->tuple_id[0]) {
1313 domain->tuple_id[0] = isl_id_copy(nested->tuple_id[0]);
1314 if (!domain->tuple_id[0])
1315 goto error;
1317 if (nested->nested[0]) {
1318 domain->nested[0] = isl_space_copy(nested->nested[0]);
1319 if (!domain->nested[0])
1320 goto error;
1323 isl_space_free(space);
1324 return domain;
1325 error:
1326 isl_space_free(space);
1327 isl_space_free(domain);
1328 return NULL;
1331 /* Given a space of the form [A -> B] -> C, return the space B -> C.
1333 __isl_give isl_space *isl_space_domain_factor_range(
1334 __isl_take isl_space *space)
1336 isl_space *nested;
1337 isl_space *range;
1339 if (!space)
1340 return NULL;
1341 if (!isl_space_domain_is_wrapping(space))
1342 isl_die(isl_space_get_ctx(space), isl_error_invalid,
1343 "domain not a product", return isl_space_free(space));
1345 nested = space->nested[0];
1346 range = isl_space_copy(space);
1347 range = isl_space_drop_dims(range, isl_dim_in, 0, nested->n_in);
1348 if (!range)
1349 return isl_space_free(space);
1350 if (nested->tuple_id[1]) {
1351 range->tuple_id[0] = isl_id_copy(nested->tuple_id[1]);
1352 if (!range->tuple_id[0])
1353 goto error;
1355 if (nested->nested[1]) {
1356 range->nested[0] = isl_space_copy(nested->nested[1]);
1357 if (!range->nested[0])
1358 goto error;
1361 isl_space_free(space);
1362 return range;
1363 error:
1364 isl_space_free(space);
1365 isl_space_free(range);
1366 return NULL;
1369 /* Given a space of the form A -> [B -> C], return the space A -> B.
1371 __isl_give isl_space *isl_space_range_factor_domain(
1372 __isl_take isl_space *space)
1374 isl_space *nested;
1375 isl_space *domain;
1377 if (!space)
1378 return NULL;
1379 if (!isl_space_range_is_wrapping(space))
1380 isl_die(isl_space_get_ctx(space), isl_error_invalid,
1381 "range not a product", return isl_space_free(space));
1383 nested = space->nested[1];
1384 domain = isl_space_copy(space);
1385 domain = isl_space_drop_dims(domain, isl_dim_out,
1386 nested->n_in, nested->n_out);
1387 if (!domain)
1388 return isl_space_free(space);
1389 if (nested->tuple_id[0]) {
1390 domain->tuple_id[1] = isl_id_copy(nested->tuple_id[0]);
1391 if (!domain->tuple_id[1])
1392 goto error;
1394 if (nested->nested[0]) {
1395 domain->nested[1] = isl_space_copy(nested->nested[0]);
1396 if (!domain->nested[1])
1397 goto error;
1400 isl_space_free(space);
1401 return domain;
1402 error:
1403 isl_space_free(space);
1404 isl_space_free(domain);
1405 return NULL;
1408 /* Given a space of the form A -> [B -> C], return the space A -> C.
1410 __isl_give isl_space *isl_space_range_factor_range(
1411 __isl_take isl_space *space)
1413 isl_space *nested;
1414 isl_space *range;
1416 if (!space)
1417 return NULL;
1418 if (!isl_space_range_is_wrapping(space))
1419 isl_die(isl_space_get_ctx(space), isl_error_invalid,
1420 "range not a product", return isl_space_free(space));
1422 nested = space->nested[1];
1423 range = isl_space_copy(space);
1424 range = isl_space_drop_dims(range, isl_dim_out, 0, nested->n_in);
1425 if (!range)
1426 return isl_space_free(space);
1427 if (nested->tuple_id[1]) {
1428 range->tuple_id[1] = isl_id_copy(nested->tuple_id[1]);
1429 if (!range->tuple_id[1])
1430 goto error;
1432 if (nested->nested[1]) {
1433 range->nested[1] = isl_space_copy(nested->nested[1]);
1434 if (!range->nested[1])
1435 goto error;
1438 isl_space_free(space);
1439 return range;
1440 error:
1441 isl_space_free(space);
1442 isl_space_free(range);
1443 return NULL;
1446 __isl_give isl_space *isl_space_map_from_set(__isl_take isl_space *dim)
1448 isl_ctx *ctx;
1449 isl_id **ids = NULL;
1451 if (!dim)
1452 return NULL;
1453 ctx = isl_space_get_ctx(dim);
1454 if (!isl_space_is_set(dim))
1455 isl_die(ctx, isl_error_invalid, "not a set space", goto error);
1456 dim = isl_space_cow(dim);
1457 if (!dim)
1458 return NULL;
1459 if (dim->ids) {
1460 ids = isl_calloc_array(dim->ctx, isl_id *,
1461 dim->nparam + dim->n_out + dim->n_out);
1462 if (!ids)
1463 goto error;
1464 get_ids(dim, isl_dim_param, 0, dim->nparam, ids);
1465 get_ids(dim, isl_dim_out, 0, dim->n_out, ids + dim->nparam);
1467 dim->n_in = dim->n_out;
1468 if (ids) {
1469 free(dim->ids);
1470 dim->ids = ids;
1471 dim->n_id = dim->nparam + dim->n_out + dim->n_out;
1472 dim = copy_ids(dim, isl_dim_out, 0, dim, isl_dim_in);
1474 isl_id_free(dim->tuple_id[0]);
1475 dim->tuple_id[0] = isl_id_copy(dim->tuple_id[1]);
1476 isl_space_free(dim->nested[0]);
1477 dim->nested[0] = isl_space_copy(dim->nested[1]);
1478 return dim;
1479 error:
1480 isl_space_free(dim);
1481 return NULL;
1484 __isl_give isl_space *isl_space_map_from_domain_and_range(
1485 __isl_take isl_space *domain, __isl_take isl_space *range)
1487 if (!domain || !range)
1488 goto error;
1489 if (!isl_space_is_set(domain))
1490 isl_die(isl_space_get_ctx(domain), isl_error_invalid,
1491 "domain is not a set space", goto error);
1492 if (!isl_space_is_set(range))
1493 isl_die(isl_space_get_ctx(range), isl_error_invalid,
1494 "range is not a set space", goto error);
1495 return isl_space_join(isl_space_reverse(domain), range);
1496 error:
1497 isl_space_free(domain);
1498 isl_space_free(range);
1499 return NULL;
1502 static __isl_give isl_space *set_ids(__isl_take isl_space *dim,
1503 enum isl_dim_type type,
1504 unsigned first, unsigned n, __isl_take isl_id **ids)
1506 int i;
1508 for (i = 0; i < n ; ++i)
1509 dim = set_id(dim, type, first + i, ids[i]);
1511 return dim;
1514 __isl_give isl_space *isl_space_reverse(__isl_take isl_space *dim)
1516 unsigned t;
1517 isl_space *nested;
1518 isl_id **ids = NULL;
1519 isl_id *id;
1521 if (!dim)
1522 return NULL;
1523 if (match(dim, isl_dim_in, dim, isl_dim_out))
1524 return dim;
1526 dim = isl_space_cow(dim);
1527 if (!dim)
1528 return NULL;
1530 id = dim->tuple_id[0];
1531 dim->tuple_id[0] = dim->tuple_id[1];
1532 dim->tuple_id[1] = id;
1534 nested = dim->nested[0];
1535 dim->nested[0] = dim->nested[1];
1536 dim->nested[1] = nested;
1538 if (dim->ids) {
1539 int n_id = dim->n_in + dim->n_out;
1540 ids = isl_alloc_array(dim->ctx, isl_id *, n_id);
1541 if (n_id && !ids)
1542 goto error;
1543 get_ids(dim, isl_dim_in, 0, dim->n_in, ids);
1544 get_ids(dim, isl_dim_out, 0, dim->n_out, ids + dim->n_in);
1547 t = dim->n_in;
1548 dim->n_in = dim->n_out;
1549 dim->n_out = t;
1551 if (dim->ids) {
1552 dim = set_ids(dim, isl_dim_out, 0, dim->n_out, ids);
1553 dim = set_ids(dim, isl_dim_in, 0, dim->n_in, ids + dim->n_out);
1554 free(ids);
1557 return dim;
1558 error:
1559 free(ids);
1560 isl_space_free(dim);
1561 return NULL;
1564 __isl_give isl_space *isl_space_drop_dims(__isl_take isl_space *dim,
1565 enum isl_dim_type type, unsigned first, unsigned num)
1567 int i;
1569 if (!dim)
1570 return NULL;
1572 if (num == 0)
1573 return isl_space_reset(dim, type);
1575 if (!valid_dim_type(type))
1576 isl_die(dim->ctx, isl_error_invalid,
1577 "cannot drop dimensions of specified type", goto error);
1579 if (first + num > n(dim, type) || first + num < first)
1580 isl_die(isl_space_get_ctx(dim), isl_error_invalid,
1581 "index out of bounds", return isl_space_free(dim));
1582 dim = isl_space_cow(dim);
1583 if (!dim)
1584 goto error;
1585 if (dim->ids) {
1586 dim = extend_ids(dim);
1587 if (!dim)
1588 goto error;
1589 for (i = 0; i < num; ++i)
1590 isl_id_free(get_id(dim, type, first + i));
1591 for (i = first+num; i < n(dim, type); ++i)
1592 set_id(dim, type, i - num, get_id(dim, type, i));
1593 switch (type) {
1594 case isl_dim_param:
1595 get_ids(dim, isl_dim_in, 0, dim->n_in,
1596 dim->ids + offset(dim, isl_dim_in) - num);
1597 case isl_dim_in:
1598 get_ids(dim, isl_dim_out, 0, dim->n_out,
1599 dim->ids + offset(dim, isl_dim_out) - num);
1600 default:
1603 dim->n_id -= num;
1605 switch (type) {
1606 case isl_dim_param: dim->nparam -= num; break;
1607 case isl_dim_in: dim->n_in -= num; break;
1608 case isl_dim_out: dim->n_out -= num; break;
1609 default: ;
1611 dim = isl_space_reset(dim, type);
1612 if (type == isl_dim_param) {
1613 if (dim && dim->nested[0] &&
1614 !(dim->nested[0] = isl_space_drop_dims(dim->nested[0],
1615 isl_dim_param, first, num)))
1616 goto error;
1617 if (dim && dim->nested[1] &&
1618 !(dim->nested[1] = isl_space_drop_dims(dim->nested[1],
1619 isl_dim_param, first, num)))
1620 goto error;
1622 return dim;
1623 error:
1624 isl_space_free(dim);
1625 return NULL;
1628 __isl_give isl_space *isl_space_drop_inputs(__isl_take isl_space *dim,
1629 unsigned first, unsigned n)
1631 if (!dim)
1632 return NULL;
1633 return isl_space_drop_dims(dim, isl_dim_in, first, n);
1636 __isl_give isl_space *isl_space_drop_outputs(__isl_take isl_space *dim,
1637 unsigned first, unsigned n)
1639 if (!dim)
1640 return NULL;
1641 return isl_space_drop_dims(dim, isl_dim_out, first, n);
1644 __isl_give isl_space *isl_space_domain(__isl_take isl_space *dim)
1646 if (!dim)
1647 return NULL;
1648 dim = isl_space_drop_outputs(dim, 0, dim->n_out);
1649 dim = isl_space_reverse(dim);
1650 dim = mark_as_set(dim);
1651 return dim;
1654 __isl_give isl_space *isl_space_from_domain(__isl_take isl_space *dim)
1656 if (!dim)
1657 return NULL;
1658 if (!isl_space_is_set(dim))
1659 isl_die(isl_space_get_ctx(dim), isl_error_invalid,
1660 "not a set space", goto error);
1661 dim = isl_space_reverse(dim);
1662 dim = isl_space_reset(dim, isl_dim_out);
1663 return dim;
1664 error:
1665 isl_space_free(dim);
1666 return NULL;
1669 __isl_give isl_space *isl_space_range(__isl_take isl_space *dim)
1671 if (!dim)
1672 return NULL;
1673 dim = isl_space_drop_inputs(dim, 0, dim->n_in);
1674 dim = mark_as_set(dim);
1675 return dim;
1678 __isl_give isl_space *isl_space_from_range(__isl_take isl_space *dim)
1680 if (!dim)
1681 return NULL;
1682 if (!isl_space_is_set(dim))
1683 isl_die(isl_space_get_ctx(dim), isl_error_invalid,
1684 "not a set space", goto error);
1685 return isl_space_reset(dim, isl_dim_in);
1686 error:
1687 isl_space_free(dim);
1688 return NULL;
1691 /* Given a map space A -> B, return the map space [A -> B] -> A.
1693 __isl_give isl_space *isl_space_domain_map(__isl_take isl_space *space)
1695 isl_space *domain;
1697 domain = isl_space_from_range(isl_space_domain(isl_space_copy(space)));
1698 space = isl_space_from_domain(isl_space_wrap(space));
1699 space = isl_space_join(space, domain);
1701 return space;
1704 /* Given a map space A -> B, return the map space [A -> B] -> B.
1706 __isl_give isl_space *isl_space_range_map(__isl_take isl_space *space)
1708 isl_space *range;
1710 range = isl_space_from_range(isl_space_range(isl_space_copy(space)));
1711 space = isl_space_from_domain(isl_space_wrap(space));
1712 space = isl_space_join(space, range);
1714 return space;
1717 __isl_give isl_space *isl_space_params(__isl_take isl_space *space)
1719 if (isl_space_is_params(space))
1720 return space;
1721 space = isl_space_drop_dims(space,
1722 isl_dim_in, 0, isl_space_dim(space, isl_dim_in));
1723 space = isl_space_drop_dims(space,
1724 isl_dim_out, 0, isl_space_dim(space, isl_dim_out));
1725 space = mark_as_params(space);
1726 return space;
1729 __isl_give isl_space *isl_space_set_from_params(__isl_take isl_space *space)
1731 if (!space)
1732 return NULL;
1733 if (!isl_space_is_params(space))
1734 isl_die(isl_space_get_ctx(space), isl_error_invalid,
1735 "not a parameter space", goto error);
1736 return isl_space_reset(space, isl_dim_set);
1737 error:
1738 isl_space_free(space);
1739 return NULL;
1742 __isl_give isl_space *isl_space_as_set_space(__isl_take isl_space *dim)
1744 dim = isl_space_cow(dim);
1745 if (!dim)
1746 return NULL;
1748 dim->n_out += dim->n_in;
1749 dim->n_in = 0;
1750 dim = isl_space_reset(dim, isl_dim_in);
1751 dim = isl_space_reset(dim, isl_dim_out);
1753 return dim;
1756 __isl_give isl_space *isl_space_underlying(__isl_take isl_space *dim,
1757 unsigned n_div)
1759 int i;
1761 if (!dim)
1762 return NULL;
1763 if (n_div == 0 &&
1764 dim->nparam == 0 && dim->n_in == 0 && dim->n_id == 0)
1765 return isl_space_reset(isl_space_reset(dim, isl_dim_in), isl_dim_out);
1766 dim = isl_space_cow(dim);
1767 if (!dim)
1768 return NULL;
1769 dim->n_out += dim->nparam + dim->n_in + n_div;
1770 dim->nparam = 0;
1771 dim->n_in = 0;
1773 for (i = 0; i < dim->n_id; ++i)
1774 isl_id_free(get_id(dim, isl_dim_out, i));
1775 dim->n_id = 0;
1776 dim = isl_space_reset(dim, isl_dim_in);
1777 dim = isl_space_reset(dim, isl_dim_out);
1779 return dim;
1782 /* Are the two spaces the same, including positions and names of parameters?
1784 int isl_space_is_equal(__isl_keep isl_space *dim1, __isl_keep isl_space *dim2)
1786 if (!dim1 || !dim2)
1787 return -1;
1788 if (dim1 == dim2)
1789 return 1;
1790 return match(dim1, isl_dim_param, dim2, isl_dim_param) &&
1791 isl_space_tuple_is_equal(dim1, isl_dim_in, dim2, isl_dim_in) &&
1792 isl_space_tuple_is_equal(dim1, isl_dim_out, dim2, isl_dim_out);
1795 /* Is space1 equal to the domain of space2?
1797 * In the internal version we also allow space2 to be the space of a set,
1798 * provided space1 is a parameter space.
1800 int isl_space_is_domain_internal(__isl_keep isl_space *space1,
1801 __isl_keep isl_space *space2)
1803 if (!space1 || !space2)
1804 return -1;
1805 if (!isl_space_is_set(space1))
1806 return 0;
1807 return match(space1, isl_dim_param, space2, isl_dim_param) &&
1808 isl_space_tuple_is_equal(space1, isl_dim_set,
1809 space2, isl_dim_in);
1812 /* Is space1 equal to the domain of space2?
1814 int isl_space_is_domain(__isl_keep isl_space *space1,
1815 __isl_keep isl_space *space2)
1817 if (!space2)
1818 return -1;
1819 if (!isl_space_is_map(space2))
1820 return 0;
1821 return isl_space_is_domain_internal(space1, space2);
1824 /* Is space1 equal to the range of space2?
1826 * In the internal version, space2 is allowed to be the space of a set,
1827 * in which case it should be equal to space1.
1829 int isl_space_is_range_internal(__isl_keep isl_space *space1,
1830 __isl_keep isl_space *space2)
1832 if (!space1 || !space2)
1833 return -1;
1834 if (!isl_space_is_set(space1))
1835 return 0;
1836 return match(space1, isl_dim_param, space2, isl_dim_param) &&
1837 isl_space_tuple_is_equal(space1, isl_dim_set,
1838 space2, isl_dim_out);
1841 /* Is space1 equal to the range of space2?
1843 int isl_space_is_range(__isl_keep isl_space *space1,
1844 __isl_keep isl_space *space2)
1846 if (!space2)
1847 return -1;
1848 if (!isl_space_is_map(space2))
1849 return 0;
1850 return isl_space_is_range_internal(space1, space2);
1853 int isl_space_compatible(__isl_keep isl_space *dim1,
1854 __isl_keep isl_space *dim2)
1856 return dim1->nparam == dim2->nparam &&
1857 dim1->n_in + dim1->n_out == dim2->n_in + dim2->n_out;
1860 static uint32_t isl_hash_dim(uint32_t hash, __isl_keep isl_space *dim)
1862 int i;
1863 isl_id *id;
1865 if (!dim)
1866 return hash;
1868 isl_hash_byte(hash, dim->nparam % 256);
1869 isl_hash_byte(hash, dim->n_in % 256);
1870 isl_hash_byte(hash, dim->n_out % 256);
1872 for (i = 0; i < dim->nparam; ++i) {
1873 id = get_id(dim, isl_dim_param, i);
1874 hash = isl_hash_id(hash, id);
1877 id = tuple_id(dim, isl_dim_in);
1878 hash = isl_hash_id(hash, id);
1879 id = tuple_id(dim, isl_dim_out);
1880 hash = isl_hash_id(hash, id);
1882 hash = isl_hash_dim(hash, dim->nested[0]);
1883 hash = isl_hash_dim(hash, dim->nested[1]);
1885 return hash;
1888 uint32_t isl_space_get_hash(__isl_keep isl_space *dim)
1890 uint32_t hash;
1892 if (!dim)
1893 return 0;
1895 hash = isl_hash_init();
1896 hash = isl_hash_dim(hash, dim);
1898 return hash;
1901 int isl_space_is_wrapping(__isl_keep isl_space *dim)
1903 if (!dim)
1904 return -1;
1906 if (!isl_space_is_set(dim))
1907 return 0;
1909 return dim->nested[1] != NULL;
1912 /* Is "space" the space of a map where the domain is a wrapped map space?
1914 int isl_space_domain_is_wrapping(__isl_keep isl_space *space)
1916 if (!space)
1917 return -1;
1919 if (isl_space_is_set(space))
1920 return 0;
1922 return space->nested[0] != NULL;
1925 /* Is "space" the space of a map where the range is a wrapped map space?
1927 int isl_space_range_is_wrapping(__isl_keep isl_space *space)
1929 if (!space)
1930 return -1;
1932 if (isl_space_is_set(space))
1933 return 0;
1935 return space->nested[1] != NULL;
1938 __isl_give isl_space *isl_space_wrap(__isl_take isl_space *dim)
1940 isl_space *wrap;
1942 if (!dim)
1943 return NULL;
1945 wrap = isl_space_set_alloc(dim->ctx,
1946 dim->nparam, dim->n_in + dim->n_out);
1948 wrap = copy_ids(wrap, isl_dim_param, 0, dim, isl_dim_param);
1949 wrap = copy_ids(wrap, isl_dim_set, 0, dim, isl_dim_in);
1950 wrap = copy_ids(wrap, isl_dim_set, dim->n_in, dim, isl_dim_out);
1952 if (!wrap)
1953 goto error;
1955 wrap->nested[1] = dim;
1957 return wrap;
1958 error:
1959 isl_space_free(dim);
1960 return NULL;
1963 __isl_give isl_space *isl_space_unwrap(__isl_take isl_space *dim)
1965 isl_space *unwrap;
1967 if (!dim)
1968 return NULL;
1970 if (!isl_space_is_wrapping(dim))
1971 isl_die(dim->ctx, isl_error_invalid, "not a wrapping space",
1972 goto error);
1974 unwrap = isl_space_copy(dim->nested[1]);
1975 isl_space_free(dim);
1977 return unwrap;
1978 error:
1979 isl_space_free(dim);
1980 return NULL;
1983 int isl_space_is_named_or_nested(__isl_keep isl_space *dim, enum isl_dim_type type)
1985 if (type != isl_dim_in && type != isl_dim_out)
1986 return 0;
1987 if (!dim)
1988 return -1;
1989 if (dim->tuple_id[type - isl_dim_in])
1990 return 1;
1991 if (dim->nested[type - isl_dim_in])
1992 return 1;
1993 return 0;
1996 int isl_space_may_be_set(__isl_keep isl_space *dim)
1998 if (!dim)
1999 return -1;
2000 if (isl_space_is_set(dim))
2001 return 1;
2002 if (isl_space_dim(dim, isl_dim_in) != 0)
2003 return 0;
2004 if (isl_space_is_named_or_nested(dim, isl_dim_in))
2005 return 0;
2006 return 1;
2009 __isl_give isl_space *isl_space_reset(__isl_take isl_space *dim,
2010 enum isl_dim_type type)
2012 if (!isl_space_is_named_or_nested(dim, type))
2013 return dim;
2015 dim = isl_space_cow(dim);
2016 if (!dim)
2017 return NULL;
2019 isl_id_free(dim->tuple_id[type - isl_dim_in]);
2020 dim->tuple_id[type - isl_dim_in] = NULL;
2021 isl_space_free(dim->nested[type - isl_dim_in]);
2022 dim->nested[type - isl_dim_in] = NULL;
2024 return dim;
2027 __isl_give isl_space *isl_space_flatten(__isl_take isl_space *dim)
2029 if (!dim)
2030 return NULL;
2031 if (!dim->nested[0] && !dim->nested[1])
2032 return dim;
2034 if (dim->nested[0])
2035 dim = isl_space_reset(dim, isl_dim_in);
2036 if (dim && dim->nested[1])
2037 dim = isl_space_reset(dim, isl_dim_out);
2039 return dim;
2042 __isl_give isl_space *isl_space_flatten_domain(__isl_take isl_space *dim)
2044 if (!dim)
2045 return NULL;
2046 if (!dim->nested[0])
2047 return dim;
2049 return isl_space_reset(dim, isl_dim_in);
2052 __isl_give isl_space *isl_space_flatten_range(__isl_take isl_space *dim)
2054 if (!dim)
2055 return NULL;
2056 if (!dim->nested[1])
2057 return dim;
2059 return isl_space_reset(dim, isl_dim_out);
2062 /* Replace the dimensions of the given type of dst by those of src.
2064 __isl_give isl_space *isl_space_replace(__isl_take isl_space *dst,
2065 enum isl_dim_type type, __isl_keep isl_space *src)
2067 dst = isl_space_cow(dst);
2069 if (!dst || !src)
2070 goto error;
2072 dst = isl_space_drop_dims(dst, type, 0, isl_space_dim(dst, type));
2073 dst = isl_space_add_dims(dst, type, isl_space_dim(src, type));
2074 dst = copy_ids(dst, type, 0, src, type);
2076 if (dst && type == isl_dim_param) {
2077 int i;
2078 for (i = 0; i <= 1; ++i) {
2079 if (!dst->nested[i])
2080 continue;
2081 dst->nested[i] = isl_space_replace(dst->nested[i],
2082 type, src);
2083 if (!dst->nested[i])
2084 goto error;
2088 return dst;
2089 error:
2090 isl_space_free(dst);
2091 return NULL;
2094 /* Given a dimension specification "dim" of a set, create a dimension
2095 * specification for the lift of the set. In particular, the result
2096 * is of the form [dim -> local[..]], with n_local variables in the
2097 * range of the wrapped map.
2099 __isl_give isl_space *isl_space_lift(__isl_take isl_space *dim, unsigned n_local)
2101 isl_space *local_dim;
2103 if (!dim)
2104 return NULL;
2106 local_dim = isl_space_dup(dim);
2107 local_dim = isl_space_drop_dims(local_dim, isl_dim_set, 0, dim->n_out);
2108 local_dim = isl_space_add_dims(local_dim, isl_dim_set, n_local);
2109 local_dim = isl_space_set_tuple_name(local_dim, isl_dim_set, "local");
2110 dim = isl_space_join(isl_space_from_domain(dim),
2111 isl_space_from_range(local_dim));
2112 dim = isl_space_wrap(dim);
2113 dim = isl_space_set_tuple_name(dim, isl_dim_set, "lifted");
2115 return dim;
2118 int isl_space_can_zip(__isl_keep isl_space *dim)
2120 if (!dim)
2121 return -1;
2123 return dim->nested[0] && dim->nested[1];
2126 __isl_give isl_space *isl_space_zip(__isl_take isl_space *dim)
2128 isl_space *dom, *ran;
2129 isl_space *dom_dom, *dom_ran, *ran_dom, *ran_ran;
2131 if (!isl_space_can_zip(dim))
2132 isl_die(dim->ctx, isl_error_invalid, "dim cannot be zipped",
2133 goto error);
2135 if (!dim)
2136 return NULL;
2137 dom = isl_space_unwrap(isl_space_domain(isl_space_copy(dim)));
2138 ran = isl_space_unwrap(isl_space_range(dim));
2139 dom_dom = isl_space_domain(isl_space_copy(dom));
2140 dom_ran = isl_space_range(dom);
2141 ran_dom = isl_space_domain(isl_space_copy(ran));
2142 ran_ran = isl_space_range(ran);
2143 dom = isl_space_join(isl_space_from_domain(dom_dom),
2144 isl_space_from_range(ran_dom));
2145 ran = isl_space_join(isl_space_from_domain(dom_ran),
2146 isl_space_from_range(ran_ran));
2147 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom)),
2148 isl_space_from_range(isl_space_wrap(ran)));
2149 error:
2150 isl_space_free(dim);
2151 return NULL;
2154 /* Can we apply isl_space_curry to "space"?
2155 * That is, does it have a nested relation in its domain?
2157 int isl_space_can_curry(__isl_keep isl_space *space)
2159 if (!space)
2160 return -1;
2162 return !!space->nested[0];
2165 /* Given a space (A -> B) -> C, return the corresponding space
2166 * A -> (B -> C).
2168 __isl_give isl_space *isl_space_curry(__isl_take isl_space *space)
2170 isl_space *dom, *ran;
2171 isl_space *dom_dom, *dom_ran;
2173 if (!space)
2174 return NULL;
2176 if (!isl_space_can_curry(space))
2177 isl_die(space->ctx, isl_error_invalid,
2178 "space cannot be curried", goto error);
2180 dom = isl_space_unwrap(isl_space_domain(isl_space_copy(space)));
2181 ran = isl_space_range(space);
2182 dom_dom = isl_space_domain(isl_space_copy(dom));
2183 dom_ran = isl_space_range(dom);
2184 ran = isl_space_join(isl_space_from_domain(dom_ran),
2185 isl_space_from_range(ran));
2186 return isl_space_join(isl_space_from_domain(dom_dom),
2187 isl_space_from_range(isl_space_wrap(ran)));
2188 error:
2189 isl_space_free(space);
2190 return NULL;
2193 /* Can we apply isl_space_uncurry to "space"?
2194 * That is, does it have a nested relation in its range?
2196 int isl_space_can_uncurry(__isl_keep isl_space *space)
2198 if (!space)
2199 return -1;
2201 return !!space->nested[1];
2204 /* Given a space A -> (B -> C), return the corresponding space
2205 * (A -> B) -> C.
2207 __isl_give isl_space *isl_space_uncurry(__isl_take isl_space *space)
2209 isl_space *dom, *ran;
2210 isl_space *ran_dom, *ran_ran;
2212 if (!space)
2213 return NULL;
2215 if (!isl_space_can_uncurry(space))
2216 isl_die(space->ctx, isl_error_invalid,
2217 "space cannot be uncurried",
2218 return isl_space_free(space));
2220 dom = isl_space_domain(isl_space_copy(space));
2221 ran = isl_space_unwrap(isl_space_range(space));
2222 ran_dom = isl_space_domain(isl_space_copy(ran));
2223 ran_ran = isl_space_range(ran);
2224 dom = isl_space_join(isl_space_from_domain(dom),
2225 isl_space_from_range(ran_dom));
2226 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom)),
2227 isl_space_from_range(ran_ran));
2230 int isl_space_has_named_params(__isl_keep isl_space *dim)
2232 int i;
2233 unsigned off;
2235 if (!dim)
2236 return -1;
2237 if (dim->nparam == 0)
2238 return 1;
2239 off = isl_space_offset(dim, isl_dim_param);
2240 if (off + dim->nparam > dim->n_id)
2241 return 0;
2242 for (i = 0; i < dim->nparam; ++i)
2243 if (!dim->ids[off + i])
2244 return 0;
2245 return 1;
2248 /* Align the initial parameters of dim1 to match the order in dim2.
2250 __isl_give isl_space *isl_space_align_params(__isl_take isl_space *dim1,
2251 __isl_take isl_space *dim2)
2253 isl_reordering *exp;
2255 if (!isl_space_has_named_params(dim1) || !isl_space_has_named_params(dim2))
2256 isl_die(isl_space_get_ctx(dim1), isl_error_invalid,
2257 "parameter alignment requires named parameters",
2258 goto error);
2260 dim2 = isl_space_params(dim2);
2261 exp = isl_parameter_alignment_reordering(dim1, dim2);
2262 exp = isl_reordering_extend_space(exp, dim1);
2263 isl_space_free(dim2);
2264 if (!exp)
2265 return NULL;
2266 dim1 = isl_space_copy(exp->dim);
2267 isl_reordering_free(exp);
2268 return dim1;
2269 error:
2270 isl_space_free(dim1);
2271 isl_space_free(dim2);
2272 return NULL;
2275 /* Given the space of set (domain), construct a space for a map
2276 * with as domain the given space and as range the range of "model".
2278 __isl_give isl_space *isl_space_extend_domain_with_range(
2279 __isl_take isl_space *space, __isl_take isl_space *model)
2281 if (!model)
2282 goto error;
2284 space = isl_space_from_domain(space);
2285 space = isl_space_add_dims(space, isl_dim_out,
2286 isl_space_dim(model, isl_dim_out));
2287 if (isl_space_has_tuple_id(model, isl_dim_out))
2288 space = isl_space_set_tuple_id(space, isl_dim_out,
2289 isl_space_get_tuple_id(model, isl_dim_out));
2290 if (!space)
2291 goto error;
2292 if (model->nested[1]) {
2293 isl_space *nested = isl_space_copy(model->nested[1]);
2294 int n_nested, n_space;
2295 nested = isl_space_align_params(nested, isl_space_copy(space));
2296 n_nested = isl_space_dim(nested, isl_dim_param);
2297 n_space = isl_space_dim(space, isl_dim_param);
2298 if (n_nested > n_space)
2299 nested = isl_space_drop_dims(nested, isl_dim_param,
2300 n_space, n_nested - n_space);
2301 if (!nested)
2302 goto error;
2303 space->nested[1] = nested;
2305 isl_space_free(model);
2306 return space;
2307 error:
2308 isl_space_free(model);
2309 isl_space_free(space);
2310 return NULL;
2313 /* Compare the "type" dimensions of two isl_spaces.
2315 * The order is fairly arbitrary.
2317 static int isl_space_cmp_type(__isl_keep isl_space *space1,
2318 __isl_keep isl_space *space2, enum isl_dim_type type)
2320 int cmp;
2321 isl_space *nested1, *nested2;
2323 if (isl_space_dim(space1, type) != isl_space_dim(space2, type))
2324 return isl_space_dim(space1, type) -
2325 isl_space_dim(space2, type);
2327 cmp = isl_id_cmp(tuple_id(space1, type), tuple_id(space2, type));
2328 if (cmp != 0)
2329 return cmp;
2331 nested1 = nested(space1, type);
2332 nested2 = nested(space2, type);
2333 if (!nested1 != !nested2)
2334 return !nested1 - !nested2;
2336 if (nested1)
2337 return isl_space_cmp(nested1, nested2);
2339 return 0;
2342 /* Compare two isl_spaces.
2344 * The order is fairly arbitrary.
2346 int isl_space_cmp(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
2348 int i;
2349 int cmp;
2351 if (space1 == space2)
2352 return 0;
2353 if (!space1)
2354 return -1;
2355 if (!space2)
2356 return 1;
2358 cmp = isl_space_cmp_type(space1, space2, isl_dim_param);
2359 if (cmp != 0)
2360 return cmp;
2361 cmp = isl_space_cmp_type(space1, space2, isl_dim_in);
2362 if (cmp != 0)
2363 return cmp;
2364 cmp = isl_space_cmp_type(space1, space2, isl_dim_out);
2365 if (cmp != 0)
2366 return cmp;
2368 if (!space1->ids && !space2->ids)
2369 return 0;
2371 for (i = 0; i < n(space1, isl_dim_param); ++i) {
2372 cmp = isl_id_cmp(get_id(space1, isl_dim_param, i),
2373 get_id(space2, isl_dim_param, i));
2374 if (cmp != 0)
2375 return cmp;
2378 return 0;