wrap results of unsigned computations
[pet.git] / include / pet.h
blob2ecb4ac84d00b512d7709d562251c88f90efbec1
1 #ifndef PET_H
2 #define PET_H
4 #include <isl/set.h>
5 #include <isl/map.h>
6 #include <isl/union_map.h>
8 #if defined(__cplusplus)
9 extern "C" {
10 #endif
12 enum pet_expr_type {
13 pet_expr_access,
14 pet_expr_call,
15 pet_expr_double,
16 pet_expr_unary,
17 pet_expr_binary,
18 pet_expr_ternary
21 enum pet_op_type {
22 /* only compound assignments operators before assignment */
23 pet_op_add_assign,
24 pet_op_sub_assign,
25 pet_op_mul_assign,
26 pet_op_div_assign,
27 pet_op_assign,
28 pet_op_add,
29 pet_op_sub,
30 pet_op_mul,
31 pet_op_div,
32 pet_op_le,
33 pet_op_lt,
34 pet_op_gt,
35 pet_op_minus,
36 pet_op_last
39 /* Index into the pet_expr->args array when pet_expr->type == pet_expr_unary
41 enum pet_un_arg_type {
42 pet_un_arg
45 /* Indices into the pet_expr->args array when
46 * pet_expr->type == pet_expr_binary
48 enum pet_bin_arg_type {
49 pet_bin_lhs,
50 pet_bin_rhs
53 /* Indices into the pet_expr->args array when
54 * pet_expr->type == pet_expr_ternary
56 enum pet_ter_arg_type {
57 pet_ter_cond,
58 pet_ter_true,
59 pet_ter_false
62 /* d is valid when type == pet_expr_double
63 * acc is valid when type == pet_expr_access
64 * call is valid when type == pet_expr_call
65 * op is valid otherwise
67 * acc.access usually maps an iteration space to a data space.
68 * If the access has arguments, however, then the domain of the
69 * mapping is a wrapped mapping from the iteration space
70 * to a space of dimensionality equal to the number of arguments.
71 * Each dimension in this space corresponds to the value of the
72 * corresponding argument.
74 * If the data space is unnamed (and 1D), then it represents
75 * the set of integers. That is, the access represents a value that
76 * is equal to the index.
78 struct pet_expr {
79 enum pet_expr_type type;
81 unsigned n_arg;
82 struct pet_expr **args;
84 union {
85 struct {
86 isl_map *access;
87 int read;
88 int write;
89 } acc;
90 enum pet_op_type op;
91 char *name;
92 double d;
96 struct pet_stmt {
97 int line;
98 isl_set *domain;
99 isl_map *schedule;
100 struct pet_expr *body;
103 /* context holds constraints on the parameter that ensure that
104 * this array has a valid (i.e., non-negative) size
106 * extent holds constraints on the indices
108 * value_bounds holds constraints on the elements of the array
109 * and may be NULL if no such constraints were specified by the user
111 struct pet_array {
112 isl_set *context;
113 isl_set *extent;
114 isl_set *value_bounds;
115 char *element_type;
118 struct pet_scop {
119 isl_set *context;
121 int n_array;
122 struct pet_array **arrays;
124 int n_stmt;
125 struct pet_stmt **stmts;
128 /* Return a textual representation of the operator. */
129 const char *pet_op_str(enum pet_op_type op);
131 /* Extract a pet_scop from a C source file.
132 * If function is not NULL, then the pet_scop is extracted from
133 * a function with that name.
135 * If autodetect is set, any valid scop is extracted.
136 * Otherwise, the scop needs to be delimited by pragmas.
138 struct pet_scop *pet_scop_extract_from_C_source(isl_ctx *ctx,
139 const char *filename, const char *function, int autodetect);
141 /* Update all isl_sets and isl_maps such that they all have the same
142 * parameters in the same order.
144 struct pet_scop *pet_scop_align_params(struct pet_scop *scop);
146 void pet_scop_dump(struct pet_scop *scop);
147 void *pet_scop_free(struct pet_scop *scop);
149 __isl_give isl_union_set *pet_scop_collect_domains(struct pet_scop *scop);
150 /* Collect all read access relations. */
151 __isl_give isl_union_map *pet_scop_collect_reads(struct pet_scop *scop);
152 /* Collect all write access relations. */
153 __isl_give isl_union_map *pet_scop_collect_writes(struct pet_scop *scop);
154 __isl_give isl_union_map *pet_scop_collect_schedule(struct pet_scop *scop);
156 #if defined(__cplusplus)
158 #endif
160 #endif