Re: [PATCH] Use range based loops to iterate over vec<> in various places
On 6/8/21 6:48 PM, Trevor Saunders wrote: Hello, This makes things a good bit shorter, and reduces complexity by removing a bunch of index variables. Very nice cleanup! Thank you! Martin bootstrapped and regtested on x86_64-linux-gnu, ok? Trev gcc/analyzer/ChangeLog: * call-string.cc (call_string::call_string): Iterate over vec<> with range based for. (call_string::operator=): Likewise. (call_string::to_json): Likewise. (call_string::hash): Likewise. (call_string::calc_recursion_depth): Likewise. * checker-path.cc (checker_path::fixup_locations): Likewise. * constraint-manager.cc (equiv_class::equiv_class): Likewise. (equiv_class::to_json): Likewise. (equiv_class::hash): Likewise. (constraint_manager::constraint_manager): Likewise. (constraint_manager::operator=): Likewise. (constraint_manager::hash): Likewise. (constraint_manager::to_json): Likewise. (constraint_manager::add_unknown_constraint): Likewise. * engine.cc (impl_region_model_context::on_svalue_leak): Likewise. (on_liveness_change): Likewise. (impl_region_model_context::on_unknown_change): Likewise. * program-state.cc (extrinsic_state::to_json): Likewise. (sm_state_map::set_state): Likewise. * region-model.cc (make_test_compound_type): Likewise. (test_canonicalization_4): Likewise. gcc/ChangeLog: * auto-profile.c (afdo_find_equiv_class): Iterate over vec<> with range based for. * cgraphclones.c (cgraph_node::create_clone): Likewise. (cgraph_node::create_version_clone): Likewise. * dwarf2out.c (output_call_frame_info): Likewise. * gcc.c (do_specs_vec): Likewise. (do_spec_1): Likewise. (driver::set_up_specs): Likewise. * gimple-loop-jam.c (any_access_function_variant_p): Likewise. * ifcvt.c (cond_move_process_if_block): Likewise. * ipa-modref.c (modref_lattice::add_escape_point): Likewise. (analyze_parms): Likewise. (modref_write_escape_summary): Likewise. (update_escape_summary_1): Likewise. * ipa-prop.h (ipa_copy_agg_values): Likewise. (ipa_release_agg_values): Likewise. * lower-subreg.c (decompose_multiword_subregs): Likewise. * lto-streamer-out.c (DFS::DFS_write_tree_body): Likewise. (hash_tree): Likewise. (prune_offload_funcs): Likewise. * sel-sched-dump.c (dump_insn_vector): Likewise. * timevar.c (timer::named_items::print): Likewise. * tree-cfgcleanup.c (cleanup_control_flow_pre): Likewise. (cleanup_tree_cfg_noloop): Likewise. * tree-data-ref.c (dump_data_references): Likewise. (print_dir_vectors): Likewise. (print_dist_vectors): Likewise. (dump_data_dependence_relation): Likewise. (dump_data_dependence_relations): Likewise. (dump_dist_dir_vectors): Likewise. (dump_ddrs): Likewise. (prune_runtime_alias_test_list): Likewise. (create_runtime_alias_checks): Likewise. (free_subscripts): Likewise. (save_dist_v): Likewise. (save_dir_v): Likewise. (invariant_access_functions): Likewise. (same_access_functions): Likewise. (access_functions_are_affine_or_constant_p): Likewise. (compute_all_dependences): Likewise. (find_data_references_in_stmt): Likewise. (graphite_find_data_references_in_stmt): Likewise. (free_dependence_relations): Likewise. (free_data_refs): Likewise. * tree-into-ssa.c (dump_currdefs): Likewise. (rewrite_update_phi_arguments): Likewise. * tree-ssa-phiopt.c (cond_if_else_store_replacement): Likewise. * tree-ssa-propagate.c (clean_up_loop_closed_phi): Likewise. * tree-ssa-structalias.c (constraint_set_union): Likewise. (merge_node_constraints): Likewise. (move_complex_constraints): Likewise. (do_deref): Likewise. (get_constraint_for_address_of): Likewise. (get_constraint_for_1): Likewise. (process_all_all_constraints): Likewise. (make_constraints_to): Likewise. (handle_rhs_call): Likewise. * tree-vect-data-refs.c (vect_analyze_possibly_independent_ddr): Likewise. (vect_slp_analyze_node_dependences): Likewise. (vect_slp_analyze_instance_dependence): Likewise. (vect_record_base_alignments): Likewise. (vect_get_peeling_costs_all_drs): Likewise. (vect_peeling_supportable): Likewise. * tree-vectorizer.c (vec_info::~vec_info): Likewise. (vec_info::free_stmt_vec_infos): Likewise. gcc/c/ChangeLog: * c-parser.c (c_parser_translation_unit): Iterate over vec<> with range based for. (c_parser_postfix_expression): Likewise. gcc/cp/ChangeLog: * constexpr.c (cxx_eval_call_expression): Iterate over
Re: [PATCH] Use range based loops to iterate over vec<> in various places
On Wed, Jun 9, 2021 at 1:32 PM Trevor Saunders wrote: > > On Wed, Jun 09, 2021 at 01:06:44PM +0200, Richard Biener wrote: > > On Wed, Jun 9, 2021 at 2:48 AM Trevor Saunders > > wrote: > > > > > > Hello, > > > > > > This makes things a good bit shorter, and reduces complexity by removing > > > a bunch of index variables. > > > > > > bootstrapped and regtested on x86_64-linux-gnu, ok? > > > > I'd call the cases where you are able to remove the iterator variable > > declarations obvious, but there are some where the element variable > > remains declared and thus one wonders if the last elem initialization > > is used. Splitting the patch into the obvious (pre-approved) and > > not-so obvious parts would be nice. The not-so obvious pieces would > > be more obvious if the retained decl were moved down to its first > > use. > > Yeah, sorry its a long patch, and that's a sensible idea for making it > more managable, sorry I didn't think of it the first time. There's also > cases where people use the index within the loop for something, kind of > peaking through the "abstraction" of the macro if you want to see it > that way. > > > That said - how may FOR_EACH_VEC_ELT macro invocations > > remain? Can we remove it? > > Very many, this is maybe a hundred of what started as about 1000 uses. > There is certainly more cases that can be converted over, but I needed > to stop at some point. There's also a bunch of cases that use the index > for something, usually either checking if its the last element if > printing a list, or using the index to index into the vector or > something else. However I suppose those uses might be better as for > (unsigned i = 0; i < vec.size (); i++). I'll see about spliting out the > obvious cases and finding more of those and once that's done we can see > about the rest. OK, agreed. Thanks, Richard. > thanks > > Trev > > > > > Thanks, > > Richard. > > > > > Trev > > > > > > gcc/analyzer/ChangeLog: > > > > > > * call-string.cc (call_string::call_string): Iterate over vec<> > > > with range based for. > > > (call_string::operator=): Likewise. > > > (call_string::to_json): Likewise. > > > (call_string::hash): Likewise. > > > (call_string::calc_recursion_depth): Likewise. > > > * checker-path.cc (checker_path::fixup_locations): Likewise. > > > * constraint-manager.cc (equiv_class::equiv_class): Likewise. > > > (equiv_class::to_json): Likewise. > > > (equiv_class::hash): Likewise. > > > (constraint_manager::constraint_manager): Likewise. > > > (constraint_manager::operator=): Likewise. > > > (constraint_manager::hash): Likewise. > > > (constraint_manager::to_json): Likewise. > > > (constraint_manager::add_unknown_constraint): Likewise. > > > * engine.cc (impl_region_model_context::on_svalue_leak): > > > Likewise. > > > (on_liveness_change): Likewise. > > > (impl_region_model_context::on_unknown_change): Likewise. > > > * program-state.cc (extrinsic_state::to_json): Likewise. > > > (sm_state_map::set_state): Likewise. > > > * region-model.cc (make_test_compound_type): Likewise. > > > (test_canonicalization_4): Likewise. > > > > > > gcc/ChangeLog: > > > > > > * auto-profile.c (afdo_find_equiv_class): Iterate over vec<> > > > with range based for. > > > * cgraphclones.c (cgraph_node::create_clone): Likewise. > > > (cgraph_node::create_version_clone): Likewise. > > > * dwarf2out.c (output_call_frame_info): Likewise. > > > * gcc.c (do_specs_vec): Likewise. > > > (do_spec_1): Likewise. > > > (driver::set_up_specs): Likewise. > > > * gimple-loop-jam.c (any_access_function_variant_p): Likewise. > > > * ifcvt.c (cond_move_process_if_block): Likewise. > > > * ipa-modref.c (modref_lattice::add_escape_point): Likewise. > > > (analyze_parms): Likewise. > > > (modref_write_escape_summary): Likewise. > > > (update_escape_summary_1): Likewise. > > > * ipa-prop.h (ipa_copy_agg_values): Likewise. > > > (ipa_release_agg_values): Likewise. > > > * lower-subreg.c (decompose_multiword_subregs): Likewise. > > > * lto-streamer-out.c (DFS::DFS_write_tree_body): Likewise. > > > (hash_tree): Likewise. > > > (prune_offload_funcs): Likewise. > > > * sel-sched-dump.c (dump_insn_vector): Likewise. > > > * timevar.c (timer::named_items::print): Likewise. > > > * tree-cfgcleanup.c (cleanup_control_flow_pre): Likewise. > > > (cleanup_tree_cfg_noloop): Likewise. > > > * tree-data-ref.c (dump_data_references): Likewise. > > > (print_dir_vectors): Likewise. > > > (print_dist_vectors): Likewise. > > > (dump_data_dependence_relation): Likewise. > > > (dump_data_dependence_relations): Likewise. > > >
Re: [PATCH] Use range based loops to iterate over vec<> in various places
On Wed, Jun 09, 2021 at 01:06:44PM +0200, Richard Biener wrote: > On Wed, Jun 9, 2021 at 2:48 AM Trevor Saunders wrote: > > > > Hello, > > > > This makes things a good bit shorter, and reduces complexity by removing > > a bunch of index variables. > > > > bootstrapped and regtested on x86_64-linux-gnu, ok? > > I'd call the cases where you are able to remove the iterator variable > declarations obvious, but there are some where the element variable > remains declared and thus one wonders if the last elem initialization > is used. Splitting the patch into the obvious (pre-approved) and > not-so obvious parts would be nice. The not-so obvious pieces would > be more obvious if the retained decl were moved down to its first > use. Yeah, sorry its a long patch, and that's a sensible idea for making it more managable, sorry I didn't think of it the first time. There's also cases where people use the index within the loop for something, kind of peaking through the "abstraction" of the macro if you want to see it that way. > That said - how may FOR_EACH_VEC_ELT macro invocations > remain? Can we remove it? Very many, this is maybe a hundred of what started as about 1000 uses. There is certainly more cases that can be converted over, but I needed to stop at some point. There's also a bunch of cases that use the index for something, usually either checking if its the last element if printing a list, or using the index to index into the vector or something else. However I suppose those uses might be better as for (unsigned i = 0; i < vec.size (); i++). I'll see about spliting out the obvious cases and finding more of those and once that's done we can see about the rest. thanks Trev > > Thanks, > Richard. > > > Trev > > > > gcc/analyzer/ChangeLog: > > > > * call-string.cc (call_string::call_string): Iterate over vec<> > > with range based for. > > (call_string::operator=): Likewise. > > (call_string::to_json): Likewise. > > (call_string::hash): Likewise. > > (call_string::calc_recursion_depth): Likewise. > > * checker-path.cc (checker_path::fixup_locations): Likewise. > > * constraint-manager.cc (equiv_class::equiv_class): Likewise. > > (equiv_class::to_json): Likewise. > > (equiv_class::hash): Likewise. > > (constraint_manager::constraint_manager): Likewise. > > (constraint_manager::operator=): Likewise. > > (constraint_manager::hash): Likewise. > > (constraint_manager::to_json): Likewise. > > (constraint_manager::add_unknown_constraint): Likewise. > > * engine.cc (impl_region_model_context::on_svalue_leak): > > Likewise. > > (on_liveness_change): Likewise. > > (impl_region_model_context::on_unknown_change): Likewise. > > * program-state.cc (extrinsic_state::to_json): Likewise. > > (sm_state_map::set_state): Likewise. > > * region-model.cc (make_test_compound_type): Likewise. > > (test_canonicalization_4): Likewise. > > > > gcc/ChangeLog: > > > > * auto-profile.c (afdo_find_equiv_class): Iterate over vec<> > > with range based for. > > * cgraphclones.c (cgraph_node::create_clone): Likewise. > > (cgraph_node::create_version_clone): Likewise. > > * dwarf2out.c (output_call_frame_info): Likewise. > > * gcc.c (do_specs_vec): Likewise. > > (do_spec_1): Likewise. > > (driver::set_up_specs): Likewise. > > * gimple-loop-jam.c (any_access_function_variant_p): Likewise. > > * ifcvt.c (cond_move_process_if_block): Likewise. > > * ipa-modref.c (modref_lattice::add_escape_point): Likewise. > > (analyze_parms): Likewise. > > (modref_write_escape_summary): Likewise. > > (update_escape_summary_1): Likewise. > > * ipa-prop.h (ipa_copy_agg_values): Likewise. > > (ipa_release_agg_values): Likewise. > > * lower-subreg.c (decompose_multiword_subregs): Likewise. > > * lto-streamer-out.c (DFS::DFS_write_tree_body): Likewise. > > (hash_tree): Likewise. > > (prune_offload_funcs): Likewise. > > * sel-sched-dump.c (dump_insn_vector): Likewise. > > * timevar.c (timer::named_items::print): Likewise. > > * tree-cfgcleanup.c (cleanup_control_flow_pre): Likewise. > > (cleanup_tree_cfg_noloop): Likewise. > > * tree-data-ref.c (dump_data_references): Likewise. > > (print_dir_vectors): Likewise. > > (print_dist_vectors): Likewise. > > (dump_data_dependence_relation): Likewise. > > (dump_data_dependence_relations): Likewise. > > (dump_dist_dir_vectors): Likewise. > > (dump_ddrs): Likewise. > > (prune_runtime_alias_test_list): Likewise. > > (create_runtime_alias_checks): Likewise. > > (free_subscripts): Likewise. > > (save_dist_v): Likewise. > > (save_dir_v): Likewise. > >
Re: [PATCH] Use range based loops to iterate over vec<> in various places
On Wed, Jun 9, 2021 at 2:48 AM Trevor Saunders wrote: > > Hello, > > This makes things a good bit shorter, and reduces complexity by removing > a bunch of index variables. > > bootstrapped and regtested on x86_64-linux-gnu, ok? I'd call the cases where you are able to remove the iterator variable declarations obvious, but there are some where the element variable remains declared and thus one wonders if the last elem initialization is used. Splitting the patch into the obvious (pre-approved) and not-so obvious parts would be nice. The not-so obvious pieces would be more obvious if the retained decl were moved down to its first use. That said - how may FOR_EACH_VEC_ELT macro invocations remain? Can we remove it? Thanks, Richard. > Trev > > gcc/analyzer/ChangeLog: > > * call-string.cc (call_string::call_string): Iterate over vec<> > with range based for. > (call_string::operator=): Likewise. > (call_string::to_json): Likewise. > (call_string::hash): Likewise. > (call_string::calc_recursion_depth): Likewise. > * checker-path.cc (checker_path::fixup_locations): Likewise. > * constraint-manager.cc (equiv_class::equiv_class): Likewise. > (equiv_class::to_json): Likewise. > (equiv_class::hash): Likewise. > (constraint_manager::constraint_manager): Likewise. > (constraint_manager::operator=): Likewise. > (constraint_manager::hash): Likewise. > (constraint_manager::to_json): Likewise. > (constraint_manager::add_unknown_constraint): Likewise. > * engine.cc (impl_region_model_context::on_svalue_leak): > Likewise. > (on_liveness_change): Likewise. > (impl_region_model_context::on_unknown_change): Likewise. > * program-state.cc (extrinsic_state::to_json): Likewise. > (sm_state_map::set_state): Likewise. > * region-model.cc (make_test_compound_type): Likewise. > (test_canonicalization_4): Likewise. > > gcc/ChangeLog: > > * auto-profile.c (afdo_find_equiv_class): Iterate over vec<> > with range based for. > * cgraphclones.c (cgraph_node::create_clone): Likewise. > (cgraph_node::create_version_clone): Likewise. > * dwarf2out.c (output_call_frame_info): Likewise. > * gcc.c (do_specs_vec): Likewise. > (do_spec_1): Likewise. > (driver::set_up_specs): Likewise. > * gimple-loop-jam.c (any_access_function_variant_p): Likewise. > * ifcvt.c (cond_move_process_if_block): Likewise. > * ipa-modref.c (modref_lattice::add_escape_point): Likewise. > (analyze_parms): Likewise. > (modref_write_escape_summary): Likewise. > (update_escape_summary_1): Likewise. > * ipa-prop.h (ipa_copy_agg_values): Likewise. > (ipa_release_agg_values): Likewise. > * lower-subreg.c (decompose_multiword_subregs): Likewise. > * lto-streamer-out.c (DFS::DFS_write_tree_body): Likewise. > (hash_tree): Likewise. > (prune_offload_funcs): Likewise. > * sel-sched-dump.c (dump_insn_vector): Likewise. > * timevar.c (timer::named_items::print): Likewise. > * tree-cfgcleanup.c (cleanup_control_flow_pre): Likewise. > (cleanup_tree_cfg_noloop): Likewise. > * tree-data-ref.c (dump_data_references): Likewise. > (print_dir_vectors): Likewise. > (print_dist_vectors): Likewise. > (dump_data_dependence_relation): Likewise. > (dump_data_dependence_relations): Likewise. > (dump_dist_dir_vectors): Likewise. > (dump_ddrs): Likewise. > (prune_runtime_alias_test_list): Likewise. > (create_runtime_alias_checks): Likewise. > (free_subscripts): Likewise. > (save_dist_v): Likewise. > (save_dir_v): Likewise. > (invariant_access_functions): Likewise. > (same_access_functions): Likewise. > (access_functions_are_affine_or_constant_p): Likewise. > (compute_all_dependences): Likewise. > (find_data_references_in_stmt): Likewise. > (graphite_find_data_references_in_stmt): Likewise. > (free_dependence_relations): Likewise. > (free_data_refs): Likewise. > * tree-into-ssa.c (dump_currdefs): Likewise. > (rewrite_update_phi_arguments): Likewise. > * tree-ssa-phiopt.c (cond_if_else_store_replacement): Likewise. > * tree-ssa-propagate.c (clean_up_loop_closed_phi): Likewise. > * tree-ssa-structalias.c (constraint_set_union): Likewise. > (merge_node_constraints): Likewise. > (move_complex_constraints): Likewise. > (do_deref): Likewise. > (get_constraint_for_address_of): Likewise. > (get_constraint_for_1): Likewise. > (process_all_all_constraints): Likewise. > (make_constraints_to): Likewise. > (handle_rhs_call): Likewise. > * tree-vect-data-refs.c
[PATCH] Use range based loops to iterate over vec<> in various places
Hello, This makes things a good bit shorter, and reduces complexity by removing a bunch of index variables. bootstrapped and regtested on x86_64-linux-gnu, ok? Trev gcc/analyzer/ChangeLog: * call-string.cc (call_string::call_string): Iterate over vec<> with range based for. (call_string::operator=): Likewise. (call_string::to_json): Likewise. (call_string::hash): Likewise. (call_string::calc_recursion_depth): Likewise. * checker-path.cc (checker_path::fixup_locations): Likewise. * constraint-manager.cc (equiv_class::equiv_class): Likewise. (equiv_class::to_json): Likewise. (equiv_class::hash): Likewise. (constraint_manager::constraint_manager): Likewise. (constraint_manager::operator=): Likewise. (constraint_manager::hash): Likewise. (constraint_manager::to_json): Likewise. (constraint_manager::add_unknown_constraint): Likewise. * engine.cc (impl_region_model_context::on_svalue_leak): Likewise. (on_liveness_change): Likewise. (impl_region_model_context::on_unknown_change): Likewise. * program-state.cc (extrinsic_state::to_json): Likewise. (sm_state_map::set_state): Likewise. * region-model.cc (make_test_compound_type): Likewise. (test_canonicalization_4): Likewise. gcc/ChangeLog: * auto-profile.c (afdo_find_equiv_class): Iterate over vec<> with range based for. * cgraphclones.c (cgraph_node::create_clone): Likewise. (cgraph_node::create_version_clone): Likewise. * dwarf2out.c (output_call_frame_info): Likewise. * gcc.c (do_specs_vec): Likewise. (do_spec_1): Likewise. (driver::set_up_specs): Likewise. * gimple-loop-jam.c (any_access_function_variant_p): Likewise. * ifcvt.c (cond_move_process_if_block): Likewise. * ipa-modref.c (modref_lattice::add_escape_point): Likewise. (analyze_parms): Likewise. (modref_write_escape_summary): Likewise. (update_escape_summary_1): Likewise. * ipa-prop.h (ipa_copy_agg_values): Likewise. (ipa_release_agg_values): Likewise. * lower-subreg.c (decompose_multiword_subregs): Likewise. * lto-streamer-out.c (DFS::DFS_write_tree_body): Likewise. (hash_tree): Likewise. (prune_offload_funcs): Likewise. * sel-sched-dump.c (dump_insn_vector): Likewise. * timevar.c (timer::named_items::print): Likewise. * tree-cfgcleanup.c (cleanup_control_flow_pre): Likewise. (cleanup_tree_cfg_noloop): Likewise. * tree-data-ref.c (dump_data_references): Likewise. (print_dir_vectors): Likewise. (print_dist_vectors): Likewise. (dump_data_dependence_relation): Likewise. (dump_data_dependence_relations): Likewise. (dump_dist_dir_vectors): Likewise. (dump_ddrs): Likewise. (prune_runtime_alias_test_list): Likewise. (create_runtime_alias_checks): Likewise. (free_subscripts): Likewise. (save_dist_v): Likewise. (save_dir_v): Likewise. (invariant_access_functions): Likewise. (same_access_functions): Likewise. (access_functions_are_affine_or_constant_p): Likewise. (compute_all_dependences): Likewise. (find_data_references_in_stmt): Likewise. (graphite_find_data_references_in_stmt): Likewise. (free_dependence_relations): Likewise. (free_data_refs): Likewise. * tree-into-ssa.c (dump_currdefs): Likewise. (rewrite_update_phi_arguments): Likewise. * tree-ssa-phiopt.c (cond_if_else_store_replacement): Likewise. * tree-ssa-propagate.c (clean_up_loop_closed_phi): Likewise. * tree-ssa-structalias.c (constraint_set_union): Likewise. (merge_node_constraints): Likewise. (move_complex_constraints): Likewise. (do_deref): Likewise. (get_constraint_for_address_of): Likewise. (get_constraint_for_1): Likewise. (process_all_all_constraints): Likewise. (make_constraints_to): Likewise. (handle_rhs_call): Likewise. * tree-vect-data-refs.c (vect_analyze_possibly_independent_ddr): Likewise. (vect_slp_analyze_node_dependences): Likewise. (vect_slp_analyze_instance_dependence): Likewise. (vect_record_base_alignments): Likewise. (vect_get_peeling_costs_all_drs): Likewise. (vect_peeling_supportable): Likewise. * tree-vectorizer.c (vec_info::~vec_info): Likewise. (vec_info::free_stmt_vec_infos): Likewise. gcc/c/ChangeLog: * c-parser.c (c_parser_translation_unit): Iterate over vec<> with range based for. (c_parser_postfix_expression): Likewise. gcc/cp/ChangeLog: * constexpr.c (cxx_eval_call_expression): Iterate over vec<> with range based for. (cxx_eval_store_expression): Likewise.