README: rename
[ppn.git] / msa.cc
blob03fc746453ad558aa99a215524d732d6eb29f482
1 #include "msa.h"
3 int MSA::add_firing(int s, int t, __isl_take isl_map *map)
5 int f;
6 char name[50];
8 snprintf(name, sizeof(name), "s%d", s);
9 map = isl_map_set_tuple_name(map, isl_dim_in, name);
10 snprintf(name, sizeof(name), "s%d", t);
11 map = isl_map_set_tuple_name(map, isl_dim_out, name);
12 for (f = 0; f < firing.size(); ++f) {
13 if (!isl_map_plain_is_equal(firing[f], map))
14 continue;
15 isl_map_free(map);
16 return f;
18 firing.push_back(map);
20 return f;
23 /* Return an index to the state of the MSA that corresponds to the
24 * given pair of computations, adding this state if necessary.
25 * If the state needs to be added, then also add all connections
26 * for the state to other states.
28 int MSA::add(computation *c1, computation *c2)
30 int s;
32 for (s = 0; s < state.size(); ++s)
33 if (state[s].first == c1 && state[s].second == c2)
34 return s;
35 state.push_back(computation_pair(c1, c2));
37 if (!c1->is_copy() && !c2->is_copy() &&
38 (strcmp(c1->operation, c2->operation) || c1->arity != c2->arity)) {
39 fail_state.push_back(s);
40 } else if (c1->is_copy()) {
41 for (int i = 0; i < c1->edges.size(); ++i) {
42 edge *e1 = c1->edges[i];
43 isl_space *dim;
44 isl_map *id, *map;
45 int t, f;
46 assert(e1->type != edge::expansion);
47 t = add(e1->source, c2);
48 dim = isl_space_map_from_set(isl_set_get_space(c2->domain));
49 id = isl_map_identity(dim);
50 map = isl_map_product(isl_map_copy(e1->relation), id);
51 f = add_firing(s, t, map);
52 transition.push_back(transition_t(state_pair(s, t), f));
54 } else if (c2->is_copy()) {
55 for (int i = 0; i < c2->edges.size(); ++i) {
56 edge *e2 = c2->edges[i];
57 isl_space *dim;
58 isl_map *id, *map;
59 int t, f;
60 assert(e2->type != edge::expansion);
61 t = add(c1, e2->source);
62 dim = isl_set_get_space(c1->domain);
63 id = isl_map_identity(isl_space_map_from_set(dim));
64 map = isl_map_product(id, isl_map_copy(e2->relation));
65 f = add_firing(s, t, map);
66 transition.push_back(transition_t(state_pair(s, t), f));
68 } else if (c1->is_input() && c2->is_input()) {
69 if (strcmp(c1->operation, c2->operation))
70 fail_state.push_back(s);
71 else
72 input_state.push_back(s);
73 } else if (c1->is_input() || c2->is_input()) {
74 fail_state.push_back(s);
75 } else if (c1->arity == 0) {
76 cst_state.push_back(s);
77 } else {
78 for (int i = 0; i < c1->edges.size(); ++i) {
79 edge *e1 = c1->edges[i];
80 assert(e1->type != edge::expansion);
81 for (int j = 0; j < c2->edges.size(); ++j) {
82 edge *e2 = c2->edges[j];
83 assert(e2->type != edge::expansion);
84 int t, f;
85 isl_map *map;
86 if (e1->pos != e2->pos)
87 continue;
88 t = add(e1->source, e2->source);
89 map = isl_map_product(
90 isl_map_copy(e1->relation),
91 isl_map_copy(e2->relation));
92 f = add_firing(s, t, map);
93 transition.push_back(
94 transition_t(state_pair(s, t), f));
99 return s;