pet.cc: extract out update_arrays
[pet.git] / scan.h
blob3bf21575bec64a306b044dcd5fd5788deda46053
1 #include <map>
3 #include <clang/Basic/SourceManager.h>
4 #include <clang/AST/Decl.h>
5 #include <clang/AST/Stmt.h>
6 #include <clang/Lex/Preprocessor.h>
8 #include <isl/ctx.h>
9 #include <isl/map.h>
11 #include "scop.h"
13 /* The location of the scop, as delimited by scop and endscop
14 * pragmas by the user.
16 struct ScopLoc {
17 ScopLoc() : end(0) {}
19 unsigned start;
20 unsigned end;
23 struct PetScan {
24 clang::Preprocessor &PP;
25 clang::ASTContext &ast_context;
26 /* If autodetect is false, then loc contains the location
27 * of the scop to be extracted.
29 ScopLoc &loc;
30 isl_ctx *ctx;
31 /* The sequence number of the next statement. */
32 int n_stmt;
33 /* If autodetect is false, a scop delimited by pragmas is extracted,
34 * otherwise we take any scop that we can find.
36 bool autodetect;
37 /* Set if the pet_scop returned by an extract method only
38 * represents part of the input tree.
40 bool partial;
41 /* Set is nested accesses are allowed in general.
42 * This currently defaults to true.
44 bool allow_nested;
45 /* Set if nested accesses are allowed in that part of the tree
46 * that is currently under investigation.
48 bool nesting_enabled;
49 /* Maps identifiers to the last expression that was assigned to them.
50 * If an identifier is mapped to NULL, then something may have
51 * been assigned, but we don't know what.
53 std::map<clang::ValueDecl *, clang::Expr *> assigned_value;
55 PetScan(isl_ctx *ctx, clang::Preprocessor &PP,
56 clang::ASTContext &ast_context, ScopLoc &loc, int autodetect) :
57 ctx(ctx), PP(PP), ast_context(ast_context), loc(loc),
58 autodetect(autodetect),
59 n_stmt(0), partial(0), allow_nested(true),
60 nesting_enabled(false) { }
62 struct pet_scop *scan(clang::FunctionDecl *fd);
63 private:
64 struct pet_scop *scan(clang::Stmt *stmt);
66 struct pet_scop *scan_arrays(struct pet_scop *scop);
67 struct pet_array *extract_array(isl_ctx *ctx, clang::ValueDecl *decl);
68 struct pet_array *set_upper_bounds(struct pet_array *array,
69 const clang::Type *type, int pos);
71 struct pet_scop *extract_conditional_assignment(clang::IfStmt *stmt);
73 struct pet_scop *extract(clang::Stmt *stmt);
74 struct pet_scop *extract(clang::StmtRange stmt_range);
75 struct pet_scop *extract(clang::IfStmt *stmt);
76 struct pet_scop *extract(clang::CompoundStmt *stmt);
78 struct pet_scop *extract(clang::Stmt *stmt, struct pet_expr *expr);
80 clang::BinaryOperator *extract_initialization(clang::ForStmt *stmt);
81 clang::ValueDecl *extract_induction_variable(clang::BinaryOperator *stmt);
82 bool check_unary_increment(clang::UnaryOperator *op,
83 clang::ValueDecl *iv, isl_int &inc);
84 bool check_binary_increment(clang::BinaryOperator *op,
85 clang::ValueDecl *iv, isl_int &inc);
86 bool check_compound_increment(clang::CompoundAssignOperator *op,
87 clang::ValueDecl *iv, isl_int &inc);
88 bool check_increment(clang::ForStmt *stmt, clang::ValueDecl *iv,
89 isl_int &inc);
90 struct pet_scop *extract_for(clang::ForStmt *stmt);
91 struct pet_scop *extract_infinite_for(clang::ForStmt *stmt);
93 struct pet_expr *extract_expr(clang::Expr *expr);
94 struct pet_expr *extract_expr(clang::UnaryOperator *expr);
95 struct pet_expr *extract_expr(clang::BinaryOperator *expr);
96 struct pet_expr *extract_expr(clang::ImplicitCastExpr *expr);
97 struct pet_expr *extract_expr(clang::FloatingLiteral *expr);
98 struct pet_expr *extract_expr(clang::ParenExpr *expr);
99 struct pet_expr *extract_expr(clang::ConditionalOperator *expr);
100 struct pet_expr *extract_expr(clang::CallExpr *expr);
102 struct pet_expr *resolve_nested(struct pet_expr *expr);
103 struct pet_expr *extract_access_expr(clang::Expr *expr);
105 __isl_give isl_map *extract_access(clang::ArraySubscriptExpr *expr);
106 __isl_give isl_map *extract_access(clang::Expr *expr);
107 __isl_give isl_map *extract_access(clang::ImplicitCastExpr *expr);
108 __isl_give isl_map *extract_access(clang::DeclRefExpr *expr);
109 __isl_give isl_map *extract_access(clang::IntegerLiteral *expr);
111 __isl_give isl_pw_aff *extract_affine_add(clang::BinaryOperator *expr);
112 __isl_give isl_pw_aff *extract_affine_div(clang::BinaryOperator *expr);
113 __isl_give isl_pw_aff *extract_affine_mod(clang::BinaryOperator *expr);
114 __isl_give isl_pw_aff *extract_affine_mul(clang::BinaryOperator *expr);
116 int extract_int(clang::IntegerLiteral *expr, isl_int *v);
118 isl_pw_aff *non_affine(clang::Expr *expr);
120 bool is_affine(clang::Expr *expr);
121 bool is_affine_condition(clang::Expr *expr);
123 __isl_give isl_pw_aff *extract_affine(const llvm::APInt &val);
124 __isl_give isl_pw_aff *extract_affine(clang::Expr *expr);
125 __isl_give isl_pw_aff *extract_affine(clang::IntegerLiteral *expr);
126 __isl_give isl_pw_aff *extract_affine(clang::ImplicitCastExpr *expr);
127 __isl_give isl_pw_aff *extract_affine(clang::DeclRefExpr *expr);
128 __isl_give isl_pw_aff *extract_affine(clang::BinaryOperator *expr);
129 __isl_give isl_pw_aff *extract_affine(clang::UnaryOperator *expr);
130 __isl_give isl_pw_aff *extract_affine(clang::ParenExpr *expr);
131 __isl_give isl_pw_aff *extract_affine(clang::CallExpr *expr);
132 __isl_give isl_pw_aff *extract_affine(clang::ArraySubscriptExpr *expr);
133 __isl_give isl_pw_aff *extract_affine(clang::ConditionalOperator *expr);
135 __isl_give isl_set *extract_implicit_condition(clang::Expr *expr);
137 __isl_give isl_set *extract_condition(clang::UnaryOperator *expr);
138 __isl_give isl_set *extract_condition(clang::Expr *expr);
139 __isl_give isl_set *extract_comparison(clang::BinaryOperator *expr);
140 __isl_give isl_set *extract_comparison(clang::BinaryOperatorKind op,
141 clang::Expr *LHS, clang::Expr *RHS, clang::Expr *comp);
142 __isl_give isl_set *extract_boolean(clang::BinaryOperator *expr);
143 __isl_give isl_set *extract_boolean(clang::UnaryOperator *expr);
145 void unsupported(clang::Stmt *stmt);