introduce pet_tree objects
[pet.git] / scan.h
blob666a849722ea8ab8a5a08579005821ef5c7d16dd
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>
10 #include <isl/val.h>
12 #include "context.h"
13 #include "loc.h"
14 #include "scop.h"
16 /* The location of the scop, as delimited by scop and endscop
17 * pragmas by the user.
19 struct ScopLoc {
20 ScopLoc() : end(0) {}
22 unsigned start;
23 unsigned end;
26 /* Compare two RecordDecl pointers based on their names.
28 struct less_name {
29 bool operator()(const clang::RecordDecl *x,
30 const clang::RecordDecl *y) {
31 return x->getNameAsString().compare(y->getNameAsString()) < 0;
35 /* A sorted set of RecordDecl pointers. The actual order is not important,
36 * only that it is consistent across platforms.
38 typedef std::set<clang::RecordDecl *, less_name> lex_recorddecl_set;
40 struct PetScan {
41 clang::Preprocessor &PP;
42 clang::ASTContext &ast_context;
43 /* If autodetect is false, then loc contains the location
44 * of the scop to be extracted.
46 ScopLoc &loc;
47 isl_ctx *ctx;
48 pet_options *options;
49 /* The sequence number of the next statement. */
50 int n_stmt;
51 /* The sequence number of the next virtual scalar. */
52 int n_test;
53 /* Set if the pet_scop returned by an extract method only
54 * represents part of the input tree.
56 bool partial;
57 /* Set if nested accesses are allowed in that part of the tree
58 * that is currently under investigation.
60 bool nesting_enabled;
62 /* A union of mappings of the form
63 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
65 isl_union_map *value_bounds;
67 PetScan(clang::Preprocessor &PP,
68 clang::ASTContext &ast_context, ScopLoc &loc,
69 pet_options *options, __isl_take isl_union_map *value_bounds) :
70 ctx(isl_union_map_get_ctx(value_bounds)), PP(PP),
71 ast_context(ast_context), loc(loc),
72 options(options), value_bounds(value_bounds),
73 n_stmt(0), n_test(0), partial(0), nesting_enabled(false) { }
75 ~PetScan();
77 struct pet_scop *scan(clang::FunctionDecl *fd);
79 static __isl_give isl_val *extract_int(isl_ctx *ctx,
80 clang::IntegerLiteral *expr);
81 static __isl_give isl_val *extract_unsigned(isl_ctx *ctx,
82 const llvm::APInt &val);
83 private:
84 struct pet_scop *scan(clang::Stmt *stmt, __isl_keep pet_context *pc);
86 struct pet_scop *scan_arrays(struct pet_scop *scop,
87 __isl_keep pet_context *pc);
88 struct pet_array *extract_array(isl_ctx *ctx, clang::ValueDecl *decl,
89 lex_recorddecl_set *types, __isl_keep pet_context *pc);
90 struct pet_array *extract_array(isl_ctx *ctx,
91 std::vector<clang::ValueDecl *> decls,
92 lex_recorddecl_set *types, __isl_keep pet_context *pc);
93 __isl_give pet_expr *set_upper_bounds(__isl_take pet_expr *expr,
94 const clang::Type *type, int pos);
95 struct pet_array *set_upper_bounds(struct pet_array *array,
96 const clang::Type *type, __isl_keep pet_context *pc);
98 struct pet_scop *extract_non_affine_condition(clang::Expr *cond,
99 int stmt_nr, __isl_take isl_multi_pw_aff *index,
100 __isl_keep pet_context *pc);
102 struct pet_scop *extract_conditional_assignment(clang::IfStmt *stmt,
103 __isl_keep pet_context *pc);
104 struct pet_scop *extract_non_affine_if(clang::Expr *cond,
105 struct pet_scop *scop_then, struct pet_scop *scop_else,
106 bool have_else, int stmt_id, __isl_keep pet_context *pc);
108 struct pet_scop *kill(clang::Stmt *stmt, struct pet_array *array,
109 __isl_keep pet_context *pc);
111 struct pet_scop *extract(clang::Stmt *stmt,
112 __isl_keep pet_context *pc, bool skip_declarations = false);
113 struct pet_scop *extract(clang::StmtRange stmt_range, bool block,
114 bool skip_declarations, __isl_keep pet_context *pc);
115 struct pet_scop *extract(clang::IfStmt *stmt,
116 __isl_keep pet_context *pc);
117 struct pet_scop *extract(clang::WhileStmt *stmt,
118 __isl_keep pet_context *pc);
119 struct pet_scop *extract(clang::CompoundStmt *stmt,
120 __isl_keep pet_context *pc, bool skip_declarations = false);
121 struct pet_scop *extract(clang::LabelStmt *stmt,
122 __isl_keep pet_context *pc);
123 struct pet_scop *extract(clang::ContinueStmt *stmt);
124 struct pet_scop *extract(clang::BreakStmt *stmt);
125 struct pet_scop *extract(clang::DeclStmt *expr,
126 __isl_keep pet_context *pc);
128 __isl_give pet_loc *construct_pet_loc(clang::SourceRange range,
129 bool skip_semi);
130 struct pet_scop *extract(__isl_take pet_expr *expr,
131 clang::SourceRange range, bool skip_semi,
132 __isl_keep pet_context *pc, __isl_take isl_id *label = NULL);
133 struct pet_stmt *extract_kill(struct pet_scop *scop);
135 clang::BinaryOperator *initialization_assignment(clang::Stmt *init);
136 clang::Decl *initialization_declaration(clang::Stmt *init);
137 clang::ValueDecl *extract_induction_variable(clang::BinaryOperator *stmt);
138 clang::VarDecl *extract_induction_variable(clang::Stmt *init,
139 clang::Decl *stmt);
140 __isl_give pet_expr *extract_unary_increment(clang::UnaryOperator *op,
141 clang::ValueDecl *iv);
142 __isl_give pet_expr *extract_binary_increment(
143 clang::BinaryOperator *op,
144 clang::ValueDecl *iv);
145 __isl_give pet_expr *extract_compound_increment(
146 clang::CompoundAssignOperator *op,
147 clang::ValueDecl *iv);
148 __isl_give pet_expr *extract_increment(clang::ForStmt *stmt,
149 clang::ValueDecl *iv);
150 struct pet_scop *extract_for(clang::ForStmt *stmt,
151 __isl_keep pet_context *pc);
152 struct pet_scop *extract_non_affine_for(clang::ForStmt *stmt,
153 clang::ValueDecl *iv,
154 __isl_take pet_expr *init, __isl_take pet_expr *inc,
155 __isl_take pet_context *pc);
156 struct pet_scop *extract_infinite_loop(clang::Stmt *body,
157 __isl_keep pet_context *pc);
158 struct pet_scop *extract_infinite_for(clang::ForStmt *stmt,
159 __isl_keep pet_context *pc);
160 struct pet_scop *extract_affine_while(__isl_take isl_pw_aff *pa,
161 clang::Stmt *body, __isl_take pet_context *pc);
162 struct pet_scop *extract_while(clang::Expr *cond, int test_nr,
163 int stmt_nr, struct pet_scop *scop_body,
164 struct pet_scop *scop_inc, __isl_take pet_context *pc);
166 __isl_give pet_expr *extract_assume(clang::Expr *expr);
167 __isl_give pet_expr *extract_argument(clang::FunctionDecl *fd, int pos,
168 clang::Expr *expr);
169 __isl_give pet_expr *extract_expr(const llvm::APInt &val);
170 __isl_give pet_expr *extract_expr(clang::Expr *expr);
171 __isl_give pet_expr *extract_expr(clang::UnaryOperator *expr);
172 __isl_give pet_expr *extract_expr(clang::BinaryOperator *expr);
173 __isl_give pet_expr *extract_expr(clang::ImplicitCastExpr *expr);
174 __isl_give pet_expr *extract_expr(clang::IntegerLiteral *expr);
175 __isl_give pet_expr *extract_expr(clang::FloatingLiteral *expr);
176 __isl_give pet_expr *extract_expr(clang::ParenExpr *expr);
177 __isl_give pet_expr *extract_expr(clang::ConditionalOperator *expr);
178 __isl_give pet_expr *extract_expr(clang::CallExpr *expr);
179 __isl_give pet_expr *extract_expr(clang::CStyleCastExpr *expr);
181 __isl_give pet_expr *extract_access_expr(clang::QualType qt,
182 __isl_take pet_expr *index);
183 __isl_give pet_expr *extract_access_expr(clang::Expr *expr);
184 __isl_give pet_expr *extract_access_expr(clang::ValueDecl *decl);
186 __isl_give pet_expr *extract_index_expr(
187 clang::ArraySubscriptExpr *expr);
188 __isl_give pet_expr *extract_index_expr(clang::Expr *expr);
189 __isl_give pet_expr *extract_index_expr(clang::ImplicitCastExpr *expr);
190 __isl_give pet_expr *extract_index_expr(clang::DeclRefExpr *expr);
191 __isl_give pet_expr *extract_index_expr(clang::ValueDecl *decl);
192 __isl_give pet_expr *extract_index_expr(clang::MemberExpr *expr);
194 __isl_give isl_val *extract_int(clang::Expr *expr);
195 __isl_give isl_val *extract_int(clang::ParenExpr *expr);
197 bool is_affine_condition(clang::Expr *expr, __isl_keep pet_context *pc);
198 __isl_give isl_pw_aff *try_extract_nested_condition(clang::Expr *expr,
199 __isl_keep pet_context *pc);
200 bool is_nested_allowed(__isl_keep isl_pw_aff *pa, pet_scop *scop);
202 __isl_give isl_pw_aff *extract_condition(clang::Expr *expr,
203 __isl_keep pet_context *pc);
205 void report(clang::Stmt *stmt, unsigned id);
206 void unsupported(clang::Stmt *stmt);
207 void report_prototype_required(clang::Stmt *stmt);
208 void report_missing_increment(clang::Stmt *stmt);
210 __isl_give pet_context *handle_writes(struct pet_stmt *stmt,
211 __isl_take pet_context *pc);
212 __isl_give pet_context *handle_writes(struct pet_scop *scop,
213 __isl_take pet_context *pc);