1/* Functions to analyze and validate GIMPLE trees.
2   Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
3   Contributed by Diego Novillo <dnovillo@redhat.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING.  If not, write to
19the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA.  */
21
22#ifndef _TREE_SIMPLE_H
23#define _TREE_SIMPLE_H 1
24
25
26#include "tree-iterator.h"
27
28extern tree create_tmp_var_raw (tree, const char *);
29extern tree create_tmp_var_name (const char *);
30extern tree create_tmp_var (tree, const char *);
31extern tree get_initialized_tmp_var (tree, tree *, tree *);
32extern tree get_formal_tmp_var (tree, tree *);
33
34extern void declare_vars (tree, tree, bool);
35
36extern void annotate_all_with_locus (tree *, location_t);
37
38/* Validation of GIMPLE expressions.  Note that these predicates only check
39   the basic form of the expression, they don't recurse to make sure that
40   underlying nodes are also of the right form.  */
41
42typedef bool (*gimple_predicate)(tree);
43
44/* Returns true iff T is a valid GIMPLE statement.  */
45extern bool is_gimple_stmt (tree);
46
47/* Returns true iff TYPE is a valid type for a scalar register variable.  */
48extern bool is_gimple_reg_type (tree);
49/* Returns true iff T is a scalar register variable.  */
50extern bool is_gimple_reg (tree);
51/* Returns true if T is a GIMPLE temporary variable, false otherwise.  */
52extern bool is_gimple_formal_tmp_var (tree);
53/* Returns true if T is a GIMPLE temporary register variable.  */
54extern bool is_gimple_formal_tmp_reg (tree);
55/* Returns true iff T is any sort of variable.  */
56extern bool is_gimple_variable (tree);
57/* Returns true iff T is any sort of symbol.  */
58extern bool is_gimple_id (tree);
59/* Returns true iff T is a variable or an INDIRECT_REF (of a variable).  */
60extern bool is_gimple_min_lval (tree);
61/* Returns true iff T is something whose address can be taken.  */
62extern bool is_gimple_addressable (tree);
63/* Returns true iff T is any valid GIMPLE lvalue.  */
64extern bool is_gimple_lvalue (tree);
65
66/* Returns true iff T is a GIMPLE restricted function invariant.  */
67extern bool is_gimple_min_invariant (tree);
68/* Returns true iff T is a GIMPLE rvalue.  */
69extern bool is_gimple_val (tree);
70/* Returns true iff T is a GIMPLE asm statement input.  */
71extern bool is_gimple_asm_val (tree);
72/* Returns true iff T is a valid rhs for a MODIFY_EXPR where the LHS is a
73   GIMPLE temporary, a renamed user variable, or something else,
74   respectively.  */
75extern bool is_gimple_formal_tmp_rhs (tree);
76extern bool is_gimple_reg_rhs (tree);
77extern bool is_gimple_mem_rhs (tree);
78/* Returns the appropriate one of the above three predicates for the LHS
79   T.  */
80extern gimple_predicate rhs_predicate_for (tree);
81
82/* Returns true iff T is a valid if-statement condition.  */
83extern bool is_gimple_condexpr (tree);
84
85/* Returns true iff T is a type conversion.  */
86extern bool is_gimple_cast (tree);
87/* Returns true iff T is a variable that does not need to live in memory.  */
88extern bool is_gimple_non_addressable (tree t);
89
90/* Returns true iff T is a valid call address expression.  */
91extern bool is_gimple_call_addr (tree);
92/* If T makes a function call, returns the CALL_EXPR operand.  */
93extern tree get_call_expr_in (tree t);
94
95extern void recalculate_side_effects (tree);
96
97/* FIXME we should deduce this from the predicate.  */
98typedef enum fallback_t {
99  fb_none = 0,
100  fb_rvalue = 1,
101  fb_lvalue = 2,
102  fb_mayfail = 4,
103  fb_either= fb_rvalue | fb_lvalue
104} fallback_t;
105
106enum gimplify_status {
107  GS_ERROR	= -2,	/* Something Bad Seen.  */
108  GS_UNHANDLED	= -1,	/* A langhook result for "I dunno".  */
109  GS_OK		= 0,	/* We did something, maybe more to do.  */
110  GS_ALL_DONE	= 1	/* The expression is fully gimplified.  */
111};
112
113extern enum gimplify_status gimplify_expr (tree *, tree *, tree *,
114					   bool (*) (tree), fallback_t);
115extern void gimplify_type_sizes (tree, tree *);
116extern void gimplify_one_sizepos (tree *, tree *);
117extern void gimplify_stmt (tree *);
118extern void gimplify_to_stmt_list (tree *);
119extern void gimplify_body (tree *, tree, bool);
120extern void push_gimplify_context (void);
121extern void pop_gimplify_context (tree);
122extern void gimplify_and_add (tree, tree *);
123
124/* Miscellaneous helpers.  */
125extern void gimple_add_tmp_var (tree);
126extern tree gimple_current_bind_expr (void);
127extern tree voidify_wrapper_expr (tree, tree);
128extern tree gimple_build_eh_filter (tree, tree, tree);
129extern tree build_and_jump (tree *);
130extern tree alloc_stmt_list (void);
131extern void free_stmt_list (tree);
132extern tree force_labels_r (tree *, int *, void *);
133extern enum gimplify_status gimplify_va_arg_expr (tree *, tree *, tree *);
134struct gimplify_omp_ctx;
135extern void omp_firstprivatize_variable (struct gimplify_omp_ctx *, tree);
136extern tree gimple_boolify (tree);
137
138/* In omp-low.c.  */
139extern void diagnose_omp_structured_block_errors (tree);
140extern tree omp_reduction_init (tree, tree);
141
142/* In tree-nested.c.  */
143extern void lower_nested_functions (tree);
144extern void insert_field_into_struct (tree, tree);
145
146/* Convenience routines to walk all statements of a gimple function.
147   The difference between these walkers and the generic walk_tree is
148   that walk_stmt provides context information to the callback
149   routine to know whether it is currently on the LHS or RHS of an
150   assignment (IS_LHS) or contexts where only GIMPLE values are
151   allowed (VAL_ONLY).
152
153   This is useful in walkers that need to re-write sub-expressions
154   inside statements while making sure the result is still in GIMPLE
155   form.
156
157   Note that this is useful exclusively before the code is converted
158   into SSA form.  Once the program is in SSA form, the standard
159   operand interface should be used to analyze/modify statements.  */
160
161struct walk_stmt_info
162{
163  /* For each statement, we invoke CALLBACK via walk_tree.  The passed
164     data is a walk_stmt_info structure.  */
165  walk_tree_fn callback;
166
167  /* Points to the current statement being walked.  */
168  tree_stmt_iterator tsi;
169
170  /* Additional data that CALLBACK may want to carry through the
171     recursion.  */
172  void *info;
173
174  /* Indicates whether the *TP being examined may be replaced
175     with something that matches is_gimple_val (if true) or something
176     slightly more complicated (if false).  "Something" technically
177     means the common subset of is_gimple_lvalue and is_gimple_rhs,
178     but we never try to form anything more complicated than that, so
179     we don't bother checking.
180
181     Also note that CALLBACK should update this flag while walking the
182     sub-expressions of a statement.  For instance, when walking the
183     statement 'foo (&var)', the flag VAL_ONLY will initially be set
184     to true, however, when walking &var, the operand of that
185     ADDR_EXPR does not need to be a GIMPLE value.  */
186  bool val_only;
187
188  /* True if we are currently walking the LHS of an assignment.  */
189  bool is_lhs;
190
191  /* Optional.  Set to true by CALLBACK if it made any changes.  */
192  bool changed;
193
194  /* True if we're interested in seeing BIND_EXPRs.  */
195  bool want_bind_expr;
196
197  /* True if we're interested in seeing RETURN_EXPRs.  */
198  bool want_return_expr;
199
200  /* True if we're interested in location information.  */
201  bool want_locations;
202};
203
204void walk_stmts (struct walk_stmt_info *, tree *);
205
206#endif /* _TREE_SIMPLE_H  */
207