This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fold substituted statements in inliner
- From: Jan Hubicka <jh at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org, rth at redhat dot com
- Date: Thu, 2 Jun 2005 19:18:51 +0200
- Subject: Fold substituted statements in inliner
Hi,
inliner might introduce folding oportunities basically by substituting
constants for on operands (but in few other cases too). These currently
remain unfolded with the exception of conditionals that are currently
folded via fold_cond_expr_cond. This makes us to lose some
optimizations and excercise interesting dead corners...
Bootstrapped/regtested on i686-pc-gnu-linux, OK?
2005-06-02 Jan Hubicka <jh@suse.cz>
* tree-inline.c: Include tree-pass.h
(inline_data): Add "substituted" field.
(copy_body_r): Set substituted when substitution happens.
(copy_bb): Fold the statements when needed.
* tree-optimize.c (tree_rest_of_compilation): Initialize bitmaps
before inlining.
Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.191
diff -c -3 -p -r1.191 tree-inline.c
*** tree-inline.c 1 Jun 2005 18:43:00 -0000 1.191
--- tree-inline.c 2 Jun 2005 13:39:33 -0000
*************** Boston, MA 02111-1307, USA. */
*** 50,55 ****
--- 50,56 ----
#include "debug.h"
#include "pointer-set.h"
#include "integrate.h"
+ #include "tree-pass.h"
/* I'm not real happy about this, but we need to handle gimple and
non-gimple trees. */
*************** typedef struct inline_data
*** 138,143 ****
--- 139,148 ----
/* Take region number in the function being copied, add this value and
get eh region number of the duplicate in the function we inline into. */
int eh_region_offset;
+
+ /* True when some substitution happent while copying so statement should be folded
+ when finished. */
+ bool substituted;
} inline_data;
/* Prototypes. */
*************** copy_body_r (tree *tp, int *walk_subtree
*** 515,520 ****
--- 520,526 ----
/* Replace the RETURN_EXPR with (a copy of) the
MODIFY_EXPR hanging underneath. */
*tp = copy_node (assignment);
+ id->substituted = true;
}
else /* Else the RETURN_EXPR returns no value. */
{
*************** copy_body_r (tree *tp, int *walk_subtree
*** 536,541 ****
--- 542,553 ----
gcc_assert (new_decl);
/* Replace this variable with the copy. */
STRIP_TYPE_NOPS (new_decl);
+ /* Subsitution here is very common, however we are only interested
+ in a cases where it might introduce folding oppurtunities.
+ Thus notice substitutions by constant. */
+ if ((TREE_CODE (new_decl) != TREE_CODE (*tp))
+ || (TREE_CONSTANT (new_decl) != TREE_CONSTANT (*tp)))
+ id->substituted = true;
*tp = new_decl;
*walk_subtrees = 0;
}
*************** copy_body_r (tree *tp, int *walk_subtree
*** 626,631 ****
--- 638,644 ----
else
*tp = build1 (INDIRECT_REF, type, (tree)n->value);
}
+ id->substituted = true;
*walk_subtrees = 0;
return NULL;
}
*************** copy_bb (inline_data *id, basic_block bb
*** 692,697 ****
--- 705,711 ----
tree stmt = bsi_stmt (bsi);
tree orig_stmt = stmt;
+ id->substituted = false;
walk_tree (&stmt, copy_body_r, id, NULL);
/* RETURN_EXPR might be removed,
*************** copy_bb (inline_data *id, basic_block bb
*** 699,704 ****
--- 713,736 ----
if (stmt)
{
tree call, decl;
+
+ if (id->substituted)
+ {
+ bool folded;
+ if (dump_file)
+ {
+ fprintf (dump_file, "Folding statement ");
+ print_generic_stmt (dump_file, stmt, dump_flags);
+ fprintf (dump_file, "Ofiginal form ");
+ print_generic_stmt (dump_file, orig_stmt, dump_flags);
+ }
+ folded = fold_stmt (&stmt);
+ if (dump_file && folded)
+ {
+ fprintf (dump_file, "Folded to ");
+ print_generic_stmt (dump_file, stmt, dump_flags);
+ }
+ }
bsi_insert_after (©_bsi, stmt, BSI_NEW_STMT);
call = get_call_expr_in (stmt);
/* We're duplicating a CALL_EXPR. Find any corresponding
*************** optimize_inline_calls (tree fn)
*** 2210,2216 ****
as inlining loops might increase the maximum. */
if (ENTRY_BLOCK_PTR->count)
counts_to_freqs ();
- fold_cond_expr_cond ();
}
/* FN is a function that has a complete body, and CLONE is a function whose
--- 2242,2247 ----
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.103
diff -c -3 -p -r2.103 tree-optimize.c
*** tree-optimize.c 29 May 2005 13:14:42 -0000 2.103
--- tree-optimize.c 2 Jun 2005 13:39:33 -0000
*************** tree_rest_of_compilation (tree fndecl)
*** 755,760 ****
--- 755,764 ----
save_body (fndecl, &cfun->saved_args, &cfun->saved_static_chain_decl);
}
+ /* Initialize the default bitmap obstack. */
+ bitmap_obstack_initialize (NULL);
+ bitmap_obstack_initialize (®_obstack); /* FIXME, only at RTL generation*/
+
if (flag_inline_trees)
{
struct cgraph_edge *e;
*************** tree_rest_of_compilation (tree fndecl)
*** 783,792 ****
Kill it so it won't confuse us. */
cgraph_node_remove_callees (node);
-
- /* Initialize the default bitmap obstack. */
- bitmap_obstack_initialize (NULL);
- bitmap_obstack_initialize (®_obstack); /* FIXME, only at RTL generation*/
tree_register_cfg_hooks ();
/* Perform all tree transforms and optimizations. */
--- 787,792 ----