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>
13 #include <isl/schedule.h>
15 #if defined(__cplusplus)
20 ISL_ARG_DECL(pet_options
, struct pet_options
, pet_options_args
)
22 /* Create an isl_ctx that references the pet options. */
23 isl_ctx
*isl_ctx_alloc_with_pet_options();
25 /* If autodetect is set, any valid scop is extracted.
26 * Otherwise, the scop needs to be delimited by pragmas.
28 int pet_options_set_autodetect(isl_ctx
*ctx
, int val
);
29 int pet_options_get_autodetect(isl_ctx
*ctx
);
31 int pet_options_set_detect_conditional_assignment(isl_ctx
*ctx
, int val
);
32 int pet_options_get_detect_conditional_assignment(isl_ctx
*ctx
);
34 /* If encapsulate-dynamic-control is set, then any dynamic control
35 * in the input program will be encapsulated in macro statements.
36 * This means in particular that no statements with arguments
39 int pet_options_set_encapsulate_dynamic_control(isl_ctx
*ctx
, int val
);
40 int pet_options_get_encapsulate_dynamic_control(isl_ctx
*ctx
);
42 #define PET_OVERFLOW_AVOID 0
43 #define PET_OVERFLOW_IGNORE 1
44 int pet_options_set_signed_overflow(isl_ctx
*ctx
, int val
);
45 int pet_options_get_signed_overflow(isl_ctx
*ctx
);
48 typedef struct pet_loc pet_loc
;
50 /* Return an additional reference to "loc". */
51 __isl_give pet_loc
*pet_loc_copy(__isl_keep pet_loc
*loc
);
52 /* Free a reference to "loc". */
53 pet_loc
*pet_loc_free(__isl_take pet_loc
*loc
);
55 /* Return the offset in the input file of the start of "loc". */
56 unsigned pet_loc_get_start(__isl_keep pet_loc
*loc
);
57 /* Return the offset in the input file of the character after "loc". */
58 unsigned pet_loc_get_end(__isl_keep pet_loc
*loc
);
59 /* Return the line number of a line within the "loc" region. */
60 int pet_loc_get_line(__isl_keep pet_loc
*loc
);
61 /* Return the indentation of the "loc" region. */
62 __isl_keep
const char *pet_loc_get_indent(__isl_keep pet_loc
*loc
);
75 /* only compound assignments operators before assignment */
113 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
115 enum pet_un_arg_type
{
119 /* Indices into the pet_expr->args array when
120 * pet_expr->type == pet_expr_binary
122 enum pet_bin_arg_type
{
127 /* Indices into the pet_expr->args array when
128 * pet_expr->type == pet_expr_ternary
130 enum pet_ter_arg_type
{
137 typedef struct pet_expr pet_expr
;
139 /* Return an additional reference to "expr". */
140 __isl_give pet_expr
*pet_expr_copy(__isl_keep pet_expr
*expr
);
141 /* Free a reference to "expr". */
142 __isl_null pet_expr
*pet_expr_free(__isl_take pet_expr
*expr
);
144 /* Return the isl_ctx in which "expr" was created. */
145 isl_ctx
*pet_expr_get_ctx(__isl_keep pet_expr
*expr
);
147 /* Return the type of "expr". */
148 enum pet_expr_type
pet_expr_get_type(__isl_keep pet_expr
*expr
);
149 /* Return the number of arguments of "expr". */
150 int pet_expr_get_n_arg(__isl_keep pet_expr
*expr
);
151 /* Set the number of arguments of "expr" to "n". */
152 __isl_give pet_expr
*pet_expr_set_n_arg(__isl_take pet_expr
*expr
, int n
);
153 /* Return the argument of "expr" at position "pos". */
154 __isl_give pet_expr
*pet_expr_get_arg(__isl_keep pet_expr
*expr
, int pos
);
155 /* Replace the argument of "expr" at position "pos" by "arg". */
156 __isl_give pet_expr
*pet_expr_set_arg(__isl_take pet_expr
*expr
, int pos
,
157 __isl_take pet_expr
*arg
);
159 /* Return the operation type of operation expression "expr". */
160 enum pet_op_type
pet_expr_op_get_type(__isl_keep pet_expr
*expr
);
161 /* Replace the operation type of operation expression "expr" by "type". */
162 __isl_give pet_expr
*pet_expr_op_set_type(__isl_take pet_expr
*expr
,
163 enum pet_op_type type
);
165 /* Construct a (read) access pet_expr from an index expression. */
166 __isl_give pet_expr
*pet_expr_from_index(__isl_take isl_multi_pw_aff
*index
);
168 /* Does "expr" represent an affine expression? */
169 isl_bool
pet_expr_is_affine(__isl_keep pet_expr
*expr
);
170 /* Does the access expression "expr" read the accessed elements? */
171 isl_bool
pet_expr_access_is_read(__isl_keep pet_expr
*expr
);
172 /* Does the access expression "expr" write to the accessed elements? */
173 isl_bool
pet_expr_access_is_write(__isl_keep pet_expr
*expr
);
174 /* Does the access expression "expr" kill the accessed elements? */
175 isl_bool
pet_expr_access_is_kill(__isl_keep pet_expr
*expr
);
176 /* Mark "expr" as a read depending on "read". */
177 __isl_give pet_expr
*pet_expr_access_set_read(__isl_take pet_expr
*expr
,
179 /* Mark "expr" as a write depending on "write". */
180 __isl_give pet_expr
*pet_expr_access_set_write(__isl_take pet_expr
*expr
,
182 /* Mark "expr" as a kill depending on "kill". */
183 __isl_give pet_expr
*pet_expr_access_set_kill(__isl_take pet_expr
*expr
,
185 /* Return the reference identifier of access expression "expr". */
186 __isl_give isl_id
*pet_expr_access_get_ref_id(__isl_keep pet_expr
*expr
);
187 /* Replace the reference identifier of access expression "expr" by "ref_id". */
188 __isl_give pet_expr
*pet_expr_access_set_ref_id(__isl_take pet_expr
*expr
,
189 __isl_take isl_id
*ref_id
);
190 /* Return the identifier of the outer array accessed by "expr". */
191 __isl_give isl_id
*pet_expr_access_get_id(__isl_keep pet_expr
*expr
);
192 /* Return the index expression of access expression "expr". */
193 __isl_give isl_multi_pw_aff
*pet_expr_access_get_index(
194 __isl_keep pet_expr
*expr
);
196 /* Return the potential read access relation of access expression "expr". */
197 __isl_give isl_union_map
*pet_expr_access_get_may_read(
198 __isl_keep pet_expr
*expr
);
199 /* Return the potential write access relation of access expression "expr". */
200 __isl_give isl_union_map
*pet_expr_access_get_may_write(
201 __isl_keep pet_expr
*expr
);
202 /* Return the definite write access relation of access expression "expr". */
203 __isl_give isl_union_map
*pet_expr_access_get_must_write(
204 __isl_keep pet_expr
*expr
);
205 /* Return the argument dependent potential read access relation of "expr". */
206 __isl_give isl_union_map
*pet_expr_access_get_dependent_may_read(
207 __isl_keep pet_expr
*expr
);
208 /* Return the argument dependent potential write access relation of "expr". */
209 __isl_give isl_union_map
*pet_expr_access_get_dependent_may_write(
210 __isl_keep pet_expr
*expr
);
211 /* Return the argument dependent definite write access relation of "expr". */
212 __isl_give isl_union_map
*pet_expr_access_get_dependent_must_write(
213 __isl_keep pet_expr
*expr
);
214 /* Return the tagged potential read access relation of access "expr". */
215 __isl_give isl_union_map
*pet_expr_access_get_tagged_may_read(
216 __isl_keep pet_expr
*expr
);
217 /* Return the tagged potential write access relation of access "expr". */
218 __isl_give isl_union_map
*pet_expr_access_get_tagged_may_write(
219 __isl_keep pet_expr
*expr
);
221 /* Return the name of the function called by "expr". */
222 __isl_keep
const char *pet_expr_call_get_name(__isl_keep pet_expr
*expr
);
223 /* Replace the name of the function called by "expr" by "name". */
224 __isl_give pet_expr
*pet_expr_call_set_name(__isl_take pet_expr
*expr
,
225 __isl_keep
const char *name
);
227 /* Create a pet_expr representing a cast of "arg" to "type_name". */
228 __isl_give pet_expr
*pet_expr_new_cast(const char *type_name
,
229 __isl_take pet_expr
*arg
);
230 /* Replace the type of the cast performed by "expr" by "name". */
231 __isl_give pet_expr
*pet_expr_cast_set_type_name(__isl_take pet_expr
*expr
,
232 __isl_keep
const char *name
);
234 /* Return the value of the integer represented by "expr". */
235 __isl_give isl_val
*pet_expr_int_get_val(__isl_keep pet_expr
*expr
);
236 /* Replace the value of the integer represented by "expr" by "v". */
237 __isl_give pet_expr
*pet_expr_int_set_val(__isl_take pet_expr
*expr
,
238 __isl_take isl_val
*v
);
240 /* Return a string representation of the double expression "expr". */
241 __isl_give
char *pet_expr_double_get_str(__isl_keep pet_expr
*expr
);
242 /* Replace value and string representation of the double expression "expr" */
243 __isl_give pet_expr
*pet_expr_double_set(__isl_take pet_expr
*expr
,
244 double d
, __isl_keep
const char *s
);
246 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_access. */
247 int pet_expr_foreach_access_expr(__isl_keep pet_expr
*expr
,
248 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
249 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_call. */
250 int pet_expr_foreach_call_expr(__isl_keep pet_expr
*expr
,
251 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
254 typedef struct pet_context pet_context
;
256 /* Create a context with the given domain. */
257 __isl_give pet_context
*pet_context_alloc(__isl_take isl_set
*domain
);
258 /* Return an additional reference to "pc". */
259 __isl_give pet_context
*pet_context_copy(__isl_keep pet_context
*pc
);
260 /* Free a reference to "pc". */
261 __isl_null pet_context
*pet_context_free(__isl_take pet_context
*pc
);
263 /* Return the isl_ctx in which "pc" was created. */
264 isl_ctx
*pet_context_get_ctx(__isl_keep pet_context
*pc
);
266 /* Extract an affine expression defined over the domain of "pc" from "expr"
269 __isl_give isl_pw_aff
*pet_expr_extract_affine(__isl_keep pet_expr
*expr
,
270 __isl_keep pet_context
*pc
);
272 void pet_expr_dump(__isl_keep pet_expr
*expr
);
280 pet_tree_decl
, /* A declaration without initialization */
281 pet_tree_decl_init
, /* A declaration with initialization */
282 pet_tree_if
, /* An if without an else branch */
283 pet_tree_if_else
, /* An if with an else branch */
285 pet_tree_infinite_loop
,
290 typedef struct pet_tree pet_tree
;
292 /* Return the isl_ctx in which "tree" was created. */
293 isl_ctx
*pet_tree_get_ctx(__isl_keep pet_tree
*tree
);
295 /* Return an additional reference to "tree". */
296 __isl_give pet_tree
*pet_tree_copy(__isl_keep pet_tree
*tree
);
297 /* Free a reference to "tree". */
298 __isl_null pet_tree
*pet_tree_free(__isl_take pet_tree
*tree
);
300 /* Return the location of "tree". */
301 __isl_give pet_loc
*pet_tree_get_loc(__isl_keep pet_tree
*tree
);
303 /* Return the type of "tree". */
304 enum pet_tree_type
pet_tree_get_type(__isl_keep pet_tree
*tree
);
306 /* Return the expression of the expression tree "tree". */
307 __isl_give pet_expr
*pet_tree_expr_get_expr(__isl_keep pet_tree
*tree
);
309 /* Return the number of children of the block tree "tree". */
310 int pet_tree_block_n_child(__isl_keep pet_tree
*tree
);
311 /* Return child "pos" of the block tree "tree". */
312 __isl_give pet_tree
*pet_tree_block_get_child(__isl_keep pet_tree
*tree
,
315 /* Is "tree" a declaration (with or without initialization)? */
316 int pet_tree_is_decl(__isl_keep pet_tree
*tree
);
317 /* Return the variable declared by the declaration tree "tree". */
318 __isl_give pet_expr
*pet_tree_decl_get_var(__isl_keep pet_tree
*tree
);
319 /* Return the initial value of the pet_tree_decl_init tree "tree". */
320 __isl_give pet_expr
*pet_tree_decl_get_init(__isl_keep pet_tree
*tree
);
322 /* Return the condition of the if tree "tree". */
323 __isl_give pet_expr
*pet_tree_if_get_cond(__isl_keep pet_tree
*tree
);
324 /* Return the then branch of the if tree "tree". */
325 __isl_give pet_tree
*pet_tree_if_get_then(__isl_keep pet_tree
*tree
);
326 /* Return the else branch of the if tree with else branch "tree". */
327 __isl_give pet_tree
*pet_tree_if_get_else(__isl_keep pet_tree
*tree
);
329 /* Is "tree" a for loop, a while loop or an infinite loop? */
330 int pet_tree_is_loop(__isl_keep pet_tree
*tree
);
331 /* Return the induction variable of the for loop "tree" */
332 __isl_give pet_expr
*pet_tree_loop_get_var(__isl_keep pet_tree
*tree
);
333 /* Return the initial value of the induction variable of the for loop "tree" */
334 __isl_give pet_expr
*pet_tree_loop_get_init(__isl_keep pet_tree
*tree
);
335 /* Return the condition of the loop tree "tree" */
336 __isl_give pet_expr
*pet_tree_loop_get_cond(__isl_keep pet_tree
*tree
);
337 /* Return the induction variable of the for loop "tree" */
338 __isl_give pet_expr
*pet_tree_loop_get_inc(__isl_keep pet_tree
*tree
);
339 /* Return the body of the loop tree "tree" */
340 __isl_give pet_tree
*pet_tree_loop_get_body(__isl_keep pet_tree
*tree
);
342 /* Call "fn" on each top-level expression in the nodes of "tree" */
343 int pet_tree_foreach_expr(__isl_keep pet_tree
*tree
,
344 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
345 /* Call "fn" on each access subexpression in the nodes of "tree" */
346 int pet_tree_foreach_access_expr(__isl_keep pet_tree
*tree
,
347 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
348 /* Modify all call subexpressions in the nodes of "tree" through "fn". */
349 __isl_give pet_tree
*pet_tree_map_call_expr(__isl_take pet_tree
*tree
,
350 __isl_give pet_expr
*(*fn
)(__isl_take pet_expr
*expr
, void *user
),
353 void pet_tree_dump(__isl_keep pet_tree
*tree
);
355 /* "loc" represents the region of the source code that is represented
358 * If the statement has arguments, i.e., n_arg != 0, then
359 * "domain" is a wrapped map, mapping the iteration domain
360 * to the values of the arguments for which this statement
362 * Otherwise, it is simply the iteration domain.
364 * If one of the arguments is an access expression that accesses
365 * more than one element for a given iteration, then the constraints
366 * on the value of this argument (encoded in "domain") should be satisfied
367 * for all of those accessed elements.
378 /* Return the iteration space of "stmt". */
379 __isl_give isl_space
*pet_stmt_get_space(struct pet_stmt
*stmt
);
381 /* Is "stmt" an assignment statement? */
382 int pet_stmt_is_assign(struct pet_stmt
*stmt
);
383 /* Is "stmt" a kill statement? */
384 int pet_stmt_is_kill(struct pet_stmt
*stmt
);
386 /* pet_stmt_build_ast_exprs is currently limited to only handle
387 * some forms of data dependent accesses.
388 * If pet_stmt_can_build_ast_exprs returns 1, then pet_stmt_build_ast_exprs
389 * can safely be called on "stmt".
391 int pet_stmt_can_build_ast_exprs(struct pet_stmt
*stmt
);
392 /* Construct an associative array from reference identifiers of
393 * access expressions in "stmt" to the corresponding isl_ast_expr.
394 * Each index expression is first transformed through "fn_index"
395 * (if not NULL). Then an AST expression is generated using "build".
396 * Finally, the AST expression is transformed using "fn_expr"
399 __isl_give isl_id_to_ast_expr
*pet_stmt_build_ast_exprs(struct pet_stmt
*stmt
,
400 __isl_keep isl_ast_build
*build
,
401 __isl_give isl_multi_pw_aff
*(*fn_index
)(
402 __isl_take isl_multi_pw_aff
*mpa
, __isl_keep isl_id
*id
,
403 void *user
), void *user_index
,
404 __isl_give isl_ast_expr
*(*fn_expr
)(__isl_take isl_ast_expr
*expr
,
405 __isl_keep isl_id
*id
, void *user
), void *user_expr
);
407 /* Print "stmt" to "p".
409 * The access expressions in "stmt" are replaced by the isl_ast_expr
410 * associated to its reference identifier in "ref2expr".
412 __isl_give isl_printer
*pet_stmt_print_body(struct pet_stmt
*stmt
,
413 __isl_take isl_printer
*p
, __isl_keep isl_id_to_ast_expr
*ref2expr
);
415 /* This structure represents a defined type.
416 * "name" is the name of the type, while "definition" is a string
417 * representation of its definition.
424 /* context holds constraints on the parameter that ensure that
425 * this array has a valid (i.e., non-negative) size
427 * extent holds constraints on the indices
429 * value_bounds holds constraints on the elements of the array
430 * and may be NULL if no such constraints were specified by the user
432 * element_size is the size in bytes of each array element
433 * element_type is the type of the array elements.
434 * element_is_record is set if this type is a record type.
436 * live_out is set if the array appears in a live-out pragma
438 * if uniquely_defined is set then the array is written by a single access
439 * such that any element that is ever read
440 * is known to be assigned exactly once before the read
442 * declared is set if the array was declared somewhere inside the scop.
443 * exposed is set if the declared array is visible outside the scop.
448 isl_set
*value_bounds
;
450 int element_is_record
;
453 int uniquely_defined
;
458 /* This structure represents an implication on a boolean filter.
459 * In particular, if the filter value of an element in the domain
460 * of "extension" is equal to "satisfied", then the filter values
461 * of the corresponding images in "extension" are also equal
464 struct pet_implication
{
469 /* This structure represents an independence implied by a for loop
470 * that is marked as independent in the source code.
471 * "filter" contains pairs of statement instances that are guaranteed
472 * not to be dependent on each other based on the independent for loop,
473 * assuming that no dependences carried by this loop are implied
474 * by the variables in "local".
475 * "local" contains the variables that are local to the loop that was
476 * marked independent.
478 struct pet_independence
{
479 isl_union_map
*filter
;
480 isl_union_set
*local
;
483 /* "loc" represents the region of the source code that is represented
485 * If the scop was detected based on scop and endscop pragmas, then
486 * the lines containing these pragmas are included in this region.
487 * In the final result, the context describes the set of parameter values
488 * for which the scop can be executed.
489 * During the construction of the pet_scop, the context lives in a set space
490 * where each dimension refers to an outer loop.
491 * context_value describes assignments to the parameters (if any)
492 * outside of the scop.
494 * "schedule" is the schedule of the statements in the scop.
496 * The n_type types define types that may be referenced from by the arrays.
498 * The n_implication implications describe implications on boolean filters.
500 * The n_independence independences describe independences implied
501 * by for loops that are marked independent in the source code.
507 isl_set
*context_value
;
508 isl_schedule
*schedule
;
511 struct pet_type
**types
;
514 struct pet_array
**arrays
;
517 struct pet_stmt
**stmts
;
520 struct pet_implication
**implications
;
523 struct pet_independence
**independences
;
525 typedef struct pet_scop pet_scop
;
527 /* Return a textual representation of the operator. */
528 const char *pet_op_str(enum pet_op_type op
);
529 int pet_op_is_inc_dec(enum pet_op_type op
);
531 /* Extract a pet_scop from a C source file.
532 * If function is not NULL, then the pet_scop is extracted from
533 * a function with that name.
535 __isl_give pet_scop
*pet_scop_extract_from_C_source(isl_ctx
*ctx
,
536 const char *filename
, const char *function
);
538 /* Transform the C source file "input" by rewriting each scop
539 * When autodetecting scops, at most one scop per function is rewritten.
540 * The transformed C code is written to "output".
542 int pet_transform_C_source(isl_ctx
*ctx
, const char *input
, FILE *output
,
543 __isl_give isl_printer
*(*transform
)(__isl_take isl_printer
*p
,
544 __isl_take pet_scop
*scop
, void *user
), void *user
);
545 /* Given a scop and a printer passed to a pet_transform_C_source callback,
546 * print the original corresponding code to the printer.
548 __isl_give isl_printer
*pet_scop_print_original(__isl_keep pet_scop
*scop
,
549 __isl_take isl_printer
*p
);
551 /* Update all isl_sets and isl_maps such that they all have the same
552 * parameters in the same order.
554 __isl_give pet_scop
*pet_scop_align_params(__isl_take pet_scop
*scop
);
556 /* Does "scop" contain any data dependent accesses? */
557 int pet_scop_has_data_dependent_accesses(__isl_keep pet_scop
*scop
);
558 /* Does "scop" contain any data dependent conditions? */
559 int pet_scop_has_data_dependent_conditions(__isl_keep pet_scop
*scop
);
560 /* pet_stmt_build_ast_exprs is currently limited to only handle
561 * some forms of data dependent accesses.
562 * If pet_scop_can_build_ast_exprs returns 1, then pet_stmt_build_ast_exprs
563 * can safely be called on all statements in the scop.
565 int pet_scop_can_build_ast_exprs(__isl_keep pet_scop
*scop
);
567 void pet_scop_dump(__isl_keep pet_scop
*scop
);
568 __isl_null pet_scop
*pet_scop_free(__isl_take pet_scop
*scop
);
570 /* Return the context of "scop". */
571 __isl_give isl_set
*pet_scop_get_context(__isl_keep pet_scop
*scop
);
572 /* Return the schedule of "scop". */
573 __isl_give isl_schedule
*pet_scop_get_schedule(__isl_keep pet_scop
*scop
);
574 /* Return the set of all statement instances. */
575 __isl_give isl_union_set
*pet_scop_get_instance_set(__isl_keep pet_scop
*scop
);
576 /* Return the potential read access relation. */
577 __isl_give isl_union_map
*pet_scop_get_may_reads(__isl_keep pet_scop
*scop
);
578 /* Return the tagged potential read access relation. */
579 __isl_give isl_union_map
*pet_scop_get_tagged_may_reads(
580 __isl_keep pet_scop
*scop
);
581 /* Return the potential write access relation. */
582 __isl_give isl_union_map
*pet_scop_get_may_writes(__isl_keep pet_scop
*scop
);
583 /* Return the definite write access relation. */
584 __isl_give isl_union_map
*pet_scop_get_must_writes(__isl_keep pet_scop
*scop
);
585 /* Return the tagged potential write access relation. */
586 __isl_give isl_union_map
*pet_scop_get_tagged_may_writes(
587 __isl_keep pet_scop
*scop
);
588 /* Return the tagged definite write access relation. */
589 __isl_give isl_union_map
*pet_scop_get_tagged_must_writes(
590 __isl_keep pet_scop
*scop
);
591 /* Return the definite kill access relation. */
592 __isl_give isl_union_map
*pet_scop_get_must_kills(__isl_keep pet_scop
*scop
);
593 /* Return the tagged definite kill access relation. */
594 __isl_give isl_union_map
*pet_scop_get_tagged_must_kills(
595 __isl_keep pet_scop
*scop
);
597 /* Compute a mapping from all outermost arrays (of structs) in scop
598 * to their innermost members.
600 __isl_give isl_union_map
*pet_scop_compute_outer_to_inner(
601 __isl_keep pet_scop
*scop
);
602 /* Compute a mapping from all outermost arrays (of structs) in scop
603 * to their members, including the outermost arrays themselves.
605 __isl_give isl_union_map
*pet_scop_compute_outer_to_any(
606 __isl_keep pet_scop
*scop
);
608 #if defined(__cplusplus)