link against isl libraries first
[pet.git] / scop_plus.h
blob82b76814b3942e5f32bb78cb9ca809da8aaf92a4
1 #ifndef PET_SCOP_PLUS_H
2 #define PET_SCOP_PLUS_H
4 #include <string.h>
5 #include <set>
7 #include <isl/id.h>
9 #include "scop.h"
11 /* Compare two sequences of identifiers based on their names.
13 struct array_desc_less {
14 bool operator()(isl_id_list *x, isl_id_list *y) const {
15 int x_n = isl_id_list_n_id(x);
16 int y_n = isl_id_list_n_id(y);
18 for (int i = 0; i < x_n && i < y_n; ++i) {
19 isl_id *x_i = isl_id_list_get_id(x, i);
20 isl_id *y_i = isl_id_list_get_id(y, i);
21 const char *x_name = isl_id_get_name(x_i);
22 const char *y_name = isl_id_get_name(y_i);
23 int cmp = strcmp(x_name, y_name);
24 isl_id_free(x_i);
25 isl_id_free(y_i);
26 if (cmp)
27 return cmp < 0;
30 return x_n < y_n;
34 /* array_desc_set is a wrapper around a sorted set of identifier sequences,
35 * with each identifier representing a (possibly renamed) ValueDecl.
36 * The actual order is not important, only that it is consistent
37 * across platforms.
38 * The wrapper takes care of the memory management of the isl_id_list objects.
39 * In particular, the set keeps hold of its own reference to these objects.
41 struct array_desc_set : public std::set<isl_id_list *, array_desc_less>
43 void insert(__isl_take isl_id_list *list) {
44 if (find(list) == end())
45 set::insert(list);
46 else
47 isl_id_list_free(list);
49 void erase(__isl_keep isl_id_list *list) {
50 iterator it;
52 it = find(list);
53 if (it == end())
54 return;
56 isl_id_list_free(*it);
57 set::erase(it);
59 ~array_desc_set() {
60 iterator it;
62 for (it = begin(); it != end(); ++it)
63 isl_id_list_free(*it);
67 void pet_scop_collect_arrays(struct pet_scop *scop, array_desc_set &arrays);
69 #endif