Polly 23.0.0git
isl_ast_codegen.c
Go to the documentation of this file.
1/*
2 * Copyright 2012-2014 Ecole Normale Superieure
3 * Copyright 2014 INRIA Rocquencourt
4 *
5 * Use of this software is governed by the MIT license
6 *
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
11 */
12
13#include <limits.h>
14#include <isl/id.h>
15#include <isl/val.h>
16#include <isl/space.h>
17#include <isl/aff.h>
18#include <isl/constraint.h>
19#include <isl/set.h>
20#include <isl/ilp.h>
21#include <isl/union_set.h>
22#include <isl/union_map.h>
23#include <isl/schedule_node.h>
24#include <isl/options.h>
25#include <isl_sort.h>
26#include <isl_tarjan.h>
27#include <isl_ast_private.h>
28#include <isl_ast_build_expr.h>
31
32/* Try and reduce the number of disjuncts in the representation of "set",
33 * without dropping explicit representations of local variables.
34 */
36{
37 isl_ctx *ctx;
38 int save_preserve;
39
40 if (!set)
41 return NULL;
42
43 ctx = isl_set_get_ctx(set);
48 return set;
49}
50
51/* Data used in generate_domain.
52 *
53 * "build" is the input build.
54 * "list" collects the results.
55 */
58
59 isl_ast_graft_list *list;
60};
61
62static __isl_give isl_ast_graft_list *generate_next_level(
63 __isl_take isl_union_map *executed,
65static __isl_give isl_ast_graft_list *generate_code(
67 int internal);
68
69/* Generate an AST for a single domain based on
70 * the (non single valued) inverse schedule "executed".
71 *
72 * We extend the schedule with the iteration domain
73 * and continue generating through a call to generate_code.
74 *
75 * In particular, if executed has the form
76 *
77 * S -> D
78 *
79 * then we continue generating code on
80 *
81 * [S -> D] -> D
82 *
83 * The extended inverse schedule is clearly single valued
84 * ensuring that the nested generate_code will not reach this function,
85 * but will instead create calls to all elements of D that need
86 * to be executed from the current schedule domain.
87 */
89 struct isl_generate_domain_data *data)
90{
92 isl_ast_build *build;
93 isl_ast_graft_list *list;
94
95 build = isl_ast_build_copy(data->build);
96
98 executed = isl_map_domain_product(executed, identity);
99
100 list = generate_code(isl_union_map_from_map(executed), build, 1);
101
102 data->list = isl_ast_graft_list_concat(data->list, list);
103
104 return isl_stat_ok;
105}
106
107/* Call the at_each_domain callback, if requested by the user,
108 * after recording the current inverse schedule in the build.
109 */
111 __isl_keep isl_map *executed, __isl_keep isl_ast_build *build)
112{
113 if (!graft || !build)
114 return isl_ast_graft_free(graft);
115 if (!build->at_each_domain)
116 return graft;
117
118 build = isl_ast_build_copy(build);
119 build = isl_ast_build_set_executed(build,
121 if (!build)
122 return isl_ast_graft_free(graft);
123
124 graft->node = build->at_each_domain(graft->node,
125 build, build->at_each_domain_user);
126 isl_ast_build_free(build);
127
128 if (!graft->node)
129 graft = isl_ast_graft_free(graft);
130
131 return graft;
132}
133
134/* Generate a call expression for the single executed
135 * domain element "executed" and put a guard around it based on its (simplified)
136 * domain.
137 *
138 * At this stage, any pending constraints in the build can no longer
139 * be simplified with respect to any enforced constraints since
140 * the call node does not have any enforced constraints.
141 * Since all pending constraints not covered by any enforced constraints
142 * will be added as a guard to the graft in create_node_scaled,
143 * even in the eliminated case, the pending constraints
144 * can be considered to have been generated by outer constructs.
145 *
146 * If the user has set an at_each_domain callback, it is called
147 * on the constructed call expression node.
148 */
150 struct isl_generate_domain_data *data)
151{
152 isl_ast_build *build;
153 isl_ast_graft *graft;
154 isl_ast_graft_list *list;
155 isl_set *guard, *pending;
156
157 build = isl_ast_build_copy(data->build);
158 pending = isl_ast_build_get_pending(build);
159 build = isl_ast_build_replace_pending_by_guard(build, pending);
160
161 guard = isl_map_domain(isl_map_copy(executed));
162 guard = isl_set_compute_divs(guard);
163 guard = isl_set_coalesce_preserve(guard);
164 guard = isl_set_gist(guard, isl_ast_build_get_generated(build));
165 guard = isl_ast_build_specialize(build, guard);
166
167 graft = isl_ast_graft_alloc_domain(isl_map_copy(executed), build);
168 graft = at_each_domain(graft, executed, build);
169 isl_ast_build_free(build);
170 isl_map_free(executed);
171 graft = isl_ast_graft_add_guard(graft, guard, data->build);
172
173 list = isl_ast_graft_list_from_ast_graft(graft);
174 data->list = isl_ast_graft_list_concat(data->list, list);
175
176 return isl_stat_ok;
177}
178
179/* Generate an AST for a single domain based on
180 * the inverse schedule "executed" and add it to data->list.
181 *
182 * If there is more than one domain element associated to the current
183 * schedule "time", then we need to continue the generation process
184 * in generate_non_single_valued.
185 * Note that the inverse schedule being single-valued may depend
186 * on constraints that are only available in the original context
187 * domain specified by the user. We therefore first introduce
188 * some of the constraints of data->build->domain. In particular,
189 * we intersect with a single-disjunct approximation of this set.
190 * We perform this approximation to avoid further splitting up
191 * the executed relation, possibly introducing a disjunctive guard
192 * on the statement.
193 *
194 * Otherwise, call add_domain to generate a call expression (with guard) and
195 * to call the at_each_domain callback, if any.
196 *
197 * Coalesce the inverse schedule before checking for single-valuedness.
198 * Skip this if the inverse schedule is obviously single-valued.
199 */
201{
202 struct isl_generate_domain_data *data = user;
204 int empty, sv;
205
208 executed = isl_map_intersect_domain(executed, domain);
209 empty = isl_map_is_empty(executed);
210 if (empty < 0)
211 goto error;
212 if (empty) {
213 isl_map_free(executed);
214 return isl_stat_ok;
215 }
216
218 if (sv < 0)
219 goto error;
220 if (sv)
221 return add_domain(executed, data);
222
223 executed = isl_map_coalesce(executed);
224 sv = isl_map_is_single_valued(executed);
225 if (sv < 0)
226 goto error;
227 if (!sv)
228 return generate_non_single_valued(executed, data);
229
230 return add_domain(executed, data);
231error:
232 isl_map_free(executed);
233 return isl_stat_error;
234}
235
236/* Call build->create_leaf to a create "leaf" node in the AST,
237 * encapsulate the result in an isl_ast_graft and return the result
238 * as a 1-element list.
239 *
240 * Note that the node returned by the user may be an entire tree.
241 *
242 * Since the node itself cannot enforce any constraints, we turn
243 * all pending constraints into guards and add them to the resulting
244 * graft to ensure that they will be generated.
245 *
246 * Before we pass control to the user, we first clear some information
247 * from the build that is (presumbably) only meaningful
248 * for the current code generation.
249 * This includes the create_leaf callback itself, so we make a copy
250 * of the build first.
251 */
252static __isl_give isl_ast_graft_list *call_create_leaf(
254{
255 isl_set *guard;
256 isl_ast_node *node;
257 isl_ast_graft *graft;
258 isl_ast_build *user_build;
259
261 user_build = isl_ast_build_copy(build);
262 user_build = isl_ast_build_replace_pending_by_guard(user_build,
263 isl_set_copy(guard));
264 user_build = isl_ast_build_set_executed(user_build, executed);
265 user_build = isl_ast_build_clear_local_info(user_build);
266 if (!user_build)
267 node = NULL;
268 else
269 node = build->create_leaf(user_build, build->create_leaf_user);
270 graft = isl_ast_graft_alloc(node, build);
271 graft = isl_ast_graft_add_guard(graft, guard, build);
273 return isl_ast_graft_list_from_ast_graft(graft);
274}
275
276static __isl_give isl_ast_graft_list *build_ast_from_child(
278 __isl_take isl_union_map *executed);
279
280/* Generate an AST after having handled the complete schedule
281 * of this call to the code generator or the complete band
282 * if we are generating an AST from a schedule tree.
283 *
284 * If we are inside a band node, then move on to the child of the band.
285 *
286 * If the user has specified a create_leaf callback, control
287 * is passed to the user in call_create_leaf.
288 *
289 * Otherwise, we generate one or more calls for each individual
290 * domain in generate_domain.
291 */
292static __isl_give isl_ast_graft_list *generate_inner_level(
294{
295 isl_ctx *ctx;
296 struct isl_generate_domain_data data = { build };
297
298 if (!build || !executed)
299 goto error;
300
302 isl_schedule_node *node;
305 return build_ast_from_child(build, node, executed);
306 }
307
308 if (build->create_leaf)
309 return call_create_leaf(executed, build);
310
311 ctx = isl_union_map_get_ctx(executed);
312 data.list = isl_ast_graft_list_alloc(ctx, 0);
313 if (isl_union_map_foreach_map(executed, &generate_domain, &data) < 0)
314 data.list = isl_ast_graft_list_free(data.list);
315
316 if (0)
317error: data.list = NULL;
319 isl_union_map_free(executed);
320 return data.list;
321}
322
323/* Call the before_each_for callback, if requested by the user.
324 */
327{
328 isl_id *id;
329
330 if (!node || !build)
331 return isl_ast_node_free(node);
333 return node;
335 node = isl_ast_node_set_annotation(node, id);
336 return node;
337}
338
339/* Call the after_each_for callback, if requested by the user.
340 */
343{
344 if (!graft || !build)
345 return isl_ast_graft_free(graft);
346 if (!build->after_each_for)
347 return graft;
348 graft->node = build->after_each_for(graft->node, build,
350 if (!graft->node)
351 return isl_ast_graft_free(graft);
352 return graft;
353}
354
355/* Plug in all the know values of the current and outer dimensions
356 * in the domain of "executed". In principle, we only need to plug
357 * in the known value of the current dimension since the values of
358 * outer dimensions have been plugged in already.
359 * However, it turns out to be easier to just plug in all known values.
360 */
367
368/* Check if the constraint "c" is a lower bound on dimension "pos",
369 * an upper bound, or independent of dimension "pos".
370 */
372{
374 return 1;
376 return 2;
377 return 0;
378}
379
380/* Compare the types of the constraints "a" and "b",
381 * resulting in constraints that are independent of "depth"
382 * to be sorted before the lower bounds on "depth", which in
383 * turn are sorted before the upper bounds on "depth".
384 */
387{
388 int *depth = user;
389 int t1 = constraint_type(a, *depth);
390 int t2 = constraint_type(b, *depth);
391
392 return t1 - t2;
393}
394
395/* Extract a lower bound on dimension "pos" from constraint "c".
396 *
397 * If the constraint is of the form
398 *
399 * a x + f(...) >= 0
400 *
401 * then we essentially return
402 *
403 * l = ceil(-f(...)/a)
404 *
405 * However, if the current dimension is strided, then we need to make
406 * sure that the lower bound we construct is of the form
407 *
408 * f + s a
409 *
410 * with f the offset and s the stride.
411 * We therefore compute
412 *
413 * f + s * ceil((l - f)/s)
414 */
441
442/* Return the exact lower bound (or upper bound if "upper" is set)
443 * of "domain" as a piecewise affine expression.
444 *
445 * If we are computing a lower bound (of a strided dimension), then
446 * we need to make sure it is of the form
447 *
448 * f + s a
449 *
450 * where f is the offset and s is the stride.
451 * We therefore need to include the stride constraint before computing
452 * the minimum.
453 */
455 __isl_keep isl_ast_build *build, int upper)
456{
457 isl_set *stride;
458 isl_map *it_map;
459 isl_pw_aff *pa;
461
463 if (!upper) {
466 }
468 if (upper)
470 else
476
477 return pa;
478}
479
480/* Callback for sorting the isl_pw_aff_list passed to reduce_list and
481 * remove_redundant_lower_bounds.
482 */
484 void *user)
485{
486 return isl_pw_aff_plain_cmp(a, b);
487}
488
489/* Given a list of lower bounds "list", remove those that are redundant
490 * with respect to the other bounds in "list" and the domain of "build".
491 *
492 * We first sort the bounds in the same way as they would be sorted
493 * by set_for_node_expressions so that we can try and remove the last
494 * bounds first.
495 *
496 * For a lower bound to be effective, there needs to be at least
497 * one domain element for which it is larger than all other lower bounds.
498 * For each lower bound we therefore intersect the domain with
499 * the conditions that it is larger than all other bounds and
500 * check whether the result is empty. If so, the bound can be removed.
501 */
503 __isl_take isl_pw_aff_list *list, __isl_keep isl_ast_build *build)
504{
505 int i, j;
506 isl_size n;
508
509 list = isl_pw_aff_list_sort(list, &reduce_list_cmp, NULL);
510
511 n = isl_pw_aff_list_n_pw_aff(list);
512 if (n < 0)
513 return isl_pw_aff_list_free(list);
514 if (n <= 1)
515 return list;
516
518
519 for (i = n - 1; i >= 0; --i) {
520 isl_pw_aff *pa_i;
521 isl_set *domain_i;
522 int empty;
523
524 domain_i = isl_set_copy(domain);
525 pa_i = isl_pw_aff_list_get_pw_aff(list, i);
526
527 for (j = 0; j < n; ++j) {
528 isl_pw_aff *pa_j;
529 isl_set *better;
530
531 if (j == i)
532 continue;
533
534 pa_j = isl_pw_aff_list_get_pw_aff(list, j);
535 better = isl_pw_aff_gt_set(isl_pw_aff_copy(pa_i), pa_j);
536 domain_i = isl_set_intersect(domain_i, better);
537 }
538
539 empty = isl_set_is_empty(domain_i);
540
541 isl_set_free(domain_i);
542 isl_pw_aff_free(pa_i);
543
544 if (empty < 0)
545 goto error;
546 if (!empty)
547 continue;
548 list = isl_pw_aff_list_drop(list, i, 1);
549 n--;
550 }
551
553
554 return list;
555error:
557 return isl_pw_aff_list_free(list);
558}
559
560/* Extract a lower bound on dimension "pos" from each constraint
561 * in "constraints" and return the list of lower bounds.
562 * If "constraints" has zero elements, then we extract a lower bound
563 * from "domain" instead.
564 *
565 * If the current dimension is strided, then the lower bound
566 * is adjusted by lower_bound to match the stride information.
567 * This modification may make one or more lower bounds redundant
568 * with respect to the other lower bounds. We therefore check
569 * for this condition and remove the redundant lower bounds.
570 */
571static __isl_give isl_pw_aff_list *lower_bounds(
572 __isl_keep isl_constraint_list *constraints, int pos,
574{
575 isl_ctx *ctx;
576 isl_pw_aff_list *list;
577 int i;
578 isl_size n;
579
580 if (!build)
581 return NULL;
582
583 n = isl_constraint_list_n_constraint(constraints);
584 if (n < 0)
585 return NULL;
586 if (n == 0) {
587 isl_pw_aff *pa;
588 pa = exact_bound(domain, build, 0);
589 return isl_pw_aff_list_from_pw_aff(pa);
590 }
591
593 list = isl_pw_aff_list_alloc(ctx,n);
594
595 for (i = 0; i < n; ++i) {
596 isl_aff *aff;
598
599 c = isl_constraint_list_get_constraint(constraints, i);
600 aff = lower_bound(c, pos, build);
602 list = isl_pw_aff_list_add(list, isl_pw_aff_from_aff(aff));
603 }
604
607
608 return list;
609}
610
611/* Extract an upper bound on dimension "pos" from each constraint
612 * in "constraints" and return the list of upper bounds.
613 * If "constraints" has zero elements, then we extract an upper bound
614 * from "domain" instead.
615 */
616static __isl_give isl_pw_aff_list *upper_bounds(
617 __isl_keep isl_constraint_list *constraints, int pos,
619{
620 isl_ctx *ctx;
621 isl_pw_aff_list *list;
622 int i;
623 isl_size n;
624
625 n = isl_constraint_list_n_constraint(constraints);
626 if (n < 0)
627 return NULL;
628 if (n == 0) {
629 isl_pw_aff *pa;
630 pa = exact_bound(domain, build, 1);
631 return isl_pw_aff_list_from_pw_aff(pa);
632 }
633
635 list = isl_pw_aff_list_alloc(ctx,n);
636
637 for (i = 0; i < n; ++i) {
638 isl_aff *aff;
640
641 c = isl_constraint_list_get_constraint(constraints, i);
645 list = isl_pw_aff_list_add(list, isl_pw_aff_from_aff(aff));
646 }
647
648 return list;
649}
650
651/* Return an isl_ast_expr that performs the reduction of type "type"
652 * on AST expressions corresponding to the elements in "list".
653 *
654 * The list is assumed to contain at least one element.
655 * If the list contains exactly one element, then the returned isl_ast_expr
656 * simply computes that affine expression.
657 * If the list contains more than one element, then we sort it
658 * using a fairly arbitrary but hopefully reasonably stable order.
659 */
661 __isl_keep isl_pw_aff_list *list, __isl_keep isl_ast_build *build)
662{
663 int i;
664 isl_size n;
665 isl_ctx *ctx;
666 isl_ast_expr *expr;
667
668 n = isl_pw_aff_list_n_pw_aff(list);
669 if (n < 0)
670 return NULL;
671
672 if (n == 1)
674 isl_pw_aff_list_get_pw_aff(list, 0));
675
676 ctx = isl_pw_aff_list_get_ctx(list);
677 expr = isl_ast_expr_alloc_op(ctx, type, n);
678
679 list = isl_pw_aff_list_copy(list);
680 list = isl_pw_aff_list_sort(list, &reduce_list_cmp, NULL);
681 if (!list)
682 return isl_ast_expr_free(expr);
683
684 for (i = 0; i < n; ++i) {
685 isl_ast_expr *expr_i;
686
688 isl_pw_aff_list_get_pw_aff(list, i));
689 expr = isl_ast_expr_op_add_arg(expr, expr_i);
690 }
691
692 isl_pw_aff_list_free(list);
693 return expr;
694}
695
696/* Add guards implied by the "generated constraints",
697 * but not (necessarily) enforced by the generated AST to "guard".
698 * In particular, if there is any stride constraints,
699 * then add the guard implied by those constraints.
700 * If we have generated a degenerate loop, then add the guard
701 * implied by "bounds" on the outer dimensions, i.e., the guard
702 * that ensures that the single value actually exists.
703 * Since there may also be guards implied by a combination
704 * of these constraints, we first combine them before
705 * deriving the implied constraints.
706 */
708 int degenerate, __isl_keep isl_basic_set *bounds,
710{
711 isl_size depth;
712 isl_bool has_stride;
713 isl_space *space;
714 isl_set *dom, *set;
715
717 has_stride = isl_ast_build_has_stride(build, depth);
718 if (depth < 0 || has_stride < 0)
719 return isl_set_free(guard);
720 if (!has_stride && !degenerate)
721 return guard;
722
723 space = isl_basic_set_get_space(bounds);
724 dom = isl_set_universe(space);
725
726 if (degenerate) {
727 bounds = isl_basic_set_copy(bounds);
729 bounds, isl_dim_set, depth, 1);
730 set = isl_set_from_basic_set(bounds);
731 dom = isl_set_intersect(dom, set);
732 }
733
734 if (has_stride) {
736 dom = isl_set_intersect(dom, set);
737 }
738
739 dom = isl_set_eliminate(dom, isl_dim_set, depth, 1);
741 guard = isl_set_intersect(guard, dom);
742
743 return guard;
744}
745
746/* Update "graft" based on "sub_build" for the degenerate case.
747 *
748 * "build" is the build in which graft->node was created
749 * "sub_build" contains information about the current level itself,
750 * including the single value attained.
751 *
752 * We set the initialization part of the for loop to the single
753 * value attained by the current dimension.
754 * The increment and condition are not strictly needed as they are known
755 * to be "1" and "iterator <= value" respectively.
756 */
759 __isl_keep isl_ast_build *sub_build)
760{
761 isl_pw_aff *value;
763
764 if (!graft || !sub_build)
765 return isl_ast_graft_free(graft);
766
767 value = isl_pw_aff_copy(sub_build->value);
768
770 graft->node = isl_ast_node_for_set_init(graft->node, init);
771 if (!graft->node)
772 return isl_ast_graft_free(graft);
773
774 return graft;
775}
776
777/* Return the intersection of constraints in "list" as a set.
778 */
780 __isl_keep isl_constraint_list *list)
781{
782 int i;
783 isl_size n;
784 isl_basic_set *bset;
785
786 n = isl_constraint_list_n_constraint(list);
787 if (n < 0)
788 return NULL;
789 if (n < 1)
790 isl_die(isl_constraint_list_get_ctx(list), isl_error_internal,
791 "expecting at least one constraint", return NULL);
792
794 isl_constraint_list_get_constraint(list, 0));
795 for (i = 1; i < n; ++i) {
796 isl_basic_set *bset_i;
797
799 isl_constraint_list_get_constraint(list, i));
800 bset = isl_basic_set_intersect(bset, bset_i);
801 }
802
803 return isl_set_from_basic_set(bset);
804}
805
806/* Compute the constraints on the outer dimensions enforced by
807 * graft->node and add those constraints to graft->enforced,
808 * in case the upper bound is expressed as a set "upper".
809 *
810 * In particular, if l(...) is a lower bound in "lower", and
811 *
812 * -a i + f(...) >= 0 or a i <= f(...)
813 *
814 * is an upper bound ocnstraint on the current dimension i,
815 * then the for loop enforces the constraint
816 *
817 * -a l(...) + f(...) >= 0 or a l(...) <= f(...)
818 *
819 * We therefore simply take each lower bound in turn, plug it into
820 * the upper bounds and compute the intersection over all lower bounds.
821 *
822 * If a lower bound is a rational expression, then
823 * isl_basic_set_preimage_multi_aff will force this rational
824 * expression to have only integer values. However, the loop
825 * itself does not enforce this integrality constraint. We therefore
826 * use the ceil of the lower bounds instead of the lower bounds themselves.
827 * Other constraints will make sure that the for loop is only executed
828 * when each of the lower bounds attains an integral value.
829 * In particular, potentially rational values only occur in
830 * lower_bound if the offset is a (seemingly) rational expression,
831 * but then outer conditions will make sure that this rational expression
832 * only attains integer values.
833 */
836 __isl_keep isl_pw_aff_list *lower, int pos, __isl_keep isl_set *upper)
837{
838 isl_space *space;
839 isl_basic_set *enforced;
841 int i;
842 isl_size n;
843
844 n = isl_pw_aff_list_n_pw_aff(lower);
845 if (!graft || n < 0)
846 return isl_ast_graft_free(graft);
847
848 space = isl_set_get_space(upper);
849 enforced = isl_basic_set_universe(isl_space_copy(space));
850
851 space = isl_space_map_from_set(space);
853
854 for (i = 0; i < n; ++i) {
855 isl_pw_aff *pa;
856 isl_set *enforced_i;
858 isl_pw_multi_aff *pma_i;
859
860 pa = isl_pw_aff_list_get_pw_aff(lower, i);
862 pma_i = isl_pw_multi_aff_copy(pma);
863 pma_i = isl_pw_multi_aff_set_pw_aff(pma_i, pos, pa);
864 enforced_i = isl_set_copy(upper);
865 enforced_i = isl_set_preimage_pw_multi_aff(enforced_i, pma_i);
866 hull = isl_set_simple_hull(enforced_i);
867 enforced = isl_basic_set_intersect(enforced, hull);
868 }
869
871
872 graft = isl_ast_graft_enforce(graft, enforced);
873
874 return graft;
875}
876
877/* Compute the constraints on the outer dimensions enforced by
878 * graft->node and add those constraints to graft->enforced,
879 * in case the upper bound is expressed as
880 * a list of affine expressions "upper".
881 *
882 * The enforced condition is that each lower bound expression is less
883 * than or equal to each upper bound expression.
884 */
887 __isl_keep isl_pw_aff_list *lower, __isl_keep isl_pw_aff_list *upper)
888{
889 isl_set *cond;
890 isl_basic_set *enforced;
891
892 lower = isl_pw_aff_list_copy(lower);
893 upper = isl_pw_aff_list_copy(upper);
894 cond = isl_pw_aff_list_le_set(lower, upper);
895 enforced = isl_set_simple_hull(cond);
896 graft = isl_ast_graft_enforce(graft, enforced);
897
898 return graft;
899}
900
901/* Does "aff" have a negative constant term?
902 */
904 __isl_keep isl_aff *aff, void *user)
905{
906 isl_bool is_neg;
907 isl_val *v;
908
910 is_neg = isl_val_is_neg(v);
911 isl_val_free(v);
912
913 return is_neg;
914}
915
916/* Does "pa" have a negative constant term over its entire domain?
917 */
923
924/* Does each element in "list" have a negative constant term?
925 */
926static int list_constant_is_negative(__isl_keep isl_pw_aff_list *list)
927{
928 return isl_pw_aff_list_every(list, &pw_aff_constant_is_negative, NULL);
929}
930
931/* Add 1 to each of the elements in "list", where each of these elements
932 * is defined over the internal schedule space of "build".
933 */
934static __isl_give isl_pw_aff_list *list_add_one(
935 __isl_take isl_pw_aff_list *list, __isl_keep isl_ast_build *build)
936{
937 int i;
938 isl_size n;
939 isl_space *space;
940 isl_aff *aff;
941 isl_pw_aff *one;
942
943 n = isl_pw_aff_list_n_pw_aff(list);
944 if (n < 0)
945 return isl_pw_aff_list_free(list);
946
947 space = isl_ast_build_get_space(build, 1);
951
952 for (i = 0; i < n; ++i) {
953 isl_pw_aff *pa;
954 pa = isl_pw_aff_list_get_pw_aff(list, i);
956 list = isl_pw_aff_list_set_pw_aff(list, i, pa);
957 }
958
959 isl_pw_aff_free(one);
960
961 return list;
962}
963
964/* Set the condition part of the for node graft->node in case
965 * the upper bound is represented as a list of piecewise affine expressions.
966 *
967 * In particular, set the condition to
968 *
969 * iterator <= min(list of upper bounds)
970 *
971 * If each of the upper bounds has a negative constant term, then
972 * set the condition to
973 *
974 * iterator < min(list of (upper bound + 1)s)
975 *
976 */
978 __isl_take isl_ast_graft *graft, __isl_keep isl_pw_aff_list *list,
980{
981 int neg;
982 isl_ast_expr *bound, *iterator, *cond;
984
985 if (!graft || !list)
986 return isl_ast_graft_free(graft);
987
989 if (neg < 0)
990 return isl_ast_graft_free(graft);
991 list = isl_pw_aff_list_copy(list);
992 if (neg) {
995 }
996
998 iterator = isl_ast_expr_copy(graft->node->u.f.iterator);
999 cond = isl_ast_expr_alloc_binary(type, iterator, bound);
1000 graft->node = isl_ast_node_for_set_cond(graft->node, cond);
1001
1002 isl_pw_aff_list_free(list);
1003 if (!graft->node)
1004 return isl_ast_graft_free(graft);
1005 return graft;
1006}
1007
1008/* Set the condition part of the for node graft->node in case
1009 * the upper bound is represented as a set.
1010 */
1014{
1015 isl_ast_expr *cond;
1016
1017 if (!graft)
1018 return NULL;
1019
1021 graft->node = isl_ast_node_for_set_cond(graft->node, cond);
1022 if (!graft->node)
1023 return isl_ast_graft_free(graft);
1024 return graft;
1025}
1026
1027/* Construct an isl_ast_expr for the increment (i.e., stride) of
1028 * the current dimension.
1029 */
1031{
1032 isl_size depth;
1033 isl_val *v;
1034 isl_ctx *ctx;
1035
1037 if (depth < 0)
1038 return NULL;
1040
1041 if (!isl_ast_build_has_stride(build, depth))
1042 return isl_ast_expr_alloc_int_si(ctx, 1);
1043
1044 v = isl_ast_build_get_stride(build, depth);
1045 return isl_ast_expr_from_val(v);
1046}
1047
1048/* Should we express the loop condition as
1049 *
1050 * iterator <= min(list of upper bounds)
1051 *
1052 * or as a conjunction of constraints?
1053 *
1054 * The first is constructed from a list of upper bounds.
1055 * The second is constructed from a set.
1056 *
1057 * If there are no upper bounds in "constraints", then this could mean
1058 * that "domain" simply doesn't have an upper bound or that we didn't
1059 * pick any upper bound. In the first case, we want to generate the
1060 * loop condition as a(n empty) conjunction of constraints
1061 * In the second case, we will compute
1062 * a single upper bound from "domain" and so we use the list form.
1063 *
1064 * If there are upper bounds in "constraints",
1065 * then we use the list form iff the atomic_upper_bound option is set.
1066 */
1067static int use_upper_bound_list(isl_ctx *ctx, int n_upper,
1068 __isl_keep isl_set *domain, int depth)
1069{
1070 if (n_upper > 0)
1072 else
1074}
1075
1076/* Fill in the expressions of the for node in graft->node.
1077 *
1078 * In particular,
1079 * - set the initialization part of the loop to the maximum of the lower bounds
1080 * - extract the increment from the stride of the current dimension
1081 * - construct the for condition either based on a list of upper bounds
1082 * or on a set of upper bound constraints.
1083 */
1085 __isl_take isl_ast_graft *graft, __isl_keep isl_pw_aff_list *lower,
1086 int use_list, __isl_keep isl_pw_aff_list *upper_list,
1088{
1090
1091 if (!graft)
1092 return NULL;
1093
1095 graft->node = isl_ast_node_for_set_init(graft->node, init);
1096 graft->node = isl_ast_node_for_set_inc(graft->node, for_inc(build));
1097
1098 if (!graft->node)
1099 graft = isl_ast_graft_free(graft);
1100
1101 if (use_list)
1102 graft = set_for_cond_from_list(graft, upper_list, build);
1103 else
1104 graft = set_for_cond_from_set(graft, upper_set, build);
1105
1106 return graft;
1107}
1108
1109/* Update "graft" based on "bounds" and "domain" for the generic,
1110 * non-degenerate, case.
1111 *
1112 * "c_lower" and "c_upper" contain the lower and upper bounds
1113 * that the loop node should express.
1114 * "domain" is the subset of the intersection of the constraints
1115 * for which some code is executed.
1116 *
1117 * There may be zero lower bounds or zero upper bounds in "constraints"
1118 * in case the list of constraints was created
1119 * based on the atomic option or based on separation with explicit bounds.
1120 * In that case, we use "domain" to derive lower and/or upper bounds.
1121 *
1122 * We first compute a list of one or more lower bounds.
1123 *
1124 * Then we decide if we want to express the condition as
1125 *
1126 * iterator <= min(list of upper bounds)
1127 *
1128 * or as a conjunction of constraints.
1129 *
1130 * The set of enforced constraints is then computed either based on
1131 * a list of upper bounds or on a set of upper bound constraints.
1132 * We do not compute any enforced constraints if we were forced
1133 * to compute a lower or upper bound using exact_bound. The domains
1134 * of the resulting expressions may imply some bounds on outer dimensions
1135 * that we do not want to appear in the enforced constraints since
1136 * they are not actually enforced by the corresponding code.
1137 *
1138 * Finally, we fill in the expressions of the for node.
1139 */
1142 __isl_take isl_constraint_list *c_lower,
1143 __isl_take isl_constraint_list *c_upper,
1145{
1146 isl_size depth;
1147 isl_ctx *ctx;
1148 isl_pw_aff_list *lower;
1149 int use_list;
1150 isl_set *upper_set = NULL;
1151 isl_pw_aff_list *upper_list = NULL;
1152 isl_size n_lower, n_upper;
1153
1155 if (!graft || !c_lower || !c_upper || depth < 0)
1156 goto error;
1157
1158 ctx = isl_ast_graft_get_ctx(graft);
1159
1160 n_lower = isl_constraint_list_n_constraint(c_lower);
1161 n_upper = isl_constraint_list_n_constraint(c_upper);
1162 if (n_lower < 0 || n_upper < 0)
1163 goto error;
1164
1165 use_list = use_upper_bound_list(ctx, n_upper, domain, depth);
1166
1167 lower = lower_bounds(c_lower, depth, domain, build);
1168
1169 if (use_list)
1170 upper_list = upper_bounds(c_upper, depth, domain, build);
1171 else if (n_upper > 0)
1172 upper_set = intersect_constraints(c_upper);
1173 else
1175
1176 if (n_lower == 0 || n_upper == 0)
1177 ;
1178 else if (use_list)
1179 graft = set_enforced_from_list(graft, lower, upper_list);
1180 else
1181 graft = set_enforced_from_set(graft, lower, depth, upper_set);
1182
1183 graft = set_for_node_expressions(graft, lower, use_list, upper_list,
1184 upper_set, build);
1185
1186 isl_pw_aff_list_free(lower);
1187 isl_pw_aff_list_free(upper_list);
1188 isl_set_free(upper_set);
1189 isl_constraint_list_free(c_lower);
1190 isl_constraint_list_free(c_upper);
1191
1192 return graft;
1193error:
1194 isl_constraint_list_free(c_lower);
1195 isl_constraint_list_free(c_upper);
1196 return isl_ast_graft_free(graft);
1197}
1198
1199/* Internal data structure used inside count_constraints to keep
1200 * track of the number of constraints that are independent of dimension "pos",
1201 * the lower bounds in "pos" and the upper bounds in "pos".
1202 */
1210
1211/* Increment data->n_indep, data->lower or data->upper depending
1212 * on whether "c" is independent of dimensions data->pos,
1213 * a lower bound or an upper bound.
1214 */
1216{
1217 struct isl_ast_count_constraints_data *data = user;
1218
1220 data->n_lower++;
1221 else if (isl_constraint_is_upper_bound(c, isl_dim_set, data->pos))
1222 data->n_upper++;
1223 else
1224 data->n_indep++;
1225
1227
1228 return isl_stat_ok;
1229}
1230
1231/* Update "graft" based on "bounds" and "domain" for the generic,
1232 * non-degenerate, case.
1233 *
1234 * "list" respresent the list of bounds that need to be encoded by
1235 * the for loop. Only the constraints that involve the iterator
1236 * are relevant here. The other constraints are taken care of by
1237 * the caller and are included in the generated constraints of "build".
1238 * "domain" is the subset of the intersection of the constraints
1239 * for which some code is executed.
1240 * "build" is the build in which graft->node was created.
1241 *
1242 * We separate lower bounds, upper bounds and constraints that
1243 * are independent of the loop iterator.
1244 *
1245 * The actual for loop bounds are generated in refine_generic_bounds.
1246 */
1248 __isl_take isl_ast_graft *graft, __isl_take isl_constraint_list *list,
1250{
1252 isl_size depth;
1253 isl_constraint_list *lower;
1254 isl_constraint_list *upper;
1255
1256 depth = isl_ast_build_get_depth(build);
1257 if (depth < 0)
1258 list = isl_constraint_list_free(list);
1259 if (!list)
1260 return isl_ast_graft_free(graft);
1261
1262 data.pos = depth;
1263
1264 list = isl_constraint_list_sort(list, &cmp_constraint, &data.pos);
1265 if (!list)
1266 return isl_ast_graft_free(graft);
1267
1268 data.n_indep = data.n_lower = data.n_upper = 0;
1269 if (isl_constraint_list_foreach(list, &count_constraints, &data) < 0) {
1270 isl_constraint_list_free(list);
1271 return isl_ast_graft_free(graft);
1272 }
1273
1274 lower = isl_constraint_list_drop(list, 0, data.n_indep);
1275 upper = isl_constraint_list_copy(lower);
1276 lower = isl_constraint_list_drop(lower, data.n_lower, data.n_upper);
1277 upper = isl_constraint_list_drop(upper, 0, data.n_lower);
1278
1279 return refine_generic_bounds(graft, lower, upper, domain, build);
1280}
1281
1282/* Update "graft" based on "bounds" and "domain" for the generic,
1283 * non-degenerate, case.
1284 *
1285 * "bounds" respresent the bounds that need to be encoded by
1286 * the for loop (or a guard around the for loop).
1287 * "domain" is the subset of "bounds" for which some code is executed.
1288 * "build" is the build in which graft->node was created.
1289 *
1290 * We break up "bounds" into a list of constraints and continue with
1291 * refine_generic_split.
1292 */
1297{
1298 isl_constraint_list *list;
1299
1300 if (!build || !graft)
1301 return isl_ast_graft_free(graft);
1302
1303 list = isl_basic_set_get_constraint_list(bounds);
1304
1305 graft = refine_generic_split(graft, list, domain, build);
1306
1307 return graft;
1308}
1309
1310/* Create a for node for the current level.
1311 *
1312 * Mark the for node degenerate if "degenerate" is set.
1313 */
1315 int degenerate)
1316{
1317 isl_size depth;
1318 isl_id *id;
1319 isl_ast_node *node;
1320
1321 depth = isl_ast_build_get_depth(build);
1322 if (depth < 0)
1323 return NULL;
1324
1325 id = isl_ast_build_get_iterator_id(build, depth);
1326 node = isl_ast_node_alloc_for(id);
1327 if (degenerate)
1329
1330 return node;
1331}
1332
1333/* If the ast_build_exploit_nested_bounds option is set, then return
1334 * the constraints enforced by all elements in "list".
1335 * Otherwise, return the universe.
1336 */
1338 __isl_keep isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
1339{
1340 isl_ctx *ctx;
1341 isl_space *space;
1342
1343 if (!list)
1344 return NULL;
1345
1346 ctx = isl_ast_graft_list_get_ctx(list);
1349
1350 space = isl_ast_build_get_space(build, 1);
1351 return isl_basic_set_universe(space);
1352}
1353
1354/* Return the pending constraints of "build" that are not already taken
1355 * care of (by a combination of "enforced" and the generated constraints
1356 * of "build").
1357 */
1359 __isl_keep isl_basic_set *enforced)
1360{
1361 isl_set *guard, *context;
1362
1363 guard = isl_ast_build_get_pending(build);
1367 return isl_set_gist(guard, context);
1368}
1369
1370/* Create an AST node for the current dimension based on
1371 * the schedule domain "bounds" and return the node encapsulated
1372 * in an isl_ast_graft.
1373 *
1374 * "executed" is the current inverse schedule, taking into account
1375 * the bounds in "bounds"
1376 * "domain" is the domain of "executed", with inner dimensions projected out.
1377 * It may be a strict subset of "bounds" in case "bounds" was created
1378 * based on the atomic option or based on separation with explicit bounds.
1379 *
1380 * "domain" may satisfy additional equalities that result
1381 * from intersecting "executed" with "bounds" in add_node.
1382 * It may also satisfy some global constraints that were dropped out because
1383 * we performed separation with explicit bounds.
1384 * The very first step is then to copy these constraints to "bounds".
1385 *
1386 * Since we may be calling before_each_for and after_each_for
1387 * callbacks, we record the current inverse schedule in the build.
1388 *
1389 * We consider three builds,
1390 * "build" is the one in which the current level is created,
1391 * "body_build" is the build in which the next level is created,
1392 * "sub_build" is essentially the same as "body_build", except that
1393 * the depth has not been increased yet.
1394 *
1395 * "build" already contains information (in strides and offsets)
1396 * about the strides at the current level, but this information is not
1397 * reflected in the build->domain.
1398 * We first add this information and the "bounds" to the sub_build->domain.
1399 * isl_ast_build_set_loop_bounds adds the stride information and
1400 * checks whether the current dimension attains
1401 * only a single value and whether this single value can be represented using
1402 * a single affine expression.
1403 * In the first case, the current level is considered "degenerate".
1404 * In the second, sub-case, the current level is considered "eliminated".
1405 * Eliminated levels don't need to be reflected in the AST since we can
1406 * simply plug in the affine expression. For degenerate, but non-eliminated,
1407 * levels, we do introduce a for node, but mark is as degenerate so that
1408 * it can be printed as an assignment of the single value to the loop
1409 * "iterator".
1410 *
1411 * If the current level is eliminated, we explicitly plug in the value
1412 * for the current level found by isl_ast_build_set_loop_bounds in the
1413 * inverse schedule. This ensures that if we are working on a slice
1414 * of the domain based on information available in the inverse schedule
1415 * and the build domain, that then this information is also reflected
1416 * in the inverse schedule. This operation also eliminates the current
1417 * dimension from the inverse schedule making sure no inner dimensions depend
1418 * on the current dimension. Otherwise, we create a for node, marking
1419 * it degenerate if appropriate. The initial for node is still incomplete
1420 * and will be completed in either refine_degenerate or refine_generic.
1421 *
1422 * We then generate a sequence of grafts for the next level,
1423 * create a surrounding graft for the current level and insert
1424 * the for node we created (if the current level is not eliminated).
1425 * Before creating a graft for the current level, we first extract
1426 * hoistable constraints from the child guards and combine them
1427 * with the pending constraints in the build. These constraints
1428 * are used to simplify the child guards and then added to the guard
1429 * of the current graft to ensure that they will be generated.
1430 * If the hoisted guard is a disjunction, then we use it directly
1431 * to gist the guards on the children before intersect it with the
1432 * pending constraints. We do so because this disjunction is typically
1433 * identical to the guards on the children such that these guards
1434 * can be effectively removed completely. After the intersection,
1435 * the gist operation would have a harder time figuring this out.
1436 *
1437 * Finally, we set the bounds of the for loop in either
1438 * refine_degenerate or refine_generic.
1439 * We do so in a context where the pending constraints of the build
1440 * have been replaced by the guard of the current graft.
1441 */
1443 __isl_take isl_union_map *executed,
1446{
1447 isl_size depth;
1448 int degenerate;
1449 isl_bool eliminated;
1450 isl_size n;
1452 isl_basic_set *enforced;
1453 isl_set *guard, *hoisted;
1454 isl_ast_node *node = NULL;
1455 isl_ast_graft *graft;
1456 isl_ast_graft_list *children;
1457 isl_ast_build *sub_build;
1458 isl_ast_build *body_build;
1459
1463 bounds = isl_basic_set_intersect(bounds, hull);
1464 build = isl_ast_build_set_executed(build, isl_union_map_copy(executed));
1465
1466 depth = isl_ast_build_get_depth(build);
1467 if (depth < 0)
1468 build = isl_ast_build_free(build);
1469 sub_build = isl_ast_build_copy(build);
1470 bounds = isl_basic_set_remove_redundancies(bounds);
1471 bounds = isl_ast_build_specialize_basic_set(sub_build, bounds);
1472 sub_build = isl_ast_build_set_loop_bounds(sub_build,
1473 isl_basic_set_copy(bounds));
1474 degenerate = isl_ast_build_has_value(sub_build);
1475 eliminated = isl_ast_build_has_affine_value(sub_build, depth);
1476 if (degenerate < 0 || eliminated < 0)
1477 executed = isl_union_map_free(executed);
1478 if (!degenerate)
1479 bounds = isl_ast_build_compute_gist_basic_set(build, bounds);
1480 sub_build = isl_ast_build_set_pending_generated(sub_build,
1481 isl_basic_set_copy(bounds));
1482 if (eliminated)
1483 executed = plug_in_values(executed, sub_build);
1484 else
1485 node = create_for(build, degenerate);
1486
1487 body_build = isl_ast_build_copy(sub_build);
1488 body_build = isl_ast_build_increase_depth(body_build);
1489 if (!eliminated)
1490 node = before_each_for(node, body_build);
1491 children = generate_next_level(executed,
1492 isl_ast_build_copy(body_build));
1493
1494 enforced = extract_shared_enforced(children, build);
1495 guard = extract_pending(sub_build, enforced);
1496 hoisted = isl_ast_graft_list_extract_hoistable_guard(children, build);
1497 n = isl_set_n_basic_set(hoisted);
1498 if (n < 0)
1499 children = isl_ast_graft_list_free(children);
1500 if (n > 1)
1501 children = isl_ast_graft_list_gist_guards(children,
1502 isl_set_copy(hoisted));
1503 guard = isl_set_intersect(guard, hoisted);
1504 if (!eliminated)
1505 guard = add_implied_guards(guard, degenerate, bounds, build);
1506
1507 graft = isl_ast_graft_alloc_from_children(children,
1508 isl_set_copy(guard), enforced, build, sub_build);
1509
1510 if (!eliminated) {
1511 isl_ast_build *for_build;
1512
1513 graft = isl_ast_graft_insert_for(graft, node);
1514 for_build = isl_ast_build_copy(build);
1515 for_build = isl_ast_build_replace_pending_by_guard(for_build,
1516 isl_set_copy(guard));
1517 if (degenerate)
1518 graft = refine_degenerate(graft, for_build, sub_build);
1519 else
1520 graft = refine_generic(graft, bounds,
1521 domain, for_build);
1522 isl_ast_build_free(for_build);
1523 }
1524 isl_set_free(guard);
1525 if (!eliminated)
1526 graft = after_each_for(graft, body_build);
1527
1528 isl_ast_build_free(body_build);
1529 isl_ast_build_free(sub_build);
1530 isl_ast_build_free(build);
1531 isl_basic_set_free(bounds);
1533
1534 return graft;
1535}
1536
1537/* Internal data structure for checking if all constraints involving
1538 * the input dimension "depth" are such that the other coefficients
1539 * are multiples of "m", reducing "m" if they are not.
1540 * If "m" is reduced all the way down to "1", then the check has failed
1541 * and we break out of the iteration.
1542 */
1547
1548/* If constraint "c" involves the input dimension data->depth,
1549 * then make sure that all the other coefficients are multiples of data->m,
1550 * reducing data->m if needed.
1551 * Break out of the iteration if data->m has become equal to "1".
1552 */
1554 void *user)
1555{
1556 struct isl_check_scaled_data *data = user;
1557 int i, j;
1558 isl_size n;
1560 isl_dim_div };
1561
1562 if (!isl_constraint_involves_dims(c, isl_dim_in, data->depth, 1)) {
1564 return isl_stat_ok;
1565 }
1566
1567 for (i = 0; i < 4; ++i) {
1568 n = isl_constraint_dim(c, t[i]);
1569 if (n < 0)
1570 break;
1571 for (j = 0; j < n; ++j) {
1572 isl_val *d;
1573
1574 if (t[i] == isl_dim_in && j == data->depth)
1575 continue;
1576 if (!isl_constraint_involves_dims(c, t[i], j, 1))
1577 continue;
1579 data->m = isl_val_gcd(data->m, d);
1580 if (isl_val_is_one(data->m))
1581 break;
1582 }
1583 if (j < n)
1584 break;
1585 }
1586
1588
1589 return i < 4 ? isl_stat_error : isl_stat_ok;
1590}
1591
1592/* For each constraint of "bmap" that involves the input dimension data->depth,
1593 * make sure that all the other coefficients are multiples of data->m,
1594 * reducing data->m if needed.
1595 * Break out of the iteration if data->m has become equal to "1".
1596 */
1598 void *user)
1599{
1600 isl_stat r;
1601
1604 isl_basic_map_free(bmap);
1605
1606 return r;
1607}
1608
1609/* For each constraint of "map" that involves the input dimension data->depth,
1610 * make sure that all the other coefficients are multiples of data->m,
1611 * reducing data->m if needed.
1612 * Break out of the iteration if data->m has become equal to "1".
1613 */
1615{
1616 isl_stat r;
1617
1620
1621 return r;
1622}
1623
1624/* Create an AST node for the current dimension based on
1625 * the schedule domain "bounds" and return the node encapsulated
1626 * in an isl_ast_graft.
1627 *
1628 * "executed" is the current inverse schedule, taking into account
1629 * the bounds in "bounds"
1630 * "domain" is the domain of "executed", with inner dimensions projected out.
1631 *
1632 *
1633 * Before moving on to the actual AST node construction in create_node_scaled,
1634 * we first check if the current dimension is strided and if we can scale
1635 * down this stride. Note that we only do this if the ast_build_scale_strides
1636 * option is set.
1637 *
1638 * In particular, let the current dimension take on values
1639 *
1640 * f + s a
1641 *
1642 * with a an integer. We check if we can find an integer m that (obviously)
1643 * divides both f and s.
1644 *
1645 * If so, we check if the current dimension only appears in constraints
1646 * where the coefficients of the other variables are multiples of m.
1647 * We perform this extra check to avoid the risk of introducing
1648 * divisions by scaling down the current dimension.
1649 *
1650 * If so, we scale the current dimension down by a factor of m.
1651 * That is, we plug in
1652 *
1653 * i = m i' (1)
1654 *
1655 * Note that in principle we could always scale down strided loops
1656 * by plugging in
1657 *
1658 * i = f + s i'
1659 *
1660 * but this may result in i' taking on larger values than the original i,
1661 * due to the shift by "f".
1662 * By constrast, the scaling in (1) can only reduce the (absolute) value "i".
1663 */
1667{
1668 struct isl_check_scaled_data data;
1670 isl_ctx *ctx;
1671 isl_aff *offset;
1672 isl_val *d;
1673
1674 ctx = isl_ast_build_get_ctx(build);
1676 return create_node_scaled(executed, bounds, domain, build);
1677
1679 if (depth < 0)
1680 build = isl_ast_build_free(build);
1681 data.depth = depth;
1682 if (!isl_ast_build_has_stride(build, data.depth))
1683 return create_node_scaled(executed, bounds, domain, build);
1684
1685 offset = isl_ast_build_get_offset(build, data.depth);
1686 data.m = isl_ast_build_get_stride(build, data.depth);
1687 if (!data.m)
1691 if (!d)
1692 executed = isl_union_map_free(executed);
1693
1694 if (executed && isl_val_is_divisible_by(data.m, d))
1695 data.m = isl_val_div(data.m, d);
1696 else {
1697 data.m = isl_val_set_si(data.m, 1);
1698 isl_val_free(d);
1699 }
1700
1701 if (!isl_val_is_one(data.m)) {
1703 &data) < 0 &&
1704 !isl_val_is_one(data.m))
1705 executed = isl_union_map_free(executed);
1706 }
1707
1708 if (!isl_val_is_one(data.m)) {
1709 isl_space *space;
1711 isl_aff *aff;
1712 isl_map *map;
1713 isl_union_map *umap;
1714
1715 space = isl_ast_build_get_space(build, 1);
1716 space = isl_space_map_from_set(space);
1717 ma = isl_multi_aff_identity(space);
1718 aff = isl_multi_aff_get_aff(ma, data.depth);
1720 ma = isl_multi_aff_set_aff(ma, data.depth, aff);
1721
1722 bounds = isl_basic_set_preimage_multi_aff(bounds,
1723 isl_multi_aff_copy(ma));
1725 isl_multi_aff_copy(ma));
1728 executed = isl_union_map_apply_domain(executed,
1729 isl_union_map_copy(umap));
1730 build = isl_ast_build_scale_down(build, isl_val_copy(data.m),
1731 umap);
1732 }
1734 isl_val_free(data.m);
1735
1736 return create_node_scaled(executed, bounds, domain, build);
1737}
1738
1739/* Add the basic set to the list that "user" points to.
1740 */
1742{
1743 isl_basic_set_list **list = user;
1744
1745 *list = isl_basic_set_list_add(*list, bset);
1746
1747 return isl_stat_ok;
1748}
1749
1750/* Extract the basic sets of "set" and collect them in an isl_basic_set_list.
1751 */
1754{
1755 isl_size n;
1756 isl_ctx *ctx;
1757 isl_basic_set_list *list;
1758
1760 if (n < 0)
1761 set = isl_set_free(set);
1762 if (!set)
1763 return NULL;
1764
1765 ctx = isl_set_get_ctx(set);
1766
1767 list = isl_basic_set_list_alloc(ctx, n);
1769 list = isl_basic_set_list_free(list);
1770
1772 return list;
1773}
1774
1775/* Generate code for the schedule domain "bounds"
1776 * and add the result to "list".
1777 *
1778 * We mainly detect strides here and check if the bounds do not
1779 * conflict with the current build domain
1780 * and then pass over control to create_node.
1781 *
1782 * "bounds" reflects the bounds on the current dimension and possibly
1783 * some extra conditions on outer dimensions.
1784 * It does not, however, include any divs involving the current dimension,
1785 * so it does not capture any stride constraints.
1786 * We therefore need to compute that part of the schedule domain that
1787 * intersects with "bounds" and derive the strides from the result.
1788 */
1789static __isl_give isl_ast_graft_list *add_node(
1790 __isl_take isl_ast_graft_list *list, __isl_take isl_union_map *executed,
1792{
1793 isl_ast_graft *graft;
1794 isl_set *domain = NULL;
1795 isl_union_set *uset;
1796 int empty, disjoint;
1797
1799 executed = isl_union_map_intersect_domain(executed, uset);
1800 empty = isl_union_map_is_empty(executed);
1801 if (empty < 0)
1802 goto error;
1803 if (empty)
1804 goto done;
1805
1806 uset = isl_union_map_domain(isl_union_map_copy(executed));
1809
1812 disjoint = isl_set_is_disjoint(domain, build->domain);
1813 if (disjoint < 0)
1814 goto error;
1815 if (disjoint)
1816 goto done;
1817
1819
1820 graft = create_node(executed, bounds, domain,
1821 isl_ast_build_copy(build));
1822 list = isl_ast_graft_list_add(list, graft);
1823 isl_ast_build_free(build);
1824 return list;
1825error:
1826 list = isl_ast_graft_list_free(list);
1827done:
1829 isl_basic_set_free(bounds);
1830 isl_union_map_free(executed);
1831 isl_ast_build_free(build);
1832 return list;
1833}
1834
1835/* Does any element of i follow or coincide with any element of j
1836 * at the current depth for equal values of the outer dimensions?
1837 */
1839 __isl_keep isl_basic_set *j, void *user)
1840{
1841 int depth = *(int *) user;
1843 isl_bool empty;
1844 int l;
1845
1848 for (l = 0; l < depth; ++l)
1850 isl_dim_out, l);
1855
1856 return isl_bool_not(empty);
1857}
1858
1859/* Split up each element of "list" into a part that is related to "bset"
1860 * according to "gt" and a part that is not.
1861 * Return a list that consist of "bset" and all the pieces.
1862 */
1866{
1867 int i;
1868 isl_size n;
1870
1871 n = isl_basic_set_list_n_basic_set(list);
1872 if (n < 0)
1873 bset = isl_basic_set_free(bset);
1874
1875 gt = isl_basic_map_copy(gt);
1877 res = isl_basic_set_list_from_basic_set(bset);
1878 for (i = 0; res && i < n; ++i) {
1879 isl_basic_set *bset;
1880 isl_set *set1, *set2;
1881 isl_basic_map *bmap;
1882 int empty;
1883
1884 bset = isl_basic_set_list_get_basic_set(list, i);
1885 bmap = isl_basic_map_copy(gt);
1886 bmap = isl_basic_map_intersect_range(bmap, bset);
1887 bset = isl_basic_map_range(bmap);
1888 empty = isl_basic_set_is_empty(bset);
1889 if (empty < 0)
1890 res = isl_basic_set_list_free(res);
1891 if (empty) {
1892 isl_basic_set_free(bset);
1893 bset = isl_basic_set_list_get_basic_set(list, i);
1894 res = isl_basic_set_list_add(res, bset);
1895 continue;
1896 }
1897
1898 res = isl_basic_set_list_add(res, isl_basic_set_copy(bset));
1900 bset = isl_basic_set_list_get_basic_set(list, i);
1904
1905 res = isl_basic_set_list_concat(res,
1907 }
1909 isl_basic_set_list_free(list);
1910 return res;
1911}
1912
1913static __isl_give isl_ast_graft_list *generate_sorted_domains(
1914 __isl_keep isl_basic_set_list *domain_list,
1915 __isl_keep isl_union_map *executed,
1916 __isl_keep isl_ast_build *build);
1917
1918/* Internal data structure for add_nodes.
1919 *
1920 * "executed" and "build" are extra arguments to be passed to add_node.
1921 * "list" collects the results.
1922 */
1929
1930/* Generate code for the schedule domains in "scc"
1931 * and add the results to "list".
1932 *
1933 * The domains in "scc" form a strongly connected component in the ordering.
1934 * If the number of domains in "scc" is larger than 1, then this means
1935 * that we cannot determine a valid ordering for the domains in the component.
1936 * This should be fairly rare because the individual domains
1937 * have been made disjoint first.
1938 * The problem is that the domains may be integrally disjoint but not
1939 * rationally disjoint. For example, we may have domains
1940 *
1941 * { [i,i] : 0 <= i <= 1 } and { [i,1-i] : 0 <= i <= 1 }
1942 *
1943 * These two domains have an empty intersection, but their rational
1944 * relaxations do intersect. It is impossible to order these domains
1945 * in the second dimension because the first should be ordered before
1946 * the second for outer dimension equal to 0, while it should be ordered
1947 * after for outer dimension equal to 1.
1948 *
1949 * This may happen in particular in case of unrolling since the domain
1950 * of each slice is replaced by its simple hull.
1951 *
1952 * For each basic set i in "scc" and for each of the following basic sets j,
1953 * we split off that part of the basic set i that shares the outer dimensions
1954 * with j and lies before j in the current dimension.
1955 * We collect all the pieces in a new list that replaces "scc".
1956 *
1957 * While the elements in "scc" should be disjoint, we double-check
1958 * this property to avoid running into an infinite recursion in case
1959 * they intersect due to some internal error.
1960 */
1962{
1963 struct isl_add_nodes_data *data = user;
1964 int i;
1965 isl_size depth;
1966 isl_size n;
1967 isl_basic_set *bset, *first;
1969 isl_space *space;
1970 isl_basic_map *gt;
1971
1972 n = isl_basic_set_list_n_basic_set(scc);
1973 if (n < 0)
1974 goto error;
1975 bset = isl_basic_set_list_get_basic_set(scc, 0);
1976 if (n == 1) {
1977 isl_basic_set_list_free(scc);
1978 data->list = add_node(data->list,
1979 isl_union_map_copy(data->executed), bset,
1980 isl_ast_build_copy(data->build));
1981 return data->list ? isl_stat_ok : isl_stat_error;
1982 }
1983
1984 depth = isl_ast_build_get_depth(data->build);
1985 if (depth < 0)
1986 bset = isl_basic_set_free(bset);
1987 space = isl_basic_set_get_space(bset);
1988 space = isl_space_map_from_set(space);
1989 gt = isl_basic_map_universe(space);
1990 for (i = 0; i < depth; ++i)
1992 gt = isl_basic_map_order_gt(gt, isl_dim_in, depth, isl_dim_out, depth);
1993
1994 first = isl_basic_set_copy(bset);
1995 list = isl_basic_set_list_from_basic_set(bset);
1996 for (i = 1; i < n; ++i) {
1997 int disjoint;
1998
1999 bset = isl_basic_set_list_get_basic_set(scc, i);
2000
2001 disjoint = isl_basic_set_is_disjoint(bset, first);
2002 if (disjoint < 0)
2003 list = isl_basic_set_list_free(list);
2004 else if (!disjoint)
2005 isl_die(isl_basic_set_list_get_ctx(scc),
2007 "basic sets in scc are assumed to be disjoint",
2008 list = isl_basic_set_list_free(list));
2009
2010 list = add_split_on(list, bset, gt);
2011 }
2012 isl_basic_set_free(first);
2014 isl_basic_set_list_free(scc);
2015 scc = list;
2016 data->list = isl_ast_graft_list_concat(data->list,
2017 generate_sorted_domains(scc, data->executed, data->build));
2018 isl_basic_set_list_free(scc);
2019
2020 return data->list ? isl_stat_ok : isl_stat_error;
2021error:
2022 isl_basic_set_list_free(scc);
2023 return isl_stat_error;
2024}
2025
2026/* Sort the domains in "domain_list" according to the execution order
2027 * at the current depth (for equal values of the outer dimensions),
2028 * generate code for each of them, collecting the results in a list.
2029 * If no code is generated (because the intersection of the inverse schedule
2030 * with the domains turns out to be empty), then an empty list is returned.
2031 *
2032 * The caller is responsible for ensuring that the basic sets in "domain_list"
2033 * are pair-wise disjoint. It can, however, in principle happen that
2034 * two basic sets should be ordered one way for one value of the outer
2035 * dimensions and the other way for some other value of the outer dimensions.
2036 * We therefore play safe and look for strongly connected components.
2037 * The function add_nodes takes care of handling non-trivial components.
2038 */
2039static __isl_give isl_ast_graft_list *generate_sorted_domains(
2040 __isl_keep isl_basic_set_list *domain_list,
2042{
2043 isl_ctx *ctx;
2044 struct isl_add_nodes_data data;
2045 isl_size depth;
2046 isl_size n;
2047
2048 n = isl_basic_set_list_n_basic_set(domain_list);
2049 if (n < 0)
2050 return NULL;
2051
2052 ctx = isl_basic_set_list_get_ctx(domain_list);
2053 data.list = isl_ast_graft_list_alloc(ctx, n);
2054 if (n == 0)
2055 return data.list;
2056 if (n == 1)
2058 isl_basic_set_list_get_basic_set(domain_list, 0),
2060
2062 data.executed = executed;
2063 data.build = build;
2064 if (depth < 0 || isl_basic_set_list_foreach_scc(domain_list,
2065 &domain_follows_at_depth, &depth,
2066 &add_nodes, &data) < 0)
2067 data.list = isl_ast_graft_list_free(data.list);
2068
2069 return data.list;
2070}
2071
2072/* Do i and j share any values for the outer dimensions?
2073 */
2075 __isl_keep isl_basic_set *j, void *user)
2076{
2077 int depth = *(int *) user;
2079 isl_bool empty;
2080 int l;
2081
2084 for (l = 0; l < depth; ++l)
2086 isl_dim_out, l);
2089
2090 return isl_bool_not(empty);
2091}
2092
2093/* Internal data structure for generate_sorted_domains_wrap.
2094 *
2095 * "n" is the total number of basic sets
2096 * "executed" and "build" are extra arguments to be passed
2097 * to generate_sorted_domains.
2098 *
2099 * "single" is set to 1 by generate_sorted_domains_wrap if there
2100 * is only a single component.
2101 * "list" collects the results.
2102 */
2111
2112/* Call generate_sorted_domains on "scc", fuse the result into a list
2113 * with either zero or one graft and collect the these single element
2114 * lists into data->list.
2115 *
2116 * If there is only one component, i.e., if the number of basic sets
2117 * in the current component is equal to the total number of basic sets,
2118 * then data->single is set to 1 and the result of generate_sorted_domains
2119 * is not fused.
2120 */
2122 void *user)
2123{
2125 isl_ast_graft_list *list;
2126 isl_size n;
2127
2128 n = isl_basic_set_list_n_basic_set(scc);
2129 if (n < 0)
2130 scc = isl_basic_set_list_free(scc);
2131 list = generate_sorted_domains(scc, data->executed, data->build);
2132 data->single = n == data->n;
2133 if (!data->single)
2135 if (!data->list)
2136 data->list = list;
2137 else
2138 data->list = isl_ast_graft_list_concat(data->list, list);
2139
2140 isl_basic_set_list_free(scc);
2141 if (!data->list)
2142 return isl_stat_error;
2143
2144 return isl_stat_ok;
2145}
2146
2147/* Look for any (weakly connected) components in the "domain_list"
2148 * of domains that share some values of the outer dimensions.
2149 * That is, domains in different components do not share any values
2150 * of the outer dimensions. This means that these components
2151 * can be freely reordered.
2152 * Within each of the components, we sort the domains according
2153 * to the execution order at the current depth.
2154 *
2155 * If there is more than one component, then generate_sorted_domains_wrap
2156 * fuses the result of each call to generate_sorted_domains
2157 * into a list with either zero or one graft and collects these (at most)
2158 * single element lists into a bigger list. This means that the elements of the
2159 * final list can be freely reordered. In particular, we sort them
2160 * according to an arbitrary but fixed ordering to ease merging of
2161 * graft lists from different components.
2162 */
2163static __isl_give isl_ast_graft_list *generate_parallel_domains(
2164 __isl_keep isl_basic_set_list *domain_list,
2166{
2167 isl_size depth;
2169
2170 data.n = isl_basic_set_list_n_basic_set(domain_list);
2171 if (data.n < 0)
2172 return NULL;
2173
2174 if (data.n <= 1)
2175 return generate_sorted_domains(domain_list, executed, build);
2176
2178 if (depth < 0)
2179 return NULL;
2180 data.list = NULL;
2181 data.executed = executed;
2182 data.build = build;
2183 data.single = 0;
2184 if (isl_basic_set_list_foreach_scc(domain_list, &shared_outer, &depth,
2186 &data) < 0)
2187 data.list = isl_ast_graft_list_free(data.list);
2188
2189 if (!data.single)
2191
2192 return data.list;
2193}
2194
2195/* Internal data for separate_domain.
2196 *
2197 * "explicit" is set if we only want to use explicit bounds.
2198 *
2199 * "domain" collects the separated domains.
2200 */
2206
2207/* Extract implicit bounds on the current dimension for the executed "map".
2208 *
2209 * The domain of "map" may involve inner dimensions, so we
2210 * need to eliminate them.
2211 */
2214{
2215 isl_set *domain;
2216
2219
2220 return domain;
2221}
2222
2223/* Extract explicit bounds on the current dimension for the executed "map".
2224 *
2225 * Rather than eliminating the inner dimensions as in implicit_bounds,
2226 * we simply drop any constraints involving those inner dimensions.
2227 * The idea is that most bounds that are implied by constraints on the
2228 * inner dimensions will be enforced by for loops and not by explicit guards.
2229 * There is then no need to separate along those bounds.
2230 */
2233{
2234 isl_set *domain;
2235 isl_size depth;
2236 isl_size dim;
2237
2238 depth = isl_ast_build_get_depth(build);
2239 dim = isl_map_dim(map, isl_dim_out);
2240 if (depth < 0 || dim < 0)
2243
2248 isl_dim_set, depth + 1, dim - (depth + 1));
2250 isl_dim_set, depth, 1);
2252
2253 return domain;
2254}
2255
2256/* Split data->domain into pieces that intersect with the range of "map"
2257 * and pieces that do not intersect with the range of "map"
2258 * and then add that part of the range of "map" that does not intersect
2259 * with data->domain.
2260 */
2262{
2263 struct isl_separate_domain_data *data = user;
2264 isl_set *domain;
2265 isl_set *d1, *d2;
2266
2267 if (data->explicit)
2268 domain = explicit_bounds(map, data->build);
2269 else
2270 domain = implicit_bounds(map, data->build);
2271
2276 data->domain = isl_set_intersect(data->domain, domain);
2277 data->domain = isl_set_union(data->domain, d1);
2278 data->domain = isl_set_union(data->domain, d2);
2279
2280 return isl_stat_ok;
2281}
2282
2283/* Separate the schedule domains of "executed".
2284 *
2285 * That is, break up the domain of "executed" into basic sets,
2286 * such that for each basic set S, every element in S is associated with
2287 * the same domain spaces.
2288 *
2289 * "space" is the (single) domain space of "executed".
2290 */
2292 __isl_take isl_space *space, __isl_take isl_union_map *executed,
2294{
2295 struct isl_separate_domain_data data = { build };
2296 isl_ctx *ctx;
2297
2301 data.domain = isl_set_empty(space);
2302 if (isl_union_map_foreach_map(executed, &separate_domain, &data) < 0)
2303 data.domain = isl_set_free(data.domain);
2304
2305 isl_union_map_free(executed);
2306 return data.domain;
2307}
2308
2309/* Temporary data used during the search for a lower bound for unrolling.
2310 *
2311 * "build" is the build in which the unrolling will be performed
2312 * "domain" is the original set for which to find a lower bound
2313 * "depth" is the dimension for which to find a lower boudn
2314 * "expansion" is the expansion that needs to be applied to "domain"
2315 * in the unrolling that will be performed
2316 *
2317 * "lower" is the best lower bound found so far. It is NULL if we have not
2318 * found any yet.
2319 * "n" is the corresponding size. If lower is NULL, then the value of n
2320 * is undefined.
2321 * "n_div" is the maximal number of integer divisions in the first
2322 * unrolled iteration (after expansion). It is set to -1 if it hasn't
2323 * been computed yet.
2324 */
2335
2336/* Return the constraint
2337 *
2338 * i_"depth" = aff + offset
2339 */
2348
2349/* Update *user to the number of integer divisions in the first element
2350 * of "ma", if it is larger than the current value.
2351 */
2354{
2355 isl_aff *aff;
2356 int *n = user;
2357 isl_size n_div;
2358
2359 aff = isl_multi_aff_get_aff(ma, 0);
2360 n_div = isl_aff_dim(aff, isl_dim_div);
2362 isl_multi_aff_free(ma);
2364
2365 if (n_div > *n)
2366 *n = n_div;
2367
2368 return n_div >= 0 ? isl_stat_ok : isl_stat_error;
2369}
2370
2371/* Get the number of integer divisions in the expression for the iterator
2372 * value at the first slice in the unrolling based on lower bound "lower",
2373 * taking into account the expansion that needs to be performed on this slice.
2374 */
2376 __isl_keep isl_aff *lower)
2377{
2378 isl_constraint *c;
2379 isl_set *set;
2380 isl_map *it_map, *expansion;
2382 int n;
2383
2384 c = at_offset(data->depth, lower, 0);
2385 set = isl_set_copy(data->domain);
2388 set = isl_set_apply(set, expansion);
2389 it_map = isl_ast_build_map_to_iterator(data->build, set);
2391 n = 0;
2393 n = -1;
2395
2396 return n;
2397}
2398
2399/* Is the lower bound "lower" with corresponding iteration count "n"
2400 * better than the one stored in "data"?
2401 * If there is no upper bound on the iteration count ("n" is infinity) or
2402 * if the count is too large, then we cannot use this lower bound.
2403 * Otherwise, if there was no previous lower bound or
2404 * if the iteration count of the new lower bound is smaller than
2405 * the iteration count of the previous lower bound, then we consider
2406 * the new lower bound to be better.
2407 * If the iteration count is the same, then compare the number
2408 * of integer divisions that would be needed to express
2409 * the iterator value at the first slice in the unrolling
2410 * according to the lower bound. If we end up computing this
2411 * number, then store the lowest value in data->n_div.
2412 */
2415{
2416 int cmp;
2417 int n_div;
2418
2419 if (!n)
2420 return -1;
2421 if (isl_val_is_infty(n))
2422 return 0;
2423 if (isl_val_cmp_si(n, INT_MAX) > 0)
2424 return 0;
2425 if (!data->lower)
2426 return 1;
2427 cmp = isl_val_cmp_si(n, *data->n);
2428 if (cmp < 0)
2429 return 1;
2430 if (cmp > 0)
2431 return 0;
2432 if (data->n_div < 0)
2433 data->n_div = get_expanded_n_div(data, data->lower);
2434 if (data->n_div < 0)
2435 return -1;
2436 if (data->n_div == 0)
2437 return 0;
2438 n_div = get_expanded_n_div(data, lower);
2439 if (n_div < 0)
2440 return -1;
2441 if (n_div >= data->n_div)
2442 return 0;
2443 data->n_div = n_div;
2444
2445 return 1;
2446}
2447
2448/* Check if we can use "c" as a lower bound and if it is better than
2449 * any previously found lower bound.
2450 *
2451 * If "c" does not involve the dimension at the current depth,
2452 * then we cannot use it.
2453 * Otherwise, let "c" be of the form
2454 *
2455 * i >= f(j)/a
2456 *
2457 * We compute the maximal value of
2458 *
2459 * -ceil(f(j)/a)) + i + 1
2460 *
2461 * over the domain. If there is such a value "n", then we know
2462 *
2463 * -ceil(f(j)/a)) + i + 1 <= n
2464 *
2465 * or
2466 *
2467 * i < ceil(f(j)/a)) + n
2468 *
2469 * meaning that we can use ceil(f(j)/a)) as a lower bound for unrolling.
2470 * We just need to check if we have found any lower bound before and
2471 * if the new lower bound is better (smaller n or fewer integer divisions)
2472 * than the previously found lower bounds.
2473 */
2476{
2477 isl_aff *aff, *lower;
2478 isl_val *max;
2479 int better;
2480
2482 return isl_stat_ok;
2483
2484 lower = isl_constraint_get_bound(c, isl_dim_set, data->depth);
2485 lower = isl_aff_ceil(lower);
2486 aff = isl_aff_copy(lower);
2487 aff = isl_aff_neg(aff);
2490 max = isl_set_max_val(data->domain, aff);
2492
2493 better = is_better_lower_bound(data, lower, max);
2494 if (better < 0 || !better) {
2495 isl_val_free(max);
2496 isl_aff_free(lower);
2497 return better < 0 ? isl_stat_error : isl_stat_ok;
2498 }
2499
2500 isl_aff_free(data->lower);
2501 data->lower = lower;
2502 *data->n = isl_val_get_num_si(max);
2503 isl_val_free(max);
2504
2505 return isl_stat_ok;
2506}
2507
2508/* Check if we can use "c" as a lower bound and if it is better than
2509 * any previously found lower bound.
2510 */
2512{
2513 struct isl_find_unroll_data *data;
2514 isl_stat r;
2515
2516 data = (struct isl_find_unroll_data *) user;
2517 r = update_unrolling_lower_bound(data, c);
2519
2520 return r;
2521}
2522
2523/* Look for a lower bound l(i) on the dimension at "depth"
2524 * and a size n such that "domain" is a subset of
2525 *
2526 * { [i] : l(i) <= i_d < l(i) + n }
2527 *
2528 * where d is "depth" and l(i) depends only on earlier dimensions.
2529 * Furthermore, try and find a lower bound such that n is as small as possible.
2530 * In particular, "n" needs to be finite.
2531 * "build" is the build in which the unrolling will be performed.
2532 * "expansion" is the expansion that needs to be applied to "domain"
2533 * in the unrolling that will be performed.
2534 *
2535 * Inner dimensions have been eliminated from "domain" by the caller.
2536 *
2537 * We first construct a collection of lower bounds on the input set
2538 * by computing its simple hull. We then iterate through them,
2539 * discarding those that we cannot use (either because they do not
2540 * involve the dimension at "depth" or because they have no corresponding
2541 * upper bound, meaning that "n" would be unbounded) and pick out the
2542 * best from the remaining ones.
2543 *
2544 * If we cannot find a suitable lower bound, then we consider that
2545 * to be an error.
2546 */
2550{
2551 struct isl_find_unroll_data data =
2552 { build, domain, depth, expansion, NULL, n, -1 };
2554
2556
2558 &constraint_find_unroll, &data) < 0)
2559 goto error;
2560
2562
2563 if (!data.lower)
2565 "cannot find lower bound for unrolling", return NULL);
2566
2567 return data.lower;
2568error:
2570 return isl_aff_free(data.lower);
2571}
2572
2573/* Call "fn" on each iteration of the current dimension of "domain".
2574 * If "init" is not NULL, then it is called with the number of
2575 * iterations before any call to "fn".
2576 * Return -1 on failure.
2577 *
2578 * Since we are going to be iterating over the individual values,
2579 * we first check if there are any strides on the current dimension.
2580 * If there is, we rewrite the current dimension i as
2581 *
2582 * i = stride i' + offset
2583 *
2584 * and then iterate over individual values of i' instead.
2585 *
2586 * We then look for a lower bound on i' and a size such that the domain
2587 * is a subset of
2588 *
2589 * { [j,i'] : l(j) <= i' < l(j) + n }
2590 *
2591 * and then take slices of the domain at values of i'
2592 * between l(j) and l(j) + n - 1.
2593 *
2594 * We compute the unshifted simple hull of each slice to ensure that
2595 * we have a single basic set per offset. The slicing constraint
2596 * may get simplified away before the unshifted simple hull is taken
2597 * and may therefore in some rare cases disappear from the result.
2598 * We therefore explicitly add the constraint back after computing
2599 * the unshifted simple hull to ensure that the basic sets
2600 * remain disjoint. The constraints that are dropped by taking the hull
2601 * will be taken into account at the next level, as in the case of the
2602 * atomic option.
2603 *
2604 * Finally, we map i' back to i and call "fn".
2605 */
2607 __isl_keep isl_ast_build *build, int (*init)(int n, void *user),
2608 int (*fn)(__isl_take isl_basic_set *bset, void *user), void *user)
2609{
2610 int i, n;
2611 isl_bool empty;
2614 isl_basic_map *bmap;
2615 isl_aff *lower = NULL;
2616 isl_ast_build *stride_build;
2617
2619 if (depth < 0)
2621
2624 stride_build = isl_ast_build_copy(build);
2625 stride_build = isl_ast_build_detect_strides(stride_build,
2628
2630 isl_multi_aff_copy(expansion));
2632 isl_ast_build_free(stride_build);
2633
2635
2636 empty = isl_set_is_empty(domain);
2637 if (empty < 0) {
2638 n = -1;
2639 } else if (empty) {
2640 n = 0;
2641 } else {
2643 if (!lower)
2644 n = -1;
2645 }
2646 if (n >= 0 && init && init(n, user) < 0)
2647 n = -1;
2648 for (i = 0; i < n; ++i) {
2649 isl_set *set;
2650 isl_basic_set *bset;
2651 isl_constraint *slice;
2652
2653 slice = at_offset(depth, lower, i);
2657 bset = isl_basic_set_add_constraint(bset, slice);
2658 bset = isl_basic_set_apply(bset, isl_basic_map_copy(bmap));
2659
2660 if (fn(bset, user) < 0)
2661 break;
2662 }
2663
2666 isl_basic_map_free(bmap);
2667
2668 return n < 0 || i < n ? -1 : 0;
2669}
2670
2671/* Data structure for storing the results and the intermediate objects
2672 * of compute_domains.
2673 *
2674 * "list" is the main result of the function and contains a list
2675 * of disjoint basic sets for which code should be generated.
2676 *
2677 * "executed" and "build" are inputs to compute_domains.
2678 * "schedule_domain" is the domain of "executed".
2679 *
2680 * "option" contains the domains at the current depth that should by
2681 * atomic, separated or unrolled. These domains are as specified by
2682 * the user, except that inner dimensions have been eliminated and
2683 * that they have been made pair-wise disjoint.
2684 *
2685 * "sep_class" contains the user-specified split into separation classes
2686 * specialized to the current depth.
2687 * "done" contains the union of the separation domains that have already
2688 * been handled.
2689 */
2702
2703/* Internal data structure for do_unroll.
2704 *
2705 * "domains" stores the results of compute_domains.
2706 * "class_domain" is the original class domain passed to do_unroll.
2707 * "unroll_domain" collects the unrolled iterations.
2708 */
2714
2715/* Given an iteration of an unrolled domain represented by "bset",
2716 * add it to data->domains->list.
2717 * Since we may have dropped some constraints, we intersect with
2718 * the class domain again to ensure that each element in the list
2719 * is disjoint from the other class domains.
2720 */
2722{
2723 struct isl_ast_unroll_data *data = user;
2724 isl_set *set;
2725 isl_basic_set_list *list;
2726
2729 isl_set_copy(set));
2733 data->domains->list = isl_basic_set_list_concat(data->domains->list,
2734 list);
2735
2736 return 0;
2737}
2738
2739/* Extend domains->list with a list of basic sets, one for each value
2740 * of the current dimension in "domain" and remove the corresponding
2741 * sets from the class domain. Return the updated class domain.
2742 * The divs that involve the current dimension have not been projected out
2743 * from this domain.
2744 *
2745 * We call foreach_iteration to iterate over the individual values and
2746 * in do_unroll_iteration we collect the individual basic sets in
2747 * domains->list and their union in data->unroll_domain, which is then
2748 * used to update the class domain.
2749 */
2752{
2753 struct isl_ast_unroll_data data;
2754
2755 if (!domain)
2756 return isl_set_free(class_domain);
2757 if (!class_domain)
2758 return isl_set_free(domain);
2759
2760 data.domains = domains;
2763
2765 &do_unroll_iteration, &data) < 0)
2767
2769
2770 return class_domain;
2771}
2772
2773/* Add domains to domains->list for each individual value of the current
2774 * dimension, for that part of the schedule domain that lies in the
2775 * intersection of the option domain and the class domain.
2776 * Remove the corresponding sets from the class domain and
2777 * return the updated class domain.
2778 *
2779 * We first break up the unroll option domain into individual pieces
2780 * and then handle each of them separately. The unroll option domain
2781 * has been made disjoint in compute_domains_init_options,
2782 *
2783 * Note that we actively want to combine different pieces of the
2784 * schedule domain that have the same value at the current dimension.
2785 * We therefore need to break up the unroll option domain before
2786 * intersecting with class and schedule domain, hoping that the
2787 * unroll option domain specified by the user is relatively simple.
2788 */
2791{
2793 isl_basic_set_list *unroll_list;
2794 int i;
2795 isl_size n;
2796 isl_bool empty;
2797
2799 if (empty < 0)
2800 return isl_set_free(class_domain);
2801 if (empty)
2802 return class_domain;
2803
2806
2807 n = isl_basic_set_list_n_basic_set(unroll_list);
2808 if (n < 0)
2810 for (i = 0; i < n; ++i) {
2811 isl_basic_set *bset;
2812
2813 bset = isl_basic_set_list_get_basic_set(unroll_list, i);
2819
2821 if (empty >= 0 && empty) {
2823 continue;
2824 }
2825
2827 }
2828
2829 isl_basic_set_list_free(unroll_list);
2830
2831 return class_domain;
2832}
2833
2834/* Try and construct a single basic set that includes the intersection of
2835 * the schedule domain, the atomic option domain and the class domain.
2836 * Add the resulting basic set(s) to domains->list and remove them
2837 * from class_domain. Return the updated class domain.
2838 *
2839 * We construct a single domain rather than trying to combine
2840 * the schedule domains of individual domains because we are working
2841 * within a single component so that non-overlapping schedule domains
2842 * should already have been separated.
2843 * We do however need to make sure that this single domains is a subset
2844 * of the class domain so that it would not intersect with any other
2845 * class domains. This means that we may end up splitting up the atomic
2846 * domain in case separation classes are being used.
2847 *
2848 * "domain" is the intersection of the schedule domain and the class domain,
2849 * with inner dimensions projected out.
2850 */
2884
2885/* Split up the schedule domain into uniform basic sets,
2886 * in the sense that each element in a basic set is associated to
2887 * elements of the same domains, and add the result to domains->list.
2888 * Do this for that part of the schedule domain that lies in the
2889 * intersection of "class_domain" and the separate option domain.
2890 *
2891 * "class_domain" may or may not include the constraints
2892 * of the schedule domain, but this does not make a difference
2893 * since we are going to intersect it with the domain of the inverse schedule.
2894 * If it includes schedule domain constraints, then they may involve
2895 * inner dimensions, but we will eliminate them in separation_domain.
2896 */
2899{
2900 isl_space *space;
2901 isl_set *domain;
2902 isl_union_map *executed;
2903 isl_basic_set_list *list;
2904 int empty;
2905
2908 executed = isl_union_map_copy(domains->executed);
2909 executed = isl_union_map_intersect_domain(executed,
2911 empty = isl_union_map_is_empty(executed);
2912 if (empty < 0 || empty) {
2913 isl_union_map_free(executed);
2914 return empty < 0 ? -1 : 0;
2915 }
2916
2918 domain = separate_schedule_domains(space, executed, domains->build);
2919
2921 domains->list = isl_basic_set_list_concat(domains->list, list);
2922
2923 return 0;
2924}
2925
2926/* Split up the domain at the current depth into disjoint
2927 * basic sets for which code should be generated separately
2928 * for the given separation class domain.
2929 *
2930 * If any separation classes have been defined, then "class_domain"
2931 * is the domain of the current class and does not refer to inner dimensions.
2932 * Otherwise, "class_domain" is the universe domain.
2933 *
2934 * We first make sure that the class domain is disjoint from
2935 * previously considered class domains.
2936 *
2937 * The separate domains can be computed directly from the "class_domain".
2938 *
2939 * The unroll, atomic and remainder domains need the constraints
2940 * from the schedule domain.
2941 *
2942 * For unrolling, the actual schedule domain is needed (with divs that
2943 * may refer to the current dimension) so that stride detection can be
2944 * performed.
2945 *
2946 * For atomic and remainder domains, inner dimensions and divs involving
2947 * the current dimensions should be eliminated.
2948 * In case we are working within a separation class, we need to intersect
2949 * the result with the current "class_domain" to ensure that the domains
2950 * are disjoint from those generated from other class domains.
2951 *
2952 * The domain that has been made atomic may be larger than specified
2953 * by the user since it needs to be representable as a single basic set.
2954 * This possibly larger domain is removed from class_domain by
2955 * compute_atomic_domain. It is computed first so that the extended domain
2956 * would not overlap with any domains computed before.
2957 * Similary, the unrolled domains may have some constraints removed and
2958 * may therefore also be larger than specified by the user.
2959 *
2960 * If anything is left after handling separate, unroll and atomic,
2961 * we split it up into basic sets and append the basic sets to domains->list.
2962 */
3004
3005/* Split up the domain at the current depth into disjoint
3006 * basic sets for which code should be generated separately
3007 * for the separation class identified by "pnt".
3008 *
3009 * We extract the corresponding class domain from domains->sep_class,
3010 * eliminate inner dimensions and pass control to compute_partial_domains.
3011 */
3013{
3014 struct isl_codegen_domains *domains = user;
3015 isl_set *class_set;
3016 isl_set *domain;
3017 int disjoint;
3018
3019 class_set = isl_set_from_point(pnt);
3021 isl_map_copy(domains->sep_class), class_set));
3024
3025 disjoint = isl_set_plain_is_disjoint(domain, domains->schedule_domain);
3026 if (disjoint < 0)
3027 return isl_stat_error;
3028 if (disjoint) {
3030 return isl_stat_ok;
3031 }
3032
3033 return compute_partial_domains(domains, domain);
3034}
3035
3036/* Extract the domains at the current depth that should be atomic,
3037 * separated or unrolled and store them in option.
3038 *
3039 * The domains specified by the user might overlap, so we make
3040 * them disjoint by subtracting earlier domains from later domains.
3041 */
3044{
3045 enum isl_ast_loop_type type, type2;
3046 isl_set *unroll;
3047
3051 for (type2 = isl_ast_loop_atomic; type2 < type; ++type2)
3053 isl_set_copy(option[type2]));
3054 }
3055
3056 unroll = option[isl_ast_loop_unroll];
3057 unroll = isl_set_coalesce(unroll);
3058 unroll = isl_set_make_disjoint(unroll);
3059 option[isl_ast_loop_unroll] = unroll;
3060}
3061
3062/* Split up the domain at the current depth into disjoint
3063 * basic sets for which code should be generated separately,
3064 * based on the user-specified options.
3065 * Return the list of disjoint basic sets.
3066 *
3067 * There are three kinds of domains that we need to keep track of.
3068 * - the "schedule domain" is the domain of "executed"
3069 * - the "class domain" is the domain corresponding to the currrent
3070 * separation class
3071 * - the "option domain" is the domain corresponding to one of the options
3072 * atomic, unroll or separate
3073 *
3074 * We first consider the individial values of the separation classes
3075 * and split up the domain for each of them separately.
3076 * Finally, we consider the remainder. If no separation classes were
3077 * specified, then we call compute_partial_domains with the universe
3078 * "class_domain". Otherwise, we take the "schedule_domain" as "class_domain",
3079 * with inner dimensions removed. We do this because we want to
3080 * avoid computing the complement of the class domains (i.e., the difference
3081 * between the universe and domains->done).
3082 */
3085{
3086 struct isl_codegen_domains domains;
3087 isl_ctx *ctx;
3088 isl_set *domain;
3090 isl_set *classes;
3091 isl_space *space;
3092 int n_param;
3094 isl_bool empty;
3095
3096 if (!executed)
3097 return NULL;
3098
3100 domains.list = isl_basic_set_list_alloc(ctx, 0);
3101
3104
3106
3108 classes = isl_map_range(isl_map_copy(domains.sep_class));
3109 n_param = isl_set_dim(classes, isl_dim_param);
3110 if (n_param < 0)
3111 classes = isl_set_free(classes);
3112 classes = isl_set_project_out(classes, isl_dim_param, 0, n_param);
3113
3114 space = isl_set_get_space(domain);
3115 domains.build = build;
3117 domains.executed = executed;
3118 domains.done = isl_set_empty(space);
3119
3120 if (isl_set_foreach_point(classes, &compute_class_domains, &domains) < 0)
3121 domains.list = isl_basic_set_list_free(domains.list);
3122 isl_set_free(classes);
3123
3124 empty = isl_set_is_empty(domains.done);
3125 if (empty < 0) {
3126 domains.list = isl_basic_set_list_free(domains.list);
3128 } else if (empty) {
3131 } else {
3133 }
3134 if (compute_partial_domains(&domains, domain) < 0)
3135 domains.list = isl_basic_set_list_free(domains.list);
3136
3138 isl_set_free(domains.done);
3139 isl_map_free(domains.sep_class);
3141 isl_set_free(domains.option[type]);
3142
3143 return domains.list;
3144}
3145
3146/* Generate code for a single component, after shifting (if any)
3147 * has been applied, in case the schedule was specified as a union map.
3148 *
3149 * We first split up the domain at the current depth into disjoint
3150 * basic sets based on the user-specified options.
3151 * Then we generated code for each of them and concatenate the results.
3152 */
3155{
3156 isl_basic_set_list *domain_list;
3157 isl_ast_graft_list *list = NULL;
3158
3159 domain_list = compute_domains(executed, build);
3161
3162 isl_basic_set_list_free(domain_list);
3165
3166 return list;
3167}
3168
3169/* Generate code for a single component, after shifting (if any)
3170 * has been applied, in case the schedule was specified as a schedule tree
3171 * and the separate option was specified.
3172 *
3173 * We perform separation on the domain of "executed" and then generate
3174 * an AST for each of the resulting disjoint basic sets.
3175 */
3178{
3179 isl_space *space;
3180 isl_set *domain;
3181 isl_basic_set_list *domain_list;
3182 isl_ast_graft_list *list;
3183
3184 space = isl_ast_build_get_space(build, 1);
3187 domain_list = isl_basic_set_list_from_set(domain);
3188
3190
3191 isl_basic_set_list_free(domain_list);
3194
3195 return list;
3196}
3197
3198/* Internal data structure for generate_shifted_component_tree_unroll.
3199 *
3200 * "executed" and "build" are inputs to generate_shifted_component_tree_unroll.
3201 * "list" collects the constructs grafts.
3202 */
3208
3209/* Initialize data->list to a list of "n" elements.
3210 */
3211static int init_unroll_tree(int n, void *user)
3212{
3213 struct isl_ast_unroll_tree_data *data = user;
3214 isl_ctx *ctx;
3215
3216 ctx = isl_ast_build_get_ctx(data->build);
3217 data->list = isl_ast_graft_list_alloc(ctx, n);
3218
3219 return 0;
3220}
3221
3222/* Given an iteration of an unrolled domain represented by "bset",
3223 * generate the corresponding AST and add the result to data->list.
3224 */
3226{
3227 struct isl_ast_unroll_tree_data *data = user;
3228
3229 data->list = add_node(data->list, isl_union_map_copy(data->executed),
3230 bset, isl_ast_build_copy(data->build));
3231
3232 return 0;
3233}
3234
3235/* Generate code for a single component, after shifting (if any)
3236 * has been applied, in case the schedule was specified as a schedule tree
3237 * and the unroll option was specified.
3238 *
3239 * We call foreach_iteration to iterate over the individual values and
3240 * construct and collect the corresponding grafts in do_unroll_tree_iteration.
3241 */
3245{
3246 struct isl_ast_unroll_tree_data data = { executed, build, NULL };
3247
3249 &do_unroll_tree_iteration, &data) < 0)
3250 data.list = isl_ast_graft_list_free(data.list);
3251
3254
3255 return data.list;
3256}
3257
3258/* Does "domain" involve a disjunction that is purely based on
3259 * constraints involving only outer dimension?
3260 *
3261 * In particular, is there a disjunction such that the constraints
3262 * involving the current and later dimensions are the same over
3263 * all the disjuncts?
3264 */
3267{
3269 isl_set *shared, *inner;
3271 isl_size depth;
3272 isl_size n;
3273 isl_size dim;
3274
3276 if (n < 0)
3277 return isl_bool_error;
3278 if (n <= 1)
3279 return isl_bool_false;
3282 if (dim < 0 || depth < 0)
3283 return isl_bool_error;
3284
3285 inner = isl_set_copy(domain);
3287 isl_dim_set, depth, dim - depth);
3289 shared = isl_set_from_basic_set(hull);
3290 equal = isl_set_plain_is_equal(inner, shared);
3291 isl_set_free(inner);
3292 isl_set_free(shared);
3293
3294 return equal;
3295}
3296
3297/* Generate code for a single component, after shifting (if any)
3298 * has been applied, in case the schedule was specified as a schedule tree.
3299 * In particular, handle the base case where there is either no isolated
3300 * set or we are within the isolated set (in which case "isolated" is set)
3301 * or the iterations that precede or follow the isolated set.
3302 *
3303 * The schedule domain is broken up or combined into basic sets
3304 * according to the AST generation option specified in the current
3305 * schedule node, which may be either atomic, separate, unroll or
3306 * unspecified. If the option is unspecified, then we currently simply
3307 * split the schedule domain into disjoint basic sets.
3308 *
3309 * In case the separate option is specified, the AST generation is
3310 * handled by generate_shifted_component_tree_separate.
3311 * In the other cases, we need the global schedule domain.
3312 * In the unroll case, the AST generation is then handled by
3313 * generate_shifted_component_tree_unroll which needs the actual
3314 * schedule domain (with divs that may refer to the current dimension)
3315 * so that stride detection can be performed.
3316 * In the atomic or unspecified case, inner dimensions and divs involving
3317 * the current dimensions should be eliminated.
3318 * The result is then either combined into a single basic set or
3319 * split up into disjoint basic sets.
3320 * Finally an AST is generated for each basic set and the results are
3321 * concatenated.
3322 *
3323 * If the schedule domain involves a disjunction that is purely based on
3324 * constraints involving only outer dimension, then it is treated as
3325 * if atomic was specified. This ensures that only a single loop
3326 * is generated instead of a sequence of identical loops with
3327 * different guards.
3328 */
3331 int isolated)
3332{
3333 isl_bool outer_disjunction;
3334 isl_union_set *schedule_domain;
3335 isl_set *domain;
3336 isl_basic_set_list *domain_list;
3337 isl_ast_graft_list *list;
3339
3341 if (type < 0)
3342 goto error;
3343
3346 build);
3347
3349 domain = isl_set_from_union_set(schedule_domain);
3350
3353 build);
3354
3357
3358 outer_disjunction = has_pure_outer_disjunction(domain, build);
3359 if (outer_disjunction < 0)
3361
3362 if (outer_disjunction || type == isl_ast_loop_atomic) {
3365 domain_list = isl_basic_set_list_from_basic_set(hull);
3366 } else {
3368 domain_list = isl_basic_set_list_from_set(domain);
3369 }
3370
3372
3373 isl_basic_set_list_free(domain_list);
3376
3377 return list;
3378error:
3381 return NULL;
3382}
3383
3384/* Extract out the disjunction imposed by "domain" on the outer
3385 * schedule dimensions.
3386 *
3387 * In particular, remove all inner dimensions from "domain" (including
3388 * the current dimension) and then remove the constraints that are shared
3389 * by all disjuncts in the result.
3390 */
3411
3412/* Add "guard" to the grafts in "list".
3413 * "build" is the outer AST build, while "sub_build" includes "guard"
3414 * in its generated domain.
3415 *
3416 * First combine the grafts into a single graft and then add the guard.
3417 * If the list is empty, or if some error occurred, then simply return
3418 * the list.
3419 */
3420static __isl_give isl_ast_graft_list *list_add_guard(
3421 __isl_take isl_ast_graft_list *list, __isl_keep isl_set *guard,
3423{
3424 isl_ast_graft *graft;
3425 isl_size n;
3426
3427 list = isl_ast_graft_list_fuse(list, sub_build);
3428
3429 n = isl_ast_graft_list_n_ast_graft(list);
3430 if (n < 0)
3431 return isl_ast_graft_list_free(list);
3432 if (n != 1)
3433 return list;
3434
3435 graft = isl_ast_graft_list_get_ast_graft(list, 0);
3436 graft = isl_ast_graft_add_guard(graft, isl_set_copy(guard), build);
3437 list = isl_ast_graft_list_set_ast_graft(list, 0, graft);
3438
3439 return list;
3440}
3441
3442/* Generate code for a single component, after shifting (if any)
3443 * has been applied, in case the schedule was specified as a schedule tree.
3444 * In particular, do so for the specified subset of the schedule domain.
3445 *
3446 * If we are outside of the isolated part, then "domain" may include
3447 * a disjunction. Explicitly generate this disjunction at this point
3448 * instead of relying on the disjunction getting hoisted back up
3449 * to this level.
3450 */
3453 __isl_keep isl_ast_build *build, int isolated)
3454{
3455 isl_union_set *uset;
3456 isl_ast_graft_list *list;
3457 isl_ast_build *sub_build;
3458 int empty;
3459
3464 if (empty < 0)
3465 goto error;
3466 if (empty) {
3467 isl_ctx *ctx;
3471 return isl_ast_graft_list_alloc(ctx, 0);
3472 }
3473
3474 sub_build = isl_ast_build_copy(build);
3475 if (!isolated) {
3477 sub_build = isl_ast_build_restrict_generated(sub_build,
3479 }
3481 isl_ast_build_copy(sub_build), isolated);
3482 if (!isolated)
3483 list = list_add_guard(list, domain, build, sub_build);
3484 isl_ast_build_free(sub_build);
3486 return list;
3487error:
3490 return NULL;
3491}
3492
3493/* Generate code for a single component, after shifting (if any)
3494 * has been applied, in case the schedule was specified as a schedule tree.
3495 * In particular, do so for the specified sequence of subsets
3496 * of the schedule domain, "before", "isolated", "after" and "other",
3497 * where only the "isolated" part is considered to be isolated.
3498 */
3501 __isl_take isl_set *isolated, __isl_take isl_set *after,
3503{
3504 isl_ast_graft_list *list, *res;
3505
3508 build, 1);
3509 res = isl_ast_graft_list_concat(res, list);
3511 res = isl_ast_graft_list_concat(res, list);
3513 res = isl_ast_graft_list_concat(res, list);
3514
3517
3518 return res;
3519}
3520
3521/* Does "set" intersect "first", but not "second"?
3522 */
3524 __isl_keep isl_set *first, __isl_keep isl_set *second)
3525{
3526 isl_bool disjoint;
3527
3528 disjoint = isl_set_is_disjoint(set, first);
3529 if (disjoint < 0)
3530 return isl_bool_error;
3531 if (disjoint)
3532 return isl_bool_false;
3533
3534 return isl_set_is_disjoint(set, second);
3535}
3536
3537/* Generate code for a single component, after shifting (if any)
3538 * has been applied, in case the schedule was specified as a schedule tree.
3539 * In particular, do so in case of isolation where there is
3540 * only an "isolated" part and an "after" part.
3541 * "dead1" and "dead2" are freed by this function in order to simplify
3542 * the caller.
3543 *
3544 * The "before" and "other" parts are set to empty sets.
3545 */
3549 __isl_take isl_set *dead1, __isl_take isl_set *dead2)
3550{
3551 isl_set *empty;
3552
3553 empty = isl_set_empty(isl_set_get_space(after));
3554 isl_set_free(dead1);
3555 isl_set_free(dead2);
3557 isolated, after, empty, build);
3558}
3559
3560/* Generate code for a single component, after shifting (if any)
3561 * has been applied, in case the schedule was specified as a schedule tree.
3562 *
3563 * We first check if the user has specified an isolated schedule domain
3564 * and that we are not already outside of this isolated schedule domain.
3565 * If so, we break up the schedule domain into iterations that
3566 * precede the isolated domain, the isolated domain itself,
3567 * the iterations that follow the isolated domain and
3568 * the remaining iterations (those that are incomparable
3569 * to the isolated domain).
3570 * We generate an AST for each piece and concatenate the results.
3571 *
3572 * If the isolated domain is not convex, then it is replaced
3573 * by a convex superset to ensure that the sets of preceding and
3574 * following iterations are properly defined and, in particular,
3575 * that there are no intermediate iterations that do not belong
3576 * to the isolated domain.
3577 *
3578 * In the special case where at least one element of the schedule
3579 * domain that does not belong to the isolated domain needs
3580 * to be scheduled after this isolated domain, but none of those
3581 * elements need to be scheduled before, break up the schedule domain
3582 * in only two parts, the isolated domain, and a part that will be
3583 * scheduled after the isolated domain.
3584 *
3585 * If no isolated set has been specified, then we generate an
3586 * AST for the entire inverse schedule.
3587 */
3590{
3591 int i;
3592 isl_size depth;
3593 int empty, has_isolate;
3594 isl_space *space;
3595 isl_union_set *schedule_domain;
3596 isl_set *domain;
3598 isl_set *isolated, *before, *after, *test;
3599 isl_map *gt, *lt;
3600 isl_bool pure;
3601
3603 has_isolate = isl_ast_build_has_isolated(build);
3604 if (has_isolate < 0)
3606 else if (!has_isolate)
3608
3610 domain = isl_set_from_union_set(schedule_domain);
3611
3613 isolated = isl_set_intersect(isolated, isl_set_copy(domain));
3615 empty = isl_set_is_empty(test);
3617 if (empty < 0)
3618 goto error;
3619 if (empty) {
3620 isl_set_free(isolated);
3623 }
3625 if (depth < 0)
3626 goto error;
3627
3628 isolated = isl_ast_build_eliminate(build, isolated);
3630 isolated = isl_set_from_basic_set(hull);
3631
3632 space = isl_space_map_from_set(isl_set_get_space(isolated));
3633 gt = isl_map_universe(space);
3634 for (i = 0; i < depth; ++i)
3635 gt = isl_map_equate(gt, isl_dim_in, i, isl_dim_out, i);
3636 gt = isl_map_order_gt(gt, isl_dim_in, depth, isl_dim_out, depth);
3637 lt = isl_map_reverse(isl_map_copy(gt));
3638 before = isl_set_apply(isl_set_copy(isolated), gt);
3639 after = isl_set_apply(isl_set_copy(isolated), lt);
3640
3642 pure = only_intersects_first(domain, after, before);
3643 if (pure < 0)
3645 else if (pure)
3647 domain, build, before, after);
3650 after = isl_set_subtract(after, isl_set_copy(isolated));
3651 after = isl_set_subtract(after, isl_set_copy(before));
3653
3655 after, domain, build);
3656error:
3658 isl_set_free(isolated);
3661 return NULL;
3662}
3663
3664/* Generate code for a single component, after shifting (if any)
3665 * has been applied.
3666 *
3667 * Call generate_shifted_component_tree or generate_shifted_component_flat
3668 * depending on whether the schedule was specified as a schedule tree.
3669 */
3678
3683
3684/* Given an array "domain" of isl_set_map_pairs and an array "order"
3685 * of indices into the "domain" array,
3686 * return the union of the "map" fields of the elements
3687 * indexed by the first "n" elements of "order".
3688 */
3690 struct isl_set_map_pair *domain, int *order, int n)
3691{
3692 int i;
3693 isl_map *map;
3694 isl_union_map *executed;
3695
3696 map = isl_map_copy(domain[order[0]].map);
3697 executed = isl_union_map_from_map(map);
3698 for (i = 1; i < n; ++i) {
3699 map = isl_map_copy(domain[order[i]].map);
3700 executed = isl_union_map_add_map(executed, map);
3701 }
3702
3703 return executed;
3704}
3705
3706/* Generate code for a single component, after shifting (if any)
3707 * has been applied.
3708 *
3709 * The component inverse schedule is specified as the "map" fields
3710 * of the elements of "domain" indexed by the first "n" elements of "order".
3711 */
3713 struct isl_set_map_pair *domain, int *order, int n,
3715{
3716 isl_union_map *executed;
3717
3718 executed = construct_component_executed(domain, order, n);
3719 return generate_shifted_component(executed, build);
3720}
3721
3722/* Does set dimension "pos" of "set" have an obviously fixed value?
3723 */
3725{
3726 int fixed;
3727 isl_val *v;
3728
3730 if (!v)
3731 return -1;
3732 fixed = !isl_val_is_nan(v);
3733 isl_val_free(v);
3734
3735 return fixed;
3736}
3737
3738/* Given an array "domain" of isl_set_map_pairs and an array "order"
3739 * of indices into the "domain" array,
3740 * do all (except for at most one) of the "set" field of the elements
3741 * indexed by the first "n" elements of "order" have a fixed value
3742 * at position "depth"?
3743 */
3745 int *order, int n, int depth)
3746{
3747 int i;
3748 int non_fixed = -1;
3749
3750 for (i = 0; i < n; ++i) {
3751 int f;
3752
3753 f = dim_is_fixed(domain[order[i]].set, depth);
3754 if (f < 0)
3755 return -1;
3756 if (f)
3757 continue;
3758 if (non_fixed >= 0)
3759 return 0;
3760 non_fixed = i;
3761 }
3762
3763 return 1;
3764}
3765
3766/* Given an array "domain" of isl_set_map_pairs and an array "order"
3767 * of indices into the "domain" array,
3768 * eliminate the inner dimensions from the "set" field of the elements
3769 * indexed by the first "n" elements of "order", provided the current
3770 * dimension does not have a fixed value.
3771 *
3772 * Return the index of the first element in "order" with a corresponding
3773 * "set" field that does not have an (obviously) fixed value.
3774 */
3776 int *order, int n, int depth, __isl_keep isl_ast_build *build)
3777{
3778 int i;
3779 int base = -1;
3780
3781 for (i = n - 1; i >= 0; --i) {
3782 int f;
3783 f = dim_is_fixed(domain[order[i]].set, depth);
3784 if (f < 0)
3785 return -1;
3786 if (f)
3787 continue;
3788 domain[order[i]].set = isl_ast_build_eliminate_inner(build,
3789 domain[order[i]].set);
3790 base = i;
3791 }
3792
3793 return base;
3794}
3795
3796/* Given an array "domain" of isl_set_map_pairs and an array "order"
3797 * of indices into the "domain" array,
3798 * find the element of "domain" (amongst those indexed by the first "n"
3799 * elements of "order") with the "set" field that has the smallest
3800 * value for the current iterator.
3801 *
3802 * Note that the domain with the smallest value may depend on the parameters
3803 * and/or outer loop dimension. Since the result of this function is only
3804 * used as heuristic, we only make a reasonable attempt at finding the best
3805 * domain, one that should work in case a single domain provides the smallest
3806 * value for the current dimension over all values of the parameters
3807 * and outer dimensions.
3808 *
3809 * In particular, we compute the smallest value of the first domain
3810 * and replace it by that of any later domain if that later domain
3811 * has a smallest value that is smaller for at least some value
3812 * of the parameters and outer dimensions.
3813 */
3814static int first_offset(struct isl_set_map_pair *domain, int *order, int n,
3816{
3817 int i;
3818 isl_map *min_first;
3819 int first = 0;
3820
3821 min_first = isl_ast_build_map_to_iterator(build,
3822 isl_set_copy(domain[order[0]].set));
3823 min_first = isl_map_lexmin(min_first);
3824
3825 for (i = 1; i < n; ++i) {
3826 isl_map *min, *test;
3827 int empty;
3828
3830 isl_set_copy(domain[order[i]].set));
3831 min = isl_map_lexmin(min);
3832 test = isl_map_copy(min);
3835 empty = isl_map_is_empty(test);
3837 if (empty >= 0 && !empty) {
3838 isl_map_free(min_first);
3839 first = i;
3840 min_first = min;
3841 } else
3842 isl_map_free(min);
3843
3844 if (empty < 0)
3845 break;
3846 }
3847
3848 isl_map_free(min_first);
3849
3850 return i < n ? -1 : first;
3851}
3852
3853/* Construct a shifted inverse schedule based on the original inverse schedule,
3854 * the stride and the offset.
3855 *
3856 * The original inverse schedule is specified as the "map" fields
3857 * of the elements of "domain" indexed by the first "n" elements of "order".
3858 *
3859 * "stride" and "offset" are such that the difference
3860 * between the values of the current dimension of domain "i"
3861 * and the values of the current dimension for some reference domain are
3862 * equal to
3863 *
3864 * stride * integer + offset[i]
3865 *
3866 * Moreover, 0 <= offset[i] < stride.
3867 *
3868 * For each domain, we create a map
3869 *
3870 * { [..., j, ...] -> [..., j - offset[i], offset[i], ....] }
3871 *
3872 * where j refers to the current dimension and the other dimensions are
3873 * unchanged, and apply this map to the original schedule domain.
3874 *
3875 * For example, for the original schedule
3876 *
3877 * { A[i] -> [2i]: 0 <= i < 10; B[i] -> [2i+1] : 0 <= i < 10 }
3878 *
3879 * and assuming the offset is 0 for the A domain and 1 for the B domain,
3880 * we apply the mapping
3881 *
3882 * { [j] -> [j, 0] }
3883 *
3884 * to the schedule of the "A" domain and the mapping
3885 *
3886 * { [j - 1] -> [j, 1] }
3887 *
3888 * to the schedule of the "B" domain.
3889 *
3890 *
3891 * Note that after the transformation, the differences between pairs
3892 * of values of the current dimension over all domains are multiples
3893 * of stride and that we have therefore exposed the stride.
3894 *
3895 *
3896 * To see that the mapping preserves the lexicographic order,
3897 * first note that each of the individual maps above preserves the order.
3898 * If the value of the current iterator is j1 in one domain and j2 in another,
3899 * then if j1 = j2, we know that the same map is applied to both domains
3900 * and the order is preserved.
3901 * Otherwise, let us assume, without loss of generality, that j1 < j2.
3902 * If c1 >= c2 (with c1 and c2 the corresponding offsets), then
3903 *
3904 * j1 - c1 < j2 - c2
3905 *
3906 * and the order is preserved.
3907 * If c1 < c2, then we know
3908 *
3909 * 0 <= c2 - c1 < s
3910 *
3911 * We also have
3912 *
3913 * j2 - j1 = n * s + r
3914 *
3915 * with n >= 0 and 0 <= r < s.
3916 * In other words, r = c2 - c1.
3917 * If n > 0, then
3918 *
3919 * j1 - c1 < j2 - c2
3920 *
3921 * If n = 0, then
3922 *
3923 * j1 - c1 = j2 - c2
3924 *
3925 * and so
3926 *
3927 * (j1 - c1, c1) << (j2 - c2, c2)
3928 *
3929 * with "<<" the lexicographic order, proving that the order is preserved
3930 * in all cases.
3931 */
3933 struct isl_set_map_pair *domain, int *order, int n,
3936{
3937 int i;
3938 isl_union_map *executed;
3939 isl_space *space;
3940 isl_map *map;
3941 isl_size depth;
3942 isl_constraint *c;
3943
3944 depth = isl_ast_build_get_depth(build);
3945 if (depth < 0)
3946 return NULL;
3947 space = isl_ast_build_get_space(build, 1);
3948 executed = isl_union_map_empty(isl_space_copy(space));
3949 space = isl_space_map_from_set(space);
3951 map = isl_map_eliminate(map, isl_dim_out, depth, 1);
3952 map = isl_map_insert_dims(map, isl_dim_out, depth + 1, 1);
3953 space = isl_space_insert_dims(space, isl_dim_out, depth + 1, 1);
3954
3958
3959 for (i = 0; i < n; ++i) {
3960 isl_map *map_i;
3961 isl_val *v;
3962
3963 v = isl_multi_val_get_val(offset, i);
3964 if (!v)
3965 break;
3966 map_i = isl_map_copy(map);
3967 map_i = isl_map_fix_val(map_i, isl_dim_out, depth + 1,
3968 isl_val_copy(v));
3969 v = isl_val_neg(v);
3972
3973 map_i = isl_map_apply_domain(isl_map_copy(domain[order[i]].map),
3974 map_i);
3975 executed = isl_union_map_add_map(executed, map_i);
3976 }
3977
3980
3981 if (i < n)
3982 executed = isl_union_map_free(executed);
3983
3984 return executed;
3985}
3986
3987/* Generate code for a single component, after exposing the stride,
3988 * given that the schedule domain is "shifted strided".
3989 *
3990 * The component inverse schedule is specified as the "map" fields
3991 * of the elements of "domain" indexed by the first "n" elements of "order".
3992 *
3993 * The schedule domain being "shifted strided" means that the differences
3994 * between the values of the current dimension of domain "i"
3995 * and the values of the current dimension for some reference domain are
3996 * equal to
3997 *
3998 * stride * integer + offset[i]
3999 *
4000 * We first look for the domain with the "smallest" value for the current
4001 * dimension and adjust the offsets such that the offset of the "smallest"
4002 * domain is equal to zero. The other offsets are reduced modulo stride.
4003 *
4004 * Based on this information, we construct a new inverse schedule in
4005 * construct_shifted_executed that exposes the stride.
4006 * Since this involves the introduction of a new schedule dimension,
4007 * the build needs to be changed accordingly.
4008 * After computing the AST, the newly introduced dimension needs
4009 * to be removed again from the list of grafts. We do this by plugging
4010 * in a mapping that represents the new schedule domain in terms of the
4011 * old schedule domain.
4012 */
4013static __isl_give isl_ast_graft_list *generate_shift_component(
4014 struct isl_set_map_pair *domain, int *order, int n,
4017{
4018 isl_ast_graft_list *list;
4019 int first;
4020 isl_size depth;
4021 isl_val *val;
4022 isl_multi_val *mv;
4023 isl_space *space;
4024 isl_multi_aff *ma, *zero;
4025 isl_union_map *executed;
4026
4027 depth = isl_ast_build_get_depth(build);
4028
4029 first = first_offset(domain, order, n, build);
4030 if (depth < 0 || first < 0)
4031 goto error;
4032
4033 mv = isl_multi_val_copy(offset);
4034 val = isl_multi_val_get_val(offset, first);
4035 val = isl_val_neg(val);
4036 mv = isl_multi_val_add_val(mv, val);
4037 mv = isl_multi_val_mod_val(mv, isl_val_copy(stride));
4038
4039 executed = construct_shifted_executed(domain, order, n, stride, mv,
4040 build);
4041 space = isl_ast_build_get_space(build, 1);
4042 space = isl_space_map_from_set(space);
4043 ma = isl_multi_aff_identity(isl_space_copy(space));
4045 space = isl_space_add_dims(space, isl_dim_out, 1);
4046 zero = isl_multi_aff_zero(space);
4047 ma = isl_multi_aff_range_splice(ma, depth + 1, zero);
4048 build = isl_ast_build_insert_dim(build, depth + 1);
4049 list = generate_shifted_component(executed, build);
4050
4052
4053 isl_multi_val_free(mv);
4054
4055 return list;
4056error:
4057 isl_ast_build_free(build);
4058 return NULL;
4059}
4060
4061/* Does any node in the schedule tree rooted at the current schedule node
4062 * of "build" depend on outer schedule nodes?
4063 */
4065{
4066 isl_schedule_node *node;
4067 int dependent = 0;
4068
4069 node = isl_ast_build_get_schedule_node(build);
4070 dependent = isl_schedule_node_is_subtree_anchored(node);
4072
4073 return dependent;
4074}
4075
4076/* Generate code for a single component.
4077 *
4078 * The component inverse schedule is specified as the "map" fields
4079 * of the elements of "domain" indexed by the first "n" elements of "order".
4080 *
4081 * This function may modify the "set" fields of "domain".
4082 *
4083 * Before proceeding with the actual code generation for the component,
4084 * we first check if there are any "shifted" strides, meaning that
4085 * the schedule domains of the individual domains are all strided,
4086 * but that they have different offsets, resulting in the union
4087 * of schedule domains not being strided anymore.
4088 *
4089 * The simplest example is the schedule
4090 *
4091 * { A[i] -> [2i]: 0 <= i < 10; B[i] -> [2i+1] : 0 <= i < 10 }
4092 *
4093 * Both schedule domains are strided, but their union is not.
4094 * This function detects such cases and then rewrites the schedule to
4095 *
4096 * { A[i] -> [2i, 0]: 0 <= i < 10; B[i] -> [2i, 1] : 0 <= i < 10 }
4097 *
4098 * In the new schedule, the schedule domains have the same offset (modulo
4099 * the stride), ensuring that the union of schedule domains is also strided.
4100 *
4101 *
4102 * If there is only a single domain in the component, then there is
4103 * nothing to do. Similarly, if the current schedule dimension has
4104 * a fixed value for almost all domains then there is nothing to be done.
4105 * In particular, we need at least two domains where the current schedule
4106 * dimension does not have a fixed value.
4107 * Finally, in case of a schedule map input,
4108 * if any of the options refer to the current schedule dimension,
4109 * then we bail out as well. It would be possible to reformulate the options
4110 * in terms of the new schedule domain, but that would introduce constraints
4111 * that separate the domains in the options and that is something we would
4112 * like to avoid.
4113 * In the case of a schedule tree input, we bail out if any of
4114 * the descendants of the current schedule node refer to outer
4115 * schedule nodes in any way.
4116 *
4117 *
4118 * To see if there is any shifted stride, we look at the differences
4119 * between the values of the current dimension in pairs of domains
4120 * for equal values of outer dimensions. These differences should be
4121 * of the form
4122 *
4123 * m x + r
4124 *
4125 * with "m" the stride and "r" a constant. Note that we cannot perform
4126 * this analysis on individual domains as the lower bound in each domain
4127 * may depend on parameters or outer dimensions and so the current dimension
4128 * itself may not have a fixed remainder on division by the stride.
4129 *
4130 * In particular, we compare the first domain that does not have an
4131 * obviously fixed value for the current dimension to itself and all
4132 * other domains and collect the offsets and the gcd of the strides.
4133 * If the gcd becomes one, then we failed to find shifted strides.
4134 * If the gcd is zero, then the differences were all fixed, meaning
4135 * that some domains had non-obviously fixed values for the current dimension.
4136 * If all the offsets are the same (for those domains that do not have
4137 * an obviously fixed value for the current dimension), then we do not
4138 * apply the transformation.
4139 * If none of the domains were skipped, then there is nothing to do.
4140 * If some of them were skipped, then if we apply separation, the schedule
4141 * domain should get split in pieces with a (non-shifted) stride.
4142 *
4143 * Otherwise, we apply a shift to expose the stride in
4144 * generate_shift_component.
4145 */
4146static __isl_give isl_ast_graft_list *generate_component(
4147 struct isl_set_map_pair *domain, int *order, int n,
4149{
4150 int i, d;
4151 isl_size depth;
4152 isl_ctx *ctx;
4153 isl_map *map;
4154 isl_set *deltas;
4155 isl_val *gcd = NULL;
4156 isl_multi_val *mv;
4157 int fixed, skip;
4158 int base;
4159 isl_ast_graft_list *list;
4160 int res = 0;
4161
4162 depth = isl_ast_build_get_depth(build);
4163 if (depth < 0)
4164 goto error;
4165
4166 skip = n == 1;
4167 if (skip >= 0 && !skip)
4168 skip = at_most_one_non_fixed(domain, order, n, depth);
4169 if (skip >= 0 && !skip) {
4171 skip = has_anchored_subtree(build);
4172 else
4174 }
4175 if (skip < 0)
4176 goto error;
4177 if (skip)
4179 order, n, build);
4180
4181 base = eliminate_non_fixed(domain, order, n, depth, build);
4182 if (base < 0)
4183 goto error;
4184
4185 ctx = isl_ast_build_get_ctx(build);
4186
4187 mv = isl_multi_val_zero(isl_space_set_alloc(ctx, 0, n));
4188
4189 fixed = 1;
4190 for (i = 0; i < n; ++i) {
4191 isl_val *r, *m;
4192
4194 isl_set_copy(domain[order[base]].set),
4195 isl_set_copy(domain[order[i]].set));
4196 for (d = 0; d < depth; ++d)
4198 isl_dim_out, d);
4199 deltas = isl_map_deltas(map);
4200 res = isl_set_dim_residue_class_val(deltas, depth, &m, &r);
4201 isl_set_free(deltas);
4202 if (res < 0)
4203 break;
4204
4205 if (i == 0)
4206 gcd = m;
4207 else
4208 gcd = isl_val_gcd(gcd, m);
4209 if (isl_val_is_one(gcd)) {
4210 isl_val_free(r);
4211 break;
4212 }
4213 mv = isl_multi_val_set_val(mv, i, r);
4214
4215 res = dim_is_fixed(domain[order[i]].set, depth);
4216 if (res < 0)
4217 break;
4218 if (res)
4219 continue;
4220
4221 if (fixed && i > base) {
4222 isl_val *a, *b;
4223 a = isl_multi_val_get_val(mv, i);
4224 b = isl_multi_val_get_val(mv, base);
4225 if (isl_val_ne(a, b))
4226 fixed = 0;
4227 isl_val_free(a);
4228 isl_val_free(b);
4229 }
4230 }
4231
4232 if (res < 0 || !gcd) {
4233 isl_ast_build_free(build);
4234 list = NULL;
4235 } else if (i < n || fixed || isl_val_is_zero(gcd)) {
4237 order, n, build);
4238 } else {
4239 list = generate_shift_component(domain, order, n, gcd, mv,
4240 build);
4241 }
4242
4244 isl_multi_val_free(mv);
4245
4246 return list;
4247error:
4248 isl_ast_build_free(build);
4249 return NULL;
4250}
4251
4252/* Store both "map" itself and its domain in the
4253 * structure pointed to by *next and advance to the next array element.
4254 */
4256{
4257 struct isl_set_map_pair **next = user;
4258
4259 (*next)->map = isl_map_copy(map);
4260 (*next)->set = isl_map_domain(map);
4261 (*next)++;
4262
4263 return isl_stat_ok;
4264}
4265
4268
4269/* Is any domain element of "umap" scheduled after any of
4270 * the corresponding image elements by the tree rooted at
4271 * the child of "node"?
4272 */
4275{
4276 isl_schedule_node *child;
4277 isl_bool after;
4278
4279 child = isl_schedule_node_get_child(node, 0);
4280 after = after_in_tree(umap, child);
4282
4283 return after;
4284}
4285
4286/* Is any domain element of "umap" scheduled after any of
4287 * the corresponding image elements by the tree rooted at
4288 * the band node "node"?
4289 *
4290 * We first check if any domain element is scheduled after any
4291 * of the corresponding image elements by the band node itself.
4292 * If not, we restrict "map" to those pairs of element that
4293 * are scheduled together by the band node and continue with
4294 * the child of the band node.
4295 * If there are no such pairs then the map passed to after_in_child
4296 * will be empty causing it to return 0.
4297 */
4300{
4302 isl_union_map *partial, *test, *gt, *universe, *umap1, *umap2;
4304 isl_space *space;
4305 isl_bool empty;
4306 isl_bool after;
4307 isl_size n;
4308
4310 if (n < 0)
4311 return isl_bool_error;
4312 if (n == 0)
4313 return after_in_child(umap, node);
4314
4316 space = isl_multi_union_pw_aff_get_space(mupa);
4318 test = isl_union_map_copy(umap);
4325
4326 if (empty < 0 || !empty) {
4327 isl_union_map_free(partial);
4328 return isl_bool_not(empty);
4329 }
4330
4334 umap1 = isl_union_map_copy(partial);
4335 umap1 = isl_union_map_intersect_domain(umap1, domain);
4336 umap2 = isl_union_map_intersect_domain(partial, range);
4339 after = after_in_child(test, node);
4341 return after;
4342}
4343
4344/* Is any domain element of "umap" scheduled after any of
4345 * the corresponding image elements by the tree rooted at
4346 * the context node "node"?
4347 *
4348 * The context constraints apply to the schedule domain,
4349 * so we cannot apply them directly to "umap", which contains
4350 * pairs of statement instances. Instead, we add them
4351 * to the range of the prefix schedule for both domain and
4352 * range of "umap".
4353 */
4356{
4357 isl_union_map *prefix, *universe, *umap1, *umap2;
4360 isl_bool after;
4361
4362 umap = isl_union_map_copy(umap);
4368 umap1 = isl_union_map_copy(prefix);
4369 umap1 = isl_union_map_intersect_domain(umap1, domain);
4370 umap2 = isl_union_map_intersect_domain(prefix, range);
4371 umap1 = isl_union_map_intersect_range(umap1,
4373 umap1 = isl_union_map_apply_range(umap1, isl_union_map_reverse(umap2));
4374 umap = isl_union_map_intersect(umap, umap1);
4375
4376 after = after_in_child(umap, node);
4377
4378 isl_union_map_free(umap);
4379
4380 return after;
4381}
4382
4383/* Is any domain element of "umap" scheduled after any of
4384 * the corresponding image elements by the tree rooted at
4385 * the expansion node "node"?
4386 *
4387 * We apply the expansion to domain and range of "umap" and
4388 * continue with its child.
4389 */
4392{
4393 isl_union_map *expansion;
4394 isl_bool after;
4395
4397 umap = isl_union_map_copy(umap);
4398 umap = isl_union_map_apply_domain(umap, isl_union_map_copy(expansion));
4399 umap = isl_union_map_apply_range(umap, expansion);
4400
4401 after = after_in_child(umap, node);
4402
4403 isl_union_map_free(umap);
4404
4405 return after;
4406}
4407
4408/* Is any domain element of "umap" scheduled after any of
4409 * the corresponding image elements by the tree rooted at
4410 * the extension node "node"?
4411 *
4412 * Since the extension node may add statement instances before or
4413 * after the pairs of statement instances in "umap", we return isl_bool_true
4414 * to ensure that these pairs are not broken up.
4415 */
4421
4422/* Is any domain element of "umap" scheduled after any of
4423 * the corresponding image elements by the tree rooted at
4424 * the filter node "node"?
4425 *
4426 * We intersect domain and range of "umap" with the filter and
4427 * continue with its child.
4428 */
4431{
4432 isl_union_set *filter;
4433 isl_bool after;
4434
4435 umap = isl_union_map_copy(umap);
4438 umap = isl_union_map_intersect_range(umap, filter);
4439
4440 after = after_in_child(umap, node);
4441
4442 isl_union_map_free(umap);
4443
4444 return after;
4445}
4446
4447/* Is any domain element of "umap" scheduled after any of
4448 * the corresponding image elements by the tree rooted at
4449 * the set node "node"?
4450 *
4451 * This is only the case if this condition holds in any
4452 * of the (filter) children of the set node.
4453 * In particular, if the domain and the range of "umap"
4454 * are contained in different children, then the condition
4455 * does not hold.
4456 */
4459{
4460 int i;
4461 isl_size n;
4462
4464 if (n < 0)
4465 return isl_bool_error;
4466 for (i = 0; i < n; ++i) {
4467 isl_schedule_node *child;
4468 isl_bool after;
4469
4470 child = isl_schedule_node_get_child(node, i);
4471 after = after_in_tree(umap, child);
4473
4474 if (after < 0 || after)
4475 return after;
4476 }
4477
4478 return isl_bool_false;
4479}
4480
4481/* Return the filter of child "i" of "node".
4482 */
4484 __isl_keep isl_schedule_node *node, int i)
4485{
4486 isl_schedule_node *child;
4487 isl_union_set *filter;
4488
4489 child = isl_schedule_node_get_child(node, i);
4492
4493 return filter;
4494}
4495
4496/* Is any domain element of "umap" scheduled after any of
4497 * the corresponding image elements by the tree rooted at
4498 * the sequence node "node"?
4499 *
4500 * This happens in particular if any domain element is
4501 * contained in a later child than one containing a range element or
4502 * if the condition holds within a given child in the sequence.
4503 * The later part of the condition is checked by after_in_set.
4504 */
4507{
4508 int i, j;
4509 isl_size n;
4510 isl_union_map *umap_i;
4511 isl_bool empty;
4512 isl_bool after = isl_bool_false;
4513
4515 if (n < 0)
4516 return isl_bool_error;
4517 for (i = 1; i < n; ++i) {
4518 isl_union_set *filter_i;
4519
4520 umap_i = isl_union_map_copy(umap);
4521 filter_i = child_filter(node, i);
4522 umap_i = isl_union_map_intersect_domain(umap_i, filter_i);
4523 empty = isl_union_map_is_empty(umap_i);
4524 if (empty < 0)
4525 goto error;
4526 if (empty) {
4527 isl_union_map_free(umap_i);
4528 continue;
4529 }
4530
4531 for (j = 0; j < i; ++j) {
4532 isl_union_set *filter_j;
4533 isl_union_map *umap_ij;
4534
4535 umap_ij = isl_union_map_copy(umap_i);
4536 filter_j = child_filter(node, j);
4537 umap_ij = isl_union_map_intersect_range(umap_ij,
4538 filter_j);
4539 empty = isl_union_map_is_empty(umap_ij);
4540 isl_union_map_free(umap_ij);
4541
4542 if (empty < 0)
4543 goto error;
4544 if (!empty)
4545 after = isl_bool_true;
4546 if (after)
4547 break;
4548 }
4549
4550 isl_union_map_free(umap_i);
4551 if (after)
4552 break;
4553 }
4554
4555 if (after < 0 || after)
4556 return after;
4557
4558 return after_in_set(umap, node);
4559error:
4560 isl_union_map_free(umap_i);
4561 return isl_bool_error;
4562}
4563
4564/* Is any domain element of "umap" scheduled after any of
4565 * the corresponding image elements by the tree rooted at "node"?
4566 *
4567 * If "umap" is empty, then clearly there is no such element.
4568 * Otherwise, consider the different types of nodes separately.
4569 */
4572{
4573 isl_bool empty;
4575
4576 empty = isl_union_map_is_empty(umap);
4577 if (empty < 0)
4578 return isl_bool_error;
4579 if (empty)
4580 return isl_bool_false;
4581 if (!node)
4582 return isl_bool_error;
4583
4585 switch (type) {
4587 return isl_bool_error;
4589 return isl_bool_false;
4591 return after_in_band(umap, node);
4594 "unexpected internal domain node",
4595 return isl_bool_error);
4597 return after_in_context(umap, node);
4599 return after_in_expansion(umap, node);
4601 return after_in_extension(umap, node);
4603 return after_in_filter(umap, node);
4606 return after_in_child(umap, node);
4608 return after_in_set(umap, node);
4610 return after_in_sequence(umap, node);
4611 }
4612
4613 return isl_bool_true;
4614}
4615
4616/* Is any domain element of "map1" scheduled after any domain
4617 * element of "map2" by the subtree underneath the current band node,
4618 * while at the same time being scheduled together by the current
4619 * band node, i.e., by "map1" and "map2?
4620 *
4621 * If the child of the current band node is a leaf, then
4622 * no element can be scheduled after any other element.
4623 *
4624 * Otherwise, we construct a relation between domain elements
4625 * of "map1" and domain elements of "map2" that are scheduled
4626 * together and then check if the subtree underneath the current
4627 * band node determines their relative order.
4628 */
4631{
4632 isl_schedule_node *node;
4633 isl_map *map;
4634 isl_union_map *umap;
4635 isl_bool after;
4636
4637 node = isl_ast_build_get_schedule_node(build);
4638 if (!node)
4639 return isl_bool_error;
4640 node = isl_schedule_node_child(node, 0);
4643 return isl_bool_false;
4644 }
4648 after = after_in_tree(umap, node);
4649 isl_union_map_free(umap);
4651 return after;
4652}
4653
4654/* Internal data for any_scheduled_after.
4655 *
4656 * "build" is the build in which the AST is constructed.
4657 * "depth" is the number of loops that have already been generated
4658 * "group_coscheduled" is a local copy of options->ast_build_group_coscheduled
4659 * "domain" is an array of set-map pairs corresponding to the different
4660 * iteration domains. The set is the schedule domain, i.e., the domain
4661 * of the inverse schedule, while the map is the inverse schedule itself.
4662 */
4669
4670/* Is any element of domain "i" scheduled after any element of domain "j"
4671 * (for a common iteration of the first data->depth loops)?
4672 *
4673 * data->domain[i].set contains the domain of the inverse schedule
4674 * for domain "i", i.e., elements in the schedule domain.
4675 *
4676 * If we are inside a band of a schedule tree and there is a pair
4677 * of elements in the two domains that is schedule together by
4678 * the current band, then we check if any element of "i" may be schedule
4679 * after element of "j" by the descendants of the band node.
4680 *
4681 * If data->group_coscheduled is set, then we also return 1 if there
4682 * is any pair of elements in the two domains that are scheduled together.
4683 */
4684static isl_bool any_scheduled_after(int i, int j, void *user)
4685{
4686 struct isl_any_scheduled_after_data *data = user;
4687 isl_size dim = isl_set_dim(data->domain[i].set, isl_dim_set);
4688 int pos;
4689
4690 if (dim < 0)
4691 return isl_bool_error;
4692
4693 for (pos = data->depth; pos < dim; ++pos) {
4694 int follows;
4695
4696 follows = isl_set_follows_at(data->domain[i].set,
4697 data->domain[j].set, pos);
4698
4699 if (follows < -1)
4700 return isl_bool_error;
4701 if (follows > 0)
4702 return isl_bool_true;
4703 if (follows < 0)
4704 return isl_bool_false;
4705 }
4706
4708 isl_bool after;
4709
4710 after = after_in_subtree(data->build, data->domain[i].map,
4711 data->domain[j].map);
4712 if (after < 0 || after)
4713 return after;
4714 }
4715
4716 return isl_bool_ok(data->group_coscheduled);
4717}
4718
4719/* Look for independent components at the current depth and generate code
4720 * for each component separately. The resulting lists of grafts are
4721 * merged in an attempt to combine grafts with identical guards.
4722 *
4723 * Code for two domains can be generated separately if all the elements
4724 * of one domain are scheduled before (or together with) all the elements
4725 * of the other domain. We therefore consider the graph with as nodes
4726 * the domains and an edge between two nodes if any element of the first
4727 * node is scheduled after any element of the second node.
4728 * If the ast_build_group_coscheduled is set, then we also add an edge if
4729 * there is any pair of elements in the two domains that are scheduled
4730 * together.
4731 * Code is then generated (by generate_component)
4732 * for each of the strongly connected components in this graph
4733 * in their topological order.
4734 *
4735 * Since the test is performed on the domain of the inverse schedules of
4736 * the different domains, we precompute these domains and store
4737 * them in data.domain.
4738 */
4739static __isl_give isl_ast_graft_list *generate_components(
4741{
4742 int i;
4744 isl_size n = isl_union_map_n_map(executed);
4746 struct isl_any_scheduled_after_data data;
4747 struct isl_set_map_pair *next;
4748 struct isl_tarjan_graph *g = NULL;
4749 isl_ast_graft_list *list = NULL;
4750 int n_domain = 0;
4751
4752 data.domain = NULL;
4753 if (n < 0)
4754 goto error;
4755 data.domain = isl_calloc_array(ctx, struct isl_set_map_pair, n);
4756 if (!data.domain)
4757 goto error;
4758 n_domain = n;
4759
4760 next = data.domain;
4761 if (isl_union_map_foreach_map(executed, &extract_domain, &next) < 0)
4762 goto error;
4763
4764 depth = isl_ast_build_get_depth(build);
4765 if (depth < 0)
4766 goto error;
4767 data.build = build;
4768 data.depth = depth;
4770 g = isl_tarjan_graph_init(ctx, n, &any_scheduled_after, &data);
4771 if (!g)
4772 goto error;
4773
4774 list = isl_ast_graft_list_alloc(ctx, 0);
4775
4776 i = 0;
4777 while (list && n) {
4778 isl_ast_graft_list *list_c;
4779 int first = i;
4780
4781 if (g->order[i] == -1)
4782 isl_die(ctx, isl_error_internal, "cannot happen",
4783 goto error);
4784 ++i; --n;
4785 while (g->order[i] != -1) {
4786 ++i; --n;
4787 }
4788
4789 list_c = generate_component(data.domain,
4790 g->order + first, i - first,
4791 isl_ast_build_copy(build));
4792 list = isl_ast_graft_list_merge(list, list_c, build);
4793
4794 ++i;
4795 }
4796
4797 if (0)
4798error: list = isl_ast_graft_list_free(list);
4800 for (i = 0; i < n_domain; ++i) {
4801 isl_map_free(data.domain[i].map);
4802 isl_set_free(data.domain[i].set);
4803 }
4804 free(data.domain);
4805 isl_union_map_free(executed);
4806 isl_ast_build_free(build);
4807
4808 return list;
4809}
4810
4811/* Generate code for the next level (and all inner levels).
4812 *
4813 * If "executed" is empty, i.e., no code needs to be generated,
4814 * then we return an empty list.
4815 *
4816 * If we have already generated code for all loop levels, then we pass
4817 * control to generate_inner_level.
4818 *
4819 * If "executed" lives in a single space, i.e., if code needs to be
4820 * generated for a single domain, then there can only be a single
4821 * component and we go directly to generate_shifted_component.
4822 * Otherwise, we call generate_components to detect the components
4823 * and to call generate_component on each of them separately.
4824 */
4825static __isl_give isl_ast_graft_list *generate_next_level(
4827{
4828 isl_size depth;
4829 isl_size dim;
4830 isl_size n;
4831
4832 if (!build || !executed)
4833 goto error;
4834
4835 if (isl_union_map_is_empty(executed)) {
4836 isl_ctx *ctx = isl_ast_build_get_ctx(build);
4837 isl_union_map_free(executed);
4838 isl_ast_build_free(build);
4839 return isl_ast_graft_list_alloc(ctx, 0);
4840 }
4841
4842 depth = isl_ast_build_get_depth(build);
4843 dim = isl_ast_build_dim(build, isl_dim_set);
4844 if (depth < 0 || dim < 0)
4845 goto error;
4846 if (depth >= dim)
4847 return generate_inner_level(executed, build);
4848
4849 n = isl_union_map_n_map(executed);
4850 if (n < 0)
4851 goto error;
4852 if (n == 1)
4853 return generate_shifted_component(executed, build);
4854
4855 return generate_components(executed, build);
4856error:
4857 isl_union_map_free(executed);
4858 isl_ast_build_free(build);
4859 return NULL;
4860}
4861
4862/* Internal data structure used by isl_ast_build_node_from_schedule_map.
4863 * internal, executed and build are the inputs to generate_code.
4864 * list collects the output.
4865 */
4873
4874/* Given an inverse schedule in terms of the external build schedule, i.e.,
4875 *
4876 * [E -> S] -> D
4877 *
4878 * with E the external build schedule and S the additional schedule "space",
4879 * reformulate the inverse schedule in terms of the internal schedule domain,
4880 * i.e., return
4881 *
4882 * [I -> S] -> D
4883 *
4884 * We first obtain a mapping
4885 *
4886 * I -> E
4887 *
4888 * take the inverse and the product with S -> S, resulting in
4889 *
4890 * [I -> S] -> [E -> S]
4891 *
4892 * Applying the map to the input produces the desired result.
4893 */
4895 __isl_take isl_union_map *executed, __isl_keep isl_space *space,
4897{
4898 isl_map *id, *proj;
4899
4900 proj = isl_ast_build_get_schedule_map(build);
4901 proj = isl_map_reverse(proj);
4902 space = isl_space_map_from_set(isl_space_copy(space));
4903 id = isl_map_identity(space);
4904 proj = isl_map_product(proj, id);
4905 executed = isl_union_map_apply_domain(executed,
4907 return executed;
4908}
4909
4910/* Generate an AST that visits the elements in the range of data->executed
4911 * in the relative order specified by the corresponding domain element(s)
4912 * for those domain elements that belong to "set".
4913 * Add the result to data->list.
4914 *
4915 * The caller ensures that "set" is a universe domain.
4916 * "space" is the space of the additional part of the schedule.
4917 * It is equal to the space of "set" if build->domain is parametric.
4918 * Otherwise, it is equal to the range of the wrapped space of "set".
4919 *
4920 * If the build space is not parametric and
4921 * if isl_ast_build_node_from_schedule_map
4922 * was called from an outside user (data->internal not set), then
4923 * the (inverse) schedule refers to the external build domain and needs to
4924 * be transformed to refer to the internal build domain.
4925 *
4926 * If the build space is parametric, then we add some of the parameter
4927 * constraints to the executed relation. Adding these constraints
4928 * allows for an earlier detection of conflicts in some cases.
4929 * However, we do not want to divide the executed relation into
4930 * more disjuncts than necessary. We therefore approximate
4931 * the constraints on the parameters by a single disjunct set.
4932 *
4933 * The build is extended to include the additional part of the schedule.
4934 * If the original build space was not parametric, then the options
4935 * in data->build refer only to the additional part of the schedule
4936 * and they need to be adjusted to refer to the complete AST build
4937 * domain.
4938 *
4939 * After having adjusted inverse schedule and build, we start generating
4940 * code with the outer loop of the current code generation
4941 * in generate_next_level.
4942 *
4943 * If the original build space was not parametric, we undo the embedding
4944 * on the resulting isl_ast_node_list so that it can be used within
4945 * the outer AST build.
4946 */
4949{
4950 isl_union_map *executed;
4951 isl_ast_build *build;
4952 isl_ast_graft_list *list;
4953 int embed;
4954
4955 executed = isl_union_map_copy(data->executed);
4956 executed = isl_union_map_intersect_domain(executed,
4958
4959 embed = !isl_set_is_params(data->build->domain);
4960 if (embed && !data->internal)
4961 executed = internal_executed(executed, space, data->build);
4962 if (!embed) {
4963 isl_set *domain;
4966 executed = isl_union_map_intersect_params(executed, domain);
4967 }
4968
4969 build = isl_ast_build_copy(data->build);
4970 build = isl_ast_build_product(build, space);
4971
4972 list = generate_next_level(executed, build);
4973
4974 list = isl_ast_graft_list_unembed(list, embed);
4975
4976 data->list = isl_ast_graft_list_concat(data->list, list);
4977
4978 return isl_stat_ok;
4979}
4980
4981/* Generate an AST that visits the elements in the range of data->executed
4982 * in the relative order specified by the corresponding domain element(s)
4983 * for those domain elements that belong to "set".
4984 * Add the result to data->list.
4985 *
4986 * The caller ensures that "set" is a universe domain.
4987 *
4988 * If the build space S is not parametric, then the space of "set"
4989 * need to be a wrapped relation with S as domain. That is, it needs
4990 * to be of the form
4991 *
4992 * [S -> T]
4993 *
4994 * Check this property and pass control to generate_code_in_space
4995 * passing along T.
4996 * If the build space is not parametric, then T is the space of "set".
4997 */
4999{
5000 struct isl_generate_code_data *data = user;
5001 isl_space *space, *build_space;
5002 int is_domain;
5003
5004 space = isl_set_get_space(set);
5005
5006 if (isl_set_is_params(data->build->domain))
5007 return generate_code_in_space(data, set, space);
5008
5009 build_space = isl_ast_build_get_space(data->build, data->internal);
5010 space = isl_space_unwrap(space);
5011 is_domain = isl_space_is_domain(build_space, space);
5012 isl_space_free(build_space);
5013 space = isl_space_range(space);
5014
5015 if (is_domain < 0)
5016 goto error;
5017 if (!is_domain)
5019 "invalid nested schedule space", goto error);
5020
5021 return generate_code_in_space(data, set, space);
5022error:
5024 isl_space_free(space);
5025 return isl_stat_error;
5026}
5027
5028/* Generate an AST that visits the elements in the range of "executed"
5029 * in the relative order specified by the corresponding domain element(s).
5030 *
5031 * "build" is an isl_ast_build that has either been constructed by
5032 * isl_ast_build_from_context or passed to a callback set by
5033 * isl_ast_build_set_create_leaf.
5034 * In the first case, the space of the isl_ast_build is typically
5035 * a parametric space, although this is currently not enforced.
5036 * In the second case, the space is never a parametric space.
5037 * If the space S is not parametric, then the domain space(s) of "executed"
5038 * need to be wrapped relations with S as domain.
5039 *
5040 * If the domain of "executed" consists of several spaces, then an AST
5041 * is generated for each of them (in arbitrary order) and the results
5042 * are concatenated.
5043 *
5044 * If "internal" is set, then the domain "S" above refers to the internal
5045 * schedule domain representation. Otherwise, it refers to the external
5046 * representation, as returned by isl_ast_build_get_schedule_space.
5047 *
5048 * We essentially run over all the spaces in the domain of "executed"
5049 * and call generate_code_set on each of them.
5050 */
5051static __isl_give isl_ast_graft_list *generate_code(
5053 int internal)
5054{
5055 isl_ctx *ctx;
5056 struct isl_generate_code_data data = { 0 };
5057 isl_space *space;
5058 isl_union_set *schedule_domain;
5060
5061 if (!build)
5062 goto error;
5063 space = isl_ast_build_get_space(build, 1);
5064 space = isl_space_align_params(space,
5066 space = isl_space_align_params(space,
5070 if (!executed || !build)
5071 goto error;
5072
5074
5075 data.internal = internal;
5076 data.executed = executed;
5077 data.build = build;
5078 data.list = isl_ast_graft_list_alloc(ctx, 0);
5079
5081 schedule_domain = isl_union_map_domain(universe);
5082 if (isl_union_set_foreach_set(schedule_domain, &generate_code_set,
5083 &data) < 0)
5084 data.list = isl_ast_graft_list_free(data.list);
5085
5086 isl_union_set_free(schedule_domain);
5088
5090 return data.list;
5091error:
5094 return NULL;
5095}
5096
5097/* Generate an AST that visits the elements in the domain of "schedule"
5098 * in the relative order specified by the corresponding image element(s).
5099 *
5100 * "build" is an isl_ast_build that has either been constructed by
5101 * isl_ast_build_from_context or passed to a callback set by
5102 * isl_ast_build_set_create_leaf.
5103 * In the first case, the space of the isl_ast_build is typically
5104 * a parametric space, although this is currently not enforced.
5105 * In the second case, the space is never a parametric space.
5106 * If the space S is not parametric, then the range space(s) of "schedule"
5107 * need to be wrapped relations with S as domain.
5108 *
5109 * If the range of "schedule" consists of several spaces, then an AST
5110 * is generated for each of them (in arbitrary order) and the results
5111 * are concatenated.
5112 *
5113 * We first initialize the local copies of the relevant options.
5114 * We do this here rather than when the isl_ast_build is created
5115 * because the options may have changed between the construction
5116 * of the isl_ast_build and the call to isl_generate_code.
5117 *
5118 * The main computation is performed on an inverse schedule (with
5119 * the schedule domain in the domain and the elements to be executed
5120 * in the range) called "executed".
5121 */
5137
5138/* The old name for isl_ast_build_node_from_schedule_map.
5139 * It is being kept for backward compatibility, but
5140 * it will be removed in the future.
5141 */
5147
5148/* Generate an AST that visits the elements in the domain of "executed"
5149 * in the relative order specified by the leaf node "node".
5150 *
5151 * The relation "executed" maps the outer generated loop iterators
5152 * to the domain elements executed by those iterations.
5153 *
5154 * Simply pass control to generate_inner_level.
5155 * Note that the current build does not refer to any band node, so
5156 * that generate_inner_level will not try to visit the child of
5157 * the leaf node.
5158 *
5159 * If multiple statement instances reach a leaf,
5160 * then they can be executed in any order.
5161 * Group the list of grafts based on shared guards
5162 * such that identical guards are only generated once
5163 * when the list is eventually passed on to isl_ast_graft_list_fuse.
5164 */
5178
5179/* Check that the band partial schedule "partial" does not filter out
5180 * any statement instances, as specified by the range of "executed".
5181 */
5185{
5187 isl_union_set *domain, *instances;
5188
5190 partial = isl_multi_union_pw_aff_copy(partial);
5194 isl_union_set_free(instances);
5195
5196 if (subset < 0)
5197 return isl_stat_error;
5198 if (!subset)
5200 "band node is not allowed to drop statement instances",
5201 return isl_stat_error);
5202 return isl_stat_ok;
5203}
5204
5205/* Generate an AST that visits the elements in the domain of "executed"
5206 * in the relative order specified by the band node "node" and its descendants.
5207 *
5208 * The relation "executed" maps the outer generated loop iterators
5209 * to the domain elements executed by those iterations.
5210 *
5211 * If the band is empty, we continue with its descendants.
5212 * Otherwise, we extend the build and the inverse schedule with
5213 * the additional space/partial schedule and continue generating
5214 * an AST in generate_next_level.
5215 * As soon as we have extended the inverse schedule with the additional
5216 * partial schedule, we look for equalities that may exists between
5217 * the old and the new part.
5218 */
5219static __isl_give isl_ast_graft_list *build_ast_from_band(
5222{
5223 isl_space *space;
5225 isl_union_map *extra_umap;
5226 isl_ast_graft_list *list;
5227 isl_size n1, n2;
5228 isl_size n;
5229
5231 if (!build || n < 0 || !executed)
5232 goto error;
5233
5234 if (n == 0)
5235 return build_ast_from_child(build, node, executed);
5236
5238 extra = isl_multi_union_pw_aff_align_params(extra,
5240 space = isl_multi_union_pw_aff_get_space(extra);
5241
5244
5245 extra_umap = isl_union_map_from_multi_union_pw_aff(extra);
5246 extra_umap = isl_union_map_reverse(extra_umap);
5247
5250
5254 if (n1 < 0 || n2 < 0)
5256 else if (n2 > n1)
5258 "band node is not allowed to introduce new parameters",
5261
5263
5265
5266 return list;
5267error:
5271 return NULL;
5272}
5273
5274/* Hoist a list of grafts (in practice containing a single graft)
5275 * from "sub_build" (which includes extra context information)
5276 * to "build".
5277 *
5278 * In particular, project out all additional parameters introduced
5279 * by the context node from the enforced constraints and the guard
5280 * of the single graft.
5281 */
5282static __isl_give isl_ast_graft_list *hoist_out_of_context(
5283 __isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build,
5284 __isl_keep isl_ast_build *sub_build)
5285{
5286 isl_ast_graft *graft;
5287 isl_basic_set *enforced;
5288 isl_set *guard;
5289 isl_size n_param, extra_param;
5290
5292 extra_param = isl_ast_build_dim(sub_build, isl_dim_param);
5293 if (n_param < 0 || extra_param < 0)
5294 return isl_ast_graft_list_free(list);
5295
5296 if (extra_param == n_param)
5297 return list;
5298
5299 extra_param -= n_param;
5300 enforced = isl_ast_graft_list_extract_shared_enforced(list, sub_build);
5301 enforced = isl_basic_set_project_out(enforced, isl_dim_param,
5302 n_param, extra_param);
5303 enforced = isl_basic_set_remove_unknown_divs(enforced);
5306 n_param, extra_param);
5307 guard = isl_set_project_out(guard, isl_dim_param, n_param, extra_param);
5308 guard = isl_set_compute_divs(guard);
5309 graft = isl_ast_graft_alloc_from_children(list, guard, enforced,
5310 build, sub_build);
5311 list = isl_ast_graft_list_from_ast_graft(graft);
5312
5313 return list;
5314}
5315
5316/* Generate an AST that visits the elements in the domain of "executed"
5317 * in the relative order specified by the context node "node"
5318 * and its descendants.
5319 *
5320 * The relation "executed" maps the outer generated loop iterators
5321 * to the domain elements executed by those iterations.
5322 *
5323 * The context node may introduce additional parameters as well as
5324 * constraints on the outer schedule dimensions or original parameters.
5325 *
5326 * We add the extra parameters to a new build and the context
5327 * constraints to both the build and (as a single disjunct)
5328 * to the domain of "executed". Since the context constraints
5329 * are specified in terms of the input schedule, we first need
5330 * to map them to the internal schedule domain.
5331 *
5332 * After constructing the AST from the descendants of "node",
5333 * we combine the list of grafts into a single graft within
5334 * the new build, in order to be able to exploit the additional
5335 * context constraints during this combination.
5336 *
5337 * Additionally, if the current node is the outermost node in
5338 * the schedule tree (apart from the root domain node), we generate
5339 * all pending guards, again to be able to exploit the additional
5340 * context constraints. We currently do not do this for internal
5341 * context nodes since we may still want to hoist conditions
5342 * to outer AST nodes.
5343 *
5344 * If the context node introduced any new parameters, then they
5345 * are removed from the set of enforced constraints and guard
5346 * in hoist_out_of_context.
5347 */
5348static __isl_give isl_ast_graft_list *build_ast_from_context(
5351{
5353 isl_space *space;
5354 isl_multi_aff *internal2input;
5355 isl_ast_build *sub_build;
5356 isl_ast_graft_list *list;
5357 isl_size n;
5358 isl_size depth;
5359
5361 if (depth < 0)
5363 space = isl_ast_build_get_space(build, 1);
5366 sub_build = isl_ast_build_copy(build);
5367 space = isl_set_get_space(context);
5368 sub_build = isl_ast_build_align_params(sub_build, space);
5369 internal2input = isl_ast_build_get_internal2input(sub_build);
5370 context = isl_set_preimage_multi_aff(context, internal2input);
5371 sub_build = isl_ast_build_restrict_generated(sub_build,
5376
5378 node, executed);
5379 n = isl_ast_graft_list_n_ast_graft(list);
5380 if (n < 0)
5381 list = isl_ast_graft_list_free(list);
5382
5383 list = isl_ast_graft_list_fuse(list, sub_build);
5384 if (depth == 1)
5386 sub_build);
5387 if (n >= 1)
5388 list = hoist_out_of_context(list, build, sub_build);
5389
5391 isl_ast_build_free(sub_build);
5392
5393 return list;
5394}
5395
5396/* Generate an AST that visits the elements in the domain of "executed"
5397 * in the relative order specified by the expansion node "node" and
5398 * its descendants.
5399 *
5400 * The relation "executed" maps the outer generated loop iterators
5401 * to the domain elements executed by those iterations.
5402 *
5403 * We expand the domain elements by the expansion and
5404 * continue with the descendants of the node.
5405 */
5406static __isl_give isl_ast_graft_list *build_ast_from_expansion(
5409{
5410 isl_union_map *expansion;
5411 isl_size n1, n2;
5412
5414 expansion = isl_union_map_align_params(expansion,
5416
5420 if (n1 < 0 || n2 < 0)
5421 goto error;
5422 if (n2 > n1)
5424 "expansion node is not allowed to introduce "
5425 "new parameters", goto error);
5426
5427 return build_ast_from_child(build, node, executed);
5428error:
5432 return NULL;
5433}
5434
5435/* Generate an AST that visits the elements in the domain of "executed"
5436 * in the relative order specified by the extension node "node" and
5437 * its descendants.
5438 *
5439 * The relation "executed" maps the outer generated loop iterators
5440 * to the domain elements executed by those iterations.
5441 *
5442 * Extend the inverse schedule with the extension applied to current
5443 * set of generated constraints. Since the extension if formulated
5444 * in terms of the input schedule, it first needs to be transformed
5445 * to refer to the internal schedule.
5446 */
5447static __isl_give isl_ast_graft_list *build_ast_from_extension(
5450{
5451 isl_union_set *schedule_domain;
5452 isl_union_map *extension;
5453 isl_set *set;
5454
5457 schedule_domain = isl_union_set_from_set(set);
5458
5460
5461 extension = isl_union_map_preimage_domain_multi_aff(extension,
5462 isl_multi_aff_copy(build->internal2input));
5463 extension = isl_union_map_intersect_domain(extension, schedule_domain);
5465 extension);
5467
5468 return build_ast_from_child(build, node, executed);
5469}
5470
5471/* Generate an AST that visits the elements in the domain of "executed"
5472 * in the relative order specified by the filter node "node" and
5473 * its descendants.
5474 *
5475 * The relation "executed" maps the outer generated loop iterators
5476 * to the domain elements executed by those iterations.
5477 *
5478 * We simply intersect the iteration domain (i.e., the range of "executed")
5479 * with the filter and continue with the descendants of the node,
5480 * unless the resulting inverse schedule is empty, in which
5481 * case we return an empty list.
5482 *
5483 * If the result of the intersection is equal to the original "executed"
5484 * relation, then keep the original representation since the intersection
5485 * may have unnecessarily broken up the relation into a greater number
5486 * of disjuncts.
5487 */
5488static __isl_give isl_ast_graft_list *build_ast_from_filter(
5491{
5492 isl_ctx *ctx;
5493 isl_union_set *filter;
5494 isl_union_map *orig;
5495 isl_ast_graft_list *list;
5496 int empty;
5497 isl_bool unchanged;
5498 isl_size n1, n2;
5499
5501 if (!build || !node || !executed)
5502 goto error;
5503
5505 filter = isl_union_set_align_params(filter,
5510 if (n1 < 0 || n2 < 0)
5511 goto error;
5512 if (n2 > n1)
5514 "filter node is not allowed to introduce "
5515 "new parameters", goto error);
5516
5517 unchanged = isl_union_map_is_subset(orig, executed);
5519 if (unchanged < 0 || empty < 0)
5520 goto error;
5521 if (unchanged) {
5523 return build_ast_from_child(build, node, orig);
5524 }
5525 isl_union_map_free(orig);
5526 if (!empty)
5527 return build_ast_from_child(build, node, executed);
5528
5530 list = isl_ast_graft_list_alloc(ctx, 0);
5534 return list;
5535error:
5539 isl_union_map_free(orig);
5540 return NULL;
5541}
5542
5543/* Generate an AST that visits the elements in the domain of "executed"
5544 * in the relative order specified by the guard node "node" and
5545 * its descendants.
5546 *
5547 * The relation "executed" maps the outer generated loop iterators
5548 * to the domain elements executed by those iterations.
5549 *
5550 * Ensure that the associated guard is enforced by the outer AST
5551 * constructs by adding it to the guard of the graft.
5552 * Since we know that we will enforce the guard, we can also include it
5553 * in the generated constraints used to construct an AST for
5554 * the descendant nodes.
5555 */
5556static __isl_give isl_ast_graft_list *build_ast_from_guard(
5559{
5560 isl_space *space;
5561 isl_set *guard, *hoisted;
5562 isl_basic_set *enforced;
5563 isl_ast_build *sub_build;
5564 isl_ast_graft *graft;
5565 isl_ast_graft_list *list;
5566 isl_size n1, n2, n;
5567
5568 space = isl_ast_build_get_space(build, 1);
5570 n1 = isl_space_dim(space, isl_dim_param);
5571 guard = isl_set_align_params(guard, space);
5572 n2 = isl_set_dim(guard, isl_dim_param);
5573 if (n1 < 0 || n2 < 0)
5574 guard = isl_set_free(guard);
5575 else if (n2 > n1)
5577 "guard node is not allowed to introduce "
5578 "new parameters", guard = isl_set_free(guard));
5579 guard = isl_set_preimage_multi_aff(guard,
5580 isl_multi_aff_copy(build->internal2input));
5581 guard = isl_ast_build_specialize(build, guard);
5582 guard = isl_set_gist(guard, isl_set_copy(build->generated));
5583
5584 sub_build = isl_ast_build_copy(build);
5585 sub_build = isl_ast_build_restrict_generated(sub_build,
5586 isl_set_copy(guard));
5587
5589 node, executed);
5590
5592 n = isl_set_n_basic_set(hoisted);
5593 if (n < 0)
5594 list = isl_ast_graft_list_free(list);
5595 if (n > 1)
5597 isl_set_copy(hoisted));
5598 guard = isl_set_intersect(guard, hoisted);
5599 enforced = extract_shared_enforced(list, build);
5600 graft = isl_ast_graft_alloc_from_children(list, guard, enforced,
5601 build, sub_build);
5602
5603 isl_ast_build_free(sub_build);
5605 return isl_ast_graft_list_from_ast_graft(graft);
5606}
5607
5608/* Call the before_each_mark callback, if requested by the user.
5609 *
5610 * Return 0 on success and -1 on error.
5611 *
5612 * The caller is responsible for recording the current inverse schedule
5613 * in "build".
5614 */
5617{
5618 if (!build)
5619 return isl_stat_error;
5620 if (!build->before_each_mark)
5621 return isl_stat_ok;
5622 return build->before_each_mark(mark, build,
5624}
5625
5626/* Call the after_each_mark callback, if requested by the user.
5627 *
5628 * The caller is responsible for recording the current inverse schedule
5629 * in "build".
5630 */
5633{
5634 if (!graft || !build)
5635 return isl_ast_graft_free(graft);
5636 if (!build->after_each_mark)
5637 return graft;
5638 graft->node = build->after_each_mark(graft->node, build,
5640 if (!graft->node)
5641 return isl_ast_graft_free(graft);
5642 return graft;
5643}
5644
5645
5646/* Generate an AST that visits the elements in the domain of "executed"
5647 * in the relative order specified by the mark node "node" and
5648 * its descendants.
5649 *
5650 * The relation "executed" maps the outer generated loop iterators
5651 * to the domain elements executed by those iterations.
5652
5653 * Since we may be calling before_each_mark and after_each_mark
5654 * callbacks, we record the current inverse schedule in the build.
5655 *
5656 * We generate an AST for the child of the mark node, combine
5657 * the graft list into a single graft and then insert the mark
5658 * in the AST of that single graft.
5659 */
5660static __isl_give isl_ast_graft_list *build_ast_from_mark(
5663{
5664 isl_id *mark;
5665 isl_ast_graft *graft;
5666 isl_ast_graft_list *list;
5667 isl_size n;
5668
5670
5671 mark = isl_schedule_node_mark_get_id(node);
5672 if (before_each_mark(mark, build) < 0)
5673 node = isl_schedule_node_free(node);
5674
5677 n = isl_ast_graft_list_n_ast_graft(list);
5678 if (n < 0)
5679 list = isl_ast_graft_list_free(list);
5680 if (n == 0) {
5681 isl_id_free(mark);
5682 } else {
5683 graft = isl_ast_graft_list_get_ast_graft(list, 0);
5684 graft = isl_ast_graft_insert_mark(graft, mark);
5685 graft = after_each_mark(graft, build);
5686 list = isl_ast_graft_list_set_ast_graft(list, 0, graft);
5687 }
5689
5690 return list;
5691}
5692
5693static __isl_give isl_ast_graft_list *build_ast_from_schedule_node(
5696
5697/* Generate an AST that visits the elements in the domain of "executed"
5698 * in the relative order specified by the sequence (or set) node "node" and
5699 * its descendants.
5700 *
5701 * The relation "executed" maps the outer generated loop iterators
5702 * to the domain elements executed by those iterations.
5703 *
5704 * We simply generate an AST for each of the children and concatenate
5705 * the results.
5706 */
5707static __isl_give isl_ast_graft_list *build_ast_from_sequence(
5710{
5711 int i;
5712 isl_size n;
5713 isl_ctx *ctx;
5714 isl_ast_graft_list *list;
5715
5717 list = isl_ast_graft_list_alloc(ctx, 0);
5718
5720 if (n < 0)
5721 list = isl_ast_graft_list_free(list);
5722 for (i = 0; i < n; ++i) {
5723 isl_schedule_node *child;
5724 isl_ast_graft_list *list_i;
5725
5726 child = isl_schedule_node_get_child(node, i);
5729 list = isl_ast_graft_list_concat(list, list_i);
5730 }
5734
5735 return list;
5736}
5737
5738/* Generate an AST that visits the elements in the domain of "executed"
5739 * in the relative order specified by the node "node" and its descendants.
5740 *
5741 * The relation "executed" maps the outer generated loop iterators
5742 * to the domain elements executed by those iterations.
5743 *
5744 * The node types are handled in separate functions.
5745 * Set nodes are currently treated in the same way as sequence nodes.
5746 * The children of a set node may be executed in any order,
5747 * including the order of the children.
5748 */
5749static __isl_give isl_ast_graft_list *build_ast_from_schedule_node(
5752{
5754
5756
5757 switch (type) {
5759 goto error;
5761 return build_ast_from_leaf(build, node, executed);
5763 return build_ast_from_band(build, node, executed);
5765 return build_ast_from_context(build, node, executed);
5768 "unexpected internal domain node", goto error);
5774 return build_ast_from_filter(build, node, executed);
5776 return build_ast_from_guard(build, node, executed);
5778 return build_ast_from_mark(build, node, executed);
5781 return build_ast_from_sequence(build, node, executed);
5782 }
5783
5785 "unhandled type", goto error);
5786error:
5790
5791 return NULL;
5792}
5793
5794/* Generate an AST that visits the elements in the domain of "executed"
5795 * in the relative order specified by the (single) child of "node" and
5796 * its descendants.
5797 *
5798 * The relation "executed" maps the outer generated loop iterators
5799 * to the domain elements executed by those iterations.
5800 *
5801 * This function is never called on a leaf, set or sequence node,
5802 * so the node always has exactly one child.
5803 */
5811
5812/* Generate an AST that visits the elements in the domain of the domain
5813 * node "node" in the relative order specified by its descendants.
5814 *
5815 * An initial inverse schedule is created that maps a zero-dimensional
5816 * schedule space to the node domain.
5817 * The input "build" is assumed to have a parametric domain and
5818 * is replaced by the same zero-dimensional schedule space.
5819 *
5820 * We also add some of the parameter constraints in the build domain
5821 * to the executed relation. Adding these constraints
5822 * allows for an earlier detection of conflicts in some cases.
5823 * However, we do not want to divide the executed relation into
5824 * more disjuncts than necessary. We therefore approximate
5825 * the constraints on the parameters by a single disjunct set.
5826 */
5829{
5830 isl_ctx *ctx;
5831 isl_union_set *domain, *schedule_domain;
5833 isl_space *space;
5834 isl_set *set;
5835 isl_ast_graft_list *list;
5836 isl_ast_node *ast;
5837 int is_params;
5838
5839 if (!build)
5840 goto error;
5841
5843 space = isl_ast_build_get_space(build, 1);
5844 is_params = isl_space_is_params(space);
5845 isl_space_free(space);
5846 if (is_params < 0)
5847 goto error;
5848 if (!is_params)
5850 "expecting parametric initial context", goto error);
5851
5854
5856 space = isl_space_set_from_params(space);
5858
5861 schedule_domain = isl_union_set_from_set(set);
5862
5867
5868 return ast;
5869error:
5872 return NULL;
5873}
5874
5875/* Generate an AST that visits the elements in the domain of "schedule"
5876 * in the relative order specified by the schedule tree.
5877 *
5878 * "build" is an isl_ast_build that has been created using
5879 * isl_ast_build_alloc or isl_ast_build_from_context based
5880 * on a parametric set.
5881 *
5882 * The construction starts at the root node of the schedule,
5883 * which is assumed to be a domain node.
5884 */
5887{
5888 isl_ctx *ctx;
5889 isl_schedule_node *node;
5890
5891 if (!build || !schedule)
5892 goto error;
5893
5895
5897 if (!node)
5898 goto error;
5900
5904 "expecting root domain node",
5906 return build_ast_from_domain(build, node);
5907error:
5909 return NULL;
5910}
__isl_give isl_aff * isl_aff_add_constant_si(__isl_take isl_aff *aff, int v)
Definition isl_aff.c:1099
__isl_give isl_pw_multi_aff * isl_pw_multi_aff_set_pw_aff(__isl_take isl_pw_multi_aff *pma, unsigned pos, __isl_take isl_pw_aff *pa)
Definition isl_aff.c:6620
__isl_null isl_aff * isl_aff_free(__isl_take isl_aff *aff)
Definition isl_aff.c:449
int isl_pw_aff_plain_cmp(__isl_keep isl_pw_aff *pa1, __isl_keep isl_pw_aff *pa2)
Definition isl_aff.c:7694
__isl_export __isl_give isl_union_set * isl_multi_union_pw_aff_domain(__isl_take isl_multi_union_pw_aff *mupa)
Definition isl_aff.c:9393
__isl_export __isl_give isl_aff * isl_aff_neg(__isl_take isl_aff *aff)
Definition isl_aff.c:1451
__isl_overload __isl_give isl_aff * isl_aff_scale_val(__isl_take isl_aff *aff, __isl_take isl_val *v)
Definition isl_aff.c:2075
__isl_give isl_val * isl_aff_get_denominator_val(__isl_keep isl_aff *aff)
Definition isl_aff.c:819
__isl_null isl_pw_aff * isl_pw_aff_free(__isl_take isl_pw_aff *pwaff)
__isl_overload __isl_give isl_union_map * isl_union_map_from_multi_union_pw_aff(__isl_take isl_multi_union_pw_aff *mupa)
Definition isl_aff.c:9157
__isl_overload __isl_give isl_aff * isl_aff_scale_down_val(__isl_take isl_aff *aff, __isl_take isl_val *v)
Definition isl_aff.c:2142
__isl_give isl_aff * isl_aff_copy(__isl_keep isl_aff *aff)
Definition isl_aff.c:145
__isl_export __isl_give isl_set * isl_pw_aff_gt_set(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2)
Definition isl_aff.c:3175
__isl_export isl_stat isl_pw_multi_aff_foreach_piece(__isl_keep isl_pw_multi_aff *pma, isl_stat(*fn)(__isl_take isl_set *set, __isl_take isl_multi_aff *maff, void *user), void *user)
__isl_export __isl_give isl_aff * isl_aff_floor(__isl_take isl_aff *aff)
Definition isl_aff.c:1729
__isl_give isl_aff * isl_aff_add_coefficient_si(__isl_take isl_aff *aff, enum isl_dim_type type, int pos, int v)
Definition isl_aff.c:1426
__isl_give isl_aff * isl_aff_zero_on_domain(__isl_take isl_local_space *ls)
Definition isl_aff.c:235
__isl_constructor __isl_give isl_pw_aff * isl_pw_aff_from_aff(__isl_take isl_aff *aff)
isl_size isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type)
Definition isl_aff.c:509
__isl_export __isl_give isl_aff * isl_aff_sub(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2)
Definition isl_aff.c:2029
__isl_export __isl_give isl_val * isl_aff_get_constant_val(__isl_keep isl_aff *aff)
Definition isl_aff.c:834
isl_bool isl_pw_aff_every_piece(__isl_keep isl_pw_aff *pa, isl_bool(*test)(__isl_keep isl_set *set, __isl_keep isl_aff *aff, void *user), void *user)
__isl_give isl_pw_multi_aff * isl_pw_multi_aff_from_map(__isl_take isl_map *map)
Definition isl_aff.c:5617
__isl_export __isl_give isl_pw_aff * isl_pw_aff_ceil(__isl_take isl_pw_aff *pwaff)
Definition isl_aff.c:3406
__isl_export __isl_give isl_aff * isl_aff_add(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2)
Definition isl_aff.c:1976
__isl_null isl_pw_multi_aff * isl_pw_multi_aff_free(__isl_take isl_pw_multi_aff *pma)
__isl_export __isl_give isl_pw_aff * isl_pw_aff_add(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2)
Definition isl_aff.c:3611
__isl_export __isl_give isl_aff * isl_aff_ceil(__isl_take isl_aff *aff)
Definition isl_aff.c:1873
__isl_export __isl_give isl_pw_aff * isl_pw_aff_coalesce(__isl_take isl_pw_aff *pa)
__isl_give isl_pw_multi_aff * isl_pw_multi_aff_copy(__isl_keep isl_pw_multi_aff *pma)
__isl_give isl_pw_aff * isl_pw_multi_aff_get_pw_aff(__isl_keep isl_pw_multi_aff *pma, int pos)
Definition isl_aff.c:6332
__isl_give isl_set * isl_pw_aff_list_le_set(__isl_take isl_pw_aff_list *list1, __isl_take isl_pw_aff_list *list2)
Definition isl_aff.c:3334
__isl_give isl_pw_aff * isl_pw_aff_copy(__isl_keep isl_pw_aff *pwaff)
__isl_give isl_pw_multi_aff * isl_pw_multi_aff_identity(__isl_take isl_space *space)
Definition isl_aff.c:4471
struct isl_multi_aff isl_multi_aff
Definition aff_type.h:29
struct isl_multi_union_pw_aff isl_multi_union_pw_aff
Definition aff_type.h:46
__isl_give isl_ast_node * isl_ast_node_set_annotation(__isl_take isl_ast_node *node, __isl_take isl_id *annotation)
__isl_null isl_ast_expr * isl_ast_expr_free(__isl_take isl_ast_expr *expr)
Definition isl_ast.c:243
__isl_give isl_ast_expr * isl_ast_expr_from_val(__isl_take isl_val *v)
Definition isl_ast.c:589
__isl_null isl_ast_node * isl_ast_node_free(__isl_take isl_ast_node *node)
Definition isl_ast.c:1180
__isl_give isl_ast_expr * isl_ast_expr_copy(__isl_keep isl_ast_expr *expr)
Definition isl_ast.c:195
__isl_give isl_ast_build * isl_ast_build_copy(__isl_keep isl_ast_build *build)
int isl_options_get_ast_build_separation_bounds(isl_ctx *ctx)
int isl_options_get_ast_build_group_coscheduled(isl_ctx *ctx)
__isl_null isl_ast_build * isl_ast_build_free(__isl_take isl_ast_build *build)
int isl_options_get_ast_build_atomic_upper_bound(isl_ctx *ctx)
int isl_options_get_ast_build_scale_strides(isl_ctx *ctx)
isl_ctx * isl_ast_build_get_ctx(__isl_keep isl_ast_build *build)
int isl_options_get_ast_build_exploit_nested_bounds(isl_ctx *ctx)
#define ISL_AST_BUILD_SEPARATION_BOUNDS_EXPLICIT
Definition ast_build.h:32
isl_ast_loop_type
Definition ast_type.h:91
@ isl_ast_loop_atomic
Definition ast_type.h:94
@ isl_ast_loop_separate
Definition ast_type.h:96
@ isl_ast_loop_unroll
Definition ast_type.h:95
isl_ast_expr_op_type
Definition ast_type.h:16
@ isl_ast_expr_op_min
Definition ast_type.h:23
@ isl_ast_expr_op_le
Definition ast_type.h:36
@ isl_ast_expr_op_lt
Definition ast_type.h:37
@ isl_ast_expr_op_max
Definition ast_type.h:22
isl_size isl_constraint_dim(__isl_keep isl_constraint *constraint, enum isl_dim_type type)
__isl_give isl_map * isl_map_add_constraint(__isl_take isl_map *map, __isl_take isl_constraint *constraint)
__isl_give isl_constraint * isl_constraint_set_constant_val(__isl_take isl_constraint *constraint, __isl_take isl_val *v)
__isl_give isl_aff * isl_constraint_get_bound(__isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos)
isl_bool isl_constraint_is_upper_bound(__isl_keep isl_constraint *constraint, enum isl_dim_type type, unsigned pos)
__isl_null isl_constraint * isl_constraint_free(__isl_take isl_constraint *c)
__isl_give isl_constraint * isl_constraint_copy(__isl_keep isl_constraint *c)
__isl_give isl_constraint * isl_constraint_alloc_equality(__isl_take isl_local_space *ls)
__isl_give isl_constraint * isl_equality_from_aff(__isl_take isl_aff *aff)
isl_bool isl_constraint_involves_dims(__isl_keep isl_constraint *constraint, enum isl_dim_type type, unsigned first, unsigned n)
__isl_give isl_basic_set * isl_basic_set_add_constraint(__isl_take isl_basic_set *bset, __isl_take isl_constraint *constraint)
__isl_give isl_constraint_list * isl_basic_set_get_constraint_list(__isl_keep isl_basic_set *bset)
isl_bool isl_constraint_is_lower_bound(__isl_keep isl_constraint *constraint, enum isl_dim_type type, unsigned pos)
isl_stat isl_basic_set_foreach_constraint(__isl_keep isl_basic_set *bset, isl_stat(*fn)(__isl_take isl_constraint *c, void *user), void *user)
__isl_give isl_basic_set * isl_basic_set_from_constraint(__isl_take isl_constraint *constraint)
__isl_give isl_val * isl_constraint_get_coefficient_val(__isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos)
__isl_give isl_set * isl_set_add_constraint(__isl_take isl_set *set, __isl_take isl_constraint *constraint)
isl_stat isl_basic_map_foreach_constraint(__isl_keep isl_basic_map *bmap, isl_stat(*fn)(__isl_take isl_constraint *c, void *user), void *user)
__isl_give isl_constraint * isl_constraint_set_coefficient_si(__isl_take isl_constraint *constraint, enum isl_dim_type type, int pos, int v)
#define __isl_take
Definition ctx.h:22
isl_stat
Definition ctx.h:84
@ isl_stat_error
Definition ctx.h:85
@ isl_stat_ok
Definition ctx.h:86
#define __isl_give
Definition ctx.h:19
#define isl_die(ctx, errno, msg, code)
Definition ctx.h:138
isl_bool isl_bool_ok(int b)
Definition isl_ctx.c:58
@ isl_error_unsupported
Definition ctx.h:82
@ isl_error_invalid
Definition ctx.h:80
@ isl_error_internal
Definition ctx.h:79
#define isl_calloc_array(ctx, type, n)
Definition ctx.h:133
#define __isl_keep
Definition ctx.h:25
int isl_size
Definition ctx.h:97
isl_bool isl_bool_not(isl_bool b)
Definition isl_ctx.c:44
isl_bool
Definition ctx.h:89
@ isl_bool_false
Definition ctx.h:91
@ isl_bool_true
Definition ctx.h:92
@ isl_bool_error
Definition ctx.h:90
m
Definition guard1-0.c:2
__isl_export __isl_give ISL_HMAP __isl_take ISL_KEY __isl_take ISL_VAL * val
Definition hmap.h:32
isl_stat isl_stat(* fn)(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user)
Definition hmap.h:37
isl_stat isl_stat void * user
Definition hmap.h:39
isl_bool isl_bool(* test)(__isl_keep ISL_KEY *key, __isl_keep ISL_VAL *val, void *user)
Definition hmap.h:41
__isl_null isl_id * isl_id_free(__isl_take isl_id *id)
Definition isl_id.c:207
__isl_export __isl_give isl_val * isl_set_max_val(__isl_keep isl_set *set, __isl_keep isl_aff *obj)
Definition isl_ilp.c:612
int GMPQAPI cmp(mp_rat op1, mp_rat op2)
void GMPZAPI neg(mp_int rop, mp_int op)
void GMPZAPI gcd(mp_int rop, mp_int op1, mp_int op2)
void GMPQAPI init(mp_rat x)
__isl_give isl_ast_node * isl_ast_node_for_mark_degenerate(__isl_take isl_ast_node *node)
Definition isl_ast.c:1358
__isl_give isl_ast_expr * isl_ast_expr_op_add_arg(__isl_take isl_ast_expr *expr, __isl_take isl_ast_expr *arg)
Definition isl_ast.c:448
__isl_give isl_ast_expr * isl_ast_expr_alloc_int_si(isl_ctx *ctx, int i)
Definition isl_ast.c:568
__isl_give isl_ast_node * isl_ast_node_alloc_for(__isl_take isl_id *id)
Definition isl_ast.c:955
__isl_give isl_ast_expr * isl_ast_expr_alloc_binary(enum isl_ast_expr_op_type type, __isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2)
Definition isl_ast.c:666
__isl_give isl_ast_expr * isl_ast_expr_alloc_op(isl_ctx *ctx, enum isl_ast_expr_op_type op, int n_arg)
Definition isl_ast.c:186
__isl_give isl_ast_build * isl_ast_build_increase_depth(__isl_take isl_ast_build *build)
int isl_ast_build_has_value(__isl_keep isl_ast_build *build)
__isl_give isl_set * isl_ast_build_eliminate_inner(__isl_keep isl_ast_build *build, __isl_take isl_set *set)
__isl_give isl_aff * isl_ast_build_get_offset(__isl_keep isl_ast_build *build, int pos)
enum isl_ast_loop_type isl_ast_build_get_loop_type(__isl_keep isl_ast_build *build, int isolated)
__isl_give isl_map * isl_ast_build_map_to_iterator(__isl_keep isl_ast_build *build, __isl_take isl_set *set)
__isl_give isl_set * isl_ast_build_specialize(__isl_keep isl_ast_build *build, __isl_take isl_set *set)
isl_bool isl_ast_build_has_stride(__isl_keep isl_ast_build *build, int pos)
__isl_give isl_basic_set * isl_ast_build_compute_gist_basic_set(__isl_keep isl_ast_build *build, __isl_take isl_basic_set *bset)
__isl_give isl_ast_build * isl_ast_build_align_params(__isl_take isl_ast_build *build, __isl_take isl_space *model)
__isl_give isl_ast_build * isl_ast_build_extract_isolated(__isl_take isl_ast_build *build)
__isl_give isl_set * isl_ast_build_eliminate_divs(__isl_keep isl_ast_build *build, __isl_take isl_set *set)
__isl_give isl_ast_build * isl_ast_build_scale_down(__isl_take isl_ast_build *build, __isl_take isl_val *m, __isl_take isl_union_map *umap)
__isl_give isl_pw_aff * isl_ast_build_compute_gist_pw_aff(__isl_keep isl_ast_build *build, __isl_take isl_pw_aff *pa)
__isl_give isl_ast_build * isl_ast_build_detect_strides(__isl_take isl_ast_build *build, __isl_take isl_set *set)
__isl_give isl_ast_build * isl_ast_build_reset_schedule_node(__isl_take isl_ast_build *build)
__isl_give isl_ast_build * isl_ast_build_clear_local_info(__isl_take isl_ast_build *build)
__isl_give isl_set * isl_ast_build_compute_gist(__isl_keep isl_ast_build *build, __isl_take isl_set *set)
__isl_give isl_set * isl_ast_build_get_generated(__isl_keep isl_ast_build *build)
__isl_give isl_aff * isl_ast_build_compute_gist_aff(__isl_keep isl_ast_build *build, __isl_take isl_aff *aff)
__isl_give isl_map * isl_ast_build_get_schedule_map(__isl_keep isl_ast_build *build)
__isl_give isl_union_map * isl_ast_build_substitute_values_union_map_domain(__isl_keep isl_ast_build *build, __isl_take isl_union_map *umap)
int isl_ast_build_has_schedule_node(__isl_keep isl_ast_build *build)
__isl_give isl_map * isl_ast_build_get_separation_class(__isl_keep isl_ast_build *build)
__isl_give isl_ast_build * isl_ast_build_replace_pending_by_guard(__isl_take isl_ast_build *build, __isl_take isl_set *guard)
__isl_give isl_space * isl_ast_build_get_space(__isl_keep isl_ast_build *build, int internal)
int isl_ast_build_has_isolated(__isl_keep isl_ast_build *build)
__isl_give isl_set * isl_ast_build_get_stride_constraint(__isl_keep isl_ast_build *build)
__isl_give isl_val * isl_ast_build_get_stride(__isl_keep isl_ast_build *build, int pos)
__isl_give isl_ast_build * isl_ast_build_set_executed(__isl_take isl_ast_build *build, __isl_take isl_union_map *executed)
__isl_give isl_multi_aff * isl_ast_build_get_stride_expansion(__isl_keep isl_ast_build *build)
isl_size isl_ast_build_get_depth(__isl_keep isl_ast_build *build)
__isl_give isl_set * isl_ast_build_get_domain(__isl_keep isl_ast_build *build)
__isl_give isl_ast_build * isl_ast_build_set_loop_bounds(__isl_take isl_ast_build *build, __isl_take isl_basic_set *bounds)
__isl_give isl_ast_build * isl_ast_build_restrict_generated(__isl_take isl_ast_build *build, __isl_take isl_set *set)
__isl_give isl_set * isl_ast_build_get_option_domain(__isl_keep isl_ast_build *build, enum isl_ast_loop_type type)
__isl_give isl_id * isl_ast_build_get_iterator_id(__isl_keep isl_ast_build *build, int pos)
__isl_give isl_ast_build * isl_ast_build_set_pending_generated(__isl_take isl_ast_build *build, __isl_take isl_basic_set *bounds)
__isl_give isl_set * isl_ast_build_get_isolated(__isl_keep isl_ast_build *build)
__isl_give isl_schedule_node * isl_ast_build_get_schedule_node(__isl_keep isl_ast_build *build)
int isl_ast_build_options_involve_depth(__isl_keep isl_ast_build *build)
isl_size isl_ast_build_dim(__isl_keep isl_ast_build *build, enum isl_dim_type type)
__isl_give isl_ast_build * isl_ast_build_product(__isl_take isl_ast_build *build, __isl_take isl_space *space)
__isl_give isl_ast_build * isl_ast_build_insert_dim(__isl_take isl_ast_build *build, int pos)
isl_bool isl_ast_build_has_affine_value(__isl_keep isl_ast_build *build, int pos)
__isl_give isl_set * isl_ast_build_get_pending(__isl_keep isl_ast_build *build)
__isl_give isl_set * isl_ast_build_eliminate(__isl_keep isl_ast_build *build, __isl_take isl_set *domain)
__isl_give isl_ast_build * isl_ast_build_set_schedule_node(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node)
__isl_give isl_basic_set * isl_ast_build_specialize_basic_set(__isl_keep isl_ast_build *build, __isl_take isl_basic_set *bset)
__isl_give isl_multi_aff * isl_ast_build_get_internal2input(__isl_keep isl_ast_build *build)
__isl_give isl_ast_expr * isl_ast_build_expr_from_pw_aff_internal(__isl_keep isl_ast_build *build, __isl_take isl_pw_aff *pa)
static int cmp_constraint(__isl_keep isl_constraint *a, __isl_keep isl_constraint *b, void *user)
__isl_give isl_ast_expr * isl_ast_build_expr_from_set_internal(__isl_keep isl_ast_build *build, __isl_take isl_set *set)
static isl_bool after_in_set(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node)
static isl_bool domain_follows_at_depth(__isl_keep isl_basic_set *i, __isl_keep isl_basic_set *j, void *user)
static __isl_give isl_ast_graft * set_for_cond_from_set(__isl_take isl_ast_graft *graft, __isl_keep isl_set *set, __isl_keep isl_ast_build *build)
static __isl_give isl_set * isl_set_coalesce_preserve(__isl_take isl_set *set)
static isl_stat check_band_schedule_total_on_instances(__isl_keep isl_multi_union_pw_aff *partial, __isl_keep isl_union_map *executed)
__isl_give isl_ast_node * isl_ast_build_node_from_schedule(__isl_keep isl_ast_build *build, __isl_take isl_schedule *schedule)
static __isl_give isl_ast_graft_list * generate_sorted_domains(__isl_keep isl_basic_set_list *domain_list, __isl_keep isl_union_map *executed, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * generate_shifted_component_tree_unroll(__isl_take isl_union_map *executed, __isl_take isl_set *domain, __isl_take isl_ast_build *build)
static isl_stat count_constraints(__isl_take isl_constraint *c, void *user)
static isl_bool has_pure_outer_disjunction(__isl_keep isl_set *domain, __isl_keep isl_ast_build *build)
static __isl_give isl_union_map * plug_in_values(__isl_take isl_union_map *executed, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft * refine_generic_split(__isl_take isl_ast_graft *graft, __isl_take isl_constraint_list *list, __isl_keep isl_set *domain, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * generate_shifted_component_tree_base(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build, int isolated)
static __isl_give isl_ast_graft_list * build_ast_from_filter(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static __isl_give isl_ast_graft_list * build_ast_from_mark(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static isl_stat add_domain(__isl_take isl_map *executed, struct isl_generate_domain_data *data)
static __isl_give isl_ast_graft_list * build_ast_from_leaf(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static isl_stat generate_code_in_space(struct isl_generate_code_data *data, __isl_take isl_set *set, __isl_take isl_space *space)
static __isl_give isl_pw_aff_list * upper_bounds(__isl_keep isl_constraint_list *constraints, int pos, __isl_keep isl_set *domain, __isl_keep isl_ast_build *build)
static __isl_give isl_union_map * internal_executed(__isl_take isl_union_map *executed, __isl_keep isl_space *space, __isl_keep isl_ast_build *build)
static __isl_give isl_aff * find_unroll_lower_bound(__isl_keep isl_ast_build *build, __isl_keep isl_set *domain, int depth, __isl_keep isl_basic_map *expansion, int *n)
static __isl_give isl_ast_graft * at_each_domain(__isl_take isl_ast_graft *graft, __isl_keep isl_map *executed, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * build_ast_from_extension(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static isl_stat generate_sorted_domains_wrap(__isl_take isl_basic_set_list *scc, void *user)
static int has_anchored_subtree(__isl_keep isl_ast_build *build)
static isl_stat update_n_div(__isl_take isl_set *set, __isl_take isl_multi_aff *ma, void *user)
__isl_give isl_ast_node * isl_ast_build_ast_from_schedule(__isl_keep isl_ast_build *build, __isl_take isl_union_map *schedule)
static isl_bool shared_outer(__isl_keep isl_basic_set *i, __isl_keep isl_basic_set *j, void *user)
static __isl_give isl_ast_graft_list * build_ast_from_context(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static int foreach_iteration(__isl_take isl_set *domain, __isl_keep isl_ast_build *build, int(*init)(int n, void *user), int(*fn)(__isl_take isl_basic_set *bset, void *user), void *user)
static __isl_give isl_pw_aff * exact_bound(__isl_keep isl_set *domain, __isl_keep isl_ast_build *build, int upper)
static __isl_give isl_ast_graft_list * generate_parallel_domains(__isl_keep isl_basic_set_list *domain_list, __isl_keep isl_union_map *executed, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * generate_shifted_component_tree_separate(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build)
static isl_bool after_in_tree(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node)
static __isl_give isl_basic_set_list * isl_basic_set_list_from_set(__isl_take isl_set *set)
static isl_stat generate_code_set(__isl_take isl_set *set, void *user)
static __isl_give isl_ast_graft_list * generate_shifted_component_only_after(__isl_take isl_union_map *executed, __isl_take isl_set *isolated, __isl_take isl_set *after, __isl_take isl_ast_build *build, __isl_take isl_set *dead1, __isl_take isl_set *dead2)
static __isl_give isl_ast_node * before_each_for(__isl_take isl_ast_node *node, __isl_keep isl_ast_build *build)
static int constraint_type(isl_constraint *c, int pos)
static __isl_give isl_set * extract_disjunction(__isl_take isl_set *domain, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * generate_next_level(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build)
static __isl_give isl_ast_graft * set_for_node_expressions(__isl_take isl_ast_graft *graft, __isl_keep isl_pw_aff_list *lower, int use_list, __isl_keep isl_pw_aff_list *upper_list, __isl_keep isl_set *upper_set, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_node * build_ast_from_domain(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node)
static isl_stat generate_domain(__isl_take isl_map *executed, void *user)
static __isl_give isl_ast_graft * after_each_for(__isl_take isl_ast_graft *graft, __isl_keep isl_ast_build *build)
static int use_upper_bound_list(isl_ctx *ctx, int n_upper, __isl_keep isl_set *domain, int depth)
static int reduce_list_cmp(__isl_keep isl_pw_aff *a, __isl_keep isl_pw_aff *b, void *user)
static __isl_give isl_set * explicit_bounds(__isl_take isl_map *map, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * generate_code(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build, int internal)
static isl_stat basic_map_check_scaled(__isl_take isl_basic_map *bmap, void *user)
static __isl_give isl_ast_graft_list * build_ast_from_schedule_node(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static int do_unroll_tree_iteration(__isl_take isl_basic_set *bset, void *user)
static __isl_give isl_ast_graft * set_for_cond_from_list(__isl_take isl_ast_graft *graft, __isl_keep isl_pw_aff_list *list, __isl_keep isl_ast_build *build)
static isl_bool aff_constant_is_negative(__isl_keep isl_set *set, __isl_keep isl_aff *aff, void *user)
static int cmp_constraint(__isl_keep isl_constraint *a, __isl_keep isl_constraint *b, void *user)
static isl_stat compute_class_domains(__isl_take isl_point *pnt, void *user)
static __isl_give isl_ast_graft * create_node(__isl_take isl_union_map *executed, __isl_take isl_basic_set *bounds, __isl_take isl_set *domain, __isl_take isl_ast_build *build)
static __isl_give isl_basic_set * extract_shared_enforced(__isl_keep isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
static int is_better_lower_bound(struct isl_find_unroll_data *data, __isl_keep isl_aff *lower, __isl_keep isl_val *n)
__isl_give isl_ast_node * isl_ast_build_node_from_schedule_map(__isl_keep isl_ast_build *build, __isl_take isl_union_map *schedule)
static __isl_give isl_ast_graft_list * generate_shifted_component_flat(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build)
static isl_bool after_in_filter(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node)
static __isl_give isl_union_set * child_filter(__isl_keep isl_schedule_node *node, int i)
static isl_stat update_unrolling_lower_bound(struct isl_find_unroll_data *data, __isl_keep isl_constraint *c)
static int dim_is_fixed(__isl_keep isl_set *set, int pos)
static __isl_give isl_pw_aff_list * lower_bounds(__isl_keep isl_constraint_list *constraints, int pos, __isl_keep isl_set *domain, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * build_ast_from_child(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static __isl_give isl_ast_graft * set_enforced_from_list(__isl_take isl_ast_graft *graft, __isl_keep isl_pw_aff_list *lower, __isl_keep isl_pw_aff_list *upper)
static int init_unroll_tree(int n, void *user)
static __isl_give isl_ast_graft * after_each_mark(__isl_take isl_ast_graft *graft, __isl_keep isl_ast_build *build)
static isl_bool pw_aff_constant_is_negative(__isl_keep isl_pw_aff *pa, void *user)
static isl_stat generate_non_single_valued(__isl_take isl_map *executed, struct isl_generate_domain_data *data)
static __isl_give isl_ast_graft_list * add_node(__isl_take isl_ast_graft_list *list, __isl_take isl_union_map *executed, __isl_take isl_basic_set *bounds, __isl_take isl_ast_build *build)
static int do_unroll_iteration(__isl_take isl_basic_set *bset, void *user)
static __isl_give isl_pw_aff_list * remove_redundant_lower_bounds(__isl_take isl_pw_aff_list *list, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * generate_components(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build)
static int eliminate_non_fixed(struct isl_set_map_pair *domain, int *order, int n, int depth, __isl_keep isl_ast_build *build)
static __isl_give isl_constraint * at_offset(int depth, __isl_keep isl_aff *aff, int offset)
static isl_bool after_in_extension(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node)
static isl_stat separate_domain(__isl_take isl_map *map, void *user)
static isl_stat collect_basic_set(__isl_take isl_basic_set *bset, void *user)
static __isl_give isl_ast_graft * set_enforced_from_set(__isl_take isl_ast_graft *graft, __isl_keep isl_pw_aff_list *lower, int pos, __isl_keep isl_set *upper)
static __isl_give isl_set * extract_pending(__isl_keep isl_ast_build *build, __isl_keep isl_basic_set *enforced)
static __isl_give isl_set * compute_atomic_domain(struct isl_codegen_domains *domains, __isl_take isl_set *class_domain)
static __isl_give isl_ast_graft_list * generate_shift_component(struct isl_set_map_pair *domain, int *order, int n, __isl_keep isl_val *stride, __isl_keep isl_multi_val *offset, __isl_take isl_ast_build *build)
static __isl_give isl_union_map * construct_shifted_executed(struct isl_set_map_pair *domain, int *order, int n, __isl_keep isl_val *stride, __isl_keep isl_multi_val *offset, __isl_keep isl_ast_build *build)
static isl_bool after_in_context(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node)
static __isl_give isl_ast_graft * create_node_scaled(__isl_take isl_union_map *executed, __isl_take isl_basic_set *bounds, __isl_take isl_set *domain, __isl_take isl_ast_build *build)
static __isl_give isl_set * separate_schedule_domains(__isl_take isl_space *space, __isl_take isl_union_map *executed, __isl_keep isl_ast_build *build)
static isl_bool after_in_child(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node)
static __isl_give isl_ast_node * create_for(__isl_keep isl_ast_build *build, int degenerate)
static __isl_give isl_ast_graft_list * hoist_out_of_context(__isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build, __isl_keep isl_ast_build *sub_build)
static __isl_give isl_ast_graft_list * build_ast_from_band(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static isl_bool only_intersects_first(__isl_keep isl_set *set, __isl_keep isl_set *first, __isl_keep isl_set *second)
static __isl_give isl_ast_graft_list * generate_shifted_component(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build)
static int list_constant_is_negative(__isl_keep isl_pw_aff_list *list)
static __isl_give isl_ast_expr * reduce_list(enum isl_ast_expr_op_type type, __isl_keep isl_pw_aff_list *list, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * build_ast_from_sequence(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static int first_offset(struct isl_set_map_pair *domain, int *order, int n, __isl_keep isl_ast_build *build)
static isl_stat map_check_scaled(__isl_take isl_map *map, void *user)
static __isl_give isl_ast_graft_list * generate_component(struct isl_set_map_pair *domain, int *order, int n, __isl_take isl_ast_build *build)
static isl_bool after_in_sequence(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node)
static __isl_give isl_basic_set_list * compute_domains(__isl_keep isl_union_map *executed, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * build_ast_from_guard(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static __isl_give isl_ast_expr * for_inc(__isl_keep isl_ast_build *build)
static __isl_give isl_set * do_unroll(struct isl_codegen_domains *domains, __isl_take isl_set *domain, __isl_take isl_set *class_domain)
static __isl_give isl_set * intersect_constraints(__isl_keep isl_constraint_list *list)
static __isl_give isl_ast_graft_list * generate_shifted_component_tree_part(__isl_keep isl_union_map *executed, __isl_take isl_set *domain, __isl_keep isl_ast_build *build, int isolated)
static isl_stat extract_domain(__isl_take isl_map *map, void *user)
static void compute_domains_init_options(isl_set *option[4], __isl_keep isl_ast_build *build)
static isl_stat add_nodes(__isl_take isl_basic_set_list *scc, void *user)
static __isl_give isl_ast_graft_list * list_add_guard(__isl_take isl_ast_graft_list *list, __isl_keep isl_set *guard, __isl_keep isl_ast_build *build, __isl_keep isl_ast_build *sub_build)
static int at_most_one_non_fixed(struct isl_set_map_pair *domain, int *order, int n, int depth)
static __isl_give isl_ast_graft * refine_degenerate(__isl_take isl_ast_graft *graft, __isl_keep isl_ast_build *build, __isl_keep isl_ast_build *sub_build)
static __isl_give isl_ast_graft * refine_generic_bounds(__isl_take isl_ast_graft *graft, __isl_take isl_constraint_list *c_lower, __isl_take isl_constraint_list *c_upper, __isl_keep isl_set *domain, __isl_keep isl_ast_build *build)
static int compute_separate_domain(struct isl_codegen_domains *domains, __isl_keep isl_set *class_domain)
static int get_expanded_n_div(struct isl_find_unroll_data *data, __isl_keep isl_aff *lower)
static __isl_give isl_set * add_implied_guards(__isl_take isl_set *guard, int degenerate, __isl_keep isl_basic_set *bounds, __isl_keep isl_ast_build *build)
static isl_stat compute_partial_domains(struct isl_codegen_domains *domains, __isl_take isl_set *class_domain)
static __isl_give isl_ast_graft_list * generate_inner_level(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build)
static __isl_give isl_ast_graft_list * build_ast_from_expansion(__isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed)
static __isl_give isl_pw_aff_list * list_add_one(__isl_take isl_pw_aff_list *list, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * call_create_leaf(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build)
static __isl_give isl_set * implicit_bounds(__isl_take isl_map *map, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * generate_shifted_component_tree(__isl_take isl_union_map *executed, __isl_take isl_ast_build *build)
static isl_bool after_in_expansion(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node)
static __isl_give isl_aff * lower_bound(__isl_keep isl_constraint *c, int pos, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft * refine_generic(__isl_take isl_ast_graft *graft, __isl_keep isl_basic_set *bounds, __isl_keep isl_set *domain, __isl_keep isl_ast_build *build)
static isl_stat constraint_check_scaled(__isl_take isl_constraint *c, void *user)
static isl_stat constraint_find_unroll(__isl_take isl_constraint *c, void *user)
static __isl_give isl_basic_set_list * add_split_on(__isl_take isl_basic_set_list *list, __isl_take isl_basic_set *bset, __isl_keep isl_basic_map *gt)
static isl_bool after_in_band(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node)
static __isl_give isl_set * compute_unroll_domains(struct isl_codegen_domains *domains, __isl_take isl_set *class_domain)
static isl_bool any_scheduled_after(int i, int j, void *user)
static __isl_give isl_union_map * construct_component_executed(struct isl_set_map_pair *domain, int *order, int n)
static __isl_give isl_ast_graft_list * generate_shifted_component_from_list(struct isl_set_map_pair *domain, int *order, int n, __isl_take isl_ast_build *build)
static isl_bool after_in_subtree(__isl_keep isl_ast_build *build, __isl_keep isl_map *map1, __isl_keep isl_map *map2)
static isl_stat before_each_mark(__isl_keep isl_id *mark, __isl_keep isl_ast_build *build)
static __isl_give isl_ast_graft_list * generate_shifted_component_parts(__isl_take isl_union_map *executed, __isl_take isl_set *before, __isl_take isl_set *isolated, __isl_take isl_set *after, __isl_take isl_set *other, __isl_take isl_ast_build *build)
__isl_give isl_set * isl_ast_graft_list_extract_hoistable_guard(__isl_keep isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
__isl_give isl_ast_graft * isl_ast_graft_insert_mark(__isl_take isl_ast_graft *graft, __isl_take isl_id *mark)
__isl_give isl_ast_graft_list * isl_ast_graft_list_preimage_multi_aff(__isl_take isl_ast_graft_list *list, __isl_take isl_multi_aff *ma)
__isl_give isl_ast_graft_list * isl_ast_graft_list_merge(__isl_take isl_ast_graft_list *list1, __isl_take isl_ast_graft_list *list2, __isl_keep isl_ast_build *build)
__isl_give isl_ast_node * isl_ast_node_from_graft_list(__isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
__isl_give isl_ast_graft_list * isl_ast_graft_list_group_on_guard(__isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
__isl_null isl_ast_graft * isl_ast_graft_free(__isl_take isl_ast_graft *graft)
__isl_give isl_ast_graft * isl_ast_graft_alloc_from_children(__isl_take isl_ast_graft_list *list, __isl_take isl_set *guard, __isl_take isl_basic_set *enforced, __isl_keep isl_ast_build *build, __isl_keep isl_ast_build *sub_build)
__isl_give isl_ast_graft_list * isl_ast_graft_list_gist_guards(__isl_take isl_ast_graft_list *list, __isl_take isl_set *context)
__isl_give isl_basic_set * isl_ast_graft_list_extract_shared_enforced(__isl_keep isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
__isl_give isl_ast_graft * isl_ast_graft_insert_for(__isl_take isl_ast_graft *graft, __isl_take isl_ast_node *node)
__isl_give isl_ast_graft_list * isl_ast_graft_list_sort_guard(__isl_take isl_ast_graft_list *list)
__isl_give isl_ast_graft * isl_ast_graft_enforce(__isl_take isl_ast_graft *graft, __isl_take isl_basic_set *enforced)
__isl_give isl_ast_graft_list * isl_ast_graft_list_insert_pending_guard_nodes(__isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
__isl_give isl_ast_graft * isl_ast_graft_add_guard(__isl_take isl_ast_graft *graft, __isl_take isl_set *guard, __isl_keep isl_ast_build *build)
__isl_give isl_ast_graft_list * isl_ast_graft_list_fuse(__isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
__isl_give isl_ast_graft_list * isl_ast_graft_list_unembed(__isl_take isl_ast_graft_list *list, int product)
isl_ctx * isl_ast_graft_get_ctx(__isl_keep isl_ast_graft *graft)
__isl_give isl_ast_graft * isl_ast_graft_alloc(__isl_take isl_ast_node *node, __isl_keep isl_ast_build *build)
__isl_give isl_ast_graft * isl_ast_graft_alloc_domain(__isl_take isl_map *executed, __isl_keep isl_ast_build *build)
__isl_give isl_ast_node * isl_ast_node_for_set_init(__isl_take isl_ast_node *node, __isl_take isl_ast_expr *init)
__isl_give isl_ast_node * isl_ast_node_for_set_inc(__isl_take isl_ast_node *node, __isl_take isl_ast_expr *init)
__isl_give isl_ast_node * isl_ast_node_for_set_cond(__isl_take isl_ast_node *node, __isl_take isl_ast_expr *init)
static int before(void *first, void *second)
Definition isl_flow.c:2419
static unsigned pos(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_map.c:73
#define isl_basic_set_list
#define isl_set
#define isl_basic_set
static struct isl_arg_choice bound[]
Definition isl_options.c:39
enum isl_schedule_node_type isl_schedule_node_get_type(__isl_keep isl_schedule_node *node)
struct isl_tarjan_graph * isl_tarjan_graph_free(struct isl_tarjan_graph *g)
Definition isl_tarjan.c:17
struct isl_tarjan_graph * isl_tarjan_graph_init(isl_ctx *ctx, int len, isl_bool(*follows)(int i, int j, void *user), void *user)
Definition isl_tarjan.c:119
int sv
Definition isl_test.c:3554
enum isl_fold type
Definition isl_test.c:3867
const char * pa
Definition isl_test.c:7173
const char * set
Definition isl_test.c:1364
const char * hull
Definition isl_test.c:1493
const char * ma
Definition isl_test.c:7387
const char * map
Definition isl_test.c:1791
int equal
Definition isl_test.c:7720
const char * pma
Definition isl_test.c:3019
const char * schedule
Definition isl_test.c:10508
const char * offset
Definition isl_test.c:1577
const char * context
Definition isl_test.c:1792
const char * map1
Definition isl_test.c:365
const char * aff
Definition isl_test.c:7130
const char * map2
Definition isl_test.c:366
const char * set1
Definition isl_test.c:4055
const char * res
Definition isl_test.c:783
const char * set2
Definition isl_test.c:4056
int subset
Definition isl_test.c:4057
const char * mupa
Definition isl_test.c:7217
const char * f
Definition isl_test.c:8453
const char * id
Definition isl_test.c:7131
static __isl_give isl_map * universe(__isl_take isl_map *map)
static __isl_give isl_space * identity(__isl_take isl_space *space)
#define isl_union_set
t0 *a *b *t *a *b * t
__isl_give isl_local_space * isl_local_space_from_space(__isl_take isl_space *space)
__isl_export __isl_give isl_map * isl_map_domain_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11649
__isl_export __isl_give isl_map * isl_map_intersect_range(__isl_take isl_map *map, __isl_take isl_set *set)
Definition isl_map.c:8973
__isl_export isl_bool isl_basic_map_is_empty(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:10044
__isl_give isl_basic_map * isl_basic_map_equate(__isl_take isl_basic_map *bmap, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:13943
__isl_export __isl_give isl_set * isl_map_domain(__isl_take isl_map *bmap)
Definition isl_map.c:8777
isl_bool isl_map_plain_is_single_valued(__isl_keep isl_map *map)
Definition isl_map.c:12613
__isl_export isl_bool isl_map_is_single_valued(__isl_keep isl_map *map)
Definition isl_map.c:12632
__isl_export __isl_give isl_map * isl_map_apply_domain(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:9263
__isl_give isl_map * isl_map_eliminate(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2717
__isl_export isl_bool isl_map_is_empty(__isl_keep isl_map *map)
Definition isl_map.c:9801
__isl_export __isl_give isl_map * isl_map_universe(__isl_take isl_space *space)
Definition isl_map.c:6967
__isl_give isl_map * isl_map_copy(__isl_keep isl_map *map)
Definition isl_map.c:1494
__isl_export __isl_give isl_map * isl_set_identity(__isl_take isl_set *set)
Definition isl_map.c:9563
__isl_give isl_map * isl_map_lex_gt(__isl_take isl_space *set_space)
Definition isl_map.c:6015
__isl_null isl_basic_map * isl_basic_map_free(__isl_take isl_basic_map *bmap)
Definition isl_map.c:1503
__isl_give isl_map * isl_map_from_domain_and_range(__isl_take isl_set *domain, __isl_take isl_set *range)
Definition isl_map.c:6847
__isl_give isl_map * isl_map_drop_constraints_involving_dims(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3727
__isl_give isl_map * isl_map_order_gt(__isl_take isl_map *map, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14132
__isl_give isl_map * isl_map_fix_val(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, __isl_take isl_val *v)
Definition isl_map.c:7288
__isl_export __isl_give isl_map * isl_map_intersect_domain(__isl_take isl_map *map, __isl_take isl_set *set)
Definition isl_map.c:9001
__isl_export isl_stat isl_map_foreach_basic_map(__isl_keep isl_map *map, isl_stat(*fn)(__isl_take isl_basic_map *bmap, void *user), void *user)
Definition isl_map.c:11933
__isl_export __isl_give isl_set * isl_map_deltas(__isl_take isl_map *map)
Definition isl_map.c:9442
__isl_export __isl_give isl_map * isl_map_lexmin(__isl_take isl_map *map)
__isl_export __isl_give isl_pw_multi_aff * isl_map_lexmin_pw_multi_aff(__isl_take isl_map *map)
__isl_give isl_map * isl_map_order_lt(__isl_take isl_map *map, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14147
isl_size isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type)
Definition isl_map.c:113
__isl_give isl_basic_map * isl_basic_map_order_ge(__isl_take isl_basic_map *bmap, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14035
__isl_export __isl_give isl_basic_map * isl_basic_map_intersect_domain(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset)
Definition isl_map.c:4118
__isl_export __isl_give isl_map * isl_map_reverse(__isl_take isl_map *map)
Definition isl_map.c:7801
__isl_export __isl_give isl_pw_multi_aff * isl_map_lexmax_pw_multi_aff(__isl_take isl_map *map)
__isl_give isl_basic_map * isl_basic_map_order_gt(__isl_take isl_basic_map *bmap, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:14117
__isl_give isl_map * isl_map_equate(__isl_take isl_map *map, enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
Definition isl_map.c:13957
__isl_export __isl_give isl_map * isl_map_product(__isl_take isl_map *map1, __isl_take isl_map *map2)
Definition isl_map.c:11613
__isl_export __isl_give isl_map * isl_map_coalesce(__isl_take isl_map *map)
__isl_give isl_map * isl_map_identity(__isl_take isl_space *space)
Definition isl_map.c:9558
__isl_give isl_map * isl_map_insert_dims(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, unsigned n)
Definition isl_map.c:4760
__isl_null isl_map * isl_map_free(__isl_take isl_map *map)
Definition isl_map.c:7040
__isl_constructor __isl_give isl_map * isl_map_from_basic_map(__isl_take isl_basic_map *bmap)
Definition isl_map.c:4037
__isl_export __isl_give isl_basic_map * isl_basic_map_intersect_range(__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset)
Definition isl_map.c:4167
__isl_give isl_basic_map * isl_basic_map_copy(__isl_keep isl_basic_map *bmap)
Definition isl_map.c:1479
__isl_give isl_basic_map * isl_basic_map_from_domain_and_range(__isl_take isl_basic_set *domain, __isl_take isl_basic_set *range)
Definition isl_map.c:6841
__isl_give isl_basic_map * isl_basic_map_from_multi_aff(__isl_take isl_multi_aff *maff)
__isl_export __isl_give isl_set * isl_map_range(__isl_take isl_map *map)
Definition isl_map.c:6728
__isl_give isl_basic_set * isl_basic_map_range(__isl_take isl_basic_map *bmap)
Definition isl_map.c:6635
__isl_give isl_basic_map * isl_basic_map_universe(__isl_take isl_space *space)
Definition isl_map.c:6902
__isl_give isl_map * isl_map_from_multi_aff(__isl_take isl_multi_aff *maff)
int isl_options_get_coalesce_preserve_locals(isl_ctx *ctx)
isl_stat isl_options_set_coalesce_preserve_locals(isl_ctx *ctx, int val)
__isl_export __isl_give isl_schedule_node * isl_schedule_get_root(__isl_keep isl_schedule *schedule)
__isl_null isl_schedule * isl_schedule_free(__isl_take isl_schedule *sched)
__isl_export isl_size isl_schedule_node_band_n_member(__isl_keep isl_schedule_node *node)
__isl_export __isl_give isl_multi_union_pw_aff * isl_schedule_node_band_get_partial_schedule(__isl_keep isl_schedule_node *node)
__isl_export isl_size isl_schedule_node_n_children(__isl_keep isl_schedule_node *node)
__isl_export __isl_give isl_union_map * isl_schedule_node_expansion_get_expansion(__isl_keep isl_schedule_node *node)
__isl_export isl_size isl_schedule_node_get_tree_depth(__isl_keep isl_schedule_node *node)
__isl_export __isl_give isl_union_map * isl_schedule_node_extension_get_extension(__isl_keep isl_schedule_node *node)
__isl_export __isl_give isl_union_set * isl_schedule_node_domain_get_domain(__isl_keep isl_schedule_node *node)
__isl_give isl_id * isl_schedule_node_mark_get_id(__isl_keep isl_schedule_node *node)
__isl_export isl_bool isl_schedule_node_is_subtree_anchored(__isl_keep isl_schedule_node *node)
__isl_export __isl_give isl_union_set * isl_schedule_node_filter_get_filter(__isl_keep isl_schedule_node *node)
__isl_export __isl_give isl_set * isl_schedule_node_context_get_context(__isl_keep isl_schedule_node *node)
__isl_export __isl_give isl_union_map * isl_schedule_node_get_prefix_schedule_union_map(__isl_keep isl_schedule_node *node)
__isl_null isl_schedule_node * isl_schedule_node_free(__isl_take isl_schedule_node *node)
__isl_export __isl_give isl_set * isl_schedule_node_guard_get_guard(__isl_keep isl_schedule_node *node)
isl_ctx * isl_schedule_node_get_ctx(__isl_keep isl_schedule_node *node)
__isl_give isl_schedule_node * isl_schedule_node_get_child(__isl_keep isl_schedule_node *node, int pos)
__isl_export __isl_give isl_schedule_node * isl_schedule_node_child(__isl_take isl_schedule_node *node, int pos)
isl_schedule_node_type
@ isl_schedule_node_mark
@ isl_schedule_node_filter
@ isl_schedule_node_domain
@ isl_schedule_node_band
@ isl_schedule_node_set
@ isl_schedule_node_guard
@ isl_schedule_node_extension
@ isl_schedule_node_expansion
@ isl_schedule_node_sequence
@ isl_schedule_node_error
@ isl_schedule_node_leaf
@ isl_schedule_node_context
a(0)
b(9)
__isl_export __isl_give isl_set * isl_set_universe(__isl_take isl_space *space)
Definition isl_map.c:6985
__isl_export __isl_give isl_basic_set * isl_set_unshifted_simple_hull(__isl_take isl_set *set)
__isl_export __isl_give isl_set * isl_set_coalesce(__isl_take isl_set *set)
__isl_give isl_basic_set * isl_basic_set_drop_constraints_not_involving_dims(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3655
__isl_export __isl_give isl_set * isl_set_subtract(__isl_take isl_set *set1, __isl_take isl_set *set2)
isl_bool isl_set_dim_has_upper_bound(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:12251
isl_ctx * isl_set_get_ctx(__isl_keep isl_set *set)
Definition isl_map.c:397
__isl_give isl_set * isl_set_make_disjoint(__isl_take isl_set *set)
__isl_export __isl_give isl_space * isl_set_get_space(__isl_keep isl_set *set)
Definition isl_map.c:604
__isl_export __isl_give isl_set * isl_set_detect_equalities(__isl_take isl_set *set)
__isl_give isl_val * isl_set_plain_get_val_if_fixed(__isl_keep isl_set *set, enum isl_dim_type type, unsigned pos)
Definition isl_map.c:10850
__isl_give isl_space * isl_basic_set_get_space(__isl_keep isl_basic_set *bset)
Definition isl_map.c:422
__isl_constructor __isl_give isl_set * isl_set_from_point(__isl_take isl_point *pnt)
Definition isl_point.c:693
__isl_export __isl_give isl_set * isl_set_union(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:8929
__isl_overload __isl_give isl_set * isl_set_preimage_multi_aff(__isl_take isl_set *set, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14675
__isl_give isl_basic_set * isl_basic_set_preimage_multi_aff(__isl_take isl_basic_set *bset, __isl_take isl_multi_aff *ma)
Definition isl_map.c:14536
__isl_give isl_basic_set * isl_basic_set_project_out(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:5170
__isl_export isl_bool isl_set_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
__isl_give isl_set * isl_set_eliminate(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:2747
__isl_null isl_basic_set * isl_basic_set_free(__isl_take isl_basic_set *bset)
Definition isl_map.c:1523
__isl_give isl_basic_set * isl_set_simple_hull(__isl_take isl_set *set)
isl_bool isl_basic_set_is_disjoint(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2)
__isl_null isl_set * isl_set_free(__isl_take isl_set *set)
Definition isl_map.c:4055
int isl_set_follows_at(__isl_keep isl_set *set1, __isl_keep isl_set *set2, int pos)
Definition isl_map.c:10684
__isl_overload __isl_give isl_set * isl_set_preimage_pw_multi_aff(__isl_take isl_set *set, __isl_take isl_pw_multi_aff *pma)
Definition isl_map.c:14802
__isl_give isl_set * isl_set_remove_divs_involving_dims(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3466
__isl_give isl_set * isl_set_drop_constraints_not_involving_dims(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3766
__isl_give isl_set * isl_set_remove_unknown_divs(__isl_take isl_set *set)
Definition isl_map.c:3856
__isl_export __isl_give isl_set * isl_set_apply(__isl_take isl_set *set, __isl_take isl_map *map)
Definition isl_map.c:10489
__isl_give isl_set * isl_set_copy(__isl_keep isl_set *set)
Definition isl_map.c:1470
__isl_give isl_basic_set * isl_basic_set_remove_redundancies(__isl_take isl_basic_set *bset)
__isl_give isl_set * isl_set_project_out(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:5241
__isl_export __isl_give isl_set * isl_set_gist(__isl_take isl_set *set, __isl_take isl_set *context)
__isl_export isl_stat isl_set_foreach_point(__isl_keep isl_set *set, isl_stat(*fn)(__isl_take isl_point *pnt, void *user), void *user)
Definition isl_point.c:579
__isl_give isl_set * isl_set_compute_divs(__isl_take isl_set *set)
Definition isl_map.c:8772
isl_bool isl_set_plain_is_equal(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
Definition isl_map.c:11240
isl_bool isl_set_is_params(__isl_keep isl_set *set)
Definition isl_map.c:1270
__isl_export isl_stat isl_set_foreach_basic_set(__isl_keep isl_set *set, isl_stat(*fn)(__isl_take isl_basic_set *bset, void *user), void *user)
Definition isl_map.c:11948
__isl_export __isl_give isl_basic_set * isl_basic_set_apply(__isl_take isl_basic_set *bset, __isl_take isl_basic_map *bmap)
Definition isl_map.c:5407
__isl_give isl_basic_set * isl_set_plain_unshifted_simple_hull(__isl_take isl_set *set)
isl_size isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type)
Definition isl_map.c:132
isl_stat isl_set_dim_residue_class_val(__isl_keep isl_set *set, int pos, __isl_give isl_val **modulo, __isl_give isl_val **residue)
__isl_give isl_set * isl_set_align_params(__isl_take isl_set *set, __isl_take isl_space *model)
Definition isl_map.c:13178
__isl_export isl_bool isl_basic_set_is_empty(__isl_keep isl_basic_set *bset)
Definition isl_map.c:10123
__isl_export isl_size isl_set_n_basic_set(__isl_keep isl_set *set)
Definition isl_map.c:11928
__isl_export __isl_give isl_set * isl_set_intersect(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:4521
__isl_export __isl_give isl_set * isl_set_empty(__isl_take isl_space *space)
Definition isl_map.c:6962
__isl_constructor __isl_give isl_set * isl_set_from_basic_set(__isl_take isl_basic_set *bset)
Definition isl_map.c:4024
__isl_give isl_basic_set * isl_basic_set_copy(__isl_keep isl_basic_set *bset)
Definition isl_map.c:1465
__isl_export __isl_give isl_basic_set * isl_basic_set_intersect(__isl_take isl_basic_set *bset1, __isl_take isl_basic_set *bset2)
Definition isl_map.c:4312
__isl_give isl_basic_set * isl_basic_set_universe(__isl_take isl_space *space)
Definition isl_map.c:6910
__isl_give isl_set * isl_set_drop_constraints_involving_dims(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n)
Definition isl_map.c:3756
__isl_give isl_basic_set * isl_basic_set_remove_unknown_divs(__isl_take isl_basic_set *bset)
Definition isl_map.c:3826
isl_bool isl_set_plain_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
__isl_export isl_bool isl_set_is_empty(__isl_keep isl_set *set)
Definition isl_map.c:9828
__isl_null isl_space * isl_space_free(__isl_take isl_space *space)
Definition isl_space.c:478
__isl_give isl_space * isl_space_from_domain(__isl_take isl_space *space)
Definition isl_space.c:2242
__isl_give isl_space * isl_space_insert_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, unsigned n)
Definition isl_space.c:1345
__isl_give isl_space * isl_space_set_from_params(__isl_take isl_space *space)
Definition isl_space.c:2321
__isl_give isl_space * isl_space_copy(__isl_keep isl_space *space)
Definition isl_space.c:469
__isl_give isl_space * isl_space_align_params(__isl_take isl_space *space1, __isl_take isl_space *space2)
Definition isl_space.c:3358
__isl_export __isl_give isl_space * isl_space_range(__isl_take isl_space *space)
Definition isl_space.c:2257
isl_bool isl_space_is_params(__isl_keep isl_space *space)
Definition isl_space.c:211
__isl_export __isl_give isl_space * isl_space_unwrap(__isl_take isl_space *space)
Definition isl_space.c:2951
__isl_give isl_space * isl_space_set_alloc(isl_ctx *ctx, unsigned nparam, unsigned dim)
Definition isl_space.c:188
__isl_export __isl_give isl_space * isl_space_map_from_set(__isl_take isl_space *space)
Definition isl_space.c:1927
isl_size isl_space_dim(__isl_keep isl_space *space, enum isl_dim_type type)
Definition isl_space.c:372
__isl_give isl_space * isl_space_add_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned n)
Definition isl_space.c:1262
isl_bool isl_space_is_domain(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition isl_space.c:2708
__isl_export __isl_give isl_space * isl_space_domain(__isl_take isl_space *space)
Definition isl_space.c:2232
isl_dim_type
Definition space_type.h:13
@ isl_dim_param
Definition space_type.h:15
@ isl_dim_in
Definition space_type.h:16
@ isl_dim_set
Definition space_type.h:18
@ isl_dim_div
Definition space_type.h:19
@ isl_dim_out
Definition space_type.h:17
isl_ast_graft_list * list
isl_ast_build * build
isl_union_map * executed
struct isl_set_map_pair * domain
isl_union_map * options
__isl_give isl_id *(* before_each_for)(__isl_keep isl_ast_build *context, void *user)
__isl_give isl_ast_node *(* after_each_for)(__isl_take isl_ast_node *node, __isl_keep isl_ast_build *context, void *user)
isl_stat(* before_each_mark)(__isl_keep isl_id *mark, __isl_keep isl_ast_build *build, void *user)
__isl_give isl_ast_node *(* after_each_mark)(__isl_take isl_ast_node *node, __isl_keep isl_ast_build *context, void *user)
isl_multi_aff * internal2input
__isl_give isl_ast_node *(* create_leaf)(__isl_take isl_ast_build *build, void *user)
struct isl_codegen_domains * domains
isl_ast_graft_list * list
isl_ast_build * build
isl_basic_set_list * list
isl_union_map * executed
isl_basic_map * expansion
isl_ast_graft_list * list
isl_ast_graft_list * list
static Signature range
static Signature domain
__isl_null isl_union_map * isl_union_map_free(__isl_take isl_union_map *umap)
__isl_export __isl_give isl_space * isl_union_map_get_space(__isl_keep isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_reverse(__isl_take isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_domain_product(__isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2)
__isl_give isl_union_map * isl_union_map_add_map(__isl_take isl_union_map *umap, __isl_take isl_map *map)
__isl_give isl_union_map * isl_union_map_align_params(__isl_take isl_union_map *umap, __isl_take isl_space *model)
__isl_export isl_stat isl_union_map_foreach_map(__isl_keep isl_union_map *umap, isl_stat(*fn)(__isl_take isl_map *map, void *user), void *user)
__isl_overload __isl_give isl_union_map * isl_union_map_preimage_domain_multi_aff(__isl_take isl_union_map *umap, __isl_take isl_multi_aff *ma)
__isl_give isl_union_set * isl_union_set_align_params(__isl_take isl_union_set *uset, __isl_take isl_space *model)
__isl_export __isl_give isl_union_map * isl_union_map_coalesce(__isl_take isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_apply_range(__isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2)
__isl_give isl_union_map * isl_union_map_copy(__isl_keep isl_union_map *umap)
__isl_export isl_bool isl_union_map_is_empty(__isl_keep isl_union_map *umap)
__isl_export __isl_give isl_union_set * isl_union_map_range(__isl_take isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_apply_domain(__isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2)
__isl_give isl_union_map * isl_union_map_empty(__isl_take isl_space *space)
__isl_constructor __isl_give isl_union_map * isl_union_map_from_map(__isl_take isl_map *map)
__isl_give isl_union_map * isl_union_map_remove_redundancies(__isl_take isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_union(__isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2)
__isl_give isl_union_map * isl_union_map_intersect_domain(__isl_take isl_union_map *umap, __isl_take isl_union_set *uset)
isl_ctx * isl_union_map_get_ctx(__isl_keep isl_union_map *umap)
isl_size isl_union_map_dim(__isl_keep isl_union_map *umap, enum isl_dim_type type)
__isl_export isl_bool isl_union_map_is_subset(__isl_keep isl_union_map *umap1, __isl_keep isl_union_map *umap2)
isl_size isl_union_map_n_map(__isl_keep isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_detect_equalities(__isl_take isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_from_domain_and_range(__isl_take isl_union_set *domain, __isl_take isl_union_set *range)
__isl_export __isl_give isl_union_set * isl_union_map_domain(__isl_take isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_intersect_params(__isl_take isl_union_map *umap, __isl_take isl_set *set)
__isl_export __isl_give isl_union_map * isl_union_map_universe(__isl_take isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_intersect(__isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2)
__isl_give isl_union_map * isl_union_map_intersect_range(__isl_take isl_union_map *umap, __isl_take isl_union_set *uset)
__isl_give isl_set * isl_set_from_union_set(__isl_take isl_union_set *uset)
__isl_export isl_stat isl_union_set_foreach_set(__isl_keep isl_union_set *uset, isl_stat(*fn)(__isl_take isl_set *set, void *user), void *user)
__isl_constructor __isl_give isl_union_set * isl_union_set_from_basic_set(__isl_take isl_basic_set *bset)
__isl_export __isl_give isl_space * isl_union_set_get_space(__isl_keep isl_union_set *uset)
__isl_constructor __isl_give isl_union_set * isl_union_set_from_set(__isl_take isl_set *set)
__isl_export __isl_give isl_union_set * isl_union_set_coalesce(__isl_take isl_union_set *uset)
__isl_give isl_union_set * isl_union_set_copy(__isl_keep isl_union_set *uset)
__isl_null isl_union_set * isl_union_set_free(__isl_take isl_union_set *uset)
__isl_export isl_bool isl_union_set_is_subset(__isl_keep isl_union_set *uset1, __isl_keep isl_union_set *uset2)
t1
Definition unroll11.c:2
t2
Definition unroll4.c:3
__isl_export isl_bool isl_val_is_nan(__isl_keep isl_val *v)
Definition isl_val.c:1161
__isl_give isl_multi_val * isl_multi_val_mod_val(__isl_take isl_multi_val *mv, __isl_take isl_val *v)
Definition isl_val.c:1615
__isl_give isl_val * isl_val_copy(__isl_keep isl_val *v)
Definition isl_val.c:219
__isl_export int isl_val_cmp_si(__isl_keep isl_val *v, long i)
Definition isl_val.c:1394
__isl_give isl_val * isl_val_set_si(__isl_take isl_val *v, long i)
Definition isl_val.c:144
__isl_export isl_bool isl_val_is_infty(__isl_keep isl_val *v)
Definition isl_val.c:1171
__isl_export __isl_give isl_val * isl_val_div(__isl_take isl_val *v1, __isl_take isl_val *v2)
Definition isl_val.c:875
__isl_overload __isl_give isl_multi_val * isl_multi_val_add_val(__isl_take isl_multi_val *mv, __isl_take isl_val *v)
Definition isl_val.c:1601
__isl_export __isl_give isl_val * isl_val_gcd(__isl_take isl_val *v1, __isl_take isl_val *v2)
Definition isl_val.c:1016
__isl_export isl_bool isl_val_is_divisible_by(__isl_keep isl_val *v1, __isl_keep isl_val *v2)
Definition isl_val.c:964
__isl_export isl_bool isl_val_is_neg(__isl_keep isl_val *v)
Definition isl_val.c:1234
__isl_null isl_val * isl_val_free(__isl_take isl_val *v)
Definition isl_val.c:263
__isl_export isl_bool isl_val_is_zero(__isl_keep isl_val *v)
Definition isl_val.c:1191
__isl_export isl_bool isl_val_ne(__isl_keep isl_val *v1, __isl_keep isl_val *v2)
Definition isl_val.c:1458
__isl_export isl_bool isl_val_is_one(__isl_keep isl_val *v)
Definition isl_val.c:1201
__isl_export __isl_give isl_val * isl_val_neg(__isl_take isl_val *v)
Definition isl_val.c:410
__isl_export long isl_val_get_num_si(__isl_keep isl_val *v)
Definition isl_val.c:282
struct isl_multi_val isl_multi_val
Definition val_type.h:16
n
Definition youcefn.c:8