3 #include <clang/Basic/SourceManager.h>
4 #include <clang/AST/Decl.h>
5 #include <clang/AST/Stmt.h>
6 #include <clang/Lex/Preprocessor.h>
17 /* The location of the scop, as delimited by scop and endscop
18 * pragmas by the user.
19 * "start_line" is the line number of the start position.
29 /* The information extracted from a pragma pencil independent.
30 * We currently only keep track of the line number where
34 Independent(unsigned line
) : line(line
) {}
39 /* Compare two RecordDecl pointers based on their names.
42 bool operator()(const clang::RecordDecl
*x
,
43 const clang::RecordDecl
*y
) {
44 return x
->getNameAsString().compare(y
->getNameAsString()) < 0;
48 /* A sorted set of RecordDecl pointers. The actual order is not important,
49 * only that it is consistent across platforms.
51 typedef std::set
<clang::RecordDecl
*, less_name
> lex_recorddecl_set
;
54 clang::Preprocessor
&PP
;
55 clang::ASTContext
&ast_context
;
56 /* If autodetect is false, then loc contains the location
57 * of the scop to be extracted.
62 /* Set if the pet_scop returned by an extract method only
63 * represents part of the input tree.
67 /* A cache of size expressions for array types as computed
68 * by PetScan::get_array_size.
70 std::map
<const clang::Type
*, pet_expr
*> type_size
;
72 /* A union of mappings of the form
73 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
75 isl_union_map
*value_bounds
;
77 /* The line number of the previously considered Stmt. */
79 /* The line number of the Stmt currently being considered. */
80 unsigned current_line
;
81 /* Information about the independent pragmas in the source code. */
82 std::vector
<Independent
> &independent
;
84 PetScan(clang::Preprocessor
&PP
,
85 clang::ASTContext
&ast_context
, ScopLoc
&loc
,
86 pet_options
*options
, __isl_take isl_union_map
*value_bounds
,
87 std::vector
<Independent
> &independent
) :
88 ctx(isl_union_map_get_ctx(value_bounds
)), PP(PP
),
89 ast_context(ast_context
), loc(loc
),
90 options(options
), value_bounds(value_bounds
),
91 partial(false), last_line(0), current_line(0),
92 independent(independent
) { }
96 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
98 static __isl_give isl_val
*extract_int(isl_ctx
*ctx
,
99 clang::IntegerLiteral
*expr
);
100 __isl_give pet_expr
*get_array_size(const clang::Type
*type
);
101 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
,
102 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
104 void set_current_stmt(clang::Stmt
*stmt
);
105 bool is_current_stmt_marked_independent();
107 struct pet_scop
*scan(clang::Stmt
*stmt
);
109 struct pet_scop
*scan_arrays(struct pet_scop
*scop
,
110 __isl_keep pet_context
*pc
);
111 struct pet_array
*extract_array(isl_ctx
*ctx
,
112 std::vector
<clang::ValueDecl
*> decls
,
113 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
114 __isl_give pet_expr
*set_upper_bounds(__isl_take pet_expr
*expr
,
115 const clang::Type
*type
, int pos
);
116 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
117 const clang::Type
*type
, __isl_keep pet_context
*pc
);
119 __isl_give pet_tree
*extract(clang::Stmt
*stmt
,
120 bool skip_declarations
= false);
121 __isl_give pet_tree
*extract(clang::StmtRange stmt_range
, bool block
,
122 bool skip_declarations
);
123 __isl_give pet_tree
*extract(clang::IfStmt
*stmt
);
124 __isl_give pet_tree
*extract(clang::WhileStmt
*stmt
);
125 __isl_give pet_tree
*extract(clang::CompoundStmt
*stmt
,
126 bool skip_declarations
= false);
127 __isl_give pet_tree
*extract(clang::LabelStmt
*stmt
);
128 __isl_give pet_tree
*extract(clang::DeclStmt
*expr
);
130 __isl_give pet_loc
*construct_pet_loc(clang::SourceRange range
,
132 __isl_give pet_tree
*extract(__isl_take pet_expr
*expr
,
133 clang::SourceRange range
, bool skip_semi
);
134 __isl_give pet_tree
*update_loc(__isl_take pet_tree
*tree
,
137 struct pet_scop
*extract_scop(__isl_take pet_tree
*tree
);
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 __isl_give pet_tree
*extract_for(clang::ForStmt
*stmt
);
156 __isl_give pet_expr
*extract_assume(clang::Expr
*expr
);
157 __isl_give pet_expr
*extract_argument(clang::FunctionDecl
*fd
, int pos
,
159 __isl_give pet_expr
*extract_expr(const llvm::APInt
&val
);
160 __isl_give pet_expr
*extract_expr(clang::Expr
*expr
);
161 __isl_give pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
162 __isl_give pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
163 __isl_give pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
164 __isl_give pet_expr
*extract_expr(clang::IntegerLiteral
*expr
);
165 __isl_give pet_expr
*extract_expr(clang::EnumConstantDecl
*expr
);
166 __isl_give pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
167 __isl_give pet_expr
*extract_expr(clang::ParenExpr
*expr
);
168 __isl_give pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
169 __isl_give pet_expr
*extract_expr(clang::CallExpr
*expr
);
170 __isl_give pet_expr
*extract_expr(clang::CStyleCastExpr
*expr
);
172 __isl_give pet_expr
*extract_access_expr(clang::QualType qt
,
173 __isl_take pet_expr
*index
);
174 __isl_give pet_expr
*extract_access_expr(clang::Expr
*expr
);
175 __isl_give pet_expr
*extract_access_expr(clang::ValueDecl
*decl
);
177 __isl_give pet_expr
*extract_index_expr(
178 clang::ArraySubscriptExpr
*expr
);
179 __isl_give pet_expr
*extract_index_expr(clang::Expr
*expr
);
180 __isl_give pet_expr
*extract_index_expr(clang::ImplicitCastExpr
*expr
);
181 __isl_give pet_expr
*extract_index_expr(clang::DeclRefExpr
*expr
);
182 __isl_give pet_expr
*extract_index_expr(clang::ValueDecl
*decl
);
183 __isl_give pet_expr
*extract_index_expr(clang::MemberExpr
*expr
);
185 __isl_give isl_val
*extract_int(clang::Expr
*expr
);
186 __isl_give isl_val
*extract_int(clang::ParenExpr
*expr
);
188 void report(clang::Stmt
*stmt
, unsigned id
);
189 void unsupported(clang::Stmt
*stmt
);
190 void report_prototype_required(clang::Stmt
*stmt
);
191 void report_missing_increment(clang::Stmt
*stmt
);