3 #include <clang/Basic/SourceManager.h>
4 #include <clang/AST/Decl.h>
5 #include <clang/AST/Stmt.h>
6 #include <clang/Lex/Preprocessor.h>
14 /* The location of the scop, as delimited by scop and endscop
15 * pragmas by the user.
25 clang::Preprocessor
&PP
;
26 clang::ASTContext
&ast_context
;
27 /* If autodetect is false, then loc contains the location
28 * of the scop to be extracted.
33 /* The sequence number of the next statement. */
35 /* The sequence number of the next virtual scalar. */
37 /* Set if the pet_scop returned by an extract method only
38 * represents part of the input tree.
41 /* Set is nested accesses are allowed in general.
42 * This currently defaults to true.
45 /* Set if nested accesses are allowed in that part of the tree
46 * that is currently under investigation.
49 /* Maps identifiers to the last value that was assigned to them.
50 * If an identifier is mapped to NULL, then something may have
51 * been assigned, but we don't know what.
52 * assigned_value does not take a reference to the isl_pw_aff
53 * object, so each such isl_pw_aff needs to be stored in
54 * the set of "expressions".
56 std::map
<clang::ValueDecl
*, isl_pw_aff
*> assigned_value
;
57 /* A collection of isl_pw_affs used in assigned_value or other
58 * temporary maps. expressions holds a reference for each
59 * isl_pw_aff, which is freed in the destructor of PetScan.
61 std::set
<isl_pw_aff
*> expressions
;
63 /* A union of mappings of the form
64 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
66 isl_union_map
*value_bounds
;
68 PetScan(clang::Preprocessor
&PP
,
69 clang::ASTContext
&ast_context
, ScopLoc
&loc
,
70 pet_options
*options
, __isl_take isl_union_map
*value_bounds
) :
71 ctx(isl_union_map_get_ctx(value_bounds
)), PP(PP
),
72 ast_context(ast_context
), loc(loc
),
73 options(options
), value_bounds(value_bounds
),
74 n_stmt(0), n_test(0), partial(0), allow_nested(true),
75 nesting_enabled(false) { }
79 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
81 static __isl_give isl_val
*extract_int(isl_ctx
*ctx
,
82 clang::IntegerLiteral
*expr
);
83 static __isl_give isl_val
*extract_unsigned(isl_ctx
*ctx
,
84 const llvm::APInt
&val
);
86 void assign(struct pet_expr
*lhs
, clang::Expr
*rhs
);
88 __isl_give isl_pw_aff
*signed_overflow(__isl_take isl_pw_aff
*pa
,
90 void insert_expression(__isl_take isl_pw_aff
*expr
);
91 struct pet_scop
*scan(clang::Stmt
*stmt
);
93 struct pet_scop
*scan_arrays(struct pet_scop
*scop
);
94 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
);
95 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
96 const clang::Type
*type
, int pos
);
98 struct pet_scop
*extract_non_affine_condition(clang::Expr
*cond
,
99 __isl_take isl_multi_pw_aff
*index
);
101 struct pet_scop
*extract_conditional_assignment(clang::IfStmt
*stmt
);
102 struct pet_scop
*extract_non_affine_if(clang::Expr
*cond
,
103 struct pet_scop
*scop_then
, struct pet_scop
*scop_else
,
104 bool have_else
, int stmt_id
);
106 struct pet_scop
*kill(clang::Stmt
*stmt
, struct pet_array
*array
);
108 struct pet_scop
*extract(clang::Stmt
*stmt
,
109 bool skip_declarations
= false);
110 struct pet_scop
*extract(clang::StmtRange stmt_range
, bool block
,
111 bool skip_declarations
);
112 struct pet_scop
*extract(clang::IfStmt
*stmt
);
113 struct pet_scop
*extract(clang::WhileStmt
*stmt
);
114 struct pet_scop
*extract(clang::CompoundStmt
*stmt
,
115 bool skip_declarations
= false);
116 struct pet_scop
*extract(clang::LabelStmt
*stmt
);
117 struct pet_scop
*extract(clang::ContinueStmt
*stmt
);
118 struct pet_scop
*extract(clang::BreakStmt
*stmt
);
119 struct pet_scop
*extract(clang::DeclStmt
*expr
);
121 struct pet_scop
*extract(clang::Stmt
*stmt
, struct pet_expr
*expr
,
122 __isl_take isl_id
*label
= NULL
);
123 struct pet_stmt
*extract_kill(struct pet_scop
*scop
);
125 clang::BinaryOperator
*initialization_assignment(clang::Stmt
*init
);
126 clang::Decl
*initialization_declaration(clang::Stmt
*init
);
127 clang::ValueDecl
*extract_induction_variable(clang::BinaryOperator
*stmt
);
128 clang::VarDecl
*extract_induction_variable(clang::Stmt
*init
,
130 __isl_give isl_pw_aff
*extract_unary_increment(clang::UnaryOperator
*op
,
131 clang::ValueDecl
*iv
);
132 __isl_give isl_pw_aff
*extract_binary_increment(
133 clang::BinaryOperator
*op
,
134 clang::ValueDecl
*iv
);
135 __isl_give isl_pw_aff
*extract_compound_increment(
136 clang::CompoundAssignOperator
*op
,
137 clang::ValueDecl
*iv
);
138 __isl_give isl_pw_aff
*extract_increment(clang::ForStmt
*stmt
,
139 clang::ValueDecl
*iv
);
140 struct pet_scop
*extract_for(clang::ForStmt
*stmt
);
141 struct pet_scop
*extract_infinite_loop(clang::Stmt
*body
);
142 struct pet_scop
*extract_infinite_for(clang::ForStmt
*stmt
);
143 struct pet_scop
*extract_affine_while(__isl_take isl_pw_aff
*pa
,
146 void mark_write(struct pet_expr
*access
);
147 struct pet_expr
*extract_expr(clang::Expr
*expr
);
148 struct pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
149 struct pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
150 struct pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
151 struct pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
152 struct pet_expr
*extract_expr(clang::ParenExpr
*expr
);
153 struct pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
154 struct pet_expr
*extract_expr(clang::CallExpr
*expr
);
155 struct pet_expr
*extract_expr(clang::CStyleCastExpr
*expr
);
157 int extract_nested(__isl_keep isl_space
*space
,
158 int n_arg
, struct pet_expr
**args
,
159 std::map
<int,int> ¶m2pos
);
160 struct pet_expr
*extract_nested(struct pet_expr
*expr
, int n
,
161 std::map
<int,int> ¶m2pos
);
162 struct pet_stmt
*extract_nested(struct pet_stmt
*stmt
, int n
,
163 std::map
<int,int> ¶m2pos
);
164 struct pet_expr
*resolve_nested(struct pet_expr
*expr
);
165 struct pet_scop
*resolve_nested(struct pet_scop
*scop
);
166 struct pet_stmt
*resolve_nested(struct pet_stmt
*stmt
);
167 struct pet_expr
*extract_access_expr(clang::Expr
*expr
);
168 struct pet_expr
*extract_access_expr(clang::ValueDecl
*decl
);
170 __isl_give isl_multi_pw_aff
*extract_index(
171 clang::ArraySubscriptExpr
*expr
);
172 __isl_give isl_multi_pw_aff
*extract_index(clang::Expr
*expr
);
173 __isl_give isl_multi_pw_aff
*extract_index(
174 clang::ImplicitCastExpr
*expr
);
175 __isl_give isl_multi_pw_aff
*extract_index(clang::DeclRefExpr
*expr
);
176 __isl_give isl_multi_pw_aff
*extract_index(clang::ValueDecl
*decl
);
177 __isl_give isl_multi_pw_aff
*extract_index(
178 clang::IntegerLiteral
*expr
);
180 __isl_give isl_val
*extract_int(clang::Expr
*expr
);
181 __isl_give isl_val
*extract_int(clang::ParenExpr
*expr
);
183 __isl_give isl_pw_aff
*extract_affine_add(clang::BinaryOperator
*expr
);
184 __isl_give isl_pw_aff
*extract_affine_div(clang::BinaryOperator
*expr
);
185 __isl_give isl_pw_aff
*extract_affine_mod(clang::BinaryOperator
*expr
);
186 __isl_give isl_pw_aff
*extract_affine_mul(clang::BinaryOperator
*expr
);
188 isl_pw_aff
*nested_access(clang::Expr
*expr
);
190 __isl_give isl_pw_aff
*try_extract_affine(clang::Expr
*expr
);
191 bool is_affine(clang::Expr
*expr
);
192 __isl_give isl_pw_aff
*try_extract_affine_condition(clang::Expr
*expr
);
193 bool is_affine_condition(clang::Expr
*expr
);
194 __isl_give isl_pw_aff
*try_extract_nested_condition(clang::Expr
*expr
);
195 bool is_nested_allowed(__isl_keep isl_pw_aff
*pa
, pet_scop
*scop
);
197 __isl_give isl_pw_aff
*extract_affine(const llvm::APInt
&val
);
198 __isl_give isl_pw_aff
*extract_affine(clang::Expr
*expr
);
199 __isl_give isl_pw_aff
*extract_affine(clang::IntegerLiteral
*expr
);
200 __isl_give isl_pw_aff
*extract_affine(clang::ImplicitCastExpr
*expr
);
201 __isl_give isl_pw_aff
*extract_affine(clang::DeclRefExpr
*expr
);
202 __isl_give isl_pw_aff
*extract_affine(clang::BinaryOperator
*expr
);
203 __isl_give isl_pw_aff
*extract_affine(clang::UnaryOperator
*expr
);
204 __isl_give isl_pw_aff
*extract_affine(clang::ParenExpr
*expr
);
205 __isl_give isl_pw_aff
*extract_affine(clang::CallExpr
*expr
);
206 __isl_give isl_pw_aff
*extract_affine(clang::ArraySubscriptExpr
*expr
);
207 __isl_give isl_pw_aff
*extract_affine(clang::ConditionalOperator
*expr
);
209 __isl_give isl_pw_aff
*extract_implicit_condition(clang::Expr
*expr
);
211 __isl_give isl_pw_aff
*extract_condition(clang::UnaryOperator
*expr
);
212 __isl_give isl_pw_aff
*extract_condition(clang::Expr
*expr
);
213 __isl_give isl_pw_aff
*extract_comparison(clang::BinaryOperator
*expr
);
214 __isl_give isl_pw_aff
*extract_comparison(clang::BinaryOperatorKind op
,
215 clang::Expr
*LHS
, clang::Expr
*RHS
, clang::Stmt
*comp
);
216 __isl_give isl_pw_aff
*extract_boolean(clang::BinaryOperator
*expr
);
217 __isl_give isl_pw_aff
*extract_boolean(clang::UnaryOperator
*expr
);
219 void unsupported(clang::Stmt
*stmt
, const char *msg
= NULL
);