add -D option
[pet.git] / scan.h
blob715b62ee53cf391d95e07387a878806b7b7081d8
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);
85 struct pet_scop *extract(clang::LabelStmt *stmt);
87 struct pet_scop *extract(clang::Stmt *stmt, struct pet_expr *expr,
88 __isl_take isl_id *label = NULL);
90 clang::BinaryOperator *initialization_assignment(clang::Stmt *init);
91 clang::Decl *initialization_declaration(clang::Stmt *init);
92 clang::ValueDecl *extract_induction_variable(clang::BinaryOperator *stmt);
93 clang::VarDecl *extract_induction_variable(clang::Stmt *init,
94 clang::Decl *stmt);
95 bool check_unary_increment(clang::UnaryOperator *op,
96 clang::ValueDecl *iv, isl_int &inc);
97 bool check_binary_increment(clang::BinaryOperator *op,
98 clang::ValueDecl *iv, isl_int &inc);
99 bool check_compound_increment(clang::CompoundAssignOperator *op,
100 clang::ValueDecl *iv, isl_int &inc);
101 bool check_increment(clang::ForStmt *stmt, clang::ValueDecl *iv,
102 isl_int &inc);
103 struct pet_scop *extract_for(clang::ForStmt *stmt);
104 struct pet_scop *extract_infinite_loop(clang::Stmt *body);
105 struct pet_scop *extract_infinite_for(clang::ForStmt *stmt);
107 void mark_write(struct pet_expr *access);
108 struct pet_expr *extract_expr(clang::Expr *expr);
109 struct pet_expr *extract_expr(clang::UnaryOperator *expr);
110 struct pet_expr *extract_expr(clang::BinaryOperator *expr);
111 struct pet_expr *extract_expr(clang::ImplicitCastExpr *expr);
112 struct pet_expr *extract_expr(clang::FloatingLiteral *expr);
113 struct pet_expr *extract_expr(clang::ParenExpr *expr);
114 struct pet_expr *extract_expr(clang::ConditionalOperator *expr);
115 struct pet_expr *extract_expr(clang::CallExpr *expr);
117 struct pet_expr *resolve_nested(struct pet_expr *expr);
118 struct pet_expr *extract_access_expr(clang::Expr *expr);
120 __isl_give isl_map *extract_access(clang::ArraySubscriptExpr *expr);
121 __isl_give isl_map *extract_access(clang::Expr *expr);
122 __isl_give isl_map *extract_access(clang::ImplicitCastExpr *expr);
123 __isl_give isl_map *extract_access(clang::DeclRefExpr *expr);
124 __isl_give isl_map *extract_access(clang::IntegerLiteral *expr);
126 __isl_give isl_pw_aff *extract_affine_add(clang::BinaryOperator *expr);
127 __isl_give isl_pw_aff *extract_affine_div(clang::BinaryOperator *expr);
128 __isl_give isl_pw_aff *extract_affine_mod(clang::BinaryOperator *expr);
129 __isl_give isl_pw_aff *extract_affine_mul(clang::BinaryOperator *expr);
131 isl_pw_aff *non_affine(clang::Expr *expr);
133 bool is_affine(clang::Expr *expr);
134 bool is_affine_condition(clang::Expr *expr);
136 __isl_give isl_pw_aff *extract_affine(const llvm::APInt &val);
137 __isl_give isl_pw_aff *extract_affine(clang::Expr *expr);
138 __isl_give isl_pw_aff *extract_affine(clang::IntegerLiteral *expr);
139 __isl_give isl_pw_aff *extract_affine(clang::ImplicitCastExpr *expr);
140 __isl_give isl_pw_aff *extract_affine(clang::DeclRefExpr *expr);
141 __isl_give isl_pw_aff *extract_affine(clang::BinaryOperator *expr);
142 __isl_give isl_pw_aff *extract_affine(clang::UnaryOperator *expr);
143 __isl_give isl_pw_aff *extract_affine(clang::ParenExpr *expr);
144 __isl_give isl_pw_aff *extract_affine(clang::CallExpr *expr);
145 __isl_give isl_pw_aff *extract_affine(clang::ArraySubscriptExpr *expr);
146 __isl_give isl_pw_aff *extract_affine(clang::ConditionalOperator *expr);
148 __isl_give isl_set *extract_implicit_condition(clang::Expr *expr);
150 __isl_give isl_set *extract_condition(clang::UnaryOperator *expr);
151 __isl_give isl_set *extract_condition(clang::Expr *expr);
152 __isl_give isl_set *extract_comparison(clang::BinaryOperator *expr);
153 __isl_give isl_set *extract_comparison(clang::BinaryOperatorKind op,
154 clang::Expr *LHS, clang::Expr *RHS, clang::Stmt *comp);
155 __isl_give isl_set *extract_boolean(clang::BinaryOperator *expr);
156 __isl_give isl_set *extract_boolean(clang::UnaryOperator *expr);
158 void unsupported(clang::Stmt *stmt);