From 74bb6f309e731887aa273603453a025b888f94cd Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 19 Dec 2013 15:58:15 -0500 Subject: [PATCH] Concretize three gimple_return_ accessors This corresponds to: [PATCH 68/89] Concretize three gimple_return_ accessors https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01233.html from the original 89-patch kit That earlier patch was approved by Jeff: > Fine once prereqs go in. in https://gcc.gnu.org/ml/gcc-patches/2014-05/msg00865.html gcc/ * gimple.h (gimple_return_retval_ptr): Require a const_gimple_return rather than a const_gimple. (gimple_return_retval): Likewise. (gimple_return_set_retval): Require a gimple_return. * cfgexpand.c (expand_gimple_stmt_1): Add a checked cast to gimple_return. (expand_gimple_basic_block): Likewise. * tree-complex.c (expand_complex_move): Likewise. (expand_complex_comparison): Likewise. * tree-inline.c (remap_gimple_stmt): Likewise. * tree-sra.c (scan_function): Likewise. (sra_modify_function_body): Likewise. (ipa_sra_modify_function_body): Likewise. * tree-ssa-structalias.c (find_func_aliases): Likewise. * gimple-ssa-isolate-paths.c (isolate_path): Strengthen local "ret" from gimple to gimple_return. (find_implicit_erroneous_behaviour): Replace a check for code GIMPLE_RETURN with a dyn_cast and a new local. (find_explicit_erroneous_behaviour): Likewise. * gimple-walk.c (walk_stmt_load_store_addr_ops): Likewise. * gimple.c (infer_nonnull_range): Likewise. * ipa-split.c (find_return_bb): Likewise. (find_retval): Likewise. (split_function): Likewise. * omp-low.c (ipa_simd_modify_function_body): Likewise. * tree-cfg.c (pass_warn_function_return::execute): Likewise. * tree-nrv.c (tree_nrv): Likewise. * tree-ssa-alias.c (ref_maybe_used_by_stmt_p): Likewise. * tree-ssa-dce.c (propagate_necessity): Likewise. * tree-ssa-structalias.c (find_func_clobbers): Likewise. * tree-tailcall.c (find_tail_calls): Likewise. * predict.c (apply_return_prediction): Rework the search for return_stmt so that the latter can have type gimple_return. --- gcc/ChangeLog.gimple-classes | 41 +++++++++++++++++++++++++++++++++++++++++ gcc/cfgexpand.c | 4 ++-- gcc/gimple-ssa-isolate-paths.c | 16 ++++++++++------ gcc/gimple-walk.c | 4 ++-- gcc/gimple.c | 14 +++++++------- gcc/gimple.h | 9 +++------ gcc/ipa-split.c | 13 +++++++------ gcc/omp-low.c | 4 ++-- gcc/predict.c | 13 ++++++++----- gcc/tree-cfg.c | 5 +++-- gcc/tree-complex.c | 9 ++++++--- gcc/tree-inline.c | 2 +- gcc/tree-nrv.c | 4 ++-- gcc/tree-sra.c | 6 +++--- gcc/tree-ssa-alias.c | 4 ++-- gcc/tree-ssa-dce.c | 4 ++-- gcc/tree-ssa-structalias.c | 12 +++++++----- gcc/tree-tailcall.c | 2 +- gcc/ubsan.c | 2 +- 19 files changed, 110 insertions(+), 58 deletions(-) diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes index f2f9a05205b..c024a2bc445 100644 --- a/gcc/ChangeLog.gimple-classes +++ b/gcc/ChangeLog.gimple-classes @@ -1,5 +1,46 @@ 2014-10-24 David Malcolm + Concretize three gimple_return_ accessors + + * gimple.h (gimple_return_retval_ptr): Require a const_gimple_return + rather than a const_gimple. + (gimple_return_retval): Likewise. + (gimple_return_set_retval): Require a gimple_return. + + * cfgexpand.c (expand_gimple_stmt_1): Add a checked cast to + gimple_return. + (expand_gimple_basic_block): Likewise. + * tree-complex.c (expand_complex_move): Likewise. + (expand_complex_comparison): Likewise. + * tree-inline.c (remap_gimple_stmt): Likewise. + * tree-sra.c (scan_function): Likewise. + (sra_modify_function_body): Likewise. + (ipa_sra_modify_function_body): Likewise. + * tree-ssa-structalias.c (find_func_aliases): Likewise. + + * gimple-ssa-isolate-paths.c (isolate_path): Strengthen local + "ret" from gimple to gimple_return. + (find_implicit_erroneous_behaviour): Replace a check for code + GIMPLE_RETURN with a dyn_cast and a new local. + (find_explicit_erroneous_behaviour): Likewise. + * gimple-walk.c (walk_stmt_load_store_addr_ops): Likewise. + * gimple.c (infer_nonnull_range): Likewise. + * ipa-split.c (find_return_bb): Likewise. + (find_retval): Likewise. + (split_function): Likewise. + * omp-low.c (ipa_simd_modify_function_body): Likewise. + * tree-cfg.c (pass_warn_function_return::execute): Likewise. + * tree-nrv.c (tree_nrv): Likewise. + * tree-ssa-alias.c (ref_maybe_used_by_stmt_p): Likewise. + * tree-ssa-dce.c (propagate_necessity): Likewise. + * tree-ssa-structalias.c (find_func_clobbers): Likewise. + * tree-tailcall.c (find_tail_calls): Likewise. + + * predict.c (apply_return_prediction): Rework the search for + return_stmt so that the latter can have type gimple_return. + +2014-10-24 David Malcolm + Make gimple_phi_arg_location require a gimple_phi. * gimple.h (gimple_phi_arg_location): Require a gimple_phi. diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 4287232873b..0715b837d1a 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -3220,7 +3220,7 @@ expand_gimple_stmt_1 (gimple stmt) break; case GIMPLE_RETURN: - op0 = gimple_return_retval (stmt); + op0 = gimple_return_retval (as_a (stmt)); if (op0 && op0 != error_mark_node) { @@ -4915,7 +4915,7 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls) if (!gsi_end_p (gsi) && gimple_code (gsi_stmt (gsi)) == GIMPLE_RETURN) { - gimple ret_stmt = gsi_stmt (gsi); + gimple_return ret_stmt = as_a (gsi_stmt (gsi)); gcc_assert (single_succ_p (bb)); gcc_assert (single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun)); diff --git a/gcc/gimple-ssa-isolate-paths.c b/gcc/gimple-ssa-isolate-paths.c index 528b3eb41cd..49c9086a631 100644 --- a/gcc/gimple-ssa-isolate-paths.c +++ b/gcc/gimple-ssa-isolate-paths.c @@ -205,7 +205,7 @@ isolate_path (basic_block bb, basic_block duplicate, { if (ret_zero) { - gimple ret = gsi_stmt (si2); + gimple_return ret = as_a (gsi_stmt (si2)); tree zero = build_zero_cst (TREE_TYPE (gimple_return_retval (ret))); gimple_return_set_retval (ret, zero); update_stmt (ret); @@ -285,8 +285,12 @@ find_implicit_erroneous_behaviour (void) { FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs) { - if (gimple_code (use_stmt) != GIMPLE_RETURN - || gimple_return_retval (use_stmt) != lhs) + gimple_return return_stmt = + dyn_cast (use_stmt); + if (!return_stmt) + continue; + + if (gimple_return_retval (return_stmt) != lhs) continue; if (warning_at (gimple_location (use_stmt), @@ -399,9 +403,9 @@ find_explicit_erroneous_behaviour (void) /* Detect returning the address of a local variable. This only becomes undefined behavior if the result is used, so we do not insert a trap and only return NULL instead. */ - if (gimple_code (stmt) == GIMPLE_RETURN) + if (gimple_return return_stmt = dyn_cast (stmt)) { - tree val = gimple_return_retval (stmt); + tree val = gimple_return_retval (return_stmt); if (val && TREE_CODE (val) == ADDR_EXPR) { tree valbase = get_base_address (TREE_OPERAND (val, 0)); @@ -425,7 +429,7 @@ find_explicit_erroneous_behaviour (void) OPT_Wreturn_local_addr, msg)) inform (DECL_SOURCE_LOCATION(valbase), "declared here"); tree zero = build_zero_cst (TREE_TYPE (val)); - gimple_return_set_retval (stmt, zero); + gimple_return_set_retval (return_stmt, zero); update_stmt (stmt); } } diff --git a/gcc/gimple-walk.c b/gcc/gimple-walk.c index bbc5963be1c..57aa780d943 100644 --- a/gcc/gimple-walk.c +++ b/gcc/gimple-walk.c @@ -852,9 +852,9 @@ walk_stmt_load_store_addr_ops (gimple stmt, void *data, } } } - else if (gimple_code (stmt) == GIMPLE_RETURN) + else if (gimple_return return_stmt = dyn_cast (stmt)) { - tree op = gimple_return_retval (stmt); + tree op = gimple_return_retval (return_stmt); if (op) { if (visit_addr diff --git a/gcc/gimple.c b/gcc/gimple.c index 0fac6b4569c..a244617a4c4 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -2653,13 +2653,13 @@ infer_nonnull_range (gimple stmt, tree op, bool dereference, bool attribute) /* If this function is marked as returning non-null, then we can infer OP is non-null if it is used in the return statement. */ - if (attribute - && gimple_code (stmt) == GIMPLE_RETURN - && gimple_return_retval (stmt) - && operand_equal_p (gimple_return_retval (stmt), op, 0) - && lookup_attribute ("returns_nonnull", - TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl)))) - return true; + if (attribute) + if (gimple_return return_stmt = dyn_cast (stmt)) + if (gimple_return_retval (return_stmt) + && operand_equal_p (gimple_return_retval (return_stmt), op, 0) + && lookup_attribute ("returns_nonnull", + TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl)))) + return true; return false; } diff --git a/gcc/gimple.h b/gcc/gimple.h index 688c375bb2f..e1afe99a82d 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -5513,18 +5513,16 @@ gimple_transaction_set_subcode (gimple_transaction transaction_stmt, /* Return a pointer to the return value for GIMPLE_RETURN GS. */ static inline tree * -gimple_return_retval_ptr (const_gimple gs) +gimple_return_retval_ptr (const_gimple_return gs) { - GIMPLE_CHECK (gs, GIMPLE_RETURN); return gimple_op_ptr (gs, 0); } /* Return the return value for GIMPLE_RETURN GS. */ static inline tree -gimple_return_retval (const_gimple gs) +gimple_return_retval (const_gimple_return gs) { - GIMPLE_CHECK (gs, GIMPLE_RETURN); return gimple_op (gs, 0); } @@ -5532,9 +5530,8 @@ gimple_return_retval (const_gimple gs) /* Set RETVAL to be the return value for GIMPLE_RETURN GS. */ static inline void -gimple_return_set_retval (gimple gs, tree retval) +gimple_return_set_retval (gimple_return gs, tree retval) { - GIMPLE_CHECK (gs, GIMPLE_RETURN); gimple_set_op (gs, 0, retval); } diff --git a/gcc/ipa-split.c b/gcc/ipa-split.c index 59901dcc07e..e5df578db85 100644 --- a/gcc/ipa-split.c +++ b/gcc/ipa-split.c @@ -710,10 +710,10 @@ find_return_bb (void) || is_gimple_min_invariant (gimple_assign_rhs1 (stmt))) && retval == gimple_assign_lhs (stmt)) ; - else if (gimple_code (stmt) == GIMPLE_RETURN) + else if (gimple_return return_stmt = dyn_cast (stmt)) { found_return = true; - retval = gimple_return_retval (stmt); + retval = gimple_return_retval (return_stmt); } else break; @@ -731,8 +731,8 @@ find_retval (basic_block return_bb) { gimple_stmt_iterator bsi; for (bsi = gsi_start_bb (return_bb); !gsi_end_p (bsi); gsi_next (&bsi)) - if (gimple_code (gsi_stmt (bsi)) == GIMPLE_RETURN) - return gimple_return_retval (gsi_stmt (bsi)); + if (gimple_return return_stmt = dyn_cast (gsi_stmt (bsi))) + return gimple_return_retval (return_stmt); else if (gimple_code (gsi_stmt (bsi)) == GIMPLE_ASSIGN && !gimple_clobber_p (gsi_stmt (bsi))) return gimple_assign_rhs1 (gsi_stmt (bsi)); @@ -1446,9 +1446,10 @@ split_function (struct split_point *split_point) gimple_stmt_iterator bsi; for (bsi = gsi_start_bb (return_bb); !gsi_end_p (bsi); gsi_next (&bsi)) - if (gimple_code (gsi_stmt (bsi)) == GIMPLE_RETURN) + if (gimple_return return_stmt = + dyn_cast (gsi_stmt (bsi))) { - gimple_return_set_retval (gsi_stmt (bsi), retval); + gimple_return_set_retval (return_stmt, retval); break; } else if (gimple_code (gsi_stmt (bsi)) == GIMPLE_ASSIGN diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 6174c3fa653..1e1ee1df3f2 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -11951,9 +11951,9 @@ ipa_simd_modify_function_body (struct cgraph_node *node, wi.info = &info; walk_gimple_op (stmt, ipa_simd_modify_stmt_ops, &wi); - if (gimple_code (stmt) == GIMPLE_RETURN) + if (gimple_return return_stmt = dyn_cast (stmt)) { - tree retval = gimple_return_retval (stmt); + tree retval = gimple_return_retval (return_stmt); if (!retval) { gsi_remove (&gsi, true); diff --git a/gcc/predict.c b/gcc/predict.c index 5e8a0e9ad57..c21cc29fdfa 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -2145,7 +2145,7 @@ return_prediction (tree val, enum prediction *prediction) static void apply_return_prediction (void) { - gimple return_stmt = NULL; + gimple_return return_stmt = NULL; tree return_val; edge e; gimple_phi phi; @@ -2156,10 +2156,13 @@ apply_return_prediction (void) FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) { - return_stmt = last_stmt (e->src); - if (return_stmt - && gimple_code (return_stmt) == GIMPLE_RETURN) - break; + gimple last = last_stmt (e->src); + if (last + && gimple_code (last) == GIMPLE_RETURN) + { + return_stmt = as_a (last); + break; + } } if (!e) return; diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index b0d94eeba49..4aaeb6ddd05 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -8335,8 +8335,9 @@ pass_warn_function_return::execute (function *fun) FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (fun)->preds) { gimple last = last_stmt (e->src); - if (gimple_code (last) == GIMPLE_RETURN - && gimple_return_retval (last) == NULL + gimple_return return_stmt = dyn_cast (last); + if (return_stmt + && gimple_return_retval (return_stmt) == NULL && !gimple_no_warning_p (last)) { location = gimple_location (last); diff --git a/gcc/tree-complex.c b/gcc/tree-complex.c index d2b4f01045f..a7cbcebfd89 100644 --- a/gcc/tree-complex.c +++ b/gcc/tree-complex.c @@ -855,7 +855,7 @@ expand_complex_move (gimple_stmt_iterator *gsi, tree type) stmt = gsi_stmt (*gsi); gcc_assert (gimple_code (stmt) == GIMPLE_RETURN); - gimple_return_set_retval (stmt, lhs); + gimple_return_set_retval (as_a (stmt), lhs); } update_stmt (stmt); @@ -1391,8 +1391,11 @@ expand_complex_comparison (gimple_stmt_iterator *gsi, tree ar, tree ai, switch (gimple_code (stmt)) { case GIMPLE_RETURN: - type = TREE_TYPE (gimple_return_retval (stmt)); - gimple_return_set_retval (stmt, fold_convert (type, cc)); + { + gimple_return return_stmt = as_a (stmt); + type = TREE_TYPE (gimple_return_retval (return_stmt)); + gimple_return_set_retval (return_stmt, fold_convert (type, cc)); + } break; case GIMPLE_ASSIGN: diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 945614aac37..11446d778f3 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1302,7 +1302,7 @@ remap_gimple_stmt (gimple stmt, copy_body_data *id) statement. */ if (gimple_code (stmt) == GIMPLE_RETURN && id->transform_return_to_modify) { - tree retval = gimple_return_retval (stmt); + tree retval = gimple_return_retval (as_a (stmt)); /* If we're returning something, just turn that into an assignment into the equivalent of the original RESULT_DECL. diff --git a/gcc/tree-nrv.c b/gcc/tree-nrv.c index 91a9531ce50..cc16aa2056b 100644 --- a/gcc/tree-nrv.c +++ b/gcc/tree-nrv.c @@ -180,12 +180,12 @@ pass_nrv::execute (function *fun) gimple stmt = gsi_stmt (gsi); tree ret_val; - if (gimple_code (stmt) == GIMPLE_RETURN) + if (gimple_return return_stmt = dyn_cast (stmt)) { /* In a function with an aggregate return value, the gimplifier has changed all non-empty RETURN_EXPRs to return the RESULT_DECL. */ - ret_val = gimple_return_retval (stmt); + ret_val = gimple_return_retval (return_stmt); if (ret_val) gcc_assert (ret_val == result); } diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 9f67f6df3b0..50464f1c7d6 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -1280,7 +1280,7 @@ scan_function (void) switch (gimple_code (stmt)) { case GIMPLE_RETURN: - t = gimple_return_retval (stmt); + t = gimple_return_retval (as_a (stmt)); if (t != NULL_TREE) ret |= build_access_from_expr (t, stmt, false); if (final_bbs) @@ -3389,7 +3389,7 @@ sra_modify_function_body (void) switch (gimple_code (stmt)) { case GIMPLE_RETURN: - t = gimple_return_retval_ptr (stmt); + t = gimple_return_retval_ptr (as_a (stmt)); if (*t != NULL_TREE) modified |= sra_modify_expr (t, &gsi, false); break; @@ -4652,7 +4652,7 @@ ipa_sra_modify_function_body (ipa_parm_adjustment_vec adjustments) switch (gimple_code (stmt)) { case GIMPLE_RETURN: - t = gimple_return_retval_ptr (stmt); + t = gimple_return_retval_ptr (as_a (stmt)); if (*t != NULL_TREE) modified |= ipa_modify_expr (t, true, adjustments); break; diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 611b16f6ac7..07ecbd1cca5 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -1826,9 +1826,9 @@ ref_maybe_used_by_stmt_p (gimple stmt, ao_ref *ref) } else if (is_gimple_call (stmt)) return ref_maybe_used_by_call_p (as_a (stmt), ref); - else if (gimple_code (stmt) == GIMPLE_RETURN) + else if (gimple_return return_stmt = dyn_cast (stmt)) { - tree retval = gimple_return_retval (stmt); + tree retval = gimple_return_retval (return_stmt); if (retval && TREE_CODE (retval) != SSA_NAME && !is_gimple_min_invariant (retval) diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index f8535129cba..aba2d986d8c 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -868,9 +868,9 @@ propagate_necessity (bool aggressive) mark_all_reaching_defs_necessary (stmt); } } - else if (gimple_code (stmt) == GIMPLE_RETURN) + else if (gimple_return return_stmt = dyn_cast (stmt)) { - tree rhs = gimple_return_retval (stmt); + tree rhs = gimple_return_retval (return_stmt); /* A return statement may perform a load. */ if (rhs && TREE_CODE (rhs) != SSA_NAME diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index a1302682339..550bfb4a8d0 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -4732,12 +4732,13 @@ find_func_aliases (struct function *fn, gimple origt) } /* Handle escapes through return. */ else if (gimple_code (t) == GIMPLE_RETURN - && gimple_return_retval (t) != NULL_TREE) + && gimple_return_retval (as_a (t)) != NULL_TREE) { + gimple_return return_stmt = as_a (t); fi = NULL; if (!in_ipa_mode || !(fi = get_vi_for_tree (fn->decl))) - make_escape_constraint (gimple_return_retval (t)); + make_escape_constraint (gimple_return_retval (return_stmt)); else if (in_ipa_mode && fi != NULL) { @@ -4746,7 +4747,7 @@ find_func_aliases (struct function *fn, gimple origt) unsigned i; lhs = get_function_part_constraint (fi, fi_result); - get_constraint_for_rhs (gimple_return_retval (t), &rhsc); + get_constraint_for_rhs (gimple_return_retval (return_stmt), &rhsc); FOR_EACH_VEC_ELT (rhsc, i, rhsp) process_constraint (new_constraint (lhs, *rhsp)); } @@ -4885,10 +4886,11 @@ find_func_clobbers (struct function *fn, gimple origt) /* Account for uses in assigments and returns. */ if (gimple_assign_single_p (t) || (gimple_code (t) == GIMPLE_RETURN - && gimple_return_retval (t) != NULL_TREE)) + && gimple_return_retval (as_a (t)) != NULL_TREE)) { tree rhs = (gimple_assign_single_p (t) - ? gimple_assign_rhs1 (t) : gimple_return_retval (t)); + ? gimple_assign_rhs1 (t) + : gimple_return_retval (as_a (t))); tree tem = rhs; while (handled_component_p (tem)) tem = TREE_OPERAND (tem, 0); diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c index 5a1763c347f..9bf3c42693f 100644 --- a/gcc/tree-tailcall.c +++ b/gcc/tree-tailcall.c @@ -586,7 +586,7 @@ find_tail_calls (basic_block bb, struct tailcall **ret) } /* See if this is a tail call we can handle. */ - ret_var = gimple_return_retval (stmt); + ret_var = gimple_return_retval (as_a (stmt)); /* We may proceed if there either is no return value, or the return value is identical to the call's return. */ diff --git a/gcc/ubsan.c b/gcc/ubsan.c index bc4f501f0af..78320d5513c 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -1364,7 +1364,7 @@ instrument_nonnull_arg (gimple_stmt_iterator *gsi) static void instrument_nonnull_return (gimple_stmt_iterator *gsi) { - gimple stmt = gsi_stmt (*gsi); + gimple_return stmt = as_a (gsi_stmt (*gsi)); location_t loc[2]; tree arg = gimple_return_retval (stmt); /* infer_nonnull_range needs flag_delete_null_pointer_checks set, -- 2.11.4.GIT