2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2012-2014 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
44 #include "value_bounds.h"
46 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
48 static char *type_str
[] = {
49 [pet_expr_access
] = "access",
50 [pet_expr_call
] = "call",
51 [pet_expr_cast
] = "cast",
52 [pet_expr_double
] = "double",
53 [pet_expr_int
] = "int",
57 static char *op_str
[] = {
58 [pet_op_add_assign
] = "+=",
59 [pet_op_sub_assign
] = "-=",
60 [pet_op_mul_assign
] = "*=",
61 [pet_op_div_assign
] = "/=",
62 [pet_op_assign
] = "=",
77 [pet_op_post_inc
] = "++",
78 [pet_op_post_dec
] = "--",
79 [pet_op_pre_inc
] = "++",
80 [pet_op_pre_dec
] = "--",
81 [pet_op_address_of
] = "&",
90 [pet_op_assume
] = "assume",
91 [pet_op_kill
] = "kill"
94 const char *pet_op_str(enum pet_op_type op
)
99 int pet_op_is_inc_dec(enum pet_op_type op
)
101 return op
== pet_op_post_inc
|| op
== pet_op_post_dec
||
102 op
== pet_op_pre_inc
|| op
== pet_op_pre_dec
;
105 const char *pet_type_str(enum pet_expr_type type
)
107 return type_str
[type
];
110 enum pet_op_type
pet_str_op(const char *str
)
114 for (i
= 0; i
< ARRAY_SIZE(op_str
); ++i
)
115 if (!strcmp(op_str
[i
], str
))
121 enum pet_expr_type
pet_str_type(const char *str
)
125 for (i
= 0; i
< ARRAY_SIZE(type_str
); ++i
)
126 if (!strcmp(type_str
[i
], str
))
132 /* Construct a pet_expr of the given type.
134 __isl_give pet_expr
*pet_expr_alloc(isl_ctx
*ctx
, enum pet_expr_type type
)
138 expr
= isl_calloc_type(ctx
, struct pet_expr
);
150 /* Construct an access pet_expr from an index expression.
151 * By default, the access is considered to be a read access.
152 * The initial depth is set from the index expression and
153 * may still be updated by the caller before the access relation
156 __isl_give pet_expr
*pet_expr_from_index(__isl_take isl_multi_pw_aff
*index
)
163 ctx
= isl_multi_pw_aff_get_ctx(index
);
164 expr
= pet_expr_alloc(ctx
, pet_expr_access
);
171 expr
= pet_expr_access_set_index(expr
, index
);
175 isl_multi_pw_aff_free(index
);
179 /* Extend the range of "access" with "n" dimensions, retaining
180 * the tuple identifier on this range.
182 * If "access" represents a member access, then extend the 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
);
191 if (!isl_map_range_is_wrapping(access
)) {
192 access
= isl_map_add_dims(access
, isl_dim_out
, n
);
196 domain
= isl_map_copy(access
);
197 domain
= isl_map_range_factor_domain(domain
);
198 access
= isl_map_range_factor_range(access
);
199 access
= extend_range(access
, n
);
200 access
= isl_map_range_product(domain
, access
);
203 access
= isl_map_set_tuple_id(access
, isl_dim_out
, id
);
208 /* Does the access expression "expr" have any explicit access relation?
210 static int has_any_access_relation(__isl_keep pet_expr
*expr
)
212 enum pet_expr_access_type type
;
217 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
)
218 if (expr
->acc
.access
[type
])
224 /* Are all relevant access relations explicitly available in "expr"?
226 static int has_relevant_access_relations(__isl_keep pet_expr
*expr
)
228 enum pet_expr_access_type type
;
233 if (expr
->acc
.kill
&& !expr
->acc
.access
[pet_expr_access_fake_killed
])
235 if (expr
->acc
.read
&& !expr
->acc
.access
[pet_expr_access_may_read
])
237 if (expr
->acc
.write
&&
238 (!expr
->acc
.access
[pet_expr_access_may_write
] ||
239 !expr
->acc
.access
[pet_expr_access_must_write
]))
245 /* Replace the depth of the access expr "expr" by "depth".
247 * To avoid inconsistencies between the depth and the access relation,
248 * we currently do not allow the depth to change once the access relation
249 * has been set or computed.
251 __isl_give pet_expr
*pet_expr_access_set_depth(__isl_take pet_expr
*expr
,
259 if (expr
->acc
.depth
== depth
)
261 if (has_any_access_relation(expr
))
262 isl_die(pet_expr_get_ctx(expr
), isl_error_unsupported
,
263 "depth cannot be changed after access relation "
264 "has been set or computed", return pet_expr_free(expr
));
266 expr
= pet_expr_cow(expr
);
269 expr
->acc
.depth
= depth
;
274 /* Construct a pet_expr that kills the elements specified by
275 * the index expression "index" and the access relation "access".
277 __isl_give pet_expr
*pet_expr_kill_from_access_and_index(
278 __isl_take isl_map
*access
, __isl_take isl_multi_pw_aff
*index
)
283 if (!access
|| !index
)
286 expr
= pet_expr_from_index(index
);
287 expr
= pet_expr_access_set_read(expr
, 0);
288 expr
= pet_expr_access_set_kill(expr
, 1);
289 depth
= isl_map_dim(access
, isl_dim_out
);
290 expr
= pet_expr_access_set_depth(expr
, depth
);
291 expr
= pet_expr_access_set_access(expr
, pet_expr_access_killed
,
292 isl_union_map_from_map(access
));
293 return pet_expr_new_unary(pet_op_kill
, expr
);
295 isl_map_free(access
);
296 isl_multi_pw_aff_free(index
);
300 /* Construct a unary pet_expr that performs "op" on "arg".
302 __isl_give pet_expr
*pet_expr_new_unary(enum pet_op_type op
,
303 __isl_take pet_expr
*arg
)
310 ctx
= pet_expr_get_ctx(arg
);
311 expr
= pet_expr_alloc(ctx
, pet_expr_op
);
312 expr
= pet_expr_set_n_arg(expr
, 1);
317 expr
->args
[pet_un_arg
] = arg
;
325 /* Construct a binary pet_expr that performs "op" on "lhs" and "rhs",
326 * where the result is represented using a type of "type_size" bits
327 * (may be zero if unknown or if the type is not an integer).
329 __isl_give pet_expr
*pet_expr_new_binary(int type_size
, enum pet_op_type op
,
330 __isl_take pet_expr
*lhs
, __isl_take pet_expr
*rhs
)
337 ctx
= pet_expr_get_ctx(lhs
);
338 expr
= pet_expr_alloc(ctx
, pet_expr_op
);
339 expr
= pet_expr_set_n_arg(expr
, 2);
344 expr
->type_size
= type_size
;
345 expr
->args
[pet_bin_lhs
] = lhs
;
346 expr
->args
[pet_bin_rhs
] = rhs
;
355 /* Construct a ternary pet_expr that performs "cond" ? "lhs" : "rhs".
357 __isl_give pet_expr
*pet_expr_new_ternary(__isl_take pet_expr
*cond
,
358 __isl_take pet_expr
*lhs
, __isl_take pet_expr
*rhs
)
363 if (!cond
|| !lhs
|| !rhs
)
365 ctx
= pet_expr_get_ctx(cond
);
366 expr
= pet_expr_alloc(ctx
, pet_expr_op
);
367 expr
= pet_expr_set_n_arg(expr
, 3);
371 expr
->op
= pet_op_cond
;
372 expr
->args
[pet_ter_cond
] = cond
;
373 expr
->args
[pet_ter_true
] = lhs
;
374 expr
->args
[pet_ter_false
] = rhs
;
384 /* Construct a call pet_expr that calls function "name" with "n_arg"
385 * arguments. The caller is responsible for filling in the arguments.
387 __isl_give pet_expr
*pet_expr_new_call(isl_ctx
*ctx
, const char *name
,
392 expr
= pet_expr_alloc(ctx
, pet_expr_call
);
393 expr
= pet_expr_set_n_arg(expr
, n_arg
);
397 expr
->name
= strdup(name
);
399 return pet_expr_free(expr
);
404 /* Construct a pet_expr that represents the cast of "arg" to "type_name".
406 __isl_give pet_expr
*pet_expr_new_cast(const char *type_name
,
407 __isl_take pet_expr
*arg
)
415 ctx
= pet_expr_get_ctx(arg
);
416 expr
= pet_expr_alloc(ctx
, pet_expr_cast
);
417 expr
= pet_expr_set_n_arg(expr
, 1);
421 expr
->type_name
= strdup(type_name
);
422 if (!expr
->type_name
)
434 /* Construct a pet_expr that represents the double "d".
436 __isl_give pet_expr
*pet_expr_new_double(isl_ctx
*ctx
,
437 double val
, const char *s
)
441 expr
= pet_expr_alloc(ctx
, pet_expr_double
);
446 expr
->d
.s
= strdup(s
);
448 return pet_expr_free(expr
);
453 /* Construct a pet_expr that represents the integer value "v".
455 __isl_give pet_expr
*pet_expr_new_int(__isl_take isl_val
*v
)
463 ctx
= isl_val_get_ctx(v
);
464 expr
= pet_expr_alloc(ctx
, pet_expr_int
);
476 /* Return an independent duplicate of "expr".
478 * In case of an access expression, make sure the depth of the duplicate is set
479 * before the access relation (if any) is set and after the index expression
482 static __isl_give pet_expr
*pet_expr_dup(__isl_keep pet_expr
*expr
)
486 enum pet_expr_access_type type
;
491 dup
= pet_expr_alloc(expr
->ctx
, expr
->type
);
492 dup
= pet_expr_set_type_size(dup
, expr
->type_size
);
493 dup
= pet_expr_set_n_arg(dup
, expr
->n_arg
);
494 for (i
= 0; i
< expr
->n_arg
; ++i
)
495 dup
= pet_expr_set_arg(dup
, i
, pet_expr_copy(expr
->args
[i
]));
497 switch (expr
->type
) {
498 case pet_expr_access
:
499 if (expr
->acc
.ref_id
)
500 dup
= pet_expr_access_set_ref_id(dup
,
501 isl_id_copy(expr
->acc
.ref_id
));
502 dup
= pet_expr_access_set_index(dup
,
503 isl_multi_pw_aff_copy(expr
->acc
.index
));
504 dup
= pet_expr_access_set_depth(dup
, expr
->acc
.depth
);
505 for (type
= pet_expr_access_begin
;
506 type
< pet_expr_access_end
; ++type
) {
507 if (!expr
->acc
.access
[type
])
509 dup
= pet_expr_access_set_access(dup
, type
,
510 isl_union_map_copy(expr
->acc
.access
[type
]));
512 dup
= pet_expr_access_set_read(dup
, expr
->acc
.read
);
513 dup
= pet_expr_access_set_write(dup
, expr
->acc
.write
);
514 dup
= pet_expr_access_set_kill(dup
, expr
->acc
.kill
);
517 dup
= pet_expr_call_set_name(dup
, expr
->name
);
520 dup
= pet_expr_cast_set_type_name(dup
, expr
->type_name
);
522 case pet_expr_double
:
523 dup
= pet_expr_double_set(dup
, expr
->d
.val
, expr
->d
.s
);
526 dup
= pet_expr_int_set_val(dup
, isl_val_copy(expr
->i
));
529 dup
= pet_expr_op_set_type(dup
, expr
->op
);
532 dup
= pet_expr_free(dup
);
539 __isl_give pet_expr
*pet_expr_cow(__isl_take pet_expr
*expr
)
547 return pet_expr_dup(expr
);
550 __isl_null pet_expr
*pet_expr_free(__isl_take pet_expr
*expr
)
552 enum pet_expr_access_type type
;
560 for (i
= 0; i
< expr
->n_arg
; ++i
)
561 pet_expr_free(expr
->args
[i
]);
564 switch (expr
->type
) {
565 case pet_expr_access
:
566 isl_id_free(expr
->acc
.ref_id
);
567 for (type
= pet_expr_access_begin
;
568 type
< pet_expr_access_end
; ++type
)
569 isl_union_map_free(expr
->acc
.access
[type
]);
570 isl_multi_pw_aff_free(expr
->acc
.index
);
576 free(expr
->type_name
);
578 case pet_expr_double
:
582 isl_val_free(expr
->i
);
589 isl_ctx_deref(expr
->ctx
);
594 /* Return an additional reference to "expr".
596 __isl_give pet_expr
*pet_expr_copy(__isl_keep pet_expr
*expr
)
605 /* Return the isl_ctx in which "expr" was created.
607 isl_ctx
*pet_expr_get_ctx(__isl_keep pet_expr
*expr
)
609 return expr
? expr
->ctx
: NULL
;
612 /* Return the type of "expr".
614 enum pet_expr_type
pet_expr_get_type(__isl_keep pet_expr
*expr
)
617 return pet_expr_error
;
621 /* Return the number of arguments of "expr".
623 int pet_expr_get_n_arg(__isl_keep pet_expr
*expr
)
631 /* Set the number of arguments of "expr" to "n".
633 * If "expr" originally had more arguments, then remove the extra arguments.
634 * If "expr" originally had fewer arguments, then create space for
635 * the extra arguments ans initialize them to NULL.
637 __isl_give pet_expr
*pet_expr_set_n_arg(__isl_take pet_expr
*expr
, int n
)
644 if (expr
->n_arg
== n
)
646 expr
= pet_expr_cow(expr
);
650 if (n
< expr
->n_arg
) {
651 for (i
= n
; i
< expr
->n_arg
; ++i
)
652 pet_expr_free(expr
->args
[i
]);
657 args
= isl_realloc_array(expr
->ctx
, expr
->args
, pet_expr
*, n
);
659 return pet_expr_free(expr
);
661 for (i
= expr
->n_arg
; i
< n
; ++i
)
662 expr
->args
[i
] = NULL
;
668 /* Return the argument of "expr" at position "pos".
670 __isl_give pet_expr
*pet_expr_get_arg(__isl_keep pet_expr
*expr
, int pos
)
674 if (pos
< 0 || pos
>= expr
->n_arg
)
675 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
676 "position out of bounds", return NULL
);
678 return pet_expr_copy(expr
->args
[pos
]);
681 /* Replace the argument of "expr" at position "pos" by "arg".
683 __isl_give pet_expr
*pet_expr_set_arg(__isl_take pet_expr
*expr
, int pos
,
684 __isl_take pet_expr
*arg
)
688 if (pos
< 0 || pos
>= expr
->n_arg
)
689 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
690 "position out of bounds", goto error
);
691 if (expr
->args
[pos
] == arg
) {
696 expr
= pet_expr_cow(expr
);
700 pet_expr_free(expr
->args
[pos
]);
701 expr
->args
[pos
] = arg
;
710 /* Does "expr" perform a comparison operation?
712 int pet_expr_is_comparison(__isl_keep pet_expr
*expr
)
716 if (expr
->type
!= pet_expr_op
)
731 /* Does "expr" perform a boolean operation?
733 int pet_expr_is_boolean(__isl_keep pet_expr
*expr
)
737 if (expr
->type
!= pet_expr_op
)
749 /* Is "expr" an assume statement?
751 int pet_expr_is_assume(__isl_keep pet_expr
*expr
)
755 if (expr
->type
!= pet_expr_op
)
757 return expr
->op
== pet_op_assume
;
760 /* Does "expr" perform a min operation?
762 int pet_expr_is_min(__isl_keep pet_expr
*expr
)
766 if (expr
->type
!= pet_expr_call
)
768 if (expr
->n_arg
!= 2)
770 if (strcmp(expr
->name
, "min") != 0)
775 /* Does "expr" perform a max operation?
777 int pet_expr_is_max(__isl_keep pet_expr
*expr
)
781 if (expr
->type
!= pet_expr_call
)
783 if (expr
->n_arg
!= 2)
785 if (strcmp(expr
->name
, "max") != 0)
790 /* Does "expr" represent an access to an unnamed space, i.e.,
791 * does it represent an affine expression?
793 int pet_expr_is_affine(__isl_keep pet_expr
*expr
)
799 if (expr
->type
!= pet_expr_access
)
802 has_id
= isl_multi_pw_aff_has_tuple_id(expr
->acc
.index
, isl_dim_out
);
809 /* Does "expr" represent an access to a scalar, i.e., a zero-dimensional array,
810 * not part of any struct?
812 int pet_expr_is_scalar_access(__isl_keep pet_expr
*expr
)
816 if (expr
->type
!= pet_expr_access
)
818 if (isl_multi_pw_aff_range_is_wrapping(expr
->acc
.index
))
821 return expr
->acc
.depth
== 0;
824 /* Are "mpa1" and "mpa2" obviously equal to each other, up to reordering
827 static int multi_pw_aff_is_equal(__isl_keep isl_multi_pw_aff
*mpa1
,
828 __isl_keep isl_multi_pw_aff
*mpa2
)
832 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
833 if (equal
< 0 || equal
)
835 mpa2
= isl_multi_pw_aff_copy(mpa2
);
836 mpa2
= isl_multi_pw_aff_align_params(mpa2
,
837 isl_multi_pw_aff_get_space(mpa1
));
838 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
839 isl_multi_pw_aff_free(mpa2
);
844 /* Construct an access relation from the index expression and
845 * the array depth of the access expression "expr".
847 * If the number of indices is smaller than the depth of the array,
848 * then we assume that all elements of the remaining dimensions
851 static __isl_give isl_union_map
*construct_access_relation(
852 __isl_keep pet_expr
*expr
)
861 access
= isl_map_from_multi_pw_aff(pet_expr_access_get_index(expr
));
865 dim
= isl_map_dim(access
, isl_dim_out
);
866 if (dim
> expr
->acc
.depth
)
867 isl_die(isl_map_get_ctx(access
), isl_error_internal
,
868 "number of indices greater than depth",
869 access
= isl_map_free(access
));
871 if (dim
!= expr
->acc
.depth
)
872 access
= extend_range(access
, expr
->acc
.depth
- dim
);
874 return isl_union_map_from_map(access
);
877 /* Ensure that all relevant access relations are explicitly
878 * available in "expr".
880 * If "expr" does not already have the relevant access relations, then create
881 * them based on the index expression and the array depth.
883 * We do not cow since adding an explicit access relation
884 * does not change the meaning of the expression.
886 static __isl_give pet_expr
*introduce_access_relations(
887 __isl_take pet_expr
*expr
)
889 enum pet_expr_access_type type
;
890 isl_union_map
*access
;
892 int kill
, read
, write
;
896 if (has_relevant_access_relations(expr
))
899 access
= construct_access_relation(expr
);
901 return pet_expr_free(expr
);
903 kill
= expr
->acc
.kill
;
904 read
= expr
->acc
.read
;
905 write
= expr
->acc
.write
;
906 if (kill
&& !expr
->acc
.access
[pet_expr_access_fake_killed
])
907 expr
->acc
.access
[pet_expr_access_fake_killed
] =
908 isl_union_map_copy(access
);
909 if (read
&& !expr
->acc
.access
[pet_expr_access_may_read
])
910 expr
->acc
.access
[pet_expr_access_may_read
] =
911 isl_union_map_copy(access
);
912 if (write
&& !expr
->acc
.access
[pet_expr_access_may_write
])
913 expr
->acc
.access
[pet_expr_access_may_write
] =
914 isl_union_map_copy(access
);
915 if (write
&& !expr
->acc
.access
[pet_expr_access_must_write
])
916 expr
->acc
.access
[pet_expr_access_must_write
] =
917 isl_union_map_copy(access
);
919 isl_union_map_free(access
);
921 if (!has_relevant_access_relations(expr
))
922 return pet_expr_free(expr
);
927 /* Return 1 if the two pet_exprs are equivalent.
929 int pet_expr_is_equal(__isl_keep pet_expr
*expr1
, __isl_keep pet_expr
*expr2
)
932 enum pet_expr_access_type type
;
934 if (!expr1
|| !expr2
)
937 if (expr1
->type
!= expr2
->type
)
939 if (expr1
->n_arg
!= expr2
->n_arg
)
941 for (i
= 0; i
< expr1
->n_arg
; ++i
)
942 if (!pet_expr_is_equal(expr1
->args
[i
], expr2
->args
[i
]))
944 switch (expr1
->type
) {
947 case pet_expr_double
:
948 if (strcmp(expr1
->d
.s
, expr2
->d
.s
))
950 if (expr1
->d
.val
!= expr2
->d
.val
)
954 if (!isl_val_eq(expr1
->i
, expr2
->i
))
957 case pet_expr_access
:
958 if (expr1
->acc
.read
!= expr2
->acc
.read
)
960 if (expr1
->acc
.write
!= expr2
->acc
.write
)
962 if (expr1
->acc
.kill
!= expr2
->acc
.kill
)
964 if (expr1
->acc
.ref_id
!= expr2
->acc
.ref_id
)
966 if (!expr1
->acc
.index
|| !expr2
->acc
.index
)
968 if (!multi_pw_aff_is_equal(expr1
->acc
.index
, expr2
->acc
.index
))
970 if (expr1
->acc
.depth
!= expr2
->acc
.depth
)
972 if (has_relevant_access_relations(expr1
) !=
973 has_relevant_access_relations(expr2
)) {
975 expr1
= pet_expr_copy(expr1
);
976 expr2
= pet_expr_copy(expr2
);
977 expr1
= introduce_access_relations(expr1
);
978 expr2
= introduce_access_relations(expr2
);
979 equal
= pet_expr_is_equal(expr1
, expr2
);
980 pet_expr_free(expr1
);
981 pet_expr_free(expr2
);
984 for (type
= pet_expr_access_begin
;
985 type
< pet_expr_access_end
; ++type
) {
986 if (!expr1
->acc
.access
[type
] !=
987 !expr2
->acc
.access
[type
])
989 if (!expr1
->acc
.access
[type
])
991 if (!isl_union_map_is_equal(expr1
->acc
.access
[type
],
992 expr2
->acc
.access
[type
]))
997 if (expr1
->op
!= expr2
->op
)
1001 if (strcmp(expr1
->name
, expr2
->name
))
1005 if (strcmp(expr1
->type_name
, expr2
->type_name
))
1013 /* Does the access expression "expr" read the accessed elements?
1015 int pet_expr_access_is_read(__isl_keep pet_expr
*expr
)
1019 if (expr
->type
!= pet_expr_access
)
1020 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1021 "not an access expression", return -1);
1023 return expr
->acc
.read
;
1026 /* Does the access expression "expr" write to the accessed elements?
1028 int pet_expr_access_is_write(__isl_keep pet_expr
*expr
)
1032 if (expr
->type
!= pet_expr_access
)
1033 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1034 "not an access expression", return -1);
1036 return expr
->acc
.write
;
1039 /* Return the identifier of the array accessed by "expr".
1041 * If "expr" represents a member access, then return the identifier
1042 * of the outer structure array.
1044 __isl_give isl_id
*pet_expr_access_get_id(__isl_keep pet_expr
*expr
)
1048 if (expr
->type
!= pet_expr_access
)
1049 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1050 "not an access expression", return NULL
);
1052 if (isl_multi_pw_aff_range_is_wrapping(expr
->acc
.index
)) {
1056 space
= isl_multi_pw_aff_get_space(expr
->acc
.index
);
1057 space
= isl_space_range(space
);
1058 while (space
&& isl_space_is_wrapping(space
))
1059 space
= isl_space_domain(isl_space_unwrap(space
));
1060 id
= isl_space_get_tuple_id(space
, isl_dim_set
);
1061 isl_space_free(space
);
1066 return isl_multi_pw_aff_get_tuple_id(expr
->acc
.index
, isl_dim_out
);
1069 /* Return the parameter space of "expr".
1071 __isl_give isl_space
*pet_expr_access_get_parameter_space(
1072 __isl_keep pet_expr
*expr
)
1078 if (expr
->type
!= pet_expr_access
)
1079 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1080 "not an access expression", return NULL
);
1082 space
= isl_multi_pw_aff_get_space(expr
->acc
.index
);
1083 space
= isl_space_params(space
);
1088 /* Return the domain space of "expr", without the arguments (if any).
1090 __isl_give isl_space
*pet_expr_access_get_domain_space(
1091 __isl_keep pet_expr
*expr
)
1097 if (expr
->type
!= pet_expr_access
)
1098 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1099 "not an access expression", return NULL
);
1101 space
= isl_multi_pw_aff_get_space(expr
->acc
.index
);
1102 space
= isl_space_domain(space
);
1103 if (isl_space_is_wrapping(space
))
1104 space
= isl_space_domain(isl_space_unwrap(space
));
1109 /* Return the space of the data accessed by "expr".
1111 __isl_give isl_space
*pet_expr_access_get_data_space(__isl_keep pet_expr
*expr
)
1117 if (expr
->type
!= pet_expr_access
)
1118 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1119 "not an access expression", return NULL
);
1121 space
= isl_multi_pw_aff_get_space(expr
->acc
.index
);
1122 space
= isl_space_range(space
);
1127 /* Modify all expressions of type pet_expr_access in "expr"
1128 * by calling "fn" on them.
1130 __isl_give pet_expr
*pet_expr_map_access(__isl_take pet_expr
*expr
,
1131 __isl_give pet_expr
*(*fn
)(__isl_take pet_expr
*expr
, void *user
),
1136 n
= pet_expr_get_n_arg(expr
);
1137 for (i
= 0; i
< n
; ++i
) {
1138 pet_expr
*arg
= pet_expr_get_arg(expr
, i
);
1139 arg
= pet_expr_map_access(arg
, fn
, user
);
1140 expr
= pet_expr_set_arg(expr
, i
, arg
);
1146 if (expr
->type
== pet_expr_access
)
1147 expr
= fn(expr
, user
);
1152 /* Call "fn" on each of the subexpressions of "expr" of type "type".
1154 * Return -1 on error (where fn returning a negative value is treated as
1156 * Otherwise return 0.
1158 int pet_expr_foreach_expr_of_type(__isl_keep pet_expr
*expr
,
1159 enum pet_expr_type type
,
1160 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
)
1167 for (i
= 0; i
< expr
->n_arg
; ++i
)
1168 if (pet_expr_foreach_expr_of_type(expr
->args
[i
],
1169 type
, fn
, user
) < 0)
1172 if (expr
->type
== type
)
1173 return fn(expr
, user
);
1178 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_access.
1180 * Return -1 on error (where fn returning a negative value is treated as
1182 * Otherwise return 0.
1184 int pet_expr_foreach_access_expr(__isl_keep pet_expr
*expr
,
1185 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
)
1187 return pet_expr_foreach_expr_of_type(expr
, pet_expr_access
, fn
, user
);
1190 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_call.
1192 * Return -1 on error (where fn returning a negative value is treated as
1194 * Otherwise return 0.
1196 int pet_expr_foreach_call_expr(__isl_keep pet_expr
*expr
,
1197 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
)
1199 return pet_expr_foreach_expr_of_type(expr
, pet_expr_call
, fn
, user
);
1202 /* Internal data structure for pet_expr_writes.
1203 * "id" is the identifier that we are looking for.
1204 * "found" is set if we have found the identifier being written to.
1206 struct pet_expr_writes_data
{
1211 /* Given an access expression, check if it writes to data->id.
1212 * If so, set data->found and abort the search.
1214 static int writes(__isl_keep pet_expr
*expr
, void *user
)
1216 struct pet_expr_writes_data
*data
= user
;
1219 if (!expr
->acc
.write
)
1221 if (pet_expr_is_affine(expr
))
1224 write_id
= pet_expr_access_get_id(expr
);
1225 isl_id_free(write_id
);
1230 if (write_id
!= data
->id
)
1237 /* Does expression "expr" write to "id"?
1239 int pet_expr_writes(__isl_keep pet_expr
*expr
, __isl_keep isl_id
*id
)
1241 struct pet_expr_writes_data data
;
1245 if (pet_expr_foreach_access_expr(expr
, &writes
, &data
) < 0 &&
1252 /* Move the "n" dimensions of "src_type" starting at "src_pos" of
1253 * index expression and access relations of "expr" (if any)
1254 * to dimensions of "dst_type" at "dst_pos".
1256 __isl_give pet_expr
*pet_expr_access_move_dims(__isl_take pet_expr
*expr
,
1257 enum isl_dim_type dst_type
, unsigned dst_pos
,
1258 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1260 enum pet_expr_access_type type
;
1262 expr
= pet_expr_cow(expr
);
1265 if (expr
->type
!= pet_expr_access
)
1266 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1267 "not an access pet_expr", return pet_expr_free(expr
));
1269 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1270 if (!expr
->acc
.access
[type
])
1272 expr
->acc
.access
[type
] =
1273 pet_union_map_move_dims(expr
->acc
.access
[type
],
1274 dst_type
, dst_pos
, src_type
, src_pos
, n
);
1275 if (!expr
->acc
.access
[type
])
1278 expr
->acc
.index
= isl_multi_pw_aff_move_dims(expr
->acc
.index
,
1279 dst_type
, dst_pos
, src_type
, src_pos
, n
);
1280 if (!expr
->acc
.index
|| type
< pet_expr_access_end
)
1281 return pet_expr_free(expr
);
1286 /* Replace the index expression and access relations (if any) of "expr"
1287 * by their preimages under the function represented by "ma".
1289 __isl_give pet_expr
*pet_expr_access_pullback_multi_aff(
1290 __isl_take pet_expr
*expr
, __isl_take isl_multi_aff
*ma
)
1292 enum pet_expr_access_type type
;
1294 expr
= pet_expr_cow(expr
);
1297 if (expr
->type
!= pet_expr_access
)
1298 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1299 "not an access pet_expr", goto error
);
1301 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1302 if (!expr
->acc
.access
[type
])
1304 expr
->acc
.access
[type
] =
1305 isl_union_map_preimage_domain_multi_aff(
1306 expr
->acc
.access
[type
], isl_multi_aff_copy(ma
));
1307 if (!expr
->acc
.access
[type
])
1310 expr
->acc
.index
= isl_multi_pw_aff_pullback_multi_aff(expr
->acc
.index
,
1312 if (!expr
->acc
.index
|| type
< pet_expr_access_end
)
1313 return pet_expr_free(expr
);
1317 isl_multi_aff_free(ma
);
1318 pet_expr_free(expr
);
1322 /* Replace the index expression and access relations (if any) of "expr"
1323 * by their preimages under the function represented by "mpa".
1325 __isl_give pet_expr
*pet_expr_access_pullback_multi_pw_aff(
1326 __isl_take pet_expr
*expr
, __isl_take isl_multi_pw_aff
*mpa
)
1328 enum pet_expr_access_type type
;
1330 expr
= pet_expr_cow(expr
);
1333 if (expr
->type
!= pet_expr_access
)
1334 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1335 "not an access pet_expr", goto error
);
1337 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1338 if (!expr
->acc
.access
[type
])
1340 expr
->acc
.access
[type
] =
1341 isl_union_map_preimage_domain_multi_pw_aff(
1342 expr
->acc
.access
[type
], isl_multi_pw_aff_copy(mpa
));
1343 if (!expr
->acc
.access
[type
])
1346 expr
->acc
.index
= isl_multi_pw_aff_pullback_multi_pw_aff(
1347 expr
->acc
.index
, mpa
);
1348 if (!expr
->acc
.index
|| type
< pet_expr_access_end
)
1349 return pet_expr_free(expr
);
1353 isl_multi_pw_aff_free(mpa
);
1354 pet_expr_free(expr
);
1358 /* Return the index expression of access expression "expr".
1360 __isl_give isl_multi_pw_aff
*pet_expr_access_get_index(
1361 __isl_keep pet_expr
*expr
)
1365 if (expr
->type
!= pet_expr_access
)
1366 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1367 "not an access expression", return NULL
);
1369 return isl_multi_pw_aff_copy(expr
->acc
.index
);
1372 /* Align the parameters of expr->acc.index and expr->acc.access[*] (if set).
1374 __isl_give pet_expr
*pet_expr_access_align_params(__isl_take pet_expr
*expr
)
1377 enum pet_expr_access_type type
;
1379 expr
= pet_expr_cow(expr
);
1382 if (expr
->type
!= pet_expr_access
)
1383 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1384 "not an access expression", return pet_expr_free(expr
));
1386 if (!has_any_access_relation(expr
))
1389 space
= isl_multi_pw_aff_get_space(expr
->acc
.index
);
1390 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1391 if (!expr
->acc
.access
[type
])
1393 space
= isl_space_align_params(space
,
1394 isl_union_map_get_space(expr
->acc
.access
[type
]));
1396 expr
->acc
.index
= isl_multi_pw_aff_align_params(expr
->acc
.index
,
1397 isl_space_copy(space
));
1398 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1399 if (!expr
->acc
.access
[type
])
1401 expr
->acc
.access
[type
] =
1402 isl_union_map_align_params(expr
->acc
.access
[type
],
1403 isl_space_copy(space
));
1404 if (!expr
->acc
.access
[type
])
1407 isl_space_free(space
);
1408 if (!expr
->acc
.index
|| type
< pet_expr_access_end
)
1409 return pet_expr_free(expr
);
1414 /* Are "expr1" and "expr2" both array accesses such that
1415 * the access relation of "expr1" is a subset of that of "expr2"?
1416 * Only take into account the first "n_arg" arguments.
1418 * This function is tailored for use by mark_self_dependences in nest.c.
1419 * In particular, the input expressions may have more than "n_arg"
1420 * elements in their arguments arrays, while only the first "n_arg"
1421 * elements are referenced from the access relations.
1423 int pet_expr_is_sub_access(__isl_keep pet_expr
*expr1
,
1424 __isl_keep pet_expr
*expr2
, int n_arg
)
1430 if (!expr1
|| !expr2
)
1432 if (pet_expr_get_type(expr1
) != pet_expr_access
)
1434 if (pet_expr_get_type(expr2
) != pet_expr_access
)
1436 if (pet_expr_is_affine(expr1
))
1438 if (pet_expr_is_affine(expr2
))
1440 n1
= pet_expr_get_n_arg(expr1
);
1443 n2
= pet_expr_get_n_arg(expr2
);
1448 for (i
= 0; i
< n1
; ++i
) {
1450 equal
= pet_expr_is_equal(expr1
->args
[i
], expr2
->args
[i
]);
1451 if (equal
< 0 || !equal
)
1454 id1
= pet_expr_access_get_id(expr1
);
1455 id2
= pet_expr_access_get_id(expr2
);
1463 expr1
= pet_expr_copy(expr1
);
1464 expr2
= pet_expr_copy(expr2
);
1465 expr1
= introduce_access_relations(expr1
);
1466 expr2
= introduce_access_relations(expr2
);
1467 if (!expr1
|| !expr2
)
1470 is_subset
= isl_union_map_is_subset(
1471 expr1
->acc
.access
[pet_expr_access_may_read
],
1472 expr2
->acc
.access
[pet_expr_access_may_read
]);
1474 pet_expr_free(expr1
);
1475 pet_expr_free(expr2
);
1479 pet_expr_free(expr1
);
1480 pet_expr_free(expr2
);
1484 /* Given a set in the iteration space "domain", extend it to live in the space
1485 * of the domain of access relations.
1487 * That, is the number of arguments "n" is 0, then simply return domain.
1488 * Otherwise, return [domain -> [a_1,...,a_n]].
1490 static __isl_give isl_set
*add_arguments(__isl_take isl_set
*domain
, int n
)
1497 map
= isl_map_from_domain(domain
);
1498 map
= isl_map_add_dims(map
, isl_dim_out
, n
);
1499 return isl_map_wrap(map
);
1502 /* Add extra conditions to the domains of all access relations in "expr",
1503 * introducing access relations if they are not already present.
1505 * The conditions are not added to the index expression. Instead, they
1506 * are used to try and simplify the index expression.
1508 __isl_give pet_expr
*pet_expr_restrict(__isl_take pet_expr
*expr
,
1509 __isl_take isl_set
*cond
)
1512 isl_union_set
*uset
;
1513 enum pet_expr_access_type type
;
1515 expr
= pet_expr_cow(expr
);
1519 for (i
= 0; i
< expr
->n_arg
; ++i
) {
1520 expr
->args
[i
] = pet_expr_restrict(expr
->args
[i
],
1521 isl_set_copy(cond
));
1526 if (expr
->type
!= pet_expr_access
) {
1531 expr
= introduce_access_relations(expr
);
1535 cond
= add_arguments(cond
, expr
->n_arg
);
1536 uset
= isl_union_set_from_set(isl_set_copy(cond
));
1537 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1538 if (!expr
->acc
.access
[type
])
1540 expr
->acc
.access
[type
] =
1541 isl_union_map_intersect_domain(expr
->acc
.access
[type
],
1542 isl_union_set_copy(uset
));
1543 if (!expr
->acc
.access
[type
])
1546 isl_union_set_free(uset
);
1547 expr
->acc
.index
= isl_multi_pw_aff_gist(expr
->acc
.index
, cond
);
1548 if (type
< pet_expr_access_end
|| !expr
->acc
.index
)
1549 return pet_expr_free(expr
);
1554 return pet_expr_free(expr
);
1557 /* Modify the access relations (if any) and index expression
1558 * of the given access expression
1559 * based on the given iteration space transformation.
1560 * In particular, precompose the access relation and index expression
1561 * with the update function.
1563 * If the access has any arguments then the domain of the access relation
1564 * is a wrapped mapping from the iteration space to the space of
1565 * argument values. We only need to change the domain of this wrapped
1566 * mapping, so we extend the input transformation with an identity mapping
1567 * on the space of argument values.
1569 __isl_give pet_expr
*pet_expr_access_update_domain(__isl_take pet_expr
*expr
,
1570 __isl_keep isl_multi_pw_aff
*update
)
1572 enum pet_expr_access_type type
;
1574 expr
= pet_expr_cow(expr
);
1577 if (expr
->type
!= pet_expr_access
)
1578 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1579 "not an access expression", return pet_expr_free(expr
));
1581 update
= isl_multi_pw_aff_copy(update
);
1583 if (expr
->n_arg
> 0) {
1585 isl_multi_pw_aff
*id
;
1587 space
= isl_multi_pw_aff_get_space(expr
->acc
.index
);
1588 space
= isl_space_domain(space
);
1589 space
= isl_space_unwrap(space
);
1590 space
= isl_space_range(space
);
1591 space
= isl_space_map_from_set(space
);
1592 id
= isl_multi_pw_aff_identity(space
);
1593 update
= isl_multi_pw_aff_product(update
, id
);
1596 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1597 if (!expr
->acc
.access
[type
])
1599 expr
->acc
.access
[type
] =
1600 isl_union_map_preimage_domain_multi_pw_aff(
1601 expr
->acc
.access
[type
],
1602 isl_multi_pw_aff_copy(update
));
1603 if (!expr
->acc
.access
[type
])
1606 expr
->acc
.index
= isl_multi_pw_aff_pullback_multi_pw_aff(
1607 expr
->acc
.index
, update
);
1608 if (type
< pet_expr_access_end
|| !expr
->acc
.index
)
1609 return pet_expr_free(expr
);
1614 static __isl_give pet_expr
*update_domain(__isl_take pet_expr
*expr
, void *user
)
1616 isl_multi_pw_aff
*update
= user
;
1618 return pet_expr_access_update_domain(expr
, update
);
1621 /* Modify all access relations in "expr" by precomposing them with
1622 * the given iteration space transformation.
1624 __isl_give pet_expr
*pet_expr_update_domain(__isl_take pet_expr
*expr
,
1625 __isl_take isl_multi_pw_aff
*update
)
1627 expr
= pet_expr_map_access(expr
, &update_domain
, update
);
1628 isl_multi_pw_aff_free(update
);
1632 /* Given an expression with accesses that have a 0D anonymous domain,
1633 * replace those domains by "space".
1635 __isl_give pet_expr
*pet_expr_insert_domain(__isl_take pet_expr
*expr
,
1636 __isl_take isl_space
*space
)
1638 isl_multi_pw_aff
*mpa
;
1640 space
= isl_space_from_domain(space
);
1641 mpa
= isl_multi_pw_aff_zero(space
);
1642 return pet_expr_update_domain(expr
, mpa
);
1645 /* Add all parameters in "space" to the access relations (if any)
1646 * and index expression of "expr".
1648 static __isl_give pet_expr
*align_params(__isl_take pet_expr
*expr
, void *user
)
1650 isl_space
*space
= user
;
1651 enum pet_expr_access_type type
;
1653 expr
= pet_expr_cow(expr
);
1656 if (expr
->type
!= pet_expr_access
)
1657 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1658 "not an access expression", return pet_expr_free(expr
));
1660 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1661 if (!expr
->acc
.access
[type
])
1663 expr
->acc
.access
[type
] =
1664 isl_union_map_align_params(expr
->acc
.access
[type
],
1665 isl_space_copy(space
));
1666 if (!expr
->acc
.access
[type
])
1669 expr
->acc
.index
= isl_multi_pw_aff_align_params(expr
->acc
.index
,
1670 isl_space_copy(space
));
1671 if (type
< pet_expr_access_end
|| !expr
->acc
.index
)
1672 return pet_expr_free(expr
);
1677 /* Add all parameters in "space" to all access relations and index expressions
1680 __isl_give pet_expr
*pet_expr_align_params(__isl_take pet_expr
*expr
,
1681 __isl_take isl_space
*space
)
1683 expr
= pet_expr_map_access(expr
, &align_params
, space
);
1684 isl_space_free(space
);
1688 /* Insert an argument expression corresponding to "test" in front
1689 * of the list of arguments described by *n_arg and *args.
1691 static __isl_give pet_expr
*insert_access_arg(__isl_take pet_expr
*expr
,
1692 __isl_keep isl_multi_pw_aff
*test
)
1695 isl_ctx
*ctx
= isl_multi_pw_aff_get_ctx(test
);
1698 return pet_expr_free(expr
);
1699 expr
= pet_expr_cow(expr
);
1704 expr
->args
= isl_calloc_array(ctx
, pet_expr
*, 1);
1706 return pet_expr_free(expr
);
1709 ext
= isl_calloc_array(ctx
, pet_expr
*, 1 + expr
->n_arg
);
1711 return pet_expr_free(expr
);
1712 for (i
= 0; i
< expr
->n_arg
; ++i
)
1713 ext
[1 + i
] = expr
->args
[i
];
1718 expr
->args
[0] = pet_expr_from_index(isl_multi_pw_aff_copy(test
));
1720 return pet_expr_free(expr
);
1725 /* Make the expression "expr" depend on the value of "test"
1726 * being equal to "satisfied".
1728 * If "test" is an affine expression, we simply add the conditions
1729 * on the expression having the value "satisfied" to all access relations
1730 * (introducing access relations if they are missing) and index expressions.
1732 * Otherwise, we add a filter to "expr" (which is then assumed to be
1733 * an access expression) corresponding to "test" being equal to "satisfied".
1735 __isl_give pet_expr
*pet_expr_filter(__isl_take pet_expr
*expr
,
1736 __isl_take isl_multi_pw_aff
*test
, int satisfied
)
1741 isl_pw_multi_aff
*pma
;
1742 enum pet_expr_access_type type
;
1744 expr
= pet_expr_cow(expr
);
1748 if (!isl_multi_pw_aff_has_tuple_id(test
, isl_dim_out
)) {
1752 pa
= isl_multi_pw_aff_get_pw_aff(test
, 0);
1753 isl_multi_pw_aff_free(test
);
1755 cond
= isl_pw_aff_non_zero_set(pa
);
1757 cond
= isl_pw_aff_zero_set(pa
);
1758 return pet_expr_restrict(expr
, cond
);
1761 ctx
= isl_multi_pw_aff_get_ctx(test
);
1762 if (expr
->type
!= pet_expr_access
)
1763 isl_die(ctx
, isl_error_invalid
,
1764 "can only filter access expressions", goto error
);
1766 expr
= introduce_access_relations(expr
);
1770 space
= isl_space_domain(isl_multi_pw_aff_get_space(expr
->acc
.index
));
1771 id
= isl_multi_pw_aff_get_tuple_id(test
, isl_dim_out
);
1772 pma
= pet_filter_insert_pma(space
, id
, satisfied
);
1774 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1775 if (!expr
->acc
.access
[type
])
1777 expr
->acc
.access
[type
] =
1778 isl_union_map_preimage_domain_pw_multi_aff(
1779 expr
->acc
.access
[type
],
1780 isl_pw_multi_aff_copy(pma
));
1781 if (!expr
->acc
.access
[type
])
1784 pma
= isl_pw_multi_aff_gist(pma
,
1785 isl_pw_multi_aff_domain(isl_pw_multi_aff_copy(pma
)));
1786 expr
->acc
.index
= isl_multi_pw_aff_pullback_pw_multi_aff(
1787 expr
->acc
.index
, pma
);
1788 if (type
< pet_expr_access_end
|| !expr
->acc
.index
)
1791 expr
= insert_access_arg(expr
, test
);
1793 isl_multi_pw_aff_free(test
);
1796 isl_multi_pw_aff_free(test
);
1797 return pet_expr_free(expr
);
1800 /* Add a reference identifier to access expression "expr".
1801 * "user" points to an integer that contains the sequence number
1802 * of the next reference.
1804 static __isl_give pet_expr
*access_add_ref_id(__isl_take pet_expr
*expr
,
1811 expr
= pet_expr_cow(expr
);
1814 if (expr
->type
!= pet_expr_access
)
1815 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1816 "not an access expression", return pet_expr_free(expr
));
1818 ctx
= pet_expr_get_ctx(expr
);
1819 snprintf(name
, sizeof(name
), "__pet_ref_%d", (*n_ref
)++);
1820 expr
->acc
.ref_id
= isl_id_alloc(ctx
, name
, NULL
);
1821 if (!expr
->acc
.ref_id
)
1822 return pet_expr_free(expr
);
1827 __isl_give pet_expr
*pet_expr_add_ref_ids(__isl_take pet_expr
*expr
, int *n_ref
)
1829 return pet_expr_map_access(expr
, &access_add_ref_id
, n_ref
);
1832 /* Reset the user pointer on all parameter and tuple ids in
1833 * the access relations (if any) and the index expression
1834 * of the access expression "expr".
1836 static __isl_give pet_expr
*access_anonymize(__isl_take pet_expr
*expr
,
1839 enum pet_expr_access_type type
;
1841 expr
= pet_expr_cow(expr
);
1844 if (expr
->type
!= pet_expr_access
)
1845 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1846 "not an access expression", return pet_expr_free(expr
));
1848 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1849 if (!expr
->acc
.access
[type
])
1851 expr
->acc
.access
[type
] =
1852 isl_union_map_reset_user(expr
->acc
.access
[type
]);
1853 if (!expr
->acc
.access
[type
])
1856 expr
->acc
.index
= isl_multi_pw_aff_reset_user(expr
->acc
.index
);
1857 if (type
< pet_expr_access_end
|| !expr
->acc
.index
)
1858 return pet_expr_free(expr
);
1863 __isl_give pet_expr
*pet_expr_anonymize(__isl_take pet_expr
*expr
)
1865 return pet_expr_map_access(expr
, &access_anonymize
, NULL
);
1868 /* Data used in access_gist() callback.
1870 struct pet_access_gist_data
{
1872 isl_union_map
*value_bounds
;
1875 /* Given an expression "expr" of type pet_expr_access, compute
1876 * the gist of the associated access relations (if any) and index expression
1877 * with respect to data->domain and the bounds on the values of the arguments
1878 * of the expression.
1880 * The arguments of "expr" have been gisted right before "expr" itself
1881 * is gisted. The gisted arguments may have become equal where before
1882 * they may not have been (obviously) equal. We therefore take
1883 * the opportunity to remove duplicate arguments here.
1885 static __isl_give pet_expr
*access_gist(__isl_take pet_expr
*expr
, void *user
)
1887 struct pet_access_gist_data
*data
= user
;
1889 isl_union_set
*uset
;
1890 enum pet_expr_access_type type
;
1892 expr
= pet_expr_remove_duplicate_args(expr
);
1893 expr
= pet_expr_cow(expr
);
1896 if (expr
->type
!= pet_expr_access
)
1897 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1898 "not an access expression", return pet_expr_free(expr
));
1900 domain
= isl_set_copy(data
->domain
);
1901 if (expr
->n_arg
> 0)
1902 domain
= pet_value_bounds_apply(domain
, expr
->n_arg
, expr
->args
,
1903 data
->value_bounds
);
1905 uset
= isl_union_set_from_set(isl_set_copy(domain
));
1906 for (type
= pet_expr_access_begin
; type
< pet_expr_access_end
; ++type
) {
1907 if (!expr
->acc
.access
[type
])
1909 expr
->acc
.access
[type
] =
1910 isl_union_map_gist_domain(expr
->acc
.access
[type
],
1911 isl_union_set_copy(uset
));
1912 if (!expr
->acc
.access
[type
])
1915 isl_union_set_free(uset
);
1916 expr
->acc
.index
= isl_multi_pw_aff_gist(expr
->acc
.index
, domain
);
1917 if (type
< pet_expr_access_end
|| !expr
->acc
.index
)
1918 return pet_expr_free(expr
);
1923 __isl_give pet_expr
*pet_expr_gist(__isl_take pet_expr
*expr
,
1924 __isl_keep isl_set
*context
, __isl_keep isl_union_map
*value_bounds
)
1926 struct pet_access_gist_data data
= { context
, value_bounds
};
1928 return pet_expr_map_access(expr
, &access_gist
, &data
);
1931 /* Mark "expr" as a read dependening on "read".
1933 __isl_give pet_expr
*pet_expr_access_set_read(__isl_take pet_expr
*expr
,
1937 return pet_expr_free(expr
);
1938 if (expr
->type
!= pet_expr_access
)
1939 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1940 "not an access expression", return pet_expr_free(expr
));
1941 if (expr
->acc
.read
== read
)
1943 expr
= pet_expr_cow(expr
);
1946 expr
->acc
.read
= read
;
1951 /* Mark "expr" as a write dependening on "write".
1953 __isl_give pet_expr
*pet_expr_access_set_write(__isl_take pet_expr
*expr
,
1957 return pet_expr_free(expr
);
1958 if (expr
->type
!= pet_expr_access
)
1959 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1960 "not an access expression", return pet_expr_free(expr
));
1961 if (expr
->acc
.write
== write
)
1963 expr
= pet_expr_cow(expr
);
1966 expr
->acc
.write
= write
;
1971 /* Mark "expr" as a kill dependening on "kill".
1973 __isl_give pet_expr
*pet_expr_access_set_kill(__isl_take pet_expr
*expr
,
1977 return pet_expr_free(expr
);
1978 if (expr
->type
!= pet_expr_access
)
1979 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
1980 "not an access expression", return pet_expr_free(expr
));
1981 if (expr
->acc
.kill
== kill
)
1983 expr
= pet_expr_cow(expr
);
1986 expr
->acc
.kill
= kill
;
1991 /* Map the access type "type" to the corresponding location
1992 * in the access array.
1993 * In particular, the access relation of type pet_expr_access_killed is
1994 * stored in the element at position pet_expr_access_fake_killed.
1996 static enum pet_expr_access_type
internalize_type(
1997 enum pet_expr_access_type type
)
1999 if (type
== pet_expr_access_killed
)
2000 return pet_expr_access_fake_killed
;
2004 /* Replace the access relation of the given "type" of "expr" by "access".
2006 __isl_give pet_expr
*pet_expr_access_set_access(__isl_take pet_expr
*expr
,
2007 enum pet_expr_access_type type
, __isl_take isl_union_map
*access
)
2009 expr
= pet_expr_cow(expr
);
2010 if (!expr
|| !access
)
2012 if (expr
->type
!= pet_expr_access
)
2013 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2014 "not an access expression", goto error
);
2015 type
= internalize_type(type
);
2016 isl_union_map_free(expr
->acc
.access
[type
]);
2017 expr
->acc
.access
[type
] = access
;
2021 isl_union_map_free(access
);
2022 pet_expr_free(expr
);
2026 /* Replace the index expression of "expr" by "index" and
2027 * set the array depth accordingly.
2029 __isl_give pet_expr
*pet_expr_access_set_index(__isl_take pet_expr
*expr
,
2030 __isl_take isl_multi_pw_aff
*index
)
2032 expr
= pet_expr_cow(expr
);
2033 if (!expr
|| !index
)
2035 if (expr
->type
!= pet_expr_access
)
2036 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2037 "not an access expression", goto error
);
2038 isl_multi_pw_aff_free(expr
->acc
.index
);
2039 expr
->acc
.index
= index
;
2040 expr
->acc
.depth
= isl_multi_pw_aff_dim(index
, isl_dim_out
);
2044 isl_multi_pw_aff_free(index
);
2045 pet_expr_free(expr
);
2049 /* Return the reference identifier of access expression "expr".
2051 __isl_give isl_id
*pet_expr_access_get_ref_id(__isl_keep pet_expr
*expr
)
2055 if (expr
->type
!= pet_expr_access
)
2056 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2057 "not an access expression", return NULL
);
2059 return isl_id_copy(expr
->acc
.ref_id
);
2062 /* Replace the reference identifier of access expression "expr" by "ref_id".
2064 __isl_give pet_expr
*pet_expr_access_set_ref_id(__isl_take pet_expr
*expr
,
2065 __isl_take isl_id
*ref_id
)
2067 expr
= pet_expr_cow(expr
);
2068 if (!expr
|| !ref_id
)
2070 if (expr
->type
!= pet_expr_access
)
2071 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2072 "not an access expression", goto error
);
2073 isl_id_free(expr
->acc
.ref_id
);
2074 expr
->acc
.ref_id
= ref_id
;
2078 isl_id_free(ref_id
);
2079 pet_expr_free(expr
);
2083 /* Tag the access relation "access" with "id".
2084 * That is, insert the id as the range of a wrapped relation
2085 * in the domain of "access".
2087 * If "access" is of the form
2091 * then the result is of the form
2093 * [D[i] -> id[]] -> A[a]
2095 __isl_give isl_union_map
*pet_expr_tag_access(__isl_keep pet_expr
*expr
,
2096 __isl_take isl_union_map
*access
)
2099 isl_multi_aff
*add_tag
;
2102 if (expr
->type
!= pet_expr_access
)
2103 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2104 "not an access expression",
2105 return isl_union_map_free(access
));
2107 id
= isl_id_copy(expr
->acc
.ref_id
);
2108 space
= pet_expr_access_get_domain_space(expr
);
2109 space
= isl_space_from_domain(space
);
2110 space
= isl_space_set_tuple_id(space
, isl_dim_out
, id
);
2111 add_tag
= isl_multi_aff_domain_map(space
);
2112 access
= isl_union_map_preimage_domain_multi_aff(access
, add_tag
);
2117 /* Return the access relation of the given "type" associated to "expr"
2118 * that maps pairs of domain iterations and argument values
2119 * to the corresponding accessed data elements.
2121 * If the requested access relation is explicitly available,
2122 * then return a copy. Otherwise, check if it is irrelevant for
2123 * the access expression and return an empty relation if this is the case.
2124 * Otherwise, introduce the requested access relation in "expr" and
2127 __isl_give isl_union_map
*pet_expr_access_get_dependent_access(
2128 __isl_keep pet_expr
*expr
, enum pet_expr_access_type type
)
2130 isl_union_map
*access
;
2135 if (expr
->type
!= pet_expr_access
)
2136 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2137 "not an access expression", return NULL
);
2139 type
= internalize_type(type
);
2140 if (expr
->acc
.access
[type
])
2141 return isl_union_map_copy(expr
->acc
.access
[type
]);
2143 if (type
== pet_expr_access_may_read
)
2144 empty
= !expr
->acc
.read
;
2146 empty
= !expr
->acc
.write
;
2149 expr
= pet_expr_copy(expr
);
2150 expr
= introduce_access_relations(expr
);
2153 access
= isl_union_map_copy(expr
->acc
.access
[type
]);
2154 pet_expr_free(expr
);
2159 return isl_union_map_empty(pet_expr_access_get_parameter_space(expr
));
2162 /* Return the may read access relation associated to "expr"
2163 * that maps pairs of domain iterations and argument values
2164 * to the corresponding accessed data elements.
2166 __isl_give isl_union_map
*pet_expr_access_get_dependent_may_read(
2167 __isl_keep pet_expr
*expr
)
2169 return pet_expr_access_get_dependent_access(expr
,
2170 pet_expr_access_may_read
);
2173 /* Return the may write access relation associated to "expr"
2174 * that maps pairs of domain iterations and argument values
2175 * to the corresponding accessed data elements.
2177 __isl_give isl_union_map
*pet_expr_access_get_dependent_may_write(
2178 __isl_keep pet_expr
*expr
)
2180 return pet_expr_access_get_dependent_access(expr
,
2181 pet_expr_access_may_write
);
2184 /* Return the must write access relation associated to "expr"
2185 * that maps pairs of domain iterations and argument values
2186 * to the corresponding accessed data elements.
2188 __isl_give isl_union_map
*pet_expr_access_get_dependent_must_write(
2189 __isl_keep pet_expr
*expr
)
2191 return pet_expr_access_get_dependent_access(expr
,
2192 pet_expr_access_must_write
);
2195 /* Return the relation of the given "type" mapping domain iterations
2196 * to the accessed data elements.
2197 * In particular, take the access relation and, in case of may_read
2198 * or may_write, project out the values of the arguments, if any.
2199 * In case of must_write, return the empty relation if there are
2202 __isl_give isl_union_map
*pet_expr_access_get_access(__isl_keep pet_expr
*expr
,
2203 enum pet_expr_access_type type
)
2205 isl_union_map
*access
;
2211 if (expr
->type
!= pet_expr_access
)
2212 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2213 "not an access expression", return NULL
);
2215 if (expr
->n_arg
!= 0 && type
== pet_expr_access_must_write
) {
2216 space
= pet_expr_access_get_parameter_space(expr
);
2217 return isl_union_map_empty(space
);
2220 access
= pet_expr_access_get_dependent_access(expr
, type
);
2221 if (expr
->n_arg
== 0)
2224 space
= isl_multi_pw_aff_get_space(expr
->acc
.index
);
2225 space
= isl_space_domain(space
);
2226 map
= isl_map_universe(isl_space_unwrap(space
));
2227 map
= isl_map_domain_map(map
);
2228 access
= isl_union_map_apply_domain(access
,
2229 isl_union_map_from_map(map
));
2234 /* Return the relation mapping domain iterations to all possibly
2235 * read data elements.
2237 __isl_give isl_union_map
*pet_expr_access_get_may_read(
2238 __isl_keep pet_expr
*expr
)
2240 return pet_expr_access_get_access(expr
, pet_expr_access_may_read
);
2243 /* Return the relation mapping domain iterations to all possibly
2244 * written data elements.
2246 __isl_give isl_union_map
*pet_expr_access_get_may_write(
2247 __isl_keep pet_expr
*expr
)
2249 return pet_expr_access_get_access(expr
, pet_expr_access_may_write
);
2252 /* Return a relation mapping domain iterations to definitely
2253 * written data elements, assuming the statement containing
2254 * the expression is executed.
2256 __isl_give isl_union_map
*pet_expr_access_get_must_write(
2257 __isl_keep pet_expr
*expr
)
2259 return pet_expr_access_get_access(expr
, pet_expr_access_must_write
);
2262 /* Return the relation of the given "type" mapping domain iterations to
2263 * accessed data elements, with its domain tagged with the reference
2266 static __isl_give isl_union_map
*pet_expr_access_get_tagged_access(
2267 __isl_keep pet_expr
*expr
, enum pet_expr_access_type type
)
2269 isl_union_map
*access
;
2274 access
= pet_expr_access_get_access(expr
, type
);
2275 access
= pet_expr_tag_access(expr
, access
);
2280 /* Return the relation mapping domain iterations to all possibly
2281 * read data elements, with its domain tagged with the reference
2284 __isl_give isl_union_map
*pet_expr_access_get_tagged_may_read(
2285 __isl_keep pet_expr
*expr
)
2287 return pet_expr_access_get_tagged_access(expr
,
2288 pet_expr_access_may_read
);
2291 /* Return the relation mapping domain iterations to all possibly
2292 * written data elements, with its domain tagged with the reference
2295 __isl_give isl_union_map
*pet_expr_access_get_tagged_may_write(
2296 __isl_keep pet_expr
*expr
)
2298 return pet_expr_access_get_tagged_access(expr
,
2299 pet_expr_access_may_write
);
2302 /* Return the operation type of operation expression "expr".
2304 enum pet_op_type
pet_expr_op_get_type(__isl_keep pet_expr
*expr
)
2308 if (expr
->type
!= pet_expr_op
)
2309 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2310 "not an operation expression", return pet_op_last
);
2315 /* Replace the operation type of operation expression "expr" by "type".
2317 __isl_give pet_expr
*pet_expr_op_set_type(__isl_take pet_expr
*expr
,
2318 enum pet_op_type type
)
2321 return pet_expr_free(expr
);
2322 if (expr
->type
!= pet_expr_op
)
2323 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2324 "not an operation expression",
2325 return pet_expr_free(expr
));
2326 if (expr
->op
== type
)
2328 expr
= pet_expr_cow(expr
);
2336 /* Return the name of the function called by "expr".
2338 __isl_keep
const char *pet_expr_call_get_name(__isl_keep pet_expr
*expr
)
2342 if (expr
->type
!= pet_expr_call
)
2343 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2344 "not a call expression", return NULL
);
2348 /* Replace the name of the function called by "expr" by "name".
2350 __isl_give pet_expr
*pet_expr_call_set_name(__isl_take pet_expr
*expr
,
2351 __isl_keep
const char *name
)
2353 expr
= pet_expr_cow(expr
);
2355 return pet_expr_free(expr
);
2356 if (expr
->type
!= pet_expr_call
)
2357 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2358 "not a call expression", return pet_expr_free(expr
));
2360 expr
->name
= strdup(name
);
2362 return pet_expr_free(expr
);
2366 /* Replace the type of the cast performed by "expr" by "name".
2368 __isl_give pet_expr
*pet_expr_cast_set_type_name(__isl_take pet_expr
*expr
,
2369 __isl_keep
const char *name
)
2371 expr
= pet_expr_cow(expr
);
2373 return pet_expr_free(expr
);
2374 if (expr
->type
!= pet_expr_cast
)
2375 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2376 "not a cast expression", return pet_expr_free(expr
));
2377 free(expr
->type_name
);
2378 expr
->type_name
= strdup(name
);
2379 if (!expr
->type_name
)
2380 return pet_expr_free(expr
);
2384 /* Return the value of the integer represented by "expr".
2386 __isl_give isl_val
*pet_expr_int_get_val(__isl_keep pet_expr
*expr
)
2390 if (expr
->type
!= pet_expr_int
)
2391 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2392 "not an int expression", return NULL
);
2394 return isl_val_copy(expr
->i
);
2397 /* Replace the value of the integer represented by "expr" by "v".
2399 __isl_give pet_expr
*pet_expr_int_set_val(__isl_take pet_expr
*expr
,
2400 __isl_take isl_val
*v
)
2402 expr
= pet_expr_cow(expr
);
2405 if (expr
->type
!= pet_expr_int
)
2406 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2407 "not an int expression", goto error
);
2408 isl_val_free(expr
->i
);
2414 pet_expr_free(expr
);
2418 /* Replace the value and string representation of the double
2419 * represented by "expr" by "d" and "s".
2421 __isl_give pet_expr
*pet_expr_double_set(__isl_take pet_expr
*expr
,
2422 double d
, __isl_keep
const char *s
)
2424 expr
= pet_expr_cow(expr
);
2426 return pet_expr_free(expr
);
2427 if (expr
->type
!= pet_expr_double
)
2428 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2429 "not a double expression", return pet_expr_free(expr
));
2432 expr
->d
.s
= strdup(s
);
2434 return pet_expr_free(expr
);
2438 /* Return a string representation of the double expression "expr".
2440 __isl_give
char *pet_expr_double_get_str(__isl_keep pet_expr
*expr
)
2444 if (expr
->type
!= pet_expr_double
)
2445 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2446 "not a double expression", return NULL
);
2447 return strdup(expr
->d
.s
);
2450 /* Return a piecewise affine expression defined on the specified domain
2451 * that represents NaN.
2453 static __isl_give isl_pw_aff
*non_affine(__isl_take isl_space
*space
)
2455 return isl_pw_aff_nan_on_domain(isl_local_space_from_space(space
));
2458 /* This function is called when we come across an access that is
2459 * nested in what is supposed to be an affine expression.
2460 * "pc" is the context in which the affine expression is created.
2461 * If nesting is allowed in "pc", we return an affine expression that is
2462 * equal to a new parameter corresponding to this nested access.
2463 * Otherwise, we return NaN.
2465 * Note that we currently don't allow nested accesses themselves
2466 * to contain any nested accesses, so we check if "expr" itself
2467 * involves any nested accesses (either explicitly as arguments
2468 * or implicitly through parameters) and return NaN if it does.
2470 * The new parameter is resolved in resolve_nested.
2472 static __isl_give isl_pw_aff
*nested_access(__isl_keep pet_expr
*expr
,
2473 __isl_keep pet_context
*pc
)
2478 isl_local_space
*ls
;
2484 if (!pet_context_allow_nesting(pc
))
2485 return non_affine(pet_context_get_space(pc
));
2487 if (pet_expr_get_type(expr
) != pet_expr_access
)
2488 isl_die(pet_expr_get_ctx(expr
), isl_error_internal
,
2489 "not an access expression", return NULL
);
2491 if (expr
->n_arg
> 0)
2492 return non_affine(pet_context_get_space(pc
));
2494 space
= pet_expr_access_get_parameter_space(expr
);
2495 nested
= pet_nested_any_in_space(space
);
2496 isl_space_free(space
);
2498 return non_affine(pet_context_get_space(pc
));
2500 ctx
= pet_expr_get_ctx(expr
);
2501 id
= pet_nested_pet_expr(pet_expr_copy(expr
));
2502 space
= pet_context_get_space(pc
);
2503 space
= isl_space_insert_dims(space
, isl_dim_param
, 0, 1);
2505 space
= isl_space_set_dim_id(space
, isl_dim_param
, 0, id
);
2506 ls
= isl_local_space_from_space(space
);
2507 aff
= isl_aff_var_on_domain(ls
, isl_dim_param
, 0);
2509 return isl_pw_aff_from_aff(aff
);
2512 /* Extract an affine expression from the access pet_expr "expr".
2513 * "pc" is the context in which the affine expression is created.
2515 * If "expr" is actually an affine expression rather than
2516 * a real access, then we return that expression.
2517 * Otherwise, we require that "expr" is of an integral type.
2518 * If not, we return NaN.
2520 * If the variable has been assigned a known affine expression,
2521 * then we return that expression.
2523 * Otherwise, we return an expression that is equal to a parameter
2524 * representing "expr" (if "allow_nested" is set).
2526 static __isl_give isl_pw_aff
*extract_affine_from_access(
2527 __isl_keep pet_expr
*expr
, __isl_keep pet_context
*pc
)
2532 if (pet_expr_is_affine(expr
)) {
2534 isl_multi_pw_aff
*mpa
;
2536 mpa
= pet_expr_access_get_index(expr
);
2537 pa
= isl_multi_pw_aff_get_pw_aff(mpa
, 0);
2538 isl_multi_pw_aff_free(mpa
);
2542 if (pet_expr_get_type_size(expr
) == 0)
2543 return non_affine(pet_context_get_space(pc
));
2545 if (!pet_expr_is_scalar_access(expr
))
2546 return nested_access(expr
, pc
);
2548 id
= pet_expr_access_get_id(expr
);
2549 if (pet_context_is_assigned(pc
, id
))
2550 return pet_context_get_value(pc
, id
);
2553 return nested_access(expr
, pc
);
2556 /* Construct an affine expression from the integer constant "expr".
2557 * "pc" is the context in which the affine expression is created.
2559 static __isl_give isl_pw_aff
*extract_affine_from_int(__isl_keep pet_expr
*expr
,
2560 __isl_keep pet_context
*pc
)
2562 isl_local_space
*ls
;
2568 ls
= isl_local_space_from_space(pet_context_get_space(pc
));
2569 aff
= isl_aff_val_on_domain(ls
, pet_expr_int_get_val(expr
));
2571 return isl_pw_aff_from_aff(aff
);
2574 /* Extract an affine expression from an addition or subtraction operation.
2575 * Return NaN if we are unable to extract an affine expression.
2577 * "pc" is the context in which the affine expression is created.
2579 static __isl_give isl_pw_aff
*extract_affine_add_sub(__isl_keep pet_expr
*expr
,
2580 __isl_keep pet_context
*pc
)
2587 if (expr
->n_arg
!= 2)
2588 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2589 "expecting two arguments", return NULL
);
2591 lhs
= pet_expr_extract_affine(expr
->args
[0], pc
);
2592 rhs
= pet_expr_extract_affine(expr
->args
[1], pc
);
2594 switch (pet_expr_op_get_type(expr
)) {
2596 return isl_pw_aff_add(lhs
, rhs
);
2598 return isl_pw_aff_sub(lhs
, rhs
);
2600 isl_pw_aff_free(lhs
);
2601 isl_pw_aff_free(rhs
);
2602 isl_die(pet_expr_get_ctx(expr
), isl_error_internal
,
2603 "not an addition or subtraction operation",
2609 /* Extract an affine expression from an integer division or a modulo operation.
2610 * Return NaN if we are unable to extract an affine expression.
2612 * "pc" is the context in which the affine expression is created.
2614 * In particular, if "expr" is lhs/rhs, then return
2616 * lhs >= 0 ? floor(lhs/rhs) : ceil(lhs/rhs)
2618 * If "expr" is lhs%rhs, then return
2620 * lhs - rhs * (lhs >= 0 ? floor(lhs/rhs) : ceil(lhs/rhs))
2622 * If the second argument (rhs) is not a (positive) integer constant,
2623 * then we fail to extract an affine expression.
2625 * We simplify the result in the context of the domain of "pc" in case
2626 * this domain implies that lhs >= 0 (or < 0).
2628 static __isl_give isl_pw_aff
*extract_affine_div_mod(__isl_keep pet_expr
*expr
,
2629 __isl_keep pet_context
*pc
)
2638 if (expr
->n_arg
!= 2)
2639 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2640 "expecting two arguments", return NULL
);
2642 rhs
= pet_expr_extract_affine(expr
->args
[1], pc
);
2644 is_cst
= isl_pw_aff_is_cst(rhs
);
2645 if (is_cst
< 0 || !is_cst
) {
2646 isl_pw_aff_free(rhs
);
2647 return non_affine(pet_context_get_space(pc
));
2650 lhs
= pet_expr_extract_affine(expr
->args
[0], pc
);
2652 switch (pet_expr_op_get_type(expr
)) {
2654 res
= isl_pw_aff_tdiv_q(lhs
, rhs
);
2657 res
= isl_pw_aff_tdiv_r(lhs
, rhs
);
2660 isl_pw_aff_free(lhs
);
2661 isl_pw_aff_free(rhs
);
2662 isl_die(pet_expr_get_ctx(expr
), isl_error_internal
,
2663 "not a div or mod operator", return NULL
);
2666 return isl_pw_aff_gist(res
, pet_context_get_gist_domain(pc
));
2669 /* Extract an affine expression from a multiplication operation.
2670 * Return NaN if we are unable to extract an affine expression.
2671 * In particular, if neither of the arguments is a (piecewise) constant
2672 * then we return NaN.
2674 * "pc" is the context in which the affine expression is created.
2676 static __isl_give isl_pw_aff
*extract_affine_mul(__isl_keep pet_expr
*expr
,
2677 __isl_keep pet_context
*pc
)
2679 int lhs_cst
, rhs_cst
;
2685 if (expr
->n_arg
!= 2)
2686 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2687 "expecting two arguments", return NULL
);
2689 lhs
= pet_expr_extract_affine(expr
->args
[0], pc
);
2690 rhs
= pet_expr_extract_affine(expr
->args
[1], pc
);
2692 lhs_cst
= isl_pw_aff_is_cst(lhs
);
2693 rhs_cst
= isl_pw_aff_is_cst(rhs
);
2694 if (lhs_cst
< 0 || rhs_cst
< 0 || (!lhs_cst
&& !rhs_cst
)) {
2695 isl_pw_aff_free(lhs
);
2696 isl_pw_aff_free(rhs
);
2697 return non_affine(pet_context_get_space(pc
));
2700 return isl_pw_aff_mul(lhs
, rhs
);
2703 /* Extract an affine expression from a negation operation.
2704 * Return NaN if we are unable to extract an affine expression.
2706 * "pc" is the context in which the affine expression is created.
2708 static __isl_give isl_pw_aff
*extract_affine_neg(__isl_keep pet_expr
*expr
,
2709 __isl_keep pet_context
*pc
)
2715 if (expr
->n_arg
!= 1)
2716 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2717 "expecting one argument", return NULL
);
2719 res
= pet_expr_extract_affine(expr
->args
[0], pc
);
2720 return isl_pw_aff_neg(res
);
2723 /* Extract an affine expression from a conditional operation.
2724 * Return NaN if we are unable to extract an affine expression.
2726 * "pc" is the context in which the affine expression is created.
2728 static __isl_give isl_pw_aff
*extract_affine_cond(__isl_keep pet_expr
*expr
,
2729 __isl_keep pet_context
*pc
)
2731 isl_pw_aff
*cond
, *lhs
, *rhs
;
2735 if (expr
->n_arg
!= 3)
2736 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
2737 "expecting three arguments", return NULL
);
2739 cond
= pet_expr_extract_affine_condition(expr
->args
[0], pc
);
2740 lhs
= pet_expr_extract_affine(expr
->args
[1], pc
);
2741 rhs
= pet_expr_extract_affine(expr
->args
[2], pc
);
2743 return isl_pw_aff_cond(cond
, lhs
, rhs
);
2750 static __isl_give isl_pw_aff
*wrap(__isl_take isl_pw_aff
*pwaff
, unsigned width
)
2755 ctx
= isl_pw_aff_get_ctx(pwaff
);
2756 mod
= isl_val_int_from_ui(ctx
, width
);
2757 mod
= isl_val_2exp(mod
);
2759 pwaff
= isl_pw_aff_mod_val(pwaff
, mod
);
2764 /* Limit the domain of "pwaff" to those elements where the function
2767 * 2^{width-1} <= pwaff < 2^{width-1}
2769 static __isl_give isl_pw_aff
*avoid_overflow(__isl_take isl_pw_aff
*pwaff
,
2774 isl_space
*space
= isl_pw_aff_get_domain_space(pwaff
);
2775 isl_local_space
*ls
= isl_local_space_from_space(space
);
2780 ctx
= isl_pw_aff_get_ctx(pwaff
);
2781 v
= isl_val_int_from_ui(ctx
, width
- 1);
2782 v
= isl_val_2exp(v
);
2784 bound
= isl_aff_zero_on_domain(ls
);
2785 bound
= isl_aff_add_constant_val(bound
, v
);
2786 b
= isl_pw_aff_from_aff(bound
);
2788 dom
= isl_pw_aff_lt_set(isl_pw_aff_copy(pwaff
), isl_pw_aff_copy(b
));
2789 pwaff
= isl_pw_aff_intersect_domain(pwaff
, dom
);
2791 b
= isl_pw_aff_neg(b
);
2792 dom
= isl_pw_aff_ge_set(isl_pw_aff_copy(pwaff
), b
);
2793 pwaff
= isl_pw_aff_intersect_domain(pwaff
, dom
);
2798 /* Handle potential overflows on signed computations.
2800 * If options->signed_overflow is set to PET_OVERFLOW_AVOID,
2801 * then we adjust the domain of "pa" to avoid overflows.
2803 static __isl_give isl_pw_aff
*signed_overflow(__isl_take isl_pw_aff
*pa
,
2807 struct pet_options
*options
;
2812 ctx
= isl_pw_aff_get_ctx(pa
);
2813 options
= isl_ctx_peek_pet_options(ctx
);
2814 if (!options
|| options
->signed_overflow
== PET_OVERFLOW_AVOID
)
2815 pa
= avoid_overflow(pa
, width
);
2820 /* Extract an affine expression from some an operation.
2821 * Return NaN if we are unable to extract an affine expression.
2822 * If the result of a binary (non boolean) operation is unsigned,
2823 * then we wrap it based on the size of the type. If the result is signed,
2824 * then we ensure that no overflow occurs.
2826 * "pc" is the context in which the affine expression is created.
2828 static __isl_give isl_pw_aff
*extract_affine_from_op(__isl_keep pet_expr
*expr
,
2829 __isl_keep pet_context
*pc
)
2834 switch (pet_expr_op_get_type(expr
)) {
2837 res
= extract_affine_add_sub(expr
, pc
);
2841 res
= extract_affine_div_mod(expr
, pc
);
2844 res
= extract_affine_mul(expr
, pc
);
2847 return extract_affine_neg(expr
, pc
);
2849 return extract_affine_cond(expr
, pc
);
2859 return pet_expr_extract_affine_condition(expr
, pc
);
2861 return non_affine(pet_context_get_space(pc
));
2866 if (isl_pw_aff_involves_nan(res
)) {
2867 isl_space
*space
= isl_pw_aff_get_domain_space(res
);
2868 isl_pw_aff_free(res
);
2869 return non_affine(space
);
2872 type_size
= pet_expr_get_type_size(expr
);
2874 res
= wrap(res
, type_size
);
2876 res
= signed_overflow(res
, -type_size
);
2881 /* Extract an affine expression from some special function calls.
2882 * Return NaN if we are unable to extract an affine expression.
2883 * In particular, we handle "min", "max", "ceild", "floord",
2884 * "intMod", "intFloor" and "intCeil".
2885 * In case of the latter five, the second argument needs to be
2886 * a (positive) integer constant.
2888 * "pc" is the context in which the affine expression is created.
2890 static __isl_give isl_pw_aff
*extract_affine_from_call(
2891 __isl_keep pet_expr
*expr
, __isl_keep pet_context
*pc
)
2893 isl_pw_aff
*aff1
, *aff2
;
2897 n
= pet_expr_get_n_arg(expr
);
2898 name
= pet_expr_call_get_name(expr
);
2899 if (!(n
== 2 && !strcmp(name
, "min")) &&
2900 !(n
== 2 && !strcmp(name
, "max")) &&
2901 !(n
== 2 && !strcmp(name
, "intMod")) &&
2902 !(n
== 2 && !strcmp(name
, "intFloor")) &&
2903 !(n
== 2 && !strcmp(name
, "intCeil")) &&
2904 !(n
== 2 && !strcmp(name
, "floord")) &&
2905 !(n
== 2 && !strcmp(name
, "ceild")))
2906 return non_affine(pet_context_get_space(pc
));
2908 if (!strcmp(name
, "min") || !strcmp(name
, "max")) {
2909 aff1
= pet_expr_extract_affine(expr
->args
[0], pc
);
2910 aff2
= pet_expr_extract_affine(expr
->args
[1], pc
);
2912 if (!strcmp(name
, "min"))
2913 aff1
= isl_pw_aff_min(aff1
, aff2
);
2915 aff1
= isl_pw_aff_max(aff1
, aff2
);
2916 } else if (!strcmp(name
, "intMod")) {
2919 if (pet_expr_get_type(expr
->args
[1]) != pet_expr_int
)
2920 return non_affine(pet_context_get_space(pc
));
2921 v
= pet_expr_int_get_val(expr
->args
[1]);
2922 aff1
= pet_expr_extract_affine(expr
->args
[0], pc
);
2923 aff1
= isl_pw_aff_mod_val(aff1
, v
);
2927 if (pet_expr_get_type(expr
->args
[1]) != pet_expr_int
)
2928 return non_affine(pet_context_get_space(pc
));
2929 v
= pet_expr_int_get_val(expr
->args
[1]);
2930 aff1
= pet_expr_extract_affine(expr
->args
[0], pc
);
2931 aff1
= isl_pw_aff_scale_down_val(aff1
, v
);
2932 if (!strcmp(name
, "floord") || !strcmp(name
, "intFloor"))
2933 aff1
= isl_pw_aff_floor(aff1
);
2935 aff1
= isl_pw_aff_ceil(aff1
);
2941 /* Extract an affine expression from "expr", if possible.
2942 * Otherwise return NaN.
2944 * "pc" is the context in which the affine expression is created.
2946 __isl_give isl_pw_aff
*pet_expr_extract_affine(__isl_keep pet_expr
*expr
,
2947 __isl_keep pet_context
*pc
)
2952 switch (pet_expr_get_type(expr
)) {
2953 case pet_expr_access
:
2954 return extract_affine_from_access(expr
, pc
);
2956 return extract_affine_from_int(expr
, pc
);
2958 return extract_affine_from_op(expr
, pc
);
2960 return extract_affine_from_call(expr
, pc
);
2962 case pet_expr_double
:
2963 case pet_expr_error
:
2964 return non_affine(pet_context_get_space(pc
));
2968 /* Extract an affine expressions representing the comparison "LHS op RHS"
2969 * Return NaN if we are unable to extract such an affine expression.
2971 * "pc" is the context in which the affine expression is created.
2973 * If the comparison is of the form
2977 * then the expression is constructed as the conjunction of
2982 * A similar optimization is performed for max(a,b) <= c.
2983 * We do this because that will lead to simpler representations
2984 * of the expression.
2985 * If isl is ever enhanced to explicitly deal with min and max expressions,
2986 * this optimization can be removed.
2988 __isl_give isl_pw_aff
*pet_expr_extract_comparison(enum pet_op_type op
,
2989 __isl_keep pet_expr
*lhs
, __isl_keep pet_expr
*rhs
,
2990 __isl_keep pet_context
*pc
)
2992 isl_pw_aff
*lhs_pa
, *rhs_pa
;
2994 if (op
== pet_op_gt
)
2995 return pet_expr_extract_comparison(pet_op_lt
, rhs
, lhs
, pc
);
2996 if (op
== pet_op_ge
)
2997 return pet_expr_extract_comparison(pet_op_le
, rhs
, lhs
, pc
);
2999 if (op
== pet_op_lt
|| op
== pet_op_le
) {
3000 if (pet_expr_is_min(rhs
)) {
3001 lhs_pa
= pet_expr_extract_comparison(op
, lhs
,
3003 rhs_pa
= pet_expr_extract_comparison(op
, lhs
,
3005 return pet_and(lhs_pa
, rhs_pa
);
3007 if (pet_expr_is_max(lhs
)) {
3008 lhs_pa
= pet_expr_extract_comparison(op
, lhs
->args
[0],
3010 rhs_pa
= pet_expr_extract_comparison(op
, lhs
->args
[1],
3012 return pet_and(lhs_pa
, rhs_pa
);
3016 lhs_pa
= pet_expr_extract_affine(lhs
, pc
);
3017 rhs_pa
= pet_expr_extract_affine(rhs
, pc
);
3019 return pet_comparison(op
, lhs_pa
, rhs_pa
);
3022 /* Extract an affine expressions from the comparison "expr".
3023 * Return NaN if we are unable to extract such an affine expression.
3025 * "pc" is the context in which the affine expression is created.
3027 static __isl_give isl_pw_aff
*extract_comparison(__isl_keep pet_expr
*expr
,
3028 __isl_keep pet_context
*pc
)
3030 enum pet_op_type type
;
3034 if (expr
->n_arg
!= 2)
3035 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
3036 "expecting two arguments", return NULL
);
3038 type
= pet_expr_op_get_type(expr
);
3039 return pet_expr_extract_comparison(type
, expr
->args
[0], expr
->args
[1],
3043 /* Extract an affine expression representing the boolean operation
3044 * expressed by "expr".
3045 * Return NaN if we are unable to extract an affine expression.
3047 * "pc" is the context in which the affine expression is created.
3049 static __isl_give isl_pw_aff
*extract_boolean(__isl_keep pet_expr
*expr
,
3050 __isl_keep pet_context
*pc
)
3052 isl_pw_aff
*lhs
, *rhs
;
3058 n
= pet_expr_get_n_arg(expr
);
3059 lhs
= pet_expr_extract_affine_condition(expr
->args
[0], pc
);
3061 return pet_not(lhs
);
3063 rhs
= pet_expr_extract_affine_condition(expr
->args
[1], pc
);
3064 return pet_boolean(pet_expr_op_get_type(expr
), lhs
, rhs
);
3067 /* Extract the affine expression "expr != 0 ? 1 : 0".
3068 * Return NaN if we are unable to extract an affine expression.
3070 * "pc" is the context in which the affine expression is created.
3072 static __isl_give isl_pw_aff
*extract_implicit_condition(
3073 __isl_keep pet_expr
*expr
, __isl_keep pet_context
*pc
)
3077 res
= pet_expr_extract_affine(expr
, pc
);
3078 return pet_to_bool(res
);
3081 /* Extract a boolean affine expression from "expr".
3082 * Return NaN if we are unable to extract an affine expression.
3084 * "pc" is the context in which the affine expression is created.
3086 * If "expr" is neither a comparison nor a boolean operation,
3087 * then we assume it is an affine expression and return the
3088 * boolean expression "expr != 0 ? 1 : 0".
3090 __isl_give isl_pw_aff
*pet_expr_extract_affine_condition(
3091 __isl_keep pet_expr
*expr
, __isl_keep pet_context
*pc
)
3096 if (pet_expr_is_comparison(expr
))
3097 return extract_comparison(expr
, pc
);
3098 if (pet_expr_is_boolean(expr
))
3099 return extract_boolean(expr
, pc
);
3101 return extract_implicit_condition(expr
, pc
);
3104 /* Check if "expr" is an assume expression and if its single argument
3105 * can be converted to an affine expression in the context of "pc".
3106 * If so, replace the argument by the affine expression.
3108 __isl_give pet_expr
*pet_expr_resolve_assume(__isl_take pet_expr
*expr
,
3109 __isl_keep pet_context
*pc
)
3112 isl_multi_pw_aff
*index
;
3116 if (!pet_expr_is_assume(expr
))
3118 if (expr
->n_arg
!= 1)
3119 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
3120 "expecting one argument", return pet_expr_free(expr
));
3122 cond
= pet_expr_extract_affine_condition(expr
->args
[0], pc
);
3124 return pet_expr_free(expr
);
3125 if (isl_pw_aff_involves_nan(cond
)) {
3126 isl_pw_aff_free(cond
);
3130 index
= isl_multi_pw_aff_from_pw_aff(cond
);
3131 expr
= pet_expr_set_arg(expr
, 0, pet_expr_from_index(index
));
3136 /* Return the number of bits needed to represent the type of "expr".
3137 * See the description of the type_size field of pet_expr.
3139 int pet_expr_get_type_size(__isl_keep pet_expr
*expr
)
3141 return expr
? expr
->type_size
: 0;
3144 /* Replace the number of bits needed to represent the type of "expr"
3146 * See the description of the type_size field of pet_expr.
3148 __isl_give pet_expr
*pet_expr_set_type_size(__isl_take pet_expr
*expr
,
3151 expr
= pet_expr_cow(expr
);
3155 expr
->type_size
= type_size
;
3160 /* Extend an access expression "expr" with an additional index "index".
3161 * In particular, add "index" as an extra argument to "expr" and
3162 * adjust the index expression of "expr" to refer to this extra argument.
3163 * The caller is responsible for calling pet_expr_access_set_depth
3164 * to update the corresponding access relation.
3166 * Note that we only collect the individual index expressions as
3167 * arguments of "expr" here.
3168 * An attempt to integrate them into the index expression of "expr"
3169 * is performed in pet_expr_access_plug_in_args.
3171 __isl_give pet_expr
*pet_expr_access_subscript(__isl_take pet_expr
*expr
,
3172 __isl_take pet_expr
*index
)
3176 isl_local_space
*ls
;
3179 expr
= pet_expr_cow(expr
);
3180 if (!expr
|| !index
)
3182 if (expr
->type
!= pet_expr_access
)
3183 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
3184 "not an access pet_expr", goto error
);
3186 n
= pet_expr_get_n_arg(expr
);
3187 expr
= pet_expr_insert_arg(expr
, n
, index
);
3191 space
= isl_multi_pw_aff_get_domain_space(expr
->acc
.index
);
3192 ls
= isl_local_space_from_space(space
);
3193 pa
= isl_pw_aff_from_aff(isl_aff_var_on_domain(ls
, isl_dim_set
, n
));
3194 expr
->acc
.index
= pet_array_subscript(expr
->acc
.index
, pa
);
3195 if (!expr
->acc
.index
)
3196 return pet_expr_free(expr
);
3200 pet_expr_free(expr
);
3201 pet_expr_free(index
);
3205 /* Extend an access expression "expr" with an additional member acces to "id".
3206 * In particular, extend the index expression of "expr" to include
3207 * the additional member access.
3208 * The caller is responsible for calling pet_expr_access_set_depth
3209 * to update the corresponding access relation.
3211 __isl_give pet_expr
*pet_expr_access_member(__isl_take pet_expr
*expr
,
3212 __isl_take isl_id
*id
)
3215 isl_multi_pw_aff
*field_access
;
3217 expr
= pet_expr_cow(expr
);
3220 if (expr
->type
!= pet_expr_access
)
3221 isl_die(pet_expr_get_ctx(expr
), isl_error_invalid
,
3222 "not an access pet_expr", goto error
);
3224 space
= isl_multi_pw_aff_get_domain_space(expr
->acc
.index
);
3225 space
= isl_space_from_domain(space
);
3226 space
= isl_space_set_tuple_id(space
, isl_dim_out
, id
);
3227 field_access
= isl_multi_pw_aff_zero(space
);
3228 expr
->acc
.index
= pet_array_member(expr
->acc
.index
, field_access
);
3229 if (!expr
->acc
.index
)
3230 return pet_expr_free(expr
);
3234 pet_expr_free(expr
);
3239 void pet_expr_dump_with_indent(__isl_keep pet_expr
*expr
, int indent
)
3246 fprintf(stderr
, "%*s", indent
, "");
3248 switch (expr
->type
) {
3249 case pet_expr_double
:
3250 fprintf(stderr
, "%s\n", expr
->d
.s
);
3253 isl_val_dump(expr
->i
);
3255 case pet_expr_access
:
3256 if (expr
->acc
.ref_id
) {
3257 isl_id_dump(expr
->acc
.ref_id
);
3258 fprintf(stderr
, "%*s", indent
, "");
3260 isl_multi_pw_aff_dump(expr
->acc
.index
);
3261 fprintf(stderr
, "%*sdepth: %d\n", indent
+ 2,
3262 "", expr
->acc
.depth
);
3263 if (expr
->acc
.kill
) {
3264 fprintf(stderr
, "%*skill: 1\n", indent
+ 2, "");
3266 fprintf(stderr
, "%*sread: %d\n", indent
+ 2,
3267 "", expr
->acc
.read
);
3268 fprintf(stderr
, "%*swrite: %d\n", indent
+ 2,
3269 "", expr
->acc
.write
);
3271 if (expr
->acc
.access
[pet_expr_access_may_read
]) {
3272 fprintf(stderr
, "%*smay_read: ", indent
+ 2, "");
3274 expr
->acc
.access
[pet_expr_access_may_read
]);
3276 if (expr
->acc
.access
[pet_expr_access_may_write
]) {
3277 fprintf(stderr
, "%*smay_write: ", indent
+ 2, "");
3279 expr
->acc
.access
[pet_expr_access_may_write
]);
3281 if (expr
->acc
.access
[pet_expr_access_must_write
]) {
3282 fprintf(stderr
, "%*smust_write: ", indent
+ 2, "");
3284 expr
->acc
.access
[pet_expr_access_must_write
]);
3286 for (i
= 0; i
< expr
->n_arg
; ++i
)
3287 pet_expr_dump_with_indent(expr
->args
[i
], indent
+ 2);
3290 fprintf(stderr
, "%s\n", op_str
[expr
->op
]);
3291 for (i
= 0; i
< expr
->n_arg
; ++i
)
3292 pet_expr_dump_with_indent(expr
->args
[i
], indent
+ 2);
3295 fprintf(stderr
, "%s/%d\n", expr
->name
, expr
->n_arg
);
3296 for (i
= 0; i
< expr
->n_arg
; ++i
)
3297 pet_expr_dump_with_indent(expr
->args
[i
], indent
+ 2);
3300 fprintf(stderr
, "(%s)\n", expr
->type_name
);
3301 for (i
= 0; i
< expr
->n_arg
; ++i
)
3302 pet_expr_dump_with_indent(expr
->args
[i
], indent
+ 2);
3304 case pet_expr_error
:
3305 fprintf(stderr
, "ERROR\n");
3310 void pet_expr_dump(__isl_keep pet_expr
*expr
)
3312 pet_expr_dump_with_indent(expr
, 0);