update isl for support for recent clangs
[ppn.git] / sloog.cc
blob12b3fc967aaeaf8a77416ef3041c19e35d732769
1 #include "suif_inc.h"
2 #include <stdlib.h>
3 #include <assert.h>
4 #include "domain.h"
5 #include "build.h"
7 #include <isl/aff.h>
8 #include <isl/ast_build.h>
9 #include <isa/yaml.h>
10 #include <isa/pdg.h>
12 using pdg::PDG;
14 static __isl_give isl_ast_node *construct_ast(pdg::PDG *pdg);
16 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(*a))
18 static isl_ast_node *tree;
20 static int oldstyle;
22 static void do_proc(tree_proc * tp)
24 static context_info *ctx = new context_info;
25 proc_sym * psym = tp->proc();
26 fill_in_access(tp);
27 construct_domains(tp, 0, oldstyle, ctx);
28 build(tp, tree);
29 isl_ast_node_free(tree);
32 int
33 main(int argc, char * argv[])
35 isl_ctx *ctx = isl_ctx_alloc();
36 char *domains = NULL;
37 FILE *input;
38 PDG *pdg;
40 cmd_line_option my_options[] = {
41 { CLO_STRING, "-domains", "", &domains },
42 { CLO_NOARG, "-oldstyle", "", &oldstyle },
45 start_suif(argc, argv);
46 init_dead_code();
47 init_unused();
48 parse_cmd_line(argc, argv, my_options, ARRAY_SIZE(my_options));
49 init(argc, argv);
51 input = fopen(domains, "r");
52 assert(input);
53 pdg = PDG::Load(input, ctx);
54 fclose(input);
55 if (!pdg) {
56 fprintf(stderr, "Empty input\n");
57 return 1;
60 tree = construct_ast(pdg);
62 suif_proc_iter(argc, argv, do_proc, TRUE);
64 if (domains)
65 delete [] domains;
67 pdg->free();
68 delete pdg;
70 isl_ctx_free(ctx);
72 return 0;
75 static void free_ast_expr_list(void *user)
77 isl_ast_expr_list_free((isl_ast_expr_list *) user);
80 static __isl_give isl_ast_node *construct_ast(pdg::PDG *pdg)
82 isl_ctx *ctx = pdg->get_isl_ctx();
83 isl_union_map *sched;
84 isl_ast_build *build;
85 isl_ast_node *tree;
87 isl_options_set_ast_build_atomic_upper_bound(ctx, 1);
88 isl_options_set_ast_build_allow_else(ctx, 0);
90 build = isl_ast_build_from_context(pdg->get_context_isl_set());
91 sched = isl_union_map_empty(isl_space_params_alloc(ctx, 0));
93 for (int i = 0; i < pdg->nodes.size(); ++i) {
94 isl_id *id;
95 isl_set *source;
96 isl_map *map;
97 char name[20];
99 if (!pdg->nodes[i]->schedule) {
100 fprintf(stderr, "Missing schedule\n");
101 exit(-1);
104 source = pdg->nodes[i]->source->get_isl_set(ctx);
106 map = pdg->nodes[i]->schedule->get_isl_map(ctx);
107 map = isl_map_intersect_domain(map, source);
108 snprintf(name, sizeof(name), "S%d", i);
109 id = isl_id_alloc(ctx, name, pdg->nodes[i]);
110 map = isl_map_set_tuple_id(map, isl_dim_in, id);
112 sched = isl_union_map_add_map(sched, map);
115 tree = isl_ast_build_ast_from_schedule(build, sched);
116 isl_ast_build_free(build);
118 return tree;