This corresponds to: [PATCH 72/89] Concretize gimple_switch_index and gimple_switch_index_ptr https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01185.html from the original 89-patch kit
That earlier patch was approved by Jeff: > OK once prereqs go in and will obviously need updating for const > changes as well. in https://gcc.gnu.org/ml/gcc-patches/2014-05/msg00860.html gcc/ * gimple.h (gimple_switch_index): Require a const_gimple_switch rather than a plain const_gimple. (gimple_switch_index_ptr): Likewise. * gimplify-me.c (gimple_regimplify_operands): Add checked cast to gimple_switch within "case GIMPLE_SWITCH". * tree-cfgcleanup.c (cleanup_control_expr_graph): Likewise. * tree-ssa-ccp.c (ccp_fold): Likewise. * tree-ssa-dom.c (optimize_stmt): Likewise. * tree-ssa-ccp.c (evaluate_stmt): Add checked cast to gimple_switch within region guarded by check for GIMPLE_SWITCH. * tree-ssa-dom.c (record_edge_info): Likewise. (eliminate_redundant_computations): Likewise. * tree-ssa-loop-ivcanon.c (tree_estimate_loop_size): Likewise. * tree-ssa-threadedge.c (simplify_control_stmt_condition): Likewise. * tree-ssa-dom.c (initialize_hash_element): Replace check for code GIMPLE_SWITCH with a dyn_cast<gimple_switch>. (propagate_rhs_into_lhs): Likewise. * tree-ssa-propagate.c (may_propagate_copy_into_stmt): Likewise. (propagate_tree_value_into_stmt): Likewise. --- gcc/ChangeLog.gimple-classes | 27 +++++++++++++++++++++++++++ gcc/gimple.h | 6 ++---- gcc/gimplify-me.c | 4 ++-- gcc/tree-cfgcleanup.c | 2 +- gcc/tree-ssa-ccp.c | 4 ++-- gcc/tree-ssa-dom.c | 22 +++++++++++----------- gcc/tree-ssa-loop-ivcanon.c | 8 ++++++-- gcc/tree-ssa-pre.c | 4 +++- gcc/tree-ssa-propagate.c | 8 ++++---- gcc/tree-ssa-sccvn.c | 2 +- gcc/tree-ssa-threadedge.c | 2 +- 11 files changed, 60 insertions(+), 29 deletions(-) diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes index 7b03dad..aa83c24 100644 --- a/gcc/ChangeLog.gimple-classes +++ b/gcc/ChangeLog.gimple-classes @@ -1,5 +1,32 @@ 2014-10-24 David Malcolm <dmalc...@redhat.com> + Concretize gimple_switch_index and gimple_switch_index_ptr + + * gimple.h (gimple_switch_index): Require a const_gimple_switch rather + than a plain const_gimple. + (gimple_switch_index_ptr): Likewise. + + * gimplify-me.c (gimple_regimplify_operands): Add checked cast to + gimple_switch within "case GIMPLE_SWITCH". + * tree-cfgcleanup.c (cleanup_control_expr_graph): Likewise. + * tree-ssa-ccp.c (ccp_fold): Likewise. + * tree-ssa-dom.c (optimize_stmt): Likewise. + + * tree-ssa-ccp.c (evaluate_stmt): Add checked cast to + gimple_switch within region guarded by check for GIMPLE_SWITCH. + * tree-ssa-dom.c (record_edge_info): Likewise. + (eliminate_redundant_computations): Likewise. + * tree-ssa-loop-ivcanon.c (tree_estimate_loop_size): Likewise. + * tree-ssa-threadedge.c (simplify_control_stmt_condition): Likewise. + + * tree-ssa-dom.c (initialize_hash_element): Replace check for + code GIMPLE_SWITCH with a dyn_cast<gimple_switch>. + (propagate_rhs_into_lhs): Likewise. + * tree-ssa-propagate.c (may_propagate_copy_into_stmt): Likewise. + (propagate_tree_value_into_stmt): Likewise. + +2014-10-24 David Malcolm <dmalc...@redhat.com> + Concretize gimple_cond_make_{false|true} * gimple.h (gimple_cond_make_false): Require a gimple_cond. diff --git a/gcc/gimple.h b/gcc/gimple.h index de1ad22..dc080de 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -4062,9 +4062,8 @@ gimple_switch_set_num_labels (gimple_switch g, unsigned nlabels) /* Return the index variable used by the switch statement GS. */ static inline tree -gimple_switch_index (const_gimple gs) +gimple_switch_index (const_gimple_switch gs) { - GIMPLE_CHECK (gs, GIMPLE_SWITCH); return gimple_op (gs, 0); } @@ -4072,9 +4071,8 @@ gimple_switch_index (const_gimple gs) /* Return a pointer to the index variable for the switch statement GS. */ static inline tree * -gimple_switch_index_ptr (const_gimple gs) +gimple_switch_index_ptr (const_gimple_switch gs) { - GIMPLE_CHECK (gs, GIMPLE_SWITCH); return gimple_op_ptr (gs, 0); } diff --git a/gcc/gimplify-me.c b/gcc/gimplify-me.c index 67d71fc..5ecd169 100644 --- a/gcc/gimplify-me.c +++ b/gcc/gimplify-me.c @@ -174,8 +174,8 @@ gimple_regimplify_operands (gimple stmt, gimple_stmt_iterator *gsi_p) is_gimple_val, fb_rvalue); break; case GIMPLE_SWITCH: - gimplify_expr (gimple_switch_index_ptr (stmt), &pre, NULL, - is_gimple_val, fb_rvalue); + gimplify_expr (gimple_switch_index_ptr (as_a <gimple_switch> (stmt)), + &pre, NULL, is_gimple_val, fb_rvalue); break; case GIMPLE_OMP_ATOMIC_LOAD: gimplify_expr (gimple_omp_atomic_load_rhs_ptr ( diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c index 7ec9145..da96036 100644 --- a/gcc/tree-cfgcleanup.c +++ b/gcc/tree-cfgcleanup.c @@ -113,7 +113,7 @@ cleanup_control_expr_graph (basic_block bb, gimple_stmt_iterator gsi) break; case GIMPLE_SWITCH: - val = gimple_switch_index (stmt); + val = gimple_switch_index (as_a <gimple_switch> (stmt)); break; default: diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 9be5b73..33fa392 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -1143,7 +1143,7 @@ ccp_fold (gimple stmt) case GIMPLE_SWITCH: { /* Return the constant switch index. */ - return valueize_op (gimple_switch_index (stmt)); + return valueize_op (gimple_switch_index (as_a <gimple_switch> (stmt))); } case GIMPLE_ASSIGN: @@ -1692,7 +1692,7 @@ evaluate_stmt (gimple stmt) simplified = gimple_assign_rhs1 (stmt); } else if (code == GIMPLE_SWITCH) - simplified = gimple_switch_index (stmt); + simplified = gimple_switch_index (as_a <gimple_switch> (stmt)); else /* These cannot satisfy is_gimple_min_invariant without folding. */ gcc_assert (code == GIMPLE_CALL || code == GIMPLE_COND); diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 26240eb..47e45da 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -346,11 +346,11 @@ initialize_hash_element (gimple stmt, tree lhs, for (i = 0; i < nargs; i++) expr->ops.call.args[i] = gimple_call_arg (stmt, i); } - else if (code == GIMPLE_SWITCH) + else if (gimple_switch swtch_stmt = dyn_cast <gimple_switch> (stmt)) { - expr->type = TREE_TYPE (gimple_switch_index (stmt)); + expr->type = TREE_TYPE (gimple_switch_index (swtch_stmt)); expr->kind = EXPR_SINGLE; - expr->ops.single.rhs = gimple_switch_index (stmt); + expr->ops.single.rhs = gimple_switch_index (swtch_stmt); } else if (code == GIMPLE_GOTO) { @@ -1796,7 +1796,7 @@ record_edge_info (basic_block bb) if (gimple_code (stmt) == GIMPLE_SWITCH) { gimple_switch switch_stmt = as_a <gimple_switch> (stmt); - tree index = gimple_switch_index (stmt); + tree index = gimple_switch_index (switch_stmt); if (TREE_CODE (index) == SSA_NAME) { @@ -2081,8 +2081,8 @@ eliminate_redundant_computations (gimple_stmt_iterator* gsi) expr_type = TREE_TYPE (gimple_call_lhs (stmt)); assigns_var_p = true; } - else if (gimple_code (stmt) == GIMPLE_SWITCH) - expr_type = TREE_TYPE (gimple_switch_index (stmt)); + else if (gimple_switch swtch_stmt = dyn_cast <gimple_switch> (stmt)) + expr_type = TREE_TYPE (gimple_switch_index (swtch_stmt)); else if (gimple_code (stmt) == GIMPLE_PHI) /* We can't propagate into a phi, so the logic below doesn't apply. Instead record an equivalence between the cached LHS and the @@ -2359,9 +2359,9 @@ optimize_stmt (basic_block bb, gimple_stmt_iterator si) rhs = gimple_assign_rhs1 (stmt); else if (gimple_code (stmt) == GIMPLE_GOTO) rhs = gimple_goto_dest (stmt); - else if (gimple_code (stmt) == GIMPLE_SWITCH) + else if (gimple_switch swtch_stmt = dyn_cast <gimple_switch> (stmt)) /* This should never be an ADDR_EXPR. */ - rhs = gimple_switch_index (stmt); + rhs = gimple_switch_index (swtch_stmt); if (rhs && TREE_CODE (rhs) == ADDR_EXPR) recompute_tree_invariant_for_addr_expr (rhs); @@ -2483,8 +2483,8 @@ optimize_stmt (basic_block bb, gimple_stmt_iterator si) val = fold_binary_loc (gimple_location (stmt), gimple_cond_code (stmt), boolean_type_node, gimple_cond_lhs (stmt), gimple_cond_rhs (stmt)); - else if (gimple_code (stmt) == GIMPLE_SWITCH) - val = gimple_switch_index (stmt); + else if (gimple_switch swtch_stmt = dyn_cast <gimple_switch> (stmt)) + val = gimple_switch_index (swtch_stmt); if (val && TREE_CODE (val) == INTEGER_CST && find_taken_edge (bb, val)) cfg_altered = true; @@ -2836,7 +2836,7 @@ propagate_rhs_into_lhs (gimple stmt, tree lhs, tree rhs, bitmap interesting_name gimple_cond_lhs (use_stmt), gimple_cond_rhs (use_stmt)); else if (gimple_code (use_stmt) == GIMPLE_SWITCH) - val = gimple_switch_index (use_stmt); + val = gimple_switch_index (as_a <gimple_switch> (use_stmt)); else val = gimple_goto_dest (use_stmt); diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c index b70f118..6715caa 100644 --- a/gcc/tree-ssa-loop-ivcanon.c +++ b/gcc/tree-ssa-loop-ivcanon.c @@ -306,7 +306,9 @@ tree_estimate_loop_size (struct loop *loop, edge exit, edge edge_to_cancel, stru && constant_after_peeling (gimple_cond_lhs (stmt), stmt, loop) && constant_after_peeling (gimple_cond_rhs (stmt), stmt, loop)) || (gimple_code (stmt) == GIMPLE_SWITCH - && constant_after_peeling (gimple_switch_index (stmt), stmt, loop))) + && constant_after_peeling (gimple_switch_index ( + as_a <gimple_switch> (stmt)), + stmt, loop))) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, " Constant conditional.\n"); @@ -358,7 +360,9 @@ tree_estimate_loop_size (struct loop *loop, edge exit, edge edge_to_cancel, stru && (!constant_after_peeling (gimple_cond_lhs (stmt), stmt, loop) || constant_after_peeling (gimple_cond_rhs (stmt), stmt, loop))) || (gimple_code (stmt) == GIMPLE_SWITCH - && !constant_after_peeling (gimple_switch_index (stmt), stmt, loop))) + && !constant_after_peeling (gimple_switch_index ( + as_a <gimple_switch> (stmt)), + stmt, loop))) && (!exit || bb != exit->src)) size->num_branches_on_hot_path++; } diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index 189363a..c5e1f85 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -4372,7 +4372,9 @@ eliminate_dom_walker::before_dom_children (basic_block b) && (gimple_cond_true_p (as_a <gimple_cond> (stmt)) || gimple_cond_false_p (as_a <gimple_cond> (stmt)))) || (gimple_code (stmt) == GIMPLE_SWITCH - && TREE_CODE (gimple_switch_index (stmt)) == INTEGER_CST)) + && TREE_CODE (gimple_switch_index ( + as_a <gimple_switch> (stmt))) + == INTEGER_CST)) el_todo |= TODO_cleanup_cfg; } /* If we removed EH side-effects from the statement, clean diff --git a/gcc/tree-ssa-propagate.c b/gcc/tree-ssa-propagate.c index 986829f..08482fd 100644 --- a/gcc/tree-ssa-propagate.c +++ b/gcc/tree-ssa-propagate.c @@ -1316,8 +1316,8 @@ may_propagate_copy_into_stmt (gimple dest, tree orig) if (gimple_assign_single_p (dest)) return may_propagate_copy (gimple_assign_rhs1 (dest), orig); - else if (gimple_code (dest) == GIMPLE_SWITCH) - return may_propagate_copy (gimple_switch_index (dest), orig); + else if (gimple_switch dest_swtch = dyn_cast <gimple_switch> (dest)) + return may_propagate_copy (gimple_switch_index (dest_swtch), orig); /* In other cases, the expression is not materialized, so there is no destination to pass to may_propagate_copy. On the other @@ -1463,8 +1463,8 @@ propagate_tree_value_into_stmt (gimple_stmt_iterator *gsi, tree val) res = update_call_from_tree (gsi, expr); gcc_assert (res); } - else if (gimple_code (stmt) == GIMPLE_SWITCH) - propagate_tree_value (gimple_switch_index_ptr (stmt), val); + else if (gimple_switch swtch_stmt = dyn_cast <gimple_switch> (stmt)) + propagate_tree_value (gimple_switch_index_ptr (swtch_stmt), val); else gcc_unreachable (); } diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 4f0ab06..48fb2dd 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -4257,7 +4257,7 @@ cond_dom_walker::before_dom_children (basic_block bb) break; } case GIMPLE_SWITCH: - val = gimple_switch_index (stmt); + val = gimple_switch_index (as_a <gimple_switch> (stmt)); break; case GIMPLE_GOTO: val = gimple_goto_dest (stmt); diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c index 50cc729..4b7bee5 100644 --- a/gcc/tree-ssa-threadedge.c +++ b/gcc/tree-ssa-threadedge.c @@ -619,7 +619,7 @@ simplify_control_stmt_condition (edge e, } if (code == GIMPLE_SWITCH) - cond = gimple_switch_index (stmt); + cond = gimple_switch_index (as_a <gimple_switch> (stmt)); else if (code == GIMPLE_GOTO) cond = gimple_goto_dest (stmt); else -- 1.8.5.3