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