m4/ax_detect_clang.m4: check presence of clang/Basic/LangStandard.h
[pet.git] / expr.h
blob5a8cf7c226ca5f602cdb3b87259f07a5c7370153
1 #ifndef PET_EXPR_H
2 #define PET_EXPR_H
4 #include <pet.h>
6 #include "context.h"
7 #include "expr_access_type.h"
8 #include "summary.h"
10 #if defined(__cplusplus)
11 extern "C" {
12 #endif
14 /* Representation of access expression.
16 * For each access expression inside the body of a statement, "ref_id"
17 * is a unique reference identifier.
18 * "index" represents the index expression, while "access"
19 * represents the corresponding access relations.
20 * The output dimension of the index expression may be smaller
21 * than the number of dimensions of the accessed array (recorded
22 * in "depth").
23 * The target space of the access relation, on the other hand,
24 * is equal to the array space.
25 * The entries in "access" may be NULL if they can be derived directly from
26 * "index" and "depth" in construct_access_relation or if they are
27 * irrelevant for the given type of access.
28 * In particular, the entries of "access" may be NULL if there are
29 * no additional constraints on the access relations.
30 * Both "index" and the "access" entries usually map an iteration space
31 * to a (partial) data space.
32 * If the access has arguments, however, then the domain of the
33 * mapping is a wrapped mapping from the iteration space
34 * to a space of dimensionality equal to the number of arguments.
35 * Each dimension in this space corresponds to the value of the
36 * corresponding argument.
38 * The ranges of the index expressions and access relations may
39 * also be wrapped relations, in which case the expression represents
40 * a member access, with the structure represented by the domain
41 * of this wrapped relation and the member represented by the range.
42 * In case of nested member accesses, the domain is itself a wrapped
43 * relation.
45 * If the data space is unnamed (and 1D), then it represents
46 * the set of integers. That is, the access represents a value that
47 * is equal to the index.
49 * An access expresssion is marked "read" if it represents a read and
50 * marked "write" if it represents a write. A single access expression
51 * may be marked both read and write.
52 * Alternatively, the expression may be marked "kill", in which case it
53 * is the argument of a kill operation and represents the set of
54 * killed array elements. Such accesses are marked neither read nor write.
55 * Since a kill can never be a read (or a write), the killed access
56 * relation is stored in the same location as the may read access relation.
58 struct pet_expr_access {
59 isl_id *ref_id;
60 isl_multi_pw_aff *index;
61 int depth;
62 unsigned read : 1;
63 unsigned write : 1;
64 unsigned kill : 1;
65 isl_union_map *access[pet_expr_access_end];
67 /* Representation of call expression.
69 * A function call is represented by the name of the called function and
70 * an optional function summary (the value NULL indicating that there is
71 * no function summary).
73 struct pet_expr_call {
74 char *name;
75 pet_function_summary *summary;
77 /* Representation of double expression.
79 * A double is represented as both an (approximate) value "val" and
80 * a string representation "s".
82 struct pet_expr_double {
83 double val;
84 char *s;
86 /* d is valid when type == pet_expr_double
87 * i isl valid when type == pet_expr_int
88 * acc is valid when type == pet_expr_access
89 * c is valid when type == pet_expr_call
90 * type is valid when type == pet_expr_cast
91 * op is valid otherwise
93 * "hash" is a copy of the hash value computed by pet_expr_get_hash.
94 * It is zero when it has not been computed yet. The value is reset
95 * whenever the pet_expr is modified (in pet_expr_cow and
96 * introduce_access_relations).
98 * If type_size is not zero, then the expression is of an integer type
99 * and type_size represents the size of the type in bits.
100 * If type_size is greater than zero, then the type is unsigned
101 * and the number of bits is equal to type_size.
102 * If type_size is less than zero, then the type is signed
103 * and the number of bits is equal to -type_size.
104 * type_size may also be zero if the size is (still) unknown.
106 struct pet_expr {
107 int ref;
108 isl_ctx *ctx;
110 uint32_t hash;
112 enum pet_expr_type type;
114 int type_size;
116 unsigned n_arg;
117 pet_expr **args;
119 union {
120 struct pet_expr_access acc;
121 enum pet_op_type op;
122 struct pet_expr_call c;
123 char *type_name;
124 struct pet_expr_double d;
125 isl_val *i;
129 const char *pet_type_str(enum pet_expr_type type);
130 enum pet_expr_type pet_str_type(const char *str);
132 enum pet_op_type pet_str_op(const char *str);
134 __isl_give pet_expr *pet_expr_alloc(isl_ctx *ctx, enum pet_expr_type type);
135 __isl_give pet_expr *pet_expr_kill_from_access_and_index(
136 __isl_take isl_map *access, __isl_take isl_multi_pw_aff *index);
137 __isl_give pet_expr *pet_expr_new_unary(int type_size, enum pet_op_type op,
138 __isl_take pet_expr *arg);
139 __isl_give pet_expr *pet_expr_new_binary(int type_size, enum pet_op_type op,
140 __isl_take pet_expr *lhs, __isl_take pet_expr *rhs);
141 __isl_give pet_expr *pet_expr_new_ternary(__isl_take pet_expr *cond,
142 __isl_take pet_expr *lhs, __isl_take pet_expr *rhs);
143 __isl_give pet_expr *pet_expr_new_call(isl_ctx *ctx, const char *name,
144 unsigned n_arg);
145 __isl_give pet_expr *pet_expr_new_double(isl_ctx *ctx, double d, const char *s);
146 __isl_give pet_expr *pet_expr_new_int(__isl_take isl_val *v);
148 __isl_give pet_expr *pet_expr_arg(__isl_take pet_expr *expr, int pos);
150 __isl_give pet_expr *pet_expr_cow(__isl_take pet_expr *expr);
152 __isl_give isl_pw_aff *pet_expr_extract_affine_condition(
153 __isl_keep pet_expr *expr, __isl_keep pet_context *pc);
154 __isl_give isl_pw_aff *pet_expr_extract_comparison(enum pet_op_type op,
155 __isl_keep pet_expr *lhs, __isl_keep pet_expr *rhs,
156 __isl_keep pet_context *pc);
157 __isl_give pet_expr *pet_expr_resolve_assume(__isl_take pet_expr *expr,
158 __isl_keep pet_context *pc);
160 uint32_t pet_expr_get_hash(__isl_keep pet_expr *expr);
162 int pet_expr_is_address_of(__isl_keep pet_expr *expr);
163 int pet_expr_is_assume(__isl_keep pet_expr *expr);
164 int pet_expr_is_boolean(__isl_keep pet_expr *expr);
165 int pet_expr_is_comparison(__isl_keep pet_expr *expr);
166 int pet_expr_is_min(__isl_keep pet_expr *expr);
167 int pet_expr_is_max(__isl_keep pet_expr *expr);
168 int pet_expr_is_scalar_access(__isl_keep pet_expr *expr);
169 int pet_expr_is_equal(__isl_keep pet_expr *expr1, __isl_keep pet_expr *expr2);
170 isl_bool pet_expr_is_same_access(__isl_keep pet_expr *expr1,
171 __isl_keep pet_expr *expr2);
173 __isl_give isl_pw_aff *pet_expr_get_affine(__isl_keep pet_expr *expr);
174 __isl_give isl_space *pet_expr_access_get_parameter_space(
175 __isl_take pet_expr *expr);
176 __isl_give isl_space *pet_expr_access_get_augmented_domain_space(
177 __isl_keep pet_expr *expr);
178 __isl_give isl_space *pet_expr_access_get_domain_space(
179 __isl_keep pet_expr *expr);
180 isl_stat pet_expr_access_foreach_data_space(__isl_keep pet_expr *expr,
181 isl_stat (*fn)(__isl_take isl_space *space, void *user), void *user);
183 isl_bool pet_expr_access_has_any_access_relation(__isl_keep pet_expr *expr);
184 __isl_give isl_union_map *pet_expr_access_get_dependent_access(
185 __isl_keep pet_expr *expr, enum pet_expr_access_type type);
186 __isl_give isl_map *pet_expr_access_get_may_access(__isl_keep pet_expr *expr);
188 __isl_give pet_expr *pet_expr_map_top_down(__isl_take pet_expr *expr,
189 __isl_give pet_expr *(*fn)(__isl_take pet_expr *expr, void *user),
190 void *user);
191 __isl_give pet_expr *pet_expr_map_access(__isl_take pet_expr *expr,
192 __isl_give pet_expr *(*fn)(__isl_take pet_expr *expr, void *user),
193 void *user);
194 __isl_give pet_expr *pet_expr_map_call(__isl_take pet_expr *expr,
195 __isl_give pet_expr *(*fn)(__isl_take pet_expr *expr, void *user),
196 void *user);
197 __isl_give pet_expr *pet_expr_map_op(__isl_take pet_expr *expr,
198 __isl_give pet_expr *(*fn)(__isl_take pet_expr *expr, void *user),
199 void *user);
201 __isl_give isl_union_map *pet_expr_access_get_access(__isl_keep pet_expr *expr,
202 enum pet_expr_access_type type);
203 __isl_give pet_expr *pet_expr_access_set_access(__isl_take pet_expr *expr,
204 enum pet_expr_access_type type, __isl_take isl_union_map *access);
205 __isl_give pet_expr *pet_expr_access_set_index(__isl_take pet_expr *expr,
206 __isl_take isl_multi_pw_aff *index);
208 int pet_expr_is_sub_access(__isl_keep pet_expr *expr1,
209 __isl_keep pet_expr *expr2, int n_arg);
211 int pet_expr_writes(__isl_keep pet_expr *expr, __isl_keep isl_id *id);
213 __isl_give pet_expr *pet_expr_access_move_dims(__isl_take pet_expr *expr,
214 enum isl_dim_type dst_type, unsigned dst_pos,
215 enum isl_dim_type src_type, unsigned src_pos, unsigned n);
216 __isl_give pet_expr *pet_expr_access_pullback_multi_aff(
217 __isl_take pet_expr *expr, __isl_take isl_multi_aff *ma);
218 __isl_give pet_expr *pet_expr_access_pullback_multi_pw_aff(
219 __isl_take pet_expr *expr, __isl_take isl_multi_pw_aff *mpa);
220 __isl_give pet_expr *pet_expr_access_align_params(__isl_take pet_expr *expr);
221 __isl_give pet_expr *pet_expr_restrict(__isl_take pet_expr *expr,
222 __isl_take isl_set *cond);
223 __isl_give pet_expr *pet_expr_access_update_domain(__isl_take pet_expr *expr,
224 __isl_keep isl_multi_pw_aff *update);
225 __isl_give pet_expr *pet_expr_update_domain(__isl_take pet_expr *expr,
226 __isl_take isl_multi_pw_aff *update);
227 __isl_give pet_expr *pet_expr_align_params(__isl_take pet_expr *expr,
228 __isl_take isl_space *space);
229 __isl_give pet_expr *pet_expr_filter(__isl_take pet_expr *expr,
230 __isl_take isl_multi_pw_aff *test, int satisfied);
231 __isl_give pet_expr *pet_expr_add_ref_ids(__isl_take pet_expr *expr,
232 int *n_ref);
233 __isl_give pet_expr *pet_expr_anonymize(__isl_take pet_expr *expr);
234 __isl_give pet_expr *pet_expr_gist(__isl_take pet_expr *expr,
235 __isl_keep isl_set *context, __isl_keep isl_union_map *value_bounds);
237 __isl_give isl_union_map *pet_expr_tag_access(__isl_keep pet_expr *expr,
238 __isl_take isl_union_map *access);
240 __isl_give pet_expr *pet_expr_access_subscript(__isl_take pet_expr *base,
241 __isl_take pet_expr *index);
242 __isl_give pet_expr *pet_expr_access_member(__isl_take pet_expr *base,
243 __isl_take isl_id *member);
245 int pet_expr_call_has_summary(__isl_keep pet_expr *expr);
246 __isl_give pet_function_summary *pet_expr_call_get_summary(
247 __isl_keep pet_expr *expr);
248 __isl_give pet_expr *pet_expr_call_set_summary(__isl_take pet_expr *expr,
249 __isl_take pet_function_summary *summary);
251 int pet_expr_get_type_size(__isl_keep pet_expr *expr);
252 __isl_give pet_expr *pet_expr_set_type_size(__isl_take pet_expr *expr,
253 int type_size);
254 __isl_give pet_expr *pet_expr_access_set_depth(__isl_take pet_expr *expr,
255 int depth);
257 __isl_give pet_expr *pet_expr_insert_domain(__isl_take pet_expr *expr,
258 __isl_take isl_space *space);
260 __isl_give pet_expr *pet_expr_access_patch(__isl_take pet_expr *expr,
261 __isl_take isl_multi_pw_aff *prefix, int add);
263 __isl_give isl_printer *pet_expr_print(__isl_keep pet_expr *expr,
264 __isl_take isl_printer *p);
265 void pet_expr_dump_with_indent(__isl_keep pet_expr *expr, int indent);
267 #if defined(__cplusplus)
269 #endif
271 #endif