@@ -1,5 +1,32 @@
2014-10-24 David Malcolm <dmalcolm@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 <dmalcolm@redhat.com>
+
Concretize gimple_cond_make_{false|true}
* gimple.h (gimple_cond_make_false): Require a gimple_cond.
@@ -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);
}
@@ -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 (
@@ -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:
@@ -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);
@@ -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);
@@ -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++;
}
@@ -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
@@ -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 ();
}
@@ -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);
@@ -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