pet_scop_extract_from_C_source: use a CompilerInstance
[pet.git] / scop_plus.cc
blob08540fb1f57f07d5618077d51d739d1e0e82f66e
1 #include <set>
3 #include "scop_plus.h"
5 using namespace std;
6 using namespace clang;
8 static void access_collect_arrays(struct pet_expr *expr,
9 set<ValueDecl *> &arrays)
11 isl_id *id;
12 ValueDecl *decl;
14 if (!isl_map_has_tuple_id(expr->acc.access, isl_dim_out))
15 return;
16 id = isl_map_get_tuple_id(expr->acc.access, isl_dim_out);
17 if (!id)
18 return;
20 decl = (ValueDecl *)isl_id_get_user(id);
21 isl_id_free(id);
23 arrays.insert(decl);
26 static void expr_collect_arrays(struct pet_expr *expr, set<ValueDecl *> &arrays)
28 if (!expr)
29 return;
31 for (int i = 0; i < expr->n_arg; ++i)
32 expr_collect_arrays(expr->args[i], arrays);
34 if (expr->type == pet_expr_access)
35 access_collect_arrays(expr, arrays);
38 static void stmt_collect_arrays(struct pet_stmt *stmt, set<ValueDecl *> &arrays)
40 if (!stmt)
41 return;
42 expr_collect_arrays(stmt->body, arrays);
45 /* Collect the set of all accessed arrays (or scalars) in "scop"
46 * and put them in "arrays".
48 void pet_scop_collect_arrays(struct pet_scop *scop, set<ValueDecl *> &arrays)
50 if (!scop)
51 return;
53 for (int i = 0; i < scop->n_stmt; ++i)
54 stmt_collect_arrays(scop->stmts[i], arrays);