From a4753433257fa44f2f5c8c2bb722fec67b0637c8 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 26 Mar 2014 16:30:31 -0400
Subject: [PATCH 08/88] Introduce gimple_phi_iterator

gcc/
	* gimple-iterator.h (struct gimple_phi_iterator): New subclass of
	gimple_stmt_iterator with identical layout, but adding...
	(gimple_phi_iterator::phi): ...new method, equivalent to
	gsi_stmt (), but casting the underlying gimple to gimple_phi,
	checking that code == GIMPLE_PHI in a checked build.
	(gsi_start_phis): Return a gimple_phi_iterator, rather than just a
	gimple_stmt_iterator.

	* tree-if-conv.c (bb_with_exit_edge_p): Require a gimple_phi rather
	than just a gimple.
	(if_convertible_phi_p): Likewise.
	* tree-phinodes.h (add_phi_node_to_bb): Likewise.
	* tree-ssa-phiprop.c (propagate_with_phi): Likewise.

	* tree-ssa-uninit.c (warn_uninitialized_phi): Require a gimple_phi
	and a vec<gimple_phi> *, rather than just a gimple and
	vec<gimple> *, and a hash_set<gimple_phi> * rather than a
	hash_set<gimple> *.
	(find_uninit_use): Likewise; add checked cast to gimple_phi when
	adding to worklist.
	(pass_late_warn_uninitialized::execute): Strengthen types of
	various locals, "worklist" from vec<gimple> to vec<gimple_phi>,
	"gsi" to a gimple_phi_iterator, "phi" and "cur_phi" to a
	gimple_phi, "added_to_worklist" from hash_set<gimple> to
	hash_set<gimple_phi>.

	* tree-ssa-loop-manip.c (rewrite_phi_with_iv): Require a
	gimple_phi_iterator * rather than a gimple_stmt_iterator *;
	use it to strengthen local from a gimple to a gimple_phi.

	* cfgloop.c (find_subloop_latch_edge_by_ivs): Convert local from a
	gimple_stmt_iterator to a gimple_phi_iterator.  Use the iterator's
	"phi" method rather than gsi_stmt.  Use this checked cast to convert
	the type of related local from a plain gimple to a gimple_phi.
	* gimple-pretty-print.c (dump_phi_nodes): Likewise.
	* gimple-ssa-isolate-paths.c (find_implicit_erroneous_behaviour):
	Likewise.
	* sese.c (sese_add_exit_phis_edge): Likewise.
	* tree-cfg.c (reinstall_phi_args): Likewise.
	(gimple_make_forwarder_block): Likewise.
	(add_phi_args_after_copy_edge): Likewise.
	(gimple_lv_adjust_loop_header_phi): Likewise.
	* tree-cfgcleanup.c (phi_alternatives_equal): Likewise.
	(remove_forwarder_block_with_phi): Likewise.
	(merge_phi_nodes): Likewise.
	* tree-complex.c (update_phi_components): Likewise.
	* tree-if-conv.c (if_convertible_loop_p_1): Likewise.
	* tree-inline.c (update_ssa_across_abnormal_edges): Likewise.
	(copy_phis_for_bb): Likewise.
	* tree-into-ssa.c (rewrite_add_phi_arguments): Likewise.
	* tree-outof-ssa.c (eliminate_build): Likewise.
	(eliminate_useless_phis): Likewise.
	(rewrite_trees): Likewise.
	(insert_backedge_copies): Likewise.
	* tree-phinodes.c (reserve_phi_args_for_new_edge): Likewise.
	(remove_phi_args): Likewise.
	(remove_phi_nodes): Likewise.
	* tree-predcom.c (find_looparound_phi): Likewise.
	(eliminate_temp_copies): Likewise.
	* tree-scalar-evolution.c (loop_closed_phi_def): Likewise.
	(scev_const_prop): Likewise; also, add checked cast to phi.
	* tree-ssa-coalesce.c (coalesce_partitions): Likewise.
	* tree-ssa-dce.c (remove_dead_phis): Likewise.
	(forward_edge_to_pdom): Likewise.
	* tree-ssa-dom.c (record_equivalences_from_phis): Likewise.
	(cprop_into_successor_phis): Likewise.
	(propagate_rhs_into_lhs): Likewise.
	(eliminate_degenerate_phis_1): Likewise.
	* tree-ssa-ifcombine.c (same_phi_args_p): Likewise.
	* tree-ssa-live.c (calculate_live_on_exit): Likewise.
	(verify_live_on_entry): Likewise.
	* tree-ssa-loop-im.c
	(move_computations_dom_walker::before_dom_children): Likewise.
	* tree-ssa-loop-ivopts.c (find_bivs): Likewise.
	(mark_bivs): Likewise.
	(find_interesting_uses_outside): Likewise.
	(determine_set_costs): Likewise.
	* tree-ssa-loop-manip.c (split_loop_exit_edge): Likewise.
	(tree_transform_and_unroll_loop): Likewise.
	(rewrite_all_phi_nodes_with_iv): Likewise.
	(canonicalize_loop_ivs): Likewise.
	* tree-ssa-loop-niter.c (determine_value_range): Likewise.
	* tree-ssa-phiopt.c (hoist_adjacent_loads): Likewise.
	* tree-ssa-phiprop.c (tree_ssa_phiprop): Likewise.
	* tree-ssa-reassoc.c (suitable_cond_bb): Likewise.
	* tree-ssa-tail-merge.c (same_phi_alternatives_1): Likewise.
	(vop_phi): Likewise.
	* tree-ssa-threadedge.c (record_temporary_equivalences_from_phis):
	Likewise.
	* tree-ssa-threadupdate.c (copy_phi_arg_into_existing_phi): Likewise.
	(copy_phi_args): Likewise.
	(phi_args_equal_on_edges): Likewise.
	* tree-ssa.c (ssa_redirect_edge): Likewise.
	(flush_pending_stmts): Likewise.
	* tree-switch-conversion.c (check_final_bb): Likewise.
	(gather_default_values): Likewise.
	(build_constructors): Likewise.
	(fix_phi_nodes): Likewise.
	* tree-tailcall.c (propagate_through_phis): Likewise.
	(add_successor_phi_arg): Likewise.
	* tree-vect-loop-manip.c (slpeel_update_phi_nodes_for_guard1):
	Likewise.
	(slpeel_update_phi_nodes_for_guard2): Likewise.
	(slpeel_tree_peel_loop_to_edge): Likewise.
	(vect_can_advance_ivs_p): Likewise.
	(vect_update_ivs_after_vectorizer): Likewise.
	* tree-vect-loop.c (vect_analyze_scalar_cycles_1): Likewise.
	* tree-vrp.c (find_assert_locations): Likewise.
	* value-prof.c (gimple_ic): Likewise.

	* omp-low.c (expand_parallel_call): Convert local to a gimple_phi.
---
 gcc/cfgloop.c                  |  6 +++---
 gcc/gimple-iterator.c          | 12 ++++++++++--
 gcc/gimple-iterator.h          | 11 ++++++++++-
 gcc/gimple-pretty-print.c      |  6 +++---
 gcc/gimple-ssa-isolate-paths.c |  4 ++--
 gcc/omp-low.c                  |  2 +-
 gcc/sese.c                     |  2 +-
 gcc/tree-cfg.c                 | 26 +++++++++++++-------------
 gcc/tree-cfgcleanup.c          | 12 ++++++------
 gcc/tree-complex.c             |  4 ++--
 gcc/tree-if-conv.c             |  6 +++---
 gcc/tree-inline.c              | 14 +++++++-------
 gcc/tree-into-ssa.c            |  6 +++---
 gcc/tree-outof-ssa.c           | 16 ++++++++--------
 gcc/tree-phinodes.c            | 12 ++++++------
 gcc/tree-phinodes.h            |  2 +-
 gcc/tree-predcom.c             | 14 ++++++++------
 gcc/tree-scalar-evolution.c    | 17 +++++++++--------
 gcc/tree-ssa-coalesce.c        |  4 ++--
 gcc/tree-ssa-dce.c             | 10 +++++-----
 gcc/tree-ssa-dom.c             | 17 +++++++++--------
 gcc/tree-ssa-ifcombine.c       |  6 +++---
 gcc/tree-ssa-live.c            |  8 ++++----
 gcc/tree-ssa-loop-im.c         |  4 ++--
 gcc/tree-ssa-loop-ivopts.c     | 20 ++++++++++----------
 gcc/tree-ssa-loop-manip.c      | 24 +++++++++++++-----------
 gcc/tree-ssa-loop-niter.c      |  4 ++--
 gcc/tree-ssa-phiopt.c          |  4 ++--
 gcc/tree-ssa-phiprop.c         |  6 +++---
 gcc/tree-ssa-reassoc.c         |  4 ++--
 gcc/tree-ssa-tail-merge.c      |  8 ++++----
 gcc/tree-ssa-threadedge.c      |  4 ++--
 gcc/tree-ssa-threadupdate.c    | 16 ++++++++--------
 gcc/tree-ssa-uninit.c          | 24 ++++++++++++------------
 gcc/tree-ssa.c                 | 12 ++++++------
 gcc/tree-switch-conversion.c   | 16 ++++++++--------
 gcc/tree-tailcall.c            |  8 ++++----
 gcc/tree-vect-loop-manip.c     | 34 +++++++++++++++++-----------------
 gcc/tree-vect-loop.c           |  4 ++--
 gcc/tree-vrp.c                 |  4 ++--
 gcc/value-prof.c               |  4 ++--
 41 files changed, 220 insertions(+), 197 deletions(-)

diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c
index 0eaadde..ed05d32 100644
--- a/gcc/cfgloop.c
+++ b/gcc/cfgloop.c
@@ -578,8 +578,8 @@ find_subloop_latch_edge_by_ivs (struct loop *loop ATTRIBUTE_UNUSED, vec<edge> la
 {
   edge e, latch = latches[0];
   unsigned i;
-  gimple phi;
-  gimple_stmt_iterator psi;
+  gimple_phi phi;
+  gimple_phi_iterator psi;
   tree lop;
   basic_block bb;
 
@@ -597,7 +597,7 @@ find_subloop_latch_edge_by_ivs (struct loop *loop ATTRIBUTE_UNUSED, vec<edge> la
      a subloop.  */
   for (psi = gsi_start_phis (loop->header); !gsi_end_p (psi); gsi_next (&psi))
     {
-      phi = gsi_stmt (psi);
+      phi = psi.phi ();
       lop = PHI_ARG_DEF_FROM_EDGE (phi, latch);
 
       /* Ignore the values that are not changed inside the subloop.  */
diff --git a/gcc/gimple-iterator.c b/gcc/gimple-iterator.c
index 7077dce..ecea718 100644
--- a/gcc/gimple-iterator.c
+++ b/gcc/gimple-iterator.c
@@ -886,9 +886,17 @@ gsi_commit_one_edge_insert (edge e, basic_block *new_bb)
 
 /* Returns iterator at the start of the list of phi nodes of BB.  */
 
-gimple_stmt_iterator
+gimple_phi_iterator
 gsi_start_phis (basic_block bb)
 {
   gimple_seq *pseq = phi_nodes_ptr (bb);
-  return gsi_start_1 (pseq);
+
+  /* Adapted from gsi_start_1. */
+  gimple_phi_iterator i;
+
+  i.ptr = gimple_seq_first (*pseq);
+  i.seq = pseq;
+  i.bb = i.ptr ? gimple_bb (i.ptr) : NULL;
+
+  return i;
 }
diff --git a/gcc/gimple-iterator.h b/gcc/gimple-iterator.h
index b117b4b..b038dfb 100644
--- a/gcc/gimple-iterator.h
+++ b/gcc/gimple-iterator.h
@@ -34,6 +34,15 @@ struct gimple_stmt_iterator
   gimple_seq *seq;
   basic_block bb;
 };
+
+/* Iterator over GIMPLE_PHI statements.  */
+struct gimple_phi_iterator : public gimple_stmt_iterator
+{
+  gimple_phi phi () const
+  {
+    return as_a <gimple_phi> (ptr);
+  }
+};
  
 enum gsi_iterator_update
 {
@@ -79,7 +88,7 @@ extern basic_block gsi_insert_on_edge_immediate (edge, gimple);
 extern basic_block gsi_insert_seq_on_edge_immediate (edge, gimple_seq);
 extern void gsi_commit_edge_inserts (void);
 extern void gsi_commit_one_edge_insert (edge, basic_block *);
-extern gimple_stmt_iterator gsi_start_phis (basic_block);
+extern gimple_phi_iterator gsi_start_phis (basic_block);
 
 /* Return a new iterator pointing to GIMPLE_SEQ's first statement.  */
 
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 51754c3..b5875b7 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -2297,15 +2297,15 @@ dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
 static void
 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
 {
-  gimple_stmt_iterator i;
+  gimple_phi_iterator i;
 
   for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
     {
-      gimple phi = gsi_stmt (i);
+      gimple_phi phi = i.phi ();
       if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
         {
           INDENT (indent);
-	  dump_gimple_phi (buffer, as_a <gimple_phi> (phi), indent, true, flags);
+	  dump_gimple_phi (buffer, phi, indent, true, flags);
           pp_newline (buffer);
         }
     }
diff --git a/gcc/gimple-ssa-isolate-paths.c b/gcc/gimple-ssa-isolate-paths.c
index 0b62915..8016db4 100644
--- a/gcc/gimple-ssa-isolate-paths.c
+++ b/gcc/gimple-ssa-isolate-paths.c
@@ -232,7 +232,7 @@ find_implicit_erroneous_behaviour (void)
 
   FOR_EACH_BB_FN (bb, cfun)
     {
-      gimple_stmt_iterator si;
+      gimple_phi_iterator si;
 
       /* Out of an abundance of caution, do not isolate paths to a
 	 block where the block has any abnormal outgoing edges.
@@ -251,7 +251,7 @@ find_implicit_erroneous_behaviour (void)
 	 cases.   */
       for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
 	{
-	  gimple phi = gsi_stmt (si);
+	  gimple_phi phi = si.phi ();
 	  tree lhs = gimple_phi_result (phi);
 
 	  /* If the result is not a pointer, then there is no need to
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index f084542..ffec0d0 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -4483,7 +4483,7 @@ expand_parallel_call (struct omp_region *region, basic_block bb,
 
 	  if (gimple_in_ssa_p (cfun))
 	    {
-	      gimple phi = create_phi_node (tmp_join, bb);
+	      gimple_phi phi = create_phi_node (tmp_join, bb);
 	      add_phi_arg (phi, tmp_then, e_then, UNKNOWN_LOCATION);
 	      add_phi_arg (phi, tmp_else, e_else, UNKNOWN_LOCATION);
 	    }
diff --git a/gcc/sese.c b/gcc/sese.c
index 71a752e..33f90c0 100644
--- a/gcc/sese.c
+++ b/gcc/sese.c
@@ -307,7 +307,7 @@ free_sese (sese region)
 static void
 sese_add_exit_phis_edge (basic_block exit, tree use, edge false_e, edge true_e)
 {
-  gimple phi = create_phi_node (NULL_TREE, exit);
+  gimple_phi phi = create_phi_node (NULL_TREE, exit);
   create_new_def_for (use, phi, gimple_phi_result_ptr (phi));
   add_phi_arg (phi, use, false_e, UNKNOWN_LOCATION);
   add_phi_arg (phi, use, true_e, UNKNOWN_LOCATION);
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 4652237..736c451 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -2588,7 +2588,7 @@ reinstall_phi_args (edge new_edge, edge old_edge)
 {
   edge_var_map *vm;
   int i;
-  gimple_stmt_iterator phis;
+  gimple_phi_iterator phis;
 
   vec<edge_var_map> *v = redirect_edge_var_map_vector (old_edge);
   if (!v)
@@ -2598,7 +2598,7 @@ reinstall_phi_args (edge new_edge, edge old_edge)
        v->iterate (i, &vm) && !gsi_end_p (phis);
        i++, gsi_next (&phis))
     {
-      gimple phi = gsi_stmt (phis);
+      gimple_phi phi = phis.phi ();
       tree result = redirect_edge_var_map_result (vm);
       tree arg = redirect_edge_var_map_def (vm);
 
@@ -5342,7 +5342,7 @@ gimple_make_forwarder_block (edge fallthru)
   edge_iterator ei;
   basic_block dummy, bb;
   tree var;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   dummy = fallthru->src;
   bb = fallthru->dest;
@@ -5354,9 +5354,9 @@ gimple_make_forwarder_block (edge fallthru)
      start of BB.  */
   for (gsi = gsi_start_phis (dummy); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi, new_phi;
+      gimple_phi phi, new_phi;
 
-      phi = gsi_stmt (gsi);
+      phi = gsi.phi ();
       var = gimple_phi_result (phi);
       new_phi = create_phi_node (var, bb);
       gimple_phi_set_result (phi, copy_ssa_name (var, phi));
@@ -5823,9 +5823,9 @@ add_phi_args_after_copy_edge (edge e_copy)
   basic_block bb, bb_copy = e_copy->src, dest;
   edge e;
   edge_iterator ei;
-  gimple phi, phi_copy;
+  gimple_phi phi, phi_copy;
   tree def;
-  gimple_stmt_iterator psi, psi_copy;
+  gimple_phi_iterator psi, psi_copy;
 
   if (gimple_seq_empty_p (phi_nodes (e_copy->dest)))
     return;
@@ -5858,8 +5858,8 @@ add_phi_args_after_copy_edge (edge e_copy)
        !gsi_end_p (psi);
        gsi_next (&psi), gsi_next (&psi_copy))
     {
-      phi = gsi_stmt (psi);
-      phi_copy = gsi_stmt (psi_copy);
+      phi = psi.phi ();
+      phi_copy = psi_copy.phi ();
       def = PHI_ARG_DEF_FROM_EDGE (phi, e);
       add_phi_arg (phi_copy, def, e_copy,
 		   gimple_phi_arg_location_from_edge (phi, e));
@@ -7967,8 +7967,8 @@ static void
 gimple_lv_adjust_loop_header_phi (basic_block first, basic_block second,
 				  basic_block new_head, edge e)
 {
-  gimple phi1, phi2;
-  gimple_stmt_iterator psi1, psi2;
+  gimple_phi phi1, phi2;
+  gimple_phi_iterator psi1, psi2;
   tree def;
   edge e2 = find_edge (new_head, second);
 
@@ -7984,8 +7984,8 @@ gimple_lv_adjust_loop_header_phi (basic_block first, basic_block second,
        !gsi_end_p (psi2) && !gsi_end_p (psi1);
        gsi_next (&psi2),  gsi_next (&psi1))
     {
-      phi1 = gsi_stmt (psi1);
-      phi2 = gsi_stmt (psi2);
+      phi1 = psi1.phi ();
+      phi2 = psi2.phi ();
       def = PHI_ARG_DEF (phi2, e2->dest_idx);
       add_phi_arg (phi1, def, e, gimple_phi_arg_location_from_edge (phi2, e2));
     }
diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c
index 451630f..3b2a107 100644
--- a/gcc/tree-cfgcleanup.c
+++ b/gcc/tree-cfgcleanup.c
@@ -367,11 +367,11 @@ phi_alternatives_equal (basic_block dest, edge e1, edge e2)
 {
   int n1 = e1->dest_idx;
   int n2 = e2->dest_idx;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (dest); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       tree val1 = gimple_phi_arg_def (phi, n1);
       tree val2 = gimple_phi_arg_def (phi, n2);
 
@@ -855,7 +855,7 @@ remove_forwarder_block_with_phi (basic_block bb)
   while (EDGE_COUNT (bb->preds) > 0)
     {
       edge e = EDGE_PRED (bb, 0), s;
-      gimple_stmt_iterator gsi;
+      gimple_phi_iterator gsi;
 
       s = find_edge (e->src, dest);
       if (s)
@@ -887,7 +887,7 @@ remove_forwarder_block_with_phi (basic_block bb)
 	   !gsi_end_p (gsi);
 	   gsi_next (&gsi))
 	{
-	  gimple phi = gsi_stmt (gsi);
+	  gimple_phi phi = gsi.phi ();
 	  tree def = gimple_phi_arg_def (phi, succ->dest_idx);
 	  source_location locus = gimple_phi_arg_location_from_edge (phi, succ);
 
@@ -1035,7 +1035,7 @@ pass_merge_phi::execute (function *fun)
 	}
       else
 	{
-	  gimple_stmt_iterator gsi;
+	  gimple_phi_iterator gsi;
 	  unsigned int dest_idx = single_succ_edge (bb)->dest_idx;
 
 	  /* BB dominates DEST.  There may be many users of the PHI
@@ -1046,7 +1046,7 @@ pass_merge_phi::execute (function *fun)
 	  for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
 	       gsi_next (&gsi))
 	    {
-	      gimple phi = gsi_stmt (gsi);
+	      gimple_phi phi = gsi.phi ();
 	      tree result = gimple_phi_result (phi);
 	      use_operand_p imm_use;
 	      gimple use_stmt;
diff --git a/gcc/tree-complex.c b/gcc/tree-complex.c
index f1bba8b..9eb77e8 100644
--- a/gcc/tree-complex.c
+++ b/gcc/tree-complex.c
@@ -722,11 +722,11 @@ update_parameter_components (void)
 static void
 update_phi_components (basic_block bb)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
 
       if (is_complex_reg (gimple_phi_result (phi)))
 	{
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index 1f8ef03..f7f27da 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -485,7 +485,7 @@ bb_with_exit_edge_p (struct loop *loop, basic_block bb)
    - there is a virtual PHI in a BB other than the loop->header.  */
 
 static bool
-if_convertible_phi_p (struct loop *loop, basic_block bb, gimple phi,
+if_convertible_phi_p (struct loop *loop, basic_block bb, gimple_phi phi,
 		      bool any_mask_load_store)
 {
   if (dump_file && (dump_flags & TDF_DETAILS))
@@ -1251,10 +1251,10 @@ if_convertible_loop_p_1 (struct loop *loop,
   for (i = 0; i < loop->num_nodes; i++)
     {
       basic_block bb = ifc_bbs[i];
-      gimple_stmt_iterator itr;
+      gimple_phi_iterator itr;
 
       for (itr = gsi_start_phis (bb); !gsi_end_p (itr); gsi_next (&itr))
-	if (!if_convertible_phi_p (loop, bb, gsi_stmt (itr),
+	if (!if_convertible_phi_p (loop, bb, itr.phi (),
 				   *any_mask_load_store))
 	  return false;
     }
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 96bd561..b5ba212 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -1970,8 +1970,8 @@ update_ssa_across_abnormal_edges (basic_block bb, basic_block ret_bb,
     if (!e->dest->aux
 	|| ((basic_block)e->dest->aux)->index == ENTRY_BLOCK)
       {
-	gimple phi;
-	gimple_stmt_iterator si;
+	gimple_phi phi;
+	gimple_phi_iterator si;
 
 	if (!nonlocal_goto)
 	  gcc_assert (e->flags & EDGE_EH);
@@ -1983,7 +1983,7 @@ update_ssa_across_abnormal_edges (basic_block bb, basic_block ret_bb,
 	  {
 	    edge re;
 
-	    phi = gsi_stmt (si);
+	    phi = si.phi ();
 
 	    /* For abnormal goto/call edges the receiver can be the
 	       ENTRY_BLOCK.  Do not assert this cannot happen.  */
@@ -2137,17 +2137,17 @@ copy_phis_for_bb (basic_block bb, copy_body_data *id)
 {
   basic_block const new_bb = (basic_block) bb->aux;
   edge_iterator ei;
-  gimple phi;
-  gimple_stmt_iterator si;
+  gimple_phi phi;
+  gimple_phi_iterator si;
   edge new_edge;
   bool inserted = false;
 
   for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
     {
       tree res, new_res;
-      gimple new_phi;
+      gimple_phi new_phi;
 
-      phi = gsi_stmt (si);
+      phi = si.phi ();
       res = PHI_RESULT (phi);
       new_res = res;
       if (!virtual_operand_p (res))
diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
index b4c4aab..3150f6b 100644
--- a/gcc/tree-into-ssa.c
+++ b/gcc/tree-into-ssa.c
@@ -1395,8 +1395,8 @@ rewrite_add_phi_arguments (basic_block bb)
 
   FOR_EACH_EDGE (e, ei, bb->succs)
     {
-      gimple phi;
-      gimple_stmt_iterator gsi;
+      gimple_phi phi;
+      gimple_phi_iterator gsi;
 
       for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi);
 	   gsi_next (&gsi))
@@ -1404,7 +1404,7 @@ rewrite_add_phi_arguments (basic_block bb)
 	  tree currdef, res;
 	  location_t loc;
 
-	  phi = gsi_stmt (gsi);
+	  phi = gsi.phi ();
 	  res = gimple_phi_result (phi);
 	  currdef = get_reaching_def (SSA_NAME_VAR (res));
 	  /* Virtual operand PHI args do not need a location.  */
diff --git a/gcc/tree-outof-ssa.c b/gcc/tree-outof-ssa.c
index 2d43bc2..59236c4 100644
--- a/gcc/tree-outof-ssa.c
+++ b/gcc/tree-outof-ssa.c
@@ -581,13 +581,13 @@ eliminate_build (elim_graph g)
 {
   tree Ti;
   int p0, pi;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   clear_elim_graph (g);
 
   for (gsi = gsi_start_phis (g->e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       source_location locus;
 
       p0 = var_to_partition (g->map, gimple_phi_result (phi));
@@ -832,14 +832,14 @@ static void
 eliminate_useless_phis (void)
 {
   basic_block bb;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   tree result;
 
   FOR_EACH_BB_FN (bb, cfun)
     {
       for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); )
         {
-	  gimple phi = gsi_stmt (gsi);
+	  gimple_phi phi = gsi.phi ();
 	  result = gimple_phi_result (phi);
 	  if (virtual_operand_p (result))
 	    {
@@ -895,10 +895,10 @@ rewrite_trees (var_map map ATTRIBUTE_UNUSED)
      create incorrect code.  */
   FOR_EACH_BB_FN (bb, cfun)
     {
-      gimple_stmt_iterator gsi;
+      gimple_phi_iterator gsi;
       for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
 	{
-	  gimple phi = gsi_stmt (gsi);
+	  gimple_phi phi = gsi.phi ();
 	  tree T0 = var_to_partition_to_var (map, gimple_phi_result (phi));
 	  if (T0 == NULL_TREE)
 	    {
@@ -1097,7 +1097,7 @@ static void
 insert_backedge_copies (void)
 {
   basic_block bb;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   mark_dfs_back_edges ();
 
@@ -1108,7 +1108,7 @@ insert_backedge_copies (void)
 
       for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
 	{
-	  gimple phi = gsi_stmt (gsi);
+	  gimple_phi phi = gsi.phi ();
 	  tree result = gimple_phi_result (phi);
 	  size_t i;
 
diff --git a/gcc/tree-phinodes.c b/gcc/tree-phinodes.c
index c075f98..d15d3b4 100644
--- a/gcc/tree-phinodes.c
+++ b/gcc/tree-phinodes.c
@@ -291,11 +291,11 @@ reserve_phi_args_for_new_edge (basic_block bb)
 {
   size_t len = EDGE_COUNT (bb->preds);
   size_t cap = ideal_phi_node_len (len + 4);
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple_phi stmt = as_a <gimple_phi> (gsi_stmt (gsi));
+      gimple_phi stmt = gsi.phi ();
 
       if (len > gimple_phi_capacity (stmt))
 	{
@@ -326,7 +326,7 @@ reserve_phi_args_for_new_edge (basic_block bb)
 /* Adds PHI to BB.  */
 
 void
-add_phi_node_to_bb (gimple phi, basic_block bb)
+add_phi_node_to_bb (gimple_phi phi, basic_block bb)
 {
   gimple_seq seq = phi_nodes (bb);
   /* Add the new PHI node to the list of PHI nodes for block BB.  */
@@ -431,10 +431,10 @@ remove_phi_arg_num (gimple_phi phi, int i)
 void
 remove_phi_args (edge e)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
-    remove_phi_arg_num (as_a <gimple_statement_phi *> (gsi_stmt (gsi)),
+    remove_phi_arg_num (gsi.phi (),
 			e->dest_idx);
 }
 
@@ -466,7 +466,7 @@ remove_phi_node (gimple_stmt_iterator *gsi, bool release_lhs_p)
 void
 remove_phi_nodes (basic_block bb)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); )
     remove_phi_node (&gsi, true);
diff --git a/gcc/tree-phinodes.h b/gcc/tree-phinodes.h
index 0159d5d..fe8b32d 100644
--- a/gcc/tree-phinodes.h
+++ b/gcc/tree-phinodes.h
@@ -23,7 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 extern void phinodes_print_statistics (void);
 extern void release_phi_node (gimple);
 extern void reserve_phi_args_for_new_edge (basic_block);
-extern void add_phi_node_to_bb (gimple phi, basic_block bb);
+extern void add_phi_node_to_bb (gimple_phi phi, basic_block bb);
 extern gimple_phi create_phi_node (tree, basic_block);
 extern void add_phi_arg (gimple, tree, edge, source_location);
 extern void remove_phi_args (edge);
diff --git a/gcc/tree-predcom.c b/gcc/tree-predcom.c
index 7348985..0ce81aa 100644
--- a/gcc/tree-predcom.c
+++ b/gcc/tree-predcom.c
@@ -1116,10 +1116,11 @@ static gimple
 find_looparound_phi (struct loop *loop, dref ref, dref root)
 {
   tree name, init, init_ref;
-  gimple phi = NULL, init_stmt;
+  gimple_phi phi = NULL;
+  gimple init_stmt;
   edge latch = loop_latch_edge (loop);
   struct data_reference init_dr;
-  gimple_stmt_iterator psi;
+  gimple_phi_iterator psi;
 
   if (is_gimple_assign (ref->stmt))
     {
@@ -1135,7 +1136,7 @@ find_looparound_phi (struct loop *loop, dref ref, dref root)
 
   for (psi = gsi_start_phis (loop->header); !gsi_end_p (psi); gsi_next (&psi))
     {
-      phi = gsi_stmt (psi);
+      phi = psi.phi ();
       if (PHI_ARG_DEF_FROM_EDGE (phi, latch) == name)
 	break;
     }
@@ -1887,14 +1888,15 @@ static void
 eliminate_temp_copies (struct loop *loop, bitmap tmp_vars)
 {
   edge e;
-  gimple phi, stmt;
+  gimple_phi phi;
+  gimple stmt;
   tree name, use, var;
-  gimple_stmt_iterator psi;
+  gimple_phi_iterator psi;
 
   e = loop_latch_edge (loop);
   for (psi = gsi_start_phis (loop->header); !gsi_end_p (psi); gsi_next (&psi))
     {
-      phi = gsi_stmt (psi);
+      phi = psi.phi ();
       name = PHI_RESULT (phi);
       var = SSA_NAME_VAR (name);
       if (!var || !bitmap_bit_p (tmp_vars, DECL_UID (var)))
diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c
index 248bb8d..0a6739f 100644
--- a/gcc/tree-scalar-evolution.c
+++ b/gcc/tree-scalar-evolution.c
@@ -2238,8 +2238,8 @@ loop_closed_phi_def (tree var)
 {
   struct loop *loop;
   edge exit;
-  gimple phi;
-  gimple_stmt_iterator psi;
+  gimple_phi phi;
+  gimple_phi_iterator psi;
 
   if (var == NULL_TREE
       || TREE_CODE (var) != SSA_NAME)
@@ -2252,7 +2252,7 @@ loop_closed_phi_def (tree var)
 
   for (psi = gsi_start_phis (exit->dest); !gsi_end_p (psi); gsi_next (&psi))
     {
-      phi = gsi_stmt (psi);
+      phi = psi.phi ();
       if (PHI_ARG_DEF_FROM_EDGE (phi, exit) == var)
 	return PHI_RESULT (phi);
     }
@@ -3338,11 +3338,12 @@ scev_const_prop (void)
 {
   basic_block bb;
   tree name, type, ev;
-  gimple phi, ass;
+  gimple_phi phi;
+  gimple ass;
   struct loop *loop, *ex_loop;
   bitmap ssa_names_to_remove = NULL;
   unsigned i;
-  gimple_stmt_iterator psi;
+  gimple_phi_iterator psi;
 
   if (number_of_loops (cfun) <= 1)
     return 0;
@@ -3353,7 +3354,7 @@ scev_const_prop (void)
 
       for (psi = gsi_start_phis (bb); !gsi_end_p (psi); gsi_next (&psi))
 	{
-	  phi = gsi_stmt (psi);
+	  phi = psi.phi ();
 	  name = PHI_RESULT (phi);
 
 	  if (virtual_operand_p (name))
@@ -3391,7 +3392,7 @@ scev_const_prop (void)
 	{
 	  gimple_stmt_iterator psi;
 	  name = ssa_name (i);
-	  phi = SSA_NAME_DEF_STMT (name);
+	  phi = as_a <gimple_phi> (SSA_NAME_DEF_STMT (name));
 
 	  gcc_assert (gimple_code (phi) == GIMPLE_PHI);
 	  psi = gsi_for_stmt (phi);
@@ -3429,7 +3430,7 @@ scev_const_prop (void)
 
       for (psi = gsi_start_phis (exit->dest); !gsi_end_p (psi); )
 	{
-	  phi = gsi_stmt (psi);
+	  phi = psi.phi ();
 	  rslt = PHI_RESULT (phi);
 	  def = PHI_ARG_DEF_FROM_EDGE (phi, exit);
 	  if (virtual_operand_p (def))
diff --git a/gcc/tree-ssa-coalesce.c b/gcc/tree-ssa-coalesce.c
index 24ed4b4..e4e2201 100644
--- a/gcc/tree-ssa-coalesce.c
+++ b/gcc/tree-ssa-coalesce.c
@@ -1189,11 +1189,11 @@ coalesce_partitions (var_map map, ssa_conflicts_p graph, coalesce_list_p cl,
       FOR_EACH_EDGE (e, ei, bb->preds)
 	if (e->flags & EDGE_ABNORMAL)
 	  {
-	    gimple_stmt_iterator gsi;
+	    gimple_phi_iterator gsi;
 	    for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
 		 gsi_next (&gsi))
 	      {
-		gimple phi = gsi_stmt (gsi);
+		gimple_phi phi = gsi.phi ();
 		tree res = PHI_RESULT (phi);
 	        tree arg = PHI_ARG_DEF (phi, e->dest_idx);
 		int v1 = SSA_NAME_VERSION (res);
diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
index fd2e444..70b405c 100644
--- a/gcc/tree-ssa-dce.c
+++ b/gcc/tree-ssa-dce.c
@@ -933,13 +933,13 @@ static bool
 remove_dead_phis (basic_block bb)
 {
   bool something_changed = false;
-  gimple phi;
-  gimple_stmt_iterator gsi;
+  gimple_phi phi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi);)
     {
       stats.total_phis++;
-      phi = gsi_stmt (gsi);
+      phi = gsi.phi ();
 
       /* We do not track necessity of virtual PHI nodes.  Instead do
          very simple dead PHI removal here.  */
@@ -991,7 +991,7 @@ remove_dead_phis (basic_block bb)
 static edge
 forward_edge_to_pdom (edge e, basic_block post_dom_bb)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   edge e2 = NULL;
   edge_iterator ei;
 
@@ -1015,7 +1015,7 @@ forward_edge_to_pdom (edge e, basic_block post_dom_bb)
 	  break;
       for (gsi = gsi_start_phis (post_dom_bb); !gsi_end_p (gsi);)
 	{
-	  gimple phi = gsi_stmt (gsi);
+	  gimple_phi phi = gsi.phi ();
 	  tree op;
 	  source_location locus;
 
diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index d26596b..81be88a 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -1189,11 +1189,11 @@ dom_opt_dom_walker::thread_across_edge (edge e)
 static void
 record_equivalences_from_phis (basic_block bb)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
 
       tree lhs = gimple_phi_result (phi);
       tree rhs = NULL;
@@ -1716,7 +1716,7 @@ cprop_into_successor_phis (basic_block bb)
   FOR_EACH_EDGE (e, ei, bb->succs)
     {
       int indx;
-      gimple_stmt_iterator gsi;
+      gimple_phi_iterator gsi;
 
       /* If this is an abnormal edge, then we do not want to copy propagate
 	 into the PHI alternative associated with this edge.  */
@@ -1755,7 +1755,7 @@ cprop_into_successor_phis (basic_block bb)
 	  tree new_val;
 	  use_operand_p orig_p;
 	  tree orig_val;
-          gimple phi = gsi_stmt (gsi);
+          gimple_phi phi = gsi.phi ();
 
 	  /* The alternative may be associated with a constant, so verify
 	     it is an SSA_NAME before doing anything with it.  */
@@ -2846,7 +2846,8 @@ propagate_rhs_into_lhs (gimple stmt, tree lhs, tree rhs, bitmap interesting_name
 		  edge te = find_taken_edge (bb, val);
 		  edge_iterator ei;
 		  edge e;
-		  gimple_stmt_iterator gsi, psi;
+		  gimple_stmt_iterator gsi;
+		  gimple_phi_iterator psi;
 
 		  /* Remove all outgoing edges except TE.  */
 		  for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei));)
@@ -2859,7 +2860,7 @@ propagate_rhs_into_lhs (gimple stmt, tree lhs, tree rhs, bitmap interesting_name
                                !gsi_end_p (psi);
                                gsi_next (&psi))
                             {
-                              gimple phi = gsi_stmt (psi);
+                              gimple_phi phi = psi.phi ();
 
 			      tree result = gimple_phi_result (phi);
 			      int version = SSA_NAME_VERSION (result);
@@ -2969,12 +2970,12 @@ eliminate_const_or_copy (gimple stmt, bitmap interesting_names)
 static void
 eliminate_degenerate_phis_1 (basic_block bb, bitmap interesting_names)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   basic_block son;
 
   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
 
       eliminate_const_or_copy (phi, interesting_names);
     }
diff --git a/gcc/tree-ssa-ifcombine.c b/gcc/tree-ssa-ifcombine.c
index 43fd50b..0420ef3 100644
--- a/gcc/tree-ssa-ifcombine.c
+++ b/gcc/tree-ssa-ifcombine.c
@@ -158,12 +158,12 @@ same_phi_args_p (basic_block bb1, basic_block bb2, basic_block dest)
 {
   edge e1 = find_edge (bb1, dest);
   edge e2 = find_edge (bb2, dest);
-  gimple_stmt_iterator gsi;
-  gimple phi;
+  gimple_phi_iterator gsi;
+  gimple_phi phi;
 
   for (gsi = gsi_start_phis (dest); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      phi = gsi_stmt (gsi);
+      phi = gsi.phi ();
       if (!operand_equal_p (PHI_ARG_DEF_FROM_EDGE (phi, e1),
 			    PHI_ARG_DEF_FROM_EDGE (phi, e2), 0))
         return false;
diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c
index 23eaf26..49ddc10 100644
--- a/gcc/tree-ssa-live.c
+++ b/gcc/tree-ssa-live.c
@@ -1154,13 +1154,13 @@ calculate_live_on_exit (tree_live_info_p liveinfo)
   /* Set all the live-on-exit bits for uses in PHIs.  */
   FOR_EACH_BB_FN (bb, cfun)
     {
-      gimple_stmt_iterator gsi;
+      gimple_phi_iterator gsi;
       size_t i;
 
       /* Mark the PHI arguments which are live on exit to the pred block.  */
       for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
 	{
-	  gimple phi = gsi_stmt (gsi);
+	  gimple_phi phi = gsi.phi ();
 	  for (i = 0; i < gimple_phi_num_args (phi); i++)
 	    {
 	      tree t = PHI_ARG_DEF (phi, i);
@@ -1433,12 +1433,12 @@ verify_live_on_entry (tree_live_info_p live)
 		   if it occurs in a PHI argument of the block.  */
 		size_t z;
 		bool ok = false;
-		gimple_stmt_iterator gsi;
+		gimple_phi_iterator gsi;
 		for (gsi = gsi_start_phis (e->dest);
 		     !gsi_end_p (gsi) && !ok;
 		     gsi_next (&gsi))
 		  {
-		    gimple phi = gsi_stmt (gsi);
+		    gimple_phi phi = gsi.phi ();
 		    for (z = 0; z < gimple_phi_num_args (phi); z++)
 		      if (var == gimple_phi_arg_def (phi, z))
 			{
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index 325f777..339e221 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -1264,11 +1264,11 @@ move_computations_dom_walker::before_dom_children (basic_block bb)
 	{
 	  /* The new VUSE is the one from the virtual PHI in the loop
 	     header or the one already present.  */
-	  gimple_stmt_iterator gsi2;
+	  gimple_phi_iterator gsi2;
 	  for (gsi2 = gsi_start_phis (e->dest);
 	       !gsi_end_p (gsi2); gsi_next (&gsi2))
 	    {
-	      gimple phi = gsi_stmt (gsi2);
+	      gimple_phi phi = gsi2.phi ();
 	      if (virtual_operand_p (gimple_phi_result (phi)))
 		{
 		  gimple_set_vuse (stmt, PHI_ARG_DEF_FROM_EDGE (phi, e));
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 400798a..8d330d9 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -1061,11 +1061,11 @@ find_bivs (struct ivopts_data *data)
   tree step, type, base;
   bool found = false;
   struct loop *loop = data->current_loop;
-  gimple_stmt_iterator psi;
+  gimple_phi_iterator psi;
 
   for (psi = gsi_start_phis (loop->header); !gsi_end_p (psi); gsi_next (&psi))
     {
-      phi = gsi_stmt (psi);
+      phi = psi.phi ();
 
       if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)))
 	continue;
@@ -1107,11 +1107,11 @@ mark_bivs (struct ivopts_data *data)
   struct iv *iv, *incr_iv;
   struct loop *loop = data->current_loop;
   basic_block incr_bb;
-  gimple_stmt_iterator psi;
+  gimple_phi_iterator psi;
 
   for (psi = gsi_start_phis (loop->header); !gsi_end_p (psi); gsi_next (&psi))
     {
-      phi = gsi_stmt (psi);
+      phi = psi.phi ();
 
       iv = get_iv (data, PHI_RESULT (phi));
       if (!iv)
@@ -1994,13 +1994,13 @@ find_interesting_uses_stmt (struct ivopts_data *data, gimple stmt)
 static void
 find_interesting_uses_outside (struct ivopts_data *data, edge exit)
 {
-  gimple phi;
-  gimple_stmt_iterator psi;
+  gimple_phi phi;
+  gimple_phi_iterator psi;
   tree def;
 
   for (psi = gsi_start_phis (exit->dest); !gsi_end_p (psi); gsi_next (&psi))
     {
-      phi = gsi_stmt (psi);
+      phi = psi.phi ();
       def = PHI_ARG_DEF_FROM_EDGE (phi, exit);
       if (!virtual_operand_p (def))
         find_interesting_uses_op (data, def);
@@ -5185,8 +5185,8 @@ static void
 determine_set_costs (struct ivopts_data *data)
 {
   unsigned j, n;
-  gimple phi;
-  gimple_stmt_iterator psi;
+  gimple_phi phi;
+  gimple_phi_iterator psi;
   tree op;
   struct loop *loop = data->current_loop;
   bitmap_iterator bi;
@@ -5203,7 +5203,7 @@ determine_set_costs (struct ivopts_data *data)
   n = 0;
   for (psi = gsi_start_phis (loop->header); !gsi_end_p (psi); gsi_next (&psi))
     {
-      phi = gsi_stmt (psi);
+      phi = psi.phi ();
       op = PHI_RESULT (phi);
 
       if (virtual_operand_p (op))
diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c
index ac96936..3acf7fb 100644
--- a/gcc/tree-ssa-loop-manip.c
+++ b/gcc/tree-ssa-loop-manip.c
@@ -630,12 +630,12 @@ split_loop_exit_edge (edge exit)
   gimple phi, new_phi;
   tree new_name, name;
   use_operand_p op_p;
-  gimple_stmt_iterator psi;
+  gimple_phi_iterator psi;
   source_location locus;
 
   for (psi = gsi_start_phis (dest); !gsi_end_p (psi); gsi_next (&psi))
     {
-      phi = gsi_stmt (psi);
+      phi = psi.phi ();
       op_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, single_succ_edge (bb));
       locus = gimple_phi_arg_location_from_edge (phi, single_succ_edge (bb));
 
@@ -1023,8 +1023,8 @@ tree_transform_and_unroll_loop (struct loop *loop, unsigned factor,
   tree ctr_before, ctr_after;
   tree enter_main_cond, exit_base, exit_step, exit_bound;
   enum tree_code exit_cmp;
-  gimple phi_old_loop, phi_new_loop, phi_rest;
-  gimple_stmt_iterator psi_old_loop, psi_new_loop;
+  gimple_phi phi_old_loop, phi_new_loop, phi_rest;
+  gimple_phi_iterator psi_old_loop, psi_new_loop;
   tree init, next, new_init;
   struct loop *new_loop;
   basic_block rest, exit_bb;
@@ -1131,8 +1131,8 @@ tree_transform_and_unroll_loop (struct loop *loop, unsigned factor,
        !gsi_end_p (psi_old_loop);
        gsi_next (&psi_old_loop), gsi_next (&psi_new_loop))
     {
-      phi_old_loop = gsi_stmt (psi_old_loop);
-      phi_new_loop = gsi_stmt (psi_new_loop);
+      phi_old_loop = psi_old_loop.phi ();
+      phi_new_loop = psi_new_loop.phi ();
 
       init = PHI_ARG_DEF_FROM_EDGE (phi_old_loop, old_entry);
       op = PHI_ARG_DEF_PTR_FROM_EDGE (phi_new_loop, new_entry);
@@ -1248,12 +1248,13 @@ tree_unroll_loop (struct loop *loop, unsigned factor,
 
 static void
 rewrite_phi_with_iv (loop_p loop,
-		     gimple_stmt_iterator *psi,
+		     gimple_phi_iterator *psi,
 		     gimple_stmt_iterator *gsi,
 		     tree main_iv)
 {
   affine_iv iv;
-  gimple stmt, phi = gsi_stmt (*psi);
+  gimple stmt;
+  gimple_phi phi = psi->phi ();
   tree atype, mtype, val, res = PHI_RESULT (phi);
 
   if (virtual_operand_p (res) || res == main_iv)
@@ -1291,7 +1292,7 @@ rewrite_all_phi_nodes_with_iv (loop_p loop, tree main_iv)
 {
   unsigned i;
   basic_block *bbs = get_loop_body_in_dom_order (loop);
-  gimple_stmt_iterator psi;
+  gimple_phi_iterator psi;
 
   for (i = 0; i < loop->num_nodes; i++)
     {
@@ -1324,7 +1325,8 @@ canonicalize_loop_ivs (struct loop *loop, tree *nit, bool bump_in_latch)
   unsigned precision = TYPE_PRECISION (TREE_TYPE (*nit));
   unsigned original_precision = precision;
   tree type, var_before;
-  gimple_stmt_iterator gsi, psi;
+  gimple_stmt_iterator gsi;
+  gimple_phi_iterator psi;
   gimple stmt;
   edge exit = single_dom_exit (loop);
   gimple_seq stmts;
@@ -1334,7 +1336,7 @@ canonicalize_loop_ivs (struct loop *loop, tree *nit, bool bump_in_latch)
   for (psi = gsi_start_phis (loop->header);
        !gsi_end_p (psi); gsi_next (&psi))
     {
-      gimple phi = gsi_stmt (psi);
+      gimple_phi phi = psi.phi ();
       tree res = PHI_RESULT (phi);
       bool uns;
 
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 4da1855..6313fc8 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -147,7 +147,7 @@ determine_value_range (struct loop *loop, tree type, tree var, mpz_t off,
     {
       edge e = loop_preheader_edge (loop);
       signop sgn = TYPE_SIGN (type);
-      gimple_stmt_iterator gsi;
+      gimple_phi_iterator gsi;
 
       /* Either for VAR itself...  */
       rtype = get_range_info (var, &minv, &maxv);
@@ -155,7 +155,7 @@ determine_value_range (struct loop *loop, tree type, tree var, mpz_t off,
 	 PHI argument from the loop preheader edge.  */
       for (gsi = gsi_start_phis (loop->header); !gsi_end_p (gsi); gsi_next (&gsi))
 	{
-	  gimple phi = gsi_stmt (gsi);
+	  gimple_phi phi = gsi.phi ();
 	  wide_int minc, maxc;
 	  if (PHI_ARG_DEF_FROM_EDGE (phi, e) == var
 	      && (get_range_info (gimple_phi_result (phi), &minc, &maxc)
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index f62010f..48e717a 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -2005,14 +2005,14 @@ hoist_adjacent_loads (basic_block bb0, basic_block bb1,
 {
   int param_align = PARAM_VALUE (PARAM_L1_CACHE_LINE_SIZE);
   unsigned param_align_bits = (unsigned) (param_align * BITS_PER_UNIT);
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   /* Walk the phis in bb3 looking for an opportunity.  We are looking
      for phis of two SSA names, one each of which is defined in bb1 and
      bb2.  */
   for (gsi = gsi_start_phis (bb3); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi_stmt = gsi_stmt (gsi);
+      gimple_phi phi_stmt = gsi.phi ();
       gimple def1, def2, defswap;
       tree arg1, arg2, ref1, ref2, field1, field2, fieldswap;
       tree tree_offset1, tree_offset2, tree_size2, next;
diff --git a/gcc/tree-ssa-phiprop.c b/gcc/tree-ssa-phiprop.c
index a549200..2105c87 100644
--- a/gcc/tree-ssa-phiprop.c
+++ b/gcc/tree-ssa-phiprop.c
@@ -247,7 +247,7 @@ phiprop_insert_phi (basic_block bb, gimple phi, gimple use_stmt,
    with aliasing issues as we are moving memory reads.  */
 
 static bool
-propagate_with_phi (basic_block bb, gimple phi, struct phiprop_d *phivn,
+propagate_with_phi (basic_block bb, gimple_phi phi, struct phiprop_d *phivn,
 		    size_t n)
 {
   tree ptr = PHI_RESULT (phi);
@@ -409,7 +409,7 @@ pass_phiprop::execute (function *fun)
   struct phiprop_d *phivn;
   bool did_something = false;
   basic_block bb;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   unsigned i;
   size_t n;
 
@@ -424,7 +424,7 @@ pass_phiprop::execute (function *fun)
 				  single_succ (ENTRY_BLOCK_PTR_FOR_FN (fun)));
   FOR_EACH_VEC_ELT (bbs, i, bb)
     for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
-      did_something |= propagate_with_phi (bb, gsi_stmt (gsi), phivn, n);
+      did_something |= propagate_with_phi (bb, gsi.phi (), phivn, n);
 
   if (did_something)
     gsi_commit_edge_inserts ();
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 2e8337c..524dc53 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -2493,7 +2493,7 @@ suitable_cond_bb (basic_block bb, basic_block test_bb, basic_block *other_bb,
   edge_iterator ei, ei2;
   edge e, e2;
   gimple stmt;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   bool other_edge_seen = false;
   bool is_cond;
 
@@ -2555,7 +2555,7 @@ suitable_cond_bb (basic_block bb, basic_block test_bb, basic_block *other_bb,
   e2 = find_edge (test_bb, *other_bb);
   for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       /* If both BB and TEST_BB end with GIMPLE_COND, all PHI arguments
 	 corresponding to BB and TEST_BB predecessor must be the same.  */
       if (!operand_equal_p (gimple_phi_arg_def (phi, e->dest_idx),
diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c
index 37181bd..521378e 100644
--- a/gcc/tree-ssa-tail-merge.c
+++ b/gcc/tree-ssa-tail-merge.c
@@ -1285,11 +1285,11 @@ static bool
 same_phi_alternatives_1 (basic_block dest, edge e1, edge e2)
 {
   int n1 = e1->dest_idx, n2 = e2->dest_idx;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (dest); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       tree lhs = gimple_phi_result (phi);
       tree val1 = gimple_phi_arg_def (phi, n1);
       tree val2 = gimple_phi_arg_def (phi, n2);
@@ -1470,10 +1470,10 @@ static gimple
 vop_phi (basic_block bb)
 {
   gimple stmt;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      stmt = gsi_stmt (gsi);
+      stmt = gsi.phi ();
       if (! virtual_operand_p (gimple_phi_result (stmt)))
 	continue;
       return stmt;
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 0a04787..da4419d 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -202,14 +202,14 @@ record_temporary_equivalence (tree x, tree y, vec<tree> *stack)
 static bool
 record_temporary_equivalences_from_phis (edge e, vec<tree> *stack)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   /* Each PHI creates a temporary equivalence, record them.
      These are context sensitive equivalences and will be removed
      later.  */
   for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       tree src = PHI_ARG_DEF_FROM_EDGE (phi, e);
       tree dst = gimple_phi_result (phi);
 
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 125f6f8..24920ca 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -394,13 +394,13 @@ copy_phi_arg_into_existing_phi (edge src_e, edge tgt_e)
   int tgt_idx = tgt_e->dest_idx;
 
   /* Iterate over each PHI in e->dest.  */
-  for (gimple_stmt_iterator gsi = gsi_start_phis (src_e->dest),
-			    gsi2 = gsi_start_phis (tgt_e->dest);
+  for (gimple_phi_iterator gsi = gsi_start_phis (src_e->dest),
+			   gsi2 = gsi_start_phis (tgt_e->dest);
        !gsi_end_p (gsi);
        gsi_next (&gsi), gsi_next (&gsi2))
     {
-      gimple src_phi = gsi_stmt (gsi);
-      gimple dest_phi = gsi_stmt (gsi2);
+      gimple_phi src_phi = gsi.phi ();
+      gimple_phi dest_phi = gsi2.phi ();
       tree val = gimple_phi_arg_def (src_phi, src_idx);
       source_location locus = gimple_phi_arg_location (src_phi, src_idx);
 
@@ -463,12 +463,12 @@ static void
 copy_phi_args (basic_block bb, edge src_e, edge tgt_e,
 	       vec<jump_thread_edge *> *path, int idx)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   int src_indx = src_e->dest_idx;
 
   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       tree def = gimple_phi_arg_def (phi, src_indx);
       source_location locus = gimple_phi_arg_location (phi, src_indx);
 
@@ -2050,13 +2050,13 @@ fail:
 static bool
 phi_args_equal_on_edges (edge e1, edge e2)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   int indx1 = e1->dest_idx;
   int indx2 = e2->dest_idx;
 
   for (gsi = gsi_start_phis (e1->dest); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
 
       if (!operand_equal_p (gimple_phi_arg_def (phi, indx1),
 			    gimple_phi_arg_def (phi, indx2), 0))
diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index 3b38fd4..bae72ff 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -2174,9 +2174,9 @@ is_use_properly_guarded (gimple use_stmt,
    if the new phi is already in the worklist.  */
 
 static gimple
-find_uninit_use (gimple phi, unsigned uninit_opnds,
-                 vec<gimple> *worklist,
-		 hash_set<gimple> *added_to_worklist)
+find_uninit_use (gimple_phi phi, unsigned uninit_opnds,
+                 vec<gimple_phi> *worklist,
+		 hash_set<gimple_phi> *added_to_worklist)
 {
   tree phi_result;
   use_operand_p use_p;
@@ -2215,7 +2215,7 @@ find_uninit_use (gimple phi, unsigned uninit_opnds,
 
       /* Found a phi use that is not guarded,
          add the phi to the worklist.  */
-      if (!added_to_worklist->add (use_stmt))
+      if (!added_to_worklist->add (as_a <gimple_phi> (use_stmt)))
         {
           if (dump_file && (dump_flags & TDF_DETAILS))
             {
@@ -2223,7 +2223,7 @@ find_uninit_use (gimple phi, unsigned uninit_opnds,
               print_gimple_stmt (dump_file, use_stmt, 0, 0);
             }
 
-          worklist->safe_push (use_stmt);
+          worklist->safe_push (as_a <gimple_phi> (use_stmt));
           possibly_undefined_names->add (phi_result);
         }
     }
@@ -2240,8 +2240,8 @@ find_uninit_use (gimple phi, unsigned uninit_opnds,
    a pointer set tracking if the new phi is added to the worklist or not.  */
 
 static void
-warn_uninitialized_phi (gimple phi, vec<gimple> *worklist,
-                        hash_set<gimple> *added_to_worklist)
+warn_uninitialized_phi (gimple_phi phi, vec<gimple_phi> *worklist,
+                        hash_set<gimple_phi> *added_to_worklist)
 {
   unsigned uninit_opnds;
   gimple uninit_use_stmt = 0;
@@ -2326,8 +2326,8 @@ unsigned int
 pass_late_warn_uninitialized::execute (function *fun)
 {
   basic_block bb;
-  gimple_stmt_iterator gsi;
-  vec<gimple> worklist = vNULL;
+  gimple_phi_iterator gsi;
+  vec<gimple_phi> worklist = vNULL;
 
   calculate_dominance_info (CDI_DOMINATORS);
   calculate_dominance_info (CDI_POST_DOMINATORS);
@@ -2339,13 +2339,13 @@ pass_late_warn_uninitialized::execute (function *fun)
   timevar_push (TV_TREE_UNINIT);
 
   possibly_undefined_names = new hash_set<tree>;
-  hash_set<gimple> added_to_worklist;
+  hash_set<gimple_phi> added_to_worklist;
 
   /* Initialize worklist  */
   FOR_EACH_BB_FN (bb, fun)
     for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
       {
-	gimple phi = gsi_stmt (gsi);
+	gimple_phi phi = gsi.phi ();
 	size_t n, i;
 
 	n = gimple_phi_num_args (phi);
@@ -2374,7 +2374,7 @@ pass_late_warn_uninitialized::execute (function *fun)
 
   while (worklist.length () != 0)
     {
-      gimple cur_phi = 0;
+      gimple_phi cur_phi = 0;
       cur_phi = worklist.pop ();
       warn_uninitialized_phi (cur_phi, &worklist, &added_to_worklist);
     }
diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
index f05db17..a907426 100644
--- a/gcc/tree-ssa.c
+++ b/gcc/tree-ssa.c
@@ -149,8 +149,8 @@ redirect_edge_var_map_destroy (void)
 edge
 ssa_redirect_edge (edge e, basic_block dest)
 {
-  gimple_stmt_iterator gsi;
-  gimple phi;
+  gimple_phi_iterator gsi;
+  gimple_phi phi;
 
   redirect_edge_var_map_clear (e);
 
@@ -160,7 +160,7 @@ ssa_redirect_edge (edge e, basic_block dest)
       tree def;
       source_location locus ;
 
-      phi = gsi_stmt (gsi);
+      phi = gsi.phi ();
       def = gimple_phi_arg_def (phi, e->dest_idx);
       locus = gimple_phi_arg_location (phi, e->dest_idx);
 
@@ -182,10 +182,10 @@ ssa_redirect_edge (edge e, basic_block dest)
 void
 flush_pending_stmts (edge e)
 {
-  gimple phi;
+  gimple_phi phi;
   edge_var_map *vm;
   int i;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   vec<edge_var_map> *v = redirect_edge_var_map_vector (e);
   if (!v)
@@ -197,7 +197,7 @@ flush_pending_stmts (edge e)
     {
       tree def;
 
-      phi = gsi_stmt (gsi);
+      phi = gsi.phi ();
       def = redirect_edge_var_map_def (vm);
       add_phi_arg (phi, def, e, redirect_edge_var_map_location (vm));
     }
diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c
index 7691aeb..424d196 100644
--- a/gcc/tree-switch-conversion.c
+++ b/gcc/tree-switch-conversion.c
@@ -773,12 +773,12 @@ check_all_empty_except_final (struct switch_conv_info *info)
 static bool
 check_final_bb (struct switch_conv_info *info)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   info->phi_count = 0;
   for (gsi = gsi_start_phis (info->final_bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       unsigned int i;
 
       info->phi_count++;
@@ -854,7 +854,7 @@ free_temp_arrays (struct switch_conv_info *info)
 static void
 gather_default_values (tree default_case, struct switch_conv_info *info)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   basic_block bb = label_to_block (CASE_LABEL (default_case));
   edge e;
   int i = 0;
@@ -868,7 +868,7 @@ gather_default_values (tree default_case, struct switch_conv_info *info)
 
   for (gsi = gsi_start_phis (info->final_bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       tree val = PHI_ARG_DEF_FROM_EDGE (phi, e);
       gcc_assert (val);
       info->default_values[i++] = val;
@@ -891,7 +891,7 @@ build_constructors (gimple_switch swtch, struct switch_conv_info *info)
       basic_block bb = label_to_block (CASE_LABEL (cs));
       edge e;
       tree high;
-      gimple_stmt_iterator gsi;
+      gimple_phi_iterator gsi;
       int j;
 
       if (bb == info->final_bb)
@@ -926,7 +926,7 @@ build_constructors (gimple_switch swtch, struct switch_conv_info *info)
       for (gsi = gsi_start_phis (info->final_bb);
 	   !gsi_end_p (gsi); gsi_next (&gsi))
 	{
-	  gimple phi = gsi_stmt (gsi);
+	  gimple_phi phi = gsi.phi ();
 	  tree val = PHI_ARG_DEF_FROM_EDGE (phi, e);
 	  tree low = CASE_LOW (cs);
 	  pos = CASE_LOW (cs);
@@ -1204,13 +1204,13 @@ static void
 fix_phi_nodes (edge e1f, edge e2f, basic_block bbf,
 	       struct switch_conv_info *info)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   int i;
 
   for (gsi = gsi_start_phis (bbf), i = 0;
        !gsi_end_p (gsi); gsi_next (&gsi), i++)
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       add_phi_arg (phi, info->target_inbound_names[i], e1f, UNKNOWN_LOCATION);
       add_phi_arg (phi, info->target_outbound_names[i], e2f, UNKNOWN_LOCATION);
     }
diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c
index b5bd635..c45c89e 100644
--- a/gcc/tree-tailcall.c
+++ b/gcc/tree-tailcall.c
@@ -388,11 +388,11 @@ static tree
 propagate_through_phis (tree var, edge e)
 {
   basic_block dest = e->dest;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (dest); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       if (PHI_ARG_DEF_FROM_EDGE (phi, e) == var)
         return PHI_RESULT (phi);
     }
@@ -620,10 +620,10 @@ find_tail_calls (basic_block bb, struct tailcall **ret)
 static void
 add_successor_phi_arg (edge e, tree var, tree phi_arg)
 {
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
-    if (PHI_RESULT (gsi_stmt (gsi)) == var)
+    if (PHI_RESULT (gsi.phi ()) == var)
       break;
 
   gcc_assert (!gsi_end_p (gsi));
diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
index 7b79ab1..46e18fe 100644
--- a/gcc/tree-vect-loop-manip.c
+++ b/gcc/tree-vect-loop-manip.c
@@ -391,8 +391,8 @@ static void
 slpeel_update_phi_nodes_for_guard1 (edge guard_edge, struct loop *loop,
                                     bool is_new_loop, basic_block *new_exit_bb)
 {
-  gimple orig_phi, new_phi;
-  gimple update_phi, update_phi2;
+  gimple_phi orig_phi, new_phi;
+  gimple_phi update_phi, update_phi2;
   tree guard_arg, loop_arg;
   basic_block new_merge_bb = guard_edge->dest;
   edge e = EDGE_SUCC (new_merge_bb, 0);
@@ -400,7 +400,7 @@ slpeel_update_phi_nodes_for_guard1 (edge guard_edge, struct loop *loop,
   basic_block orig_bb = loop->header;
   edge new_exit_e;
   tree current_new_name;
-  gimple_stmt_iterator gsi_orig, gsi_update;
+  gimple_phi_iterator gsi_orig, gsi_update;
 
   /* Create new bb between loop and new_merge_bb.  */
   *new_exit_bb = split_edge (single_exit (loop));
@@ -414,8 +414,8 @@ slpeel_update_phi_nodes_for_guard1 (edge guard_edge, struct loop *loop,
     {
       source_location loop_locus, guard_locus;
       tree new_res;
-      orig_phi = gsi_stmt (gsi_orig);
-      update_phi = gsi_stmt (gsi_update);
+      orig_phi = gsi_orig.phi ();
+      update_phi = gsi_update.phi ();
 
       /** 1. Handle new-merge-point phis  **/
 
@@ -531,8 +531,8 @@ static void
 slpeel_update_phi_nodes_for_guard2 (edge guard_edge, struct loop *loop,
                                     bool is_new_loop, basic_block *new_exit_bb)
 {
-  gimple orig_phi, new_phi;
-  gimple update_phi, update_phi2;
+  gimple_phi orig_phi, new_phi;
+  gimple_phi update_phi, update_phi2;
   tree guard_arg, loop_arg;
   basic_block new_merge_bb = guard_edge->dest;
   edge e = EDGE_SUCC (new_merge_bb, 0);
@@ -541,7 +541,7 @@ slpeel_update_phi_nodes_for_guard2 (edge guard_edge, struct loop *loop,
   tree orig_def, orig_def_new_name;
   tree new_name, new_name2;
   tree arg;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   /* Create new bb between loop and new_merge_bb.  */
   *new_exit_bb = split_edge (single_exit (loop));
@@ -551,7 +551,7 @@ slpeel_update_phi_nodes_for_guard2 (edge guard_edge, struct loop *loop,
   for (gsi = gsi_start_phis (update_bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
       tree new_res;
-      update_phi = gsi_stmt (gsi);
+      update_phi = gsi.phi ();
       orig_phi = update_phi;
       orig_def = PHI_ARG_DEF_FROM_EDGE (orig_phi, e);
       /* This loop-closed-phi actually doesn't represent a use
@@ -1173,7 +1173,7 @@ slpeel_tree_peel_loop_to_edge (struct loop *loop, struct loop *scalar_loop,
   basic_block bb_before_first_loop;
   basic_block bb_between_loops;
   basic_block new_exit_bb;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   edge exit_e = single_exit (loop);
   source_location loop_loc;
   /* There are many aspects to how likely the first loop is going to be executed.
@@ -1205,7 +1205,7 @@ slpeel_tree_peel_loop_to_edge (struct loop *loop, struct loop *scalar_loop,
   for (gsi = gsi_start_phis (loop->header); !gsi_end_p (gsi); gsi_next (&gsi))
     if (virtual_operand_p (gimple_phi_result (gsi_stmt (gsi))))
       {
-	gimple phi = gsi_stmt (gsi);
+	gimple_phi phi = gsi.phi ();
 	for (gsi = gsi_start_phis (exit_e->dest);
 	     !gsi_end_p (gsi); gsi_next (&gsi))
 	  if (virtual_operand_p (gimple_phi_result (gsi_stmt (gsi))))
@@ -1529,7 +1529,7 @@ vect_can_advance_ivs_p (loop_vec_info loop_vinfo)
   struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
   basic_block bb = loop->header;
   gimple phi;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
 
   /* Analyze phi functions of the loop header.  */
 
@@ -1539,7 +1539,7 @@ vect_can_advance_ivs_p (loop_vec_info loop_vinfo)
     {
       tree evolution_part;
 
-      phi = gsi_stmt (gsi);
+      phi = gsi.phi ();
       if (dump_enabled_p ())
 	{
           dump_printf_loc (MSG_NOTE, vect_location, "Analyze phi: ");
@@ -1638,8 +1638,8 @@ vect_update_ivs_after_vectorizer (loop_vec_info loop_vinfo, tree niters,
 {
   struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
   basic_block exit_bb = single_exit (loop)->dest;
-  gimple phi, phi1;
-  gimple_stmt_iterator gsi, gsi1;
+  gimple_phi phi, phi1;
+  gimple_phi_iterator gsi, gsi1;
   basic_block update_bb = update_e->dest;
 
   gcc_checking_assert (vect_can_advance_ivs_p (loop_vinfo));
@@ -1658,8 +1658,8 @@ vect_update_ivs_after_vectorizer (loop_vec_info loop_vinfo, tree niters,
       gimple_stmt_iterator last_gsi;
       stmt_vec_info stmt_info;
 
-      phi = gsi_stmt (gsi);
-      phi1 = gsi_stmt (gsi1);
+      phi = gsi.phi ();
+      phi1 = gsi1.phi ();
       if (dump_enabled_p ())
         {
           dump_printf_loc (MSG_NOTE, vect_location,
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index fd1166f..5e56d1b 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -622,7 +622,7 @@ vect_analyze_scalar_cycles_1 (loop_vec_info loop_vinfo, struct loop *loop)
   basic_block bb = loop->header;
   tree init, step;
   auto_vec<gimple, 64> worklist;
-  gimple_stmt_iterator gsi;
+  gimple_phi_iterator gsi;
   bool double_reduc;
 
   if (dump_enabled_p ())
@@ -634,7 +634,7 @@ vect_analyze_scalar_cycles_1 (loop_vec_info loop_vinfo, struct loop *loop)
      changed.  */
   for (gsi = gsi_start_phis  (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple phi = gsi_stmt (gsi);
+      gimple_phi phi = gsi.phi ();
       tree access_fn = NULL;
       tree def = PHI_RESULT (phi);
       stmt_vec_info stmt_vinfo = vinfo_for_stmt (phi);
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index b75ac9c..2e19273 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -6076,10 +6076,10 @@ find_assert_locations (void)
     {
       i = loop->latch->index;
       unsigned int j = single_succ_edge (loop->latch)->dest_idx;
-      for (gimple_stmt_iterator gsi = gsi_start_phis (loop->header);
+      for (gimple_phi_iterator gsi = gsi_start_phis (loop->header);
 	   !gsi_end_p (gsi); gsi_next (&gsi))
 	{
-	  gimple phi = gsi_stmt (gsi);
+	  gimple_phi phi = gsi.phi ();
 	  if (virtual_operand_p (gimple_phi_result (phi)))
 	    continue;
 	  tree arg = gimple_phi_arg_def (phi, j);
diff --git a/gcc/value-prof.c b/gcc/value-prof.c
index 37710ca..0312295 100644
--- a/gcc/value-prof.c
+++ b/gcc/value-prof.c
@@ -1378,7 +1378,7 @@ gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call,
   int lp_nr, dflags;
   edge e_eh, e;
   edge_iterator ei;
-  gimple_stmt_iterator psi;
+  gimple_phi_iterator psi;
 
   cond_bb = gimple_bb (icall_stmt);
   gsi = gsi_for_stmt (icall_stmt);
@@ -1491,7 +1491,7 @@ gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call,
 	for (psi = gsi_start_phis (e_eh->dest);
 	     !gsi_end_p (psi); gsi_next (&psi))
 	  {
-	    gimple phi = gsi_stmt (psi);
+	    gimple_phi phi = psi.phi ();
 	    SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, e),
 		     PHI_ARG_DEF_FROM_EDGE (phi, e_eh));
 	  }
-- 
1.8.5.3

