190075Sobrien/* Tree inlining hooks and declarations.
2169689Skan   Copyright 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
390075Sobrien   Contributed by Alexandre Oliva  <aoliva@redhat.com>
490075Sobrien
5132718SkanThis file is part of GCC.
690075Sobrien
7132718SkanGCC is free software; you can redistribute it and/or modify
890075Sobrienit under the terms of the GNU General Public License as published by
990075Sobrienthe Free Software Foundation; either version 2, or (at your option)
1090075Sobrienany later version.
1190075Sobrien
12132718SkanGCC is distributed in the hope that it will be useful,
1390075Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
1490075SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1590075SobrienGNU General Public License for more details.
1690075Sobrien
1790075SobrienYou should have received a copy of the GNU General Public License
18132718Skanalong with GCC; see the file COPYING.  If not, write to
19169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
20169689SkanBoston, MA 02110-1301, USA.  */
2190075Sobrien
2290075Sobrien#ifndef GCC_TREE_INLINE_H
2390075Sobrien#define GCC_TREE_INLINE_H
2490075Sobrien
25169689Skan#include "varray.h"
26169689Skan#include "splay-tree.h"
27169689Skan
28169689Skan
29169689Skan/* Data required for function body duplication.  */
30169689Skan
31169689Skantypedef struct copy_body_data
32169689Skan{
33169689Skan  /* FUNCTION_DECL for function being inlined, or in general the
34169689Skan     source function providing the original trees.  */
35169689Skan  tree src_fn;
36169689Skan  /* FUNCTION_DECL for function being inlined into, or in general
37169689Skan     the destination function receiving the new trees.  */
38169689Skan  tree dst_fn;
39169689Skan  /* Callgraph node of the source function.  */
40169689Skan  struct cgraph_node *src_node;
41169689Skan  /* Callgraph node of the destination function.  */
42169689Skan  struct cgraph_node *dst_node;
43169689Skan  /* struct function for function being inlined.  Usually this is the same
44169689Skan     as DECL_STRUCT_FUNCTION (src_fn), but can be different if saved_cfg
45169689Skan     and saved_eh are in use.  */
46169689Skan  struct function *src_cfun;
47169689Skan
48169689Skan  /* The VAR_DECL for the return value.  */
49169689Skan  tree retvar;
50169689Skan  /* The map from local declarations in the inlined function to
51169689Skan     equivalents in the function into which it is being inlined.  */
52169689Skan  splay_tree decl_map;
53169689Skan
54169689Skan  /* Create a new decl to replace DECL in the destination function.  */
55169689Skan  tree (*copy_decl) (tree, struct copy_body_data *);
56169689Skan
57169689Skan  /* Current BLOCK.  */
58169689Skan  tree block;
59169689Skan
60169689Skan  /* Exception region the inlined call lie in.  */
61169689Skan  int eh_region;
62169689Skan  /* Take region number in the function being copied, add this value and
63169689Skan     get eh region number of the duplicate in the function we inline into.  */
64169689Skan  int eh_region_offset;
65169689Skan
66169689Skan  /* We use the same mechanism do all sorts of different things.  Rather
67169689Skan     than enumerating the different cases, we categorize the behavior
68169689Skan     in the various situations.  */
69169689Skan
70169689Skan  /* Indicate the desired behavior wrt call graph edges.  We can either
71169689Skan     duplicate the edge (inlining, cloning), move the edge (versioning,
72169689Skan     parallelization), or move the edges of the clones (saving).  */
73169689Skan  enum copy_body_cge_which {
74169689Skan    CB_CGE_DUPLICATE,
75169689Skan    CB_CGE_MOVE,
76169689Skan    CB_CGE_MOVE_CLONES
77169689Skan  } transform_call_graph_edges;
78169689Skan
79169689Skan  /* True if a new CFG should be created.  False for inlining, true for
80169689Skan     everything else.  */
81169689Skan  bool transform_new_cfg;
82169689Skan
83169689Skan  /* True if RETURN_EXPRs should be transformed to just the contained
84169689Skan     MODIFY_EXPR.  The branch semantics of the return will be handled
85169689Skan     by manipulating the CFG rather than a statement.  */
86169689Skan  bool transform_return_to_modify;
87169689Skan
88169689Skan  /* True if lang_hooks.decls.insert_block should be invoked when
89169689Skan     duplicating BLOCK nodes.  */
90169689Skan  bool transform_lang_insert_block;
91169689Skan} copy_body_data;
92169689Skan
9390075Sobrien/* Function prototypes.  */
9490075Sobrien
95169689Skanextern tree copy_body_r (tree *, int *, void *);
96169689Skanextern void insert_decl_map (copy_body_data *, tree, tree);
97169689Skan
98132718Skanvoid optimize_inline_calls (tree);
99132718Skanbool tree_inlinable_function_p (tree);
100169689Skantree copy_tree_r (tree *, int *, void *);
101169689Skanvoid clone_body (tree, tree, void *);
102169689Skanvoid save_body (tree, tree *, tree *);
103169689Skanint estimate_move_cost (tree type);
104169689Skanvoid push_cfun (struct function *new_cfun);
105169689Skanvoid pop_cfun (void);
106169689Skanint estimate_num_insns (tree expr);
107169689Skanbool tree_versionable_function_p (tree);
108169689Skanvoid tree_function_versioning (tree, tree, varray_type, bool);
10990075Sobrien
110169689Skanextern tree remap_decl (tree decl, copy_body_data *id);
111169689Skanextern tree remap_type (tree type, copy_body_data *id);
112169689Skan
11390075Sobrien/* 0 if we should not perform inlining.
114117395Skan   1 if we should expand functions calls inline at the tree level.
115117395Skan   2 if we should consider *all* functions to be inline
11690075Sobrien   candidates.  */
11790075Sobrien
11890075Sobrienextern int flag_inline_trees;
11990075Sobrien
12090075Sobrien#endif /* GCC_TREE_INLINE_H */
121