PetScan::extract(pet_expr*): take explicit source range
[pet.git] / include / pet.h
blob12bab466a88ab6257684449ba8277bd3f2a29e98
1 #ifndef PET_H
2 #define PET_H
4 #include <isl/aff.h>
5 #include <isl/arg.h>
6 #include <isl/ast_build.h>
7 #include <isl/set.h>
8 #include <isl/map.h>
9 #include <isl/union_map.h>
10 #include <isl/printer.h>
11 #include <isl/id_to_ast_expr.h>
13 #if defined(__cplusplus)
14 extern "C" {
15 #endif
17 struct pet_options;
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);
34 enum pet_expr_type {
35 pet_expr_error = -1,
36 pet_expr_access,
37 pet_expr_call,
38 pet_expr_cast,
39 pet_expr_int,
40 pet_expr_double,
41 pet_expr_op
44 enum pet_op_type {
45 /* only compound assignments operators before assignment */
46 pet_op_add_assign,
47 pet_op_sub_assign,
48 pet_op_mul_assign,
49 pet_op_div_assign,
50 pet_op_assign,
51 pet_op_add,
52 pet_op_sub,
53 pet_op_mul,
54 pet_op_div,
55 pet_op_mod,
56 pet_op_shl,
57 pet_op_shr,
58 pet_op_eq,
59 pet_op_ne,
60 pet_op_le,
61 pet_op_ge,
62 pet_op_lt,
63 pet_op_gt,
64 pet_op_minus,
65 pet_op_post_inc,
66 pet_op_post_dec,
67 pet_op_pre_inc,
68 pet_op_pre_dec,
69 pet_op_address_of,
70 pet_op_assume,
71 pet_op_kill,
72 pet_op_and,
73 pet_op_xor,
74 pet_op_or,
75 pet_op_not,
76 pet_op_land,
77 pet_op_lor,
78 pet_op_lnot,
79 pet_op_cond,
80 pet_op_last
83 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
85 enum pet_un_arg_type {
86 pet_un_arg
89 /* Indices into the pet_expr->args array when
90 * pet_expr->type == pet_expr_binary
92 enum pet_bin_arg_type {
93 pet_bin_lhs,
94 pet_bin_rhs
97 /* Indices into the pet_expr->args array when
98 * pet_expr->type == pet_expr_ternary
100 enum pet_ter_arg_type {
101 pet_ter_cond,
102 pet_ter_true,
103 pet_ter_false
106 struct pet_expr;
107 typedef struct pet_expr pet_expr;
109 /* Return an additional reference to "expr". */
110 __isl_give pet_expr *pet_expr_copy(__isl_keep pet_expr *expr);
111 /* Free a reference to "expr". */
112 __isl_null pet_expr *pet_expr_free(__isl_take pet_expr *expr);
114 /* Return the isl_ctx in which "expr" was created. */
115 isl_ctx *pet_expr_get_ctx(__isl_keep pet_expr *expr);
117 /* Return the type of "expr". */
118 enum pet_expr_type pet_expr_get_type(__isl_keep pet_expr *expr);
119 /* Return the number of arguments of "expr". */
120 int pet_expr_get_n_arg(__isl_keep pet_expr *expr);
121 /* Set the number of arguments of "expr" to "n". */
122 __isl_give pet_expr *pet_expr_set_n_arg(__isl_take pet_expr *expr, int n);
123 /* Return the argument of "expr" at position "pos". */
124 __isl_give pet_expr *pet_expr_get_arg(__isl_keep pet_expr *expr, int pos);
125 /* Replace the argument of "expr" at position "pos" by "arg". */
126 __isl_give pet_expr *pet_expr_set_arg(__isl_take pet_expr *expr, int pos,
127 __isl_take pet_expr *arg);
129 /* Return the operation type of operation expression "expr". */
130 enum pet_op_type pet_expr_op_get_type(__isl_keep pet_expr *expr);
131 /* Replace the operation type of operation expression "expr" by "type". */
132 __isl_give pet_expr *pet_expr_op_set_type(__isl_take pet_expr *expr,
133 enum pet_op_type type);
135 /* Construct a (read) access pet_expr from an index expression. */
136 __isl_give pet_expr *pet_expr_from_index(__isl_take isl_multi_pw_aff *index);
138 /* Does "expr" represent an affine expression? */
139 int pet_expr_is_affine(__isl_keep pet_expr *expr);
140 /* Does the access expression "expr" read the accessed elements? */
141 int pet_expr_access_is_read(__isl_keep pet_expr *expr);
142 /* Does the access expression "expr" write to the accessed elements? */
143 int pet_expr_access_is_write(__isl_keep pet_expr *expr);
144 /* Mark "expr" as a read dependening on "read". */
145 __isl_give pet_expr *pet_expr_access_set_read(__isl_take pet_expr *expr,
146 int read);
147 /* Mark "expr" as a write dependening on "write". */
148 __isl_give pet_expr *pet_expr_access_set_write(__isl_take pet_expr *expr,
149 int write);
150 /* Return the reference identifier of access expression "expr". */
151 __isl_give isl_id *pet_expr_access_get_ref_id(__isl_keep pet_expr *expr);
152 /* Replace the reference identifier of access expression "expr" by "ref_id". */
153 __isl_give pet_expr *pet_expr_access_set_ref_id(__isl_take pet_expr *expr,
154 __isl_take isl_id *ref_id);
155 /* Return the identifier of the outer array accessed by "expr". */
156 __isl_give isl_id *pet_expr_access_get_id(__isl_keep pet_expr *expr);
157 /* Return the index expression of access expression "expr". */
158 __isl_give isl_multi_pw_aff *pet_expr_access_get_index(
159 __isl_keep pet_expr *expr);
161 /* Return the potential read access relation of access expression "expr". */
162 __isl_give isl_map *pet_expr_access_get_may_access(__isl_keep pet_expr *expr);
163 /* Return the definite access relation of access expression "expr". */
164 __isl_give isl_map *pet_expr_access_get_must_access(__isl_keep pet_expr *expr);
165 /* Return the argument dependent access relation of access expression "expr". */
166 __isl_give isl_map *pet_expr_access_get_dependent_access(
167 __isl_keep pet_expr *expr);
168 /* Return the tagged potential read access relation of access "expr". */
169 __isl_give isl_map *pet_expr_access_get_tagged_may_access(
170 __isl_keep pet_expr *expr);
172 /* Return the name of the function called by "expr". */
173 __isl_keep const char *pet_expr_call_get_name(__isl_keep pet_expr *expr);
174 /* Replace the name of the function called by "expr" by "name". */
175 __isl_give pet_expr *pet_expr_call_set_name(__isl_take pet_expr *expr,
176 __isl_keep const char *name);
178 /* Replace the type of the cast performed by "expr" by "name". */
179 __isl_give pet_expr *pet_expr_cast_set_type_name(__isl_take pet_expr *expr,
180 __isl_keep const char *name);
182 /* Return the value of the integer represented by "expr". */
183 __isl_give isl_val *pet_expr_int_get_val(__isl_keep pet_expr *expr);
184 /* Replace the value of the integer represented by "expr" by "v". */
185 __isl_give pet_expr *pet_expr_int_set_val(__isl_take pet_expr *expr,
186 __isl_take isl_val *v);
188 /* Return a string representation of the double expression "expr". */
189 __isl_give char *pet_expr_double_get_str(__isl_keep pet_expr *expr);
190 /* Replace value and string representation of the double expression "expr" */
191 __isl_give pet_expr *pet_expr_double_set(__isl_take pet_expr *expr,
192 double d, __isl_keep const char *s);
194 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_access. */
195 int pet_expr_foreach_access_expr(__isl_keep pet_expr *expr,
196 int (*fn)(__isl_keep pet_expr *expr, void *user), void *user);
197 /* Call "fn" on each of the subexpressions of "expr" of type pet_expr_call. */
198 int pet_expr_foreach_call_expr(__isl_keep pet_expr *expr,
199 int (*fn)(__isl_keep pet_expr *expr, void *user), void *user);
201 void pet_expr_dump(__isl_keep pet_expr *expr);
203 /* If the statement has arguments, i.e., n_arg != 0, then
204 * "domain" is a wrapped map, mapping the iteration domain
205 * to the values of the arguments for which this statement
206 * is executed.
207 * Otherwise, it is simply the iteration domain.
209 * If one of the arguments is an access expression that accesses
210 * more than one element for a given iteration, then the constraints
211 * on the value of this argument (encoded in "domain") should be satisfied
212 * for all of those accessed elements.
214 struct pet_stmt {
215 int line;
216 isl_set *domain;
217 isl_map *schedule;
218 pet_expr *body;
220 unsigned n_arg;
221 pet_expr **args;
224 /* Return the iteration space of "stmt". */
225 __isl_give isl_space *pet_stmt_get_space(struct pet_stmt *stmt);
227 /* Is "stmt" an assignment statement? */
228 int pet_stmt_is_assign(struct pet_stmt *stmt);
229 /* Is "stmt" a kill statement? */
230 int pet_stmt_is_kill(struct pet_stmt *stmt);
232 /* pet_stmt_build_ast_exprs is currently limited to only handle
233 * some forms of data dependent accesses.
234 * If pet_stmt_can_build_ast_exprs returns 1, then pet_stmt_build_ast_exprs
235 * can safely be called on "stmt".
237 int pet_stmt_can_build_ast_exprs(struct pet_stmt *stmt);
238 /* Construct an associative array from reference identifiers of
239 * access expressions in "stmt" to the corresponding isl_ast_expr.
240 * Each index expression is first transformed through "fn_index"
241 * (if not NULL). Then an AST expression is generated using "build".
242 * Finally, the AST expression is transformed using "fn_expr"
243 * (if not NULL).
245 __isl_give isl_id_to_ast_expr *pet_stmt_build_ast_exprs(struct pet_stmt *stmt,
246 __isl_keep isl_ast_build *build,
247 __isl_give isl_multi_pw_aff *(*fn_index)(
248 __isl_take isl_multi_pw_aff *mpa, __isl_keep isl_id *id,
249 void *user), void *user_index,
250 __isl_give isl_ast_expr *(*fn_expr)(__isl_take isl_ast_expr *expr,
251 __isl_keep isl_id *id, void *user), void *user_expr);
253 /* Print "stmt" to "p".
255 * The access expressions in "stmt" are replaced by the isl_ast_expr
256 * associated to its reference identifier in "ref2expr".
258 __isl_give isl_printer *pet_stmt_print_body(struct pet_stmt *stmt,
259 __isl_take isl_printer *p, __isl_keep isl_id_to_ast_expr *ref2expr);
261 /* This structure represents a defined type.
262 * "name" is the name of the type, while "definition" is a string
263 * representation of its definition.
265 struct pet_type {
266 char *name;
267 char *definition;
270 /* context holds constraints on the parameter that ensure that
271 * this array has a valid (i.e., non-negative) size
273 * extent holds constraints on the indices
275 * value_bounds holds constraints on the elements of the array
276 * and may be NULL if no such constraints were specified by the user
278 * element_size is the size in bytes of each array element
279 * element_type is the type of the array elements.
280 * element_is_record is set if this type is a record type.
282 * live_out is set if the array appears in a live-out pragma
284 * if uniquely_defined is set then the array is written by a single access
285 * such that any element that is ever read
286 * is known to be assigned exactly once before the read
288 * declared is set if the array was declared somewhere inside the scop.
289 * exposed is set if the declared array is visible outside the scop.
291 struct pet_array {
292 isl_set *context;
293 isl_set *extent;
294 isl_set *value_bounds;
295 char *element_type;
296 int element_is_record;
297 int element_size;
298 int live_out;
299 int uniquely_defined;
300 int declared;
301 int exposed;
304 /* This structure represents an implication on a boolean filter.
305 * In particular, if the filter value of an element in the domain
306 * of "extension" is equal to "satisfied", then the filter values
307 * of the corresponding images in "extension" are also equal
308 * to "satisfied".
310 struct pet_implication {
311 int satisfied;
312 isl_map *extension;
315 /* The start and end fields contain the offsets in the input file
316 * of the scop, where end points to the first character after the scop.
317 * If the scop was detected based on scop and endscop pragmas, then
318 * the lines containing these pragmas are included in this range.
319 * Internally, end may be zero to indicate that no offset information is
320 * available (yet).
321 * The context describes the set of parameter values for which
322 * the scop can be executed.
323 * context_value describes assignments to the parameters (if any)
324 * outside of the scop.
326 * The n_type types define types that may be referenced from by the arrays.
328 * The n_implication implications describe implications on boolean filters.
330 struct pet_scop {
331 unsigned start;
332 unsigned end;
334 isl_set *context;
335 isl_set *context_value;
337 int n_type;
338 struct pet_type **types;
340 int n_array;
341 struct pet_array **arrays;
343 int n_stmt;
344 struct pet_stmt **stmts;
346 int n_implication;
347 struct pet_implication **implications;
350 /* Return a textual representation of the operator. */
351 const char *pet_op_str(enum pet_op_type op);
352 int pet_op_is_inc_dec(enum pet_op_type op);
354 /* Extract a pet_scop from a C source file.
355 * If function is not NULL, then the pet_scop is extracted from
356 * a function with that name.
358 struct pet_scop *pet_scop_extract_from_C_source(isl_ctx *ctx,
359 const char *filename, const char *function);
361 /* Transform the C source file "input" by rewriting each scop
362 * When autodetecting scops, at most one scop per function is rewritten.
363 * The transformed C code is written to "output".
365 int pet_transform_C_source(isl_ctx *ctx, const char *input, FILE *output,
366 __isl_give isl_printer *(*transform)(__isl_take isl_printer *p,
367 struct pet_scop *scop, void *user), void *user);
368 /* Given a scop and a printer passed to a pet_transform_C_source callback,
369 * print the original corresponding code to the printer.
371 __isl_give isl_printer *pet_scop_print_original(struct pet_scop *scop,
372 __isl_take isl_printer *p);
374 /* Update all isl_sets and isl_maps such that they all have the same
375 * parameters in the same order.
377 struct pet_scop *pet_scop_align_params(struct pet_scop *scop);
379 /* Does "scop" contain any data dependent accesses? */
380 int pet_scop_has_data_dependent_accesses(struct pet_scop *scop);
381 /* Does "scop" contain any data dependent conditions? */
382 int pet_scop_has_data_dependent_conditions(struct pet_scop *scop);
383 /* pet_stmt_build_ast_exprs is currently limited to only handle
384 * some forms of data dependent accesses.
385 * If pet_scop_can_build_ast_exprs returns 1, then pet_stmt_build_ast_exprs
386 * can safely be called on all statements in the scop.
388 int pet_scop_can_build_ast_exprs(struct pet_scop *scop);
390 void pet_scop_dump(struct pet_scop *scop);
391 struct pet_scop *pet_scop_free(struct pet_scop *scop);
393 __isl_give isl_union_set *pet_scop_collect_domains(struct pet_scop *scop);
394 /* Collect all potential read access relations. */
395 __isl_give isl_union_map *pet_scop_collect_may_reads(struct pet_scop *scop);
396 /* Collect all tagged potential read access relations. */
397 __isl_give isl_union_map *pet_scop_collect_tagged_may_reads(
398 struct pet_scop *scop);
399 /* Collect all potential write access relations. */
400 __isl_give isl_union_map *pet_scop_collect_may_writes(struct pet_scop *scop);
401 /* Collect all definite write access relations. */
402 __isl_give isl_union_map *pet_scop_collect_must_writes(struct pet_scop *scop);
403 /* Collect all tagged potential write access relations. */
404 __isl_give isl_union_map *pet_scop_collect_tagged_may_writes(
405 struct pet_scop *scop);
406 /* Collect all tagged definite write access relations. */
407 __isl_give isl_union_map *pet_scop_collect_tagged_must_writes(
408 struct pet_scop *scop);
409 /* Collect all definite kill access relations. */
410 __isl_give isl_union_map *pet_scop_collect_must_kills(struct pet_scop *scop);
411 /* Collect all tagged definite kill access relations. */
412 __isl_give isl_union_map *pet_scop_collect_tagged_must_kills(
413 struct pet_scop *scop);
414 __isl_give isl_union_map *pet_scop_collect_schedule(struct pet_scop *scop);
416 #if defined(__cplusplus)
418 #endif
420 #endif