Add new gswitch related functions into tree-cfg.c.
authorMartin Liska <mliska@suse.cz>
Mon, 27 Aug 2018 12:17:19 +0000 (14:17 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Mon, 27 Aug 2018 12:17:19 +0000 (12:17 +0000)
2018-08-27  Martin Liska  <mliska@suse.cz>

* 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

18 files changed:
gcc/ChangeLog
gcc/cfgexpand.c
gcc/gimple-pretty-print.c
gcc/hsa-gen.c
gcc/ipa-fnsummary.c
gcc/stmt.c
gcc/tree-cfg.c
gcc/tree-cfg.h
gcc/tree-cfgcleanup.c
gcc/tree-eh.c
gcc/tree-ssa-dom.c
gcc/tree-ssa-forwprop.c
gcc/tree-ssa-threadedge.c
gcc/tree-ssa-uncprop.c
gcc/tree-ssa-uninit.c
gcc/tree-switch-conversion.c
gcc/tree-vrp.c
gcc/vr-values.c

index a4f4f565977e67f197ab48ddee80b8d957c608bc..40a8735a44610b7bfffc3a51f5402aaad02a3559 100644 (file)
@@ -1,3 +1,79 @@
+2018-08-27  Martin Liska  <mliska@suse.cz>
+
+       * 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  <rguenther@suse.de>
 
        * cfganal.h (rev_post_order_and_mark_dfs_back_seme): Declare.
index 3c5b30b79f8702a9222cd0c7d45f8da41f94a5e8..647764b0e94ec3476a38f7d07d2845eb8820798e 100644 (file)
@@ -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 ();
index d3c5ec6f79beb7e20bde80217e85284bcc33eda9..dd63a28761b85cf38d38108d559db86531edb823 100644 (file)
@@ -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);
index 6595bedac82b99ac91c7a6032bd3f1cf31f310fe..416de933a22b57777c0340f26493c147fb42669b 100644 (file)
@@ -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 <edge> 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 <profile_probability>
                 (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))
index a8fc2c2df9a64744dc03055fe3cf002bf96d0463..d8311d25ab2b95aed43246b2ff44dfb2aad53da5 100644 (file)
@@ -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);
 
index b8df18181377a13923000f7f85c0706c7ac08252..07355984de1aeaf2b5549d676f1a4792e3df53d2 100644 (file)
@@ -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);
 \f
 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.  */
index 463dd8a3bf920ebbc0455d0cfc49e7e759ce7a87..b021fb0f97ba6acec3bcc2244feb1e93e396f2ef 100644 (file)
@@ -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 {
index 9491bb45feb428224b3974117b33ccd5f4805474..349a954316858394df44ce35e98db5c8cb39e9d4 100644 (file)
@@ -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.  */
 
index b27ba8a7333bdf7720e12b1d26ef459bd25f8f5e..7fd0430d6cfad00f05e1c351dc03c8460608b529 100644 (file)
@@ -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)
index f367040af4512f3c75290134007c8f4dd86de112..20e2db9e29a5e455034baabb4cf9806e731b3115 100644 (file)
@@ -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)
        {
index 267880f3b5c29e8c04a9addfe2c3bcd807950867..7430fd7e706c2d38fb449c9d261dd9b02854f0da 100644 (file)
@@ -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])
index 56078110b39970d5baf46fa10c3d103e98cbc0df..4ed61c37a5fa5c8705928cb864936f97d9ce136b 100644 (file)
@@ -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)); )
index dbc0bbd772a67913d519586cf14b9ba99142f45a..a2304493495db2c8f893bfc7cffb9e9191437623 100644 (file)
@@ -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);
 
index 7d863a71551cd8f63c95bddf524c0b347da6c435..98cc79e86070726332f5d1e568fcb450bb0fbf5f 100644 (file)
@@ -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)
index a93610084f2a101b5399a10128b64c3f407b111d..f3e42ddbd7f2460fd204986987cb26997c4b141b 100644 (file)
@@ -725,7 +725,7 @@ convert_control_dep_chain_into_preds (vec<edge> *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;
index 9a594a01fc48cd78ef3fabe69a317f59cde4270f..ef08bdc990dcb773eeb1bfc6d7a5a6f87cc2cdcd 100644 (file)
@@ -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<cluster *> 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<cluster *> &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
index f20730a85badf4b6963ce2f7fa91b0b4c7691107..e8eb92925060f1464e0d0544409a3e1f436c7917 100644 (file)
@@ -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);
index 072d9a7b4548c53878782c4d886fc2a1ff693f8a..11df1023b6efa3618c670122a396f0cb67f0d94b 100644 (file)
@@ -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;
     }