parse.c: extract_double: fix return type
[pet.git] / include / pet.h
blobe4068fbd7ff9aa7f590cd6a534ffd8e30d14a227
1 #ifndef PET_H
2 #define PET_H
4 #include <isl/arg.h>
5 #include <isl/set.h>
6 #include <isl/map.h>
7 #include <isl/union_map.h>
9 #if defined(__cplusplus)
10 extern "C" {
11 #endif
13 struct pet_options;
14 ISL_ARG_DECL(pet_options, struct pet_options, pet_options_args)
16 /* If autodetect is set, any valid scop is extracted.
17 * Otherwise, the scop needs to be delimited by pragmas.
19 int pet_options_set_autodetect(isl_ctx *ctx, int val);
20 int pet_options_get_autodetect(isl_ctx *ctx);
22 #define PET_OVERFLOW_AVOID 0
23 #define PET_OVERFLOW_IGNORE 1
24 int pet_options_set_signed_overflow(isl_ctx *ctx, int val);
25 int pet_options_get_signed_overflow(isl_ctx *ctx);
27 enum pet_expr_type {
28 pet_expr_access,
29 pet_expr_call,
30 pet_expr_double,
31 pet_expr_unary,
32 pet_expr_binary,
33 pet_expr_ternary
36 enum pet_op_type {
37 /* only compound assignments operators before assignment */
38 pet_op_add_assign,
39 pet_op_sub_assign,
40 pet_op_mul_assign,
41 pet_op_div_assign,
42 pet_op_assign,
43 pet_op_add,
44 pet_op_sub,
45 pet_op_mul,
46 pet_op_div,
47 pet_op_mod,
48 pet_op_eq,
49 pet_op_le,
50 pet_op_lt,
51 pet_op_gt,
52 pet_op_minus,
53 pet_op_post_inc,
54 pet_op_post_dec,
55 pet_op_pre_inc,
56 pet_op_pre_dec,
57 pet_op_address_of,
58 pet_op_kill,
59 pet_op_last
62 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
64 enum pet_un_arg_type {
65 pet_un_arg
68 /* Indices into the pet_expr->args array when
69 * pet_expr->type == pet_expr_binary
71 enum pet_bin_arg_type {
72 pet_bin_lhs,
73 pet_bin_rhs
76 /* Indices into the pet_expr->args array when
77 * pet_expr->type == pet_expr_ternary
79 enum pet_ter_arg_type {
80 pet_ter_cond,
81 pet_ter_true,
82 pet_ter_false
85 /* d is valid when type == pet_expr_double
86 * acc is valid when type == pet_expr_access
87 * name is valid when type == pet_expr_call
88 * op is valid otherwise
90 * acc.access usually maps an iteration space to a data space.
91 * If the access has arguments, however, then the domain of the
92 * mapping is a wrapped mapping from the iteration space
93 * to a space of dimensionality equal to the number of arguments.
94 * Each dimension in this space corresponds to the value of the
95 * corresponding argument.
97 * If the data space is unnamed (and 1D), then it represents
98 * the set of integers. That is, the access represents a value that
99 * is equal to the index.
101 struct pet_expr {
102 enum pet_expr_type type;
104 unsigned n_arg;
105 struct pet_expr **args;
107 union {
108 struct {
109 isl_map *access;
110 int read;
111 int write;
112 } acc;
113 enum pet_op_type op;
114 char *name;
115 double d;
119 /* If the statement has arguments, i.e., n_arg != 0, then
120 * "domain" is a wrapped map, mapping the iteration domain
121 * to the values of the arguments for which this statement
122 * is executed.
123 * Otherwise, it is simply the iteration domain.
125 * If one of the arguments is an access expression that accesses
126 * more than one element for a given iteration, then the constraints
127 * on the value of this argument (encoded in "domain") should be satisfied
128 * for all of those accessed elements.
130 struct pet_stmt {
131 int line;
132 isl_set *domain;
133 isl_map *schedule;
134 struct pet_expr *body;
136 unsigned n_arg;
137 struct pet_expr **args;
140 /* context holds constraints on the parameter that ensure that
141 * this array has a valid (i.e., non-negative) size
143 * extent holds constraints on the indices
145 * value_bounds holds constraints on the elements of the array
146 * and may be NULL if no such constraints were specified by the user
148 * element_size is the size in bytes of each array element
150 * live_out is set if the array appears in a live-out pragma
152 * if uniquely_defined is set then the array is written by a single access
153 * such that any element that is ever read
154 * is known to be assigned exactly once before the read
156 * declared is set if the array was declared somewhere inside the scop.
157 * exposed is set if the declared array is visible outside the scop.
159 struct pet_array {
160 isl_set *context;
161 isl_set *extent;
162 isl_set *value_bounds;
163 char *element_type;
164 int element_size;
165 int live_out;
166 int uniquely_defined;
167 int declared;
168 int exposed;
171 /* The context describes the set of parameter values for which
172 * the scop can be executed.
173 * context_value describes assignments to the parameters (if any)
174 * outside of the scop.
176 struct pet_scop {
177 isl_set *context;
178 isl_set *context_value;
180 int n_array;
181 struct pet_array **arrays;
183 int n_stmt;
184 struct pet_stmt **stmts;
187 /* Return a textual representation of the operator. */
188 const char *pet_op_str(enum pet_op_type op);
189 int pet_op_is_inc_dec(enum pet_op_type op);
191 /* Extract a pet_scop from a C source file.
192 * If function is not NULL, then the pet_scop is extracted from
193 * a function with that name.
195 struct pet_scop *pet_scop_extract_from_C_source(isl_ctx *ctx,
196 const char *filename, const char *function);
198 /* Update all isl_sets and isl_maps such that they all have the same
199 * parameters in the same order.
201 struct pet_scop *pet_scop_align_params(struct pet_scop *scop);
203 void pet_scop_dump(struct pet_scop *scop);
204 void *pet_scop_free(struct pet_scop *scop);
206 __isl_give isl_union_set *pet_scop_collect_domains(struct pet_scop *scop);
207 /* Collect all read access relations. */
208 __isl_give isl_union_map *pet_scop_collect_reads(struct pet_scop *scop);
209 /* Collect all write access relations. */
210 __isl_give isl_union_map *pet_scop_collect_writes(struct pet_scop *scop);
211 __isl_give isl_union_map *pet_scop_collect_schedule(struct pet_scop *scop);
213 #if defined(__cplusplus)
215 #endif
217 #endif