update isl for change in isl_pw_aff_set_tuple_id prototype
[pet.git] / scan.h
blobcd307dfa61ccedf1b8f428c0211ca41312720fad
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);
64 static int extract_int(clang::IntegerLiteral *expr, isl_int *v);
65 private:
66 struct pet_scop *scan(clang::Stmt *stmt);
68 struct pet_scop *scan_arrays(struct pet_scop *scop);
69 struct pet_array *extract_array(isl_ctx *ctx, clang::ValueDecl *decl);
70 struct pet_array *set_upper_bounds(struct pet_array *array,
71 const clang::Type *type, int pos);
73 struct pet_scop *extract_conditional_assignment(clang::IfStmt *stmt);
75 struct pet_scop *extract(clang::Stmt *stmt);
76 struct pet_scop *extract(clang::StmtRange stmt_range);
77 struct pet_scop *extract(clang::IfStmt *stmt);
78 struct pet_scop *extract(clang::WhileStmt *stmt);
79 struct pet_scop *extract(clang::CompoundStmt *stmt);
81 struct pet_scop *extract(clang::Stmt *stmt, struct pet_expr *expr);
83 clang::BinaryOperator *initialization_assignment(clang::Stmt *init);
84 clang::Decl *initialization_declaration(clang::Stmt *init);
85 clang::ValueDecl *extract_induction_variable(clang::BinaryOperator *stmt);
86 clang::VarDecl *extract_induction_variable(clang::Stmt *init,
87 clang::Decl *stmt);
88 bool check_unary_increment(clang::UnaryOperator *op,
89 clang::ValueDecl *iv, isl_int &inc);
90 bool check_binary_increment(clang::BinaryOperator *op,
91 clang::ValueDecl *iv, isl_int &inc);
92 bool check_compound_increment(clang::CompoundAssignOperator *op,
93 clang::ValueDecl *iv, isl_int &inc);
94 bool check_increment(clang::ForStmt *stmt, clang::ValueDecl *iv,
95 isl_int &inc);
96 struct pet_scop *extract_for(clang::ForStmt *stmt);
97 struct pet_scop *extract_infinite_loop(clang::Stmt *body);
98 struct pet_scop *extract_infinite_for(clang::ForStmt *stmt);
100 void mark_write(struct pet_expr *access);
101 struct pet_expr *extract_expr(clang::Expr *expr);
102 struct pet_expr *extract_expr(clang::UnaryOperator *expr);
103 struct pet_expr *extract_expr(clang::BinaryOperator *expr);
104 struct pet_expr *extract_expr(clang::ImplicitCastExpr *expr);
105 struct pet_expr *extract_expr(clang::FloatingLiteral *expr);
106 struct pet_expr *extract_expr(clang::ParenExpr *expr);
107 struct pet_expr *extract_expr(clang::ConditionalOperator *expr);
108 struct pet_expr *extract_expr(clang::CallExpr *expr);
110 struct pet_expr *resolve_nested(struct pet_expr *expr);
111 struct pet_expr *extract_access_expr(clang::Expr *expr);
113 __isl_give isl_map *extract_access(clang::ArraySubscriptExpr *expr);
114 __isl_give isl_map *extract_access(clang::Expr *expr);
115 __isl_give isl_map *extract_access(clang::ImplicitCastExpr *expr);
116 __isl_give isl_map *extract_access(clang::DeclRefExpr *expr);
117 __isl_give isl_map *extract_access(clang::IntegerLiteral *expr);
119 __isl_give isl_pw_aff *extract_affine_add(clang::BinaryOperator *expr);
120 __isl_give isl_pw_aff *extract_affine_div(clang::BinaryOperator *expr);
121 __isl_give isl_pw_aff *extract_affine_mod(clang::BinaryOperator *expr);
122 __isl_give isl_pw_aff *extract_affine_mul(clang::BinaryOperator *expr);
124 isl_pw_aff *non_affine(clang::Expr *expr);
126 bool is_affine(clang::Expr *expr);
127 bool is_affine_condition(clang::Expr *expr);
129 __isl_give isl_pw_aff *extract_affine(const llvm::APInt &val);
130 __isl_give isl_pw_aff *extract_affine(clang::Expr *expr);
131 __isl_give isl_pw_aff *extract_affine(clang::IntegerLiteral *expr);
132 __isl_give isl_pw_aff *extract_affine(clang::ImplicitCastExpr *expr);
133 __isl_give isl_pw_aff *extract_affine(clang::DeclRefExpr *expr);
134 __isl_give isl_pw_aff *extract_affine(clang::BinaryOperator *expr);
135 __isl_give isl_pw_aff *extract_affine(clang::UnaryOperator *expr);
136 __isl_give isl_pw_aff *extract_affine(clang::ParenExpr *expr);
137 __isl_give isl_pw_aff *extract_affine(clang::CallExpr *expr);
138 __isl_give isl_pw_aff *extract_affine(clang::ArraySubscriptExpr *expr);
139 __isl_give isl_pw_aff *extract_affine(clang::ConditionalOperator *expr);
141 __isl_give isl_set *extract_implicit_condition(clang::Expr *expr);
143 __isl_give isl_set *extract_condition(clang::UnaryOperator *expr);
144 __isl_give isl_set *extract_condition(clang::Expr *expr);
145 __isl_give isl_set *extract_comparison(clang::BinaryOperator *expr);
146 __isl_give isl_set *extract_comparison(clang::BinaryOperatorKind op,
147 clang::Expr *LHS, clang::Expr *RHS, clang::Stmt *comp);
148 __isl_give isl_set *extract_boolean(clang::BinaryOperator *expr);
149 __isl_give isl_set *extract_boolean(clang::UnaryOperator *expr);
151 void unsupported(clang::Stmt *stmt);