update isl for isl_set_upper_bound_si
[pet.git] / scan.h
blob0b3b0fb99c82d83acc6b3e8d2e1b8a0b7f0e1bbf
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 /* The sequence number of the next virtual scalar. */
34 int n_test;
35 /* If autodetect is false, a scop delimited by pragmas is extracted,
36 * otherwise we take any scop that we can find.
38 bool autodetect;
39 /* Set if the pet_scop returned by an extract method only
40 * represents part of the input tree.
42 bool partial;
43 /* Set is nested accesses are allowed in general.
44 * This currently defaults to true.
46 bool allow_nested;
47 /* Set if nested accesses are allowed in that part of the tree
48 * that is currently under investigation.
50 bool nesting_enabled;
51 /* Maps identifiers to the last expression that was assigned to them.
52 * If an identifier is mapped to NULL, then something may have
53 * been assigned, but we don't know what.
55 std::map<clang::ValueDecl *, clang::Expr *> assigned_value;
57 PetScan(isl_ctx *ctx, clang::Preprocessor &PP,
58 clang::ASTContext &ast_context, ScopLoc &loc, int autodetect) :
59 ctx(ctx), PP(PP), ast_context(ast_context), loc(loc),
60 autodetect(autodetect),
61 n_stmt(0), n_test(0), partial(0), allow_nested(true),
62 nesting_enabled(false) { }
64 struct pet_scop *scan(clang::FunctionDecl *fd);
66 static int extract_int(clang::IntegerLiteral *expr, isl_int *v);
67 private:
68 struct pet_scop *scan(clang::Stmt *stmt);
70 struct pet_scop *scan_arrays(struct pet_scop *scop);
71 struct pet_array *extract_array(isl_ctx *ctx, clang::ValueDecl *decl);
72 struct pet_array *set_upper_bounds(struct pet_array *array,
73 const clang::Type *type, int pos);
75 struct pet_scop *extract_non_affine_condition(clang::Expr *cond,
76 __isl_take isl_map *access);
78 struct pet_scop *extract_conditional_assignment(clang::IfStmt *stmt);
80 struct pet_scop *extract(clang::Stmt *stmt);
81 struct pet_scop *extract(clang::StmtRange stmt_range);
82 struct pet_scop *extract(clang::IfStmt *stmt);
83 struct pet_scop *extract(clang::WhileStmt *stmt);
84 struct pet_scop *extract(clang::CompoundStmt *stmt);
86 struct pet_scop *extract(clang::Stmt *stmt, struct pet_expr *expr);
88 clang::BinaryOperator *initialization_assignment(clang::Stmt *init);
89 clang::Decl *initialization_declaration(clang::Stmt *init);
90 clang::ValueDecl *extract_induction_variable(clang::BinaryOperator *stmt);
91 clang::VarDecl *extract_induction_variable(clang::Stmt *init,
92 clang::Decl *stmt);
93 bool check_unary_increment(clang::UnaryOperator *op,
94 clang::ValueDecl *iv, isl_int &inc);
95 bool check_binary_increment(clang::BinaryOperator *op,
96 clang::ValueDecl *iv, isl_int &inc);
97 bool check_compound_increment(clang::CompoundAssignOperator *op,
98 clang::ValueDecl *iv, isl_int &inc);
99 bool check_increment(clang::ForStmt *stmt, clang::ValueDecl *iv,
100 isl_int &inc);
101 struct pet_scop *extract_for(clang::ForStmt *stmt);
102 struct pet_scop *extract_infinite_loop(clang::Stmt *body);
103 struct pet_scop *extract_infinite_for(clang::ForStmt *stmt);
105 void mark_write(struct pet_expr *access);
106 struct pet_expr *extract_expr(clang::Expr *expr);
107 struct pet_expr *extract_expr(clang::UnaryOperator *expr);
108 struct pet_expr *extract_expr(clang::BinaryOperator *expr);
109 struct pet_expr *extract_expr(clang::ImplicitCastExpr *expr);
110 struct pet_expr *extract_expr(clang::FloatingLiteral *expr);
111 struct pet_expr *extract_expr(clang::ParenExpr *expr);
112 struct pet_expr *extract_expr(clang::ConditionalOperator *expr);
113 struct pet_expr *extract_expr(clang::CallExpr *expr);
115 struct pet_expr *resolve_nested(struct pet_expr *expr);
116 struct pet_expr *extract_access_expr(clang::Expr *expr);
118 __isl_give isl_map *extract_access(clang::ArraySubscriptExpr *expr);
119 __isl_give isl_map *extract_access(clang::Expr *expr);
120 __isl_give isl_map *extract_access(clang::ImplicitCastExpr *expr);
121 __isl_give isl_map *extract_access(clang::DeclRefExpr *expr);
122 __isl_give isl_map *extract_access(clang::IntegerLiteral *expr);
124 __isl_give isl_pw_aff *extract_affine_add(clang::BinaryOperator *expr);
125 __isl_give isl_pw_aff *extract_affine_div(clang::BinaryOperator *expr);
126 __isl_give isl_pw_aff *extract_affine_mod(clang::BinaryOperator *expr);
127 __isl_give isl_pw_aff *extract_affine_mul(clang::BinaryOperator *expr);
129 isl_pw_aff *non_affine(clang::Expr *expr);
131 bool is_affine(clang::Expr *expr);
132 bool is_affine_condition(clang::Expr *expr);
134 __isl_give isl_pw_aff *extract_affine(const llvm::APInt &val);
135 __isl_give isl_pw_aff *extract_affine(clang::Expr *expr);
136 __isl_give isl_pw_aff *extract_affine(clang::IntegerLiteral *expr);
137 __isl_give isl_pw_aff *extract_affine(clang::ImplicitCastExpr *expr);
138 __isl_give isl_pw_aff *extract_affine(clang::DeclRefExpr *expr);
139 __isl_give isl_pw_aff *extract_affine(clang::BinaryOperator *expr);
140 __isl_give isl_pw_aff *extract_affine(clang::UnaryOperator *expr);
141 __isl_give isl_pw_aff *extract_affine(clang::ParenExpr *expr);
142 __isl_give isl_pw_aff *extract_affine(clang::CallExpr *expr);
143 __isl_give isl_pw_aff *extract_affine(clang::ArraySubscriptExpr *expr);
144 __isl_give isl_pw_aff *extract_affine(clang::ConditionalOperator *expr);
146 __isl_give isl_set *extract_implicit_condition(clang::Expr *expr);
148 __isl_give isl_set *extract_condition(clang::UnaryOperator *expr);
149 __isl_give isl_set *extract_condition(clang::Expr *expr);
150 __isl_give isl_set *extract_comparison(clang::BinaryOperator *expr);
151 __isl_give isl_set *extract_comparison(clang::BinaryOperatorKind op,
152 clang::Expr *LHS, clang::Expr *RHS, clang::Stmt *comp);
153 __isl_give isl_set *extract_boolean(clang::BinaryOperator *expr);
154 __isl_give isl_set *extract_boolean(clang::UnaryOperator *expr);
156 void unsupported(clang::Stmt *stmt);