rename pet_expr_foreach_access to pet_expr_map_access
[pet.git] / include / pet.h
blob755d71ea6bc9c6a366cb371a04d709cf914aca4d
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 * acc.access usually maps an iteration space to a data space.
93 * If the access has arguments, however, then the domain of the
94 * mapping is a wrapped mapping from the iteration space
95 * to a space of dimensionality equal to the number of arguments.
96 * Each dimension in this space corresponds to the value of the
97 * corresponding argument.
99 * If the data space is unnamed (and 1D), then it represents
100 * the set of integers. That is, the access represents a value that
101 * is equal to the index.
103 * A double is represented as both an (approximate) value "val" and
104 * a string representation "s".
106 struct pet_expr {
107 enum pet_expr_type type;
109 unsigned n_arg;
110 struct pet_expr **args;
112 union {
113 struct {
114 isl_map *access;
115 int read;
116 int write;
117 } acc;
118 enum pet_op_type op;
119 char *name;
120 char *type_name;
121 struct {
122 double val;
123 char *s;
124 } d;
128 /* If the statement has arguments, i.e., n_arg != 0, then
129 * "domain" is a wrapped map, mapping the iteration domain
130 * to the values of the arguments for which this statement
131 * is executed.
132 * Otherwise, it is simply the iteration domain.
134 * If one of the arguments is an access expression that accesses
135 * more than one element for a given iteration, then the constraints
136 * on the value of this argument (encoded in "domain") should be satisfied
137 * for all of those accessed elements.
139 struct pet_stmt {
140 int line;
141 isl_set *domain;
142 isl_map *schedule;
143 struct pet_expr *body;
145 unsigned n_arg;
146 struct pet_expr **args;
149 /* context holds constraints on the parameter that ensure that
150 * this array has a valid (i.e., non-negative) size
152 * extent holds constraints on the indices
154 * value_bounds holds constraints on the elements of the array
155 * and may be NULL if no such constraints were specified by the user
157 * element_size is the size in bytes of each array element
159 * live_out is set if the array appears in a live-out pragma
161 * if uniquely_defined is set then the array is written by a single access
162 * such that any element that is ever read
163 * is known to be assigned exactly once before the read
165 * declared is set if the array was declared somewhere inside the scop.
166 * exposed is set if the declared array is visible outside the scop.
168 struct pet_array {
169 isl_set *context;
170 isl_set *extent;
171 isl_set *value_bounds;
172 char *element_type;
173 int element_size;
174 int live_out;
175 int uniquely_defined;
176 int declared;
177 int exposed;
180 /* The start and end fields contain the offsets in the input file
181 * of the scop, where end points to the first character after the scop.
182 * If the scop was detected based on scop and endscop pragmas, then
183 * the lines containing these pragmas are included in this range.
184 * Internally, end may be zero to indicate that no offset information is
185 * available (yet).
186 * The context describes the set of parameter values for which
187 * the scop can be executed.
188 * context_value describes assignments to the parameters (if any)
189 * outside of the scop.
191 struct pet_scop {
192 unsigned start;
193 unsigned end;
195 isl_set *context;
196 isl_set *context_value;
198 int n_array;
199 struct pet_array **arrays;
201 int n_stmt;
202 struct pet_stmt **stmts;
205 /* Return a textual representation of the operator. */
206 const char *pet_op_str(enum pet_op_type op);
207 int pet_op_is_inc_dec(enum pet_op_type op);
209 /* Extract a pet_scop from a C source file.
210 * If function is not NULL, then the pet_scop is extracted from
211 * a function with that name.
213 struct pet_scop *pet_scop_extract_from_C_source(isl_ctx *ctx,
214 const char *filename, const char *function);
216 /* Update all isl_sets and isl_maps such that they all have the same
217 * parameters in the same order.
219 struct pet_scop *pet_scop_align_params(struct pet_scop *scop);
221 void pet_scop_dump(struct pet_scop *scop);
222 void *pet_scop_free(struct pet_scop *scop);
224 __isl_give isl_union_set *pet_scop_collect_domains(struct pet_scop *scop);
225 /* Collect all read access relations. */
226 __isl_give isl_union_map *pet_scop_collect_reads(struct pet_scop *scop);
227 /* Collect all write access relations. */
228 __isl_give isl_union_map *pet_scop_collect_writes(struct pet_scop *scop);
229 __isl_give isl_union_map *pet_scop_collect_schedule(struct pet_scop *scop);
231 #if defined(__cplusplus)
233 #endif
235 #endif