update isl for explicit parameter spaces
[pet.git] / scan.h
blob331133c1a23f4d3da875e232a7d428e67e55ea55
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::WhileStmt *stmt);
77 struct pet_scop *extract(clang::CompoundStmt *stmt);
79 struct pet_scop *extract(clang::Stmt *stmt, struct pet_expr *expr);
81 clang::BinaryOperator *initialization_assignment(clang::Stmt *init);
82 clang::Decl *initialization_declaration(clang::Stmt *init);
83 clang::ValueDecl *extract_induction_variable(clang::BinaryOperator *stmt);
84 clang::VarDecl *extract_induction_variable(clang::Stmt *init,
85 clang::Decl *stmt);
86 bool check_unary_increment(clang::UnaryOperator *op,
87 clang::ValueDecl *iv, isl_int &inc);
88 bool check_binary_increment(clang::BinaryOperator *op,
89 clang::ValueDecl *iv, isl_int &inc);
90 bool check_compound_increment(clang::CompoundAssignOperator *op,
91 clang::ValueDecl *iv, isl_int &inc);
92 bool check_increment(clang::ForStmt *stmt, clang::ValueDecl *iv,
93 isl_int &inc);
94 struct pet_scop *extract_for(clang::ForStmt *stmt);
95 struct pet_scop *extract_infinite_loop(clang::Stmt *body);
96 struct pet_scop *extract_infinite_for(clang::ForStmt *stmt);
98 struct pet_expr *extract_expr(clang::Expr *expr);
99 struct pet_expr *extract_expr(clang::UnaryOperator *expr);
100 struct pet_expr *extract_expr(clang::BinaryOperator *expr);
101 struct pet_expr *extract_expr(clang::ImplicitCastExpr *expr);
102 struct pet_expr *extract_expr(clang::FloatingLiteral *expr);
103 struct pet_expr *extract_expr(clang::ParenExpr *expr);
104 struct pet_expr *extract_expr(clang::ConditionalOperator *expr);
105 struct pet_expr *extract_expr(clang::CallExpr *expr);
107 struct pet_expr *resolve_nested(struct pet_expr *expr);
108 struct pet_expr *extract_access_expr(clang::Expr *expr);
110 __isl_give isl_map *extract_access(clang::ArraySubscriptExpr *expr);
111 __isl_give isl_map *extract_access(clang::Expr *expr);
112 __isl_give isl_map *extract_access(clang::ImplicitCastExpr *expr);
113 __isl_give isl_map *extract_access(clang::DeclRefExpr *expr);
114 __isl_give isl_map *extract_access(clang::IntegerLiteral *expr);
116 __isl_give isl_pw_aff *extract_affine_add(clang::BinaryOperator *expr);
117 __isl_give isl_pw_aff *extract_affine_div(clang::BinaryOperator *expr);
118 __isl_give isl_pw_aff *extract_affine_mod(clang::BinaryOperator *expr);
119 __isl_give isl_pw_aff *extract_affine_mul(clang::BinaryOperator *expr);
121 int extract_int(clang::IntegerLiteral *expr, isl_int *v);
123 isl_pw_aff *non_affine(clang::Expr *expr);
125 bool is_affine(clang::Expr *expr);
126 bool is_affine_condition(clang::Expr *expr);
128 __isl_give isl_pw_aff *extract_affine(const llvm::APInt &val);
129 __isl_give isl_pw_aff *extract_affine(clang::Expr *expr);
130 __isl_give isl_pw_aff *extract_affine(clang::IntegerLiteral *expr);
131 __isl_give isl_pw_aff *extract_affine(clang::ImplicitCastExpr *expr);
132 __isl_give isl_pw_aff *extract_affine(clang::DeclRefExpr *expr);
133 __isl_give isl_pw_aff *extract_affine(clang::BinaryOperator *expr);
134 __isl_give isl_pw_aff *extract_affine(clang::UnaryOperator *expr);
135 __isl_give isl_pw_aff *extract_affine(clang::ParenExpr *expr);
136 __isl_give isl_pw_aff *extract_affine(clang::CallExpr *expr);
137 __isl_give isl_pw_aff *extract_affine(clang::ArraySubscriptExpr *expr);
138 __isl_give isl_pw_aff *extract_affine(clang::ConditionalOperator *expr);
140 __isl_give isl_set *extract_implicit_condition(clang::Expr *expr);
142 __isl_give isl_set *extract_condition(clang::UnaryOperator *expr);
143 __isl_give isl_set *extract_condition(clang::Expr *expr);
144 __isl_give isl_set *extract_comparison(clang::BinaryOperator *expr);
145 __isl_give isl_set *extract_comparison(clang::BinaryOperatorKind op,
146 clang::Expr *LHS, clang::Expr *RHS, clang::Stmt *comp);
147 __isl_give isl_set *extract_boolean(clang::BinaryOperator *expr);
148 __isl_give isl_set *extract_boolean(clang::UnaryOperator *expr);
150 void unsupported(clang::Stmt *stmt);