fix check for "simple" loop termination condition
[pet.git] / scan.h
blobdeae095e7474c2d7ef7da6750a44d501f67ede11
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 /* If autodetect is false, then loc contains the location
26 * of the scop to be extracted.
28 ScopLoc &loc;
29 isl_ctx *ctx;
30 /* The sequence number of the next statement. */
31 int n_stmt;
32 /* If autodetect is false, a scop delimited by pragmas is extracted,
33 * otherwise we take any scop that we can find.
35 bool autodetect;
36 /* Set if the pet_scop returned by an extract method only
37 * represents part of the input tree.
39 bool partial;
40 /* Set is nested accesses are allowed in general.
41 * This currently defaults to true.
43 bool allow_nested;
44 /* Set if nested accesses are allowed in that part of the tree
45 * that is currently under investigation.
47 bool nesting_enabled;
48 /* Maps identifiers to the last expression that was assigned to them.
49 * If an identifier is mapped to NULL, then something may have
50 * been assigned, but we don't know what.
52 std::map<clang::ValueDecl *, clang::Expr *> assigned_value;
54 PetScan(isl_ctx *ctx, clang::Preprocessor &PP, ScopLoc &loc,
55 int autodetect) :
56 ctx(ctx), PP(PP), loc(loc), autodetect(autodetect),
57 n_stmt(0), partial(0), allow_nested(true),
58 nesting_enabled(false) { }
60 struct pet_scop *scan(clang::FunctionDecl *fd);
61 private:
62 struct pet_scop *scan(clang::Stmt *stmt);
64 struct pet_scop *scan_arrays(struct pet_scop *scop);
65 struct pet_array *extract_array(isl_ctx *ctx, clang::ValueDecl *decl);
66 struct pet_array *set_upper_bounds(struct pet_array *array,
67 const clang::Type *type, int pos);
69 struct pet_scop *extract_conditional_assignment(clang::IfStmt *stmt);
71 struct pet_scop *extract(clang::Stmt *stmt);
72 struct pet_scop *extract(clang::StmtRange stmt_range);
73 struct pet_scop *extract(clang::IfStmt *stmt);
74 struct pet_scop *extract(clang::CompoundStmt *stmt);
76 struct pet_scop *extract(clang::Stmt *stmt, struct pet_expr *expr);
78 clang::BinaryOperator *extract_initialization(clang::ForStmt *stmt);
79 clang::ValueDecl *extract_induction_variable(clang::BinaryOperator *stmt);
80 bool check_increment(clang::ForStmt *stmt, clang::ValueDecl *iv,
81 bool &up);
82 struct pet_scop *extract_for(clang::ForStmt *stmt);
83 struct pet_scop *extract_infinite_for(clang::ForStmt *stmt);
85 struct pet_expr *extract_expr(clang::Expr *expr);
86 struct pet_expr *extract_expr(clang::UnaryOperator *expr);
87 struct pet_expr *extract_expr(clang::BinaryOperator *expr);
88 struct pet_expr *extract_expr(clang::ImplicitCastExpr *expr);
89 struct pet_expr *extract_expr(clang::FloatingLiteral *expr);
90 struct pet_expr *extract_expr(clang::ParenExpr *expr);
91 struct pet_expr *extract_expr(clang::ConditionalOperator *expr);
92 struct pet_expr *extract_expr(clang::CallExpr *expr);
94 struct pet_expr *resolve_nested(struct pet_expr *expr);
95 struct pet_expr *extract_access_expr(clang::Expr *expr);
97 __isl_give isl_map *extract_access(clang::ArraySubscriptExpr *expr);
98 __isl_give isl_map *extract_access(clang::Expr *expr);
99 __isl_give isl_map *extract_access(clang::ImplicitCastExpr *expr);
100 __isl_give isl_map *extract_access(clang::DeclRefExpr *expr);
101 __isl_give isl_map *extract_access(clang::IntegerLiteral *expr);
103 __isl_give isl_pw_aff *extract_affine_div(clang::BinaryOperator *expr);
104 __isl_give isl_pw_aff *extract_affine_mod(clang::BinaryOperator *expr);
105 __isl_give isl_pw_aff *extract_affine_mul(clang::BinaryOperator *expr);
107 int extract_int(clang::IntegerLiteral *expr, isl_int *v);
109 isl_pw_aff *non_affine(clang::Expr *expr);
111 bool is_affine(clang::Expr *expr);
112 bool is_affine_condition(clang::Expr *expr);
114 __isl_give isl_pw_aff *extract_affine(const llvm::APInt &val);
115 __isl_give isl_pw_aff *extract_affine(clang::Expr *expr);
116 __isl_give isl_pw_aff *extract_affine(clang::IntegerLiteral *expr);
117 __isl_give isl_pw_aff *extract_affine(clang::ImplicitCastExpr *expr);
118 __isl_give isl_pw_aff *extract_affine(clang::DeclRefExpr *expr);
119 __isl_give isl_pw_aff *extract_affine(clang::BinaryOperator *expr);
120 __isl_give isl_pw_aff *extract_affine(clang::UnaryOperator *expr);
121 __isl_give isl_pw_aff *extract_affine(clang::ParenExpr *expr);
122 __isl_give isl_pw_aff *extract_affine(clang::CallExpr *expr);
123 __isl_give isl_pw_aff *extract_affine(clang::ArraySubscriptExpr *expr);
124 __isl_give isl_pw_aff *extract_affine(clang::ConditionalOperator *expr);
126 __isl_give isl_set *extract_implicit_condition(clang::Expr *expr);
128 __isl_give isl_set *extract_condition(clang::UnaryOperator *expr);
129 __isl_give isl_set *extract_condition(clang::Expr *expr);
130 __isl_give isl_set *extract_comparison(clang::BinaryOperator *expr);
131 __isl_give isl_set *extract_comparison(clang::BinaryOperatorKind op,
132 clang::Expr *LHS, clang::Expr *RHS, clang::Expr *comp);
133 __isl_give isl_set *extract_boolean(clang::BinaryOperator *expr);
134 __isl_give isl_set *extract_boolean(clang::UnaryOperator *expr);
136 void unsupported(clang::Stmt *stmt);