tree2scop.c: extract out scop_from_for_init
[pet.git] / tree.h
blobbaf9163a93feafa87c7ba2661b5743d7c3a4cc42
1 #ifndef PET_TREE_H
2 #define PET_TREE_H
4 #include <pet.h>
6 #if defined(__cplusplus)
7 extern "C" {
8 #endif
10 /* A pet_tree represents an AST.
12 * "loc" is the location of the code corresponding to the tree
13 * in the input file.
14 * "label" is the label (if any) that precedes the AST and may be NULL.
16 * The "b" field of the union is used for type pet_tree_block.
17 * "block" is set if the block has its own scope.
18 * "n" is the number of children in "child".
19 * "max" is the capacity of the child array "child".
21 * The "d" field of the union is used for types pet_tree_decl
22 * and pet_tree_decl_init.
23 * "var" is the variable that is being declared.
24 * "init" is the initial value (in case of pet_tree_decl_init).
26 * The "e" field of the union is used for type pet_tree_expr.
27 * "expr" is the expression represented by the tree.
29 * The "l" field of the union is used for types pet_tree_for,
30 * pet_tree_infinite_loop and pet_tree_while.
31 * "body" represents the body of the loop.
32 * "cond" is the loop condition (for pet_tree_for and pet_tree_while).
33 * The remaining fields are only used for pet_tree_for.
34 * "iv" is the induction variable of the for loop.
35 " "declared" is set if this induction variable is declared by the loop.
36 * "init" is the initial value of the induction variable.
37 * "inc" is the increment to the induction variable.
38 * "independent" is set if the for loop is marked independent.
40 * The "i" field of the union is used for types pet_tree_if
41 * and pet_tree_if_else.
42 * "cond" is the if condition.
43 * "then_body" represents the then branch of the if statement.
44 * "else_body" represents the else branch of the if statement
45 * (in case of pet_tree_if_else).
47 struct pet_tree {
48 int ref;
49 isl_ctx *ctx;
51 pet_loc *loc;
52 isl_id *label;
54 enum pet_tree_type type;
56 union {
57 struct {
58 int block;
59 int n;
60 int max;
61 pet_tree **child;
62 } b;
63 struct {
64 pet_expr *var;
65 pet_expr *init;
66 } d;
67 struct {
68 pet_expr *expr;
69 } e;
70 struct {
71 int independent;
72 int declared;
73 pet_expr *iv;
74 pet_expr *init;
75 pet_expr *cond;
76 pet_expr *inc;
77 pet_tree *body;
78 } l;
79 struct {
80 pet_expr *cond;
81 pet_tree *then_body;
82 pet_tree *else_body;
83 } i;
84 } u;
87 const char *pet_tree_type_str(enum pet_tree_type type);
88 enum pet_tree_type pet_tree_str_type(const char *str);
90 int pet_tree_is_equal(__isl_keep pet_tree *tree1, __isl_keep pet_tree *tree2);
92 int pet_tree_is_kill(__isl_keep pet_tree *tree);
93 int pet_tree_is_assign(__isl_keep pet_tree *tree);
94 int pet_tree_is_assume(__isl_keep pet_tree *tree);
95 int pet_tree_is_affine_assume(__isl_keep pet_tree *tree);
96 __isl_give isl_multi_pw_aff *pet_tree_assume_get_index(
97 __isl_keep pet_tree *tree);
99 __isl_give pet_tree *pet_tree_new_decl(__isl_take pet_expr *var);
100 __isl_give pet_tree *pet_tree_new_decl_init(__isl_take pet_expr *var,
101 __isl_take pet_expr *init);
103 __isl_give pet_tree *pet_tree_new_expr(__isl_take pet_expr *expr);
105 __isl_give pet_tree *pet_tree_set_label(__isl_take pet_tree *tree,
106 __isl_take isl_id *label);
108 __isl_give pet_tree *pet_tree_new_block(isl_ctx *ctx, int block, int n);
109 __isl_give pet_tree *pet_tree_block_add_child(__isl_take pet_tree *block,
110 __isl_take pet_tree *child);
111 int pet_tree_block_get_block(__isl_keep pet_tree *block);
112 __isl_give pet_tree *pet_tree_block_set_block(__isl_take pet_tree *block,
113 int is_block);
115 __isl_give pet_tree *pet_tree_new_break(isl_ctx *ctx);
116 __isl_give pet_tree *pet_tree_new_continue(isl_ctx *ctx);
118 __isl_give pet_tree *pet_tree_new_infinite_loop(__isl_take pet_tree *body);
119 __isl_give pet_tree *pet_tree_new_while(__isl_take pet_expr *cond,
120 __isl_take pet_tree *body);
121 __isl_give pet_tree *pet_tree_new_for(int independent, int declared,
122 __isl_take pet_expr *iv, __isl_take pet_expr *init,
123 __isl_take pet_expr *cond, __isl_take pet_expr *inc,
124 __isl_take pet_tree *body);
125 __isl_give pet_tree *pet_tree_new_if(__isl_take pet_expr *cond,
126 __isl_take pet_tree *then_body);
127 __isl_give pet_tree *pet_tree_new_if_else(__isl_take pet_expr *cond,
128 __isl_take pet_tree *then_body, __isl_take pet_tree *else_body);
130 __isl_give pet_tree *pet_tree_set_loc(__isl_take pet_tree *tree,
131 __isl_take pet_loc *loc);
133 int pet_tree_foreach_sub_tree(__isl_keep pet_tree *tree,
134 int (*fn)(__isl_keep pet_tree *tree, void *user), void *user);
136 __isl_give pet_tree *pet_tree_map_access_expr(__isl_take pet_tree *tree,
137 __isl_give pet_expr *(*fn)(__isl_take pet_expr *expr, void *user),
138 void *user);
139 __isl_give pet_tree *pet_tree_map_expr(__isl_take pet_tree *tree,
140 __isl_give pet_expr *(*fn)(__isl_take pet_expr *expr, void *user),
141 void *user);
143 int pet_tree_writes(__isl_keep pet_tree *tree, __isl_keep isl_id *id);
144 int pet_tree_has_continue_or_break(__isl_keep pet_tree *tree);
146 __isl_give pet_tree *pet_tree_align_params(__isl_take pet_tree *tree,
147 __isl_take isl_space *space);
148 __isl_give pet_tree *pet_tree_add_ref_ids(__isl_take pet_tree *tree,
149 int *n_ref);
150 __isl_give pet_tree *pet_tree_anonymize(__isl_take pet_tree *tree);
151 __isl_give pet_tree *pet_tree_gist(__isl_take pet_tree *tree,
152 __isl_keep isl_set *context, __isl_keep isl_union_map *value_bounds);
153 __isl_give pet_tree *pet_tree_update_domain(__isl_take pet_tree *tree,
154 __isl_take isl_multi_pw_aff *update);
156 void pet_tree_dump_with_indent(__isl_keep pet_tree *tree, int indent);
158 #if defined(__cplusplus)
160 #endif
162 #endif