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.
27 /* Compare two RecordDecl pointers based on their names.
30 bool operator()(const clang::RecordDecl
*x
,
31 const clang::RecordDecl
*y
) {
32 return x
->getNameAsString().compare(y
->getNameAsString()) < 0;
36 /* A sorted set of RecordDecl pointers. The actual order is not important,
37 * only that it is consistent across platforms.
39 typedef std::set
<clang::RecordDecl
*, less_name
> lex_recorddecl_set
;
42 clang::Preprocessor
&PP
;
43 clang::ASTContext
&ast_context
;
44 /* If autodetect is false, then loc contains the location
45 * of the scop to be extracted.
50 /* Set if the pet_scop returned by an extract method only
51 * represents part of the input tree.
55 /* A cache of size expressions for array types as computed
56 * by PetScan::get_array_size.
58 std::map
<const clang::Type
*, pet_expr
*> type_size
;
60 /* A union of mappings of the form
61 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
63 isl_union_map
*value_bounds
;
65 PetScan(clang::Preprocessor
&PP
,
66 clang::ASTContext
&ast_context
, ScopLoc
&loc
,
67 pet_options
*options
, __isl_take isl_union_map
*value_bounds
) :
68 ctx(isl_union_map_get_ctx(value_bounds
)), PP(PP
),
69 ast_context(ast_context
), loc(loc
),
70 options(options
), value_bounds(value_bounds
),
75 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
77 static __isl_give isl_val
*extract_int(isl_ctx
*ctx
,
78 clang::IntegerLiteral
*expr
);
79 static __isl_give isl_val
*extract_unsigned(isl_ctx
*ctx
,
80 const llvm::APInt
&val
);
81 __isl_give pet_expr
*get_array_size(const clang::Type
*type
);
82 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
,
83 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
85 struct pet_scop
*scan(clang::Stmt
*stmt
);
87 struct pet_scop
*scan_arrays(struct pet_scop
*scop
,
88 __isl_keep pet_context
*pc
);
89 struct pet_array
*extract_array(isl_ctx
*ctx
,
90 std::vector
<clang::ValueDecl
*> decls
,
91 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
92 __isl_give pet_expr
*set_upper_bounds(__isl_take pet_expr
*expr
,
93 const clang::Type
*type
, int pos
);
94 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
95 const clang::Type
*type
, __isl_keep pet_context
*pc
);
97 __isl_give pet_tree
*extract(clang::Stmt
*stmt
,
98 bool skip_declarations
= false);
99 __isl_give pet_tree
*extract(clang::StmtRange stmt_range
, bool block
,
100 bool skip_declarations
);
101 __isl_give pet_tree
*extract(clang::IfStmt
*stmt
);
102 __isl_give pet_tree
*extract(clang::WhileStmt
*stmt
);
103 __isl_give pet_tree
*extract(clang::CompoundStmt
*stmt
,
104 bool skip_declarations
= false);
105 __isl_give pet_tree
*extract(clang::LabelStmt
*stmt
);
106 __isl_give pet_tree
*extract(clang::DeclStmt
*expr
);
108 __isl_give pet_loc
*construct_pet_loc(clang::SourceRange range
,
110 __isl_give pet_tree
*extract(__isl_take pet_expr
*expr
,
111 clang::SourceRange range
, bool skip_semi
);
112 __isl_give pet_tree
*update_loc(__isl_take pet_tree
*tree
,
115 struct pet_scop
*extract_scop(__isl_take pet_tree
*tree
);
117 clang::BinaryOperator
*initialization_assignment(clang::Stmt
*init
);
118 clang::Decl
*initialization_declaration(clang::Stmt
*init
);
119 clang::ValueDecl
*extract_induction_variable(clang::BinaryOperator
*stmt
);
120 clang::VarDecl
*extract_induction_variable(clang::Stmt
*init
,
122 __isl_give pet_expr
*extract_unary_increment(clang::UnaryOperator
*op
,
123 clang::ValueDecl
*iv
);
124 __isl_give pet_expr
*extract_binary_increment(
125 clang::BinaryOperator
*op
,
126 clang::ValueDecl
*iv
);
127 __isl_give pet_expr
*extract_compound_increment(
128 clang::CompoundAssignOperator
*op
,
129 clang::ValueDecl
*iv
);
130 __isl_give pet_expr
*extract_increment(clang::ForStmt
*stmt
,
131 clang::ValueDecl
*iv
);
132 __isl_give pet_tree
*extract_for(clang::ForStmt
*stmt
);
134 __isl_give pet_expr
*extract_assume(clang::Expr
*expr
);
135 __isl_give pet_expr
*extract_argument(clang::FunctionDecl
*fd
, int pos
,
137 __isl_give pet_expr
*extract_expr(const llvm::APInt
&val
);
138 __isl_give pet_expr
*extract_expr(clang::Expr
*expr
);
139 __isl_give pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
140 __isl_give pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
141 __isl_give pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
142 __isl_give pet_expr
*extract_expr(clang::IntegerLiteral
*expr
);
143 __isl_give pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
144 __isl_give pet_expr
*extract_expr(clang::ParenExpr
*expr
);
145 __isl_give pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
146 __isl_give pet_expr
*extract_expr(clang::CallExpr
*expr
);
147 __isl_give pet_expr
*extract_expr(clang::CStyleCastExpr
*expr
);
149 __isl_give pet_expr
*extract_access_expr(clang::QualType qt
,
150 __isl_take pet_expr
*index
);
151 __isl_give pet_expr
*extract_access_expr(clang::Expr
*expr
);
152 __isl_give pet_expr
*extract_access_expr(clang::ValueDecl
*decl
);
154 __isl_give pet_expr
*extract_index_expr(
155 clang::ArraySubscriptExpr
*expr
);
156 __isl_give pet_expr
*extract_index_expr(clang::Expr
*expr
);
157 __isl_give pet_expr
*extract_index_expr(clang::ImplicitCastExpr
*expr
);
158 __isl_give pet_expr
*extract_index_expr(clang::DeclRefExpr
*expr
);
159 __isl_give pet_expr
*extract_index_expr(clang::ValueDecl
*decl
);
160 __isl_give pet_expr
*extract_index_expr(clang::MemberExpr
*expr
);
162 __isl_give isl_val
*extract_int(clang::Expr
*expr
);
163 __isl_give isl_val
*extract_int(clang::ParenExpr
*expr
);
165 void report(clang::Stmt
*stmt
, unsigned id
);
166 void unsupported(clang::Stmt
*stmt
);
167 void report_prototype_required(clang::Stmt
*stmt
);
168 void report_missing_increment(clang::Stmt
*stmt
);