export pet_expr_access_get_may_access
[pet.git] / scop_plus.cc
blob1a9563e412e3ec4a2047939cb32644be0604f62e
1 /*
2 * Copyright 2011 Leiden University. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY LEIDEN UNIVERSITY ''AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEIDEN UNIVERSITY OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * The views and conclusions contained in the software and documentation
29 * are those of the authors and should not be interpreted as
30 * representing official policies, either expressed or implied, of
31 * Leiden University.
32 */
34 #include <set>
36 #include "scop_plus.h"
38 using namespace std;
39 using namespace clang;
41 /* If the array being accessed has a NULL ValueDecl, then it
42 * is a virtual scalar. We don't need to collect such scalars
43 * because they are added to the scop of the statement writing
44 * to the scalar.
46 static void access_collect_arrays(struct pet_expr *expr,
47 set<ValueDecl *> &arrays)
49 isl_id *id;
50 ValueDecl *decl;
52 if (pet_expr_is_affine(expr))
53 return;
54 id = pet_expr_access_get_id(expr);
55 if (!id)
56 return;
58 decl = (ValueDecl *)isl_id_get_user(id);
59 isl_id_free(id);
61 if (decl)
62 arrays.insert(decl);
65 static void expr_collect_arrays(struct pet_expr *expr, set<ValueDecl *> &arrays)
67 if (!expr)
68 return;
70 for (int i = 0; i < expr->n_arg; ++i)
71 expr_collect_arrays(expr->args[i], arrays);
73 if (expr->type == pet_expr_access)
74 access_collect_arrays(expr, arrays);
77 static void stmt_collect_arrays(struct pet_stmt *stmt, set<ValueDecl *> &arrays)
79 if (!stmt)
80 return;
82 for (int i = 0; i < stmt->n_arg; ++i)
83 expr_collect_arrays(stmt->args[i], arrays);
85 expr_collect_arrays(stmt->body, arrays);
88 /* Collect the set of all accessed arrays (or scalars) in "scop",
89 * except those that already appear in scop->arrays,
90 * and put them in "arrays".
92 void pet_scop_collect_arrays(struct pet_scop *scop, set<ValueDecl *> &arrays)
94 if (!scop)
95 return;
97 for (int i = 0; i < scop->n_stmt; ++i)
98 stmt_collect_arrays(scop->stmts[i], arrays);
100 for (int i = 0; i < scop->n_array; ++i) {
101 ValueDecl *decl;
102 isl_id *id = isl_set_get_tuple_id(scop->arrays[i]->extent);
103 decl = (ValueDecl *)isl_id_get_user(id);
104 isl_id_free(id);
106 arrays.erase(decl);