update isl for isl_space_domain_factor_domain
[ppn.git] / dump_model.cc
blob204be07ba6d30e563fb770140b3f03adfbd6a1e7
1 #include <isl/map.h>
2 #include <isl/set.h>
3 #include <isl/union_map.h>
4 #include <isl/union_set.h>
6 #include <isa/yaml.h>
7 #include <isa/pdg.h>
9 using namespace pdg;
11 __isl_give isl_map *prefix2schedule(isl_ctx *ctx, pdg::node *node,
12 int sched_dim)
14 isl_space *dim;
15 isl_map *schedule;
17 dim = node->source->get_dim();
18 dim = isl_space_map_from_set(dim);
19 schedule = isl_map_identity(dim);
21 for (int i = 0; i < node->prefix.size(); ++i) {
22 int v = node->prefix[i];
23 if (v == -1)
24 continue;
25 schedule = isl_map_insert_dims(schedule, isl_dim_out, i, 1);
26 schedule = isl_map_fix_si(schedule, isl_dim_out, i, v);
28 schedule = isl_map_add_dims(schedule, isl_dim_out,
29 sched_dim - node->prefix.size());
30 for (int i = node->prefix.size(); i < sched_dim; ++i)
31 schedule = isl_map_fix_si(schedule, isl_dim_out, i, 0);
33 return schedule;
36 int main(int argc, char * argv[])
38 PDG *pdg;
39 isl_ctx *ctx = isl_ctx_alloc();
40 pdg = PDG::Load(stdin, ctx);
41 isl_space *dim;
42 isl_union_set *domain;
43 isl_union_map *read;
44 isl_union_map *write;
45 isl_union_map *schedule;
46 isl_printer *p;
47 char name[40];
48 int sched_dim = 0;
50 dim = isl_space_set_alloc(ctx, pdg->params.size(), 0);
51 isl_dim_set_parameter_names(dim, pdg->params);
52 domain = isl_union_set_empty(dim);
54 dim = isl_space_alloc(ctx, pdg->params.size(), 0, 0);
55 isl_dim_set_parameter_names(dim, pdg->params);
56 schedule = isl_union_map_empty(isl_space_copy(dim));
57 write = isl_union_map_empty(isl_space_copy(dim));
58 read = isl_union_map_empty(dim);
60 for (int i = 0; i < pdg->nodes.size(); ++i) {
61 pdg::node *node = pdg->nodes[i];
62 if (node->prefix.size() > sched_dim)
63 sched_dim = node->prefix.size();
66 for (int i = 0; i < pdg->nodes.size(); ++i) {
67 pdg::node *node = pdg->nodes[i];
68 pdg::statement *s = node->statement;
69 isl_set *domain_i;
70 isl_map *access_i, *schedule_i;
72 snprintf(name, sizeof(name), "S%d", i);
74 domain_i = node->source->get_isl_set(ctx);
75 domain_i = isl_set_set_tuple_name(domain_i, name);
76 domain = isl_union_set_add_set(domain, domain_i);
78 for (int j = 0; j < s->accesses.size(); ++j) {
79 pdg::access *access = s->accesses[j];
81 if (!access->array)
82 continue;
84 access_i = access->map->get_isl_map(ctx);
85 access_i = isl_map_set_tuple_name(access_i,
86 isl_dim_in, name);
87 access_i = isl_map_set_tuple_name(access_i,
88 isl_dim_out,
89 access->array->name->s.c_str());
90 if (access->type == pdg::access::read)
91 read = isl_union_map_add_map(read, access_i);
92 else
93 write = isl_union_map_add_map(write, access_i);
96 if (node->schedule)
97 schedule_i = node->schedule->get_isl_map(ctx);
98 else
99 schedule_i = prefix2schedule(ctx, node, sched_dim);
100 schedule_i = isl_map_set_tuple_name(schedule_i,
101 isl_dim_in, name);
102 schedule = isl_union_map_add_map(schedule, schedule_i);
105 p = isl_printer_to_file(ctx, stdout);
107 p = isl_printer_print_str(p, "D := ");
108 p = isl_printer_print_union_set(p, domain);
109 p = isl_printer_print_str(p, ";");
110 p = isl_printer_end_line(p);
112 p = isl_printer_print_str(p, "R := ");
113 p = isl_printer_print_union_map(p, read);
114 p = isl_printer_print_str(p, " * D;");
115 p = isl_printer_end_line(p);
117 p = isl_printer_print_str(p, "W := ");
118 p = isl_printer_print_union_map(p, write);
119 p = isl_printer_print_str(p, " * D;");
120 p = isl_printer_end_line(p);
122 p = isl_printer_print_str(p, "S := ");
123 p = isl_printer_print_union_map(p, schedule);
124 p = isl_printer_print_str(p, ";");
125 p = isl_printer_end_line(p);
127 isl_printer_free(p);
129 isl_union_set_free(domain);
130 isl_union_map_free(read);
131 isl_union_map_free(write);
132 isl_union_map_free(schedule);
134 pdg->free();
135 delete pdg;
136 isl_ctx_free(ctx);
138 return 0;