3 #include <clang/Basic/SourceManager.h>
4 #include <clang/AST/Decl.h>
5 #include <clang/AST/Stmt.h>
6 #include <clang/Lex/Preprocessor.h>
13 /* The location of the scop, as delimited by scop and endscop
14 * pragmas by the user.
24 clang::Preprocessor
&PP
;
25 clang::ASTContext
&ast_context
;
26 /* If autodetect is false, then loc contains the location
27 * of the scop to be extracted.
32 /* The sequence number of the next statement. */
34 /* The sequence number of the next virtual scalar. */
36 /* Set if the pet_scop returned by an extract method only
37 * represents part of the input tree.
40 /* Set is nested accesses are allowed in general.
41 * This currently defaults to true.
44 /* Set if nested accesses are allowed in that part of the tree
45 * that is currently under investigation.
48 /* Maps identifiers to the last value that was assigned to them.
49 * If an identifier is mapped to NULL, then something may have
50 * been assigned, but we don't know what.
51 * assigned_value does not take a reference to the isl_pw_aff
52 * object, so each such isl_pw_aff needs to be stored in
53 * the set of "expressions".
55 std::map
<clang::ValueDecl
*, isl_pw_aff
*> assigned_value
;
56 /* A collection of isl_pw_affs used in assigned_value or other
57 * temporary maps. expressions holds a reference for each
58 * isl_pw_aff, which is freed in the destructor of PetScan.
60 std::set
<isl_pw_aff
*> expressions
;
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), allow_nested(true),
74 nesting_enabled(false) { }
78 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
80 static int extract_int(clang::IntegerLiteral
*expr
, isl_int
*v
);
82 __isl_give isl_pw_aff
*signed_overflow(__isl_take isl_pw_aff
*pa
,
84 void insert_expression(__isl_take isl_pw_aff
*expr
);
85 struct pet_scop
*scan(clang::Stmt
*stmt
);
87 struct pet_scop
*scan_arrays(struct pet_scop
*scop
);
88 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
);
89 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
90 const clang::Type
*type
, int pos
);
92 struct pet_scop
*extract_non_affine_condition(clang::Expr
*cond
,
93 __isl_take isl_map
*access
);
95 struct pet_scop
*extract_conditional_assignment(clang::IfStmt
*stmt
);
96 struct pet_scop
*extract_non_affine_if(clang::Expr
*cond
,
97 struct pet_scop
*scop_then
, struct pet_scop
*scop_else
,
98 bool have_else
, int stmt_id
);
100 struct pet_scop
*extract(clang::Stmt
*stmt
);
101 struct pet_scop
*extract(clang::StmtRange stmt_range
);
102 struct pet_scop
*extract(clang::IfStmt
*stmt
);
103 struct pet_scop
*extract(clang::WhileStmt
*stmt
);
104 struct pet_scop
*extract(clang::CompoundStmt
*stmt
);
105 struct pet_scop
*extract(clang::LabelStmt
*stmt
);
106 struct pet_scop
*extract(clang::ContinueStmt
*stmt
);
107 struct pet_scop
*extract(clang::BreakStmt
*stmt
);
109 struct pet_scop
*extract(clang::Stmt
*stmt
, struct pet_expr
*expr
,
110 __isl_take isl_id
*label
= NULL
);
112 clang::BinaryOperator
*initialization_assignment(clang::Stmt
*init
);
113 clang::Decl
*initialization_declaration(clang::Stmt
*init
);
114 clang::ValueDecl
*extract_induction_variable(clang::BinaryOperator
*stmt
);
115 clang::VarDecl
*extract_induction_variable(clang::Stmt
*init
,
117 __isl_give isl_pw_aff
*extract_unary_increment(clang::UnaryOperator
*op
,
118 clang::ValueDecl
*iv
);
119 __isl_give isl_pw_aff
*extract_binary_increment(
120 clang::BinaryOperator
*op
,
121 clang::ValueDecl
*iv
);
122 __isl_give isl_pw_aff
*extract_compound_increment(
123 clang::CompoundAssignOperator
*op
,
124 clang::ValueDecl
*iv
);
125 __isl_give isl_pw_aff
*extract_increment(clang::ForStmt
*stmt
,
126 clang::ValueDecl
*iv
);
127 struct pet_scop
*extract_for(clang::ForStmt
*stmt
);
128 struct pet_scop
*extract_infinite_loop(clang::Stmt
*body
);
129 struct pet_scop
*extract_infinite_for(clang::ForStmt
*stmt
);
130 struct pet_scop
*extract_affine_while(__isl_take isl_pw_aff
*pa
,
133 void mark_write(struct pet_expr
*access
);
134 struct pet_expr
*extract_expr(clang::Expr
*expr
);
135 struct pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
136 struct pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
137 struct pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
138 struct pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
139 struct pet_expr
*extract_expr(clang::ParenExpr
*expr
);
140 struct pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
141 struct pet_expr
*extract_expr(clang::CallExpr
*expr
);
143 int extract_nested(__isl_keep isl_space
*space
,
144 int n_arg
, struct pet_expr
**args
,
145 std::map
<int,int> ¶m2pos
);
146 struct pet_expr
*extract_nested(struct pet_expr
*expr
, int n
,
147 std::map
<int,int> ¶m2pos
);
148 struct pet_stmt
*extract_nested(struct pet_stmt
*stmt
, int n
,
149 std::map
<int,int> ¶m2pos
);
150 struct pet_expr
*resolve_nested(struct pet_expr
*expr
);
151 struct pet_scop
*resolve_nested(struct pet_scop
*scop
);
152 struct pet_stmt
*resolve_nested(struct pet_stmt
*stmt
);
153 struct pet_expr
*extract_access_expr(clang::Expr
*expr
);
155 __isl_give isl_map
*extract_access(clang::ArraySubscriptExpr
*expr
);
156 __isl_give isl_map
*extract_access(clang::Expr
*expr
);
157 __isl_give isl_map
*extract_access(clang::ImplicitCastExpr
*expr
);
158 __isl_give isl_map
*extract_access(clang::DeclRefExpr
*expr
);
159 __isl_give isl_map
*extract_access(clang::IntegerLiteral
*expr
);
161 int extract_int(clang::Expr
*expr
, isl_int
*v
);
162 int extract_int(clang::ParenExpr
*expr
, isl_int
*v
);
164 __isl_give isl_pw_aff
*extract_affine_add(clang::BinaryOperator
*expr
);
165 __isl_give isl_pw_aff
*extract_affine_div(clang::BinaryOperator
*expr
);
166 __isl_give isl_pw_aff
*extract_affine_mod(clang::BinaryOperator
*expr
);
167 __isl_give isl_pw_aff
*extract_affine_mul(clang::BinaryOperator
*expr
);
169 isl_pw_aff
*nested_access(clang::Expr
*expr
);
171 __isl_give isl_pw_aff
*try_extract_affine(clang::Expr
*expr
);
172 bool is_affine(clang::Expr
*expr
);
173 __isl_give isl_pw_aff
*try_extract_affine_condition(clang::Expr
*expr
);
174 bool is_affine_condition(clang::Expr
*expr
);
175 __isl_give isl_pw_aff
*try_extract_nested_condition(clang::Expr
*expr
);
176 bool is_nested_allowed(__isl_keep isl_pw_aff
*pa
, pet_scop
*scop
);
178 __isl_give isl_pw_aff
*extract_affine(const llvm::APInt
&val
);
179 __isl_give isl_pw_aff
*extract_affine(clang::Expr
*expr
);
180 __isl_give isl_pw_aff
*extract_affine(clang::IntegerLiteral
*expr
);
181 __isl_give isl_pw_aff
*extract_affine(clang::ImplicitCastExpr
*expr
);
182 __isl_give isl_pw_aff
*extract_affine(clang::DeclRefExpr
*expr
);
183 __isl_give isl_pw_aff
*extract_affine(clang::BinaryOperator
*expr
);
184 __isl_give isl_pw_aff
*extract_affine(clang::UnaryOperator
*expr
);
185 __isl_give isl_pw_aff
*extract_affine(clang::ParenExpr
*expr
);
186 __isl_give isl_pw_aff
*extract_affine(clang::CallExpr
*expr
);
187 __isl_give isl_pw_aff
*extract_affine(clang::ArraySubscriptExpr
*expr
);
188 __isl_give isl_pw_aff
*extract_affine(clang::ConditionalOperator
*expr
);
190 __isl_give isl_pw_aff
*extract_implicit_condition(clang::Expr
*expr
);
192 __isl_give isl_pw_aff
*extract_condition(clang::UnaryOperator
*expr
);
193 __isl_give isl_pw_aff
*extract_condition(clang::Expr
*expr
);
194 __isl_give isl_pw_aff
*extract_comparison(clang::BinaryOperator
*expr
);
195 __isl_give isl_pw_aff
*extract_comparison(clang::BinaryOperatorKind op
,
196 clang::Expr
*LHS
, clang::Expr
*RHS
, clang::Stmt
*comp
);
197 __isl_give isl_pw_aff
*extract_boolean(clang::BinaryOperator
*expr
);
198 __isl_give isl_pw_aff
*extract_boolean(clang::UnaryOperator
*expr
);
200 void unsupported(clang::Stmt
*stmt
, const char *msg
= NULL
);