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
);
44 /* only compound assignments operators before assignment */
82 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
84 enum pet_un_arg_type
{
88 /* Indices into the pet_expr->args array when
89 * pet_expr->type == pet_expr_binary
91 enum pet_bin_arg_type
{
96 /* Indices into the pet_expr->args array when
97 * pet_expr->type == pet_expr_ternary
99 enum pet_ter_arg_type
{
105 /* d is valid when type == pet_expr_double
106 * i isl valid when type == pet_expr_int
107 * acc is valid when type == pet_expr_access
108 * name is valid when type == pet_expr_call
109 * type is valid when type == pet_expr_cast
110 * op is valid otherwise
112 * For each access expression inside the body of a statement, acc.ref_id
113 * is a unique reference identifier.
114 * acc.index represents the index expression, while acc.access
115 * represents the corresponding access relation.
116 * The output dimension of the index expression may be smaller
117 * than the number of dimensions of the accessed array.
118 * The target space of the access relation, on the other hand,
119 * is equal to the array space.
120 * Both acc.index and acc.access usually map an iteration space
121 * to a (partial) data space.
122 * If the access has arguments, however, then the domain of the
123 * mapping is a wrapped mapping from the iteration space
124 * to a space of dimensionality equal to the number of arguments.
125 * Each dimension in this space corresponds to the value of the
126 * corresponding argument.
128 * The ranges of the index expressions and access relations may
129 * also be wrapped relations, in which case the expression represents
130 * a member access, with the structure represented by the domain
131 * of this wrapped relation and the member represented by the range.
132 * In case of nested member accesses, the domain is itself a wrapped
135 * If the data space is unnamed (and 1D), then it represents
136 * the set of integers. That is, the access represents a value that
137 * is equal to the index.
139 * A double is represented as both an (approximate) value "val" and
140 * a string representation "s".
143 enum pet_expr_type type
;
146 struct pet_expr
**args
;
152 isl_multi_pw_aff
*index
;
167 struct pet_expr
*pet_expr_free(struct pet_expr
*expr
);
169 /* Construct a (read) access pet_expr from an index expression. */
170 struct pet_expr
*pet_expr_from_index(__isl_take isl_multi_pw_aff
*index
);
172 /* Does "expr" represent an affine expression? */
173 int pet_expr_is_affine(struct pet_expr
*expr
);
174 /* Return the identifier of the outer array accessed by "expr". */
175 __isl_give isl_id
*pet_expr_access_get_id(struct pet_expr
*expr
);
177 /* Return the potential read access relation of access expression "expr". */
178 __isl_give isl_map
*pet_expr_access_get_may_access(struct pet_expr
*expr
);
179 /* Return the definite access relation of access expression "expr". */
180 __isl_give isl_map
*pet_expr_access_get_must_access(struct pet_expr
*expr
);
181 /* Return the tagged potential read access relation of access "expr". */
182 __isl_give isl_map
*pet_expr_access_get_tagged_may_access(
183 struct pet_expr
*expr
);
185 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_access. */
186 int pet_expr_foreach_access_expr(struct pet_expr
*expr
,
187 int (*fn
)(struct pet_expr
*expr
, void *user
), void *user
);
189 void pet_expr_dump(struct pet_expr
*expr
);
191 /* If the statement has arguments, i.e., n_arg != 0, then
192 * "domain" is a wrapped map, mapping the iteration domain
193 * to the values of the arguments for which this statement
195 * Otherwise, it is simply the iteration domain.
197 * If one of the arguments is an access expression that accesses
198 * more than one element for a given iteration, then the constraints
199 * on the value of this argument (encoded in "domain") should be satisfied
200 * for all of those accessed elements.
206 struct pet_expr
*body
;
209 struct pet_expr
**args
;
212 /* Return the iteration space of "stmt". */
213 __isl_give isl_space
*pet_stmt_get_space(struct pet_stmt
*stmt
);
215 /* Is "stmt" an assignment statement? */
216 int pet_stmt_is_assign(struct pet_stmt
*stmt
);
217 /* Is "stmt" a kill statement? */
218 int pet_stmt_is_kill(struct pet_stmt
*stmt
);
220 /* Construct an associative array from reference identifiers of
221 * access expressions in "stmt" to the corresponding isl_ast_expr.
222 * Each index expression is first transformed through "fn_index"
223 * (if not NULL). Then an AST expression is generated using "build".
224 * Finally, the AST expression is transformed using "fn_expr"
227 __isl_give isl_id_to_ast_expr
*pet_stmt_build_ast_exprs(struct pet_stmt
*stmt
,
228 __isl_keep isl_ast_build
*build
,
229 __isl_give isl_multi_pw_aff
*(*fn_index
)(
230 __isl_take isl_multi_pw_aff
*mpa
, __isl_keep isl_id
*id
,
231 void *user
), void *user_index
,
232 __isl_give isl_ast_expr
*(*fn_expr
)(__isl_take isl_ast_expr
*expr
,
233 __isl_keep isl_id
*id
, void *user
), void *user_expr
);
235 /* Print "stmt" to "p".
237 * The access expressions in "stmt" are replaced by the isl_ast_expr
238 * associated to its reference identifier in "ref2expr".
240 __isl_give isl_printer
*pet_stmt_print_body(struct pet_stmt
*stmt
,
241 __isl_take isl_printer
*p
, __isl_keep isl_id_to_ast_expr
*ref2expr
);
243 /* This structure represents a defined type.
244 * "name" is the name of the type, while "definition" is a string
245 * representation of its definition.
252 /* context holds constraints on the parameter that ensure that
253 * this array has a valid (i.e., non-negative) size
255 * extent holds constraints on the indices
257 * value_bounds holds constraints on the elements of the array
258 * and may be NULL if no such constraints were specified by the user
260 * element_size is the size in bytes of each array element
261 * element_type is the type of the array elements.
262 * element_is_record is set if this type is a record type.
264 * live_out is set if the array appears in a live-out pragma
266 * if uniquely_defined is set then the array is written by a single access
267 * such that any element that is ever read
268 * is known to be assigned exactly once before the read
270 * declared is set if the array was declared somewhere inside the scop.
271 * exposed is set if the declared array is visible outside the scop.
276 isl_set
*value_bounds
;
278 int element_is_record
;
281 int uniquely_defined
;
286 /* This structure represents an implication on a boolean filter.
287 * In particular, if the filter value of an element in the domain
288 * of "extension" is equal to "satisfied", then the filter values
289 * of the corresponding images in "extension" are also equal
292 struct pet_implication
{
297 /* The start and end fields contain the offsets in the input file
298 * of the scop, where end points to the first character after the scop.
299 * If the scop was detected based on scop and endscop pragmas, then
300 * the lines containing these pragmas are included in this range.
301 * Internally, end may be zero to indicate that no offset information is
303 * The context describes the set of parameter values for which
304 * the scop can be executed.
305 * context_value describes assignments to the parameters (if any)
306 * outside of the scop.
308 * The n_type types define types that may be referenced from by the arrays.
310 * The n_implication implications describe implications on boolean filters.
317 isl_set
*context_value
;
320 struct pet_type
**types
;
323 struct pet_array
**arrays
;
326 struct pet_stmt
**stmts
;
329 struct pet_implication
**implications
;
332 /* Return a textual representation of the operator. */
333 const char *pet_op_str(enum pet_op_type op
);
334 int pet_op_is_inc_dec(enum pet_op_type op
);
336 /* Extract a pet_scop from a C source file.
337 * If function is not NULL, then the pet_scop is extracted from
338 * a function with that name.
340 struct pet_scop
*pet_scop_extract_from_C_source(isl_ctx
*ctx
,
341 const char *filename
, const char *function
);
343 /* Transform the C source file "input" by rewriting each scop
344 * When autodetecting scops, at most one scop per function is rewritten.
345 * The transformed C code is written to "output".
347 int pet_transform_C_source(isl_ctx
*ctx
, const char *input
, FILE *output
,
348 __isl_give isl_printer
*(*transform
)(__isl_take isl_printer
*p
,
349 struct pet_scop
*scop
, void *user
), void *user
);
350 /* Given a scop and a printer passed to a pet_transform_C_source callback,
351 * print the original corresponding code to the printer.
353 __isl_give isl_printer
*pet_scop_print_original(struct pet_scop
*scop
,
354 __isl_take isl_printer
*p
);
356 /* Update all isl_sets and isl_maps such that they all have the same
357 * parameters in the same order.
359 struct pet_scop
*pet_scop_align_params(struct pet_scop
*scop
);
361 /* Does "scop" contain any data dependent accesses? */
362 int pet_scop_has_data_dependent_accesses(struct pet_scop
*scop
);
363 /* Does "scop" contain any data dependent conditions? */
364 int pet_scop_has_data_dependent_conditions(struct pet_scop
*scop
);
366 void pet_scop_dump(struct pet_scop
*scop
);
367 struct pet_scop
*pet_scop_free(struct pet_scop
*scop
);
369 __isl_give isl_union_set
*pet_scop_collect_domains(struct pet_scop
*scop
);
370 /* Collect all potential read access relations. */
371 __isl_give isl_union_map
*pet_scop_collect_may_reads(struct pet_scop
*scop
);
372 /* Collect all tagged potential read access relations. */
373 __isl_give isl_union_map
*pet_scop_collect_tagged_may_reads(
374 struct pet_scop
*scop
);
375 /* Collect all potential write access relations. */
376 __isl_give isl_union_map
*pet_scop_collect_may_writes(struct pet_scop
*scop
);
377 /* Collect all definite write access relations. */
378 __isl_give isl_union_map
*pet_scop_collect_must_writes(struct pet_scop
*scop
);
379 /* Collect all tagged potential write access relations. */
380 __isl_give isl_union_map
*pet_scop_collect_tagged_may_writes(
381 struct pet_scop
*scop
);
382 /* Collect all tagged definite write access relations. */
383 __isl_give isl_union_map
*pet_scop_collect_tagged_must_writes(
384 struct pet_scop
*scop
);
385 /* Collect all definite kill access relations. */
386 __isl_give isl_union_map
*pet_scop_collect_must_kills(struct pet_scop
*scop
);
387 /* Collect all tagged definite kill access relations. */
388 __isl_give isl_union_map
*pet_scop_collect_tagged_must_kills(
389 struct pet_scop
*scop
);
390 __isl_give isl_union_map
*pet_scop_collect_schedule(struct pet_scop
*scop
);
392 #if defined(__cplusplus)