This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix inliner WRT indirect calls
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 10 May 2009 17:17:30 +0200
- Subject: Fix inliner WRT indirect calls
Hi,
this patch fixes two problems in inliner. First estimate_move_cost is called on
VOID types in code estimating cost of call funptr(); and it returns non-trivial
cost since size of VOID is -1 and it thinks that memcpy loop will be needed.
Second since we are now able to keep cgraph intact in inlining, I added verification
and also removal of unreachable blocks so we don't have stale edges after execution.
These two changes are needed to make early inliner handle indirect calls correctly.
Bootstrappe/regtested x86_64-linux, will commit it shortly.
* tree-inline.c (delete_unreachable_blocks_update_callgraph): Declare.
(estimate_move_cost): Assert that it does not get called for VOID_TYPE_P.
(estimate_num_insns): Skip VOID types in argument handling.
(optimize_inline_calls): Delete unreachable blocks and verify that
callgraph is valid.
Index: tree-inline.c
===================================================================
*** tree-inline.c (revision 147338)
--- tree-inline.c (working copy)
*************** static tree copy_decl_to_var (tree, copy
*** 132,137 ****
--- 132,138 ----
static tree copy_result_decl_to_var (tree, copy_body_data *);
static tree copy_decl_maybe_to_var (tree, copy_body_data *);
static gimple remap_gimple_stmt (gimple, copy_body_data *);
+ static bool delete_unreachable_blocks_update_callgraph (copy_body_data *id);
/* Insert a tree->tree mapping for ID. Despite the name suggests
that the trees should be variables, it is used for more than that. */
*************** estimate_move_cost (tree type)
*** 2768,2773 ****
--- 2769,2776 ----
{
HOST_WIDE_INT size;
+ gcc_assert (!VOID_TYPE_P (type));
+
size = int_size_in_bytes (type);
if (size < 0 || size > MOVE_MAX_PIECES * MOVE_RATIO (!optimize_size))
*************** estimate_num_insns (gimple stmt, eni_wei
*** 3013,3032 ****
{
tree arg;
for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
! cost += estimate_move_cost (TREE_TYPE (arg));
}
else if (funtype && prototype_p (funtype))
{
tree t;
! for (t = TYPE_ARG_TYPES (funtype); t; t = TREE_CHAIN (t))
! cost += estimate_move_cost (TREE_VALUE (t));
}
else
{
for (i = 0; i < gimple_call_num_args (stmt); i++)
{
tree arg = gimple_call_arg (stmt, i);
! cost += estimate_move_cost (TREE_TYPE (arg));
}
}
--- 3016,3039 ----
{
tree arg;
for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
! if (!VOID_TYPE_P (TREE_TYPE (arg)))
! cost += estimate_move_cost (TREE_TYPE (arg));
}
else if (funtype && prototype_p (funtype))
{
tree t;
! for (t = TYPE_ARG_TYPES (funtype); t && t != void_list_node;
! t = TREE_CHAIN (t))
! if (!VOID_TYPE_P (TREE_VALUE (t)))
! cost += estimate_move_cost (TREE_VALUE (t));
}
else
{
for (i = 0; i < gimple_call_num_args (stmt); i++)
{
tree arg = gimple_call_arg (stmt, i);
! if (!VOID_TYPE_P (TREE_TYPE (arg)))
! cost += estimate_move_cost (TREE_TYPE (arg));
}
}
*************** optimize_inline_calls (tree fn)
*** 3657,3662 ****
--- 3664,3673 ----
number_blocks (fn);
fold_cond_expr_cond ();
+ delete_unreachable_blocks_update_callgraph (&id);
+ #ifdef ENABLE_CHECKING
+ verify_cgraph_node (id.dst_node);
+ #endif
/* It would be nice to check SSA/CFG/statement consistency here, but it is
not possible yet - the IPA passes might make various functions to not