public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use range based loops to iterate over vec<> in various places
@ 2021-06-09  0:48 Trevor Saunders
  2021-06-09 11:06 ` Richard Biener
  2021-06-09 15:00 ` Martin Sebor
  0 siblings, 2 replies; 5+ messages in thread
From: Trevor Saunders @ 2021-06-09  0:48 UTC (permalink / raw)
  To: gcc-patches; +Cc: Trevor Saunders

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.
	(cxx_eval_loop_expr): Likewise.
	(cxx_eval_outermost_constant_expr): Likewise.
	* decl.c (wrapup_namespace_globals): Likewise.
	(cp_finish_decl): Likewise.
	(cxx_simulate_enum_decl): Likewise.
	* parser.c (cp_parser_postfix_expression): Likewise.

Signed-off-by: Trevor Saunders <tbsaunde@tbsaunde.org>
---
 gcc/analyzer/call-string.cc        |  18 ++---
 gcc/analyzer/checker-path.cc       |   4 +-
 gcc/analyzer/constraint-manager.cc |  73 +++++++----------
 gcc/analyzer/engine.cc             |  12 +--
 gcc/analyzer/program-state.cc      |   6 +-
 gcc/analyzer/region-model.cc       |   6 +-
 gcc/auto-profile.c                 |   6 +-
 gcc/c/c-parser.c                   |  11 +--
 gcc/cgraphclones.c                 |   6 +-
 gcc/cp/constexpr.c                 |  23 ++----
 gcc/cp/decl.c                      |  15 ++--
 gcc/cp/parser.c                    |   4 +-
 gcc/dwarf2out.c                    |   2 +-
 gcc/gcc.c                          |  13 +--
 gcc/gimple-loop-jam.c              |   4 +-
 gcc/ifcvt.c                        |   6 +-
 gcc/ipa-modref.c                   |  52 +++++-------
 gcc/ipa-prop.h                     |  15 +---
 gcc/lower-subreg.c                 |  11 +--
 gcc/lto-streamer-out.c             |  12 +--
 gcc/sel-sched-dump.c               |   5 +-
 gcc/timevar.c                      |   4 +-
 gcc/tree-cfgcleanup.c              |   8 +-
 gcc/tree-data-ref.c                | 123 +++++++++--------------------
 gcc/tree-into-ssa.c                |   9 +--
 gcc/tree-ssa-phiopt.c              |   7 +-
 gcc/tree-ssa-propagate.c           |   4 +-
 gcc/tree-ssa-structalias.c         |  78 +++++++-----------
 gcc/tree-vect-data-refs.c          |  30 +++----
 gcc/tree-vectorizer.c              |   9 +--
 30 files changed, 183 insertions(+), 393 deletions(-)

diff --git a/gcc/analyzer/call-string.cc b/gcc/analyzer/call-string.cc
index 224b2e2fb0e..fc4db0f8741 100644
--- a/gcc/analyzer/call-string.cc
+++ b/gcc/analyzer/call-string.cc
@@ -50,9 +50,7 @@ along with GCC; see the file COPYING3.  If not see
 call_string::call_string (const call_string &other)
 : m_return_edges (other.m_return_edges.length ())
 {
-  const return_superedge *e;
-  int i;
-  FOR_EACH_VEC_ELT (other.m_return_edges, i, e)
+  for (const return_superedge *e : other.m_return_edges)
     m_return_edges.quick_push (e);
 }
 
@@ -66,7 +64,7 @@ call_string::operator= (const call_string &other)
   m_return_edges.reserve (other.m_return_edges.length (), true);
   const return_superedge *e;
   int i;
-  FOR_EACH_VEC_ELT (other.m_return_edges, i, e)
+  for (const return_superedge *e : other.m_return_edges)
     m_return_edges.quick_push (e);
   return *this;
 }
@@ -118,9 +116,7 @@ call_string::to_json () const
 {
   json::array *arr = new json::array ();
 
-  const return_superedge *e;
-  int i;
-  FOR_EACH_VEC_ELT (m_return_edges, i, e)
+  for (const return_superedge *e : m_return_edges)
     {
       json::object *e_obj = new json::object ();
       e_obj->set ("src_snode_idx",
@@ -141,9 +137,7 @@ hashval_t
 call_string::hash () const
 {
   inchash::hash hstate;
-  int i;
-  const return_superedge *e;
-  FOR_EACH_VEC_ELT (m_return_edges, i, e)
+  for (const return_superedge *e : m_return_edges)
     hstate.add_ptr (e);
   return hstate.end ();
 }
@@ -173,9 +167,7 @@ call_string::calc_recursion_depth () const
     = m_return_edges[m_return_edges.length () - 1];
 
   int result = 0;
-  const return_superedge *e;
-  int i;
-  FOR_EACH_VEC_ELT (m_return_edges, i, e)
+  for (const return_superedge *e : m_return_edges)
     if (e == top_return_sedge)
       ++result;
   return result;
diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc
index 7d229bbf823..e6f838b7d52 100644
--- a/gcc/analyzer/checker-path.cc
+++ b/gcc/analyzer/checker-path.cc
@@ -1001,9 +1001,7 @@ checker_path::add_final_event (const state_machine *sm,
 void
 checker_path::fixup_locations (pending_diagnostic *pd)
 {
-  checker_event *e;
-  int i;
-  FOR_EACH_VEC_ELT (m_events, i, e)
+  for (checker_event *e : m_events)
     e->set_location (pd->fixup_location (e->get_location ()));
 }
 
diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc
index 4dadd200bee..318b2d8e890 100644
--- a/gcc/analyzer/constraint-manager.cc
+++ b/gcc/analyzer/constraint-manager.cc
@@ -270,9 +270,7 @@ equiv_class::equiv_class (const equiv_class &other)
 : m_constant (other.m_constant), m_cst_sval (other.m_cst_sval),
   m_vars (other.m_vars.length ())
 {
-  int i;
-  const svalue *sval;
-  FOR_EACH_VEC_ELT (other.m_vars, i, sval)
+  for (const svalue *sval : other.m_vars)
     m_vars.quick_push (sval);
 }
 
@@ -310,9 +308,7 @@ equiv_class::to_json () const
   json::object *ec_obj = new json::object ();
 
   json::array *sval_arr = new json::array ();
-  int i;
-  const svalue *sval;
-  FOR_EACH_VEC_ELT (m_vars, i, sval)
+  for (const svalue *sval : m_vars)
     sval_arr->append (sval->to_json ());
   ec_obj->set ("svals", sval_arr);
 
@@ -337,9 +333,7 @@ equiv_class::hash () const
   inchash::hash hstate;
 
   inchash::add_expr (m_constant, hstate);
-  int i;
-  const svalue *sval;
-  FOR_EACH_VEC_ELT (m_vars, i, sval)
+  for (const svalue * sval : m_vars)
     hstate.add_ptr (sval);
   return hstate.end ();
 }
@@ -620,13 +614,11 @@ constraint_manager::constraint_manager (const constraint_manager &other)
   m_constraints (other.m_constraints.length ()),
   m_mgr (other.m_mgr)
 {
-  int i;
-  equiv_class *ec;
-  FOR_EACH_VEC_ELT (other.m_equiv_classes, i, ec)
+  for (const equiv_class *ec : other.m_equiv_classes)
     m_equiv_classes.quick_push (new equiv_class (*ec));
-  constraint *c;
-  FOR_EACH_VEC_ELT (other.m_constraints, i, c)
-    m_constraints.quick_push (*c);
+
+  for (const constraint &c : other.m_constraints)
+    m_constraints.quick_push (c);
 }
 
 /* constraint_manager's assignment operator.  */
@@ -637,15 +629,13 @@ constraint_manager::operator= (const constraint_manager &other)
   gcc_assert (m_equiv_classes.length () == 0);
   gcc_assert (m_constraints.length () == 0);
 
-  int i;
-  equiv_class *ec;
   m_equiv_classes.reserve (other.m_equiv_classes.length ());
-  FOR_EACH_VEC_ELT (other.m_equiv_classes, i, ec)
+  for (const equiv_class *ec : other.m_equiv_classes)
     m_equiv_classes.quick_push (new equiv_class (*ec));
-  constraint *c;
+
   m_constraints.reserve (other.m_constraints.length ());
-  FOR_EACH_VEC_ELT (other.m_constraints, i, c)
-    m_constraints.quick_push (*c);
+  for (const constraint &c : other.m_constraints)
+    m_constraints.quick_push (c);
 
   return *this;
 }
@@ -656,14 +646,11 @@ hashval_t
 constraint_manager::hash () const
 {
   inchash::hash hstate;
-  int i;
-  equiv_class *ec;
-  constraint *c;
 
-  FOR_EACH_VEC_ELT (m_equiv_classes, i, ec)
+  for (const equiv_class *ec : m_equiv_classes)
     hstate.merge_hash (ec->hash ());
-  FOR_EACH_VEC_ELT (m_constraints, i, c)
-    hstate.merge_hash (c->hash ());
+  for (const constraint &c : m_constraints)
+    hstate.merge_hash (c.hash ());
   return hstate.end ();
 }
 
@@ -811,9 +798,7 @@ constraint_manager::to_json () const
   /* Equivalence classes.  */
   {
     json::array *ec_arr = new json::array ();
-    int i;
-    equiv_class *ec;
-    FOR_EACH_VEC_ELT (m_equiv_classes, i, ec)
+    for (const equiv_class *ec : m_equiv_classes)
       ec_arr->append (ec->to_json ());
     cm_obj->set ("ecs", ec_arr);
   }
@@ -821,10 +806,8 @@ constraint_manager::to_json () const
   /* Constraints.  */
   {
     json::array *con_arr = new json::array ();
-    int i;
-    constraint *c;
-    FOR_EACH_VEC_ELT (m_constraints, i, c)
-      con_arr->append (c->to_json ());
+    for (const constraint &c : m_constraints)
+      con_arr->append (c.to_json ());
     cm_obj->set ("constraints", con_arr);
   }
 
@@ -927,9 +910,7 @@ constraint_manager::add_unknown_constraint (equiv_class_id lhs_ec_id,
 	equiv_class &lhs_ec_obj = lhs_ec_id.get_obj (*this);
 	const equiv_class &rhs_ec_obj = rhs_ec_id.get_obj (*this);
 
-	int i;
-	const svalue *sval;
-	FOR_EACH_VEC_ELT (rhs_ec_obj.m_vars, i, sval)
+	for (const svalue *sval : rhs_ec_obj.m_vars)
 	  lhs_ec_obj.add (sval);
 
 	if (rhs_ec_obj.m_constant)
@@ -949,21 +930,21 @@ constraint_manager::add_unknown_constraint (equiv_class_id lhs_ec_id,
 
 	/* Update the constraints.  */
 	constraint *c;
-	FOR_EACH_VEC_ELT (m_constraints, i, c)
+	for (constraint &c : m_constraints)
 	  {
 	    /* Update references to the rhs_ec so that
 	       they refer to the lhs_ec.  */
-	    if (c->m_lhs == rhs_ec_id)
-	      c->m_lhs = lhs_ec_id;
-	    if (c->m_rhs == rhs_ec_id)
-	      c->m_rhs = lhs_ec_id;
+	    if (c.m_lhs == rhs_ec_id)
+	      c.m_lhs = lhs_ec_id;
+	    if (c.m_rhs == rhs_ec_id)
+	      c.m_rhs = lhs_ec_id;
 
 	    /* Renumber all constraints that refer to the final rhs_ec
 	       to the old rhs_ec, where the old final_ec now lives.  */
-	    if (c->m_lhs == final_ec_id)
-	      c->m_lhs = rhs_ec_id;
-	    if (c->m_rhs == final_ec_id)
-	      c->m_rhs = rhs_ec_id;
+	    if (c.m_lhs == final_ec_id)
+	      c.m_lhs = rhs_ec_id;
+	    if (c.m_rhs == final_ec_id)
+	      c.m_rhs = rhs_ec_id;
 	  }
 
 	/* We may now have self-comparisons due to the merger; these
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 5b519fdf385..7444e7d6394 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -121,9 +121,7 @@ void
 impl_region_model_context::on_svalue_leak (const svalue *sval)
 
 {
-  int sm_idx;
-  sm_state_map *smap;
-  FOR_EACH_VEC_ELT (m_new_state->m_checker_states, sm_idx, smap)
+  for (sm_state_map *smap : m_new_state->m_checker_states)
     smap->on_svalue_leak (sval, this);
 }
 
@@ -132,9 +130,7 @@ impl_region_model_context::
 on_liveness_change (const svalue_set &live_svalues,
 		    const region_model *model)
 {
-  int sm_idx;
-  sm_state_map *smap;
-  FOR_EACH_VEC_ELT (m_new_state->m_checker_states, sm_idx, smap)
+  for (sm_state_map *smap : m_new_state->m_checker_states)
     smap->on_liveness_change (live_svalues, model, this);
 }
 
@@ -142,9 +138,7 @@ void
 impl_region_model_context::on_unknown_change (const svalue *sval,
 					      bool is_mutable)
 {
-  int sm_idx;
-  sm_state_map *smap;
-  FOR_EACH_VEC_ELT (m_new_state->m_checker_states, sm_idx, smap)
+  for (sm_state_map *smap : m_new_state->m_checker_states)
     smap->on_unknown_change (sval, is_mutable, m_ext_state);
 }
 
diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc
index 5c690b08fd3..e961d86dfc5 100644
--- a/gcc/analyzer/program-state.cc
+++ b/gcc/analyzer/program-state.cc
@@ -112,7 +112,7 @@ extrinsic_state::to_json () const
     json::array *checkers_arr = new json::array ();
     unsigned i;
     state_machine *sm;
-    FOR_EACH_VEC_ELT (m_checkers, i, sm)
+    for (state_machine *sm : m_checkers)
       checkers_arr->append (sm->to_json ());
     ext_state_obj->set ("checkers", checkers_arr);
   }
@@ -441,10 +441,8 @@ sm_state_map::set_state (const equiv_class &ec,
 			 const svalue *origin,
 			 const extrinsic_state &ext_state)
 {
-  int i;
-  const svalue *sval;
   bool any_changed = false;
-  FOR_EACH_VEC_ELT (ec.m_vars, i, sval)
+  for (const svalue *sval : ec.m_vars)
     any_changed |= impl_set_state (sval, state, origin, ext_state);
   return any_changed;
 }
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index c7038dd2d4b..8d1882337b2 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -3413,7 +3413,7 @@ make_test_compound_type (const char *name, bool is_struct,
   tree fieldlist = NULL;
   int i;
   tree field;
-  FOR_EACH_VEC_ELT (*fields, i, field)
+  for (tree field : *fields)
     {
       gcc_assert (TREE_CODE (field) == FIELD_DECL);
       DECL_CONTEXT (field) = t;
@@ -4231,9 +4231,7 @@ test_canonicalization_4 ()
   region_model_manager mgr;
   region_model model (&mgr);
 
-  unsigned i;
-  tree cst;
-  FOR_EACH_VEC_ELT (csts, i, cst)
+  for (tree cst : csts)
     model.get_rvalue (cst, NULL);
 
   model.canonicalize ();
diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c
index 2a6d9a1fc24..9dc9eb5dd43 100644
--- a/gcc/auto-profile.c
+++ b/gcc/auto-profile.c
@@ -1156,14 +1156,12 @@ afdo_find_equiv_class (bb_set *annotated_bb)
   FOR_ALL_BB_FN (bb, cfun)
   {
     vec<basic_block> dom_bbs;
-    basic_block bb1;
-    int i;
 
     if (bb->aux != NULL)
       continue;
     bb->aux = bb;
     dom_bbs = get_dominated_by (CDI_DOMINATORS, bb);
-    FOR_EACH_VEC_ELT (dom_bbs, i, bb1)
+    for (basic_block bb1 : dom_bbs)
       if (bb1->aux == NULL && dominated_by_p (CDI_POST_DOMINATORS, bb, bb1)
 	  && bb1->loop_father == bb->loop_father)
 	{
@@ -1175,7 +1173,7 @@ afdo_find_equiv_class (bb_set *annotated_bb)
 	    }
 	}
     dom_bbs = get_dominated_by (CDI_POST_DOMINATORS, bb);
-    FOR_EACH_VEC_ELT (dom_bbs, i, bb1)
+    for (basic_block bb1 : dom_bbs)
       if (bb1->aux == NULL && dominated_by_p (CDI_DOMINATORS, bb, bb1)
 	  && bb1->loop_father == bb->loop_father)
 	{
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index add33532a60..6eea27de68e 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1653,9 +1653,7 @@ c_parser_translation_unit (c_parser *parser)
       while (c_parser_next_token_is_not (parser, CPP_EOF));
     }
 
-  unsigned int i;
-  tree decl;
-  FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl)
+  for (tree decl : incomplete_record_decls)
     if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node)
       error ("storage size of %q+D isn%'t known", decl);
 
@@ -9354,10 +9352,8 @@ c_parser_postfix_expression (c_parser *parser)
 		break;
 	      }
 
-	    unsigned int i;
-	    c_expr_t *p;
-	    FOR_EACH_VEC_ELT (*cexpr_list, i, p)
-	      *p = convert_lvalue_to_rvalue (loc, *p, true, true);
+	    for (c_expr_t &p : *cexpr_list)
+	      p = convert_lvalue_to_rvalue (loc, p, true, true);
 	    unsigned int nargs = check_tgmath_function (&(*cexpr_list)[0], 1);
 	    if (nargs == 0)
 	      {
@@ -9565,6 +9561,7 @@ c_parser_postfix_expression (c_parser *parser)
 	    bool all_binary = true;
 	    bool all_decimal = true;
 	    hash_set<tree> tg_types;
+	    unsigned i;
 	    FOR_EACH_VEC_ELT (tg_type, i, t)
 	      {
 		if (TREE_CODE (t) == COMPLEX_TYPE)
diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index 9f86463b42d..fc8eae76cbe 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -362,7 +362,6 @@ cgraph_node::create_clone (tree new_decl, profile_count prof_count,
 {
   cgraph_node *new_node = symtab->create_empty ();
   cgraph_edge *e;
-  unsigned i;
   profile_count old_count = count;
   bool nonzero = count.ipa ().nonzero_p ();
 
@@ -419,7 +418,7 @@ cgraph_node::create_clone (tree new_decl, profile_count prof_count,
 	 = vec_safe_copy (info->performed_splits);
   new_node->split_part = split_part;
 
-  FOR_EACH_VEC_ELT (redirect_callers, i, e)
+  for (cgraph_edge *e : redirect_callers)
     {
       /* Redirect calls to the old version node to point to its new
 	 version.  The only exception is when the edge was proved to
@@ -919,7 +918,6 @@ cgraph_node::create_version_clone (tree new_decl,
  {
    cgraph_node *new_version;
    cgraph_edge *e;
-   unsigned i;
 
    new_version = cgraph_node::create (new_decl);
 
@@ -948,7 +946,7 @@ cgraph_node::create_version_clone (tree new_decl,
        e->clone (new_version, e->call_stmt,
 		 e->lto_stmt_uid, count, count,
 		 true);
-   FOR_EACH_VEC_ELT (redirect_callers, i, e)
+   for (cgraph_edge *e : redirect_callers)
      {
        /* Redirect calls to the old version node to point to its new
 	  version.  */
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 297f2072de8..18f0be82fb5 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -2790,9 +2790,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
 
 	  /* Forget the saved values of the callee's SAVE_EXPRs and
 	     TARGET_EXPRs.  */
-	  unsigned int i;
-	  tree save_expr;
-	  FOR_EACH_VEC_ELT (save_exprs, i, save_expr)
+	  for (tree save_expr : save_exprs)
 	    ctx->global->values.remove (save_expr);
 
 	  /* Remove the parms/result from the values map.  Is it worth
@@ -5466,9 +5464,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
 	     semantics are not applied on an object under construction.
 	     They come into effect when the constructor for the most
 	     derived object ends."  */
-	  tree elt;
-	  unsigned int i;
-	  FOR_EACH_VEC_ELT (*ctors, i, elt)
+	  for (tree elt : *ctors)
 	    if (same_type_ignoring_top_level_qualifiers_p
 		(TREE_TYPE (const_object_being_modified), TREE_TYPE (elt)))
 	      {
@@ -5576,12 +5572,10 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
 
   /* Update TREE_CONSTANT and TREE_SIDE_EFFECTS on enclosing
      CONSTRUCTORs, if any.  */
-  tree elt;
-  unsigned i;
   bool c = TREE_CONSTANT (init);
   bool s = TREE_SIDE_EFFECTS (init);
   if (!c || s || activated_union_member_p)
-    FOR_EACH_VEC_ELT (*ctors, i, elt)
+    for (tree elt : *ctors)
       {
 	if (!c)
 	  TREE_CONSTANT (elt) = false;
@@ -5899,9 +5893,7 @@ cxx_eval_loop_expr (const constexpr_ctx *ctx, tree t,
 	}
 
       /* Forget saved values of SAVE_EXPRs and TARGET_EXPRs.  */
-      unsigned int i;
-      tree save_expr;
-      FOR_EACH_VEC_ELT (save_exprs, i, save_expr)
+      for (tree save_expr : save_exprs)
 	ctx->global->values.remove (save_expr);
       save_exprs.truncate (0);
 
@@ -5923,9 +5915,7 @@ cxx_eval_loop_expr (const constexpr_ctx *ctx, tree t,
 	 && !*non_constant_p);
 
   /* Forget saved values of SAVE_EXPRs and TARGET_EXPRs.  */
-  unsigned int i;
-  tree save_expr;
-  FOR_EACH_VEC_ELT (save_exprs, i, save_expr)
+  for (tree save_expr : save_exprs)
     ctx->global->values.remove (save_expr);
 
   return NULL_TREE;
@@ -7290,7 +7280,6 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
     {
       tree heap_var = cp_walk_tree_without_duplicates (&r, find_heap_var_refs,
 						       NULL);
-      unsigned int i;
       if (heap_var)
 	{
 	  if (!allow_non_constant && !non_constant_p)
@@ -7300,7 +7289,7 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
 	  r = t;
 	  non_constant_p = true;
 	}
-      FOR_EACH_VEC_ELT (global_ctx.heap_vars, i, heap_var)
+      for (tree heap_var : global_ctx.heap_vars)
 	{
 	  if (DECL_NAME (heap_var) != heap_deleted_identifier)
 	    {
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a3687dbb0dd..de75bff93dc 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -828,9 +828,7 @@ wrapup_namespace_globals ()
 {
   if (vec<tree, va_gc> *statics = static_decls)
     {
-      tree decl;
-      unsigned int i;
-      FOR_EACH_VEC_ELT (*statics, i, decl)
+      for (tree decl : *statics)
 	{
 	  if (warn_unused_function
 	      && TREE_CODE (decl) == FUNCTION_DECL
@@ -8237,8 +8235,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
      reference, insert it in the statement-tree now.  */
   if (cleanups)
     {
-      unsigned i; tree t;
-      FOR_EACH_VEC_ELT (*cleanups, i, t)
+      for (tree t : *cleanups)
 	push_cleanup (decl, t, false);
       release_tree_vector (cleanups);
     }
@@ -16390,11 +16387,9 @@ cxx_simulate_enum_decl (location_t loc, const char *name,
   SET_OPAQUE_ENUM_P (enumtype, false);
   DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
 
-  string_int_pair *value;
-  unsigned int i;
-  FOR_EACH_VEC_ELT (values, i, value)
-    build_enumerator (get_identifier (value->first),
-		      build_int_cst (integer_type_node, value->second),
+  for (const string_int_pair &value : values)
+    build_enumerator (get_identifier (value.first),
+		      build_int_cst (integer_type_node, value.second),
 		      enumtype, NULL_TREE, loc);
 
   finish_enum_value_list (enumtype);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 24f248af11c..a41fc51e0ab 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -7299,8 +7299,6 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
     case RID_BUILTIN_LAUNDER:
       {
 	vec<tree, va_gc> *vec;
-	unsigned int i;
-	tree p;
 
 	cp_lexer_consume_token (parser->lexer);
 	vec = cp_parser_parenthesized_expression_list (parser, non_attr,
@@ -7312,7 +7310,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
 	    break;
 	  }
 
-	FOR_EACH_VEC_ELT (*vec, i, p)
+	for (tree p : *vec)
 	  mark_exp_read (p);
 
 	switch (keyword)
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 88eb3f9c455..cd1401238a5 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -784,7 +784,7 @@ output_call_frame_info (int for_eh)
     {
       bool any_eh_needed = false;
 
-      FOR_EACH_VEC_ELT (*fde_vec, i, fde)
+      for (dw_fde_ref fde : fde_vec)
 	{
 	  if (fde->uses_eh_lsda)
 	    any_eh_needed = any_lsda_needed = true;
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 4c1a659d5e8..af286400a4a 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -5838,10 +5838,7 @@ compile_input_file_p (struct infile *infile)
 static void
 do_specs_vec (vec<char_p> vec)
 {
-  unsigned ix;
-  char *opt;
-
-  FOR_EACH_VEC_ELT (vec, ix, opt)
+  for (char *opt : vec)
     {
       do_spec_1 (opt, 1, NULL);
       /* Make each accumulated option a separate argument.  */
@@ -6436,8 +6433,6 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
 	    {
 	      const char *p1 = p;
 	      char *string;
-	      char *opt;
-	      unsigned ix;
 
 	      /* Skip past the option value and make a copy.  */
 	      if (*p != '{')
@@ -6448,7 +6443,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
 	      string = save_string (p1 + 1, p - p1 - 2);
 
 	      /* See if we already recorded this option.  */
-	      FOR_EACH_VEC_ELT (linker_options, ix, opt)
+	      for (const char *opt : linker_options)
 		if (! strcmp (string, opt))
 		  {
 		    free (string);
@@ -8316,9 +8311,7 @@ driver::set_up_specs () const
       && do_spec_2 (startfile_prefix_spec, NULL) == 0
       && do_spec_1 (" ", 0, NULL) == 0)
     {
-      const char *arg;
-      int ndx;
-      FOR_EACH_VEC_ELT (argbuf, ndx, arg)
+      for (const char *arg : argbuf)
 	add_sysrooted_prefix (&startfile_prefixes, arg, "BINUTILS",
 			      PREFIX_PRIORITY_LAST, 0, 1);
     }
diff --git a/gcc/gimple-loop-jam.c b/gcc/gimple-loop-jam.c
index 69dbaeb6cb9..4842f0dff80 100644
--- a/gcc/gimple-loop-jam.c
+++ b/gcc/gimple-loop-jam.c
@@ -365,11 +365,9 @@ static bool
 any_access_function_variant_p (const struct data_reference *a,
 			       const class loop *loop_nest)
 {
-  unsigned int i;
   vec<tree> fns = DR_ACCESS_FNS (a);
-  tree t;
 
-  FOR_EACH_VEC_ELT (fns, i, t)
+  for (tree t : fns)
     if (!evolution_function_is_invariant_p (t, loop_nest->num))
       return true;
 
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 6ee44cbada2..6112cccf734 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -3889,11 +3889,9 @@ cond_move_process_if_block (struct noce_if_info *if_info)
   rtx_insn *jump = if_info->jump;
   rtx cond = if_info->cond;
   rtx_insn *seq, *loc_insn;
-  rtx reg;
   int c;
   vec<rtx> then_regs = vNULL;
   vec<rtx> else_regs = vNULL;
-  unsigned int i;
   int success_p = FALSE;
   int limit = param_max_rtl_if_conversion_insns;
 
@@ -3915,7 +3913,7 @@ cond_move_process_if_block (struct noce_if_info *if_info)
      source register does not change after the assignment.  Also count
      the number of registers set in only one of the blocks.  */
   c = 0;
-  FOR_EACH_VEC_ELT (then_regs, i, reg)
+  for (rtx reg : then_regs)
     {
       rtx *then_slot = then_vals.get (reg);
       rtx *else_slot = else_vals.get (reg);
@@ -3934,7 +3932,7 @@ cond_move_process_if_block (struct noce_if_info *if_info)
     }
 
   /* Finish off c for MAX_CONDITIONAL_EXECUTE.  */
-  FOR_EACH_VEC_ELT (else_regs, i, reg)
+  for (rtx reg : else_regs)
     {
       gcc_checking_assert (else_vals.get (reg));
       if (!then_vals.get (reg))
diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index d5a8332fb55..551b60b8931 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -1406,20 +1406,17 @@ bool
 modref_lattice::add_escape_point (gcall *call, int arg, int min_flags,
 				  bool direct)
 {
-  escape_point *ep;
-  unsigned int i;
-
   /* If we already determined flags to be bad enough,
    * we do not need to record.  */
   if ((flags & min_flags) == flags)
     return false;
 
-  FOR_EACH_VEC_ELT (escape_points, i, ep)
-    if (ep->call == call && ep->arg == arg && ep->direct == direct)
+  for (escape_point &ep : escape_points)
+    if (ep.call == call && ep.arg == arg && ep.direct == direct)
       {
-	if ((ep->min_flags & min_flags) == min_flags)
+	if ((ep.min_flags & min_flags) == min_flags)
 	  return false;
-	ep->min_flags &= min_flags;
+	ep.min_flags &= min_flags;
 	return true;
       }
   /* Give up if max escape points is met.  */
@@ -1881,18 +1878,15 @@ analyze_parms (modref_summary *summary, modref_summary_lto *summary_lto,
 	    }
 	  if (lattice[SSA_NAME_VERSION (name)].escape_points.length ())
 	    {
-	      escape_point *ep;
-	      unsigned int ip;
 	      cgraph_node *node = cgraph_node::get (current_function_decl);
 
 	      gcc_checking_assert (ipa);
-	      FOR_EACH_VEC_ELT
-		  (lattice[SSA_NAME_VERSION (name)].escape_points, ip, ep)
-		if ((ep->min_flags & flags) != flags)
+		  for (const escape_point &ep : lattice[SSA_NAME_VERSION (name)].escape_points)
+		if ((ep.min_flags & flags) != flags)
 		  {
-		    cgraph_edge *e = node->get_edge (ep->call);
-		    struct escape_entry ee = {parm_index, ep->arg,
-		     			      ep->min_flags, ep->direct};
+		    cgraph_edge *e = node->get_edge (ep.call);
+		    struct escape_entry ee = {parm_index, ep.arg,
+		     			      ep.min_flags, ep.direct};
 
 		    escape_summaries->get_create (e)->esc.safe_push (ee);
 		  }
@@ -2438,14 +2432,12 @@ modref_write_escape_summary (struct bitpack_d *bp, escape_summary *esum)
       return;
     }
   bp_pack_var_len_unsigned (bp, esum->esc.length ());
-  unsigned int i;
-  escape_entry *ee;
-  FOR_EACH_VEC_ELT (esum->esc, i, ee)
+  for (const escape_entry &ee : esum->esc)
     {
-      bp_pack_var_len_unsigned (bp, ee->parm_index);
-      bp_pack_var_len_unsigned (bp, ee->arg);
-      bp_pack_var_len_unsigned (bp, ee->min_flags);
-      bp_pack_value (bp, ee->direct, 1);
+      bp_pack_var_len_unsigned (bp, ee.parm_index);
+      bp_pack_var_len_unsigned (bp, ee.arg);
+      bp_pack_var_len_unsigned (bp, ee.min_flags);
+      bp_pack_value (bp, ee.direct, 1);
     }
 }
 
@@ -3001,19 +2993,15 @@ update_escape_summary_1 (cgraph_edge *e,
   auto_vec <escape_entry> old = sum->esc.copy ();
   sum->esc.release ();
 
-  unsigned int i;
-  escape_entry *ee;
-  FOR_EACH_VEC_ELT (old, i, ee)
+  for (const escape_entry &ee : old)
     {
-      unsigned int j;
-      struct escape_map *em;
-      if (ee->parm_index >= map.length ())
+      if (ee.parm_index >= map.length ())
 	continue;
-      FOR_EACH_VEC_ELT (map[ee->parm_index], j, em)
+      for (const escape_map &em : map[ee.parm_index])
 	{
-	  struct escape_entry entry = {em->parm_index, ee->arg,
-	    			       ee->min_flags,
-				       ee->direct & em->direct};
+	  struct escape_entry entry = {em.parm_index, ee.arg,
+	    			       ee.min_flags,
+				       ee.direct & em.direct};
 	  sum->esc.safe_push (entry);
 	}
     }
diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
index 3d28a6e8640..03a07cc6a09 100644
--- a/gcc/ipa-prop.h
+++ b/gcc/ipa-prop.h
@@ -251,13 +251,9 @@ ipa_copy_agg_values (const vec<ipa_agg_value_set> &aggs)
 
   if (!aggs.is_empty ())
     {
-      ipa_agg_value_set *agg;
-      int i;
-
       aggs_copy.reserve_exact (aggs.length ());
-
-      FOR_EACH_VEC_ELT (aggs, i, agg)
-	aggs_copy.quick_push (agg->copy ());
+      for (const ipa_agg_value_set &agg : aggs)
+	aggs_copy.quick_push (agg.copy ());
     }
 
   return aggs_copy;
@@ -272,11 +268,8 @@ static inline void
 ipa_release_agg_values (vec<ipa_agg_value_set> &aggs,
 			bool release_vector = true)
 {
-  ipa_agg_value_set *agg;
-  int i;
-
-  FOR_EACH_VEC_ELT (aggs, i, agg)
-    agg->release ();
+  for (ipa_agg_value_set &agg : aggs)
+    agg.release ();
   if (release_vector)
     aggs.release ();
 }
diff --git a/gcc/lower-subreg.c b/gcc/lower-subreg.c
index 34eb8b193ac..21078268ba0 100644
--- a/gcc/lower-subreg.c
+++ b/gcc/lower-subreg.c
@@ -1731,14 +1731,9 @@ decompose_multiword_subregs (bool decompose_copies)
 	}
     }
 
-  {
-    unsigned int i;
-    bitmap b;
-
-    FOR_EACH_VEC_ELT (reg_copy_graph, i, b)
-      if (b)
-	BITMAP_FREE (b);
-  }
+  for (bitmap b : reg_copy_graph)
+    if (b)
+      BITMAP_FREE (b);
 
   reg_copy_graph.release ();
 
diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
index a26d4885800..7dc3b87132e 100644
--- a/gcc/lto-streamer-out.c
+++ b/gcc/lto-streamer-out.c
@@ -1127,13 +1127,10 @@ DFS::DFS_write_tree_body (struct output_block *ob,
 
   if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
     {
-      unsigned i;
-      tree t;
-
       /* Note that the number of BINFO slots has already been emitted in
 	 EXPR's header (see streamer_write_tree_header) because this length
 	 is needed to build the empty BINFO node on the reader side.  */
-      FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (expr), i, t)
+      for (tree t : *BINFO_BASE_BINFOS (expr))
 	DFS_follow_tree_edge (t);
       DFS_follow_tree_edge (BINFO_OFFSET (expr));
       DFS_follow_tree_edge (BINFO_VTABLE (expr));
@@ -1510,9 +1507,7 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map,
 
   if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
     {
-      unsigned i;
-      tree b;
-      FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (t), i, b)
+      for (tree b : *BINFO_BASE_BINFOS (t))
 	visit (b);
       visit (BINFO_OFFSET (t));
       visit (BINFO_VTABLE (t));
@@ -2644,8 +2639,7 @@ prune_offload_funcs (void)
   VEC_ORDERED_REMOVE_IF (*offload_funcs, ix, ix2, elem_ptr,
 			 cgraph_node::get (*elem_ptr) == NULL);
 
-  tree fn_decl;
-  FOR_EACH_VEC_ELT (*offload_funcs, ix, fn_decl)
+  for (tree fn_decl : *offload_funcs)
     DECL_PRESERVE_P (fn_decl) = 1;
 }
 
diff --git a/gcc/sel-sched-dump.c b/gcc/sel-sched-dump.c
index 3d26483696b..993a16a3f0c 100644
--- a/gcc/sel-sched-dump.c
+++ b/gcc/sel-sched-dump.c
@@ -528,10 +528,7 @@ dump_flist (flist_t l)
 void
 dump_insn_vector (rtx_vec_t succs)
 {
-  int i;
-  rtx_insn *succ;
-
-  FOR_EACH_VEC_ELT (succs, i, succ)
+  for (rtx_insn *succ : succs)
     if (succ)
       dump_insn (succ);
     else
diff --git a/gcc/timevar.c b/gcc/timevar.c
index 8fc122ba9fe..5f54215f108 100644
--- a/gcc/timevar.c
+++ b/gcc/timevar.c
@@ -198,10 +198,8 @@ timer::named_items::pop ()
 void
 timer::named_items::print (FILE *fp, const timevar_time_def *total)
 {
-  unsigned int i;
-  const char *item_name;
   fprintf (fp, "Client items:\n");
-  FOR_EACH_VEC_ELT (m_names, i, item_name)
+  for (const char *item_name : m_names)
     {
       timer::timevar_def *def = m_hash_map.get (item_name);
       gcc_assert (def);
diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c
index b736e17339b..a016ee47a02 100644
--- a/gcc/tree-cfgcleanup.c
+++ b/gcc/tree-cfgcleanup.c
@@ -950,9 +950,7 @@ cleanup_control_flow_pre ()
   /* If we've marked .ABNORMAL_DISPATCHER basic block(s) as visited
      above, but haven't marked any of their successors as visited,
      unmark them now, so that they can be removed as useless.  */
-  basic_block dispatcher_bb;
-  unsigned int k;
-  FOR_EACH_VEC_ELT (abnormal_dispatchers, k, dispatcher_bb)
+  for (basic_block dispatcher_bb : abnormal_dispatchers)
     {
       edge e;
       edge_iterator ei;
@@ -1015,9 +1013,7 @@ cleanup_tree_cfg_noloop (unsigned ssa_update_flags)
       if (!dom_info_available_p (CDI_DOMINATORS))
 	mark_dfs_back_edges ();
 
-      loop_p loop;
-      unsigned i;
-      FOR_EACH_VEC_ELT (*get_loops (cfun), i, loop)
+      for (loop_p loop : *get_loops (cfun))
 	if (loop && loop->header)
 	  {
 	    basic_block bb = loop->header;
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index b1f64684840..ba939251639 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -170,10 +170,7 @@ ref_contains_union_access_p (tree ref)
 static void
 dump_data_references (FILE *file, vec<data_reference_p> datarefs)
 {
-  unsigned int i;
-  struct data_reference *dr;
-
-  FOR_EACH_VEC_ELT (datarefs, i, dr)
+  for (data_reference *dr : datarefs)
     dump_data_reference (file, dr);
 }
 
@@ -378,10 +375,7 @@ DEBUG_FUNCTION void
 print_dir_vectors (FILE *outf, vec<lambda_vector> dir_vects,
 		   int length)
 {
-  unsigned j;
-  lambda_vector v;
-
-  FOR_EACH_VEC_ELT (dir_vects, j, v)
+  for (lambda_vector v : dir_vects)
     print_direction_vector (outf, v, length);
 }
 
@@ -403,10 +397,7 @@ DEBUG_FUNCTION void
 print_dist_vectors (FILE *outf, vec<lambda_vector> dist_vects,
 		    int length)
 {
-  unsigned j;
-  lambda_vector v;
-
-  FOR_EACH_VEC_ELT (dist_vects, j, v)
+  for (lambda_vector v : dist_vects)
     print_lambda_vector (outf, v, length);
 }
 
@@ -450,10 +441,8 @@ dump_data_dependence_relation (FILE *outf,
   else if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE)
     {
       unsigned int i;
-      class loop *loopi;
 
-      subscript *sub;
-      FOR_EACH_VEC_ELT (DDR_SUBSCRIPTS (ddr), i, sub)
+      for (subscript *sub : DDR_SUBSCRIPTS (ddr))
 	{
 	  fprintf (outf, "  access_fn_A: ");
 	  print_generic_stmt (outf, SUB_ACCESS_FN (sub, 0));
@@ -463,7 +452,7 @@ dump_data_dependence_relation (FILE *outf,
 	}
 
       fprintf (outf, "  loop nest: (");
-      FOR_EACH_VEC_ELT (DDR_LOOP_NEST (ddr), i, loopi)
+      for (class loop *loopi : DDR_LOOP_NEST (ddr))
 	fprintf (outf, "%d ", loopi->num);
       fprintf (outf, ")\n");
 
@@ -499,10 +488,7 @@ DEBUG_FUNCTION void
 dump_data_dependence_relations (FILE *file,
 				vec<ddr_p> ddrs)
 {
-  unsigned int i;
-  struct data_dependence_relation *ddr;
-
-  FOR_EACH_VEC_ELT (ddrs, i, ddr)
+  for (data_dependence_relation *ddr : ddrs)
     dump_data_dependence_relation (file, ddr);
 }
 
@@ -538,21 +524,17 @@ debug_data_dependence_relations (vec<ddr_p> ddrs)
 DEBUG_FUNCTION void
 dump_dist_dir_vectors (FILE *file, vec<ddr_p> ddrs)
 {
-  unsigned int i, j;
-  struct data_dependence_relation *ddr;
-  lambda_vector v;
-
-  FOR_EACH_VEC_ELT (ddrs, i, ddr)
+  for (data_dependence_relation *ddr : ddrs)
     if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE && DDR_AFFINE_P (ddr))
       {
-	FOR_EACH_VEC_ELT (DDR_DIST_VECTS (ddr), j, v)
+	for (lambda_vector v : DDR_DIST_VECTS (ddr))
 	  {
 	    fprintf (file, "DISTANCE_V (");
 	    print_lambda_vector (file, v, DDR_NB_LOOPS (ddr));
 	    fprintf (file, ")\n");
 	  }
 
-	FOR_EACH_VEC_ELT (DDR_DIR_VECTS (ddr), j, v)
+	for (lambda_vector v : DDR_DIR_VECTS (ddr))
 	  {
 	    fprintf (file, "DIRECTION_V (");
 	    print_direction_vector (file, v, DDR_NB_LOOPS (ddr));
@@ -568,10 +550,7 @@ dump_dist_dir_vectors (FILE *file, vec<ddr_p> ddrs)
 DEBUG_FUNCTION void
 dump_ddrs (FILE *file, vec<ddr_p> ddrs)
 {
-  unsigned int i;
-  struct data_dependence_relation *ddr;
-
-  FOR_EACH_VEC_ELT (ddrs, i, ddr)
+  for (data_dependence_relation *ddr : ddrs)
     dump_data_dependence_relation (file, ddr);
 
   fprintf (file, "\n\n");
@@ -1808,10 +1787,10 @@ prune_runtime_alias_test_list (vec<dr_with_seg_len_pair_t> *alias_pairs,
      cases.  */
   unsigned int i;
   dr_with_seg_len_pair_t *alias_pair;
-  FOR_EACH_VEC_ELT (*alias_pairs, i, alias_pair)
+  for (dr_with_seg_len_pair_t &alias_pair : *alias_pairs)
     {
-      data_reference_p dr_a = alias_pair->first.dr;
-      data_reference_p dr_b = alias_pair->second.dr;
+      data_reference_p dr_a = alias_pair.first.dr;
+      data_reference_p dr_b = alias_pair.second.dr;
       int comp_res = data_ref_compare_tree (DR_BASE_ADDRESS (dr_a),
 					    DR_BASE_ADDRESS (dr_b));
       if (comp_res == 0)
@@ -1820,11 +1799,11 @@ prune_runtime_alias_test_list (vec<dr_with_seg_len_pair_t> *alias_pairs,
 	comp_res = data_ref_compare_tree (DR_INIT (dr_a), DR_INIT (dr_b));
       if (comp_res > 0)
 	{
-	  std::swap (alias_pair->first, alias_pair->second);
-	  alias_pair->flags |= DR_ALIAS_SWAPPED;
+	  std::swap (alias_pair.first, alias_pair.second);
+	  alias_pair.flags |= DR_ALIAS_SWAPPED;
 	}
       else
-	alias_pair->flags |= DR_ALIAS_UNSWAPPED;
+	alias_pair.flags |= DR_ALIAS_UNSWAPPED;
     }
 
   /* Sort the collected data ref pairs so that we can scan them once to
@@ -2668,19 +2647,17 @@ create_runtime_alias_checks (class loop *loop,
   tree part_cond_expr;
 
   fold_defer_overflow_warnings ();
-  dr_with_seg_len_pair_t *alias_pair;
-  unsigned int i;
-  FOR_EACH_VEC_ELT (*alias_pairs, i, alias_pair)
+  for (const dr_with_seg_len_pair_t &alias_pair : alias_pairs)
     {
-      gcc_assert (alias_pair->flags);
+      gcc_assert (alias_pair.flags);
       if (dump_enabled_p ())
 	dump_printf (MSG_NOTE,
 		     "create runtime check for data references %T and %T\n",
-		     DR_REF (alias_pair->first.dr),
-		     DR_REF (alias_pair->second.dr));
+		     DR_REF (alias_pair.first.dr),
+		     DR_REF (alias_pair.second.dr));
 
       /* Create condition expression for each pair data references.  */
-      create_intersect_range_checks (loop, &part_cond_expr, *alias_pair);
+      create_intersect_range_checks (loop, &part_cond_expr, alias_pair);
       if (*cond_expr)
 	*cond_expr = fold_build2 (TRUTH_AND_EXPR, boolean_type_node,
 				  *cond_expr, part_cond_expr);
@@ -3436,10 +3413,7 @@ free_conflict_function (conflict_function *f)
 static void
 free_subscripts (vec<subscript_p> subscripts)
 {
-  unsigned i;
-  subscript_p s;
-
-  FOR_EACH_VEC_ELT (subscripts, i, s)
+  for (subscript_p s : subscripts)
     {
       free_conflict_function (s->conflicting_iterations_in_a);
       free_conflict_function (s->conflicting_iterations_in_b);
@@ -4980,10 +4954,7 @@ analyze_overlapping_iterations (tree chrec_a,
 static void
 save_dist_v (struct data_dependence_relation *ddr, lambda_vector dist_v)
 {
-  unsigned i;
-  lambda_vector v;
-
-  FOR_EACH_VEC_ELT (DDR_DIST_VECTS (ddr), i, v)
+  for (lambda_vector v : DDR_DIST_VECTS (ddr))
     if (lambda_vector_equal (v, dist_v, DDR_NB_LOOPS (ddr)))
       return;
 
@@ -4995,10 +4966,7 @@ save_dist_v (struct data_dependence_relation *ddr, lambda_vector dist_v)
 static void
 save_dir_v (struct data_dependence_relation *ddr, lambda_vector dir_v)
 {
-  unsigned i;
-  lambda_vector v;
-
-  FOR_EACH_VEC_ELT (DDR_DIR_VECTS (ddr), i, v)
+  for (lambda_vector v : DDR_DIR_VECTS (ddr))
     if (lambda_vector_equal (v, dir_v, DDR_NB_LOOPS (ddr)))
       return;
 
@@ -5133,10 +5101,7 @@ static bool
 invariant_access_functions (const struct data_dependence_relation *ddr,
 			    int lnum)
 {
-  unsigned i;
-  subscript *sub;
-
-  FOR_EACH_VEC_ELT (DDR_SUBSCRIPTS (ddr), i, sub)
+  for (subscript *sub : DDR_SUBSCRIPTS (ddr))
     if (!evolution_function_is_invariant_p (SUB_ACCESS_FN (sub, 0), lnum)
 	|| !evolution_function_is_invariant_p (SUB_ACCESS_FN (sub, 1), lnum))
       return false;
@@ -5305,10 +5270,7 @@ add_distance_for_zero_overlaps (struct data_dependence_relation *ddr)
 static inline bool
 same_access_functions (const struct data_dependence_relation *ddr)
 {
-  unsigned i;
-  subscript *sub;
-
-  FOR_EACH_VEC_ELT (DDR_SUBSCRIPTS (ddr), i, sub)
+  for (subscript *sub : DDR_SUBSCRIPTS (ddr))
     if (!eq_evolutions_p (SUB_ACCESS_FN (sub, 0),
 			  SUB_ACCESS_FN (sub, 1)))
       return false;
@@ -5585,11 +5547,8 @@ static bool
 access_functions_are_affine_or_constant_p (const struct data_reference *a,
 					   const class loop *loop_nest)
 {
-  unsigned int i;
   vec<tree> fns = DR_ACCESS_FNS (a);
-  tree t;
-
-  FOR_EACH_VEC_ELT (fns, i, t)
+  for (tree t : fns)
     if (!evolution_function_is_invariant_p (t, loop_nest->num)
 	&& !evolution_function_is_affine_multivariate_p (t, loop_nest->num))
       return false;
@@ -5700,7 +5659,7 @@ compute_all_dependences (vec<data_reference_p> datarefs,
 	}
 
   if (compute_self_and_rr)
-    FOR_EACH_VEC_ELT (datarefs, i, a)
+    for (data_reference *a : datarefs)
       {
 	ddr = initialize_data_dependence_relation (a, a, loop_nest);
 	dependence_relations->safe_push (ddr);
@@ -5896,20 +5855,18 @@ opt_result
 find_data_references_in_stmt (class loop *nest, gimple *stmt,
 			      vec<data_reference_p> *datarefs)
 {
-  unsigned i;
   auto_vec<data_ref_loc, 2> references;
-  data_ref_loc *ref;
   data_reference_p dr;
 
   if (get_references_in_stmt (stmt, &references))
     return opt_result::failure_at (stmt, "statement clobbers memory: %G",
 				   stmt);
 
-  FOR_EACH_VEC_ELT (references, i, ref)
+  for (const data_ref_loc &ref : references)
     {
       dr = create_data_ref (nest ? loop_preheader_edge (nest) : NULL,
-			    loop_containing_stmt (stmt), ref->ref,
-			    stmt, ref->is_read, ref->is_conditional_in_stmt);
+			    loop_containing_stmt (stmt), ref.ref,
+			    stmt, ref.is_read, ref.is_conditional_in_stmt);
       gcc_assert (dr != NULL);
       datarefs->safe_push (dr);
     }
@@ -5927,19 +5884,17 @@ bool
 graphite_find_data_references_in_stmt (edge nest, loop_p loop, gimple *stmt,
 				       vec<data_reference_p> *datarefs)
 {
-  unsigned i;
   auto_vec<data_ref_loc, 2> references;
-  data_ref_loc *ref;
   bool ret = true;
   data_reference_p dr;
 
   if (get_references_in_stmt (stmt, &references))
     return false;
 
-  FOR_EACH_VEC_ELT (references, i, ref)
+  for (const data_ref_loc &ref : references)
     {
-      dr = create_data_ref (nest, loop, ref->ref, stmt, ref->is_read,
-			    ref->is_conditional_in_stmt);
+      dr = create_data_ref (nest, loop, ref.ref, stmt, ref.is_read,
+			    ref.is_conditional_in_stmt);
       gcc_assert (dr != NULL);
       datarefs->safe_push (dr);
     }
@@ -6247,10 +6202,7 @@ free_dependence_relation (struct data_dependence_relation *ddr)
 void
 free_dependence_relations (vec<ddr_p> dependence_relations)
 {
-  unsigned int i;
-  struct data_dependence_relation *ddr;
-
-  FOR_EACH_VEC_ELT (dependence_relations, i, ddr)
+  for (data_dependence_relation *ddr : dependence_relations)
     if (ddr)
       free_dependence_relation (ddr);
 
@@ -6262,10 +6214,7 @@ free_dependence_relations (vec<ddr_p> dependence_relations)
 void
 free_data_refs (vec<data_reference_p> datarefs)
 {
-  unsigned int i;
-  struct data_reference *dr;
-
-  FOR_EACH_VEC_ELT (datarefs, i, dr)
+  for (data_reference *dr : datarefs)
     free_data_ref (dr);
   datarefs.release ();
 }
diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
index 85adb1ad8c7..8045e34df26 100644
--- a/gcc/tree-into-ssa.c
+++ b/gcc/tree-into-ssa.c
@@ -1638,14 +1638,11 @@ debug_defs_stack (int n)
 void
 dump_currdefs (FILE *file)
 {
-  unsigned i;
-  tree var;
-
   if (symbols_to_rename.is_empty ())
     return;
 
   fprintf (file, "\n\nCurrent reaching definitions\n\n");
-  FOR_EACH_VEC_ELT (symbols_to_rename, i, var)
+  for (tree var : symbols_to_rename)
     {
       common_info *info = get_common_info (var);
       fprintf (file, "CURRDEF (");
@@ -2069,18 +2066,16 @@ rewrite_update_phi_arguments (basic_block bb)
 {
   edge e;
   edge_iterator ei;
-  unsigned i;
 
   FOR_EACH_EDGE (e, ei, bb->succs)
     {
-      gphi *phi;
       vec<gphi *> phis;
 
       if (!bitmap_bit_p (blocks_with_phis_to_rewrite, e->dest->index))
 	continue;
 
       phis = phis_to_rewrite[e->dest->index];
-      FOR_EACH_VEC_ELT (phis, i, phi)
+      for (gphi *phi : phis)
 	{
 	  tree arg, lhs_sym, reaching_def = NULL;
 	  use_operand_p arg_p;
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index 969b868397e..d8233a6cb0e 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -3180,8 +3180,7 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
   gimple *then_store, *else_store;
   bool found, ok = false, res;
   struct data_dependence_relation *ddr;
-  data_reference_p then_dr, else_dr;
-  int i, j;
+  int i;
   tree then_lhs, else_lhs;
   basic_block blocks[3];
 
@@ -3233,7 +3232,7 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
 
   /* Find pairs of stores with equal LHS.  */
   auto_vec<gimple *, 1> then_stores, else_stores;
-  FOR_EACH_VEC_ELT (then_datarefs, i, then_dr)
+  for (data_reference_p then_dr : then_datarefs)
     {
       if (DR_IS_READ (then_dr))
         continue;
@@ -3244,7 +3243,7 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
 	continue;
       found = false;
 
-      FOR_EACH_VEC_ELT (else_datarefs, j, else_dr)
+      for (data_reference_p else_dr : else_datarefs)
         {
           if (DR_IS_READ (else_dr))
             continue;
diff --git a/gcc/tree-ssa-propagate.c b/gcc/tree-ssa-propagate.c
index b3dcd43c00d..d93ec90b002 100644
--- a/gcc/tree-ssa-propagate.c
+++ b/gcc/tree-ssa-propagate.c
@@ -1258,8 +1258,6 @@ propagate_tree_value_into_stmt (gimple_stmt_iterator *gsi, tree val)
 unsigned
 clean_up_loop_closed_phi (function *fun)
 {
-  unsigned i;
-  edge e;
   gphi *phi;
   tree rhs;
   tree lhs;
@@ -1280,7 +1278,7 @@ clean_up_loop_closed_phi (function *fun)
     {
       /* Check each exit edege of loop.  */
       auto_vec<edge> exits = get_loop_exit_edges (loop);
-      FOR_EACH_VEC_ELT (exits, i, e)
+      for (edge e : exits)
 	if (single_pred_p (e->dest))
 	  /* Walk over loop-closed PHIs.  */
 	  for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi);)
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 7163438e23d..988df87b41c 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -933,11 +933,9 @@ static bool
 constraint_set_union (vec<constraint_t> *to,
 		      vec<constraint_t> *from)
 {
-  int i;
-  constraint_t c;
   bool any_change = false;
 
-  FOR_EACH_VEC_ELT (*from, i, c)
+  for (constraint_t c : *from)
     {
       if (constraint_vec_find (*to, *c) == NULL)
 	{
@@ -1080,14 +1078,12 @@ static bool
 merge_node_constraints (constraint_graph_t graph, unsigned int to,
 			unsigned int from)
 {
-  unsigned int i;
-  constraint_t c;
   bool any_change = false;
 
   gcc_checking_assert (find (from) == to);
 
   /* Move all complex constraints from src node into to node  */
-  FOR_EACH_VEC_ELT (graph->complex[from], i, c)
+  for (constraint_t c : graph->complex[from])
     {
       /* In complex constraints for node FROM, we may have either
 	 a = *FROM, and *FROM = a, or an offseted constraint which are
@@ -2580,10 +2576,7 @@ unite_pointer_equivalences (constraint_graph_t graph)
 static void
 move_complex_constraints (constraint_graph_t graph)
 {
-  int i;
-  constraint_t c;
-
-  FOR_EACH_VEC_ELT (constraints, i, c)
+  for (constraint_t c : constraints)
     {
       if (c)
 	{
@@ -3458,21 +3451,18 @@ get_constraint_for_component_ref (tree t, vec<ce_s> *results,
 static void
 do_deref (vec<ce_s> *constraints)
 {
-  struct constraint_expr *c;
-  unsigned int i = 0;
-
-  FOR_EACH_VEC_ELT (*constraints, i, c)
+  for (constraint_expr &c : *constraints)
     {
-      if (c->type == SCALAR)
-	c->type = DEREF;
-      else if (c->type == ADDRESSOF)
-	c->type = SCALAR;
-      else if (c->type == DEREF)
+      if (c.type == SCALAR)
+	c.type = DEREF;
+      else if (c.type == ADDRESSOF)
+	c.type = SCALAR;
+      else if (c.type == DEREF)
 	{
 	  struct constraint_expr tmplhs;
 	  tmplhs = new_scalar_tmp_constraint_exp ("dereftmp", true);
-	  process_constraint (new_constraint (tmplhs, *c));
-	  c->var = tmplhs.var;
+	  process_constraint (new_constraint (tmplhs, c));
+	  c.var = tmplhs.var;
 	}
       else
 	gcc_unreachable ();
@@ -3485,17 +3475,14 @@ do_deref (vec<ce_s> *constraints)
 static void
 get_constraint_for_address_of (tree t, vec<ce_s> *results)
 {
-  struct constraint_expr *c;
-  unsigned int i;
-
   get_constraint_for_1 (t, results, true, true);
 
-  FOR_EACH_VEC_ELT (*results, i, c)
+  for (constraint_expr &c : *results)
     {
-      if (c->type == DEREF)
-	c->type = SCALAR;
+      if (c.type == DEREF)
+	c.type = SCALAR;
       else
-	c->type = ADDRESSOF;
+	c.type = ADDRESSOF;
     }
 }
 
@@ -3647,11 +3634,9 @@ get_constraint_for_1 (tree t, vec<ce_s> *results, bool address_p,
 	      auto_vec<ce_s> tmp;
 	      FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), i, val)
 		{
-		  struct constraint_expr *rhsp;
-		  unsigned j;
 		  get_constraint_for_1 (val, &tmp, address_p, lhs_p);
-		  FOR_EACH_VEC_ELT (tmp, j, rhsp)
-		    results->safe_push (*rhsp);
+		  for (const constraint_expr &rhsp : tmp)
+		    results->safe_push (rhsp);
 		  tmp.truncate (0);
 		}
 	      /* We do not know whether the constructor was complete,
@@ -3716,23 +3701,20 @@ static void
 process_all_all_constraints (vec<ce_s> lhsc,
 			     vec<ce_s> rhsc)
 {
-  struct constraint_expr *lhsp, *rhsp;
-  unsigned i, j;
-
   if (lhsc.length () <= 1 || rhsc.length () <= 1)
     {
-      FOR_EACH_VEC_ELT (lhsc, i, lhsp)
-	FOR_EACH_VEC_ELT (rhsc, j, rhsp)
-	  process_constraint (new_constraint (*lhsp, *rhsp));
+      for (const constraint_expr &lhsp : lhsc)
+	for (const constraint_expr &rhsp : rhsc)
+	  process_constraint (new_constraint (lhsp, rhsp));
     }
   else
     {
       struct constraint_expr tmp;
       tmp = new_scalar_tmp_constraint_exp ("allalltmp", true);
-      FOR_EACH_VEC_ELT (rhsc, i, rhsp)
-	process_constraint (new_constraint (tmp, *rhsp));
-      FOR_EACH_VEC_ELT (lhsc, i, lhsp)
-	process_constraint (new_constraint (*lhsp, tmp));
+      for (const constraint_expr &rhsp : rhsc)
+	process_constraint (new_constraint (tmp, rhsp));
+      for (const constraint_expr &lhsp : lhsc)
+	process_constraint (new_constraint (lhsp, tmp));
     }
 }
 
@@ -3816,16 +3798,14 @@ do_structure_copy (tree lhsop, tree rhsop)
 static void
 make_constraints_to (unsigned id, vec<ce_s> rhsc)
 {
-  struct constraint_expr *c;
   struct constraint_expr includes;
-  unsigned int j;
 
   includes.var = id;
   includes.offset = 0;
   includes.type = SCALAR;
 
-  FOR_EACH_VEC_ELT (rhsc, j, c)
-    process_constraint (new_constraint (includes, *c));
+  for (const constraint_expr &c : rhsc)
+    process_constraint (new_constraint (includes, c));
 }
 
 /* Create a constraint ID = OP.  */
@@ -4137,13 +4117,13 @@ handle_rhs_call (gcall *stmt, vec<ce_s> *results)
       && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
     {
       auto_vec<ce_s> tmpc;
-      struct constraint_expr lhsc, *c;
+      struct constraint_expr lhsc;
       get_constraint_for_address_of (gimple_call_lhs (stmt), &tmpc);
       lhsc.var = escaped_id;
       lhsc.offset = 0;
       lhsc.type = SCALAR;
-      FOR_EACH_VEC_ELT (tmpc, i, c)
-	process_constraint (new_constraint (lhsc, *c));
+      for (const constraint_expr &c : tmpc)
+	process_constraint (new_constraint (lhsc, c));
     }
 
   /* Regular functions return nonlocal memory.  */
diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c
index b317df532a9..2694d1ab452 100644
--- a/gcc/tree-vect-data-refs.c
+++ b/gcc/tree-vect-data-refs.c
@@ -290,9 +290,7 @@ vect_analyze_possibly_independent_ddr (data_dependence_relation *ddr,
 				       int loop_depth, unsigned int *max_vf)
 {
   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
-  lambda_vector dist_v;
-  unsigned int i;
-  FOR_EACH_VEC_ELT (DDR_DIST_VECTS (ddr), i, dist_v)
+  for (lambda_vector &dist_v : DDR_DIST_VECTS (ddr))
     {
       int dist = dist_v[loop_depth];
       if (dist != 0 && !(dist > 0 && DDR_REVERSED_P (ddr)))
@@ -729,9 +727,8 @@ vect_slp_analyze_node_dependences (vec_info *vinfo, slp_tree node,
 		{
 		  if (stmt_info != last_store_info)
 		    continue;
-		  unsigned i;
-		  stmt_vec_info store_info;
-		  FOR_EACH_VEC_ELT (stores, i, store_info)
+
+		  for (stmt_vec_info &store_info : stores)
 		    {
 		      data_reference *store_dr
 			= STMT_VINFO_DATA_REF (store_info);
@@ -804,9 +801,8 @@ vect_slp_analyze_node_dependences (vec_info *vinfo, slp_tree node,
 		{
 		  if (stmt_info != last_store_info)
 		    continue;
-		  unsigned i;
-		  stmt_vec_info store_info;
-		  FOR_EACH_VEC_ELT (stores, i, store_info)
+
+		  for (stmt_vec_info &store_info : stores)
 		    {
 		      data_reference *store_dr
 			= STMT_VINFO_DATA_REF (store_info);
@@ -868,9 +864,7 @@ vect_slp_analyze_instance_dependence (vec_info *vinfo, slp_instance instance)
 
   /* Verify we can sink loads to the vectorized stmt insert location,
      special-casing stores of this instance.  */
-  slp_tree load;
-  unsigned int i;
-  FOR_EACH_VEC_ELT (SLP_INSTANCE_LOADS (instance), i, load)
+  for (slp_tree &load : SLP_INSTANCE_LOADS (instance))
     if (! vect_slp_analyze_node_dependences (vinfo, load,
 					     store
 					     ? SLP_TREE_SCALAR_STMTS (store)
@@ -927,9 +921,7 @@ vect_record_base_alignments (vec_info *vinfo)
 {
   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
   class loop *loop = loop_vinfo ? LOOP_VINFO_LOOP (loop_vinfo) : NULL;
-  data_reference *dr;
-  unsigned int i;
-  FOR_EACH_VEC_ELT (vinfo->shared->datarefs, i, dr)
+  for (data_reference *dr : vinfo->shared->datarefs)
     {
       dr_vec_info *dr_info = vinfo->lookup_dr (dr);
       stmt_vec_info stmt_info = dr_info->stmt;
@@ -1463,10 +1455,8 @@ vect_get_peeling_costs_all_drs (loop_vec_info loop_vinfo,
 				bool unknown_misalignment)
 {
   vec<data_reference_p> datarefs = LOOP_VINFO_DATAREFS (loop_vinfo);
-  unsigned i;
-  data_reference *dr;
 
-  FOR_EACH_VEC_ELT (datarefs, i, dr)
+  for (data_reference *dr : datarefs)
     {
       dr_vec_info *dr_info = loop_vinfo->lookup_dr (dr);
       if (!vect_relevant_for_alignment_p (dr_info))
@@ -1575,13 +1565,11 @@ static bool
 vect_peeling_supportable (loop_vec_info loop_vinfo, dr_vec_info *dr0_info,
 			  unsigned npeel)
 {
-  unsigned i;
-  struct data_reference *dr = NULL;
   vec<data_reference_p> datarefs = LOOP_VINFO_DATAREFS (loop_vinfo);
   enum dr_alignment_support supportable_dr_alignment;
 
   /* Ensure that all data refs can be vectorized after the peel.  */
-  FOR_EACH_VEC_ELT (datarefs, i, dr)
+  for (data_reference *dr : datarefs)
     {
       int save_misalignment;
 
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index 63ba594f227..9748043f3ee 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -469,10 +469,7 @@ vec_info::vec_info (vec_info::vec_kind kind_in, void *target_cost_data_in,
 
 vec_info::~vec_info ()
 {
-  slp_instance instance;
-  unsigned int i;
-
-  FOR_EACH_VEC_ELT (slp_instances, i, instance)
+  for (slp_instance &instance : slp_instances)
     vect_free_slp_instance (instance);
 
   destroy_cost_data (target_cost_data);
@@ -739,9 +736,7 @@ vec_info::set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info, bool check_ro)
 void
 vec_info::free_stmt_vec_infos (void)
 {
-  unsigned int i;
-  stmt_vec_info info;
-  FOR_EACH_VEC_ELT (stmt_vec_infos, i, info)
+  for (stmt_vec_info &info : stmt_vec_infos)
     if (info != NULL)
       free_stmt_vec_info (info);
   stmt_vec_infos.release ();
-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-09 15:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09  0:48 [PATCH] Use range based loops to iterate over vec<> in various places Trevor Saunders
2021-06-09 11:06 ` Richard Biener
2021-06-09 11:32   ` Trevor Saunders
2021-06-09 11:57     ` Richard Biener
2021-06-09 15:00 ` Martin Sebor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).