keep track of index expressions
[pet.git] / include / pet.h
blob65266431d87d37ac3d09d645368591176112e6b0
1 #ifndef PET_H
2 #define PET_H
4 #include <isl/arg.h>
5 #include <isl/set.h>
6 #include <isl/map.h>
7 #include <isl/union_map.h>
9 #if defined(__cplusplus)
10 extern "C" {
11 #endif
13 struct pet_options;
14 ISL_ARG_DECL(pet_options, struct pet_options, pet_options_args)
16 /* If autodetect is set, any valid scop is extracted.
17 * Otherwise, the scop needs to be delimited by pragmas.
19 int pet_options_set_autodetect(isl_ctx *ctx, int val);
20 int pet_options_get_autodetect(isl_ctx *ctx);
22 #define PET_OVERFLOW_AVOID 0
23 #define PET_OVERFLOW_IGNORE 1
24 int pet_options_set_signed_overflow(isl_ctx *ctx, int val);
25 int pet_options_get_signed_overflow(isl_ctx *ctx);
27 enum pet_expr_type {
28 pet_expr_access,
29 pet_expr_call,
30 pet_expr_cast,
31 pet_expr_double,
32 pet_expr_unary,
33 pet_expr_binary,
34 pet_expr_ternary
37 enum pet_op_type {
38 /* only compound assignments operators before assignment */
39 pet_op_add_assign,
40 pet_op_sub_assign,
41 pet_op_mul_assign,
42 pet_op_div_assign,
43 pet_op_assign,
44 pet_op_add,
45 pet_op_sub,
46 pet_op_mul,
47 pet_op_div,
48 pet_op_mod,
49 pet_op_eq,
50 pet_op_le,
51 pet_op_lt,
52 pet_op_gt,
53 pet_op_minus,
54 pet_op_post_inc,
55 pet_op_post_dec,
56 pet_op_pre_inc,
57 pet_op_pre_dec,
58 pet_op_address_of,
59 pet_op_kill,
60 pet_op_last
63 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
65 enum pet_un_arg_type {
66 pet_un_arg
69 /* Indices into the pet_expr->args array when
70 * pet_expr->type == pet_expr_binary
72 enum pet_bin_arg_type {
73 pet_bin_lhs,
74 pet_bin_rhs
77 /* Indices into the pet_expr->args array when
78 * pet_expr->type == pet_expr_ternary
80 enum pet_ter_arg_type {
81 pet_ter_cond,
82 pet_ter_true,
83 pet_ter_false
86 /* d is valid when type == pet_expr_double
87 * acc is valid when type == pet_expr_access
88 * name is valid when type == pet_expr_call
89 * type is valid when type == pet_expr_cast
90 * op is valid otherwise
92 * For each access expression inside the body of a statement, acc.ref_id
93 * is a unique reference identifier.
94 * acc.index represents the index expression, while acc.access
95 * represents the corresponding access relation.
96 * The output dimension of the index expression may be smaller
97 * than the number of dimensions of the accessed array.
98 * The target space of the access relation, on the other hand,
99 * is equal to the array space.
100 * Both acc.index and acc.access usually map an iteration space
101 * to a (partial) data space.
102 * If the access has arguments, however, then the domain of the
103 * mapping is a wrapped mapping from the iteration space
104 * to a space of dimensionality equal to the number of arguments.
105 * Each dimension in this space corresponds to the value of the
106 * corresponding argument.
108 * If the data space is unnamed (and 1D), then it represents
109 * the set of integers. That is, the access represents a value that
110 * is equal to the index.
112 * A double is represented as both an (approximate) value "val" and
113 * a string representation "s".
115 struct pet_expr {
116 enum pet_expr_type type;
118 unsigned n_arg;
119 struct pet_expr **args;
121 union {
122 struct {
123 isl_id *ref_id;
124 isl_map *access;
125 isl_multi_pw_aff *index;
126 int read;
127 int write;
128 } acc;
129 enum pet_op_type op;
130 char *name;
131 char *type_name;
132 struct {
133 double val;
134 char *s;
135 } d;
139 /* If the statement has arguments, i.e., n_arg != 0, then
140 * "domain" is a wrapped map, mapping the iteration domain
141 * to the values of the arguments for which this statement
142 * is executed.
143 * Otherwise, it is simply the iteration domain.
145 * If one of the arguments is an access expression that accesses
146 * more than one element for a given iteration, then the constraints
147 * on the value of this argument (encoded in "domain") should be satisfied
148 * for all of those accessed elements.
150 struct pet_stmt {
151 int line;
152 isl_set *domain;
153 isl_map *schedule;
154 struct pet_expr *body;
156 unsigned n_arg;
157 struct pet_expr **args;
160 /* context holds constraints on the parameter that ensure that
161 * this array has a valid (i.e., non-negative) size
163 * extent holds constraints on the indices
165 * value_bounds holds constraints on the elements of the array
166 * and may be NULL if no such constraints were specified by the user
168 * element_size is the size in bytes of each array element
170 * live_out is set if the array appears in a live-out pragma
172 * if uniquely_defined is set then the array is written by a single access
173 * such that any element that is ever read
174 * is known to be assigned exactly once before the read
176 * declared is set if the array was declared somewhere inside the scop.
177 * exposed is set if the declared array is visible outside the scop.
179 struct pet_array {
180 isl_set *context;
181 isl_set *extent;
182 isl_set *value_bounds;
183 char *element_type;
184 int element_size;
185 int live_out;
186 int uniquely_defined;
187 int declared;
188 int exposed;
191 /* This structure represents an implication on a boolean filter.
192 * In particular, if the filter value of an element in the domain
193 * of "extension" is equal to "satisfied", then the filter values
194 * of the corresponding images in "extension" are also equal
195 * to "satisfied".
197 struct pet_implication {
198 int satisfied;
199 isl_map *extension;
202 /* The start and end fields contain the offsets in the input file
203 * of the scop, where end points to the first character after the scop.
204 * If the scop was detected based on scop and endscop pragmas, then
205 * the lines containing these pragmas are included in this range.
206 * Internally, end may be zero to indicate that no offset information is
207 * available (yet).
208 * The context describes the set of parameter values for which
209 * the scop can be executed.
210 * context_value describes assignments to the parameters (if any)
211 * outside of the scop.
213 * The n_implication implications describe implications on boolean filters.
215 struct pet_scop {
216 unsigned start;
217 unsigned end;
219 isl_set *context;
220 isl_set *context_value;
222 int n_array;
223 struct pet_array **arrays;
225 int n_stmt;
226 struct pet_stmt **stmts;
228 int n_implication;
229 struct pet_implication **implications;
232 /* Return a textual representation of the operator. */
233 const char *pet_op_str(enum pet_op_type op);
234 int pet_op_is_inc_dec(enum pet_op_type op);
236 /* Extract a pet_scop from a C source file.
237 * If function is not NULL, then the pet_scop is extracted from
238 * a function with that name.
240 struct pet_scop *pet_scop_extract_from_C_source(isl_ctx *ctx,
241 const char *filename, const char *function);
243 /* Update all isl_sets and isl_maps such that they all have the same
244 * parameters in the same order.
246 struct pet_scop *pet_scop_align_params(struct pet_scop *scop);
248 void pet_scop_dump(struct pet_scop *scop);
249 void *pet_scop_free(struct pet_scop *scop);
251 __isl_give isl_union_set *pet_scop_collect_domains(struct pet_scop *scop);
252 /* Collect all read access relations. */
253 __isl_give isl_union_map *pet_scop_collect_reads(struct pet_scop *scop);
254 /* Collect all write access relations. */
255 __isl_give isl_union_map *pet_scop_collect_writes(struct pet_scop *scop);
256 __isl_give isl_union_map *pet_scop_collect_schedule(struct pet_scop *scop);
258 #if defined(__cplusplus)
260 #endif
262 #endif