From: Martin Liska Date: Mon, 27 Aug 2018 12:17:19 +0000 (+0200) Subject: Add new gswitch related functions into tree-cfg.c. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=61ff5d6f4ed5000ee427e054ee803bc8f5535bdd;p=gcc.git Add new gswitch related functions into tree-cfg.c. 2018-08-27 Martin Liska * cfgexpand.c (expand_asm_stmt): Use label_to_block and pass cfun argument explicitly. * gimple-pretty-print.c (dump_gimple_switch): Likewise. * hsa-gen.c (gen_hsa_insns_for_switch_stmt): Use new function gimple_switch_default_bb. (convert_switch_statements): (expand_builtins): * ipa-fnsummary.c (set_switch_stmt_execution_predicate): * stmt.c (label_to_block_fn): Use label_to_block and pass cfun argument explicitly and use gimple_switch_label_bb. (expand_case): Likewise. * tree-cfg.c (lower_phi_internal_fn): Use label_to_block and pass cfun argument explicitly. Likewise. (make_edges_bb): Likewise. (make_cond_expr_edges): Likewise. (get_cases_for_edge): Likewise. (make_gimple_switch_edges): Likewise. (label_to_block_fn): Likewise. (label_to_block): Likewise. (make_goto_expr_edges): Likewise. (make_gimple_asm_edges): Likewise. (main_block_label): Likewise. (group_case_labels_stmt): Likewise. (find_taken_edge_computed_goto): Likewise. (find_taken_edge_switch_expr): Likewise. (gimple_verify_flow_info): Likewise. (gimple_redirect_edge_and_branch): Likewise. (gimple_switch_label_bb): New function. (gimple_switch_default_bb): Likewise. (gimple_switch_edge): Likewise. (gimple_switch_default_edge): Likewise. * tree-cfg.h (label_to_block_fn): Remove and replace ... (label_to_block): ... with this. (gimple_switch_label_bb): New. (gimple_switch_default_bb): Likewise. (gimple_switch_edge): Likewise. (gimple_switch_default_edge): Likewise. * tree-cfgcleanup.c (convert_single_case_switch): Use new gimple functions and pass new argument to label_to_block. (cleanup_control_flow_bb): * tree-eh.c (make_eh_dispatch_edges): Use label_to_block and pass cfun argument explicitly. (make_eh_edges): Likewise. (redirect_eh_dispatch_edge): Likewise. (lower_resx): Likewise. (lower_eh_dispatch): Likewise. (maybe_remove_unreachable_handlers): Likewise. (unsplit_eh): Likewise. (cleanup_empty_eh): Likewise. (verify_eh_edges): Likewise. (verify_eh_dispatch_edge): Likewise. * tree-ssa-dom.c (record_edge_info): Likewise. * tree-ssa-forwprop.c (simplify_gimple_switch_label_vec): Likewise. * tree-ssa-threadedge.c (thread_around_empty_blocks): Likewise. (thread_through_normal_block): Likewise. * tree-ssa-uncprop.c (associate_equivalences_with_edges): Likewise. * tree-ssa-uninit.c (convert_control_dep_chain_into_preds): * tree-switch-conversion.c (switch_conversion::collect): Use new gimple functions. (switch_conversion::check_final_bb): Likewise. (switch_conversion::gather_default_values): Pass new argument to label_to_block. (switch_conversion::build_constructors): Likewise. (switch_decision_tree::compute_cases_per_edge): Use new gimple_switch_edge function. (switch_decision_tree::analyze_switch_statement): Pass new argument to label_to_block. (switch_decision_tree::try_switch_expansion): Use gimple_switch_default_edge. * tree-vrp.c (find_switch_asserts): Pass new argument to label_to_block. * vr-values.c (vr_values::vrp_visit_switch_stmt): Likewise. (vr_values::simplify_switch_using_ranges): Likewise. From-SVN: r263876 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a4f4f565977..40a8735a446 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,79 @@ +2018-08-27 Martin Liska + + * cfgexpand.c (expand_asm_stmt): Use label_to_block and pass + cfun argument explicitly. + * gimple-pretty-print.c (dump_gimple_switch): Likewise. + * hsa-gen.c (gen_hsa_insns_for_switch_stmt): Use new + function gimple_switch_default_bb. + (convert_switch_statements): + (expand_builtins): + * ipa-fnsummary.c (set_switch_stmt_execution_predicate): + * stmt.c (label_to_block_fn): Use label_to_block and pass + cfun argument explicitly and use gimple_switch_label_bb. + (expand_case): Likewise. + * tree-cfg.c (lower_phi_internal_fn): Use label_to_block and pass + cfun argument explicitly. Likewise. + (make_edges_bb): Likewise. + (make_cond_expr_edges): Likewise. + (get_cases_for_edge): Likewise. + (make_gimple_switch_edges): Likewise. + (label_to_block_fn): Likewise. + (label_to_block): Likewise. + (make_goto_expr_edges): Likewise. + (make_gimple_asm_edges): Likewise. + (main_block_label): Likewise. + (group_case_labels_stmt): Likewise. + (find_taken_edge_computed_goto): Likewise. + (find_taken_edge_switch_expr): Likewise. + (gimple_verify_flow_info): Likewise. + (gimple_redirect_edge_and_branch): Likewise. + (gimple_switch_label_bb): New function. + (gimple_switch_default_bb): Likewise. + (gimple_switch_edge): Likewise. + (gimple_switch_default_edge): Likewise. + * tree-cfg.h (label_to_block_fn): Remove and replace ... + (label_to_block): ... with this. + (gimple_switch_label_bb): New. + (gimple_switch_default_bb): Likewise. + (gimple_switch_edge): Likewise. + (gimple_switch_default_edge): Likewise. + * tree-cfgcleanup.c (convert_single_case_switch): Use + new gimple functions and pass new argument to label_to_block. + (cleanup_control_flow_bb): + * tree-eh.c (make_eh_dispatch_edges): Use label_to_block and pass + cfun argument explicitly. + (make_eh_edges): Likewise. + (redirect_eh_dispatch_edge): Likewise. + (lower_resx): Likewise. + (lower_eh_dispatch): Likewise. + (maybe_remove_unreachable_handlers): Likewise. + (unsplit_eh): Likewise. + (cleanup_empty_eh): Likewise. + (verify_eh_edges): Likewise. + (verify_eh_dispatch_edge): Likewise. + * tree-ssa-dom.c (record_edge_info): Likewise. + * tree-ssa-forwprop.c (simplify_gimple_switch_label_vec): Likewise. + * tree-ssa-threadedge.c (thread_around_empty_blocks): Likewise. + (thread_through_normal_block): Likewise. + * tree-ssa-uncprop.c (associate_equivalences_with_edges): Likewise. + * tree-ssa-uninit.c (convert_control_dep_chain_into_preds): + * tree-switch-conversion.c (switch_conversion::collect): Use new + gimple functions. + (switch_conversion::check_final_bb): Likewise. + (switch_conversion::gather_default_values): Pass new argument + to label_to_block. + (switch_conversion::build_constructors): Likewise. + (switch_decision_tree::compute_cases_per_edge): Use new + gimple_switch_edge function. + (switch_decision_tree::analyze_switch_statement): Pass new argument + to label_to_block. + (switch_decision_tree::try_switch_expansion): Use + gimple_switch_default_edge. + * tree-vrp.c (find_switch_asserts): Pass new argument + to label_to_block. + * vr-values.c (vr_values::vrp_visit_switch_stmt): Likewise. + (vr_values::simplify_switch_using_ranges): Likewise. + 2018-08-27 Richard Biener * cfganal.h (rev_post_order_and_mark_dfs_back_seme): Declare. diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 3c5b30b79f8..647764b0e94 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -3239,7 +3239,7 @@ expand_asm_stmt (gasm *stmt) may insert further instructions into the same basic block after asm goto and if we don't do this, insertion of instructions on the fallthru edge might misbehave. See PR58670. */ - if (fallthru_bb && label_to_block_fn (cfun, label) == fallthru_bb) + if (fallthru_bb && label_to_block (cfun, label) == fallthru_bb) { if (fallthru_label == NULL_RTX) fallthru_label = gen_label_rtx (); diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index d3c5ec6f79b..dd63a28761b 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -992,7 +992,7 @@ dump_gimple_switch (pretty_printer *buffer, gswitch *gs, int spc, if (cfun && cfun->cfg) { - basic_block dest = label_to_block (label); + basic_block dest = label_to_block (cfun, label); if (dest) { edge label_edge = find_edge (gimple_bb (gs), dest); diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c index 6595bedac82..416de933a22 100644 --- a/gcc/hsa-gen.c +++ b/gcc/hsa-gen.c @@ -3475,7 +3475,6 @@ gen_hsa_insns_for_switch_stmt (gswitch *s, hsa_bb *hbb) e->flags &= ~EDGE_FALLTHRU; e->flags |= EDGE_TRUE_VALUE; - function *func = DECL_STRUCT_FUNCTION (current_function_decl); tree index_tree = gimple_switch_index (s); tree lowest = get_switch_low (s); tree highest = get_switch_high (s); @@ -3499,9 +3498,7 @@ gen_hsa_insns_for_switch_stmt (gswitch *s, hsa_bb *hbb) hbb->append_insn (new hsa_insn_cbr (cmp_reg)); - tree default_label = gimple_switch_default_label (s); - basic_block default_label_bb = label_to_block_fn (func, - CASE_LABEL (default_label)); + basic_block default_label_bb = gimple_switch_default_bb (cfun, s); if (!gimple_seq_empty_p (phi_nodes (default_label_bb))) { @@ -3536,7 +3533,7 @@ gen_hsa_insns_for_switch_stmt (gswitch *s, hsa_bb *hbb) for (unsigned i = 1; i < labels; i++) { tree label = gimple_switch_label (s, i); - basic_block bb = label_to_block_fn (func, CASE_LABEL (label)); + basic_block bb = label_to_block (cfun, CASE_LABEL (label)); unsigned HOST_WIDE_INT sub_low = tree_to_uhwi (int_const_binop (MINUS_EXPR, CASE_LOW (label), lowest)); @@ -6290,12 +6287,11 @@ LD: hard_work_3 (); static bool convert_switch_statements (void) { - function *func = DECL_STRUCT_FUNCTION (current_function_decl); basic_block bb; bool modified_cfg = false; - FOR_EACH_BB_FN (bb, func) + FOR_EACH_BB_FN (bb, cfun) { gimple_stmt_iterator gsi = gsi_last_bb (bb); if (gsi_end_p (gsi)) @@ -6318,7 +6314,7 @@ convert_switch_statements (void) tree index_type = TREE_TYPE (index); tree default_label = gimple_switch_default_label (s); basic_block default_label_bb - = label_to_block_fn (func, CASE_LABEL (default_label)); + = label_to_block (cfun, CASE_LABEL (default_label)); basic_block cur_bb = bb; auto_vec new_edges; @@ -6330,8 +6326,7 @@ convert_switch_statements (void) should be fixed after we add new collection of edges. */ for (unsigned i = 0; i < labels; i++) { - tree label = gimple_switch_label (s, i); - basic_block label_bb = label_to_block_fn (func, CASE_LABEL (label)); + basic_block label_bb = gimple_switch_label_bb (cfun, s, i); edge e = find_edge (bb, label_bb); edge_counts.safe_push (e->count ()); edge_probabilities.safe_push (e->probability); @@ -6413,8 +6408,7 @@ convert_switch_statements (void) gsi_insert_before (&cond_gsi, c, GSI_SAME_STMT); - basic_block label_bb - = label_to_block_fn (func, CASE_LABEL (label)); + basic_block label_bb = label_to_block (cfun, CASE_LABEL (label)); edge new_edge = make_edge (cur_bb, label_bb, EDGE_TRUE_VALUE); profile_probability prob_sum = sum_slice (edge_probabilities, i, labels, profile_probability::never ()) @@ -6481,10 +6475,9 @@ convert_switch_statements (void) static void expand_builtins () { - function *func = DECL_STRUCT_FUNCTION (current_function_decl); basic_block bb; - FOR_EACH_BB_FN (bb, func) + FOR_EACH_BB_FN (bb, cfun) { for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) diff --git a/gcc/ipa-fnsummary.c b/gcc/ipa-fnsummary.c index a8fc2c2df9a..d8311d25ab2 100644 --- a/gcc/ipa-fnsummary.c +++ b/gcc/ipa-fnsummary.c @@ -1291,7 +1291,7 @@ set_switch_stmt_execution_predicate (struct ipa_func_body_info *fbi, tree min, max; predicate p; - e = find_edge (bb, label_to_block (CASE_LABEL (cl))); + e = gimple_switch_edge (cfun, last, case_idx); min = CASE_LOW (cl); max = CASE_HIGH (cl); diff --git a/gcc/stmt.c b/gcc/stmt.c index b8df1818137..07355984de1 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -81,8 +81,6 @@ struct simple_case_node /* Label to jump to when node matches. */ tree m_code_label; }; - -extern basic_block label_to_block_fn (struct function *, tree); static bool check_unique_operand_names (tree, tree, tree); static char *resolve_operand_name_1 (char *, tree, tree, tree); @@ -907,7 +905,7 @@ expand_case (gswitch *stmt) /* Find the default case target label. */ tree default_lab = CASE_LABEL (gimple_switch_default_label (stmt)); default_label = jump_target_rtx (default_lab); - basic_block default_bb = label_to_block_fn (cfun, default_lab); + basic_block default_bb = label_to_block (cfun, default_lab); edge default_edge = find_edge (bb, default_bb); /* Get upper and lower bounds of case values. */ diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 463dd8a3bf9..b021fb0f97b 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -389,7 +389,7 @@ lower_phi_internal_fn () { tree arg = gimple_call_arg (stmt, i); if (TREE_CODE (arg) == LABEL_DECL) - pred = label_to_block (arg); + pred = label_to_block (cfun, arg); else { edge e = find_edge (pred, bb); @@ -972,15 +972,15 @@ make_edges_bb (basic_block bb, struct omp_region **pcur_region, int *pomp_index) tree label2 = gimple_transaction_label_uninst (txn); if (label1) - make_edge (bb, label_to_block (label1), EDGE_FALLTHRU); + make_edge (bb, label_to_block (cfun, label1), EDGE_FALLTHRU); if (label2) - make_edge (bb, label_to_block (label2), + make_edge (bb, label_to_block (cfun, label2), EDGE_TM_UNINSTRUMENTED | (label1 ? 0 : EDGE_FALLTHRU)); tree label3 = gimple_transaction_label_over (txn); if (gimple_transaction_subcode (txn) & (GTMA_HAVE_ABORT | GTMA_IS_OUTER)) - make_edge (bb, label_to_block (label3), EDGE_TM_ABORT); + make_edge (bb, label_to_block (cfun, label3), EDGE_TM_ABORT); fallthru = false; } @@ -1265,8 +1265,8 @@ make_cond_expr_edges (basic_block bb) /* Entry basic blocks for each component. */ then_label = gimple_cond_true_label (entry); else_label = gimple_cond_false_label (entry); - then_bb = label_to_block (then_label); - else_bb = label_to_block (else_label); + then_bb = label_to_block (cfun, then_label); + else_bb = label_to_block (cfun, else_label); then_stmt = first_stmt (then_bb); else_stmt = first_stmt (else_bb); @@ -1373,7 +1373,7 @@ get_cases_for_edge (edge e, gswitch *t) { tree elt = gimple_switch_label (t, i); tree lab = CASE_LABEL (elt); - basic_block label_bb = label_to_block (lab); + basic_block label_bb = label_to_block (cfun, lab); edge this_edge = find_edge (e->src, label_bb); /* Add it to the chain of CASE_LABEL_EXPRs referencing E, or create @@ -1397,8 +1397,7 @@ make_gimple_switch_edges (gswitch *entry, basic_block bb) for (i = 0; i < n; ++i) { - tree lab = CASE_LABEL (gimple_switch_label (entry, i)); - basic_block label_bb = label_to_block (lab); + basic_block label_bb = gimple_switch_label_bb (cfun, entry, i); make_edge (bb, label_bb, 0); } } @@ -1407,7 +1406,7 @@ make_gimple_switch_edges (gswitch *entry, basic_block bb) /* Return the basic block holding label DEST. */ basic_block -label_to_block_fn (struct function *ifun, tree dest) +label_to_block (struct function *ifun, tree dest) { int uid = LABEL_DECL_UID (dest); @@ -1442,7 +1441,7 @@ make_goto_expr_edges (basic_block bb) if (simple_goto_p (goto_t)) { tree dest = gimple_goto_dest (goto_t); - basic_block label_bb = label_to_block (dest); + basic_block label_bb = label_to_block (cfun, dest); edge e = make_edge (bb, label_bb, EDGE_FALLTHRU); e->goto_locus = gimple_location (goto_t); gsi_remove (&last, true); @@ -1464,7 +1463,7 @@ make_gimple_asm_edges (basic_block bb) for (i = 0; i < n; ++i) { tree label = TREE_VALUE (gimple_asm_label_op (stmt, i)); - basic_block label_bb = label_to_block (label); + basic_block label_bb = label_to_block (cfun, label); make_edge (bb, label_bb, 0); } } @@ -1496,7 +1495,7 @@ static struct label_record static tree main_block_label (tree label) { - basic_block bb = label_to_block (label); + basic_block bb = label_to_block (cfun, label); tree main_label = label_for_bb[bb->index].label; /* label_to_block possibly inserted undefined label into the chain. */ @@ -1773,7 +1772,7 @@ group_case_labels_stmt (gswitch *stmt) int i, next_index, new_size; basic_block default_bb = NULL; - default_bb = label_to_block (CASE_LABEL (gimple_switch_default_label (stmt))); + default_bb = gimple_switch_default_bb (cfun, stmt); /* Look for possible opportunities to merge cases. */ new_size = i = 1; @@ -1785,7 +1784,7 @@ group_case_labels_stmt (gswitch *stmt) base_case = gimple_switch_label (stmt, i); gcc_assert (base_case); - base_bb = label_to_block (CASE_LABEL (base_case)); + base_bb = label_to_block (cfun, CASE_LABEL (base_case)); /* Discard cases that have the same destination as the default case or whose destiniation blocks have already been removed as unreachable. */ @@ -1806,7 +1805,7 @@ group_case_labels_stmt (gswitch *stmt) while (next_index < old_size) { tree merge_case = gimple_switch_label (stmt, next_index); - basic_block merge_bb = label_to_block (CASE_LABEL (merge_case)); + basic_block merge_bb = label_to_block (cfun, CASE_LABEL (merge_case)); wide_int bhp1 = wi::to_wide (base_high) + 1; /* Merge the cases if they jump to the same place, @@ -2387,7 +2386,7 @@ find_taken_edge_computed_goto (basic_block bb, tree val) basic_block dest; edge e = NULL; - dest = label_to_block (val); + dest = label_to_block (cfun, val); if (dest) e = find_edge (bb, dest); @@ -2455,7 +2454,7 @@ find_taken_edge_switch_expr (const gswitch *switch_stmt, tree val) else taken_case = find_case_label_for_value (switch_stmt, val); } - dest_bb = label_to_block (CASE_LABEL (taken_case)); + dest_bb = label_to_block (cfun, CASE_LABEL (taken_case)); e = find_edge (gimple_bb (switch_stmt), dest_bb); gcc_assert (e); @@ -5498,7 +5497,7 @@ gimple_verify_flow_info (void) err = 1; } - if (label_to_block (label) != bb) + if (label_to_block (cfun, label) != bb) { error ("label "); print_generic_expr (stderr, label); @@ -5655,8 +5654,7 @@ gimple_verify_flow_info (void) /* Mark all the destination basic blocks. */ for (i = 0; i < n; ++i) { - tree lab = CASE_LABEL (gimple_switch_label (switch_stmt, i)); - basic_block label_bb = label_to_block (lab); + basic_block label_bb = gimple_switch_label_bb (cfun, switch_stmt, i); gcc_assert (!label_bb->aux || label_bb->aux == (void *)1); label_bb->aux = (void *)1; } @@ -5711,8 +5709,8 @@ gimple_verify_flow_info (void) /* Check that we have all of them. */ for (i = 0; i < n; ++i) { - tree lab = CASE_LABEL (gimple_switch_label (switch_stmt, i)); - basic_block label_bb = label_to_block (lab); + basic_block label_bb = gimple_switch_label_bb (cfun, + switch_stmt, i); if (label_bb->aux != (void *)2) { @@ -5936,7 +5934,7 @@ gimple_redirect_edge_and_branch (edge e, basic_block dest) for (i = 0; i < n; i++) { tree elt = gimple_switch_label (switch_stmt, i); - if (label_to_block (CASE_LABEL (elt)) == e->dest) + if (label_to_block (cfun, CASE_LABEL (elt)) == e->dest) CASE_LABEL (elt) = label; } } @@ -5952,7 +5950,7 @@ gimple_redirect_edge_and_branch (edge e, basic_block dest) for (i = 0; i < n; ++i) { tree cons = gimple_asm_label_op (asm_stmt, i); - if (label_to_block (TREE_VALUE (cons)) == e->dest) + if (label_to_block (cfun, TREE_VALUE (cons)) == e->dest) { if (!label) label = gimple_block_label (dest); @@ -9143,6 +9141,41 @@ generate_range_test (basic_block bb, tree index, tree low, tree high, gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT); } +/* Return the basic block that belongs to label numbered INDEX + of a switch statement. */ + +basic_block +gimple_switch_label_bb (function *ifun, gswitch *gs, unsigned index) +{ + return label_to_block (ifun, CASE_LABEL (gimple_switch_label (gs, index))); +} + +/* Return the default basic block of a switch statement. */ + +basic_block +gimple_switch_default_bb (function *ifun, gswitch *gs) +{ + return gimple_switch_label_bb (ifun, gs, 0); +} + +/* Return the edge that belongs to label numbered INDEX + of a switch statement. */ + +edge +gimple_switch_edge (function *ifun, gswitch *gs, unsigned index) +{ + return find_edge (gimple_bb (gs), gimple_switch_label_bb (ifun, gs, index)); +} + +/* Return the default edge of a switch statement. */ + +edge +gimple_switch_default_edge (function *ifun, gswitch *gs) +{ + return gimple_switch_edge (ifun, gs, 0); +} + + /* Emit return warnings. */ namespace { diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h index 9491bb45feb..349a9543168 100644 --- a/gcc/tree-cfg.h +++ b/gcc/tree-cfg.h @@ -33,8 +33,7 @@ extern void init_empty_tree_cfg_for_function (struct function *); extern void init_empty_tree_cfg (void); extern void start_recording_case_labels (void); extern void end_recording_case_labels (void); -extern basic_block label_to_block_fn (struct function *, tree); -#define label_to_block(t) (label_to_block_fn (cfun, t)) +extern basic_block label_to_block (struct function *, tree); extern void cleanup_dead_labels (void); extern bool group_case_labels_stmt (gswitch *); extern bool group_case_labels (void); @@ -112,6 +111,10 @@ extern bool extract_true_false_controlled_edges (basic_block, basic_block, edge *, edge *); extern void generate_range_test (basic_block bb, tree index, tree low, tree high, tree *lhs, tree *rhs); +extern basic_block gimple_switch_label_bb (function *, gswitch *, unsigned); +extern basic_block gimple_switch_default_bb (function *, gswitch *); +extern edge gimple_switch_edge (function *, gswitch *, unsigned); +extern edge gimple_switch_default_edge (function *, gswitch *); /* Return true if the LHS of a call should be removed. */ diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c index b27ba8a7333..7fd0430d6cf 100644 --- a/gcc/tree-cfgcleanup.c +++ b/gcc/tree-cfgcleanup.c @@ -84,13 +84,12 @@ convert_single_case_switch (gswitch *swtch, gimple_stmt_iterator &gsi) return false; tree index = gimple_switch_index (swtch); - tree default_label = CASE_LABEL (gimple_switch_default_label (swtch)); tree label = gimple_switch_label (swtch, 1); tree low = CASE_LOW (label); tree high = CASE_HIGH (label); - basic_block default_bb = label_to_block_fn (cfun, default_label); - basic_block case_bb = label_to_block_fn (cfun, CASE_LABEL (label)); + basic_block default_bb = gimple_switch_default_bb (cfun, swtch); + basic_block case_bb = label_to_block (cfun, CASE_LABEL (label)); basic_block bb = gimple_bb (swtch); gcond *cond; @@ -266,7 +265,7 @@ cleanup_control_flow_bb (basic_block bb) label = TREE_OPERAND (gimple_goto_dest (stmt), 0); if (DECL_CONTEXT (label) != cfun->decl) return retval; - target_block = label_to_block (label); + target_block = label_to_block (cfun, label); for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); ) { if (e->dest != target_block) diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c index f367040af45..20e2db9e29a 100644 --- a/gcc/tree-eh.c +++ b/gcc/tree-eh.c @@ -2231,7 +2231,7 @@ make_eh_dispatch_edges (geh_dispatch *stmt) case ERT_TRY: for (c = r->u.eh_try.first_catch; c ; c = c->next_catch) { - dst = label_to_block (c->label); + dst = label_to_block (cfun, c->label); make_edge (src, dst, 0); /* A catch-all handler doesn't have a fallthru. */ @@ -2241,7 +2241,7 @@ make_eh_dispatch_edges (geh_dispatch *stmt) break; case ERT_ALLOWED_EXCEPTIONS: - dst = label_to_block (r->u.allowed.label); + dst = label_to_block (cfun, r->u.allowed.label); make_edge (src, dst, 0); break; @@ -2270,7 +2270,7 @@ make_eh_edges (gimple *stmt) gcc_assert (lp != NULL); src = gimple_bb (stmt); - dst = label_to_block (lp->post_landing_pad); + dst = label_to_block (cfun, lp->post_landing_pad); make_edge (src, dst, EDGE_EH); } @@ -2389,7 +2389,7 @@ redirect_eh_dispatch_edge (geh_dispatch *stmt, edge e, basic_block new_bb) case ERT_TRY: for (c = r->u.eh_try.first_catch; c ; c = c->next_catch) { - old_bb = label_to_block (c->label); + old_bb = label_to_block (cfun, c->label); if (old_bb == e->dest) { c->label = new_lab; @@ -2399,7 +2399,7 @@ redirect_eh_dispatch_edge (geh_dispatch *stmt, edge e, basic_block new_bb) break; case ERT_ALLOWED_EXCEPTIONS: - old_bb = label_to_block (r->u.allowed.label); + old_bb = label_to_block (cfun, r->u.allowed.label); gcc_assert (old_bb == e->dest); r->u.allowed.label = new_lab; any_changed = true; @@ -3329,7 +3329,7 @@ lower_resx (basic_block bb, gresx *stmt, else { lab = *slot; - new_bb = label_to_block (lab); + new_bb = label_to_block (cfun, lab); } gcc_assert (EDGE_COUNT (bb->succs) == 0); @@ -3733,7 +3733,7 @@ lower_eh_dispatch (basic_block src, geh_dispatch *stmt) while (tp_node); if (! have_label) { - remove_edge (find_edge (src, label_to_block (lab))); + remove_edge (find_edge (src, label_to_block (cfun, lab))); redirected = true; } } @@ -4046,7 +4046,7 @@ maybe_remove_unreachable_handlers (void) FOR_EACH_VEC_SAFE_ELT (cfun->eh->lp_array, i, lp) if (lp && lp->post_landing_pad) { - if (label_to_block (lp->post_landing_pad) == NULL) + if (label_to_block (cfun, lp->post_landing_pad) == NULL) { remove_unreachable_handlers (); return; @@ -4110,7 +4110,7 @@ remove_unreachable_handlers_no_lp (void) static bool unsplit_eh (eh_landing_pad lp) { - basic_block bb = label_to_block (lp->post_landing_pad); + basic_block bb = label_to_block (cfun, lp->post_landing_pad); gimple_stmt_iterator gsi; edge e_in, e_out; @@ -4475,7 +4475,7 @@ infinite_empty_loop_p (edge e_first) static bool cleanup_empty_eh (eh_landing_pad lp) { - basic_block bb = label_to_block (lp->post_landing_pad); + basic_block bb = label_to_block (cfun, lp->post_landing_pad); gimple_stmt_iterator gsi; gimple *resx; eh_region new_region; @@ -4795,7 +4795,7 @@ verify_eh_edges (gimple *stmt) return true; } - if (eh_edge->dest != label_to_block (lp->post_landing_pad)) + if (eh_edge->dest != label_to_block (cfun, lp->post_landing_pad)) { error ("Incorrect EH edge %i->%i", bb->index, eh_edge->dest->index); return true; @@ -4827,7 +4827,7 @@ verify_eh_dispatch_edge (geh_dispatch *stmt) case ERT_TRY: for (c = r->u.eh_try.first_catch; c ; c = c->next_catch) { - dst = label_to_block (c->label); + dst = label_to_block (cfun, c->label); e = find_edge (src, dst); if (e == NULL) { @@ -4846,7 +4846,7 @@ verify_eh_dispatch_edge (geh_dispatch *stmt) break; case ERT_ALLOWED_EXCEPTIONS: - dst = label_to_block (r->u.allowed.label); + dst = label_to_block (cfun, r->u.allowed.label); e = find_edge (src, dst); if (e == NULL) { diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 267880f3b5c..7430fd7e706 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -436,7 +436,8 @@ record_edge_info (basic_block bb) for (i = 0; i < n_labels; i++) { tree label = gimple_switch_label (switch_stmt, i); - basic_block target_bb = label_to_block (CASE_LABEL (label)); + basic_block target_bb + = label_to_block (cfun, CASE_LABEL (label)); if (CASE_HIGH (label) || !CASE_LOW (label) || info[target_bb->index]) diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index 56078110b39..4ed61c37a5f 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -1071,7 +1071,7 @@ simplify_gimple_switch_label_vec (gswitch *stmt, tree index_type) for (i = 0; i < gimple_switch_num_labels (stmt); i++) { tree elt = gimple_switch_label (stmt, i); - basic_block target = label_to_block (CASE_LABEL (elt)); + basic_block target = label_to_block (cfun, CASE_LABEL (elt)); bitmap_set_bit (target_blocks, target->index); } for (ei = ei_start (gimple_bb (stmt)->succs); (e = ei_safe_edge (ei)); ) diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c index dbc0bbd772a..a2304493495 100644 --- a/gcc/tree-ssa-threadedge.c +++ b/gcc/tree-ssa-threadedge.c @@ -977,7 +977,7 @@ thread_around_empty_blocks (edge taken_edge, || TREE_CODE (cond) == CASE_LABEL_EXPR)) { if (TREE_CODE (cond) == CASE_LABEL_EXPR) - taken_edge = find_edge (bb, label_to_block (CASE_LABEL (cond))); + taken_edge = find_edge (bb, label_to_block (cfun, CASE_LABEL (cond))); else taken_edge = find_taken_edge (bb, cond); @@ -1109,7 +1109,7 @@ thread_through_normal_block (edge e, edge taken_edge; if (TREE_CODE (cond) == CASE_LABEL_EXPR) taken_edge = find_edge (e->dest, - label_to_block (CASE_LABEL (cond))); + label_to_block (cfun, CASE_LABEL (cond))); else taken_edge = find_taken_edge (e->dest, cond); diff --git a/gcc/tree-ssa-uncprop.c b/gcc/tree-ssa-uncprop.c index 7d863a71551..98cc79e8607 100644 --- a/gcc/tree-ssa-uncprop.c +++ b/gcc/tree-ssa-uncprop.c @@ -184,7 +184,7 @@ associate_equivalences_with_edges (void) for (i = 0; i < n_labels; i++) { tree label = gimple_switch_label (switch_stmt, i); - basic_block bb = label_to_block (CASE_LABEL (label)); + basic_block bb = label_to_block (cfun, CASE_LABEL (label)); if (CASE_HIGH (label) || !CASE_LOW (label) diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c index a93610084f2..f3e42ddbd7f 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -725,7 +725,7 @@ convert_control_dep_chain_into_preds (vec *dep_chains, for (idx = 0; idx < gimple_switch_num_labels (gs); ++idx) { tree tl = gimple_switch_label (gs, idx); - if (e->dest == label_to_block (CASE_LABEL (tl))) + if (e->dest == label_to_block (cfun, CASE_LABEL (tl))) { if (!l) l = tl; diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c index 9a594a01fc4..ef08bdc990d 100644 --- a/gcc/tree-switch-conversion.c +++ b/gcc/tree-switch-conversion.c @@ -78,7 +78,6 @@ switch_conversion::collect (gswitch *swtch) unsigned int i; edge e, e_default, e_first; edge_iterator ei; - basic_block first; m_switch = swtch; @@ -87,9 +86,8 @@ switch_conversion::collect (gswitch *swtch) Collect the bits we can deduce from the CFG. */ m_index_expr = gimple_switch_index (swtch); m_switch_bb = gimple_bb (swtch); - m_default_bb - = label_to_block (CASE_LABEL (gimple_switch_default_label (swtch))); - e_default = find_edge (m_switch_bb, m_default_bb); + e_default = gimple_switch_default_edge (cfun, swtch); + m_default_bb = e_default->dest; m_default_prob = e_default->probability; m_default_count = e_default->count (); FOR_EACH_EDGE (e, ei, m_switch_bb->succs) @@ -120,15 +118,9 @@ switch_conversion::collect (gswitch *swtch) } if (m_contiguous_range) - { - first = label_to_block (CASE_LABEL (gimple_switch_label (swtch, 1))); - e_first = find_edge (m_switch_bb, first); - } + e_first = gimple_switch_edge (cfun, swtch, 1); else - { - first = m_default_bb; - e_first = e_default; - } + e_first = e_default; /* See if there is one common successor block for all branch targets. If it exists, record it in FINAL_BB. @@ -306,8 +298,7 @@ switch_conversion::check_final_bb () unsigned int branch_num = gimple_switch_num_labels (m_switch); for (unsigned int i = 1; i < branch_num; i++) { - tree lab = CASE_LABEL (gimple_switch_label (m_switch, i)); - if (label_to_block (lab) == bb) + if (gimple_switch_label_bb (cfun, m_switch, i) == bb) { m_reason = reason; return false; @@ -351,7 +342,7 @@ void switch_conversion::gather_default_values (tree default_case) { gphi_iterator gsi; - basic_block bb = label_to_block (CASE_LABEL (default_case)); + basic_block bb = label_to_block (cfun, CASE_LABEL (default_case)); edge e; int i = 0; @@ -388,7 +379,7 @@ switch_conversion::build_constructors () for (i = 1; i < branch_num; i++) { tree cs = gimple_switch_label (m_switch, i); - basic_block bb = label_to_block (CASE_LABEL (cs)); + basic_block bb = label_to_block (cfun, CASE_LABEL (cs)); edge e; tree high; gphi_iterator gsi; @@ -1577,15 +1568,11 @@ bit_test_cluster::hoist_edge_and_branch_if_true (gimple_stmt_iterator *gsip, void switch_decision_tree::compute_cases_per_edge () { - basic_block bb = gimple_bb (m_switch); reset_out_edges_aux (); int ncases = gimple_switch_num_labels (m_switch); for (int i = ncases - 1; i >= 1; --i) { - tree elt = gimple_switch_label (m_switch, i); - tree lab = CASE_LABEL (elt); - basic_block case_bb = label_to_block_fn (cfun, lab); - edge case_edge = find_edge (bb, case_bb); + edge case_edge = gimple_switch_edge (cfun, m_switch, i); case_edge->aux = (void *) ((intptr_t) (case_edge->aux) + 1); } } @@ -1601,8 +1588,7 @@ switch_decision_tree::analyze_switch_statement () auto_vec clusters; clusters.create (l - 1); - tree default_label = CASE_LABEL (gimple_switch_default_label (m_switch)); - basic_block default_bb = label_to_block_fn (cfun, default_label); + basic_block default_bb = gimple_switch_default_bb (cfun, m_switch); m_case_bbs.reserve (l); m_case_bbs.quick_push (default_bb); @@ -1612,15 +1598,16 @@ switch_decision_tree::analyze_switch_statement () { tree elt = gimple_switch_label (m_switch, i); tree lab = CASE_LABEL (elt); - basic_block case_bb = label_to_block_fn (cfun, lab); + basic_block case_bb = label_to_block (cfun, lab); edge case_edge = find_edge (bb, case_bb); tree low = CASE_LOW (elt); tree high = CASE_HIGH (elt); profile_probability p = case_edge->probability.apply_scale (1, (intptr_t) (case_edge->aux)); - clusters.quick_push (new simple_cluster (low, high, elt, case_bb, p)); - m_case_bbs.quick_push (case_bb); + clusters.quick_push (new simple_cluster (low, high, elt, case_edge->dest, + p)); + m_case_bbs.quick_push (case_edge->dest); } reset_out_edges_aux (); @@ -1694,9 +1681,8 @@ switch_decision_tree::try_switch_expansion (vec &clusters) return false; /* Find the default case target label. */ - tree default_label_expr = CASE_LABEL (gimple_switch_default_label (m_switch)); - m_default_bb = label_to_block_fn (cfun, default_label_expr); - edge default_edge = find_edge (bb, m_default_bb); + edge default_edge = gimple_switch_default_edge (cfun, m_switch); + m_default_bb = default_edge->dest; /* Do the insertion of a case label into m_case_list. The labels are fed to us in descending order from the sorted vector of case labels used diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index f20730a85ba..e8eb9292506 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3474,7 +3474,7 @@ find_switch_asserts (basic_block bb, gswitch *last) for (idx = 0; idx < n; ++idx) { ci[idx].expr = gimple_switch_label (last, idx); - ci[idx].bb = label_to_block (CASE_LABEL (ci[idx].expr)); + ci[idx].bb = label_to_block (cfun, CASE_LABEL (ci[idx].expr)); } edge default_edge = find_edge (bb, ci[0].bb); qsort (ci, n, sizeof (struct case_info), compare_case_labels); diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 072d9a7b454..11df1023b6e 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -2707,7 +2707,7 @@ vr_values::vrp_visit_switch_stmt (gswitch *stmt, edge *taken_edge_p) } *taken_edge_p = find_edge (gimple_bb (stmt), - label_to_block (CASE_LABEL (val))); + label_to_block (cfun, CASE_LABEL (val))); if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -3760,7 +3760,8 @@ vr_values::simplify_switch_using_ranges (gswitch *stmt) for (i = 0; i < n2; ++i) { e = find_edge (gimple_bb (stmt), - label_to_block (CASE_LABEL (TREE_VEC_ELT (vec2, i)))); + label_to_block (cfun, + CASE_LABEL (TREE_VEC_ELT (vec2, i)))); e->aux = (void *)-1; }