#include "flags.h"
#include "timevar.h"
#include "diagnostic.h"
+#include "tree-pretty-print.h"
#include "tree-dump.h"
#include "tree-inline.h"
#include "fibheap.h"
ipcp_init_cloned_node (struct cgraph_node *orig_node,
struct cgraph_node *new_node)
{
- ipa_check_create_node_params ();
- ipa_initialize_node_params (new_node);
+ gcc_checking_assert (ipa_node_params_vector
+ && (VEC_length (ipa_node_params_t,
+ ipa_node_params_vector)
+ > (unsigned) cgraph_max_uid));
+ gcc_checking_assert (IPA_NODE_REF (new_node)->params);
IPA_NODE_REF (new_node)->ipcp_orig_node = orig_node;
}
-/* Perform intraprocedrual analysis needed for ipcp. */
-static void
-ipcp_analyze_node (struct cgraph_node *node)
-{
- /* Unreachable nodes should have been eliminated before ipcp. */
- gcc_assert (node->needed || node->reachable);
-
- ipa_initialize_node_params (node);
- ipa_detect_param_modifications (node);
-}
-
/* Return scale for NODE. */
static inline gcov_type
ipcp_get_node_scale (struct cgraph_node *node)
static bool
ipcp_versionable_function_p (struct cgraph_node *node)
{
- tree decl = node->decl;
- basic_block bb;
+ struct cgraph_edge *edge;
/* There are a number of generic reasons functions cannot be versioned. */
- if (!tree_versionable_function_p (decl))
- return false;
-
- /* Removing arguments doesn't work if the function takes varargs. */
- if (DECL_STRUCT_FUNCTION (decl)->stdarg)
+ if (!node->local.versionable)
return false;
- /* Removing arguments doesn't work if we use __builtin_apply_args. */
- FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (decl))
+ /* Removing arguments doesn't work if the function takes varargs
+ or use __builtin_apply_args. */
+ for (edge = node->callees; edge; edge = edge->next_callee)
{
- gimple_stmt_iterator gsi;
- for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
- {
- const_gimple stmt = gsi_stmt (gsi);
- tree t;
-
- if (!is_gimple_call (stmt))
- continue;
- t = gimple_call_fndecl (stmt);
- if (t == NULL_TREE)
- continue;
- if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL
- && DECL_FUNCTION_CODE (t) == BUILT_IN_APPLY_ARGS)
- return false;
- }
+ tree t = edge->callee->decl;
+ if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL
+ && (DECL_FUNCTION_CODE (t) == BUILT_IN_APPLY_ARGS
+ || DECL_FUNCTION_CODE (t) == BUILT_IN_VA_START))
+ return false;
}
return true;
/* Initialization and computation of IPCP data structures. This is the initial
intraprocedural analysis of functions, which gathers information to be
propagated later on. */
+
static void
ipcp_init_stage (void)
{
struct cgraph_node *node;
- struct cgraph_edge *cs;
for (node = cgraph_nodes; node; node = node->next)
if (node->analyzed)
- ipcp_analyze_node (node);
- for (node = cgraph_nodes; node; node = node->next)
- {
- if (!node->analyzed)
- continue;
- /* building jump functions */
- for (cs = node->callees; cs; cs = cs->next_callee)
- {
- /* We do not need to bother analyzing calls to unknown
- functions unless they may become known during lto/whopr. */
- if (!cs->callee->analyzed && !flag_lto && !flag_whopr)
- continue;
- ipa_count_arguments (cs);
- if (ipa_get_cs_argument_count (IPA_EDGE_REF (cs))
- != ipa_get_param_count (IPA_NODE_REF (cs->callee)))
- ipa_set_called_with_variable_arg (IPA_NODE_REF (cs->callee));
- ipa_compute_jump_functions (cs);
- }
- }
+ {
+ /* Unreachable nodes should have been eliminated before ipcp. */
+ gcc_assert (node->needed || node->reachable);
+
+ node->local.versionable = tree_versionable_function_p (node->decl);
+ ipa_analyze_node (node);
+ }
}
/* Return true if there are some formal parameters whose value is IPA_TOP (in
struct ipa_replace_map *replace_map;
tree const_val;
- replace_map = GGC_NEW (struct ipa_replace_map);
+ replace_map = ggc_alloc_ipa_replace_map ();
const_val = build_const_val (lat, TREE_TYPE (parm_tree));
if (dump_file)
{
for (i = 0; i < count; i++)
{
struct ipcp_lattice *lat = ipcp_get_lattice (info, i);
- tree parm_tree = ipa_get_param (info, i);
/* We can proactively remove obviously unused arguments. */
- if (is_gimple_reg (parm_tree)
- && !gimple_default_def (DECL_STRUCT_FUNCTION (orig_node->decl),
- parm_tree))
+ if (!ipa_is_param_used (info, i))
{
bitmap_set_bit (args_to_skip, i);
continue;
struct cgraph_edge *cs;
int redirectable_node_callers = 0;
int removable_args = 0;
- bool need_original = !cgraph_only_called_directly_p (node);
+ bool need_original
+ = !cgraph_will_be_removed_from_program_if_no_direct_calls (node);
struct ipa_node_params *info;
int i, count;
int growth;
for (i = 0; i < count; i++)
{
struct ipcp_lattice *lat = ipcp_get_lattice (info, i);
- tree parm_tree = ipa_get_param (info, i);
/* We can proactively remove obviously unused arguments. */
- if (is_gimple_reg (parm_tree)
- && !gimple_default_def (DECL_STRUCT_FUNCTION (node->decl),
- parm_tree))
+ if (!ipa_is_param_used (info, i))
removable_args++;
if (lat->type == IPA_CONST_VALUE)
for (i = 0; i < count; i++)
{
struct ipcp_lattice *lat = ipcp_get_lattice (info, i);
- tree parm_tree = ipa_get_param (info, i);
if (ipcp_lat_is_insertable (lat)
/* Do not count obviously unused arguments. */
- && (!is_gimple_reg (parm_tree)
- || gimple_default_def (DECL_STRUCT_FUNCTION (node->decl),
- parm_tree)))
+ && ipa_is_param_used (info, i))
const_param++;
}
return const_param;
for (cs = node->callers; cs != NULL; cs = cs->next_caller)
if (cs->caller == node || ipcp_need_redirect_p (cs))
break;
- if (!cs && cgraph_only_called_directly_p (node))
+ if (!cs && cgraph_will_be_removed_from_program_if_no_direct_calls (node))
bitmap_set_bit (dead_nodes, node->uid);
info = IPA_NODE_REF (node);
parm_tree = ipa_get_param (info, i);
/* We can proactively remove obviously unused arguments. */
- if (is_gimple_reg (parm_tree)
- && !gimple_default_def (DECL_STRUCT_FUNCTION (node->decl),
- parm_tree))
+ if (!ipa_is_param_used (info, i))
{
bitmap_set_bit (args_to_skip, i);
continue;
new versioned node. */
node1 =
cgraph_create_virtual_clone (node, redirect_callers, replace_trees,
- args_to_skip);
+ args_to_skip, "constprop");
args_to_skip = NULL;
VEC_free (cgraph_edge_p, heap, redirect_callers);
replace_trees = NULL;
static bool
cgraph_gate_cp (void)
{
- return flag_ipa_cp;
+ /* FIXME: We should remove the optimize check after we ensure we never run
+ IPA passes when not optimizng. */
+ return flag_ipa_cp && optimize;
}
struct ipa_opt_pass_d pass_ipa_cp =
0, /* properties_destroyed */
0, /* todo_flags_start */
TODO_dump_cgraph | TODO_dump_func |
- TODO_remove_functions /* todo_flags_finish */
+ TODO_remove_functions | TODO_ggc_collect /* todo_flags_finish */
},
ipcp_generate_summary, /* generate_summary */
ipcp_write_summary, /* write_summary */