-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathscop_plus.h
69 lines (57 loc) · 1.61 KB
/
scop_plus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef PET_SCOP_PLUS_H
#define PET_SCOP_PLUS_H
#include <string.h>
#include <set>
#include <isl/id.h>
#include "scop.h"
/* Compare two sequences of identifiers based on their names.
*/
struct array_desc_less {
bool operator()(isl_id_list *x, isl_id_list *y) {
int x_n = isl_id_list_n_id(x);
int y_n = isl_id_list_n_id(y);
for (int i = 0; i < x_n && i < y_n; ++i) {
isl_id *x_i = isl_id_list_get_id(x, i);
isl_id *y_i = isl_id_list_get_id(y, i);
const char *x_name = isl_id_get_name(x_i);
const char *y_name = isl_id_get_name(y_i);
int cmp = strcmp(x_name, y_name);
isl_id_free(x_i);
isl_id_free(y_i);
if (cmp)
return cmp < 0;
}
return x_n < y_n;
}
};
/* array_desc_set is a wrapper around a sorted set of identifier sequences,
* with each identifier representing a (possibly renamed) ValueDecl.
* The actual order is not important, only that it is consistent
* across platforms.
* The wrapper takes care of the memory management of the isl_id_list objects.
* In particular, the set keeps hold of its own reference to these objects.
*/
struct array_desc_set : public std::set<isl_id_list *, array_desc_less>
{
void insert(__isl_take isl_id_list *list) {
if (find(list) == end())
set::insert(list);
else
isl_id_list_free(list);
}
void erase(__isl_keep isl_id_list *list) {
iterator it;
it = find(list);
if (it == end())
return;
isl_id_list_free(*it);
set::erase(it);
}
~array_desc_set() {
iterator it;
for (it = begin(); it != end(); ++it)
isl_id_list_free(*it);
}
};
void pet_scop_collect_arrays(struct pet_scop *scop, array_desc_set &arrays);
#endif