isl_schedule_node.c: collect_filter_prefix: allow caller to initialize filter
[isl.git] / isl_ast_build_private.h
blobf7f921fddf68366927fd1da3791d1509d5089227
1 #ifndef ISL_AST_BUILD_PRIVATE_H
2 #define ISL_AST_BUILD_PRIVATE_H
4 #include <isl/aff.h>
5 #include <isl/ast.h>
6 #include <isl/ast_build.h>
7 #include <isl/set.h>
8 #include <isl/list.h>
9 #include <isl/schedule_node.h>
11 /* An isl_ast_build represents the context in which AST is being
12 * generated. That is, it (mostly) contains information about outer
13 * loops that can be used to simplify inner loops.
15 * "domain" represents constraints on the internal schedule domain,
16 * corresponding to the context of the AST generation and the constraints
17 * implied by the loops that have already been generated.
18 * When an isl_ast_build is first created, outside any AST generation,
19 * the domain is typically a parameter set. It is only when a AST
20 * generation phase is initiated that the domain of the isl_ast_build
21 * is changed to refer to the internal schedule domain.
22 * The domain then lives in a space of the form
24 * S
26 * or
28 * [O -> S]
30 * O represents the loops generated in outer AST generations.
31 * S represents the loops (both generated and to be generated)
32 * of the current AST generation.
33 * Both include eliminated loops.
34 * "domain" is expected not to have any unknown divs because
35 * it is used as the context argument in a call to isl_basic_set_gist
36 * in isl_ast_build_compute_gist_basic_set.
38 * "depth" is equal to the number of loops that have already
39 * been generated (including those in outer AST generations).
40 * "outer_pos" is equal to the number of loops in outer AST generations.
42 * "generated" is a superset of "domain" corresponding to those
43 * constraints that were either given by the user or that have
44 * effectively been generated (as bounds on a for loop).
46 * "pending" is a superset of "domain" corresponding to the constraints
47 * that still need to be generated (as guards), but that may end up
48 * not getting generated if they are implied by any constraints
49 * enforced by inner loops.
51 * "strides" contains the stride of each loop. The number of elements
52 * is equal to the number of dimensions in "domain".
53 * "offsets" constains the offsets of strided loops. If s is the stride
54 * for a given dimension and f is the corresponding offset, then the
55 * dimension takes on values
57 * f + s a
59 * with a an integer. For non-strided loops, the offset is zero.
61 * "iterators" contains the loop iterators of both generated and
62 * to be generated loops. The number of elements is at least as
63 * large as the dimension of the internal schedule domain. The
64 * number may be larger, in which case the additional ids can be
65 * used in a nested AST generation should the schedule be non-injective.
67 * "values" lives in the space
69 * [O -> S] -> [O -> S] (or S -> S)
71 * and expresses (if possible) loop iterators in terms of parameters
72 * and outer loop iterators. If the value of a given loop iterator
73 * cannot be expressed as an affine expression (either because the iterator
74 * attains multiple values or because the single value is a piecewise
75 * affine expression), then it is expressed in "values" as being equal
76 * to itself.
78 * "value" is the value of the loop iterator at the current depth.
79 * It is NULL if it has not been computed yet or if the value of the
80 * given loop iterator cannot be expressed as a piecewise affine expression
81 * (because the iterator attains multiple values).
83 * "schedule_map" maps the internal schedule domain to the external schedule
84 * domain. It may be NULL if it hasn't been computed yet.
85 * See isl_ast_build_get_schedule_map_multi_aff.
87 * "internal2input" maps the internal schedule domain to the original
88 * input schedule domain. In case of a schedule tree input, the original
89 * input schedule domain consist of the flat product of all outer
90 * band node spaces, including the current band node.
91 * It may be NULL if there no longer is such a uniform mapping
92 * (because different iterations have been rescheduled differently).
94 * "options" contains the AST build options in case we are generating
95 * an AST from a flat schedule map. When creating an AST from a schedule
96 * tree, this field is ignored.
98 * The "create_leaf" callback is called for every leaf in the generated AST.
99 * The callback is responsible for creating the node to be placed at those
100 * leaves. If this callback is not set, then isl will generated user
101 * nodes with call expressions corresponding to an element of the domain.
103 * The "at_each_domain" callback is called on every node created to represent
104 * an element of the domain. Each of these nodes is a user node
105 * with as expression a call expression.
107 * The "before_each_for" callback is called on each for node before
108 * its children have been created.
110 * The "after_each_for" callback is called on each for node after
111 * its children have been created.
113 * "executed" contains the inverse schedule at this point
114 * of the AST generation.
115 * It is currently only used in isl_ast_build_get_schedule, which is
116 * in turn only used by user code from within a callback.
117 * The value is set right before we may be calling such a callback.
119 * "single_valued" is set if the current inverse schedule (which may or may
120 * not be stored in "executed") is known to be single valued, specifically
121 * an inverse schedule that was not (appeared not to be) single valued
122 * is extended to a single valued inverse schedule. This is mainly used
123 * to avoid an infinite recursion when we fail to detect later on that
124 * the extended inverse schedule is single valued.
126 * "node" points to the current band node in case we are generating
127 * an AST from a schedule tree. It may be NULL if we are not generating
128 * an AST from a schedule tree or if we are not inside a band node.
130 * "loop_type" originally constains loop AST generation types for
131 * the "n" members of "node" and it is updated (along with "n") when
132 * a schedule dimension is inserted.
133 * It is NULL if "node" is NULL.
135 * "isolated" is the piece of the schedule domain isolated by the isolate
136 * option on the current band. This set may be NULL if we have not checked
137 * for the isolate option yet.
139 struct isl_ast_build {
140 int ref;
142 int outer_pos;
143 int depth;
145 isl_id_list *iterators;
147 isl_set *domain;
148 isl_set *generated;
149 isl_set *pending;
150 isl_multi_aff *values;
152 isl_pw_aff *value;
154 isl_vec *strides;
155 isl_multi_aff *offsets;
157 isl_multi_aff *schedule_map;
158 isl_multi_aff *internal2input;
160 isl_union_map *options;
162 __isl_give isl_ast_node *(*at_each_domain)(
163 __isl_take isl_ast_node *node,
164 __isl_keep isl_ast_build *build, void *user);
165 void *at_each_domain_user;
167 __isl_give isl_id *(*before_each_for)(
168 __isl_keep isl_ast_build *context, void *user);
169 void *before_each_for_user;
170 __isl_give isl_ast_node *(*after_each_for)(
171 __isl_take isl_ast_node *node,
172 __isl_keep isl_ast_build *context, void *user);
173 void *after_each_for_user;
175 __isl_give isl_ast_node *(*create_leaf)(
176 __isl_take isl_ast_build *build, void *user);
177 void *create_leaf_user;
179 isl_union_map *executed;
180 int single_valued;
182 isl_schedule_node *node;
183 int n;
184 enum isl_ast_loop_type *loop_type;
185 isl_set *isolated;
188 __isl_give isl_ast_build *isl_ast_build_clear_local_info(
189 __isl_take isl_ast_build *build);
190 __isl_give isl_ast_build *isl_ast_build_increase_depth(
191 __isl_take isl_ast_build *build);
192 int isl_ast_build_get_depth(__isl_keep isl_ast_build *build);
193 unsigned isl_ast_build_dim(__isl_keep isl_ast_build *build,
194 enum isl_dim_type type);
195 __isl_give isl_space *isl_ast_build_get_space(
196 __isl_keep isl_ast_build *build, int internal);
197 __isl_give isl_ast_build *isl_ast_build_align_params(
198 __isl_take isl_ast_build *build, __isl_take isl_space *model);
199 __isl_give isl_ast_build *isl_ast_build_cow(
200 __isl_take isl_ast_build *build);
201 __isl_give isl_ast_build *isl_ast_build_insert_dim(
202 __isl_take isl_ast_build *build, int pos);
203 __isl_give isl_ast_build *isl_ast_build_scale_down(
204 __isl_take isl_ast_build *build, __isl_take isl_val *m,
205 __isl_take isl_union_map *umap);
206 __isl_give isl_ast_build *isl_ast_build_product(
207 __isl_take isl_ast_build *build, __isl_take isl_space *embedding);
208 __isl_give isl_ast_build *isl_ast_build_set_loop_bounds(
209 __isl_take isl_ast_build *build, __isl_take isl_basic_set *bounds);
210 __isl_give isl_ast_build *isl_ast_build_detect_strides(
211 __isl_take isl_ast_build *build, __isl_take isl_set *set);
212 __isl_give isl_ast_build *isl_ast_build_include_stride(
213 __isl_take isl_ast_build *build);
214 __isl_give isl_ast_build *isl_ast_build_set_executed(
215 __isl_take isl_ast_build *build,
216 __isl_take isl_union_map *executed);
217 __isl_give isl_ast_build *isl_ast_build_set_single_valued(
218 __isl_take isl_ast_build *build, int sv);
219 __isl_give isl_multi_aff *isl_ast_build_get_internal2input(
220 __isl_keep isl_ast_build *build);
221 __isl_give isl_set *isl_ast_build_get_domain(
222 __isl_keep isl_ast_build *build);
223 __isl_give isl_set *isl_ast_build_get_pending(
224 __isl_keep isl_ast_build *build);
225 __isl_give isl_set *isl_ast_build_get_generated(
226 __isl_keep isl_ast_build *build);
227 __isl_give isl_ast_build *isl_ast_build_restrict_generated(
228 __isl_take isl_ast_build *build, __isl_take isl_set *set);
229 __isl_give isl_ast_build *isl_ast_build_replace_pending_by_guard(
230 __isl_take isl_ast_build *build, __isl_take isl_set *guard);
231 __isl_give isl_ast_build *isl_ast_build_restrict_pending(
232 __isl_take isl_ast_build *build, __isl_take isl_set *set);
233 __isl_give int isl_ast_build_need_schedule_map(
234 __isl_keep isl_ast_build *build);
235 __isl_give isl_multi_aff *isl_ast_build_get_schedule_map_multi_aff(
236 __isl_keep isl_ast_build *build);
237 __isl_give isl_map *isl_ast_build_get_schedule_map(
238 __isl_keep isl_ast_build *build);
239 int isl_ast_build_has_affine_value(__isl_keep isl_ast_build *build, int pos);
240 int isl_ast_build_has_value(__isl_keep isl_ast_build *build);
241 __isl_give isl_id *isl_ast_build_get_iterator_id(
242 __isl_keep isl_ast_build *build, int pos);
244 int isl_ast_build_has_schedule_node(__isl_keep isl_ast_build *build);
245 __isl_give isl_schedule_node *isl_ast_build_get_schedule_node(
246 __isl_keep isl_ast_build *build);
247 __isl_give isl_ast_build *isl_ast_build_set_schedule_node(
248 __isl_take isl_ast_build *build,
249 __isl_take isl_schedule_node *node);
250 __isl_give isl_ast_build *isl_ast_build_reset_schedule_node(
251 __isl_take isl_ast_build *build);
253 __isl_give isl_ast_build *isl_ast_build_extract_isolated(
254 __isl_take isl_ast_build *build);
255 int isl_ast_build_has_isolated(__isl_keep isl_ast_build *build);
256 __isl_give isl_set *isl_ast_build_get_isolated(
257 __isl_keep isl_ast_build *build);
259 __isl_give isl_basic_set *isl_ast_build_compute_gist_basic_set(
260 __isl_keep isl_ast_build *build, __isl_take isl_basic_set *bset);
261 __isl_give isl_set *isl_ast_build_specialize(__isl_keep isl_ast_build *build,
262 __isl_take isl_set *set);
263 __isl_give isl_set *isl_ast_build_compute_gist(
264 __isl_keep isl_ast_build *build, __isl_take isl_set *set);
265 __isl_give isl_map *isl_ast_build_compute_gist_map_domain(
266 __isl_keep isl_ast_build *build, __isl_take isl_map *map);
267 __isl_give isl_aff *isl_ast_build_compute_gist_aff(
268 __isl_keep isl_ast_build *build, __isl_take isl_aff *aff);
269 __isl_give isl_pw_aff *isl_ast_build_compute_gist_pw_aff(
270 __isl_keep isl_ast_build *build, __isl_take isl_pw_aff *pa);
271 __isl_give isl_pw_multi_aff *isl_ast_build_compute_gist_pw_multi_aff(
272 __isl_keep isl_ast_build *build, __isl_take isl_pw_multi_aff *pma);
274 __isl_give isl_union_map *isl_ast_build_substitute_values_union_map_domain(
275 __isl_keep isl_ast_build *build, __isl_take isl_union_map *umap);
277 int isl_ast_build_aff_is_nonneg(__isl_keep isl_ast_build *build,
278 __isl_keep isl_aff *aff);
280 int isl_ast_build_has_stride(__isl_keep isl_ast_build *build, int pos);
281 __isl_give isl_aff *isl_ast_build_get_offset(__isl_keep isl_ast_build *build,
282 int pos);
283 __isl_give isl_val *isl_ast_build_get_stride(__isl_keep isl_ast_build *build,
284 int pos);
285 __isl_give isl_set *isl_ast_build_get_stride_constraint(
286 __isl_keep isl_ast_build *build);
287 __isl_give isl_multi_aff *isl_ast_build_get_stride_expansion(
288 __isl_keep isl_ast_build *build);
290 void isl_ast_build_dump(__isl_keep isl_ast_build *build);
292 __isl_give isl_set *isl_ast_build_get_option_domain(
293 __isl_keep isl_ast_build *build, enum isl_ast_loop_type type);
294 __isl_give isl_map *isl_ast_build_get_separation_class(
295 __isl_keep isl_ast_build *build);
296 __isl_give isl_set *isl_ast_build_eliminate(
297 __isl_keep isl_ast_build *build, __isl_take isl_set *domain);
298 __isl_give isl_set *isl_ast_build_eliminate_inner(
299 __isl_keep isl_ast_build *build, __isl_take isl_set *set);
300 __isl_give isl_set *isl_ast_build_eliminate_divs(
301 __isl_keep isl_ast_build *build, __isl_take isl_set *set);
303 enum isl_ast_loop_type isl_ast_build_get_loop_type(
304 __isl_keep isl_ast_build *build, int isolated);
306 __isl_give isl_map *isl_ast_build_map_to_iterator(
307 __isl_keep isl_ast_build *build, __isl_take isl_set *set);
309 int isl_ast_build_options_involve_depth(__isl_keep isl_ast_build *build);
311 #endif