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 #define PET_OVERFLOW_AVOID 0
27 #define PET_OVERFLOW_IGNORE 1
28 int pet_options_set_signed_overflow(isl_ctx
*ctx
, int val
);
29 int pet_options_get_signed_overflow(isl_ctx
*ctx
);
42 /* only compound assignments operators before assignment */
67 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
69 enum pet_un_arg_type
{
73 /* Indices into the pet_expr->args array when
74 * pet_expr->type == pet_expr_binary
76 enum pet_bin_arg_type
{
81 /* Indices into the pet_expr->args array when
82 * pet_expr->type == pet_expr_ternary
84 enum pet_ter_arg_type
{
90 /* d is valid when type == pet_expr_double
91 * acc is valid when type == pet_expr_access
92 * name is valid when type == pet_expr_call
93 * type is valid when type == pet_expr_cast
94 * op is valid otherwise
96 * For each access expression inside the body of a statement, acc.ref_id
97 * is a unique reference identifier.
98 * acc.index represents the index expression, while acc.access
99 * represents the corresponding access relation.
100 * The output dimension of the index expression may be smaller
101 * than the number of dimensions of the accessed array.
102 * The target space of the access relation, on the other hand,
103 * is equal to the array space.
104 * Both acc.index and acc.access usually map an iteration space
105 * to a (partial) data space.
106 * If the access has arguments, however, then the domain of the
107 * mapping is a wrapped mapping from the iteration space
108 * to a space of dimensionality equal to the number of arguments.
109 * Each dimension in this space corresponds to the value of the
110 * corresponding argument.
112 * The ranges of the index expressions and access relations may
113 * also be wrapped relations, in which case the expression represents
114 * a member access, with the structure represented by the domain
115 * of this wrapped relation and the member represented by the range.
116 * In case of nested member accesses, the domain is itself a wrapped
119 * If the data space is unnamed (and 1D), then it represents
120 * the set of integers. That is, the access represents a value that
121 * is equal to the index.
123 * A double is represented as both an (approximate) value "val" and
124 * a string representation "s".
127 enum pet_expr_type type
;
130 struct pet_expr
**args
;
136 isl_multi_pw_aff
*index
;
150 /* Return the potential read access relation of access expression "expr". */
151 __isl_give isl_map
*pet_expr_access_get_may_access(struct pet_expr
*expr
);
152 /* Return the tagged potential read access relation of access "expr". */
153 __isl_give isl_map
*pet_expr_access_get_tagged_may_access(
154 struct pet_expr
*expr
);
156 /* If the statement has arguments, i.e., n_arg != 0, then
157 * "domain" is a wrapped map, mapping the iteration domain
158 * to the values of the arguments for which this statement
160 * Otherwise, it is simply the iteration domain.
162 * If one of the arguments is an access expression that accesses
163 * more than one element for a given iteration, then the constraints
164 * on the value of this argument (encoded in "domain") should be satisfied
165 * for all of those accessed elements.
171 struct pet_expr
*body
;
174 struct pet_expr
**args
;
177 /* Construct an associative array from reference identifiers of
178 * access expressions in "stmt" to the corresponding isl_ast_expr.
179 * Each index expression is first transformed through "fn_index"
180 * (if not NULL). Then an AST expression is generated using "build".
181 * Finally, the AST expression is transformed using "fn_expr"
184 __isl_give isl_id_to_ast_expr
*pet_stmt_build_ast_exprs(struct pet_stmt
*stmt
,
185 __isl_keep isl_ast_build
*build
,
186 __isl_give isl_multi_pw_aff
*(*fn_index
)(
187 __isl_take isl_multi_pw_aff
*mpa
, __isl_keep isl_id
*id
,
188 void *user
), void *user_index
,
189 __isl_give isl_ast_expr
*(*fn_expr
)(__isl_take isl_ast_expr
*expr
,
190 __isl_keep isl_id
*id
, void *user
), void *user_expr
);
192 /* Print "stmt" to "p".
194 * The access expressions in "stmt" are replaced by the isl_ast_expr
195 * associated to its reference identifier in "ref2expr".
197 __isl_give isl_printer
*pet_stmt_print_body(struct pet_stmt
*stmt
,
198 __isl_take isl_printer
*p
, __isl_keep isl_id_to_ast_expr
*ref2expr
);
200 /* This structure represents a defined type.
201 * "name" is the name of the type, while "definition" is a string
202 * representation of its definition.
209 /* context holds constraints on the parameter that ensure that
210 * this array has a valid (i.e., non-negative) size
212 * extent holds constraints on the indices
214 * value_bounds holds constraints on the elements of the array
215 * and may be NULL if no such constraints were specified by the user
217 * element_size is the size in bytes of each array element
218 * element_type is the type of the array elements.
219 * element_is_record is set if this type is a record type.
221 * live_out is set if the array appears in a live-out pragma
223 * if uniquely_defined is set then the array is written by a single access
224 * such that any element that is ever read
225 * is known to be assigned exactly once before the read
227 * declared is set if the array was declared somewhere inside the scop.
228 * exposed is set if the declared array is visible outside the scop.
233 isl_set
*value_bounds
;
235 int element_is_record
;
238 int uniquely_defined
;
243 /* This structure represents an implication on a boolean filter.
244 * In particular, if the filter value of an element in the domain
245 * of "extension" is equal to "satisfied", then the filter values
246 * of the corresponding images in "extension" are also equal
249 struct pet_implication
{
254 /* The start and end fields contain the offsets in the input file
255 * of the scop, where end points to the first character after the scop.
256 * If the scop was detected based on scop and endscop pragmas, then
257 * the lines containing these pragmas are included in this range.
258 * Internally, end may be zero to indicate that no offset information is
260 * The context describes the set of parameter values for which
261 * the scop can be executed.
262 * context_value describes assignments to the parameters (if any)
263 * outside of the scop.
265 * The n_type types define types that may be referenced from by the arrays.
267 * The n_implication implications describe implications on boolean filters.
274 isl_set
*context_value
;
277 struct pet_type
**types
;
280 struct pet_array
**arrays
;
283 struct pet_stmt
**stmts
;
286 struct pet_implication
**implications
;
289 /* Return a textual representation of the operator. */
290 const char *pet_op_str(enum pet_op_type op
);
291 int pet_op_is_inc_dec(enum pet_op_type op
);
293 /* Extract a pet_scop from a C source file.
294 * If function is not NULL, then the pet_scop is extracted from
295 * a function with that name.
297 struct pet_scop
*pet_scop_extract_from_C_source(isl_ctx
*ctx
,
298 const char *filename
, const char *function
);
300 /* Transform the C source file "input" by rewriting each scop
301 * When autodetecting scops, at most one scop per function is rewritten.
302 * The transformed C code is written to "output".
304 int pet_transform_C_source(isl_ctx
*ctx
, const char *input
, FILE *output
,
305 __isl_give isl_printer
*(*transform
)(__isl_take isl_printer
*p
,
306 struct pet_scop
*scop
, void *user
), void *user
);
307 /* Given a scop and a printer passed to a pet_transform_C_source callback,
308 * print the original corresponding code to the printer.
310 __isl_give isl_printer
*pet_scop_print_original(struct pet_scop
*scop
,
311 __isl_take isl_printer
*p
);
313 /* Update all isl_sets and isl_maps such that they all have the same
314 * parameters in the same order.
316 struct pet_scop
*pet_scop_align_params(struct pet_scop
*scop
);
318 /* Does "scop" contain any data dependent accesses? */
319 int pet_scop_has_data_dependent_accesses(struct pet_scop
*scop
);
320 /* Does "scop" contain any data dependent conditions? */
321 int pet_scop_has_data_dependent_conditions(struct pet_scop
*scop
);
323 void pet_scop_dump(struct pet_scop
*scop
);
324 struct pet_scop
*pet_scop_free(struct pet_scop
*scop
);
326 __isl_give isl_union_set
*pet_scop_collect_domains(struct pet_scop
*scop
);
327 /* Collect all potential read access relations. */
328 __isl_give isl_union_map
*pet_scop_collect_may_reads(struct pet_scop
*scop
);
329 /* Collect all tagged potential read access relations. */
330 __isl_give isl_union_map
*pet_scop_collect_tagged_may_reads(
331 struct pet_scop
*scop
);
332 /* Collect all potential write access relations. */
333 __isl_give isl_union_map
*pet_scop_collect_may_writes(struct pet_scop
*scop
);
334 /* Collect all definite write access relations. */
335 __isl_give isl_union_map
*pet_scop_collect_must_writes(struct pet_scop
*scop
);
336 /* Collect all tagged potential write access relations. */
337 __isl_give isl_union_map
*pet_scop_collect_tagged_may_writes(
338 struct pet_scop
*scop
);
339 /* Collect all tagged definite write access relations. */
340 __isl_give isl_union_map
*pet_scop_collect_tagged_must_writes(
341 struct pet_scop
*scop
);
342 /* Collect all definite kill access relations. */
343 __isl_give isl_union_map
*pet_scop_collect_must_kills(struct pet_scop
*scop
);
344 /* Collect all tagged definite kill access relations. */
345 __isl_give isl_union_map
*pet_scop_collect_tagged_must_kills(
346 struct pet_scop
*scop
);
347 __isl_give isl_union_map
*pet_scop_collect_schedule(struct pet_scop
*scop
);
349 #if defined(__cplusplus)