This corresponds to: [PATCH 67/89] Make gimple_phi_arg_location require a gimple_phi. https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01182.html from the original 89-patch kit
That earlier patch was approved by Jeff: > OK once prerequisites go in. in https://gcc.gnu.org/ml/gcc-patches/2014-05/msg00848.html gcc/ * gimple.h (gimple_phi_arg_location): Require a gimple_phi. * tree-into-ssa.c (rewrite_update_phi_arguments): Replace a check for code GIMPLE_PHI with a dyn_cast and a new local. * tree-ssa-ter.c (ter_is_replaceable_p): Likewise. * tree-ssa-live.c (remove_unused_locals): Replace a gimple_stmt_iterator with a gimple_phi_iterator, using it to make local "phi" be a gimple_phi. * tree-ssa-phiopt.c (tree_ssa_phiopt_worker): Likewise. * tree-ssa-phiopt.c (conditional_replacement): Require a gimple_phi. (single_non_singleton_phi_for_edges): Return a gimple_phi; update local to be a gimple_phi, adding checked casts since we're working on a sequence of gimple_phi. (conditional_replacement): Require a gimple_phi. * tree-ssa-threadupdate.c (get_value_locus_in_path): Strengthen type of local "def_phi" to gimple_phi by replacing a check of the code for GIMPLE_PHI with a dyn_cast<gimple_phi>. --- gcc/ChangeLog.gimple-classes | 25 +++++++++++++++++++++++++ gcc/gimple.h | 6 +++--- gcc/tree-into-ssa.c | 7 ++++--- gcc/tree-ssa-live.c | 6 ++++-- gcc/tree-ssa-phiopt.c | 17 +++++++++-------- gcc/tree-ssa-ter.c | 4 ++-- gcc/tree-ssa-threadupdate.c | 6 +++--- 7 files changed, 50 insertions(+), 21 deletions(-) diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes index 5a271ca..f2f9a05 100644 --- a/gcc/ChangeLog.gimple-classes +++ b/gcc/ChangeLog.gimple-classes @@ -1,5 +1,30 @@ 2014-10-24 David Malcolm <dmalc...@redhat.com> + Make gimple_phi_arg_location require a gimple_phi. + + * gimple.h (gimple_phi_arg_location): Require a gimple_phi. + + * tree-into-ssa.c (rewrite_update_phi_arguments): Replace a check + for code GIMPLE_PHI with a dyn_cast and a new local. + * tree-ssa-ter.c (ter_is_replaceable_p): Likewise. + + * tree-ssa-live.c (remove_unused_locals): Replace a + gimple_stmt_iterator with a gimple_phi_iterator, using it to make + local "phi" be a gimple_phi. + * tree-ssa-phiopt.c (tree_ssa_phiopt_worker): Likewise. + + * tree-ssa-phiopt.c (conditional_replacement): Require a gimple_phi. + (single_non_singleton_phi_for_edges): Return a gimple_phi; update + local to be a gimple_phi, adding checked casts since we're working + on a sequence of gimple_phi. + (conditional_replacement): Require a gimple_phi. + + * tree-ssa-threadupdate.c (get_value_locus_in_path): Strengthen + type of local "def_phi" to gimple_phi by replacing a check of the + code for GIMPLE_PHI with a dyn_cast<gimple_phi>. + +2014-10-24 David Malcolm <dmalc...@redhat.com> + Make gimple_phi_arg_location_from_edge require a gimple_phi * gimple.h (gimple_phi_arg_location_from_edge): Require a diff --git a/gcc/gimple.h b/gcc/gimple.h index 0c8db97..688c375 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -3972,12 +3972,12 @@ gimple_phi_arg_edge (gimple_phi phi, size_t i) return EDGE_PRED (gimple_bb (phi), i); } -/* Return the source location of gimple argument I of phi node GS. */ +/* Return the source location of gimple argument I of phi node PHI. */ static inline source_location -gimple_phi_arg_location (gimple gs, size_t i) +gimple_phi_arg_location (gimple_phi phi, size_t i) { - return gimple_phi_arg (gs, i)->locus; + return gimple_phi_arg (phi, i)->locus; } /* Return the source location of the argument on edge E of phi node PHI. */ diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c index 9291105..b4e0e4b 100644 --- a/gcc/tree-into-ssa.c +++ b/gcc/tree-into-ssa.c @@ -2045,12 +2045,13 @@ rewrite_update_phi_arguments (basic_block bb) else { gimple stmt = SSA_NAME_DEF_STMT (reaching_def); + gimple_phi other_phi = dyn_cast <gimple_phi> (stmt); /* Single element PHI nodes behave like copies, so get the location from the phi argument. */ - if (gimple_code (stmt) == GIMPLE_PHI - && gimple_phi_num_args (stmt) == 1) - locus = gimple_phi_arg_location (stmt, 0); + if (other_phi + && gimple_phi_num_args (other_phi) == 1) + locus = gimple_phi_arg_location (other_phi, 0); else locus = gimple_location (stmt); } diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c index 5157ff0..00fcbc3 100644 --- a/gcc/tree-ssa-live.c +++ b/gcc/tree-ssa-live.c @@ -819,12 +819,14 @@ remove_unused_locals (void) mark_all_vars_used (gimple_op_ptr (gsi_stmt (gsi), i)); } - for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + for (gimple_phi_iterator gpi = gsi_start_phis (bb); + !gsi_end_p (gpi); + gsi_next (&gpi)) { use_operand_p arg_p; ssa_op_iter i; tree def; - gimple phi = gsi_stmt (gsi); + gimple_phi phi = gpi.phi (); if (virtual_operand_p (gimple_phi_result (phi))) continue; diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index dfeefbe..df15a45 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -62,7 +62,7 @@ along with GCC; see the file COPYING3. If not see static unsigned int tree_ssa_phiopt_worker (bool, bool); static bool conditional_replacement (basic_block, basic_block, - edge, edge, gimple, tree, tree); + edge, edge, gimple_phi, tree, tree); static int value_replacement (basic_block, basic_block, edge, edge, gimple, tree, tree); static bool minmax_replacement (basic_block, basic_block, @@ -138,16 +138,16 @@ tree_ssa_cs_elim (void) /* Return the singleton PHI in the SEQ of PHIs for edges E0 and E1. */ -static gimple +static gimple_phi single_non_singleton_phi_for_edges (gimple_seq seq, edge e0, edge e1) { gimple_stmt_iterator i; - gimple phi = NULL; + gimple_phi phi = NULL; if (gimple_seq_singleton_p (seq)) - return gsi_stmt (gsi_start (seq)); + return as_a <gimple_phi> (gsi_stmt (gsi_start (seq))); for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i)) { - gimple p = gsi_stmt (i); + gimple_phi p = as_a <gimple_phi> (gsi_stmt (i)); /* If the PHI arguments are equal then we can skip this PHI. */ if (operand_equal_for_phi_arg_p (gimple_phi_arg_def (p, e0->dest_idx), gimple_phi_arg_def (p, e1->dest_idx))) @@ -211,7 +211,8 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads) for (i = 0; i < n; i++) { - gimple cond_stmt, phi; + gimple cond_stmt; + gimple_phi phi; basic_block bb1, bb2; edge e1, e2; tree arg0, arg1; @@ -322,7 +323,7 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads) so try that first. */ for (gsi = gsi_start (phis); !gsi_end_p (gsi); gsi_next (&gsi)) { - phi = gsi_stmt (gsi); + phi = as_a <gimple_phi> (gsi_stmt (gsi)); arg0 = gimple_phi_arg_def (phi, e1->dest_idx); arg1 = gimple_phi_arg_def (phi, e2->dest_idx); if (value_replacement (bb, bb1, e1, e2, phi, arg0, arg1) == 2) @@ -433,7 +434,7 @@ replace_phi_edge_with_variable (basic_block cond_block, static bool conditional_replacement (basic_block cond_bb, basic_block middle_bb, - edge e0, edge e1, gimple phi, + edge e0, edge e1, gimple_phi phi, tree arg0, tree arg1) { tree result; diff --git a/gcc/tree-ssa-ter.c b/gcc/tree-ssa-ter.c index 78bedfc..d8ab499 100644 --- a/gcc/tree-ssa-ter.c +++ b/gcc/tree-ssa-ter.c @@ -428,8 +428,8 @@ ter_is_replaceable_p (gimple stmt) block1 = LOCATION_BLOCK (locus1); locus1 = LOCATION_LOCUS (locus1); - if (gimple_code (use_stmt) == GIMPLE_PHI) - locus2 = gimple_phi_arg_location (use_stmt, + if (gimple_phi phi = dyn_cast <gimple_phi> (use_stmt)) + locus2 = gimple_phi_arg_location (phi, PHI_ARG_INDEX_FROM_USE (use_p)); else locus2 = gimple_location (use_stmt); diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c index 24920ca..883574c 100644 --- a/gcc/tree-ssa-threadupdate.c +++ b/gcc/tree-ssa-threadupdate.c @@ -419,14 +419,14 @@ get_value_locus_in_path (tree def, vec<jump_thread_edge *> *path, basic_block bb, int idx, source_location *locus) { tree arg; - gimple def_phi; + gimple_phi def_phi; basic_block def_bb; if (path == NULL || idx == 0) return def; - def_phi = SSA_NAME_DEF_STMT (def); - if (gimple_code (def_phi) != GIMPLE_PHI) + def_phi = dyn_cast <gimple_phi> (SSA_NAME_DEF_STMT (def)); + if (!def_phi) return def; def_bb = gimple_bb (def_phi); -- 1.8.5.3