6 #include <isl/ast_build.h>
9 #include <isl/union_map.h>
10 #include <isl/printer.h>
11 #include <isl/id_to_ast_expr.h>
12 #include <isl/id_to_pw_aff.h>
14 #if defined(__cplusplus)
19 ISL_ARG_DECL(pet_options
, struct pet_options
, pet_options_args
)
21 /* If autodetect is set, any valid scop is extracted.
22 * Otherwise, the scop needs to be delimited by pragmas.
24 int pet_options_set_autodetect(isl_ctx
*ctx
, int val
);
25 int pet_options_get_autodetect(isl_ctx
*ctx
);
27 int pet_options_set_detect_conditional_assignment(isl_ctx
*ctx
, int val
);
28 int pet_options_get_detect_conditional_assignment(isl_ctx
*ctx
);
30 /* If encapsulate-dynamic-control is set, then any dynamic control
31 * in the input program will be encapsulated in macro statements.
32 * This means in particular that no statements with arguments
35 int pet_options_set_encapsulate_dynamic_control(isl_ctx
*ctx
, int val
);
36 int pet_options_get_encapsulate_dynamic_control(isl_ctx
*ctx
);
38 #define PET_OVERFLOW_AVOID 0
39 #define PET_OVERFLOW_IGNORE 1
40 int pet_options_set_signed_overflow(isl_ctx
*ctx
, int val
);
41 int pet_options_get_signed_overflow(isl_ctx
*ctx
);
44 typedef struct pet_loc pet_loc
;
46 /* Return an additional reference to "loc". */
47 __isl_give pet_loc
*pet_loc_copy(__isl_keep pet_loc
*loc
);
48 /* Free a reference to "loc". */
49 pet_loc
*pet_loc_free(__isl_take pet_loc
*loc
);
51 /* Return the offset in the input file of the start of "loc". */
52 unsigned pet_loc_get_start(__isl_keep pet_loc
*loc
);
53 /* Return the offset in the input file of the character after "loc". */
54 unsigned pet_loc_get_end(__isl_keep pet_loc
*loc
);
55 /* Return the line number of a line within the "loc" region. */
56 int pet_loc_get_line(__isl_keep pet_loc
*loc
);
57 /* Return the indentation of the "loc" region. */
58 __isl_keep
const char *pet_loc_get_indent(__isl_keep pet_loc
*loc
);
71 /* only compound assignments operators before assignment */
109 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
111 enum pet_un_arg_type
{
115 /* Indices into the pet_expr->args array when
116 * pet_expr->type == pet_expr_binary
118 enum pet_bin_arg_type
{
123 /* Indices into the pet_expr->args array when
124 * pet_expr->type == pet_expr_ternary
126 enum pet_ter_arg_type
{
133 typedef struct pet_expr pet_expr
;
135 /* Return an additional reference to "expr". */
136 __isl_give pet_expr
*pet_expr_copy(__isl_keep pet_expr
*expr
);
137 /* Free a reference to "expr". */
138 __isl_null pet_expr
*pet_expr_free(__isl_take pet_expr
*expr
);
140 /* Return the isl_ctx in which "expr" was created. */
141 isl_ctx
*pet_expr_get_ctx(__isl_keep pet_expr
*expr
);
143 /* Return the type of "expr". */
144 enum pet_expr_type
pet_expr_get_type(__isl_keep pet_expr
*expr
);
145 /* Return the number of arguments of "expr". */
146 int pet_expr_get_n_arg(__isl_keep pet_expr
*expr
);
147 /* Set the number of arguments of "expr" to "n". */
148 __isl_give pet_expr
*pet_expr_set_n_arg(__isl_take pet_expr
*expr
, int n
);
149 /* Return the argument of "expr" at position "pos". */
150 __isl_give pet_expr
*pet_expr_get_arg(__isl_keep pet_expr
*expr
, int pos
);
151 /* Replace the argument of "expr" at position "pos" by "arg". */
152 __isl_give pet_expr
*pet_expr_set_arg(__isl_take pet_expr
*expr
, int pos
,
153 __isl_take pet_expr
*arg
);
155 /* Return the operation type of operation expression "expr". */
156 enum pet_op_type
pet_expr_op_get_type(__isl_keep pet_expr
*expr
);
157 /* Replace the operation type of operation expression "expr" by "type". */
158 __isl_give pet_expr
*pet_expr_op_set_type(__isl_take pet_expr
*expr
,
159 enum pet_op_type type
);
161 /* Construct a (read) access pet_expr from an index expression. */
162 __isl_give pet_expr
*pet_expr_from_index(__isl_take isl_multi_pw_aff
*index
);
164 /* Does "expr" represent an affine expression? */
165 int pet_expr_is_affine(__isl_keep pet_expr
*expr
);
166 /* Does the access expression "expr" read the accessed elements? */
167 int pet_expr_access_is_read(__isl_keep pet_expr
*expr
);
168 /* Does the access expression "expr" write to the accessed elements? */
169 int pet_expr_access_is_write(__isl_keep pet_expr
*expr
);
170 /* Mark "expr" as a read dependening on "read". */
171 __isl_give pet_expr
*pet_expr_access_set_read(__isl_take pet_expr
*expr
,
173 /* Mark "expr" as a write dependening on "write". */
174 __isl_give pet_expr
*pet_expr_access_set_write(__isl_take pet_expr
*expr
,
176 /* Mark "expr" as a kill dependening on "kill". */
177 __isl_give pet_expr
*pet_expr_access_set_kill(__isl_take pet_expr
*expr
,
179 /* Return the reference identifier of access expression "expr". */
180 __isl_give isl_id
*pet_expr_access_get_ref_id(__isl_keep pet_expr
*expr
);
181 /* Replace the reference identifier of access expression "expr" by "ref_id". */
182 __isl_give pet_expr
*pet_expr_access_set_ref_id(__isl_take pet_expr
*expr
,
183 __isl_take isl_id
*ref_id
);
184 /* Return the identifier of the outer array accessed by "expr". */
185 __isl_give isl_id
*pet_expr_access_get_id(__isl_keep pet_expr
*expr
);
186 /* Return the index expression of access expression "expr". */
187 __isl_give isl_multi_pw_aff
*pet_expr_access_get_index(
188 __isl_keep pet_expr
*expr
);
190 /* Return the potential read access relation of access expression "expr". */
191 __isl_give isl_union_map
*pet_expr_access_get_may_read(
192 __isl_keep pet_expr
*expr
);
193 /* Return the potential write access relation of access expression "expr". */
194 __isl_give isl_union_map
*pet_expr_access_get_may_write(
195 __isl_keep pet_expr
*expr
);
196 /* Return the definite write access relation of access expression "expr". */
197 __isl_give isl_union_map
*pet_expr_access_get_must_write(
198 __isl_keep pet_expr
*expr
);
199 /* Return the argument dependent potential read access relation of "expr". */
200 __isl_give isl_union_map
*pet_expr_access_get_dependent_may_read(
201 __isl_keep pet_expr
*expr
);
202 /* Return the argument dependent potential write access relation of "expr". */
203 __isl_give isl_union_map
*pet_expr_access_get_dependent_may_write(
204 __isl_keep pet_expr
*expr
);
205 /* Return the argument dependent definite write access relation of "expr". */
206 __isl_give isl_union_map
*pet_expr_access_get_dependent_must_write(
207 __isl_keep pet_expr
*expr
);
208 /* Return the tagged potential read access relation of access "expr". */
209 __isl_give isl_union_map
*pet_expr_access_get_tagged_may_read(
210 __isl_keep pet_expr
*expr
);
211 /* Return the tagged potential write access relation of access "expr". */
212 __isl_give isl_union_map
*pet_expr_access_get_tagged_may_write(
213 __isl_keep pet_expr
*expr
);
215 /* Return the name of the function called by "expr". */
216 __isl_keep
const char *pet_expr_call_get_name(__isl_keep pet_expr
*expr
);
217 /* Replace the name of the function called by "expr" by "name". */
218 __isl_give pet_expr
*pet_expr_call_set_name(__isl_take pet_expr
*expr
,
219 __isl_keep
const char *name
);
221 /* Create a pet_expr representing a cast of "arg" to "type_name". */
222 __isl_give pet_expr
*pet_expr_new_cast(const char *type_name
,
223 __isl_take pet_expr
*arg
);
224 /* Replace the type of the cast performed by "expr" by "name". */
225 __isl_give pet_expr
*pet_expr_cast_set_type_name(__isl_take pet_expr
*expr
,
226 __isl_keep
const char *name
);
228 /* Return the value of the integer represented by "expr". */
229 __isl_give isl_val
*pet_expr_int_get_val(__isl_keep pet_expr
*expr
);
230 /* Replace the value of the integer represented by "expr" by "v". */
231 __isl_give pet_expr
*pet_expr_int_set_val(__isl_take pet_expr
*expr
,
232 __isl_take isl_val
*v
);
234 /* Return a string representation of the double expression "expr". */
235 __isl_give
char *pet_expr_double_get_str(__isl_keep pet_expr
*expr
);
236 /* Replace value and string representation of the double expression "expr" */
237 __isl_give pet_expr
*pet_expr_double_set(__isl_take pet_expr
*expr
,
238 double d
, __isl_keep
const char *s
);
240 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_access. */
241 int pet_expr_foreach_access_expr(__isl_keep pet_expr
*expr
,
242 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
243 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_call. */
244 int pet_expr_foreach_call_expr(__isl_keep pet_expr
*expr
,
245 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
248 typedef struct pet_context pet_context
;
250 /* Create a context with the given domain. */
251 __isl_give pet_context
*pet_context_alloc(__isl_take isl_set
*domain
);
252 /* Return an additional reference to "pc". */
253 __isl_give pet_context
*pet_context_copy(__isl_keep pet_context
*pc
);
254 /* Free a reference to "pc". */
255 __isl_null pet_context
*pet_context_free(__isl_take pet_context
*pc
);
257 /* Return the isl_ctx in which "pc" was created. */
258 isl_ctx
*pet_context_get_ctx(__isl_keep pet_context
*pc
);
260 /* Extract an affine expression defined over the domain of "pc" from "expr"
263 __isl_give isl_pw_aff
*pet_expr_extract_affine(__isl_keep pet_expr
*expr
,
264 __isl_keep pet_context
*pc
);
266 void pet_expr_dump(__isl_keep pet_expr
*expr
);
274 pet_tree_decl
, /* A declaration without initialization */
275 pet_tree_decl_init
, /* A declaration with initialization */
276 pet_tree_if
, /* An if without an else branch */
277 pet_tree_if_else
, /* An if with an else branch */
279 pet_tree_infinite_loop
,
284 typedef struct pet_tree pet_tree
;
286 /* Return the isl_ctx in which "tree" was created. */
287 isl_ctx
*pet_tree_get_ctx(__isl_keep pet_tree
*tree
);
289 /* Return an additional reference to "tree". */
290 __isl_give pet_tree
*pet_tree_copy(__isl_keep pet_tree
*tree
);
291 /* Free a reference to "tree". */
292 __isl_null pet_tree
*pet_tree_free(__isl_take pet_tree
*tree
);
294 /* Return the location of "tree". */
295 __isl_give pet_loc
*pet_tree_get_loc(__isl_keep pet_tree
*tree
);
297 /* Return the type of "tree". */
298 enum pet_tree_type
pet_tree_get_type(__isl_keep pet_tree
*tree
);
300 /* Return the expression of the expression tree "tree". */
301 __isl_give pet_expr
*pet_tree_expr_get_expr(__isl_keep pet_tree
*tree
);
303 /* Return the number of children of the block tree "tree". */
304 int pet_tree_block_n_child(__isl_keep pet_tree
*tree
);
305 /* Return child "pos" of the block tree "tree". */
306 __isl_give pet_tree
*pet_tree_block_get_child(__isl_keep pet_tree
*tree
,
309 /* Is "tree" a declaration (with or without initialization)? */
310 int pet_tree_is_decl(__isl_keep pet_tree
*tree
);
311 /* Return the variable declared by the declaration tree "tree". */
312 __isl_give pet_expr
*pet_tree_decl_get_var(__isl_keep pet_tree
*tree
);
313 /* Return the initial value of the pet_tree_decl_init tree "tree". */
314 __isl_give pet_expr
*pet_tree_decl_get_init(__isl_keep pet_tree
*tree
);
316 /* Return the condition of the if tree "tree". */
317 __isl_give pet_expr
*pet_tree_if_get_cond(__isl_keep pet_tree
*tree
);
318 /* Return the then branch of the if tree "tree". */
319 __isl_give pet_tree
*pet_tree_if_get_then(__isl_keep pet_tree
*tree
);
320 /* Return the else branch of the if tree with else branch "tree". */
321 __isl_give pet_tree
*pet_tree_if_get_else(__isl_keep pet_tree
*tree
);
323 /* Is "tree" a for loop, a while loop or an infinite loop? */
324 int pet_tree_is_loop(__isl_keep pet_tree
*tree
);
325 /* Return the induction variable of the for loop "tree" */
326 __isl_give pet_expr
*pet_tree_loop_get_var(__isl_keep pet_tree
*tree
);
327 /* Return the initial value of the induction variable of the for loop "tree" */
328 __isl_give pet_expr
*pet_tree_loop_get_init(__isl_keep pet_tree
*tree
);
329 /* Return the condition of the loop tree "tree" */
330 __isl_give pet_expr
*pet_tree_loop_get_cond(__isl_keep pet_tree
*tree
);
331 /* Return the induction variable of the for loop "tree" */
332 __isl_give pet_expr
*pet_tree_loop_get_inc(__isl_keep pet_tree
*tree
);
333 /* Return the body of the loop tree "tree" */
334 __isl_give pet_tree
*pet_tree_loop_get_body(__isl_keep pet_tree
*tree
);
336 /* Call "fn" on each top-level expression in the nodes of "tree" */
337 int pet_tree_foreach_expr(__isl_keep pet_tree
*tree
,
338 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
339 /* Call "fn" on each access subexpression in the nodes of "tree" */
340 int pet_tree_foreach_access_expr(__isl_keep pet_tree
*tree
,
341 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
343 void pet_tree_dump(__isl_keep pet_tree
*tree
);
345 /* "loc" represents the region of the source code that is represented
348 * If the statement has arguments, i.e., n_arg != 0, then
349 * "domain" is a wrapped map, mapping the iteration domain
350 * to the values of the arguments for which this statement
352 * Otherwise, it is simply the iteration domain.
354 * If one of the arguments is an access expression that accesses
355 * more than one element for a given iteration, then the constraints
356 * on the value of this argument (encoded in "domain") should be satisfied
357 * for all of those accessed elements.
369 /* Return the iteration space of "stmt". */
370 __isl_give isl_space
*pet_stmt_get_space(struct pet_stmt
*stmt
);
372 /* Is "stmt" an assignment statement? */
373 int pet_stmt_is_assign(struct pet_stmt
*stmt
);
374 /* Is "stmt" a kill statement? */
375 int pet_stmt_is_kill(struct pet_stmt
*stmt
);
377 /* pet_stmt_build_ast_exprs is currently limited to only handle
378 * some forms of data dependent accesses.
379 * If pet_stmt_can_build_ast_exprs returns 1, then pet_stmt_build_ast_exprs
380 * can safely be called on "stmt".
382 int pet_stmt_can_build_ast_exprs(struct pet_stmt
*stmt
);
383 /* Construct an associative array from reference identifiers of
384 * access expressions in "stmt" to the corresponding isl_ast_expr.
385 * Each index expression is first transformed through "fn_index"
386 * (if not NULL). Then an AST expression is generated using "build".
387 * Finally, the AST expression is transformed using "fn_expr"
390 __isl_give isl_id_to_ast_expr
*pet_stmt_build_ast_exprs(struct pet_stmt
*stmt
,
391 __isl_keep isl_ast_build
*build
,
392 __isl_give isl_multi_pw_aff
*(*fn_index
)(
393 __isl_take isl_multi_pw_aff
*mpa
, __isl_keep isl_id
*id
,
394 void *user
), void *user_index
,
395 __isl_give isl_ast_expr
*(*fn_expr
)(__isl_take isl_ast_expr
*expr
,
396 __isl_keep isl_id
*id
, void *user
), void *user_expr
);
398 /* Print "stmt" to "p".
400 * The access expressions in "stmt" are replaced by the isl_ast_expr
401 * associated to its reference identifier in "ref2expr".
403 __isl_give isl_printer
*pet_stmt_print_body(struct pet_stmt
*stmt
,
404 __isl_take isl_printer
*p
, __isl_keep isl_id_to_ast_expr
*ref2expr
);
406 /* This structure represents a defined type.
407 * "name" is the name of the type, while "definition" is a string
408 * representation of its definition.
415 /* context holds constraints on the parameter that ensure that
416 * this array has a valid (i.e., non-negative) size
418 * extent holds constraints on the indices
420 * value_bounds holds constraints on the elements of the array
421 * and may be NULL if no such constraints were specified by the user
423 * element_size is the size in bytes of each array element
424 * element_type is the type of the array elements.
425 * element_is_record is set if this type is a record type.
427 * live_out is set if the array appears in a live-out pragma
429 * if uniquely_defined is set then the array is written by a single access
430 * such that any element that is ever read
431 * is known to be assigned exactly once before the read
433 * declared is set if the array was declared somewhere inside the scop.
434 * exposed is set if the declared array is visible outside the scop.
439 isl_set
*value_bounds
;
441 int element_is_record
;
444 int uniquely_defined
;
449 /* This structure represents an implication on a boolean filter.
450 * In particular, if the filter value of an element in the domain
451 * of "extension" is equal to "satisfied", then the filter values
452 * of the corresponding images in "extension" are also equal
455 struct pet_implication
{
460 /* This structure represents an independence implied by a for loop
461 * that is marked as independent in the source code.
462 * "filter" contains pairs of statement instances that are guaranteed
463 * not to be dependent on each other based on the independent for loop,
464 * assuming that no dependences carried by this loop are implied
465 * by the variables in "local".
466 * "local" contains the variables that are local to the loop that was
467 * marked independent.
469 struct pet_independence
{
470 isl_union_map
*filter
;
471 isl_union_set
*local
;
474 /* "loc" represents the region of the source code that is represented
476 * If the scop was detected based on scop and endscop pragmas, then
477 * the lines containing these pragmas are included in this region.
478 * In the final result, the context describes the set of parameter values
479 * for which the scop can be executed.
480 * During the construction of the pet_scop, the context lives in a set space
481 * where each dimension refers to an outer loop.
482 * context_value describes assignments to the parameters (if any)
483 * outside of the scop.
485 * The n_type types define types that may be referenced from by the arrays.
487 * The n_implication implications describe implications on boolean filters.
489 * The n_independence independences describe independences implied
490 * by for loops that are marked independent in the source code.
496 isl_set
*context_value
;
499 struct pet_type
**types
;
502 struct pet_array
**arrays
;
505 struct pet_stmt
**stmts
;
508 struct pet_implication
**implications
;
511 struct pet_independence
**independences
;
514 /* Return a textual representation of the operator. */
515 const char *pet_op_str(enum pet_op_type op
);
516 int pet_op_is_inc_dec(enum pet_op_type op
);
518 /* Extract a pet_scop from a C source file.
519 * If function is not NULL, then the pet_scop is extracted from
520 * a function with that name.
522 struct pet_scop
*pet_scop_extract_from_C_source(isl_ctx
*ctx
,
523 const char *filename
, const char *function
);
525 /* Transform the C source file "input" by rewriting each scop
526 * When autodetecting scops, at most one scop per function is rewritten.
527 * The transformed C code is written to "output".
529 int pet_transform_C_source(isl_ctx
*ctx
, const char *input
, FILE *output
,
530 __isl_give isl_printer
*(*transform
)(__isl_take isl_printer
*p
,
531 struct pet_scop
*scop
, void *user
), void *user
);
532 /* Given a scop and a printer passed to a pet_transform_C_source callback,
533 * print the original corresponding code to the printer.
535 __isl_give isl_printer
*pet_scop_print_original(struct pet_scop
*scop
,
536 __isl_take isl_printer
*p
);
538 /* Update all isl_sets and isl_maps such that they all have the same
539 * parameters in the same order.
541 struct pet_scop
*pet_scop_align_params(struct pet_scop
*scop
);
543 /* Does "scop" contain any data dependent accesses? */
544 int pet_scop_has_data_dependent_accesses(struct pet_scop
*scop
);
545 /* Does "scop" contain any data dependent conditions? */
546 int pet_scop_has_data_dependent_conditions(struct pet_scop
*scop
);
547 /* pet_stmt_build_ast_exprs is currently limited to only handle
548 * some forms of data dependent accesses.
549 * If pet_scop_can_build_ast_exprs returns 1, then pet_stmt_build_ast_exprs
550 * can safely be called on all statements in the scop.
552 int pet_scop_can_build_ast_exprs(struct pet_scop
*scop
);
554 void pet_scop_dump(struct pet_scop
*scop
);
555 struct pet_scop
*pet_scop_free(struct pet_scop
*scop
);
557 __isl_give isl_union_set
*pet_scop_collect_domains(struct pet_scop
*scop
);
558 /* Collect all potential read access relations. */
559 __isl_give isl_union_map
*pet_scop_collect_may_reads(struct pet_scop
*scop
);
560 /* Collect all tagged potential read access relations. */
561 __isl_give isl_union_map
*pet_scop_collect_tagged_may_reads(
562 struct pet_scop
*scop
);
563 /* Collect all potential write access relations. */
564 __isl_give isl_union_map
*pet_scop_collect_may_writes(struct pet_scop
*scop
);
565 /* Collect all definite write access relations. */
566 __isl_give isl_union_map
*pet_scop_collect_must_writes(struct pet_scop
*scop
);
567 /* Collect all tagged potential write access relations. */
568 __isl_give isl_union_map
*pet_scop_collect_tagged_may_writes(
569 struct pet_scop
*scop
);
570 /* Collect all tagged definite write access relations. */
571 __isl_give isl_union_map
*pet_scop_collect_tagged_must_writes(
572 struct pet_scop
*scop
);
573 /* Collect all definite kill access relations. */
574 __isl_give isl_union_map
*pet_scop_collect_must_kills(struct pet_scop
*scop
);
575 /* Collect all tagged definite kill access relations. */
576 __isl_give isl_union_map
*pet_scop_collect_tagged_must_kills(
577 struct pet_scop
*scop
);
578 __isl_give isl_union_map
*pet_scop_collect_schedule(struct pet_scop
*scop
);
580 /* Compute a mapping from all outermost arrays (of structs) in scop
581 * to their innermost members.
583 __isl_give isl_union_map
*pet_scop_compute_outer_to_inner(
584 struct pet_scop
*scop
);
585 /* Compute a mapping from all outermost arrays (of structs) in scop
586 * to their members, including the outermost arrays themselves.
588 __isl_give isl_union_map
*pet_scop_compute_outer_to_any(struct pet_scop
*scop
);
590 #if defined(__cplusplus)