pet_context_evaluate_expr: also plug in affine expressions for scalar reads
[pet.git] / scan.h
blob22496e6495a6eae420544fc3f3c32c92c4683bca
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"
15 #include "tree.h"
17 /* The location of the scop, as delimited by scop and endscop
18 * pragmas by the user.
20 struct ScopLoc {
21 ScopLoc() : end(0) {}
23 unsigned start;
24 unsigned end;
27 /* Compare two RecordDecl pointers based on their names.
29 struct less_name {
30 bool operator()(const clang::RecordDecl *x,
31 const clang::RecordDecl *y) {
32 return x->getNameAsString().compare(y->getNameAsString()) < 0;
36 /* A sorted set of RecordDecl pointers. The actual order is not important,
37 * only that it is consistent across platforms.
39 typedef std::set<clang::RecordDecl *, less_name> lex_recorddecl_set;
41 struct PetScan {
42 clang::Preprocessor &PP;
43 clang::ASTContext &ast_context;
44 /* If autodetect is false, then loc contains the location
45 * of the scop to be extracted.
47 ScopLoc &loc;
48 isl_ctx *ctx;
49 pet_options *options;
50 /* Set if the pet_scop returned by an extract method only
51 * represents part of the input tree.
53 bool partial;
55 /* A union of mappings of the form
56 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
58 isl_union_map *value_bounds;
60 PetScan(clang::Preprocessor &PP,
61 clang::ASTContext &ast_context, ScopLoc &loc,
62 pet_options *options, __isl_take isl_union_map *value_bounds) :
63 ctx(isl_union_map_get_ctx(value_bounds)), PP(PP),
64 ast_context(ast_context), loc(loc),
65 options(options), value_bounds(value_bounds),
66 partial(false) { }
68 ~PetScan();
70 struct pet_scop *scan(clang::FunctionDecl *fd);
72 static __isl_give isl_val *extract_int(isl_ctx *ctx,
73 clang::IntegerLiteral *expr);
74 static __isl_give isl_val *extract_unsigned(isl_ctx *ctx,
75 const llvm::APInt &val);
76 struct pet_array *extract_array(isl_ctx *ctx, clang::ValueDecl *decl,
77 lex_recorddecl_set *types, __isl_keep pet_context *pc);
78 private:
79 struct pet_scop *scan(clang::Stmt *stmt);
81 struct pet_scop *scan_arrays(struct pet_scop *scop,
82 __isl_keep pet_context *pc);
83 struct pet_array *extract_array(isl_ctx *ctx,
84 std::vector<clang::ValueDecl *> decls,
85 lex_recorddecl_set *types, __isl_keep pet_context *pc);
86 __isl_give pet_expr *set_upper_bounds(__isl_take pet_expr *expr,
87 const clang::Type *type, int pos);
88 struct pet_array *set_upper_bounds(struct pet_array *array,
89 const clang::Type *type, __isl_keep pet_context *pc);
91 __isl_give pet_tree *extract(clang::Stmt *stmt,
92 bool skip_declarations = false);
93 __isl_give pet_tree *extract(clang::StmtRange stmt_range, bool block,
94 bool skip_declarations);
95 __isl_give pet_tree *extract(clang::IfStmt *stmt);
96 __isl_give pet_tree *extract(clang::WhileStmt *stmt);
97 __isl_give pet_tree *extract(clang::CompoundStmt *stmt,
98 bool skip_declarations = false);
99 __isl_give pet_tree *extract(clang::LabelStmt *stmt);
100 __isl_give pet_tree *extract(clang::DeclStmt *expr);
102 __isl_give pet_loc *construct_pet_loc(clang::SourceRange range,
103 bool skip_semi);
104 __isl_give pet_tree *extract(__isl_take pet_expr *expr,
105 clang::SourceRange range, bool skip_semi);
106 __isl_give pet_tree *update_loc(__isl_take pet_tree *tree,
107 clang::Stmt *stmt);
109 struct pet_scop *extract_scop(__isl_take pet_tree *tree);
111 clang::BinaryOperator *initialization_assignment(clang::Stmt *init);
112 clang::Decl *initialization_declaration(clang::Stmt *init);
113 clang::ValueDecl *extract_induction_variable(clang::BinaryOperator *stmt);
114 clang::VarDecl *extract_induction_variable(clang::Stmt *init,
115 clang::Decl *stmt);
116 __isl_give pet_expr *extract_unary_increment(clang::UnaryOperator *op,
117 clang::ValueDecl *iv);
118 __isl_give pet_expr *extract_binary_increment(
119 clang::BinaryOperator *op,
120 clang::ValueDecl *iv);
121 __isl_give pet_expr *extract_compound_increment(
122 clang::CompoundAssignOperator *op,
123 clang::ValueDecl *iv);
124 __isl_give pet_expr *extract_increment(clang::ForStmt *stmt,
125 clang::ValueDecl *iv);
126 __isl_give pet_tree *extract_for(clang::ForStmt *stmt);
128 __isl_give pet_expr *extract_assume(clang::Expr *expr);
129 __isl_give pet_expr *extract_argument(clang::FunctionDecl *fd, int pos,
130 clang::Expr *expr);
131 __isl_give pet_expr *extract_expr(const llvm::APInt &val);
132 __isl_give pet_expr *extract_expr(clang::Expr *expr);
133 __isl_give pet_expr *extract_expr(clang::UnaryOperator *expr);
134 __isl_give pet_expr *extract_expr(clang::BinaryOperator *expr);
135 __isl_give pet_expr *extract_expr(clang::ImplicitCastExpr *expr);
136 __isl_give pet_expr *extract_expr(clang::IntegerLiteral *expr);
137 __isl_give pet_expr *extract_expr(clang::FloatingLiteral *expr);
138 __isl_give pet_expr *extract_expr(clang::ParenExpr *expr);
139 __isl_give pet_expr *extract_expr(clang::ConditionalOperator *expr);
140 __isl_give pet_expr *extract_expr(clang::CallExpr *expr);
141 __isl_give pet_expr *extract_expr(clang::CStyleCastExpr *expr);
143 __isl_give pet_expr *extract_access_expr(clang::QualType qt,
144 __isl_take pet_expr *index);
145 __isl_give pet_expr *extract_access_expr(clang::Expr *expr);
146 __isl_give pet_expr *extract_access_expr(clang::ValueDecl *decl);
148 __isl_give pet_expr *extract_index_expr(
149 clang::ArraySubscriptExpr *expr);
150 __isl_give pet_expr *extract_index_expr(clang::Expr *expr);
151 __isl_give pet_expr *extract_index_expr(clang::ImplicitCastExpr *expr);
152 __isl_give pet_expr *extract_index_expr(clang::DeclRefExpr *expr);
153 __isl_give pet_expr *extract_index_expr(clang::ValueDecl *decl);
154 __isl_give pet_expr *extract_index_expr(clang::MemberExpr *expr);
156 __isl_give isl_val *extract_int(clang::Expr *expr);
157 __isl_give isl_val *extract_int(clang::ParenExpr *expr);
159 void report(clang::Stmt *stmt, unsigned id);
160 void unsupported(clang::Stmt *stmt);
161 void report_prototype_required(clang::Stmt *stmt);
162 void report_missing_increment(clang::Stmt *stmt);