tree-gimple.h revision 169690
138032Speter/* Functions to analyze and validate GIMPLE trees.
2249729Sgshapiro   Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
364562Sgshapiro   Contributed by Diego Novillo <dnovillo@redhat.com>
438032Speter
538032SpeterThis file is part of GCC.
638032Speter
738032SpeterGCC is free software; you can redistribute it and/or modify
838032Speterit under the terms of the GNU General Public License as published by
938032Speterthe Free Software Foundation; either version 2, or (at your option)
1038032Speterany later version.
1138032Speter
1238032SpeterGCC is distributed in the hope that it will be useful,
1338032Speterbut WITHOUT ANY WARRANTY; without even the implied warranty of
1464562SgshapiroMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15168515SgshapiroGNU General Public License for more details.
1638032Speter
17249729SgshapiroYou should have received a copy of the GNU General Public License
1864562Sgshapiroalong with GCC; see the file COPYING.  If not, write to
1964562Sgshapirothe Free Software Foundation, 51 Franklin Street, Fifth Floor,
2064562SgshapiroBoston, MA 02110-1301, USA.  */
2164562Sgshapiro
2264562Sgshapiro#ifndef _TREE_SIMPLE_H
23223067Sgshapiro#define _TREE_SIMPLE_H 1
2464562Sgshapiro
2564562Sgshapiro
2664562Sgshapiro#include "tree-iterator.h"
2764562Sgshapiro
2864562Sgshapiroextern tree create_tmp_var_raw (tree, const char *);
2994334Sgshapiroextern tree create_tmp_var_name (const char *);
3064562Sgshapiroextern tree create_tmp_var (tree, const char *);
3164562Sgshapiroextern tree get_initialized_tmp_var (tree, tree *, tree *);
3264562Sgshapiroextern tree get_formal_tmp_var (tree, tree *);
3390792Sgshapiro
34141858Sgshapiroextern void declare_vars (tree, tree, bool);
3564562Sgshapiro
3638032Speterextern void annotate_all_with_locus (tree *, location_t);
3738032Speter
3838032Speter/* Validation of GIMPLE expressions.  Note that these predicates only check
3938032Speter   the basic form of the expression, they don't recurse to make sure that
4038032Speter   underlying nodes are also of the right form.  */
4138032Speter
4238032Spetertypedef bool (*gimple_predicate)(tree);
4338032Speter
4438032Speter/* Returns true iff T is a valid GIMPLE statement.  */
4538032Speterextern bool is_gimple_stmt (tree);
4638032Speter
4738032Speter/* Returns true iff TYPE is a valid type for a scalar register variable.  */
4838032Speterextern bool is_gimple_reg_type (tree);
4938032Speter/* Returns true iff T is a scalar register variable.  */
5038032Speterextern bool is_gimple_reg (tree);
5138032Speter/* Returns true if T is a GIMPLE temporary variable, false otherwise.  */
5238032Speterextern bool is_gimple_formal_tmp_var (tree);
5338032Speter/* Returns true if T is a GIMPLE temporary register variable.  */
5438032Speterextern bool is_gimple_formal_tmp_reg (tree);
5538032Speter/* Returns true iff T is any sort of variable.  */
5638032Speterextern bool is_gimple_variable (tree);
5738032Speter/* Returns true iff T is any sort of symbol.  */
5838032Speterextern bool is_gimple_id (tree);
5938032Speter/* Returns true iff T is a variable or an INDIRECT_REF (of a variable).  */
6038032Speterextern bool is_gimple_min_lval (tree);
6190792Sgshapiro/* Returns true iff T is something whose address can be taken.  */
6238032Speterextern bool is_gimple_addressable (tree);
6390792Sgshapiro/* Returns true iff T is any valid GIMPLE lvalue.  */
6490792Sgshapiroextern bool is_gimple_lvalue (tree);
6538032Speter
6638032Speter/* Returns true iff T is a GIMPLE restricted function invariant.  */
6738032Speterextern bool is_gimple_min_invariant (tree);
6838032Speter/* Returns true iff T is a GIMPLE rvalue.  */
6938032Speterextern bool is_gimple_val (tree);
7038032Speter/* Returns true iff T is a GIMPLE asm statement input.  */
7138032Speterextern bool is_gimple_asm_val (tree);
7238032Speter/* Returns true iff T is a valid rhs for a MODIFY_EXPR where the LHS is a
7338032Speter   GIMPLE temporary, a renamed user variable, or something else,
7438032Speter   respectively.  */
7590792Sgshapiroextern bool is_gimple_formal_tmp_rhs (tree);
7690792Sgshapiroextern bool is_gimple_reg_rhs (tree);
7738032Speterextern bool is_gimple_mem_rhs (tree);
7838032Speter/* Returns the appropriate one of the above three predicates for the LHS
7938032Speter   T.  */
8038032Speterextern gimple_predicate rhs_predicate_for (tree);
8138032Speter
8238032Speter/* Returns true iff T is a valid if-statement condition.  */
8338032Speterextern bool is_gimple_condexpr (tree);
8438032Speter
8538032Speter/* Returns true iff T is a type conversion.  */
8638032Speterextern bool is_gimple_cast (tree);
8738032Speter/* Returns true iff T is a variable that does not need to live in memory.  */
8838032Speterextern bool is_gimple_non_addressable (tree t);
8938032Speter
9038032Speter/* Returns true iff T is a valid call address expression.  */
9138032Speterextern bool is_gimple_call_addr (tree);
9290792Sgshapiro/* If T makes a function call, returns the CALL_EXPR operand.  */
9364562Sgshapiroextern tree get_call_expr_in (tree t);
9438032Speter
9538032Speterextern void recalculate_side_effects (tree);
9638032Speter
9738032Speter/* FIXME we should deduce this from the predicate.  */
9838032Spetertypedef enum fallback_t {
9938032Speter  fb_none = 0,
10038032Speter  fb_rvalue = 1,
10190792Sgshapiro  fb_lvalue = 2,
10294334Sgshapiro  fb_mayfail = 4,
10338032Speter  fb_either= fb_rvalue | fb_lvalue
10438032Speter} fallback_t;
10564562Sgshapiro
10638032Speterenum gimplify_status {
10738032Speter  GS_ERROR	= -2,	/* Something Bad Seen.  */
108168515Sgshapiro  GS_UNHANDLED	= -1,	/* A langhook result for "I dunno".  */
10938032Speter  GS_OK		= 0,	/* We did something, maybe more to do.  */
11038032Speter  GS_ALL_DONE	= 1	/* The expression is fully gimplified.  */
11138032Speter};
11290792Sgshapiro
11338032Speterextern enum gimplify_status gimplify_expr (tree *, tree *, tree *,
11438032Speter					   bool (*) (tree), fallback_t);
11538032Speterextern void gimplify_type_sizes (tree, tree *);
11638032Speterextern void gimplify_one_sizepos (tree *, tree *);
117203004Sgshapiroextern void gimplify_stmt (tree *);
118223067Sgshapiroextern void gimplify_to_stmt_list (tree *);
119223067Sgshapiroextern void gimplify_body (tree *, tree, bool);
120223067Sgshapiroextern void push_gimplify_context (void);
121223067Sgshapiroextern void pop_gimplify_context (tree);
122223067Sgshapiroextern void gimplify_and_add (tree, tree *);
123223067Sgshapiro
124223067Sgshapiro/* Miscellaneous helpers.  */
125223067Sgshapiroextern void gimple_add_tmp_var (tree);
126223067Sgshapiroextern tree gimple_current_bind_expr (void);
127203004Sgshapiroextern tree voidify_wrapper_expr (tree, tree);
12838032Speterextern tree gimple_build_eh_filter (tree, tree, tree);
12938032Speterextern tree build_and_jump (tree *);
13038032Speterextern tree alloc_stmt_list (void);
13138032Speterextern void free_stmt_list (tree);
13238032Speterextern tree force_labels_r (tree *, int *, void *);
13338032Speterextern enum gimplify_status gimplify_va_arg_expr (tree *, tree *, tree *);
13490792Sgshapirostruct gimplify_omp_ctx;
13538032Speterextern void omp_firstprivatize_variable (struct gimplify_omp_ctx *, tree);
13638032Speterextern tree gimple_boolify (tree);
13790792Sgshapiro
13838032Speter/* In omp-low.c.  */
13938032Speterextern void diagnose_omp_structured_block_errors (tree);
14090792Sgshapiroextern tree omp_reduction_init (tree, tree);
14138032Speter
14238032Speter/* In tree-nested.c.  */
14338032Speterextern void lower_nested_functions (tree);
14438032Speterextern void insert_field_into_struct (tree, tree);
14538032Speter
14690792Sgshapiro/* Convenience routines to walk all statements of a gimple function.
14738032Speter   The difference between these walkers and the generic walk_tree is
14838032Speter   that walk_stmt provides context information to the callback
14938032Speter   routine to know whether it is currently on the LHS or RHS of an
15038032Speter   assignment (IS_LHS) or contexts where only GIMPLE values are
151203004Sgshapiro   allowed (VAL_ONLY).
15290792Sgshapiro
15390792Sgshapiro   This is useful in walkers that need to re-write sub-expressions
15490792Sgshapiro   inside statements while making sure the result is still in GIMPLE
15538032Speter   form.
15638032Speter
15764562Sgshapiro   Note that this is useful exclusively before the code is converted
15864562Sgshapiro   into SSA form.  Once the program is in SSA form, the standard
15938032Speter   operand interface should be used to analyze/modify statements.  */
16038032Speter
16190792Sgshapirostruct walk_stmt_info
16238032Speter{
16364562Sgshapiro  /* For each statement, we invoke CALLBACK via walk_tree.  The passed
16438032Speter     data is a walk_stmt_info structure.  */
165168515Sgshapiro  walk_tree_fn callback;
166168515Sgshapiro
16738032Speter  /* Points to the current statement being walked.  */
168168515Sgshapiro  tree_stmt_iterator tsi;
169168515Sgshapiro
17038032Speter  /* Additional data that CALLBACK may want to carry through the
17138032Speter     recursion.  */
17238032Speter  void *info;
17390792Sgshapiro
17438032Speter  /* Indicates whether the *TP being examined may be replaced
17538032Speter     with something that matches is_gimple_val (if true) or something
17638032Speter     slightly more complicated (if false).  "Something" technically
17738032Speter     means the common subset of is_gimple_lvalue and is_gimple_rhs,
178168515Sgshapiro     but we never try to form anything more complicated than that, so
179168515Sgshapiro     we don't bother checking.
180168515Sgshapiro
181168515Sgshapiro     Also note that CALLBACK should update this flag while walking the
18238032Speter     sub-expressions of a statement.  For instance, when walking the
18338032Speter     statement 'foo (&var)', the flag VAL_ONLY will initially be set
18438032Speter     to true, however, when walking &var, the operand of that
18538032Speter     ADDR_EXPR does not need to be a GIMPLE value.  */
18638032Speter  bool val_only;
18738032Speter
18838032Speter  /* True if we are currently walking the LHS of an assignment.  */
18938032Speter  bool is_lhs;
19038032Speter
19138032Speter  /* Optional.  Set to true by CALLBACK if it made any changes.  */
19264562Sgshapiro  bool changed;
19364562Sgshapiro
19464562Sgshapiro  /* True if we're interested in seeing BIND_EXPRs.  */
19564562Sgshapiro  bool want_bind_expr;
19664562Sgshapiro
19738032Speter  /* True if we're interested in seeing RETURN_EXPRs.  */
19838032Speter  bool want_return_expr;
19938032Speter
20038032Speter  /* True if we're interested in location information.  */
20138032Speter  bool want_locations;
20238032Speter};
20338032Speter
20438032Spetervoid walk_stmts (struct walk_stmt_info *, tree *);
20538032Speter
20638032Speter#endif /* _TREE_SIMPLE_H  */
20738032Speter