2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2012 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
35 #include <isl/constraint.h>
36 #include <isl/union_set.h>
40 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
42 static char *type_str
[] = {
43 [pet_expr_access
] = "access",
44 [pet_expr_call
] = "call",
45 [pet_expr_double
] = "double",
46 [pet_expr_unary
] = "unary",
47 [pet_expr_binary
] = "binary",
48 [pet_expr_ternary
] = "ternary"
51 static char *op_str
[] = {
52 [pet_op_add_assign
] = "+=",
53 [pet_op_sub_assign
] = "-=",
54 [pet_op_mul_assign
] = "*=",
55 [pet_op_div_assign
] = "/=",
56 [pet_op_assign
] = "=",
66 [pet_op_address_of
] = "&"
69 const char *pet_op_str(enum pet_op_type op
)
74 const char *pet_type_str(enum pet_expr_type type
)
76 return type_str
[type
];
79 enum pet_op_type
pet_str_op(const char *str
)
83 for (i
= 0; i
< ARRAY_SIZE(op_str
); ++i
)
84 if (!strcmp(op_str
[i
], str
))
90 enum pet_expr_type
pet_str_type(const char *str
)
94 for (i
= 0; i
< ARRAY_SIZE(type_str
); ++i
)
95 if (!strcmp(type_str
[i
], str
))
101 /* Construct a pet_expr from an access relation.
102 * By default, it is considered to be a read access.
104 struct pet_expr
*pet_expr_from_access(__isl_take isl_map
*access
)
106 isl_ctx
*ctx
= isl_map_get_ctx(access
);
107 struct pet_expr
*expr
;
111 expr
= isl_calloc_type(ctx
, struct pet_expr
);
115 expr
->type
= pet_expr_access
;
116 expr
->acc
.access
= access
;
122 isl_map_free(access
);
126 /* Construct a unary pet_expr that performs "op" on "arg".
128 struct pet_expr
*pet_expr_new_unary(isl_ctx
*ctx
, enum pet_op_type op
,
129 struct pet_expr
*arg
)
131 struct pet_expr
*expr
;
135 expr
= isl_alloc_type(ctx
, struct pet_expr
);
139 expr
->type
= pet_expr_unary
;
142 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, 1);
145 expr
->args
[pet_un_arg
] = arg
;
153 /* Construct a binary pet_expr that performs "op" on "lhs" and "rhs".
155 struct pet_expr
*pet_expr_new_binary(isl_ctx
*ctx
, enum pet_op_type op
,
156 struct pet_expr
*lhs
, struct pet_expr
*rhs
)
158 struct pet_expr
*expr
;
162 expr
= isl_alloc_type(ctx
, struct pet_expr
);
166 expr
->type
= pet_expr_binary
;
169 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, 2);
172 expr
->args
[pet_bin_lhs
] = lhs
;
173 expr
->args
[pet_bin_rhs
] = rhs
;
182 /* Construct a ternary pet_expr that performs "cond" ? "lhs" : "rhs".
184 struct pet_expr
*pet_expr_new_ternary(isl_ctx
*ctx
, struct pet_expr
*cond
,
185 struct pet_expr
*lhs
, struct pet_expr
*rhs
)
187 struct pet_expr
*expr
;
189 if (!cond
|| !lhs
|| !rhs
)
191 expr
= isl_alloc_type(ctx
, struct pet_expr
);
195 expr
->type
= pet_expr_ternary
;
197 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, 3);
200 expr
->args
[pet_ter_cond
] = cond
;
201 expr
->args
[pet_ter_true
] = lhs
;
202 expr
->args
[pet_ter_false
] = rhs
;
212 /* Construct a call pet_expr that calls function "name" with "n_arg"
213 * arguments. The caller is responsible for filling in the arguments.
215 struct pet_expr
*pet_expr_new_call(isl_ctx
*ctx
, const char *name
,
218 struct pet_expr
*expr
;
220 expr
= isl_alloc_type(ctx
, struct pet_expr
);
224 expr
->type
= pet_expr_call
;
226 expr
->name
= strdup(name
);
227 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, n_arg
);
228 if (!expr
->name
|| !expr
->args
)
229 return pet_expr_free(expr
);
234 /* Construct a pet_expr that represents the double "d".
236 struct pet_expr
*pet_expr_new_double(isl_ctx
*ctx
, double d
)
238 struct pet_expr
*expr
;
240 expr
= isl_calloc_type(ctx
, struct pet_expr
);
244 expr
->type
= pet_expr_double
;
250 void *pet_expr_free(struct pet_expr
*expr
)
257 for (i
= 0; i
< expr
->n_arg
; ++i
)
258 pet_expr_free(expr
->args
[i
]);
261 switch (expr
->type
) {
262 case pet_expr_access
:
263 isl_map_free(expr
->acc
.access
);
268 case pet_expr_double
:
270 case pet_expr_binary
:
271 case pet_expr_ternary
:
279 static void expr_dump(struct pet_expr
*expr
, int indent
)
286 fprintf(stderr
, "%*s", indent
, "");
288 switch (expr
->type
) {
289 case pet_expr_double
:
290 fprintf(stderr
, "%g\n", expr
->d
);
292 case pet_expr_access
:
293 isl_map_dump(expr
->acc
.access
);
294 fprintf(stderr
, "%*sread: %d\n", indent
+ 2,
296 fprintf(stderr
, "%*swrite: %d\n", indent
+ 2,
297 "", expr
->acc
.write
);
298 for (i
= 0; i
< expr
->n_arg
; ++i
)
299 expr_dump(expr
->args
[i
], indent
+ 2);
302 fprintf(stderr
, "%s\n", op_str
[expr
->op
]);
303 expr_dump(expr
->args
[pet_un_arg
], indent
+ 2);
305 case pet_expr_binary
:
306 fprintf(stderr
, "%s\n", op_str
[expr
->op
]);
307 expr_dump(expr
->args
[pet_bin_lhs
], indent
+ 2);
308 expr_dump(expr
->args
[pet_bin_rhs
], indent
+ 2);
310 case pet_expr_ternary
:
311 fprintf(stderr
, "?:\n");
312 expr_dump(expr
->args
[pet_ter_cond
], indent
+ 2);
313 expr_dump(expr
->args
[pet_ter_true
], indent
+ 2);
314 expr_dump(expr
->args
[pet_ter_false
], indent
+ 2);
317 fprintf(stderr
, "%s/%d\n", expr
->name
, expr
->n_arg
);
318 for (i
= 0; i
< expr
->n_arg
; ++i
)
319 expr_dump(expr
->args
[i
], indent
+ 2);
324 void pet_expr_dump(struct pet_expr
*expr
)
329 /* Return 1 if the two pet_exprs are equivalent.
331 int pet_expr_is_equal(struct pet_expr
*expr1
, struct pet_expr
*expr2
)
335 if (!expr1
|| !expr2
)
338 if (expr1
->type
!= expr2
->type
)
340 if (expr1
->n_arg
!= expr2
->n_arg
)
342 for (i
= 0; i
< expr1
->n_arg
; ++i
)
343 if (!pet_expr_is_equal(expr1
->args
[i
], expr2
->args
[i
]))
345 switch (expr1
->type
) {
346 case pet_expr_double
:
347 if (expr1
->d
!= expr2
->d
)
350 case pet_expr_access
:
351 if (expr1
->acc
.read
!= expr2
->acc
.read
)
353 if (expr1
->acc
.write
!= expr2
->acc
.write
)
355 if (!expr1
->acc
.access
|| !expr2
->acc
.access
)
357 if (!isl_map_is_equal(expr1
->acc
.access
, expr2
->acc
.access
))
361 case pet_expr_binary
:
362 case pet_expr_ternary
:
363 if (expr1
->op
!= expr2
->op
)
367 if (strcmp(expr1
->name
, expr2
->name
))
375 /* Add extra conditions on the parameters to all access relations in "expr".
377 struct pet_expr
*pet_expr_restrict(struct pet_expr
*expr
,
378 __isl_take isl_set
*cond
)
385 for (i
= 0; i
< expr
->n_arg
; ++i
) {
386 expr
->args
[i
] = pet_expr_restrict(expr
->args
[i
],
392 if (expr
->type
== pet_expr_access
) {
393 expr
->acc
.access
= isl_map_intersect_params(expr
->acc
.access
,
395 if (!expr
->acc
.access
)
403 return pet_expr_free(expr
);
406 /* Modify all access relations in "expr" by calling "fn" on them.
408 struct pet_expr
*pet_expr_foreach_access(struct pet_expr
*expr
,
409 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*access
, void *user
),
417 for (i
= 0; i
< expr
->n_arg
; ++i
) {
418 expr
->args
[i
] = pet_expr_foreach_access(expr
->args
[i
], fn
, user
);
420 return pet_expr_free(expr
);
423 if (expr
->type
== pet_expr_access
) {
424 expr
->acc
.access
= fn(expr
->acc
.access
, user
);
425 if (!expr
->acc
.access
)
426 return pet_expr_free(expr
);
432 /* Modify the given access relation based on the given iteration space
434 * If the access has any arguments then the domain of the access relation
435 * is a wrapped mapping from the iteration space to the space of
436 * argument values. We only need to change the domain of this wrapped
437 * mapping, so we extend the input transformation with an identity mapping
438 * on the space of argument values.
440 static __isl_give isl_map
*update_domain(__isl_take isl_map
*access
,
443 isl_map
*update
= user
;
446 update
= isl_map_copy(update
);
448 dim
= isl_map_get_space(access
);
449 dim
= isl_space_domain(dim
);
450 if (!isl_space_is_wrapping(dim
))
454 dim
= isl_space_unwrap(dim
);
455 dim
= isl_space_range(dim
);
456 dim
= isl_space_map_from_set(dim
);
457 id
= isl_map_identity(dim
);
458 update
= isl_map_product(update
, id
);
461 return isl_map_apply_domain(access
, update
);
464 /* Modify all access relations in "expr" based on the given iteration space
467 static struct pet_expr
*expr_update_domain(struct pet_expr
*expr
,
468 __isl_take isl_map
*update
)
470 expr
= pet_expr_foreach_access(expr
, &update_domain
, update
);
471 isl_map_free(update
);
475 /* Construct a pet_stmt with given line number and statement
476 * number from a pet_expr.
477 * The initial iteration domain is the zero-dimensional universe.
478 * The name of the domain is given by "label" if it is non-NULL.
479 * Otherwise, the name is constructed as S_<id>.
480 * The domains of all access relations are modified to refer
481 * to the statement iteration domain.
483 struct pet_stmt
*pet_stmt_from_pet_expr(isl_ctx
*ctx
, int line
,
484 __isl_take isl_id
*label
, int id
, struct pet_expr
*expr
)
486 struct pet_stmt
*stmt
;
496 stmt
= isl_calloc_type(ctx
, struct pet_stmt
);
500 dim
= isl_space_set_alloc(ctx
, 0, 0);
502 dim
= isl_space_set_tuple_id(dim
, isl_dim_set
, label
);
504 snprintf(name
, sizeof(name
), "S_%d", id
);
505 dim
= isl_space_set_tuple_name(dim
, isl_dim_set
, name
);
507 dom
= isl_set_universe(isl_space_copy(dim
));
508 sched
= isl_map_from_domain(isl_set_copy(dom
));
510 dim
= isl_space_from_range(dim
);
511 add_name
= isl_map_universe(dim
);
512 expr
= expr_update_domain(expr
, add_name
);
516 stmt
->schedule
= sched
;
519 if (!stmt
->domain
|| !stmt
->schedule
|| !stmt
->body
)
520 return pet_stmt_free(stmt
);
525 return pet_expr_free(expr
);
528 void *pet_stmt_free(struct pet_stmt
*stmt
)
535 isl_set_free(stmt
->domain
);
536 isl_map_free(stmt
->schedule
);
537 pet_expr_free(stmt
->body
);
539 for (i
= 0; i
< stmt
->n_arg
; ++i
)
540 pet_expr_free(stmt
->args
[i
]);
547 static void stmt_dump(struct pet_stmt
*stmt
, int indent
)
554 fprintf(stderr
, "%*s%d\n", indent
, "", stmt
->line
);
555 fprintf(stderr
, "%*s", indent
, "");
556 isl_set_dump(stmt
->domain
);
557 fprintf(stderr
, "%*s", indent
, "");
558 isl_map_dump(stmt
->schedule
);
559 expr_dump(stmt
->body
, indent
);
560 for (i
= 0; i
< stmt
->n_arg
; ++i
)
561 expr_dump(stmt
->args
[i
], indent
+ 2);
564 void pet_stmt_dump(struct pet_stmt
*stmt
)
569 void *pet_array_free(struct pet_array
*array
)
574 isl_set_free(array
->context
);
575 isl_set_free(array
->extent
);
576 isl_set_free(array
->value_bounds
);
577 free(array
->element_type
);
583 void pet_array_dump(struct pet_array
*array
)
588 isl_set_dump(array
->context
);
589 isl_set_dump(array
->extent
);
590 isl_set_dump(array
->value_bounds
);
591 fprintf(stderr
, "%s %s\n", array
->element_type
,
592 array
->live_out
? "live-out" : "");
595 /* Construct a pet_scop with room for n statements.
597 static struct pet_scop
*scop_alloc(isl_ctx
*ctx
, int n
)
600 struct pet_scop
*scop
;
602 scop
= isl_calloc_type(ctx
, struct pet_scop
);
606 space
= isl_space_params_alloc(ctx
, 0);
607 scop
->context
= isl_set_universe(isl_space_copy(space
));
608 scop
->context_value
= isl_set_universe(space
);
609 scop
->stmts
= isl_calloc_array(ctx
, struct pet_stmt
*, n
);
610 if (!scop
->context
|| !scop
->stmts
)
611 return pet_scop_free(scop
);
618 struct pet_scop
*pet_scop_empty(isl_ctx
*ctx
)
620 return scop_alloc(ctx
, 0);
623 /* Construct a pet_scop that contains the given pet_stmt.
625 struct pet_scop
*pet_scop_from_pet_stmt(isl_ctx
*ctx
, struct pet_stmt
*stmt
)
627 struct pet_scop
*scop
;
632 scop
= scop_alloc(ctx
, 1);
634 scop
->stmts
[0] = stmt
;
643 /* Construct a pet_scop that contains the arrays and the statements
644 * in "scop1" and "scop2".
646 struct pet_scop
*pet_scop_add(isl_ctx
*ctx
, struct pet_scop
*scop1
,
647 struct pet_scop
*scop2
)
650 struct pet_scop
*scop
;
652 if (!scop1
|| !scop2
)
655 if (scop1
->n_stmt
== 0) {
656 pet_scop_free(scop1
);
660 if (scop2
->n_stmt
== 0) {
661 pet_scop_free(scop2
);
665 scop
= scop_alloc(ctx
, scop1
->n_stmt
+ scop2
->n_stmt
);
669 scop
->arrays
= isl_calloc_array(ctx
, struct pet_array
*,
670 scop1
->n_array
+ scop2
->n_array
);
673 scop
->n_array
= scop1
->n_array
+ scop2
->n_array
;
675 for (i
= 0; i
< scop1
->n_stmt
; ++i
) {
676 scop
->stmts
[i
] = scop1
->stmts
[i
];
677 scop1
->stmts
[i
] = NULL
;
680 for (i
= 0; i
< scop2
->n_stmt
; ++i
) {
681 scop
->stmts
[scop1
->n_stmt
+ i
] = scop2
->stmts
[i
];
682 scop2
->stmts
[i
] = NULL
;
685 for (i
= 0; i
< scop1
->n_array
; ++i
) {
686 scop
->arrays
[i
] = scop1
->arrays
[i
];
687 scop1
->arrays
[i
] = NULL
;
690 for (i
= 0; i
< scop2
->n_array
; ++i
) {
691 scop
->arrays
[scop1
->n_array
+ i
] = scop2
->arrays
[i
];
692 scop2
->arrays
[i
] = NULL
;
695 pet_scop_free(scop1
);
696 pet_scop_free(scop2
);
699 pet_scop_free(scop1
);
700 pet_scop_free(scop2
);
704 void *pet_scop_free(struct pet_scop
*scop
)
710 isl_set_free(scop
->context
);
711 isl_set_free(scop
->context_value
);
713 for (i
= 0; i
< scop
->n_array
; ++i
)
714 pet_array_free(scop
->arrays
[i
]);
717 for (i
= 0; i
< scop
->n_stmt
; ++i
)
718 pet_stmt_free(scop
->stmts
[i
]);
724 void pet_scop_dump(struct pet_scop
*scop
)
731 isl_set_dump(scop
->context
);
732 isl_set_dump(scop
->context_value
);
733 for (i
= 0; i
< scop
->n_array
; ++i
)
734 pet_array_dump(scop
->arrays
[i
]);
735 for (i
= 0; i
< scop
->n_stmt
; ++i
)
736 pet_stmt_dump(scop
->stmts
[i
]);
739 /* Return 1 if the two pet_arrays are equivalent.
741 * We don't compare element_size as this may be target dependent.
743 int pet_array_is_equal(struct pet_array
*array1
, struct pet_array
*array2
)
745 if (!array1
|| !array2
)
748 if (!isl_set_is_equal(array1
->context
, array2
->context
))
750 if (!isl_set_is_equal(array1
->extent
, array2
->extent
))
752 if (!!array1
->value_bounds
!= !!array2
->value_bounds
)
754 if (array1
->value_bounds
&&
755 !isl_set_is_equal(array1
->value_bounds
, array2
->value_bounds
))
757 if (strcmp(array1
->element_type
, array2
->element_type
))
759 if (array1
->live_out
!= array2
->live_out
)
765 /* Return 1 if the two pet_stmts are equivalent.
767 int pet_stmt_is_equal(struct pet_stmt
*stmt1
, struct pet_stmt
*stmt2
)
771 if (!stmt1
|| !stmt2
)
774 if (stmt1
->line
!= stmt2
->line
)
776 if (!isl_set_is_equal(stmt1
->domain
, stmt2
->domain
))
778 if (!isl_map_is_equal(stmt1
->schedule
, stmt2
->schedule
))
780 if (!pet_expr_is_equal(stmt1
->body
, stmt2
->body
))
782 if (stmt1
->n_arg
!= stmt2
->n_arg
)
784 for (i
= 0; i
< stmt1
->n_arg
; ++i
) {
785 if (!pet_expr_is_equal(stmt1
->args
[i
], stmt2
->args
[i
]))
792 /* Return 1 if the two pet_scops are equivalent.
794 int pet_scop_is_equal(struct pet_scop
*scop1
, struct pet_scop
*scop2
)
798 if (!scop1
|| !scop2
)
801 if (!isl_set_is_equal(scop1
->context
, scop2
->context
))
803 if (!isl_set_is_equal(scop1
->context_value
, scop2
->context_value
))
806 if (scop1
->n_array
!= scop2
->n_array
)
808 for (i
= 0; i
< scop1
->n_array
; ++i
)
809 if (!pet_array_is_equal(scop1
->arrays
[i
], scop2
->arrays
[i
]))
812 if (scop1
->n_stmt
!= scop2
->n_stmt
)
814 for (i
= 0; i
< scop1
->n_stmt
; ++i
)
815 if (!pet_stmt_is_equal(scop1
->stmts
[i
], scop2
->stmts
[i
]))
821 /* Prefix the schedule of "stmt" with an extra dimension with constant
824 struct pet_stmt
*pet_stmt_prefix(struct pet_stmt
*stmt
, int pos
)
829 stmt
->schedule
= isl_map_insert_dims(stmt
->schedule
, isl_dim_out
, 0, 1);
830 stmt
->schedule
= isl_map_fix_si(stmt
->schedule
, isl_dim_out
, 0, pos
);
832 return pet_stmt_free(stmt
);
837 /* Prefix the schedules of all statements in "scop" with an extra
838 * dimension with constant value "pos".
840 struct pet_scop
*pet_scop_prefix(struct pet_scop
*scop
, int pos
)
847 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
848 scop
->stmts
[i
] = pet_stmt_prefix(scop
->stmts
[i
], pos
);
850 return pet_scop_free(scop
);
856 /* Data used in embed_access.
857 * extend adds an iterator to the iteration domain
858 * var_id represents the induction variable of the corresponding loop
860 struct pet_embed_access
{
865 /* Embed the access relation in an extra outer loop.
867 * We first update the iteration domain to insert the extra dimension.
869 * If the access refers to the induction variable, then it is
870 * turned into an access to the set of integers with index (and value)
871 * equal to the induction variable.
873 * If the induction variable appears in the constraints (as a parameter),
874 * then the parameter is equated to the newly introduced iteration
875 * domain dimension and subsequently projected out.
877 * Similarly, if the accessed array is a virtual array (with user
878 * pointer equal to NULL), as created by create_test_access,
879 * then it is extended along with the domain of the access.
881 static __isl_give isl_map
*embed_access(__isl_take isl_map
*access
,
884 struct pet_embed_access
*data
= user
;
885 isl_id
*array_id
= NULL
;
888 access
= update_domain(access
, data
->extend
);
890 if (isl_map_has_tuple_id(access
, isl_dim_out
))
891 array_id
= isl_map_get_tuple_id(access
, isl_dim_out
);
892 if (array_id
== data
->var_id
||
893 (array_id
&& !isl_id_get_user(array_id
))) {
894 access
= isl_map_insert_dims(access
, isl_dim_out
, 0, 1);
895 access
= isl_map_equate(access
,
896 isl_dim_in
, 0, isl_dim_out
, 0);
897 if (array_id
!= data
->var_id
)
898 access
= isl_map_set_tuple_id(access
, isl_dim_out
,
899 isl_id_copy(array_id
));
901 isl_id_free(array_id
);
903 pos
= isl_map_find_dim_by_id(access
, isl_dim_param
, data
->var_id
);
905 access
= isl_map_equate(access
,
906 isl_dim_param
, pos
, isl_dim_in
, 0);
907 access
= isl_map_project_out(access
, isl_dim_param
, pos
, 1);
909 access
= isl_map_set_dim_id(access
, isl_dim_in
, 0,
910 isl_id_copy(data
->var_id
));
915 /* Embed all access relations in "expr" in an extra loop.
916 * "extend" inserts an outer loop iterator in the iteration domains.
917 * "var_id" represents the induction variable.
919 static struct pet_expr
*expr_embed(struct pet_expr
*expr
,
920 __isl_take isl_map
*extend
, __isl_keep isl_id
*var_id
)
922 struct pet_embed_access data
= { .extend
= extend
, .var_id
= var_id
};
924 expr
= pet_expr_foreach_access(expr
, &embed_access
, &data
);
925 isl_map_free(extend
);
929 /* Embed the given pet_stmt in an extra outer loop with iteration domain
930 * "dom" and schedule "sched". "var_id" represents the induction variable
933 * The iteration domain and schedule of the statement are updated
934 * according to the iteration domain and schedule of the new loop.
935 * If stmt->domain is a wrapped map, then the iteration domain
936 * is the domain of this map, so we need to be careful to adjust
939 * If the induction variable appears in the constraints (as a parameter)
940 * of the current iteration domain or the schedule of the statement,
941 * then the parameter is equated to the newly introduced iteration
942 * domain dimension and subsequently projected out.
944 * Finally, all access relations are updated based on the extra loop.
946 struct pet_stmt
*pet_stmt_embed(struct pet_stmt
*stmt
, __isl_take isl_set
*dom
,
947 __isl_take isl_map
*sched
, __isl_take isl_id
*var_id
)
958 if (isl_set_is_wrapping(stmt
->domain
)) {
963 map
= isl_set_unwrap(stmt
->domain
);
964 stmt_id
= isl_map_get_tuple_id(map
, isl_dim_in
);
965 ran_dim
= isl_space_range(isl_map_get_space(map
));
966 ext
= isl_map_from_domain_and_range(isl_set_copy(dom
),
967 isl_set_universe(ran_dim
));
968 map
= isl_map_flat_domain_product(ext
, map
);
969 map
= isl_map_set_tuple_id(map
, isl_dim_in
,
970 isl_id_copy(stmt_id
));
971 dim
= isl_space_domain(isl_map_get_space(map
));
972 stmt
->domain
= isl_map_wrap(map
);
974 stmt_id
= isl_set_get_tuple_id(stmt
->domain
);
975 stmt
->domain
= isl_set_flat_product(isl_set_copy(dom
),
977 stmt
->domain
= isl_set_set_tuple_id(stmt
->domain
,
978 isl_id_copy(stmt_id
));
979 dim
= isl_set_get_space(stmt
->domain
);
982 pos
= isl_set_find_dim_by_id(stmt
->domain
, isl_dim_param
, var_id
);
984 stmt
->domain
= isl_set_equate(stmt
->domain
,
985 isl_dim_param
, pos
, isl_dim_set
, 0);
986 stmt
->domain
= isl_set_project_out(stmt
->domain
,
987 isl_dim_param
, pos
, 1);
990 stmt
->schedule
= isl_map_flat_product(sched
, stmt
->schedule
);
991 stmt
->schedule
= isl_map_set_tuple_id(stmt
->schedule
,
992 isl_dim_in
, stmt_id
);
994 pos
= isl_map_find_dim_by_id(stmt
->schedule
, isl_dim_param
, var_id
);
996 stmt
->schedule
= isl_map_equate(stmt
->schedule
,
997 isl_dim_param
, pos
, isl_dim_in
, 0);
998 stmt
->schedule
= isl_map_project_out(stmt
->schedule
,
999 isl_dim_param
, pos
, 1);
1002 dim
= isl_space_map_from_set(dim
);
1003 extend
= isl_map_identity(dim
);
1004 extend
= isl_map_remove_dims(extend
, isl_dim_in
, 0, 1);
1005 extend
= isl_map_set_tuple_id(extend
, isl_dim_in
,
1006 isl_map_get_tuple_id(extend
, isl_dim_out
));
1007 for (i
= 0; i
< stmt
->n_arg
; ++i
)
1008 stmt
->args
[i
] = expr_embed(stmt
->args
[i
],
1009 isl_map_copy(extend
), var_id
);
1010 stmt
->body
= expr_embed(stmt
->body
, extend
, var_id
);
1013 isl_id_free(var_id
);
1015 for (i
= 0; i
< stmt
->n_arg
; ++i
)
1017 return pet_stmt_free(stmt
);
1018 if (!stmt
->domain
|| !stmt
->schedule
|| !stmt
->body
)
1019 return pet_stmt_free(stmt
);
1023 isl_map_free(sched
);
1024 isl_id_free(var_id
);
1028 /* Embed the given pet_array in an extra outer loop with iteration domain
1030 * This embedding only has an effect on virtual arrays (those with
1031 * user pointer equal to NULL), which need to be extended along with
1032 * the iteration domain.
1034 static struct pet_array
*pet_array_embed(struct pet_array
*array
,
1035 __isl_take isl_set
*dom
)
1037 isl_id
*array_id
= NULL
;
1042 if (isl_set_has_tuple_id(array
->extent
))
1043 array_id
= isl_set_get_tuple_id(array
->extent
);
1045 if (array_id
&& !isl_id_get_user(array_id
)) {
1046 array
->extent
= isl_set_flat_product(dom
, array
->extent
);
1047 array
->extent
= isl_set_set_tuple_id(array
->extent
, array_id
);
1050 isl_id_free(array_id
);
1059 /* Embed all statements and arrays in "scop" in an extra outer loop
1060 * with iteration domain "dom" and schedule "sched".
1061 * "var_id" represents the induction variable of the loop.
1063 struct pet_scop
*pet_scop_embed(struct pet_scop
*scop
, __isl_take isl_set
*dom
,
1064 __isl_take isl_map
*sched
, __isl_take isl_id
*id
)
1071 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1072 scop
->stmts
[i
] = pet_stmt_embed(scop
->stmts
[i
],
1074 isl_map_copy(sched
), isl_id_copy(id
));
1075 if (!scop
->stmts
[i
])
1079 for (i
= 0; i
< scop
->n_array
; ++i
) {
1080 scop
->arrays
[i
] = pet_array_embed(scop
->arrays
[i
],
1082 if (!scop
->arrays
[i
])
1087 isl_map_free(sched
);
1092 isl_map_free(sched
);
1094 return pet_scop_free(scop
);
1097 /* Add extra conditions on the parameters to iteration domain of "stmt".
1099 static struct pet_stmt
*stmt_restrict(struct pet_stmt
*stmt
,
1100 __isl_take isl_set
*cond
)
1105 stmt
->domain
= isl_set_intersect_params(stmt
->domain
, cond
);
1110 return pet_stmt_free(stmt
);
1113 /* Add extra conditions on the parameters to all iteration domains.
1115 struct pet_scop
*pet_scop_restrict(struct pet_scop
*scop
,
1116 __isl_take isl_set
*cond
)
1123 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1124 scop
->stmts
[i
] = stmt_restrict(scop
->stmts
[i
],
1125 isl_set_copy(cond
));
1126 if (!scop
->stmts
[i
])
1134 return pet_scop_free(scop
);
1137 /* Make the statements "stmt" depend on the value of "test"
1138 * being equal to "satisfied" by adjusting stmt->domain.
1140 * We insert an argument corresponding to a read to "test"
1141 * from the iteration domain of "stmt" in front of the list of arguments.
1142 * We also insert a corresponding output dimension in the wrapped
1143 * map contained in stmt->domain, with value set to "satisfied".
1145 static struct pet_stmt
*stmt_filter(struct pet_stmt
*stmt
,
1146 __isl_take isl_map
*test
, int satisfied
)
1157 if (isl_set_is_wrapping(stmt
->domain
))
1158 map
= isl_set_unwrap(stmt
->domain
);
1160 map
= isl_map_from_domain(stmt
->domain
);
1161 map
= isl_map_insert_dims(map
, isl_dim_out
, 0, 1);
1162 id
= isl_map_get_tuple_id(test
, isl_dim_out
);
1163 map
= isl_map_set_dim_id(map
, isl_dim_out
, 0, id
);
1164 map
= isl_map_fix_si(map
, isl_dim_out
, 0, satisfied
);
1165 dom
= isl_set_universe(isl_space_domain(isl_map_get_space(map
)));
1166 test
= isl_map_apply_domain(test
, isl_map_from_range(dom
));
1168 stmt
->domain
= isl_map_wrap(map
);
1170 ctx
= isl_map_get_ctx(test
);
1172 stmt
->args
= isl_calloc_array(ctx
, struct pet_expr
*, 1);
1176 struct pet_expr
**args
;
1177 args
= isl_calloc_array(ctx
, struct pet_expr
*, 1 + stmt
->n_arg
);
1180 for (i
= 0; i
< stmt
->n_arg
; ++i
)
1181 args
[1 + i
] = stmt
->args
[i
];
1186 stmt
->args
[0] = pet_expr_from_access(isl_map_copy(test
));
1194 return pet_stmt_free(stmt
);
1197 /* Make all statements in "scop" depend on the value of "test"
1198 * being equal to "satisfied" by adjusting their domains.
1200 struct pet_scop
*pet_scop_filter(struct pet_scop
*scop
,
1201 __isl_take isl_map
*test
, int satisfied
)
1208 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1209 scop
->stmts
[i
] = stmt_filter(scop
->stmts
[i
],
1210 isl_map_copy(test
), satisfied
);
1211 if (!scop
->stmts
[i
])
1219 return pet_scop_free(scop
);
1222 /* Add all parameters in "expr" to "dim" and return the result.
1224 static __isl_give isl_space
*expr_collect_params(struct pet_expr
*expr
,
1225 __isl_take isl_space
*dim
)
1231 for (i
= 0; i
< expr
->n_arg
; ++i
)
1233 dim
= expr_collect_params(expr
->args
[i
], dim
);
1235 if (expr
->type
== pet_expr_access
)
1236 dim
= isl_space_align_params(dim
,
1237 isl_map_get_space(expr
->acc
.access
));
1241 isl_space_free(dim
);
1242 return pet_expr_free(expr
);
1245 /* Add all parameters in "stmt" to "dim" and return the result.
1247 static __isl_give isl_space
*stmt_collect_params(struct pet_stmt
*stmt
,
1248 __isl_take isl_space
*dim
)
1253 dim
= isl_space_align_params(dim
, isl_set_get_space(stmt
->domain
));
1254 dim
= isl_space_align_params(dim
, isl_map_get_space(stmt
->schedule
));
1255 dim
= expr_collect_params(stmt
->body
, dim
);
1259 isl_space_free(dim
);
1260 return pet_stmt_free(stmt
);
1263 /* Add all parameters in "array" to "dim" and return the result.
1265 static __isl_give isl_space
*array_collect_params(struct pet_array
*array
,
1266 __isl_take isl_space
*dim
)
1271 dim
= isl_space_align_params(dim
, isl_set_get_space(array
->context
));
1272 dim
= isl_space_align_params(dim
, isl_set_get_space(array
->extent
));
1276 isl_space_free(dim
);
1277 return pet_array_free(array
);
1280 /* Add all parameters in "scop" to "dim" and return the result.
1282 static __isl_give isl_space
*scop_collect_params(struct pet_scop
*scop
,
1283 __isl_take isl_space
*dim
)
1290 for (i
= 0; i
< scop
->n_array
; ++i
)
1291 dim
= array_collect_params(scop
->arrays
[i
], dim
);
1293 for (i
= 0; i
< scop
->n_stmt
; ++i
)
1294 dim
= stmt_collect_params(scop
->stmts
[i
], dim
);
1298 isl_space_free(dim
);
1299 return pet_scop_free(scop
);
1302 /* Add all parameters in "dim" to all access relations in "expr".
1304 static struct pet_expr
*expr_propagate_params(struct pet_expr
*expr
,
1305 __isl_take isl_space
*dim
)
1312 for (i
= 0; i
< expr
->n_arg
; ++i
) {
1314 expr_propagate_params(expr
->args
[i
],
1315 isl_space_copy(dim
));
1320 if (expr
->type
== pet_expr_access
) {
1321 expr
->acc
.access
= isl_map_align_params(expr
->acc
.access
,
1322 isl_space_copy(dim
));
1323 if (!expr
->acc
.access
)
1327 isl_space_free(dim
);
1330 isl_space_free(dim
);
1331 return pet_expr_free(expr
);
1334 /* Add all parameters in "dim" to the domain, schedule and
1335 * all access relations in "stmt".
1337 static struct pet_stmt
*stmt_propagate_params(struct pet_stmt
*stmt
,
1338 __isl_take isl_space
*dim
)
1343 stmt
->domain
= isl_set_align_params(stmt
->domain
, isl_space_copy(dim
));
1344 stmt
->schedule
= isl_map_align_params(stmt
->schedule
,
1345 isl_space_copy(dim
));
1346 stmt
->body
= expr_propagate_params(stmt
->body
, isl_space_copy(dim
));
1348 if (!stmt
->domain
|| !stmt
->schedule
|| !stmt
->body
)
1351 isl_space_free(dim
);
1354 isl_space_free(dim
);
1355 return pet_stmt_free(stmt
);
1358 /* Add all parameters in "dim" to "array".
1360 static struct pet_array
*array_propagate_params(struct pet_array
*array
,
1361 __isl_take isl_space
*dim
)
1366 array
->context
= isl_set_align_params(array
->context
,
1367 isl_space_copy(dim
));
1368 array
->extent
= isl_set_align_params(array
->extent
,
1369 isl_space_copy(dim
));
1370 if (array
->value_bounds
) {
1371 array
->value_bounds
= isl_set_align_params(array
->value_bounds
,
1372 isl_space_copy(dim
));
1373 if (!array
->value_bounds
)
1377 if (!array
->context
|| !array
->extent
)
1380 isl_space_free(dim
);
1383 isl_space_free(dim
);
1384 return pet_array_free(array
);
1387 /* Add all parameters in "dim" to "scop".
1389 static struct pet_scop
*scop_propagate_params(struct pet_scop
*scop
,
1390 __isl_take isl_space
*dim
)
1397 for (i
= 0; i
< scop
->n_array
; ++i
) {
1398 scop
->arrays
[i
] = array_propagate_params(scop
->arrays
[i
],
1399 isl_space_copy(dim
));
1400 if (!scop
->arrays
[i
])
1404 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1405 scop
->stmts
[i
] = stmt_propagate_params(scop
->stmts
[i
],
1406 isl_space_copy(dim
));
1407 if (!scop
->stmts
[i
])
1411 isl_space_free(dim
);
1414 isl_space_free(dim
);
1415 return pet_scop_free(scop
);
1418 /* Update all isl_sets and isl_maps in "scop" such that they all
1419 * have the same parameters.
1421 struct pet_scop
*pet_scop_align_params(struct pet_scop
*scop
)
1428 dim
= isl_set_get_space(scop
->context
);
1429 dim
= scop_collect_params(scop
, dim
);
1431 scop
->context
= isl_set_align_params(scop
->context
, isl_space_copy(dim
));
1432 scop
= scop_propagate_params(scop
, dim
);
1437 /* Check if the given access relation accesses a (0D) array that corresponds
1438 * to one of the parameters in "dim". If so, replace the array access
1439 * by an access to the set of integers with as index (and value)
1442 static __isl_give isl_map
*access_detect_parameter(__isl_take isl_map
*access
,
1443 __isl_take isl_space
*dim
)
1445 isl_id
*array_id
= NULL
;
1448 if (isl_map_has_tuple_id(access
, isl_dim_out
)) {
1449 array_id
= isl_map_get_tuple_id(access
, isl_dim_out
);
1450 pos
= isl_space_find_dim_by_id(dim
, isl_dim_param
, array_id
);
1452 isl_space_free(dim
);
1455 isl_id_free(array_id
);
1459 pos
= isl_map_find_dim_by_id(access
, isl_dim_param
, array_id
);
1461 access
= isl_map_insert_dims(access
, isl_dim_param
, 0, 1);
1462 access
= isl_map_set_dim_id(access
, isl_dim_param
, 0, array_id
);
1465 isl_id_free(array_id
);
1467 access
= isl_map_insert_dims(access
, isl_dim_out
, 0, 1);
1468 access
= isl_map_equate(access
, isl_dim_param
, pos
, isl_dim_out
, 0);
1473 /* Replace all accesses to (0D) arrays that correspond to one of the parameters
1474 * in "dim" by a value equal to the corresponding parameter.
1476 static struct pet_expr
*expr_detect_parameter_accesses(struct pet_expr
*expr
,
1477 __isl_take isl_space
*dim
)
1484 for (i
= 0; i
< expr
->n_arg
; ++i
) {
1486 expr_detect_parameter_accesses(expr
->args
[i
],
1487 isl_space_copy(dim
));
1492 if (expr
->type
== pet_expr_access
) {
1493 expr
->acc
.access
= access_detect_parameter(expr
->acc
.access
,
1494 isl_space_copy(dim
));
1495 if (!expr
->acc
.access
)
1499 isl_space_free(dim
);
1502 isl_space_free(dim
);
1503 return pet_expr_free(expr
);
1506 /* Replace all accesses to (0D) arrays that correspond to one of the parameters
1507 * in "dim" by a value equal to the corresponding parameter.
1509 static struct pet_stmt
*stmt_detect_parameter_accesses(struct pet_stmt
*stmt
,
1510 __isl_take isl_space
*dim
)
1515 stmt
->body
= expr_detect_parameter_accesses(stmt
->body
,
1516 isl_space_copy(dim
));
1518 if (!stmt
->domain
|| !stmt
->schedule
|| !stmt
->body
)
1521 isl_space_free(dim
);
1524 isl_space_free(dim
);
1525 return pet_stmt_free(stmt
);
1528 /* Replace all accesses to (0D) arrays that correspond to one of the parameters
1529 * in "dim" by a value equal to the corresponding parameter.
1531 static struct pet_scop
*scop_detect_parameter_accesses(struct pet_scop
*scop
,
1532 __isl_take isl_space
*dim
)
1539 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1540 scop
->stmts
[i
] = stmt_detect_parameter_accesses(scop
->stmts
[i
],
1541 isl_space_copy(dim
));
1542 if (!scop
->stmts
[i
])
1546 isl_space_free(dim
);
1549 isl_space_free(dim
);
1550 return pet_scop_free(scop
);
1553 /* Replace all accesses to (0D) arrays that correspond to any of
1554 * the parameters used in "scop" by a value equal
1555 * to the corresponding parameter.
1557 struct pet_scop
*pet_scop_detect_parameter_accesses(struct pet_scop
*scop
)
1564 dim
= isl_set_get_space(scop
->context
);
1565 dim
= scop_collect_params(scop
, dim
);
1567 scop
= scop_detect_parameter_accesses(scop
, dim
);
1572 /* Add all read access relations (if "read" is set) and/or all write
1573 * access relations (if "write" is set) to "accesses" and return the result.
1575 static __isl_give isl_union_map
*expr_collect_accesses(struct pet_expr
*expr
,
1576 int read
, int write
, __isl_take isl_union_map
*accesses
)
1585 for (i
= 0; i
< expr
->n_arg
; ++i
)
1586 accesses
= expr_collect_accesses(expr
->args
[i
],
1587 read
, write
, accesses
);
1589 if (expr
->type
== pet_expr_access
&&
1590 isl_map_has_tuple_id(expr
->acc
.access
, isl_dim_out
) &&
1591 ((read
&& expr
->acc
.read
) || (write
&& expr
->acc
.write
)))
1592 accesses
= isl_union_map_add_map(accesses
,
1593 isl_map_copy(expr
->acc
.access
));
1598 /* Collect and return all read access relations (if "read" is set)
1599 * and/or all write * access relations (if "write" is set) in "stmt".
1601 static __isl_give isl_union_map
*stmt_collect_accesses(struct pet_stmt
*stmt
,
1602 int read
, int write
, __isl_take isl_space
*dim
)
1604 isl_union_map
*accesses
;
1609 accesses
= isl_union_map_empty(dim
);
1610 accesses
= expr_collect_accesses(stmt
->body
, read
, write
, accesses
);
1611 accesses
= isl_union_map_intersect_domain(accesses
,
1612 isl_union_set_from_set(isl_set_copy(stmt
->domain
)));
1617 /* Collect and return all read access relations (if "read" is set)
1618 * and/or all write * access relations (if "write" is set) in "scop".
1620 static __isl_give isl_union_map
*scop_collect_accesses(struct pet_scop
*scop
,
1621 int read
, int write
)
1624 isl_union_map
*accesses
;
1629 accesses
= isl_union_map_empty(isl_set_get_space(scop
->context
));
1631 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1632 isl_union_map
*accesses_i
;
1633 isl_space
*dim
= isl_set_get_space(scop
->context
);
1634 accesses_i
= stmt_collect_accesses(scop
->stmts
[i
],
1636 accesses
= isl_union_map_union(accesses
, accesses_i
);
1642 __isl_give isl_union_map
*pet_scop_collect_reads(struct pet_scop
*scop
)
1644 return scop_collect_accesses(scop
, 1, 0);
1647 __isl_give isl_union_map
*pet_scop_collect_writes(struct pet_scop
*scop
)
1649 return scop_collect_accesses(scop
, 0, 1);
1652 /* Collect and return the union of iteration domains in "scop".
1654 __isl_give isl_union_set
*pet_scop_collect_domains(struct pet_scop
*scop
)
1658 isl_union_set
*domain
;
1663 domain
= isl_union_set_empty(isl_set_get_space(scop
->context
));
1665 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1666 domain_i
= isl_set_copy(scop
->stmts
[i
]->domain
);
1667 domain
= isl_union_set_add_set(domain
, domain_i
);
1673 /* Collect and return the schedules of the statements in "scop".
1674 * The range is normalized to the maximal number of scheduling
1677 __isl_give isl_union_map
*pet_scop_collect_schedule(struct pet_scop
*scop
)
1680 isl_map
*schedule_i
;
1681 isl_union_map
*schedule
;
1682 int depth
, max_depth
= 0;
1687 schedule
= isl_union_map_empty(isl_set_get_space(scop
->context
));
1689 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1690 depth
= isl_map_dim(scop
->stmts
[i
]->schedule
, isl_dim_out
);
1691 if (depth
> max_depth
)
1695 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1696 schedule_i
= isl_map_copy(scop
->stmts
[i
]->schedule
);
1697 depth
= isl_map_dim(schedule_i
, isl_dim_out
);
1698 schedule_i
= isl_map_add_dims(schedule_i
, isl_dim_out
,
1700 for (j
= depth
; j
< max_depth
; ++j
)
1701 schedule_i
= isl_map_fix_si(schedule_i
,
1703 schedule
= isl_union_map_add_map(schedule
, schedule_i
);
1709 /* Does expression "expr" write to "id"?
1711 static int expr_writes(struct pet_expr
*expr
, __isl_keep isl_id
*id
)
1716 for (i
= 0; i
< expr
->n_arg
; ++i
) {
1717 int writes
= expr_writes(expr
->args
[i
], id
);
1718 if (writes
< 0 || writes
)
1722 if (expr
->type
!= pet_expr_access
)
1724 if (!expr
->acc
.write
)
1726 if (!isl_map_has_tuple_id(expr
->acc
.access
, isl_dim_out
))
1729 write_id
= isl_map_get_tuple_id(expr
->acc
.access
, isl_dim_out
);
1730 isl_id_free(write_id
);
1735 return write_id
== id
;
1738 /* Does statement "stmt" write to "id"?
1740 static int stmt_writes(struct pet_stmt
*stmt
, __isl_keep isl_id
*id
)
1742 return expr_writes(stmt
->body
, id
);
1745 /* Is there any write access in "scop" that accesses "id"?
1747 int pet_scop_writes(struct pet_scop
*scop
, __isl_keep isl_id
*id
)
1754 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1755 int writes
= stmt_writes(scop
->stmts
[i
], id
);
1756 if (writes
< 0 || writes
)
1763 /* Reset the user pointer on all parameter ids in "set".
1765 static __isl_give isl_set
*set_anonymize(__isl_take isl_set
*set
)
1769 n
= isl_set_dim(set
, isl_dim_param
);
1770 for (i
= 0; i
< n
; ++i
) {
1771 isl_id
*id
= isl_set_get_dim_id(set
, isl_dim_param
, i
);
1772 const char *name
= isl_id_get_name(id
);
1773 set
= isl_set_set_dim_name(set
, isl_dim_param
, i
, name
);
1780 /* Reset the user pointer on all parameter ids in "map".
1782 static __isl_give isl_map
*map_anonymize(__isl_take isl_map
*map
)
1786 n
= isl_map_dim(map
, isl_dim_param
);
1787 for (i
= 0; i
< n
; ++i
) {
1788 isl_id
*id
= isl_map_get_dim_id(map
, isl_dim_param
, i
);
1789 const char *name
= isl_id_get_name(id
);
1790 map
= isl_map_set_dim_name(map
, isl_dim_param
, i
, name
);
1797 /* Reset the user pointer on all parameter ids in "array".
1799 static struct pet_array
*array_anonymize(struct pet_array
*array
)
1804 array
->context
= set_anonymize(array
->context
);
1805 array
->extent
= set_anonymize(array
->extent
);
1806 if (!array
->context
|| !array
->extent
)
1807 return pet_array_free(array
);
1812 /* Reset the user pointer on all parameter ids in "access".
1814 static __isl_give isl_map
*access_anonymize(__isl_take isl_map
*access
,
1817 access
= map_anonymize(access
);
1822 /* Reset the user pointer on all parameter ids in "stmt".
1824 static struct pet_stmt
*stmt_anonymize(struct pet_stmt
*stmt
)
1833 stmt
->domain
= set_anonymize(stmt
->domain
);
1834 stmt
->schedule
= map_anonymize(stmt
->schedule
);
1835 if (!stmt
->domain
|| !stmt
->schedule
)
1836 return pet_stmt_free(stmt
);
1838 for (i
= 0; i
< stmt
->n_arg
; ++i
) {
1839 stmt
->args
[i
] = pet_expr_foreach_access(stmt
->args
[i
],
1840 &access_anonymize
, NULL
);
1842 return pet_stmt_free(stmt
);
1845 stmt
->body
= pet_expr_foreach_access(stmt
->body
,
1846 &access_anonymize
, NULL
);
1848 return pet_stmt_free(stmt
);
1853 /* Reset the user pointer on all parameter ids in "scop".
1855 struct pet_scop
*pet_scop_anonymize(struct pet_scop
*scop
)
1862 scop
->context
= set_anonymize(scop
->context
);
1863 scop
->context_value
= set_anonymize(scop
->context_value
);
1864 if (!scop
->context
|| !scop
->context_value
)
1865 return pet_scop_free(scop
);
1867 for (i
= 0; i
< scop
->n_array
; ++i
) {
1868 scop
->arrays
[i
] = array_anonymize(scop
->arrays
[i
]);
1869 if (!scop
->arrays
[i
])
1870 return pet_scop_free(scop
);
1873 for (i
= 0; i
< scop
->n_stmt
; ++i
) {
1874 scop
->stmts
[i
] = stmt_anonymize(scop
->stmts
[i
]);
1875 if (!scop
->stmts
[i
])
1876 return pet_scop_free(scop
);