pet_expr_filter: avoid introduction of constraints in index expression
[pet.git] / expr.h
blob8008c0843187cee7e9e82c3bfe38454f50229687
1 #ifndef PET_EXPR_H
2 #define PET_EXPR_H
4 #include <isl/id_to_pw_aff.h>
6 #include <pet.h>
8 #include "context.h"
10 #if defined(__cplusplus)
11 extern "C" {
12 #endif
14 /* d is valid when type == pet_expr_double
15 * i isl valid when type == pet_expr_int
16 * acc is valid when type == pet_expr_access
17 * name is valid when type == pet_expr_call
18 * type is valid when type == pet_expr_cast
19 * op is valid otherwise
21 * If type_size is not zero, then the expression is of an integer type
22 * and type_size represents the size of the type in bits.
23 * If type_size is greater than zero, then the type is unsigned
24 * and the number of bits is equal to type_size.
25 * If type_size is less than zero, then the type is signed
26 * and the number of bits is equal to -type_size.
27 * type_size may also be zero if the size is (still) unknown.
29 * For each access expression inside the body of a statement, acc.ref_id
30 * is a unique reference identifier.
31 * acc.index represents the index expression, while acc.access
32 * represents the corresponding access relation.
33 * The output dimension of the index expression may be smaller
34 * than the number of dimensions of the accessed array.
35 * The target space of the access relation, on the other hand,
36 * is equal to the array space.
37 * Both acc.index and acc.access usually map an iteration space
38 * to a (partial) data space.
39 * If the access has arguments, however, then the domain of the
40 * mapping is a wrapped mapping from the iteration space
41 * to a space of dimensionality equal to the number of arguments.
42 * Each dimension in this space corresponds to the value of the
43 * corresponding argument.
45 * The ranges of the index expressions and access relations may
46 * also be wrapped relations, in which case the expression represents
47 * a member access, with the structure represented by the domain
48 * of this wrapped relation and the member represented by the range.
49 * In case of nested member accesses, the domain is itself a wrapped
50 * relation.
52 * If the data space is unnamed (and 1D), then it represents
53 * the set of integers. That is, the access represents a value that
54 * is equal to the index.
56 * A double is represented as both an (approximate) value "val" and
57 * a string representation "s".
59 struct pet_expr {
60 int ref;
61 isl_ctx *ctx;
63 enum pet_expr_type type;
65 int type_size;
67 unsigned n_arg;
68 pet_expr **args;
70 union {
71 struct {
72 isl_id *ref_id;
73 isl_map *access;
74 isl_multi_pw_aff *index;
75 int read;
76 int write;
77 } acc;
78 enum pet_op_type op;
79 char *name;
80 char *type_name;
81 struct {
82 double val;
83 char *s;
84 } d;
85 isl_val *i;
89 const char *pet_type_str(enum pet_expr_type type);
90 enum pet_expr_type pet_str_type(const char *str);
92 enum pet_op_type pet_str_op(const char *str);
94 __isl_give pet_expr *pet_expr_alloc(isl_ctx *ctx, enum pet_expr_type type);
95 __isl_give pet_expr *pet_expr_from_access_and_index(__isl_take isl_map *access,
96 __isl_take isl_multi_pw_aff *index);
97 __isl_give pet_expr *pet_expr_kill_from_access_and_index(
98 __isl_take isl_map *access, __isl_take isl_multi_pw_aff *index);
99 __isl_give pet_expr *pet_expr_new_unary(enum pet_op_type op,
100 __isl_take pet_expr *arg);
101 __isl_give pet_expr *pet_expr_new_binary(int type_size, enum pet_op_type op,
102 __isl_take pet_expr *lhs, __isl_take pet_expr *rhs);
103 __isl_give pet_expr *pet_expr_new_ternary(__isl_take pet_expr *cond,
104 __isl_take pet_expr *lhs, __isl_take pet_expr *rhs);
105 __isl_give pet_expr *pet_expr_new_call(isl_ctx *ctx, const char *name,
106 unsigned n_arg);
107 __isl_give pet_expr *pet_expr_new_cast(const char *type_name,
108 __isl_take pet_expr *arg);
109 __isl_give pet_expr *pet_expr_new_double(isl_ctx *ctx, double d, const char *s);
110 __isl_give pet_expr *pet_expr_new_int(__isl_take isl_val *v);
112 __isl_give pet_expr *pet_expr_cow(__isl_take pet_expr *expr);
114 __isl_give isl_pw_aff *pet_expr_extract_affine(__isl_keep pet_expr *expr,
115 __isl_keep pet_context *pc);
116 __isl_give isl_pw_aff *pet_expr_extract_affine_condition(
117 __isl_keep pet_expr *expr, __isl_keep pet_context *pc);
118 __isl_give isl_pw_aff *pet_expr_extract_comparison(enum pet_op_type op,
119 __isl_keep pet_expr *lhs, __isl_keep pet_expr *rhs,
120 __isl_keep pet_context *pc);
121 __isl_give pet_expr *pet_expr_resolve_assume(__isl_take pet_expr *expr,
122 __isl_keep pet_context *pc);
124 int pet_expr_is_assume(__isl_keep pet_expr *expr);
125 int pet_expr_is_boolean(__isl_keep pet_expr *expr);
126 int pet_expr_is_comparison(__isl_keep pet_expr *expr);
127 int pet_expr_is_min(__isl_keep pet_expr *expr);
128 int pet_expr_is_max(__isl_keep pet_expr *expr);
129 int pet_expr_is_scalar_access(__isl_keep pet_expr *expr);
130 int pet_expr_is_equal(__isl_keep pet_expr *expr1, __isl_keep pet_expr *expr2);
132 __isl_give isl_space *pet_expr_access_get_parameter_space(
133 __isl_take pet_expr *expr);
134 __isl_give isl_space *pet_expr_access_get_domain_space(
135 __isl_keep pet_expr *expr);
136 __isl_give isl_space *pet_expr_access_get_data_space(__isl_keep pet_expr *expr);
138 __isl_give pet_expr *pet_expr_map_access(__isl_take pet_expr *expr,
139 __isl_give pet_expr *(*fn)(__isl_take pet_expr *expr, void *user),
140 void *user);
142 __isl_give isl_map *pet_expr_access_get_access(__isl_keep pet_expr *expr);
143 __isl_give pet_expr *pet_expr_access_set_access(__isl_take pet_expr *expr,
144 __isl_take isl_map *access);
145 __isl_give pet_expr *pet_expr_access_set_index(__isl_take pet_expr *expr,
146 __isl_take isl_multi_pw_aff *index);
148 int pet_expr_writes(__isl_keep pet_expr *expr, __isl_keep isl_id *id);
150 __isl_give pet_expr *pet_expr_access_move_dims(__isl_take pet_expr *expr,
151 enum isl_dim_type dst_type, unsigned dst_pos,
152 enum isl_dim_type src_type, unsigned src_pos, unsigned n);
153 __isl_give pet_expr *pet_expr_access_pullback_multi_aff(
154 __isl_take pet_expr *expr, __isl_take isl_multi_aff *ma);
155 __isl_give pet_expr *pet_expr_access_pullback_multi_pw_aff(
156 __isl_take pet_expr *expr, __isl_take isl_multi_pw_aff *mpa);
157 __isl_give pet_expr *pet_expr_access_align_params(__isl_take pet_expr *expr);
158 __isl_give pet_expr *pet_expr_restrict(__isl_take pet_expr *expr,
159 __isl_take isl_set *cond);
160 __isl_give pet_expr *pet_expr_access_update_domain(__isl_take pet_expr *expr,
161 __isl_keep isl_multi_pw_aff *update);
162 __isl_give pet_expr *pet_expr_update_domain(__isl_take pet_expr *expr,
163 __isl_take isl_multi_pw_aff *update);
164 __isl_give pet_expr *pet_expr_align_params(__isl_take pet_expr *expr,
165 __isl_take isl_space *space);
166 __isl_give pet_expr *pet_expr_filter(__isl_take pet_expr *expr,
167 __isl_take isl_multi_pw_aff *test, int satisfied);
168 __isl_give pet_expr *pet_expr_detect_parameter_accesses(
169 __isl_take pet_expr *expr, __isl_take isl_space *space);
170 __isl_give pet_expr *pet_expr_add_ref_ids(__isl_take pet_expr *expr,
171 int *n_ref);
172 __isl_give pet_expr *pet_expr_anonymize(__isl_take pet_expr *expr);
173 __isl_give pet_expr *pet_expr_gist(__isl_take pet_expr *expr,
174 __isl_keep isl_set *context, __isl_keep isl_union_map *value_bounds);
176 __isl_give isl_map *pet_expr_tag_access(__isl_keep pet_expr *expr,
177 __isl_take isl_map *access);
179 __isl_give pet_expr *pet_expr_access_subscript(__isl_take pet_expr *base,
180 __isl_take pet_expr *index);
181 __isl_give pet_expr *pet_expr_access_member(__isl_take pet_expr *base,
182 __isl_take isl_id *member);
184 int pet_expr_get_type_size(__isl_keep pet_expr *expr);
185 __isl_give pet_expr *pet_expr_set_type_size(__isl_take pet_expr *expr,
186 int type_size);
187 __isl_give pet_expr *pet_expr_access_set_depth(__isl_take pet_expr *expr,
188 int depth);
190 void pet_expr_dump_with_indent(__isl_keep pet_expr *expr, int indent);
192 #if defined(__cplusplus)
194 #endif
196 #endif