3 #include <clang/Basic/SourceManager.h>
4 #include <clang/AST/Decl.h>
5 #include <clang/AST/Stmt.h>
6 #include <clang/Lex/Preprocessor.h>
15 /* The location of the scop, as delimited by scop and endscop
16 * pragmas by the user.
25 /* Compare two RecordDecl pointers based on their names.
28 bool operator()(const clang::RecordDecl
*x
,
29 const clang::RecordDecl
*y
) {
30 return x
->getNameAsString().compare(y
->getNameAsString()) < 0;
34 /* A sorted set of RecordDecl pointers. The actual order is not important,
35 * only that it is consistent across platforms.
37 typedef std::set
<clang::RecordDecl
*, less_name
> lex_recorddecl_set
;
40 clang::Preprocessor
&PP
;
41 clang::ASTContext
&ast_context
;
42 /* If autodetect is false, then loc contains the location
43 * of the scop to be extracted.
48 /* The sequence number of the next statement. */
50 /* The sequence number of the next virtual scalar. */
52 /* Set if the pet_scop returned by an extract method only
53 * represents part of the input tree.
56 /* Set is nested accesses are allowed in general.
57 * This currently defaults to true.
60 /* Set if nested accesses are allowed in that part of the tree
61 * that is currently under investigation.
65 /* A union of mappings of the form
66 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
68 isl_union_map
*value_bounds
;
70 PetScan(clang::Preprocessor
&PP
,
71 clang::ASTContext
&ast_context
, ScopLoc
&loc
,
72 pet_options
*options
, __isl_take isl_union_map
*value_bounds
) :
73 ctx(isl_union_map_get_ctx(value_bounds
)), PP(PP
),
74 ast_context(ast_context
), loc(loc
),
75 options(options
), value_bounds(value_bounds
),
76 n_stmt(0), n_test(0), partial(0), allow_nested(true),
77 nesting_enabled(false) { }
81 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
83 static __isl_give isl_val
*extract_int(isl_ctx
*ctx
,
84 clang::IntegerLiteral
*expr
);
85 static __isl_give isl_val
*extract_unsigned(isl_ctx
*ctx
,
86 const llvm::APInt
&val
);
88 struct pet_scop
*scan(clang::Stmt
*stmt
, __isl_keep pet_context
*pc
);
90 struct pet_scop
*scan_arrays(struct pet_scop
*scop
,
91 __isl_keep pet_context
*pc
);
92 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
,
93 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
94 struct pet_array
*extract_array(isl_ctx
*ctx
,
95 std::vector
<clang::ValueDecl
*> decls
,
96 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
97 __isl_give pet_expr
*set_upper_bounds(__isl_take pet_expr
*expr
,
98 const clang::Type
*type
, int pos
);
99 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
100 const clang::Type
*type
, __isl_keep pet_context
*pc
);
102 struct pet_scop
*extract_non_affine_condition(clang::Expr
*cond
,
103 int stmt_nr
, __isl_take isl_multi_pw_aff
*index
,
104 __isl_keep pet_context
*pc
);
106 struct pet_scop
*extract_conditional_assignment(clang::IfStmt
*stmt
,
107 __isl_keep pet_context
*pc
);
108 struct pet_scop
*extract_non_affine_if(clang::Expr
*cond
,
109 struct pet_scop
*scop_then
, struct pet_scop
*scop_else
,
110 bool have_else
, int stmt_id
, __isl_keep pet_context
*pc
);
112 struct pet_scop
*kill(clang::Stmt
*stmt
, struct pet_array
*array
,
113 __isl_keep pet_context
*pc
);
115 struct pet_scop
*extract(clang::Stmt
*stmt
,
116 __isl_keep pet_context
*pc
, bool skip_declarations
= false);
117 struct pet_scop
*extract(clang::StmtRange stmt_range
, bool block
,
118 bool skip_declarations
, __isl_keep pet_context
*pc
);
119 struct pet_scop
*extract(clang::IfStmt
*stmt
,
120 __isl_keep pet_context
*pc
);
121 struct pet_scop
*extract(clang::WhileStmt
*stmt
,
122 __isl_keep pet_context
*pc
);
123 struct pet_scop
*extract(clang::CompoundStmt
*stmt
,
124 __isl_keep pet_context
*pc
, bool skip_declarations
= false);
125 struct pet_scop
*extract(clang::LabelStmt
*stmt
,
126 __isl_keep pet_context
*pc
);
127 struct pet_scop
*extract(clang::ContinueStmt
*stmt
);
128 struct pet_scop
*extract(clang::BreakStmt
*stmt
);
129 struct pet_scop
*extract(clang::DeclStmt
*expr
,
130 __isl_keep pet_context
*pc
);
132 struct pet_scop
*update_scop_start_end(struct pet_scop
*scop
,
133 clang::SourceRange range
, bool skip_semi
);
134 struct pet_scop
*extract(__isl_take pet_expr
*expr
,
135 clang::SourceRange range
, bool skip_semi
,
136 __isl_keep pet_context
*pc
, __isl_take isl_id
*label
= NULL
);
137 struct pet_stmt
*extract_kill(struct pet_scop
*scop
);
139 clang::BinaryOperator
*initialization_assignment(clang::Stmt
*init
);
140 clang::Decl
*initialization_declaration(clang::Stmt
*init
);
141 clang::ValueDecl
*extract_induction_variable(clang::BinaryOperator
*stmt
);
142 clang::VarDecl
*extract_induction_variable(clang::Stmt
*init
,
144 __isl_give pet_expr
*extract_unary_increment(clang::UnaryOperator
*op
,
145 clang::ValueDecl
*iv
);
146 __isl_give pet_expr
*extract_binary_increment(
147 clang::BinaryOperator
*op
,
148 clang::ValueDecl
*iv
);
149 __isl_give pet_expr
*extract_compound_increment(
150 clang::CompoundAssignOperator
*op
,
151 clang::ValueDecl
*iv
);
152 __isl_give pet_expr
*extract_increment(clang::ForStmt
*stmt
,
153 clang::ValueDecl
*iv
);
154 struct pet_scop
*extract_for(clang::ForStmt
*stmt
,
155 __isl_keep pet_context
*pc
);
156 struct pet_scop
*extract_non_affine_for(clang::ForStmt
*stmt
,
157 clang::ValueDecl
*iv
,
158 __isl_take pet_expr
*init
, __isl_take pet_expr
*inc
,
159 __isl_take pet_context
*pc
);
160 struct pet_scop
*extract_infinite_loop(clang::Stmt
*body
,
161 __isl_keep pet_context
*pc
);
162 struct pet_scop
*extract_infinite_for(clang::ForStmt
*stmt
,
163 __isl_keep pet_context
*pc
);
164 struct pet_scop
*extract_affine_while(__isl_take isl_pw_aff
*pa
,
165 clang::Stmt
*body
, __isl_take pet_context
*pc
);
166 struct pet_scop
*extract_while(clang::Expr
*cond
, int test_nr
,
167 int stmt_nr
, struct pet_scop
*scop_body
,
168 struct pet_scop
*scop_inc
, __isl_take pet_context
*pc
);
170 __isl_give pet_expr
*extract_assume(clang::Expr
*expr
);
171 __isl_give pet_expr
*extract_argument(clang::FunctionDecl
*fd
, int pos
,
173 __isl_give pet_expr
*extract_expr(const llvm::APInt
&val
);
174 __isl_give pet_expr
*extract_expr(clang::Expr
*expr
);
175 __isl_give pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
176 __isl_give pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
177 __isl_give pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
178 __isl_give pet_expr
*extract_expr(clang::IntegerLiteral
*expr
);
179 __isl_give pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
180 __isl_give pet_expr
*extract_expr(clang::ParenExpr
*expr
);
181 __isl_give pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
182 __isl_give pet_expr
*extract_expr(clang::CallExpr
*expr
);
183 __isl_give pet_expr
*extract_expr(clang::CStyleCastExpr
*expr
);
185 __isl_give pet_expr
*extract_access_expr(clang::QualType qt
,
186 __isl_take pet_expr
*index
);
187 __isl_give pet_expr
*extract_access_expr(clang::Expr
*expr
);
188 __isl_give pet_expr
*extract_access_expr(clang::ValueDecl
*decl
);
190 __isl_give pet_expr
*extract_index_expr(
191 clang::ArraySubscriptExpr
*expr
);
192 __isl_give pet_expr
*extract_index_expr(clang::Expr
*expr
);
193 __isl_give pet_expr
*extract_index_expr(clang::ImplicitCastExpr
*expr
);
194 __isl_give pet_expr
*extract_index_expr(clang::DeclRefExpr
*expr
);
195 __isl_give pet_expr
*extract_index_expr(clang::ValueDecl
*decl
);
196 __isl_give pet_expr
*extract_index_expr(clang::MemberExpr
*expr
);
198 __isl_give isl_val
*extract_int(clang::Expr
*expr
);
199 __isl_give isl_val
*extract_int(clang::ParenExpr
*expr
);
201 bool is_affine_condition(clang::Expr
*expr
, __isl_keep pet_context
*pc
);
202 __isl_give isl_pw_aff
*try_extract_nested_condition(clang::Expr
*expr
,
203 __isl_keep pet_context
*pc
);
204 bool is_nested_allowed(__isl_keep isl_pw_aff
*pa
, pet_scop
*scop
);
206 __isl_give isl_pw_aff
*extract_condition(clang::Expr
*expr
,
207 __isl_keep pet_context
*pc
);
209 void report(clang::Stmt
*stmt
, unsigned id
);
210 void unsupported(clang::Stmt
*stmt
);
211 void report_prototype_required(clang::Stmt
*stmt
);
212 void report_missing_increment(clang::Stmt
*stmt
);
214 __isl_give pet_context
*handle_writes(struct pet_stmt
*stmt
,
215 __isl_take pet_context
*pc
);
216 __isl_give pet_context
*handle_writes(struct pet_scop
*scop
,
217 __isl_take pet_context
*pc
);