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.
31 /* The sequence number of the next statement. */
33 /* The sequence number of the next virtual scalar. */
35 /* If autodetect is false, a scop delimited by pragmas is extracted,
36 * otherwise we take any scop that we can find.
39 /* Set if the pet_scop returned by an extract method only
40 * represents part of the input tree.
43 /* Set is nested accesses are allowed in general.
44 * This currently defaults to true.
47 /* Set if nested accesses are allowed in that part of the tree
48 * that is currently under investigation.
51 /* Maps identifiers to the last value that was assigned to them.
52 * If an identifier is mapped to NULL, then something may have
53 * been assigned, but we don't know what.
54 * assigned_value does not take a reference to the isl_pw_aff
55 * object, so each such isl_pw_aff needs to be stored in
56 * the set of "expressions".
58 std::map
<clang::ValueDecl
*, isl_pw_aff
*> assigned_value
;
59 /* A collection of isl_pw_affs used in assigned_value or other
60 * temporary maps. expressions holds a reference for each
61 * isl_pw_aff, which is freed in the destructor of PetScan.
63 std::set
<isl_pw_aff
*> expressions
;
65 PetScan(isl_ctx
*ctx
, clang::Preprocessor
&PP
,
66 clang::ASTContext
&ast_context
, ScopLoc
&loc
, int autodetect
) :
67 ctx(ctx
), PP(PP
), ast_context(ast_context
), loc(loc
),
68 autodetect(autodetect
),
69 n_stmt(0), n_test(0), partial(0), allow_nested(true),
70 nesting_enabled(false) { }
74 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
76 static int extract_int(clang::IntegerLiteral
*expr
, isl_int
*v
);
78 void insert_expression(__isl_take isl_pw_aff
*expr
);
79 struct pet_scop
*scan(clang::Stmt
*stmt
);
81 struct pet_scop
*scan_arrays(struct pet_scop
*scop
);
82 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
);
83 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
84 const clang::Type
*type
, int pos
);
86 struct pet_scop
*extract_non_affine_condition(clang::Expr
*cond
,
87 __isl_take isl_map
*access
);
89 struct pet_scop
*extract_conditional_assignment(clang::IfStmt
*stmt
);
91 struct pet_scop
*extract(clang::Stmt
*stmt
);
92 struct pet_scop
*extract(clang::StmtRange stmt_range
);
93 struct pet_scop
*extract(clang::IfStmt
*stmt
);
94 struct pet_scop
*extract(clang::WhileStmt
*stmt
);
95 struct pet_scop
*extract(clang::CompoundStmt
*stmt
);
96 struct pet_scop
*extract(clang::LabelStmt
*stmt
);
98 struct pet_scop
*extract(clang::Stmt
*stmt
, struct pet_expr
*expr
,
99 __isl_take isl_id
*label
= NULL
);
101 clang::BinaryOperator
*initialization_assignment(clang::Stmt
*init
);
102 clang::Decl
*initialization_declaration(clang::Stmt
*init
);
103 clang::ValueDecl
*extract_induction_variable(clang::BinaryOperator
*stmt
);
104 clang::VarDecl
*extract_induction_variable(clang::Stmt
*init
,
106 bool check_unary_increment(clang::UnaryOperator
*op
,
107 clang::ValueDecl
*iv
, isl_int
&inc
);
108 bool check_binary_increment(clang::BinaryOperator
*op
,
109 clang::ValueDecl
*iv
, isl_int
&inc
);
110 bool check_compound_increment(clang::CompoundAssignOperator
*op
,
111 clang::ValueDecl
*iv
, isl_int
&inc
);
112 bool check_increment(clang::ForStmt
*stmt
, clang::ValueDecl
*iv
,
114 struct pet_scop
*extract_for(clang::ForStmt
*stmt
);
115 struct pet_scop
*extract_infinite_loop(clang::Stmt
*body
);
116 struct pet_scop
*extract_infinite_for(clang::ForStmt
*stmt
);
118 void mark_write(struct pet_expr
*access
);
119 struct pet_expr
*extract_expr(clang::Expr
*expr
);
120 struct pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
121 struct pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
122 struct pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
123 struct pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
124 struct pet_expr
*extract_expr(clang::ParenExpr
*expr
);
125 struct pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
126 struct pet_expr
*extract_expr(clang::CallExpr
*expr
);
128 int extract_nested(__isl_keep isl_space
*space
,
129 int n_arg
, struct pet_expr
**args
,
130 std::map
<int,int> ¶m2pos
);
131 struct pet_expr
*extract_nested(struct pet_expr
*expr
, int n
,
132 std::map
<int,int> ¶m2pos
);
133 struct pet_stmt
*extract_nested(struct pet_stmt
*stmt
, int n
,
134 std::map
<int,int> ¶m2pos
);
135 struct pet_expr
*resolve_nested(struct pet_expr
*expr
);
136 struct pet_scop
*resolve_nested(struct pet_scop
*scop
);
137 struct pet_stmt
*resolve_nested(struct pet_stmt
*stmt
);
138 struct pet_expr
*extract_access_expr(clang::Expr
*expr
);
140 __isl_give isl_map
*extract_access(clang::ArraySubscriptExpr
*expr
);
141 __isl_give isl_map
*extract_access(clang::Expr
*expr
);
142 __isl_give isl_map
*extract_access(clang::ImplicitCastExpr
*expr
);
143 __isl_give isl_map
*extract_access(clang::DeclRefExpr
*expr
);
144 __isl_give isl_map
*extract_access(clang::IntegerLiteral
*expr
);
146 int extract_int(clang::Expr
*expr
, isl_int
*v
);
147 int extract_int(clang::ParenExpr
*expr
, isl_int
*v
);
149 __isl_give isl_pw_aff
*extract_affine_add(clang::BinaryOperator
*expr
);
150 __isl_give isl_pw_aff
*extract_affine_div(clang::BinaryOperator
*expr
);
151 __isl_give isl_pw_aff
*extract_affine_mod(clang::BinaryOperator
*expr
);
152 __isl_give isl_pw_aff
*extract_affine_mul(clang::BinaryOperator
*expr
);
154 isl_pw_aff
*nested_access(clang::Expr
*expr
);
156 __isl_give isl_pw_aff
*try_extract_affine(clang::Expr
*expr
);
157 bool is_affine(clang::Expr
*expr
);
158 bool is_affine_condition(clang::Expr
*expr
);
159 __isl_give isl_set
*try_extract_nested_condition(clang::Expr
*expr
);
160 bool is_nested_allowed(__isl_keep isl_set
*set
, pet_scop
*scop
);
162 __isl_give isl_pw_aff
*extract_affine(const llvm::APInt
&val
);
163 __isl_give isl_pw_aff
*extract_affine(clang::Expr
*expr
);
164 __isl_give isl_pw_aff
*extract_affine(clang::IntegerLiteral
*expr
);
165 __isl_give isl_pw_aff
*extract_affine(clang::ImplicitCastExpr
*expr
);
166 __isl_give isl_pw_aff
*extract_affine(clang::DeclRefExpr
*expr
);
167 __isl_give isl_pw_aff
*extract_affine(clang::BinaryOperator
*expr
);
168 __isl_give isl_pw_aff
*extract_affine(clang::UnaryOperator
*expr
);
169 __isl_give isl_pw_aff
*extract_affine(clang::ParenExpr
*expr
);
170 __isl_give isl_pw_aff
*extract_affine(clang::CallExpr
*expr
);
171 __isl_give isl_pw_aff
*extract_affine(clang::ArraySubscriptExpr
*expr
);
172 __isl_give isl_pw_aff
*extract_affine(clang::ConditionalOperator
*expr
);
174 __isl_give isl_pw_aff
*extract_implicit_affine(clang::Expr
*expr
);
175 __isl_give isl_set
*extract_implicit_condition(clang::Expr
*expr
);
177 __isl_give isl_set
*extract_condition(clang::UnaryOperator
*expr
);
178 __isl_give isl_set
*extract_condition(clang::Expr
*expr
);
179 __isl_give isl_set
*extract_comparison(clang::BinaryOperator
*expr
);
180 __isl_give isl_set
*extract_comparison(clang::BinaryOperatorKind op
,
181 clang::Expr
*LHS
, clang::Expr
*RHS
, clang::Stmt
*comp
);
182 __isl_give isl_set
*extract_boolean(clang::BinaryOperator
*expr
);
183 __isl_give isl_set
*extract_boolean(clang::UnaryOperator
*expr
);
185 void unsupported(clang::Stmt
*stmt
);