tree-gimple.h revision 169689
198937Sdes/* Functions to analyze and validate GIMPLE trees.
298937Sdes   Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
398937Sdes   Contributed by Diego Novillo <dnovillo@redhat.com>
498937Sdes
598937SdesThis file is part of GCC.
698937Sdes
798937SdesGCC is free software; you can redistribute it and/or modify
898937Sdesit under the terms of the GNU General Public License as published by
998937Sdesthe Free Software Foundation; either version 2, or (at your option)
1098937Sdesany later version.
1198937Sdes
1298937SdesGCC is distributed in the hope that it will be useful,
1398937Sdesbut WITHOUT ANY WARRANTY; without even the implied warranty of
1498937SdesMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1598937SdesGNU General Public License for more details.
1698937Sdes
1798937SdesYou should have received a copy of the GNU General Public License
1898937Sdesalong with GCC; see the file COPYING.  If not, write to
1998937Sdesthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
2098937SdesBoston, MA 02110-1301, USA.  */
2198937Sdes
2298937Sdes#ifndef _TREE_SIMPLE_H
2398937Sdes#define _TREE_SIMPLE_H 1
2498937Sdes
2598937Sdes
2698937Sdes#include "tree-iterator.h"
2798937Sdes
2898937Sdesextern tree create_tmp_var_raw (tree, const char *);
2998937Sdesextern tree create_tmp_var_name (const char *);
3098937Sdesextern tree create_tmp_var (tree, const char *);
3198937Sdesextern tree get_initialized_tmp_var (tree, tree *, tree *);
3298937Sdesextern tree get_formal_tmp_var (tree, tree *);
3398937Sdes
3498937Sdesextern void declare_vars (tree, tree, bool);
3598937Sdes
3698937Sdesextern void annotate_all_with_locus (tree *, location_t);
3798937Sdes
3898937Sdes/* Validation of GIMPLE expressions.  Note that these predicates only check
3998937Sdes   the basic form of the expression, they don't recurse to make sure that
4098937Sdes   underlying nodes are also of the right form.  */
4198937Sdes
4298937Sdestypedef bool (*gimple_predicate)(tree);
4398937Sdes
4498937Sdes/* Returns true iff T is a valid GIMPLE statement.  */
4598937Sdesextern bool is_gimple_stmt (tree);
4698937Sdes
4798937Sdes/* Returns true iff TYPE is a valid type for a scalar register variable.  */
4898937Sdesextern bool is_gimple_reg_type (tree);
4998937Sdes/* Returns true iff T is a scalar register variable.  */
5098937Sdesextern bool is_gimple_reg (tree);
5198937Sdes/* Returns true if T is a GIMPLE temporary variable, false otherwise.  */
5298937Sdesextern bool is_gimple_formal_tmp_var (tree);
5398937Sdes/* Returns true if T is a GIMPLE temporary register variable.  */
5498937Sdesextern bool is_gimple_formal_tmp_reg (tree);
5598937Sdes/* Returns true iff T is any sort of variable.  */
5698937Sdesextern bool is_gimple_variable (tree);
5798937Sdes/* Returns true iff T is any sort of symbol.  */
5898937Sdesextern bool is_gimple_id (tree);
5998937Sdes/* Returns true iff T is a variable or an INDIRECT_REF (of a variable).  */
6098937Sdesextern bool is_gimple_min_lval (tree);
6198937Sdes/* Returns true iff T is something whose address can be taken.  */
6298937Sdesextern bool is_gimple_addressable (tree);
6398937Sdes/* Returns true iff T is any valid GIMPLE lvalue.  */
6498937Sdesextern bool is_gimple_lvalue (tree);
6598937Sdes
6698937Sdes/* Returns true iff T is a GIMPLE restricted function invariant.  */
6798937Sdesextern bool is_gimple_min_invariant (tree);
6898937Sdes/* Returns true iff T is a GIMPLE rvalue.  */
6998937Sdesextern bool is_gimple_val (tree);
7098937Sdes/* Returns true iff T is a GIMPLE asm statement input.  */
7198937Sdesextern bool is_gimple_asm_val (tree);
7298937Sdes/* Returns true iff T is a valid rhs for a MODIFY_EXPR where the LHS is a
7398937Sdes   GIMPLE temporary, a renamed user variable, or something else,
7498937Sdes   respectively.  */
7598937Sdesextern bool is_gimple_formal_tmp_rhs (tree);
7698937Sdesextern bool is_gimple_reg_rhs (tree);
7798937Sdesextern bool is_gimple_mem_rhs (tree);
7898937Sdes/* Returns the appropriate one of the above three predicates for the LHS
7998937Sdes   T.  */
8098937Sdesextern gimple_predicate rhs_predicate_for (tree);
8198937Sdes
8298937Sdes/* Returns true iff T is a valid if-statement condition.  */
8398937Sdesextern bool is_gimple_condexpr (tree);
8498937Sdes
8598937Sdes/* Returns true iff T is a type conversion.  */
8698937Sdesextern bool is_gimple_cast (tree);
8798937Sdes/* Returns true iff T is a variable that does not need to live in memory.  */
8898937Sdesextern bool is_gimple_non_addressable (tree t);
8998937Sdes
9098937Sdes/* Returns true iff T is a valid call address expression.  */
9198937Sdesextern bool is_gimple_call_addr (tree);
9298937Sdes/* If T makes a function call, returns the CALL_EXPR operand.  */
9398937Sdesextern tree get_call_expr_in (tree t);
9498937Sdes
9598937Sdesextern void recalculate_side_effects (tree);
9698937Sdes
9798937Sdes/* FIXME we should deduce this from the predicate.  */
9898937Sdestypedef enum fallback_t {
9998937Sdes  fb_none = 0,
10098937Sdes  fb_rvalue = 1,
10198937Sdes  fb_lvalue = 2,
10298937Sdes  fb_mayfail = 4,
10398937Sdes  fb_either= fb_rvalue | fb_lvalue
10498937Sdes} fallback_t;
10598937Sdes
10698937Sdesenum gimplify_status {
10798937Sdes  GS_ERROR	= -2,	/* Something Bad Seen.  */
10898937Sdes  GS_UNHANDLED	= -1,	/* A langhook result for "I dunno".  */
10998937Sdes  GS_OK		= 0,	/* We did something, maybe more to do.  */
11098937Sdes  GS_ALL_DONE	= 1	/* The expression is fully gimplified.  */
11198937Sdes};
11298937Sdes
11398937Sdesextern enum gimplify_status gimplify_expr (tree *, tree *, tree *,
11498937Sdes					   bool (*) (tree), fallback_t);
11598937Sdesextern void gimplify_type_sizes (tree, tree *);
11698937Sdesextern void gimplify_one_sizepos (tree *, tree *);
11798937Sdesextern void gimplify_stmt (tree *);
11898937Sdesextern void gimplify_to_stmt_list (tree *);
11998937Sdesextern void gimplify_body (tree *, tree, bool);
12098937Sdesextern void push_gimplify_context (void);
12198937Sdesextern void pop_gimplify_context (tree);
12298937Sdesextern void gimplify_and_add (tree, tree *);
12398937Sdes
12498937Sdes/* Miscellaneous helpers.  */
12598937Sdesextern void gimple_add_tmp_var (tree);
12698937Sdesextern tree gimple_current_bind_expr (void);
12798937Sdesextern tree voidify_wrapper_expr (tree, tree);
12898937Sdesextern tree gimple_build_eh_filter (tree, tree, tree);
12998937Sdesextern tree build_and_jump (tree *);
13098937Sdesextern tree alloc_stmt_list (void);
13198937Sdesextern void free_stmt_list (tree);
13298937Sdesextern tree force_labels_r (tree *, int *, void *);
13398937Sdesextern enum gimplify_status gimplify_va_arg_expr (tree *, tree *, tree *);
13498937Sdesstruct gimplify_omp_ctx;
13598937Sdesextern void omp_firstprivatize_variable (struct gimplify_omp_ctx *, tree);
13698937Sdesextern tree gimple_boolify (tree);
13798937Sdes
13898937Sdes/* In omp-low.c.  */
13998937Sdesextern void diagnose_omp_structured_block_errors (tree);
14098937Sdesextern tree omp_reduction_init (tree, tree);
14198937Sdes
14298937Sdes/* In tree-nested.c.  */
14398937Sdesextern void lower_nested_functions (tree);
14498937Sdesextern void insert_field_into_struct (tree, tree);
14598937Sdes
14698937Sdes/* Convenience routines to walk all statements of a gimple function.
14798937Sdes   The difference between these walkers and the generic walk_tree is
14898937Sdes   that walk_stmt provides context information to the callback
14998937Sdes   routine to know whether it is currently on the LHS or RHS of an
15098937Sdes   assignment (IS_LHS) or contexts where only GIMPLE values are
15198937Sdes   allowed (VAL_ONLY).
15298937Sdes
15398937Sdes   This is useful in walkers that need to re-write sub-expressions
15498937Sdes   inside statements while making sure the result is still in GIMPLE
15598937Sdes   form.
15698937Sdes
15798937Sdes   Note that this is useful exclusively before the code is converted
15898937Sdes   into SSA form.  Once the program is in SSA form, the standard
15998937Sdes   operand interface should be used to analyze/modify statements.  */
16098937Sdes
16198937Sdesstruct walk_stmt_info
16298937Sdes{
16398937Sdes  /* For each statement, we invoke CALLBACK via walk_tree.  The passed
16498937Sdes     data is a walk_stmt_info structure.  */
16598937Sdes  walk_tree_fn callback;
166106130Sdes
16799768Sdes  /* Points to the current statement being walked.  */
16898937Sdes  tree_stmt_iterator tsi;
16998937Sdes
17098937Sdes  /* Additional data that CALLBACK may want to carry through the
17198937Sdes     recursion.  */
17298937Sdes  void *info;
17398937Sdes
17498937Sdes  /* Indicates whether the *TP being examined may be replaced
17598937Sdes     with something that matches is_gimple_val (if true) or something
17698937Sdes     slightly more complicated (if false).  "Something" technically
17798937Sdes     means the common subset of is_gimple_lvalue and is_gimple_rhs,
17898937Sdes     but we never try to form anything more complicated than that, so
17998937Sdes     we don't bother checking.
18098937Sdes
18198937Sdes     Also note that CALLBACK should update this flag while walking the
18298937Sdes     sub-expressions of a statement.  For instance, when walking the
18398937Sdes     statement 'foo (&var)', the flag VAL_ONLY will initially be set
18498937Sdes     to true, however, when walking &var, the operand of that
18598937Sdes     ADDR_EXPR does not need to be a GIMPLE value.  */
18698937Sdes  bool val_only;
18798937Sdes
18898937Sdes  /* True if we are currently walking the LHS of an assignment.  */
18998937Sdes  bool is_lhs;
19098937Sdes
19198937Sdes  /* Optional.  Set to true by CALLBACK if it made any changes.  */
19298937Sdes  bool changed;
19398937Sdes
19498937Sdes  /* True if we're interested in seeing BIND_EXPRs.  */
19598937Sdes  bool want_bind_expr;
19698937Sdes
19798937Sdes  /* True if we're interested in seeing RETURN_EXPRs.  */
19898937Sdes  bool want_return_expr;
19998937Sdes
20098937Sdes  /* True if we're interested in location information.  */
20198937Sdes  bool want_locations;
20298937Sdes};
20398937Sdes
20498937Sdesvoid walk_stmts (struct walk_stmt_info *, tree *);
20598937Sdes
20698937Sdes#endif /* _TREE_SIMPLE_H  */
20798937Sdes