Polly 19.0.0git
isl_schedule_read.c
Go to the documentation of this file.
1#include <isl/id.h>
2#include <isl/val.h>
3#include <isl/schedule.h>
4#include <isl/stream.h>
6#include <isl_schedule_tree.h>
7
8/* An enumeration of the various keys that may appear in a YAML mapping
9 * of a schedule.
10 */
30};
31
32/* Textual representations of the YAML keys for an isl_schedule object.
33 */
34static char *key_str[] = {
35 [isl_schedule_key_child] = "child",
36 [isl_schedule_key_coincident] = "coincident",
37 [isl_schedule_key_context] = "context",
38 [isl_schedule_key_contraction] = "contraction",
39 [isl_schedule_key_domain] = "domain",
40 [isl_schedule_key_expansion] = "expansion",
41 [isl_schedule_key_extension] = "extension",
42 [isl_schedule_key_filter] = "filter",
43 [isl_schedule_key_guard] = "guard",
44 [isl_schedule_key_leaf] = "leaf",
45 [isl_schedule_key_mark] = "mark",
46 [isl_schedule_key_options] = "options",
47 [isl_schedule_key_permutable] = "permutable",
48 [isl_schedule_key_schedule] = "schedule",
49 [isl_schedule_key_sequence] = "sequence",
50 [isl_schedule_key_set] = "set",
51};
52
53#undef KEY
54#define KEY enum isl_schedule_key
55#undef KEY_ERROR
56#define KEY_ERROR isl_schedule_key_error
57#undef KEY_END
58#define KEY_END isl_schedule_key_end
59#undef KEY_STR
60#define KEY_STR key_str
61#undef KEY_EXTRACT
62#define KEY_EXTRACT extract_key
63#undef KEY_GET
64#define KEY_GET get_key
65#include "extract_key.c"
66
69
70/* Read a subtree with context root node from "s".
71 */
73{
74 isl_set *context = NULL;
76 isl_ctx *ctx;
77 struct isl_token *tok;
79 char *str;
80 isl_bool more;
81
82 ctx = isl_stream_get_ctx(s);
83
84 key = get_key(s);
85
86 if (isl_stream_yaml_next(s) < 0)
87 return NULL;
88
90 if (!tok) {
91 isl_stream_error(s, NULL, "unexpected EOF");
92 return NULL;
93 }
94 str = isl_token_get_str(ctx, tok);
96 free(str);
97 isl_token_free(tok);
98
99 more = isl_stream_yaml_next(s);
100 if (more < 0)
101 goto error;
102 if (!more) {
104 } else {
105 key = get_key(s);
107 isl_die(ctx, isl_error_invalid, "expecting child",
108 goto error);
109 if (isl_stream_yaml_next(s) < 0)
110 goto error;
113 }
114
115 return tree;
116error:
118 return NULL;
119}
120
121/* Read a subtree with domain root node from "s".
122 */
124{
125 isl_union_set *domain = NULL;
127 isl_ctx *ctx;
128 struct isl_token *tok;
130 char *str;
131 isl_bool more;
132
133 ctx = isl_stream_get_ctx(s);
134
135 key = get_key(s);
136
137 if (isl_stream_yaml_next(s) < 0)
138 return NULL;
139
141 if (!tok) {
142 isl_stream_error(s, NULL, "unexpected EOF");
143 return NULL;
144 }
145 str = isl_token_get_str(ctx, tok);
147 free(str);
148 isl_token_free(tok);
149
150 more = isl_stream_yaml_next(s);
151 if (more < 0)
152 goto error;
153 if (!more) {
155 } else {
156 key = get_key(s);
158 isl_die(ctx, isl_error_invalid, "expecting child",
159 goto error);
160 if (isl_stream_yaml_next(s) < 0)
161 goto error;
164 }
165
166 return tree;
167error:
169 return NULL;
170}
171
172/* Read a subtree with expansion root node from "s".
173 */
175{
176 isl_ctx *ctx;
177 isl_union_pw_multi_aff *contraction = NULL;
178 isl_union_map *expansion = NULL;
179 isl_schedule_tree *tree = NULL;
180 isl_bool more;
181
182 ctx = isl_stream_get_ctx(s);
183
184 do {
185 struct isl_token *tok;
187 char *str;
188
189 key = get_key(s);
190 if (isl_stream_yaml_next(s) < 0)
191 goto error;
192
193 switch (key) {
195 isl_union_pw_multi_aff_free(contraction);
197 str = isl_token_get_str(ctx, tok);
198 contraction = isl_union_pw_multi_aff_read_from_str(ctx,
199 str);
200 free(str);
201 isl_token_free(tok);
202 if (!contraction)
203 goto error;
204 break;
206 isl_union_map_free(expansion);
208 str = isl_token_get_str(ctx, tok);
209 expansion = isl_union_map_read_from_str(ctx, str);
210 free(str);
211 isl_token_free(tok);
212 if (!expansion)
213 goto error;
214 break;
218 if (!tree)
219 goto error;
220 break;
221 default:
222 isl_die(ctx, isl_error_invalid, "unexpected key",
223 goto error);
224 }
225 } while ((more = isl_stream_yaml_next(s)) == isl_bool_true);
226
227 if (more < 0)
228 goto error;
229
230 if (!contraction)
231 isl_die(ctx, isl_error_invalid, "missing contraction",
232 goto error);
233 if (!expansion)
234 isl_die(ctx, isl_error_invalid, "missing expansion",
235 goto error);
236
237 if (!tree)
238 return isl_schedule_tree_from_expansion(contraction, expansion);
239 return isl_schedule_tree_insert_expansion(tree, contraction, expansion);
240error:
242 isl_union_pw_multi_aff_free(contraction);
243 isl_union_map_free(expansion);
244 return NULL;
245}
246
247/* Read a subtree with extension root node from "s".
248 */
250{
251 isl_union_map *extension = NULL;
253 isl_ctx *ctx;
254 struct isl_token *tok;
256 char *str;
257 isl_bool more;
258
259 ctx = isl_stream_get_ctx(s);
260
261 key = get_key(s);
262
263 if (isl_stream_yaml_next(s) < 0)
264 return NULL;
265
267 if (!tok) {
268 isl_stream_error(s, NULL, "unexpected EOF");
269 return NULL;
270 }
271 str = isl_token_get_str(ctx, tok);
272 extension = isl_union_map_read_from_str(ctx, str);
273 free(str);
274 isl_token_free(tok);
275
276 more = isl_stream_yaml_next(s);
277 if (more < 0)
278 goto error;
279 if (!more) {
281 } else {
282 key = get_key(s);
284 isl_die(ctx, isl_error_invalid, "expecting child",
285 goto error);
286 if (isl_stream_yaml_next(s) < 0)
287 goto error;
290 }
291
292 return tree;
293error:
294 isl_union_map_free(extension);
295 return NULL;
296}
297
298/* Read a subtree with filter root node from "s".
299 */
301{
302 isl_union_set *filter = NULL;
304 isl_ctx *ctx;
305 struct isl_token *tok;
307 char *str;
308 isl_bool more;
309
310 ctx = isl_stream_get_ctx(s);
311
312 key = get_key(s);
313
314 if (isl_stream_yaml_next(s) < 0)
315 return NULL;
316
318 if (!tok) {
319 isl_stream_error(s, NULL, "unexpected EOF");
320 return NULL;
321 }
322 str = isl_token_get_str(ctx, tok);
323 filter = isl_union_set_read_from_str(ctx, str);
324 free(str);
325 isl_token_free(tok);
326
327 more = isl_stream_yaml_next(s);
328 if (more < 0)
329 goto error;
330 if (!more) {
332 } else {
333 key = get_key(s);
335 isl_die(ctx, isl_error_invalid, "expecting child",
336 goto error);
337 if (isl_stream_yaml_next(s) < 0)
338 goto error;
341 }
342
343 return tree;
344error:
345 isl_union_set_free(filter);
346 return NULL;
347}
348
349/* Read a subtree with guard root node from "s".
350 */
352{
353 isl_set *guard = NULL;
355 isl_ctx *ctx;
356 struct isl_token *tok;
358 char *str;
359 isl_bool more;
360
361 ctx = isl_stream_get_ctx(s);
362
363 key = get_key(s);
364
365 if (isl_stream_yaml_next(s) < 0)
366 return NULL;
367
369 if (!tok) {
370 isl_stream_error(s, NULL, "unexpected EOF");
371 return NULL;
372 }
373 str = isl_token_get_str(ctx, tok);
374 guard = isl_set_read_from_str(ctx, str);
375 free(str);
376 isl_token_free(tok);
377
378 more = isl_stream_yaml_next(s);
379 if (more < 0)
380 goto error;
381 if (!more) {
383 } else {
384 key = get_key(s);
386 isl_die(ctx, isl_error_invalid, "expecting child",
387 goto error);
388 if (isl_stream_yaml_next(s) < 0)
389 goto error;
392 }
393
394 return tree;
395error:
396 isl_set_free(guard);
397 return NULL;
398}
399
400/* Read a subtree with mark root node from "s".
401 */
403{
404 isl_id *mark;
406 isl_ctx *ctx;
407 struct isl_token *tok;
409 char *str;
410 isl_bool more;
411
412 ctx = isl_stream_get_ctx(s);
413
414 key = get_key(s);
415
416 if (isl_stream_yaml_next(s) < 0)
417 return NULL;
418
420 if (!tok) {
421 isl_stream_error(s, NULL, "unexpected EOF");
422 return NULL;
423 }
424 str = isl_token_get_str(ctx, tok);
425 mark = isl_id_alloc(ctx, str, NULL);
426 free(str);
427 isl_token_free(tok);
428
429 more = isl_stream_yaml_next(s);
430 if (more < 0)
431 goto error;
432 if (!more) {
433 isl_die(ctx, isl_error_invalid, "expecting child",
434 goto error);
435 } else {
436 key = get_key(s);
438 isl_die(ctx, isl_error_invalid, "expecting child",
439 goto error);
440 if (isl_stream_yaml_next(s) < 0)
441 goto error;
444 }
445
446 return tree;
447error:
448 isl_id_free(mark);
449 return NULL;
450}
451
452#undef EL_BASE
453#define EL_BASE val
454
456
457/* Read a sequence of integers from "s" (representing the coincident
458 * property of a band node).
459 */
461{
462 return isl_stream_yaml_read_val_list(s);
463}
464
465/* Set the (initial) coincident properties of "band" according to
466 * the (initial) elements of "coincident".
467 */
469 __isl_take isl_schedule_band *band, __isl_take isl_val_list *coincident)
470{
471 int i;
472 isl_size n, m;
473
475 m = isl_val_list_n_val(coincident);
476 if (n < 0 || m < 0)
477 band = isl_schedule_band_free(band);
478
479 for (i = 0; i < n && i < m; ++i) {
480 isl_val *v;
481
482 v = isl_val_list_get_val(coincident, i);
483 if (!v)
484 band = isl_schedule_band_free(band);
488 }
489 isl_val_list_free(coincident);
490 return band;
491}
492
493/* Read a subtree with band root node from "s".
494 */
496{
498 isl_schedule_tree *tree = NULL;
499 isl_val_list *coincident = NULL;
500 isl_union_set *options = NULL;
501 isl_ctx *ctx;
502 isl_schedule_band *band;
503 int permutable = 0;
504 isl_bool more;
505
506 ctx = isl_stream_get_ctx(s);
507
508 do {
509 struct isl_token *tok;
511 char *str;
512 isl_val *v;
513
514 key = get_key(s);
515 if (isl_stream_yaml_next(s) < 0)
516 goto error;
517
518 switch (key) {
520 schedule = isl_multi_union_pw_aff_free(schedule);
522 if (!tok) {
523 isl_stream_error(s, NULL, "unexpected EOF");
524 goto error;
525 }
526 str = isl_token_get_str(ctx, tok);
528 str);
529 free(str);
530 isl_token_free(tok);
531 if (!schedule)
532 goto error;
533 break;
535 coincident = read_coincident(s);
536 if (!coincident)
537 goto error;
538 break;
541 permutable = !isl_val_is_zero(v);
543 break;
547 str = isl_token_get_str(ctx, tok);
549 free(str);
550 isl_token_free(tok);
551 if (!options)
552 goto error;
553 break;
557 if (!tree)
558 goto error;
559 break;
560 default:
561 isl_die(ctx, isl_error_invalid, "unexpected key",
562 goto error);
563 }
564 } while ((more = isl_stream_yaml_next(s)) == isl_bool_true);
565
566 if (more < 0)
567 goto error;
568
569 if (!schedule)
570 isl_die(ctx, isl_error_invalid, "missing schedule", goto error);
571
573 band = isl_schedule_band_set_permutable(band, permutable);
574 if (coincident)
575 band = set_coincident(band, coincident);
576 if (options)
578 if (tree)
580 else
582
583 return tree;
584error:
585 isl_val_list_free(coincident);
588 isl_multi_union_pw_aff_free(schedule);
589 return NULL;
590}
591
592#undef EL_BASE
593#define EL_BASE schedule_tree
594
596
597/* Read a subtree with root node of type "type" from "s".
598 * The node is represented by a sequence of children.
599 */
602{
603 isl_schedule_tree_list *list;
604
606
607 if (isl_stream_yaml_next(s) < 0)
608 return NULL;
609
610 list = isl_stream_yaml_read_schedule_tree_list(s);
611
613}
614
615/* Read a subtree with sequence root node from "s".
616 */
618{
620}
621
622/* Read a subtree with set root node from "s".
623 */
625{
627}
628
629/* Read a schedule (sub)tree from "s".
630 *
631 * We first determine the type of the root node based on the first
632 * mapping key and then hand over to a function tailored to reading
633 * nodes of this type.
634 */
636 struct isl_stream *s)
637{
639 struct isl_token *tok;
640 isl_schedule_tree *tree = NULL;
641 isl_bool more;
642
644 return NULL;
645 more = isl_stream_yaml_next(s);
646 if (more < 0)
647 return NULL;
648 if (!more) {
649 isl_stream_error(s, NULL, "missing key");
650 return NULL;
651 }
652
654 key = extract_key(s, tok);
656 if (key < 0)
657 return NULL;
658 switch (key) {
661 break;
663 tree = read_domain(s);
664 break;
668 break;
671 break;
673 tree = read_filter(s);
674 break;
676 tree = read_guard(s);
677 break;
681 break;
683 tree = read_mark(s);
684 break;
687 break;
689 tree = read_set(s);
690 break;
695 tree = read_band(s);
696 break;
699 "cannot identify node type", return NULL);
702 return NULL;
703 }
704
707
708 return tree;
709}
710
711/* Read an isl_schedule from "s".
712 */
714{
715 isl_ctx *ctx;
717
718 if (!s)
719 return NULL;
720
721 ctx = isl_stream_get_ctx(s);
724}
725
726/* Read an isl_schedule from "input".
727 */
729{
730 struct isl_stream *s;
732
733 s = isl_stream_new_file(ctx, input);
734 if (!s)
735 return NULL;
738
739 return schedule;
740}
741
742#undef TYPE_BASE
743#define TYPE_BASE schedule
polly Polly Forward operand tree
__isl_null isl_union_pw_multi_aff * isl_union_pw_multi_aff_free(__isl_take isl_union_pw_multi_aff *upma)
__isl_constructor __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_read_from_str(isl_ctx *ctx, const char *str)
__isl_constructor __isl_give isl_union_pw_multi_aff * isl_union_pw_multi_aff_read_from_str(isl_ctx *ctx, const char *str)
struct isl_union_pw_multi_aff isl_union_pw_multi_aff
Definition: aff_type.h:38
struct isl_multi_union_pw_aff isl_multi_union_pw_aff
Definition: aff_type.h:46
#define __isl_take
Definition: ctx.h:22
#define __isl_give
Definition: ctx.h:19
#define isl_die(ctx, errno, msg, code)
Definition: ctx.h:137
@ isl_error_unsupported
Definition: ctx.h:82
@ isl_error_invalid
Definition: ctx.h:80
#define __isl_keep
Definition: ctx.h:25
int isl_size
Definition: ctx.h:96
isl_bool
Definition: ctx.h:89
@ isl_bool_true
Definition: ctx.h:92
m
Definition: guard1-0.c:2
isl_bool __isl_keep ISL_KEY * key
Definition: hmap.h:27
__isl_null isl_id * isl_id_free(__isl_take isl_id *id)
Definition: isl_id.c:207
__isl_give isl_id * isl_id_alloc(isl_ctx *ctx, __isl_keep const char *name, void *user)
__isl_give isl_schedule * isl_schedule_from_schedule_tree(isl_ctx *ctx, __isl_take isl_schedule_tree *tree)
Definition: isl_schedule.c:38
__isl_give isl_schedule_band * isl_schedule_band_member_set_coincident(__isl_take isl_schedule_band *band, int pos, int coincident)
isl_size isl_schedule_band_n_member(__isl_keep isl_schedule_band *band)
__isl_give isl_schedule_band * isl_schedule_band_set_ast_build_options(__isl_take isl_schedule_band *band, __isl_take isl_union_set *options)
__isl_give isl_schedule_band * isl_schedule_band_from_multi_union_pw_aff(__isl_take isl_multi_union_pw_aff *mupa)
__isl_null isl_schedule_band * isl_schedule_band_free(__isl_take isl_schedule_band *band)
__isl_give isl_schedule_band * isl_schedule_band_set_permutable(__isl_take isl_schedule_band *band, int permutable)
static __isl_give isl_schedule_tree * read_guard(isl_stream *s)
static __isl_give isl_val_list * read_coincident(__isl_keep isl_stream *s)
static __isl_give isl_schedule_tree * read_set(isl_stream *s)
static __isl_give isl_schedule_tree * read_expansion(isl_stream *s)
__isl_give isl_schedule * isl_stream_read_schedule(isl_stream *s)
static __isl_give isl_schedule_tree * read_context(__isl_keep isl_stream *s)
static char * key_str[]
static __isl_give isl_schedule_tree * read_extension(isl_stream *s)
static __isl_give isl_schedule_tree * read_children(isl_stream *s, enum isl_schedule_node_type type)
static __isl_give isl_schedule_tree * read_mark(isl_stream *s)
static __isl_give isl_schedule_tree * read_band(isl_stream *s)
__isl_give isl_schedule * isl_schedule_read_from_file(isl_ctx *ctx, FILE *input)
static __isl_give isl_schedule_tree * isl_stream_read_schedule_tree(__isl_keep isl_stream *s)
static __isl_give isl_schedule_tree * read_sequence(isl_stream *s)
isl_schedule_key
@ isl_schedule_key_expansion
@ isl_schedule_key_domain
@ isl_schedule_key_sequence
@ isl_schedule_key_filter
@ isl_schedule_key_coincident
@ isl_schedule_key_extension
@ isl_schedule_key_guard
@ isl_schedule_key_options
@ isl_schedule_key_permutable
@ isl_schedule_key_set
@ isl_schedule_key_leaf
@ isl_schedule_key_context
@ isl_schedule_key_end
@ isl_schedule_key_error
@ isl_schedule_key_child
@ isl_schedule_key_contraction
@ isl_schedule_key_mark
@ isl_schedule_key_schedule
static __isl_give isl_schedule_band * set_coincident(__isl_take isl_schedule_band *band, __isl_take isl_val_list *coincident)
static __isl_give isl_schedule_tree * read_domain(__isl_keep isl_stream *s)
static __isl_give isl_schedule_tree * read_filter(__isl_keep isl_stream *s)
__isl_null isl_schedule_tree * isl_schedule_tree_free(__isl_take isl_schedule_tree *tree)
__isl_give isl_schedule_tree * isl_schedule_tree_from_filter(__isl_take isl_union_set *filter)
__isl_give isl_schedule_tree * isl_schedule_tree_from_extension(__isl_take isl_union_map *extension)
__isl_give isl_schedule_tree * isl_schedule_tree_insert_band(__isl_take isl_schedule_tree *tree, __isl_take isl_schedule_band *band)
__isl_give isl_schedule_tree * isl_schedule_tree_from_band(__isl_take isl_schedule_band *band)
__isl_give isl_schedule_tree * isl_schedule_tree_from_domain(__isl_take isl_union_set *domain)
__isl_give isl_schedule_tree * isl_schedule_tree_insert_mark(__isl_take isl_schedule_tree *tree, __isl_take isl_id *mark)
__isl_give isl_schedule_tree * isl_schedule_tree_insert_expansion(__isl_take isl_schedule_tree *tree, __isl_take isl_union_pw_multi_aff *contraction, __isl_take isl_union_map *expansion)
__isl_give isl_schedule_tree * isl_schedule_tree_insert_domain(__isl_take isl_schedule_tree *tree, __isl_take isl_union_set *domain)
__isl_give isl_schedule_tree * isl_schedule_tree_insert_guard(__isl_take isl_schedule_tree *tree, __isl_take isl_set *guard)
__isl_give isl_schedule_tree * isl_schedule_tree_from_context(__isl_take isl_set *context)
__isl_give isl_schedule_tree * isl_schedule_tree_leaf(isl_ctx *ctx)
__isl_give isl_schedule_tree * isl_schedule_tree_from_children(enum isl_schedule_node_type type, __isl_take isl_schedule_tree_list *list)
__isl_give isl_schedule_tree * isl_schedule_tree_insert_filter(__isl_take isl_schedule_tree *tree, __isl_take isl_union_set *filter)
__isl_give isl_schedule_tree * isl_schedule_tree_from_guard(__isl_take isl_set *guard)
__isl_give isl_schedule_tree * isl_schedule_tree_from_expansion(__isl_take isl_union_pw_multi_aff *contraction, __isl_take isl_union_map *expansion)
__isl_give isl_schedule_tree * isl_schedule_tree_insert_context(__isl_take isl_schedule_tree *tree, __isl_take isl_set *context)
__isl_give isl_schedule_tree * isl_schedule_tree_insert_extension(__isl_take isl_schedule_tree *tree, __isl_take isl_union_map *extension)
enum isl_fold type
Definition: isl_test.c:4017
const char * schedule
Definition: isl_test.c:10697
const char * context
Definition: isl_test.c:1784
const char * str
Definition: isl_test.c:2095
struct isl_set isl_set
Definition: map_type.h:26
isl_schedule_node_type
Definition: schedule_type.h:8
@ isl_schedule_node_set
Definition: schedule_type.h:20
@ isl_schedule_node_sequence
Definition: schedule_type.h:19
__isl_null isl_set * isl_set_free(__isl_take isl_set *set)
Definition: isl_map.c:3513
__isl_constructor __isl_give isl_set * isl_set_read_from_str(isl_ctx *ctx, const char *str)
void isl_stream_error(__isl_keep isl_stream *s, struct isl_token *tok, char *msg)
Definition: isl_stream.c:142
void isl_token_free(struct isl_token *tok)
Definition: isl_stream.c:127
__isl_give isl_val * isl_stream_read_val(__isl_keep isl_stream *s)
Definition: isl_input.c:191
isl_bool isl_stream_yaml_next(__isl_keep isl_stream *s)
Definition: isl_stream.c:966
void isl_stream_push_token(__isl_keep isl_stream *s, struct isl_token *tok)
Definition: isl_stream.c:311
isl_ctx * isl_stream_get_ctx(__isl_keep isl_stream *s)
Definition: isl_stream.c:800
isl_stat isl_stream_yaml_read_start_mapping(__isl_keep isl_stream *s)
Definition: isl_stream.c:1070
struct isl_token * isl_stream_next_token(__isl_keep isl_stream *s)
Definition: isl_stream.c:693
__isl_give isl_stream * isl_stream_new_file(isl_ctx *ctx, FILE *file)
Definition: isl_stream.c:219
isl_stat isl_stream_yaml_read_end_mapping(__isl_keep isl_stream *s)
Definition: isl_stream.c:1102
__isl_give char * isl_token_get_str(isl_ctx *ctx, struct isl_token *tok)
Definition: isl_stream.c:115
void isl_stream_free(__isl_take isl_stream *s)
Definition: isl_stream.c:805
struct isl_ctx * ctx
static Signature domain
__isl_null isl_union_map * isl_union_map_free(__isl_take isl_union_map *umap)
__isl_constructor __isl_give isl_union_map * isl_union_map_read_from_str(isl_ctx *ctx, const char *str)
struct isl_union_set isl_union_set
__isl_constructor __isl_give isl_union_set * isl_union_set_read_from_str(isl_ctx *ctx, const char *str)
__isl_null isl_union_set * isl_union_set_free(__isl_take isl_union_set *uset)
__isl_null isl_val * isl_val_free(__isl_take isl_val *v)
Definition: isl_val.c:263
__isl_export isl_bool isl_val_is_zero(__isl_keep isl_val *v)
Definition: isl_val.c:1191
n
Definition: youcefn.c:8