2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2012-2013 Ecole Normale Superieure. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY LEIDEN UNIVERSITY ''AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEIDEN UNIVERSITY OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * The views and conclusions contained in the software and documentation
30 * are those of the authors and should not be interpreted as
31 * representing official policies, either expressed or implied, of
36 #include <isl/constraint.h>
37 #include <isl/union_set.h>
42 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
44 static char *type_str
[] = {
45 [pet_expr_access
] = "access",
46 [pet_expr_call
] = "call",
47 [pet_expr_cast
] = "cast",
48 [pet_expr_double
] = "double",
49 [pet_expr_unary
] = "unary",
50 [pet_expr_binary
] = "binary",
51 [pet_expr_ternary
] = "ternary"
54 static char *op_str
[] = {
55 [pet_op_add_assign
] = "+=",
56 [pet_op_sub_assign
] = "-=",
57 [pet_op_mul_assign
] = "*=",
58 [pet_op_div_assign
] = "/=",
59 [pet_op_assign
] = "=",
70 [pet_op_post_inc
] = "++",
71 [pet_op_post_dec
] = "--",
72 [pet_op_pre_inc
] = "++",
73 [pet_op_pre_dec
] = "--",
74 [pet_op_address_of
] = "&",
75 [pet_op_kill
] = "kill"
78 /* pet_scop with extra information that is used during parsing and printing.
80 * In particular, we keep track of conditions under which we want
81 * to skip the rest of the current loop iteration (skip[pet_skip_now])
82 * and of conditions under which we want to skip subsequent
83 * loop iterations (skip[pet_skip_later]).
85 * The conditions are represented as index expressions defined
86 * over a zero-dimensiona domain. The index expression is either
87 * a boolean affine expression or an access to a variable, which
88 * is assumed to attain values zero and one. The condition holds
89 * if the variable has value one or if the affine expression
90 * has value one (typically for only part of the parameter space).
92 * A missing condition (skip[type] == NULL) means that we don't want
95 * Additionally, we keep track of the original input file
96 * inside pet_transform_C_source.
101 isl_multi_pw_aff
*skip
[2];
105 const char *pet_op_str(enum pet_op_type op
)
110 int pet_op_is_inc_dec(enum pet_op_type op
)
112 return op
== pet_op_post_inc
|| op
== pet_op_post_dec
||
113 op
== pet_op_pre_inc
|| op
== pet_op_pre_dec
;
116 const char *pet_type_str(enum pet_expr_type type
)
118 return type_str
[type
];
121 enum pet_op_type
pet_str_op(const char *str
)
125 for (i
= 0; i
< ARRAY_SIZE(op_str
); ++i
)
126 if (!strcmp(op_str
[i
], str
))
132 enum pet_expr_type
pet_str_type(const char *str
)
136 for (i
= 0; i
< ARRAY_SIZE(type_str
); ++i
)
137 if (!strcmp(type_str
[i
], str
))
143 /* Construct an access pet_expr from an access relation and an index expression.
144 * By default, it is considered to be a read access.
146 struct pet_expr
*pet_expr_from_access_and_index( __isl_take isl_map
*access
,
147 __isl_take isl_multi_pw_aff
*index
)
149 isl_ctx
*ctx
= isl_map_get_ctx(access
);
150 struct pet_expr
*expr
;
152 if (!index
|| !access
)
154 expr
= isl_calloc_type(ctx
, struct pet_expr
);
158 expr
->type
= pet_expr_access
;
159 expr
->acc
.access
= access
;
160 expr
->acc
.index
= index
;
166 isl_map_free(access
);
167 isl_multi_pw_aff_free(index
);
171 /* Construct an access pet_expr from an index expression.
172 * By default, the access is considered to be a read access.
174 struct pet_expr
*pet_expr_from_index(__isl_take isl_multi_pw_aff
*index
)
178 access
= isl_map_from_multi_pw_aff(isl_multi_pw_aff_copy(index
));
179 return pet_expr_from_access_and_index(access
, index
);
182 /* Extend the range of "access" with "n" dimensions, retaining
183 * the tuple identifier on this range.
185 static __isl_give isl_map
*extend_range(__isl_take isl_map
*access
, int n
)
189 id
= isl_map_get_tuple_id(access
, isl_dim_out
);
190 access
= isl_map_add_dims(access
, isl_dim_out
, n
);
191 access
= isl_map_set_tuple_id(access
, isl_dim_out
, id
);
196 /* Construct an access pet_expr from an index expression and
197 * the depth of the accessed array.
198 * By default, the access is considered to be a read access.
200 * If the number of indices is smaller than the depth of the array,
201 * then we assume that all elements of the remaining dimensions
204 struct pet_expr
*pet_expr_from_index_and_depth(
205 __isl_take isl_multi_pw_aff
*index
, int depth
)
210 access
= isl_map_from_multi_pw_aff(isl_multi_pw_aff_copy(index
));
213 dim
= isl_map_dim(access
, isl_dim_out
);
215 isl_die(isl_map_get_ctx(access
), isl_error_internal
,
216 "number of indices greater than depth",
217 access
= isl_map_free(access
));
219 return pet_expr_from_access_and_index(access
, index
);
221 access
= extend_range(access
, depth
- dim
);
223 return pet_expr_from_access_and_index(access
, index
);
225 isl_multi_pw_aff_free(index
);
229 /* Construct a pet_expr that kills the elements specified by
230 * the index expression "index" and the access relation "access".
232 struct pet_expr
*pet_expr_kill_from_access_and_index(__isl_take isl_map
*access
,
233 __isl_take isl_multi_pw_aff
*index
)
236 struct pet_expr
*expr
;
238 if (!access
|| !index
)
241 ctx
= isl_multi_pw_aff_get_ctx(index
);
242 expr
= pet_expr_from_access_and_index(access
, index
);
246 return pet_expr_new_unary(ctx
, pet_op_kill
, expr
);
248 isl_map_free(access
);
249 isl_multi_pw_aff_free(index
);
253 /* Construct a unary pet_expr that performs "op" on "arg".
255 struct pet_expr
*pet_expr_new_unary(isl_ctx
*ctx
, enum pet_op_type op
,
256 struct pet_expr
*arg
)
258 struct pet_expr
*expr
;
262 expr
= isl_alloc_type(ctx
, struct pet_expr
);
266 expr
->type
= pet_expr_unary
;
269 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, 1);
272 expr
->args
[pet_un_arg
] = arg
;
280 /* Construct a binary pet_expr that performs "op" on "lhs" and "rhs".
282 struct pet_expr
*pet_expr_new_binary(isl_ctx
*ctx
, enum pet_op_type op
,
283 struct pet_expr
*lhs
, struct pet_expr
*rhs
)
285 struct pet_expr
*expr
;
289 expr
= isl_alloc_type(ctx
, struct pet_expr
);
293 expr
->type
= pet_expr_binary
;
296 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, 2);
299 expr
->args
[pet_bin_lhs
] = lhs
;
300 expr
->args
[pet_bin_rhs
] = rhs
;
309 /* Construct a ternary pet_expr that performs "cond" ? "lhs" : "rhs".
311 struct pet_expr
*pet_expr_new_ternary(isl_ctx
*ctx
, struct pet_expr
*cond
,
312 struct pet_expr
*lhs
, struct pet_expr
*rhs
)
314 struct pet_expr
*expr
;
316 if (!cond
|| !lhs
|| !rhs
)
318 expr
= isl_alloc_type(ctx
, struct pet_expr
);
322 expr
->type
= pet_expr_ternary
;
324 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, 3);
327 expr
->args
[pet_ter_cond
] = cond
;
328 expr
->args
[pet_ter_true
] = lhs
;
329 expr
->args
[pet_ter_false
] = rhs
;
339 /* Construct a call pet_expr that calls function "name" with "n_arg"
340 * arguments. The caller is responsible for filling in the arguments.
342 struct pet_expr
*pet_expr_new_call(isl_ctx
*ctx
, const char *name
,
345 struct pet_expr
*expr
;
347 expr
= isl_alloc_type(ctx
, struct pet_expr
);
351 expr
->type
= pet_expr_call
;
353 expr
->name
= strdup(name
);
354 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, n_arg
);
355 if (!expr
->name
|| !expr
->args
)
356 return pet_expr_free(expr
);
361 /* Construct a pet_expr that represents the cast of "arg" to "type_name".
363 struct pet_expr
*pet_expr_new_cast(isl_ctx
*ctx
, const char *type_name
,
364 struct pet_expr
*arg
)
366 struct pet_expr
*expr
;
371 expr
= isl_alloc_type(ctx
, struct pet_expr
);
375 expr
->type
= pet_expr_cast
;
377 expr
->type_name
= strdup(type_name
);
378 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, 1);
379 if (!expr
->type_name
|| !expr
->args
)
391 /* Construct a pet_expr that represents the double "d".
393 struct pet_expr
*pet_expr_new_double(isl_ctx
*ctx
, double val
, const char *s
)
395 struct pet_expr
*expr
;
397 expr
= isl_calloc_type(ctx
, struct pet_expr
);
401 expr
->type
= pet_expr_double
;
403 expr
->d
.s
= strdup(s
);
405 return pet_expr_free(expr
);
410 struct pet_expr
*pet_expr_free(struct pet_expr
*expr
)
417 for (i
= 0; i
< expr
->n_arg
; ++i
)
418 pet_expr_free(expr
->args
[i
]);
421 switch (expr
->type
) {
422 case pet_expr_access
:
423 isl_id_free(expr
->acc
.ref_id
);
424 isl_map_free(expr
->acc
.access
);
425 isl_multi_pw_aff_free(expr
->acc
.index
);
431 free(expr
->type_name
);
433 case pet_expr_double
:
437 case pet_expr_binary
:
438 case pet_expr_ternary
:
446 static void expr_dump(struct pet_expr
*expr
, int indent
)
453 fprintf(stderr
, "%*s", indent
, "");
455 switch (expr
->type
) {
456 case pet_expr_double
:
457 fprintf(stderr
, "%s\n", expr
->d
.s
);
459 case pet_expr_access
:
460 isl_id_dump(expr
->acc
.ref_id
);
461 fprintf(stderr
, "%*s", indent
, "");
462 isl_map_dump(expr
->acc
.access
);
463 fprintf(stderr
, "%*s", indent
, "");
464 isl_multi_pw_aff_dump(expr
->acc
.index
);
465 fprintf(stderr
, "%*sread: %d\n", indent
+ 2,
467 fprintf(stderr
, "%*swrite: %d\n", indent
+ 2,
468 "", expr
->acc
.write
);
469 for (i
= 0; i
< expr
->n_arg
; ++i
)
470 expr_dump(expr
->args
[i
], indent
+ 2);
473 fprintf(stderr
, "%s\n", op_str
[expr
->op
]);
474 expr_dump(expr
->args
[pet_un_arg
], indent
+ 2);
476 case pet_expr_binary
:
477 fprintf(stderr
, "%s\n", op_str
[expr
->op
]);
478 expr_dump(expr
->args
[pet_bin_lhs
], indent
+ 2);
479 expr_dump(expr
->args
[pet_bin_rhs
], indent
+ 2);
481 case pet_expr_ternary
:
482 fprintf(stderr
, "?:\n");
483 expr_dump(expr
->args
[pet_ter_cond
], indent
+ 2);
484 expr_dump(expr
->args
[pet_ter_true
], indent
+ 2);
485 expr_dump(expr
->args
[pet_ter_false
], indent
+ 2);
488 fprintf(stderr
, "%s/%d\n", expr
->name
, expr
->n_arg
);
489 for (i
= 0; i
< expr
->n_arg
; ++i
)
490 expr_dump(expr
->args
[i
], indent
+ 2);
493 fprintf(stderr
, "(%s)\n", expr
->type_name
);
494 for (i
= 0; i
< expr
->n_arg
; ++i
)
495 expr_dump(expr
->args
[i
], indent
+ 2);
500 void pet_expr_dump(struct pet_expr
*expr
)
505 /* Does "expr" represent an access to an unnamed space, i.e.,
506 * does it represent an affine expression?
508 int pet_expr_is_affine(struct pet_expr
*expr
)
514 if (expr
->type
!= pet_expr_access
)
517 has_id
= isl_map_has_tuple_id(expr
->acc
.access
, isl_dim_out
);
524 /* Return the identifier of the array accessed by "expr".
526 __isl_give isl_id
*pet_expr_access_get_id(struct pet_expr
*expr
)
530 if (expr
->type
!= pet_expr_access
)
532 return isl_map_get_tuple_id(expr
->acc
.access
, isl_dim_out
);
535 /* Align the parameters of expr->acc.index and expr->acc.access.
537 struct pet_expr
*pet_expr_access_align_params(struct pet_expr
*expr
)
541 if (expr
->type
!= pet_expr_access
)
542 return pet_expr_free(expr
);
544 expr
->acc
.access
= isl_map_align_params(expr
->acc
.access
,
545 isl_multi_pw_aff_get_space(expr
->acc
.index
));
546 expr
->acc
.index
= isl_multi_pw_aff_align_params(expr
->acc
.index
,
547 isl_map_get_space(expr
->acc
.access
));
548 if (!expr
->acc
.access
|| !expr
->acc
.index
)
549 return pet_expr_free(expr
);
554 /* Does "expr" represent an access to a scalar, i.e., zero-dimensional array?
556 int pet_expr_is_scalar_access(struct pet_expr
*expr
)
560 if (expr
->type
!= pet_expr_access
)
563 return isl_map_dim(expr
->acc
.access
, isl_dim_out
) == 0;
566 /* Return 1 if the two pet_exprs are equivalent.
568 int pet_expr_is_equal(struct pet_expr
*expr1
, struct pet_expr
*expr2
)
572 if (!expr1
|| !expr2
)
575 if (expr1
->type
!= expr2
->type
)
577 if (expr1
->n_arg
!= expr2
->n_arg
)
579 for (i
= 0; i
< expr1
->n_arg
; ++i
)
580 if (!pet_expr_is_equal(expr1
->args
[i
], expr2
->args
[i
]))
582 switch (expr1
->type
) {
583 case pet_expr_double
:
584 if (strcmp(expr1
->d
.s
, expr2
->d
.s
))
586 if (expr1
->d
.val
!= expr2
->d
.val
)
589 case pet_expr_access
:
590 if (expr1
->acc
.read
!= expr2
->acc
.read
)
592 if (expr1
->acc
.write
!= expr2
->acc
.write
)
594 if (expr1
->acc
.ref_id
!= expr2
->acc
.ref_id
)
596 if (!expr1
->acc
.access
|| !expr2
->acc
.access
)
598 if (!isl_map_is_equal(expr1
->acc
.access
, expr2
->acc
.access
))
600 if (!expr1
->acc
.index
|| !expr2
->acc
.index
)
602 if (!isl_multi_pw_aff_plain_is_equal(expr1
->acc
.index
,
607 case pet_expr_binary
:
608 case pet_expr_ternary
:
609 if (expr1
->op
!= expr2
->op
)
613 if (strcmp(expr1
->name
, expr2
->name
))
617 if (strcmp(expr1
->type_name
, expr2
->type_name
))
625 /* Add extra conditions on the parameters to all access relations in "expr".
627 * The conditions are not added to the index expression. Instead, they
628 * are used to try and simplifty the index expression.
630 struct pet_expr
*pet_expr_restrict(struct pet_expr
*expr
,
631 __isl_take isl_set
*cond
)
638 for (i
= 0; i
< expr
->n_arg
; ++i
) {
639 expr
->args
[i
] = pet_expr_restrict(expr
->args
[i
],
645 if (expr
->type
== pet_expr_access
) {
646 expr
->acc
.access
= isl_map_intersect_params(expr
->acc
.access
,
648 expr
->acc
.index
= isl_multi_pw_aff_gist_params(
649 expr
->acc
.index
, isl_set_copy(cond
));
650 if (!expr
->acc
.access
|| !expr
->acc
.index
)
658 return pet_expr_free(expr
);
661 /* Modify all expressions of type pet_expr_access in "expr"
662 * by calling "fn" on them.
664 struct pet_expr
*pet_expr_map_access(struct pet_expr
*expr
,
665 struct pet_expr
*(*fn
)(struct pet_expr
*expr
, void *user
),
673 for (i
= 0; i
< expr
->n_arg
; ++i
) {
674 expr
->args
[i
] = pet_expr_map_access(expr
->args
[i
], fn
, user
);
676 return pet_expr_free(expr
);
679 if (expr
->type
== pet_expr_access
)
680 expr
= fn(expr
, user
);
685 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_access.
687 * Return -1 on error (where fn return a negative value is treated as an error).
688 * Otherwise return 0.
690 int pet_expr_foreach_access_expr(struct pet_expr
*expr
,
691 int (*fn
)(struct pet_expr
*expr
, void *user
), void *user
)
698 for (i
= 0; i
< expr
->n_arg
; ++i
)
699 if (pet_expr_foreach_access_expr(expr
->args
[i
], fn
, user
) < 0)
702 if (expr
->type
== pet_expr_access
)
703 return fn(expr
, user
);
708 /* Modify the access relation and index expression
709 * of the given access expression
710 * based on the given iteration space transformation.
711 * In particular, precompose the access relation and index expression
712 * with the update function.
714 * If the access has any arguments then the domain of the access relation
715 * is a wrapped mapping from the iteration space to the space of
716 * argument values. We only need to change the domain of this wrapped
717 * mapping, so we extend the input transformation with an identity mapping
718 * on the space of argument values.
720 static struct pet_expr
*update_domain(struct pet_expr
*expr
, void *user
)
722 isl_multi_pw_aff
*update
= user
;
725 update
= isl_multi_pw_aff_copy(update
);
727 space
= isl_map_get_space(expr
->acc
.access
);
728 space
= isl_space_domain(space
);
729 if (!isl_space_is_wrapping(space
))
730 isl_space_free(space
);
732 isl_multi_pw_aff
*id
;
733 space
= isl_space_unwrap(space
);
734 space
= isl_space_range(space
);
735 space
= isl_space_map_from_set(space
);
736 id
= isl_multi_pw_aff_identity(space
);
737 update
= isl_multi_pw_aff_product(update
, id
);
740 expr
->acc
.access
= isl_map_preimage_domain_multi_pw_aff(
742 isl_multi_pw_aff_copy(update
));
743 expr
->acc
.index
= isl_multi_pw_aff_pullback_multi_pw_aff(
744 expr
->acc
.index
, update
);
745 if (!expr
->acc
.access
|| !expr
->acc
.index
)
746 return pet_expr_free(expr
);
751 /* Modify all access relations in "expr" by precomposing them with
752 * the given iteration space transformation.
754 static struct pet_expr
*expr_update_domain(struct pet_expr
*expr
,
755 __isl_take isl_multi_pw_aff
*update
)
757 expr
= pet_expr_map_access(expr
, &update_domain
, update
);
758 isl_multi_pw_aff_free(update
);
762 /* Construct a pet_stmt with given line number and statement
763 * number from a pet_expr.
764 * The initial iteration domain is the zero-dimensional universe.
765 * The name of the domain is given by "label" if it is non-NULL.
766 * Otherwise, the name is constructed as S_<id>.
767 * The domains of all access relations are modified to refer
768 * to the statement iteration domain.
770 struct pet_stmt
*pet_stmt_from_pet_expr(isl_ctx
*ctx
, int line
,
771 __isl_take isl_id
*label
, int id
, struct pet_expr
*expr
)
773 struct pet_stmt
*stmt
;
777 isl_multi_pw_aff
*add_name
;
783 stmt
= isl_calloc_type(ctx
, struct pet_stmt
);
787 dim
= isl_space_set_alloc(ctx
, 0, 0);
789 dim
= isl_space_set_tuple_id(dim
, isl_dim_set
, label
);
791 snprintf(name
, sizeof(name
), "S_%d", id
);
792 dim
= isl_space_set_tuple_name(dim
, isl_dim_set
, name
);
794 dom
= isl_set_universe(isl_space_copy(dim
));
795 sched
= isl_map_from_domain(isl_set_copy(dom
));
797 dim
= isl_space_from_domain(dim
);
798 add_name
= isl_multi_pw_aff_zero(dim
);
799 expr
= expr_update_domain(expr
, add_name
);
803 stmt
->schedule
= sched
;
806 if (!stmt
->domain
|| !stmt
->schedule
|| !stmt
->body
)
807 return pet_stmt_free(stmt
);
816 void *pet_stmt_free(struct pet_stmt
*stmt
)
823 isl_set_free(stmt
->domain
);
824 isl_map_free(stmt
->schedule
);
825 pet_expr_free(stmt
->body
);
827 for (i
= 0; i
< stmt
->n_arg
; ++i
)
828 pet_expr_free(stmt
->args
[i
]);
835 static void stmt_dump(struct pet_stmt
*stmt
, int indent
)
842 fprintf(stderr
, "%*s%d\n", indent
, "", stmt
->line
);
843 fprintf(stderr
, "%*s", indent
, "");
844 isl_set_dump(stmt
->domain
);
845 fprintf(stderr
, "%*s", indent
, "");
846 isl_map_dump(stmt
->schedule
);
847 expr_dump(stmt
->body
, indent
);
848 for (i
= 0; i
< stmt
->n_arg
; ++i
)
849 expr_dump(stmt
->args
[i
], indent
+ 2);
852 void pet_stmt_dump(struct pet_stmt
*stmt
)
857 /* Allocate a new pet_type with the given "name" and "definition".
859 struct pet_type
*pet_type_alloc(isl_ctx
*ctx
, const char *name
,
860 const char *definition
)
862 struct pet_type
*type
;
864 type
= isl_alloc_type(ctx
, struct pet_type
);
868 type
->name
= strdup(name
);
869 type
->definition
= strdup(definition
);
871 if (!type
->name
|| !type
->definition
)
872 return pet_type_free(type
);
877 /* Free "type" and return NULL.
879 struct pet_type
*pet_type_free(struct pet_type
*type
)
885 free(type
->definition
);
891 struct pet_array
*pet_array_free(struct pet_array
*array
)
896 isl_set_free(array
->context
);
897 isl_set_free(array
->extent
);
898 isl_set_free(array
->value_bounds
);
899 free(array
->element_type
);
905 void pet_array_dump(struct pet_array
*array
)
910 isl_set_dump(array
->context
);
911 isl_set_dump(array
->extent
);
912 isl_set_dump(array
->value_bounds
);
913 fprintf(stderr
, "%s %s\n", array
->element_type
,
914 array
->live_out
? "live-out" : "");
917 /* Alloc a pet_scop structure, with extra room for information that
918 * is only used during parsing.
920 struct pet_scop
*pet_scop_alloc(isl_ctx
*ctx
)
922 return &isl_calloc_type(ctx
, struct pet_scop_ext
)->scop
;
925 /* Construct a pet_scop with room for n statements.
927 static struct pet_scop
*scop_alloc(isl_ctx
*ctx
, int n
)
930 struct pet_scop
*scop
;
932 scop
= pet_scop_alloc(ctx
);
936 space
= isl_space_params_alloc(ctx
, 0);
937 scop
->context
= isl_set_universe(isl_space_copy(space
));
938 scop
->context_value
= isl_set_universe(space
);
939 scop
->stmts
= isl_calloc_array(ctx
, struct pet_stmt
*, n
);
940 if (!scop
->context
|| !scop
->stmts
)
941 return pet_scop_free(scop
);
948 struct pet_scop
*pet_scop_empty(isl_ctx
*ctx
)
950 return scop_alloc(ctx
, 0);
953 /* Update "context" with respect to the valid parameter values for "access".
955 static __isl_give isl_set
*access_extract_context(__isl_keep isl_map
*access
,
956 __isl_take isl_set
*context
)
958 context
= isl_set_intersect(context
,
959 isl_map_params(isl_map_copy(access
)));
963 /* Update "context" with respect to the valid parameter values for "expr".
965 * If "expr" represents a ternary operator, then a parameter value
966 * needs to be valid for the condition and for at least one of the
967 * remaining two arguments.
968 * If the condition is an affine expression, then we can be a bit more specific.
969 * The parameter then has to be valid for the second argument for
970 * non-zero accesses and valid for the third argument for zero accesses.
972 static __isl_give isl_set
*expr_extract_context(struct pet_expr
*expr
,
973 __isl_take isl_set
*context
)
977 if (expr
->type
== pet_expr_ternary
) {
979 isl_set
*context1
, *context2
;
981 is_aff
= pet_expr_is_affine(expr
->args
[0]);
985 context
= expr_extract_context(expr
->args
[0], context
);
986 context1
= expr_extract_context(expr
->args
[1],
987 isl_set_copy(context
));
988 context2
= expr_extract_context(expr
->args
[2], context
);
994 access
= isl_map_copy(expr
->args
[0]->acc
.access
);
995 access
= isl_map_fix_si(access
, isl_dim_out
, 0, 0);
996 zero_set
= isl_map_params(access
);
997 context1
= isl_set_subtract(context1
,
998 isl_set_copy(zero_set
));
999 context2
= isl_set_intersect(context2
, zero_set
);
1002 context
= isl_set_union(context1
, context2
);
1003 context
= isl_set_coalesce(context
);
1008 for (i
= 0; i
< expr
->n_arg
; ++i
)
1009 context
= expr_extract_context(expr
->args
[i
], context
);
1011 if (expr
->type
== pet_expr_access
)
1012 context
= access_extract_context(expr
->acc
.access
, context
);
1016 isl_set_free(context
);
1020 /* Update "context" with respect to the valid parameter values for "stmt".
1022 static __isl_give isl_set
*stmt_extract_context(struct pet_stmt
*stmt
,
1023 __isl_take isl_set
*context
)
1027 for (i
= 0; i
< stmt
->n_arg
; ++i
)
1028 context
= expr_extract_context(stmt
->args
[i
], context
);
1030 context
= expr_extract_context(stmt
->body
, context
);
1035 /* Construct a pet_scop that contains the given pet_stmt.
1037 struct pet_scop
*pet_scop_from_pet_stmt(isl_ctx
*ctx
, struct pet_stmt
*stmt
)
1039 struct pet_scop
*scop
;
1044 scop
= scop_alloc(ctx
, 1);
1048 scop
->context
= stmt_extract_context(stmt
, scop
->context
);
1052 scop
->stmts
[0] = stmt
;
1056 pet_stmt_free(stmt
);
1057 pet_scop_free(scop
);
1061 /* Does "mpa" represent an access to an element of an unnamed space, i.e.,
1062 * does it represent an affine expression?
1064 static int multi_pw_aff_is_affine(__isl_keep isl_multi_pw_aff
*mpa
)
1068 has_id
= isl_multi_pw_aff_has_tuple_id(mpa
, isl_dim_out
);
1075 /* Return the piecewise affine expression "set ? 1 : 0" defined on "dom".
1077 static __isl_give isl_pw_aff
*indicator_function(__isl_take isl_set
*set
,
1078 __isl_take isl_set
*dom
)
1081 pa
= isl_set_indicator_function(set
);
1082 pa
= isl_pw_aff_intersect_domain(pa
, dom
);
1086 /* Return "lhs || rhs", defined on the shared definition domain.
1088 static __isl_give isl_pw_aff
*pw_aff_or(__isl_take isl_pw_aff
*lhs
,
1089 __isl_take isl_pw_aff
*rhs
)
1094 dom
= isl_set_intersect(isl_pw_aff_domain(isl_pw_aff_copy(lhs
)),
1095 isl_pw_aff_domain(isl_pw_aff_copy(rhs
)));
1096 cond
= isl_set_union(isl_pw_aff_non_zero_set(lhs
),
1097 isl_pw_aff_non_zero_set(rhs
));
1098 cond
= isl_set_coalesce(cond
);
1099 return indicator_function(cond
, dom
);
1102 /* Combine ext1->skip[type] and ext2->skip[type] into ext->skip[type].
1103 * ext may be equal to either ext1 or ext2.
1105 * The two skips that need to be combined are assumed to be affine expressions.
1107 * We need to skip in ext if we need to skip in either ext1 or ext2.
1108 * We don't need to skip in ext if we don't need to skip in both ext1 and ext2.
1110 static struct pet_scop_ext
*combine_skips(struct pet_scop_ext
*ext
,
1111 struct pet_scop_ext
*ext1
, struct pet_scop_ext
*ext2
,
1114 isl_pw_aff
*skip
, *skip1
, *skip2
;
1118 if (!ext1
->skip
[type
] && !ext2
->skip
[type
])
1120 if (!ext1
->skip
[type
]) {
1123 ext
->skip
[type
] = ext2
->skip
[type
];
1124 ext2
->skip
[type
] = NULL
;
1127 if (!ext2
->skip
[type
]) {
1130 ext
->skip
[type
] = ext1
->skip
[type
];
1131 ext1
->skip
[type
] = NULL
;
1135 if (!multi_pw_aff_is_affine(ext1
->skip
[type
]) ||
1136 !multi_pw_aff_is_affine(ext2
->skip
[type
]))
1137 isl_die(isl_multi_pw_aff_get_ctx(ext1
->skip
[type
]),
1138 isl_error_internal
, "can only combine affine skips",
1141 skip1
= isl_multi_pw_aff_get_pw_aff(ext1
->skip
[type
], 0);
1142 skip2
= isl_multi_pw_aff_get_pw_aff(ext2
->skip
[type
], 0);
1143 skip
= pw_aff_or(skip1
, skip2
);
1144 isl_multi_pw_aff_free(ext1
->skip
[type
]);
1145 ext1
->skip
[type
] = NULL
;
1146 isl_multi_pw_aff_free(ext2
->skip
[type
]);
1147 ext2
->skip
[type
] = NULL
;
1148 ext
->skip
[type
] = isl_multi_pw_aff_from_pw_aff(skip
);
1149 if (!ext
->skip
[type
])
1154 pet_scop_free(&ext
->scop
);
1158 /* Combine scop1->skip[type] and scop2->skip[type] into scop->skip[type],
1159 * where type takes on the values pet_skip_now and pet_skip_later.
1160 * scop may be equal to either scop1 or scop2.
1162 static struct pet_scop
*scop_combine_skips(struct pet_scop
*scop
,
1163 struct pet_scop
*scop1
, struct pet_scop
*scop2
)
1165 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
1166 struct pet_scop_ext
*ext1
= (struct pet_scop_ext
*) scop1
;
1167 struct pet_scop_ext
*ext2
= (struct pet_scop_ext
*) scop2
;
1169 ext
= combine_skips(ext
, ext1
, ext2
, pet_skip_now
);
1170 ext
= combine_skips(ext
, ext1
, ext2
, pet_skip_later
);
1174 /* Update scop->start and scop->end to include the region from "start"
1175 * to "end". In particular, if scop->end == 0, then "scop" does not
1176 * have any offset information yet and we simply take the information
1177 * from "start" and "end". Otherwise, we update the fields if the
1178 * region from "start" to "end" is not already included.
1180 struct pet_scop
*pet_scop_update_start_end(struct pet_scop
*scop
,
1181 unsigned start
, unsigned end
)
1185 if (scop
->end
== 0) {
1186 scop
->start
= start
;
1189 if (start
< scop
->start
)
1190 scop
->start
= start
;
1191 if (end
> scop
->end
)
1198 /* Does "implication" appear in the list of implications of "scop"?
1200 static int is_known_implication(struct pet_scop
*scop
,
1201 struct pet_implication
*implication
)
1205 for (i
= 0; i
< scop
->n_implication
; ++i
) {
1206 struct pet_implication
*pi
= scop
->implications
[i
];
1209 if (pi
->satisfied
!= implication
->satisfied
)
1211 equal
= isl_map_is_equal(pi
->extension
, implication
->extension
);
1221 /* Store the concatenation of the impliciations of "scop1" and "scop2"
1222 * in "scop", removing duplicates (i.e., implications in "scop2" that
1223 * already appear in "scop1").
1225 static struct pet_scop
*scop_collect_implications(isl_ctx
*ctx
,
1226 struct pet_scop
*scop
, struct pet_scop
*scop1
, struct pet_scop
*scop2
)
1233 if (scop2
->n_implication
== 0) {
1234 scop
->n_implication
= scop1
->n_implication
;
1235 scop
->implications
= scop1
->implications
;
1236 scop1
->n_implication
= 0;
1237 scop1
->implications
= NULL
;
1241 if (scop1
->n_implication
== 0) {
1242 scop
->n_implication
= scop2
->n_implication
;
1243 scop
->implications
= scop2
->implications
;
1244 scop2
->n_implication
= 0;
1245 scop2
->implications
= NULL
;
1249 scop
->implications
= isl_calloc_array(ctx
, struct pet_implication
*,
1250 scop1
->n_implication
+ scop2
->n_implication
);
1251 if (!scop
->implications
)
1252 return pet_scop_free(scop
);
1254 for (i
= 0; i
< scop1
->n_implication
; ++i
) {
1255 scop
->implications
[i
] = scop1
->implications
[i
];
1256 scop1
->implications
[i
] = NULL
;
1259 scop
->n_implication
= scop1
->n_implication
;
1260 j
= scop1
->n_implication
;
1261 for (i
= 0; i
< scop2
->n_implication
; ++i
) {
1264 known
= is_known_implication(scop
, scop2
->implications
[i
]);
1266 return pet_scop_free(scop
);
1269 scop
->implications
[j
++] = scop2
->implications
[i
];
1270 scop2
->implications
[i
] = NULL
;
1272 scop
->n_implication
= j
;
1277 /* Combine the offset information of "scop1" and "scop2" into "scop".
1279 static struct pet_scop
*scop_combine_start_end(struct pet_scop
*scop
,
1280 struct pet_scop
*scop1
, struct pet_scop
*scop2
)
1283 scop
= pet_scop_update_start_end(scop
,
1284 scop1
->start
, scop1
->end
);
1286 scop
= pet_scop_update_start_end(scop
,
1287 scop2
->start
, scop2
->end
);
1291 /* Construct a pet_scop that contains the offset information,
1292 * arrays, statements and skip information in "scop1" and "scop2".
1294 static struct pet_scop
*pet_scop_add(isl_ctx
*ctx
, struct pet_scop
*scop1
,
1295 struct pet_scop
*scop2
)
1298 struct pet_scop
*scop
= NULL
;
1300 if (!scop1
|| !scop2
)
1303 if (scop1
->n_stmt
== 0) {
1304 scop2
= scop_combine_skips(scop2
, scop1
, scop2
);
1305 pet_scop_free(scop1
);
1309 if (scop2
->n_stmt
== 0) {
1310 scop1
= scop_combine_skips(scop1
, scop1
, scop2
);
1311 pet_scop_free(scop2
);
1315 scop
= scop_alloc(ctx
, scop1
->n_stmt
+ scop2
->n_stmt
);
1319 scop
->arrays
= isl_calloc_array(ctx
, struct pet_array
*,
1320 scop1
->n_array
+ scop2
->n_array
);
1323 scop
->n_array
= scop1
->n_array
+ scop2
->n_array
;
1325 for (i
= 0; i
< scop1
->n_stmt
; ++i
) {
1326 scop
->stmts
[i
] = scop1
->stmts
[i
];
1327 scop1
->stmts
[i
] = NULL
;
1330 for (i
= 0; i
< scop2
->n_stmt
; ++i
) {
1331 scop
->stmts
[scop1
->n_stmt
+ i
] = scop2
->stmts
[i
];
1332 scop2
->stmts
[i
] = NULL
;
1335 for (i
= 0; i
< scop1
->n_array
; ++i
) {
1336 scop
->arrays
[i
] = scop1
->arrays
[i
];
1337 scop1
->arrays
[i
] = NULL
;
1340 for (i
= 0; i
< scop2
->n_array
; ++i
) {
1341 scop
->arrays
[scop1
->n_array
+ i
] = scop2
->arrays
[i
];
1342 scop2
->arrays
[i
] = NULL
;
1345 scop
= scop_collect_implications(ctx
, scop
, scop1
, scop2
);
1346 scop
= pet_scop_restrict_context(scop
, isl_set_copy(scop1
->context
));
1347 scop
= pet_scop_restrict_context(scop
, isl_set_copy(scop2
->context
));
1348 scop
= scop_combine_skips(scop
, scop1
, scop2
);
1349 scop
= scop_combine_start_end(scop
, scop1
, scop2
);
1351 pet_scop_free(scop1
);
1352 pet_scop_free(scop2
);
1355 pet_scop_free(scop1
);
1356 pet_scop_free(scop2
);
1357 pet_scop_free(scop
);
1361 /* Apply the skip condition "skip" to "scop".
1362 * That is, make sure "scop" is not executed when the condition holds.
1364 * If "skip" is an affine expression, we add the conditions under
1365 * which the expression is zero to the iteration domains.
1366 * Otherwise, we add a filter on the variable attaining the value zero.
1368 static struct pet_scop
*restrict_skip(struct pet_scop
*scop
,
1369 __isl_take isl_multi_pw_aff
*skip
)
1378 is_aff
= multi_pw_aff_is_affine(skip
);
1383 return pet_scop_filter(scop
, skip
, 0);
1385 pa
= isl_multi_pw_aff_get_pw_aff(skip
, 0);
1386 isl_multi_pw_aff_free(skip
);
1387 zero
= isl_set_params(isl_pw_aff_zero_set(pa
));
1388 scop
= pet_scop_restrict(scop
, zero
);
1392 isl_multi_pw_aff_free(skip
);
1393 return pet_scop_free(scop
);
1396 /* Construct a pet_scop that contains the arrays, statements and
1397 * skip information in "scop1" and "scop2", where the two scops
1398 * are executed "in sequence". That is, breaks and continues
1399 * in scop1 have an effect on scop2.
1401 struct pet_scop
*pet_scop_add_seq(isl_ctx
*ctx
, struct pet_scop
*scop1
,
1402 struct pet_scop
*scop2
)
1404 if (scop1
&& pet_scop_has_skip(scop1
, pet_skip_now
))
1405 scop2
= restrict_skip(scop2
,
1406 pet_scop_get_skip(scop1
, pet_skip_now
));
1407 return pet_scop_add(ctx
, scop1
, scop2
);
1410 /* Construct a pet_scop that contains the arrays, statements and
1411 * skip information in "scop1" and "scop2", where the two scops
1412 * are executed "in parallel". That is, any break or continue
1413 * in scop1 has no effect on scop2.
1415 struct pet_scop
*pet_scop_add_par(isl_ctx
*ctx
, struct pet_scop
*scop1
,
1416 struct pet_scop
*scop2
)
1418 return pet_scop_add(ctx
, scop1
, scop2
);
1421 void *pet_implication_free(struct pet_implication
*implication
)
1428 isl_map_free(implication
->extension
);
1434 struct pet_scop
*pet_scop_free(struct pet_scop
*scop
)
1437 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
1441 isl_set_free(scop
->context
);
1442 isl_set_free(scop
->context_value
);
1444 for (i
= 0; i
< scop
->n_type
; ++i
)
1445 pet_type_free(scop
->types
[i
]);
1448 for (i
= 0; i
< scop
->n_array
; ++i
)
1449 pet_array_free(scop
->arrays
[i
]);
1452 for (i
= 0; i
< scop
->n_stmt
; ++i
)
1453 pet_stmt_free(scop
->stmts
[i
]);
1455 if (scop
->implications
)
1456 for (i
= 0; i
< scop
->n_implication
; ++i
)
1457 pet_implication_free(scop
->implications
[i
]);
1458 free(scop
->implications
);
1459 isl_multi_pw_aff_free(ext
->skip
[pet_skip_now
]);
1460 isl_multi_pw_aff_free(ext
->skip
[pet_skip_later
]);
1465 void pet_type_dump(struct pet_type
*type
)
1470 fprintf(stderr
, "%s -> %s\n", type
->name
, type
->definition
);
1473 void pet_implication_dump(struct pet_implication
*implication
)
1478 fprintf(stderr
, "%d\n", implication
->satisfied
);
1479 isl_map_dump(implication
->extension
);
1482 void pet_scop_dump(struct pet_scop
*scop
)
1485 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
1490 isl_set_dump(scop
->context
);
1491 isl_set_dump(scop
->context_value
);
1492 for (i
= 0; i
< scop
->n_type
; ++i
)
1493 pet_type_dump(scop
->types
[i
]);
1494 for (i
= 0; i
< scop
->n_array
; ++i
)
1495 pet_array_dump(scop
->arrays
[i
]);
1496 for (i
= 0; i
< scop
->n_stmt
; ++i
)
1497 pet_stmt_dump(scop
->stmts
[i
]);
1498 for (i
= 0; i
< scop
->n_implication
; ++i
)
1499 pet_implication_dump(scop
->implications
[i
]);
1502 fprintf(stderr
, "skip\n");
1503 isl_multi_pw_aff_dump(ext
->skip
[0]);
1504 isl_multi_pw_aff_dump(ext
->skip
[1]);
1508 /* Return 1 if the two pet_arrays are equivalent.
1510 * We don't compare element_size as this may be target dependent.
1512 int pet_array_is_equal(struct pet_array
*array1
, struct pet_array
*array2
)
1514 if (!array1
|| !array2
)
1517 if (!isl_set_is_equal(array1
->context
, array2
->context
))
1519 if (!isl_set_is_equal(array1
->extent
, array2
->extent
))
1521 if (!!array1
->value_bounds
!= !!array2
->value_bounds
)
1523 if (array1
->value_bounds
&&
1524 !isl_set_is_equal(array1
->value_bounds
, array2
->value_bounds
))
1526 if (strcmp(array1
->element_type
, array2
->element_type
))
1528 if (array1
->live_out
!= array2
->live_out
)
1530 if (array1
->uniquely_defined
!= array2
->uniquely_defined
)
1532 if (array1
->declared
!= array2
->declared
)
1534 if (array1
->exposed
!= array2
->exposed
)
1540 /* Return 1 if the two pet_stmts are equivalent.
1542 int pet_stmt_is_equal(struct pet_stmt
*stmt1
, struct pet_stmt
*stmt2
)
1546 if (!stmt1
|| !stmt2
)
1549 if (stmt1
->line
!= stmt2
->line
)
1551 if (!isl_set_is_equal(stmt1
->domain
, stmt2
->domain
))
1553 if (!isl_map_is_equal(stmt1
->schedule
, stmt2
->schedule
))
1555 if (!pet_expr_is_equal(stmt1
->body
, stmt2
->body
))
1557 if (stmt1
->n_arg
!= stmt2
->n_arg
)
1559 for (i
= 0; i
< stmt1
->n_arg
; ++i
) {
1560 if (!pet_expr_is_equal(stmt1
->args
[i
], stmt2
->args
[i
]))
1567 /* Return 1 if the two pet_types are equivalent.
1569 * We only compare the names of the types since the exact representation
1570 * of the definition may depend on the version of clang being used.
1572 int pet_type_is_equal(struct pet_type
*type1
, struct pet_type
*type2
)
1574 if (!type1
|| !type2
)
1577 if (strcmp(type1
->name
, type2
->name
))
1583 /* Return 1 if the two pet_implications are equivalent.
1585 int pet_implication_is_equal(struct pet_implication
*implication1
,
1586 struct pet_implication
*implication2
)
1588 if (!implication1
|| !implication2
)
1591 if (implication1
->satisfied
!= implication2
->satisfied
)
1593 if (!isl_map_is_equal(implication1
->extension
, implication2
->extension
))
1599 /* Return 1 if the two pet_scops are equivalent.
1601 int pet_scop_is_equal(struct pet_scop
*scop1
, struct pet_scop
*scop2
)
1605 if (!scop1
|| !scop2
)
1608 if (!isl_set_is_equal(scop1
->context
, scop2
->context
))
1610 if (!isl_set_is_equal(scop1
->context_value
, scop2
->context_value
))
1613 if (scop1
->n_type
!= scop2
->n_type
)
1615 for (i
= 0; i
< scop1
->n_type
; ++i
)
1616 if (!pet_type_is_equal(scop1
->types
[i
], scop2
->types
[i
]))
1619 if (scop1
->n_array
!= scop2
->n_array
)
1621 for (i
= 0; i
< scop1
->n_array
; ++i
)
1622 if (!pet_array_is_equal(scop1
->arrays
[i
], scop2
->arrays
[i
]))
1625 if (scop1
->n_stmt
!= scop2
->n_stmt
)
1627 for (i
= 0; i
< scop1
->n_stmt
; ++i
)
1628 if (!pet_stmt_is_equal(scop1
->stmts
[i
], scop2
->stmts
[i
]))
1631 if (scop1
->n_implication
!= scop2
->n_implication
)
1633 for (i
= 0; i
< scop1
->n_implication
; ++i
)
1634 if (!pet_implication_is_equal(scop1
->implications
[i
],
1635 scop2
->implications
[i
]))
1641 /* Prefix the schedule of "stmt" with an extra dimension with constant
1644 struct pet_stmt
*pet_stmt_prefix(struct pet_stmt
*stmt
, int pos
)
1649 stmt
->schedule
= isl_map_insert_dims(stmt
->schedule
, isl_dim_out
, 0, 1);
1650 stmt
->schedule
= isl_map_fix_si(stmt
->schedule
, isl_dim_out
, 0, pos
);
1651 if (!stmt
->schedule
)
1652 return pet_stmt_free(stmt
);
1657 /* Prefix the schedules of all statements in "scop" with an extra
1658 * dimension with constant value "pos".
1660 struct pet_scop
*pet_scop_prefix(struct pet_scop
*scop
, int pos
)
1667 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1668 scop
->stmts
[i
] = pet_stmt_prefix(scop
->stmts
[i
], pos
);
1669 if (!scop
->stmts
[i
])
1670 return pet_scop_free(scop
);
1676 /* Given a set with a parameter at "param_pos" that refers to the
1677 * iterator, "move" the iterator to the first set dimension.
1678 * That is, essentially equate the parameter to the first set dimension
1679 * and then project it out.
1681 * The first set dimension may however refer to a virtual iterator,
1682 * while the parameter refers to the "real" iterator.
1683 * We therefore need to take into account the affine expression "iv_map", which
1684 * expresses the real iterator in terms of the virtual iterator.
1685 * In particular, we equate the set dimension to the input of the map
1686 * and the parameter to the output of the map and then project out
1687 * everything we don't need anymore.
1689 static __isl_give isl_set
*internalize_iv(__isl_take isl_set
*set
,
1690 int param_pos
, __isl_take isl_aff
*iv_map
)
1692 isl_map
*map
, *map2
;
1693 map
= isl_map_from_domain(set
);
1694 map
= isl_map_add_dims(map
, isl_dim_out
, 1);
1695 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
1696 map2
= isl_map_from_aff(iv_map
);
1697 map2
= isl_map_align_params(map2
, isl_map_get_space(map
));
1698 map
= isl_map_apply_range(map
, map2
);
1699 map
= isl_map_equate(map
, isl_dim_param
, param_pos
, isl_dim_out
, 0);
1700 map
= isl_map_project_out(map
, isl_dim_param
, param_pos
, 1);
1701 return isl_map_domain(map
);
1704 /* Data used in embed_access.
1705 * extend adds an iterator to the iteration domain (through precomposition).
1706 * iv_map expresses the real iterator in terms of the virtual iterator
1707 * var_id represents the induction variable of the corresponding loop
1709 struct pet_embed_access
{
1710 isl_multi_pw_aff
*extend
;
1715 /* Given an index expression, return an expression for the outer iterator.
1717 static __isl_give isl_aff
*index_outer_iterator(
1718 __isl_take isl_multi_pw_aff
*index
)
1721 isl_local_space
*ls
;
1723 space
= isl_multi_pw_aff_get_domain_space(index
);
1724 isl_multi_pw_aff_free(index
);
1726 ls
= isl_local_space_from_space(space
);
1727 return isl_aff_var_on_domain(ls
, isl_dim_set
, 0);
1730 /* Replace an index expression that references the new (outer) iterator variable
1731 * by one that references the corresponding (real) iterator.
1733 * The input index expression is of the form
1735 * { S[i',...] -> i[] }
1737 * where i' refers to the virtual iterator.
1739 * iv_map is of the form
1743 * Return the index expression
1745 * { S[i',...] -> [i] }
1747 static __isl_give isl_multi_pw_aff
*replace_by_iterator(
1748 __isl_take isl_multi_pw_aff
*index
, __isl_take isl_aff
*iv_map
)
1753 aff
= index_outer_iterator(index
);
1754 space
= isl_aff_get_space(aff
);
1755 iv_map
= isl_aff_align_params(iv_map
, space
);
1756 aff
= isl_aff_pullback_aff(iv_map
, aff
);
1758 return isl_multi_pw_aff_from_pw_aff(isl_pw_aff_from_aff(aff
));
1761 /* Given an index expression "index" that refers to the (real) iterator
1762 * through the parameter at position "pos", plug in "iv_map", expressing
1763 * the real iterator in terms of the virtual (outer) iterator.
1765 * In particular, the index expression is of the form
1767 * [..., i, ...] -> { S[i',...] -> ... i ... }
1769 * where i refers to the real iterator and i' refers to the virtual iterator.
1771 * iv_map is of the form
1775 * Return the index expression
1777 * [..., ...] -> { S[i',...] -> ... iv_map(i') ... }
1780 * We first move the parameter to the input
1782 * [..., ...] -> { [i, i',...] -> ... i ... }
1786 * { S[i',...] -> [i=iv_map(i'), i', ...] }
1788 * and then combine the two to obtain the desired result.
1790 static __isl_give isl_multi_pw_aff
*index_internalize_iv(
1791 __isl_take isl_multi_pw_aff
*index
, int pos
, __isl_take isl_aff
*iv_map
)
1793 isl_space
*space
= isl_multi_pw_aff_get_domain_space(index
);
1796 space
= isl_space_drop_dims(space
, isl_dim_param
, pos
, 1);
1797 index
= isl_multi_pw_aff_move_dims(index
, isl_dim_in
, 0,
1798 isl_dim_param
, pos
, 1);
1800 space
= isl_space_map_from_set(space
);
1801 ma
= isl_multi_aff_identity(isl_space_copy(space
));
1802 iv_map
= isl_aff_align_params(iv_map
, space
);
1803 iv_map
= isl_aff_pullback_aff(iv_map
, isl_multi_aff_get_aff(ma
, 0));
1804 ma
= isl_multi_aff_flat_range_product(
1805 isl_multi_aff_from_aff(iv_map
), ma
);
1806 index
= isl_multi_pw_aff_pullback_multi_aff(index
, ma
);
1811 /* Embed the given index expression in an extra outer loop.
1812 * The domain of the index expression has already been updated.
1814 * If the access refers to the induction variable, then it is
1815 * turned into an access to the set of integers with index (and value)
1816 * equal to the induction variable.
1818 * If the accessed array is a virtual array (with user
1819 * pointer equal to NULL), as created by create_test_index,
1820 * then it is extended along with the domain of the index expression.
1822 static __isl_give isl_multi_pw_aff
*embed_index_expression(
1823 __isl_take isl_multi_pw_aff
*index
, struct pet_embed_access
*data
)
1825 isl_id
*array_id
= NULL
;
1828 if (isl_multi_pw_aff_has_tuple_id(index
, isl_dim_out
))
1829 array_id
= isl_multi_pw_aff_get_tuple_id(index
, isl_dim_out
);
1830 if (array_id
== data
->var_id
) {
1831 index
= replace_by_iterator(index
, isl_aff_copy(data
->iv_map
));
1832 } else if (array_id
&& !isl_id_get_user(array_id
)) {
1834 isl_multi_pw_aff
*mpa
;
1836 aff
= index_outer_iterator(isl_multi_pw_aff_copy(index
));
1837 mpa
= isl_multi_pw_aff_from_pw_aff(isl_pw_aff_from_aff(aff
));
1838 index
= isl_multi_pw_aff_flat_range_product(mpa
, index
);
1839 index
= isl_multi_pw_aff_set_tuple_id(index
, isl_dim_out
,
1840 isl_id_copy(array_id
));
1842 isl_id_free(array_id
);
1844 pos
= isl_multi_pw_aff_find_dim_by_id(index
,
1845 isl_dim_param
, data
->var_id
);
1847 index
= index_internalize_iv(index
, pos
,
1848 isl_aff_copy(data
->iv_map
));
1849 index
= isl_multi_pw_aff_set_dim_id(index
, isl_dim_in
, 0,
1850 isl_id_copy(data
->var_id
));
1855 /* Embed the given access relation in an extra outer loop.
1856 * The domain of the access relation has already been updated.
1858 * If the access refers to the induction variable, then it is
1859 * turned into an access to the set of integers with index (and value)
1860 * equal to the induction variable.
1862 * If the induction variable appears in the constraints (as a parameter),
1863 * then the parameter is equated to the newly introduced iteration
1864 * domain dimension and subsequently projected out.
1866 * Similarly, if the accessed array is a virtual array (with user
1867 * pointer equal to NULL), as created by create_test_index,
1868 * then it is extended along with the domain of the access.
1870 static __isl_give isl_map
*embed_access_relation(__isl_take isl_map
*access
,
1871 struct pet_embed_access
*data
)
1873 isl_id
*array_id
= NULL
;
1876 if (isl_map_has_tuple_id(access
, isl_dim_out
))
1877 array_id
= isl_map_get_tuple_id(access
, isl_dim_out
);
1878 if (array_id
== data
->var_id
||
1879 (array_id
&& !isl_id_get_user(array_id
))) {
1880 access
= isl_map_insert_dims(access
, isl_dim_out
, 0, 1);
1881 access
= isl_map_equate(access
,
1882 isl_dim_in
, 0, isl_dim_out
, 0);
1883 if (array_id
== data
->var_id
)
1884 access
= isl_map_apply_range(access
,
1885 isl_map_from_aff(isl_aff_copy(data
->iv_map
)));
1887 access
= isl_map_set_tuple_id(access
, isl_dim_out
,
1888 isl_id_copy(array_id
));
1890 isl_id_free(array_id
);
1892 pos
= isl_map_find_dim_by_id(access
, isl_dim_param
, data
->var_id
);
1894 isl_set
*set
= isl_map_wrap(access
);
1895 set
= internalize_iv(set
, pos
, isl_aff_copy(data
->iv_map
));
1896 access
= isl_set_unwrap(set
);
1898 access
= isl_map_set_dim_id(access
, isl_dim_in
, 0,
1899 isl_id_copy(data
->var_id
));
1904 /* Given an access expression, embed the associated access relation and
1905 * index expression in an extra outer loop.
1907 * We first update the domains to insert the extra dimension and
1908 * then update the access relation and index expression to take
1909 * into account the mapping "iv_map" from virtual iterator
1912 static struct pet_expr
*embed_access(struct pet_expr
*expr
, void *user
)
1915 struct pet_embed_access
*data
= user
;
1917 expr
= update_domain(expr
, data
->extend
);
1921 expr
->acc
.access
= embed_access_relation(expr
->acc
.access
, data
);
1922 expr
->acc
.index
= embed_index_expression(expr
->acc
.index
, data
);
1923 if (!expr
->acc
.access
|| !expr
->acc
.index
)
1924 return pet_expr_free(expr
);
1929 /* Embed all access subexpressions of "expr" in an extra loop.
1930 * "extend" inserts an outer loop iterator in the iteration domains
1931 * (through precomposition).
1932 * "iv_map" expresses the real iterator in terms of the virtual iterator
1933 * "var_id" represents the induction variable.
1935 static struct pet_expr
*expr_embed(struct pet_expr
*expr
,
1936 __isl_take isl_multi_pw_aff
*extend
, __isl_take isl_aff
*iv_map
,
1937 __isl_keep isl_id
*var_id
)
1939 struct pet_embed_access data
=
1940 { .extend
= extend
, .iv_map
= iv_map
, .var_id
= var_id
};
1942 expr
= pet_expr_map_access(expr
, &embed_access
, &data
);
1943 isl_aff_free(iv_map
);
1944 isl_multi_pw_aff_free(extend
);
1948 /* Embed the given pet_stmt in an extra outer loop with iteration domain
1949 * "dom" and schedule "sched". "var_id" represents the induction variable
1950 * of the loop. "iv_map" maps a possibly virtual iterator to the real iterator.
1951 * That is, it expresses the iterator that some of the parameters in "stmt"
1952 * may refer to in terms of the iterator used in "dom" and
1953 * the domain of "sched".
1955 * The iteration domain and schedule of the statement are updated
1956 * according to the iteration domain and schedule of the new loop.
1957 * If stmt->domain is a wrapped map, then the iteration domain
1958 * is the domain of this map, so we need to be careful to adjust
1961 * If the induction variable appears in the constraints (as a parameter)
1962 * of the current iteration domain or the schedule of the statement,
1963 * then the parameter is equated to the newly introduced iteration
1964 * domain dimension and subsequently projected out.
1966 * Finally, all access relations are updated based on the extra loop.
1968 static struct pet_stmt
*pet_stmt_embed(struct pet_stmt
*stmt
,
1969 __isl_take isl_set
*dom
, __isl_take isl_map
*sched
,
1970 __isl_take isl_aff
*iv_map
, __isl_take isl_id
*var_id
)
1976 isl_multi_pw_aff
*extend
;
1981 if (isl_set_is_wrapping(stmt
->domain
)) {
1986 map
= isl_set_unwrap(stmt
->domain
);
1987 stmt_id
= isl_map_get_tuple_id(map
, isl_dim_in
);
1988 ran_dim
= isl_space_range(isl_map_get_space(map
));
1989 ext
= isl_map_from_domain_and_range(isl_set_copy(dom
),
1990 isl_set_universe(ran_dim
));
1991 map
= isl_map_flat_domain_product(ext
, map
);
1992 map
= isl_map_set_tuple_id(map
, isl_dim_in
,
1993 isl_id_copy(stmt_id
));
1994 dim
= isl_space_domain(isl_map_get_space(map
));
1995 stmt
->domain
= isl_map_wrap(map
);
1997 stmt_id
= isl_set_get_tuple_id(stmt
->domain
);
1998 stmt
->domain
= isl_set_flat_product(isl_set_copy(dom
),
2000 stmt
->domain
= isl_set_set_tuple_id(stmt
->domain
,
2001 isl_id_copy(stmt_id
));
2002 dim
= isl_set_get_space(stmt
->domain
);
2005 pos
= isl_set_find_dim_by_id(stmt
->domain
, isl_dim_param
, var_id
);
2007 stmt
->domain
= internalize_iv(stmt
->domain
, pos
,
2008 isl_aff_copy(iv_map
));
2010 stmt
->schedule
= isl_map_flat_product(sched
, stmt
->schedule
);
2011 stmt
->schedule
= isl_map_set_tuple_id(stmt
->schedule
,
2012 isl_dim_in
, stmt_id
);
2014 pos
= isl_map_find_dim_by_id(stmt
->schedule
, isl_dim_param
, var_id
);
2016 isl_set
*set
= isl_map_wrap(stmt
->schedule
);
2017 set
= internalize_iv(set
, pos
, isl_aff_copy(iv_map
));
2018 stmt
->schedule
= isl_set_unwrap(set
);
2021 dim
= isl_space_map_from_set(dim
);
2022 extend
= isl_multi_pw_aff_identity(dim
);
2023 extend
= isl_multi_pw_aff_drop_dims(extend
, isl_dim_out
, 0, 1);
2024 extend
= isl_multi_pw_aff_set_tuple_id(extend
, isl_dim_out
,
2025 isl_multi_pw_aff_get_tuple_id(extend
, isl_dim_in
));
2026 for (i
= 0; i
< stmt
->n_arg
; ++i
)
2027 stmt
->args
[i
] = expr_embed(stmt
->args
[i
],
2028 isl_multi_pw_aff_copy(extend
),
2029 isl_aff_copy(iv_map
), var_id
);
2030 stmt
->body
= expr_embed(stmt
->body
, extend
, iv_map
, var_id
);
2033 isl_id_free(var_id
);
2035 for (i
= 0; i
< stmt
->n_arg
; ++i
)
2037 return pet_stmt_free(stmt
);
2038 if (!stmt
->domain
|| !stmt
->schedule
|| !stmt
->body
)
2039 return pet_stmt_free(stmt
);
2043 isl_map_free(sched
);
2044 isl_aff_free(iv_map
);
2045 isl_id_free(var_id
);
2049 /* Embed the given pet_array in an extra outer loop with iteration domain
2051 * This embedding only has an effect on virtual arrays (those with
2052 * user pointer equal to NULL), which need to be extended along with
2053 * the iteration domain.
2055 static struct pet_array
*pet_array_embed(struct pet_array
*array
,
2056 __isl_take isl_set
*dom
)
2058 isl_id
*array_id
= NULL
;
2063 if (isl_set_has_tuple_id(array
->extent
))
2064 array_id
= isl_set_get_tuple_id(array
->extent
);
2066 if (array_id
&& !isl_id_get_user(array_id
)) {
2067 array
->extent
= isl_set_flat_product(dom
, array
->extent
);
2068 array
->extent
= isl_set_set_tuple_id(array
->extent
, array_id
);
2070 return pet_array_free(array
);
2073 isl_id_free(array_id
);
2082 /* Project out all unnamed parameters from "set" and return the result.
2084 static __isl_give isl_set
*set_project_out_unnamed_params(
2085 __isl_take isl_set
*set
)
2089 n
= isl_set_dim(set
, isl_dim_param
);
2090 for (i
= n
- 1; i
>= 0; --i
) {
2091 if (isl_set_has_dim_name(set
, isl_dim_param
, i
))
2093 set
= isl_set_project_out(set
, isl_dim_param
, i
, 1);
2099 /* Update the context with respect to an embedding into a loop
2100 * with iteration domain "dom" and induction variable "id".
2101 * "iv_map" expresses the real iterator (parameter "id") in terms
2102 * of a possibly virtual iterator (used in "dom").
2104 * If the current context is independent of "id", we don't need
2106 * Otherwise, a parameter value is invalid for the embedding if
2107 * any of the corresponding iterator values is invalid.
2108 * That is, a parameter value is valid only if all the corresponding
2109 * iterator values are valid.
2110 * We therefore compute the set of parameters
2112 * forall i in dom : valid (i)
2116 * not exists i in dom : not valid(i)
2120 * not exists i in dom \ valid(i)
2122 * Before we subtract valid(i) from dom, we first need to substitute
2123 * the real iterator for the virtual iterator.
2125 * If there are any unnamed parameters in "dom", then we consider
2126 * a parameter value to be valid if it is valid for any value of those
2127 * unnamed parameters. They are therefore projected out at the end.
2129 static __isl_give isl_set
*context_embed(__isl_take isl_set
*context
,
2130 __isl_keep isl_set
*dom
, __isl_keep isl_aff
*iv_map
,
2131 __isl_keep isl_id
*id
)
2136 pos
= isl_set_find_dim_by_id(context
, isl_dim_param
, id
);
2140 context
= isl_set_from_params(context
);
2141 context
= isl_set_add_dims(context
, isl_dim_set
, 1);
2142 context
= isl_set_equate(context
, isl_dim_param
, pos
, isl_dim_set
, 0);
2143 context
= isl_set_project_out(context
, isl_dim_param
, pos
, 1);
2144 ma
= isl_multi_aff_from_aff(isl_aff_copy(iv_map
));
2145 context
= isl_set_preimage_multi_aff(context
, ma
);
2146 context
= isl_set_subtract(isl_set_copy(dom
), context
);
2147 context
= isl_set_params(context
);
2148 context
= isl_set_complement(context
);
2149 context
= set_project_out_unnamed_params(context
);
2153 /* Update the implication with respect to an embedding into a loop
2154 * with iteration domain "dom".
2156 * Since embed_access extends virtual arrays along with the domain
2157 * of the access, we need to do the same with domain and range
2158 * of the implication. Since the original implication is only valid
2159 * within a given iteration of the loop, the extended implication
2160 * maps the extra array dimension corresponding to the extra loop
2163 static struct pet_implication
*pet_implication_embed(
2164 struct pet_implication
*implication
, __isl_take isl_set
*dom
)
2172 map
= isl_set_identity(dom
);
2173 id
= isl_map_get_tuple_id(implication
->extension
, isl_dim_in
);
2174 map
= isl_map_flat_product(map
, implication
->extension
);
2175 map
= isl_map_set_tuple_id(map
, isl_dim_in
, isl_id_copy(id
));
2176 map
= isl_map_set_tuple_id(map
, isl_dim_out
, id
);
2177 implication
->extension
= map
;
2178 if (!implication
->extension
)
2179 return pet_implication_free(implication
);
2187 /* Embed all statements and arrays in "scop" in an extra outer loop
2188 * with iteration domain "dom" and schedule "sched".
2189 * "id" represents the induction variable of the loop.
2190 * "iv_map" maps a possibly virtual iterator to the real iterator.
2191 * That is, it expresses the iterator that some of the parameters in "scop"
2192 * may refer to in terms of the iterator used in "dom" and
2193 * the domain of "sched".
2195 * Any skip conditions within the loop have no effect outside of the loop.
2196 * The caller is responsible for making sure skip[pet_skip_later] has been
2197 * taken into account.
2199 struct pet_scop
*pet_scop_embed(struct pet_scop
*scop
, __isl_take isl_set
*dom
,
2200 __isl_take isl_map
*sched
, __isl_take isl_aff
*iv_map
,
2201 __isl_take isl_id
*id
)
2208 pet_scop_reset_skip(scop
, pet_skip_now
);
2209 pet_scop_reset_skip(scop
, pet_skip_later
);
2211 scop
->context
= context_embed(scop
->context
, dom
, iv_map
, id
);
2215 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
2216 scop
->stmts
[i
] = pet_stmt_embed(scop
->stmts
[i
],
2217 isl_set_copy(dom
), isl_map_copy(sched
),
2218 isl_aff_copy(iv_map
), isl_id_copy(id
));
2219 if (!scop
->stmts
[i
])
2223 for (i
= 0; i
< scop
->n_array
; ++i
) {
2224 scop
->arrays
[i
] = pet_array_embed(scop
->arrays
[i
],
2226 if (!scop
->arrays
[i
])
2230 for (i
= 0; i
< scop
->n_implication
; ++i
) {
2231 scop
->implications
[i
] =
2232 pet_implication_embed(scop
->implications
[i
],
2234 if (!scop
->implications
[i
])
2239 isl_map_free(sched
);
2240 isl_aff_free(iv_map
);
2245 isl_map_free(sched
);
2246 isl_aff_free(iv_map
);
2248 return pet_scop_free(scop
);
2251 /* Add extra conditions on the parameters to iteration domain of "stmt".
2253 static struct pet_stmt
*stmt_restrict(struct pet_stmt
*stmt
,
2254 __isl_take isl_set
*cond
)
2259 stmt
->domain
= isl_set_intersect_params(stmt
->domain
, cond
);
2264 return pet_stmt_free(stmt
);
2267 /* Add extra conditions to scop->skip[type].
2269 * The new skip condition only holds if it held before
2270 * and the condition is true. It does not hold if it did not hold
2271 * before or the condition is false.
2273 * The skip condition is assumed to be an affine expression.
2275 static struct pet_scop
*pet_scop_restrict_skip(struct pet_scop
*scop
,
2276 enum pet_skip type
, __isl_keep isl_set
*cond
)
2278 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
2284 if (!ext
->skip
[type
])
2287 if (!multi_pw_aff_is_affine(ext
->skip
[type
]))
2288 isl_die(isl_multi_pw_aff_get_ctx(ext
->skip
[type
]),
2289 isl_error_internal
, "can only resrict affine skips",
2290 return pet_scop_free(scop
));
2292 skip
= isl_multi_pw_aff_get_pw_aff(ext
->skip
[type
], 0);
2293 dom
= isl_pw_aff_domain(isl_pw_aff_copy(skip
));
2294 cond
= isl_set_copy(cond
);
2295 cond
= isl_set_from_params(cond
);
2296 cond
= isl_set_intersect(cond
, isl_pw_aff_non_zero_set(skip
));
2297 skip
= indicator_function(cond
, dom
);
2298 isl_multi_pw_aff_free(ext
->skip
[type
]);
2299 ext
->skip
[type
] = isl_multi_pw_aff_from_pw_aff(skip
);
2300 if (!ext
->skip
[type
])
2301 return pet_scop_free(scop
);
2306 /* Add extra conditions on the parameters to all iteration domains
2307 * and skip conditions.
2309 * A parameter value is valid for the result if it was valid
2310 * for the original scop and satisfies "cond" or if it does
2311 * not satisfy "cond" as in this case the scop is not executed
2312 * and the original constraints on the parameters are irrelevant.
2314 struct pet_scop
*pet_scop_restrict(struct pet_scop
*scop
,
2315 __isl_take isl_set
*cond
)
2319 scop
= pet_scop_restrict_skip(scop
, pet_skip_now
, cond
);
2320 scop
= pet_scop_restrict_skip(scop
, pet_skip_later
, cond
);
2325 scop
->context
= isl_set_intersect(scop
->context
, isl_set_copy(cond
));
2326 scop
->context
= isl_set_union(scop
->context
,
2327 isl_set_complement(isl_set_copy(cond
)));
2328 scop
->context
= isl_set_coalesce(scop
->context
);
2329 scop
->context
= set_project_out_unnamed_params(scop
->context
);
2333 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
2334 scop
->stmts
[i
] = stmt_restrict(scop
->stmts
[i
],
2335 isl_set_copy(cond
));
2336 if (!scop
->stmts
[i
])
2344 return pet_scop_free(scop
);
2347 /* Construct a function that (upon precomposition) inserts
2348 * a filter value with name "id" and value "satisfied"
2349 * in the list of filter values embedded in the set space "space".
2351 * If "space" does not contain any filter values yet, we first create
2352 * a function that inserts 0 filter values, i.e.,
2354 * [space -> []] -> space
2356 * We can now assume that space is of the form [dom -> [filters]]
2357 * We construct an identity mapping on dom and a mapping on filters
2358 * that (upon precomposition) inserts the new filter
2361 * [satisfied, filters] -> [filters]
2363 * and then compute the cross product
2365 * [dom -> [satisfied, filters]] -> [dom -> [filters]]
2367 static __isl_give isl_pw_multi_aff
*insert_filter_pma(
2368 __isl_take isl_space
*space
, __isl_take isl_id
*id
, int satisfied
)
2372 isl_pw_multi_aff
*pma0
, *pma
, *pma_dom
, *pma_ran
;
2375 if (isl_space_is_wrapping(space
)) {
2376 space2
= isl_space_map_from_set(isl_space_copy(space
));
2377 ma
= isl_multi_aff_identity(space2
);
2378 space
= isl_space_unwrap(space
);
2380 space
= isl_space_from_domain(space
);
2381 ma
= isl_multi_aff_domain_map(isl_space_copy(space
));
2384 space2
= isl_space_domain(isl_space_copy(space
));
2385 pma_dom
= isl_pw_multi_aff_identity(isl_space_map_from_set(space2
));
2386 space
= isl_space_range(space
);
2387 space
= isl_space_insert_dims(space
, isl_dim_set
, 0, 1);
2388 pma_ran
= isl_pw_multi_aff_project_out_map(space
, isl_dim_set
, 0, 1);
2389 pma_ran
= isl_pw_multi_aff_set_dim_id(pma_ran
, isl_dim_in
, 0, id
);
2390 pma_ran
= isl_pw_multi_aff_fix_si(pma_ran
, isl_dim_in
, 0, satisfied
);
2391 pma
= isl_pw_multi_aff_product(pma_dom
, pma_ran
);
2393 pma0
= isl_pw_multi_aff_from_multi_aff(ma
);
2394 pma
= isl_pw_multi_aff_pullback_pw_multi_aff(pma0
, pma
);
2399 /* Insert an argument expression corresponding to "test" in front
2400 * of the list of arguments described by *n_arg and *args.
2402 static int args_insert_access(unsigned *n_arg
, struct pet_expr
***args
,
2403 __isl_keep isl_multi_pw_aff
*test
)
2406 isl_ctx
*ctx
= isl_multi_pw_aff_get_ctx(test
);
2412 *args
= isl_calloc_array(ctx
, struct pet_expr
*, 1);
2416 struct pet_expr
**ext
;
2417 ext
= isl_calloc_array(ctx
, struct pet_expr
*, 1 + *n_arg
);
2420 for (i
= 0; i
< *n_arg
; ++i
)
2421 ext
[1 + i
] = (*args
)[i
];
2426 (*args
)[0] = pet_expr_from_index(isl_multi_pw_aff_copy(test
));
2433 /* Make the expression "expr" depend on the value of "test"
2434 * being equal to "satisfied".
2436 * If "test" is an affine expression, we simply add the conditions
2437 * on the expression having the value "satisfied" to all access relations
2438 * and index expressions.
2440 * Otherwise, we add a filter to "expr" (which is then assumed to be
2441 * an access expression) corresponding to "test" being equal to "satisfied".
2443 struct pet_expr
*pet_expr_filter(struct pet_expr
*expr
,
2444 __isl_take isl_multi_pw_aff
*test
, int satisfied
)
2449 isl_pw_multi_aff
*pma
;
2454 if (!isl_multi_pw_aff_has_tuple_id(test
, isl_dim_out
)) {
2458 pa
= isl_multi_pw_aff_get_pw_aff(test
, 0);
2459 isl_multi_pw_aff_free(test
);
2461 cond
= isl_pw_aff_non_zero_set(pa
);
2463 cond
= isl_pw_aff_zero_set(pa
);
2464 return pet_expr_restrict(expr
, isl_set_params(cond
));
2467 ctx
= isl_multi_pw_aff_get_ctx(test
);
2468 if (expr
->type
!= pet_expr_access
)
2469 isl_die(ctx
, isl_error_invalid
,
2470 "can only filter access expressions", goto error
);
2472 space
= isl_space_domain(isl_map_get_space(expr
->acc
.access
));
2473 id
= isl_multi_pw_aff_get_tuple_id(test
, isl_dim_out
);
2474 pma
= insert_filter_pma(space
, id
, satisfied
);
2476 expr
->acc
.access
= isl_map_preimage_domain_pw_multi_aff(
2478 isl_pw_multi_aff_copy(pma
));
2479 expr
->acc
.index
= isl_multi_pw_aff_pullback_pw_multi_aff(
2480 expr
->acc
.index
, pma
);
2481 if (!expr
->acc
.access
|| !expr
->acc
.index
)
2484 if (args_insert_access(&expr
->n_arg
, &expr
->args
, test
) < 0)
2487 isl_multi_pw_aff_free(test
);
2490 isl_multi_pw_aff_free(test
);
2491 return pet_expr_free(expr
);
2494 /* Look through the applications in "scop" for any that can be
2495 * applied to the filter expressed by "map" and "satisified".
2496 * If there is any, then apply it to "map" and return the result.
2497 * Otherwise, return "map".
2498 * "id" is the identifier of the virtual array.
2500 * We only introduce at most one implication for any given virtual array,
2501 * so we can apply the implication and return as soon as we find one.
2503 static __isl_give isl_map
*apply_implications(struct pet_scop
*scop
,
2504 __isl_take isl_map
*map
, __isl_keep isl_id
*id
, int satisfied
)
2508 for (i
= 0; i
< scop
->n_implication
; ++i
) {
2509 struct pet_implication
*pi
= scop
->implications
[i
];
2512 if (pi
->satisfied
!= satisfied
)
2514 pi_id
= isl_map_get_tuple_id(pi
->extension
, isl_dim_in
);
2519 return isl_map_apply_range(map
, isl_map_copy(pi
->extension
));
2525 /* Is the filter expressed by "test" and "satisfied" implied
2526 * by filter "pos" on "domain", with filter "expr", taking into
2527 * account the implications of "scop"?
2529 * For filter on domain implying that expressed by "test" and "satisfied",
2530 * the filter needs to be an access to the same (virtual) array as "test" and
2531 * the filter value needs to be equal to "satisfied".
2532 * Moreover, the filter access relation, possibly extended by
2533 * the implications in "scop" needs to contain "test".
2535 static int implies_filter(struct pet_scop
*scop
,
2536 __isl_keep isl_map
*domain
, int pos
, struct pet_expr
*expr
,
2537 __isl_keep isl_map
*test
, int satisfied
)
2539 isl_id
*test_id
, *arg_id
;
2546 if (expr
->type
!= pet_expr_access
)
2548 test_id
= isl_map_get_tuple_id(test
, isl_dim_out
);
2549 arg_id
= pet_expr_access_get_id(expr
);
2550 isl_id_free(arg_id
);
2551 isl_id_free(test_id
);
2552 if (test_id
!= arg_id
)
2554 val
= isl_map_plain_get_val_if_fixed(domain
, isl_dim_out
, pos
);
2555 is_int
= isl_val_is_int(val
);
2557 s
= isl_val_get_num_si(val
);
2566 implied
= isl_map_copy(expr
->acc
.access
);
2567 implied
= apply_implications(scop
, implied
, test_id
, satisfied
);
2568 is_subset
= isl_map_is_subset(test
, implied
);
2569 isl_map_free(implied
);
2574 /* Is the filter expressed by "test" and "satisfied" implied
2575 * by any of the filters on the domain of "stmt", taking into
2576 * account the implications of "scop"?
2578 static int filter_implied(struct pet_scop
*scop
,
2579 struct pet_stmt
*stmt
, __isl_keep isl_multi_pw_aff
*test
, int satisfied
)
2587 if (!scop
|| !stmt
|| !test
)
2589 if (scop
->n_implication
== 0)
2591 if (stmt
->n_arg
== 0)
2594 domain
= isl_set_unwrap(isl_set_copy(stmt
->domain
));
2595 test_map
= isl_map_from_multi_pw_aff(isl_multi_pw_aff_copy(test
));
2598 for (i
= 0; i
< stmt
->n_arg
; ++i
) {
2599 implied
= implies_filter(scop
, domain
, i
, stmt
->args
[i
],
2600 test_map
, satisfied
);
2601 if (implied
< 0 || implied
)
2605 isl_map_free(test_map
);
2606 isl_map_free(domain
);
2610 /* Make the statement "stmt" depend on the value of "test"
2611 * being equal to "satisfied" by adjusting stmt->domain.
2613 * The domain of "test" corresponds to the (zero or more) outer dimensions
2614 * of the iteration domain.
2616 * We first extend "test" to apply to the entire iteration domain and
2617 * then check if the filter that we are about to add is implied
2618 * by any of the current filters, possibly taking into account
2619 * the implications in "scop". If so, we leave "stmt" untouched and return.
2621 * Otherwise, we insert an argument corresponding to a read to "test"
2622 * from the iteration domain of "stmt" in front of the list of arguments.
2623 * We also insert a corresponding output dimension in the wrapped
2624 * map contained in stmt->domain, with value set to "satisfied".
2626 static struct pet_stmt
*stmt_filter(struct pet_scop
*scop
,
2627 struct pet_stmt
*stmt
, __isl_take isl_multi_pw_aff
*test
, int satisfied
)
2633 isl_pw_multi_aff
*pma
;
2634 isl_multi_aff
*add_dom
;
2636 isl_local_space
*ls
;
2642 space
= isl_set_get_space(stmt
->domain
);
2643 if (isl_space_is_wrapping(space
))
2644 space
= isl_space_domain(isl_space_unwrap(space
));
2645 n_test_dom
= isl_multi_pw_aff_dim(test
, isl_dim_in
);
2646 space
= isl_space_from_domain(space
);
2647 space
= isl_space_add_dims(space
, isl_dim_out
, n_test_dom
);
2648 add_dom
= isl_multi_aff_zero(isl_space_copy(space
));
2649 ls
= isl_local_space_from_space(isl_space_domain(space
));
2650 for (i
= 0; i
< n_test_dom
; ++i
) {
2652 aff
= isl_aff_var_on_domain(isl_local_space_copy(ls
),
2654 add_dom
= isl_multi_aff_set_aff(add_dom
, i
, aff
);
2656 isl_local_space_free(ls
);
2657 test
= isl_multi_pw_aff_pullback_multi_aff(test
, add_dom
);
2659 implied
= filter_implied(scop
, stmt
, test
, satisfied
);
2663 isl_multi_pw_aff_free(test
);
2667 id
= isl_multi_pw_aff_get_tuple_id(test
, isl_dim_out
);
2668 pma
= insert_filter_pma(isl_set_get_space(stmt
->domain
), id
, satisfied
);
2669 stmt
->domain
= isl_set_preimage_pw_multi_aff(stmt
->domain
, pma
);
2671 if (args_insert_access(&stmt
->n_arg
, &stmt
->args
, test
) < 0)
2674 isl_multi_pw_aff_free(test
);
2677 isl_multi_pw_aff_free(test
);
2678 return pet_stmt_free(stmt
);
2681 /* Does "scop" have a skip condition of the given "type"?
2683 int pet_scop_has_skip(struct pet_scop
*scop
, enum pet_skip type
)
2685 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
2689 return ext
->skip
[type
] != NULL
;
2692 /* Does "scop" have a skip condition of the given "type" that
2693 * is an affine expression?
2695 int pet_scop_has_affine_skip(struct pet_scop
*scop
, enum pet_skip type
)
2697 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
2701 if (!ext
->skip
[type
])
2703 return multi_pw_aff_is_affine(ext
->skip
[type
]);
2706 /* Does "scop" have a skip condition of the given "type" that
2707 * is not an affine expression?
2709 int pet_scop_has_var_skip(struct pet_scop
*scop
, enum pet_skip type
)
2711 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
2716 if (!ext
->skip
[type
])
2718 aff
= multi_pw_aff_is_affine(ext
->skip
[type
]);
2724 /* Does "scop" have a skip condition of the given "type" that
2725 * is affine and holds on the entire domain?
2727 int pet_scop_has_universal_skip(struct pet_scop
*scop
, enum pet_skip type
)
2729 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
2735 is_aff
= pet_scop_has_affine_skip(scop
, type
);
2736 if (is_aff
< 0 || !is_aff
)
2739 pa
= isl_multi_pw_aff_get_pw_aff(ext
->skip
[type
], 0);
2740 set
= isl_pw_aff_non_zero_set(pa
);
2741 is_univ
= isl_set_plain_is_universe(set
);
2747 /* Replace scop->skip[type] by "skip".
2749 struct pet_scop
*pet_scop_set_skip(struct pet_scop
*scop
,
2750 enum pet_skip type
, __isl_take isl_multi_pw_aff
*skip
)
2752 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
2757 isl_multi_pw_aff_free(ext
->skip
[type
]);
2758 ext
->skip
[type
] = skip
;
2762 isl_multi_pw_aff_free(skip
);
2763 return pet_scop_free(scop
);
2766 /* Return a copy of scop->skip[type].
2768 __isl_give isl_multi_pw_aff
*pet_scop_get_skip(struct pet_scop
*scop
,
2771 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
2776 return isl_multi_pw_aff_copy(ext
->skip
[type
]);
2779 /* Assuming scop->skip[type] is an affine expression,
2780 * return the constraints on the parameters for which the skip condition
2783 __isl_give isl_set
*pet_scop_get_affine_skip_domain(struct pet_scop
*scop
,
2786 isl_multi_pw_aff
*skip
;
2789 skip
= pet_scop_get_skip(scop
, type
);
2790 pa
= isl_multi_pw_aff_get_pw_aff(skip
, 0);
2791 isl_multi_pw_aff_free(skip
);
2792 return isl_set_params(isl_pw_aff_non_zero_set(pa
));
2795 /* Return the identifier of the variable that is accessed by
2796 * the skip condition of the given type.
2798 * The skip condition is assumed not to be an affine condition.
2800 __isl_give isl_id
*pet_scop_get_skip_id(struct pet_scop
*scop
,
2803 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
2808 return isl_multi_pw_aff_get_tuple_id(ext
->skip
[type
], isl_dim_out
);
2811 /* Return an access pet_expr corresponding to the skip condition
2812 * of the given type.
2814 struct pet_expr
*pet_scop_get_skip_expr(struct pet_scop
*scop
,
2817 return pet_expr_from_index(pet_scop_get_skip(scop
, type
));
2820 /* Drop the the skip condition scop->skip[type].
2822 void pet_scop_reset_skip(struct pet_scop
*scop
, enum pet_skip type
)
2824 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
2829 isl_multi_pw_aff_free(ext
->skip
[type
]);
2830 ext
->skip
[type
] = NULL
;
2833 /* Make the skip condition (if any) depend on the value of "test" being
2834 * equal to "satisfied".
2836 * We only support the case where the original skip condition is universal,
2837 * i.e., where skipping is unconditional, and where satisfied == 1.
2838 * In this case, the skip condition is changed to skip only when
2839 * "test" is equal to one.
2841 static struct pet_scop
*pet_scop_filter_skip(struct pet_scop
*scop
,
2842 enum pet_skip type
, __isl_keep isl_multi_pw_aff
*test
, int satisfied
)
2848 if (!pet_scop_has_skip(scop
, type
))
2852 is_univ
= pet_scop_has_universal_skip(scop
, type
);
2854 return pet_scop_free(scop
);
2855 if (satisfied
&& is_univ
) {
2856 isl_space
*space
= isl_multi_pw_aff_get_space(test
);
2857 isl_multi_pw_aff
*skip
;
2858 skip
= isl_multi_pw_aff_zero(space
);
2859 scop
= pet_scop_set_skip(scop
, type
, skip
);
2863 isl_die(isl_multi_pw_aff_get_ctx(test
), isl_error_internal
,
2864 "skip expression cannot be filtered",
2865 return pet_scop_free(scop
));
2871 /* Make all statements in "scop" depend on the value of "test"
2872 * being equal to "satisfied" by adjusting their domains.
2874 struct pet_scop
*pet_scop_filter(struct pet_scop
*scop
,
2875 __isl_take isl_multi_pw_aff
*test
, int satisfied
)
2879 scop
= pet_scop_filter_skip(scop
, pet_skip_now
, test
, satisfied
);
2880 scop
= pet_scop_filter_skip(scop
, pet_skip_later
, test
, satisfied
);
2885 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
2886 scop
->stmts
[i
] = stmt_filter(scop
, scop
->stmts
[i
],
2887 isl_multi_pw_aff_copy(test
), satisfied
);
2888 if (!scop
->stmts
[i
])
2892 isl_multi_pw_aff_free(test
);
2895 isl_multi_pw_aff_free(test
);
2896 return pet_scop_free(scop
);
2899 /* Add all parameters in "expr" to "dim" and return the result.
2901 static __isl_give isl_space
*expr_collect_params(struct pet_expr
*expr
,
2902 __isl_take isl_space
*dim
)
2908 for (i
= 0; i
< expr
->n_arg
; ++i
)
2910 dim
= expr_collect_params(expr
->args
[i
], dim
);
2912 if (expr
->type
== pet_expr_access
)
2913 dim
= isl_space_align_params(dim
,
2914 isl_map_get_space(expr
->acc
.access
));
2918 pet_expr_free(expr
);
2919 return isl_space_free(dim
);
2922 /* Add all parameters in "stmt" to "dim" and return the result.
2924 static __isl_give isl_space
*stmt_collect_params(struct pet_stmt
*stmt
,
2925 __isl_take isl_space
*dim
)
2930 dim
= isl_space_align_params(dim
, isl_set_get_space(stmt
->domain
));
2931 dim
= isl_space_align_params(dim
, isl_map_get_space(stmt
->schedule
));
2932 dim
= expr_collect_params(stmt
->body
, dim
);
2936 isl_space_free(dim
);
2937 return pet_stmt_free(stmt
);
2940 /* Add all parameters in "array" to "dim" and return the result.
2942 static __isl_give isl_space
*array_collect_params(struct pet_array
*array
,
2943 __isl_take isl_space
*dim
)
2948 dim
= isl_space_align_params(dim
, isl_set_get_space(array
->context
));
2949 dim
= isl_space_align_params(dim
, isl_set_get_space(array
->extent
));
2953 pet_array_free(array
);
2954 return isl_space_free(dim
);
2957 /* Add all parameters in "scop" to "dim" and return the result.
2959 static __isl_give isl_space
*scop_collect_params(struct pet_scop
*scop
,
2960 __isl_take isl_space
*dim
)
2967 for (i
= 0; i
< scop
->n_array
; ++i
)
2968 dim
= array_collect_params(scop
->arrays
[i
], dim
);
2970 for (i
= 0; i
< scop
->n_stmt
; ++i
)
2971 dim
= stmt_collect_params(scop
->stmts
[i
], dim
);
2975 isl_space_free(dim
);
2976 pet_scop_free(scop
);
2980 /* Add all parameters in "dim" to all access relations and index expressions
2983 static struct pet_expr
*expr_propagate_params(struct pet_expr
*expr
,
2984 __isl_take isl_space
*dim
)
2991 for (i
= 0; i
< expr
->n_arg
; ++i
) {
2993 expr_propagate_params(expr
->args
[i
],
2994 isl_space_copy(dim
));
2999 if (expr
->type
== pet_expr_access
) {
3000 expr
->acc
.access
= isl_map_align_params(expr
->acc
.access
,
3001 isl_space_copy(dim
));
3002 expr
->acc
.index
= isl_multi_pw_aff_align_params(expr
->acc
.index
,
3003 isl_space_copy(dim
));
3004 if (!expr
->acc
.access
|| !expr
->acc
.index
)
3008 isl_space_free(dim
);
3011 isl_space_free(dim
);
3012 return pet_expr_free(expr
);
3015 /* Add all parameters in "dim" to the domain, schedule and
3016 * all access relations in "stmt".
3018 static struct pet_stmt
*stmt_propagate_params(struct pet_stmt
*stmt
,
3019 __isl_take isl_space
*dim
)
3024 stmt
->domain
= isl_set_align_params(stmt
->domain
, isl_space_copy(dim
));
3025 stmt
->schedule
= isl_map_align_params(stmt
->schedule
,
3026 isl_space_copy(dim
));
3027 stmt
->body
= expr_propagate_params(stmt
->body
, isl_space_copy(dim
));
3029 if (!stmt
->domain
|| !stmt
->schedule
|| !stmt
->body
)
3032 isl_space_free(dim
);
3035 isl_space_free(dim
);
3036 return pet_stmt_free(stmt
);
3039 /* Add all parameters in "dim" to "array".
3041 static struct pet_array
*array_propagate_params(struct pet_array
*array
,
3042 __isl_take isl_space
*dim
)
3047 array
->context
= isl_set_align_params(array
->context
,
3048 isl_space_copy(dim
));
3049 array
->extent
= isl_set_align_params(array
->extent
,
3050 isl_space_copy(dim
));
3051 if (array
->value_bounds
) {
3052 array
->value_bounds
= isl_set_align_params(array
->value_bounds
,
3053 isl_space_copy(dim
));
3054 if (!array
->value_bounds
)
3058 if (!array
->context
|| !array
->extent
)
3061 isl_space_free(dim
);
3064 isl_space_free(dim
);
3065 return pet_array_free(array
);
3068 /* Add all parameters in "dim" to "scop".
3070 static struct pet_scop
*scop_propagate_params(struct pet_scop
*scop
,
3071 __isl_take isl_space
*dim
)
3078 for (i
= 0; i
< scop
->n_array
; ++i
) {
3079 scop
->arrays
[i
] = array_propagate_params(scop
->arrays
[i
],
3080 isl_space_copy(dim
));
3081 if (!scop
->arrays
[i
])
3085 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3086 scop
->stmts
[i
] = stmt_propagate_params(scop
->stmts
[i
],
3087 isl_space_copy(dim
));
3088 if (!scop
->stmts
[i
])
3092 isl_space_free(dim
);
3095 isl_space_free(dim
);
3096 return pet_scop_free(scop
);
3099 /* Update all isl_sets and isl_maps in "scop" such that they all
3100 * have the same parameters.
3102 struct pet_scop
*pet_scop_align_params(struct pet_scop
*scop
)
3109 dim
= isl_set_get_space(scop
->context
);
3110 dim
= scop_collect_params(scop
, dim
);
3112 scop
->context
= isl_set_align_params(scop
->context
, isl_space_copy(dim
));
3113 scop
= scop_propagate_params(scop
, dim
);
3118 /* Check if the given index expression accesses a (0D) array that corresponds
3119 * to one of the parameters in "dim". If so, replace the array access
3120 * by an access to the set of integers with as index (and value)
3123 static __isl_give isl_multi_pw_aff
*index_detect_parameter(
3124 __isl_take isl_multi_pw_aff
*index
, __isl_take isl_space
*space
)
3126 isl_local_space
*ls
;
3127 isl_id
*array_id
= NULL
;
3131 if (isl_multi_pw_aff_has_tuple_id(index
, isl_dim_out
)) {
3132 array_id
= isl_multi_pw_aff_get_tuple_id(index
, isl_dim_out
);
3133 pos
= isl_space_find_dim_by_id(space
, isl_dim_param
, array_id
);
3135 isl_space_free(space
);
3138 isl_id_free(array_id
);
3142 space
= isl_multi_pw_aff_get_domain_space(index
);
3143 isl_multi_pw_aff_free(index
);
3145 pos
= isl_space_find_dim_by_id(space
, isl_dim_param
, array_id
);
3147 space
= isl_space_insert_dims(space
, isl_dim_param
, 0, 1);
3148 space
= isl_space_set_dim_id(space
, isl_dim_param
, 0, array_id
);
3151 isl_id_free(array_id
);
3153 ls
= isl_local_space_from_space(space
);
3154 aff
= isl_aff_var_on_domain(ls
, isl_dim_param
, pos
);
3155 index
= isl_multi_pw_aff_from_pw_aff(isl_pw_aff_from_aff(aff
));
3160 /* Check if the given access relation accesses a (0D) array that corresponds
3161 * to one of the parameters in "dim". If so, replace the array access
3162 * by an access to the set of integers with as index (and value)
3165 static __isl_give isl_map
*access_detect_parameter(__isl_take isl_map
*access
,
3166 __isl_take isl_space
*dim
)
3168 isl_id
*array_id
= NULL
;
3171 if (isl_map_has_tuple_id(access
, isl_dim_out
)) {
3172 array_id
= isl_map_get_tuple_id(access
, isl_dim_out
);
3173 pos
= isl_space_find_dim_by_id(dim
, isl_dim_param
, array_id
);
3175 isl_space_free(dim
);
3178 isl_id_free(array_id
);
3182 pos
= isl_map_find_dim_by_id(access
, isl_dim_param
, array_id
);
3184 access
= isl_map_insert_dims(access
, isl_dim_param
, 0, 1);
3185 access
= isl_map_set_dim_id(access
, isl_dim_param
, 0, array_id
);
3188 isl_id_free(array_id
);
3190 access
= isl_map_insert_dims(access
, isl_dim_out
, 0, 1);
3191 access
= isl_map_equate(access
, isl_dim_param
, pos
, isl_dim_out
, 0);
3196 /* Replace all accesses to (0D) arrays that correspond to one of the parameters
3197 * in "dim" by a value equal to the corresponding parameter.
3199 static struct pet_expr
*expr_detect_parameter_accesses(struct pet_expr
*expr
,
3200 __isl_take isl_space
*dim
)
3207 for (i
= 0; i
< expr
->n_arg
; ++i
) {
3209 expr_detect_parameter_accesses(expr
->args
[i
],
3210 isl_space_copy(dim
));
3215 if (expr
->type
== pet_expr_access
) {
3216 expr
->acc
.access
= access_detect_parameter(expr
->acc
.access
,
3217 isl_space_copy(dim
));
3218 expr
->acc
.index
= index_detect_parameter(expr
->acc
.index
,
3219 isl_space_copy(dim
));
3220 if (!expr
->acc
.access
|| !expr
->acc
.index
)
3224 isl_space_free(dim
);
3227 isl_space_free(dim
);
3228 return pet_expr_free(expr
);
3231 /* Replace all accesses to (0D) arrays that correspond to one of the parameters
3232 * in "dim" by a value equal to the corresponding parameter.
3234 static struct pet_stmt
*stmt_detect_parameter_accesses(struct pet_stmt
*stmt
,
3235 __isl_take isl_space
*dim
)
3240 stmt
->body
= expr_detect_parameter_accesses(stmt
->body
,
3241 isl_space_copy(dim
));
3243 if (!stmt
->domain
|| !stmt
->schedule
|| !stmt
->body
)
3246 isl_space_free(dim
);
3249 isl_space_free(dim
);
3250 return pet_stmt_free(stmt
);
3253 /* Replace all accesses to (0D) arrays that correspond to one of the parameters
3254 * in "dim" by a value equal to the corresponding parameter.
3256 static struct pet_scop
*scop_detect_parameter_accesses(struct pet_scop
*scop
,
3257 __isl_take isl_space
*dim
)
3264 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3265 scop
->stmts
[i
] = stmt_detect_parameter_accesses(scop
->stmts
[i
],
3266 isl_space_copy(dim
));
3267 if (!scop
->stmts
[i
])
3271 isl_space_free(dim
);
3274 isl_space_free(dim
);
3275 return pet_scop_free(scop
);
3278 /* Replace all accesses to (0D) arrays that correspond to any of
3279 * the parameters used in "scop" by a value equal
3280 * to the corresponding parameter.
3282 struct pet_scop
*pet_scop_detect_parameter_accesses(struct pet_scop
*scop
)
3289 dim
= isl_set_get_space(scop
->context
);
3290 dim
= scop_collect_params(scop
, dim
);
3292 scop
= scop_detect_parameter_accesses(scop
, dim
);
3297 /* Return the relation mapping domain iterations to all possibly
3298 * accessed data elements.
3299 * In particular, take the access relation and project out the values
3300 * of the arguments, if any.
3302 static __isl_give isl_map
*expr_access_get_may_access(struct pet_expr
*expr
)
3310 if (expr
->type
!= pet_expr_access
)
3313 access
= isl_map_copy(expr
->acc
.access
);
3314 if (expr
->n_arg
== 0)
3317 space
= isl_space_domain(isl_map_get_space(access
));
3318 map
= isl_map_universe(isl_space_unwrap(space
));
3319 map
= isl_map_domain_map(map
);
3320 access
= isl_map_apply_domain(access
, map
);
3325 /* Add all read access relations (if "read" is set) and/or all write
3326 * access relations (if "write" is set) to "accesses" and return the result.
3328 * If "must" is set, then we only add the accesses that are definitely
3329 * performed. Otherwise, we add all potential accesses.
3330 * In particular, if the access has any arguments, then if "must" is
3331 * set we currently skip the access completely. If "must" is not set,
3332 * we project out the values of the access arguments.
3334 static __isl_give isl_union_map
*expr_collect_accesses(struct pet_expr
*expr
,
3335 int read
, int write
, int must
, __isl_take isl_union_map
*accesses
)
3344 for (i
= 0; i
< expr
->n_arg
; ++i
)
3345 accesses
= expr_collect_accesses(expr
->args
[i
],
3346 read
, write
, must
, accesses
);
3348 if (expr
->type
== pet_expr_access
&& !pet_expr_is_affine(expr
) &&
3349 ((read
&& expr
->acc
.read
) || (write
&& expr
->acc
.write
)) &&
3350 (!must
|| expr
->n_arg
== 0)) {
3353 access
= expr_access_get_may_access(expr
);
3354 accesses
= isl_union_map_add_map(accesses
, access
);
3360 /* Collect and return all read access relations (if "read" is set)
3361 * and/or all write access relations (if "write" is set) in "stmt".
3363 * If "must" is set, then we only add the accesses that are definitely
3364 * performed. Otherwise, we add all potential accesses.
3365 * In particular, if the statement has any arguments, then if "must" is
3366 * set we currently skip the statement completely. If "must" is not set,
3367 * we project out the values of the statement arguments.
3369 static __isl_give isl_union_map
*stmt_collect_accesses(struct pet_stmt
*stmt
,
3370 int read
, int write
, int must
, __isl_take isl_space
*dim
)
3372 isl_union_map
*accesses
;
3378 accesses
= isl_union_map_empty(dim
);
3380 if (must
&& stmt
->n_arg
> 0)
3383 domain
= isl_set_copy(stmt
->domain
);
3384 if (isl_set_is_wrapping(domain
))
3385 domain
= isl_map_domain(isl_set_unwrap(domain
));
3387 accesses
= expr_collect_accesses(stmt
->body
,
3388 read
, write
, must
, accesses
);
3389 accesses
= isl_union_map_intersect_domain(accesses
,
3390 isl_union_set_from_set(domain
));
3395 /* Collect and return all read access relations (if "read" is set)
3396 * and/or all write access relations (if "write" is set) in "scop".
3397 * If "must" is set, then we only add the accesses that are definitely
3398 * performed. Otherwise, we add all potential accesses.
3400 static __isl_give isl_union_map
*scop_collect_accesses(struct pet_scop
*scop
,
3401 int read
, int write
, int must
)
3404 isl_union_map
*accesses
;
3405 isl_union_set
*arrays
;
3410 accesses
= isl_union_map_empty(isl_set_get_space(scop
->context
));
3412 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3413 isl_union_map
*accesses_i
;
3414 isl_space
*dim
= isl_set_get_space(scop
->context
);
3415 accesses_i
= stmt_collect_accesses(scop
->stmts
[i
],
3416 read
, write
, must
, dim
);
3417 accesses
= isl_union_map_union(accesses
, accesses_i
);
3420 arrays
= isl_union_set_empty(isl_union_map_get_space(accesses
));
3421 for (i
= 0; i
< scop
->n_array
; ++i
) {
3422 isl_set
*extent
= isl_set_copy(scop
->arrays
[i
]->extent
);
3423 arrays
= isl_union_set_add_set(arrays
, extent
);
3425 accesses
= isl_union_map_intersect_range(accesses
, arrays
);
3430 /* Collect all potential read access relations.
3432 __isl_give isl_union_map
*pet_scop_collect_may_reads(struct pet_scop
*scop
)
3434 return scop_collect_accesses(scop
, 1, 0, 0);
3437 /* Collect all potential write access relations.
3439 __isl_give isl_union_map
*pet_scop_collect_may_writes(struct pet_scop
*scop
)
3441 return scop_collect_accesses(scop
, 0, 1, 0);
3444 /* Collect all definite write access relations.
3446 __isl_give isl_union_map
*pet_scop_collect_must_writes(struct pet_scop
*scop
)
3448 return scop_collect_accesses(scop
, 0, 1, 1);
3451 /* Collect and return the union of iteration domains in "scop".
3453 __isl_give isl_union_set
*pet_scop_collect_domains(struct pet_scop
*scop
)
3457 isl_union_set
*domain
;
3462 domain
= isl_union_set_empty(isl_set_get_space(scop
->context
));
3464 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3465 domain_i
= isl_set_copy(scop
->stmts
[i
]->domain
);
3466 domain
= isl_union_set_add_set(domain
, domain_i
);
3472 /* Collect and return the schedules of the statements in "scop".
3473 * The range is normalized to the maximal number of scheduling
3476 __isl_give isl_union_map
*pet_scop_collect_schedule(struct pet_scop
*scop
)
3479 isl_map
*schedule_i
;
3480 isl_union_map
*schedule
;
3481 int depth
, max_depth
= 0;
3486 schedule
= isl_union_map_empty(isl_set_get_space(scop
->context
));
3488 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3489 depth
= isl_map_dim(scop
->stmts
[i
]->schedule
, isl_dim_out
);
3490 if (depth
> max_depth
)
3494 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3495 schedule_i
= isl_map_copy(scop
->stmts
[i
]->schedule
);
3496 depth
= isl_map_dim(schedule_i
, isl_dim_out
);
3497 schedule_i
= isl_map_add_dims(schedule_i
, isl_dim_out
,
3499 for (j
= depth
; j
< max_depth
; ++j
)
3500 schedule_i
= isl_map_fix_si(schedule_i
,
3502 schedule
= isl_union_map_add_map(schedule
, schedule_i
);
3508 /* Does expression "expr" write to "id"?
3510 static int expr_writes(struct pet_expr
*expr
, __isl_keep isl_id
*id
)
3515 for (i
= 0; i
< expr
->n_arg
; ++i
) {
3516 int writes
= expr_writes(expr
->args
[i
], id
);
3517 if (writes
< 0 || writes
)
3521 if (expr
->type
!= pet_expr_access
)
3523 if (!expr
->acc
.write
)
3525 if (pet_expr_is_affine(expr
))
3528 write_id
= pet_expr_access_get_id(expr
);
3529 isl_id_free(write_id
);
3534 return write_id
== id
;
3537 /* Does statement "stmt" write to "id"?
3539 static int stmt_writes(struct pet_stmt
*stmt
, __isl_keep isl_id
*id
)
3541 return expr_writes(stmt
->body
, id
);
3544 /* Is there any write access in "scop" that accesses "id"?
3546 int pet_scop_writes(struct pet_scop
*scop
, __isl_keep isl_id
*id
)
3553 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3554 int writes
= stmt_writes(scop
->stmts
[i
], id
);
3555 if (writes
< 0 || writes
)
3562 /* Add a reference identifier to access expression "expr".
3563 * "user" points to an integer that contains the sequence number
3564 * of the next reference.
3566 static struct pet_expr
*access_add_ref_id(struct pet_expr
*expr
, void *user
)
3575 ctx
= isl_map_get_ctx(expr
->acc
.access
);
3576 snprintf(name
, sizeof(name
), "__pet_ref_%d", (*n_ref
)++);
3577 expr
->acc
.ref_id
= isl_id_alloc(ctx
, name
, NULL
);
3578 if (!expr
->acc
.ref_id
)
3579 return pet_expr_free(expr
);
3584 /* Add a reference identifier to all access expressions in "stmt".
3585 * "n_ref" points to an integer that contains the sequence number
3586 * of the next reference.
3588 static struct pet_stmt
*stmt_add_ref_ids(struct pet_stmt
*stmt
, int *n_ref
)
3595 for (i
= 0; i
< stmt
->n_arg
; ++i
) {
3596 stmt
->args
[i
] = pet_expr_map_access(stmt
->args
[i
],
3597 &access_add_ref_id
, n_ref
);
3599 return pet_stmt_free(stmt
);
3602 stmt
->body
= pet_expr_map_access(stmt
->body
, &access_add_ref_id
, n_ref
);
3604 return pet_stmt_free(stmt
);
3609 /* Add a reference identifier to all access expressions in "scop".
3611 struct pet_scop
*pet_scop_add_ref_ids(struct pet_scop
*scop
)
3620 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3621 scop
->stmts
[i
] = stmt_add_ref_ids(scop
->stmts
[i
], &n_ref
);
3622 if (!scop
->stmts
[i
])
3623 return pet_scop_free(scop
);
3629 /* Reset the user pointer on all parameter ids in "array".
3631 static struct pet_array
*array_anonymize(struct pet_array
*array
)
3636 array
->context
= isl_set_reset_user(array
->context
);
3637 array
->extent
= isl_set_reset_user(array
->extent
);
3638 if (!array
->context
|| !array
->extent
)
3639 return pet_array_free(array
);
3644 /* Reset the user pointer on all parameter and tuple ids in
3645 * the access relation and the index expressions
3646 * of the access expression "expr".
3648 static struct pet_expr
*access_anonymize(struct pet_expr
*expr
, void *user
)
3650 expr
->acc
.access
= isl_map_reset_user(expr
->acc
.access
);
3651 expr
->acc
.index
= isl_multi_pw_aff_reset_user(expr
->acc
.index
);
3652 if (!expr
->acc
.access
|| !expr
->acc
.index
)
3653 return pet_expr_free(expr
);
3658 /* Reset the user pointer on all parameter and tuple ids in "stmt".
3660 static struct pet_stmt
*stmt_anonymize(struct pet_stmt
*stmt
)
3669 stmt
->domain
= isl_set_reset_user(stmt
->domain
);
3670 stmt
->schedule
= isl_map_reset_user(stmt
->schedule
);
3671 if (!stmt
->domain
|| !stmt
->schedule
)
3672 return pet_stmt_free(stmt
);
3674 for (i
= 0; i
< stmt
->n_arg
; ++i
) {
3675 stmt
->args
[i
] = pet_expr_map_access(stmt
->args
[i
],
3676 &access_anonymize
, NULL
);
3678 return pet_stmt_free(stmt
);
3681 stmt
->body
= pet_expr_map_access(stmt
->body
,
3682 &access_anonymize
, NULL
);
3684 return pet_stmt_free(stmt
);
3689 /* Reset the user pointer on the tuple ids and all parameter ids
3692 static struct pet_implication
*implication_anonymize(
3693 struct pet_implication
*implication
)
3698 implication
->extension
= isl_map_reset_user(implication
->extension
);
3699 if (!implication
->extension
)
3700 return pet_implication_free(implication
);
3705 /* Reset the user pointer on all parameter and tuple ids in "scop".
3707 struct pet_scop
*pet_scop_anonymize(struct pet_scop
*scop
)
3714 scop
->context
= isl_set_reset_user(scop
->context
);
3715 scop
->context_value
= isl_set_reset_user(scop
->context_value
);
3716 if (!scop
->context
|| !scop
->context_value
)
3717 return pet_scop_free(scop
);
3719 for (i
= 0; i
< scop
->n_array
; ++i
) {
3720 scop
->arrays
[i
] = array_anonymize(scop
->arrays
[i
]);
3721 if (!scop
->arrays
[i
])
3722 return pet_scop_free(scop
);
3725 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3726 scop
->stmts
[i
] = stmt_anonymize(scop
->stmts
[i
]);
3727 if (!scop
->stmts
[i
])
3728 return pet_scop_free(scop
);
3731 for (i
= 0; i
< scop
->n_implication
; ++i
) {
3732 scop
->implications
[i
] =
3733 implication_anonymize(scop
->implications
[i
]);
3734 if (!scop
->implications
[i
])
3735 return pet_scop_free(scop
);
3741 /* If "value_bounds" contains any bounds on the variable accessed by "arg",
3742 * then intersect the range of "map" with the valid set of values.
3744 static __isl_give isl_map
*access_apply_value_bounds(__isl_take isl_map
*map
,
3745 struct pet_expr
*arg
, __isl_keep isl_union_map
*value_bounds
)
3750 isl_ctx
*ctx
= isl_map_get_ctx(map
);
3752 id
= pet_expr_access_get_id(arg
);
3753 space
= isl_space_alloc(ctx
, 0, 0, 1);
3754 space
= isl_space_set_tuple_id(space
, isl_dim_in
, id
);
3755 vb
= isl_union_map_extract_map(value_bounds
, space
);
3756 if (!isl_map_plain_is_empty(vb
))
3757 map
= isl_map_intersect_range(map
, isl_map_range(vb
));
3764 /* Given a set "domain", return a wrapped relation with the given set
3765 * as domain and a range of dimension "n_arg", where each coordinate
3766 * is either unbounded or, if the corresponding element of args is of
3767 * type pet_expr_access, bounded by the bounds specified by "value_bounds".
3769 static __isl_give isl_set
*apply_value_bounds(__isl_take isl_set
*domain
,
3770 unsigned n_arg
, struct pet_expr
**args
,
3771 __isl_keep isl_union_map
*value_bounds
)
3777 map
= isl_map_from_domain(domain
);
3778 space
= isl_map_get_space(map
);
3779 space
= isl_space_add_dims(space
, isl_dim_out
, 1);
3781 for (i
= 0; i
< n_arg
; ++i
) {
3783 struct pet_expr
*arg
= args
[i
];
3785 map_i
= isl_map_universe(isl_space_copy(space
));
3786 if (arg
->type
== pet_expr_access
)
3787 map_i
= access_apply_value_bounds(map_i
, arg
,
3789 map
= isl_map_flat_range_product(map
, map_i
);
3791 isl_space_free(space
);
3793 return isl_map_wrap(map
);
3796 /* Data used in access_gist() callback.
3798 struct pet_access_gist_data
{
3800 isl_union_map
*value_bounds
;
3803 /* Given an expression "expr" of type pet_expr_access, compute
3804 * the gist of the associated access relation and index expression
3805 * with respect to data->domain and the bounds on the values of the arguments
3806 * of the expression.
3808 static struct pet_expr
*access_gist(struct pet_expr
*expr
, void *user
)
3810 struct pet_access_gist_data
*data
= user
;
3813 domain
= isl_set_copy(data
->domain
);
3814 if (expr
->n_arg
> 0)
3815 domain
= apply_value_bounds(domain
, expr
->n_arg
, expr
->args
,
3816 data
->value_bounds
);
3818 expr
->acc
.access
= isl_map_gist_domain(expr
->acc
.access
,
3819 isl_set_copy(domain
));
3820 expr
->acc
.index
= isl_multi_pw_aff_gist(expr
->acc
.index
, domain
);
3821 if (!expr
->acc
.access
|| !expr
->acc
.index
)
3822 return pet_expr_free(expr
);
3827 /* Compute the gist of the iteration domain and all access relations
3828 * of "stmt" based on the constraints on the parameters specified by "context"
3829 * and the constraints on the values of nested accesses specified
3830 * by "value_bounds".
3832 static struct pet_stmt
*stmt_gist(struct pet_stmt
*stmt
,
3833 __isl_keep isl_set
*context
, __isl_keep isl_union_map
*value_bounds
)
3838 struct pet_access_gist_data data
;
3843 data
.domain
= isl_set_copy(stmt
->domain
);
3844 data
.value_bounds
= value_bounds
;
3845 if (stmt
->n_arg
> 0)
3846 data
.domain
= isl_map_domain(isl_set_unwrap(data
.domain
));
3848 data
.domain
= isl_set_intersect_params(data
.domain
,
3849 isl_set_copy(context
));
3851 for (i
= 0; i
< stmt
->n_arg
; ++i
) {
3852 stmt
->args
[i
] = pet_expr_map_access(stmt
->args
[i
],
3853 &access_gist
, &data
);
3858 stmt
->body
= pet_expr_map_access(stmt
->body
, &access_gist
, &data
);
3862 isl_set_free(data
.domain
);
3864 space
= isl_set_get_space(stmt
->domain
);
3865 if (isl_space_is_wrapping(space
))
3866 space
= isl_space_domain(isl_space_unwrap(space
));
3867 domain
= isl_set_universe(space
);
3868 domain
= isl_set_intersect_params(domain
, isl_set_copy(context
));
3869 if (stmt
->n_arg
> 0)
3870 domain
= apply_value_bounds(domain
, stmt
->n_arg
, stmt
->args
,
3872 stmt
->domain
= isl_set_gist(stmt
->domain
, domain
);
3874 return pet_stmt_free(stmt
);
3878 isl_set_free(data
.domain
);
3879 return pet_stmt_free(stmt
);
3882 /* Compute the gist of the extent of the array
3883 * based on the constraints on the parameters specified by "context".
3885 static struct pet_array
*array_gist(struct pet_array
*array
,
3886 __isl_keep isl_set
*context
)
3891 array
->extent
= isl_set_gist_params(array
->extent
,
3892 isl_set_copy(context
));
3894 return pet_array_free(array
);
3899 /* Compute the gist of all sets and relations in "scop"
3900 * based on the constraints on the parameters specified by "scop->context"
3901 * and the constraints on the values of nested accesses specified
3902 * by "value_bounds".
3904 struct pet_scop
*pet_scop_gist(struct pet_scop
*scop
,
3905 __isl_keep isl_union_map
*value_bounds
)
3912 scop
->context
= isl_set_coalesce(scop
->context
);
3914 return pet_scop_free(scop
);
3916 for (i
= 0; i
< scop
->n_array
; ++i
) {
3917 scop
->arrays
[i
] = array_gist(scop
->arrays
[i
], scop
->context
);
3918 if (!scop
->arrays
[i
])
3919 return pet_scop_free(scop
);
3922 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
3923 scop
->stmts
[i
] = stmt_gist(scop
->stmts
[i
], scop
->context
,
3925 if (!scop
->stmts
[i
])
3926 return pet_scop_free(scop
);
3932 /* Intersect the context of "scop" with "context".
3933 * To ensure that we don't introduce any unnamed parameters in
3934 * the context of "scop", we first remove the unnamed parameters
3937 struct pet_scop
*pet_scop_restrict_context(struct pet_scop
*scop
,
3938 __isl_take isl_set
*context
)
3943 context
= set_project_out_unnamed_params(context
);
3944 scop
->context
= isl_set_intersect(scop
->context
, context
);
3946 return pet_scop_free(scop
);
3950 isl_set_free(context
);
3951 return pet_scop_free(scop
);
3954 /* Drop the current context of "scop". That is, replace the context
3955 * by a universal set.
3957 struct pet_scop
*pet_scop_reset_context(struct pet_scop
*scop
)
3964 space
= isl_set_get_space(scop
->context
);
3965 isl_set_free(scop
->context
);
3966 scop
->context
= isl_set_universe(space
);
3968 return pet_scop_free(scop
);
3973 /* Append "array" to the arrays of "scop".
3975 struct pet_scop
*pet_scop_add_array(struct pet_scop
*scop
,
3976 struct pet_array
*array
)
3979 struct pet_array
**arrays
;
3981 if (!array
|| !scop
)
3984 ctx
= isl_set_get_ctx(scop
->context
);
3985 arrays
= isl_realloc_array(ctx
, scop
->arrays
, struct pet_array
*,
3989 scop
->arrays
= arrays
;
3990 scop
->arrays
[scop
->n_array
] = array
;
3995 pet_array_free(array
);
3996 return pet_scop_free(scop
);
3999 /* Create and return an implication on filter values equal to "satisfied"
4000 * with extension "map".
4002 static struct pet_implication
*new_implication(__isl_take isl_map
*map
,
4006 struct pet_implication
*implication
;
4010 ctx
= isl_map_get_ctx(map
);
4011 implication
= isl_alloc_type(ctx
, struct pet_implication
);
4015 implication
->extension
= map
;
4016 implication
->satisfied
= satisfied
;
4024 /* Add an implication on filter values equal to "satisfied"
4025 * with extension "map" to "scop".
4027 struct pet_scop
*pet_scop_add_implication(struct pet_scop
*scop
,
4028 __isl_take isl_map
*map
, int satisfied
)
4031 struct pet_implication
*implication
;
4032 struct pet_implication
**implications
;
4034 implication
= new_implication(map
, satisfied
);
4035 if (!scop
|| !implication
)
4038 ctx
= isl_set_get_ctx(scop
->context
);
4039 implications
= isl_realloc_array(ctx
, scop
->implications
,
4040 struct pet_implication
*,
4041 scop
->n_implication
+ 1);
4044 scop
->implications
= implications
;
4045 scop
->implications
[scop
->n_implication
] = implication
;
4046 scop
->n_implication
++;
4050 pet_implication_free(implication
);
4051 return pet_scop_free(scop
);
4054 /* Given an access expression, check if it is data dependent.
4055 * If so, set *found and abort the search.
4057 static int is_data_dependent(struct pet_expr
*expr
, void *user
)
4069 /* Does "scop" contain any data dependent accesses?
4071 * Check the body of each statement for such accesses.
4073 int pet_scop_has_data_dependent_accesses(struct pet_scop
*scop
)
4081 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
4082 int r
= pet_expr_foreach_access_expr(scop
->stmts
[i
]->body
,
4083 &is_data_dependent
, &found
);
4084 if (r
< 0 && !found
)
4093 /* Does "scop" contain and data dependent conditions?
4095 int pet_scop_has_data_dependent_conditions(struct pet_scop
*scop
)
4102 for (i
= 0; i
< scop
->n_stmt
; ++i
)
4103 if (scop
->stmts
[i
]->n_arg
> 0)
4109 /* Keep track of the "input" file inside the (extended) "scop".
4111 struct pet_scop
*pet_scop_set_input_file(struct pet_scop
*scop
, FILE *input
)
4113 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
4123 /* Print the original code corresponding to "scop" to printer "p".
4125 * pet_scop_print_original can only be called from
4126 * a pet_transform_C_source callback. This means that the input
4127 * file is stored in the extended scop and that the printer prints
4130 __isl_give isl_printer
*pet_scop_print_original(struct pet_scop
*scop
,
4131 __isl_take isl_printer
*p
)
4133 struct pet_scop_ext
*ext
= (struct pet_scop_ext
*) scop
;
4137 return isl_printer_free(p
);
4140 isl_die(isl_printer_get_ctx(p
), isl_error_invalid
,
4141 "no input file stored in scop",
4142 return isl_printer_free(p
));
4144 output
= isl_printer_get_file(p
);
4146 return isl_printer_free(p
);
4148 if (copy(ext
->input
, output
, scop
->start
, scop
->end
) < 0)
4149 return isl_printer_free(p
);