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>
13 #if defined(__cplusplus)
18 ISL_ARG_DECL(pet_options
, struct pet_options
, pet_options_args
)
20 /* If autodetect is set, any valid scop is extracted.
21 * Otherwise, the scop needs to be delimited by pragmas.
23 int pet_options_set_autodetect(isl_ctx
*ctx
, int val
);
24 int pet_options_get_autodetect(isl_ctx
*ctx
);
26 int pet_options_set_detect_conditional_assignment(isl_ctx
*ctx
, int val
);
27 int pet_options_get_detect_conditional_assignment(isl_ctx
*ctx
);
29 #define PET_OVERFLOW_AVOID 0
30 #define PET_OVERFLOW_IGNORE 1
31 int pet_options_set_signed_overflow(isl_ctx
*ctx
, int val
);
32 int pet_options_get_signed_overflow(isl_ctx
*ctx
);
35 typedef struct pet_loc pet_loc
;
37 /* Return an additional reference to "loc". */
38 __isl_give pet_loc
*pet_loc_copy(__isl_keep pet_loc
*loc
);
39 /* Free a reference to "loc". */
40 pet_loc
*pet_loc_free(__isl_take pet_loc
*loc
);
42 /* Return the offset in the input file of the start of "loc". */
43 unsigned pet_loc_get_start(__isl_keep pet_loc
*loc
);
44 /* Return the offset in the input file of the character after "loc". */
45 unsigned pet_loc_get_end(__isl_keep pet_loc
*loc
);
46 /* Return the line number of a line within the "loc" region. */
47 int pet_loc_get_line(__isl_keep pet_loc
*loc
);
60 /* only compound assignments operators before assignment */
98 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
100 enum pet_un_arg_type
{
104 /* Indices into the pet_expr->args array when
105 * pet_expr->type == pet_expr_binary
107 enum pet_bin_arg_type
{
112 /* Indices into the pet_expr->args array when
113 * pet_expr->type == pet_expr_ternary
115 enum pet_ter_arg_type
{
122 typedef struct pet_expr pet_expr
;
124 /* Return an additional reference to "expr". */
125 __isl_give pet_expr
*pet_expr_copy(__isl_keep pet_expr
*expr
);
126 /* Free a reference to "expr". */
127 __isl_null pet_expr
*pet_expr_free(__isl_take pet_expr
*expr
);
129 /* Return the isl_ctx in which "expr" was created. */
130 isl_ctx
*pet_expr_get_ctx(__isl_keep pet_expr
*expr
);
132 /* Return the type of "expr". */
133 enum pet_expr_type
pet_expr_get_type(__isl_keep pet_expr
*expr
);
134 /* Return the number of arguments of "expr". */
135 int pet_expr_get_n_arg(__isl_keep pet_expr
*expr
);
136 /* Set the number of arguments of "expr" to "n". */
137 __isl_give pet_expr
*pet_expr_set_n_arg(__isl_take pet_expr
*expr
, int n
);
138 /* Return the argument of "expr" at position "pos". */
139 __isl_give pet_expr
*pet_expr_get_arg(__isl_keep pet_expr
*expr
, int pos
);
140 /* Replace the argument of "expr" at position "pos" by "arg". */
141 __isl_give pet_expr
*pet_expr_set_arg(__isl_take pet_expr
*expr
, int pos
,
142 __isl_take pet_expr
*arg
);
144 /* Return the operation type of operation expression "expr". */
145 enum pet_op_type
pet_expr_op_get_type(__isl_keep pet_expr
*expr
);
146 /* Replace the operation type of operation expression "expr" by "type". */
147 __isl_give pet_expr
*pet_expr_op_set_type(__isl_take pet_expr
*expr
,
148 enum pet_op_type type
);
150 /* Construct a (read) access pet_expr from an index expression. */
151 __isl_give pet_expr
*pet_expr_from_index(__isl_take isl_multi_pw_aff
*index
);
153 /* Does "expr" represent an affine expression? */
154 int pet_expr_is_affine(__isl_keep pet_expr
*expr
);
155 /* Does the access expression "expr" read the accessed elements? */
156 int pet_expr_access_is_read(__isl_keep pet_expr
*expr
);
157 /* Does the access expression "expr" write to the accessed elements? */
158 int pet_expr_access_is_write(__isl_keep pet_expr
*expr
);
159 /* Mark "expr" as a read dependening on "read". */
160 __isl_give pet_expr
*pet_expr_access_set_read(__isl_take pet_expr
*expr
,
162 /* Mark "expr" as a write dependening on "write". */
163 __isl_give pet_expr
*pet_expr_access_set_write(__isl_take pet_expr
*expr
,
165 /* Return the reference identifier of access expression "expr". */
166 __isl_give isl_id
*pet_expr_access_get_ref_id(__isl_keep pet_expr
*expr
);
167 /* Replace the reference identifier of access expression "expr" by "ref_id". */
168 __isl_give pet_expr
*pet_expr_access_set_ref_id(__isl_take pet_expr
*expr
,
169 __isl_take isl_id
*ref_id
);
170 /* Return the identifier of the outer array accessed by "expr". */
171 __isl_give isl_id
*pet_expr_access_get_id(__isl_keep pet_expr
*expr
);
172 /* Return the index expression of access expression "expr". */
173 __isl_give isl_multi_pw_aff
*pet_expr_access_get_index(
174 __isl_keep pet_expr
*expr
);
176 /* Return the potential read access relation of access expression "expr". */
177 __isl_give isl_map
*pet_expr_access_get_may_access(__isl_keep pet_expr
*expr
);
178 /* Return the definite access relation of access expression "expr". */
179 __isl_give isl_map
*pet_expr_access_get_must_access(__isl_keep pet_expr
*expr
);
180 /* Return the argument dependent access relation of access expression "expr". */
181 __isl_give isl_map
*pet_expr_access_get_dependent_access(
182 __isl_keep pet_expr
*expr
);
183 /* Return the tagged potential read access relation of access "expr". */
184 __isl_give isl_map
*pet_expr_access_get_tagged_may_access(
185 __isl_keep pet_expr
*expr
);
187 /* Return the name of the function called by "expr". */
188 __isl_keep
const char *pet_expr_call_get_name(__isl_keep pet_expr
*expr
);
189 /* Replace the name of the function called by "expr" by "name". */
190 __isl_give pet_expr
*pet_expr_call_set_name(__isl_take pet_expr
*expr
,
191 __isl_keep
const char *name
);
193 /* Replace the type of the cast performed by "expr" by "name". */
194 __isl_give pet_expr
*pet_expr_cast_set_type_name(__isl_take pet_expr
*expr
,
195 __isl_keep
const char *name
);
197 /* Return the value of the integer represented by "expr". */
198 __isl_give isl_val
*pet_expr_int_get_val(__isl_keep pet_expr
*expr
);
199 /* Replace the value of the integer represented by "expr" by "v". */
200 __isl_give pet_expr
*pet_expr_int_set_val(__isl_take pet_expr
*expr
,
201 __isl_take isl_val
*v
);
203 /* Return a string representation of the double expression "expr". */
204 __isl_give
char *pet_expr_double_get_str(__isl_keep pet_expr
*expr
);
205 /* Replace value and string representation of the double expression "expr" */
206 __isl_give pet_expr
*pet_expr_double_set(__isl_take pet_expr
*expr
,
207 double d
, __isl_keep
const char *s
);
209 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_access. */
210 int pet_expr_foreach_access_expr(__isl_keep pet_expr
*expr
,
211 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
212 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_call. */
213 int pet_expr_foreach_call_expr(__isl_keep pet_expr
*expr
,
214 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
216 void pet_expr_dump(__isl_keep pet_expr
*expr
);
224 pet_tree_decl
, /* A declaration without initialization */
225 pet_tree_decl_init
, /* A declaration with initialization */
226 pet_tree_if
, /* An if without an else branch */
227 pet_tree_if_else
, /* An if with an else branch */
229 pet_tree_infinite_loop
,
234 typedef struct pet_tree pet_tree
;
236 /* Return the isl_ctx in which "tree" was created. */
237 isl_ctx
*pet_tree_get_ctx(__isl_keep pet_tree
*tree
);
239 /* Return an additional reference to "tree". */
240 __isl_give pet_tree
*pet_tree_copy(__isl_keep pet_tree
*tree
);
241 /* Free a reference to "tree". */
242 __isl_null pet_tree
*pet_tree_free(__isl_take pet_tree
*tree
);
244 /* Return the location of "tree". */
245 __isl_give pet_loc
*pet_tree_get_loc(__isl_keep pet_tree
*tree
);
247 /* Return the type of "tree". */
248 enum pet_tree_type
pet_tree_get_type(__isl_keep pet_tree
*tree
);
250 /* Return the expression of the expression tree "tree". */
251 __isl_give pet_expr
*pet_tree_expr_get_expr(__isl_keep pet_tree
*tree
);
253 /* Return the number of children of the block tree "tree". */
254 int pet_tree_block_n_child(__isl_keep pet_tree
*tree
);
255 /* Return child "pos" of the block tree "tree". */
256 __isl_give pet_tree
*pet_tree_block_get_child(__isl_keep pet_tree
*tree
,
259 /* Is "tree" a declaration (with or without initialization)? */
260 int pet_tree_is_decl(__isl_keep pet_tree
*tree
);
261 /* Return the variable declared by the declaration tree "tree". */
262 __isl_give pet_expr
*pet_tree_decl_get_var(__isl_keep pet_tree
*tree
);
263 /* Return the initial value of the pet_tree_decl_init tree "tree". */
264 __isl_give pet_expr
*pet_tree_decl_get_init(__isl_keep pet_tree
*tree
);
266 /* Return the condition of the if tree "tree". */
267 __isl_give pet_expr
*pet_tree_if_get_cond(__isl_keep pet_tree
*tree
);
268 /* Return the then branch of the if tree "tree". */
269 __isl_give pet_tree
*pet_tree_if_get_then(__isl_keep pet_tree
*tree
);
270 /* Return the else branch of the if tree with else branch "tree". */
271 __isl_give pet_tree
*pet_tree_if_get_else(__isl_keep pet_tree
*tree
);
273 /* Is "tree" a for loop, a while loop or an infinite loop? */
274 int pet_tree_is_loop(__isl_keep pet_tree
*tree
);
275 /* Return the induction variable of the for loop "tree" */
276 __isl_give pet_expr
*pet_tree_loop_get_var(__isl_keep pet_tree
*tree
);
277 /* Return the initial value of the induction variable of the for loop "tree" */
278 __isl_give pet_expr
*pet_tree_loop_get_init(__isl_keep pet_tree
*tree
);
279 /* Return the condition of the loop tree "tree" */
280 __isl_give pet_expr
*pet_tree_loop_get_cond(__isl_keep pet_tree
*tree
);
281 /* Return the induction variable of the for loop "tree" */
282 __isl_give pet_expr
*pet_tree_loop_get_inc(__isl_keep pet_tree
*tree
);
283 /* Return the body of the loop tree "tree" */
284 __isl_give pet_tree
*pet_tree_loop_get_body(__isl_keep pet_tree
*tree
);
286 /* Call "fn" on each top-level expression in the nodes of "tree" */
287 int pet_tree_foreach_expr(__isl_keep pet_tree
*tree
,
288 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
289 /* Call "fn" on each access subexpression in the nodes of "tree" */
290 int pet_tree_foreach_access_expr(__isl_keep pet_tree
*tree
,
291 int (*fn
)(__isl_keep pet_expr
*expr
, void *user
), void *user
);
293 void pet_tree_dump(__isl_keep pet_tree
*tree
);
295 /* "loc" represents the region of the source code that is represented
298 * If the statement has arguments, i.e., n_arg != 0, then
299 * "domain" is a wrapped map, mapping the iteration domain
300 * to the values of the arguments for which this statement
302 * Otherwise, it is simply the iteration domain.
304 * If one of the arguments is an access expression that accesses
305 * more than one element for a given iteration, then the constraints
306 * on the value of this argument (encoded in "domain") should be satisfied
307 * for all of those accessed elements.
319 /* Return the iteration space of "stmt". */
320 __isl_give isl_space
*pet_stmt_get_space(struct pet_stmt
*stmt
);
322 /* Is "stmt" an assignment statement? */
323 int pet_stmt_is_assign(struct pet_stmt
*stmt
);
324 /* Is "stmt" a kill statement? */
325 int pet_stmt_is_kill(struct pet_stmt
*stmt
);
327 /* pet_stmt_build_ast_exprs is currently limited to only handle
328 * some forms of data dependent accesses.
329 * If pet_stmt_can_build_ast_exprs returns 1, then pet_stmt_build_ast_exprs
330 * can safely be called on "stmt".
332 int pet_stmt_can_build_ast_exprs(struct pet_stmt
*stmt
);
333 /* Construct an associative array from reference identifiers of
334 * access expressions in "stmt" to the corresponding isl_ast_expr.
335 * Each index expression is first transformed through "fn_index"
336 * (if not NULL). Then an AST expression is generated using "build".
337 * Finally, the AST expression is transformed using "fn_expr"
340 __isl_give isl_id_to_ast_expr
*pet_stmt_build_ast_exprs(struct pet_stmt
*stmt
,
341 __isl_keep isl_ast_build
*build
,
342 __isl_give isl_multi_pw_aff
*(*fn_index
)(
343 __isl_take isl_multi_pw_aff
*mpa
, __isl_keep isl_id
*id
,
344 void *user
), void *user_index
,
345 __isl_give isl_ast_expr
*(*fn_expr
)(__isl_take isl_ast_expr
*expr
,
346 __isl_keep isl_id
*id
, void *user
), void *user_expr
);
348 /* Print "stmt" to "p".
350 * The access expressions in "stmt" are replaced by the isl_ast_expr
351 * associated to its reference identifier in "ref2expr".
353 __isl_give isl_printer
*pet_stmt_print_body(struct pet_stmt
*stmt
,
354 __isl_take isl_printer
*p
, __isl_keep isl_id_to_ast_expr
*ref2expr
);
356 /* This structure represents a defined type.
357 * "name" is the name of the type, while "definition" is a string
358 * representation of its definition.
365 /* context holds constraints on the parameter that ensure that
366 * this array has a valid (i.e., non-negative) size
368 * extent holds constraints on the indices
370 * value_bounds holds constraints on the elements of the array
371 * and may be NULL if no such constraints were specified by the user
373 * element_size is the size in bytes of each array element
374 * element_type is the type of the array elements.
375 * element_is_record is set if this type is a record type.
377 * live_out is set if the array appears in a live-out pragma
379 * if uniquely_defined is set then the array is written by a single access
380 * such that any element that is ever read
381 * is known to be assigned exactly once before the read
383 * declared is set if the array was declared somewhere inside the scop.
384 * exposed is set if the declared array is visible outside the scop.
389 isl_set
*value_bounds
;
391 int element_is_record
;
394 int uniquely_defined
;
399 /* This structure represents an implication on a boolean filter.
400 * In particular, if the filter value of an element in the domain
401 * of "extension" is equal to "satisfied", then the filter values
402 * of the corresponding images in "extension" are also equal
405 struct pet_implication
{
410 /* "loc" represents the region of the source code that is represented
412 * If the scop was detected based on scop and endscop pragmas, then
413 * the lines containing these pragmas are included in this region.
414 * The context describes the set of parameter values for which
415 * the scop can be executed.
416 * context_value describes assignments to the parameters (if any)
417 * outside of the scop.
419 * The n_type types define types that may be referenced from by the arrays.
421 * The n_implication implications describe implications on boolean filters.
427 isl_set
*context_value
;
430 struct pet_type
**types
;
433 struct pet_array
**arrays
;
436 struct pet_stmt
**stmts
;
439 struct pet_implication
**implications
;
442 /* Return a textual representation of the operator. */
443 const char *pet_op_str(enum pet_op_type op
);
444 int pet_op_is_inc_dec(enum pet_op_type op
);
446 /* Extract a pet_scop from a C source file.
447 * If function is not NULL, then the pet_scop is extracted from
448 * a function with that name.
450 struct pet_scop
*pet_scop_extract_from_C_source(isl_ctx
*ctx
,
451 const char *filename
, const char *function
);
453 /* Transform the C source file "input" by rewriting each scop
454 * When autodetecting scops, at most one scop per function is rewritten.
455 * The transformed C code is written to "output".
457 int pet_transform_C_source(isl_ctx
*ctx
, const char *input
, FILE *output
,
458 __isl_give isl_printer
*(*transform
)(__isl_take isl_printer
*p
,
459 struct pet_scop
*scop
, void *user
), void *user
);
460 /* Given a scop and a printer passed to a pet_transform_C_source callback,
461 * print the original corresponding code to the printer.
463 __isl_give isl_printer
*pet_scop_print_original(struct pet_scop
*scop
,
464 __isl_take isl_printer
*p
);
466 /* Update all isl_sets and isl_maps such that they all have the same
467 * parameters in the same order.
469 struct pet_scop
*pet_scop_align_params(struct pet_scop
*scop
);
471 /* Does "scop" contain any data dependent accesses? */
472 int pet_scop_has_data_dependent_accesses(struct pet_scop
*scop
);
473 /* Does "scop" contain any data dependent conditions? */
474 int pet_scop_has_data_dependent_conditions(struct pet_scop
*scop
);
475 /* pet_stmt_build_ast_exprs is currently limited to only handle
476 * some forms of data dependent accesses.
477 * If pet_scop_can_build_ast_exprs returns 1, then pet_stmt_build_ast_exprs
478 * can safely be called on all statements in the scop.
480 int pet_scop_can_build_ast_exprs(struct pet_scop
*scop
);
482 void pet_scop_dump(struct pet_scop
*scop
);
483 struct pet_scop
*pet_scop_free(struct pet_scop
*scop
);
485 __isl_give isl_union_set
*pet_scop_collect_domains(struct pet_scop
*scop
);
486 /* Collect all potential read access relations. */
487 __isl_give isl_union_map
*pet_scop_collect_may_reads(struct pet_scop
*scop
);
488 /* Collect all tagged potential read access relations. */
489 __isl_give isl_union_map
*pet_scop_collect_tagged_may_reads(
490 struct pet_scop
*scop
);
491 /* Collect all potential write access relations. */
492 __isl_give isl_union_map
*pet_scop_collect_may_writes(struct pet_scop
*scop
);
493 /* Collect all definite write access relations. */
494 __isl_give isl_union_map
*pet_scop_collect_must_writes(struct pet_scop
*scop
);
495 /* Collect all tagged potential write access relations. */
496 __isl_give isl_union_map
*pet_scop_collect_tagged_may_writes(
497 struct pet_scop
*scop
);
498 /* Collect all tagged definite write access relations. */
499 __isl_give isl_union_map
*pet_scop_collect_tagged_must_writes(
500 struct pet_scop
*scop
);
501 /* Collect all definite kill access relations. */
502 __isl_give isl_union_map
*pet_scop_collect_must_kills(struct pet_scop
*scop
);
503 /* Collect all tagged definite kill access relations. */
504 __isl_give isl_union_map
*pet_scop_collect_tagged_must_kills(
505 struct pet_scop
*scop
);
506 __isl_give isl_union_map
*pet_scop_collect_schedule(struct pet_scop
*scop
);
508 #if defined(__cplusplus)