2 * Copyright 2011 Leiden University. All rights reserved.
7 /* Return a C representation of the variable.
8 * The pointer is only valid during the lifetime of the object
9 * or until the next time get_expr() is called.
11 * The pointer is saved in this->expr so that it can be free
12 * when the object is destroyed.
14 __isl_keep
const char *adg_var::get_expr()
23 p
= isl_printer_to_str(isl_pw_multi_aff_get_ctx(access
));
24 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
25 p
= isl_printer_print_pw_multi_aff(p
, access
);
26 expr
= isl_printer_get_str(p
);
32 /* Return an adg_expr that corresponds to the affine expression "aff".
33 * If such an adg_expr already exists in controls, then we return that.
34 * Otherwise, we construct a new one with a unique name.
36 adg_expr
*adg::to_control(__isl_take isl_aff
*aff
)
42 pa
= isl_pw_aff_from_aff(aff
);
44 for (i
= 0; i
< controls
.size(); ++i
)
45 if (isl_pw_aff_plain_is_equal(pa
, controls
[i
]->expr
))
48 if (i
< controls
.size()) {
55 snprintf(buf
, sizeof(buf
), "e%zd", controls
.size());
56 expr
->name
= isl_id_alloc(isl_pw_aff_get_ctx(pa
), buf
, NULL
);
58 controls
.push_back(expr
);
61 return new adg_expr(*expr
);
64 /* Find and return a pointer to the node that has the give name.
66 adg_node
*adg::node_by_id(__isl_take isl_id
*id
)
70 for (i
= 0; i
< nodes
.size(); ++i
)
71 if (nodes
[i
]->name
== id
)
74 return i
< nodes
.size() ? nodes
[i
] : NULL
;
77 int adg_var::is_equal(adg_var
*var2
)
79 if (!isl_pw_multi_aff_plain_is_equal(access
, var2
->access
))
81 if (type
!= var2
->type
)
83 if (!expr
!= !var2
->expr
)
85 if (expr
&& strcmp(expr
, var2
->expr
))
91 int adg_expr::is_equal(adg_expr
*expr2
)
93 if (name
!= expr2
->name
)
95 if (!isl_pw_aff_plain_is_equal(expr
, expr2
->expr
))
101 int adg_domain::is_equal(adg_domain
*domain2
)
103 if (!isl_set_is_equal(bounds
, domain2
->bounds
))
106 if (filters
.size() != domain2
->filters
.size())
108 for (int i
= 0; i
< filters
.size(); ++i
)
109 if (!filters
[i
]->is_equal(domain2
->filters
[i
]))
115 int adg_gate::is_equal(adg_gate
*gate2
)
117 if (name
!= gate2
->name
)
119 if (node_name
!= gate2
->node_name
)
121 if (!in
->is_equal(gate2
->in
))
123 if (!out
->is_equal(gate2
->out
))
125 if (!domain
->is_equal(gate2
->domain
))
131 int adg_port::is_equal(adg_port
*port2
)
133 if (name
!= port2
->name
)
135 if (node_name
!= port2
->node_name
)
137 if (edge_name
!= port2
->edge_name
)
140 if (vars
.size() != port2
->vars
.size())
142 for (int i
= 0; i
< vars
.size(); ++i
)
143 if (!vars
[i
]->is_equal(port2
->vars
[i
]))
146 if (!domain
->is_equal(port2
->domain
))
152 int adg_function::is_equal(adg_function
*function2
)
154 if (name
!= function2
->name
)
156 if (!domain
->is_equal(function2
->domain
))
159 if (in
.size() != function2
->in
.size())
161 for (int i
= 0; i
< in
.size(); ++i
)
162 if (!in
[i
]->is_equal(function2
->in
[i
]))
165 if (out
.size() != function2
->out
.size())
167 for (int i
= 0; i
< out
.size(); ++i
)
168 if (!out
[i
]->is_equal(function2
->out
[i
]))
171 if (ctrl
.size() != function2
->ctrl
.size())
173 for (int i
= 0; i
< ctrl
.size(); ++i
)
174 if (!ctrl
[i
]->is_equal(function2
->ctrl
[i
]))
180 int adg_node::is_equal(adg_node
*node2
)
182 if (name
!= node2
->name
)
185 if (input_ports
.size() != node2
->input_ports
.size())
187 for (int i
= 0; i
< input_ports
.size(); ++i
)
188 if (!input_ports
[i
]->is_equal(node2
->input_ports
[i
]))
191 if (gates
.size() != node2
->gates
.size())
193 for (int i
= 0; i
< gates
.size(); ++i
)
194 if (!gates
[i
]->is_equal(node2
->gates
[i
]))
197 if (output_ports
.size() != node2
->output_ports
.size())
199 for (int i
= 0; i
< output_ports
.size(); ++i
)
200 if (!output_ports
[i
]->is_equal(node2
->output_ports
[i
]))
203 if (expressions
.size() != node2
->expressions
.size())
205 for (int i
= 0; i
< expressions
.size(); ++i
)
206 if (!expressions
[i
]->is_equal(node2
->expressions
[i
]))
209 if (!function
->is_equal(node2
->function
))
211 if (!domain
->is_equal(node2
->domain
))
213 if (!isl_map_is_equal(schedule
, node2
->schedule
))
219 int adg_arg::is_equal(adg_arg
*arg2
)
221 if (type
!= arg2
->type
)
223 if (!var
!= !arg2
->var
)
225 if (var
&& !var
->is_equal(arg2
->var
))
231 int adg_edge::is_equal(adg_edge
*edge2
)
233 if (name
!= edge2
->name
)
235 if (from_node_name
!= edge2
->from_node_name
)
237 if (from_port_name
!= edge2
->from_port_name
)
239 if (to_node_name
!= edge2
->to_node_name
)
241 if (to_port_name
!= edge2
->to_port_name
)
243 if (type
!= edge2
->type
)
245 if (!isl_multi_aff_plain_is_equal(map
, edge2
->map
))
247 if (isl_int_ne(value_size
, edge2
->value_size
))
253 int adg_param::is_equal(adg_param
*param2
)
255 if (name
!= param2
->name
)
257 if (!isl_aff_plain_is_equal(lb
, param2
->lb
))
259 if (!isl_aff_plain_is_equal(ub
, param2
->ub
))
261 if (!isl_aff_plain_is_equal(val
, param2
->val
))
267 int adg::is_equal(adg
*adg2
)
269 if (name
!= adg2
->name
)
271 if (!isl_set_is_equal(context
, adg2
->context
))
273 if (!isl_map_is_equal(iterator_map
, adg2
->iterator_map
))
276 if (params
.size() != adg2
->params
.size())
278 for (int i
= 0; i
< params
.size(); ++i
)
279 if (!params
[i
]->is_equal(adg2
->params
[i
]))
282 if (nodes
.size() != adg2
->nodes
.size())
284 for (int i
= 0; i
< nodes
.size(); ++i
)
285 if (!nodes
[i
]->is_equal(adg2
->nodes
[i
]))
288 if (edges
.size() != adg2
->edges
.size())
290 for (int i
= 0; i
< edges
.size(); ++i
)
291 if (!edges
[i
]->is_equal(adg2
->edges
[i
]))
294 if (all_iterators
.size() != adg2
->all_iterators
.size())
296 for (int i
= 0; i
< all_iterators
.size(); ++i
)
297 if (all_iterators
[i
] != adg2
->all_iterators
[i
])
300 if (iterators
.size() != adg2
->iterators
.size())
302 for (int i
= 0; i
< iterators
.size(); ++i
)
303 if (iterators
[i
] != adg2
->iterators
[i
])