Polly 20.0.0git
codegen.c
Go to the documentation of this file.
1/*
2 * Copyright 2012,2014 Ecole Normale Superieure
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
8 */
9
10/* This program prints an AST that scans the domain elements of
11 * the domain of a given schedule in the order specified by
12 * the schedule tree or by their image(s) in the schedule map.
13 *
14 * The input consists of either a schedule tree or
15 * a sequence of three sets/relations.
16 * - a schedule map
17 * - a context
18 * - a relation describing AST generation options
19 */
20
21#include <assert.h>
22#include <stdlib.h>
23#include <isl/ast.h>
24#include <isl/ast_build.h>
25#include <isl/options.h>
26#include <isl/space.h>
27#include <isl/set.h>
28#include <isl/union_set.h>
29#include <isl/union_map.h>
30#include <isl/stream.h>
31#include <isl/schedule_node.h>
32
33struct options {
35 unsigned atomic;
36 unsigned separate;
37};
38
39ISL_ARGS_START(struct options, options_args)
40ISL_ARG_CHILD(struct options, isl, "isl", &isl_options_args, "isl options")
41ISL_ARG_BOOL(struct options, atomic, 0, "atomic", 0,
42 "globally set the atomic option")
43ISL_ARG_BOOL(struct options, separate, 0, "separate", 0,
44 "globally set the separate option")
46
47ISL_ARG_DEF(cg_options, struct options, options_args)
48ISL_ARG_CTX_DEF(cg_options, struct options, options_args)
49
50/* Return a universal, 1-dimensional set with the given name.
51 */
52static __isl_give isl_union_set *universe(isl_ctx *ctx, const char *name)
53{
54 isl_space *space;
55
56 space = isl_space_set_alloc(ctx, 0, 1);
59}
60
61/* Set the "name" option for the entire schedule domain.
62 */
65{
66 isl_ctx *ctx;
67 isl_union_set *domain, *target;
68 isl_union_map *option;
69
70 ctx = isl_union_map_get_ctx(opt);
71
74 target = universe(ctx, name);
76 opt = isl_union_map_union(opt, option);
77
78 return opt;
79}
80
81/* Update the build options based on the user-specified options.
82 *
83 * If the --separate or --atomic options were specified, then
84 * we clear any separate or atomic options that may already exist in "opt".
85 */
89{
90 if (options->separate || options->atomic) {
91 isl_ctx *ctx;
92 isl_union_set *target;
93
95
96 target = universe(ctx, "separate");
97 opt = isl_union_map_subtract_range(opt, target);
98 target = universe(ctx, "atomic");
99 opt = isl_union_map_subtract_range(opt, target);
100 }
101
102 if (options->separate)
103 opt = set_universe(opt, schedule, "separate");
104 if (options->atomic)
105 opt = set_universe(opt, schedule, "atomic");
106
107 build = isl_ast_build_set_options(build, opt);
108
109 return build;
110}
111
112/* Construct an AST in case the schedule is specified by a union map.
113 *
114 * We read the context and the options from "s" and construct the AST.
115 */
118{
120 isl_union_map *options_map;
121 isl_ast_build *build;
123 struct options *options;
124
125 options = isl_ctx_peek_cg_options(isl_stream_get_ctx(s));
126
128 options_map = isl_stream_read_union_map(s);
129
131 build = set_options(build, options_map, options, schedule);
133 isl_ast_build_free(build);
134
135 return tree;
136}
137
138/* If "node" is a band node, then replace the AST build options
139 * by "options".
140 */
142 __isl_take isl_schedule_node *node, void *user)
143{
145 int i;
146 isl_size n;
147
149 return node;
150
152 if (n < 0)
153 return isl_schedule_node_free(node);
154 for (i = 0; i < n; ++i)
156 i, *type);
157 return node;
158}
159
160/* Replace the AST build options on all band nodes if requested
161 * by the user.
162 */
165{
167
168 if (!options->separate && !options->atomic)
169 return schedule;
170
174
175 return schedule;
176}
177
178/* Construct an AST in case the schedule is specified by a schedule tree.
179 */
182{
183 isl_ast_build *build;
185 struct options *options;
186
187 options = isl_ctx_peek_cg_options(isl_schedule_get_ctx(schedule));
188
192 isl_ast_build_free(build);
193
194 return tree;
195}
196
197/* Read an object from stdin.
198 * If it is a (union) map, then assume an input specified by
199 * schedule map, context and options and construct an AST from
200 * those elements
201 * If it is a schedule object, then construct the AST from the schedule.
202 */
203int main(int argc, char **argv)
204{
205 isl_ctx *ctx;
206 isl_stream *s;
207 isl_ast_node *tree = NULL;
208 struct options *options;
209 isl_printer *p;
210 struct isl_obj obj;
211 int r = EXIT_SUCCESS;
212
213 options = cg_options_new_with_defaults();
215 ctx = isl_ctx_alloc_with_options(&options_args, options);
218 argc = cg_options_parse(options, argc, argv, ISL_ARG_ALL);
219
220 s = isl_stream_new_file(ctx, stdin);
222 if (obj.v == NULL) {
223 r = EXIT_FAILURE;
224 } else if (obj.type == isl_obj_map) {
225 isl_union_map *umap;
226
227 umap = isl_union_map_from_map(obj.v);
229 } else if (obj.type == isl_obj_union_map) {
231 } else if (obj.type == isl_obj_schedule) {
233 } else {
234 obj.type->free(obj.v);
235 isl_die(ctx, isl_error_invalid, "unknown input",
236 r = EXIT_FAILURE);
237 }
239
240 p = isl_printer_to_file(ctx, stdout);
244
246
247 isl_ctx_free(ctx);
248 return r;
249}
polly Polly Forward operand tree
#define ISL_ARG_DEF(prefix, st, args)
Definition: arg.h:302
#define ISL_ARG_BOOL(st, f, s, l, d, h)
Definition: arg.h:182
#define ISL_ARG_CHILD(st, f, l, c, h)
Definition: arg.h:264
#define ISL_ARG_ALL
Definition: arg.h:288
#define ISL_ARGS_START(s, name)
Definition: arg.h:113
#define ISL_ARGS_END
Definition: arg.h:117
__isl_give isl_printer * isl_printer_print_ast_node(__isl_take isl_printer *p, __isl_keep isl_ast_node *node)
Definition: isl_ast.c:3239
isl_stat isl_options_set_ast_print_outermost_block(isl_ctx *ctx, int val)
__isl_null isl_ast_node * isl_ast_node_free(__isl_take isl_ast_node *node)
Definition: isl_ast.c:1180
isl_stat isl_options_set_ast_build_detect_min_max(isl_ctx *ctx, int val)
__isl_export __isl_give isl_ast_build * isl_ast_build_from_context(__isl_take isl_set *set)
__isl_export __isl_give isl_ast_node * isl_ast_build_node_from_schedule_map(__isl_keep isl_ast_build *build, __isl_take isl_union_map *schedule)
__isl_give isl_ast_build * isl_ast_build_set_options(__isl_take isl_ast_build *build, __isl_take isl_union_map *options)
__isl_null isl_ast_build * isl_ast_build_free(__isl_take isl_ast_build *build)
__isl_overload __isl_give isl_ast_node * isl_ast_build_node_from_schedule(__isl_keep isl_ast_build *build, __isl_take isl_schedule *schedule)
__isl_constructor __isl_give isl_ast_build * isl_ast_build_alloc(isl_ctx *ctx)
isl_ast_loop_type
Definition: ast_type.h:91
@ isl_ast_loop_atomic
Definition: ast_type.h:94
@ isl_ast_loop_separate
Definition: ast_type.h:96
static __isl_give isl_schedule_node * node_set_options(__isl_take isl_schedule_node *node, void *user)
Definition: codegen.c:141
static __isl_give isl_schedule * schedule_set_options(__isl_take isl_schedule *schedule, struct options *options)
Definition: codegen.c:163
static __isl_give isl_ast_build * set_options(__isl_take isl_ast_build *build, __isl_take isl_union_map *opt, struct options *options, __isl_keep isl_union_map *schedule)
Definition: codegen.c:86
static __isl_give isl_ast_node * construct_ast_from_schedule(__isl_take isl_schedule *schedule)
Definition: codegen.c:180
static __isl_give isl_union_map * set_universe(__isl_take isl_union_map *opt, __isl_keep isl_union_map *schedule, const char *name)
Definition: codegen.c:63
static __isl_give isl_ast_node * construct_ast_from_union_map(__isl_take isl_union_map *schedule, __isl_keep isl_stream *s)
Definition: codegen.c:116
isl_ctx * isl_ctx_alloc_with_options(struct isl_args *args, __isl_take void *opt)
#define __isl_take
Definition: ctx.h:22
#define ISL_ARG_CTX_DEF(prefix, st, args)
Definition: ctx.h:181
#define __isl_give
Definition: ctx.h:19
#define isl_die(ctx, errno, msg, code)
Definition: ctx.h:137
@ isl_error_invalid
Definition: ctx.h:80
#define __isl_keep
Definition: ctx.h:25
int isl_size
Definition: ctx.h:96
void isl_ctx_free(isl_ctx *ctx)
Definition: isl_ctx.c:288
isl_stat isl_stat(*) void user)
Definition: hmap.h:39
enum isl_schedule_node_type isl_schedule_node_get_type(__isl_keep isl_schedule_node *node)
enum isl_fold type
Definition: isl_test.c:4017
const char * schedule
Definition: isl_test.c:10697
const char * set
Definition: isl_test.c:1356
const char * p
Definition: isl_test.c:8643
const char * name
Definition: isl_test.c:10938
const char * context
Definition: isl_test.c:1784
const char * obj
Definition: isl_test.c:3316
#define assert(exp)
static __isl_give isl_map * universe(__isl_take isl_map *map)
struct isl_set isl_set
Definition: map_type.h:26
These are automatically generated checked C++ bindings for isl.
Definition: ISLTools.h:45
#define isl_obj_union_map
Definition: obj.h:35
#define isl_obj_map
Definition: obj.h:33
#define isl_obj_schedule
Definition: obj.h:47
__isl_null isl_printer * isl_printer_free(__isl_take isl_printer *printer)
Definition: isl_printer.c:269
#define ISL_FORMAT_C
Definition: printer.h:31
__isl_give isl_printer * isl_printer_to_file(isl_ctx *ctx, FILE *file)
Definition: isl_printer.c:217
__isl_give isl_printer * isl_printer_set_output_format(__isl_take isl_printer *p, int output_format)
Definition: isl_printer.c:373
__isl_give isl_schedule * isl_schedule_map_schedule_node_bottom_up(__isl_take isl_schedule *schedule, __isl_give isl_schedule_node *(*fn)(__isl_take isl_schedule_node *node, void *user), void *user)
Definition: isl_schedule.c:272
isl_ctx * isl_schedule_get_ctx(__isl_keep isl_schedule *sched)
Definition: isl_schedule.c:160
__isl_export isl_size isl_schedule_node_band_n_member(__isl_keep isl_schedule_node *node)
__isl_export __isl_give isl_schedule_node * isl_schedule_node_band_member_set_ast_loop_type(__isl_take isl_schedule_node *node, int pos, enum isl_ast_loop_type type)
__isl_null isl_schedule_node * isl_schedule_node_free(__isl_take isl_schedule_node *node)
@ isl_schedule_node_band
Definition: schedule_type.h:10
__isl_export __isl_give isl_set * isl_set_universe(__isl_take isl_space *space)
Definition: isl_map.c:6366
__isl_give isl_space * isl_space_set_tuple_name(__isl_take isl_space *space, enum isl_dim_type type, const char *s)
Definition: isl_space.c:785
__isl_give isl_space * isl_space_set_alloc(isl_ctx *ctx, unsigned nparam, unsigned dim)
Definition: isl_space.c:156
@ isl_dim_set
Definition: space_type.h:18
struct isl_obj isl_stream_read_obj(__isl_keep isl_stream *s)
Definition: isl_input.c:3135
isl_ctx * isl_stream_get_ctx(__isl_keep isl_stream *s)
Definition: isl_stream.c:800
__isl_give isl_stream * isl_stream_new_file(isl_ctx *ctx, FILE *file)
Definition: isl_stream.c:219
__isl_give isl_set * isl_stream_read_set(__isl_keep isl_stream *s)
Definition: isl_input.c:3158
void isl_stream_free(__isl_take isl_stream *s)
Definition: isl_stream.c:805
__isl_give isl_union_map * isl_stream_read_union_map(__isl_keep isl_stream *s)
Definition: isl_input.c:3177
Definition: obj.h:48
struct isl_options * isl
Definition: codegen.c:34
unsigned separate
Definition: codegen.c:36
unsigned atomic
Definition: codegen.c:35
static Signature domain
__isl_give isl_union_map * isl_union_map_copy(__isl_keep isl_union_map *umap)
__isl_export __isl_give isl_union_set * isl_union_map_range(__isl_take isl_union_map *umap)
__isl_constructor __isl_give isl_union_map * isl_union_map_from_map(__isl_take isl_map *map)
__isl_export __isl_give isl_union_map * isl_union_map_subtract_range(__isl_take isl_union_map *umap, __isl_take isl_union_set *dom)
__isl_export __isl_give isl_union_map * isl_union_map_union(__isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2)
isl_ctx * isl_union_map_get_ctx(__isl_keep isl_union_map *umap)
__isl_export __isl_give isl_union_map * isl_union_map_from_domain_and_range(__isl_take isl_union_set *domain, __isl_take isl_union_set *range)
struct isl_union_set isl_union_set
__isl_export __isl_give isl_union_set * isl_union_set_universe(__isl_take isl_union_set *uset)
__isl_constructor __isl_give isl_union_set * isl_union_set_from_set(__isl_take isl_set *set)
n
Definition: youcefn.c:8