Commit 2c9561b5 by Martin Jambor Committed by Martin Jambor

re PR tree-optimization/53787 (Possible IPA-SRA / IPA-CP improvement)

2012-11-07  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/53787
	* ipa-cp.c (ipcp_value_source): New field offset.
	(ipcp_agg_lattice): New type.
	(ipcp_param_lattices): Likewise, move virt_call from ipcp_lattice here.
	(ipcp_agg_lattice_pool): New variable.
	(ipa_get_parm_lattices): New function.
	(ipa_get_lattice): Turned into ipa_get_scalar_lat, use the above.
	Adjusted all callers.
	(print_lattice): New function.
	(print_all_lattices): Use the above, also print aggregate lattices.
	(set_agg_lats_to_bottom): New function.
	(set_agg_lats_contain_variable): Likewise.
	(set_all_contains_variable): Likewise.
	(initialize_node_lattices): Also handle aggregate lattices, set
	virt_call in ipcp_param_lattices.
	(add_value_source): Handle offsets.
	(add_value_to_lattice): Likewise.
	(add_scalar_value_to_lattice): New function.
	(propagate_vals_accross_pass_through): Use add_scalar_value_to_lattice.
	(propagate_vals_accross_ancestor): Likewise.
	(propagate_accross_jump_function): Renamed to
	propagate_scalar_accross_jump_function, use
	add_scalar_value_to_lattice.
	(set_check_aggs_by_ref): New function.
	(merge_agg_lats_step): Likewise.
	(set_chain_of_aglats_contains_variable): Likewise.
	(merge_aggregate_lattices): Likewise.
	(propagate_constants_accross_call): Also handle aggregate lattices.
	(hint_time_bonus): New function.
	(context_independent_aggregate_values): Likewise.
	(gather_context_independent_values): Also handle agggregate values.
	(agg_jmp_p_vec_for_t_vec): New function.
	(estimate_local_effects): Also handle agggregate values.
	(add_all_node_vals_to_toposort): Likewise.
	(ipcp_propagate_stage): Use struct ipcp_param_lattices.
	(get_clone_agg_value): New function.
	(cgraph_edge_brings_value_p): Also handle agggregate values.
	(create_specialized_node): Likewise.
	(find_more_values_for_callers_subset): Rename to
	find_more_scalar_values_for_callers_subset.  Modify dump.
	(copy_plats_to_inter): New function.
	(intersect_with_plats): Likewise.
	(agg_replacements_to_vector): Likewise.
	(intersect_with_agg_replacements): Likewise.
	(find_aggregate_values_for_callers_subset): Likewise.
	(known_aggs_to_agg_replacement_list): Likewise.
	(cgraph_edge_brings_all_scalars_for_node): Likewise.
	(cgraph_edge_brings_all_agg_vals_for_node): Likewise.
	(perhaps_add_new_callers): Old functionality moved to
	cgraph_edge_brings_all_scalars_for_node, call it and
	cgraph_edge_brings_all_agg_vals_for_node.
	(ipcp_val_in_agg_replacements_p): New function.
	(decide_about_value): New function.
	(decide_whether_version_node): A lot of functionality moved to
	decide_about_value.  Also handle agggregate values.
	(ipcp_driver): Also allocate ipcp_agg_lattice_pool.
	(pass_ipa_cp): Fill in new entries.
	* ipa-prop.c (ipa_node_agg_replacements): New variable.
	(free_parms_ainfo): New function.
	(ipa_analyze_node): Use free_parms_ainfo to free stuff.
	(ipa_find_agg_cst_for_param): Do not rely on offset ordering.
	(ipa_set_node_agg_value_chain): New function.
	(ipa_node_removal_hook): Also handle ipa_node_agg_replacements.
	(ipa_node_duplication_hook): Likewise.
	(ipa_free_all_structures_after_ipa_cp): Also free ipcp_agg_lattice_pool.
	(ipa_free_all_structures_after_iinln): Likewise.
	(ipa_dump_agg_replacement_values): New function.
	(write_agg_replacement_chain): Likewise.
	(read_agg_replacement_chain): Likewise.
	(ipa_prop_write_all_agg_replacement): Likewise.
	(read_replacements_section): Likewise.
	(ipa_prop_read_all_agg_replacement): Likewise.
	(adjust_agg_replacement_values): Likewise.
	(ipcp_transform_function): Likewise.
	* ipa-prop.h: Also define heap vector of ipa_agg_jf_item_t and of
	ipa_agg_jump_function_t.
	(ipa_node_params): Make lattices an array of ipcp_param_lattices.
	(ipa_agg_replacement_value): New type and its vector.
	(ipa_set_node_agg_value_chain) Declare.
	(ipa_node_agg_replacements): Likewise.
	(ipa_get_agg_replacements_for_node): New function.
	(ipcp_agg_lattice_pool): Declare.
	(ipa_dump_agg_replacement_values): Likewise.
	(ipa_prop_write_all_agg_replacement): Likewise.
	(ipa_prop_read_all_agg_replacement): Likewise.
	(ipcp_transform_function): Likewise.
	* ipa-inline-analysis.c (estimate_ipcp_clone_size_and_time): Pass around
	known aggregates and hints.
	* ipa-inline.h: include ipa-prop.h.
	(estimate_ipcp_clone_size_and_time): Adjust declaration.
	* lto-streamer.h (lto_section_type): New item
	LTO_section_ipcp_transform.
	* lto-section-in.c (lto_section_name): New element ipcp_trans.
	* params.def (PARAM_IPA_CP_LOOP_HINT_BONUS): New parameter.
	* Makefile.in (IPA_INLINE_H): New.  Use everywhee instead of
	ipa-inline.h.

	* testsuite/gcc.dg/ipa/ipa-5.c: Adjust.
	* testsuite/gcc.dg/ipa/ipcp-agg-1.c: New test.
	* testsuite/gcc.dg/ipa/ipcp-agg-2.c: Likewise.
	* testsuite/gcc.dg/ipa/ipcp-agg-3.c: Likewise.
	* testsuite/gcc.dg/ipa/ipcp-agg-4.c: Likewise.
	* testsuite/gcc.dg/ipa/ipcp-agg-5.c: Likewise.
	* testsuite/gcc.dg/ipa/ipcp-agg-6.c: Likewise.
	* testsuite/gfortran.dg/pr48636.f90: Add -fno-ipa-cp.
	* testsuite/gfortran.dg/pr48636-2.f90: New test.
	* testsuite/gfortran.dg/pr53787.f90: Likewise.

From-SVN: r193298
parent a57d75dc
2012-11-07 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/53787
* ipa-cp.c (ipcp_value_source): New field offset.
(ipcp_agg_lattice): New type.
(ipcp_param_lattices): Likewise, move virt_call from ipcp_lattice here.
(ipcp_agg_lattice_pool): New variable.
(ipa_get_parm_lattices): New function.
(ipa_get_lattice): Turned into ipa_get_scalar_lat, use the above.
Adjusted all callers.
(print_lattice): New function.
(print_all_lattices): Use the above, also print aggregate lattices.
(set_agg_lats_to_bottom): New function.
(set_agg_lats_contain_variable): Likewise.
(set_all_contains_variable): Likewise.
(initialize_node_lattices): Also handle aggregate lattices, set
virt_call in ipcp_param_lattices.
(add_value_source): Handle offsets.
(add_value_to_lattice): Likewise.
(add_scalar_value_to_lattice): New function.
(propagate_vals_accross_pass_through): Use add_scalar_value_to_lattice.
(propagate_vals_accross_ancestor): Likewise.
(propagate_accross_jump_function): Renamed to
propagate_scalar_accross_jump_function, use
add_scalar_value_to_lattice.
(set_check_aggs_by_ref): New function.
(merge_agg_lats_step): Likewise.
(set_chain_of_aglats_contains_variable): Likewise.
(merge_aggregate_lattices): Likewise.
(propagate_constants_accross_call): Also handle aggregate lattices.
(hint_time_bonus): New function.
(context_independent_aggregate_values): Likewise.
(gather_context_independent_values): Also handle agggregate values.
(agg_jmp_p_vec_for_t_vec): New function.
(estimate_local_effects): Also handle agggregate values.
(add_all_node_vals_to_toposort): Likewise.
(ipcp_propagate_stage): Use struct ipcp_param_lattices.
(get_clone_agg_value): New function.
(cgraph_edge_brings_value_p): Also handle agggregate values.
(create_specialized_node): Likewise.
(find_more_values_for_callers_subset): Rename to
find_more_scalar_values_for_callers_subset. Modify dump.
(copy_plats_to_inter): New function.
(intersect_with_plats): Likewise.
(agg_replacements_to_vector): Likewise.
(intersect_with_agg_replacements): Likewise.
(find_aggregate_values_for_callers_subset): Likewise.
(known_aggs_to_agg_replacement_list): Likewise.
(cgraph_edge_brings_all_scalars_for_node): Likewise.
(cgraph_edge_brings_all_agg_vals_for_node): Likewise.
(perhaps_add_new_callers): Old functionality moved to
cgraph_edge_brings_all_scalars_for_node, call it and
cgraph_edge_brings_all_agg_vals_for_node.
(ipcp_val_in_agg_replacements_p): New function.
(decide_about_value): New function.
(decide_whether_version_node): A lot of functionality moved to
decide_about_value. Also handle agggregate values.
(ipcp_driver): Also allocate ipcp_agg_lattice_pool.
(pass_ipa_cp): Fill in new entries.
* ipa-prop.c (ipa_node_agg_replacements): New variable.
(free_parms_ainfo): New function.
(ipa_analyze_node): Use free_parms_ainfo to free stuff.
(ipa_find_agg_cst_for_param): Do not rely on offset ordering.
(ipa_set_node_agg_value_chain): New function.
(ipa_node_removal_hook): Also handle ipa_node_agg_replacements.
(ipa_node_duplication_hook): Likewise.
(ipa_free_all_structures_after_ipa_cp): Also free ipcp_agg_lattice_pool.
(ipa_free_all_structures_after_iinln): Likewise.
(ipa_dump_agg_replacement_values): New function.
(write_agg_replacement_chain): Likewise.
(read_agg_replacement_chain): Likewise.
(ipa_prop_write_all_agg_replacement): Likewise.
(read_replacements_section): Likewise.
(ipa_prop_read_all_agg_replacement): Likewise.
(adjust_agg_replacement_values): Likewise.
(ipcp_transform_function): Likewise.
* ipa-prop.h: Also define heap vector of ipa_agg_jf_item_t and of
ipa_agg_jump_function_t.
(ipa_node_params): Make lattices an array of ipcp_param_lattices.
(ipa_agg_replacement_value): New type and its vector.
(ipa_set_node_agg_value_chain) Declare.
(ipa_node_agg_replacements): Likewise.
(ipa_get_agg_replacements_for_node): New function.
(ipcp_agg_lattice_pool): Declare.
(ipa_dump_agg_replacement_values): Likewise.
(ipa_prop_write_all_agg_replacement): Likewise.
(ipa_prop_read_all_agg_replacement): Likewise.
(ipcp_transform_function): Likewise.
* ipa-inline-analysis.c (estimate_ipcp_clone_size_and_time): Pass around
known aggregates and hints.
* ipa-inline.h: include ipa-prop.h.
(estimate_ipcp_clone_size_and_time): Adjust declaration.
* lto-streamer.h (lto_section_type): New item
LTO_section_ipcp_transform.
* lto-section-in.c (lto_section_name): New element ipcp_trans.
* params.def (PARAM_IPA_CP_LOOP_HINT_BONUS): New parameter.
* Makefile.in (IPA_INLINE_H): New. Use everywhee instead of
ipa-inline.h.
2012-11-07 Uros Bizjak <ubizjak@gmail.com> 2012-11-07 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.c (enum upper_128bits_state): Remove. * config/i386/i386.c (enum upper_128bits_state): Remove.
...@@ -953,6 +953,7 @@ TREE_STREAMER_H = tree-streamer.h $(TREE_H) $(LTO_STREAMER_H) \ ...@@ -953,6 +953,7 @@ TREE_STREAMER_H = tree-streamer.h $(TREE_H) $(LTO_STREAMER_H) \
STREAMER_HOOKS_H = streamer-hooks.h $(TREE_H) STREAMER_HOOKS_H = streamer-hooks.h $(TREE_H)
TREE_VECTORIZER_H = tree-vectorizer.h $(TREE_DATA_REF_H) $(TARGET_H) TREE_VECTORIZER_H = tree-vectorizer.h $(TREE_DATA_REF_H) $(TARGET_H)
IPA_PROP_H = ipa-prop.h $(TREE_H) $(VEC_H) $(CGRAPH_H) $(GIMPLE_H) alloc-pool.h IPA_PROP_H = ipa-prop.h $(TREE_H) $(VEC_H) $(CGRAPH_H) $(GIMPLE_H) alloc-pool.h
IPA_INLINE_H = ipa-inline.h $(IPA_PROP_H)
GSTAB_H = gstab.h stab.def GSTAB_H = gstab.h stab.def
BITMAP_H = bitmap.h $(HASHTAB_H) statistics.h BITMAP_H = bitmap.h $(HASHTAB_H) statistics.h
GCC_PLUGIN_H = gcc-plugin.h highlev-plugin-common.h plugin.def \ GCC_PLUGIN_H = gcc-plugin.h highlev-plugin-common.h plugin.def \
...@@ -2834,14 +2835,14 @@ cgraph.o : cgraph.c $(CONFIG_H) $(SYSTEM_H) coretypes.h dumpfile.h \ ...@@ -2834,14 +2835,14 @@ cgraph.o : cgraph.c $(CONFIG_H) $(SYSTEM_H) coretypes.h dumpfile.h \
gt-cgraph.h intl.h $(BASIC_BLOCK_H) debug.h $(HASHTAB_H) \ gt-cgraph.h intl.h $(BASIC_BLOCK_H) debug.h $(HASHTAB_H) \
$(TREE_INLINE_H) $(TREE_FLOW_H) cif-code.def \ $(TREE_INLINE_H) $(TREE_FLOW_H) cif-code.def \
value-prof.h $(EXCEPT_H) $(IPA_UTILS_H) $(DIAGNOSTIC_CORE_H) \ value-prof.h $(EXCEPT_H) $(IPA_UTILS_H) $(DIAGNOSTIC_CORE_H) \
ipa-inline.h $(LTO_STREAMER_H) $(CFGLOOP_H) $(GIMPLE_PRETTY_PRINT_H) $(IPA_INLINE_H) $(LTO_STREAMER_H) $(CFGLOOP_H) $(GIMPLE_PRETTY_PRINT_H)
cgraphunit.o : cgraphunit.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ cgraphunit.o : cgraphunit.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) langhooks.h $(TREE_INLINE_H) toplev.h $(DIAGNOSTIC_CORE_H) $(FLAGS_H) $(GGC_H) \ $(TREE_H) langhooks.h $(TREE_INLINE_H) toplev.h $(DIAGNOSTIC_CORE_H) $(FLAGS_H) $(GGC_H) \
$(TARGET_H) $(CGRAPH_H) intl.h pointer-set.h $(FUNCTION_H) $(GIMPLE_H) \ $(TARGET_H) $(CGRAPH_H) intl.h pointer-set.h $(FUNCTION_H) $(GIMPLE_H) \
$(TREE_FLOW_H) $(TREE_PASS_H) debug.h $(DIAGNOSTIC_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) debug.h $(DIAGNOSTIC_H) \
$(FIBHEAP_H) output.h $(PARAMS_H) $(RTL_H) $(IPA_PROP_H) \ $(FIBHEAP_H) output.h $(PARAMS_H) $(RTL_H) $(IPA_PROP_H) \
gt-cgraphunit.h tree-iterator.h $(COVERAGE_H) $(TREE_DUMP_H) \ gt-cgraphunit.h tree-iterator.h $(COVERAGE_H) $(TREE_DUMP_H) \
$(GIMPLE_PRETTY_PRINT_H) ipa-inline.h $(IPA_UTILS_H) \ $(GIMPLE_PRETTY_PRINT_H) $(IPA_INLINE_H) $(IPA_UTILS_H) \
$(LTO_STREAMER_H) output.h $(REGSET_H) $(EXCEPT_H) $(GCC_PLUGIN_H) plugin.h $(LTO_STREAMER_H) output.h $(REGSET_H) $(EXCEPT_H) $(GCC_PLUGIN_H) plugin.h
cgraphclones.o : cgraphclones.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ cgraphclones.o : cgraphclones.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) langhooks.h $(TREE_INLINE_H) toplev.h $(DIAGNOSTIC_CORE_H) $(FLAGS_H) $(GGC_H) \ $(TREE_H) langhooks.h $(TREE_INLINE_H) toplev.h $(DIAGNOSTIC_CORE_H) $(FLAGS_H) $(GGC_H) \
...@@ -2849,12 +2850,12 @@ cgraphclones.o : cgraphclones.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ ...@@ -2849,12 +2850,12 @@ cgraphclones.o : cgraphclones.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_FLOW_H) $(TREE_PASS_H) debug.h $(DIAGNOSTIC_H) $(TREE_DUMP_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) debug.h $(DIAGNOSTIC_H) $(TREE_DUMP_H) \
$(PARAMS_H) $(RTL_H) $(IPA_PROP_H) \ $(PARAMS_H) $(RTL_H) $(IPA_PROP_H) \
tree-iterator.h $(COVERAGE_H) \ tree-iterator.h $(COVERAGE_H) \
$(GIMPLE_PRETTY_PRINT_H) ipa-inline.h $(IPA_UTILS_H) \ $(GIMPLE_PRETTY_PRINT_H) $(IPA_INLINE_H) $(IPA_UTILS_H) \
$(LTO_STREAMER_H) $(EXCEPT_H) $(GCC_PLUGIN_H) gt-cgraphclones.h $(LTO_STREAMER_H) $(EXCEPT_H) $(GCC_PLUGIN_H) gt-cgraphclones.h
cgraphbuild.o : cgraphbuild.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ cgraphbuild.o : cgraphbuild.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) langhooks.h $(CGRAPH_H) intl.h pointer-set.h $(GIMPLE_H) \ $(TREE_H) langhooks.h $(CGRAPH_H) intl.h pointer-set.h $(GIMPLE_H) \
$(TREE_FLOW_H) $(TREE_PASS_H) $(IPA_UTILS_H) $(EXCEPT_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) $(IPA_UTILS_H) $(EXCEPT_H) \
ipa-inline.h $(IPA_INLINE_H)
varpool.o : varpool.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ varpool.o : varpool.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) $(CGRAPH_H) langhooks.h $(DIAGNOSTIC_CORE_H) $(HASHTAB_H) \ $(TREE_H) $(CGRAPH_H) langhooks.h $(DIAGNOSTIC_CORE_H) $(HASHTAB_H) \
$(GGC_H) $(TIMEVAR_H) debug.h $(TARGET_H) output.h $(GIMPLE_H) \ $(GGC_H) $(TIMEVAR_H) debug.h $(TARGET_H) output.h $(GIMPLE_H) \
...@@ -2874,21 +2875,22 @@ ipa-ref.o : ipa-ref.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ ...@@ -2874,21 +2875,22 @@ ipa-ref.o : ipa-ref.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
ipa-cp.o : ipa-cp.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ ipa-cp.o : ipa-cp.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TREE_H) $(TARGET_H) $(GIMPLE_H) $(CGRAPH_H) $(IPA_PROP_H) $(TREE_FLOW_H) \ $(TREE_H) $(TARGET_H) $(GIMPLE_H) $(CGRAPH_H) $(IPA_PROP_H) $(TREE_FLOW_H) \
$(TREE_PASS_H) $(FLAGS_H) $(DIAGNOSTIC_H) \ $(TREE_PASS_H) $(FLAGS_H) $(DIAGNOSTIC_H) \
$(TREE_INLINE_H) $(PARAMS_H) $(TREE_PRETTY_PRINT_H) ipa-inline.h $(TREE_INLINE_H) $(PARAMS_H) $(TREE_PRETTY_PRINT_H) $(IPA_INLINE_H)
ipa-split.o : ipa-split.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ ipa-split.o : ipa-split.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TREE_H) $(TARGET_H) $(CGRAPH_H) $(IPA_PROP_H) $(TREE_FLOW_H) \ $(TREE_H) $(TARGET_H) $(CGRAPH_H) $(IPA_PROP_H) $(TREE_FLOW_H) \
$(TREE_PASS_H) $(FLAGS_H) $(DIAGNOSTIC_H) $(TREE_DUMP_H) \ $(TREE_PASS_H) $(FLAGS_H) $(DIAGNOSTIC_H) $(TREE_DUMP_H) \
$(TREE_INLINE_H) $(PARAMS_H) $(GIMPLE_PRETTY_PRINT_H) ipa-inline.h $(TREE_INLINE_H) $(PARAMS_H) $(GIMPLE_PRETTY_PRINT_H) $(IPA_INLINE_H)
ipa-inline.o : ipa-inline.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ ipa-inline.o : ipa-inline.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) langhooks.h $(TREE_INLINE_H) $(FLAGS_H) $(CGRAPH_H) intl.h \ $(TREE_H) langhooks.h $(TREE_INLINE_H) $(FLAGS_H) $(CGRAPH_H) intl.h \
$(DIAGNOSTIC_H) $(FIBHEAP_H) $(PARAMS_H) $(TREE_PASS_H) \ $(DIAGNOSTIC_H) $(FIBHEAP_H) $(PARAMS_H) $(TREE_PASS_H) \
$(COVERAGE_H) $(GGC_H) $(TREE_FLOW_H) $(RTL_H) $(IPA_PROP_H) \ $(COVERAGE_H) $(GGC_H) $(TREE_FLOW_H) $(RTL_H) $(IPA_PROP_H) \
$(EXCEPT_H) $(GIMPLE_PRETTY_PRINT_H) ipa-inline.h $(TARGET_H) $(IPA_UTILS_H) $(EXCEPT_H) $(GIMPLE_PRETTY_PRINT_H) $(IPA_INLINE_H) $(TARGET_H) \
$(IPA_UTILS_H)
ipa-inline-analysis.o : ipa-inline-analysis.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ ipa-inline-analysis.o : ipa-inline-analysis.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) langhooks.h $(TREE_INLINE_H) $(FLAGS_H) $(CGRAPH_H) intl.h \ $(TREE_H) langhooks.h $(TREE_INLINE_H) $(FLAGS_H) $(CGRAPH_H) intl.h \
$(DIAGNOSTIC_H) $(PARAMS_H) $(TREE_PASS_H) $(CFGLOOP_H) \ $(DIAGNOSTIC_H) $(PARAMS_H) $(TREE_PASS_H) $(CFGLOOP_H) \
$(HASHTAB_H) $(COVERAGE_H) $(GGC_H) $(TREE_FLOW_H) $(IPA_PROP_H) \ $(HASHTAB_H) $(COVERAGE_H) $(GGC_H) $(TREE_FLOW_H) $(IPA_PROP_H) \
$(GIMPLE_PRETTY_PRINT_H) ipa-inline.h $(LTO_STREAMER_H) $(DATA_STREAMER_H) \ $(GIMPLE_PRETTY_PRINT_H) $(IPA_INLINE_H) $(LTO_STREAMER_H) $(DATA_STREAMER_H) \
$(TREE_STREAMER_H) $(TREE_STREAMER_H)
ipa-inline-transform.o : ipa-inline-transform.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ ipa-inline-transform.o : ipa-inline-transform.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) langhooks.h $(TREE_INLINE_H) $(FLAGS_H) $(CGRAPH_H) intl.h \ $(TREE_H) langhooks.h $(TREE_INLINE_H) $(FLAGS_H) $(CGRAPH_H) intl.h \
......
...@@ -125,6 +125,9 @@ struct ipcp_value; ...@@ -125,6 +125,9 @@ struct ipcp_value;
struct ipcp_value_source struct ipcp_value_source
{ {
/* Aggregate offset of the source, negative if the source is scalar value of
the argument itself. */
HOST_WIDE_INT offset;
/* The incoming edge that brought the value. */ /* The incoming edge that brought the value. */
struct cgraph_edge *cs; struct cgraph_edge *cs;
/* If the jump function that resulted into his value was a pass-through or an /* If the jump function that resulted into his value was a pass-through or an
...@@ -173,15 +176,10 @@ struct ipcp_value ...@@ -173,15 +176,10 @@ struct ipcp_value
bool on_stack; bool on_stack;
}; };
/* Allocation pools for values and their sources in ipa-cp. */ /* Lattice describing potential values of a formal parameter of a function, or
a part of an aggreagate. TOP is represented by a lattice with zero values
alloc_pool ipcp_values_pool; and with contains_variable and bottom flags cleared. BOTTOM is represented
alloc_pool ipcp_sources_pool; by a lattice with the bottom flag set. In that case, values and
/* Lattice describing potential values of a formal parameter of a function and
some of their other properties. TOP is represented by a lattice with zero
values and with contains_variable and bottom flags cleared. BOTTOM is
represented by a lattice with the bottom flag set. In that case, values and
contains_variable flag should be disregarded. */ contains_variable flag should be disregarded. */
struct ipcp_lattice struct ipcp_lattice
...@@ -192,15 +190,58 @@ struct ipcp_lattice ...@@ -192,15 +190,58 @@ struct ipcp_lattice
struct ipcp_value *values; struct ipcp_value *values;
/* Number of known values and types in this lattice. */ /* Number of known values and types in this lattice. */
int values_count; int values_count;
/* The lattice contains a variable component (in addition to values). */ /* The lattice contains a variable component (in addition to values). */
bool contains_variable; bool contains_variable;
/* The value of the lattice is bottom (i.e. variable and unusable for any /* The value of the lattice is bottom (i.e. variable and unusable for any
propagation). */ propagation). */
bool bottom; bool bottom;
};
/* Lattice with an offset to describe a part of an aggregate. */
struct ipcp_agg_lattice : public ipcp_lattice
{
/* Offset that is being described by this lattice. */
HOST_WIDE_INT offset;
/* Size so that we don't have to re-compute it every time we traverse the
list. Must correspond to TYPE_SIZE of all lat values. */
HOST_WIDE_INT size;
/* Next element of the linked list. */
struct ipcp_agg_lattice *next;
};
/* Structure containing lattices for a parameter itself and for pieces of
aggregates that are passed in the parameter or by a reference in a parameter
plus some other useful flags. */
struct ipcp_param_lattices
{
/* Lattice describing the value of the parameter itself. */
struct ipcp_lattice itself;
/* Lattices describing aggregate parts. */
struct ipcp_agg_lattice *aggs;
/* Number of aggregate lattices */
int aggs_count;
/* True if aggregate data were passed by reference (as opposed to by
value). */
bool aggs_by_ref;
/* All aggregate lattices contain a variable component (in addition to
values). */
bool aggs_contain_variable;
/* The value of all aggregate lattices is bottom (i.e. variable and unusable
for any propagation). */
bool aggs_bottom;
/* There is a virtual call based on this parameter. */ /* There is a virtual call based on this parameter. */
bool virt_call; bool virt_call;
}; };
/* Allocation pools for values and their sources in ipa-cp. */
alloc_pool ipcp_values_pool;
alloc_pool ipcp_sources_pool;
alloc_pool ipcp_agg_lattice_pool;
/* Maximal count found in program. */ /* Maximal count found in program. */
static gcov_type max_count; static gcov_type max_count;
...@@ -213,10 +254,10 @@ static long overall_size, max_new_size; ...@@ -213,10 +254,10 @@ static long overall_size, max_new_size;
static struct ipcp_value *values_topo; static struct ipcp_value *values_topo;
/* Return the lattice corresponding to the Ith formal parameter of the function /* Return the param lattices structure corresponding to the Ith formal
described by INFO. */ parameter of the function described by INFO. */
static inline struct ipcp_lattice * static inline struct ipcp_param_lattices *
ipa_get_lattice (struct ipa_node_params *info, int i) ipa_get_parm_lattices (struct ipa_node_params *info, int i)
{ {
gcc_assert (i >= 0 && i < ipa_get_param_count (info)); gcc_assert (i >= 0 && i < ipa_get_param_count (info));
gcc_checking_assert (!info->ipcp_orig_node); gcc_checking_assert (!info->ipcp_orig_node);
...@@ -224,6 +265,15 @@ ipa_get_lattice (struct ipa_node_params *info, int i) ...@@ -224,6 +265,15 @@ ipa_get_lattice (struct ipa_node_params *info, int i)
return &(info->lattices[i]); return &(info->lattices[i]);
} }
/* Return the lattice corresponding to the scalar value of the Ith formal
parameter of the function described by INFO. */
static inline struct ipcp_lattice *
ipa_get_scalar_lat (struct ipa_node_params *info, int i)
{
struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
return &plats->itself;
}
/* Return whether LAT is a lattice with a single constant and without an /* Return whether LAT is a lattice with a single constant and without an
undefined value. */ undefined value. */
...@@ -274,6 +324,66 @@ print_ipcp_constant_value (FILE * f, tree v) ...@@ -274,6 +324,66 @@ print_ipcp_constant_value (FILE * f, tree v)
print_generic_expr (f, v, 0); print_generic_expr (f, v, 0);
} }
/* Print a lattice LAT to F. */
static void
print_lattice (FILE * f, struct ipcp_lattice *lat,
bool dump_sources, bool dump_benefits)
{
struct ipcp_value *val;
bool prev = false;
if (lat->bottom)
{
fprintf (f, "BOTTOM\n");
return;
}
if (!lat->values_count && !lat->contains_variable)
{
fprintf (f, "TOP\n");
return;
}
if (lat->contains_variable)
{
fprintf (f, "VARIABLE");
prev = true;
if (dump_benefits)
fprintf (f, "\n");
}
for (val = lat->values; val; val = val->next)
{
if (dump_benefits && prev)
fprintf (f, " ");
else if (!dump_benefits && prev)
fprintf (f, ", ");
else
prev = true;
print_ipcp_constant_value (f, val->value);
if (dump_sources)
{
struct ipcp_value_source *s;
fprintf (f, " [from:");
for (s = val->sources; s; s = s->next)
fprintf (f, " %i(%i)", s->cs->caller->uid,s->cs->frequency);
fprintf (f, "]");
}
if (dump_benefits)
fprintf (f, " [loc_time: %i, loc_size: %i, "
"prop_time: %i, prop_size: %i]\n",
val->local_time_benefit, val->local_size_cost,
val->prop_time_benefit, val->prop_size_cost);
}
if (!dump_benefits)
fprintf (f, "\n");
}
/* Print all ipcp_lattices of all functions to F. */ /* Print all ipcp_lattices of all functions to F. */
static void static void
...@@ -292,60 +402,27 @@ print_all_lattices (FILE * f, bool dump_sources, bool dump_benefits) ...@@ -292,60 +402,27 @@ print_all_lattices (FILE * f, bool dump_sources, bool dump_benefits)
count = ipa_get_param_count (info); count = ipa_get_param_count (info);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
struct ipcp_lattice *lat = ipa_get_lattice (info, i); struct ipcp_agg_lattice *aglat;
struct ipcp_value *val; struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
bool prev = false;
fprintf (f, " param [%d]: ", i); fprintf (f, " param [%d]: ", i);
if (lat->bottom) print_lattice (f, &plats->itself, dump_sources, dump_benefits);
{
fprintf (f, "BOTTOM\n");
continue;
}
if (!lat->values_count && !lat->contains_variable) if (plats->virt_call)
fprintf (f, " virt_call flag set\n");
if (plats->aggs_bottom)
{ {
fprintf (f, "TOP\n"); fprintf (f, " AGGS BOTTOM\n");
continue; continue;
} }
if (plats->aggs_contain_variable)
if (lat->contains_variable) fprintf (f, " AGGS VARIABLE\n");
for (aglat = plats->aggs; aglat; aglat = aglat->next)
{ {
fprintf (f, "VARIABLE"); fprintf (f, " %soffset " HOST_WIDE_INT_PRINT_DEC ": ",
prev = true; plats->aggs_by_ref ? "ref " : "", aglat->offset);
if (dump_benefits) print_lattice (f, aglat, dump_sources, dump_benefits);
fprintf (f, "\n");
} }
for (val = lat->values; val; val = val->next)
{
if (dump_benefits && prev)
fprintf (f, " ");
else if (!dump_benefits && prev)
fprintf (f, ", ");
else
prev = true;
print_ipcp_constant_value (f, val->value);
if (dump_sources)
{
struct ipcp_value_source *s;
fprintf (f, " [from:");
for (s = val->sources; s; s = s->next)
fprintf (f, " %i(%i)", s->cs->caller->uid,s->cs->frequency);
fprintf (f, "]");
}
if (dump_benefits)
fprintf (f, " [loc_time: %i, loc_size: %i, "
"prop_time: %i, prop_size: %i]\n",
val->local_time_benefit, val->local_size_cost,
val->prop_time_benefit, val->prop_size_cost);
}
if (!dump_benefits)
fprintf (f, "\n");
} }
} }
} }
...@@ -578,6 +655,40 @@ set_lattice_contains_variable (struct ipcp_lattice *lat) ...@@ -578,6 +655,40 @@ set_lattice_contains_variable (struct ipcp_lattice *lat)
return ret; return ret;
} }
/* Set all aggegate lattices in PLATS to bottom and return true if they were
not previously set as such. */
static inline bool
set_agg_lats_to_bottom (struct ipcp_param_lattices *plats)
{
bool ret = !plats->aggs_bottom;
plats->aggs_bottom = true;
return ret;
}
/* Mark all aggegate lattices in PLATS as containing an unknown value and
return true if they were not previously marked as such. */
static inline bool
set_agg_lats_contain_variable (struct ipcp_param_lattices *plats)
{
bool ret = !plats->aggs_contain_variable;
plats->aggs_contain_variable = true;
return ret;
}
/* Mark bot aggregate and scalar lattices as containing an unknown variable,
return true is any of them has not been marked as such so far. */
static inline bool
set_all_contains_variable (struct ipcp_param_lattices *plats)
{
bool ret = !plats->itself.contains_variable || !plats->aggs_contain_variable;
plats->itself.contains_variable = true;
plats->aggs_contain_variable = true;
return ret;
}
/* Initialize ipcp_lattices. */ /* Initialize ipcp_lattices. */
static void static void
...@@ -605,11 +716,14 @@ initialize_node_lattices (struct cgraph_node *node) ...@@ -605,11 +716,14 @@ initialize_node_lattices (struct cgraph_node *node)
{ {
for (i = 0; i < ipa_get_param_count (info) ; i++) for (i = 0; i < ipa_get_param_count (info) ; i++)
{ {
struct ipcp_lattice *lat = ipa_get_lattice (info, i); struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
if (disable) if (disable)
set_lattice_to_bottom (lat); {
set_lattice_to_bottom (&plats->itself);
set_agg_lats_to_bottom (plats);
}
else else
set_lattice_contains_variable (lat); set_all_contains_variable (plats);
} }
if (dump_file && (dump_flags & TDF_DETAILS) if (dump_file && (dump_flags & TDF_DETAILS)
&& node->alias && node->thunk.thunk_p) && node->alias && node->thunk.thunk_p)
...@@ -622,7 +736,8 @@ initialize_node_lattices (struct cgraph_node *node) ...@@ -622,7 +736,8 @@ initialize_node_lattices (struct cgraph_node *node)
if (ie->indirect_info->polymorphic) if (ie->indirect_info->polymorphic)
{ {
gcc_checking_assert (ie->indirect_info->param_index >= 0); gcc_checking_assert (ie->indirect_info->param_index >= 0);
ipa_get_lattice (info, ie->indirect_info->param_index)->virt_call = 1; ipa_get_parm_lattices (info,
ie->indirect_info->param_index)->virt_call = 1;
} }
} }
...@@ -725,7 +840,7 @@ ipa_value_from_jfunc (struct ipa_node_params *info, struct ipa_jump_func *jfunc) ...@@ -725,7 +840,7 @@ ipa_value_from_jfunc (struct ipa_node_params *info, struct ipa_jump_func *jfunc)
gcc_checking_assert (!flag_ipa_cp); gcc_checking_assert (!flag_ipa_cp);
return NULL_TREE; return NULL_TREE;
} }
lat = ipa_get_lattice (info, idx); lat = ipa_get_scalar_lat (info, idx);
if (!ipa_lat_is_single_const (lat)) if (!ipa_lat_is_single_const (lat))
return NULL_TREE; return NULL_TREE;
input = lat->values->value; input = lat->values->value;
...@@ -760,7 +875,7 @@ ipcp_verify_propagated_values (void) ...@@ -760,7 +875,7 @@ ipcp_verify_propagated_values (void)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
struct ipcp_lattice *lat = ipa_get_lattice (info, i); struct ipcp_lattice *lat = ipa_get_scalar_lat (info, i);
if (!lat->bottom if (!lat->bottom
&& !lat->contains_variable && !lat->contains_variable
...@@ -804,15 +919,18 @@ values_equal_for_ipcp_p (tree x, tree y) ...@@ -804,15 +919,18 @@ values_equal_for_ipcp_p (tree x, tree y)
/* Add a new value source to VAL, marking that a value comes from edge CS and /* Add a new value source to VAL, marking that a value comes from edge CS and
(if the underlying jump function is a pass-through or an ancestor one) from (if the underlying jump function is a pass-through or an ancestor one) from
a caller value SRC_VAL of a caller parameter described by SRC_INDEX. */ a caller value SRC_VAL of a caller parameter described by SRC_INDEX. OFFSET
is negative if the source was the scalar value of the parameter itself or
the offset within an aggregate. */
static void static void
add_value_source (struct ipcp_value *val, struct cgraph_edge *cs, add_value_source (struct ipcp_value *val, struct cgraph_edge *cs,
struct ipcp_value *src_val, int src_idx) struct ipcp_value *src_val, int src_idx, HOST_WIDE_INT offset)
{ {
struct ipcp_value_source *src; struct ipcp_value_source *src;
src = (struct ipcp_value_source *) pool_alloc (ipcp_sources_pool); src = (struct ipcp_value_source *) pool_alloc (ipcp_sources_pool);
src->offset = offset;
src->cs = cs; src->cs = cs;
src->val = src_val; src->val = src_val;
src->index = src_idx; src->index = src_idx;
...@@ -821,22 +939,20 @@ add_value_source (struct ipcp_value *val, struct cgraph_edge *cs, ...@@ -821,22 +939,20 @@ add_value_source (struct ipcp_value *val, struct cgraph_edge *cs,
val->sources = src; val->sources = src;
} }
/* Try to add NEWVAL to LAT, potentially creating a new struct ipcp_value for /* Try to add NEWVAL to LAT, potentially creating a new struct ipcp_value for
it. CS, SRC_VAL and SRC_INDEX are meant for add_value_source and have the it. CS, SRC_VAL SRC_INDEX and OFFSET are meant for add_value_source and
same meaning. */ have the same meaning. */
static bool static bool
add_value_to_lattice (struct ipcp_lattice *lat, tree newval, add_value_to_lattice (struct ipcp_lattice *lat, tree newval,
struct cgraph_edge *cs, struct ipcp_value *src_val, struct cgraph_edge *cs, struct ipcp_value *src_val,
int src_idx) int src_idx, HOST_WIDE_INT offset)
{ {
struct ipcp_value *val; struct ipcp_value *val;
if (lat->bottom) if (lat->bottom)
return false; return false;
for (val = lat->values; val; val = val->next) for (val = lat->values; val; val = val->next)
if (values_equal_for_ipcp_p (val->value, newval)) if (values_equal_for_ipcp_p (val->value, newval))
{ {
...@@ -850,7 +966,7 @@ add_value_to_lattice (struct ipcp_lattice *lat, tree newval, ...@@ -850,7 +966,7 @@ add_value_to_lattice (struct ipcp_lattice *lat, tree newval,
return false; return false;
} }
add_value_source (val, cs, src_val, src_idx); add_value_source (val, cs, src_val, src_idx, offset);
return false; return false;
} }
...@@ -876,13 +992,25 @@ add_value_to_lattice (struct ipcp_lattice *lat, tree newval, ...@@ -876,13 +992,25 @@ add_value_to_lattice (struct ipcp_lattice *lat, tree newval,
val = (struct ipcp_value *) pool_alloc (ipcp_values_pool); val = (struct ipcp_value *) pool_alloc (ipcp_values_pool);
memset (val, 0, sizeof (*val)); memset (val, 0, sizeof (*val));
add_value_source (val, cs, src_val, src_idx); add_value_source (val, cs, src_val, src_idx, offset);
val->value = newval; val->value = newval;
val->next = lat->values; val->next = lat->values;
lat->values = val; lat->values = val;
return true; return true;
} }
/* Like above but passes a special value of offset to distinguish that the
origin is the scalar value of the parameter rather than a part of an
aggregate. */
static inline bool
add_scalar_value_to_lattice (struct ipcp_lattice *lat, tree newval,
struct cgraph_edge *cs,
struct ipcp_value *src_val, int src_idx)
{
return add_value_to_lattice (lat, newval, cs, src_val, src_idx, -1);
}
/* Propagate values through a pass-through jump function JFUNC associated with /* Propagate values through a pass-through jump function JFUNC associated with
edge CS, taking values from SRC_LAT and putting them into DEST_LAT. SRC_IDX edge CS, taking values from SRC_LAT and putting them into DEST_LAT. SRC_IDX
is the index of the source parameter. */ is the index of the source parameter. */
...@@ -899,8 +1027,8 @@ propagate_vals_accross_pass_through (struct cgraph_edge *cs, ...@@ -899,8 +1027,8 @@ propagate_vals_accross_pass_through (struct cgraph_edge *cs,
if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR) if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
for (src_val = src_lat->values; src_val; src_val = src_val->next) for (src_val = src_lat->values; src_val; src_val = src_val->next)
ret |= add_value_to_lattice (dest_lat, src_val->value, cs, ret |= add_scalar_value_to_lattice (dest_lat, src_val->value, cs,
src_val, src_idx); src_val, src_idx);
/* Do not create new values when propagating within an SCC because if there /* Do not create new values when propagating within an SCC because if there
are arithmetic functions with circular dependencies, there is infinite are arithmetic functions with circular dependencies, there is infinite
number of them and we would just make lattices bottom. */ number of them and we would just make lattices bottom. */
...@@ -919,7 +1047,8 @@ propagate_vals_accross_pass_through (struct cgraph_edge *cs, ...@@ -919,7 +1047,8 @@ propagate_vals_accross_pass_through (struct cgraph_edge *cs,
cstval = ipa_get_jf_pass_through_result (jfunc, cstval); cstval = ipa_get_jf_pass_through_result (jfunc, cstval);
if (cstval) if (cstval)
ret |= add_value_to_lattice (dest_lat, cstval, cs, src_val, src_idx); ret |= add_scalar_value_to_lattice (dest_lat, cstval, cs, src_val,
src_idx);
else else
ret |= set_lattice_contains_variable (dest_lat); ret |= set_lattice_contains_variable (dest_lat);
} }
...@@ -949,7 +1078,7 @@ propagate_vals_accross_ancestor (struct cgraph_edge *cs, ...@@ -949,7 +1078,7 @@ propagate_vals_accross_ancestor (struct cgraph_edge *cs,
tree t = ipa_get_jf_ancestor_result (jfunc, src_val->value); tree t = ipa_get_jf_ancestor_result (jfunc, src_val->value);
if (t) if (t)
ret |= add_value_to_lattice (dest_lat, t, cs, src_val, src_idx); ret |= add_scalar_value_to_lattice (dest_lat, t, cs, src_val, src_idx);
else else
ret |= set_lattice_contains_variable (dest_lat); ret |= set_lattice_contains_variable (dest_lat);
} }
...@@ -957,13 +1086,13 @@ propagate_vals_accross_ancestor (struct cgraph_edge *cs, ...@@ -957,13 +1086,13 @@ propagate_vals_accross_ancestor (struct cgraph_edge *cs,
return ret; return ret;
} }
/* Propagate values across jump function JFUNC that is associated with edge CS /* Propagate scalar values across jump function JFUNC that is associated with
and put the values into DEST_LAT. */ edge CS and put the values into DEST_LAT. */
static bool static bool
propagate_accross_jump_function (struct cgraph_edge *cs, propagate_scalar_accross_jump_function (struct cgraph_edge *cs,
struct ipa_jump_func *jfunc, struct ipa_jump_func *jfunc,
struct ipcp_lattice *dest_lat) struct ipcp_lattice *dest_lat)
{ {
if (dest_lat->bottom) if (dest_lat->bottom)
return false; return false;
...@@ -981,7 +1110,7 @@ propagate_accross_jump_function (struct cgraph_edge *cs, ...@@ -981,7 +1110,7 @@ propagate_accross_jump_function (struct cgraph_edge *cs,
} }
else else
val = ipa_get_jf_constant (jfunc); val = ipa_get_jf_constant (jfunc);
return add_value_to_lattice (dest_lat, val, cs, NULL, 0); return add_scalar_value_to_lattice (dest_lat, val, cs, NULL, 0);
} }
else if (jfunc->type == IPA_JF_PASS_THROUGH else if (jfunc->type == IPA_JF_PASS_THROUGH
|| jfunc->type == IPA_JF_ANCESTOR) || jfunc->type == IPA_JF_ANCESTOR)
...@@ -996,7 +1125,7 @@ propagate_accross_jump_function (struct cgraph_edge *cs, ...@@ -996,7 +1125,7 @@ propagate_accross_jump_function (struct cgraph_edge *cs,
else else
src_idx = ipa_get_jf_ancestor_formal_id (jfunc); src_idx = ipa_get_jf_ancestor_formal_id (jfunc);
src_lat = ipa_get_lattice (caller_info, src_idx); src_lat = ipa_get_scalar_lat (caller_info, src_idx);
if (src_lat->bottom) if (src_lat->bottom)
return set_lattice_contains_variable (dest_lat); return set_lattice_contains_variable (dest_lat);
...@@ -1024,6 +1153,257 @@ propagate_accross_jump_function (struct cgraph_edge *cs, ...@@ -1024,6 +1153,257 @@ propagate_accross_jump_function (struct cgraph_edge *cs,
return set_lattice_contains_variable (dest_lat); return set_lattice_contains_variable (dest_lat);
} }
/* If DEST_PLATS already has aggregate items, check that aggs_by_ref matches
NEW_AGGS_BY_REF and if not, mark all aggs as bottoms and return true (in all
other cases, return false). If there are no aggregate items, set
aggs_by_ref to NEW_AGGS_BY_REF. */
static bool
set_check_aggs_by_ref (struct ipcp_param_lattices *dest_plats,
bool new_aggs_by_ref)
{
if (dest_plats->aggs)
{
if (dest_plats->aggs_by_ref != new_aggs_by_ref)
{
set_agg_lats_to_bottom (dest_plats);
return true;
}
}
else
dest_plats->aggs_by_ref = new_aggs_by_ref;
return false;
}
/* Walk aggregate lattices in DEST_PLATS from ***AGLAT on, until ***aglat is an
already existing lattice for the given OFFSET and SIZE, marking all skipped
lattices as containing variable and checking for overlaps. If there is no
already existing lattice for the OFFSET and VAL_SIZE, create one, initialize
it with offset, size and contains_variable to PRE_EXISTING, and return true,
unless there are too many already. If there are two many, return false. If
there are overlaps turn whole DEST_PLATS to bottom and return false. If any
skipped lattices were newly marked as containing variable, set *CHANGE to
true. */
static bool
merge_agg_lats_step (struct ipcp_param_lattices *dest_plats,
HOST_WIDE_INT offset, HOST_WIDE_INT val_size,
struct ipcp_agg_lattice ***aglat,
bool pre_existing, bool *change)
{
gcc_checking_assert (offset >= 0);
while (**aglat && (**aglat)->offset < offset)
{
if ((**aglat)->offset + (**aglat)->size > offset)
{
set_agg_lats_to_bottom (dest_plats);
return false;
}
*change |= set_lattice_contains_variable (**aglat);
*aglat = &(**aglat)->next;
}
if (**aglat && (**aglat)->offset == offset)
{
if ((**aglat)->size != val_size
|| ((**aglat)->next
&& (**aglat)->next->offset < offset + val_size))
{
set_agg_lats_to_bottom (dest_plats);
return false;
}
gcc_checking_assert (!(**aglat)->next
|| (**aglat)->next->offset >= offset + val_size);
return true;
}
else
{
struct ipcp_agg_lattice *new_al;
if (**aglat && (**aglat)->offset < offset + val_size)
{
set_agg_lats_to_bottom (dest_plats);
return false;
}
if (dest_plats->aggs_count == PARAM_VALUE (PARAM_IPA_MAX_AGG_ITEMS))
return false;
dest_plats->aggs_count++;
new_al = (struct ipcp_agg_lattice *) pool_alloc (ipcp_agg_lattice_pool);
memset (new_al, 0, sizeof (*new_al));
new_al->offset = offset;
new_al->size = val_size;
new_al->contains_variable = pre_existing;
new_al->next = **aglat;
**aglat = new_al;
return true;
}
}
/* Set all AGLAT and all other aggregate lattices reachable by next pointers as
containing an unknown value. */
static bool
set_chain_of_aglats_contains_variable (struct ipcp_agg_lattice *aglat)
{
bool ret = false;
while (aglat)
{
ret |= set_lattice_contains_variable (aglat);
aglat = aglat->next;
}
return ret;
}
/* Merge existing aggregate lattices in SRC_PLATS to DEST_PLATS, subtracting
DELTA_OFFSET. CS is the call graph edge and SRC_IDX the index of the source
parameter used for lattice value sources. Return true if DEST_PLATS changed
in any way. */
static bool
merge_aggregate_lattices (struct cgraph_edge *cs,
struct ipcp_param_lattices *dest_plats,
struct ipcp_param_lattices *src_plats,
int src_idx, HOST_WIDE_INT offset_delta)
{
bool pre_existing = dest_plats->aggs != NULL;
struct ipcp_agg_lattice **dst_aglat;
bool ret = false;
if (set_check_aggs_by_ref (dest_plats, src_plats->aggs_by_ref))
return true;
if (src_plats->aggs_bottom)
return set_agg_lats_contain_variable (dest_plats);
dst_aglat = &dest_plats->aggs;
for (struct ipcp_agg_lattice *src_aglat = src_plats->aggs;
src_aglat;
src_aglat = src_aglat->next)
{
HOST_WIDE_INT new_offset = src_aglat->offset - offset_delta;
if (new_offset < 0)
continue;
if (merge_agg_lats_step (dest_plats, new_offset, src_aglat->size,
&dst_aglat, pre_existing, &ret))
{
struct ipcp_agg_lattice *new_al = *dst_aglat;
dst_aglat = &(*dst_aglat)->next;
if (src_aglat->bottom)
{
ret |= set_lattice_contains_variable (new_al);
continue;
}
if (src_aglat->contains_variable)
ret |= set_lattice_contains_variable (new_al);
for (struct ipcp_value *val = src_aglat->values;
val;
val = val->next)
ret |= add_value_to_lattice (new_al, val->value, cs, val, src_idx,
src_aglat->offset);
}
else if (dest_plats->aggs_bottom)
return true;
}
ret |= set_chain_of_aglats_contains_variable (*dst_aglat);
return ret;
}
/* Propagate scalar values across jump function JFUNC that is associated with
edge CS and put the values into DEST_LAT. */
static bool
propagate_aggs_accross_jump_function (struct cgraph_edge *cs,
struct ipa_jump_func *jfunc,
struct ipcp_param_lattices *dest_plats)
{
bool ret = false;
if (dest_plats->aggs_bottom)
return false;
if (jfunc->type == IPA_JF_PASS_THROUGH
&& ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
{
struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
int src_idx = ipa_get_jf_pass_through_formal_id (jfunc);
struct ipcp_param_lattices *src_plats;
src_plats = ipa_get_parm_lattices (caller_info, src_idx);
if (src_plats->aggs
&& (!src_plats->aggs_by_ref
|| ipa_get_jf_pass_through_agg_preserved (jfunc)))
{
/* Currently we do not produce clobber aggregate jump
functions, replace with merging when we do. */
gcc_assert (!jfunc->agg.items);
ret |= merge_aggregate_lattices (cs, dest_plats, src_plats,
src_idx, 0);
}
else
ret |= set_agg_lats_contain_variable (dest_plats);
}
else if (jfunc->type == IPA_JF_ANCESTOR
&& ipa_get_jf_ancestor_agg_preserved (jfunc))
{
struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
int src_idx = ipa_get_jf_ancestor_formal_id (jfunc);
struct ipcp_param_lattices *src_plats;
src_plats = ipa_get_parm_lattices (caller_info, src_idx);
if (src_plats->aggs && src_plats->aggs_by_ref)
{
/* Currently we do not produce clobber aggregate jump
functions, replace with merging when we do. */
gcc_assert (!jfunc->agg.items);
ret |= merge_aggregate_lattices (cs, dest_plats, src_plats, src_idx,
ipa_get_jf_ancestor_offset (jfunc));
}
else if (!src_plats->aggs_by_ref)
ret |= set_agg_lats_to_bottom (dest_plats);
else
ret |= set_agg_lats_contain_variable (dest_plats);
}
else if (jfunc->agg.items)
{
bool pre_existing = dest_plats->aggs != NULL;
struct ipcp_agg_lattice **aglat = &dest_plats->aggs;
struct ipa_agg_jf_item *item;
int i;
if (set_check_aggs_by_ref (dest_plats, jfunc->agg.by_ref))
return true;
FOR_EACH_VEC_ELT (ipa_agg_jf_item_t, jfunc->agg.items, i, item)
{
HOST_WIDE_INT val_size;
if (item->offset < 0)
continue;
gcc_checking_assert (is_gimple_ip_invariant (item->value));
val_size = tree_low_cst (TYPE_SIZE (TREE_TYPE (item->value)), 1);
if (merge_agg_lats_step (dest_plats, item->offset, val_size,
&aglat, pre_existing, &ret))
{
ret |= add_value_to_lattice (*aglat, item->value, cs, NULL, 0, 0);
aglat = &(*aglat)->next;
}
else if (dest_plats->aggs_bottom)
return true;
}
ret |= set_chain_of_aglats_contains_variable (*aglat);
}
else
ret |= set_agg_lats_contain_variable (dest_plats);
return ret;
}
/* Propagate constants from the caller to the callee of CS. INFO describes the /* Propagate constants from the caller to the callee of CS. INFO describes the
caller. */ caller. */
...@@ -1055,7 +1435,8 @@ propagate_constants_accross_call (struct cgraph_edge *cs) ...@@ -1055,7 +1435,8 @@ propagate_constants_accross_call (struct cgraph_edge *cs)
alias_or_thunk = cgraph_alias_aliased_node (alias_or_thunk); alias_or_thunk = cgraph_alias_aliased_node (alias_or_thunk);
if (alias_or_thunk->thunk.thunk_p) if (alias_or_thunk->thunk.thunk_p)
{ {
ret |= set_lattice_contains_variable (ipa_get_lattice (callee_info, 0)); ret |= set_all_contains_variable (ipa_get_parm_lattices (callee_info,
0));
i = 1; i = 1;
} }
else else
...@@ -1064,15 +1445,21 @@ propagate_constants_accross_call (struct cgraph_edge *cs) ...@@ -1064,15 +1445,21 @@ propagate_constants_accross_call (struct cgraph_edge *cs)
for (; (i < args_count) && (i < parms_count); i++) for (; (i < args_count) && (i < parms_count); i++)
{ {
struct ipa_jump_func *jump_func = ipa_get_ith_jump_func (args, i); struct ipa_jump_func *jump_func = ipa_get_ith_jump_func (args, i);
struct ipcp_lattice *dest_lat = ipa_get_lattice (callee_info, i); struct ipcp_param_lattices *dest_plats;
dest_plats = ipa_get_parm_lattices (callee_info, i);
if (availability == AVAIL_OVERWRITABLE) if (availability == AVAIL_OVERWRITABLE)
ret |= set_lattice_contains_variable (dest_lat); ret |= set_all_contains_variable (dest_plats);
else else
ret |= propagate_accross_jump_function (cs, jump_func, dest_lat); {
ret |= propagate_scalar_accross_jump_function (cs, jump_func,
&dest_plats->itself);
ret |= propagate_aggs_accross_jump_function (cs, jump_func,
dest_plats);
}
} }
for (; i < parms_count; i++) for (; i < parms_count; i++)
ret |= set_lattice_contains_variable (ipa_get_lattice (callee_info, i)); ret |= set_all_contains_variable (ipa_get_parm_lattices (callee_info, i));
return ret; return ret;
} }
...@@ -1204,6 +1591,16 @@ devirtualization_time_bonus (struct cgraph_node *node, ...@@ -1204,6 +1591,16 @@ devirtualization_time_bonus (struct cgraph_node *node,
return res; return res;
} }
/* Return time bonus incurred because of HINTS. */
static int
hint_time_bonus (inline_hints hints)
{
if (hints & (INLINE_HINT_loop_iterations | INLINE_HINT_loop_stride))
return PARAM_VALUE (PARAM_IPA_CP_LOOP_HINT_BONUS);
return 0;
}
/* Return true if cloning NODE is a good idea, given the estimated TIME_BENEFIT /* Return true if cloning NODE is a good idea, given the estimated TIME_BENEFIT
and SIZE_COST and with the sum of frequencies of incoming edges to the and SIZE_COST and with the sum of frequencies of incoming edges to the
potential new clone in FREQUENCIES. */ potential new clone in FREQUENCIES. */
...@@ -1251,17 +1648,43 @@ good_cloning_opportunity_p (struct cgraph_node *node, int time_benefit, ...@@ -1251,17 +1648,43 @@ good_cloning_opportunity_p (struct cgraph_node *node, int time_benefit,
} }
} }
/* Return all context independent values from aggregate lattices in PLATS in a
vector. Return NULL if there are none. */
static VEC (ipa_agg_jf_item_t, gc) *
context_independent_aggregate_values (struct ipcp_param_lattices *plats)
{
VEC (ipa_agg_jf_item_t, gc) *res = NULL;
if (plats->aggs_bottom
|| plats->aggs_contain_variable
|| plats->aggs_count == 0)
return NULL;
for (struct ipcp_agg_lattice *aglat = plats->aggs;
aglat;
aglat = aglat->next)
if (ipa_lat_is_single_const (aglat))
{
struct ipa_agg_jf_item item;
item.offset = aglat->offset;
item.value = aglat->values->value;
VEC_safe_push (ipa_agg_jf_item_t, gc, res, item);
}
return res;
}
/* Allocate KNOWN_CSTS and KNOWN_BINFOS and populate them with values of /* Allocate KNOWN_CSTS, KNOWN_BINFOS and, if non-NULL, KNOWN_AGGS and populate
parameters that are known independent of the context. INFO describes the them with values of parameters that are known independent of the context.
function. If REMOVABLE_PARAMS_COST is non-NULL, the movement cost of all INFO describes the function. If REMOVABLE_PARAMS_COST is non-NULL, the
removable parameters will be stored in it. */ movement cost of all removable parameters will be stored in it. */
static bool static bool
gather_context_independent_values (struct ipa_node_params *info, gather_context_independent_values (struct ipa_node_params *info,
VEC (tree, heap) **known_csts, VEC (tree, heap) **known_csts,
VEC (tree, heap) **known_binfos, VEC (tree, heap) **known_binfos,
int *removable_params_cost) VEC (ipa_agg_jump_function_t, heap) **known_aggs,
int *removable_params_cost)
{ {
int i, count = ipa_get_param_count (info); int i, count = ipa_get_param_count (info);
bool ret = false; bool ret = false;
...@@ -1270,13 +1693,19 @@ gather_context_independent_values (struct ipa_node_params *info, ...@@ -1270,13 +1693,19 @@ gather_context_independent_values (struct ipa_node_params *info,
*known_binfos = NULL; *known_binfos = NULL;
VEC_safe_grow_cleared (tree, heap, *known_csts, count); VEC_safe_grow_cleared (tree, heap, *known_csts, count);
VEC_safe_grow_cleared (tree, heap, *known_binfos, count); VEC_safe_grow_cleared (tree, heap, *known_binfos, count);
if (known_aggs)
{
*known_aggs = NULL;
VEC_safe_grow_cleared (ipa_agg_jump_function_t, heap, *known_aggs, count);
}
if (removable_params_cost) if (removable_params_cost)
*removable_params_cost = 0; *removable_params_cost = 0;
for (i = 0; i < count ; i++) for (i = 0; i < count ; i++)
{ {
struct ipcp_lattice *lat = ipa_get_lattice (info, i); struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
struct ipcp_lattice *lat = &plats->itself;
if (ipa_lat_is_single_const (lat)) if (ipa_lat_is_single_const (lat))
{ {
...@@ -1289,7 +1718,7 @@ gather_context_independent_values (struct ipa_node_params *info, ...@@ -1289,7 +1718,7 @@ gather_context_independent_values (struct ipa_node_params *info,
+= estimate_move_cost (TREE_TYPE (val->value)); += estimate_move_cost (TREE_TYPE (val->value));
ret = true; ret = true;
} }
else if (lat->virt_call) else if (plats->virt_call)
{ {
VEC_replace (tree, *known_binfos, i, val->value); VEC_replace (tree, *known_binfos, i, val->value);
ret = true; ret = true;
...@@ -1302,12 +1731,45 @@ gather_context_independent_values (struct ipa_node_params *info, ...@@ -1302,12 +1731,45 @@ gather_context_independent_values (struct ipa_node_params *info,
else if (removable_params_cost else if (removable_params_cost
&& !ipa_is_param_used (info, i)) && !ipa_is_param_used (info, i))
*removable_params_cost *removable_params_cost
+= estimate_move_cost (TREE_TYPE (ipa_get_param (info, i))); += estimate_move_cost (TREE_TYPE (ipa_get_param (info, i)));
if (known_aggs)
{
VEC (ipa_agg_jf_item_t, gc) *agg_items;
struct ipa_agg_jump_function *ajf;
agg_items = context_independent_aggregate_values (plats);
ajf = &VEC_index (ipa_agg_jump_function_t, *known_aggs, i);
ajf->items = agg_items;
ajf->by_ref = plats->aggs_by_ref;
ret |= agg_items != NULL;
}
} }
return ret; return ret;
} }
/* The current interface in ipa-inline-analysis requires a pointer vector.
Create it.
FIXME: That interface should be re-worked, this is slightly silly. Still,
I'd like to discuss how to change it first and this demonstrates the
issue. */
static VEC (ipa_agg_jump_function_p, heap) *
agg_jmp_p_vec_for_t_vec (VEC (ipa_agg_jump_function_t, heap) *known_aggs)
{
VEC (ipa_agg_jump_function_p, heap) *ret;
struct ipa_agg_jump_function *ajf;
int i;
ret = VEC_alloc (ipa_agg_jump_function_p, heap,
VEC_length (ipa_agg_jump_function_t, known_aggs));
FOR_EACH_VEC_ELT (ipa_agg_jump_function_t, known_aggs, i, ajf)
VEC_quick_push (ipa_agg_jump_function_p, ret, ajf);
return ret;
}
/* Iterate over known values of parameters of NODE and estimate the local /* Iterate over known values of parameters of NODE and estimate the local
effects in terms of time and size they have. */ effects in terms of time and size they have. */
...@@ -1317,6 +1779,8 @@ estimate_local_effects (struct cgraph_node *node) ...@@ -1317,6 +1779,8 @@ estimate_local_effects (struct cgraph_node *node)
struct ipa_node_params *info = IPA_NODE_REF (node); struct ipa_node_params *info = IPA_NODE_REF (node);
int i, count = ipa_get_param_count (info); int i, count = ipa_get_param_count (info);
VEC (tree, heap) *known_csts, *known_binfos; VEC (tree, heap) *known_csts, *known_binfos;
VEC (ipa_agg_jump_function_t, heap) *known_aggs;
VEC (ipa_agg_jump_function_p, heap) *known_aggs_ptrs;
bool always_const; bool always_const;
int base_time = inline_summary (node)->time; int base_time = inline_summary (node)->time;
int removable_params_cost; int removable_params_cost;
...@@ -1329,18 +1793,21 @@ estimate_local_effects (struct cgraph_node *node) ...@@ -1329,18 +1793,21 @@ estimate_local_effects (struct cgraph_node *node)
cgraph_node_name (node), node->uid, base_time); cgraph_node_name (node), node->uid, base_time);
always_const = gather_context_independent_values (info, &known_csts, always_const = gather_context_independent_values (info, &known_csts,
&known_binfos, &known_binfos, &known_aggs,
&removable_params_cost); &removable_params_cost);
known_aggs_ptrs = agg_jmp_p_vec_for_t_vec (known_aggs);
if (always_const) if (always_const)
{ {
struct caller_statistics stats; struct caller_statistics stats;
inline_hints hints;
int time, size; int time, size;
init_caller_stats (&stats); init_caller_stats (&stats);
cgraph_for_node_and_aliases (node, gather_caller_stats, &stats, false); cgraph_for_node_and_aliases (node, gather_caller_stats, &stats, false);
estimate_ipcp_clone_size_and_time (node, known_csts, known_binfos, estimate_ipcp_clone_size_and_time (node, known_csts, known_binfos,
&size, &time); known_aggs_ptrs, &size, &time, &hints);
time -= devirtualization_time_bonus (node, known_csts, known_binfos); time -= devirtualization_time_bonus (node, known_csts, known_binfos);
time -= hint_time_bonus (hints);
time -= removable_params_cost; time -= removable_params_cost;
size -= stats.n_calls * removable_params_cost; size -= stats.n_calls * removable_params_cost;
...@@ -1381,7 +1848,8 @@ estimate_local_effects (struct cgraph_node *node) ...@@ -1381,7 +1848,8 @@ estimate_local_effects (struct cgraph_node *node)
for (i = 0; i < count ; i++) for (i = 0; i < count ; i++)
{ {
struct ipcp_lattice *lat = ipa_get_lattice (info, i); struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
struct ipcp_lattice *lat = &plats->itself;
struct ipcp_value *val; struct ipcp_value *val;
int emc; int emc;
...@@ -1394,6 +1862,7 @@ estimate_local_effects (struct cgraph_node *node) ...@@ -1394,6 +1862,7 @@ estimate_local_effects (struct cgraph_node *node)
for (val = lat->values; val; val = val->next) for (val = lat->values; val; val = val->next)
{ {
int time, size, time_benefit; int time, size, time_benefit;
inline_hints hints;
if (TREE_CODE (val->value) != TREE_BINFO) if (TREE_CODE (val->value) != TREE_BINFO)
{ {
...@@ -1401,7 +1870,7 @@ estimate_local_effects (struct cgraph_node *node) ...@@ -1401,7 +1870,7 @@ estimate_local_effects (struct cgraph_node *node)
VEC_replace (tree, known_binfos, i, NULL_TREE); VEC_replace (tree, known_binfos, i, NULL_TREE);
emc = estimate_move_cost (TREE_TYPE (val->value)); emc = estimate_move_cost (TREE_TYPE (val->value));
} }
else if (lat->virt_call) else if (plats->virt_call)
{ {
VEC_replace (tree, known_csts, i, NULL_TREE); VEC_replace (tree, known_csts, i, NULL_TREE);
VEC_replace (tree, known_binfos, i, val->value); VEC_replace (tree, known_binfos, i, val->value);
...@@ -1411,9 +1880,11 @@ estimate_local_effects (struct cgraph_node *node) ...@@ -1411,9 +1880,11 @@ estimate_local_effects (struct cgraph_node *node)
continue; continue;
estimate_ipcp_clone_size_and_time (node, known_csts, known_binfos, estimate_ipcp_clone_size_and_time (node, known_csts, known_binfos,
&size, &time); known_aggs_ptrs, &size, &time,
&hints);
time_benefit = base_time - time time_benefit = base_time - time
+ devirtualization_time_bonus (node, known_csts, known_binfos) + devirtualization_time_bonus (node, known_csts, known_binfos)
+ hint_time_bonus (hints)
+ removable_params_cost + emc; + removable_params_cost + emc;
gcc_checking_assert (size >=0); gcc_checking_assert (size >=0);
...@@ -1437,10 +1908,79 @@ estimate_local_effects (struct cgraph_node *node) ...@@ -1437,10 +1908,79 @@ estimate_local_effects (struct cgraph_node *node)
val->local_time_benefit = time_benefit; val->local_time_benefit = time_benefit;
val->local_size_cost = size; val->local_size_cost = size;
} }
VEC_replace (tree, known_binfos, i, NULL_TREE);
VEC_replace (tree, known_csts, i, NULL_TREE);
}
for (i = 0; i < count ; i++)
{
struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
struct ipa_agg_jump_function *ajf;
struct ipcp_agg_lattice *aglat;
if (plats->aggs_bottom || !plats->aggs)
continue;
ajf = &VEC_index (ipa_agg_jump_function_t, known_aggs, i);
for (aglat = plats->aggs; aglat; aglat = aglat->next)
{
struct ipcp_value *val;
if (aglat->bottom || !aglat->values
/* If the following is true, the one value is in known_aggs. */
|| (!plats->aggs_contain_variable
&& ipa_lat_is_single_const (aglat)))
continue;
for (val = aglat->values; val; val = val->next)
{
int time, size, time_benefit;
struct ipa_agg_jf_item item;
inline_hints hints;
item.offset = aglat->offset;
item.value = val->value;
VEC_safe_push (ipa_agg_jf_item_t, gc, ajf->items, item);
estimate_ipcp_clone_size_and_time (node, known_csts, known_binfos,
known_aggs_ptrs, &size, &time,
&hints);
time_benefit = base_time - time
+ devirtualization_time_bonus (node, known_csts, known_binfos)
+ hint_time_bonus (hints);
gcc_checking_assert (size >=0);
if (size == 0)
size = 1;
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, " - estimates for value ");
print_ipcp_constant_value (dump_file, val->value);
fprintf (dump_file, " for parameter ");
print_generic_expr (dump_file, ipa_get_param (info, i), 0);
fprintf (dump_file, "[%soffset: " HOST_WIDE_INT_PRINT_DEC
"]: time_benefit: %i, size: %i\n",
plats->aggs_by_ref ? "ref " : "",
aglat->offset, time_benefit, size);
}
val->local_time_benefit = time_benefit;
val->local_size_cost = size;
VEC_pop (ipa_agg_jf_item_t, ajf->items);
}
}
}
for (i = 0; i < count ; i++)
{
VEC_free (ipa_agg_jf_item_t, gc,
VEC_index (ipa_agg_jump_function_t, known_aggs, i).items);
VEC_index (ipa_agg_jump_function_t, known_aggs, i).items = NULL;
} }
VEC_free (tree, heap, known_csts); VEC_free (tree, heap, known_csts);
VEC_free (tree, heap, known_binfos); VEC_free (tree, heap, known_binfos);
VEC_free (ipa_agg_jump_function_t, heap, known_aggs);
VEC_free (ipa_agg_jump_function_p, heap, known_aggs_ptrs);
} }
...@@ -1510,13 +2050,20 @@ add_all_node_vals_to_toposort (struct cgraph_node *node) ...@@ -1510,13 +2050,20 @@ add_all_node_vals_to_toposort (struct cgraph_node *node)
for (i = 0; i < count ; i++) for (i = 0; i < count ; i++)
{ {
struct ipcp_lattice *lat = ipa_get_lattice (info, i); struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
struct ipcp_lattice *lat = &plats->itself;
struct ipcp_agg_lattice *aglat;
struct ipcp_value *val; struct ipcp_value *val;
if (lat->bottom || !lat->values) if (!lat->bottom)
continue; for (val = lat->values; val; val = val->next)
for (val = lat->values; val; val = val->next) add_val_to_toposort (val);
add_val_to_toposort (val);
if (!plats->aggs_bottom)
for (aglat = plats->aggs; aglat; aglat = aglat->next)
if (!aglat->bottom)
for (val = aglat->values; val; val = val->next)
add_val_to_toposort (val);
} }
} }
...@@ -1649,7 +2196,7 @@ ipcp_propagate_stage (struct topo_info *topo) ...@@ -1649,7 +2196,7 @@ ipcp_propagate_stage (struct topo_info *topo)
determine_versionability (node); determine_versionability (node);
if (cgraph_function_with_gimple_body_p (node)) if (cgraph_function_with_gimple_body_p (node))
{ {
info->lattices = XCNEWVEC (struct ipcp_lattice, info->lattices = XCNEWVEC (struct ipcp_param_lattices,
ipa_get_param_count (info)); ipa_get_param_count (info));
initialize_node_lattices (node); initialize_node_lattices (node);
} }
...@@ -1734,12 +2281,24 @@ ipcp_edge_duplication_hook (struct cgraph_edge *src, struct cgraph_edge *dst, ...@@ -1734,12 +2281,24 @@ ipcp_edge_duplication_hook (struct cgraph_edge *src, struct cgraph_edge *dst,
VEC_replace (cgraph_edge_p, next_edge_clone, src->uid, dst); VEC_replace (cgraph_edge_p, next_edge_clone, src->uid, dst);
} }
/* Get the next clone in the linked list of clones of an edge. */ /* See if NODE is a clone with a known aggregate value at a given OFFSET of a
parameter with the given INDEX. */
static inline struct cgraph_edge * static tree
get_next_cgraph_edge_clone (struct cgraph_edge *cs) get_clone_agg_value (struct cgraph_node *node, HOST_WIDEST_INT offset,
int index)
{ {
return VEC_index (cgraph_edge_p, next_edge_clone, cs->uid); struct ipa_agg_replacement_value *aggval;
aggval = ipa_get_agg_replacements_for_node (node);
while (aggval)
{
if (aggval->offset == offset
&& aggval->index == index)
return aggval->value;
aggval = aggval->next;
}
return NULL_TREE;
} }
/* Return true if edge CS does bring about the value described by SRC. */ /* Return true if edge CS does bring about the value described by SRC. */
...@@ -1758,21 +2317,45 @@ cgraph_edge_brings_value_p (struct cgraph_edge *cs, ...@@ -1758,21 +2317,45 @@ cgraph_edge_brings_value_p (struct cgraph_edge *cs,
if (caller_info->ipcp_orig_node) if (caller_info->ipcp_orig_node)
{ {
tree t = VEC_index (tree, caller_info->known_vals, src->index); tree t;
if (src->offset == -1)
t = VEC_index (tree, caller_info->known_vals, src->index);
else
t = get_clone_agg_value (cs->caller, src->offset, src->index);
return (t != NULL_TREE return (t != NULL_TREE
&& values_equal_for_ipcp_p (src->val->value, t)); && values_equal_for_ipcp_p (src->val->value, t));
} }
else else
{ {
struct ipcp_lattice *lat = ipa_get_lattice (caller_info, src->index); struct ipcp_agg_lattice *aglat;
if (ipa_lat_is_single_const (lat) struct ipcp_param_lattices *plats = ipa_get_parm_lattices (caller_info,
&& values_equal_for_ipcp_p (src->val->value, lat->values->value)) src->index);
return true; if (src->offset == -1)
return (ipa_lat_is_single_const (&plats->itself)
&& values_equal_for_ipcp_p (src->val->value,
plats->itself.values->value));
else else
return false; {
if (plats->aggs_bottom || plats->aggs_contain_variable)
return false;
for (aglat = plats->aggs; aglat; aglat = aglat->next)
if (aglat->offset == src->offset)
return (ipa_lat_is_single_const (aglat)
&& values_equal_for_ipcp_p (src->val->value,
aglat->values->value));
}
return false;
} }
} }
/* Get the next clone in the linked list of clones of an edge. */
static inline struct cgraph_edge *
get_next_cgraph_edge_clone (struct cgraph_edge *cs)
{
return VEC_index (cgraph_edge_p, next_edge_clone, cs->uid);
}
/* Given VAL, iterate over all its sources and if they still hold, add their /* Given VAL, iterate over all its sources and if they still hold, add their
edge frequency and their number into *FREQUENCY and *CALLER_COUNT edge frequency and their number into *FREQUENCY and *CALLER_COUNT
respectively. */ respectively. */
...@@ -2009,6 +2592,7 @@ update_specialized_profile (struct cgraph_node *new_node, ...@@ -2009,6 +2592,7 @@ update_specialized_profile (struct cgraph_node *new_node,
static struct cgraph_node * static struct cgraph_node *
create_specialized_node (struct cgraph_node *node, create_specialized_node (struct cgraph_node *node,
VEC (tree, heap) *known_vals, VEC (tree, heap) *known_vals,
struct ipa_agg_replacement_value *aggvals,
VEC (cgraph_edge_p,heap) *callers) VEC (cgraph_edge_p,heap) *callers)
{ {
struct ipa_node_params *new_info, *info = IPA_NODE_REF (node); struct ipa_node_params *new_info, *info = IPA_NODE_REF (node);
...@@ -2053,9 +2637,14 @@ create_specialized_node (struct cgraph_node *node, ...@@ -2053,9 +2637,14 @@ create_specialized_node (struct cgraph_node *node,
new_node = cgraph_create_virtual_clone (node, callers, replace_trees, new_node = cgraph_create_virtual_clone (node, callers, replace_trees,
args_to_skip, "constprop"); args_to_skip, "constprop");
ipa_set_node_agg_value_chain (new_node, aggvals);
if (dump_file && (dump_flags & TDF_DETAILS)) if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, " the new node is %s/%i.\n", {
cgraph_node_name (new_node), new_node->uid); fprintf (dump_file, " the new node is %s/%i.\n",
cgraph_node_name (new_node), new_node->uid);
if (aggvals)
ipa_dump_agg_replacement_values (dump_file, aggvals);
}
gcc_checking_assert (ipa_node_params_vector gcc_checking_assert (ipa_node_params_vector
&& (VEC_length (ipa_node_params_t, && (VEC_length (ipa_node_params_t,
ipa_node_params_vector) ipa_node_params_vector)
...@@ -2076,9 +2665,9 @@ create_specialized_node (struct cgraph_node *node, ...@@ -2076,9 +2665,9 @@ create_specialized_node (struct cgraph_node *node,
CALLERS. */ CALLERS. */
static void static void
find_more_values_for_callers_subset (struct cgraph_node *node, find_more_scalar_values_for_callers_subset (struct cgraph_node *node,
VEC (tree, heap) *known_vals, VEC (tree, heap) *known_vals,
VEC (cgraph_edge_p,heap) *callers) VEC (cgraph_edge_p,heap) *callers)
{ {
struct ipa_node_params *info = IPA_NODE_REF (node); struct ipa_node_params *info = IPA_NODE_REF (node);
int i, count = ipa_get_param_count (info); int i, count = ipa_get_param_count (info);
...@@ -2089,7 +2678,7 @@ find_more_values_for_callers_subset (struct cgraph_node *node, ...@@ -2089,7 +2678,7 @@ find_more_values_for_callers_subset (struct cgraph_node *node,
tree newval = NULL_TREE; tree newval = NULL_TREE;
int j; int j;
if (ipa_get_lattice (info, i)->bottom if (ipa_get_scalar_lat (info, i)->bottom
|| VEC_index (tree, known_vals, i)) || VEC_index (tree, known_vals, i))
continue; continue;
...@@ -2120,7 +2709,7 @@ find_more_values_for_callers_subset (struct cgraph_node *node, ...@@ -2120,7 +2709,7 @@ find_more_values_for_callers_subset (struct cgraph_node *node,
{ {
if (dump_file && (dump_flags & TDF_DETAILS)) if (dump_file && (dump_flags & TDF_DETAILS))
{ {
fprintf (dump_file, " adding an extra known value "); fprintf (dump_file, " adding an extra known scalar value ");
print_ipcp_constant_value (dump_file, newval); print_ipcp_constant_value (dump_file, newval);
fprintf (dump_file, " for parameter "); fprintf (dump_file, " for parameter ");
print_generic_expr (dump_file, ipa_get_param (info, i), 0); print_generic_expr (dump_file, ipa_get_param (info, i), 0);
...@@ -2132,6 +2721,391 @@ find_more_values_for_callers_subset (struct cgraph_node *node, ...@@ -2132,6 +2721,391 @@ find_more_values_for_callers_subset (struct cgraph_node *node,
} }
} }
/* Go through PLATS and create a vector of values consisting of values and
offsets (minus OFFSET) of lattices that contain only a single value. */
static VEC (ipa_agg_jf_item_t, heap) *
copy_plats_to_inter (struct ipcp_param_lattices *plats, HOST_WIDE_INT offset)
{
VEC (ipa_agg_jf_item_t, heap) *res = NULL;
if (!plats->aggs || plats->aggs_contain_variable || plats->aggs_bottom)
return NULL;
for (struct ipcp_agg_lattice *aglat = plats->aggs; aglat; aglat = aglat->next)
if (ipa_lat_is_single_const (aglat))
{
struct ipa_agg_jf_item ti;
ti.offset = aglat->offset - offset;
ti.value = aglat->values->value;
VEC_safe_push (ipa_agg_jf_item_t, heap, res, ti);
}
return res;
}
/* Intersect all values in INTER with single value lattices in PLATS (while
subtracting OFFSET). */
static void
intersect_with_plats (struct ipcp_param_lattices *plats,
VEC (ipa_agg_jf_item_t, heap) **inter,
HOST_WIDE_INT offset)
{
struct ipcp_agg_lattice *aglat;
struct ipa_agg_jf_item *item;
int k;
if (!plats->aggs || plats->aggs_contain_variable || plats->aggs_bottom)
{
VEC_free (ipa_agg_jf_item_t, heap, *inter);
*inter = NULL;
return;
}
aglat = plats->aggs;
FOR_EACH_VEC_ELT (ipa_agg_jf_item_t, *inter, k, item)
{
bool found = false;
if (!item->value)
continue;
while (aglat)
{
if (aglat->offset - offset > item->offset)
break;
if (aglat->offset - offset == item->offset)
{
gcc_checking_assert (item->value);
if (values_equal_for_ipcp_p (item->value, aglat->values->value))
found = true;
break;
}
aglat = aglat->next;
}
if (!found)
item->value = NULL_TREE;
}
}
/* Copy agggregate replacement values of NODE (which is an IPA-CP clone) to the
vector result while subtracting OFFSET from the individual value offsets. */
static VEC (ipa_agg_jf_item_t, heap) *
agg_replacements_to_vector (struct cgraph_node *node, HOST_WIDE_INT offset)
{
struct ipa_agg_replacement_value *av;
VEC (ipa_agg_jf_item_t, heap) *res = NULL;
for (av = ipa_get_agg_replacements_for_node (node); av; av = av->next)
{
struct ipa_agg_jf_item item;
gcc_checking_assert (av->value);
item.offset = av->offset - offset;
item.value = av->value;
VEC_safe_push (ipa_agg_jf_item_t, heap, res, item);
}
return res;
}
/* Intersect all values in INTER with those that we have already scheduled to
be replaced in parameter number INDEX of NODE, which is an IPA-CP clone
(while subtracting OFFSET). */
static void
intersect_with_agg_replacements (struct cgraph_node *node, int index,
VEC (ipa_agg_jf_item_t, heap) **inter,
HOST_WIDE_INT offset)
{
struct ipa_agg_replacement_value *srcvals;
struct ipa_agg_jf_item *item;
int i;
srcvals = ipa_get_agg_replacements_for_node (node);
if (!srcvals)
{
VEC_free (ipa_agg_jf_item_t, heap, *inter);
*inter = NULL;
return;
}
FOR_EACH_VEC_ELT (ipa_agg_jf_item_t, *inter, i, item)
{
struct ipa_agg_replacement_value *av;
bool found = false;
if (!item->value)
continue;
for (av = srcvals; av; av = av->next)
{
gcc_checking_assert (av->value);
if (av->index == index
&& av->offset - offset == item->offset)
{
if (values_equal_for_ipcp_p (item->value, av->value))
found = true;
break;
}
}
if (!found)
item->value = NULL_TREE;
}
}
/* Look at edges in CALLERS and collect all known aggregate values that arrive
from all of them. */
static struct ipa_agg_replacement_value *
find_aggregate_values_for_callers_subset (struct cgraph_node *node,
VEC (cgraph_edge_p,heap) *callers)
{
struct ipa_node_params *info = IPA_NODE_REF (node);
struct ipa_agg_replacement_value *res = NULL;
struct cgraph_edge *cs;
int i, j, count = ipa_get_param_count (info);
FOR_EACH_VEC_ELT (cgraph_edge_p, callers, j, cs)
{
int c = ipa_get_cs_argument_count (IPA_EDGE_REF (cs));
if (c < count)
count = c;
}
for (i = 0; i < count ; i++)
{
struct cgraph_edge *cs;
VEC (ipa_agg_jf_item_t, heap) *inter = NULL;
struct ipa_agg_jf_item *item;
int j;
/* Among other things, the following check should deal with all by_ref
mismatches. */
if (ipa_get_parm_lattices (info, i)->aggs_bottom)
continue;
FOR_EACH_VEC_ELT (cgraph_edge_p, callers, j, cs)
{
struct ipa_jump_func *jfunc;
jfunc = ipa_get_ith_jump_func (IPA_EDGE_REF (cs), i);
if (jfunc->type == IPA_JF_PASS_THROUGH
&& ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
{
struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
int src_idx = ipa_get_jf_pass_through_formal_id (jfunc);
if (caller_info->ipcp_orig_node)
{
if (!inter)
inter = agg_replacements_to_vector (cs->caller, 0);
else
intersect_with_agg_replacements (cs->caller, src_idx,
&inter, 0);
}
else
{
struct ipcp_param_lattices *src_plats;
src_plats = ipa_get_parm_lattices (caller_info, src_idx);
/* Currently we do not produce clobber aggregate jump
functions, adjust when we do. */
gcc_checking_assert (!jfunc->agg.items);
if (!inter)
inter = copy_plats_to_inter (src_plats, 0);
else
intersect_with_plats (src_plats, &inter, 0);
}
}
else if (jfunc->type == IPA_JF_ANCESTOR
&& ipa_get_jf_ancestor_agg_preserved (jfunc))
{
struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
int src_idx = ipa_get_jf_ancestor_formal_id (jfunc);
struct ipcp_param_lattices *src_plats;
HOST_WIDE_INT delta = ipa_get_jf_ancestor_offset (jfunc);
if (info->ipcp_orig_node)
{
if (!inter)
inter = agg_replacements_to_vector (cs->caller, delta);
else
intersect_with_agg_replacements (cs->caller, i, &inter,
delta);
}
else
{
src_plats = ipa_get_parm_lattices (caller_info, src_idx);;
/* Currently we do not produce clobber aggregate jump
functions, adjust when we do. */
gcc_checking_assert (!jfunc->agg.items);
if (!inter)
inter = copy_plats_to_inter (src_plats, delta);
else
intersect_with_plats (src_plats, &inter, delta);
}
}
else if (jfunc->agg.items)
{
int k;
if (!inter)
inter = VEC_copy (ipa_agg_jf_item, heap, jfunc->agg.items);
else
FOR_EACH_VEC_ELT (ipa_agg_jf_item_t, inter, k, item)
{
int l = 0;
bool found = false;;
if (!item->value)
continue;
while ((unsigned) l < VEC_length (ipa_agg_jf_item_t,
jfunc->agg.items))
{
struct ipa_agg_jf_item *ti;
ti = &VEC_index (ipa_agg_jf_item_t,
jfunc->agg.items, l);
if (ti->offset > item->offset)
break;
if (ti->offset == item->offset)
{
gcc_checking_assert (ti->value);
if (values_equal_for_ipcp_p (item->value,
ti->value))
found = true;
break;
}
l++;
}
if (!found)
item->value = NULL;
}
}
else
goto next_param;
if (!inter)
goto next_param;
}
FOR_EACH_VEC_ELT (ipa_agg_jf_item_t, inter, j, item)
{
struct ipa_agg_replacement_value *v;
if (!item->value)
continue;
v = ggc_alloc_ipa_agg_replacement_value ();
v->index = i;
v->offset = item->offset;
v->value = item->value;
v->next = res;
res = v;
}
next_param:
if (inter)
VEC_free (ipa_agg_jf_item, heap, inter);
}
return res;
}
/* Turn KNOWN_AGGS into a list of aggreate replacement values. */
static struct ipa_agg_replacement_value *
known_aggs_to_agg_replacement_list (VEC (ipa_agg_jump_function_t,
heap) *known_aggs)
{
struct ipa_agg_replacement_value *res = NULL;
struct ipa_agg_jump_function *aggjf;
struct ipa_agg_jf_item *item;
int i, j;
FOR_EACH_VEC_ELT (ipa_agg_jump_function_t, known_aggs, i, aggjf)
FOR_EACH_VEC_ELT (ipa_agg_jf_item_t, aggjf->items, j, item)
{
struct ipa_agg_replacement_value *v;
v = ggc_alloc_ipa_agg_replacement_value ();
v->index = i;
v->offset = item->offset;
v->value = item->value;
v->next = res;
res = v;
}
return res;
}
/* Determine whether CS also brings all scalar values that the NODE is
specialized for. */
static bool
cgraph_edge_brings_all_scalars_for_node (struct cgraph_edge *cs,
struct cgraph_node *node)
{
struct ipa_node_params *dest_info = IPA_NODE_REF (node);
int count = ipa_get_param_count (dest_info);
struct ipa_node_params *caller_info;
struct ipa_edge_args *args;
int i;
caller_info = IPA_NODE_REF (cs->caller);
args = IPA_EDGE_REF (cs);
for (i = 0; i < count; i++)
{
struct ipa_jump_func *jump_func;
tree val, t;
val = VEC_index (tree, dest_info->known_vals, i);
if (!val)
continue;
if (i >= ipa_get_cs_argument_count (args))
return false;
jump_func = ipa_get_ith_jump_func (args, i);
t = ipa_value_from_jfunc (caller_info, jump_func);
if (!t || !values_equal_for_ipcp_p (val, t))
return false;
}
return true;
}
/* Determine whether CS also brings all aggregate values that NODE is
specialized for. */
static bool
cgraph_edge_brings_all_agg_vals_for_node (struct cgraph_edge *cs,
struct cgraph_node *node)
{
struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
struct ipa_agg_replacement_value *aggval;
aggval = ipa_get_agg_replacements_for_node (node);
while (aggval)
{
bool found = false;
struct ipcp_param_lattices *plats;
plats = ipa_get_parm_lattices (caller_info, aggval->index);
if (plats->aggs_bottom || plats->aggs_contain_variable)
return false;
for (struct ipcp_agg_lattice *aglat = plats->aggs;
aglat;
aglat = aglat->next)
if (aglat->offset == aggval->offset)
{
if (ipa_lat_is_single_const (aglat)
&& values_equal_for_ipcp_p (aggval->value,
aglat->values->value))
{
found = true;
break;
}
else
return false;
}
if (!found)
return false;
aggval = aggval->next;
}
return true;
}
/* Given an original NODE and a VAL for which we have already created a /* Given an original NODE and a VAL for which we have already created a
specialized clone, look whether there are incoming edges that still lead specialized clone, look whether there are incoming edges that still lead
into the old node but now also bring the requested value and also conform to into the old node but now also bring the requested value and also conform to
...@@ -2141,9 +3115,7 @@ find_more_values_for_callers_subset (struct cgraph_node *node, ...@@ -2141,9 +3115,7 @@ find_more_values_for_callers_subset (struct cgraph_node *node,
static void static void
perhaps_add_new_callers (struct cgraph_node *node, struct ipcp_value *val) perhaps_add_new_callers (struct cgraph_node *node, struct ipcp_value *val)
{ {
struct ipa_node_params *dest_info = IPA_NODE_REF (val->spec_node);
struct ipcp_value_source *src; struct ipcp_value_source *src;
int count = ipa_get_param_count (dest_info);
gcov_type redirected_sum = 0; gcov_type redirected_sum = 0;
for (src = val->sources; src; src = src->next) for (src = val->sources; src; src = src->next)
...@@ -2152,42 +3124,14 @@ perhaps_add_new_callers (struct cgraph_node *node, struct ipcp_value *val) ...@@ -2152,42 +3124,14 @@ perhaps_add_new_callers (struct cgraph_node *node, struct ipcp_value *val)
while (cs) while (cs)
{ {
enum availability availability; enum availability availability;
bool insufficient = false;
if (cgraph_function_node (cs->callee, &availability) == node if (cgraph_function_node (cs->callee, &availability) == node
&& availability > AVAIL_OVERWRITABLE && availability > AVAIL_OVERWRITABLE
&& cgraph_edge_brings_value_p (cs, src)) && cgraph_edge_brings_value_p (cs, src))
{ {
struct ipa_node_params *caller_info; if (cgraph_edge_brings_all_scalars_for_node (cs, val->spec_node)
struct ipa_edge_args *args; && cgraph_edge_brings_all_agg_vals_for_node (cs,
int i; val->spec_node))
caller_info = IPA_NODE_REF (cs->caller);
args = IPA_EDGE_REF (cs);
for (i = 0; i < count; i++)
{
struct ipa_jump_func *jump_func;
tree val, t;
val = VEC_index (tree, dest_info->known_vals, i);
if (!val)
continue;
if (i >= ipa_get_cs_argument_count (args))
{
insufficient = true;
break;
}
jump_func = ipa_get_ith_jump_func (args, i);
t = ipa_value_from_jfunc (caller_info, jump_func);
if (!t || !values_equal_for_ipcp_p (val, t))
{
insufficient = true;
break;
}
}
if (!insufficient)
{ {
if (dump_file) if (dump_file)
fprintf (dump_file, " - adding an extra caller %s/%i" fprintf (dump_file, " - adding an extra caller %s/%i"
...@@ -2224,6 +3168,102 @@ move_binfos_to_values (VEC (tree, heap) *known_vals, ...@@ -2224,6 +3168,102 @@ move_binfos_to_values (VEC (tree, heap) *known_vals,
VEC_replace (tree, known_vals, i, t); VEC_replace (tree, known_vals, i, t);
} }
/* Return true if there is a replacement equivalent to VALUE, INDEX and OFFSET
among those in the AGGVALS list. */
DEBUG_FUNCTION bool
ipcp_val_in_agg_replacements_p (struct ipa_agg_replacement_value *aggvals,
int index, HOST_WIDE_INT offset, tree value)
{
while (aggvals)
{
if (aggvals->index == index
&& aggvals->offset == offset
&& values_equal_for_ipcp_p (aggvals->value, value))
return true;
aggvals = aggvals->next;
}
return false;
}
/* Decide wheter to create a special version of NODE for value VAL of parameter
at the given INDEX. If OFFSET is -1, the value is for the parameter itself,
otherwise it is stored at the given OFFSET of the parameter. KNOWN_CSTS,
KNOWN_BINFOS and KNOWN_AGGS describe the other already known values. */
static bool
decide_about_value (struct cgraph_node *node, int index, HOST_WIDE_INT offset,
struct ipcp_value *val, VEC (tree, heap) *known_csts,
VEC (tree, heap) *known_binfos)
{
struct ipa_agg_replacement_value *aggvals;
int freq_sum, caller_count;
gcov_type count_sum;
VEC (cgraph_edge_p, heap) *callers;
VEC (tree, heap) *kv;
if (val->spec_node)
{
perhaps_add_new_callers (node, val);
return false;
}
else if (val->local_size_cost + overall_size > max_new_size)
{
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, " Ignoring candidate value because "
"max_new_size would be reached with %li.\n",
val->local_size_cost + overall_size);
return false;
}
else if (!get_info_about_necessary_edges (val, &freq_sum, &count_sum,
&caller_count))
return false;
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, " - considering value ");
print_ipcp_constant_value (dump_file, val->value);
fprintf (dump_file, " for parameter ");
print_generic_expr (dump_file, ipa_get_param (IPA_NODE_REF (node),
index), 0);
if (offset != -1)
fprintf (dump_file, ", offset: " HOST_WIDE_INT_PRINT_DEC, offset);
fprintf (dump_file, " (caller_count: %i)\n", caller_count);
}
if (!good_cloning_opportunity_p (node, val->local_time_benefit,
freq_sum, count_sum,
val->local_size_cost)
&& !good_cloning_opportunity_p (node,
val->local_time_benefit
+ val->prop_time_benefit,
freq_sum, count_sum,
val->local_size_cost
+ val->prop_size_cost))
return false;
if (dump_file)
fprintf (dump_file, " Creating a specialized node of %s/%i.\n",
cgraph_node_name (node), node->uid);
callers = gather_edges_for_value (val, caller_count);
kv = VEC_copy (tree, heap, known_csts);
move_binfos_to_values (kv, known_binfos);
if (offset == -1)
VEC_replace (tree, kv, index, val->value);
find_more_scalar_values_for_callers_subset (node, kv, callers);
aggvals = find_aggregate_values_for_callers_subset (node, callers);
gcc_checking_assert (offset == -1
|| ipcp_val_in_agg_replacements_p (aggvals, index,
offset, val->value));
val->spec_node = create_specialized_node (node, kv, aggvals, callers);
overall_size += val->local_size_cost;
/* TODO: If for some lattice there is only one other known value
left, make a special node for it too. */
return true;
}
/* Decide whether and what specialized clones of NODE should be created. */ /* Decide whether and what specialized clones of NODE should be created. */
...@@ -2233,6 +3273,7 @@ decide_whether_version_node (struct cgraph_node *node) ...@@ -2233,6 +3273,7 @@ decide_whether_version_node (struct cgraph_node *node)
struct ipa_node_params *info = IPA_NODE_REF (node); struct ipa_node_params *info = IPA_NODE_REF (node);
int i, count = ipa_get_param_count (info); int i, count = ipa_get_param_count (info);
VEC (tree, heap) *known_csts, *known_binfos; VEC (tree, heap) *known_csts, *known_binfos;
VEC (ipa_agg_jump_function_t, heap) *known_aggs = NULL;
bool ret = false; bool ret = false;
if (count == 0) if (count == 0)
...@@ -2243,82 +3284,37 @@ decide_whether_version_node (struct cgraph_node *node) ...@@ -2243,82 +3284,37 @@ decide_whether_version_node (struct cgraph_node *node)
cgraph_node_name (node), node->uid); cgraph_node_name (node), node->uid);
gather_context_independent_values (info, &known_csts, &known_binfos, gather_context_independent_values (info, &known_csts, &known_binfos,
NULL); info->clone_for_all_contexts ? &known_aggs
: NULL, NULL);
for (i = 0; i < count ; i++) for (i = 0; i < count ;i++)
{ {
struct ipcp_lattice *lat = ipa_get_lattice (info, i); struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
struct ipcp_lattice *lat = &plats->itself;
struct ipcp_value *val; struct ipcp_value *val;
if (lat->bottom if (!lat->bottom
|| VEC_index (tree, known_csts, i) && !VEC_index (tree, known_csts, i)
|| VEC_index (tree, known_binfos, i)) && !VEC_index (tree, known_binfos, i))
continue; for (val = lat->values; val; val = val->next)
ret |= decide_about_value (node, i, -1, val, known_csts,
known_binfos);
for (val = lat->values; val; val = val->next) if (!plats->aggs_bottom || !plats->aggs)
{ {
int freq_sum, caller_count; struct ipcp_agg_lattice *aglat;
gcov_type count_sum; struct ipcp_value *val;
VEC (cgraph_edge_p, heap) *callers; for (aglat = plats->aggs; aglat; aglat = aglat->next)
VEC (tree, heap) *kv; if (!aglat->bottom && aglat->values
/* If the following is false, the one value is in
if (val->spec_node) known_aggs. */
{ && (plats->aggs_contain_variable
perhaps_add_new_callers (node, val); || !ipa_lat_is_single_const (aglat)))
continue; for (val = aglat->values; val; val = val->next)
} ret |= decide_about_value (node, i, aglat->offset, val,
else if (val->local_size_cost + overall_size > max_new_size) known_csts, known_binfos);
{
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, " Ignoring candidate value because "
"max_new_size would be reached with %li.\n",
val->local_size_cost + overall_size);
continue;
}
else if (!get_info_about_necessary_edges (val, &freq_sum, &count_sum,
&caller_count))
continue;
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, " - considering value ");
print_ipcp_constant_value (dump_file, val->value);
fprintf (dump_file, " for parameter ");
print_generic_expr (dump_file, ipa_get_param (info, i), 0);
fprintf (dump_file, " (caller_count: %i)\n", caller_count);
}
if (!good_cloning_opportunity_p (node, val->local_time_benefit,
freq_sum, count_sum,
val->local_size_cost)
&& !good_cloning_opportunity_p (node,
val->local_time_benefit
+ val->prop_time_benefit,
freq_sum, count_sum,
val->local_size_cost
+ val->prop_size_cost))
continue;
if (dump_file)
fprintf (dump_file, " Creating a specialized node of %s/%i.\n",
cgraph_node_name (node), node->uid);
callers = gather_edges_for_value (val, caller_count);
kv = VEC_copy (tree, heap, known_csts);
move_binfos_to_values (kv, known_binfos);
VEC_replace (tree, kv, i, val->value);
find_more_values_for_callers_subset (node, kv, callers);
val->spec_node = create_specialized_node (node, kv, callers);
overall_size += val->local_size_cost;
info = IPA_NODE_REF (node);
/* TODO: If for some lattice there is only one other known value
left, make a special node for it too. */
ret = true;
VEC_replace (tree, kv, i, val->value);
} }
info = IPA_NODE_REF (node);
} }
if (info->clone_for_all_contexts) if (info->clone_for_all_contexts)
...@@ -2332,7 +3328,9 @@ decide_whether_version_node (struct cgraph_node *node) ...@@ -2332,7 +3328,9 @@ decide_whether_version_node (struct cgraph_node *node)
callers = collect_callers_of_node (node); callers = collect_callers_of_node (node);
move_binfos_to_values (known_csts, known_binfos); move_binfos_to_values (known_csts, known_binfos);
create_specialized_node (node, known_csts, callers); create_specialized_node (node, known_csts,
known_aggs_to_agg_replacement_list (known_aggs),
callers);
info = IPA_NODE_REF (node); info = IPA_NODE_REF (node);
info->clone_for_all_contexts = false; info->clone_for_all_contexts = false;
ret = true; ret = true;
...@@ -2466,6 +3464,9 @@ ipcp_driver (void) ...@@ -2466,6 +3464,9 @@ ipcp_driver (void)
sizeof (struct ipcp_value), 32); sizeof (struct ipcp_value), 32);
ipcp_sources_pool = create_alloc_pool ("IPA-CP value sources", ipcp_sources_pool = create_alloc_pool ("IPA-CP value sources",
sizeof (struct ipcp_value_source), 64); sizeof (struct ipcp_value_source), 64);
ipcp_agg_lattice_pool = create_alloc_pool ("IPA_CP aggregate lattices",
sizeof (struct ipcp_agg_lattice),
32);
if (dump_file) if (dump_file)
{ {
fprintf (dump_file, "\nIPA structures before propagation:\n"); fprintf (dump_file, "\nIPA structures before propagation:\n");
...@@ -2560,10 +3561,10 @@ struct ipa_opt_pass_d pass_ipa_cp = ...@@ -2560,10 +3561,10 @@ struct ipa_opt_pass_d pass_ipa_cp =
ipcp_generate_summary, /* generate_summary */ ipcp_generate_summary, /* generate_summary */
ipcp_write_summary, /* write_summary */ ipcp_write_summary, /* write_summary */
ipcp_read_summary, /* read_summary */ ipcp_read_summary, /* read_summary */
NULL, /* write_optimization_summary */ ipa_prop_write_all_agg_replacement, /* write_optimization_summary */
NULL, /* read_optimization_summary */ ipa_prop_read_all_agg_replacement, /* read_optimization_summary */
NULL, /* stmt_fixup */ NULL, /* stmt_fixup */
0, /* TODOs */ 0, /* TODOs */
NULL, /* function_transform */ ipcp_transform_function, /* function_transform */
NULL, /* variable_transform */ NULL, /* variable_transform */
}; };
...@@ -2913,16 +2913,18 @@ estimate_node_size_and_time (struct cgraph_node *node, ...@@ -2913,16 +2913,18 @@ estimate_node_size_and_time (struct cgraph_node *node,
void void
estimate_ipcp_clone_size_and_time (struct cgraph_node *node, estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
VEC (tree, heap) *known_vals, VEC (tree, heap) *known_vals,
VEC (tree, heap) *known_binfos, VEC (tree, heap) *known_binfos,
int *ret_size, int *ret_time) VEC (ipa_agg_jump_function_p, heap) *known_aggs,
int *ret_size, int *ret_time,
inline_hints *hints)
{ {
clause_t clause; clause_t clause;
clause = evaluate_conditions_for_known_args (node, false, known_vals, NULL); clause = evaluate_conditions_for_known_args (node, false, known_vals,
estimate_node_size_and_time (node, clause, known_vals, known_binfos, NULL, known_aggs);
ret_size, ret_time, NULL, estimate_node_size_and_time (node, clause, known_vals, known_binfos,
NULL); known_aggs, ret_size, ret_time, hints, NULL);
} }
/* Translate all conditions from callee representation into caller /* Translate all conditions from callee representation into caller
......
...@@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License ...@@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */ <http://www.gnu.org/licenses/>. */
#include "ipa-prop.h"
/* Representation of inline parameters that do depend on context function is /* Representation of inline parameters that do depend on context function is
inlined into (i.e. known constant values of function parameters. inlined into (i.e. known constant values of function parameters.
...@@ -207,9 +209,9 @@ void initialize_inline_failed (struct cgraph_edge *); ...@@ -207,9 +209,9 @@ void initialize_inline_failed (struct cgraph_edge *);
int estimate_time_after_inlining (struct cgraph_node *, struct cgraph_edge *); int estimate_time_after_inlining (struct cgraph_node *, struct cgraph_edge *);
int estimate_size_after_inlining (struct cgraph_node *, struct cgraph_edge *); int estimate_size_after_inlining (struct cgraph_node *, struct cgraph_edge *);
void estimate_ipcp_clone_size_and_time (struct cgraph_node *, void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
VEC (tree, heap) *known_vals, VEC (tree, heap) *, VEC (tree, heap) *,
VEC (tree, heap) *known_binfos, VEC (ipa_agg_jump_function_p, heap) *,
int *, int *); int *, int *, inline_hints *);
int do_estimate_growth (struct cgraph_node *); int do_estimate_growth (struct cgraph_node *);
void inline_merge_summary (struct cgraph_edge *edge); void inline_merge_summary (struct cgraph_edge *edge);
void inline_update_overall_summary (struct cgraph_node *node); void inline_update_overall_summary (struct cgraph_node *node);
......
...@@ -40,7 +40,6 @@ along with GCC; see the file COPYING3. If not see ...@@ -40,7 +40,6 @@ along with GCC; see the file COPYING3. If not see
#include "tree-streamer.h" #include "tree-streamer.h"
#include "params.h" #include "params.h"
/* Intermediate information about a parameter that is only useful during the /* Intermediate information about a parameter that is only useful during the
run of ipa_analyze_node and is not kept afterwards. */ run of ipa_analyze_node and is not kept afterwards. */
...@@ -52,6 +51,8 @@ struct param_analysis_info ...@@ -52,6 +51,8 @@ struct param_analysis_info
/* Vector where the parameter infos are actually stored. */ /* Vector where the parameter infos are actually stored. */
VEC (ipa_node_params_t, heap) *ipa_node_params_vector; VEC (ipa_node_params_t, heap) *ipa_node_params_vector;
/* Vector of known aggregate values in cloned nodes. */
VEC (ipa_agg_replacement_value_p, gc) *ipa_node_agg_replacements;
/* Vector where the parameter infos are actually stored. */ /* Vector where the parameter infos are actually stored. */
VEC (ipa_edge_args_t, gc) *ipa_edge_args_vector; VEC (ipa_edge_args_t, gc) *ipa_edge_args_vector;
...@@ -1936,6 +1937,22 @@ ipa_analyze_params_uses (struct cgraph_node *node, ...@@ -1936,6 +1937,22 @@ ipa_analyze_params_uses (struct cgraph_node *node,
info->uses_analysis_done = 1; info->uses_analysis_done = 1;
} }
/* Free stuff in PARMS_AINFO, assume there are PARAM_COUNT parameters. */
static void
free_parms_ainfo (struct param_analysis_info *parms_ainfo, int param_count)
{
int i;
for (i = 0; i < param_count; i++)
{
if (parms_ainfo[i].parm_visited_statements)
BITMAP_FREE (parms_ainfo[i].parm_visited_statements);
if (parms_ainfo[i].pt_visited_statements)
BITMAP_FREE (parms_ainfo[i].pt_visited_statements);
}
}
/* Initialize the array describing properties of of formal parameters /* Initialize the array describing properties of of formal parameters
of NODE, analyze their uses and compute jump functions associated of NODE, analyze their uses and compute jump functions associated
with actual arguments of calls from within NODE. */ with actual arguments of calls from within NODE. */
...@@ -1945,7 +1962,7 @@ ipa_analyze_node (struct cgraph_node *node) ...@@ -1945,7 +1962,7 @@ ipa_analyze_node (struct cgraph_node *node)
{ {
struct ipa_node_params *info; struct ipa_node_params *info;
struct param_analysis_info *parms_ainfo; struct param_analysis_info *parms_ainfo;
int i, param_count; int param_count;
ipa_check_create_node_params (); ipa_check_create_node_params ();
ipa_check_create_edge_args (); ipa_check_create_edge_args ();
...@@ -1960,14 +1977,7 @@ ipa_analyze_node (struct cgraph_node *node) ...@@ -1960,14 +1977,7 @@ ipa_analyze_node (struct cgraph_node *node)
ipa_analyze_params_uses (node, parms_ainfo); ipa_analyze_params_uses (node, parms_ainfo);
ipa_compute_jump_functions (node, parms_ainfo); ipa_compute_jump_functions (node, parms_ainfo);
for (i = 0; i < param_count; i++) free_parms_ainfo (parms_ainfo, param_count);
{
if (parms_ainfo[i].parm_visited_statements)
BITMAP_FREE (parms_ainfo[i].parm_visited_statements);
if (parms_ainfo[i].pt_visited_statements)
BITMAP_FREE (parms_ainfo[i].pt_visited_statements);
}
pop_cfun (); pop_cfun ();
} }
...@@ -2163,17 +2173,13 @@ ipa_find_agg_cst_for_param (struct ipa_agg_jump_function *agg, ...@@ -2163,17 +2173,13 @@ ipa_find_agg_cst_for_param (struct ipa_agg_jump_function *agg,
return NULL; return NULL;
FOR_EACH_VEC_ELT (ipa_agg_jf_item_t, agg->items, i, item) FOR_EACH_VEC_ELT (ipa_agg_jf_item_t, agg->items, i, item)
{ if (item->offset == offset)
if (item->offset == offset) {
{ /* Currently we do not have clobber values, return NULL for them once
/* Currently we do not have clobber values, return NULL for them once we do. */
we do. */ gcc_checking_assert (is_gimple_ip_invariant (item->value));
gcc_checking_assert (is_gimple_ip_invariant (item->value)); return item->value;
return item->value; }
}
else if (item->offset > offset)
return NULL;
}
return NULL; return NULL;
} }
...@@ -2436,6 +2442,21 @@ ipa_free_all_node_params (void) ...@@ -2436,6 +2442,21 @@ ipa_free_all_node_params (void)
ipa_node_params_vector = NULL; ipa_node_params_vector = NULL;
} }
/* Set the aggregate replacements of NODE to be AGGVALS. */
void
ipa_set_node_agg_value_chain (struct cgraph_node *node,
struct ipa_agg_replacement_value *aggvals)
{
if (VEC_length (ipa_agg_replacement_value_p, ipa_node_agg_replacements)
<= (unsigned) cgraph_max_uid)
VEC_safe_grow_cleared (ipa_agg_replacement_value_p, gc,
ipa_node_agg_replacements, cgraph_max_uid + 1);
VEC_replace (ipa_agg_replacement_value_p, ipa_node_agg_replacements,
node->uid, aggvals);
}
/* Hook that is called by cgraph.c when an edge is removed. */ /* Hook that is called by cgraph.c when an edge is removed. */
static void static void
...@@ -2455,9 +2476,12 @@ ipa_node_removal_hook (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED) ...@@ -2455,9 +2476,12 @@ ipa_node_removal_hook (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
{ {
/* During IPA-CP updating we can be called on not-yet analyze clones. */ /* During IPA-CP updating we can be called on not-yet analyze clones. */
if (VEC_length (ipa_node_params_t, ipa_node_params_vector) if (VEC_length (ipa_node_params_t, ipa_node_params_vector)
<= (unsigned)node->uid) > (unsigned)node->uid)
return; ipa_free_node_params_substructures (IPA_NODE_REF (node));
ipa_free_node_params_substructures (IPA_NODE_REF (node)); if (VEC_length (ipa_agg_replacement_value_p, ipa_node_agg_replacements)
> (unsigned)node->uid)
VEC_replace (ipa_agg_replacement_value_p, ipa_node_agg_replacements,
(unsigned)node->uid, NULL);
} }
/* Hook that is called by cgraph.c when an edge is duplicated. */ /* Hook that is called by cgraph.c when an edge is duplicated. */
...@@ -2491,6 +2515,7 @@ ipa_node_duplication_hook (struct cgraph_node *src, struct cgraph_node *dst, ...@@ -2491,6 +2515,7 @@ ipa_node_duplication_hook (struct cgraph_node *src, struct cgraph_node *dst,
ATTRIBUTE_UNUSED void *data) ATTRIBUTE_UNUSED void *data)
{ {
struct ipa_node_params *old_info, *new_info; struct ipa_node_params *old_info, *new_info;
struct ipa_agg_replacement_value *old_av, *new_av;
ipa_check_create_node_params (); ipa_check_create_node_params ();
old_info = IPA_NODE_REF (src); old_info = IPA_NODE_REF (src);
...@@ -2503,6 +2528,23 @@ ipa_node_duplication_hook (struct cgraph_node *src, struct cgraph_node *dst, ...@@ -2503,6 +2528,23 @@ ipa_node_duplication_hook (struct cgraph_node *src, struct cgraph_node *dst,
new_info->uses_analysis_done = old_info->uses_analysis_done; new_info->uses_analysis_done = old_info->uses_analysis_done;
new_info->node_enqueued = old_info->node_enqueued; new_info->node_enqueued = old_info->node_enqueued;
old_av = ipa_get_agg_replacements_for_node (src);
if (!old_av)
return;
new_av = NULL;
while (old_av)
{
struct ipa_agg_replacement_value *v;
v = ggc_alloc_ipa_agg_replacement_value ();
memcpy (v, old_av, sizeof (*v));
v->next = new_av;
new_av = v;
old_av = old_av->next;
}
ipa_set_node_agg_value_chain (dst, new_av);
} }
...@@ -2564,6 +2606,7 @@ ipa_free_all_structures_after_ipa_cp (void) ...@@ -2564,6 +2606,7 @@ ipa_free_all_structures_after_ipa_cp (void)
ipa_free_all_node_params (); ipa_free_all_node_params ();
free_alloc_pool (ipcp_sources_pool); free_alloc_pool (ipcp_sources_pool);
free_alloc_pool (ipcp_values_pool); free_alloc_pool (ipcp_values_pool);
free_alloc_pool (ipcp_agg_lattice_pool);
ipa_unregister_cgraph_hooks (); ipa_unregister_cgraph_hooks ();
} }
} }
...@@ -2581,13 +2624,15 @@ ipa_free_all_structures_after_iinln (void) ...@@ -2581,13 +2624,15 @@ ipa_free_all_structures_after_iinln (void)
free_alloc_pool (ipcp_sources_pool); free_alloc_pool (ipcp_sources_pool);
if (ipcp_values_pool) if (ipcp_values_pool)
free_alloc_pool (ipcp_values_pool); free_alloc_pool (ipcp_values_pool);
if (ipcp_agg_lattice_pool)
free_alloc_pool (ipcp_agg_lattice_pool);
} }
/* Print ipa_tree_map data structures of all functions in the /* Print ipa_tree_map data structures of all functions in the
callgraph to F. */ callgraph to F. */
void void
ipa_print_node_params (FILE * f, struct cgraph_node *node) ipa_print_node_params (FILE *f, struct cgraph_node *node)
{ {
int i, count; int i, count;
tree temp; tree temp;
...@@ -3171,6 +3216,23 @@ ipa_dump_param_adjustments (FILE *file, ipa_parm_adjustment_vec adjustments, ...@@ -3171,6 +3216,23 @@ ipa_dump_param_adjustments (FILE *file, ipa_parm_adjustment_vec adjustments,
VEC_free (tree, heap, parms); VEC_free (tree, heap, parms);
} }
/* Dump the AV linked list. */
void
ipa_dump_agg_replacement_values (FILE *f, struct ipa_agg_replacement_value *av)
{
bool comma = false;
fprintf (f, " Aggregate replacements:");
for (; av; av = av->next)
{
fprintf (f, "%s %i[" HOST_WIDE_INT_PRINT_DEC "]=", comma ? "," : "",
av->index, av->offset);
print_generic_expr (f, av->value, 0);
comma = true;
}
fprintf (f, "\n");
}
/* Stream out jump function JUMP_FUNC to OB. */ /* Stream out jump function JUMP_FUNC to OB. */
static void static void
...@@ -3550,3 +3612,327 @@ ipa_update_after_lto_read (void) ...@@ -3550,3 +3612,327 @@ ipa_update_after_lto_read (void)
if (node->analyzed) if (node->analyzed)
ipa_initialize_node_params (node); ipa_initialize_node_params (node);
} }
void
write_agg_replacement_chain (struct output_block *ob, struct cgraph_node *node)
{
int node_ref;
unsigned int count = 0;
lto_symtab_encoder_t encoder;
struct ipa_agg_replacement_value *aggvals, *av;
aggvals = ipa_get_agg_replacements_for_node (node);
encoder = ob->decl_state->symtab_node_encoder;
node_ref = lto_symtab_encoder_encode (encoder, (symtab_node) node);
streamer_write_uhwi (ob, node_ref);
for (av = aggvals; av; av = av->next)
count++;
streamer_write_uhwi (ob, count);
for (av = aggvals; av; av = av->next)
{
streamer_write_uhwi (ob, av->offset);
streamer_write_uhwi (ob, av->index);
stream_write_tree (ob, av->value, true);
}
}
/* Stream in the aggregate value replacement chain for NODE from IB. */
static void
read_agg_replacement_chain (struct lto_input_block *ib,
struct cgraph_node *node,
struct data_in *data_in)
{
struct ipa_agg_replacement_value *aggvals = NULL;
unsigned int count, i;
count = streamer_read_uhwi (ib);
for (i = 0; i <count; i++)
{
struct ipa_agg_replacement_value *av;
av = ggc_alloc_ipa_agg_replacement_value ();
av->offset = streamer_read_uhwi (ib);
av->index = streamer_read_uhwi (ib);
av->value = stream_read_tree (ib, data_in);
av->next = aggvals;
aggvals = av;
}
ipa_set_node_agg_value_chain (node, aggvals);
}
/* Write all aggregate replacement for nodes in set. */
void
ipa_prop_write_all_agg_replacement (void)
{
struct cgraph_node *node;
struct output_block *ob;
unsigned int count = 0;
lto_symtab_encoder_iterator lsei;
lto_symtab_encoder_t encoder;
if (!ipa_node_agg_replacements)
return;
ob = create_output_block (LTO_section_ipcp_transform);
encoder = ob->decl_state->symtab_node_encoder;
ob->cgraph_node = NULL;
for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
lsei_next_function_in_partition (&lsei))
{
node = lsei_cgraph_node (lsei);
if (cgraph_function_with_gimple_body_p (node)
&& ipa_get_agg_replacements_for_node (node) != NULL)
count++;
}
streamer_write_uhwi (ob, count);
for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
lsei_next_function_in_partition (&lsei))
{
node = lsei_cgraph_node (lsei);
if (cgraph_function_with_gimple_body_p (node)
&& ipa_get_agg_replacements_for_node (node) != NULL)
write_agg_replacement_chain (ob, node);
}
streamer_write_char_stream (ob->main_stream, 0);
produce_asm (ob, NULL);
destroy_output_block (ob);
}
/* Read replacements section in file FILE_DATA of length LEN with data
DATA. */
static void
read_replacements_section (struct lto_file_decl_data *file_data,
const char *data,
size_t len)
{
const struct lto_function_header *header =
(const struct lto_function_header *) data;
const int cfg_offset = sizeof (struct lto_function_header);
const int main_offset = cfg_offset + header->cfg_size;
const int string_offset = main_offset + header->main_size;
struct data_in *data_in;
struct lto_input_block ib_main;
unsigned int i;
unsigned int count;
LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0,
header->main_size);
data_in = lto_data_in_create (file_data, (const char *) data + string_offset,
header->string_size, NULL);
count = streamer_read_uhwi (&ib_main);
for (i = 0; i < count; i++)
{
unsigned int index;
struct cgraph_node *node;
lto_symtab_encoder_t encoder;
index = streamer_read_uhwi (&ib_main);
encoder = file_data->symtab_node_encoder;
node = cgraph (lto_symtab_encoder_deref (encoder, index));
gcc_assert (node->analyzed);
read_agg_replacement_chain (&ib_main, node, data_in);
}
lto_free_section_data (file_data, LTO_section_jump_functions, NULL, data,
len);
lto_data_in_delete (data_in);
}
/* Read IPA-CP aggregate replacements. */
void
ipa_prop_read_all_agg_replacement (void)
{
struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
struct lto_file_decl_data *file_data;
unsigned int j = 0;
while ((file_data = file_data_vec[j++]))
{
size_t len;
const char *data = lto_get_section_data (file_data,
LTO_section_ipcp_transform,
NULL, &len);
if (data)
read_replacements_section (file_data, data, len);
}
}
/* Adjust the aggregate replacements in AGGVAL to reflect parameters skipped in
NODE. */
static void
adjust_agg_replacement_values (struct cgraph_node *node,
struct ipa_agg_replacement_value *aggval)
{
struct ipa_agg_replacement_value *v;
int i, c = 0, d = 0, *adj;
if (!node->clone.combined_args_to_skip)
return;
for (v = aggval; v; v = v->next)
{
gcc_assert (v->index >= 0);
if (c < v->index)
c = v->index;
}
c++;
adj = XALLOCAVEC (int, c);
for (i = 0; i < c; i++)
if (bitmap_bit_p (node->clone.combined_args_to_skip, i))
{
adj[i] = -1;
d++;
}
else
adj[i] = i - d;
for (v = aggval; v; v = v->next)
v->index = adj[v->index];
}
/* Function body transformation phase. */
unsigned int
ipcp_transform_function (struct cgraph_node *node)
{
VEC (ipa_param_descriptor_t, heap) *descriptors = NULL;
struct param_analysis_info *parms_ainfo;
struct ipa_agg_replacement_value *aggval;
gimple_stmt_iterator gsi;
basic_block bb;
int param_count;
bool cfg_changed = false, something_changed = false;
gcc_checking_assert (cfun);
gcc_checking_assert (current_function_decl);
if (dump_file)
fprintf (dump_file, "Modification phase of node %s/%i\n",
cgraph_node_name (node), node->uid);
aggval = ipa_get_agg_replacements_for_node (node);
if (!aggval)
return 0;
param_count = count_formal_params (node->symbol.decl);
if (param_count == 0)
return 0;
adjust_agg_replacement_values (node, aggval);
if (dump_file)
ipa_dump_agg_replacement_values (dump_file, aggval);
parms_ainfo = XALLOCAVEC (struct param_analysis_info, param_count);
memset (parms_ainfo, 0, sizeof (struct param_analysis_info) * param_count);
VEC_safe_grow_cleared (ipa_param_descriptor_t, heap,
descriptors, param_count);
ipa_populate_param_decls (node, descriptors);
FOR_EACH_BB (bb)
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
{
struct ipa_agg_replacement_value *v;
gimple stmt = gsi_stmt (gsi);
tree rhs, val, t;
HOST_WIDE_INT offset;
int index;
bool by_ref, vce;
if (!gimple_assign_load_p (stmt))
continue;
rhs = gimple_assign_rhs1 (stmt);
if (!is_gimple_reg_type (TREE_TYPE (rhs)))
continue;
vce = false;
t = rhs;
while (handled_component_p (t))
{
/* V_C_E can do things like convert an array of integers to one
bigger integer and similar things we do not handle below. */
if (TREE_CODE (rhs) == VIEW_CONVERT_EXPR)
{
vce = true;
break;
}
t = TREE_OPERAND (t, 0);
}
if (vce)
continue;
if (!ipa_load_from_parm_agg_1 (descriptors, parms_ainfo, stmt,
rhs, &index, &offset, &by_ref))
continue;
for (v = aggval; v; v = v->next)
if (v->index == index
&& v->offset == offset)
break;
if (!v)
continue;
gcc_checking_assert (is_gimple_ip_invariant (v->value));
if (!useless_type_conversion_p (TREE_TYPE (rhs), TREE_TYPE (v->value)))
{
if (fold_convertible_p (TREE_TYPE (rhs), v->value))
val = fold_build1 (NOP_EXPR, TREE_TYPE (rhs), v->value);
else if (TYPE_SIZE (TREE_TYPE (rhs))
== TYPE_SIZE (TREE_TYPE (v->value)))
val = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (rhs), v->value);
else
{
if (dump_file)
{
fprintf (dump_file, " const ");
print_generic_expr (dump_file, v->value, 0);
fprintf (dump_file, " can't be converted to type of ");
print_generic_expr (dump_file, rhs, 0);
fprintf (dump_file, "\n");
}
continue;
}
}
else
val = v->value;
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "Modifying stmt:\n ");
print_gimple_stmt (dump_file, stmt, 0, 0);
}
gimple_assign_set_rhs_from_tree (&gsi, val);
update_stmt (stmt);
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "into:\n ");
print_gimple_stmt (dump_file, stmt, 0, 0);
fprintf (dump_file, "\n");
}
something_changed = true;
if (maybe_clean_eh_stmt (stmt)
&& gimple_purge_dead_eh_edges (gimple_bb (stmt)))
cfg_changed = true;
}
VEC_replace (ipa_agg_replacement_value_p, ipa_node_agg_replacements,
node->uid, NULL);
free_parms_ainfo (parms_ainfo, param_count);
VEC_free (ipa_param_descriptor_t, heap, descriptors);
if (!something_changed)
return 0;
else if (cfg_changed)
return TODO_update_ssa_only_virtuals | TODO_cleanup_cfg;
else
return TODO_update_ssa_only_virtuals;
}
...@@ -144,6 +144,7 @@ typedef struct GTY(()) ipa_agg_jf_item ...@@ -144,6 +144,7 @@ typedef struct GTY(()) ipa_agg_jf_item
DEF_VEC_O (ipa_agg_jf_item_t); DEF_VEC_O (ipa_agg_jf_item_t);
DEF_VEC_ALLOC_O (ipa_agg_jf_item_t, gc); DEF_VEC_ALLOC_O (ipa_agg_jf_item_t, gc);
DEF_VEC_ALLOC_O (ipa_agg_jf_item_t, heap);
/* Aggregate jump function - i.e. description of contents of aggregates passed /* Aggregate jump function - i.e. description of contents of aggregates passed
either by reference or value. */ either by reference or value. */
...@@ -159,6 +160,9 @@ struct GTY(()) ipa_agg_jump_function ...@@ -159,6 +160,9 @@ struct GTY(()) ipa_agg_jump_function
typedef struct ipa_agg_jump_function *ipa_agg_jump_function_p; typedef struct ipa_agg_jump_function *ipa_agg_jump_function_p;
DEF_VEC_P (ipa_agg_jump_function_p); DEF_VEC_P (ipa_agg_jump_function_p);
DEF_VEC_ALLOC_P (ipa_agg_jump_function_p, heap); DEF_VEC_ALLOC_P (ipa_agg_jump_function_p, heap);
typedef struct ipa_agg_jump_function ipa_agg_jump_function_t;
DEF_VEC_P (ipa_agg_jump_function_t);
DEF_VEC_ALLOC_P (ipa_agg_jump_function_t, heap);
/* A jump function for a callsite represents the values passed as actual /* A jump function for a callsite represents the values passed as actual
arguments of the callsite. See enum jump_func_type for the various arguments of the callsite. See enum jump_func_type for the various
...@@ -322,7 +326,7 @@ struct ipa_node_params ...@@ -322,7 +326,7 @@ struct ipa_node_params
VEC (ipa_param_descriptor_t, heap) *descriptors; VEC (ipa_param_descriptor_t, heap) *descriptors;
/* Pointer to an array of structures describing individual formal /* Pointer to an array of structures describing individual formal
parameters. */ parameters. */
struct ipcp_lattice *lattices; struct ipcp_param_lattices *lattices;
/* Only for versioned nodes this field would not be NULL, /* Only for versioned nodes this field would not be NULL,
it points to the node that IPA cp cloned from. */ it points to the node that IPA cp cloned from. */
struct cgraph_node *ipcp_orig_node; struct cgraph_node *ipcp_orig_node;
...@@ -380,6 +384,27 @@ ipa_is_param_used (struct ipa_node_params *info, int i) ...@@ -380,6 +384,27 @@ ipa_is_param_used (struct ipa_node_params *info, int i)
return VEC_index (ipa_param_descriptor_t, info->descriptors, i).used; return VEC_index (ipa_param_descriptor_t, info->descriptors, i).used;
} }
/* Information about replacements done in aggregates for a given node (each
node has its linked list). */
struct GTY(()) ipa_agg_replacement_value
{
/* Next item in the linked list. */
struct ipa_agg_replacement_value *next;
/* Offset within the aggregate. */
HOST_WIDE_INT offset;
/* The constant value. */
tree value;
/* The paramter index. */
int index;
};
typedef struct ipa_agg_replacement_value *ipa_agg_replacement_value_p;
DEF_VEC_P (ipa_agg_replacement_value_p);
DEF_VEC_ALLOC_P (ipa_agg_replacement_value_p, gc);
void ipa_set_node_agg_value_chain (struct cgraph_node *node,
struct ipa_agg_replacement_value *aggvals);
/* ipa_edge_args stores information related to a callsite and particularly its /* ipa_edge_args stores information related to a callsite and particularly its
arguments. It can be accessed by the IPA_EDGE_REF macro. */ arguments. It can be accessed by the IPA_EDGE_REF macro. */
typedef struct GTY(()) ipa_edge_args typedef struct GTY(()) ipa_edge_args
...@@ -420,6 +445,8 @@ DEF_VEC_ALLOC_O (ipa_edge_args_t, gc); ...@@ -420,6 +445,8 @@ DEF_VEC_ALLOC_O (ipa_edge_args_t, gc);
/* Vector where the parameter infos are actually stored. */ /* Vector where the parameter infos are actually stored. */
extern VEC (ipa_node_params_t, heap) *ipa_node_params_vector; extern VEC (ipa_node_params_t, heap) *ipa_node_params_vector;
/* Vector of known aggregate values in cloned nodes. */
extern GTY(()) VEC (ipa_agg_replacement_value_p, gc) *ipa_node_agg_replacements;
/* Vector where the parameter infos are actually stored. */ /* Vector where the parameter infos are actually stored. */
extern GTY(()) VEC (ipa_edge_args_t, gc) *ipa_edge_args_vector; extern GTY(()) VEC (ipa_edge_args_t, gc) *ipa_edge_args_vector;
...@@ -487,6 +514,18 @@ ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge) ...@@ -487,6 +514,18 @@ ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
ipa_edge_args_vector)); ipa_edge_args_vector));
} }
/* Return the aggregate replacements for NODE, if there are any. */
static inline struct ipa_agg_replacement_value *
ipa_get_agg_replacements_for_node (struct cgraph_node *node)
{
if ((unsigned) node->uid >= VEC_length (ipa_agg_replacement_value_p,
ipa_node_agg_replacements))
return NULL;
return VEC_index (ipa_agg_replacement_value_p, ipa_node_agg_replacements,
node->uid);
}
/* Function formal parameters related computations. */ /* Function formal parameters related computations. */
void ipa_initialize_node_params (struct cgraph_node *node); void ipa_initialize_node_params (struct cgraph_node *node);
bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs, bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
...@@ -517,6 +556,7 @@ void ipcp_verify_propagated_values (void); ...@@ -517,6 +556,7 @@ void ipcp_verify_propagated_values (void);
extern alloc_pool ipcp_values_pool; extern alloc_pool ipcp_values_pool;
extern alloc_pool ipcp_sources_pool; extern alloc_pool ipcp_sources_pool;
extern alloc_pool ipcp_agg_lattice_pool;
/* Structure to describe transformations of formal parameters and actual /* Structure to describe transformations of formal parameters and actual
arguments. Each instance describes one new parameter and they are meant to arguments. Each instance describes one new parameter and they are meant to
...@@ -589,13 +629,17 @@ void ipa_modify_call_arguments (struct cgraph_edge *, gimple, ...@@ -589,13 +629,17 @@ void ipa_modify_call_arguments (struct cgraph_edge *, gimple,
ipa_parm_adjustment_vec ipa_combine_adjustments (ipa_parm_adjustment_vec, ipa_parm_adjustment_vec ipa_combine_adjustments (ipa_parm_adjustment_vec,
ipa_parm_adjustment_vec); ipa_parm_adjustment_vec);
void ipa_dump_param_adjustments (FILE *, ipa_parm_adjustment_vec, tree); void ipa_dump_param_adjustments (FILE *, ipa_parm_adjustment_vec, tree);
void ipa_dump_agg_replacement_values (FILE *f,
struct ipa_agg_replacement_value *av);
void ipa_prop_write_jump_functions (void); void ipa_prop_write_jump_functions (void);
void ipa_prop_read_jump_functions (void); void ipa_prop_read_jump_functions (void);
void ipa_prop_write_all_agg_replacement (void);
void ipa_prop_read_all_agg_replacement (void);
void ipa_update_after_lto_read (void); void ipa_update_after_lto_read (void);
int ipa_get_param_decl_index (struct ipa_node_params *, tree); int ipa_get_param_decl_index (struct ipa_node_params *, tree);
tree ipa_value_from_jfunc (struct ipa_node_params *info, tree ipa_value_from_jfunc (struct ipa_node_params *info,
struct ipa_jump_func *jfunc); struct ipa_jump_func *jfunc);
unsigned int ipcp_transform_function (struct cgraph_node *node);
/* From tree-sra.c: */ /* From tree-sra.c: */
......
...@@ -58,7 +58,8 @@ const char *lto_section_name[LTO_N_SECTION_TYPES] = ...@@ -58,7 +58,8 @@ const char *lto_section_name[LTO_N_SECTION_TYPES] =
"symbol_nodes", "symbol_nodes",
"opts", "opts",
"cgraphopt", "cgraphopt",
"inline" "inline",
"ipcp_trans"
}; };
......
...@@ -248,6 +248,7 @@ enum lto_section_type ...@@ -248,6 +248,7 @@ enum lto_section_type
LTO_section_opts, LTO_section_opts,
LTO_section_cgraph_opt_sum, LTO_section_cgraph_opt_sum,
LTO_section_inline_summary, LTO_section_inline_summary,
LTO_section_ipcp_transform,
LTO_N_SECTION_TYPES /* Must be last. */ LTO_N_SECTION_TYPES /* Must be last. */
}; };
......
...@@ -901,6 +901,12 @@ DEFPARAM (PARAM_IPA_MAX_AGG_ITEMS, ...@@ -901,6 +901,12 @@ DEFPARAM (PARAM_IPA_MAX_AGG_ITEMS,
"jump functions and lattices", "jump functions and lattices",
16, 0, 0) 16, 0, 0)
DEFPARAM (PARAM_IPA_CP_LOOP_HINT_BONUS,
"ipa-cp-loop-hint-bonus",
"Compile-time bonus IPA-CP assigns to candidates which make loop "
"bounds or strides known.",
64, 0, 0)
/* WHOPR partitioning configuration. */ /* WHOPR partitioning configuration. */
DEFPARAM (PARAM_LTO_PARTITIONS, DEFPARAM (PARAM_LTO_PARTITIONS,
......
2012-11-07 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/53787
* gcc.dg/ipa/ipa-5.c: Adjust.
* gcc.dg/ipa/ipcp-agg-1.c: New test.
* gcc.dg/ipa/ipcp-agg-2.c: Likewise.
* gcc.dg/ipa/ipcp-agg-3.c: Likewise.
* gcc.dg/ipa/ipcp-agg-4.c: Likewise.
* gcc.dg/ipa/ipcp-agg-5.c: Likewise.
* gcc.dg/ipa/ipcp-agg-6.c: Likewise.
* gfortran.dg/pr48636.f90: Add -fno-ipa-cp.
* gfortran.dg/pr48636-2.f90: New test.
* gfortran.dg/pr53787.f90: Likewise.
2012-11-07 Paolo Carlini <paolo.carlini@oracle.com> 2012-11-07 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/55226 PR c++/55226
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
/* Float & short constants. */ /* Float & short constants. */
#include <stdio.h> #include <stdio.h>
void t(void); int t(void);
int g (float b, short c) int g (float b, short c)
{ {
t(); t();
...@@ -13,10 +13,11 @@ int g (float b, short c) ...@@ -13,10 +13,11 @@ int g (float b, short c)
} }
int f (float a) int f (float a)
{ {
t(); int i, j = t();
/* a is modified. */ /* a is modified. */
if (a++ > 0) if (a++ > 0)
g (a, 3); for (i = 0; i < j; i++)
g (a, 3);
} }
int main () int main ()
{ {
...@@ -26,7 +27,7 @@ int main () ...@@ -26,7 +27,7 @@ int main ()
return 0; return 0;
} }
/* { dg-final { scan-ipa-dump-times "Creating a specialized node" 2 "cp" } } */ /* { dg-final { scan-ipa-dump-times "Creating a specialized node" 3 "cp" } } */
/* { dg-final { scan-ipa-dump "replacing param c with const 3" "cp" } } */ /* { dg-final { scan-ipa-dump "replacing param c with const 3" "cp" } } */
/* { dg-final { scan-ipa-dump "replacing param a with const 7" "cp" } } */ /* { dg-final { scan-ipa-dump "replacing param a with const 7" "cp" } } */
/* { dg-final { cleanup-ipa-dump "cp" } } */ /* { dg-final { cleanup-ipa-dump "cp" } } */
/* { dg-do compile } */
/* { dg-options "-O3 -fno-ipa-sra -fdump-ipa-cp-details -fdump-tree-optimized-slim" } */
/* { dg-add-options bind_pic_locally } */
struct S
{
int a, b, c;
};
void *blah(int, void *);
static void __attribute__ ((noinline))
foo (struct S *p)
{
int i, c = p->c;
int b = p->b;
void *v = (void *) p;
for (i= 0; i< c; i++)
v = blah(b + i, v);
}
void
entry (void)
{
struct S s;
s.a = 1;
s.b = 64;
s.c = 32;
foo (&s);
}
/* { dg-final { scan-ipa-dump "Creating a specialized node of foo.*for all known contexts" "cp" } } */
/* { dg-final { scan-ipa-dump-times "Aggregate replacements:" 2 "cp" } } */
/* { dg-final { cleanup-ipa-dump "cp" } } */
/* { dg-final { scan-tree-dump-not "->c;" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
/* { dg-do compile } */
/* { dg-options "-O3 -fno-ipa-sra -fdump-ipa-cp-details -fdump-tree-optimized-slim" } */
/* { dg-add-options bind_pic_locally } */
struct S
{
int a, b, c;
};
void *blah(int, void *);
static void __attribute__ ((noinline))
foo (struct S *p)
{
int i, c = p->c;
int b = p->b;
void *v = (void *) p;
for (i= 0; i< c; i++)
v = blah(b + i, v);
}
void
entry (int c)
{
struct S s;
int i;
for (i = 0; i<c; i++)
{
s.a = 1;
s.b = 64;
s.c = 32;
foo (&s);
}
s.c = 2;
foo (&s);
}
/* { dg-final { scan-ipa-dump-times "Creating a specialized node of foo/\[0-9\]*\\." 2 "cp" } } */
/* { dg-final { scan-ipa-dump-times "Aggregate replacements:" 4 "cp" } } */
/* { dg-final { cleanup-ipa-dump "cp" } } */
/* { dg-final { scan-tree-dump-not "->c;" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
/* { dg-do compile } */
/* { dg-options "-O3 -fno-ipa-sra -fdump-ipa-cp-details -fdump-tree-optimized-slim" } */
/* { dg-add-options bind_pic_locally } */
struct S
{
int a, b, c;
};
void *blah(int, void *);
static void __attribute__ ((noinline))
foo (int z, struct S *p)
{
int i, c = p->c;
int b = p->b;
void *v = (void *) p;
for (i= 0; i< c; i++)
v = blah(b + i, v);
}
void
entry (int c)
{
struct S s;
int i;
for (i = 0; i<c; i++)
{
s.a = 1;
s.b = 64;
s.c = 32;
foo (i, &s);
}
s.c = 2;
foo (0, &s);
}
/* { dg-final { scan-ipa-dump-times "Creating a specialized node of foo/\[0-9\]*\\." 2 "cp" } } */
/* { dg-final { scan-ipa-dump-times "Aggregate replacements: 1" 2 "cp" } } */
/* { dg-final { scan-ipa-dump-times "Aggregate replacements: 0" 2 "cp" } } */
/* { dg-final { cleanup-ipa-dump "cp" } } */
/* { dg-final { scan-tree-dump-not "->c;" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
/* { dg-do compile } */
/* { dg-options "-O3 -fno-ipa-sra -fdump-ipa-cp-details -fdump-tree-optimized-slim" } */
/* { dg-add-options bind_pic_locally } */
struct S
{
int a, b, c;
};
void *blah(int, void *);
static void __attribute__ ((noinline))
foo (struct S *p)
{
int i, c = p->c;
int b = p->b;
void *v = (void *) p;
for (i= 0; i< c; i++)
v = blah(b + i, v);
}
void
entry1 (int c)
{
struct S s;
int i;
for (i = 0; i<c; i++)
{
s.a = 1;
s.b = 64;
s.c = 32;
foo (&s);
}
s.c = 2;
foo (&s);
}
void
entry2 (int c)
{
struct S s;
int i;
for (i = 0; i<c; i++)
{
s.a = 6;
s.b = 64;
s.c = 32;
foo (&s);
}
s.c = 2;
foo (&s);
}
/* { dg-final { scan-ipa-dump-times "Creating a specialized node of foo/\[0-9\]*\\." 2 "cp" } } */
/* { dg-final { scan-ipa-dump-times "Aggregate replacements:" 4 "cp" } } */
/* { dg-final { cleanup-ipa-dump "cp" } } */
/* { dg-final { scan-tree-dump-not "->c;" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
/* { dg-do compile } */
/* { dg-options "-O3 -fno-ipa-sra -fdump-ipa-cp-details -fdump-tree-optimized-slim" } */
/* { dg-add-options bind_pic_locally } */
struct S
{
int a, b, c;
};
void *blah(int, void *);
static void __attribute__ ((noinline))
foo (struct S *p)
{
int i, c = p->c;
int b = p->b;
void *v = (void *) p;
for (i= 0; i< c; i++)
v = blah(b + i, v);
}
static void __attribute__ ((noinline))
bar (struct S *p)
{
foo (p);
}
void
entry1 (int c)
{
struct S s;
int i;
for (i = 0; i<c; i++)
{
s.a = 1;
s.b = 64;
s.c = 32;
bar (&s);
}
s.c = 2;
bar (&s);
}
void
entry2 (int c)
{
struct S s;
int i;
for (i = 0; i<c; i++)
{
s.a = 6;
s.b = 64;
s.c = 32;
foo (&s);
}
s.c = 2;
foo (&s);
}
/* { dg-final { scan-ipa-dump-times "Creating a specialized node of foo/\[0-9\]*\\." 2 "cp" } } */
/* { dg-final { scan-ipa-dump-times "Creating a specialized node of bar/\[0-9\]*\\." 2 "cp" } } */
/* { dg-final { scan-ipa-dump-times "Aggregate replacements:" 8 "cp" } } */
/* { dg-final { cleanup-ipa-dump "cp" } } */
/* { dg-final { scan-tree-dump-not "->c;" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
/* { dg-do compile } */
/* { dg-options "-O3 -fno-ipa-sra -fdump-ipa-cp-details -fdump-tree-optimized-slim" } */
/* { dg-add-options bind_pic_locally } */
struct S
{
int a, b, c;
};
void *blah(int, void *);
static void __attribute__ ((noinline))
foo (struct S *p)
{
int i, c = p->c;
int b = p->b;
void *v = (void *) p;
for (i= 0; i< c; i++)
v = blah(b + i, v);
}
static void __attribute__ ((noinline))
bar (struct S *p)
{
foo (p);
}
static void __attribute__ ((noinline))
bar_2 (struct S *p)
{
foo (p);
}
void
entry1 (int c)
{
struct S s;
int i;
for (i = 0; i<c; i++)
{
s.a = 1;
s.b = 64;
s.c = 32;
bar (&s);
}
s.c = 2;
bar (&s);
}
void
entry2 (int c)
{
struct S s;
int i;
for (i = 0; i<c; i++)
{
s.a = 6;
s.b = 64;
s.c = 32;
bar_2 (&s);
}
s.c = 2;
foo (&s);
}
/* { dg-final { scan-ipa-dump-times "Creating a specialized node of foo/\[0-9\]*\\." 2 "cp" } } */
/* { dg-final { scan-ipa-dump-times "Creating a specialized node of bar/\[0-9\]*\\." 2 "cp" } } */
/* { dg-final { scan-ipa-dump "Creating a specialized node of bar_2.*for all known contexts" "cp" } } */
/* { dg-final { scan-ipa-dump-times "Aggregate replacements:" 10 "cp" } } */
/* { dg-final { cleanup-ipa-dump "cp" } } */
/* { dg-final { scan-tree-dump-not "->c;" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
! { dg-do compile }
! { dg-options "-O3 -fdump-ipa-cp-details -fno-inline" }
module foo
implicit none
contains
subroutine bar(a,x)
real, dimension(:,:), intent(in) :: a
real, intent(out) :: x
integer :: i,j
x = 0
do j=1,ubound(a,2)
do i=1,ubound(a,1)
x = x + a(i,j)**2
end do
end do
end subroutine bar
end module foo
program main
use foo
implicit none
real, dimension(2,3) :: a
real :: x
integer :: i
data a /1.0, 2.0, 3.0, -1.0, -2.0, -3.0/
do i=1,2000000
call bar(a,x)
end do
print *,x
end program main
! { dg-final { scan-ipa-dump "Creating a specialized node of bar/\[0-9\]*\\." "cp" } }
! { dg-final { scan-ipa-dump-times "Aggregate replacements\[^=\]*=\[^=\]*=\[^=\]*=\[^=\]*=\[^=\]*=\[^=\]*=\[^=\]*=\[^=\]*=\[^=\]*=" 2 "cp" } }
! { dg-final { cleanup-ipa-dump "cp" } }
! { dg-do compile } ! { dg-do compile }
! { dg-options "-O3 -fdump-ipa-inline-details" } ! { dg-options "-O3 -fdump-ipa-inline-details -fno-ipa-cp" }
module foo module foo
implicit none implicit none
......
! { dg-do compile }
! { dg-options "-O3 -fdump-ipa-cp-details -fno-inline -fwhole-program" }
real x(10)
n = 10
call init(x,n)
print *, x
end program
subroutine init(x, n)
real x(10)
do i=1,n
x(i) = i*i + 1
enddo
return
end subroutine init
! { dg-final { scan-ipa-dump "Creating a specialized node of init" "cp" } }
! { dg-final { scan-ipa-dump-times "Aggregate replacements" 2 "cp" } }
! { dg-final { cleanup-ipa-dump "cp" } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment