3 #include <clang/Basic/SourceManager.h>
4 #include <clang/AST/Decl.h>
5 #include <clang/AST/Stmt.h>
6 #include <clang/Lex/Preprocessor.h>
16 /* The location of the scop, as delimited by scop and endscop
17 * pragmas by the user.
26 /* Compare two RecordDecl pointers based on their names.
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
;
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.
49 /* The sequence number of the next statement. */
51 /* The sequence number of the next virtual scalar. */
53 /* Set if the pet_scop returned by an extract method only
54 * represents part of the input tree.
57 /* Set is nested accesses are allowed in general.
58 * This currently defaults to true.
61 /* Set if nested accesses are allowed in that part of the tree
62 * that is currently under investigation.
66 /* A union of mappings of the form
67 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
69 isl_union_map
*value_bounds
;
71 PetScan(clang::Preprocessor
&PP
,
72 clang::ASTContext
&ast_context
, ScopLoc
&loc
,
73 pet_options
*options
, __isl_take isl_union_map
*value_bounds
) :
74 ctx(isl_union_map_get_ctx(value_bounds
)), PP(PP
),
75 ast_context(ast_context
), loc(loc
),
76 options(options
), value_bounds(value_bounds
),
77 n_stmt(0), n_test(0), partial(0), allow_nested(true),
78 nesting_enabled(false) { }
82 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
84 static __isl_give isl_val
*extract_int(isl_ctx
*ctx
,
85 clang::IntegerLiteral
*expr
);
86 static __isl_give isl_val
*extract_unsigned(isl_ctx
*ctx
,
87 const llvm::APInt
&val
);
89 struct pet_scop
*scan(clang::Stmt
*stmt
, __isl_keep pet_context
*pc
);
91 struct pet_scop
*scan_arrays(struct pet_scop
*scop
,
92 __isl_keep pet_context
*pc
);
93 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
,
94 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
95 struct pet_array
*extract_array(isl_ctx
*ctx
,
96 std::vector
<clang::ValueDecl
*> decls
,
97 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
98 __isl_give pet_expr
*set_upper_bounds(__isl_take pet_expr
*expr
,
99 const clang::Type
*type
, int pos
);
100 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
101 const clang::Type
*type
, __isl_keep pet_context
*pc
);
103 struct pet_scop
*extract_non_affine_condition(clang::Expr
*cond
,
104 int stmt_nr
, __isl_take isl_multi_pw_aff
*index
,
105 __isl_keep pet_context
*pc
);
107 struct pet_scop
*extract_conditional_assignment(clang::IfStmt
*stmt
,
108 __isl_keep pet_context
*pc
);
109 struct pet_scop
*extract_non_affine_if(clang::Expr
*cond
,
110 struct pet_scop
*scop_then
, struct pet_scop
*scop_else
,
111 bool have_else
, int stmt_id
, __isl_keep pet_context
*pc
);
113 struct pet_scop
*kill(clang::Stmt
*stmt
, struct pet_array
*array
,
114 __isl_keep pet_context
*pc
);
116 struct pet_scop
*extract(clang::Stmt
*stmt
,
117 __isl_keep pet_context
*pc
, bool skip_declarations
= false);
118 struct pet_scop
*extract(clang::StmtRange stmt_range
, bool block
,
119 bool skip_declarations
, __isl_keep pet_context
*pc
);
120 struct pet_scop
*extract(clang::IfStmt
*stmt
,
121 __isl_keep pet_context
*pc
);
122 struct pet_scop
*extract(clang::WhileStmt
*stmt
,
123 __isl_keep pet_context
*pc
);
124 struct pet_scop
*extract(clang::CompoundStmt
*stmt
,
125 __isl_keep pet_context
*pc
, bool skip_declarations
= false);
126 struct pet_scop
*extract(clang::LabelStmt
*stmt
,
127 __isl_keep pet_context
*pc
);
128 struct pet_scop
*extract(clang::ContinueStmt
*stmt
);
129 struct pet_scop
*extract(clang::BreakStmt
*stmt
);
130 struct pet_scop
*extract(clang::DeclStmt
*expr
,
131 __isl_keep pet_context
*pc
);
133 __isl_give pet_loc
*construct_pet_loc(clang::SourceRange range
,
135 struct pet_scop
*extract(__isl_take pet_expr
*expr
,
136 clang::SourceRange range
, bool skip_semi
,
137 __isl_keep pet_context
*pc
, __isl_take isl_id
*label
= NULL
);
138 struct pet_stmt
*extract_kill(struct pet_scop
*scop
);
140 clang::BinaryOperator
*initialization_assignment(clang::Stmt
*init
);
141 clang::Decl
*initialization_declaration(clang::Stmt
*init
);
142 clang::ValueDecl
*extract_induction_variable(clang::BinaryOperator
*stmt
);
143 clang::VarDecl
*extract_induction_variable(clang::Stmt
*init
,
145 __isl_give pet_expr
*extract_unary_increment(clang::UnaryOperator
*op
,
146 clang::ValueDecl
*iv
);
147 __isl_give pet_expr
*extract_binary_increment(
148 clang::BinaryOperator
*op
,
149 clang::ValueDecl
*iv
);
150 __isl_give pet_expr
*extract_compound_increment(
151 clang::CompoundAssignOperator
*op
,
152 clang::ValueDecl
*iv
);
153 __isl_give pet_expr
*extract_increment(clang::ForStmt
*stmt
,
154 clang::ValueDecl
*iv
);
155 struct pet_scop
*extract_for(clang::ForStmt
*stmt
,
156 __isl_keep pet_context
*pc
);
157 struct pet_scop
*extract_non_affine_for(clang::ForStmt
*stmt
,
158 clang::ValueDecl
*iv
,
159 __isl_take pet_expr
*init
, __isl_take pet_expr
*inc
,
160 __isl_take pet_context
*pc
);
161 struct pet_scop
*extract_infinite_loop(clang::Stmt
*body
,
162 __isl_keep pet_context
*pc
);
163 struct pet_scop
*extract_infinite_for(clang::ForStmt
*stmt
,
164 __isl_keep pet_context
*pc
);
165 struct pet_scop
*extract_affine_while(__isl_take isl_pw_aff
*pa
,
166 clang::Stmt
*body
, __isl_take pet_context
*pc
);
167 struct pet_scop
*extract_while(clang::Expr
*cond
, int test_nr
,
168 int stmt_nr
, struct pet_scop
*scop_body
,
169 struct pet_scop
*scop_inc
, __isl_take pet_context
*pc
);
171 __isl_give pet_expr
*extract_assume(clang::Expr
*expr
);
172 __isl_give pet_expr
*extract_argument(clang::FunctionDecl
*fd
, int pos
,
174 __isl_give pet_expr
*extract_expr(const llvm::APInt
&val
);
175 __isl_give pet_expr
*extract_expr(clang::Expr
*expr
);
176 __isl_give pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
177 __isl_give pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
178 __isl_give pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
179 __isl_give pet_expr
*extract_expr(clang::IntegerLiteral
*expr
);
180 __isl_give pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
181 __isl_give pet_expr
*extract_expr(clang::ParenExpr
*expr
);
182 __isl_give pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
183 __isl_give pet_expr
*extract_expr(clang::CallExpr
*expr
);
184 __isl_give pet_expr
*extract_expr(clang::CStyleCastExpr
*expr
);
186 __isl_give pet_expr
*extract_access_expr(clang::QualType qt
,
187 __isl_take pet_expr
*index
);
188 __isl_give pet_expr
*extract_access_expr(clang::Expr
*expr
);
189 __isl_give pet_expr
*extract_access_expr(clang::ValueDecl
*decl
);
191 __isl_give pet_expr
*extract_index_expr(
192 clang::ArraySubscriptExpr
*expr
);
193 __isl_give pet_expr
*extract_index_expr(clang::Expr
*expr
);
194 __isl_give pet_expr
*extract_index_expr(clang::ImplicitCastExpr
*expr
);
195 __isl_give pet_expr
*extract_index_expr(clang::DeclRefExpr
*expr
);
196 __isl_give pet_expr
*extract_index_expr(clang::ValueDecl
*decl
);
197 __isl_give pet_expr
*extract_index_expr(clang::MemberExpr
*expr
);
199 __isl_give isl_val
*extract_int(clang::Expr
*expr
);
200 __isl_give isl_val
*extract_int(clang::ParenExpr
*expr
);
202 bool is_affine_condition(clang::Expr
*expr
, __isl_keep pet_context
*pc
);
203 __isl_give isl_pw_aff
*try_extract_nested_condition(clang::Expr
*expr
,
204 __isl_keep pet_context
*pc
);
205 bool is_nested_allowed(__isl_keep isl_pw_aff
*pa
, pet_scop
*scop
);
207 __isl_give isl_pw_aff
*extract_condition(clang::Expr
*expr
,
208 __isl_keep pet_context
*pc
);
210 void report(clang::Stmt
*stmt
, unsigned id
);
211 void unsupported(clang::Stmt
*stmt
);
212 void report_prototype_required(clang::Stmt
*stmt
);
213 void report_missing_increment(clang::Stmt
*stmt
);
215 __isl_give pet_context
*handle_writes(struct pet_stmt
*stmt
,
216 __isl_take pet_context
*pc
);
217 __isl_give pet_context
*handle_writes(struct pet_scop
*scop
,
218 __isl_take pet_context
*pc
);