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 union of mappings of the form
56 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
58 isl_union_map
*value_bounds
;
60 PetScan(clang::Preprocessor
&PP
,
61 clang::ASTContext
&ast_context
, ScopLoc
&loc
,
62 pet_options
*options
, __isl_take isl_union_map
*value_bounds
) :
63 ctx(isl_union_map_get_ctx(value_bounds
)), PP(PP
),
64 ast_context(ast_context
), loc(loc
),
65 options(options
), value_bounds(value_bounds
),
70 struct pet_scop
*scan(clang::FunctionDecl
*fd
);
72 static __isl_give isl_val
*extract_int(isl_ctx
*ctx
,
73 clang::IntegerLiteral
*expr
);
74 static __isl_give isl_val
*extract_unsigned(isl_ctx
*ctx
,
75 const llvm::APInt
&val
);
76 struct pet_array
*extract_array(isl_ctx
*ctx
, clang::ValueDecl
*decl
,
77 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
79 struct pet_scop
*scan(clang::Stmt
*stmt
, __isl_keep pet_context
*pc
);
81 struct pet_scop
*scan_arrays(struct pet_scop
*scop
,
82 __isl_keep pet_context
*pc
);
83 struct pet_array
*extract_array(isl_ctx
*ctx
,
84 std::vector
<clang::ValueDecl
*> decls
,
85 lex_recorddecl_set
*types
, __isl_keep pet_context
*pc
);
86 __isl_give pet_expr
*set_upper_bounds(__isl_take pet_expr
*expr
,
87 const clang::Type
*type
, int pos
);
88 struct pet_array
*set_upper_bounds(struct pet_array
*array
,
89 const clang::Type
*type
, __isl_keep pet_context
*pc
);
91 __isl_give pet_tree
*extract(clang::Stmt
*stmt
,
92 bool skip_declarations
= false);
93 __isl_give pet_tree
*extract(clang::StmtRange stmt_range
, bool block
,
94 bool skip_declarations
);
95 __isl_give pet_tree
*extract(clang::IfStmt
*stmt
);
96 __isl_give pet_tree
*extract(clang::WhileStmt
*stmt
);
97 __isl_give pet_tree
*extract(clang::CompoundStmt
*stmt
,
98 bool skip_declarations
= false);
99 __isl_give pet_tree
*extract(clang::LabelStmt
*stmt
);
100 __isl_give pet_tree
*extract(clang::DeclStmt
*expr
);
102 __isl_give pet_loc
*construct_pet_loc(clang::SourceRange range
,
104 __isl_give pet_tree
*extract(__isl_take pet_expr
*expr
,
105 clang::SourceRange range
, bool skip_semi
);
106 __isl_give pet_tree
*update_loc(__isl_take pet_tree
*tree
,
109 struct pet_scop
*extract_scop(__isl_take pet_tree
*tree
,
110 __isl_keep pet_context
*pc
);
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 pet_expr
*extract_unary_increment(clang::UnaryOperator
*op
,
118 clang::ValueDecl
*iv
);
119 __isl_give pet_expr
*extract_binary_increment(
120 clang::BinaryOperator
*op
,
121 clang::ValueDecl
*iv
);
122 __isl_give pet_expr
*extract_compound_increment(
123 clang::CompoundAssignOperator
*op
,
124 clang::ValueDecl
*iv
);
125 __isl_give pet_expr
*extract_increment(clang::ForStmt
*stmt
,
126 clang::ValueDecl
*iv
);
127 __isl_give pet_tree
*extract_for(clang::ForStmt
*stmt
);
129 __isl_give pet_expr
*extract_assume(clang::Expr
*expr
);
130 __isl_give pet_expr
*extract_argument(clang::FunctionDecl
*fd
, int pos
,
132 __isl_give pet_expr
*extract_expr(const llvm::APInt
&val
);
133 __isl_give pet_expr
*extract_expr(clang::Expr
*expr
);
134 __isl_give pet_expr
*extract_expr(clang::UnaryOperator
*expr
);
135 __isl_give pet_expr
*extract_expr(clang::BinaryOperator
*expr
);
136 __isl_give pet_expr
*extract_expr(clang::ImplicitCastExpr
*expr
);
137 __isl_give pet_expr
*extract_expr(clang::IntegerLiteral
*expr
);
138 __isl_give pet_expr
*extract_expr(clang::FloatingLiteral
*expr
);
139 __isl_give pet_expr
*extract_expr(clang::ParenExpr
*expr
);
140 __isl_give pet_expr
*extract_expr(clang::ConditionalOperator
*expr
);
141 __isl_give pet_expr
*extract_expr(clang::CallExpr
*expr
);
142 __isl_give pet_expr
*extract_expr(clang::CStyleCastExpr
*expr
);
144 __isl_give pet_expr
*extract_access_expr(clang::QualType qt
,
145 __isl_take pet_expr
*index
);
146 __isl_give pet_expr
*extract_access_expr(clang::Expr
*expr
);
147 __isl_give pet_expr
*extract_access_expr(clang::ValueDecl
*decl
);
149 __isl_give pet_expr
*extract_index_expr(
150 clang::ArraySubscriptExpr
*expr
);
151 __isl_give pet_expr
*extract_index_expr(clang::Expr
*expr
);
152 __isl_give pet_expr
*extract_index_expr(clang::ImplicitCastExpr
*expr
);
153 __isl_give pet_expr
*extract_index_expr(clang::DeclRefExpr
*expr
);
154 __isl_give pet_expr
*extract_index_expr(clang::ValueDecl
*decl
);
155 __isl_give pet_expr
*extract_index_expr(clang::MemberExpr
*expr
);
157 __isl_give isl_val
*extract_int(clang::Expr
*expr
);
158 __isl_give isl_val
*extract_int(clang::ParenExpr
*expr
);
160 void report(clang::Stmt
*stmt
, unsigned id
);
161 void unsupported(clang::Stmt
*stmt
);
162 void report_prototype_required(clang::Stmt
*stmt
);
163 void report_missing_increment(clang::Stmt
*stmt
);