3 #include <clang/Basic/SourceManager.h>
4 #include <clang/AST/Decl.h>
5 #include <clang/AST/Stmt.h>
6 #include <clang/Lex/Preprocessor.h>
18 /* The location of the scop, as delimited by scop and endscop
19 * pragmas by the user.
20 * "start_line" is the line number of the start position.
30 /* The information extracted from a pragma pencil independent.
31 * We currently only keep track of the line number where
35 Independent(unsigned line
) : line(line
) {}
40 /* Compare two RecordDecl pointers based on their names.
43 bool operator()(const clang::RecordDecl
*x
,
44 const clang::RecordDecl
*y
) {
45 return x
->getNameAsString().compare(y
->getNameAsString()) < 0;
49 /* A sorted set of RecordDecl pointers. The actual order is not important,
50 * only that it is consistent across platforms.
52 typedef std::set
<clang::RecordDecl
*, less_name
> lex_recorddecl_set
;
55 clang::Preprocessor
&PP
;
56 clang::ASTContext
&ast_context
;
57 /* If autodetect is false, then loc contains the location
58 * of the scop to be extracted.
63 /* Set if the pet_scop returned by an extract method only
64 * represents part of the input tree.
68 /* A cache of size expressions for array types as computed
69 * by PetScan::get_array_size.
71 std::map
<const clang::Type
*, pet_expr
*> type_size
;
73 /* A cache of funtion summaries for function declarations
74 * as extracted by PetScan::get_summary.
76 std::map
<clang::FunctionDecl
*, pet_function_summary
*> summary_cache
;
78 /* A union of mappings of the form
79 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
81 isl_union_map
*value_bounds
;
83 /* The line number of the previously considered Stmt. */
85 /* The line number of the Stmt currently being considered. */
86 unsigned current_line
;
87 /* Information about the independent pragmas in the source code. */
88 std::vector
<Independent
> &independent
;
90 PetScan(clang::Preprocessor
&PP
,
91 clang::ASTContext
&ast_context
, ScopLoc
&loc
,
92 pet_options
*options
, __isl_take isl_union_map
*value_bounds
,
93 std::vector
<Independent
> &independent
) :
94 ctx(isl_union_map_get_ctx(value_bounds
)), PP(PP
),
95 ast_context(ast_context
), loc(loc
),
96 options(options
), value_bounds(value_bounds
),
97 partial(false), last_line(0), current_line(0),
98 independent(independent
) { }
102 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
104 static __isl_give isl_val
*extract_int(isl_ctx
*ctx
,
105 clang::IntegerLiteral
*expr
);
106 __isl_give pet_expr
*get_array_size(const clang::Type
*type
);
107 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
,
108 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
110 void set_current_stmt(clang::Stmt
*stmt
);
111 bool is_current_stmt_marked_independent();
113 struct pet_scop
*scan(clang::Stmt
*stmt
);
115 struct pet_scop
*scan_arrays(struct pet_scop
*scop
,
116 __isl_keep pet_context
*pc
);
117 struct pet_array
*extract_array(isl_ctx
*ctx
,
118 std::vector
<clang::ValueDecl
*> decls
,
119 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
120 __isl_give pet_expr
*set_upper_bounds(__isl_take pet_expr
*expr
,
121 const clang::Type
*type
, int pos
);
122 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
123 const clang::Type
*type
, __isl_keep pet_context
*pc
);
125 __isl_give pet_tree
*extract(clang::Stmt
*stmt
,
126 bool skip_declarations
= false);
127 __isl_give pet_tree
*extract(clang::StmtRange stmt_range
, bool block
,
128 bool skip_declarations
);
129 __isl_give pet_tree
*extract(clang::IfStmt
*stmt
);
130 __isl_give pet_tree
*extract(clang::WhileStmt
*stmt
);
131 __isl_give pet_tree
*extract(clang::CompoundStmt
*stmt
,
132 bool skip_declarations
= false);
133 __isl_give pet_tree
*extract(clang::LabelStmt
*stmt
);
134 __isl_give pet_tree
*extract(clang::DeclStmt
*expr
);
136 __isl_give pet_loc
*construct_pet_loc(clang::SourceRange range
,
138 __isl_give pet_tree
*extract(__isl_take pet_expr
*expr
,
139 clang::SourceRange range
, bool skip_semi
);
140 __isl_give pet_tree
*update_loc(__isl_take pet_tree
*tree
,
143 struct pet_scop
*extract_scop(__isl_take pet_tree
*tree
);
145 clang::BinaryOperator
*initialization_assignment(clang::Stmt
*init
);
146 clang::Decl
*initialization_declaration(clang::Stmt
*init
);
147 clang::ValueDecl
*extract_induction_variable(clang::BinaryOperator
*stmt
);
148 clang::VarDecl
*extract_induction_variable(clang::Stmt
*init
,
150 __isl_give pet_expr
*extract_unary_increment(clang::UnaryOperator
*op
,
151 clang::ValueDecl
*iv
);
152 __isl_give pet_expr
*extract_binary_increment(
153 clang::BinaryOperator
*op
,
154 clang::ValueDecl
*iv
);
155 __isl_give pet_expr
*extract_compound_increment(
156 clang::CompoundAssignOperator
*op
,
157 clang::ValueDecl
*iv
);
158 __isl_give pet_expr
*extract_increment(clang::ForStmt
*stmt
,
159 clang::ValueDecl
*iv
);
160 __isl_give pet_tree
*extract_for(clang::ForStmt
*stmt
);
162 __isl_give pet_expr
*extract_assume(clang::Expr
*expr
);
163 __isl_give pet_function_summary
*get_summary(clang::FunctionDecl
*fd
);
164 __isl_give pet_expr
*set_summary(__isl_take pet_expr
*expr
,
165 clang::FunctionDecl
*fd
);
166 __isl_give pet_expr
*extract_argument(clang::FunctionDecl
*fd
, int pos
,
168 __isl_give pet_expr
*extract_expr(const llvm::APInt
&val
);
169 __isl_give pet_expr
*extract_expr(clang::Expr
*expr
);
170 __isl_give pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
171 __isl_give pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
172 __isl_give pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
173 __isl_give pet_expr
*extract_expr(clang::IntegerLiteral
*expr
);
174 __isl_give pet_expr
*extract_expr(clang::EnumConstantDecl
*expr
);
175 __isl_give pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
176 __isl_give pet_expr
*extract_expr(clang::ParenExpr
*expr
);
177 __isl_give pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
178 __isl_give pet_expr
*extract_expr(clang::CallExpr
*expr
);
179 __isl_give pet_expr
*extract_expr(clang::CStyleCastExpr
*expr
);
181 __isl_give pet_expr
*extract_access_expr(clang::QualType qt
,
182 __isl_take pet_expr
*index
);
183 __isl_give pet_expr
*extract_access_expr(clang::Expr
*expr
);
184 __isl_give pet_expr
*extract_access_expr(clang::ValueDecl
*decl
);
186 __isl_give pet_expr
*extract_index_expr(
187 clang::ArraySubscriptExpr
*expr
);
188 __isl_give pet_expr
*extract_index_expr(clang::Expr
*expr
);
189 __isl_give pet_expr
*extract_index_expr(clang::ImplicitCastExpr
*expr
);
190 __isl_give pet_expr
*extract_index_expr(clang::DeclRefExpr
*expr
);
191 __isl_give pet_expr
*extract_index_expr(clang::ValueDecl
*decl
);
192 __isl_give pet_expr
*extract_index_expr(clang::MemberExpr
*expr
);
194 __isl_give isl_val
*extract_int(clang::Expr
*expr
);
195 __isl_give isl_val
*extract_int(clang::ParenExpr
*expr
);
197 clang::FunctionDecl
*find_decl_from_name(clang::CallExpr
*call
,
199 clang::FunctionDecl
*get_summary_function(clang::CallExpr
*call
);
201 void report(clang::Stmt
*stmt
, unsigned id
);
202 void unsupported(clang::Stmt
*stmt
);
203 void report_prototype_required(clang::Stmt
*stmt
);
204 void report_missing_increment(clang::Stmt
*stmt
);
205 void report_missing_summary_function(clang::Stmt
*stmt
);
206 void report_missing_summary_function_body(clang::Stmt
*stmt
);