2 * Copyright 2013-2014 Ecole Normale Superieure
3 * Copyright 2014 INRIA Rocquencourt
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
9 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
10 * B.P. 105 - 78153 Le Chesnay, France
14 #include <isl_schedule_band.h>
15 #include <isl_schedule_private.h>
18 #define EL isl_schedule_tree
20 #include <isl_list_templ.h>
23 #define BASE schedule_tree
25 #include <isl_list_templ.c>
27 /* Is "tree" the leaf of a schedule tree?
29 int isl_schedule_tree_is_leaf(__isl_keep isl_schedule_tree
*tree
)
31 return isl_schedule_tree_get_type(tree
) == isl_schedule_node_leaf
;
34 /* Create a new schedule tree of type "type".
35 * The caller is responsible for filling in the type specific fields and
38 static __isl_give isl_schedule_tree
*isl_schedule_tree_alloc(isl_ctx
*ctx
,
39 enum isl_schedule_node_type type
)
41 isl_schedule_tree
*tree
;
43 if (type
== isl_schedule_node_error
)
46 tree
= isl_calloc_type(ctx
, isl_schedule_tree
);
58 /* Return a fresh copy of "tree".
60 __isl_take isl_schedule_tree
*isl_schedule_tree_dup(
61 __isl_keep isl_schedule_tree
*tree
)
64 isl_schedule_tree
*dup
;
69 ctx
= isl_schedule_tree_get_ctx(tree
);
70 dup
= isl_schedule_tree_alloc(ctx
, tree
->type
);
75 case isl_schedule_node_error
:
76 isl_die(ctx
, isl_error_internal
,
77 "allocation should have failed",
78 isl_schedule_tree_free(dup
));
79 case isl_schedule_node_band
:
80 dup
->band
= isl_schedule_band_copy(tree
->band
);
82 return isl_schedule_tree_free(dup
);
84 case isl_schedule_node_domain
:
85 dup
->domain
= isl_union_set_copy(tree
->domain
);
87 return isl_schedule_tree_free(dup
);
89 case isl_schedule_node_filter
:
90 dup
->filter
= isl_union_set_copy(tree
->filter
);
92 return isl_schedule_tree_free(dup
);
94 case isl_schedule_node_leaf
:
95 case isl_schedule_node_sequence
:
96 case isl_schedule_node_set
:
100 if (tree
->children
) {
101 dup
->children
= isl_schedule_tree_list_copy(tree
->children
);
103 return isl_schedule_tree_free(dup
);
109 /* Return an isl_schedule_tree that is equal to "tree" and that has only
110 * a single reference.
112 * This function is called before a tree is modified.
113 * A static tree (with negative reference count) should never be modified,
114 * so it is not allowed to call this function on a static tree.
116 __isl_give isl_schedule_tree
*isl_schedule_tree_cow(
117 __isl_take isl_schedule_tree
*tree
)
123 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_internal
,
124 "static trees cannot be modified",
125 return isl_schedule_tree_free(tree
));
130 return isl_schedule_tree_dup(tree
);
133 /* Return a new reference to "tree".
135 * A static tree (with negative reference count) does not keep track
136 * of the number of references and should not be modified.
138 __isl_give isl_schedule_tree
*isl_schedule_tree_copy(
139 __isl_keep isl_schedule_tree
*tree
)
151 /* Free "tree" and return NULL.
153 __isl_null isl_schedule_tree
*isl_schedule_tree_free(
154 __isl_take isl_schedule_tree
*tree
)
163 switch (tree
->type
) {
164 case isl_schedule_node_band
:
165 isl_schedule_band_free(tree
->band
);
167 case isl_schedule_node_domain
:
168 isl_union_set_free(tree
->domain
);
170 case isl_schedule_node_filter
:
171 isl_union_set_free(tree
->filter
);
173 case isl_schedule_node_sequence
:
174 case isl_schedule_node_set
:
175 case isl_schedule_node_error
:
176 case isl_schedule_node_leaf
:
179 isl_schedule_tree_list_free(tree
->children
);
180 isl_ctx_deref(tree
->ctx
);
186 /* Create and return a new leaf schedule tree.
188 __isl_give isl_schedule_tree
*isl_schedule_tree_leaf(isl_ctx
*ctx
)
190 return isl_schedule_tree_alloc(ctx
, isl_schedule_node_leaf
);
193 /* Create a new band schedule tree referring to "band"
196 __isl_give isl_schedule_tree
*isl_schedule_tree_from_band(
197 __isl_take isl_schedule_band
*band
)
200 isl_schedule_tree
*tree
;
205 ctx
= isl_schedule_band_get_ctx(band
);
206 tree
= isl_schedule_tree_alloc(ctx
, isl_schedule_node_band
);
214 isl_schedule_band_free(band
);
218 /* Create a new domain schedule tree with the given domain and no children.
220 __isl_give isl_schedule_tree
*isl_schedule_tree_from_domain(
221 __isl_take isl_union_set
*domain
)
224 isl_schedule_tree
*tree
;
229 ctx
= isl_union_set_get_ctx(domain
);
230 tree
= isl_schedule_tree_alloc(ctx
, isl_schedule_node_domain
);
234 tree
->domain
= domain
;
238 isl_union_set_free(domain
);
242 /* Create a new filter schedule tree with the given filter and no children.
244 __isl_give isl_schedule_tree
*isl_schedule_tree_from_filter(
245 __isl_take isl_union_set
*filter
)
248 isl_schedule_tree
*tree
;
253 ctx
= isl_union_set_get_ctx(filter
);
254 tree
= isl_schedule_tree_alloc(ctx
, isl_schedule_node_filter
);
258 tree
->filter
= filter
;
262 isl_union_set_free(filter
);
266 /* Create a new tree of the given type (isl_schedule_node_sequence or
267 * isl_schedule_node_set) with the given children.
269 __isl_give isl_schedule_tree
*isl_schedule_tree_from_children(
270 enum isl_schedule_node_type type
,
271 __isl_take isl_schedule_tree_list
*list
)
274 isl_schedule_tree
*tree
;
279 ctx
= isl_schedule_tree_list_get_ctx(list
);
280 tree
= isl_schedule_tree_alloc(ctx
, type
);
284 tree
->children
= list
;
288 isl_schedule_tree_list_free(list
);
292 /* Construct a tree with a root node of type "type" and as children
293 * "tree1" and "tree2".
294 * If the root of one (or both) of the input trees is itself of type "type",
295 * then the tree is replaced by its children.
297 __isl_give isl_schedule_tree
*isl_schedule_tree_from_pair(
298 enum isl_schedule_node_type type
, __isl_take isl_schedule_tree
*tree1
,
299 __isl_take isl_schedule_tree
*tree2
)
302 isl_schedule_tree_list
*list
;
304 if (!tree1
|| !tree2
)
307 ctx
= isl_schedule_tree_get_ctx(tree1
);
308 if (isl_schedule_tree_get_type(tree1
) == type
) {
309 list
= isl_schedule_tree_list_copy(tree1
->children
);
310 isl_schedule_tree_free(tree1
);
312 list
= isl_schedule_tree_list_alloc(ctx
, 2);
313 list
= isl_schedule_tree_list_add(list
, tree1
);
315 if (isl_schedule_tree_get_type(tree2
) == type
) {
316 isl_schedule_tree_list
*children
;
318 children
= isl_schedule_tree_list_copy(tree2
->children
);
319 list
= isl_schedule_tree_list_concat(list
, children
);
320 isl_schedule_tree_free(tree2
);
322 list
= isl_schedule_tree_list_add(list
, tree2
);
325 return isl_schedule_tree_from_children(type
, list
);
327 isl_schedule_tree_free(tree1
);
328 isl_schedule_tree_free(tree2
);
332 /* Return the isl_ctx to which "tree" belongs.
334 isl_ctx
*isl_schedule_tree_get_ctx(__isl_keep isl_schedule_tree
*tree
)
336 return tree
? tree
->ctx
: NULL
;
339 /* Return the type of the root of the tree or isl_schedule_node_error
342 enum isl_schedule_node_type
isl_schedule_tree_get_type(
343 __isl_keep isl_schedule_tree
*tree
)
345 return tree
? tree
->type
: isl_schedule_node_error
;
348 /* Are "tree1" and "tree2" obviously equal to each other?
350 int isl_schedule_tree_plain_is_equal(__isl_keep isl_schedule_tree
*tree1
,
351 __isl_keep isl_schedule_tree
*tree2
)
356 if (!tree1
|| !tree2
)
360 if (tree1
->type
!= tree2
->type
)
363 switch (tree1
->type
) {
364 case isl_schedule_node_band
:
365 equal
= isl_schedule_band_plain_is_equal(tree1
->band
,
368 case isl_schedule_node_domain
:
369 equal
= isl_union_set_is_equal(tree1
->domain
, tree2
->domain
);
371 case isl_schedule_node_filter
:
372 equal
= isl_union_set_is_equal(tree1
->filter
, tree2
->filter
);
374 case isl_schedule_node_leaf
:
375 case isl_schedule_node_sequence
:
376 case isl_schedule_node_set
:
379 case isl_schedule_node_error
:
384 if (equal
< 0 || !equal
)
387 n
= isl_schedule_tree_n_children(tree1
);
388 if (n
!= isl_schedule_tree_n_children(tree2
))
390 for (i
= 0; i
< n
; ++i
) {
391 isl_schedule_tree
*child1
, *child2
;
393 child1
= isl_schedule_tree_get_child(tree1
, i
);
394 child2
= isl_schedule_tree_get_child(tree2
, i
);
395 equal
= isl_schedule_tree_plain_is_equal(child1
, child2
);
396 isl_schedule_tree_free(child1
);
397 isl_schedule_tree_free(child2
);
399 if (equal
< 0 || !equal
)
406 /* Does "tree" have any children, other than an implicit leaf.
408 int isl_schedule_tree_has_children(__isl_keep isl_schedule_tree
*tree
)
413 return tree
->children
!= NULL
;
416 /* Return the number of children of "tree", excluding implicit leaves.
418 int isl_schedule_tree_n_children(__isl_keep isl_schedule_tree
*tree
)
423 return isl_schedule_tree_list_n_schedule_tree(tree
->children
);
426 /* Return a copy of the (explicit) child at position "pos" of "tree".
428 __isl_give isl_schedule_tree
*isl_schedule_tree_get_child(
429 __isl_keep isl_schedule_tree
*tree
, int pos
)
434 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_internal
,
435 "schedule tree has no explicit children", return NULL
);
436 return isl_schedule_tree_list_get_schedule_tree(tree
->children
, pos
);
439 /* Return a copy of the (explicit) child at position "pos" of "tree" and
442 __isl_give isl_schedule_tree
*isl_schedule_tree_child(
443 __isl_take isl_schedule_tree
*tree
, int pos
)
445 isl_schedule_tree
*child
;
447 child
= isl_schedule_tree_get_child(tree
, pos
);
448 isl_schedule_tree_free(tree
);
452 /* Remove all (explicit) children from "tree".
454 __isl_give isl_schedule_tree
*isl_schedule_tree_reset_children(
455 __isl_take isl_schedule_tree
*tree
)
457 tree
= isl_schedule_tree_cow(tree
);
460 tree
->children
= isl_schedule_tree_list_free(tree
->children
);
464 /* Remove the child at position "pos" from the children of "tree".
465 * If there was only one child to begin with, then remove all children.
467 __isl_give isl_schedule_tree
*isl_schedule_tree_drop_child(
468 __isl_take isl_schedule_tree
*tree
, int pos
)
472 tree
= isl_schedule_tree_cow(tree
);
476 if (!isl_schedule_tree_has_children(tree
))
477 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
478 "tree does not have any explicit children",
479 return isl_schedule_tree_free(tree
));
480 n
= isl_schedule_tree_list_n_schedule_tree(tree
->children
);
481 if (pos
< 0 || pos
>= n
)
482 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
483 "position out of bounds",
484 return isl_schedule_tree_free(tree
));
486 return isl_schedule_tree_reset_children(tree
);
488 tree
->children
= isl_schedule_tree_list_drop(tree
->children
, pos
, 1);
490 return isl_schedule_tree_free(tree
);
495 /* Replace the child at position "pos" of "tree" by "child".
497 * If the new child is a leaf, then it is not explicitly
498 * recorded in the list of children. Instead, the list of children
499 * (which is assumed to have only one element) is removed.
500 * Note that the children of set and sequence nodes are always
501 * filters, so they cannot be replaced by empty trees.
503 __isl_give isl_schedule_tree
*isl_schedule_tree_replace_child(
504 __isl_take isl_schedule_tree
*tree
, int pos
,
505 __isl_take isl_schedule_tree
*child
)
507 tree
= isl_schedule_tree_cow(tree
);
511 if (isl_schedule_tree_is_leaf(child
)) {
512 isl_schedule_tree_free(child
);
513 if (!tree
->children
&& pos
== 0)
515 if (isl_schedule_tree_n_children(tree
) != 1)
516 isl_die(isl_schedule_tree_get_ctx(tree
),
518 "can only replace single child by leaf",
520 return isl_schedule_tree_reset_children(tree
);
523 if (!tree
->children
&& pos
== 0)
525 isl_schedule_tree_list_from_schedule_tree(child
);
527 tree
->children
= isl_schedule_tree_list_set_schedule_tree(
528 tree
->children
, pos
, child
);
531 return isl_schedule_tree_free(tree
);
535 isl_schedule_tree_free(tree
);
536 isl_schedule_tree_free(child
);
540 /* Replace the (explicit) children of "tree" by "children"?
542 __isl_give isl_schedule_tree
*isl_schedule_tree_set_children(
543 __isl_take isl_schedule_tree
*tree
,
544 __isl_take isl_schedule_tree_list
*children
)
546 tree
= isl_schedule_tree_cow(tree
);
547 if (!tree
|| !children
)
549 isl_schedule_tree_list_free(tree
->children
);
550 tree
->children
= children
;
553 isl_schedule_tree_free(tree
);
554 isl_schedule_tree_list_free(children
);
558 /* Create a new band schedule tree referring to "band"
559 * with "tree" as single child.
561 __isl_give isl_schedule_tree
*isl_schedule_tree_insert_band(
562 __isl_take isl_schedule_tree
*tree
, __isl_take isl_schedule_band
*band
)
564 isl_schedule_tree
*res
;
566 res
= isl_schedule_tree_from_band(band
);
567 return isl_schedule_tree_replace_child(res
, 0, tree
);
570 /* Create a new domain schedule tree with the given domain and
571 * with "tree" as single child.
573 __isl_give isl_schedule_tree
*isl_schedule_tree_insert_domain(
574 __isl_take isl_schedule_tree
*tree
, __isl_take isl_union_set
*domain
)
576 isl_schedule_tree
*res
;
578 res
= isl_schedule_tree_from_domain(domain
);
579 return isl_schedule_tree_replace_child(res
, 0, tree
);
582 /* Create a new filter schedule tree with the given filter and single child.
584 * If the root of "tree" is itself a filter node, then the two
585 * filter nodes are merged into one node.
587 __isl_give isl_schedule_tree
*isl_schedule_tree_insert_filter(
588 __isl_take isl_schedule_tree
*tree
, __isl_take isl_union_set
*filter
)
590 isl_schedule_tree
*res
;
592 if (isl_schedule_tree_get_type(tree
) == isl_schedule_node_filter
) {
593 isl_union_set
*tree_filter
;
595 tree_filter
= isl_schedule_tree_filter_get_filter(tree
);
596 tree_filter
= isl_union_set_intersect(tree_filter
, filter
);
597 tree
= isl_schedule_tree_filter_set_filter(tree
, tree_filter
);
601 res
= isl_schedule_tree_from_filter(filter
);
602 return isl_schedule_tree_replace_child(res
, 0, tree
);
605 /* Insert a filter node with filter set "filter"
606 * in each of the children of "tree".
608 __isl_give isl_schedule_tree
*isl_schedule_tree_children_insert_filter(
609 __isl_take isl_schedule_tree
*tree
, __isl_take isl_union_set
*filter
)
613 if (!tree
|| !filter
)
616 n
= isl_schedule_tree_n_children(tree
);
617 for (i
= 0; i
< n
; ++i
) {
618 isl_schedule_tree
*child
;
620 child
= isl_schedule_tree_get_child(tree
, i
);
621 child
= isl_schedule_tree_insert_filter(child
,
622 isl_union_set_copy(filter
));
623 tree
= isl_schedule_tree_replace_child(tree
, i
, child
);
626 isl_union_set_free(filter
);
629 isl_union_set_free(filter
);
630 isl_schedule_tree_free(tree
);
634 /* Return the number of members in the band tree root.
636 unsigned isl_schedule_tree_band_n_member(__isl_keep isl_schedule_tree
*tree
)
641 if (tree
->type
!= isl_schedule_node_band
)
642 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
643 "not a band node", return 0);
645 return isl_schedule_band_n_member(tree
->band
);
648 /* Is the band member at position "pos" of the band tree root
651 int isl_schedule_tree_band_member_get_coincident(
652 __isl_keep isl_schedule_tree
*tree
, int pos
)
657 if (tree
->type
!= isl_schedule_node_band
)
658 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
659 "not a band node", return -1);
661 return isl_schedule_band_member_get_coincident(tree
->band
, pos
);
664 /* Mark the given band member as being coincident or not
665 * according to "coincident".
667 __isl_give isl_schedule_tree
*isl_schedule_tree_band_member_set_coincident(
668 __isl_take isl_schedule_tree
*tree
, int pos
, int coincident
)
672 if (tree
->type
!= isl_schedule_node_band
)
673 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
674 "not a band node", return isl_schedule_tree_free(tree
));
675 if (isl_schedule_tree_band_member_get_coincident(tree
, pos
) ==
678 tree
= isl_schedule_tree_cow(tree
);
682 tree
->band
= isl_schedule_band_member_set_coincident(tree
->band
, pos
,
685 return isl_schedule_tree_free(tree
);
689 /* Is the band tree root marked permutable?
691 int isl_schedule_tree_band_get_permutable(__isl_keep isl_schedule_tree
*tree
)
696 if (tree
->type
!= isl_schedule_node_band
)
697 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
698 "not a band node", return -1);
700 return isl_schedule_band_get_permutable(tree
->band
);
703 /* Mark the band tree root permutable or not according to "permutable"?
705 __isl_give isl_schedule_tree
*isl_schedule_tree_band_set_permutable(
706 __isl_take isl_schedule_tree
*tree
, int permutable
)
710 if (tree
->type
!= isl_schedule_node_band
)
711 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
712 "not a band node", return isl_schedule_tree_free(tree
));
713 if (isl_schedule_tree_band_get_permutable(tree
) == permutable
)
715 tree
= isl_schedule_tree_cow(tree
);
719 tree
->band
= isl_schedule_band_set_permutable(tree
->band
, permutable
);
721 return isl_schedule_tree_free(tree
);
725 /* Return the schedule space of the band tree root.
727 __isl_give isl_space
*isl_schedule_tree_band_get_space(
728 __isl_keep isl_schedule_tree
*tree
)
733 if (tree
->type
!= isl_schedule_node_band
)
734 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
735 "not a band node", return NULL
);
737 return isl_schedule_band_get_space(tree
->band
);
740 /* Return the schedule of the band tree root in isolation.
742 __isl_give isl_multi_union_pw_aff
*isl_schedule_tree_band_get_partial_schedule(
743 __isl_keep isl_schedule_tree
*tree
)
748 if (tree
->type
!= isl_schedule_node_band
)
749 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
750 "not a band node", return NULL
);
752 return isl_schedule_band_get_partial_schedule(tree
->band
);
755 /* Return the domain of the domain tree root.
757 __isl_give isl_union_set
*isl_schedule_tree_domain_get_domain(
758 __isl_keep isl_schedule_tree
*tree
)
763 if (tree
->type
!= isl_schedule_node_domain
)
764 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
765 "not a domain node", return NULL
);
767 return isl_union_set_copy(tree
->domain
);
770 /* Replace the domain of domain tree root "tree" by "domain".
772 __isl_give isl_schedule_tree
*isl_schedule_tree_domain_set_domain(
773 __isl_take isl_schedule_tree
*tree
, __isl_take isl_union_set
*domain
)
775 tree
= isl_schedule_tree_cow(tree
);
776 if (!tree
|| !domain
)
779 if (tree
->type
!= isl_schedule_node_domain
)
780 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
781 "not a domain node", goto error
);
783 isl_union_set_free(tree
->domain
);
784 tree
->domain
= domain
;
788 isl_schedule_tree_free(tree
);
789 isl_union_set_free(domain
);
793 /* Return the filter of the filter tree root.
795 __isl_give isl_union_set
*isl_schedule_tree_filter_get_filter(
796 __isl_keep isl_schedule_tree
*tree
)
801 if (tree
->type
!= isl_schedule_node_filter
)
802 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
803 "not a filter node", return NULL
);
805 return isl_union_set_copy(tree
->filter
);
808 /* Replace the filter of the filter tree root by "filter".
810 __isl_give isl_schedule_tree
*isl_schedule_tree_filter_set_filter(
811 __isl_take isl_schedule_tree
*tree
, __isl_take isl_union_set
*filter
)
813 tree
= isl_schedule_tree_cow(tree
);
814 if (!tree
|| !filter
)
817 if (tree
->type
!= isl_schedule_node_filter
)
818 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
819 "not a filter node", return NULL
);
821 isl_union_set_free(tree
->filter
);
822 tree
->filter
= filter
;
826 isl_schedule_tree_free(tree
);
827 isl_union_set_free(filter
);
831 /* Set dim to the range dimension of "map" and abort the search.
833 static int set_range_dim(__isl_take isl_map
*map
, void *user
)
837 *dim
= isl_map_dim(map
, isl_dim_out
);
843 /* Return the dimension of the range of "umap".
844 * "umap" is assumed not to be empty and
845 * all maps inside "umap" are assumed to have the same range.
847 * We extract the range dimension from the first map in "umap".
849 static int range_dim(__isl_keep isl_union_map
*umap
)
855 if (isl_union_map_n_map(umap
) == 0)
856 isl_die(isl_union_map_get_ctx(umap
), isl_error_internal
,
857 "unexpected empty input", return -1);
859 isl_union_map_foreach_map(umap
, &set_range_dim
, &dim
);
864 /* Append an "extra" number of zeros to the range of "umap" and
867 static __isl_give isl_union_map
*append_range(__isl_take isl_union_map
*umap
,
873 isl_union_pw_multi_aff
*suffix
;
874 isl_union_map
*universe
;
875 isl_union_map
*suffix_umap
;
877 universe
= isl_union_map_universe(isl_union_map_copy(umap
));
878 dom
= isl_union_map_domain(universe
);
879 space
= isl_union_set_get_space(dom
);
880 space
= isl_space_set_from_params(space
);
881 space
= isl_space_add_dims(space
, isl_dim_set
, extra
);
882 mv
= isl_multi_val_zero(space
);
884 suffix
= isl_union_pw_multi_aff_multi_val_on_domain(dom
, mv
);
885 suffix_umap
= isl_union_map_from_union_pw_multi_aff(suffix
);
886 umap
= isl_union_map_flat_range_product(umap
, suffix_umap
);
891 /* Move down to the first descendant of "tree" that contains any schedule
892 * information or return "leaf" if there is no such descendant.
894 __isl_give isl_schedule_tree
*isl_schedule_tree_first_schedule_descendant(
895 __isl_take isl_schedule_tree
*tree
, __isl_keep isl_schedule_tree
*leaf
)
897 while (isl_schedule_tree_get_type(tree
) == isl_schedule_node_band
&&
898 isl_schedule_tree_band_n_member(tree
) == 0) {
899 if (!isl_schedule_tree_has_children(tree
)) {
900 isl_schedule_tree_free(tree
);
901 return isl_schedule_tree_copy(leaf
);
903 tree
= isl_schedule_tree_child(tree
, 0);
909 static __isl_give isl_union_map
*subtree_schedule_extend(
910 __isl_keep isl_schedule_tree
*tree
, __isl_take isl_union_map
*outer
);
912 /* Extend the schedule map "outer" with the subtree schedule
913 * of the (single) child of "tree", if any.
915 * If "tree" does not have any descendants (apart from those that
916 * do not carry any schedule information), then we simply return "outer".
917 * Otherwise, we extend the schedule map "outer" with the subtree schedule
918 * of the single child.
920 static __isl_give isl_union_map
*subtree_schedule_extend_child(
921 __isl_keep isl_schedule_tree
*tree
, __isl_take isl_union_map
*outer
)
923 isl_schedule_tree
*child
;
927 return isl_union_map_free(outer
);
928 if (!isl_schedule_tree_has_children(tree
))
930 child
= isl_schedule_tree_get_child(tree
, 0);
932 return isl_union_map_free(outer
);
933 res
= subtree_schedule_extend(child
, outer
);
934 isl_schedule_tree_free(child
);
938 /* Extract the parameter space from one of the children of "tree",
939 * which are assumed to be filters.
941 static __isl_give isl_space
*extract_space_from_filter_child(
942 __isl_keep isl_schedule_tree
*tree
)
946 isl_schedule_tree
*child
;
948 child
= isl_schedule_tree_list_get_schedule_tree(tree
->children
, 0);
949 dom
= isl_schedule_tree_filter_get_filter(child
);
950 space
= isl_union_set_get_space(dom
);
951 isl_union_set_free(dom
);
952 isl_schedule_tree_free(child
);
957 /* Extend the schedule map "outer" with the subtree schedule
958 * of a set or sequence node.
960 * The schedule for the set or sequence node itself is composed of
969 * The first form is used if there is only a single child or
970 * if the current node is a set node and the schedule_separate_components
973 * Each of the pieces above is extended with the subtree schedule of
974 * the child of the corresponding filter, if any, padded with zeros
975 * to ensure that all pieces have the same range dimension.
977 static __isl_give isl_union_map
*subtree_schedule_extend_from_children(
978 __isl_keep isl_schedule_tree
*tree
, __isl_take isl_union_map
*outer
)
992 ctx
= isl_schedule_tree_get_ctx(tree
);
994 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_internal
,
995 "missing children", return NULL
);
996 n
= isl_schedule_tree_list_n_schedule_tree(tree
->children
);
998 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_internal
,
999 "missing children", return NULL
);
1001 separate
= n
> 1 && (tree
->type
== isl_schedule_node_sequence
||
1002 isl_options_get_schedule_separate_components(ctx
));
1004 space
= extract_space_from_filter_child(tree
);
1006 umap
= isl_union_map_empty(isl_space_copy(space
));
1007 space
= isl_space_set_from_params(space
);
1009 space
= isl_space_add_dims(space
, isl_dim_set
, 1);
1010 v
= isl_val_zero(ctx
);
1012 mv
= isl_multi_val_zero(space
);
1014 dim
= isl_multi_val_dim(mv
, isl_dim_set
);
1015 for (i
= 0; i
< n
; ++i
) {
1016 isl_union_pw_multi_aff
*upma
;
1017 isl_union_map
*umap_i
;
1019 isl_schedule_tree
*child
;
1023 child
= isl_schedule_tree_list_get_schedule_tree(
1025 dom
= isl_schedule_tree_filter_get_filter(child
);
1028 mv
= isl_multi_val_set_val(mv
, 0, isl_val_copy(v
));
1029 v
= isl_val_add_ui(v
, 1);
1031 upma
= isl_union_pw_multi_aff_multi_val_on_domain(dom
,
1032 isl_multi_val_copy(mv
));
1033 umap_i
= isl_union_map_from_union_pw_multi_aff(upma
);
1034 umap_i
= isl_union_map_flat_range_product(
1035 isl_union_map_copy(outer
), umap_i
);
1036 umap_i
= subtree_schedule_extend_child(child
, umap_i
);
1037 isl_schedule_tree_free(child
);
1039 empty
= isl_union_map_is_empty(umap_i
);
1041 umap_i
= isl_union_map_free(umap_i
);
1043 isl_union_map_free(umap_i
);
1047 dim_i
= range_dim(umap_i
);
1049 umap
= isl_union_map_free(umap
);
1050 } else if (dim
< dim_i
) {
1051 umap
= append_range(umap
, dim_i
- dim
);
1053 } else if (dim_i
< dim
) {
1054 umap_i
= append_range(umap_i
, dim
- dim_i
);
1056 umap
= isl_union_map_union(umap
, umap_i
);
1060 isl_multi_val_free(mv
);
1061 isl_union_map_free(outer
);
1066 /* Extend the schedule map "outer" with the subtree schedule of "tree".
1068 * If the root of the tree is a set or a sequence, then we extend
1069 * the schedule map in subtree_schedule_extend_from_children.
1070 * Otherwise, we extend the schedule map with the partial schedule
1071 * corresponding to the root of the tree and then continue with
1072 * the single child of this root.
1074 static __isl_give isl_union_map
*subtree_schedule_extend(
1075 __isl_keep isl_schedule_tree
*tree
, __isl_take isl_union_map
*outer
)
1077 isl_multi_union_pw_aff
*mupa
;
1078 isl_union_map
*umap
;
1079 isl_union_set
*domain
;
1084 switch (tree
->type
) {
1085 case isl_schedule_node_error
:
1086 return isl_union_map_free(outer
);
1087 case isl_schedule_node_band
:
1088 if (isl_schedule_tree_band_n_member(tree
) == 0)
1089 return subtree_schedule_extend_child(tree
, outer
);
1090 mupa
= isl_schedule_band_get_partial_schedule(tree
->band
);
1091 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
1092 outer
= isl_union_map_flat_range_product(outer
, umap
);
1093 umap
= subtree_schedule_extend_child(tree
, outer
);
1095 case isl_schedule_node_domain
:
1096 domain
= isl_schedule_tree_domain_get_domain(tree
);
1097 umap
= isl_union_map_from_domain(domain
);
1098 outer
= isl_union_map_flat_range_product(outer
, umap
);
1099 umap
= subtree_schedule_extend_child(tree
, outer
);
1101 case isl_schedule_node_filter
:
1102 domain
= isl_schedule_tree_filter_get_filter(tree
);
1103 umap
= isl_union_map_from_domain(domain
);
1104 outer
= isl_union_map_flat_range_product(outer
, umap
);
1105 umap
= subtree_schedule_extend_child(tree
, outer
);
1107 case isl_schedule_node_leaf
:
1108 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_internal
,
1109 "leaf node should be handled by caller", return NULL
);
1110 case isl_schedule_node_set
:
1111 case isl_schedule_node_sequence
:
1112 umap
= subtree_schedule_extend_from_children(tree
, outer
);
1119 static __isl_give isl_union_set
*initial_domain(
1120 __isl_keep isl_schedule_tree
*tree
);
1122 /* Extract a universe domain from the children of the tree root "tree",
1123 * which is a set or sequence, meaning that its children are filters.
1124 * In particular, return the union of the universes of the filters.
1126 static __isl_give isl_union_set
*initial_domain_from_children(
1127 __isl_keep isl_schedule_tree
*tree
)
1131 isl_union_set
*domain
;
1133 if (!tree
->children
)
1134 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_internal
,
1135 "missing children", return NULL
);
1136 n
= isl_schedule_tree_list_n_schedule_tree(tree
->children
);
1138 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_internal
,
1139 "missing children", return NULL
);
1141 space
= extract_space_from_filter_child(tree
);
1142 domain
= isl_union_set_empty(space
);
1144 for (i
= 0; i
< n
; ++i
) {
1145 isl_schedule_tree
*child
;
1146 isl_union_set
*domain_i
;
1148 child
= isl_schedule_tree_get_child(tree
, i
);
1149 domain_i
= initial_domain(child
);
1150 domain
= isl_union_set_union(domain
, domain_i
);
1151 isl_schedule_tree_free(child
);
1157 /* Extract a universe domain from the tree root "tree".
1158 * The caller is responsible for making sure that this node
1159 * would not be skipped by isl_schedule_tree_first_schedule_descendant
1160 * and that it is not a leaf node.
1162 static __isl_give isl_union_set
*initial_domain(
1163 __isl_keep isl_schedule_tree
*tree
)
1165 isl_multi_union_pw_aff
*mupa
;
1166 isl_union_set
*domain
;
1171 switch (tree
->type
) {
1172 case isl_schedule_node_error
:
1174 case isl_schedule_node_band
:
1175 if (isl_schedule_tree_band_n_member(tree
) == 0)
1176 isl_die(isl_schedule_tree_get_ctx(tree
),
1178 "0D band should be handled by caller",
1180 mupa
= isl_schedule_band_get_partial_schedule(tree
->band
);
1181 domain
= isl_multi_union_pw_aff_domain(mupa
);
1182 domain
= isl_union_set_universe(domain
);
1184 case isl_schedule_node_domain
:
1185 domain
= isl_schedule_tree_domain_get_domain(tree
);
1186 domain
= isl_union_set_universe(domain
);
1188 case isl_schedule_node_filter
:
1189 domain
= isl_schedule_tree_filter_get_filter(tree
);
1190 domain
= isl_union_set_universe(domain
);
1192 case isl_schedule_node_leaf
:
1193 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_internal
,
1194 "leaf node should be handled by caller", return NULL
);
1195 case isl_schedule_node_set
:
1196 case isl_schedule_node_sequence
:
1197 domain
= initial_domain_from_children(tree
);
1204 /* Return the subtree schedule of a node that contains some schedule
1205 * information, i.e., a node that would not be skipped by
1206 * isl_schedule_tree_first_schedule_descendant and that is not a leaf.
1208 * We start with an initial zero-dimensional subtree schedule based
1209 * on the domain information in the root node and then extend it
1210 * based on the schedule information in the root node and its descendants.
1212 __isl_give isl_union_map
*isl_schedule_tree_get_subtree_schedule_union_map(
1213 __isl_keep isl_schedule_tree
*tree
)
1215 isl_union_set
*domain
;
1216 isl_union_map
*umap
;
1218 domain
= initial_domain(tree
);
1219 umap
= isl_union_map_from_domain(domain
);
1220 return subtree_schedule_extend(tree
, umap
);
1223 /* Multiply the partial schedule of the band root node of "tree"
1224 * with the factors in "mv".
1226 __isl_give isl_schedule_tree
*isl_schedule_tree_band_scale(
1227 __isl_take isl_schedule_tree
*tree
, __isl_take isl_multi_val
*mv
)
1231 if (tree
->type
!= isl_schedule_node_band
)
1232 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
1233 "not a band node", goto error
);
1235 tree
= isl_schedule_tree_cow(tree
);
1239 tree
->band
= isl_schedule_band_scale(tree
->band
, mv
);
1241 return isl_schedule_tree_free(tree
);
1245 isl_schedule_tree_free(tree
);
1246 isl_multi_val_free(mv
);
1250 /* Divide the partial schedule of the band root node of "tree"
1251 * by the factors in "mv".
1253 __isl_give isl_schedule_tree
*isl_schedule_tree_band_scale_down(
1254 __isl_take isl_schedule_tree
*tree
, __isl_take isl_multi_val
*mv
)
1258 if (tree
->type
!= isl_schedule_node_band
)
1259 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
1260 "not a band node", goto error
);
1262 tree
= isl_schedule_tree_cow(tree
);
1266 tree
->band
= isl_schedule_band_scale_down(tree
->band
, mv
);
1268 return isl_schedule_tree_free(tree
);
1272 isl_schedule_tree_free(tree
);
1273 isl_multi_val_free(mv
);
1277 /* Tile the band root node of "tree" with tile sizes "sizes".
1279 * We duplicate the band node, change the schedule of one of them
1280 * to the tile schedule and the other to the point schedule and then
1281 * attach the point band as a child to the tile band.
1283 __isl_give isl_schedule_tree
*isl_schedule_tree_band_tile(
1284 __isl_take isl_schedule_tree
*tree
, __isl_take isl_multi_val
*sizes
)
1286 isl_schedule_tree
*child
= NULL
;
1288 if (!tree
|| !sizes
)
1290 if (tree
->type
!= isl_schedule_node_band
)
1291 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
1292 "not a band node", goto error
);
1294 child
= isl_schedule_tree_copy(tree
);
1295 tree
= isl_schedule_tree_cow(tree
);
1296 child
= isl_schedule_tree_cow(child
);
1297 if (!tree
|| !child
)
1300 tree
->band
= isl_schedule_band_tile(tree
->band
,
1301 isl_multi_val_copy(sizes
));
1304 child
->band
= isl_schedule_band_point(child
->band
, tree
->band
, sizes
);
1306 child
= isl_schedule_tree_free(child
);
1308 tree
= isl_schedule_tree_replace_child(tree
, 0, child
);
1312 isl_schedule_tree_free(child
);
1313 isl_schedule_tree_free(tree
);
1314 isl_multi_val_free(sizes
);
1318 /* Split the band root node of "tree" into two nested band nodes,
1319 * one with the first "pos" dimensions and
1320 * one with the remaining dimensions.
1322 __isl_give isl_schedule_tree
*isl_schedule_tree_band_split(
1323 __isl_take isl_schedule_tree
*tree
, int pos
)
1326 isl_schedule_tree
*child
;
1330 if (tree
->type
!= isl_schedule_node_band
)
1331 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
1332 "not a band node", return isl_schedule_tree_free(tree
));
1334 n
= isl_schedule_tree_band_n_member(tree
);
1335 if (pos
< 0 || pos
> n
)
1336 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
1337 "position out of bounds",
1338 return isl_schedule_tree_free(tree
));
1340 child
= isl_schedule_tree_copy(tree
);
1341 tree
= isl_schedule_tree_cow(tree
);
1342 child
= isl_schedule_tree_cow(child
);
1343 if (!tree
|| !child
)
1346 child
->band
= isl_schedule_band_drop(child
->band
, 0, pos
);
1347 tree
->band
= isl_schedule_band_drop(tree
->band
, pos
, n
- pos
);
1348 if (!child
->band
|| !tree
->band
)
1351 tree
= isl_schedule_tree_replace_child(tree
, 0, child
);
1355 isl_schedule_tree_free(child
);
1356 isl_schedule_tree_free(tree
);
1360 /* Attach "tree2" at each of the leaves of "tree1".
1362 * If "tree1" does not have any explicit children, then make "tree2"
1363 * its single child. Otherwise, attach "tree2" to the leaves of
1364 * each of the children of "tree1".
1366 __isl_give isl_schedule_tree
*isl_schedule_tree_append_to_leaves(
1367 __isl_take isl_schedule_tree
*tree1
,
1368 __isl_take isl_schedule_tree
*tree2
)
1372 if (!tree1
|| !tree2
)
1374 n
= isl_schedule_tree_n_children(tree1
);
1376 isl_schedule_tree_list
*list
;
1377 list
= isl_schedule_tree_list_from_schedule_tree(tree2
);
1378 tree1
= isl_schedule_tree_set_children(tree1
, list
);
1381 for (i
= 0; i
< n
; ++i
) {
1382 isl_schedule_tree
*child
;
1384 child
= isl_schedule_tree_get_child(tree1
, i
);
1385 child
= isl_schedule_tree_append_to_leaves(child
,
1386 isl_schedule_tree_copy(tree2
));
1387 tree1
= isl_schedule_tree_replace_child(tree1
, i
, child
);
1390 isl_schedule_tree_free(tree2
);
1393 isl_schedule_tree_free(tree1
);
1394 isl_schedule_tree_free(tree2
);
1398 /* Reset the user pointer on all identifiers of parameters and tuples
1399 * in the root of "tree".
1401 __isl_give isl_schedule_tree
*isl_schedule_tree_reset_user(
1402 __isl_take isl_schedule_tree
*tree
)
1404 if (isl_schedule_tree_is_leaf(tree
))
1407 tree
= isl_schedule_tree_cow(tree
);
1411 switch (tree
->type
) {
1412 case isl_schedule_node_error
:
1413 return isl_schedule_tree_free(tree
);
1414 case isl_schedule_node_band
:
1415 tree
->band
= isl_schedule_band_reset_user(tree
->band
);
1417 return isl_schedule_tree_free(tree
);
1419 case isl_schedule_node_domain
:
1420 tree
->domain
= isl_union_set_reset_user(tree
->domain
);
1422 return isl_schedule_tree_free(tree
);
1424 case isl_schedule_node_filter
:
1425 tree
->filter
= isl_union_set_reset_user(tree
->filter
);
1427 return isl_schedule_tree_free(tree
);
1429 case isl_schedule_node_leaf
:
1430 case isl_schedule_node_sequence
:
1431 case isl_schedule_node_set
:
1438 /* Align the parameters of the root of "tree" to those of "space".
1440 __isl_give isl_schedule_tree
*isl_schedule_tree_align_params(
1441 __isl_take isl_schedule_tree
*tree
, __isl_take isl_space
*space
)
1446 if (isl_schedule_tree_is_leaf(tree
)) {
1447 isl_space_free(space
);
1451 tree
= isl_schedule_tree_cow(tree
);
1455 switch (tree
->type
) {
1456 case isl_schedule_node_error
:
1458 case isl_schedule_node_band
:
1459 tree
->band
= isl_schedule_band_align_params(tree
->band
, space
);
1461 return isl_schedule_tree_free(tree
);
1463 case isl_schedule_node_domain
:
1464 tree
->domain
= isl_union_set_align_params(tree
->domain
, space
);
1466 return isl_schedule_tree_free(tree
);
1468 case isl_schedule_node_filter
:
1469 tree
->filter
= isl_union_set_align_params(tree
->filter
, space
);
1471 return isl_schedule_tree_free(tree
);
1473 case isl_schedule_node_leaf
:
1474 case isl_schedule_node_sequence
:
1475 case isl_schedule_node_set
:
1476 isl_space_free(space
);
1482 isl_space_free(space
);
1483 isl_schedule_tree_free(tree
);
1487 /* Does "tree" involve the iteration domain?
1488 * That is, does it need to be modified
1489 * by isl_schedule_tree_pullback_union_pw_multi_aff?
1491 static int involves_iteration_domain(__isl_keep isl_schedule_tree
*tree
)
1496 switch (tree
->type
) {
1497 case isl_schedule_node_error
:
1499 case isl_schedule_node_band
:
1500 case isl_schedule_node_domain
:
1501 case isl_schedule_node_filter
:
1503 case isl_schedule_node_leaf
:
1504 case isl_schedule_node_sequence
:
1505 case isl_schedule_node_set
:
1510 /* Compute the pullback of the root node of "tree" by the function
1511 * represented by "upma".
1512 * In other words, plug in "upma" in the iteration domains of
1513 * the root node of "tree".
1515 * We first check if the root node involves any iteration domains.
1516 * If so, we handle the specific cases.
1518 __isl_give isl_schedule_tree
*isl_schedule_tree_pullback_union_pw_multi_aff(
1519 __isl_take isl_schedule_tree
*tree
,
1520 __isl_take isl_union_pw_multi_aff
*upma
)
1527 involves
= involves_iteration_domain(tree
);
1531 isl_union_pw_multi_aff_free(upma
);
1535 tree
= isl_schedule_tree_cow(tree
);
1539 if (tree
->type
== isl_schedule_node_band
) {
1540 tree
->band
= isl_schedule_band_pullback_union_pw_multi_aff(
1543 return isl_schedule_tree_free(tree
);
1544 } else if (tree
->type
== isl_schedule_node_domain
) {
1546 isl_union_set_preimage_union_pw_multi_aff(tree
->domain
,
1549 return isl_schedule_tree_free(tree
);
1550 } else if (tree
->type
== isl_schedule_node_filter
) {
1552 isl_union_set_preimage_union_pw_multi_aff(tree
->filter
,
1555 return isl_schedule_tree_free(tree
);
1560 isl_union_pw_multi_aff_free(upma
);
1561 isl_schedule_tree_free(tree
);
1565 /* Compute the gist of the band tree root with respect to "context".
1567 __isl_give isl_schedule_tree
*isl_schedule_tree_band_gist(
1568 __isl_take isl_schedule_tree
*tree
, __isl_take isl_union_set
*context
)
1572 if (tree
->type
!= isl_schedule_node_band
)
1573 isl_die(isl_schedule_tree_get_ctx(tree
), isl_error_invalid
,
1574 "not a band node", goto error
);
1575 tree
= isl_schedule_tree_cow(tree
);
1579 tree
->band
= isl_schedule_band_gist(tree
->band
, context
);
1581 return isl_schedule_tree_free(tree
);
1584 isl_union_set_free(context
);
1585 isl_schedule_tree_free(tree
);
1589 /* Are any members in "band" marked coincident?
1591 static int any_coincident(__isl_keep isl_schedule_band
*band
)
1595 n
= isl_schedule_band_n_member(band
);
1596 for (i
= 0; i
< n
; ++i
)
1597 if (isl_schedule_band_member_get_coincident(band
, i
))
1603 /* Print the band node "band" to "p".
1605 * The permutable and coincident properties are only printed if they
1606 * are different from the defaults.
1607 * The coincident property is always printed in YAML flow style.
1609 static __isl_give isl_printer
*print_tree_band(__isl_take isl_printer
*p
,
1610 __isl_keep isl_schedule_band
*band
)
1612 p
= isl_printer_print_str(p
, "schedule");
1613 p
= isl_printer_yaml_next(p
);
1614 p
= isl_printer_print_str(p
, "\"");
1615 p
= isl_printer_print_multi_union_pw_aff(p
, band
->mupa
);
1616 p
= isl_printer_print_str(p
, "\"");
1617 if (isl_schedule_band_get_permutable(band
)) {
1618 p
= isl_printer_yaml_next(p
);
1619 p
= isl_printer_print_str(p
, "permutable");
1620 p
= isl_printer_yaml_next(p
);
1621 p
= isl_printer_print_int(p
, 1);
1623 if (any_coincident(band
)) {
1627 p
= isl_printer_yaml_next(p
);
1628 p
= isl_printer_print_str(p
, "coincident");
1629 p
= isl_printer_yaml_next(p
);
1630 style
= isl_printer_get_yaml_style(p
);
1631 p
= isl_printer_set_yaml_style(p
, ISL_YAML_STYLE_FLOW
);
1632 p
= isl_printer_yaml_start_sequence(p
);
1633 n
= isl_schedule_band_n_member(band
);
1634 for (i
= 0; i
< n
; ++i
) {
1635 p
= isl_printer_print_int(p
,
1636 isl_schedule_band_member_get_coincident(band
, i
));
1637 p
= isl_printer_yaml_next(p
);
1639 p
= isl_printer_yaml_end_sequence(p
);
1640 p
= isl_printer_set_yaml_style(p
, style
);
1646 /* Print "tree" to "p".
1648 * If "n_ancestor" is non-negative, then "child_pos" contains the child
1649 * positions of a descendant of the current node that should be marked
1650 * (by the comment "YOU ARE HERE"). In particular, if "n_ancestor"
1651 * is zero, then the current node should be marked.
1652 * The marking is only printed in YAML block format.
1654 * Implicit leaf nodes are not printed, except if they correspond
1655 * to the node that should be marked.
1657 __isl_give isl_printer
*isl_printer_print_schedule_tree_mark(
1658 __isl_take isl_printer
*p
, __isl_keep isl_schedule_tree
*tree
,
1659 int n_ancestor
, int *child_pos
)
1665 block
= isl_printer_get_yaml_style(p
) == ISL_YAML_STYLE_BLOCK
;
1667 p
= isl_printer_yaml_start_mapping(p
);
1668 if (n_ancestor
== 0 && block
) {
1669 p
= isl_printer_print_str(p
, "# YOU ARE HERE");
1670 p
= isl_printer_end_line(p
);
1671 p
= isl_printer_start_line(p
);
1673 switch (tree
->type
) {
1674 case isl_schedule_node_error
:
1675 p
= isl_printer_print_str(p
, "ERROR");
1677 case isl_schedule_node_leaf
:
1678 p
= isl_printer_print_str(p
, "leaf");
1680 case isl_schedule_node_sequence
:
1681 p
= isl_printer_print_str(p
, "sequence");
1684 case isl_schedule_node_set
:
1685 p
= isl_printer_print_str(p
, "set");
1688 case isl_schedule_node_domain
:
1689 p
= isl_printer_print_str(p
, "domain");
1690 p
= isl_printer_yaml_next(p
);
1691 p
= isl_printer_print_str(p
, "\"");
1692 p
= isl_printer_print_union_set(p
, tree
->domain
);
1693 p
= isl_printer_print_str(p
, "\"");
1695 case isl_schedule_node_filter
:
1696 p
= isl_printer_print_str(p
, "filter");
1697 p
= isl_printer_yaml_next(p
);
1698 p
= isl_printer_print_str(p
, "\"");
1699 p
= isl_printer_print_union_set(p
, tree
->filter
);
1700 p
= isl_printer_print_str(p
, "\"");
1702 case isl_schedule_node_band
:
1703 p
= print_tree_band(p
, tree
->band
);
1706 p
= isl_printer_yaml_next(p
);
1708 if (!tree
->children
) {
1709 if (n_ancestor
> 0 && block
) {
1710 isl_schedule_tree
*leaf
;
1712 p
= isl_printer_print_str(p
, "child");
1713 p
= isl_printer_yaml_next(p
);
1714 leaf
= isl_schedule_tree_leaf(isl_printer_get_ctx(p
));
1715 p
= isl_printer_print_schedule_tree_mark(p
,
1717 isl_schedule_tree_free(leaf
);
1718 p
= isl_printer_yaml_next(p
);
1720 return isl_printer_yaml_end_mapping(p
);
1724 p
= isl_printer_yaml_start_sequence(p
);
1726 p
= isl_printer_print_str(p
, "child");
1727 p
= isl_printer_yaml_next(p
);
1730 n
= isl_schedule_tree_list_n_schedule_tree(tree
->children
);
1731 for (i
= 0; i
< n
; ++i
) {
1732 isl_schedule_tree
*t
;
1734 t
= isl_schedule_tree_get_child(tree
, i
);
1735 if (n_ancestor
> 0 && child_pos
[0] == i
)
1736 p
= isl_printer_print_schedule_tree_mark(p
, t
,
1737 n_ancestor
- 1, child_pos
+ 1);
1739 p
= isl_printer_print_schedule_tree_mark(p
, t
,
1741 isl_schedule_tree_free(t
);
1743 p
= isl_printer_yaml_next(p
);
1747 p
= isl_printer_yaml_end_sequence(p
);
1748 p
= isl_printer_yaml_end_mapping(p
);
1753 /* Print "tree" to "p".
1755 __isl_give isl_printer
*isl_printer_print_schedule_tree(
1756 __isl_take isl_printer
*p
, __isl_keep isl_schedule_tree
*tree
)
1758 return isl_printer_print_schedule_tree_mark(p
, tree
, -1, NULL
);
1761 void isl_schedule_tree_dump(__isl_keep isl_schedule_tree
*tree
)
1764 isl_printer
*printer
;
1769 ctx
= isl_schedule_tree_get_ctx(tree
);
1770 printer
= isl_printer_to_file(ctx
, stderr
);
1771 printer
= isl_printer_set_yaml_style(printer
, ISL_YAML_STYLE_BLOCK
);
1772 printer
= isl_printer_print_schedule_tree(printer
, tree
);
1774 isl_printer_free(printer
);