3 #include <isl/union_map.h>
4 #include <isl/union_set.h>
11 __isl_give isl_map
*prefix2schedule(isl_ctx
*ctx
, pdg::node
*node
,
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
];
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);
36 int main(int argc
, char * argv
[])
39 isl_ctx
*ctx
= isl_ctx_alloc();
40 pdg
= PDG::Load(stdin
, ctx
);
42 isl_union_set
*domain
;
45 isl_union_map
*schedule
;
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
;
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
];
84 access_i
= access
->map
->get_isl_map(ctx
);
85 access_i
= isl_map_set_tuple_name(access_i
,
87 access_i
= isl_map_set_tuple_name(access_i
,
89 access
->array
->name
->s
.c_str());
90 if (access
->type
== pdg::access::read
)
91 read
= isl_union_map_add_map(read
, access_i
);
93 write
= isl_union_map_add_map(write
, access_i
);
97 schedule_i
= node
->schedule
->get_isl_map(ctx
);
99 schedule_i
= prefix2schedule(ctx
, node
, sched_dim
);
100 schedule_i
= isl_map_set_tuple_name(schedule_i
,
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
);
129 isl_union_set_free(domain
);
130 isl_union_map_free(read
);
131 isl_union_map_free(write
);
132 isl_union_map_free(schedule
);