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/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-propagate.c | 8 ++++---- gcc/tree-ssa-threadedge.c | 2 +- 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/gcc/gimple.h b/gcc/gimple.h index ed99d02..bdb2162 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -4340,9 +4340,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); } @@ -4350,9 +4349,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 68e7e9d..5008fff 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 (stmt->as_a_gimple_switch ()), + &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 914cc71..1e4ceb0 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 (stmt->as_a_gimple_switch ()); break; default: diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index cc8c78b..c79d981 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -1128,7 +1128,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 (stmt->as_a_gimple_switch ())); } case GIMPLE_ASSIGN: @@ -1650,7 +1650,7 @@ evaluate_stmt (gimple stmt) simplified = gimple_assign_rhs1 (stmt); } else if (code == GIMPLE_SWITCH) - simplified = gimple_switch_index (stmt); + simplified = gimple_switch_index (stmt->as_a_gimple_switch ()); 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 4ecab6a..8fc8e1a 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -342,11 +342,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 = stmt->dyn_cast_gimple_switch ()) { - 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) { @@ -1794,7 +1794,7 @@ record_edge_info (basic_block bb) if (gimple_code (stmt) == GIMPLE_SWITCH) { gimple_switch switch_stmt = stmt->as_a_gimple_switch (); - tree index = gimple_switch_index (stmt); + tree index = gimple_switch_index (switch_stmt); if (TREE_CODE (index) == SSA_NAME) { @@ -2079,8 +2079,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 = stmt->dyn_cast_gimple_switch ()) + 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 @@ -2373,9 +2373,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 = stmt->dyn_cast_gimple_switch ()) /* 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); @@ -2497,8 +2497,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 = stmt->dyn_cast_gimple_switch ()) + val = gimple_switch_index (swtch_stmt); if (val && TREE_CODE (val) == INTEGER_CST && find_taken_edge (bb, val)) cfg_altered = true; @@ -2856,7 +2856,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 (use_stmt->as_a_gimple_switch ()); else val = gimple_goto_dest (use_stmt); diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c index 52f8e85..cbef59b 100644 --- a/gcc/tree-ssa-loop-ivcanon.c +++ b/gcc/tree-ssa-loop-ivcanon.c @@ -305,7 +305,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 ( + stmt->as_a_gimple_switch ()), + stmt, loop))) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, " Constant conditional.\n"); @@ -357,7 +359,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 ( + stmt->as_a_gimple_switch ()), + stmt, loop))) && (!exit || bb != exit->src)) size->num_branches_on_hot_path++; } diff --git a/gcc/tree-ssa-propagate.c b/gcc/tree-ssa-propagate.c index ad7f008..dd8fad4 100644 --- a/gcc/tree-ssa-propagate.c +++ b/gcc/tree-ssa-propagate.c @@ -1297,8 +1297,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 = dest->dyn_cast_gimple_switch ()) + 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 @@ -1449,8 +1449,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 = stmt->dyn_cast_gimple_switch ()) + propagate_tree_value (gimple_switch_index_ptr (swtch_stmt), val); else gcc_unreachable (); } diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c index 03c6b4a..4edd9e3 100644 --- a/gcc/tree-ssa-threadedge.c +++ b/gcc/tree-ssa-threadedge.c @@ -624,7 +624,7 @@ simplify_control_stmt_condition (edge e, } if (code == GIMPLE_SWITCH) - cond = gimple_switch_index (stmt); + cond = gimple_switch_index (stmt->as_a_gimple_switch ()); else if (code == GIMPLE_GOTO) cond = gimple_goto_dest (stmt); else -- 1.8.5.3