update isl for support for recent clangs
[pet.git] / include / pet.h
blobfcbb65911f830e08df0088148bc43e4f978c335b
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 #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);
31 enum pet_expr_type {
32 pet_expr_access,
33 pet_expr_call,
34 pet_expr_cast,
35 pet_expr_double,
36 pet_expr_unary,
37 pet_expr_binary,
38 pet_expr_ternary
41 enum pet_op_type {
42 /* only compound assignments operators before assignment */
43 pet_op_add_assign,
44 pet_op_sub_assign,
45 pet_op_mul_assign,
46 pet_op_div_assign,
47 pet_op_assign,
48 pet_op_add,
49 pet_op_sub,
50 pet_op_mul,
51 pet_op_div,
52 pet_op_mod,
53 pet_op_shl,
54 pet_op_shr,
55 pet_op_eq,
56 pet_op_ne,
57 pet_op_le,
58 pet_op_ge,
59 pet_op_lt,
60 pet_op_gt,
61 pet_op_minus,
62 pet_op_post_inc,
63 pet_op_post_dec,
64 pet_op_pre_inc,
65 pet_op_pre_dec,
66 pet_op_address_of,
67 pet_op_assume,
68 pet_op_kill,
69 pet_op_and,
70 pet_op_xor,
71 pet_op_or,
72 pet_op_not,
73 pet_op_last
76 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
78 enum pet_un_arg_type {
79 pet_un_arg
82 /* Indices into the pet_expr->args array when
83 * pet_expr->type == pet_expr_binary
85 enum pet_bin_arg_type {
86 pet_bin_lhs,
87 pet_bin_rhs
90 /* Indices into the pet_expr->args array when
91 * pet_expr->type == pet_expr_ternary
93 enum pet_ter_arg_type {
94 pet_ter_cond,
95 pet_ter_true,
96 pet_ter_false
99 /* d is valid when type == pet_expr_double
100 * acc is valid when type == pet_expr_access
101 * name is valid when type == pet_expr_call
102 * type is valid when type == pet_expr_cast
103 * op is valid otherwise
105 * For each access expression inside the body of a statement, acc.ref_id
106 * is a unique reference identifier.
107 * acc.index represents the index expression, while acc.access
108 * represents the corresponding access relation.
109 * The output dimension of the index expression may be smaller
110 * than the number of dimensions of the accessed array.
111 * The target space of the access relation, on the other hand,
112 * is equal to the array space.
113 * Both acc.index and acc.access usually map an iteration space
114 * to a (partial) data space.
115 * If the access has arguments, however, then the domain of the
116 * mapping is a wrapped mapping from the iteration space
117 * to a space of dimensionality equal to the number of arguments.
118 * Each dimension in this space corresponds to the value of the
119 * corresponding argument.
121 * The ranges of the index expressions and access relations may
122 * also be wrapped relations, in which case the expression represents
123 * a member access, with the structure represented by the domain
124 * of this wrapped relation and the member represented by the range.
125 * In case of nested member accesses, the domain is itself a wrapped
126 * relation.
128 * If the data space is unnamed (and 1D), then it represents
129 * the set of integers. That is, the access represents a value that
130 * is equal to the index.
132 * A double is represented as both an (approximate) value "val" and
133 * a string representation "s".
135 struct pet_expr {
136 enum pet_expr_type type;
138 unsigned n_arg;
139 struct pet_expr **args;
141 union {
142 struct {
143 isl_id *ref_id;
144 isl_map *access;
145 isl_multi_pw_aff *index;
146 int read;
147 int write;
148 } acc;
149 enum pet_op_type op;
150 char *name;
151 char *type_name;
152 struct {
153 double val;
154 char *s;
155 } d;
159 /* Return the potential read access relation of access expression "expr". */
160 __isl_give isl_map *pet_expr_access_get_may_access(struct pet_expr *expr);
161 /* Return the tagged potential read access relation of access "expr". */
162 __isl_give isl_map *pet_expr_access_get_tagged_may_access(
163 struct pet_expr *expr);
165 /* If the statement has arguments, i.e., n_arg != 0, then
166 * "domain" is a wrapped map, mapping the iteration domain
167 * to the values of the arguments for which this statement
168 * is executed.
169 * Otherwise, it is simply the iteration domain.
171 * If one of the arguments is an access expression that accesses
172 * more than one element for a given iteration, then the constraints
173 * on the value of this argument (encoded in "domain") should be satisfied
174 * for all of those accessed elements.
176 struct pet_stmt {
177 int line;
178 isl_set *domain;
179 isl_map *schedule;
180 struct pet_expr *body;
182 unsigned n_arg;
183 struct pet_expr **args;
186 /* Construct an associative array from reference identifiers of
187 * access expressions in "stmt" to the corresponding isl_ast_expr.
188 * Each index expression is first transformed through "fn_index"
189 * (if not NULL). Then an AST expression is generated using "build".
190 * Finally, the AST expression is transformed using "fn_expr"
191 * (if not NULL).
193 __isl_give isl_id_to_ast_expr *pet_stmt_build_ast_exprs(struct pet_stmt *stmt,
194 __isl_keep isl_ast_build *build,
195 __isl_give isl_multi_pw_aff *(*fn_index)(
196 __isl_take isl_multi_pw_aff *mpa, __isl_keep isl_id *id,
197 void *user), void *user_index,
198 __isl_give isl_ast_expr *(*fn_expr)(__isl_take isl_ast_expr *expr,
199 __isl_keep isl_id *id, void *user), void *user_expr);
201 /* Print "stmt" to "p".
203 * The access expressions in "stmt" are replaced by the isl_ast_expr
204 * associated to its reference identifier in "ref2expr".
206 __isl_give isl_printer *pet_stmt_print_body(struct pet_stmt *stmt,
207 __isl_take isl_printer *p, __isl_keep isl_id_to_ast_expr *ref2expr);
209 /* This structure represents a defined type.
210 * "name" is the name of the type, while "definition" is a string
211 * representation of its definition.
213 struct pet_type {
214 char *name;
215 char *definition;
218 /* context holds constraints on the parameter that ensure that
219 * this array has a valid (i.e., non-negative) size
221 * extent holds constraints on the indices
223 * value_bounds holds constraints on the elements of the array
224 * and may be NULL if no such constraints were specified by the user
226 * element_size is the size in bytes of each array element
227 * element_type is the type of the array elements.
228 * element_is_record is set if this type is a record type.
230 * live_out is set if the array appears in a live-out pragma
232 * if uniquely_defined is set then the array is written by a single access
233 * such that any element that is ever read
234 * is known to be assigned exactly once before the read
236 * declared is set if the array was declared somewhere inside the scop.
237 * exposed is set if the declared array is visible outside the scop.
239 struct pet_array {
240 isl_set *context;
241 isl_set *extent;
242 isl_set *value_bounds;
243 char *element_type;
244 int element_is_record;
245 int element_size;
246 int live_out;
247 int uniquely_defined;
248 int declared;
249 int exposed;
252 /* This structure represents an implication on a boolean filter.
253 * In particular, if the filter value of an element in the domain
254 * of "extension" is equal to "satisfied", then the filter values
255 * of the corresponding images in "extension" are also equal
256 * to "satisfied".
258 struct pet_implication {
259 int satisfied;
260 isl_map *extension;
263 /* The start and end fields contain the offsets in the input file
264 * of the scop, where end points to the first character after the scop.
265 * If the scop was detected based on scop and endscop pragmas, then
266 * the lines containing these pragmas are included in this range.
267 * Internally, end may be zero to indicate that no offset information is
268 * available (yet).
269 * The context describes the set of parameter values for which
270 * the scop can be executed.
271 * context_value describes assignments to the parameters (if any)
272 * outside of the scop.
274 * The n_type types define types that may be referenced from by the arrays.
276 * The n_implication implications describe implications on boolean filters.
278 struct pet_scop {
279 unsigned start;
280 unsigned end;
282 isl_set *context;
283 isl_set *context_value;
285 int n_type;
286 struct pet_type **types;
288 int n_array;
289 struct pet_array **arrays;
291 int n_stmt;
292 struct pet_stmt **stmts;
294 int n_implication;
295 struct pet_implication **implications;
298 /* Return a textual representation of the operator. */
299 const char *pet_op_str(enum pet_op_type op);
300 int pet_op_is_inc_dec(enum pet_op_type op);
302 /* Extract a pet_scop from a C source file.
303 * If function is not NULL, then the pet_scop is extracted from
304 * a function with that name.
306 struct pet_scop *pet_scop_extract_from_C_source(isl_ctx *ctx,
307 const char *filename, const char *function);
309 /* Transform the C source file "input" by rewriting each scop
310 * When autodetecting scops, at most one scop per function is rewritten.
311 * The transformed C code is written to "output".
313 int pet_transform_C_source(isl_ctx *ctx, const char *input, FILE *output,
314 __isl_give isl_printer *(*transform)(__isl_take isl_printer *p,
315 struct pet_scop *scop, void *user), void *user);
316 /* Given a scop and a printer passed to a pet_transform_C_source callback,
317 * print the original corresponding code to the printer.
319 __isl_give isl_printer *pet_scop_print_original(struct pet_scop *scop,
320 __isl_take isl_printer *p);
322 /* Update all isl_sets and isl_maps such that they all have the same
323 * parameters in the same order.
325 struct pet_scop *pet_scop_align_params(struct pet_scop *scop);
327 /* Does "scop" contain any data dependent accesses? */
328 int pet_scop_has_data_dependent_accesses(struct pet_scop *scop);
329 /* Does "scop" contain any data dependent conditions? */
330 int pet_scop_has_data_dependent_conditions(struct pet_scop *scop);
332 void pet_scop_dump(struct pet_scop *scop);
333 struct pet_scop *pet_scop_free(struct pet_scop *scop);
335 __isl_give isl_union_set *pet_scop_collect_domains(struct pet_scop *scop);
336 /* Collect all potential read access relations. */
337 __isl_give isl_union_map *pet_scop_collect_may_reads(struct pet_scop *scop);
338 /* Collect all tagged potential read access relations. */
339 __isl_give isl_union_map *pet_scop_collect_tagged_may_reads(
340 struct pet_scop *scop);
341 /* Collect all potential write access relations. */
342 __isl_give isl_union_map *pet_scop_collect_may_writes(struct pet_scop *scop);
343 /* Collect all definite write access relations. */
344 __isl_give isl_union_map *pet_scop_collect_must_writes(struct pet_scop *scop);
345 /* Collect all tagged potential write access relations. */
346 __isl_give isl_union_map *pet_scop_collect_tagged_may_writes(
347 struct pet_scop *scop);
348 /* Collect all tagged definite write access relations. */
349 __isl_give isl_union_map *pet_scop_collect_tagged_must_writes(
350 struct pet_scop *scop);
351 /* Collect all definite kill access relations. */
352 __isl_give isl_union_map *pet_scop_collect_must_kills(struct pet_scop *scop);
353 /* Collect all tagged definite kill access relations. */
354 __isl_give isl_union_map *pet_scop_collect_tagged_must_kills(
355 struct pet_scop *scop);
356 __isl_give isl_union_map *pet_scop_collect_schedule(struct pet_scop *scop);
358 #if defined(__cplusplus)
360 #endif
362 #endif